@testver/testver 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +88 -69
  2. package/README.md +6 -2
  3. package/bin/testver.js +9 -1
  4. package/dist/index.js +52200 -35695
  5. package/package.json +179 -178
  6. package/src/ui/static/agents/antigravity.svg +76 -0
  7. package/src/ui/static/agents/codex.svg +3 -0
  8. package/src/ui/static/agents/gemini.svg +1 -0
  9. package/src/ui/static/agents/opencode.svg +4 -0
  10. package/src/ui/static/agents/vscode.svg +17 -0
  11. package/src/ui/static/assets/{AIPanel-KQFq4c0Q.js → AIPanel-RWO8Cd9w.js} +32 -32
  12. package/src/ui/static/assets/{AIRecordPanel-CAs8fXyS.js → AIRecordPanel-DnreS585.js} +40 -40
  13. package/src/ui/static/assets/{AIStreamUI-p_sMTEDQ.js → AIStreamUI-C1gHJtlF.js} +9 -9
  14. package/src/ui/static/assets/{AITestGenPage-CHaHfmu4.js → AITestGenPage-C8bWUelu.js} +5 -5
  15. package/src/ui/static/assets/{APITestingPage-BSGJY_hd.js → APITestingPage-DwL67hqL.js} +19 -19
  16. package/src/ui/static/assets/AboutPage-CynLB95E.js +1 -0
  17. package/src/ui/static/assets/AccessTokensTab-BdevOmpE.js +1 -0
  18. package/src/ui/static/assets/AdvancedPage-BeM7aB8b.js +3 -0
  19. package/src/ui/static/assets/{AnalyticsPage-Lm8noJqC.js → AnalyticsPage-C5ddYfRk.js} +1 -1
  20. package/src/ui/static/assets/AuditLogPage-DYcUdJoj.js +1 -0
  21. package/src/ui/static/assets/{ChangesSummary-Cu0_4Ucf.js → ChangesSummary-BjNMwGIZ.js} +3 -3
  22. package/src/ui/static/assets/{CodeMapPage-uEjuo3fk.js → CodeMapPage-BQOEtv-R.js} +3 -3
  23. package/src/ui/static/assets/{ConfirmDialog-DtotgVmI.js → ConfirmDialog-D_N9188T.js} +1 -1
  24. package/src/ui/static/assets/{CoveragePage-jNkQJA1P.js → CoveragePage-8bDSphY1.js} +2 -2
  25. package/src/ui/static/assets/{CronBuilder-D2fERHt9.js → CronBuilder-C7_JADb7.js} +1 -1
  26. package/src/ui/static/assets/{Dashboard-BaIj_IdQ.js → Dashboard-B22yRPyV.js} +1 -1
  27. package/src/ui/static/assets/{DefectsPage-DH0njYFG.js → DefectsPage-Arv4Ac-b.js} +72 -72
  28. package/src/ui/static/assets/{EmptyState-utxlJ0fu.js → EmptyState-BShNSbLf.js} +1 -1
  29. package/src/ui/static/assets/{ExportButton-ouKqn9CU.js → ExportButton-xrS_AnfS.js} +1 -1
  30. package/src/ui/static/assets/{FileViewer-mU3JloJ6.js → FileViewer-Bcr9T1jW.js} +18 -18
  31. package/src/ui/static/assets/{GitPage-TrX-RqNC.js → GitPage-DXL2Sv40.js} +12 -12
  32. package/src/ui/static/assets/{ImportExportPage-CIhK_raX.js → ImportExportPage-BcjzRd7T.js} +36 -36
  33. package/src/ui/static/assets/{JiraPushDialog-DgEZS-0u.js → JiraPushDialog-DNYU9Ce0.js} +1 -1
  34. package/src/ui/static/assets/{KpiTile-BHLE3HVj.js → KpiTile-BKlWqjgN.js} +1 -1
  35. package/src/ui/static/assets/{LiveExecutionView-CaIf7Jux.js → LiveExecutionView-1LlyEDEe.js} +1 -1
  36. package/src/ui/static/assets/{MediaModal-DNM45Uz2.js → MediaModal-Dyy_iHl9.js} +1 -1
  37. package/src/ui/static/assets/MobileRunPicker-Cf5rm469.js +1 -0
  38. package/src/ui/static/assets/MobileRunTarget-C4M4YJJh.js +6 -0
  39. package/src/ui/static/assets/{ModuleExplorer-rni7JbsL.js → ModuleExplorer-BKVbxFZK.js} +1 -1
  40. package/src/ui/static/assets/{OutputPage-Cn2WCpJ6.js → OutputPage-Bi-28tJi.js} +1 -1
  41. package/src/ui/static/assets/PipelinesPanel-BtO3iSJ4.js +1 -0
  42. package/src/ui/static/assets/{ProfilePage-BKNdkSnx.js → ProfilePage-BgZ4VDC-.js} +1 -1
  43. package/src/ui/static/assets/{ProjectExplorer-5e7J8t-o.js → ProjectExplorer-BVGbmVP7.js} +1 -1
  44. package/src/ui/static/assets/{RemoteFileStrip-C1S2aclP.js → RemoteFileStrip-dzPInzgb.js} +1 -1
  45. package/src/ui/static/assets/{ReportCard-D4EElEe9.js → ReportCard-LOf1PXlb.js} +2 -2
  46. package/src/ui/static/assets/{ReportFullView-2w2ysKRg.js → ReportFullView-Ce4OI8lf.js} +1 -1
  47. package/src/ui/static/assets/{ReportsPage-9Fx-IEwV.js → ReportsPage-DFxCQ8cY.js} +48 -48
  48. package/src/ui/static/assets/{ResultsPage-DPkfGh-K.js → ResultsPage-DD-uj8gk.js} +115 -115
  49. package/src/ui/static/assets/{RunState-CRuS_bC2.js → RunState-DDwFB4tA.js} +1 -1
  50. package/src/ui/static/assets/{RunTargets-CPKBrefj.js → RunTargets-CkIpY3v3.js} +1 -1
  51. package/src/ui/static/assets/ScriptMappingPage-DQQoR6sR.js +1 -0
  52. package/src/ui/static/assets/{SearchableDevicePicker-DubIldKj.js → SearchableDevicePicker-CenIxD7b.js} +1 -1
  53. package/src/ui/static/assets/{SettingsPage-BuZrrlW2.js → SettingsPage-DAV_0y0m.js} +83 -83
  54. package/src/ui/static/assets/{SharedReportView-ig5hECRk.js → SharedReportView-CqSLFKT1.js} +1 -1
  55. package/src/ui/static/assets/{SourcesPage-BPkqRqkC.js → SourcesPage-BvqC9oKw.js} +14 -14
  56. package/src/ui/static/assets/TestExplorerPage-Bdnll77k.js +7 -0
  57. package/src/ui/static/assets/{TestManagementPage-DJiWpCne.js → TestManagementPage-CCNE688A.js} +10 -10
  58. package/src/ui/static/assets/{TestPlansPage-G1lvK1C0.js → TestPlansPage-T6D25i6-.js} +5 -5
  59. package/src/ui/static/assets/{TestverCreditsRing-CEBSy3w3.js → TestverCreditsRing-CoDk5eAS.js} +1 -1
  60. package/src/ui/static/assets/TestverMcpPage-Dte0qSXp.js +34 -0
  61. package/src/ui/static/assets/{UncommittedDiffViewer-FKvUZcRi.js → UncommittedDiffViewer-BNroxCoo.js} +2 -2
  62. package/src/ui/static/assets/{UserManagementPage-gDGhaHE4.js → UserManagementPage-BU4MuDJZ.js} +10 -10
  63. package/src/ui/static/assets/{WorkflowsPage-BACdnU-1.js → WorkflowsPage-BP5k7AqE.js} +83 -83
  64. package/src/ui/static/assets/clipboard-BIEd7Ccc.js +1 -0
  65. package/src/ui/static/assets/{hiddenLlmProviders-DzwaR-b9.js → hiddenLlmProviders-BPORgy-e.js} +1 -1
  66. package/src/ui/static/assets/index-BlA8ntjb.js +47 -0
  67. package/src/ui/static/assets/index-Co4_SlGD.css +1 -0
  68. package/src/ui/static/assets/{reportMeta-3kxT7BIT.js → reportMeta-B9ZRW6ts.js} +1 -1
  69. package/src/ui/static/assets/runSelected-BoPm1sz-.js +1 -0
  70. package/src/ui/static/assets/{useFeatureFlags-DrhvBp0C.js → useFeatureFlags-B4Otsv-N.js} +1 -1
  71. package/src/ui/static/assets/{useJiraConnector-Dwj69Rfh.js → useJiraConnector--JZhbYrT.js} +1 -1
  72. package/src/ui/static/assets/{useOwnership-C1CmzcvJ.js → useOwnership-BhPOiYzy.js} +1 -1
  73. package/src/ui/static/assets/useSuites-GN_K2mHc.js +1 -0
  74. package/src/ui/static/assets/{useTestExplorer-CUqC18DV.js → useTestExplorer-BGhkGHKy.js} +1 -1
  75. package/src/ui/static/assets/{useTestLifecycle-C2S_vaX2.js → useTestLifecycle-DX5ES6x8.js} +1 -1
  76. package/src/ui/static/assets/{useTestManagement-DW6AW2mt.js → useTestManagement-ommXjx0q.js} +2 -2
  77. package/src/ui/static/assets/{useTestResults-yjH1aUy-.js → useTestResults-DWjvm8gm.js} +1 -1
  78. package/src/ui/static/assets/{vendor-icons-D_Dmmj8d.js → vendor-icons-Cm92aSc5.js} +1426 -1416
  79. package/src/ui/static/index.html +479 -479
  80. package/src/ui/static/assets/AboutPage-CDa24SCJ.js +0 -1
  81. package/src/ui/static/assets/AdvancedPage-BqXP0FLg.js +0 -3
  82. package/src/ui/static/assets/AuditLogPage-BvldSIik.js +0 -1
  83. package/src/ui/static/assets/MobileRunPicker-DFKm6_nU.js +0 -1
  84. package/src/ui/static/assets/MobileRunTarget-DHDoDZ_F.js +0 -6
  85. package/src/ui/static/assets/PipelinesPanel-D6zWcLtD.js +0 -1
  86. package/src/ui/static/assets/ScriptMappingPage-C3K_uyf0.js +0 -1
  87. package/src/ui/static/assets/TestExplorerPage-C_jl93GR.js +0 -7
  88. package/src/ui/static/assets/index-D6sQYc_0.js +0 -47
  89. package/src/ui/static/assets/index-aInN0yoR.css +0 -1
  90. package/src/ui/static/assets/runSelected-WlgnZcSF.js +0 -1
  91. package/src/ui/static/assets/useSuites-V0AxZYex.js +0 -1
@@ -1,40 +1,40 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D6sQYc_0.js","assets/vendor-react-DOVfxdUy.js","assets/vendor-query-DkZSMtfn.js","assets/vendor-icons-D_Dmmj8d.js","assets/index-aInN0yoR.css"])))=>i.map(i=>d[i]);
2
- import{r as s,j as e,d as mr,n as Gn}from"./vendor-react-DOVfxdUy.js";import{b as un,az as Sa,aA as nn,aB as Ra,aC as an,aD as Ca,aE as Wn,aF as Ta,aG as zr,ad as $a,aH as Vn,aI as gn,aJ as Yn,Q as Aa,S as bn,T as yn,aK as vn,aL as Ia,aM as wn,U as Ea,aN as jn,aO as za,aP as Ma,aQ as Xr,aR as Ar,aS as Pa,aT as Da,aU as kn,aV as Fa,aW as La,aX as _a,aY as qa,aZ as Ha,a_ as Oa,a$ as Nn,V as Ba,b0 as cr,ao as Bt,b1 as Ir,b2 as Sn,am as Qn,X as Ka,W as Ua,b3 as Ga,b4 as Wa,b5 as Va,b6 as Ya,b7 as Qa,b8 as Xa,b9 as Ja,ba as Za,bb as eo,bc as to,bd as Xn,be as so,x as Jn,bf as ro,bg as no,bh as Rn,bi as ao,bj as Cn,bk as Tn,bl as $n,bm as oo,bn as io,bo as lo,bp as co,bq as uo,br as po,bs as xo,bt as mo,bu as fo,bv as Jr,bw as ho,bx as go,by as bo,bz as yo,bA as vo,bB as wo,bC as jo,bD as ko,bE as No}from"./index-D6sQYc_0.js";import{t as ns,f as qs}from"./formatTestName-BKd2Uqhs.js";import{a as Zn,f as Zr}from"./formatDate-T65-Y6Mi.js";import{a as pn,u as ea,c as Pr}from"./vendor-query-DkZSMtfn.js";import{C as ta}from"./ConfirmDialog-DtotgVmI.js";import{u as as,X as wt,v as xn,a0 as je,bn as sa,bs as Bs,bt as ra,b7 as Ks,b8 as lt,ap as Us,r as yt,h as vt,Z as na,S as pr,a as Hs,bu as Dr,bv as mn,ac as Gs,bw as Or,al as fn,aC as aa,y as hs,bx as So,K as hn,J as on,a1 as xr,by as Ro,bz as Co,bA as To,a4 as Kt,bB as $o,bC as Ao,bD as Io,bE as Eo,bF as zo,aG as Mo,ag as An,b4 as fr,bG as Po,aI as Mr,a2 as Os,bd as oa,an as Fr,bH as dr,a_ as Lr,a6 as lr,ah as Do,bI as Fo,bJ as ia,bK as Lo,ba as _r,b6 as _o,aa as qo,bL as Ho,bM as Oo,bN as Bo}from"./vendor-icons-D_Dmmj8d.js";import{D as Ko,P as ln,A as la,a as Uo,L as Go,f as In,b as Wo,T as Vo,C as Yo}from"./ChangesSummary-Cu0_4Ucf.js";import{A as ca}from"./AIStreamUI-p_sMTEDQ.js";import{H as Qo,P as En}from"./hiddenLlmProviders-DzwaR-b9.js";import{T as cn}from"./TestverCreditsRing-CEBSy3w3.js";import{S as Xo,L as Jo}from"./SearchableDevicePicker-DubIldKj.js";import{u as da}from"./useTestExplorer-CUqC18DV.js";import"./useTabParam-CyYAP90W.js";import"./MediaModal-DNM45Uz2.js";const Zo="\"'`“”‘’„‟‚‛«»‹›"'",ei="?*+()[]{}|^$\\&<>%!;",ti=t=>t.charCodeAt(0)<32||t.charCodeAt(0)===127;function si(t){let o="";for(const m of t)Zo.includes(m)||(m==="&"?o+=" and ":m==="%"?o+=" percent ":m==="+"?o+=" plus ":m===";"?o+=", ":ei.includes(m)||ti(m)?o+=" ":o+=m);return o.replace(/\s+/g," ").replace(/ ([,:.])/g,"$1").replace(/,(?=[,:])/g,"").trim().replace(/^[,:.\-\s]+|[,:\-\s]+$/g,"")}function qr(t){const o=t.trim();if(!o)return null;const m=si(o);return m===o.replace(/\s+/g," ")?null:m?`Saved as “${m}” — 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 zn={recorded:{icon:e.jsx(vt,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(na,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(vt,{size:14,className:"text-gray-400"}),label:"Draft"}},Mn={success:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Us,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(lt,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function ri(t){return t.outcome&&Mn[t.outcome]?Mn[t.outcome]:zn[t.status]||zn.recorded}function ni(t){const o=Date.now()-t;return o<6e4?"Just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:o<6048e5?`${Math.floor(o/864e5)}d ago`:Zn(t)}function ai(t){const o=new Date,m=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),d=m-864e5,N=m-7*864e5,l={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const S of t){const y=S.createdAt;y>=m?l.Today.push(S):y>=d?l.Yesterday.push(S):y>=N?l["This Week"].push(S):l.Earlier.push(S)}return Object.entries(l).filter(([,S])=>S.length>0).map(([S,y])=>({label:S,items:y}))}const oi=["login","checkout","search","smoke","regression","e2e","navigation","form"];function ii({onLoadSession:t,onClose:o,activeSessionId:m}){const d=pn(),{toast:N}=un(),[l,S]=s.useState(""),[y,$]=s.useState(null),[L,_]=s.useState(!1),x=s.useRef({}),[C,z]=s.useState(null),[D,B]=s.useState(null),[K,q]=s.useState(""),[te,Y]=s.useState(null),[H,U]=s.useState(""),[w,Q]=s.useState(null),{data:G,isLoading:ee}=ea({queryKey:["recording-history"],queryFn:()=>Sa()}),ne=Pr({mutationFn:nn,onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),ue=Pr({mutationFn:({id:M,data:h})=>Ra(M,h),onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),oe=s.useMemo(()=>{const M=(G==null?void 0:G.sessions)||[];return Array.isArray(M)?M.filter(h=>h.status!=="draft"):[]},[G]),pe=s.useMemo(()=>{let M=oe;if(l){const h=l.toLowerCase();M=M.filter(X=>(X.name||"").toLowerCase().includes(h)||(X.url||"").toLowerCase().includes(h))}return C&&(M=M.filter(h=>Array.isArray(h.tags)&&h.tags.includes(C))),M},[oe,l,C]),b=s.useMemo(()=>{const M=new Set;return oe.forEach(h=>{Array.isArray(h.tags)&&h.tags.forEach(X=>M.add(X))}),Array.from(M).sort()},[oe]),A=s.useMemo(()=>{const M=new Set([...oi,...b]);return Array.from(M).sort()},[b]),R=s.useMemo(()=>ai(pe),[pe]),W=async M=>{try{const h=await an(M);h&&t(h)}catch(h){N("error",`Couldn't open the recording: ${h}`)}},le=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];j.includes(h)||(ue.mutate({id:M,data:{tags:[...j,h]}}),B(null),q(""))},ke=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];ue.mutate({id:M,data:{tags:j.filter(ce=>ce!==h)}})};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(as,{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:oe.length})]}),e.jsx("button",{onClick:o,"aria-label":"Close history",className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(xn,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:l,onChange:M=>S(M.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"})]}),b.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>z(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C?"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"}),b.map(M=>e.jsx("button",{onClick:()=>z(C===M?null:M),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C===M?"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:M},M))]})]}),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(je,{size:20,className:"text-brand-400 animate-spin"})}):R.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(as,{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"})]}):R.map(M=>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:M.label})}),M.items.map(h=>{const X=ri(h);return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":`Open recording ${h.name}`,"aria-current":m===h.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 ${m===h.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(h.id),onKeyDown:j=>{j.target===j.currentTarget&&(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),W(h.id))},children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[te===h.id?e.jsx("input",{type:"text",value:H,onChange:j=>U(j.target.value),onClick:j=>j.stopPropagation(),onBlur:()=>{H.trim()&&H.trim()!==h.name&&ue.mutate({id:h.id,data:{name:H.trim()}}),Y(null)},onKeyDown:j=>{j.key==="Enter"&&j.target.blur(),j.key==="Escape"&&Y(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:j=>{j.stopPropagation(),Y(h.id),U(h.name)},title:"Double-click to rename",children:h.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[h.actionCount," steps"]}),e.jsx("span",{children:ni(h.createdAt)})]}),Array.isArray(h.tags)&&h.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:j=>j.stopPropagation(),children:h.tags.map(j=>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:[j,e.jsx("button",{onClick:()=>Q({type:"remove-tag",sessionId:h.id,tag:j}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${j}"`,children:e.jsx(wt,{size:8})})]},j))}),D===h.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:j=>j.stopPropagation(),children:[A.filter(j=>!(h.tags||[]).includes(j)).map(j=>e.jsxs("button",{onClick:()=>le(h.id,j),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:["+ ",j]},j)),e.jsx("input",{type:"text",value:K,onChange:j=>q(j.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:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"&&K.trim()&&le(h.id,K.trim().toLowerCase())}}),e.jsx("button",{onClick:j=>{j.stopPropagation(),B(null),q("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{ref:j=>{x.current[h.id]=j},onClick:()=>{if(y===h.id)$(null);else{const j=x.current[h.id];if(j){const ce=j.getBoundingClientRect(),ct=window.innerHeight-ce.bottom;_(ct<160)}$(h.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(sa,{size:14})}),y===h.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>$(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 ${L?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{Y(h.id),U(h.name),$(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(Bs,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{B(D===h.id?null:h.id),$(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(ra,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Q({type:"delete-session",sessionId:h.id,sessionName:h.name}),$(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(Ks,{size:14})," Delete"]})]})]})]})]},h.id)})]},M.label))}),e.jsx(ta,{open:!!w,title:(w==null?void 0:w.type)==="delete-session"?"Delete recording?":(w==null?void 0:w.type)==="remove-tag"?"Remove tag?":"",description:(w==null?void 0:w.type)==="delete-session"?`Are you sure you want to delete "${w.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code history, and conversation. This action cannot be undone.`:(w==null?void 0:w.type)==="remove-tag"?`Are you sure you want to remove the tag "${w.tag}" from this recording? You can add it back later.`:"",confirmLabel:(w==null?void 0:w.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Q(null),onConfirm:()=>{(w==null?void 0:w.type)==="delete-session"?ne.mutate(w.sessionId):(w==null?void 0:w.type)==="remove-tag"&&ke(w.sessionId,w.tag),Q(null)}})]})}function Ct({label:t,hint:o,shortcut:m,children:d}){const N=s.useRef(null),l=s.useRef(null),[S,y]=s.useState(null),[$,L]=s.useState(null),_=()=>{var z;const C=(z=N.current)==null?void 0:z.getBoundingClientRect();C&&y(C)},x=()=>{y(null),L(null)};return s.useLayoutEffect(()=>{if(!S||!l.current)return;const C=l.current.getBoundingClientRect(),z=8,D=S.bottom+z+C.height<=window.innerHeight-8||S.top-z-C.height<8,B=S.left+S.width/2,K=Math.max(8,Math.min(B-C.width/2,window.innerWidth-C.width-8));L({left:K,top:D?S.bottom+z:S.top-z-C.height,below:D,arrowX:Math.max(10,Math.min(B-K,C.width-10))})},[S,t,o,m]),e.jsxs("span",{ref:N,className:"inline-flex",onMouseEnter:_,onMouseLeave:x,onFocus:_,onBlur:x,children:[d,S&&mr.createPortal(e.jsxs("span",{ref:l,role:"tooltip",style:$?{left:$.left,top:$.top}:{left:0,top:0,visibility:"hidden"},className:"pointer-events-none fixed z-[75] animate-tooltip-in",children:[$&&e.jsx("span",{style:{left:$.arrowX},className:`absolute -translate-x-1/2 w-2 h-2 bg-[#111827] rotate-45 ring-1 ring-white/10 ${$.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,m&&e.jsx("kbd",{className:"px-1 py-px rounded bg-white/15 text-[10px] font-mono font-normal text-white/90",children:m})]}),o&&e.jsx("span",{className:"text-[11px] leading-snug text-white/70",children:o})]})]}),document.body)]})}const Pn={recorded:{icon:e.jsx(vt,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(na,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(vt,{size:14,className:"text-gray-400"}),label:"Draft"}},Dn={success:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Us,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(lt,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function li(t){return t.outcome&&Dn[t.outcome]?Dn[t.outcome]:Pn[t.status]||Pn.recorded}function ci(t){const o=Date.now()-t;return o<6e4?"Just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:o<6048e5?`${Math.floor(o/864e5)}d ago`:Zn(t)}function di(t){const o=new Date,m=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),d=m-864e5,N=m-7*864e5,l={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const S of t){const y=S.createdAt;y>=m?l.Today.push(S):y>=d?l.Yesterday.push(S):y>=N?l["This Week"].push(S):l.Earlier.push(S)}return Object.entries(l).filter(([,S])=>S.length>0).map(([S,y])=>({label:S,items:y}))}const ui=["login","checkout","search","smoke","regression","e2e","navigation","form"];function en({open:t,onClose:o,onLoad:m,activeSessionId:d}){const N=pn(),[l,S]=s.useState(""),[y,$]=s.useState(null),[L,_]=s.useState(!1),x=s.useRef({}),[C,z]=s.useState(null),[D,B]=s.useState(null),[K,q]=s.useState(""),[te,Y]=s.useState(null),[H,U]=s.useState(""),[w,Q]=s.useState(null),{data:G,isLoading:ee}=ea({queryKey:["mobile-recording-history"],queryFn:()=>Ca({limit:500}),enabled:t,refetchInterval:t?1e4:!1}),ne=Pr({mutationFn:Wn,onSuccess:()=>N.invalidateQueries({queryKey:["mobile-recording-history"]})}),ue=Pr({mutationFn:({id:M,data:h})=>Ta(M,h),onSuccess:()=>N.invalidateQueries({queryKey:["mobile-recording-history"]})}),oe=s.useMemo(()=>{const M=(G==null?void 0:G.recordings)||[];return Array.isArray(M)?M.filter(h=>h.status!=="draft"):[]},[G]),pe=s.useMemo(()=>{let M=oe;if(l){const h=l.toLowerCase();M=M.filter(X=>(X.name||"").toLowerCase().includes(h)||(X.url||"").toLowerCase().includes(h)||(X.device||"").toLowerCase().includes(h))}return C&&(M=M.filter(h=>Array.isArray(h.tags)&&h.tags.includes(C))),M},[oe,l,C]),b=s.useMemo(()=>{const M=new Set;return oe.forEach(h=>{Array.isArray(h.tags)&&h.tags.forEach(X=>M.add(X))}),Array.from(M).sort()},[oe]),A=s.useMemo(()=>{const M=new Set([...ui,...b]);return Array.from(M).sort()},[b]),R=s.useMemo(()=>di(pe),[pe]),W=async M=>{try{const h=await zr(M);h!=null&&h.recording&&(m(h.recording),o())}catch{}},le=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];j.includes(h)||(ue.mutate({id:M,data:{tags:[...j,h]}}),B(null),q(""))},ke=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];ue.mutate({id:M,data:{tags:j.filter(ce=>ce!==h)}})};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(as,{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:oe.length})]}),e.jsx("button",{onClick:o,className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(xn,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:l,onChange:M=>S(M.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"})]}),b.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>z(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C?"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"}),b.map(M=>e.jsx("button",{onClick:()=>z(C===M?null:M),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C===M?"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:M},M))]})]}),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(je,{size:20,className:"text-brand-400 animate-spin"})}):R.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(as,{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"})]}):R.map(M=>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:M.label})}),M.items.map(h=>{const X=li(h);return e.jsxs("div",{className:`flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer group transition-colors ${d===h.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(h.id),children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[te===h.id?e.jsx("input",{type:"text",value:H,onChange:j=>U(j.target.value),onClick:j=>j.stopPropagation(),onBlur:()=>{H.trim()&&H.trim()!==h.name&&ue.mutate({id:h.id,data:{name:H.trim()}}),Y(null)},onKeyDown:j=>{j.key==="Enter"&&j.target.blur(),j.key==="Escape"&&Y(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:j=>{j.stopPropagation(),Y(h.id),U(h.name)},title:"Double-click to rename",children:h.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[h.actionCount," steps"]}),e.jsx("span",{children:ci(h.createdAt)})]}),Array.isArray(h.tags)&&h.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:j=>j.stopPropagation(),children:h.tags.map(j=>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:[j,e.jsx("button",{onClick:()=>Q({type:"remove-tag",sessionId:h.id,tag:j}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${j}"`,children:e.jsx(wt,{size:8})})]},j))}),D===h.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:j=>j.stopPropagation(),children:[A.filter(j=>!(h.tags||[]).includes(j)).map(j=>e.jsxs("button",{onClick:()=>le(h.id,j),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:["+ ",j]},j)),e.jsx("input",{type:"text",value:K,onChange:j=>q(j.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:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"&&K.trim()&&le(h.id,K.trim().toLowerCase())}}),e.jsx("button",{onClick:j=>{j.stopPropagation(),B(null),q("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{ref:j=>{x.current[h.id]=j},onClick:()=>{if(y===h.id)$(null);else{const j=x.current[h.id];if(j){const ce=j.getBoundingClientRect(),ct=window.innerHeight-ce.bottom;_(ct<160)}$(h.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(sa,{size:14})}),y===h.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>$(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 ${L?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{Y(h.id),U(h.name),$(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(Bs,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{B(D===h.id?null:h.id),$(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(ra,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Q({type:"delete-session",sessionId:h.id,sessionName:h.name}),$(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(Ks,{size:14})," Delete"]})]})]})]})]},h.id)})]},M.label))}),e.jsx(ta,{open:!!w,title:(w==null?void 0:w.type)==="delete-session"?"Delete recording?":(w==null?void 0:w.type)==="remove-tag"?"Remove tag?":"",description:(w==null?void 0:w.type)==="delete-session"?`Are you sure you want to delete "${w.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code, and healing manifest references. This action cannot be undone.`:(w==null?void 0:w.type)==="remove-tag"?`Are you sure you want to remove the tag "${w.tag}" from this recording? You can add it back later.`:"",confirmLabel:(w==null?void 0:w.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Q(null),onConfirm:()=>{(w==null?void 0:w.type)==="delete-session"?ne.mutate(w.sessionId):(w==null?void 0:w.type)==="remove-tag"&&ke(w.sessionId,w.tag),Q(null)}})]}):null}function tn({screenshot:t,screenshotSize:o,elementRect:m,step:d,description:N,onClose:l}){const S=s.useRef(null),[y,$]=s.useState(null);s.useEffect(()=>{const x=C=>{C.key==="Escape"&&l()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[l]),s.useLayoutEffect(()=>{if(!S.current)return;const x=()=>{var D;const z=(D=S.current)==null?void 0:D.getBoundingClientRect();z&&$({width:z.width,height:z.height})};x(),window.addEventListener("resize",x);const C=setInterval(x,250);return()=>{window.removeEventListener("resize",x),clearInterval(C)}},[]);const L=(()=>{if(!m||!o||!y)return null;const x=y.width/o.width,C=y.height/o.height;return{left:m.x*x,top:m.y*C,width:m.width*x,height:m.height*C}})(),_=e.jsx("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/70 backdrop-blur-sm",onClick:l,role:"dialog","aria-label":`Step ${d} screenshot`,children:e.jsxs("div",{className:"relative max-w-[92vw] max-h-[92vh] flex flex-col",onClick:x=>x.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:N}),e.jsx("button",{onClick:l,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(wt,{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:S,src:t,alt:N,className:"block max-w-[92vw] max-h-[82vh] w-auto h-auto",draggable:!1}),L&&e.jsx("div",{className:"absolute pointer-events-none border-[3px] border-red-400 rounded-sm",style:{left:L.left,top:L.top,width:L.width,height:L.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 mr.createPortal(_,document.body)}function Fn({entries:t,busy:o,onPermission:m,onOpenScreenshot:d}){const N=s.useRef(null);return s.useEffect(()=>{N.current&&(N.current.scrollTop=N.current.scrollHeight)},[t,o]),t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500 text-sm gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:14,className:"animate-spin"}),"Waiting for the AI to start…"]}):e.jsx(e.Fragment,{children:"No output yet."})}):e.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto p-4 space-y-1",children:[t.map(l=>e.jsx(pi,{entry:l,onPermission:m,onOpenScreenshot:d},l.id)),o&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 mt-3 px-4",children:[e.jsx(je,{size:11,className:"animate-spin"}),"Streaming…"]})]})}function pi({entry:t,onPermission:o,onOpenScreenshot:m}){return t.kind==="recorded-action"?e.jsx(mi,{entry:t,onOpenScreenshot:m}):t.kind==="system"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx(pr,{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(pr,{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(ca,{text:t.content})})}):t.kind==="tool"?e.jsx(fi,{entry:t}):t.kind==="file-diff"?e.jsx("div",{className:"py-1",children:e.jsx(Ko,{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"&&o?e.jsx(hi,{entry:t,onPermission:o}):t.kind==="permission"?null:t.kind==="error"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx(Hs,{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 xi={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 mi({entry:t,onOpenScreenshot:o}){const m=t.actionType==="tap"?Dr:t.actionType==="type"?Bs:t.actionType==="swipe"?mn:t.actionType==="assertion"?Gs:t.actionType==="annotation"?Or:fn,d=xi[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:()=>o==null?void 0:o({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(m,{size:12,className:"text-gray-500"})}),e.jsx(m,{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 fi({entry:t}){const[o,m]=s.useState(!1),d=t.phase==="start"?e.jsx(je,{size:11,className:"animate-spin text-blue-400"}):t.phase==="complete"?e.jsx(yt,{size:11,className:"text-emerald-400"}):t.phase==="error"?e.jsx(Us,{size:11,className:"text-red-400"}):e.jsx(aa,{size:11,className:"text-amber-400"}),N=!!(t.result||t.error||t.args);return e.jsxs("div",{className:"my-0.5",children:[e.jsxs("button",{onClick:()=>N&&m(l=>!l),className:`inline-flex max-w-full items-center gap-2 px-4 py-1.5 rounded-lg text-left transition-colors ${N?"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}),N&&t.phase!=="start"&&e.jsx(hs,{size:10,className:`text-gray-600 transition-transform ${o?"rotate-180":""}`})]}),o&&N&&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 hi({entry:t,onPermission:o}){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(aa,{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(So,{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:()=>o(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:()=>o(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:()=>o(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 ua({value:t,onChange:o,disabled:m=!1}){const d=m?"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 ${m?"opacity-50":""}`,title:d,children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="web",disabled:m,onClick:()=>o("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(hn,{size:12}),"Web"]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="mobile",disabled:m,onClick:()=>o("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(on,{size:12}),"Mobile"]})]})}function pa(t){const[o,m]=s.useState([]),[d,N]=s.useState((t==null?void 0:t.provider)||""),[l,S]=s.useState(t!=null&&t.provider&&t.model||""),y=s.useRef(!!(t!=null&&t.provider));return s.useEffect(()=>{let L=!0;return $a().then(_=>{var D;if(!L)return;const x=[],C=_.effectiveProvider||_.defaultProvider;for(const[B,K]of Object.entries(_.providers||{})){if(Qo.has(B))continue;const q=K;if(!q.hasApiKey&&!q.isLocal)continue;if(B==="testver"){x.push({provider:B,models:[""]});continue}const te=Array.isArray(q.models)&&q.models.length>0?q.models:[q.model].filter(Boolean);te.length>0&&x.push({provider:B,models:te})}m(x);const z=(D=_.providers)==null?void 0:D[C];z&&!y.current&&(N(C),S(C==="testver"?"":z.activeModel||z.model||""))}).catch(()=>{}),()=>{L=!1}},[]),{providerModels:o,selectedProvider:d,selectedModel:l,select:(L,_)=>{N(L),S(_)},setSelectedProvider:N,setSelectedModel:S}}function dn({providerModels:t,selectedProvider:o,selectedModel:m,onPick:d,disabled:N=!1,title:l="Select model for code generation",size:S="md"}){const[y,$]=s.useState(!1),L=s.useRef(null);if(s.useEffect(()=>{if(!y)return;const x=C=>{var z;C.key==="Escape"&&(C.stopPropagation(),$(!1),(z=L.current)==null||z.focus())};return document.addEventListener("keydown",x,!0),()=>document.removeEventListener("keydown",x,!0)},[y]),s.useEffect(()=>{N&&$(!1)},[N]),t.length===0)return null;const _=o==="testver"?"Testver":m||"Model";return e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs("button",{ref:L,type:"button",onClick:()=>$(x=>!x),disabled:N,"aria-haspopup":"listbox","aria-expanded":y,"aria-label":`Model: ${_}`,className:`flex items-center gap-1.5 px-2.5 ${S==="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:l,children:[e.jsx(En,{provider:o,size:14}),e.jsx("span",{className:"truncate",children:_}),e.jsx(hs,{size:11,className:`flex-shrink-0 transition-transform ${y?"rotate-180":""}`})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>$(!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(x=>e.jsxs("div",{role:"group","aria-label":x.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(En,{provider:x.provider,size:14}),x.provider]}),x.models.map(C=>{const z=C===m&&x.provider===o;return e.jsxs("button",{type:"button",role:"option","aria-selected":z,onClick:()=>{var D;d(x.provider,C),$(!1),(D=L.current)==null||D.focus()},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-sm font-mono transition-colors ${z?"bg-brand-500/10 text-brand-300":"text-gray-400 hover:bg-brand-500/10 hover:text-gray-200"}`,children:[z&&e.jsx(yt,{size:12,className:"text-brand-400 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:x.provider==="testver"?"Testver — managed model":C})]},`${x.provider}-${C}`)})]},x.provider))})]})]})}const gi={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 ur({icon:t,label:o,hint:m,onClick:d,disabled:N=!1,compact:l=!1,tone:S="ghost"}){return e.jsx(Ct,{label:o,hint:m,children:e.jsxs("button",{type:"button",onClick:d,disabled:N,"aria-label":o,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 ${l?"w-8":"px-3"} ${gi[S]}`,children:[t,!l&&e.jsx("span",{children:o})]})})}function Hr({kind:t,size:o=12}){return t==="data"?e.jsx(xr,{size:o,className:"text-teal-500 flex-shrink-0"}):t==="test"?e.jsx(Ro,{size:o,className:"text-blue-500 flex-shrink-0"}):t==="step"?e.jsx(Co,{size:o,className:"text-violet-500 flex-shrink-0"}):e.jsx(To,{size:o,className:"text-indigo-500 flex-shrink-0"})}function Ln(t,o){const m=t.slice(0,o),d=/(^|[\s(])@([^\s@]{0,60})$/.exec(m);return d?{start:m.length-d[2].length-1,query:d[2]}:null}function xa({value:t,onChange:o,references:m,onReferencesChange:d,placeholder:N,rows:l=3,autoFocus:S=!1,kinds:y,ariaLabel:$,onSubmit:L,textareaRef:_,size:x="md"}){const C=s.useRef(null),z=_??C,[D,B]=s.useState(null),[K,q]=s.useState([]),[te,Y]=s.useState(!1),[H,U]=s.useState(0),w=s.useRef(0),Q=s.useRef(null),[G,ee]=s.useState(null),ne=()=>{const b=z.current;if(!b)return;const A=b.getBoundingClientRect(),R=260,W=window.innerHeight-A.bottom-12,le=A.top-12,ke=W<Math.min(R,180)&&le>W;ee(ke?{left:A.left,width:A.width,bottom:window.innerHeight-A.top+4,maxHeight:Math.min(R,le)}:{left:A.left,width:A.width,top:A.bottom+4,maxHeight:Math.max(120,Math.min(R,W))})};s.useLayoutEffect(()=>{if(!D){ee(null);return}ne()},[D!==null,t]),s.useEffect(()=>{if(!D)return;const b=A=>{var R;(R=Q.current)!=null&&R.contains(A.target)||ne()};return window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[D!==null]),s.useEffect(()=>{var b,A;(A=(b=Q.current)==null?void 0:b.querySelector('[aria-selected="true"]'))==null||A.scrollIntoView({block:"nearest"})},[H]),s.useEffect(()=>{var b;S&&((b=z.current)==null||b.focus())},[S,z]),s.useEffect(()=>{if(!D){q([]);return}const b=++w.current;Y(!0);const A=setTimeout(()=>{Vn(D.query,y,20).then(R=>{w.current===b&&(q(R.items||[]),U(0))}).catch(()=>{w.current===b&&q([])}).finally(()=>{w.current===b&&Y(!1)})},150);return()=>clearTimeout(A)},[D==null?void 0:D.query,D!==null]);const ue=(b,A)=>{o(b),B(Ln(b,A))},oe=b=>{const A=z.current;if(!A||!D)return;const R=A.selectionStart??t.length,W=`@${b.kind==="method"&&b.name?b.className?`${b.className}.${b.name}`:b.name:b.label} `,le=t.slice(0,D.start)+W+t.slice(R);o(le);const{detail:ke,...M}=b;m.some(h=>h.kind===b.kind&&h.label===b.label)||d([...m,M]),B(null),requestAnimationFrame(()=>{A.focus();const h=D.start+W.length;A.setSelectionRange(h,h)})},pe=b=>{if(D&&K.length>0){if(b.key==="ArrowDown"){b.preventDefault(),U(A=>(A+1)%K.length);return}if(b.key==="ArrowUp"){b.preventDefault(),U(A=>(A-1+K.length)%K.length);return}if(b.key==="Enter"||b.key==="Tab"){b.preventDefault(),oe(K[H]);return}}if(D&&b.key==="Escape"){b.preventDefault(),b.stopPropagation(),B(null);return}b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&L&&(b.preventDefault(),L())};return e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:z,value:t,rows:l,"aria-label":$,placeholder:N,onChange:b=>ue(b.target.value,b.target.selectionStart??b.target.value.length),onClick:b=>B(Ln(t,b.target.selectionStart??t.length)),onKeyDown:pe,onBlur:()=>setTimeout(()=>B(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 ${x==="lg"?"px-4 py-3 text-[15px] leading-relaxed":"px-3 py-2 text-sm"}`}),D&&G&&mr.createPortal(e.jsxs("div",{ref:Q,role:"listbox","aria-label":"Project code and data",onMouseDown:b=>b.preventDefault(),style:{left:G.left,width:G.width,top:G.top,bottom:G.bottom,maxHeight:G.maxHeight},className:"fixed z-[90] overflow-y-auto rounded-lg border border-white/10 bg-surface-1 shadow-xl py-1",children:[te&&K.length===0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-gray-500",children:[e.jsx(je,{size:12,className:"animate-spin"})," Searching the project…"]}),!te&&K.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:D.query?`Nothing in the project matches "${D.query}".`:"Type a name to search page objects, helpers, tests and test data."}),K.map((b,A)=>e.jsxs("button",{type:"button",role:"option","aria-selected":A===H,onMouseDown:R=>{R.preventDefault(),oe(b)},onMouseEnter:()=>U(A),className:`w-full flex items-start gap-2 px-3 py-1.5 text-left ${A===H?"bg-brand-500/10":"hover:bg-white/5"}`,children:[e.jsx("span",{className:"mt-0.5",children:e.jsx(Hr,{kind:b.kind,size:x==="lg"?14:12})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block font-mono text-gray-200 truncate ${x==="lg"?"text-sm":"text-xs"}`,children:b.label}),e.jsx("span",{className:`block text-gray-500 truncate ${x==="lg"?"text-xs":"text-[10px]"}`,children:b.detail})]})]},`${b.kind}:${b.label}:${b.file}`))]}),document.body),m.length>0&&e.jsx("div",{className:`flex flex-wrap mt-1.5 ${x==="lg"?"gap-1.5":"gap-1"}`,children:m.map(b=>e.jsxs("span",{className:`inline-flex items-center gap-1 max-w-full rounded border border-white/10 bg-surface-2 text-gray-300 ${x==="lg"?"px-2 py-1 text-xs":"px-1.5 py-0.5 text-[11px]"}`,title:b.file?`${b.file}${b.line?`:${b.line}`:""}`:b.label,children:[e.jsx(Hr,{kind:b.kind,size:x==="lg"?13:11}),e.jsx("span",{className:"font-mono truncate",children:b.label}),e.jsx("button",{type:"button","aria-label":`Remove reference ${b.label}`,onClick:()=>d(m.filter(A=>!(A.kind===b.kind&&A.label===b.label))),className:"text-gray-500 hover:text-red-400",children:e.jsx(wt,{size:10})})]},`${b.kind}:${b.label}`))})]})}const Er=[{kind:"reuse",label:"Use existing step",icon:e.jsx($o,{size:15}),placeholder:"e.g. Log in as Admin using @LoginPage.loginAs"},{kind:"data",label:"Test data",icon:e.jsx(xr,{size:15}),placeholder:"e.g. Pick the first in-stock product from @data/products.json"},{kind:"email",label:"Email / code",icon:e.jsx(Ao,{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(Io,{size:15}),placeholder:"e.g. Create a user with POST /api/users and keep its id"},{kind:"wait",label:"Wait for",icon:e.jsx(Eo,{size:15}),placeholder:'e.g. Wait until the order status shows "Shipped" (up to 60 s)'},{kind:"custom",label:"Custom",icon:e.jsx(zo,{size:15}),placeholder:"Describe what the test does at this point…"}],sn=[{value:"link",label:"the link in it",name:"emailLink"},{value:"code",label:"the verification code",name:"emailCode"},{value:"text",label:"its text",name:"emailText"}],bi=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/;function ma({open:t,mode:o,initial:m,replaceCount:d=0,onCancel:N,onSave:l}){const[S,y]=s.useState("custom"),[$,L]=s.useState(""),[_,x]=s.useState([]),[C,z]=s.useState(""),[D,B]=s.useState(""),[K,q]=s.useState(""),[te,Y]=s.useState("link"),[H,U]=s.useState(!1),[w,Q]=s.useState(null),G=s.useRef(null);s.useEffect(()=>{t&&(y((m==null?void 0:m.customKind)||"custom"),L((m==null?void 0:m.instruction)||""),x((m==null?void 0:m.references)||[]),z(((m==null?void 0:m.outputs)||[]).join(", ")),B(""),q(""),Y("link"),U(!1),Q(null))},[t]),s.useEffect(()=>{if(!t)return;const R=W=>{W.key==="Escape"&&!H&&N()};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[t,H,N]);const ee=(R,W,le)=>{const ke=sn.find(ce=>ce.value===le),M=R.trim()?` with subject containing "${R.trim()}"`:"",h=W.trim()?` sent to ${W.trim()}`:"";L(`Read the latest email${h}${M} and keep ${ke.label}`);const X=C.split(",").map(ce=>ce.trim()).filter(Boolean),j=sn.map(ce=>ce.name);(X.length===0||X.every(ce=>j.includes(ce)))&&z(ke.name)};if(!t)return null;const ne=C.split(",").map(R=>R.trim().replace(/^\{+|\}+$/g,"")).filter(Boolean),ue=ne.find(R=>!bi.test(R)),oe=$.trim().length>0&&!ue&&!H,pe=o==="edit"?"Edit custom step":o==="replace"?`Replace ${d} step${d===1?"":"s"} with a custom step`:"Add custom step",b=Er.find(R=>R.kind===S)??Er[Er.length-1],A=async()=>{if(oe){U(!0),Q(null);try{await l({instruction:$.trim(),customKind:S,references:_,outputs:ne})}catch(R){Q(String((R==null?void 0:R.message)||R).replace(/^Error:\s*/,"")),U(!1)}}};return mr.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:()=>!H&&N()}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":pe,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(Kt,{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:pe}),e.jsx("p",{className:"text-sm text-gray-400 mt-1 leading-relaxed",children:o==="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:N,disabled:H,"aria-label":"Close",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5",children:e.jsx(wt,{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:Er.map(R=>e.jsxs("button",{type:"button",role:"radio","aria-checked":S===R.kind,onClick:()=>{var W;y(R.kind),R.kind==="email"&&!$.trim()&&ee(D,K,te),(W=G.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 ${S===R.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:[R.icon,R.label]},R.kind))}),S==="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:D,onChange:R=>{B(R.target.value),ee(R.target.value,K,te)},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:K,onChange:R=>{q(R.target.value),ee(D,R.target.value,te)},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:te,onChange:R=>{const W=R.target.value;Y(W),ee(D,K,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:sn.map(R=>e.jsx("option",{value:R.value,children:R.label},R.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(xa,{textareaRef:G,value:$,onChange:L,references:_,onReferencesChange:x,placeholder:b.placeholder,rows:S==="email"?3:5,size:"lg",autoFocus:!0,ariaLabel:"What the step does",onSubmit:A}),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:C,onChange:R=>z(R.target.value),placeholder:"e.g. resetLink, otpCode","aria-invalid":!!ue,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 ${ue?"border-red-500/50":"border-white/10 focus:border-brand-500/50"}`}),e.jsx("p",{className:`text-xs mt-2 leading-relaxed ${ue?"text-red-500 dark:text-red-400":"text-gray-500"}`,children:ue?`"${ue}" 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."}),w&&e.jsx("p",{role:"alert",className:"mt-4 text-sm text-red-600 dark:text-red-400",children:w})]}),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:N,disabled:H,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:A,disabled:!oe,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:[H&&e.jsx(je,{size:14,className:"animate-spin"}),o==="edit"?"Save":o==="replace"?"Replace steps":"Add step"]})]})]})]}),document.body)}function fa({current:t,options:o,onPick:m,disabled:d=!1}){const[N,l]=s.useState(!1),[S,y]=s.useState(null),$=s.useRef(null),L=s.useRef(null),_=()=>{var z;if(N){l(!1);return}const C=(z=$.current)==null?void 0:z.getBoundingClientRect();if(C){const B=Math.max(8,Math.min(C.right-288,window.innerWidth-288-8)),K=window.innerHeight-C.bottom;y(K<260&&C.top>K?{left:B,bottom:window.innerHeight-C.top+4}:{left:B,top:C.bottom+4})}l(!0)};s.useEffect(()=>{if(!N)return;const C=B=>{var K;B.key==="Escape"&&(B.stopPropagation(),l(!1),(K=$.current)==null||K.focus())},z=B=>{var K,q;!((K=L.current)!=null&&K.contains(B.target))&&!((q=$.current)!=null&&q.contains(B.target))&&l(!1)},D=B=>{var K;(K=L.current)!=null&&K.contains(B.target)||l(!1)};return document.addEventListener("keydown",C,!0),document.addEventListener("mousedown",z),window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),()=>{document.removeEventListener("keydown",C,!0),document.removeEventListener("mousedown",z),window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D)}},[N]);const x=C=>{var z;m(C),l(!1),(z=$.current)==null||z.focus()};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:$,type:"button",disabled:d,onClick:C=>{C.stopPropagation(),_()},title:"Use a value for this step","aria-label":"Use a value for this step","aria-haspopup":"listbox","aria-expanded":N,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(Mo,{size:14})}),N&&S&&mr.createPortal(e.jsxs("div",{ref:L,role:"listbox","aria-label":"Values",onClick:C=>C.stopPropagation(),style:{left:S.left,top:S.top,bottom:S.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:()=>x(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(An,{size:12,className:"text-brand-500"})}),"The value recorded (as typed)"]}),o.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."}),o.map(C=>e.jsxs("button",{type:"button",role:"option","aria-selected":t===C.name,onClick:()=>x(C.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===C.name&&e.jsx(An,{size:12,className:"text-brand-500"})}),C.source==="data"?e.jsx(xr,{size:12,className:"text-teal-500 flex-shrink-0"}):e.jsx(Kt,{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:`{${C.name}}`}),e.jsx("span",{className:"block text-[10px] text-gray-500 truncate",children:C.detail})]})]},C.name))]}),document.body)]})}function ha({settings:t,onChange:o,inputs:m,onMatch:d,disabled:N=!1}){var ue,oe,pe,b;const[l,S]=s.useState(!1),[y,$]=s.useState(""),[L,_]=s.useState([]),[x,C]=s.useState(!1),[z,D]=s.useState(!1),[B,K]=s.useState(null),[q,te]=s.useState(null),[Y,H]=s.useState(!!((ue=t==null?void 0:t.before)!=null&&ue.text)),U=s.useRef(null),w=t==null?void 0:t.testData,Q=s.useRef(t);Q.current=t;const G=A=>{const R={...Q.current||{},...A};R.testData||delete R.testData,(!R.before||!R.before.text.trim())&&delete R.before;const W=R.testData||R.before?R:null;Q.current=W,o(W)};s.useEffect(()=>{if(!l)return;let A=!0;C(!0);const R=setTimeout(()=>{Vn(y,["data"],25).then(W=>{A&&_(W.items||[])}).catch(()=>{A&&_([])}).finally(()=>{A&&C(!1)})},150);return()=>{A=!1,clearTimeout(R)}},[l,y]),s.useEffect(()=>{var A;l&&((A=U.current)==null||A.focus())},[l]),s.useEffect(()=>{if(!(w!=null&&w.file)){te(null);return}let A=!0;return gn(w.file).then(R=>{A&&te({columns:R.columns,values:R.firstRow,rowCount:R.rowCount})}).catch(()=>{A&&te(null)}),()=>{A=!1}},[w==null?void 0:w.file]);const ee=async A=>{D(!0),K(null);try{const R=await gn(A);G({testData:{file:R.file,columns:R.columns,perRow:!1}}),te({columns:R.columns,values:R.firstRow,rowCount:R.rowCount}),S(!1),$("")}catch(R){K(String((R==null?void 0:R.message)||R).replace(/^Error:\s*/,""))}finally{D(!1)}},ne=[];if(q)for(const A of m){if(A.valueFrom||!A.value)continue;const R=q.values.findIndex(W=>W&&W===A.value);R>=0&&ne.push({id:A.id,valueFrom:`data.${q.columns[R]}`})}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)"})]})}),!w&&!l&&e.jsxs("button",{type:"button",disabled:N,onClick:()=>S(!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(fr,{size:12})," Read the data from a file"]}),l&&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(xn,{size:12,className:"text-gray-500"}),e.jsx("input",{ref:U,value:y,onChange:A=>$(A.target.value),placeholder:"Search test-data files…",onKeyDown:A=>{A.key==="Escape"&&(A.stopPropagation(),S(!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:()=>S(!1),className:"text-gray-500 hover:text-gray-200",children:e.jsx(wt,{size:12})})]}),e.jsxs("div",{className:"max-h-44 overflow-y-auto py-1",children:[(x||z)&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-xs text-gray-500",children:[e.jsx(je,{size:12,className:"animate-spin"})," ",z?"Reading columns…":"Searching…"]}),!x&&L.length===0&&e.jsxs("div",{className:"px-3 py-2 text-xs text-gray-500",children:["No test-data files found",y?` for "${y}"`:"",". Files show up here once the Data Map has scanned them."]}),L.map(A=>e.jsxs("button",{type:"button",onClick:()=>ee(A.file||A.label),disabled:z,className:"w-full flex items-start gap-2 px-3 py-1.5 text-left hover:bg-white/5",children:[e.jsx(xr,{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:A.label}),e.jsx("span",{className:"block text-[10px] text-gray-500 truncate",children:A.detail})]})]},A.label))]})]}),B&&e.jsx("p",{role:"alert",className:"text-xs text-red-600 dark:text-red-400 mt-1",children:B}),w&&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(xr,{size:13,className:"text-teal-500 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-mono text-gray-200 truncate flex-1",title:w.file,children:w.file}),e.jsx("button",{type:"button",disabled:N,"aria-label":"Remove test data",onClick:()=>G({testData:void 0}),className:"text-gray-500 hover:text-red-400",children:e.jsx(wt,{size:13})})]}),!!((oe=w.columns)!=null&&oe.length)&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[w.columns.slice(0,10).map(A=>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.${A}`},A)),w.columns.length>10&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:["+",w.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:N,checked:!!w.perRow,onChange:A=>G({testData:{...w,perRow:A.target.checked}})}),"Run the test once per row",q!=null&&q.rowCount?` (${q.rowCount})`:""]}),ne.length>0&&e.jsxs("button",{type:"button",disabled:N,onClick:()=>d(ne),className:"inline-flex items-center gap-1 text-xs text-teal-600 dark:text-teal-400 hover:underline",children:[e.jsx(Po,{size:12})," Use the data for ",ne.length," recorded value",ne.length===1?"":"s"]})]})]})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>H(A=>!A),"aria-expanded":Y,className:"inline-flex items-center gap-1 text-[10px] text-gray-500 uppercase tracking-wider hover:text-gray-300",children:[e.jsx(hs,{size:11,className:`transition-transform ${Y?"":"-rotate-90"}`}),"Before the test ",e.jsx("span",{className:"normal-case",children:"(optional)"})]}),Y&&e.jsx("div",{className:"mt-1",children:e.jsx(xa,{value:((pe=t==null?void 0:t.before)==null?void 0:pe.text)||"",onChange:A=>{var R,W;return G({before:{text:A,references:(W=(R=Q.current)==null?void 0:R.before)==null?void 0:W.references}})},references:((b=t==null?void 0:t.before)==null?void 0:b.references)||[],onReferencesChange:A=>{var R,W;return G({before:{text:((W=(R=Q.current)==null?void 0:R.before)==null?void 0:W.text)||"",references:A}})},placeholder:"e.g. Start logged in as a Manager using @loginAs",rows:2,ariaLabel:"Before the test"})})]})]})}const yi=!1;function vi({onPhaseChange:t,registerControls:o}){const{toast:m}=un(),[d,N]=s.useState([]),[l,S]=s.useState("browserstack"),[y,$]=s.useState([]),[L,_]=s.useState([]),[x,C]=s.useState(""),[z,D]=s.useState(""),[B,K]=s.useState(!1),[q,te]=s.useState(null),Y=s.useRef(null),[H,U]=s.useState("setup"),[w,Q]=s.useState(null),[G,ee]=s.useState([]),[ne,ue]=s.useState(!1),[oe,pe]=s.useState(!1),[b,A]=s.useState(!1),[R,W]=s.useState(0),le=s.useRef(0),ke=s.useRef(()=>{}),M=s.useCallback(n=>{const i=Math.floor(n/1e3)!==Math.floor(le.current/1e3);le.current=n,i&&ke.current()},[]),[h,X]=s.useState(!1),[j,ce]=s.useState([]),[ct,gs]=s.useState("wdio-appium-ts"),[os,Ws]=s.useState(null),[ve,Tt]=s.useState(null),[Ut,st]=s.useState(!1),[we,$t]=s.useState(!1),[Ye,is]=s.useState(""),[be,He]=s.useState(""),[Ie,Oe]=s.useState("auto"),[$e,ls]=s.useState(""),{data:Me}=da(),[dt,Gt]=s.useState(!1),[ut,Wt]=s.useState(""),[Ne,bs]=s.useState(""),[At,Vt]=s.useState(new Set),[ys,It]=s.useState([]),[Vs,Et]=s.useState(!1),{providerModels:vs,selectedModel:Qe,selectedProvider:rt,select:ws}=pa(),[pt,Be]=s.useState(!1),[xt,js]=s.useState(""),Ys=s.useRef(null),[mt,me]=s.useState([]),[Qs,ks]=s.useState(null),[ze,jt]=s.useState(!1),hr=s.useRef(!1);hr.current=ze;const[Xs,Ke]=s.useState(null),[nt,cs]=s.useState(""),Ue=s.useRef(null),zt=s.useRef([]);s.useEffect(()=>{zt.current=mt},[mt]);const[Js,ds]=s.useState(!1),[gr,Ns]=s.useState({}),[br,Mt]=s.useState(!1),[at,Ss]=s.useState(null),Yt=s.useRef([]),[kt,Rs]=s.useState(null),Zs=s.useRef(null);s.useEffect(()=>{Zs.current=kt},[kt]);const[Pe,De]=s.useState(!1),ye=Gn(),Pt=s.useRef(null),Qt=s.useRef(null),Fe=s.useRef(new Set),Dt=s.useRef(()=>{}),er=n=>{Xn(n).catch(()=>{})},Ge=()=>{for(const n of Fe.current)er(n);Fe.current=new Set},[Ae,se]=s.useState(null),[Ft,he]=s.useState(null),[ie,xe]=s.useState(!1),[We,Cs]=s.useState(""),[us,Ts]=s.useState(""),[ot,ps]=s.useState(null),[Xt,it]=s.useState(""),[yr,ft]=s.useState(!1),[Xe,Lt]=s.useState(null),Le=s.useRef(null),Se=s.useRef(0),Re=pn(),[Ce,_e]=s.useState(null),[qe,Ve]=s.useState(new Set),[Nt,re]=s.useState(null),xs=s.useRef(null),[$s,As]=s.useState(null),[ms,vr]=s.useState("above"),[wr,Je]=s.useState(null),[tr,sr]=s.useState(null),Is=s.useRef(null),[Te,_t]=s.useState(null);s.useEffect(()=>{(async()=>{try{await Yn().catch(()=>null),await wa();const[n,i,c,P,u]=await Promise.all([Aa(),bn(),yn().catch(()=>({session:null})),vn().catch(()=>({recording:!1,startedAt:0,actions:[]})),Ia().catch(()=>({formatters:[]}))]);if(N(n.providers),_(i.apps),ce(u.formatters),c.session&&Q(c.session),P.recording&&P.actions&&P.actions.length>0)ee(P.actions),W(P.startedAt),U("recording"),re(P.settings||null),Le.current=wn();else if(!await va())try{const O=await zr(wn());O.recording&&O.recording.status==="draft"&&O.recording.actionCount>0&&(Lt({id:O.recording.id,name:O.recording.name,actionCount:O.recording.actionCount,url:O.recording.url||O.recording.device}),X(!0))}catch{}const I=n.providers.find(O=>O.hasCredentials&&O.enabled);I&&S(I.id)}catch(n){se(n.message)}})()},[]);const Es=s.useRef([]);s.useEffect(()=>{Es.current=G},[G]);const zs=s.useRef(null);s.useEffect(()=>{zs.current=w},[w]),s.useEffect(()=>{if(H!=="recording"||ne)return;const n=()=>{var u,I;if(Es.current.length===0)return;const P=Le.current||Xr();Le.current=P,Ar({id:P,name:`Draft — ${((u=zs.current)==null?void 0:u.device)||"mobile recording"}`,status:"draft",url:(I=zs.current)==null?void 0:I.device}).then(()=>Re.invalidateQueries({queryKey:["mobile-recording-history"]})).catch(()=>{})},i=setTimeout(n,1500),c=setInterval(n,1e4);return()=>{clearTimeout(i),clearInterval(c)}},[H,ne,Re]);const Ms=s.useCallback(async n=>{K(!0),se(null);try{const c=[...(await Ea(n)).devices].sort((u,I)=>u.realMobile!==I.realMobile?u.realMobile?-1:1:u.name.localeCompare(I.name));$(c);const P=c.filter(u=>!u.unavailableReason);if(!x||!c.some(u=>u.id===x)){const u=P.find(I=>I.realMobile&&/iphone 15/i.test(I.name))||P.find(I=>I.realMobile&&/pixel/i.test(I.name))||P[0];C((u==null?void 0:u.id)??"")}}catch(i){se(i.message),$([])}finally{K(!1)}},[x]);s.useEffect(()=>{const n=d.find(i=>i.id===l);n!=null&&n.hasCredentials?Ms(l):$([])},[l,d,Ms]),s.useEffect(()=>{if(H!=="recording"||ne||R===0)return;const n=setInterval(()=>M(Date.now()-R),250);return()=>clearInterval(n)},[H,ne,R]);const Ps=s.useRef(null),jr=s.useRef(!0),Br=()=>{const n=Ps.current;n&&(jr.current=n.scrollHeight-n.scrollTop-n.clientHeight<120)};s.useEffect(()=>{const n=Ps.current;!n||H!=="recording"||!jr.current||requestAnimationFrame(()=>{n.scrollTo({top:n.scrollHeight,behavior:"smooth"})})},[G.length,H]),s.useEffect(()=>{const n=i=>{const c=i.detail;c!=null&&c.action&&(ee(P=>P.some(u=>u.index===c.action.index)?P:[...P,c.action]),c.action.type==="assertion"&&(pe(!1),kn(!1).catch(()=>{})))};return window.addEventListener("testver-mobile-action",n),()=>window.removeEventListener("testver-mobile-action",n)},[]),s.useEffect(()=>{window.__testver_mobile_record_paused=ne},[ne]),s.useEffect(()=>{window.__testver_mobile_assert_mode=oe,window.__testver_mobile_annotate_mode=b},[oe,b]);const Kr=async n=>{xe(!0),se(null),te(0),he(`Uploading ${n.name}…`);try{const i=await Ka(n,void 0,P=>te(P)),c=await bn();_(c.apps),D(i.id),he(`Added ${n.name}.`)}catch(i){se(i.message),he(null)}finally{xe(!1),te(null)}},kr=async()=>{const n=y.find(i=>i.id===x);if(!n){se("Pick a device first.");return}if(!z){se("Pick or upload an app first.");return}xe(!0),U("starting"),se(null),he(l==="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 i=w;i||(i=(await Ua({provider:l,deviceKey:n.rawDeviceKey,osVersion:n.os,platform:n.platform,appId:z,sessionName:"Testver AI Record"})).session,Q(i));const c=await Ga();Le.current=Xr(),Se.current=0,re(null),Ve(new Set),ee(c.actions),W(c.startedAt),M(0),ue(!1),pe(!1),A(!1),Ws(null),Tt(null),X(!1),U("recording"),he(`Recording on ${n.name} (${n.os}). Click on the device to capture taps.`),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"recorder-page"}}))}catch(i){se(i.message),he(null),U("setup")}finally{xe(!1)}},Ds=s.useCallback(()=>{ue(!0),Se.current=Date.now(),he("Recording paused."),jn(!0).catch(n=>{ue(!1),Se.current=0,se(`Couldn't pause the recording: ${n.message}`)})},[]),Nr=s.useCallback(()=>{const n=Se.current;n&&W(i=>i&&i+(Date.now()-n)),Se.current=0,ue(!1),he("Recording resumed."),jn(!1).catch(i=>{ue(!0),Se.current=Date.now(),se(`Couldn't resume the recording: ${i.message}`)})},[]),Sr=s.useCallback(async()=>{xe(!0),se(null);try{try{const i=await za();Array.isArray(i.actions)&&ee(i.actions)}catch{}Se.current=0,ue(!1),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!1,owner:"recorder-page"}}));const n=await Ma({testName:`Recorded ${Zr(new Date)}`,formatter:ct});if(Ws(n),U("stopped"),he(`${G.length} step${G.length===1?"":"s"} captured. Review or generate.`),G.length>0){const i=Le.current||Xr();Le.current=i;try{await Ar({id:i,name:`Recorded — ${(w==null?void 0:w.device)||Zr(new Date)}`,status:"recorded",url:w==null?void 0:w.device}),Re.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(c){console.warn("[MobileRecorder] Failed to persist on Stop:",c)}}}catch(n){se(n.message)}finally{xe(!1)}},[G.length,ct,w,Re]),Rr=s.useCallback(async n=>{if(!(Js||Es.current.length===0)){Mt(!1),se(null),Ns({}),ds(!0),he(n?"Restarting the app, then replaying recorded steps…":"Replaying recorded steps from the current screen…");try{await Pa(1,n)}catch(i){ds(!1),se(`Playback failed: ${i.message}`)}}},[Js]),rr=s.useCallback(async()=>{xe(!0);try{const n=await Da();ee(n.actions),n.startedAt&&W(n.startedAt),Se.current=0,ue(!1),U("recording"),he("Recording resumed — capture additional steps."),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"recorder-page"}}))}catch(n){se(n.message)}finally{xe(!1)}},[]),nr=s.useCallback(async()=>{const n=!oe;try{await kn(n),pe(n),n&&A(!1)}catch(i){se(i.message)}},[oe]),qt=s.useCallback(async()=>{const n=!b;try{await Fa(n),A(n),n&&pe(!1)}catch(i){se(i.message)}},[b]),ar=n=>{try{window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:n}}))}catch{}},Cr=async()=>{if(We.trim()){xe(!0),se(null),window.__testver_mobile_action_in_flight=!0;try{const n=await Ja(We);ee(i=>[...i,n.action]),ar(n.action),Cs("")}catch(n){se(n.message)}finally{xe(!1),window.__testver_mobile_action_in_flight=!1}}},Jt=async n=>{xe(!0),se(null),window.__testver_mobile_action_in_flight=!0;try{if(ne){await Za(n);return}const i=await eo(n);ee(c=>[...c,i.action]),ar(i.action)}catch(i){se(i.message)}finally{xe(!1),window.__testver_mobile_action_in_flight=!1}},or=async()=>{if(us.trim()){xe(!0);try{const n=await Xa(us);ee(i=>[...i,n.action]),ar(n.action),Ts("")}catch(n){se(n.message)}finally{xe(!1)}}},ht=s.useCallback(async()=>{const n=Le.current;if(n)try{await Ar({id:n}),Re.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(i){console.warn("[MobileRecorder] persist after mutation failed:",i)}},[Re]),Ur=async n=>{xe(!0);try{await Ya(n),ee(i=>i.filter(c=>c.index!==n)),await ht()}catch(i){se(i.message)}finally{xe(!1)}},Gr=n=>{ps(n.index),it(n.description)},Wr=async()=>{if(ot!==null){try{const n=await Ir(ot,{description:Xt});ee(i=>i.map(c=>c.index===ot?n.action:c)),await ht()}catch(n){se(n.message)}ps(null)}},Vr=async n=>{const i=Ce;if(i){if(i.mode==="add"){const c=await Wa(n,i.afterIndex);ee(P=>{const u=[...P];if(i.afterIndex===null)u.unshift(c.action);else{const I=i.afterIndex!==void 0?u.findIndex(O=>O.index===i.afterIndex):-1;I>=0?u.splice(I+1,0,c.action):u.push(c.action)}return u})}else if(i.mode==="edit"&&i.editIndex!==void 0){const c=await Ir(i.editIndex,{instruction:n.instruction,customKind:n.customKind,references:n.references||[],outputs:n.outputs||[]});ee(P=>P.map(u=>u.index===i.editIndex?c.action:u))}else if(i.mode==="replace"){const c=[...qe],P=await Va(c,n);ee(u=>{const I=new Set(c),O=u.findIndex(tt=>I.has(tt.index)),de=u.filter(tt=>!I.has(tt.index));return de.splice(O>=0?Math.min(O,de.length):de.length,0,P.action),de}),Ve(new Set)}_e(null),await ht()}},Yr=async n=>{try{const i=await Qa(n);ee(c=>{const P=c.findIndex(de=>de.index===n);if(P<0)return c;const u=[...c];if(u.splice(P,1,...i.actions),!i.order)return u;const I=new Map(u.map(de=>[de.index,de])),O=i.order.map(de=>I.get(de)).filter(de=>!!de);return O.length===u.length?O:u}),await ht()}catch(i){se(i.message)}},ir=async(n,i)=>{try{const c=await Ir(n,{valueFrom:i});ee(P=>P.map(u=>u.index===n?c.action:u)),await ht()}catch(c){se(c.message)}},r=s.useRef(null),a=n=>{re(n),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{to(n).then(()=>ht()).catch(()=>{})},500)},p=s.useMemo(()=>{var P;const n=new Map,i=[],c=(((P=Nt==null?void 0:Nt.testData)==null?void 0:P.columns)||[]).map(u=>({name:`data.${u}`,source:"data",detail:Nt.testData.file}));return G.forEach((u,I)=>{if(n.set(u.index,[...i,...c]),u.type==="custom")for(const O of u.outputs||[])i.push({name:O,source:"step",detail:`saved by step ${I+1}`})}),n},[G,Nt]),f=async n=>{try{const i=await so(n);ee(i.actions),await ht()}catch(i){se(i.message)}},k=n=>i=>{xs.current=n,Je(n),i.dataTransfer.effectAllowed="move";try{const c=G[n];if(c){const P=document.createElement("div");P.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;",P.textContent=`#${n+1} ${c.description.slice(0,60)}`,document.body.appendChild(P),i.dataTransfer.setDragImage(P,12,12),setTimeout(()=>P.remove(),0)}}catch{}},v=n=>i=>{i.preventDefault(),i.dataTransfer.dropEffect="move";const c=i.currentTarget.getBoundingClientRect(),P=c.top+c.height/2,u=i.clientY<P?"above":"below";($s!==n||ms!==u)&&(As(n),vr(u))},g=n=>()=>{$s===n&&As(null)},T=n=>async i=>{i.preventDefault();const c=xs.current;if(xs.current=null,Je(null),As(null),c===null||c===n)return;const P=G[c],u=G.map(de=>de.index),[I]=u.splice(c,1);let O=n;c<n?O=ms==="above"?n-1:n:O=ms==="above"?n:n+1,O=Math.max(0,Math.min(O,u.length)),u.splice(O,0,I),await f(u),P&&(Is.current&&clearTimeout(Is.current),sr(P.index),Is.current=setTimeout(()=>{sr(null),Is.current=null},2500))},Z=()=>{xs.current=null,Je(null),As(null)},J=s.useCallback(async()=>{xe(!0),U("generating"),se(null);try{const n=await La({testName:`Recorded ${Zr(new Date)}`,formatter:ct});Tt(n),U("done"),he(`Saved to ${n.specPath}`),Re.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(n){se(n.message),U("stopped")}finally{xe(!1)}},[ct,Re]);s.useEffect(()=>{if(!(ye!=null&&ye.subscribe))return;const n=c=>{var P;if(!(!c||typeof c!="object")&&!(c.requestId&&c.requestId!==Ue.current)){if(c.requestId&&typeof c.runSeq=="number"){const u=Pt.current;if(u&&u.requestId===c.requestId){if(c.runSeq<=u.lastSeq)return;u.lastSeq=c.runSeq}else Pt.current={requestId:c.requestId,lastSeq:c.runSeq}}if(c.type==="ai-fix-stopped"){Ue.current=null,Ke("stopped"),jt(!1),xe(!1),st(!1),Ss(null),Yt.current=[],U("done");return}switch(c.type){case"mobile-session-started":{const u=c.session;u&&Q(u);break}case"mobile-session-closed":{Q(null);const u=c.reason;typeof u=="string"&&u&&m("info",u);break}case"mobile-recorded-action":{const u=c.action;if(u){if(!u.screenshot)try{const I=(P=window.__testver_capture_mobile_frame)==null?void 0:P.call(window);if(I!=null&&I.dataUrl){if(u.screenshot=I.dataUrl,u.screenshotSize={width:I.width,height:I.height},u.elementRect&&I.deviceWidth>0&&I.deviceHeight>0){const O=I.width/I.deviceWidth,de=I.height/I.deviceHeight;u.elementRect={x:Math.round(u.elementRect.x*O),y:Math.round(u.elementRect.y*de),width:Math.round(u.elementRect.width*O),height:Math.round(u.elementRect.height*de)}}Ir(u.index,{screenshot:u.screenshot,screenshotSize:u.screenshotSize,elementRect:u.elementRect}).catch(()=>{})}}catch{}window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:u}}))}break}case"ai-fix-stream":{const u=typeof c.content=="string"?c.content:"";if(!u)return;me(I=>{const O=I[I.length-1];return(O==null?void 0:O.kind)==="text"?[...I.slice(0,-1),{...O,content:O.content+u}]:[...I,{kind:"text",id:`text-${Date.now()}-${I.length}`,content:u}]});break}case"ai-fix-tool":{const u=c.phase;me(I=>{if(u!=="start")for(let O=I.length-1;O>=0;O--){const de=I[O];if(de.kind==="tool"&&de.toolName===c.toolName&&de.phase==="start"){const tt=[...I];return tt[O]={...de,phase:u,result:c.result,error:c.error},tt}}return[...I,{kind:"tool",id:`tool-${Date.now()}-${I.length}`,phase:u,toolName:String(c.toolName||"tool"),args:typeof c.args=="string"?c.args:c.args?JSON.stringify(c.args,null,2):void 0,result:typeof c.result=="string"?c.result:void 0,error:typeof c.error=="string"?c.error:void 0}]});break}case"ai-fix-file-diff":{me(u=>[...u,{kind:"file-diff",id:`diff-${Date.now()}-${u.length}`,filePath:String(c.filePath||""),diffType:c.diffType,diff:typeof c.diff=="string"?c.diff:"",linesAdded:typeof c.linesAdded=="number"?c.linesAdded:void 0,linesRemoved:typeof c.linesRemoved=="number"?c.linesRemoved:void 0}]);break}case"ai-fix-permission":{const u={permissionId:String(c.permissionId),toolName:String(c.toolName||"tool"),args:typeof c.args=="string"?c.args:c.args?JSON.stringify(c.args,null,2):"",fullPath:typeof c.fullPath=="string"?c.fullPath:void 0};Ss(I=>I?(Yt.current.push(u),I):u);break}case"ai-fix-status":break;case"ai-fix-error":{me(u=>[...u,{kind:"error",id:`err-${Date.now()}-${u.length}`,message:String(c.message||"Unknown error")}]);break}case"ai-fix-done":{xe(!1),st(!1),jt(u=>{if(u)return u;const I=[/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],O=zt.current;let de=0;for(let ge=O.length-1;ge>=0;ge--)if(O[ge].kind==="user"){de=ge+1;break}const Ht=O.slice(de).some(ge=>ge.kind==="error"||ge.kind==="text"&&typeof ge.content=="string"&&I.some(bt=>bt.test(ge.content)))?"failed":"success";Ke(ge=>ge??Ht);const F=Le.current;return F?Ar({id:F,name:Zs.current||void 0,status:"generated",outcome:Ht,fullTimeline:zt.current}).then(()=>{for(const ge of Fe.current)er(ge)}).catch(()=>{}).finally(()=>Re.invalidateQueries({queryKey:["mobile-recording-history"]})):Re.invalidateQueries({queryKey:["mobile-recording-history"]}),u}),U("done");break}case"mobile-playback":{const u=c;if(u.action&&typeof u.index=="number"){const I=u.status==="ok"?"done":u.status==="error"?"error":"running";Ns(O=>({...O,[u.index]:I}))}else u.status==="started"?(ds(!0),Ns({})):u.status==="done"?(ds(!1),he("Playback complete.")):u.status==="error"&&(ds(!1),se(u.error||"Playback failed."));break}}}};return Dt.current=n,ye.subscribe(c=>{const P=Qt.current;if(P&&c&&c.requestId===P.requestId){P.queue.push(c);return}n(c)})},[ye,Re,m]);const ae=s.useCallback((n,i=!1)=>{!at||!(ye!=null&&ye.send)||(ye.send({type:"ai-fix-permission-response",permissionId:at.permissionId,granted:n,remember:n&&i}),Ss(Yt.current.shift()||null))},[at,ye]),fe=s.useCallback(async()=>{const n=Ue.current;if(n){try{await _a(n)}catch{}Ke("stopped"),Ue.current=null,jt(!1),xe(!1),st(!1),U("done")}},[]),E=s.useCallback(async()=>{const n=`mobile-recorder-followup-${Date.now()}`,i=nt.trim(),c=ze&&!i;cs(""),xe(!0),st(!0),jt(!1),Ue.current=n,Pt.current={requestId:n,lastSeq:0},Fe.current.add(n),ks(n),me(F=>[...F,c?{kind:"system",id:`system-confirm-${Date.now()}-${F.length}`,message:"✓ Confirmed — executing the plan"}:{kind:"user",id:`user-${Date.now()}-${F.length}`,text:i}]),U("generating");const P=new Set,u=[],I=[];for(const F of G)u.push(`${F.type}: ${F.description}`);for(const F of mt)if(F.kind==="file-diff")P.add(F.filePath);else if(F.kind==="user")I.push(`User: ${F.text}`);else if(F.kind==="text"&&F.content){const ge=String(F.content);I.push(`Assistant: ${ge.length>2e3?ge.substring(0,2e3)+"... [truncated]":ge}`)}else if(F.kind==="tool"){if(F.phase==="start")continue;const ge=F.args?` ${String(F.args).substring(0,100)}`:"";let bt="";if(F.phase==="complete"){const Rt=F.result?String(F.result):"";bt=Rt?` → ${Rt.length>300?Rt.substring(0,300)+"... [truncated]":Rt}`:" → (no output)"}else F.phase==="error"?bt=` → ERROR: ${F.error?String(F.error).substring(0,300):"failed"}`:F.phase==="denied"&&(bt=" → DENIED by user");I.push(`[Tool ${F.phase}] ${F.toolName}${ge}${bt}`)}else F.kind==="error"&&I.push(`[Stream Error] ${F.message}`);const O=[];u.length>0&&O.push(`Recorded steps (${u.length}):
4
- ${u.map((F,ge)=>` ${ge+1}. ${F}`).join(`
5
- `)}`),P.size>0&&O.push(`Files created/modified:
6
- ${[...P].map(F=>` - ${F}`).join(`
7
- `)}`),I.length>0&&O.push(`Conversation history (in order):
8
- ${I.join(`
9
-
10
- `)}`);const de=O.length>0?O.join(`
11
-
12
- `):void 0,tt=/\.(spec|test|e2e)\.(ts|js|tsx|jsx|mjs|cjs)$|(^|[\\/])test_[^\\/]+\.py$|_test\.py$|\.feature$|(Test|Tests|IT|Spec)\.(java|kt|rb|cs)$/,Ht=mt.filter(F=>F.kind==="file-diff").map(F=>F.filePath).filter(Boolean).find(F=>tt.test(F))||(we&&be?be:void 0);try{await qa({requestId:n,prompt:i,proceedAfterAnalysis:c,previousContext:de,model:Qe||void 0,provider:rt||void 0,testFilePath:Ht,recordingId:Le.current||void 0,displayText:i||void 0})}catch(F){se(F.message),xe(!1),st(!1),Ue.current=null,c&&jt(!0),U("done")}},[nt,ze,G,mt,Qe,rt,we,be]),Ee=s.useCallback(async()=>{xe(!0),st(!0),se(null),he(null),De(!1);const n=Es.current,i=(w==null?void 0:w.device)||"device",c=[{kind:"system",id:`sys-start-${Date.now()}`,message:`Recording started — ${i}`},...n.map((I,O)=>({kind:"recorded-action",id:`rec-${I.index}`,stepNum:O+1,actionType:I.type,description:I.description,screenshot:I.screenshot,screenshotSize:I.screenshotSize,elementRect:I.elementRect})),{kind:"system",id:`sys-stop-${Date.now()}`,message:`Recording stopped — ${n.length} action${n.length===1?"":"s"} captured`},{kind:"system",id:`system-${Date.now()}`,message:"Analyzing your project patterns and recorded actions…"}];me(c),Ke(null),jt(!0);const P=`mobile-recorder-${Date.now()}`;Ue.current=P,Pt.current={requestId:P,lastSeq:0},Ge(),Fe.current.add(P),ks(P),U("generating");const u=Ye||`recorded-${new Date().toISOString().slice(0,16).replace(/[:.]/g,"-")}`;Rs(u);try{await Ha({requestId:P,testName:u,model:Qe||void 0,provider:rt||void 0,mergeMode:we,targetTestFile:we?be:void 0,targetTestName:we&&Ne?Ne:void 0,insertPosition:we?Ie:void 0,userGuidance:we&&Ie==="auto"?$e:void 0,settings:Nt,analyzeOnly:!0,recordingId:Le.current||void 0})}catch(I){se(I.message),U("stopped"),xe(!1),st(!1),Ue.current=null}},[we,Ye,be,Ne,Ie,$e,Qe,rt,w,Nt]);s.useEffect(()=>{if(!be||!Ne){It([]);return}if(Me!=null&&Me.suites){const n=c=>c.replace(/\\/g,"/"),i=Me.suites.find(c=>n(c.file)===n(be));if(i){const c=i.tests.find(P=>P.name===Ne);if(c!=null&&c.steps&&c.steps.length>0){It(c.steps.map(P=>({keyword:P.keyword,name:P.name})));return}}}Et(!0),Oa(be,Ne).then(n=>{n!=null&&n.humanSteps&&Array.isArray(n.humanSteps)&&n.humanSteps.length>0?It(n.humanSteps.map(i=>({keyword:i.keyword,name:i.name}))):It([])}).catch(()=>It([])).finally(()=>Et(!1))},[be,Ne,Me]);const Ze=s.useMemo(()=>ys,[ys]),Zt=ie||Js||G.length===0||!we&&!Ye.trim()||we&&(!be||!Ne)||we&&Ie==="auto"&&!$e.trim(),V=s.useCallback(async()=>{Ge();try{await Nn()}catch{}ee([]),re(null),Ve(new Set),ue(!1),W(0),M(0),Ws(null),Tt(null),se(null),he(null),pe(!1),A(!1),X(!1),De(!1),_t(null),U("setup");try{const n=await yn();Q(n.session??null)}catch{Q(null)}window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!1,owner:"recorder-page"}}))},[]);s.useCallback(async()=>{xe(!0);try{await Ba()}catch{}Q(null),await V(),xe(!1)},[V]);const et=async()=>{try{if(Xe!=null&&Xe.id){const i=await zr(Xe.id);if(i.recording.actions.length>0){await Sn(i.recording.actions,i.recording.sessionInfo),ee(i.recording.actions),W(Date.now()-(i.recording.durationMs||0)),X(!1),Lt(null),Le.current=Xe.id,U("stopped");return}}const n=await vn();ee(n.actions),W(n.startedAt||Date.now()),X(!1),U("stopped")}catch(n){se(n.message)}},es=async()=>{try{await Nn()}catch{}if(Xe!=null&&Xe.id){try{await Wn(Xe.id)}catch{}Re.invalidateQueries({queryKey:["mobile-recording-history"]})}Lt(null),X(!1)},St=async n=>{n.id!==Le.current&&Ge(),await ts(n),await gt(n,{onlyThisTab:!0})},ts=async n=>{Fe.current=new Set,re(n.settings||null),Ve(new Set);try{await Sn(n.actions,n.sessionInfo,n.settings||null)}catch(c){console.warn("[MobileRecorder] Failed to hydrate backend on load:",c)}ee(n.actions),W(Date.now()),Le.current=n.id;const i=n.status==="generated";if(i){Tt({status:"loaded",specPath:n.generatedSpecPath||"(not generated)",healingPath:n.generatedHealingPath||"(not generated)",specSource:"",healingJson:"",actions:n.actions});const c=Array.isArray(n.fullTimeline)&&n.fullTimeline.length>0?n.fullTimeline:[{kind:"system",id:`sys-load-${n.id}`,message:`Loaded "${n.name}" — ${n.actions.length} recorded step${n.actions.length===1?"":"s"}. (Generated before transcript history was saved, so the AI conversation isn't available for this recording.)`}];me(c),jt(!1),Rs(n.name||null),Ke(n.outcome==="failed"?"failed":n.outcome==="stopped"?"stopped":"success"),De(!0),U("done")}else me([]),De(!1),U("stopped");he(i?`Loaded generated "${n.name}" — read-only view (${n.actions.length} step${n.actions.length===1?"":"s"}). Click "New Recording" to start fresh.`:`Loaded "${n.name}" — ${n.actions.length} step${n.actions.length===1?"":"s"}. You can edit, reorder, delete, or generate code.`)},gt=async(n,i={})=>{var fs,Ht;let c=[];try{c=(await cr(n.id)).runs}catch{return}const P=Bt(),u=c.filter(F=>F.kind==="record-mobile"&&!F.saved&&(!i.onlyThisTab||F.status!=="running"||F.clientId===P)).sort((F,ge)=>F.startedAt-ge.startedAt);if(u.length===0)return;const I=n.actions||[],O=Array.isArray(n.fullTimeline)&&n.fullTimeline.length>0;me(O?n.fullTimeline:[{kind:"system",id:`sys-start-${n.id}`,message:`Recording started — ${((fs=n.sessionInfo)==null?void 0:fs.device)||"device"}`},...I.map((F,ge)=>({kind:"recorded-action",id:`rec-${F.index}`,stepNum:ge+1,actionType:F.type,description:F.description,screenshot:F.screenshot,screenshotSize:F.screenshotSize,elementRect:F.elementRect})),{kind:"system",id:`sys-stop-${n.id}`,message:`Recording stopped — ${I.length} action${I.length===1?"":"s"} captured`}]),De(!1),he(null);const de=()=>new Promise(F=>setTimeout(F,30));for(const F of u){F===u[u.length-1]&&F.status==="running"&&(Qt.current={requestId:F.requestId,queue:[]});let bt;try{bt=await Qn(F.requestId)}catch{Qt.current=null;continue}const Rt=F.meta||{},$r=`${F.requestId}-${Date.now()}`;me(ss=>[...ss,Rt.followUp?F.userText?{kind:"user",id:`user-${$r}`,text:F.userText}:{kind:"system",id:`system-confirm-${$r}`,message:"✓ Confirmed — executing the plan"}:{kind:"system",id:`system-${$r}`,message:"Analyzing your project patterns and recorded actions…"}]),bt.truncated&&me(ss=>[...ss,{kind:"system",id:`sys-trunc-${$r}`,message:"The earliest steps of this generation are too long to show here."}]),jt(!!Rt.analyzeOnly),hr.current=!!Rt.analyzeOnly,typeof Rt.testName=="string"&&Rs(Rt.testName),Ke(null),Ue.current=F.requestId,Pt.current={requestId:F.requestId,lastSeq:0},Fe.current.add(F.requestId),ks(F.requestId),xe(!0),st(!0),U("generating");const Na=new Set(bt.pendingPermissionIds);for(const ss of bt.events)if(!(ss.type==="ai-fix-permission"&&!Na.has(String(ss.permissionId)))){ss.type==="ai-fix-done"&&await de();try{Dt.current(ss)}catch{}}await de()}const tt=((Ht=Qt.current)==null?void 0:Ht.queue)??[];Qt.current=null;for(const F of tt)try{Dt.current(F)}catch{}},va=async()=>{var P;let n;try{n=await cr()}catch{return!1}const i=Bt(),c=n.runs.filter(u=>u.kind==="record-mobile"&&!u.saved&&!!u.sessionId&&(u.clientId===i||!u.tabOpen)).sort((u,I)=>I.startedAt-u.startedAt)[0];if(!(c!=null&&c.sessionId)||c.clientId&&c.clientId!==i&&await((P=ye==null?void 0:ye.adoptClientId)==null?void 0:P.call(ye,c.clientId).catch(()=>null))!==c.clientId&&c.status==="running")return!1;try{const u=(await zr(c.sessionId)).recording;return u?(await ts(u),await gt(u),!0):!1}catch{return!1}},wa=async()=>{var n;try{const i=await cr(),c=Bt(),P=(i.recordings??[]).find(u=>u.kind==="record-mobile"&&!u.tabOpen&&u.clientId!==c);P&&await((n=ye==null?void 0:ye.adoptClientId)==null?void 0:n.call(ye,P.clientId).catch(()=>null))}catch{}};ke.current=()=>t==null?void 0:t(H,{actionCount:G.length,durationMs:le.current,paused:ne,assertMode:oe,annotateMode:b}),s.useEffect(()=>{t==null||t(H,{actionCount:G.length,durationMs:le.current,paused:ne,assertMode:oe,annotateMode:b})},[H,G.length,ne,oe,b,t]),s.useEffect(()=>{o&&o({stop:Sr,pause:Ds,resume:Nr,reset:V,generate:J,addMoreSteps:rr,toggleAssert:nr,toggleAnnotate:qt,openHistory:()=>ft(!0)})},[Sr,Ds,Nr,V,J,rr,nr,qt,o]);const Fs=d.find(n=>n.id===l),Tr=!(Fs!=null&&Fs.hasCredentials);if(H==="setup"||H==="starting")return e.jsxs("div",{className:"relative h-full overflow-y-auto bg-white dark:bg-transparent",children:[e.jsx(en,{open:yr,onClose:()=>ft(!1),onLoad:St}),Te&&e.jsx(tn,{screenshot:Te.screenshot,screenshotSize:Te.screenshotSize,elementRect:Te.elementRect,step:Te.step,description:Te.description,onClose:()=>_t(null)}),e.jsxs("div",{className:"max-w-5xl mx-auto mt-8 space-y-6 px-4 pb-12",children:[h&&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(Mr,{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:et,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(Os,{size:12})," Resume Draft"]}),e.jsx("button",{onClick:es,className:"p-1.5 rounded-lg text-gray-500 hover:text-red-400 hover:bg-red-500/10",title:"Discard draft",children:e.jsx(Ks,{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(vt,{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(Hn,{value:l,onChange:n=>S(n),options:d.map(n=>({value:n.id,label:`${n.displayName}${n.hasCredentials?"":" (no credentials)"}`,disabled:!n.hasCredentials}))}),Tr&&e.jsxs("p",{className:"text-[12px] text-amber-300 flex items-center gap-1",children:[e.jsx(Hs,{size:11}),"Add credentials in Connectors → ",(Fs==null?void 0:Fs.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(Xo,{devices:y,selectedId:x,onSelect:n=>C(n.id),loading:B,disabled:Tr,onRefresh:()=>void Ms(l),placeholder:Tr?"(add creds in Connectors)":"Pick device",emptyText:l==="local-appium"?Jo: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(Hn,{value:z,onChange:D,placeholder:L.length===0?"No apps uploaded yet":"Pick app",options:L.map(n=>({value:n.id,label:`${n.label||n.filename} · ${n.kind.toUpperCase()} · ${(n.size/1024/1024).toFixed(1)} MB`}))}),e.jsxs("button",{type:"button",onClick:()=>{var n;return(n=Y.current)==null?void 0:n.click()},disabled:ie,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(oa,{size:13})," Upload"]}),e.jsx("input",{ref:Y,type:"file",accept:".apk,.aab,.ipa,.zip,application/vnd.android.package-archive,application/zip,application/octet-stream",hidden:!0,onChange:n=>{var c;const i=(c=n.target.files)==null?void 0:c[0];i&&Kr(i),n.target.value=""}})]}),q!==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(q*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 ${w?"bg-emerald-400":"bg-gray-600"}`}),w?`Session is running on ${w.device} — recording will reuse it`:"A new mobile session will be launched for recording"]}),e.jsxs("button",{onClick:kr,disabled:ie||H==="starting"||Tr||!x||!z,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:[H==="starting"?e.jsx(je,{size:18,className:"animate-spin"}):e.jsx(vt,{size:18,className:"fill-red-400 text-red-400"}),"Start Recording"]}),(Ae||Ft)&&e.jsxs("div",{className:`text-[12px] flex items-start gap-1.5 ${Ae?"text-red-300":"text-gray-400"}`,children:[Ae?e.jsx(Hs,{size:12,className:"mt-0.5 flex-shrink-0"}):e.jsx(yt,{size:12,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:Ae||Ft})]})]})]})]});if(H==="recording"||H==="stopped"||H==="generating"){const n=H==="recording"||H==="stopped";return e.jsxs("div",{className:"relative h-full flex flex-col bg-white dark:bg-transparent",children:[e.jsx(en,{open:yr,onClose:()=>ft(!1),onLoad:St}),br&&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:i=>i.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(Os,{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:[G.length," step",G.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(wt,{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 Rr(!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(Fr,{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 Rr(!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(on,{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(ma,{open:!!Ce,mode:(Ce==null?void 0:Ce.mode)||"add",initial:Ce==null?void 0:Ce.initial,replaceCount:qe.size,onCancel:()=>_e(null),onSave:Vr}),Te&&e.jsx(tn,{screenshot:Te.screenshot,screenshotSize:Te.screenshotSize,elementRect:Te.elementRect,step:Te.step,description:Te.description,onClose:()=>_t(null)}),H==="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:oe?e.jsxs(e.Fragment,{children:[e.jsx(Gs,{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)"})]}):b?e.jsxs(e.Fragment,{children:[e.jsx(dr,{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(on,{size:13,className:"text-indigo-400"}),e.jsx("span",{className:"text-gray-400",children:ne?"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."})]})}),H==="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:()=>ft(!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(Lr,{size:16})}),ze&&!ie?e.jsxs(e.Fragment,{children:[e.jsx(as,{size:14,className:"text-amber-400"}),e.jsxs("span",{className:"text-sm font-semibold text-amber-300",children:["Waiting for your input",kt?` — ${kt}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{size:14,className:"animate-spin text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-brand-300",children:"Generating Code…"})]})]}),H==="generating"?e.jsx(Fn,{entries:mt,busy:ie,onOpenScreenshot:i=>_t(i)}):e.jsxs("div",{ref:Ps,onScroll:Br,className:"flex-1 overflow-y-auto p-3 space-y-0.5",children:[G.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."}):G.map((i,c)=>{var P;return e.jsxs("div",{children:[H==="stopped"&&c===0&&e.jsx(_n,{label:"Insert a custom step before step 1",onInsert:()=>_e({mode:"add",afterIndex:null})}),e.jsx(ji,{action:i,stepNum:c+1,selectable:H==="stopped"&&i.type!=="custom",selected:qe.has(i.index),anySelected:qe.size>0,onToggleSelect:()=>Ve(u=>{const I=new Set(u);return I.has(i.index)?I.delete(i.index):I.add(i.index),I}),onEditCustom:()=>_e({mode:"edit",editIndex:i.index,initial:{instruction:i.instruction||i.description,customKind:i.customKind,references:i.references,outputs:i.outputs}}),onRestore:H==="stopped"&&((P=i.replaces)!=null&&P.length)?()=>void Yr(i.index):void 0,valuePicker:n&&i.type==="type"&&!i.secretEnv?e.jsx(fa,{current:i.valueFrom,options:p.get(i.index)||[],onPick:u=>void ir(i.index,u)}):null,playbackStatus:gr[i.index],canMutate:n,isEditing:ot===i.index,editingDescription:Xt,onEditChange:it,onStartEdit:()=>Gr(i),onSaveEdit:()=>void Wr(),onCancelEdit:()=>ps(null),onDelete:()=>void Ur(i.index),isDragging:wr===c,isDropTarget:$s===c,dropPosition:ms,wasJustDropped:tr===i.index,onDragStart:k(c),onDragOver:v(c),onDragLeave:g(c),onDrop:T(c),onDragEnd:Z,onOpenScreenshot:()=>{i.screenshot&&_t({screenshot:i.screenshot,screenshotSize:i.screenshotSize,elementRect:i.elementRect,step:c+1,description:i.description})}}),H==="stopped"&&e.jsx(_n,{label:`Insert a custom step after step ${c+1}`,onInsert:()=>_e({mode:"add",afterIndex:i.index})})]},i.index)}),n&&e.jsx("div",{className:"pt-2",children:e.jsxs("button",{type:"button",onClick:()=>_e({mode:"add"}),disabled:ie,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(Kt,{size:12})," Add custom step"]})})]}),H==="recording"&&e.jsx("div",{className:"border-t border-white/[0.05] bg-surface-1",children:b?e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2",children:[e.jsx(Or,{size:12,className:"text-purple-400"}),e.jsx("input",{type:"text",value:us,onChange:i=>Ts(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),or())},disabled:ie,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:or,disabled:ie||!us.trim(),className:"p-1.5 rounded text-purple-300 hover:text-purple-200 hover:bg-purple-500/10 disabled:opacity-40",children:e.jsx(lr,{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:We,onChange:i=>Cs(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),Cr())},disabled:ie||ne,placeholder:ne?"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:Cr,disabled:ie||ne||!We.trim(),className:"p-1.5 rounded text-red-300 hover:text-red-200 hover:bg-red-500/10 disabled:opacity-40",children:ie?e.jsx(je,{size:12,className:"animate-spin"}):e.jsx(lr,{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(_s,{label:"Enter",hint:"↵",onClick:()=>Jt("enter"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Back",hint:"←",onClick:()=>Jt("back"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Home",hint:"⌂",onClick:()=>Jt("home"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Vol +",hint:"🔊",onClick:()=>Jt("volume_up"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Vol −",hint:"🔉",onClick:()=>Jt("volume_down"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Power",hint:"⏻",onClick:()=>Jt("power"),disabled:ie,paused:ne})]})]})}),H==="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),He(""),bs(""),ls("")},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${we?"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 ${we?"bg-indigo-500/15 text-indigo-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:"Add to Existing Test"})]}),we&&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(qn,{active:Ie==="auto",onClick:()=>Oe("auto"),children:"Guide AI"}),e.jsx(qn,{active:Ie==="append",onClick:()=>Oe("append"),children:"Append At End"})]})]}),!we&&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:Ye,onChange:i=>is(i.target.value),placeholder:"Test name (e.g. login-flow-test)",disabled:ie,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"}),qr(Ye)&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400/90",children:qr(Ye)})]}),we&&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(Ni,{selectedFile:be,selectedTest:Ne,open:dt,setOpen:Gt,search:ut,setSearch:Wt,expanded:At,setExpanded:Vt,suites:(Me==null?void 0:Me.suites)??[],loading:!Me,onPick:(i,c)=>{He(i),bs(c),Gt(!1),Wt("")}})]}),Ie==="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:"*"}),Ne?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"})]}),Ne?e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:Ys,value:$e,onChange:i=>{ls(i.target.value);const c=i.target;c.style.height="auto",c.style.height=`${c.scrollHeight}px`},onKeyUp:i=>{const c=i.currentTarget,P=c.value,u=c.selectionStart??P.length,I=P.slice(0,u),O=I.lastIndexOf("@");if(O>=0&&(O===0||I[O-1]===" "||I[O-1]===`
13
- `)){const de=I.slice(O+1);if(!de.includes("]")){js(de.toLowerCase()),Be(!0);return}}Be(!1)},onKeyDown:i=>{i.key==="Escape"&&pt&&(i.preventDefault(),Be(!1))},placeholder:'e.g., Insert after @[#3 tap "Settings"] and add cart validation...',rows:1,disabled:ie,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:$e.split(`
14
- `).length>2||$e.length>100?"auto":"hidden"}}),pt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>Be(!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 i=Ze.filter(c=>!xt||c.keyword.toLowerCase().includes(xt)||c.name.toLowerCase().includes(xt));return Ze.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"}):i.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No matching steps"}):i.map((c,P)=>e.jsxs("button",{onClick:()=>{const u=Ys.current;if(!u)return;const I=u.selectionStart||0,O=$e.slice(0,I),de=O.lastIndexOf("@"),tt=$e.slice(I),fs=`@[${c.keyword} ${c.name}]`,Ht=O.slice(0,de)+fs+" "+tt;ls(Ht),Be(!1),setTimeout(()=>{u.focus();const F=de+fs.length+1;u.setSelectionRange(F,F)},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:c.keyword}),e.jsx("span",{className:"text-gray-300 truncate",children:c.name})]},`${c.keyword}-${P}`))})()})]})]}):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"})]})]})]}),qe.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:[qe.size," step",qe.size===1?"":"s"," selected"]}),e.jsxs("button",{type:"button",onClick:()=>_e({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(Kt,{size:12})," Replace with custom step"]}),e.jsx("button",{type:"button",onClick:()=>Ve(new Set),className:"px-2 py-1 rounded-md text-xs text-gray-400 hover:text-gray-200",children:"Clear"})]}),e.jsx(ha,{settings:Nt,onChange:a,inputs:G.filter(i=>i.type==="type"&&!i.secretEnv).map(i=>({id:String(i.index),value:i.text,valueFrom:i.valueFrom})),onMatch:i=>{for(const c of i)ir(Number(c.id),c.valueFrom)},disabled:ie}),e.jsxs("div",{className:"flex items-center gap-2",children:[yi,rt==="testver"&&e.jsx(cn,{refreshSignal:Ut}),e.jsx(dn,{providerModels:vs,selectedProvider:rt,selectedModel:Qe,onPick:ws}),e.jsxs("button",{onClick:Ee,disabled:Zt,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 ${we?"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:[Ut?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(pr,{size:14}),we?"Merge & Generate":"Generate Test Code"]})]})]}),H==="generating"&&at&&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(ln,{pending:at,queuedCount:Yt.current.length,onAllow:()=>ae(!0,!1),onAlwaysAllow:()=>ae(!0,!0),onDeny:()=>ae(!1,!1)})})}),H==="generating"&&e.jsxs("div",{className:"sticky bottom-0 border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[ie&&e.jsx("div",{className:"flex items-center pl-1 pb-3",children:e.jsx(la,{})}),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:nt,onChange:i=>{cs(i.target.value);const c=i.target;c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight,120)}px`},onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),!ie&&(nt.trim()||ze)&&E())},placeholder:ie?"AI is working... click stop to cancel":ze?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:ie,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:ie?e.jsx("button",{onClick:fe,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(lt,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:E,disabled:!nt.trim()&&!ze,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(lr,{size:14})})})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:ie?"Click the stop button to cancel the current generation":ze?"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"})]}),(Ae||Ft)&&H!=="generating"&&e.jsxs("div",{className:`px-3 py-1.5 border-t border-white/[0.05] text-[11px] flex items-center gap-1.5 ${Ae?"text-red-300":"text-gray-500"}`,children:[Ae?e.jsx(Hs,{size:11}):e.jsx(yt,{size:11}),Ae||Ft]})]})}const Qr=mt.length>0,Ls=ze?{icon:as,color:"amber",label:"Waiting for your input"}:Xs==="failed"?{icon:Us,color:"red",label:"Generation Failed"}:Xs==="stopped"?{icon:lt,color:"gray",label:"Stopped"}:{icon:yt,color:"emerald",label:"Code Generated"},ja=Ls.icon,ka=kt?` — ${kt}`:"";return e.jsxs("div",{className:"relative h-full flex flex-col bg-white dark:bg-transparent",children:[e.jsx(en,{open:yr,onClose:()=>ft(!1),onLoad:St}),Te&&e.jsx(tn,{screenshot:Te.screenshot,screenshotSize:Te.screenshotSize,elementRect:Te.elementRect,step:Te.step,description:Te.description,onClose:()=>_t(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:()=>ft(!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(Lr,{size:16})}),e.jsx(ja,{size:16,className:`text-${Ls.color}-400 ${Ls.color==="gray"?"fill-gray-400":""}`,strokeWidth:Ls.color==="gray"?0:2}),e.jsxs("span",{className:`text-sm font-semibold text-${Ls.color}-300`,children:[Ls.label,ka]}),e.jsx("span",{className:"text-[12px] text-gray-500",children:"·"}),e.jsxs("span",{className:"text-[12px] text-gray-400",children:[G.length," steps"]}),e.jsx("div",{className:"flex-1"}),(ve==null?void 0:ve.specSource)&&e.jsxs("button",{onClick:async()=>{ve!=null&&ve.specSource&&await navigator.clipboard.writeText(ve.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(Do,{size:12})," Copy spec"]}),e.jsxs("button",{onClick:V,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(Fr,{size:12})," New Recording"]})]}),ve&&ve.specPath&&ve.specPath!=="(see AI Assistant tab for written files)"&&ve.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(Mr,{size:13,className:"mt-0.5 text-indigo-400 flex-shrink-0"}),e.jsx("code",{className:"break-all",children:ve.specPath})]}),ve.healingPath&&ve.healingPath!=="(see AI Assistant tab for written files)"&&e.jsxs("div",{className:"flex items-start gap-2 text-gray-400",children:[e.jsx(Mr,{size:13,className:"mt-0.5 opacity-60 flex-shrink-0"}),e.jsx("code",{className:"break-all opacity-80",children:ve.healingPath})]})]}),Qr?e.jsx(Fn,{entries:mt,busy:ie,onOpenScreenshot:n=>_t(n)}):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:(ve==null?void 0:ve.specSource)??"(empty)"})}),Qr&&at&&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(ln,{pending:at,queuedCount:Yt.current.length,onAllow:()=>ae(!0,!1),onAlwaysAllow:()=>ae(!0,!0),onDeny:()=>ae(!1,!1)})})}),Qr&&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:nt,onChange:n=>{cs(n.target.value);const i=n.target;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight,120)}px`},onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),!ie&&(nt.trim()||ze)&&E())},placeholder:ie?"AI is working... click stop to cancel":ze?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:ie,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:ie?e.jsx("button",{onClick:fe,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(lt,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:E,disabled:!nt.trim()&&!ze,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(lr,{size:14})})})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:ie?"Click the stop button to cancel the current generation":ze?"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 wi={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 _n({onInsert:t,label:o}){return e.jsx("div",{className:"group/ins relative h-2 flex items-center",children:e.jsxs("button",{type:"button",onClick:t,"aria-label":o,title:o,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(fr,{size:10})," Custom step"]}),e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"})]})})}function ji({action:t,stepNum:o,canMutate:m,isEditing:d,editingDescription:N,onEditChange:l,onStartEdit:S,onSaveEdit:y,onCancelEdit:$,onDelete:L,isDragging:_,isDropTarget:x,dropPosition:C,wasJustDropped:z,onDragStart:D,onDragOver:B,onDragLeave:K,onDrop:q,onDragEnd:te,onOpenScreenshot:Y,playbackStatus:H,selectable:U=!1,selected:w=!1,anySelected:Q=!1,onToggleSelect:G,onEditCustom:ee,onRestore:ne,valuePicker:ue}){var A,R,W;const oe=wi[t.type]||"border-l-gray-500",pe=t.type==="tap"?Dr:t.type==="type"?Bs:t.type==="swipe"?mn:t.type==="assertion"?Gs:t.type==="annotation"?Or:t.type==="custom"?Kt:fn,b=t.type==="custom";return e.jsxs("div",{draggable:m,onDragStart:D,onDragOver:B,onDragLeave:K,onDrop:q,onDragEnd:te,className:`relative flex items-center gap-2.5 px-3 py-2 rounded-r-lg border-l-[3px] ${oe}
15
- hover:bg-black/[0.04] dark:hover:bg-white/[0.06]
16
- group transition-all duration-500
17
- ${H==="running"?"ring-2 ring-brand-400/70 bg-brand-500/[0.10] shadow-[0_0_16px_rgba(99,102,241,0.35)]":""}
18
- ${H==="done"?"bg-emerald-500/[0.07]":""}
19
- ${H==="error"?"bg-red-500/[0.08] ring-1 ring-red-500/40":""}
20
- ${_?"opacity-50 ring-2 ring-blue-400/60 shadow-[0_0_18px_rgba(96,165,250,0.45)] bg-blue-500/[0.06]":""}
21
- ${z?"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
- ${m?"cursor-grab active:cursor-grabbing":""}`,children:[x&&!_&&C==="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"})}),x&&!_&&C==="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"})}),U&&e.jsx("input",{type:"checkbox",checked:w,onChange:()=>G==null?void 0:G(),onMouseDown:le=>le.stopPropagation(),"aria-label":`Select step ${o} (to replace it with a custom step)`,title:"Select to replace with a custom step",className:`flex-shrink-0 cursor-pointer accent-indigo-500 ${Q||w?"opacity-100":"opacity-0 group-hover:opacity-100 focus:opacity-100"}`}),m&&e.jsx(Fo,{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:o}),e.jsx(ki,{action:t,onOpen:Y,Fallback:pe}),e.jsx("div",{className:"flex-1 min-w-0",children:d?e.jsx("input",{type:"text",value:N,autoFocus:!0,onChange:le=>l(le.target.value),onKeyDown:le=>{le.key==="Enter"&&(le.preventDefault(),y()),le.key==="Escape"&&(le.preventDefault(),$())},onBlur:y,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:[b&&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:b?t.instruction:void 0,children:b&&t.instruction||t.description})]}),(b||t.valueFrom)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-0.5",children:[b&&!!((A=t.references)!=null&&A.length)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-gray-500",title:t.references.map(le=>le.label).join(`
23
- `),children:[e.jsx(Hr,{kind:t.references[0].kind,size:11}),t.references.length>1?`${t.references.length} refs`:t.references[0].label]}),b&&((R=t.outputs)==null?void 0:R.map(le=>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:`→ {${le}}`},le))),b&&!!((W=t.replaces)!=null&&W.length)&&e.jsxs("span",{className:"text-[10px] text-gray-500",title:t.replaces.map(le=>le.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})]})]})}),m&&!d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-0 group-hover:opacity-100 focus-within:opacity-100",children:ue}),ne&&e.jsx("button",{type:"button",onClick:ne,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(ia,{size:12})}),e.jsx("button",{type:"button",onClick:b&&ee?ee:S,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:b?"Edit custom step":"Edit description","aria-label":b?"Edit custom step":"Edit description",children:e.jsx(Lo,{size:12})}),e.jsx("button",{type:"button",onClick:L,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(Ks,{size:12})})]})]})}function ki({action:t,onOpen:o,Fallback:m}){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(m,{size:16,className:"text-gray-400"})});let l,S=null;const y=t.screenshotSize,$=t.elementRect;if(y&&$&&$.width>0&&$.height>0){const L=$.height,x=Math.min(4,64*.65/Math.max(20,L)),C=y.width*x,z=y.height*x,D=($.x+$.width/2)*x,B=($.y+$.height/2)*x,K=48/2-D,q=64/2-B;l={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${C}px ${z}px`,backgroundPosition:`${K}px ${q}px`,backgroundRepeat:"no-repeat",backgroundColor:"#000"},S={left:$.x*x+K,top:$.y*x+q,width:$.width*x,height:$.height*x}}else if(y){const L=Math.min(48/y.width,64/y.height),_=y.width*L,x=y.height*L;l={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${_}px ${x}px`,backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundColor:"#000"}}else l={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#000"};return e.jsxs("button",{type:"button",onClick:L=>{L.stopPropagation(),o()},onMouseDown:L=>L.stopPropagation(),onDragStart:L=>{L.preventDefault(),L.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:l}),S&&e.jsx("div",{className:"absolute pointer-events-none border-[2px] border-red-400 rounded-[2px]",style:{...S,boxShadow:"0 0 0 1px rgba(255,255,255,0.4), 0 0 6px rgba(239,68,68,0.6)"}})]})}function _s({label:t,hint:o,onClick:m,disabled:d,paused:N}){return e.jsxs("button",{type:"button",onClick:m,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:N?`Press ${t} (not recorded while paused)`:`Record ${t} key press`,children:[o&&e.jsx("span",{className:"text-gray-500",children:o}),e.jsx("span",{children:t})]})}function qn({active:t,onClick:o,children:m}){return e.jsxs("label",{onClick:o,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:o,className:"hidden"}),m]})}function Ni({selectedFile:t,selectedTest:o,open:m,setOpen:d,search:N,setSearch:l,expanded:S,setExpanded:y,suites:$,loading:L,onPick:_}){const x=N.toLowerCase().trim(),C=s.useMemo(()=>x?$.filter(z=>ns(z.name,x)||z.file.toLowerCase().includes(x)||z.tests.some(D=>ns(D.name,x))):$,[$,x]);return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>d(!m),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:o?e.jsxs("div",{title:o,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:qs(o)}),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…"})}),m&&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:N,onChange:z=>l(z.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:[L&&C.length===0&&e.jsxs("div",{className:"flex items-center justify-center py-4 text-[11px] text-gray-500 gap-1.5",children:[e.jsx(je,{size:11,className:"animate-spin"})," Loading tests…"]}),!L&&C.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."]}),C.map(z=>{const D=z.file,B=S.has(D)||!!x,K=x?z.tests.filter(te=>ns(te.name,x)||ns(z.name,x)):z.tests,q=()=>y(te=>{const Y=new Set(te);return Y.has(D)?Y.delete(D):Y.add(D),Y});return e.jsxs("div",{children:[e.jsxs("button",{onClick:q,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(hs,{size:11,className:`text-gray-500 transition-transform ${B?"":"-rotate-90"}`}),e.jsx("span",{className:"text-gray-300 font-medium truncate",title:z.name,children:qs(z.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:z.tests.length})]}),B&&K.map((te,Y)=>{const H=t===z.file&&o===te.name;return e.jsx("button",{onClick:()=>_(z.file,te.name),className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${H?"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:te.name,children:qs(te.name)})},Y)})]},D)})]})]})]})]})}function Hn({value:t,onChange:o,options:m,placeholder:d,disabled:N,dense:l}){return e.jsxs("div",{className:`relative ${l?"":"flex-1"}`,children:[e.jsxs("select",{value:t,onChange:S=>o(S.target.value),disabled:N,className:`appearance-none bg-surface-2 border border-white/5 rounded-lg ${l?"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}),m.map(S=>e.jsx("option",{value:S.value,disabled:S.disabled,children:S.label},S.value))]}),e.jsx(hs,{size:l?11:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none"})]})}function ga(t,o){const[m,d]=s.useState(!1);return s.useEffect(()=>{const N=t.current;if(!N||typeof ResizeObserver>"u")return;const l=()=>d(N.getBoundingClientRect().width<o);l();const S=new ResizeObserver(l);return S.observe(N),()=>S.disconnect()},[t,o]),m}function Si(t){const o=Math.floor(t/1e3),m=Math.floor(o/60).toString().padStart(2,"0"),d=(o%60).toString().padStart(2,"0");return`${m}:${d}`}function Ri({recorderMode:t,setRecorderMode:o}){const m=Jn(),[d,N]=s.useState("setup"),[l,S]=s.useState(0),[y,$]=s.useState(0),[L,_]=s.useState(!1),[x,C]=s.useState(!1),[z,D]=s.useState(!1),B=s.useRef(null),K=s.useRef(null),q=ga(K,640),[te,Y]=s.useState(!1),H=s.useCallback((pe,b)=>{N(pe),S(b.actionCount),$(b.durationMs),_(b.paused),C(b.assertMode),D(b.annotateMode)},[]),U=s.useCallback(pe=>{B.current=pe},[]),w=()=>{B.current&&(L?(B.current.resume(),_(!1)):(B.current.pause(),_(!0)))},Q=pe=>async()=>{if(B.current){Y(!0);try{await pe()}finally{Y(!1)}}},G=Q(()=>B.current.stop()),ee=Q(()=>B.current.reset()),ne=Q(()=>B.current.addMoreSteps()),ue=Q(()=>B.current.toggleAssert()),oe=Q(()=>B.current.toggleAnnotate());return e.jsx(Uo,{children:e.jsxs("div",{className:"h-full flex flex-col relative",children:[d!=="generating"&&d!=="done"&&e.jsx("div",{ref:K,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 pe;return(pe=B.current)==null?void 0:pe.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(Lr,{size:16})}),d==="recording"?e.jsxs(e.Fragment,{children:[L?e.jsxs(e.Fragment,{children:[e.jsx(_r,{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:Si(y)}),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:l})]}):d==="starting"?e.jsxs(e.Fragment,{children:[e.jsx(je,{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(lt,{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:[l," action",l!==1?"s":""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(vt,{size:14,className:"text-gray-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Mobile Recorder"})]}),m.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(ua,{value:t,onChange:o,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:[!L&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:x?"Exit assertion mode":"Add an assertion",hint:x?void 0:"Tap an element on the device to check it, instead of tapping it",children:e.jsxs("button",{"aria-label":x?"Exit assertion mode":"Add an assertion",onClick:ue,disabled:te,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${x?"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(Gs,{size:14}),x&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:z?"Exit annotate mode":"Annotate a step",hint:z?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":z?"Exit annotate mode":"Annotate a step",onClick:oe,disabled:te,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${z?"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(dr,{size:14}),z&&e.jsx("span",{children:"ON"})]})})]}),e.jsx(Ct,{label:L?"Resume recording":"Pause recording",hint:L?"Your taps are recorded again":"Use the device freely — nothing is recorded until you resume",children:e.jsx("button",{onClick:w,"aria-label":L?"Resume recording":"Pause recording",className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${L?"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:L?e.jsx(Os,{size:14}):e.jsx(_r,{size:14})})}),e.jsx(Ct,{label:"Stop recording",hint:"Then review the steps and generate the test",children:e.jsx("button",{onClick:G,disabled:te,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:te?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(lt,{size:14})})})]}),d==="stopped"&&e.jsxs(e.Fragment,{children:[e.jsx(ur,{tone:"brand",compact:q,icon:e.jsx(fr,{size:13}),label:"Add More Steps",hint:"Continue recording — add more steps to this recording",disabled:te,onClick:ne}),e.jsx(ur,{compact:q,icon:e.jsx(Fr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",disabled:te,onClick:ee})]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto transition-all duration-200",children:e.jsx(vi,{onPhaseChange:H,registerControls:U})})]})})}const Ci=!1,Ti={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"},$i=new Set(["annotate","assert","hover","dialog","custom"]),On=new Set(["fill","type","select","navigate"]);function Ai(t){const o=Math.floor(t/60),m=t%60;return`${o}:${m.toString().padStart(2,"0")}`}function rn({type:t,size:o=12}){const m={click:e.jsx(Dr,{size:o,className:"text-blue-400"}),dblclick:e.jsx(Dr,{size:o,className:"text-blue-300"}),fill:e.jsx(Bs,{size:o,className:"text-emerald-400"}),type:e.jsx(Bs,{size:o,className:"text-emerald-400"}),press:e.jsx(Bo,{size:o,className:"text-amber-400"}),navigate:e.jsx(hn,{size:o,className:"text-purple-400"}),select:e.jsx(Oo,{size:o,className:"text-cyan-400"}),check:e.jsx(Ho,{size:o,className:"text-emerald-400"}),uncheck:e.jsx(lt,{size:o,className:"text-gray-400"}),hover:e.jsx(fn,{size:o,className:"text-purple-400"}),scroll:e.jsx(hs,{size:o,className:"text-gray-400"}),assert:e.jsx(Gs,{size:o,className:"text-green-400"}),annotate:e.jsx(qo,{size:o,className:"text-violet-400"}),upload:e.jsx(oa,{size:o,className:"text-teal-400"}),drag:e.jsx(mn,{size:o,className:"text-indigo-400"}),dialog:e.jsx(Or,{size:o,className:"text-orange-400"}),custom:e.jsx(Kt,{size:o,className:"text-indigo-500"})};return e.jsx(e.Fragment,{children:m[t]||e.jsx(vt,{size:o-2,className:"text-gray-500"})})}function rs(t,o){return{kind:"recorded-action",id:t.id||o(),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(m=>({id:m.id,type:m.type,description:m.description}))}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function ba(t){var o,m;return{...t.instruction?{instruction:t.instruction}:{},...t.customKind?{customKind:t.customKind}:{},...(o=t.references)!=null&&o.length?{references:t.references}:{},...(m=t.outputs)!=null&&m.length?{outputs:t.outputs}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function Bn(t){return t.filter(o=>o.kind==="recorded-action").map(o=>({id:o.id,type:o.actionType,description:o.description,selector:o.selector,value:o.value,url:o.url,timestamp:o.timestamp,assertType:o.assertType,expectedValue:o.expectedValue,screenshot:o.screenshot,elementRect:o.elementRect,...o.screenshotCrop?{screenshotCrop:o.screenshotCrop}:{},...ba(o)}))}function Ii(t){return t.map(o=>{switch(o.kind){case"recorded-action":return{kind:o.kind,id:o.id,actionType:o.actionType,description:o.description,selector:o.selector,value:o.value,url:o.url,timestamp:o.timestamp,assertType:o.assertType,expectedValue:o.expectedValue,elementRect:o.elementRect,...ba(o)};case"text":return{kind:o.kind,id:o.id,text:o.text};case"tool":return{kind:o.kind,id:o.id,phase:o.phase,toolName:o.toolName,args:o.args,result:o.result,error:o.error,startedAt:o.startedAt,endedAt:o.endedAt};case"file-diff":return{kind:o.kind,id:o.id,filePath:o.filePath,diffType:o.diffType,diff:o.diff,linesAdded:o.linesAdded,linesRemoved:o.linesRemoved,via:o.via,unavailable:o.unavailable,netNoChange:o.netNoChange,omitted:o.omitted};case"error":case"user":case"system":return{kind:o.kind,id:o.id,text:o.text};default:return{kind:o.kind,id:o.id}}})}function Ei(t,o){const m=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 N=m.get(d.id);return rs({...d,screenshot:d.screenshot||(N==null?void 0:N.screenshot),elementRect:d.elementRect||(N==null?void 0:N.elementRect),screenshotCrop:d.screenshot?d.screenshotCrop:N==null?void 0:N.screenshotCrop},o)}return d.kind==="text"?{kind:"text",id:d.id||o(),text:d.text||"",done:!0}:d.kind==="tool"?{kind:"tool",id:d.id||o(),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||o(),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||o(),text:d.text||""}:d.kind==="user"?{kind:"user",id:d.id||o(),text:d.text||""}:{kind:"system",id:d.id||o(),text:d.text||""}})}const zi=[/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 Mi(t,o){if(o==="failed"||o==="stopped")return o;let m=0;for(let d=t.length-1;d>=0;d--)if(t[d].kind==="user"){m=d+1;break}for(const d of t.slice(m))if(d.kind==="error"||d.kind==="text"&&d.text&&zi.some(N=>N.test(d.text)))return"failed";return"success"}function Pi(t,o,m){return!t||t.src!==o?!1:Math.abs(t.w-m.clipW)<=2&&Math.abs(t.h-m.clipH)<=2}function Kn(t,o){return new Promise(m=>{const d=new Image;d.onload=()=>{try{const N=document.createElement("canvas");N.width=o.clipW,N.height=o.clipH;const l=N.getContext("2d");if(!l){m(t);return}const S=d.naturalWidth/o.vpW,y=d.naturalHeight/o.vpH;l.drawImage(d,o.clipX*S,o.clipY*y,o.clipW*S,o.clipH*y,0,0,o.clipW,o.clipH),m(N.toDataURL("image/jpeg",.8))}catch{m(t)}},d.onerror=()=>m(t),d.src=t})}const Di=/\.(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 Un({onInsert:t,label:o}){return e.jsx("div",{className:"group/ins relative h-2 flex items-center",children:e.jsxs("button",{type:"button",onClick:t,"aria-label":o,title:o,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(fr,{size:10})," Custom step"]}),e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"})]})})}let Ot=null;const Fi=2e4,Li=/^(recorder-|ai-fix-|browser-(closed|launched)$)/;function _i(t,o){ya();const m={clientId:Bt(),state:t,buffer:[],overflow:!1,stop:null,replayed:!1};try{m.stop=o(d=>{if(Li.test(String((d==null?void 0:d.type)||""))){if(m.buffer.length>=Fi){m.overflow=!0;return}m.buffer.push(d)}})}catch{}Ot=m}function qi(){const t=Ot;if(!t)return null;const o=Bt();return t.clientId&&o&&t.clientId!==o?null:t}function ya(){var t;try{(t=Ot==null?void 0:Ot.stop)==null||t.call(Ot)}catch{}Ot=null}function Hi(){var ir;const{subscribe:t,send:o,adoptClientId:m}=Gn(),{toast:d}=un(),[N]=s.useState(qi),l=N==null?void 0:N.state,{data:S}=da(),[y,$]=s.useState((l==null?void 0:l.phase)??"setup"),L=s.useRef(y);L.current=y;const[_,x]=s.useState((l==null?void 0:l.timeline)??[]),C=s.useRef(_);C.current=_;const z=s.useMemo(()=>new Map(_.map((r,a)=>[r.id,a])),[_]),[D,B]=s.useState((l==null?void 0:l.startUrl)??""),K=(()=>{const r=D.trim();if(!/^https?:\/\//i.test(r))return!1;try{return!!new URL(r).hostname}catch{return!1}})(),[q,te]=s.useState((l==null?void 0:l.testName)??""),[Y,H]=s.useState((l==null?void 0:l.mergeMode)??!1),[U,w]=s.useState((l==null?void 0:l.targetTestFile)??""),[Q,G]=s.useState((l==null?void 0:l.targetTestName)??""),[ee,ne]=s.useState((l==null?void 0:l.insertPosition)??"auto"),[ue,oe]=s.useState(!1),[pe,b]=s.useState(""),[A,R]=s.useState(new Set),[W,le]=s.useState((l==null?void 0:l.userGuidance)??""),[ke,M]=s.useState((l==null?void 0:l.followUpPrompt)??""),[h,X]=s.useState((l==null?void 0:l.awaitingConfirmation)??!1),[j,ce]=s.useState((l==null?void 0:l.genOutcome)??null),[ct,gs]=s.useState(!1),[os,Ws]=s.useState(""),ve=s.useRef(null),[Tt,Ut]=s.useState([]),[st,we]=s.useState(!1);s.useEffect(()=>{if(!U||!Q){Ut([]);return}if(S!=null&&S.suites){const r=S.suites.find(a=>a.file===U||a.file.replace(/\\/g,"/")===U.replace(/\\/g,"/"));if(r){const a=r.tests.find(p=>p.name===Q);if(a!=null&&a.steps&&a.steps.length>0){Ut(a.steps.map(p=>({keyword:p.keyword,name:p.name})));return}}}we(!0),ro(async()=>{const{getTestSourceByName:r}=await import("./index-D6sQYc_0.js").then(a=>a.iK);return{getTestSourceByName:r}},__vite__mapDeps([0,1,2,3,4])).then(({getTestSourceByName:r})=>{r(U,Q).then(a=>{a!=null&&a.humanSteps&&a.humanSteps.length>0?Ut(a.humanSteps.map(p=>({keyword:p.keyword,name:p.name}))):Ut([])}).catch(()=>Ut([])).finally(()=>we(!1))})},[U,Q,S]);const[$t,Ye]=s.useState((l==null?void 0:l.elapsedTime)??0),[is,be]=s.useState((l==null?void 0:l.actionCount)??0),[He,Ie]=s.useState((l==null?void 0:l.isPaused)??!1),Oe=s.useRef((l==null?void 0:l.startTime)??0),$e=s.useRef((l==null?void 0:l.pausedAt)??0),[ls,Me]=s.useState((l==null?void 0:l.canAddSteps)??!0),dt=s.useRef((l==null?void 0:l.executed)??!1),Gt=s.useRef((l==null?void 0:l.lastSavedRun)??null),[ut,Wt]=s.useState((l==null?void 0:l.testSettings)??null),[Ne,bs]=s.useState(null),[At,Vt]=s.useState(new Set),ys=s.useRef(new Map),It=s.useRef(`draft-${Bt()||`local-${Math.random().toString(36).slice(2,10)}`}`),Vs=()=>{const r=Bt();return r&&!It.current.startsWith(`draft-${r}`)&&(It.current=`draft-${r}`),It.current},[Et,vs]=s.useState(!1),Qe=Jn(),[rt,ws]=s.useState(Qe.mode==="mobile"?"mobile":"web");s.useEffect(()=>{Qe.isLoading||(Qe.mode==="mobile"&&rt!=="mobile"?ws("mobile"):Qe.mode==="web"&&rt!=="web"&&ws("web"))},[Qe.mode,Qe.isLoading]);const[pt,Be]=s.useState((l==null?void 0:l.activeSessionId)??null),[xt,js]=s.useState(null),[Ys,mt]=s.useState(null),[me,Qs]=s.useState(null),ks=s.useRef(null),ze=ga(ks,640),[jt,hr]=s.useState(null),Xs=s.useRef(null),[Ke,nt]=s.useState(null),[cs,Ue]=s.useState(null),[zt,Js]=s.useState("below"),[ds,gr]=s.useState(null),Ns=s.useRef(0),[br,Mt]=s.useState(!1),[at,Ss]=s.useState(!1),[Yt,kt]=s.useState(null),[Rs,Zs]=s.useState(!1),[Pe,De]=s.useState((l==null?void 0:l.genLoading)??!1),[ye,Pt]=s.useState((l==null?void 0:l.playbackLoading)??!1),{providerModels:Qt,selectedProvider:Fe,selectedModel:Dt,select:er}=pa(l?{provider:l.selectedProvider,model:l.selectedModel}:void 0),Ge=s.useRef((l==null?void 0:l.streamText)??""),Ae=s.useRef((l==null?void 0:l.streamTextId)??null),se=s.useRef((l==null?void 0:l.loadedFromHistory)??!1),Ft=s.useRef((l==null?void 0:l.currentRequestId)??null),he=r=>{Ft.current=r},ie=s.useRef(null),xe=s.useRef(null),We=s.useRef(new Set((l==null?void 0:l.runIds)??[])),Cs=s.useRef(()=>{}),us=r=>{Xn(r).catch(()=>{})},Ts=()=>{for(const r of We.current)us(r);We.current=new Set},[ot,ps]=s.useState((l==null?void 0:l.pendingPermission)??null),Xt=s.useRef((l==null?void 0:l.permissionQueue)??[]),it=()=>{ps(null),Xt.current=[]},[yr]=s.useState(1),[ft,Xe]=s.useState((l==null?void 0:l.playbackIndex)??-1),[Lt,Le]=s.useState((l==null?void 0:l.playbackTotal)??0),[Se,Re]=s.useState((l==null?void 0:l.assertActive)??!1),[Ce,_e]=s.useState((l==null?void 0:l.annotateActive)??!1),qe=s.useRef(null),Ve=s.useRef(!0),Nt=s.useRef(0),re=()=>`rec-${Date.now().toString(36)}-${++Nt.current}`,xs=s.useRef({});xs.current={phase:y,timeline:_,startUrl:D,testName:q,mergeMode:Y,targetTestFile:U,targetTestName:Q,insertPosition:ee,userGuidance:W,followUpPrompt:ke,awaitingConfirmation:h,genOutcome:j,elapsedTime:$t,actionCount:is,isPaused:He,activeSessionId:pt,genLoading:Pe,pendingPermission:ot,assertActive:Se,annotateActive:Ce,canAddSteps:ls,selectedProvider:Fe,selectedModel:Dt,playbackLoading:ye,playbackIndex:ft,playbackTotal:Lt,testSettings:ut};const $s=s.useRef(t);$s.current=t,s.useEffect(()=>()=>{_i({...xs.current,currentRequestId:Ft.current,permissionQueue:Xt.current,streamText:Ge.current,streamTextId:Ae.current,loadedFromHistory:se.current,executed:dt.current,lastSavedRun:Gt.current,runIds:[...We.current],startTime:Oe.current,pausedAt:$e.current},$s.current)},[]),s.useEffect(()=>{const r=qe.current;r&&Ve.current&&(r.scrollTop=r.scrollHeight)},[_]);const As=()=>{const r=qe.current;r&&(Ve.current=r.scrollHeight-r.scrollTop-r.clientHeight<120)};s.useEffect(()=>{ot&&qe.current&&(Ve.current=!0,requestAnimationFrame(()=>{qe.current&&(qe.current.scrollTop=qe.current.scrollHeight)}))},[ot]),s.useEffect(()=>{var a;if(!me)return;(a=Xs.current)==null||a.focus();const r=p=>{p.key==="Escape"&&Qs(null)};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[me]),s.useEffect(()=>{no().then(r=>Mt(r.active)).catch(()=>Mt(!1))},[y]);const ms=async r=>{let a=[];try{a=(await oo()).actions||[]}catch{}const p=a.map(f=>rs(f,re));x([{kind:"system",id:re(),text:r.recording?"Recording in progress — picked up where you left off":"Recording restored"},...p]),be(r.actionCount??p.length),Ye(Math.floor((r.duration||0)/1e3)),r.startUrl&&B(r.startUrl),Wt(r.settings||null),r.sessionId&&Be(r.sessionId),r.recording?(Oe.current=Date.now()-(r.duration||0),$e.current=r.paused?Date.now():0,Ie(!!r.paused),$("recording")):(Me(r.canAddSteps!==!1),$("stopped"))};s.useEffect(()=>{if(N&&N.state.phase!=="setup")return;let r=!0;return(async()=>{var a;if(await Yn().catch(()=>null),!(r&&await jr())){try{const p=await Rn();r&&(p.recording||p.hasSession)&&await ms(p)}catch{}if(!(!r||L.current!=="setup"))for(const p of[Vs(),...ao().map(f=>`draft-${f}`),"draft-current"])try{const f=await an(p);if(f&&((a=f.actions)==null?void 0:a.length)>0){r&&js(f);break}}catch{}}})(),()=>{r=!1}},[]),s.useEffect(()=>{if(y!=="recording")return;if(Oe.current||(Oe.current=Date.now()),He){$e.current||($e.current=Date.now());return}$e.current&&(Oe.current+=Date.now()-$e.current,$e.current=0);const r=()=>Ye(Math.floor((Date.now()-Oe.current)/1e3));r();const a=setInterval(r,1e3);return()=>clearInterval(a)},[y,He]);const vr=s.useRef($t);vr.current=$t;const wr=s.useRef(D);wr.current=D,s.useEffect(()=>{if(y!=="recording")return;const r=setInterval(()=>{var k;const a=Bn(C.current);if(a.length===0)return;const p=((k=a.find(v=>v.type==="navigate"))==null?void 0:k.url)||wr.current||"";let f="recording";try{p&&(f=new URL(p).hostname)}catch{}Cn({id:Vs(),name:`Draft — ${f}`,url:p,status:"draft",actions:a,duration:vr.current*1e3}).catch(()=>{})},1e4);return()=>clearInterval(r)},[y]),s.useEffect(()=>{var T,Z;if(y!=="done"||h)return;const r=Mi(_,j);if(r!==j&&ce(r),se.current){se.current=!1;return}if(!dt.current)return;const a=Bn(_);if(a.length===0)return;const p=`${pt}:${_.length}:${(T=_[_.length-1])==null?void 0:T.id}`;if(Gt.current===p)return;Gt.current=p;const f=((Z=a.find(J=>J.type==="navigate"))==null?void 0:Z.url)||D||"",k=pt||`session-${Date.now()}`;let v="test";try{f&&(v=new URL(f).hostname)}catch{v="unknown"}const g=(Y&&Q?Q:"")||q||`Recording — ${v}`;Cn({id:k,name:g,rename:!!(Y&&Q||q),url:f,status:"generated",outcome:r,actionCount:a.length,actions:a,fullTimeline:Ii(_),duration:$t*1e3,settings:ut||null}).then(()=>{pt||Be(k);for(const J of We.current)us(J)}).catch(()=>{})},[y,h]);const Je=s.useCallback(()=>{if(Ge.current&&Ae.current){const r=Ae.current,a=Ge.current;x(p=>{const f=p.findIndex(k=>k.id===r);if(f>=0){const k=[...p];return k[f]={kind:"text",id:r,text:a,done:!0},k}return p})}Ge.current="",Ae.current=null},[]),tr=s.useRef(new Set);s.useEffect(()=>{for(const r of _){if(r.kind!=="recorded-action"||!r.screenshot||!r.screenshotCrop)continue;const a=`${r.id}:${r.screenshot.length}`;if(tr.current.has(a))continue;tr.current.add(a);const{id:p,screenshot:f,screenshotCrop:k}=r;Kn(f,k).then(v=>{tr.current.delete(a),v!==f&&x(g=>g.map(T=>{if(T.id!==p||T.kind!=="recorded-action"||T.screenshot!==f)return T;const{screenshotCrop:Z,...J}=T;return{...J,screenshot:v}}))})}},[_]),s.useEffect(()=>{var p;const r=f=>{if(f.type==="recorder-action"){const g=f.action,T=g.id||re();if(typeof T=="string"&&T.endsWith("-screenshot")){const Z=T.replace("-screenshot",""),J=ae=>x(fe=>fe.map(E=>E.id===Z&&E.kind==="recorded-action"?{...E,screenshot:ae,elementRect:g.elementRect}:E));g.screenshotCrop&&g.screenshot?Kn(g.screenshot,g.screenshotCrop).then(J):J(g.screenshot);return}if(typeof T=="string"&&T.endsWith("-update")){x(Z=>{const J=[...Z];for(let ae=J.length-1;ae>=0;ae--){const fe=J[ae];if(fe.kind==="recorded-action"&&fe.actionType==="fill"){J[ae]={...fe,description:g.description||fe.description,value:g.value??fe.value};break}}return J});return}x(Z=>[...Z,rs({...g,id:T},re)]),be(Z=>Z+1),g.type==="annotate"&&_e(!1),g.type==="assert"&&Re(!1);return}if(f.type==="recorder-annotate-mode"&&_e(!!f.active),f.type==="recorder-assert-mode"){Re(!!f.active);return}if(f.type==="browser-closed"){Mt(!1),L.current==="recording"&&(x(g=>[...g,{kind:"system",id:re(),text:"Browser closed — recording stopped"}]),$("stopped"),Re(!1),_e(!1)),Me(!1);return}if(f.type==="browser-launched"){Mt(!0);return}if(f.type==="recorder-status"){if(f.status==="recording")$("recording"),Ie(!1),Oe.current||(Oe.current=Date.now());else if(f.status==="paused")Ie(!0);else if(f.status==="stopped"){$("stopped"),Ie(!1);const g=f;g.sessionId&&Be(g.sessionId),typeof g.actionCount=="number"&&be(g.actionCount)}else f.status==="reset"&&($("setup"),x([]),be(0),Ye(0),it(),X(!1),ce(null),Be(null));return}if(f.type==="recorder-playback"){const g=f;g.status==="started"?($("playback"),Xe(0),Le(g.totalActions||0),x(T=>[...T,{kind:"system",id:re(),text:`Playback started — replaying ${g.totalActions} action(s)...`}])):g.status==="action"?(Xe(g.index+1),x(T=>[...T,{kind:"playback-action",id:re(),actionType:g.actionType||"action",description:g.description||`Action ${g.index+1}`,status:"done"}])):g.status==="action-error"?x(T=>[...T,{kind:"playback-action",id:re(),actionType:g.actionType||"action",description:g.description||`Action ${g.index+1}`,status:"error"}]):g.status==="done"?($("stopped"),Pt(!1),x(T=>[...T,{kind:"system",id:re(),text:`Playback complete — ${g.replayed||0} of ${g.total||0} actions replayed${g.errors?` (${g.errors} errors)`:""}`}])):g.status==="error"&&($("stopped"),Pt(!1),x(T=>[...T,{kind:"error",id:re(),text:`Playback failed: ${g.error||"Unknown error"}`}]));return}const k=f.requestId;if(!k||k!==Ft.current)return;const v=f.runSeq;if(typeof v=="number"){const g=ie.current;if(g&&g.requestId===k){if(v<=g.lastSeq)return;g.lastSeq=v}else ie.current={requestId:k,lastSeq:v}}if(f.type==="ai-fix-stopped"){Je(),he(null),it(),X(!1),$("done"),De(!1),ce("stopped"),x(g=>[...g,{kind:"system",id:re(),text:"Generation stopped by user"}]);return}if(f.type==="ai-fix-stream"){const g=f.content;if(Ae.current){Ge.current+=g;const T=Ae.current,Z=Ge.current;x(J=>{const ae=J.findIndex(fe=>fe.id===T);if(ae>=0){const fe=[...J];return fe[ae]={kind:"text",id:T,text:Z},fe}return J})}else{const T=re();Ae.current=T,Ge.current=g,x(Z=>[...Z,{kind:"text",id:T,text:g}])}}else if(f.type==="ai-fix-tool"){const g=f,T=`${g.toolName}::${g.args||""}`;g.phase==="start"?(Je(),x(Z=>[...Z,{kind:"tool",id:re(),toolId:T,phase:"start",toolName:g.toolName,args:g.args||"",startedAt:Date.now()}])):x(Z=>{const J=[...Z].reverse().findIndex(ae=>ae.kind==="tool"&&ae.toolId===T&&ae.phase==="start");if(J>=0){const ae=Z.length-1-J,fe=[...Z];return fe[ae]={...fe[ae],phase:g.phase,result:g.result,error:g.error,endedAt:Date.now()},fe}return[...Z,{kind:"tool",id:re(),toolId:T,phase:g.phase,toolName:g.toolName,args:g.args||"",result:g.result,error:g.error}]})}else if(f.type==="ai-fix-file-diff"){const g=f;Je(),x(T=>[...T,{kind:"file-diff",id:re(),filePath:g.filePath,diffType:g.diffType,diff:g.diff,linesAdded:g.linesAdded,linesRemoved:g.linesRemoved,via:g.via==="detected"?"detected":void 0,unavailable:g.unavailable,netNoChange:g.netNoChange===!0||void 0}])}else if(f.type==="ai-fix-file-changes-omitted"){const g=f;x(T=>[...T,{kind:"file-diff",id:re(),filePath:"",diffType:"modified",diff:"",via:"detected",omitted:{count:Number(g.count)||0,examples:Array.isArray(g.examples)?g.examples:[]}}])}else if(f.type==="ai-fix-permission"){const g=f,T={permissionId:g.permissionId,toolName:g.toolName,args:g.args||"",fullPath:g.fullPath||void 0};Je(),ps(Z=>Z?(Xt.current.push(T),Z):T)}else f.type==="ai-fix-done"?(Je(),it(),$("done"),De(!1)):f.type==="ai-fix-error"&&(Je(),x(g=>[...g,{kind:"error",id:re(),text:f.message||"Unknown error"}]),it(),X(!1),$("done"),De(!1),ce("failed"))};Cs.current=r;const a=t(f=>{const k=xe.current;if(k&&f.requestId===k.requestId){k.queue.push(f);return}r(f)});if(N&&!N.replayed){N.replayed=!0;try{(p=N.stop)==null||p.call(N)}catch{}N.stop=null;for(const f of N.buffer.splice(0))try{r(f)}catch{}N.overflow&&x(f=>[...f,{kind:"system",id:re(),text:"Some live updates were missed while this screen was closed."}])}return Ot&&ya(),a},[t,Je]);const sr=async()=>{if(!K||at)return;Ss(!0),kt(null);const r=re();x([{kind:"system",id:r,text:D?`Recording started — navigating to ${D}`:"Recording started — interact with the browser"}]),be(0);try{await mo({url:D.trim(),browser:"chromium",headless:!1}),$("recording"),Ie(!1),Ye(0),Oe.current=Date.now(),$e.current=0,Ve.current=!0,Me(!0),ce(null),X(!1),Wt(null),Vt(new Set),dt.current=!1,Ts(),Be(null),se.current=!1}catch(a){x([]);const p=String((a==null?void 0:a.message)||a).replace(/^Error:\s*/,"");kt(p),d("error",`Couldn't start recording: ${p}`)}finally{Ss(!1)}},Is=async()=>{Zs(!0);try{const r=await uo();if(x(a=>[...a,{kind:"system",id:re(),text:`Recording stopped — ${r.actionCount} action(s) captured in ${(r.duration/1e3).toFixed(1)}s`}]),$("stopped"),Ie(!1),Re(!1),_e(!1),Me(!0),js(null),nn(Vs()).catch(()=>{}),r.sessionId&&Be(r.sessionId),!q&&r.actions.length>0){const a=r.actions.find(p=>p.type==="navigate");if(a!=null&&a.url)try{const p=new URL(a.url).hostname.replace(/\./g,"-");te(`${p}-test`)}catch{}}}catch(r){x(a=>[...a,{kind:"error",id:re(),text:`Failed to stop recording: ${r}`}])}finally{Zs(!1)}},Te=async()=>{try{await co(),Ie(!0),x(r=>[...r,{kind:"system",id:re(),text:"⏸ Recording paused — interact freely without recording"}])}catch(r){d("error",`Couldn't pause the recording: ${r}`)}},_t=async()=>{try{await lo(),Ie(!1),x(r=>[...r,{kind:"system",id:re(),text:"▶ Recording resumed"}])}catch(r){d("error",`Couldn't resume the recording: ${r}`)}},Es=async()=>{try{const r=await po();r!=null&&r.success&&(Oe.current=Date.now()-$t*1e3,$e.current=0,$("recording"),Ie(!1),x(a=>[...a,{kind:"system",id:re(),text:"➕ Adding more steps to the recording"}]))}catch(r){x(a=>[...a,{kind:"system",id:re(),text:`Failed to resume recording: ${r}`}])}},zs=async r=>{if(L.current==="recording"||L.current==="generating"||L.current==="playback"){d("info",L.current==="generating"?"Wait for the generation to finish (or stop it) before opening another recording.":"Stop the current recording before opening another one.");return}r.id!==pt&&Ts(),await Ms(r)&&await Ps(r.id,{onlyThisTab:!0})},Ms=async r=>{var k;let a=!1,p=r.settings||null;try{const v=await io(r.id);a=!!v.canAddSteps,v.settings!==void 0&&(p=v.settings||null)}catch(v){return d("error",`Couldn't open the recording: ${v}`),!1}if(se.current=!0,dt.current=!1,Gt.current=null,We.current=new Set,Be(r.id||null),vs(!1),Me(a),Wt(p),Vt(new Set),be(r.actionCount||((k=r.actions)==null?void 0:k.length)||0),Ye(Math.round((r.duration||0)/1e3)),r.name&&te(r.name),ce(r.outcome||null),X(!1),it(),he(null),Ve.current=!0,r.fullTimeline&&r.fullTimeline.length>0)return $(r.status==="completed"||r.status==="generated"?"done":"stopped"),x(Ei(r,re)),!0;$("stopped");const f=r.actions||[];return x([{kind:"system",id:re(),text:`Loaded recording: ${r.name} (${f.length} actions)`},...f.map(v=>rs(v,re))]),!0},Ps=async(r,a={})=>{var g;let p=[];try{p=(await cr(r)).runs}catch{return}const f=Bt(),k=p.filter(T=>T.kind==="record-web"&&!T.saved&&(!a.onlyThisTab||T.status!=="running"||T.clientId===f)).sort((T,Z)=>T.startedAt-Z.startedAt);if(k.length===0)return;se.current=!1;for(const T of k){T===k[k.length-1]&&T.status==="running"&&(xe.current={requestId:T.requestId,queue:[]});let J;try{J=await Qn(T.requestId)}catch{xe.current=null;continue}const ae=T.meta||{};Je(),ae.followUp?(dt.current=!0,T.userText&&x(E=>[...E,{kind:"user",id:re(),text:T.userText}])):(dt.current=!ae.analyzeOnly,x(E=>[...E,{kind:"system",id:re(),text:"Analyzing your project patterns and recorded actions..."}])),J.truncated&&x(E=>[...E,{kind:"system",id:re(),text:"The earliest steps of this generation are too long to show here."}]),X(!!ae.analyzeOnly),ce(null),he(T.requestId),ie.current={requestId:T.requestId,lastSeq:0},We.current.add(T.requestId),$("generating"),De(!0);const fe=new Set(J.pendingPermissionIds);for(const E of J.events)if(!(E.type==="ai-fix-permission"&&!fe.has(String(E.permissionId))))try{Cs.current(E)}catch{}}const v=((g=xe.current)==null?void 0:g.queue)??[];xe.current=null;for(const T of v)try{Cs.current(T)}catch{}},jr=async()=>{let r;try{r=await cr()}catch{return!1}const a=Bt(),p=r.runs.filter(v=>v.kind==="record-web"&&!v.saved&&!!v.sessionId&&(v.clientId===a||!v.tabOpen)).sort((v,g)=>g.startedAt-v.startedAt)[0],f=(r.recordings??[]).find(v=>v.kind==="record-web"&&!v.tabOpen&&v.clientId!==a),k=p&&p.clientId!==a?p.clientId:f==null?void 0:f.clientId;if(k&&m&&await m(k).catch(()=>null)!==k&&(!p||p.status==="running"||p.clientId!==k))return!1;if(p!=null&&p.sessionId){let v;try{v=await an(p.sessionId)}catch{return!1}return!v||!await Ms(v)?!1:(await Ps(p.sessionId),!0)}if(f)try{const v=await Rn();if(v.recording||v.hasSession)return await ms(v),!0}catch{}return!1},Br=async()=>{if(Pe)return;De(!0),it(),Ge.current="",Ae.current=null,ce(null),se.current=!1,dt.current=!1,Ve.current=!0;const r=`recorder-${Date.now()}`;he(r),ie.current={requestId:r,lastSeq:0},We.current.add(r),$("generating"),X(!0),x(a=>[...a,{kind:"system",id:re(),text:Y?`Analyzing project to merge recorded actions into — ${U}...`:"Analyzing your project patterns and recorded actions..."}]);try{await vo({requestId:r,testName:q||"recorded test",model:Dt||void 0,provider:Fe||void 0,mergeMode:Y||void 0,targetTestFile:Y?U:void 0,insertPosition:Y?ee:void 0,userGuidance:Y&&W.trim()?W.trim():void 0,sessionId:pt||void 0,analyzeOnly:!0,settings:ut})}catch(a){x(p=>[...p,{kind:"error",id:re(),text:`Failed to start code generation: ${a}`}]),De(!1),X(!1),he(null),$("stopped")}},Kr=async()=>{const r=Ft.current;r&&(Je(),he(null),it(),X(!1),$("done"),De(!1),ce("stopped"),x(a=>[...a,{kind:"system",id:re(),text:"Generation stopped by user"}]),jo({requestId:r}).catch(()=>{}))},kr=async()=>{var fe;if(Pe)return;const r=ke.trim();if(!r&&!h)return;const a=h,p=!r||/^(proceed|ok|yes|go|continue|looks good|lgtm|sure|do it|go ahead)$/i.test(r),f=a&&p?'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;M(""),De(!0),ce(null),it(),Ge.current="",Ae.current=null,se.current=!1,dt.current=!0,Ve.current=!0,a&&X(!1);const k=`recorder-followup-${Date.now()}`;he(k),ie.current={requestId:k,lastSeq:0},We.current.add(k),$("generating"),x(E=>[...E,{kind:"user",id:re(),text:r||(a?"Looks good, proceed!":"")}]);const v=_.filter(E=>E.kind==="file-diff").filter(E=>!E.via&&!E.omitted&&!E.netNoChange&&E.diffType!=="deleted"&&!!E.filePath).map(E=>E.filePath),g=v.find(E=>Di.test(E))||(Y&&U?U:void 0)||v[0],T=new Set,Z=[],J=[];for(const E of _)if(E.kind==="recorded-action")Z.push(E.actionType==="custom"?`custom step: ${E.instruction||E.description}${(fe=E.outputs)!=null&&fe.length?` (saves ${E.outputs.map(Ee=>`{${Ee}}`).join(", ")})`:""}`:`${E.actionType}: ${E.description}${E.valueFrom?` (uses {${E.valueFrom}})`:""}`);else if(E.kind==="file-diff"&&E.filePath&&!E.netNoChange)T.add(E.filePath);else if(E.kind==="user")J.push(`User: ${E.text}`);else if(E.kind==="text"&&E.text){const Ee=String(E.text);J.push(`Assistant: ${Ee.length>2e3?Ee.substring(0,2e3)+"... [truncated]":Ee}`)}else if(E.kind==="tool"){if(E.phase==="start")continue;const Ee=E.args?` ${String(E.args).substring(0,100)}`:"";let Ze="";if(E.phase==="complete"){const Zt=E.result?String(E.result):"";Ze=Zt?` → ${Zt.length>300?Zt.substring(0,300)+"... [truncated]":Zt}`:" → (no output)"}else E.phase==="error"?Ze=` → ERROR: ${E.error?String(E.error).substring(0,300):"failed"}`:E.phase==="denied"&&(Ze=" → DENIED by user");J.push(`[Tool ${E.phase}] ${E.toolName}${Ee}${Ze}`)}else E.kind==="error"&&J.push(`[Stream Error] ${E.text}`);const ae=[];Z.length>0&&ae.push(`Recorded steps (${Z.length}):
29
- ${Z.map((E,Ee)=>` ${Ee+1}. ${E}`).join(`
30
- `)}`),T.size>0&&ae.push(`Files created/modified:
31
- ${[...T].map(E=>` - ${E}`).join(`
32
- `)}`),J.length>0&&ae.push(`Conversation history (in order):
33
- ${J.join(`
34
-
35
- `)}`);try{await wo({requestId:k,prompt:f,testFilePath:g,previousContext:ae.length>0?ae.join(`
36
- `):void 0,model:Dt||void 0,provider:Fe||void 0,proceedAfterAnalysis:a,sessionId:pt||void 0,displayText:r||(a?"Looks good, proceed!":"")})}catch(E){x(Ee=>[...Ee,{kind:"error",id:re(),text:`Failed to start follow-up: ${E}`}]),De(!1),he(null),a&&X(!0),$("done")}},Ds=(r,a=!1)=>{ot&&(o({type:"ai-fix-permission-response",permissionId:ot.permissionId,granted:r,remember:r&&a}),ps(Nr()))},Nr=()=>Xt.current.shift()||null,Sr=async r=>{const a=C.current.find(p=>p.id===r&&p.kind==="recorded-action");if(a){mt(r);try{const p=await ho();if(!(p!=null&&p.success)||!p.element)return;const f=p.description||a.description,v=`${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}"`:""}`;x(g=>g.map(T=>T.id===r&&T.kind==="recorded-action"?{...T,description:v,selector:p.selector}:T));try{await Jr(r,{selector:p.selector,locators:p.locators,domContext:p.domContext,elementMeta:p.elementMeta,description:v})}catch(g){x(T=>T.map(Z=>Z.id===r?a:Z)),d("error",`Couldn't update the step — it was left as it was. ${g}`)}}catch(p){d("error",`Re-inspect failed: ${p}`)}finally{mt(null)}}},Rr=async r=>{const a=C.current.findIndex(f=>f.id===r),p=a>=0?C.current[a]:void 0;x(f=>f.filter(k=>k.id!==r)),be(f=>Math.max(0,f-1));try{await go(r)}catch(f){p&&(x(k=>{if(k.some(g=>g.id===r))return k;const v=[...k];return v.splice(Math.min(a,v.length),0,p),v}),be(k=>k+1)),d("error",`Couldn't remove the step — it was put back. ${f}`)}},rr=r=>{const a=C.current;x(r);const p=r.filter(f=>f.kind==="recorded-action").map(f=>f.id);bo(p).catch(f=>{x(a),d("error",`Couldn't reorder the steps — the previous order was restored. ${f}`)})},nr=(r,a)=>{const p=C.current,f=p.findIndex(T=>T.id===r);if(f<0)return;let k=f+a;for(;k>=0&&k<p.length&&p[k].kind!=="recorded-action";)k+=a;if(k<0||k>=p.length)return;const v=[...p],[g]=v.splice(f,1);v.splice(k,0,g),rr(v),requestAnimationFrame(()=>{var T;return(T=document.querySelector(`[data-action-id="${r}"]`))==null?void 0:T.focus()})},qt=r=>bs(r),ar=(r,a,p)=>{const f=[...r];if(p===null){const k=f.findIndex(v=>v.kind==="recorded-action");f.splice(k>=0?k:f.length,0,a)}else{const k=p?f.findIndex(v=>v.id===p):-1;k>=0?f.splice(k+1,0,a):f.push(a)}return f},Cr=async r=>{const a=Ne;if(a){if(a.mode==="add"){const p=await ko(r,a.afterId),f=rs(p.action,re);x(k=>ar(k,f,a.afterId)),be(k=>k+1)}else if(a.mode==="edit"&&a.editId){const p=await Jr(a.editId,{instruction:r.instruction,customKind:r.customKind,references:r.references||[],outputs:r.outputs||[]}),f=p.action?rs(p.action,re):null;x(k=>k.map(v=>v.id===a.editId&&v.kind==="recorded-action"?{...v,...f?{description:f.description,instruction:f.instruction,customKind:f.customKind,references:f.references,outputs:f.outputs}:{}}:v))}else if(a.mode==="replace"){const p=[...At],f=await No(p,r),k=rs(f.action,re),v=new Set(p);x(g=>{const T=g.findIndex(J=>v.has(J.id));ys.current.set(k.id,g.filter(J=>v.has(J.id)));const Z=g.filter(J=>!v.has(J.id));return Z.splice(T>=0?Math.min(T,Z.length):Z.length,0,k),Z}),be(g=>Math.max(0,g-p.length+1)),Vt(new Set)}bs(null)}},Jt=async r=>{try{const a=await fo(r),p=ys.current.get(r),f=p&&p.length===a.actions.length?p:a.actions.map(k=>rs(k,re));ys.current.delete(r),x(k=>{const v=k.findIndex(J=>J.id===r);if(v<0)return k;const g=[...k];if(!a.order)return g.splice(v,1,...f),g;g.splice(v,1);let T=v;const Z=new Map(a.order.map((J,ae)=>[J,ae]));for(const J of[...f].sort((ae,fe)=>(Z.get(ae.id)??0)-(Z.get(fe.id)??0))){const ae=Z.get(J.id)??-1,fe=ae>0?a.order[ae-1]:null,E=fe?g.findIndex(Ze=>Ze.id===fe):-1,Ee=E>=0?E+1:Math.min(T,g.length);g.splice(Ee,0,J),T=Ee+1}return g}),be(k=>k-1+f.length)}catch(a){d("error",`Couldn't put the steps back: ${a}`)}},or=async(r,a)=>{const p=C.current.find(f=>f.id===r&&f.kind==="recorded-action");x(f=>f.map(k=>k.id===r&&k.kind==="recorded-action"?{...k,valueFrom:a||void 0}:k));try{await Jr(r,{valueFrom:a})}catch(f){x(k=>k.map(v=>v.id===r&&v.kind==="recorded-action"?{...v,valueFrom:p==null?void 0:p.valueFrom}:v)),d("error",`Couldn't change the step: ${f}`)}},ht=s.useRef(null),Ur=r=>{Wt(r),ht.current&&clearTimeout(ht.current),ht.current=setTimeout(()=>{yo(r).catch(()=>{})},500)},Gr=s.useMemo(()=>{var k;const r=new Map,a=[],p=(((k=ut==null?void 0:ut.testData)==null?void 0:k.columns)||[]).map(v=>({name:`data.${v}`,source:"data",detail:ut.testData.file}));let f=0;for(const v of _)if(v.kind==="recorded-action"&&(f++,r.set(v.id,[...a,...p]),v.actionType==="custom"))for(const g of v.outputs||[])a.push({name:g,source:"step",detail:`saved by step ${f}`});return r},[_,ut]),Wr=r=>Vt(a=>{const p=new Set(a);return p.has(r)?p.delete(r):p.add(r),p}),Vr=async()=>{Ts(),await xo().catch(()=>{}),$("setup"),x([]),be(0),Ye(0),Ie(!1),Oe.current=0,$e.current=0,B(""),te(""),it(),he(null),De(!1),Pt(!1),Xe(-1),Ge.current="",Ae.current=null,M(""),X(!1),ce(null),Re(!1),_e(!1),Me(!0),Wt(null),Vt(new Set),dt.current=!1,Gt.current=null,We.current=new Set,Be(null),se.current=!1},Yr=y==="recording"||y==="generating"||y==="playback";return rt==="mobile"?e.jsx(Ri,{showHistory:Et,setShowHistory:vs,recorderMode:rt,setRecorderMode:ws}):e.jsxs(Go,{userControlOnly:!0,children:[e.jsxs("div",{className:"h-full flex flex-col relative bg-white dark:bg-transparent",children:[e.jsx("div",{ref:ks,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:()=>vs(!Et),className:`flex-shrink-0 p-1.5 rounded-lg transition-colors ${Et?"bg-brand-500/15 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,"aria-label":"Recording History","aria-expanded":Et,title:"Recording History",children:e.jsx(Lr,{size:16})}),y==="recording"?e.jsxs(e.Fragment,{children:[He?e.jsxs(e.Fragment,{children:[e.jsx(_r,{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:Ai($t)}),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:is})]}):y==="playback"?e.jsxs(e.Fragment,{children:[e.jsx(Os,{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:[ft,"/",Lt]})]}):y==="generating"?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:14,className:"animate-spin text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-brand-300",children:"Generating Code..."})]}):y==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(lt,{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:[is," action",is!==1?"s":""]})]}):y==="done"?h?e.jsxs(e.Fragment,{children:[e.jsx(as,{size:14,className:"flex-shrink-0 text-amber-400"}),e.jsxs("span",{className:"text-sm font-semibold text-amber-300 truncate",title:q||void 0,children:["Waiting for your input",q?` — ${q}`:""]})]}):j==="failed"?e.jsxs(e.Fragment,{children:[e.jsx(Us,{size:14,className:"flex-shrink-0 text-red-400"}),e.jsxs("span",{className:"text-sm font-semibold text-red-300 truncate",title:q||void 0,children:["Generation Failed",q?` — ${q}`:""]})]}):j==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(lt,{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:q||void 0,children:["Stopped",q?` — ${q}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(yt,{size:14,className:"flex-shrink-0 text-emerald-400"}),e.jsxs("span",{className:"text-sm font-semibold text-emerald-300 truncate",title:q||void 0,children:["Code Generated",q?` — ${q}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(vt,{size:14,className:"text-gray-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Browser Recorder"})]}),Qe.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(ua,{value:rt,onChange:ws,disabled:Yr})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[y==="recording"&&e.jsxs(e.Fragment,{children:[!He&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:Se?"Exit assertion mode":"Add an assertion",hint:Se?void 0:"Click an element in the browser to check it, instead of clicking it",shortcut:Se?"Esc":void 0,children:e.jsxs("button",{"aria-label":Se?"Exit assertion mode":"Add an assertion",onClick:async()=>{try{Ce&&(await Tn(!1),_e(!1)),await $n(!Se),Re(!Se),Se||In()}catch{}},className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${Se?"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(Gs,{size:14}),Se&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:Ce?"Exit annotate mode":"Annotate a step",hint:Ce?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:Ce?"Esc":void 0,children:e.jsxs("button",{"aria-label":Ce?"Exit annotate mode":"Annotate a step",onClick:async()=>{try{Se&&(await $n(!1),Re(!1)),await Tn(!Ce),_e(!Ce),Ce||In()}catch{}},className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${Ce?"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(dr,{size:14}),Ce&&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:()=>qt({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(Kt,{size:14})})}),e.jsx(Ct,{label:He?"Resume recording":"Pause recording",hint:He?"Your actions are recorded again":"Use the page freely — nothing is recorded until you resume",children:e.jsx("button",{"aria-label":He?"Resume recording":"Pause recording",onClick:He?_t:Te,className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${He?"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:He?e.jsx(Os,{size:14}):e.jsx(_r,{size:14})})}),e.jsx(Ct,{label:"Stop recording",hint:"Then review the steps and generate the test",children:e.jsx("button",{onClick:Is,disabled:Rs,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:Rs?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(lt,{size:14})})})]}),(y==="stopped"||y==="done")&&e.jsxs(e.Fragment,{children:[y==="stopped"&&e.jsx(ur,{tone:"indigo",compact:ze,icon:e.jsx(Kt,{size:13}),label:"Custom Step",hint:"Add a custom step at the end — or hover between two steps to insert one there",onClick:()=>qt({mode:"add"})}),y==="stopped"&&e.jsx(ur,{tone:"brand",compact:ze,icon:e.jsx(fr,{size:13}),label:"Add More Steps",hint:ls?"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:!ls,onClick:Es}),e.jsx(ur,{compact:ze,icon:e.jsx(Fr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",onClick:Vr})]})]})]})}),e.jsxs("div",{ref:qe,onScroll:As,className:`flex-1 overflow-y-auto p-4 space-y-3 transition-all duration-200 ${Et?"ml-[280px]":""}`,children:[y==="setup"&&e.jsxs("div",{className:"max-w-xl mx-auto mt-8 space-y-6",children:[xt&&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(Mr,{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:[xt.actionCount||((ir=xt.actions)==null?void 0:ir.length)||0," steps recorded",xt.url?` on ${xt.url}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("button",{onClick:()=>{zs(xt),js(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(Os,{size:12})," Resume Draft"]}),e.jsx("button",{onClick:()=>{nn(xt.id||Vs()).catch(()=>{}),js(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(Ks,{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(vt,{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(hn,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:D,onChange:r=>{B(r.target.value),kt(null)},placeholder:"https://example.com","aria-invalid":D.trim()!==""&&!K,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 ${D.trim()!==""&&!K?"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"&&!at&&sr()}})]})}),D.trim()!==""&&!K?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 ${br?"bg-emerald-400":"bg-gray-600"}`}),br?"Browser is running — recording will use the current session":"A new browser will be launched for recording"]}),e.jsxs("button",{onClick:sr,disabled:at||!K,title:K?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:[at?e.jsx(je,{size:18,className:"animate-spin"}):e.jsx(vt,{size:18,className:"fill-red-400 text-red-400"}),"Start Recording"]}),Yt&&e.jsxs("p",{role:"alert",className:"flex items-start gap-1.5 text-sm text-red-600 dark:text-red-400",children:[e.jsx(Hs,{size:15,className:"mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:["Couldn't start recording: ",Yt]})]})]}),y!=="setup"&&e.jsx("div",{className:"space-y-0.5",children:Wo(_,{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:y==="generating"}).map(r=>{var f,k,v,g;if(r.kind==="group")return e.jsx(Vo,{group:r,className:"!-my-1"},r.id);if(r.kind==="changes")return e.jsx(Yo,{item:r},r.id);const a=r.entry,p=z.get(a.id)??0;if(a.kind==="recorded-action"){const T=_.slice(0,p+1).filter(V=>V.kind==="recorded-action").length,Z=Ti[a.actionType]||"border-l-gray-500",J=$i.has(a.actionType),ae=Ke===p,fe=cs===p&&Ke!==p,E=a.actionType==="custom",Ee=y==="stopped"&&!E,Ze=At.has(a.id),Zt=(y==="stopped"||y==="recording")&&On.has(a.actionType)&&!a.secretEnv;return e.jsxs("div",{children:[y==="stopped"&&T===1&&e.jsx(Un,{label:"Insert a custom step before step 1",onInsert:()=>qt({mode:"add",afterId:null})}),e.jsxs("div",{draggable:y==="stopped",onDragStart:V=>{nt(p),V.dataTransfer.effectAllowed="move";try{const et=document.createElement("div");et.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;",et.textContent=a.description.substring(0,40),document.body.appendChild(et),V.dataTransfer.setDragImage(et,100,15),setTimeout(()=>et.remove(),0)}catch{}},onDragOver:V=>{V.preventDefault(),V.dataTransfer.dropEffect="move";const et=Date.now();if(et-Ns.current<50)return;Ns.current=et;const es=V.currentTarget.getBoundingClientRect(),St=es.top+es.height/2,ts=V.clientY<St?"above":"below";(cs!==p||zt!==ts)&&(Ue(p),Js(ts))},onDragLeave:()=>{cs===p&&Ue(null)},onDrop:V=>{var et;if(V.preventDefault(),Ke!==null&&Ke!==p){const es=(et=_[Ke])==null?void 0:et.id,St=[..._],[ts]=St.splice(Ke,1);if(ts){let gt=p;Ke<p?gt=zt==="above"?p-1:p:gt=zt==="above"?p:p+1,gt=Math.max(0,Math.min(gt,St.length)),St.splice(gt,0,ts),rr(St)}es&&(gr(es),setTimeout(()=>{const gt=document.querySelector(`[data-action-id="${es}"]`);gt&&gt.scrollIntoView({behavior:"smooth",block:"nearest"})},50),setTimeout(()=>gr(null),3e3))}nt(null),Ue(null)},onDragEnd:()=>{nt(null),Ue(null)},tabIndex:y==="stopped"?0:void 0,"aria-label":`Step ${T}: ${a.description}${y==="stopped"?" — Alt+Up or Alt+Down to move":""}`,onKeyDown:V=>{y!=="stopped"||!V.altKey||V.target!==V.currentTarget||(V.key==="ArrowUp"?(V.preventDefault(),nr(a.id,-1)):V.key==="ArrowDown"&&(V.preventDefault(),nr(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] ${Z} ${Ze?"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 ${ae?"cursor-grabbing":"cursor-default"} ${ae?"opacity-30":"transition-colors duration-100"} ${ds===a.id?"ring-2 ring-blue-400 bg-blue-500/5 animate-pulse":""}`,children:[fe&&zt==="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"})}),fe&&zt==="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"})}),y==="stopped"&&e.jsx("span",{className:"flex-shrink-0 w-4 flex items-center justify-center",onMouseDown:V=>V.stopPropagation(),children:Ee&&e.jsx("input",{type:"checkbox",checked:Ze,onChange:()=>Wr(a.id),onClick:V=>V.stopPropagation(),"aria-label":`Select step ${T} (to replace it with a custom step)`,title:"Select to replace with a custom step",className:`cursor-pointer accent-indigo-500 ${At.size>0||Ze?"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:T}),a.screenshot?e.jsx("button",{draggable:!1,onMouseDown:V=>V.stopPropagation(),onDragStart:V=>{V.preventDefault(),V.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:V=>{V.stopPropagation(),Qs({screenshot:a.screenshot,elementRect:a.elementRect,description:a.description,step:T})},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(rn,{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(rn,{type:a.actionType,size:16})}),J&&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:E?a.instruction:void 0,children:E&&a.instruction||a.description}),E&&!!((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(V=>V.label).join(`
37
- `),children:[e.jsx(Hr,{kind:a.references[0].kind,size:11}),a.references.length>1?`${a.references.length} refs`:a.references[0].label]}),E&&((k=a.outputs)==null?void 0:k.map(V=>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:`→ {${V}}`},V))),E&&!!((v=a.replaces)!=null&&v.length)&&e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-gray-500",title:a.replaces.map(V=>V.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}}`})]}),Ys===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(dr,{size:10,className:"text-blue-400"}),e.jsx("span",{className:"text-[10px] text-blue-400 font-medium",children:"Pick..."})]}),(y==="recording"||y==="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:V=>V.stopPropagation(),onDragStart:V=>{V.preventDefault(),V.stopPropagation()},children:[E&&e.jsx("button",{onClick:V=>{V.stopPropagation(),qt({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(_o,{size:14})}),E&&!!((g=a.replaces)!=null&&g.length)&&y==="stopped"&&e.jsx("button",{onClick:V=>{V.stopPropagation(),Jt(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(ia,{size:14})}),Zt&&e.jsx(fa,{current:a.valueFrom,options:Gr.get(a.id)||[],onPick:V=>or(a.id,V)}),a.actionType!=="annotate"&&!E&&e.jsx("button",{onClick:V=>{V.stopPropagation(),Sr(a.id)},disabled:!!Ys,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(dr,{size:14})}),e.jsx("button",{onClick:V=>{V.stopPropagation(),Rr(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(Ks,{size:14})})]})]}),y==="stopped"&&e.jsx(Un,{label:`Insert a custom step after step ${T}`,onInsert:()=>qt({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(pr,{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(ca,{text:a.text})})},a.id);if(a.kind==="playback-action"){const T=a.status==="running"?e.jsx(je,{size:11,className:"animate-spin text-cyan-400"}):a.status==="done"?e.jsx(yt,{size:11,className:"text-emerald-400"}):a.status==="error"?e.jsx(Us,{size:11,className:"text-red-400"}):e.jsx(as,{size:11,className:"text-gray-500"});return e.jsxs("div",{className:"flex items-center gap-2 px-4 py-1",children:[T,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(rn,{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(Hs,{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})})]}),y==="stopped"&&e.jsxs("div",{className:"flex-shrink-0 px-4 py-3 border-t border-white/5 bg-surface-1 space-y-3",children:[At.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:[At.size," step",At.size===1?"":"s"," selected"]}),e.jsxs("button",{onClick:()=>qt({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(Kt,{size:12})," Replace with custom step"]}),e.jsx("button",{onClick:()=>Vt(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":!Y,onClick:()=>{H(!1),w(""),G(""),le("")},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${Y?"text-gray-500 hover:text-gray-300":"bg-brand-500/15 text-brand-300 shadow-sm"}`,children:"New Test"}),e.jsx("button",{"aria-pressed":Y,onClick:()=>H(!0),className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${Y?"bg-indigo-500/15 text-indigo-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:"Add to Existing Test"})]}),Y&&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 ${ee==="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:ee==="auto",onChange:()=>ne("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 ${ee==="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:ee==="append",onChange:()=>ne("append"),className:"sr-only"}),"Append At End"]})]})]}),!Y&&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:q,onChange:r=>te(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"}),qr(q)&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400/90",children:qr(q)})]}),Y&&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:()=>oe(!ue),"aria-haspopup":"listbox","aria-expanded":ue,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:Q?e.jsxs("div",{title:Q,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:qs(Q)}),e.jsx("span",{className:"text-[10px] text-gray-500 block mt-0.5 truncate",children:U})]}):e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:"Select a test..."})}),ue&&(S==null?void 0:S.suites)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>oe(!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(),oe(!1))},children:[e.jsx("div",{className:"px-2 py-2 border-b border-white/5",children:e.jsx("input",{type:"text",value:pe,onChange:r=>b(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:S.suites.filter(r=>{const a=pe.toLowerCase();return a?ns(r.name,a)||r.file.toLowerCase().includes(a)||r.tests.some(p=>ns(p.name,a)):!0}).map(r=>{const a=r.file,p=pe.toLowerCase(),f=A.has(a)||!!p,k=p?r.tests.filter(v=>ns(v.name,p)||ns(r.name,p)):r.tests;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>R(v=>{const g=new Set(v);return g.has(a)?g.delete(a):g.add(a),g}),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(hs,{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:qs(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&&k.map((v,g)=>e.jsx("button",{onClick:()=>{w(r.file),G(v.name),oe(!1),b("")},className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${U===r.file&&Q===v.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:v.name,children:qs(v.name)})},g))]},a)})})]})]})]})]}),ee==="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:"*"}),Q?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"})]}),Q?e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:ve,value:W,onChange:r=>{le(r.target.value);const a=r.target;a.style.height="auto",a.style.height=`${a.scrollHeight}px`},onKeyUp:r=>{const a=r.currentTarget,p=a.value,f=a.selectionStart??p.length,k=p.slice(0,f),v=k.lastIndexOf("@");if(v>=0&&(v===0||k[v-1]===" "||k[v-1]===`
39
- `)){const g=k.slice(v+1);if(!g.includes("]")){Ws(g.toLowerCase()),gs(!0);return}}gs(!1)},onKeyDown:r=>{r.key==="Escape"&&ct&&(r.preventDefault(),gs(!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:W.split(`
40
- `).length>2||W.length>100?"auto":"hidden"}}),ct&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>gs(!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:[Tt.filter(r=>!os||r.keyword.toLowerCase().includes(os)||r.name.toLowerCase().includes(os)).map((r,a)=>e.jsxs("button",{onClick:()=>{const p=ve.current;if(!p)return;const f=p.selectionStart||0,k=W.slice(0,f),v=k.lastIndexOf("@"),g=W.slice(f),T=`@[${r.keyword} ${r.name}]`,Z=k.slice(0,v)+T+" "+g;le(Z),gs(!1),setTimeout(()=>{p.focus();const J=v+T.length+1;p.setSelectionRange(J,J)},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)),st&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 text-center",children:"Loading steps..."}),!st&&Tt.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No steps found for this test"}),!st&&Tt.length>0&&Tt.filter(r=>!os||r.keyword.toLowerCase().includes(os)||r.name.toLowerCase().includes(os)).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(ha,{settings:ut,onChange:Ur,inputs:_.filter(r=>r.kind==="recorded-action"&&On.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)or(a.id,a.valueFrom)},disabled:Pe}),e.jsxs("div",{className:"flex gap-2",children:[Ci,Fe==="testver"&&e.jsx(cn,{refreshSignal:Pe,align:"left"}),e.jsx(dn,{providerModels:Qt,selectedProvider:Fe,selectedModel:Dt,onPick:er}),e.jsxs("button",{onClick:Br,disabled:Pe||is===0||!Y&&!q.trim()||Y&&(!U||!Q)||Y&&ee==="auto"&&!W.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 ${Y?"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:[Pe?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(pr,{size:14}),Y?"Merge & Generate":"Generate Test Code"]})]})]}),y==="playback"&&Lt>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(je,{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:`${ft/Lt*100}%`}})})}),e.jsxs("span",{className:"text-[10px] text-gray-500 font-mono",children:[ft,"/",Lt]})]})}),ot&&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(ln,{pending:ot,queuedCount:Xt.current.length,onAllow:()=>Ds(!0,!1),onAlwaysAllow:()=>Ds(!0,!0),onDeny:()=>Ds(!1,!1)})})}),(y==="done"||y==="generating")&&e.jsxs("div",{className:"sticky bottom-0 border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[Pe&&e.jsx("div",{className:"flex items-center pl-1 pb-3",children:e.jsx(la,{})}),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:[Fe==="testver"&&e.jsx(cn,{refreshSignal:Pe,align:"left"}),e.jsx(dn,{providerModels:Qt,selectedProvider:Fe,selectedModel:Dt,onPick:er,disabled:Pe,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:ke,onChange:r=>{M(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(),!Pe&&(ke.trim()||h)&&kr())},"aria-label":"Message to the AI",placeholder:Pe?"AI is working... click stop to cancel":h?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:Pe,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:Pe?e.jsx("button",{onClick:Kr,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(lt,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:kr,"aria-label":h&&!ke.trim()?"Proceed":"Send",title:h&&!ke.trim()?"Proceed":"Send",disabled:!ke.trim()&&!h,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(lr,{size:14})})})]})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:Pe?"Click the stop button to cancel the current generation":h?"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&&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(ii,{onLoadSession:zs,onClose:()=>vs(!1),activeSessionId:pt})}),e.jsx(ma,{open:!!Ne,mode:(Ne==null?void 0:Ne.mode)||"add",initial:Ne==null?void 0:Ne.initial,replaceCount:At.size,onCancel:()=>bs(null),onSave:Cr}),me&&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:()=>Qs(null)}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":`Step ${me.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:me.step}),e.jsx("span",{className:"text-sm text-gray-200",children:me.description})]}),e.jsx("button",{ref:Xs,onClick:()=>Qs(null),"aria-label":"Close screenshot",className:"text-gray-400 hover:text-gray-200 p-1",children:e.jsx(wt,{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:me.screenshot,alt:"Element screenshot",className:"block max-w-full max-h-[75vh]",onLoad:r=>hr({src:me.screenshot,w:r.currentTarget.naturalWidth,h:r.currentTarget.naturalHeight})}),me.elementRect&&me.elementRect.clipW&&Pi(jt,me.screenshot,me.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:`${me.elementRect.x/me.elementRect.clipW*100}%`,top:`${me.elementRect.y/me.elementRect.clipH*100}%`,width:`${me.elementRect.width/me.elementRect.clipW*100}%`,height:`${me.elementRect.height/me.elementRect.clipH*100}%`,backgroundColor:"transparent",boxShadow:"0 0 0 9999px rgba(0,0,0,0.35)"}})})]})})]})]})]})}function rl(){return e.jsx("div",{className:"flex-1 flex flex-col overflow-hidden h-full",children:e.jsx(Hi,{})})}export{rl as AIRecordPanel};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BlA8ntjb.js","assets/vendor-react-DOVfxdUy.js","assets/vendor-query-DkZSMtfn.js","assets/vendor-icons-Cm92aSc5.js","assets/index-Co4_SlGD.css"])))=>i.map(i=>d[i]);
2
+ import{r as s,j as e,d as mr,n as Gn}from"./vendor-react-DOVfxdUy.js";import{b as un,az as Sa,aA as nn,aB as Ra,aC as an,aD as Ca,aE as Wn,aF as Ta,aG as zr,ad as $a,aH as Vn,aI as gn,aJ as Yn,Q as Aa,S as bn,T as yn,aK as vn,aL as Ia,aM as wn,U as Ea,aN as jn,aO as za,aP as Ma,aQ as Xr,aR as Ar,aS as Pa,aT as Da,aU as kn,aV as Fa,aW as La,aX as _a,aY as qa,aZ as Ha,a_ as Oa,a$ as Nn,V as Ba,b0 as cr,ao as Bt,b1 as Ir,b2 as Sn,am as Qn,X as Ua,W as Ka,b3 as Ga,b4 as Wa,b5 as Va,b6 as Ya,b7 as Qa,b8 as Xa,b9 as Ja,ba as Za,bb as eo,bc as to,bd as Xn,be as so,x as Jn,bf as ro,bg as no,bh as Rn,bi as ao,bj as Cn,bk as Tn,bl as $n,bm as oo,bn as io,bo as lo,bp as co,bq as uo,br as po,bs as xo,bt as mo,bu as fo,bv as Jr,bw as ho,bx as go,by as bo,bz as yo,bA as vo,bB as wo,bC as jo,bD as ko,bE as No}from"./index-BlA8ntjb.js";import{t as ns,f as qs}from"./formatTestName-BKd2Uqhs.js";import{a as Zn,f as Zr}from"./formatDate-T65-Y6Mi.js";import{a as pn,u as ea,c as Pr}from"./vendor-query-DkZSMtfn.js";import{C as ta}from"./ConfirmDialog-D_N9188T.js";import{v as as,X as wt,w as xn,a1 as je,bo as sa,bt as Bs,bu as ra,b8 as Us,b9 as lt,aq as Ks,s as yt,h as vt,Z as na,S as pr,a as Hs,bv as Dr,bw as mn,ad as Gs,bx as Or,am as fn,aD as aa,z as hs,by as So,O as hn,K as on,a2 as xr,bz as Ro,bA as Co,bB as To,a5 as Ut,bC as $o,bD as Ao,bE as Io,bF as Eo,bG as zo,aH as Mo,ah as An,b5 as fr,bH as Po,aJ as Mr,a3 as Os,be as oa,ao as Fr,bI as dr,a$ as Lr,a7 as lr,ai as Do,bJ as Fo,bK as ia,bL as Lo,bb as _r,b7 as _o,ab as qo,bM as Ho,bN as Oo,bO as Bo}from"./vendor-icons-Cm92aSc5.js";import{D as Uo,P as ln,A as la,a as Ko,L as Go,f as In,b as Wo,T as Vo,C as Yo}from"./ChangesSummary-BjNMwGIZ.js";import{A as ca}from"./AIStreamUI-C1gHJtlF.js";import{H as Qo,P as En}from"./hiddenLlmProviders-BPORgy-e.js";import{T as cn}from"./TestverCreditsRing-CoDk5eAS.js";import{S as Xo,L as Jo}from"./SearchableDevicePicker-CenIxD7b.js";import{u as da}from"./useTestExplorer-BGhkGHKy.js";import"./useTabParam-CyYAP90W.js";import"./MediaModal-Dyy_iHl9.js";const Zo="\"'`“”‘’„‟‚‛«»‹›"'",ei="?*+()[]{}|^$\\&<>%!;",ti=t=>t.charCodeAt(0)<32||t.charCodeAt(0)===127;function si(t){let o="";for(const m of t)Zo.includes(m)||(m==="&"?o+=" and ":m==="%"?o+=" percent ":m==="+"?o+=" plus ":m===";"?o+=", ":ei.includes(m)||ti(m)?o+=" ":o+=m);return o.replace(/\s+/g," ").replace(/ ([,:.])/g,"$1").replace(/,(?=[,:])/g,"").trim().replace(/^[,:.\-\s]+|[,:\-\s]+$/g,"")}function qr(t){const o=t.trim();if(!o)return null;const m=si(o);return m===o.replace(/\s+/g," ")?null:m?`Saved as “${m}” — 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 zn={recorded:{icon:e.jsx(vt,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(na,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(vt,{size:14,className:"text-gray-400"}),label:"Draft"}},Mn={success:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Ks,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(lt,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function ri(t){return t.outcome&&Mn[t.outcome]?Mn[t.outcome]:zn[t.status]||zn.recorded}function ni(t){const o=Date.now()-t;return o<6e4?"Just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:o<6048e5?`${Math.floor(o/864e5)}d ago`:Zn(t)}function ai(t){const o=new Date,m=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),d=m-864e5,N=m-7*864e5,l={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const S of t){const y=S.createdAt;y>=m?l.Today.push(S):y>=d?l.Yesterday.push(S):y>=N?l["This Week"].push(S):l.Earlier.push(S)}return Object.entries(l).filter(([,S])=>S.length>0).map(([S,y])=>({label:S,items:y}))}const oi=["login","checkout","search","smoke","regression","e2e","navigation","form"];function ii({onLoadSession:t,onClose:o,activeSessionId:m}){const d=pn(),{toast:N}=un(),[l,S]=s.useState(""),[y,$]=s.useState(null),[L,_]=s.useState(!1),x=s.useRef({}),[C,z]=s.useState(null),[D,B]=s.useState(null),[U,q]=s.useState(""),[te,Y]=s.useState(null),[H,K]=s.useState(""),[w,Q]=s.useState(null),{data:G,isLoading:ee}=ea({queryKey:["recording-history"],queryFn:()=>Sa()}),ne=Pr({mutationFn:nn,onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),ue=Pr({mutationFn:({id:M,data:h})=>Ra(M,h),onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),oe=s.useMemo(()=>{const M=(G==null?void 0:G.sessions)||[];return Array.isArray(M)?M.filter(h=>h.status!=="draft"):[]},[G]),pe=s.useMemo(()=>{let M=oe;if(l){const h=l.toLowerCase();M=M.filter(X=>(X.name||"").toLowerCase().includes(h)||(X.url||"").toLowerCase().includes(h))}return C&&(M=M.filter(h=>Array.isArray(h.tags)&&h.tags.includes(C))),M},[oe,l,C]),b=s.useMemo(()=>{const M=new Set;return oe.forEach(h=>{Array.isArray(h.tags)&&h.tags.forEach(X=>M.add(X))}),Array.from(M).sort()},[oe]),A=s.useMemo(()=>{const M=new Set([...oi,...b]);return Array.from(M).sort()},[b]),R=s.useMemo(()=>ai(pe),[pe]),W=async M=>{try{const h=await an(M);h&&t(h)}catch(h){N("error",`Couldn't open the recording: ${h}`)}},le=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];j.includes(h)||(ue.mutate({id:M,data:{tags:[...j,h]}}),B(null),q(""))},ke=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];ue.mutate({id:M,data:{tags:j.filter(ce=>ce!==h)}})};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(as,{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:oe.length})]}),e.jsx("button",{onClick:o,"aria-label":"Close history",className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(xn,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:l,onChange:M=>S(M.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"})]}),b.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>z(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C?"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"}),b.map(M=>e.jsx("button",{onClick:()=>z(C===M?null:M),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C===M?"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:M},M))]})]}),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(je,{size:20,className:"text-brand-400 animate-spin"})}):R.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(as,{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"})]}):R.map(M=>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:M.label})}),M.items.map(h=>{const X=ri(h);return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":`Open recording ${h.name}`,"aria-current":m===h.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 ${m===h.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(h.id),onKeyDown:j=>{j.target===j.currentTarget&&(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),W(h.id))},children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[te===h.id?e.jsx("input",{type:"text",value:H,onChange:j=>K(j.target.value),onClick:j=>j.stopPropagation(),onBlur:()=>{H.trim()&&H.trim()!==h.name&&ue.mutate({id:h.id,data:{name:H.trim()}}),Y(null)},onKeyDown:j=>{j.key==="Enter"&&j.target.blur(),j.key==="Escape"&&Y(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:j=>{j.stopPropagation(),Y(h.id),K(h.name)},title:"Double-click to rename",children:h.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[h.actionCount," steps"]}),e.jsx("span",{children:ni(h.createdAt)})]}),Array.isArray(h.tags)&&h.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:j=>j.stopPropagation(),children:h.tags.map(j=>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:[j,e.jsx("button",{onClick:()=>Q({type:"remove-tag",sessionId:h.id,tag:j}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${j}"`,children:e.jsx(wt,{size:8})})]},j))}),D===h.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:j=>j.stopPropagation(),children:[A.filter(j=>!(h.tags||[]).includes(j)).map(j=>e.jsxs("button",{onClick:()=>le(h.id,j),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:["+ ",j]},j)),e.jsx("input",{type:"text",value:U,onChange:j=>q(j.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:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"&&U.trim()&&le(h.id,U.trim().toLowerCase())}}),e.jsx("button",{onClick:j=>{j.stopPropagation(),B(null),q("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{ref:j=>{x.current[h.id]=j},onClick:()=>{if(y===h.id)$(null);else{const j=x.current[h.id];if(j){const ce=j.getBoundingClientRect(),ct=window.innerHeight-ce.bottom;_(ct<160)}$(h.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(sa,{size:14})}),y===h.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>$(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 ${L?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{Y(h.id),K(h.name),$(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(Bs,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{B(D===h.id?null:h.id),$(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(ra,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Q({type:"delete-session",sessionId:h.id,sessionName:h.name}),$(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(Us,{size:14})," Delete"]})]})]})]})]},h.id)})]},M.label))}),e.jsx(ta,{open:!!w,title:(w==null?void 0:w.type)==="delete-session"?"Delete recording?":(w==null?void 0:w.type)==="remove-tag"?"Remove tag?":"",description:(w==null?void 0:w.type)==="delete-session"?`Are you sure you want to delete "${w.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code history, and conversation. This action cannot be undone.`:(w==null?void 0:w.type)==="remove-tag"?`Are you sure you want to remove the tag "${w.tag}" from this recording? You can add it back later.`:"",confirmLabel:(w==null?void 0:w.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Q(null),onConfirm:()=>{(w==null?void 0:w.type)==="delete-session"?ne.mutate(w.sessionId):(w==null?void 0:w.type)==="remove-tag"&&ke(w.sessionId,w.tag),Q(null)}})]})}function Ct({label:t,hint:o,shortcut:m,children:d}){const N=s.useRef(null),l=s.useRef(null),[S,y]=s.useState(null),[$,L]=s.useState(null),_=()=>{var z;const C=(z=N.current)==null?void 0:z.getBoundingClientRect();C&&y(C)},x=()=>{y(null),L(null)};return s.useLayoutEffect(()=>{if(!S||!l.current)return;const C=l.current.getBoundingClientRect(),z=8,D=S.bottom+z+C.height<=window.innerHeight-8||S.top-z-C.height<8,B=S.left+S.width/2,U=Math.max(8,Math.min(B-C.width/2,window.innerWidth-C.width-8));L({left:U,top:D?S.bottom+z:S.top-z-C.height,below:D,arrowX:Math.max(10,Math.min(B-U,C.width-10))})},[S,t,o,m]),e.jsxs("span",{ref:N,className:"inline-flex",onMouseEnter:_,onMouseLeave:x,onFocus:_,onBlur:x,children:[d,S&&mr.createPortal(e.jsxs("span",{ref:l,role:"tooltip",style:$?{left:$.left,top:$.top}:{left:0,top:0,visibility:"hidden"},className:"pointer-events-none fixed z-[75] animate-tooltip-in",children:[$&&e.jsx("span",{style:{left:$.arrowX},className:`absolute -translate-x-1/2 w-2 h-2 bg-[#111827] rotate-45 ring-1 ring-white/10 ${$.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,m&&e.jsx("kbd",{className:"px-1 py-px rounded bg-white/15 text-[10px] font-mono font-normal text-white/90",children:m})]}),o&&e.jsx("span",{className:"text-[11px] leading-snug text-white/70",children:o})]})]}),document.body)]})}const Pn={recorded:{icon:e.jsx(vt,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(na,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(vt,{size:14,className:"text-gray-400"}),label:"Draft"}},Dn={success:{icon:e.jsx(yt,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Ks,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(lt,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function li(t){return t.outcome&&Dn[t.outcome]?Dn[t.outcome]:Pn[t.status]||Pn.recorded}function ci(t){const o=Date.now()-t;return o<6e4?"Just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:o<6048e5?`${Math.floor(o/864e5)}d ago`:Zn(t)}function di(t){const o=new Date,m=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),d=m-864e5,N=m-7*864e5,l={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const S of t){const y=S.createdAt;y>=m?l.Today.push(S):y>=d?l.Yesterday.push(S):y>=N?l["This Week"].push(S):l.Earlier.push(S)}return Object.entries(l).filter(([,S])=>S.length>0).map(([S,y])=>({label:S,items:y}))}const ui=["login","checkout","search","smoke","regression","e2e","navigation","form"];function en({open:t,onClose:o,onLoad:m,activeSessionId:d}){const N=pn(),[l,S]=s.useState(""),[y,$]=s.useState(null),[L,_]=s.useState(!1),x=s.useRef({}),[C,z]=s.useState(null),[D,B]=s.useState(null),[U,q]=s.useState(""),[te,Y]=s.useState(null),[H,K]=s.useState(""),[w,Q]=s.useState(null),{data:G,isLoading:ee}=ea({queryKey:["mobile-recording-history"],queryFn:()=>Ca({limit:500}),enabled:t,refetchInterval:t?1e4:!1}),ne=Pr({mutationFn:Wn,onSuccess:()=>N.invalidateQueries({queryKey:["mobile-recording-history"]})}),ue=Pr({mutationFn:({id:M,data:h})=>Ta(M,h),onSuccess:()=>N.invalidateQueries({queryKey:["mobile-recording-history"]})}),oe=s.useMemo(()=>{const M=(G==null?void 0:G.recordings)||[];return Array.isArray(M)?M.filter(h=>h.status!=="draft"):[]},[G]),pe=s.useMemo(()=>{let M=oe;if(l){const h=l.toLowerCase();M=M.filter(X=>(X.name||"").toLowerCase().includes(h)||(X.url||"").toLowerCase().includes(h)||(X.device||"").toLowerCase().includes(h))}return C&&(M=M.filter(h=>Array.isArray(h.tags)&&h.tags.includes(C))),M},[oe,l,C]),b=s.useMemo(()=>{const M=new Set;return oe.forEach(h=>{Array.isArray(h.tags)&&h.tags.forEach(X=>M.add(X))}),Array.from(M).sort()},[oe]),A=s.useMemo(()=>{const M=new Set([...ui,...b]);return Array.from(M).sort()},[b]),R=s.useMemo(()=>di(pe),[pe]),W=async M=>{try{const h=await zr(M);h!=null&&h.recording&&(m(h.recording),o())}catch{}},le=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];j.includes(h)||(ue.mutate({id:M,data:{tags:[...j,h]}}),B(null),q(""))},ke=(M,h)=>{const X=oe.find(ce=>ce.id===M);if(!X)return;const j=Array.isArray(X.tags)?X.tags:[];ue.mutate({id:M,data:{tags:j.filter(ce=>ce!==h)}})};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(as,{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:oe.length})]}),e.jsx("button",{onClick:o,className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(xn,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:l,onChange:M=>S(M.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"})]}),b.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>z(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C?"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"}),b.map(M=>e.jsx("button",{onClick:()=>z(C===M?null:M),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${C===M?"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:M},M))]})]}),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(je,{size:20,className:"text-brand-400 animate-spin"})}):R.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(as,{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"})]}):R.map(M=>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:M.label})}),M.items.map(h=>{const X=li(h);return e.jsxs("div",{className:`flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer group transition-colors ${d===h.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(h.id),children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[te===h.id?e.jsx("input",{type:"text",value:H,onChange:j=>K(j.target.value),onClick:j=>j.stopPropagation(),onBlur:()=>{H.trim()&&H.trim()!==h.name&&ue.mutate({id:h.id,data:{name:H.trim()}}),Y(null)},onKeyDown:j=>{j.key==="Enter"&&j.target.blur(),j.key==="Escape"&&Y(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:j=>{j.stopPropagation(),Y(h.id),K(h.name)},title:"Double-click to rename",children:h.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[h.actionCount," steps"]}),e.jsx("span",{children:ci(h.createdAt)})]}),Array.isArray(h.tags)&&h.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:j=>j.stopPropagation(),children:h.tags.map(j=>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:[j,e.jsx("button",{onClick:()=>Q({type:"remove-tag",sessionId:h.id,tag:j}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${j}"`,children:e.jsx(wt,{size:8})})]},j))}),D===h.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:j=>j.stopPropagation(),children:[A.filter(j=>!(h.tags||[]).includes(j)).map(j=>e.jsxs("button",{onClick:()=>le(h.id,j),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:["+ ",j]},j)),e.jsx("input",{type:"text",value:U,onChange:j=>q(j.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:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"&&U.trim()&&le(h.id,U.trim().toLowerCase())}}),e.jsx("button",{onClick:j=>{j.stopPropagation(),B(null),q("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{ref:j=>{x.current[h.id]=j},onClick:()=>{if(y===h.id)$(null);else{const j=x.current[h.id];if(j){const ce=j.getBoundingClientRect(),ct=window.innerHeight-ce.bottom;_(ct<160)}$(h.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(sa,{size:14})}),y===h.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>$(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 ${L?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{Y(h.id),K(h.name),$(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(Bs,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{B(D===h.id?null:h.id),$(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(ra,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Q({type:"delete-session",sessionId:h.id,sessionName:h.name}),$(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(Us,{size:14})," Delete"]})]})]})]})]},h.id)})]},M.label))}),e.jsx(ta,{open:!!w,title:(w==null?void 0:w.type)==="delete-session"?"Delete recording?":(w==null?void 0:w.type)==="remove-tag"?"Remove tag?":"",description:(w==null?void 0:w.type)==="delete-session"?`Are you sure you want to delete "${w.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code, and healing manifest references. This action cannot be undone.`:(w==null?void 0:w.type)==="remove-tag"?`Are you sure you want to remove the tag "${w.tag}" from this recording? You can add it back later.`:"",confirmLabel:(w==null?void 0:w.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Q(null),onConfirm:()=>{(w==null?void 0:w.type)==="delete-session"?ne.mutate(w.sessionId):(w==null?void 0:w.type)==="remove-tag"&&ke(w.sessionId,w.tag),Q(null)}})]}):null}function tn({screenshot:t,screenshotSize:o,elementRect:m,step:d,description:N,onClose:l}){const S=s.useRef(null),[y,$]=s.useState(null);s.useEffect(()=>{const x=C=>{C.key==="Escape"&&l()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[l]),s.useLayoutEffect(()=>{if(!S.current)return;const x=()=>{var D;const z=(D=S.current)==null?void 0:D.getBoundingClientRect();z&&$({width:z.width,height:z.height})};x(),window.addEventListener("resize",x);const C=setInterval(x,250);return()=>{window.removeEventListener("resize",x),clearInterval(C)}},[]);const L=(()=>{if(!m||!o||!y)return null;const x=y.width/o.width,C=y.height/o.height;return{left:m.x*x,top:m.y*C,width:m.width*x,height:m.height*C}})(),_=e.jsx("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/70 backdrop-blur-sm",onClick:l,role:"dialog","aria-label":`Step ${d} screenshot`,children:e.jsxs("div",{className:"relative max-w-[92vw] max-h-[92vh] flex flex-col",onClick:x=>x.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:N}),e.jsx("button",{onClick:l,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(wt,{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:S,src:t,alt:N,className:"block max-w-[92vw] max-h-[82vh] w-auto h-auto",draggable:!1}),L&&e.jsx("div",{className:"absolute pointer-events-none border-[3px] border-red-400 rounded-sm",style:{left:L.left,top:L.top,width:L.width,height:L.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 mr.createPortal(_,document.body)}function Fn({entries:t,busy:o,onPermission:m,onOpenScreenshot:d}){const N=s.useRef(null);return s.useEffect(()=>{N.current&&(N.current.scrollTop=N.current.scrollHeight)},[t,o]),t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500 text-sm gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:14,className:"animate-spin"}),"Waiting for the AI to start…"]}):e.jsx(e.Fragment,{children:"No output yet."})}):e.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto p-4 space-y-1",children:[t.map(l=>e.jsx(pi,{entry:l,onPermission:m,onOpenScreenshot:d},l.id)),o&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 mt-3 px-4",children:[e.jsx(je,{size:11,className:"animate-spin"}),"Streaming…"]})]})}function pi({entry:t,onPermission:o,onOpenScreenshot:m}){return t.kind==="recorded-action"?e.jsx(mi,{entry:t,onOpenScreenshot:m}):t.kind==="system"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx(pr,{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(pr,{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(ca,{text:t.content})})}):t.kind==="tool"?e.jsx(fi,{entry:t}):t.kind==="file-diff"?e.jsx("div",{className:"py-1",children:e.jsx(Uo,{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"&&o?e.jsx(hi,{entry:t,onPermission:o}):t.kind==="permission"?null:t.kind==="error"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx(Hs,{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 xi={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 mi({entry:t,onOpenScreenshot:o}){const m=t.actionType==="tap"?Dr:t.actionType==="type"?Bs:t.actionType==="swipe"?mn:t.actionType==="assertion"?Gs:t.actionType==="annotation"?Or:fn,d=xi[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:()=>o==null?void 0:o({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(m,{size:12,className:"text-gray-500"})}),e.jsx(m,{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 fi({entry:t}){const[o,m]=s.useState(!1),d=t.phase==="start"?e.jsx(je,{size:11,className:"animate-spin text-blue-400"}):t.phase==="complete"?e.jsx(yt,{size:11,className:"text-emerald-400"}):t.phase==="error"?e.jsx(Ks,{size:11,className:"text-red-400"}):e.jsx(aa,{size:11,className:"text-amber-400"}),N=!!(t.result||t.error||t.args);return e.jsxs("div",{className:"my-0.5",children:[e.jsxs("button",{onClick:()=>N&&m(l=>!l),className:`inline-flex max-w-full items-center gap-2 px-4 py-1.5 rounded-lg text-left transition-colors ${N?"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}),N&&t.phase!=="start"&&e.jsx(hs,{size:10,className:`text-gray-600 transition-transform ${o?"rotate-180":""}`})]}),o&&N&&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 hi({entry:t,onPermission:o}){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(aa,{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(So,{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:()=>o(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:()=>o(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:()=>o(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 ua({value:t,onChange:o,disabled:m=!1}){const d=m?"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 ${m?"opacity-50":""}`,title:d,children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="web",disabled:m,onClick:()=>o("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(hn,{size:12}),"Web"]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="mobile",disabled:m,onClick:()=>o("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(on,{size:12}),"Mobile"]})]})}function pa(t){const[o,m]=s.useState([]),[d,N]=s.useState((t==null?void 0:t.provider)||""),[l,S]=s.useState(t!=null&&t.provider&&t.model||""),y=s.useRef(!!(t!=null&&t.provider));return s.useEffect(()=>{let L=!0;return $a().then(_=>{var D;if(!L)return;const x=[],C=_.effectiveProvider||_.defaultProvider;for(const[B,U]of Object.entries(_.providers||{})){if(Qo.has(B))continue;const q=U;if(!q.hasApiKey&&!q.isLocal)continue;if(B==="testver"){x.push({provider:B,models:[""]});continue}const te=Array.isArray(q.models)&&q.models.length>0?q.models:[q.model].filter(Boolean);te.length>0&&x.push({provider:B,models:te})}m(x);const z=(D=_.providers)==null?void 0:D[C];z&&!y.current&&(N(C),S(C==="testver"?"":z.activeModel||z.model||""))}).catch(()=>{}),()=>{L=!1}},[]),{providerModels:o,selectedProvider:d,selectedModel:l,select:(L,_)=>{N(L),S(_)},setSelectedProvider:N,setSelectedModel:S}}function dn({providerModels:t,selectedProvider:o,selectedModel:m,onPick:d,disabled:N=!1,title:l="Select model for code generation",size:S="md"}){const[y,$]=s.useState(!1),L=s.useRef(null);if(s.useEffect(()=>{if(!y)return;const x=C=>{var z;C.key==="Escape"&&(C.stopPropagation(),$(!1),(z=L.current)==null||z.focus())};return document.addEventListener("keydown",x,!0),()=>document.removeEventListener("keydown",x,!0)},[y]),s.useEffect(()=>{N&&$(!1)},[N]),t.length===0)return null;const _=o==="testver"?"Testver":m||"Model";return e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs("button",{ref:L,type:"button",onClick:()=>$(x=>!x),disabled:N,"aria-haspopup":"listbox","aria-expanded":y,"aria-label":`Model: ${_}`,className:`flex items-center gap-1.5 px-2.5 ${S==="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:l,children:[e.jsx(En,{provider:o,size:14}),e.jsx("span",{className:"truncate",children:_}),e.jsx(hs,{size:11,className:`flex-shrink-0 transition-transform ${y?"rotate-180":""}`})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>$(!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(x=>e.jsxs("div",{role:"group","aria-label":x.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(En,{provider:x.provider,size:14}),x.provider]}),x.models.map(C=>{const z=C===m&&x.provider===o;return e.jsxs("button",{type:"button",role:"option","aria-selected":z,onClick:()=>{var D;d(x.provider,C),$(!1),(D=L.current)==null||D.focus()},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-sm font-mono transition-colors ${z?"bg-brand-500/10 text-brand-300":"text-gray-400 hover:bg-brand-500/10 hover:text-gray-200"}`,children:[z&&e.jsx(yt,{size:12,className:"text-brand-400 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:x.provider==="testver"?"Testver — managed model":C})]},`${x.provider}-${C}`)})]},x.provider))})]})]})}const gi={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 ur({icon:t,label:o,hint:m,onClick:d,disabled:N=!1,compact:l=!1,tone:S="ghost"}){return e.jsx(Ct,{label:o,hint:m,children:e.jsxs("button",{type:"button",onClick:d,disabled:N,"aria-label":o,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 ${l?"w-8":"px-3"} ${gi[S]}`,children:[t,!l&&e.jsx("span",{children:o})]})})}function Hr({kind:t,size:o=12}){return t==="data"?e.jsx(xr,{size:o,className:"text-teal-500 flex-shrink-0"}):t==="test"?e.jsx(Ro,{size:o,className:"text-blue-500 flex-shrink-0"}):t==="step"?e.jsx(Co,{size:o,className:"text-violet-500 flex-shrink-0"}):e.jsx(To,{size:o,className:"text-indigo-500 flex-shrink-0"})}function Ln(t,o){const m=t.slice(0,o),d=/(^|[\s(])@([^\s@]{0,60})$/.exec(m);return d?{start:m.length-d[2].length-1,query:d[2]}:null}function xa({value:t,onChange:o,references:m,onReferencesChange:d,placeholder:N,rows:l=3,autoFocus:S=!1,kinds:y,ariaLabel:$,onSubmit:L,textareaRef:_,size:x="md"}){const C=s.useRef(null),z=_??C,[D,B]=s.useState(null),[U,q]=s.useState([]),[te,Y]=s.useState(!1),[H,K]=s.useState(0),w=s.useRef(0),Q=s.useRef(null),[G,ee]=s.useState(null),ne=()=>{const b=z.current;if(!b)return;const A=b.getBoundingClientRect(),R=260,W=window.innerHeight-A.bottom-12,le=A.top-12,ke=W<Math.min(R,180)&&le>W;ee(ke?{left:A.left,width:A.width,bottom:window.innerHeight-A.top+4,maxHeight:Math.min(R,le)}:{left:A.left,width:A.width,top:A.bottom+4,maxHeight:Math.max(120,Math.min(R,W))})};s.useLayoutEffect(()=>{if(!D){ee(null);return}ne()},[D!==null,t]),s.useEffect(()=>{if(!D)return;const b=A=>{var R;(R=Q.current)!=null&&R.contains(A.target)||ne()};return window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[D!==null]),s.useEffect(()=>{var b,A;(A=(b=Q.current)==null?void 0:b.querySelector('[aria-selected="true"]'))==null||A.scrollIntoView({block:"nearest"})},[H]),s.useEffect(()=>{var b;S&&((b=z.current)==null||b.focus())},[S,z]),s.useEffect(()=>{if(!D){q([]);return}const b=++w.current;Y(!0);const A=setTimeout(()=>{Vn(D.query,y,20).then(R=>{w.current===b&&(q(R.items||[]),K(0))}).catch(()=>{w.current===b&&q([])}).finally(()=>{w.current===b&&Y(!1)})},150);return()=>clearTimeout(A)},[D==null?void 0:D.query,D!==null]);const ue=(b,A)=>{o(b),B(Ln(b,A))},oe=b=>{const A=z.current;if(!A||!D)return;const R=A.selectionStart??t.length,W=`@${b.kind==="method"&&b.name?b.className?`${b.className}.${b.name}`:b.name:b.label} `,le=t.slice(0,D.start)+W+t.slice(R);o(le);const{detail:ke,...M}=b;m.some(h=>h.kind===b.kind&&h.label===b.label)||d([...m,M]),B(null),requestAnimationFrame(()=>{A.focus();const h=D.start+W.length;A.setSelectionRange(h,h)})},pe=b=>{if(D&&U.length>0){if(b.key==="ArrowDown"){b.preventDefault(),K(A=>(A+1)%U.length);return}if(b.key==="ArrowUp"){b.preventDefault(),K(A=>(A-1+U.length)%U.length);return}if(b.key==="Enter"||b.key==="Tab"){b.preventDefault(),oe(U[H]);return}}if(D&&b.key==="Escape"){b.preventDefault(),b.stopPropagation(),B(null);return}b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&L&&(b.preventDefault(),L())};return e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:z,value:t,rows:l,"aria-label":$,placeholder:N,onChange:b=>ue(b.target.value,b.target.selectionStart??b.target.value.length),onClick:b=>B(Ln(t,b.target.selectionStart??t.length)),onKeyDown:pe,onBlur:()=>setTimeout(()=>B(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 ${x==="lg"?"px-4 py-3 text-[15px] leading-relaxed":"px-3 py-2 text-sm"}`}),D&&G&&mr.createPortal(e.jsxs("div",{ref:Q,role:"listbox","aria-label":"Project code and data",onMouseDown:b=>b.preventDefault(),style:{left:G.left,width:G.width,top:G.top,bottom:G.bottom,maxHeight:G.maxHeight},className:"fixed z-[90] overflow-y-auto rounded-lg border border-white/10 bg-surface-1 shadow-xl py-1",children:[te&&U.length===0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-gray-500",children:[e.jsx(je,{size:12,className:"animate-spin"})," Searching the project…"]}),!te&&U.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:D.query?`Nothing in the project matches "${D.query}".`:"Type a name to search page objects, helpers, tests and test data."}),U.map((b,A)=>e.jsxs("button",{type:"button",role:"option","aria-selected":A===H,onMouseDown:R=>{R.preventDefault(),oe(b)},onMouseEnter:()=>K(A),className:`w-full flex items-start gap-2 px-3 py-1.5 text-left ${A===H?"bg-brand-500/10":"hover:bg-white/5"}`,children:[e.jsx("span",{className:"mt-0.5",children:e.jsx(Hr,{kind:b.kind,size:x==="lg"?14:12})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block font-mono text-gray-200 truncate ${x==="lg"?"text-sm":"text-xs"}`,children:b.label}),e.jsx("span",{className:`block text-gray-500 truncate ${x==="lg"?"text-xs":"text-[10px]"}`,children:b.detail})]})]},`${b.kind}:${b.label}:${b.file}`))]}),document.body),m.length>0&&e.jsx("div",{className:`flex flex-wrap mt-1.5 ${x==="lg"?"gap-1.5":"gap-1"}`,children:m.map(b=>e.jsxs("span",{className:`inline-flex items-center gap-1 max-w-full rounded border border-white/10 bg-surface-2 text-gray-300 ${x==="lg"?"px-2 py-1 text-xs":"px-1.5 py-0.5 text-[11px]"}`,title:b.file?`${b.file}${b.line?`:${b.line}`:""}`:b.label,children:[e.jsx(Hr,{kind:b.kind,size:x==="lg"?13:11}),e.jsx("span",{className:"font-mono truncate",children:b.label}),e.jsx("button",{type:"button","aria-label":`Remove reference ${b.label}`,onClick:()=>d(m.filter(A=>!(A.kind===b.kind&&A.label===b.label))),className:"text-gray-500 hover:text-red-400",children:e.jsx(wt,{size:10})})]},`${b.kind}:${b.label}`))})]})}const Er=[{kind:"reuse",label:"Use existing step",icon:e.jsx($o,{size:15}),placeholder:"e.g. Log in as Admin using @LoginPage.loginAs"},{kind:"data",label:"Test data",icon:e.jsx(xr,{size:15}),placeholder:"e.g. Pick the first in-stock product from @data/products.json"},{kind:"email",label:"Email / code",icon:e.jsx(Ao,{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(Io,{size:15}),placeholder:"e.g. Create a user with POST /api/users and keep its id"},{kind:"wait",label:"Wait for",icon:e.jsx(Eo,{size:15}),placeholder:'e.g. Wait until the order status shows "Shipped" (up to 60 s)'},{kind:"custom",label:"Custom",icon:e.jsx(zo,{size:15}),placeholder:"Describe what the test does at this point…"}],sn=[{value:"link",label:"the link in it",name:"emailLink"},{value:"code",label:"the verification code",name:"emailCode"},{value:"text",label:"its text",name:"emailText"}],bi=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/;function ma({open:t,mode:o,initial:m,replaceCount:d=0,onCancel:N,onSave:l}){const[S,y]=s.useState("custom"),[$,L]=s.useState(""),[_,x]=s.useState([]),[C,z]=s.useState(""),[D,B]=s.useState(""),[U,q]=s.useState(""),[te,Y]=s.useState("link"),[H,K]=s.useState(!1),[w,Q]=s.useState(null),G=s.useRef(null);s.useEffect(()=>{t&&(y((m==null?void 0:m.customKind)||"custom"),L((m==null?void 0:m.instruction)||""),x((m==null?void 0:m.references)||[]),z(((m==null?void 0:m.outputs)||[]).join(", ")),B(""),q(""),Y("link"),K(!1),Q(null))},[t]),s.useEffect(()=>{if(!t)return;const R=W=>{W.key==="Escape"&&!H&&N()};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[t,H,N]);const ee=(R,W,le)=>{const ke=sn.find(ce=>ce.value===le),M=R.trim()?` with subject containing "${R.trim()}"`:"",h=W.trim()?` sent to ${W.trim()}`:"";L(`Read the latest email${h}${M} and keep ${ke.label}`);const X=C.split(",").map(ce=>ce.trim()).filter(Boolean),j=sn.map(ce=>ce.name);(X.length===0||X.every(ce=>j.includes(ce)))&&z(ke.name)};if(!t)return null;const ne=C.split(",").map(R=>R.trim().replace(/^\{+|\}+$/g,"")).filter(Boolean),ue=ne.find(R=>!bi.test(R)),oe=$.trim().length>0&&!ue&&!H,pe=o==="edit"?"Edit custom step":o==="replace"?`Replace ${d} step${d===1?"":"s"} with a custom step`:"Add custom step",b=Er.find(R=>R.kind===S)??Er[Er.length-1],A=async()=>{if(oe){K(!0),Q(null);try{await l({instruction:$.trim(),customKind:S,references:_,outputs:ne})}catch(R){Q(String((R==null?void 0:R.message)||R).replace(/^Error:\s*/,"")),K(!1)}}};return mr.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:()=>!H&&N()}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":pe,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(Ut,{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:pe}),e.jsx("p",{className:"text-sm text-gray-400 mt-1 leading-relaxed",children:o==="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:N,disabled:H,"aria-label":"Close",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5",children:e.jsx(wt,{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:Er.map(R=>e.jsxs("button",{type:"button",role:"radio","aria-checked":S===R.kind,onClick:()=>{var W;y(R.kind),R.kind==="email"&&!$.trim()&&ee(D,U,te),(W=G.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 ${S===R.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:[R.icon,R.label]},R.kind))}),S==="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:D,onChange:R=>{B(R.target.value),ee(R.target.value,U,te)},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:U,onChange:R=>{q(R.target.value),ee(D,R.target.value,te)},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:te,onChange:R=>{const W=R.target.value;Y(W),ee(D,U,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:sn.map(R=>e.jsx("option",{value:R.value,children:R.label},R.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(xa,{textareaRef:G,value:$,onChange:L,references:_,onReferencesChange:x,placeholder:b.placeholder,rows:S==="email"?3:5,size:"lg",autoFocus:!0,ariaLabel:"What the step does",onSubmit:A}),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:C,onChange:R=>z(R.target.value),placeholder:"e.g. resetLink, otpCode","aria-invalid":!!ue,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 ${ue?"border-red-500/50":"border-white/10 focus:border-brand-500/50"}`}),e.jsx("p",{className:`text-xs mt-2 leading-relaxed ${ue?"text-red-500 dark:text-red-400":"text-gray-500"}`,children:ue?`"${ue}" 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."}),w&&e.jsx("p",{role:"alert",className:"mt-4 text-sm text-red-600 dark:text-red-400",children:w})]}),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:N,disabled:H,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:A,disabled:!oe,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:[H&&e.jsx(je,{size:14,className:"animate-spin"}),o==="edit"?"Save":o==="replace"?"Replace steps":"Add step"]})]})]})]}),document.body)}function fa({current:t,options:o,onPick:m,disabled:d=!1}){const[N,l]=s.useState(!1),[S,y]=s.useState(null),$=s.useRef(null),L=s.useRef(null),_=()=>{var z;if(N){l(!1);return}const C=(z=$.current)==null?void 0:z.getBoundingClientRect();if(C){const B=Math.max(8,Math.min(C.right-288,window.innerWidth-288-8)),U=window.innerHeight-C.bottom;y(U<260&&C.top>U?{left:B,bottom:window.innerHeight-C.top+4}:{left:B,top:C.bottom+4})}l(!0)};s.useEffect(()=>{if(!N)return;const C=B=>{var U;B.key==="Escape"&&(B.stopPropagation(),l(!1),(U=$.current)==null||U.focus())},z=B=>{var U,q;!((U=L.current)!=null&&U.contains(B.target))&&!((q=$.current)!=null&&q.contains(B.target))&&l(!1)},D=B=>{var U;(U=L.current)!=null&&U.contains(B.target)||l(!1)};return document.addEventListener("keydown",C,!0),document.addEventListener("mousedown",z),window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),()=>{document.removeEventListener("keydown",C,!0),document.removeEventListener("mousedown",z),window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D)}},[N]);const x=C=>{var z;m(C),l(!1),(z=$.current)==null||z.focus()};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:$,type:"button",disabled:d,onClick:C=>{C.stopPropagation(),_()},title:"Use a value for this step","aria-label":"Use a value for this step","aria-haspopup":"listbox","aria-expanded":N,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(Mo,{size:14})}),N&&S&&mr.createPortal(e.jsxs("div",{ref:L,role:"listbox","aria-label":"Values",onClick:C=>C.stopPropagation(),style:{left:S.left,top:S.top,bottom:S.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:()=>x(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(An,{size:12,className:"text-brand-500"})}),"The value recorded (as typed)"]}),o.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."}),o.map(C=>e.jsxs("button",{type:"button",role:"option","aria-selected":t===C.name,onClick:()=>x(C.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===C.name&&e.jsx(An,{size:12,className:"text-brand-500"})}),C.source==="data"?e.jsx(xr,{size:12,className:"text-teal-500 flex-shrink-0"}):e.jsx(Ut,{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:`{${C.name}}`}),e.jsx("span",{className:"block text-[10px] text-gray-500 truncate",children:C.detail})]})]},C.name))]}),document.body)]})}function ha({settings:t,onChange:o,inputs:m,onMatch:d,disabled:N=!1}){var ue,oe,pe,b;const[l,S]=s.useState(!1),[y,$]=s.useState(""),[L,_]=s.useState([]),[x,C]=s.useState(!1),[z,D]=s.useState(!1),[B,U]=s.useState(null),[q,te]=s.useState(null),[Y,H]=s.useState(!!((ue=t==null?void 0:t.before)!=null&&ue.text)),K=s.useRef(null),w=t==null?void 0:t.testData,Q=s.useRef(t);Q.current=t;const G=A=>{const R={...Q.current||{},...A};R.testData||delete R.testData,(!R.before||!R.before.text.trim())&&delete R.before;const W=R.testData||R.before?R:null;Q.current=W,o(W)};s.useEffect(()=>{if(!l)return;let A=!0;C(!0);const R=setTimeout(()=>{Vn(y,["data"],25).then(W=>{A&&_(W.items||[])}).catch(()=>{A&&_([])}).finally(()=>{A&&C(!1)})},150);return()=>{A=!1,clearTimeout(R)}},[l,y]),s.useEffect(()=>{var A;l&&((A=K.current)==null||A.focus())},[l]),s.useEffect(()=>{if(!(w!=null&&w.file)){te(null);return}let A=!0;return gn(w.file).then(R=>{A&&te({columns:R.columns,values:R.firstRow,rowCount:R.rowCount})}).catch(()=>{A&&te(null)}),()=>{A=!1}},[w==null?void 0:w.file]);const ee=async A=>{D(!0),U(null);try{const R=await gn(A);G({testData:{file:R.file,columns:R.columns,perRow:!1}}),te({columns:R.columns,values:R.firstRow,rowCount:R.rowCount}),S(!1),$("")}catch(R){U(String((R==null?void 0:R.message)||R).replace(/^Error:\s*/,""))}finally{D(!1)}},ne=[];if(q)for(const A of m){if(A.valueFrom||!A.value)continue;const R=q.values.findIndex(W=>W&&W===A.value);R>=0&&ne.push({id:A.id,valueFrom:`data.${q.columns[R]}`})}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)"})]})}),!w&&!l&&e.jsxs("button",{type:"button",disabled:N,onClick:()=>S(!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(fr,{size:12})," Read the data from a file"]}),l&&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(xn,{size:12,className:"text-gray-500"}),e.jsx("input",{ref:K,value:y,onChange:A=>$(A.target.value),placeholder:"Search test-data files…",onKeyDown:A=>{A.key==="Escape"&&(A.stopPropagation(),S(!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:()=>S(!1),className:"text-gray-500 hover:text-gray-200",children:e.jsx(wt,{size:12})})]}),e.jsxs("div",{className:"max-h-44 overflow-y-auto py-1",children:[(x||z)&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-xs text-gray-500",children:[e.jsx(je,{size:12,className:"animate-spin"})," ",z?"Reading columns…":"Searching…"]}),!x&&L.length===0&&e.jsxs("div",{className:"px-3 py-2 text-xs text-gray-500",children:["No test-data files found",y?` for "${y}"`:"",". Files show up here once the Data Map has scanned them."]}),L.map(A=>e.jsxs("button",{type:"button",onClick:()=>ee(A.file||A.label),disabled:z,className:"w-full flex items-start gap-2 px-3 py-1.5 text-left hover:bg-white/5",children:[e.jsx(xr,{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:A.label}),e.jsx("span",{className:"block text-[10px] text-gray-500 truncate",children:A.detail})]})]},A.label))]})]}),B&&e.jsx("p",{role:"alert",className:"text-xs text-red-600 dark:text-red-400 mt-1",children:B}),w&&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(xr,{size:13,className:"text-teal-500 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-mono text-gray-200 truncate flex-1",title:w.file,children:w.file}),e.jsx("button",{type:"button",disabled:N,"aria-label":"Remove test data",onClick:()=>G({testData:void 0}),className:"text-gray-500 hover:text-red-400",children:e.jsx(wt,{size:13})})]}),!!((oe=w.columns)!=null&&oe.length)&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[w.columns.slice(0,10).map(A=>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.${A}`},A)),w.columns.length>10&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:["+",w.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:N,checked:!!w.perRow,onChange:A=>G({testData:{...w,perRow:A.target.checked}})}),"Run the test once per row",q!=null&&q.rowCount?` (${q.rowCount})`:""]}),ne.length>0&&e.jsxs("button",{type:"button",disabled:N,onClick:()=>d(ne),className:"inline-flex items-center gap-1 text-xs text-teal-600 dark:text-teal-400 hover:underline",children:[e.jsx(Po,{size:12})," Use the data for ",ne.length," recorded value",ne.length===1?"":"s"]})]})]})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>H(A=>!A),"aria-expanded":Y,className:"inline-flex items-center gap-1 text-[10px] text-gray-500 uppercase tracking-wider hover:text-gray-300",children:[e.jsx(hs,{size:11,className:`transition-transform ${Y?"":"-rotate-90"}`}),"Before the test ",e.jsx("span",{className:"normal-case",children:"(optional)"})]}),Y&&e.jsx("div",{className:"mt-1",children:e.jsx(xa,{value:((pe=t==null?void 0:t.before)==null?void 0:pe.text)||"",onChange:A=>{var R,W;return G({before:{text:A,references:(W=(R=Q.current)==null?void 0:R.before)==null?void 0:W.references}})},references:((b=t==null?void 0:t.before)==null?void 0:b.references)||[],onReferencesChange:A=>{var R,W;return G({before:{text:((W=(R=Q.current)==null?void 0:R.before)==null?void 0:W.text)||"",references:A}})},placeholder:"e.g. Start logged in as a Manager using @loginAs",rows:2,ariaLabel:"Before the test"})})]})]})}const yi=!1;function vi({onPhaseChange:t,registerControls:o}){const{toast:m}=un(),[d,N]=s.useState([]),[l,S]=s.useState("browserstack"),[y,$]=s.useState([]),[L,_]=s.useState([]),[x,C]=s.useState(""),[z,D]=s.useState(""),[B,U]=s.useState(!1),[q,te]=s.useState(null),Y=s.useRef(null),[H,K]=s.useState("setup"),[w,Q]=s.useState(null),[G,ee]=s.useState([]),[ne,ue]=s.useState(!1),[oe,pe]=s.useState(!1),[b,A]=s.useState(!1),[R,W]=s.useState(0),le=s.useRef(0),ke=s.useRef(()=>{}),M=s.useCallback(n=>{const i=Math.floor(n/1e3)!==Math.floor(le.current/1e3);le.current=n,i&&ke.current()},[]),[h,X]=s.useState(!1),[j,ce]=s.useState([]),[ct,gs]=s.useState("wdio-appium-ts"),[os,Ws]=s.useState(null),[ve,Tt]=s.useState(null),[Kt,st]=s.useState(!1),[we,$t]=s.useState(!1),[Ye,is]=s.useState(""),[be,He]=s.useState(""),[Ie,Oe]=s.useState("auto"),[$e,ls]=s.useState(""),{data:Me}=da(),[dt,Gt]=s.useState(!1),[ut,Wt]=s.useState(""),[Ne,bs]=s.useState(""),[At,Vt]=s.useState(new Set),[ys,It]=s.useState([]),[Vs,Et]=s.useState(!1),{providerModels:vs,selectedModel:Qe,selectedProvider:rt,select:ws}=pa(),[pt,Be]=s.useState(!1),[xt,js]=s.useState(""),Ys=s.useRef(null),[mt,me]=s.useState([]),[Qs,ks]=s.useState(null),[ze,jt]=s.useState(!1),hr=s.useRef(!1);hr.current=ze;const[Xs,Ue]=s.useState(null),[nt,cs]=s.useState(""),Ke=s.useRef(null),zt=s.useRef([]);s.useEffect(()=>{zt.current=mt},[mt]);const[Js,ds]=s.useState(!1),[gr,Ns]=s.useState({}),[br,Mt]=s.useState(!1),[at,Ss]=s.useState(null),Yt=s.useRef([]),[kt,Rs]=s.useState(null),Zs=s.useRef(null);s.useEffect(()=>{Zs.current=kt},[kt]);const[Pe,De]=s.useState(!1),ye=Gn(),Pt=s.useRef(null),Qt=s.useRef(null),Fe=s.useRef(new Set),Dt=s.useRef(()=>{}),er=n=>{Xn(n).catch(()=>{})},Ge=()=>{for(const n of Fe.current)er(n);Fe.current=new Set},[Ae,se]=s.useState(null),[Ft,he]=s.useState(null),[ie,xe]=s.useState(!1),[We,Cs]=s.useState(""),[us,Ts]=s.useState(""),[ot,ps]=s.useState(null),[Xt,it]=s.useState(""),[yr,ft]=s.useState(!1),[Xe,Lt]=s.useState(null),Le=s.useRef(null),Se=s.useRef(0),Re=pn(),[Ce,_e]=s.useState(null),[qe,Ve]=s.useState(new Set),[Nt,re]=s.useState(null),xs=s.useRef(null),[$s,As]=s.useState(null),[ms,vr]=s.useState("above"),[wr,Je]=s.useState(null),[tr,sr]=s.useState(null),Is=s.useRef(null),[Te,_t]=s.useState(null);s.useEffect(()=>{(async()=>{try{await Yn().catch(()=>null),await wa();const[n,i,c,P,u]=await Promise.all([Aa(),bn(),yn().catch(()=>({session:null})),vn().catch(()=>({recording:!1,startedAt:0,actions:[]})),Ia().catch(()=>({formatters:[]}))]);if(N(n.providers),_(i.apps),ce(u.formatters),c.session&&Q(c.session),P.recording&&P.actions&&P.actions.length>0)ee(P.actions),W(P.startedAt),K("recording"),re(P.settings||null),Le.current=wn();else if(!await va())try{const O=await zr(wn());O.recording&&O.recording.status==="draft"&&O.recording.actionCount>0&&(Lt({id:O.recording.id,name:O.recording.name,actionCount:O.recording.actionCount,url:O.recording.url||O.recording.device}),X(!0))}catch{}const I=n.providers.find(O=>O.hasCredentials&&O.enabled);I&&S(I.id)}catch(n){se(n.message)}})()},[]);const Es=s.useRef([]);s.useEffect(()=>{Es.current=G},[G]);const zs=s.useRef(null);s.useEffect(()=>{zs.current=w},[w]),s.useEffect(()=>{if(H!=="recording"||ne)return;const n=()=>{var u,I;if(Es.current.length===0)return;const P=Le.current||Xr();Le.current=P,Ar({id:P,name:`Draft — ${((u=zs.current)==null?void 0:u.device)||"mobile recording"}`,status:"draft",url:(I=zs.current)==null?void 0:I.device}).then(()=>Re.invalidateQueries({queryKey:["mobile-recording-history"]})).catch(()=>{})},i=setTimeout(n,1500),c=setInterval(n,1e4);return()=>{clearTimeout(i),clearInterval(c)}},[H,ne,Re]);const Ms=s.useCallback(async n=>{U(!0),se(null);try{const c=[...(await Ea(n)).devices].sort((u,I)=>u.realMobile!==I.realMobile?u.realMobile?-1:1:u.name.localeCompare(I.name));$(c);const P=c.filter(u=>!u.unavailableReason);if(!x||!c.some(u=>u.id===x)){const u=P.find(I=>I.realMobile&&/iphone 15/i.test(I.name))||P.find(I=>I.realMobile&&/pixel/i.test(I.name))||P[0];C((u==null?void 0:u.id)??"")}}catch(i){se(i.message),$([])}finally{U(!1)}},[x]);s.useEffect(()=>{const n=d.find(i=>i.id===l);n!=null&&n.hasCredentials?Ms(l):$([])},[l,d,Ms]),s.useEffect(()=>{if(H!=="recording"||ne||R===0)return;const n=setInterval(()=>M(Date.now()-R),250);return()=>clearInterval(n)},[H,ne,R]);const Ps=s.useRef(null),jr=s.useRef(!0),Br=()=>{const n=Ps.current;n&&(jr.current=n.scrollHeight-n.scrollTop-n.clientHeight<120)};s.useEffect(()=>{const n=Ps.current;!n||H!=="recording"||!jr.current||requestAnimationFrame(()=>{n.scrollTo({top:n.scrollHeight,behavior:"smooth"})})},[G.length,H]),s.useEffect(()=>{const n=i=>{const c=i.detail;c!=null&&c.action&&(ee(P=>P.some(u=>u.index===c.action.index)?P:[...P,c.action]),c.action.type==="assertion"&&(pe(!1),kn(!1).catch(()=>{})))};return window.addEventListener("testver-mobile-action",n),()=>window.removeEventListener("testver-mobile-action",n)},[]),s.useEffect(()=>{window.__testver_mobile_record_paused=ne},[ne]),s.useEffect(()=>{window.__testver_mobile_assert_mode=oe,window.__testver_mobile_annotate_mode=b},[oe,b]);const Ur=async n=>{xe(!0),se(null),te(0),he(`Uploading ${n.name}…`);try{const i=await Ua(n,void 0,P=>te(P)),c=await bn();_(c.apps),D(i.id),he(`Added ${n.name}.`)}catch(i){se(i.message),he(null)}finally{xe(!1),te(null)}},kr=async()=>{const n=y.find(i=>i.id===x);if(!n){se("Pick a device first.");return}if(!z){se("Pick or upload an app first.");return}xe(!0),K("starting"),se(null),he(l==="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 i=w;i||(i=(await Ka({provider:l,deviceKey:n.rawDeviceKey,osVersion:n.os,platform:n.platform,appId:z,sessionName:"Testver AI Record"})).session,Q(i));const c=await Ga();Le.current=Xr(),Se.current=0,re(null),Ve(new Set),ee(c.actions),W(c.startedAt),M(0),ue(!1),pe(!1),A(!1),Ws(null),Tt(null),X(!1),K("recording"),he(`Recording on ${n.name} (${n.os}). Click on the device to capture taps.`),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"recorder-page"}}))}catch(i){se(i.message),he(null),K("setup")}finally{xe(!1)}},Ds=s.useCallback(()=>{ue(!0),Se.current=Date.now(),he("Recording paused."),jn(!0).catch(n=>{ue(!1),Se.current=0,se(`Couldn't pause the recording: ${n.message}`)})},[]),Nr=s.useCallback(()=>{const n=Se.current;n&&W(i=>i&&i+(Date.now()-n)),Se.current=0,ue(!1),he("Recording resumed."),jn(!1).catch(i=>{ue(!0),Se.current=Date.now(),se(`Couldn't resume the recording: ${i.message}`)})},[]),Sr=s.useCallback(async()=>{xe(!0),se(null);try{try{const i=await za();Array.isArray(i.actions)&&ee(i.actions)}catch{}Se.current=0,ue(!1),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!1,owner:"recorder-page"}}));const n=await Ma({testName:`Recorded ${Zr(new Date)}`,formatter:ct});if(Ws(n),K("stopped"),he(`${G.length} step${G.length===1?"":"s"} captured. Review or generate.`),G.length>0){const i=Le.current||Xr();Le.current=i;try{await Ar({id:i,name:`Recorded — ${(w==null?void 0:w.device)||Zr(new Date)}`,status:"recorded",url:w==null?void 0:w.device}),Re.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(c){console.warn("[MobileRecorder] Failed to persist on Stop:",c)}}}catch(n){se(n.message)}finally{xe(!1)}},[G.length,ct,w,Re]),Rr=s.useCallback(async n=>{if(!(Js||Es.current.length===0)){Mt(!1),se(null),Ns({}),ds(!0),he(n?"Restarting the app, then replaying recorded steps…":"Replaying recorded steps from the current screen…");try{await Pa(1,n)}catch(i){ds(!1),se(`Playback failed: ${i.message}`)}}},[Js]),rr=s.useCallback(async()=>{xe(!0);try{const n=await Da();ee(n.actions),n.startedAt&&W(n.startedAt),Se.current=0,ue(!1),K("recording"),he("Recording resumed — capture additional steps."),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"recorder-page"}}))}catch(n){se(n.message)}finally{xe(!1)}},[]),nr=s.useCallback(async()=>{const n=!oe;try{await kn(n),pe(n),n&&A(!1)}catch(i){se(i.message)}},[oe]),qt=s.useCallback(async()=>{const n=!b;try{await Fa(n),A(n),n&&pe(!1)}catch(i){se(i.message)}},[b]),ar=n=>{try{window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:n}}))}catch{}},Cr=async()=>{if(We.trim()){xe(!0),se(null),window.__testver_mobile_action_in_flight=!0;try{const n=await Ja(We);ee(i=>[...i,n.action]),ar(n.action),Cs("")}catch(n){se(n.message)}finally{xe(!1),window.__testver_mobile_action_in_flight=!1}}},Jt=async n=>{xe(!0),se(null),window.__testver_mobile_action_in_flight=!0;try{if(ne){await Za(n);return}const i=await eo(n);ee(c=>[...c,i.action]),ar(i.action)}catch(i){se(i.message)}finally{xe(!1),window.__testver_mobile_action_in_flight=!1}},or=async()=>{if(us.trim()){xe(!0);try{const n=await Xa(us);ee(i=>[...i,n.action]),ar(n.action),Ts("")}catch(n){se(n.message)}finally{xe(!1)}}},ht=s.useCallback(async()=>{const n=Le.current;if(n)try{await Ar({id:n}),Re.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(i){console.warn("[MobileRecorder] persist after mutation failed:",i)}},[Re]),Kr=async n=>{xe(!0);try{await Ya(n),ee(i=>i.filter(c=>c.index!==n)),await ht()}catch(i){se(i.message)}finally{xe(!1)}},Gr=n=>{ps(n.index),it(n.description)},Wr=async()=>{if(ot!==null){try{const n=await Ir(ot,{description:Xt});ee(i=>i.map(c=>c.index===ot?n.action:c)),await ht()}catch(n){se(n.message)}ps(null)}},Vr=async n=>{const i=Ce;if(i){if(i.mode==="add"){const c=await Wa(n,i.afterIndex);ee(P=>{const u=[...P];if(i.afterIndex===null)u.unshift(c.action);else{const I=i.afterIndex!==void 0?u.findIndex(O=>O.index===i.afterIndex):-1;I>=0?u.splice(I+1,0,c.action):u.push(c.action)}return u})}else if(i.mode==="edit"&&i.editIndex!==void 0){const c=await Ir(i.editIndex,{instruction:n.instruction,customKind:n.customKind,references:n.references||[],outputs:n.outputs||[]});ee(P=>P.map(u=>u.index===i.editIndex?c.action:u))}else if(i.mode==="replace"){const c=[...qe],P=await Va(c,n);ee(u=>{const I=new Set(c),O=u.findIndex(tt=>I.has(tt.index)),de=u.filter(tt=>!I.has(tt.index));return de.splice(O>=0?Math.min(O,de.length):de.length,0,P.action),de}),Ve(new Set)}_e(null),await ht()}},Yr=async n=>{try{const i=await Qa(n);ee(c=>{const P=c.findIndex(de=>de.index===n);if(P<0)return c;const u=[...c];if(u.splice(P,1,...i.actions),!i.order)return u;const I=new Map(u.map(de=>[de.index,de])),O=i.order.map(de=>I.get(de)).filter(de=>!!de);return O.length===u.length?O:u}),await ht()}catch(i){se(i.message)}},ir=async(n,i)=>{try{const c=await Ir(n,{valueFrom:i});ee(P=>P.map(u=>u.index===n?c.action:u)),await ht()}catch(c){se(c.message)}},r=s.useRef(null),a=n=>{re(n),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{to(n).then(()=>ht()).catch(()=>{})},500)},p=s.useMemo(()=>{var P;const n=new Map,i=[],c=(((P=Nt==null?void 0:Nt.testData)==null?void 0:P.columns)||[]).map(u=>({name:`data.${u}`,source:"data",detail:Nt.testData.file}));return G.forEach((u,I)=>{if(n.set(u.index,[...i,...c]),u.type==="custom")for(const O of u.outputs||[])i.push({name:O,source:"step",detail:`saved by step ${I+1}`})}),n},[G,Nt]),f=async n=>{try{const i=await so(n);ee(i.actions),await ht()}catch(i){se(i.message)}},k=n=>i=>{xs.current=n,Je(n),i.dataTransfer.effectAllowed="move";try{const c=G[n];if(c){const P=document.createElement("div");P.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;",P.textContent=`#${n+1} ${c.description.slice(0,60)}`,document.body.appendChild(P),i.dataTransfer.setDragImage(P,12,12),setTimeout(()=>P.remove(),0)}}catch{}},v=n=>i=>{i.preventDefault(),i.dataTransfer.dropEffect="move";const c=i.currentTarget.getBoundingClientRect(),P=c.top+c.height/2,u=i.clientY<P?"above":"below";($s!==n||ms!==u)&&(As(n),vr(u))},g=n=>()=>{$s===n&&As(null)},T=n=>async i=>{i.preventDefault();const c=xs.current;if(xs.current=null,Je(null),As(null),c===null||c===n)return;const P=G[c],u=G.map(de=>de.index),[I]=u.splice(c,1);let O=n;c<n?O=ms==="above"?n-1:n:O=ms==="above"?n:n+1,O=Math.max(0,Math.min(O,u.length)),u.splice(O,0,I),await f(u),P&&(Is.current&&clearTimeout(Is.current),sr(P.index),Is.current=setTimeout(()=>{sr(null),Is.current=null},2500))},Z=()=>{xs.current=null,Je(null),As(null)},J=s.useCallback(async()=>{xe(!0),K("generating"),se(null);try{const n=await La({testName:`Recorded ${Zr(new Date)}`,formatter:ct});Tt(n),K("done"),he(`Saved to ${n.specPath}`),Re.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(n){se(n.message),K("stopped")}finally{xe(!1)}},[ct,Re]);s.useEffect(()=>{if(!(ye!=null&&ye.subscribe))return;const n=c=>{var P;if(!(!c||typeof c!="object")&&!(c.requestId&&c.requestId!==Ke.current)){if(c.requestId&&typeof c.runSeq=="number"){const u=Pt.current;if(u&&u.requestId===c.requestId){if(c.runSeq<=u.lastSeq)return;u.lastSeq=c.runSeq}else Pt.current={requestId:c.requestId,lastSeq:c.runSeq}}if(c.type==="ai-fix-stopped"){Ke.current=null,Ue("stopped"),jt(!1),xe(!1),st(!1),Ss(null),Yt.current=[],K("done");return}switch(c.type){case"mobile-session-started":{const u=c.session;u&&Q(u);break}case"mobile-session-closed":{Q(null);const u=c.reason;typeof u=="string"&&u&&m("info",u);break}case"mobile-recorded-action":{const u=c.action;if(u){if(!u.screenshot)try{const I=(P=window.__testver_capture_mobile_frame)==null?void 0:P.call(window);if(I!=null&&I.dataUrl){if(u.screenshot=I.dataUrl,u.screenshotSize={width:I.width,height:I.height},u.elementRect&&I.deviceWidth>0&&I.deviceHeight>0){const O=I.width/I.deviceWidth,de=I.height/I.deviceHeight;u.elementRect={x:Math.round(u.elementRect.x*O),y:Math.round(u.elementRect.y*de),width:Math.round(u.elementRect.width*O),height:Math.round(u.elementRect.height*de)}}Ir(u.index,{screenshot:u.screenshot,screenshotSize:u.screenshotSize,elementRect:u.elementRect}).catch(()=>{})}}catch{}window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:u}}))}break}case"ai-fix-stream":{const u=typeof c.content=="string"?c.content:"";if(!u)return;me(I=>{const O=I[I.length-1];return(O==null?void 0:O.kind)==="text"?[...I.slice(0,-1),{...O,content:O.content+u}]:[...I,{kind:"text",id:`text-${Date.now()}-${I.length}`,content:u}]});break}case"ai-fix-tool":{const u=c.phase;me(I=>{if(u!=="start")for(let O=I.length-1;O>=0;O--){const de=I[O];if(de.kind==="tool"&&de.toolName===c.toolName&&de.phase==="start"){const tt=[...I];return tt[O]={...de,phase:u,result:c.result,error:c.error},tt}}return[...I,{kind:"tool",id:`tool-${Date.now()}-${I.length}`,phase:u,toolName:String(c.toolName||"tool"),args:typeof c.args=="string"?c.args:c.args?JSON.stringify(c.args,null,2):void 0,result:typeof c.result=="string"?c.result:void 0,error:typeof c.error=="string"?c.error:void 0}]});break}case"ai-fix-file-diff":{me(u=>[...u,{kind:"file-diff",id:`diff-${Date.now()}-${u.length}`,filePath:String(c.filePath||""),diffType:c.diffType,diff:typeof c.diff=="string"?c.diff:"",linesAdded:typeof c.linesAdded=="number"?c.linesAdded:void 0,linesRemoved:typeof c.linesRemoved=="number"?c.linesRemoved:void 0}]);break}case"ai-fix-permission":{const u={permissionId:String(c.permissionId),toolName:String(c.toolName||"tool"),args:typeof c.args=="string"?c.args:c.args?JSON.stringify(c.args,null,2):"",fullPath:typeof c.fullPath=="string"?c.fullPath:void 0};Ss(I=>I?(Yt.current.push(u),I):u);break}case"ai-fix-status":break;case"ai-fix-error":{me(u=>[...u,{kind:"error",id:`err-${Date.now()}-${u.length}`,message:String(c.message||"Unknown error")}]);break}case"ai-fix-done":{xe(!1),st(!1),jt(u=>{if(u)return u;const I=[/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],O=zt.current;let de=0;for(let ge=O.length-1;ge>=0;ge--)if(O[ge].kind==="user"){de=ge+1;break}const Ht=O.slice(de).some(ge=>ge.kind==="error"||ge.kind==="text"&&typeof ge.content=="string"&&I.some(bt=>bt.test(ge.content)))?"failed":"success";Ue(ge=>ge??Ht);const F=Le.current;return F?Ar({id:F,name:Zs.current||void 0,status:"generated",outcome:Ht,fullTimeline:zt.current}).then(()=>{for(const ge of Fe.current)er(ge)}).catch(()=>{}).finally(()=>Re.invalidateQueries({queryKey:["mobile-recording-history"]})):Re.invalidateQueries({queryKey:["mobile-recording-history"]}),u}),K("done");break}case"mobile-playback":{const u=c;if(u.action&&typeof u.index=="number"){const I=u.status==="ok"?"done":u.status==="error"?"error":"running";Ns(O=>({...O,[u.index]:I}))}else u.status==="started"?(ds(!0),Ns({})):u.status==="done"?(ds(!1),he("Playback complete.")):u.status==="error"&&(ds(!1),se(u.error||"Playback failed."));break}}}};return Dt.current=n,ye.subscribe(c=>{const P=Qt.current;if(P&&c&&c.requestId===P.requestId){P.queue.push(c);return}n(c)})},[ye,Re,m]);const ae=s.useCallback((n,i=!1)=>{!at||!(ye!=null&&ye.send)||(ye.send({type:"ai-fix-permission-response",permissionId:at.permissionId,granted:n,remember:n&&i}),Ss(Yt.current.shift()||null))},[at,ye]),fe=s.useCallback(async()=>{const n=Ke.current;if(n){try{await _a(n)}catch{}Ue("stopped"),Ke.current=null,jt(!1),xe(!1),st(!1),K("done")}},[]),E=s.useCallback(async()=>{const n=`mobile-recorder-followup-${Date.now()}`,i=nt.trim(),c=ze&&!i;cs(""),xe(!0),st(!0),jt(!1),Ke.current=n,Pt.current={requestId:n,lastSeq:0},Fe.current.add(n),ks(n),me(F=>[...F,c?{kind:"system",id:`system-confirm-${Date.now()}-${F.length}`,message:"✓ Confirmed — executing the plan"}:{kind:"user",id:`user-${Date.now()}-${F.length}`,text:i}]),K("generating");const P=new Set,u=[],I=[];for(const F of G)u.push(`${F.type}: ${F.description}`);for(const F of mt)if(F.kind==="file-diff")P.add(F.filePath);else if(F.kind==="user")I.push(`User: ${F.text}`);else if(F.kind==="text"&&F.content){const ge=String(F.content);I.push(`Assistant: ${ge.length>2e3?ge.substring(0,2e3)+"... [truncated]":ge}`)}else if(F.kind==="tool"){if(F.phase==="start")continue;const ge=F.args?` ${String(F.args).substring(0,100)}`:"";let bt="";if(F.phase==="complete"){const Rt=F.result?String(F.result):"";bt=Rt?` → ${Rt.length>300?Rt.substring(0,300)+"... [truncated]":Rt}`:" → (no output)"}else F.phase==="error"?bt=` → ERROR: ${F.error?String(F.error).substring(0,300):"failed"}`:F.phase==="denied"&&(bt=" → DENIED by user");I.push(`[Tool ${F.phase}] ${F.toolName}${ge}${bt}`)}else F.kind==="error"&&I.push(`[Stream Error] ${F.message}`);const O=[];u.length>0&&O.push(`Recorded steps (${u.length}):
4
+ ${u.map((F,ge)=>` ${ge+1}. ${F}`).join(`
5
+ `)}`),P.size>0&&O.push(`Files created/modified:
6
+ ${[...P].map(F=>` - ${F}`).join(`
7
+ `)}`),I.length>0&&O.push(`Conversation history (in order):
8
+ ${I.join(`
9
+
10
+ `)}`);const de=O.length>0?O.join(`
11
+
12
+ `):void 0,tt=/\.(spec|test|e2e)\.(ts|js|tsx|jsx|mjs|cjs)$|(^|[\\/])test_[^\\/]+\.py$|_test\.py$|\.feature$|(Test|Tests|IT|Spec)\.(java|kt|rb|cs)$/,Ht=mt.filter(F=>F.kind==="file-diff").map(F=>F.filePath).filter(Boolean).find(F=>tt.test(F))||(we&&be?be:void 0);try{await qa({requestId:n,prompt:i,proceedAfterAnalysis:c,previousContext:de,model:Qe||void 0,provider:rt||void 0,testFilePath:Ht,recordingId:Le.current||void 0,displayText:i||void 0})}catch(F){se(F.message),xe(!1),st(!1),Ke.current=null,c&&jt(!0),K("done")}},[nt,ze,G,mt,Qe,rt,we,be]),Ee=s.useCallback(async()=>{xe(!0),st(!0),se(null),he(null),De(!1);const n=Es.current,i=(w==null?void 0:w.device)||"device",c=[{kind:"system",id:`sys-start-${Date.now()}`,message:`Recording started — ${i}`},...n.map((I,O)=>({kind:"recorded-action",id:`rec-${I.index}`,stepNum:O+1,actionType:I.type,description:I.description,screenshot:I.screenshot,screenshotSize:I.screenshotSize,elementRect:I.elementRect})),{kind:"system",id:`sys-stop-${Date.now()}`,message:`Recording stopped — ${n.length} action${n.length===1?"":"s"} captured`},{kind:"system",id:`system-${Date.now()}`,message:"Analyzing your project patterns and recorded actions…"}];me(c),Ue(null),jt(!0);const P=`mobile-recorder-${Date.now()}`;Ke.current=P,Pt.current={requestId:P,lastSeq:0},Ge(),Fe.current.add(P),ks(P),K("generating");const u=Ye||`recorded-${new Date().toISOString().slice(0,16).replace(/[:.]/g,"-")}`;Rs(u);try{await Ha({requestId:P,testName:u,model:Qe||void 0,provider:rt||void 0,mergeMode:we,targetTestFile:we?be:void 0,targetTestName:we&&Ne?Ne:void 0,insertPosition:we?Ie:void 0,userGuidance:we&&Ie==="auto"?$e:void 0,settings:Nt,analyzeOnly:!0,recordingId:Le.current||void 0})}catch(I){se(I.message),K("stopped"),xe(!1),st(!1),Ke.current=null}},[we,Ye,be,Ne,Ie,$e,Qe,rt,w,Nt]);s.useEffect(()=>{if(!be||!Ne){It([]);return}if(Me!=null&&Me.suites){const n=c=>c.replace(/\\/g,"/"),i=Me.suites.find(c=>n(c.file)===n(be));if(i){const c=i.tests.find(P=>P.name===Ne);if(c!=null&&c.steps&&c.steps.length>0){It(c.steps.map(P=>({keyword:P.keyword,name:P.name})));return}}}Et(!0),Oa(be,Ne).then(n=>{n!=null&&n.humanSteps&&Array.isArray(n.humanSteps)&&n.humanSteps.length>0?It(n.humanSteps.map(i=>({keyword:i.keyword,name:i.name}))):It([])}).catch(()=>It([])).finally(()=>Et(!1))},[be,Ne,Me]);const Ze=s.useMemo(()=>ys,[ys]),Zt=ie||Js||G.length===0||!we&&!Ye.trim()||we&&(!be||!Ne)||we&&Ie==="auto"&&!$e.trim(),V=s.useCallback(async()=>{Ge();try{await Nn()}catch{}ee([]),re(null),Ve(new Set),ue(!1),W(0),M(0),Ws(null),Tt(null),se(null),he(null),pe(!1),A(!1),X(!1),De(!1),_t(null),K("setup");try{const n=await yn();Q(n.session??null)}catch{Q(null)}window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!1,owner:"recorder-page"}}))},[]);s.useCallback(async()=>{xe(!0);try{await Ba()}catch{}Q(null),await V(),xe(!1)},[V]);const et=async()=>{try{if(Xe!=null&&Xe.id){const i=await zr(Xe.id);if(i.recording.actions.length>0){await Sn(i.recording.actions,i.recording.sessionInfo),ee(i.recording.actions),W(Date.now()-(i.recording.durationMs||0)),X(!1),Lt(null),Le.current=Xe.id,K("stopped");return}}const n=await vn();ee(n.actions),W(n.startedAt||Date.now()),X(!1),K("stopped")}catch(n){se(n.message)}},es=async()=>{try{await Nn()}catch{}if(Xe!=null&&Xe.id){try{await Wn(Xe.id)}catch{}Re.invalidateQueries({queryKey:["mobile-recording-history"]})}Lt(null),X(!1)},St=async n=>{n.id!==Le.current&&Ge(),await ts(n),await gt(n,{onlyThisTab:!0})},ts=async n=>{Fe.current=new Set,re(n.settings||null),Ve(new Set);try{await Sn(n.actions,n.sessionInfo,n.settings||null)}catch(c){console.warn("[MobileRecorder] Failed to hydrate backend on load:",c)}ee(n.actions),W(Date.now()),Le.current=n.id;const i=n.status==="generated";if(i){Tt({status:"loaded",specPath:n.generatedSpecPath||"(not generated)",healingPath:n.generatedHealingPath||"(not generated)",specSource:"",healingJson:"",actions:n.actions});const c=Array.isArray(n.fullTimeline)&&n.fullTimeline.length>0?n.fullTimeline:[{kind:"system",id:`sys-load-${n.id}`,message:`Loaded "${n.name}" — ${n.actions.length} recorded step${n.actions.length===1?"":"s"}. (Generated before transcript history was saved, so the AI conversation isn't available for this recording.)`}];me(c),jt(!1),Rs(n.name||null),Ue(n.outcome==="failed"?"failed":n.outcome==="stopped"?"stopped":"success"),De(!0),K("done")}else me([]),De(!1),K("stopped");he(i?`Loaded generated "${n.name}" — read-only view (${n.actions.length} step${n.actions.length===1?"":"s"}). Click "New Recording" to start fresh.`:`Loaded "${n.name}" — ${n.actions.length} step${n.actions.length===1?"":"s"}. You can edit, reorder, delete, or generate code.`)},gt=async(n,i={})=>{var fs,Ht;let c=[];try{c=(await cr(n.id)).runs}catch{return}const P=Bt(),u=c.filter(F=>F.kind==="record-mobile"&&!F.saved&&(!i.onlyThisTab||F.status!=="running"||F.clientId===P)).sort((F,ge)=>F.startedAt-ge.startedAt);if(u.length===0)return;const I=n.actions||[],O=Array.isArray(n.fullTimeline)&&n.fullTimeline.length>0;me(O?n.fullTimeline:[{kind:"system",id:`sys-start-${n.id}`,message:`Recording started — ${((fs=n.sessionInfo)==null?void 0:fs.device)||"device"}`},...I.map((F,ge)=>({kind:"recorded-action",id:`rec-${F.index}`,stepNum:ge+1,actionType:F.type,description:F.description,screenshot:F.screenshot,screenshotSize:F.screenshotSize,elementRect:F.elementRect})),{kind:"system",id:`sys-stop-${n.id}`,message:`Recording stopped — ${I.length} action${I.length===1?"":"s"} captured`}]),De(!1),he(null);const de=()=>new Promise(F=>setTimeout(F,30));for(const F of u){F===u[u.length-1]&&F.status==="running"&&(Qt.current={requestId:F.requestId,queue:[]});let bt;try{bt=await Qn(F.requestId)}catch{Qt.current=null;continue}const Rt=F.meta||{},$r=`${F.requestId}-${Date.now()}`;me(ss=>[...ss,Rt.followUp?F.userText?{kind:"user",id:`user-${$r}`,text:F.userText}:{kind:"system",id:`system-confirm-${$r}`,message:"✓ Confirmed — executing the plan"}:{kind:"system",id:`system-${$r}`,message:"Analyzing your project patterns and recorded actions…"}]),bt.truncated&&me(ss=>[...ss,{kind:"system",id:`sys-trunc-${$r}`,message:"The earliest steps of this generation are too long to show here."}]),jt(!!Rt.analyzeOnly),hr.current=!!Rt.analyzeOnly,typeof Rt.testName=="string"&&Rs(Rt.testName),Ue(null),Ke.current=F.requestId,Pt.current={requestId:F.requestId,lastSeq:0},Fe.current.add(F.requestId),ks(F.requestId),xe(!0),st(!0),K("generating");const Na=new Set(bt.pendingPermissionIds);for(const ss of bt.events)if(!(ss.type==="ai-fix-permission"&&!Na.has(String(ss.permissionId)))){ss.type==="ai-fix-done"&&await de();try{Dt.current(ss)}catch{}}await de()}const tt=((Ht=Qt.current)==null?void 0:Ht.queue)??[];Qt.current=null;for(const F of tt)try{Dt.current(F)}catch{}},va=async()=>{var P;let n;try{n=await cr()}catch{return!1}const i=Bt(),c=n.runs.filter(u=>u.kind==="record-mobile"&&!u.saved&&!!u.sessionId&&(u.clientId===i||!u.tabOpen)).sort((u,I)=>I.startedAt-u.startedAt)[0];if(!(c!=null&&c.sessionId)||c.clientId&&c.clientId!==i&&await((P=ye==null?void 0:ye.adoptClientId)==null?void 0:P.call(ye,c.clientId).catch(()=>null))!==c.clientId&&c.status==="running")return!1;try{const u=(await zr(c.sessionId)).recording;return u?(await ts(u),await gt(u),!0):!1}catch{return!1}},wa=async()=>{var n;try{const i=await cr(),c=Bt(),P=(i.recordings??[]).find(u=>u.kind==="record-mobile"&&!u.tabOpen&&u.clientId!==c);P&&await((n=ye==null?void 0:ye.adoptClientId)==null?void 0:n.call(ye,P.clientId).catch(()=>null))}catch{}};ke.current=()=>t==null?void 0:t(H,{actionCount:G.length,durationMs:le.current,paused:ne,assertMode:oe,annotateMode:b}),s.useEffect(()=>{t==null||t(H,{actionCount:G.length,durationMs:le.current,paused:ne,assertMode:oe,annotateMode:b})},[H,G.length,ne,oe,b,t]),s.useEffect(()=>{o&&o({stop:Sr,pause:Ds,resume:Nr,reset:V,generate:J,addMoreSteps:rr,toggleAssert:nr,toggleAnnotate:qt,openHistory:()=>ft(!0)})},[Sr,Ds,Nr,V,J,rr,nr,qt,o]);const Fs=d.find(n=>n.id===l),Tr=!(Fs!=null&&Fs.hasCredentials);if(H==="setup"||H==="starting")return e.jsxs("div",{className:"relative h-full overflow-y-auto bg-white dark:bg-transparent",children:[e.jsx(en,{open:yr,onClose:()=>ft(!1),onLoad:St}),Te&&e.jsx(tn,{screenshot:Te.screenshot,screenshotSize:Te.screenshotSize,elementRect:Te.elementRect,step:Te.step,description:Te.description,onClose:()=>_t(null)}),e.jsxs("div",{className:"max-w-5xl mx-auto mt-8 space-y-6 px-4 pb-12",children:[h&&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(Mr,{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:et,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(Os,{size:12})," Resume Draft"]}),e.jsx("button",{onClick:es,className:"p-1.5 rounded-lg text-gray-500 hover:text-red-400 hover:bg-red-500/10",title:"Discard draft",children:e.jsx(Us,{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(vt,{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(Hn,{value:l,onChange:n=>S(n),options:d.map(n=>({value:n.id,label:`${n.displayName}${n.hasCredentials?"":" (no credentials)"}`,disabled:!n.hasCredentials}))}),Tr&&e.jsxs("p",{className:"text-[12px] text-amber-300 flex items-center gap-1",children:[e.jsx(Hs,{size:11}),"Add credentials in Connectors → ",(Fs==null?void 0:Fs.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(Xo,{devices:y,selectedId:x,onSelect:n=>C(n.id),loading:B,disabled:Tr,onRefresh:()=>void Ms(l),placeholder:Tr?"(add creds in Connectors)":"Pick device",emptyText:l==="local-appium"?Jo: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(Hn,{value:z,onChange:D,placeholder:L.length===0?"No apps uploaded yet":"Pick app",options:L.map(n=>({value:n.id,label:`${n.label||n.filename} · ${n.kind.toUpperCase()} · ${(n.size/1024/1024).toFixed(1)} MB`}))}),e.jsxs("button",{type:"button",onClick:()=>{var n;return(n=Y.current)==null?void 0:n.click()},disabled:ie,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(oa,{size:13})," Upload"]}),e.jsx("input",{ref:Y,type:"file",accept:".apk,.aab,.ipa,.zip,application/vnd.android.package-archive,application/zip,application/octet-stream",hidden:!0,onChange:n=>{var c;const i=(c=n.target.files)==null?void 0:c[0];i&&Ur(i),n.target.value=""}})]}),q!==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(q*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 ${w?"bg-emerald-400":"bg-gray-600"}`}),w?`Session is running on ${w.device} — recording will reuse it`:"A new mobile session will be launched for recording"]}),e.jsxs("button",{onClick:kr,disabled:ie||H==="starting"||Tr||!x||!z,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:[H==="starting"?e.jsx(je,{size:18,className:"animate-spin"}):e.jsx(vt,{size:18,className:"fill-red-400 text-red-400"}),"Start Recording"]}),(Ae||Ft)&&e.jsxs("div",{className:`text-[12px] flex items-start gap-1.5 ${Ae?"text-red-300":"text-gray-400"}`,children:[Ae?e.jsx(Hs,{size:12,className:"mt-0.5 flex-shrink-0"}):e.jsx(yt,{size:12,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:Ae||Ft})]})]})]})]});if(H==="recording"||H==="stopped"||H==="generating"){const n=H==="recording"||H==="stopped";return e.jsxs("div",{className:"relative h-full flex flex-col bg-white dark:bg-transparent",children:[e.jsx(en,{open:yr,onClose:()=>ft(!1),onLoad:St}),br&&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:i=>i.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(Os,{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:[G.length," step",G.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(wt,{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 Rr(!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(Fr,{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 Rr(!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(on,{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(ma,{open:!!Ce,mode:(Ce==null?void 0:Ce.mode)||"add",initial:Ce==null?void 0:Ce.initial,replaceCount:qe.size,onCancel:()=>_e(null),onSave:Vr}),Te&&e.jsx(tn,{screenshot:Te.screenshot,screenshotSize:Te.screenshotSize,elementRect:Te.elementRect,step:Te.step,description:Te.description,onClose:()=>_t(null)}),H==="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:oe?e.jsxs(e.Fragment,{children:[e.jsx(Gs,{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)"})]}):b?e.jsxs(e.Fragment,{children:[e.jsx(dr,{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(on,{size:13,className:"text-indigo-400"}),e.jsx("span",{className:"text-gray-400",children:ne?"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."})]})}),H==="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:()=>ft(!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(Lr,{size:16})}),ze&&!ie?e.jsxs(e.Fragment,{children:[e.jsx(as,{size:14,className:"text-amber-400"}),e.jsxs("span",{className:"text-sm font-semibold text-amber-300",children:["Waiting for your input",kt?` — ${kt}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{size:14,className:"animate-spin text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-brand-300",children:"Generating Code…"})]})]}),H==="generating"?e.jsx(Fn,{entries:mt,busy:ie,onOpenScreenshot:i=>_t(i)}):e.jsxs("div",{ref:Ps,onScroll:Br,className:"flex-1 overflow-y-auto p-3 space-y-0.5",children:[G.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."}):G.map((i,c)=>{var P;return e.jsxs("div",{children:[H==="stopped"&&c===0&&e.jsx(_n,{label:"Insert a custom step before step 1",onInsert:()=>_e({mode:"add",afterIndex:null})}),e.jsx(ji,{action:i,stepNum:c+1,selectable:H==="stopped"&&i.type!=="custom",selected:qe.has(i.index),anySelected:qe.size>0,onToggleSelect:()=>Ve(u=>{const I=new Set(u);return I.has(i.index)?I.delete(i.index):I.add(i.index),I}),onEditCustom:()=>_e({mode:"edit",editIndex:i.index,initial:{instruction:i.instruction||i.description,customKind:i.customKind,references:i.references,outputs:i.outputs}}),onRestore:H==="stopped"&&((P=i.replaces)!=null&&P.length)?()=>void Yr(i.index):void 0,valuePicker:n&&i.type==="type"&&!i.secretEnv?e.jsx(fa,{current:i.valueFrom,options:p.get(i.index)||[],onPick:u=>void ir(i.index,u)}):null,playbackStatus:gr[i.index],canMutate:n,isEditing:ot===i.index,editingDescription:Xt,onEditChange:it,onStartEdit:()=>Gr(i),onSaveEdit:()=>void Wr(),onCancelEdit:()=>ps(null),onDelete:()=>void Kr(i.index),isDragging:wr===c,isDropTarget:$s===c,dropPosition:ms,wasJustDropped:tr===i.index,onDragStart:k(c),onDragOver:v(c),onDragLeave:g(c),onDrop:T(c),onDragEnd:Z,onOpenScreenshot:()=>{i.screenshot&&_t({screenshot:i.screenshot,screenshotSize:i.screenshotSize,elementRect:i.elementRect,step:c+1,description:i.description})}}),H==="stopped"&&e.jsx(_n,{label:`Insert a custom step after step ${c+1}`,onInsert:()=>_e({mode:"add",afterIndex:i.index})})]},i.index)}),n&&e.jsx("div",{className:"pt-2",children:e.jsxs("button",{type:"button",onClick:()=>_e({mode:"add"}),disabled:ie,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(Ut,{size:12})," Add custom step"]})})]}),H==="recording"&&e.jsx("div",{className:"border-t border-white/[0.05] bg-surface-1",children:b?e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2",children:[e.jsx(Or,{size:12,className:"text-purple-400"}),e.jsx("input",{type:"text",value:us,onChange:i=>Ts(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),or())},disabled:ie,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:or,disabled:ie||!us.trim(),className:"p-1.5 rounded text-purple-300 hover:text-purple-200 hover:bg-purple-500/10 disabled:opacity-40",children:e.jsx(lr,{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:We,onChange:i=>Cs(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),Cr())},disabled:ie||ne,placeholder:ne?"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:Cr,disabled:ie||ne||!We.trim(),className:"p-1.5 rounded text-red-300 hover:text-red-200 hover:bg-red-500/10 disabled:opacity-40",children:ie?e.jsx(je,{size:12,className:"animate-spin"}):e.jsx(lr,{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(_s,{label:"Enter",hint:"↵",onClick:()=>Jt("enter"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Back",hint:"←",onClick:()=>Jt("back"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Home",hint:"⌂",onClick:()=>Jt("home"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Vol +",hint:"🔊",onClick:()=>Jt("volume_up"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Vol −",hint:"🔉",onClick:()=>Jt("volume_down"),disabled:ie,paused:ne}),e.jsx(_s,{label:"Power",hint:"⏻",onClick:()=>Jt("power"),disabled:ie,paused:ne})]})]})}),H==="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),He(""),bs(""),ls("")},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${we?"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 ${we?"bg-indigo-500/15 text-indigo-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:"Add to Existing Test"})]}),we&&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(qn,{active:Ie==="auto",onClick:()=>Oe("auto"),children:"Guide AI"}),e.jsx(qn,{active:Ie==="append",onClick:()=>Oe("append"),children:"Append At End"})]})]}),!we&&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:Ye,onChange:i=>is(i.target.value),placeholder:"Test name (e.g. login-flow-test)",disabled:ie,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"}),qr(Ye)&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400/90",children:qr(Ye)})]}),we&&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(Ni,{selectedFile:be,selectedTest:Ne,open:dt,setOpen:Gt,search:ut,setSearch:Wt,expanded:At,setExpanded:Vt,suites:(Me==null?void 0:Me.suites)??[],loading:!Me,onPick:(i,c)=>{He(i),bs(c),Gt(!1),Wt("")}})]}),Ie==="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:"*"}),Ne?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"})]}),Ne?e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:Ys,value:$e,onChange:i=>{ls(i.target.value);const c=i.target;c.style.height="auto",c.style.height=`${c.scrollHeight}px`},onKeyUp:i=>{const c=i.currentTarget,P=c.value,u=c.selectionStart??P.length,I=P.slice(0,u),O=I.lastIndexOf("@");if(O>=0&&(O===0||I[O-1]===" "||I[O-1]===`
13
+ `)){const de=I.slice(O+1);if(!de.includes("]")){js(de.toLowerCase()),Be(!0);return}}Be(!1)},onKeyDown:i=>{i.key==="Escape"&&pt&&(i.preventDefault(),Be(!1))},placeholder:'e.g., Insert after @[#3 tap "Settings"] and add cart validation...',rows:1,disabled:ie,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:$e.split(`
14
+ `).length>2||$e.length>100?"auto":"hidden"}}),pt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>Be(!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 i=Ze.filter(c=>!xt||c.keyword.toLowerCase().includes(xt)||c.name.toLowerCase().includes(xt));return Ze.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"}):i.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No matching steps"}):i.map((c,P)=>e.jsxs("button",{onClick:()=>{const u=Ys.current;if(!u)return;const I=u.selectionStart||0,O=$e.slice(0,I),de=O.lastIndexOf("@"),tt=$e.slice(I),fs=`@[${c.keyword} ${c.name}]`,Ht=O.slice(0,de)+fs+" "+tt;ls(Ht),Be(!1),setTimeout(()=>{u.focus();const F=de+fs.length+1;u.setSelectionRange(F,F)},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:c.keyword}),e.jsx("span",{className:"text-gray-300 truncate",children:c.name})]},`${c.keyword}-${P}`))})()})]})]}):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"})]})]})]}),qe.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:[qe.size," step",qe.size===1?"":"s"," selected"]}),e.jsxs("button",{type:"button",onClick:()=>_e({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(Ut,{size:12})," Replace with custom step"]}),e.jsx("button",{type:"button",onClick:()=>Ve(new Set),className:"px-2 py-1 rounded-md text-xs text-gray-400 hover:text-gray-200",children:"Clear"})]}),e.jsx(ha,{settings:Nt,onChange:a,inputs:G.filter(i=>i.type==="type"&&!i.secretEnv).map(i=>({id:String(i.index),value:i.text,valueFrom:i.valueFrom})),onMatch:i=>{for(const c of i)ir(Number(c.id),c.valueFrom)},disabled:ie}),e.jsxs("div",{className:"flex items-center gap-2",children:[yi,rt==="testver"&&e.jsx(cn,{refreshSignal:Kt}),e.jsx(dn,{providerModels:vs,selectedProvider:rt,selectedModel:Qe,onPick:ws}),e.jsxs("button",{onClick:Ee,disabled:Zt,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 ${we?"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:[Kt?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(pr,{size:14}),we?"Merge & Generate":"Generate Test Code"]})]})]}),H==="generating"&&at&&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(ln,{pending:at,queuedCount:Yt.current.length,onAllow:()=>ae(!0,!1),onAlwaysAllow:()=>ae(!0,!0),onDeny:()=>ae(!1,!1)})})}),H==="generating"&&e.jsxs("div",{className:"sticky bottom-0 border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[ie&&e.jsx("div",{className:"flex items-center pl-1 pb-3",children:e.jsx(la,{})}),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:nt,onChange:i=>{cs(i.target.value);const c=i.target;c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight,120)}px`},onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),!ie&&(nt.trim()||ze)&&E())},placeholder:ie?"AI is working... click stop to cancel":ze?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:ie,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:ie?e.jsx("button",{onClick:fe,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(lt,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:E,disabled:!nt.trim()&&!ze,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(lr,{size:14})})})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:ie?"Click the stop button to cancel the current generation":ze?"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"})]}),(Ae||Ft)&&H!=="generating"&&e.jsxs("div",{className:`px-3 py-1.5 border-t border-white/[0.05] text-[11px] flex items-center gap-1.5 ${Ae?"text-red-300":"text-gray-500"}`,children:[Ae?e.jsx(Hs,{size:11}):e.jsx(yt,{size:11}),Ae||Ft]})]})}const Qr=mt.length>0,Ls=ze?{icon:as,color:"amber",label:"Waiting for your input"}:Xs==="failed"?{icon:Ks,color:"red",label:"Generation Failed"}:Xs==="stopped"?{icon:lt,color:"gray",label:"Stopped"}:{icon:yt,color:"emerald",label:"Code Generated"},ja=Ls.icon,ka=kt?` — ${kt}`:"";return e.jsxs("div",{className:"relative h-full flex flex-col bg-white dark:bg-transparent",children:[e.jsx(en,{open:yr,onClose:()=>ft(!1),onLoad:St}),Te&&e.jsx(tn,{screenshot:Te.screenshot,screenshotSize:Te.screenshotSize,elementRect:Te.elementRect,step:Te.step,description:Te.description,onClose:()=>_t(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:()=>ft(!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(Lr,{size:16})}),e.jsx(ja,{size:16,className:`text-${Ls.color}-400 ${Ls.color==="gray"?"fill-gray-400":""}`,strokeWidth:Ls.color==="gray"?0:2}),e.jsxs("span",{className:`text-sm font-semibold text-${Ls.color}-300`,children:[Ls.label,ka]}),e.jsx("span",{className:"text-[12px] text-gray-500",children:"·"}),e.jsxs("span",{className:"text-[12px] text-gray-400",children:[G.length," steps"]}),e.jsx("div",{className:"flex-1"}),(ve==null?void 0:ve.specSource)&&e.jsxs("button",{onClick:async()=>{ve!=null&&ve.specSource&&await navigator.clipboard.writeText(ve.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(Do,{size:12})," Copy spec"]}),e.jsxs("button",{onClick:V,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(Fr,{size:12})," New Recording"]})]}),ve&&ve.specPath&&ve.specPath!=="(see AI Assistant tab for written files)"&&ve.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(Mr,{size:13,className:"mt-0.5 text-indigo-400 flex-shrink-0"}),e.jsx("code",{className:"break-all",children:ve.specPath})]}),ve.healingPath&&ve.healingPath!=="(see AI Assistant tab for written files)"&&e.jsxs("div",{className:"flex items-start gap-2 text-gray-400",children:[e.jsx(Mr,{size:13,className:"mt-0.5 opacity-60 flex-shrink-0"}),e.jsx("code",{className:"break-all opacity-80",children:ve.healingPath})]})]}),Qr?e.jsx(Fn,{entries:mt,busy:ie,onOpenScreenshot:n=>_t(n)}):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:(ve==null?void 0:ve.specSource)??"(empty)"})}),Qr&&at&&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(ln,{pending:at,queuedCount:Yt.current.length,onAllow:()=>ae(!0,!1),onAlwaysAllow:()=>ae(!0,!0),onDeny:()=>ae(!1,!1)})})}),Qr&&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:nt,onChange:n=>{cs(n.target.value);const i=n.target;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight,120)}px`},onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),!ie&&(nt.trim()||ze)&&E())},placeholder:ie?"AI is working... click stop to cancel":ze?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:ie,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:ie?e.jsx("button",{onClick:fe,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(lt,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:E,disabled:!nt.trim()&&!ze,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(lr,{size:14})})})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:ie?"Click the stop button to cancel the current generation":ze?"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 wi={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 _n({onInsert:t,label:o}){return e.jsx("div",{className:"group/ins relative h-2 flex items-center",children:e.jsxs("button",{type:"button",onClick:t,"aria-label":o,title:o,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(fr,{size:10})," Custom step"]}),e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"})]})})}function ji({action:t,stepNum:o,canMutate:m,isEditing:d,editingDescription:N,onEditChange:l,onStartEdit:S,onSaveEdit:y,onCancelEdit:$,onDelete:L,isDragging:_,isDropTarget:x,dropPosition:C,wasJustDropped:z,onDragStart:D,onDragOver:B,onDragLeave:U,onDrop:q,onDragEnd:te,onOpenScreenshot:Y,playbackStatus:H,selectable:K=!1,selected:w=!1,anySelected:Q=!1,onToggleSelect:G,onEditCustom:ee,onRestore:ne,valuePicker:ue}){var A,R,W;const oe=wi[t.type]||"border-l-gray-500",pe=t.type==="tap"?Dr:t.type==="type"?Bs:t.type==="swipe"?mn:t.type==="assertion"?Gs:t.type==="annotation"?Or:t.type==="custom"?Ut:fn,b=t.type==="custom";return e.jsxs("div",{draggable:m,onDragStart:D,onDragOver:B,onDragLeave:U,onDrop:q,onDragEnd:te,className:`relative flex items-center gap-2.5 px-3 py-2 rounded-r-lg border-l-[3px] ${oe}
15
+ hover:bg-black/[0.04] dark:hover:bg-white/[0.06]
16
+ group transition-all duration-500
17
+ ${H==="running"?"ring-2 ring-brand-400/70 bg-brand-500/[0.10] shadow-[0_0_16px_rgba(99,102,241,0.35)]":""}
18
+ ${H==="done"?"bg-emerald-500/[0.07]":""}
19
+ ${H==="error"?"bg-red-500/[0.08] ring-1 ring-red-500/40":""}
20
+ ${_?"opacity-50 ring-2 ring-blue-400/60 shadow-[0_0_18px_rgba(96,165,250,0.45)] bg-blue-500/[0.06]":""}
21
+ ${z?"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
+ ${m?"cursor-grab active:cursor-grabbing":""}`,children:[x&&!_&&C==="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"})}),x&&!_&&C==="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"})}),K&&e.jsx("input",{type:"checkbox",checked:w,onChange:()=>G==null?void 0:G(),onMouseDown:le=>le.stopPropagation(),"aria-label":`Select step ${o} (to replace it with a custom step)`,title:"Select to replace with a custom step",className:`flex-shrink-0 cursor-pointer accent-indigo-500 ${Q||w?"opacity-100":"opacity-0 group-hover:opacity-100 focus:opacity-100"}`}),m&&e.jsx(Fo,{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:o}),e.jsx(ki,{action:t,onOpen:Y,Fallback:pe}),e.jsx("div",{className:"flex-1 min-w-0",children:d?e.jsx("input",{type:"text",value:N,autoFocus:!0,onChange:le=>l(le.target.value),onKeyDown:le=>{le.key==="Enter"&&(le.preventDefault(),y()),le.key==="Escape"&&(le.preventDefault(),$())},onBlur:y,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:[b&&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:b?t.instruction:void 0,children:b&&t.instruction||t.description})]}),(b||t.valueFrom)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-0.5",children:[b&&!!((A=t.references)!=null&&A.length)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-gray-500",title:t.references.map(le=>le.label).join(`
23
+ `),children:[e.jsx(Hr,{kind:t.references[0].kind,size:11}),t.references.length>1?`${t.references.length} refs`:t.references[0].label]}),b&&((R=t.outputs)==null?void 0:R.map(le=>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:`→ {${le}}`},le))),b&&!!((W=t.replaces)!=null&&W.length)&&e.jsxs("span",{className:"text-[10px] text-gray-500",title:t.replaces.map(le=>le.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})]})]})}),m&&!d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-0 group-hover:opacity-100 focus-within:opacity-100",children:ue}),ne&&e.jsx("button",{type:"button",onClick:ne,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(ia,{size:12})}),e.jsx("button",{type:"button",onClick:b&&ee?ee:S,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:b?"Edit custom step":"Edit description","aria-label":b?"Edit custom step":"Edit description",children:e.jsx(Lo,{size:12})}),e.jsx("button",{type:"button",onClick:L,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(Us,{size:12})})]})]})}function ki({action:t,onOpen:o,Fallback:m}){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(m,{size:16,className:"text-gray-400"})});let l,S=null;const y=t.screenshotSize,$=t.elementRect;if(y&&$&&$.width>0&&$.height>0){const L=$.height,x=Math.min(4,64*.65/Math.max(20,L)),C=y.width*x,z=y.height*x,D=($.x+$.width/2)*x,B=($.y+$.height/2)*x,U=48/2-D,q=64/2-B;l={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${C}px ${z}px`,backgroundPosition:`${U}px ${q}px`,backgroundRepeat:"no-repeat",backgroundColor:"#000"},S={left:$.x*x+U,top:$.y*x+q,width:$.width*x,height:$.height*x}}else if(y){const L=Math.min(48/y.width,64/y.height),_=y.width*L,x=y.height*L;l={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${_}px ${x}px`,backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundColor:"#000"}}else l={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#000"};return e.jsxs("button",{type:"button",onClick:L=>{L.stopPropagation(),o()},onMouseDown:L=>L.stopPropagation(),onDragStart:L=>{L.preventDefault(),L.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:l}),S&&e.jsx("div",{className:"absolute pointer-events-none border-[2px] border-red-400 rounded-[2px]",style:{...S,boxShadow:"0 0 0 1px rgba(255,255,255,0.4), 0 0 6px rgba(239,68,68,0.6)"}})]})}function _s({label:t,hint:o,onClick:m,disabled:d,paused:N}){return e.jsxs("button",{type:"button",onClick:m,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:N?`Press ${t} (not recorded while paused)`:`Record ${t} key press`,children:[o&&e.jsx("span",{className:"text-gray-500",children:o}),e.jsx("span",{children:t})]})}function qn({active:t,onClick:o,children:m}){return e.jsxs("label",{onClick:o,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:o,className:"hidden"}),m]})}function Ni({selectedFile:t,selectedTest:o,open:m,setOpen:d,search:N,setSearch:l,expanded:S,setExpanded:y,suites:$,loading:L,onPick:_}){const x=N.toLowerCase().trim(),C=s.useMemo(()=>x?$.filter(z=>ns(z.name,x)||z.file.toLowerCase().includes(x)||z.tests.some(D=>ns(D.name,x))):$,[$,x]);return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>d(!m),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:o?e.jsxs("div",{title:o,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:qs(o)}),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…"})}),m&&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:N,onChange:z=>l(z.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:[L&&C.length===0&&e.jsxs("div",{className:"flex items-center justify-center py-4 text-[11px] text-gray-500 gap-1.5",children:[e.jsx(je,{size:11,className:"animate-spin"})," Loading tests…"]}),!L&&C.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."]}),C.map(z=>{const D=z.file,B=S.has(D)||!!x,U=x?z.tests.filter(te=>ns(te.name,x)||ns(z.name,x)):z.tests,q=()=>y(te=>{const Y=new Set(te);return Y.has(D)?Y.delete(D):Y.add(D),Y});return e.jsxs("div",{children:[e.jsxs("button",{onClick:q,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(hs,{size:11,className:`text-gray-500 transition-transform ${B?"":"-rotate-90"}`}),e.jsx("span",{className:"text-gray-300 font-medium truncate",title:z.name,children:qs(z.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:z.tests.length})]}),B&&U.map((te,Y)=>{const H=t===z.file&&o===te.name;return e.jsx("button",{onClick:()=>_(z.file,te.name),className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${H?"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:te.name,children:qs(te.name)})},Y)})]},D)})]})]})]})]})}function Hn({value:t,onChange:o,options:m,placeholder:d,disabled:N,dense:l}){return e.jsxs("div",{className:`relative ${l?"":"flex-1"}`,children:[e.jsxs("select",{value:t,onChange:S=>o(S.target.value),disabled:N,className:`appearance-none bg-surface-2 border border-white/5 rounded-lg ${l?"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}),m.map(S=>e.jsx("option",{value:S.value,disabled:S.disabled,children:S.label},S.value))]}),e.jsx(hs,{size:l?11:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none"})]})}function ga(t,o){const[m,d]=s.useState(!1);return s.useEffect(()=>{const N=t.current;if(!N||typeof ResizeObserver>"u")return;const l=()=>d(N.getBoundingClientRect().width<o);l();const S=new ResizeObserver(l);return S.observe(N),()=>S.disconnect()},[t,o]),m}function Si(t){const o=Math.floor(t/1e3),m=Math.floor(o/60).toString().padStart(2,"0"),d=(o%60).toString().padStart(2,"0");return`${m}:${d}`}function Ri({recorderMode:t,setRecorderMode:o}){const m=Jn(),[d,N]=s.useState("setup"),[l,S]=s.useState(0),[y,$]=s.useState(0),[L,_]=s.useState(!1),[x,C]=s.useState(!1),[z,D]=s.useState(!1),B=s.useRef(null),U=s.useRef(null),q=ga(U,640),[te,Y]=s.useState(!1),H=s.useCallback((pe,b)=>{N(pe),S(b.actionCount),$(b.durationMs),_(b.paused),C(b.assertMode),D(b.annotateMode)},[]),K=s.useCallback(pe=>{B.current=pe},[]),w=()=>{B.current&&(L?(B.current.resume(),_(!1)):(B.current.pause(),_(!0)))},Q=pe=>async()=>{if(B.current){Y(!0);try{await pe()}finally{Y(!1)}}},G=Q(()=>B.current.stop()),ee=Q(()=>B.current.reset()),ne=Q(()=>B.current.addMoreSteps()),ue=Q(()=>B.current.toggleAssert()),oe=Q(()=>B.current.toggleAnnotate());return e.jsx(Ko,{children:e.jsxs("div",{className:"h-full flex flex-col relative",children:[d!=="generating"&&d!=="done"&&e.jsx("div",{ref:U,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 pe;return(pe=B.current)==null?void 0:pe.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(Lr,{size:16})}),d==="recording"?e.jsxs(e.Fragment,{children:[L?e.jsxs(e.Fragment,{children:[e.jsx(_r,{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:Si(y)}),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:l})]}):d==="starting"?e.jsxs(e.Fragment,{children:[e.jsx(je,{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(lt,{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:[l," action",l!==1?"s":""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(vt,{size:14,className:"text-gray-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Mobile Recorder"})]}),m.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(ua,{value:t,onChange:o,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:[!L&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:x?"Exit assertion mode":"Add an assertion",hint:x?void 0:"Tap an element on the device to check it, instead of tapping it",children:e.jsxs("button",{"aria-label":x?"Exit assertion mode":"Add an assertion",onClick:ue,disabled:te,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${x?"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(Gs,{size:14}),x&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:z?"Exit annotate mode":"Annotate a step",hint:z?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":z?"Exit annotate mode":"Annotate a step",onClick:oe,disabled:te,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${z?"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(dr,{size:14}),z&&e.jsx("span",{children:"ON"})]})})]}),e.jsx(Ct,{label:L?"Resume recording":"Pause recording",hint:L?"Your taps are recorded again":"Use the device freely — nothing is recorded until you resume",children:e.jsx("button",{onClick:w,"aria-label":L?"Resume recording":"Pause recording",className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${L?"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:L?e.jsx(Os,{size:14}):e.jsx(_r,{size:14})})}),e.jsx(Ct,{label:"Stop recording",hint:"Then review the steps and generate the test",children:e.jsx("button",{onClick:G,disabled:te,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:te?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(lt,{size:14})})})]}),d==="stopped"&&e.jsxs(e.Fragment,{children:[e.jsx(ur,{tone:"brand",compact:q,icon:e.jsx(fr,{size:13}),label:"Add More Steps",hint:"Continue recording — add more steps to this recording",disabled:te,onClick:ne}),e.jsx(ur,{compact:q,icon:e.jsx(Fr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",disabled:te,onClick:ee})]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto transition-all duration-200",children:e.jsx(vi,{onPhaseChange:H,registerControls:K})})]})})}const Ci=!1,Ti={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"},$i=new Set(["annotate","assert","hover","dialog","custom"]),On=new Set(["fill","type","select","navigate"]);function Ai(t){const o=Math.floor(t/60),m=t%60;return`${o}:${m.toString().padStart(2,"0")}`}function rn({type:t,size:o=12}){const m={click:e.jsx(Dr,{size:o,className:"text-blue-400"}),dblclick:e.jsx(Dr,{size:o,className:"text-blue-300"}),fill:e.jsx(Bs,{size:o,className:"text-emerald-400"}),type:e.jsx(Bs,{size:o,className:"text-emerald-400"}),press:e.jsx(Bo,{size:o,className:"text-amber-400"}),navigate:e.jsx(hn,{size:o,className:"text-purple-400"}),select:e.jsx(Oo,{size:o,className:"text-cyan-400"}),check:e.jsx(Ho,{size:o,className:"text-emerald-400"}),uncheck:e.jsx(lt,{size:o,className:"text-gray-400"}),hover:e.jsx(fn,{size:o,className:"text-purple-400"}),scroll:e.jsx(hs,{size:o,className:"text-gray-400"}),assert:e.jsx(Gs,{size:o,className:"text-green-400"}),annotate:e.jsx(qo,{size:o,className:"text-violet-400"}),upload:e.jsx(oa,{size:o,className:"text-teal-400"}),drag:e.jsx(mn,{size:o,className:"text-indigo-400"}),dialog:e.jsx(Or,{size:o,className:"text-orange-400"}),custom:e.jsx(Ut,{size:o,className:"text-indigo-500"})};return e.jsx(e.Fragment,{children:m[t]||e.jsx(vt,{size:o-2,className:"text-gray-500"})})}function rs(t,o){return{kind:"recorded-action",id:t.id||o(),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(m=>({id:m.id,type:m.type,description:m.description}))}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function ba(t){var o,m;return{...t.instruction?{instruction:t.instruction}:{},...t.customKind?{customKind:t.customKind}:{},...(o=t.references)!=null&&o.length?{references:t.references}:{},...(m=t.outputs)!=null&&m.length?{outputs:t.outputs}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function Bn(t){return t.filter(o=>o.kind==="recorded-action").map(o=>({id:o.id,type:o.actionType,description:o.description,selector:o.selector,value:o.value,url:o.url,timestamp:o.timestamp,assertType:o.assertType,expectedValue:o.expectedValue,screenshot:o.screenshot,elementRect:o.elementRect,...o.screenshotCrop?{screenshotCrop:o.screenshotCrop}:{},...ba(o)}))}function Ii(t){return t.map(o=>{switch(o.kind){case"recorded-action":return{kind:o.kind,id:o.id,actionType:o.actionType,description:o.description,selector:o.selector,value:o.value,url:o.url,timestamp:o.timestamp,assertType:o.assertType,expectedValue:o.expectedValue,elementRect:o.elementRect,...ba(o)};case"text":return{kind:o.kind,id:o.id,text:o.text};case"tool":return{kind:o.kind,id:o.id,phase:o.phase,toolName:o.toolName,args:o.args,result:o.result,error:o.error,startedAt:o.startedAt,endedAt:o.endedAt};case"file-diff":return{kind:o.kind,id:o.id,filePath:o.filePath,diffType:o.diffType,diff:o.diff,linesAdded:o.linesAdded,linesRemoved:o.linesRemoved,via:o.via,unavailable:o.unavailable,netNoChange:o.netNoChange,omitted:o.omitted};case"error":case"user":case"system":return{kind:o.kind,id:o.id,text:o.text};default:return{kind:o.kind,id:o.id}}})}function Ei(t,o){const m=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 N=m.get(d.id);return rs({...d,screenshot:d.screenshot||(N==null?void 0:N.screenshot),elementRect:d.elementRect||(N==null?void 0:N.elementRect),screenshotCrop:d.screenshot?d.screenshotCrop:N==null?void 0:N.screenshotCrop},o)}return d.kind==="text"?{kind:"text",id:d.id||o(),text:d.text||"",done:!0}:d.kind==="tool"?{kind:"tool",id:d.id||o(),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||o(),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||o(),text:d.text||""}:d.kind==="user"?{kind:"user",id:d.id||o(),text:d.text||""}:{kind:"system",id:d.id||o(),text:d.text||""}})}const zi=[/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 Mi(t,o){if(o==="failed"||o==="stopped")return o;let m=0;for(let d=t.length-1;d>=0;d--)if(t[d].kind==="user"){m=d+1;break}for(const d of t.slice(m))if(d.kind==="error"||d.kind==="text"&&d.text&&zi.some(N=>N.test(d.text)))return"failed";return"success"}function Pi(t,o,m){return!t||t.src!==o?!1:Math.abs(t.w-m.clipW)<=2&&Math.abs(t.h-m.clipH)<=2}function Un(t,o){return new Promise(m=>{const d=new Image;d.onload=()=>{try{const N=document.createElement("canvas");N.width=o.clipW,N.height=o.clipH;const l=N.getContext("2d");if(!l){m(t);return}const S=d.naturalWidth/o.vpW,y=d.naturalHeight/o.vpH;l.drawImage(d,o.clipX*S,o.clipY*y,o.clipW*S,o.clipH*y,0,0,o.clipW,o.clipH),m(N.toDataURL("image/jpeg",.8))}catch{m(t)}},d.onerror=()=>m(t),d.src=t})}const Di=/\.(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 Kn({onInsert:t,label:o}){return e.jsx("div",{className:"group/ins relative h-2 flex items-center",children:e.jsxs("button",{type:"button",onClick:t,"aria-label":o,title:o,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(fr,{size:10})," Custom step"]}),e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"})]})})}let Ot=null;const Fi=2e4,Li=/^(recorder-|ai-fix-|browser-(closed|launched)$)/;function _i(t,o){ya();const m={clientId:Bt(),state:t,buffer:[],overflow:!1,stop:null,replayed:!1};try{m.stop=o(d=>{if(Li.test(String((d==null?void 0:d.type)||""))){if(m.buffer.length>=Fi){m.overflow=!0;return}m.buffer.push(d)}})}catch{}Ot=m}function qi(){const t=Ot;if(!t)return null;const o=Bt();return t.clientId&&o&&t.clientId!==o?null:t}function ya(){var t;try{(t=Ot==null?void 0:Ot.stop)==null||t.call(Ot)}catch{}Ot=null}function Hi(){var ir;const{subscribe:t,send:o,adoptClientId:m}=Gn(),{toast:d}=un(),[N]=s.useState(qi),l=N==null?void 0:N.state,{data:S}=da(),[y,$]=s.useState((l==null?void 0:l.phase)??"setup"),L=s.useRef(y);L.current=y;const[_,x]=s.useState((l==null?void 0:l.timeline)??[]),C=s.useRef(_);C.current=_;const z=s.useMemo(()=>new Map(_.map((r,a)=>[r.id,a])),[_]),[D,B]=s.useState((l==null?void 0:l.startUrl)??""),U=(()=>{const r=D.trim();if(!/^https?:\/\//i.test(r))return!1;try{return!!new URL(r).hostname}catch{return!1}})(),[q,te]=s.useState((l==null?void 0:l.testName)??""),[Y,H]=s.useState((l==null?void 0:l.mergeMode)??!1),[K,w]=s.useState((l==null?void 0:l.targetTestFile)??""),[Q,G]=s.useState((l==null?void 0:l.targetTestName)??""),[ee,ne]=s.useState((l==null?void 0:l.insertPosition)??"auto"),[ue,oe]=s.useState(!1),[pe,b]=s.useState(""),[A,R]=s.useState(new Set),[W,le]=s.useState((l==null?void 0:l.userGuidance)??""),[ke,M]=s.useState((l==null?void 0:l.followUpPrompt)??""),[h,X]=s.useState((l==null?void 0:l.awaitingConfirmation)??!1),[j,ce]=s.useState((l==null?void 0:l.genOutcome)??null),[ct,gs]=s.useState(!1),[os,Ws]=s.useState(""),ve=s.useRef(null),[Tt,Kt]=s.useState([]),[st,we]=s.useState(!1);s.useEffect(()=>{if(!K||!Q){Kt([]);return}if(S!=null&&S.suites){const r=S.suites.find(a=>a.file===K||a.file.replace(/\\/g,"/")===K.replace(/\\/g,"/"));if(r){const a=r.tests.find(p=>p.name===Q);if(a!=null&&a.steps&&a.steps.length>0){Kt(a.steps.map(p=>({keyword:p.keyword,name:p.name})));return}}}we(!0),ro(async()=>{const{getTestSourceByName:r}=await import("./index-BlA8ntjb.js").then(a=>a.iS);return{getTestSourceByName:r}},__vite__mapDeps([0,1,2,3,4])).then(({getTestSourceByName:r})=>{r(K,Q).then(a=>{a!=null&&a.humanSteps&&a.humanSteps.length>0?Kt(a.humanSteps.map(p=>({keyword:p.keyword,name:p.name}))):Kt([])}).catch(()=>Kt([])).finally(()=>we(!1))})},[K,Q,S]);const[$t,Ye]=s.useState((l==null?void 0:l.elapsedTime)??0),[is,be]=s.useState((l==null?void 0:l.actionCount)??0),[He,Ie]=s.useState((l==null?void 0:l.isPaused)??!1),Oe=s.useRef((l==null?void 0:l.startTime)??0),$e=s.useRef((l==null?void 0:l.pausedAt)??0),[ls,Me]=s.useState((l==null?void 0:l.canAddSteps)??!0),dt=s.useRef((l==null?void 0:l.executed)??!1),Gt=s.useRef((l==null?void 0:l.lastSavedRun)??null),[ut,Wt]=s.useState((l==null?void 0:l.testSettings)??null),[Ne,bs]=s.useState(null),[At,Vt]=s.useState(new Set),ys=s.useRef(new Map),It=s.useRef(`draft-${Bt()||`local-${Math.random().toString(36).slice(2,10)}`}`),Vs=()=>{const r=Bt();return r&&!It.current.startsWith(`draft-${r}`)&&(It.current=`draft-${r}`),It.current},[Et,vs]=s.useState(!1),Qe=Jn(),[rt,ws]=s.useState(Qe.mode==="mobile"?"mobile":"web");s.useEffect(()=>{Qe.isLoading||(Qe.mode==="mobile"&&rt!=="mobile"?ws("mobile"):Qe.mode==="web"&&rt!=="web"&&ws("web"))},[Qe.mode,Qe.isLoading]);const[pt,Be]=s.useState((l==null?void 0:l.activeSessionId)??null),[xt,js]=s.useState(null),[Ys,mt]=s.useState(null),[me,Qs]=s.useState(null),ks=s.useRef(null),ze=ga(ks,640),[jt,hr]=s.useState(null),Xs=s.useRef(null),[Ue,nt]=s.useState(null),[cs,Ke]=s.useState(null),[zt,Js]=s.useState("below"),[ds,gr]=s.useState(null),Ns=s.useRef(0),[br,Mt]=s.useState(!1),[at,Ss]=s.useState(!1),[Yt,kt]=s.useState(null),[Rs,Zs]=s.useState(!1),[Pe,De]=s.useState((l==null?void 0:l.genLoading)??!1),[ye,Pt]=s.useState((l==null?void 0:l.playbackLoading)??!1),{providerModels:Qt,selectedProvider:Fe,selectedModel:Dt,select:er}=pa(l?{provider:l.selectedProvider,model:l.selectedModel}:void 0),Ge=s.useRef((l==null?void 0:l.streamText)??""),Ae=s.useRef((l==null?void 0:l.streamTextId)??null),se=s.useRef((l==null?void 0:l.loadedFromHistory)??!1),Ft=s.useRef((l==null?void 0:l.currentRequestId)??null),he=r=>{Ft.current=r},ie=s.useRef(null),xe=s.useRef(null),We=s.useRef(new Set((l==null?void 0:l.runIds)??[])),Cs=s.useRef(()=>{}),us=r=>{Xn(r).catch(()=>{})},Ts=()=>{for(const r of We.current)us(r);We.current=new Set},[ot,ps]=s.useState((l==null?void 0:l.pendingPermission)??null),Xt=s.useRef((l==null?void 0:l.permissionQueue)??[]),it=()=>{ps(null),Xt.current=[]},[yr]=s.useState(1),[ft,Xe]=s.useState((l==null?void 0:l.playbackIndex)??-1),[Lt,Le]=s.useState((l==null?void 0:l.playbackTotal)??0),[Se,Re]=s.useState((l==null?void 0:l.assertActive)??!1),[Ce,_e]=s.useState((l==null?void 0:l.annotateActive)??!1),qe=s.useRef(null),Ve=s.useRef(!0),Nt=s.useRef(0),re=()=>`rec-${Date.now().toString(36)}-${++Nt.current}`,xs=s.useRef({});xs.current={phase:y,timeline:_,startUrl:D,testName:q,mergeMode:Y,targetTestFile:K,targetTestName:Q,insertPosition:ee,userGuidance:W,followUpPrompt:ke,awaitingConfirmation:h,genOutcome:j,elapsedTime:$t,actionCount:is,isPaused:He,activeSessionId:pt,genLoading:Pe,pendingPermission:ot,assertActive:Se,annotateActive:Ce,canAddSteps:ls,selectedProvider:Fe,selectedModel:Dt,playbackLoading:ye,playbackIndex:ft,playbackTotal:Lt,testSettings:ut};const $s=s.useRef(t);$s.current=t,s.useEffect(()=>()=>{_i({...xs.current,currentRequestId:Ft.current,permissionQueue:Xt.current,streamText:Ge.current,streamTextId:Ae.current,loadedFromHistory:se.current,executed:dt.current,lastSavedRun:Gt.current,runIds:[...We.current],startTime:Oe.current,pausedAt:$e.current},$s.current)},[]),s.useEffect(()=>{const r=qe.current;r&&Ve.current&&(r.scrollTop=r.scrollHeight)},[_]);const As=()=>{const r=qe.current;r&&(Ve.current=r.scrollHeight-r.scrollTop-r.clientHeight<120)};s.useEffect(()=>{ot&&qe.current&&(Ve.current=!0,requestAnimationFrame(()=>{qe.current&&(qe.current.scrollTop=qe.current.scrollHeight)}))},[ot]),s.useEffect(()=>{var a;if(!me)return;(a=Xs.current)==null||a.focus();const r=p=>{p.key==="Escape"&&Qs(null)};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[me]),s.useEffect(()=>{no().then(r=>Mt(r.active)).catch(()=>Mt(!1))},[y]);const ms=async r=>{let a=[];try{a=(await oo()).actions||[]}catch{}const p=a.map(f=>rs(f,re));x([{kind:"system",id:re(),text:r.recording?"Recording in progress — picked up where you left off":"Recording restored"},...p]),be(r.actionCount??p.length),Ye(Math.floor((r.duration||0)/1e3)),r.startUrl&&B(r.startUrl),Wt(r.settings||null),r.sessionId&&Be(r.sessionId),r.recording?(Oe.current=Date.now()-(r.duration||0),$e.current=r.paused?Date.now():0,Ie(!!r.paused),$("recording")):(Me(r.canAddSteps!==!1),$("stopped"))};s.useEffect(()=>{if(N&&N.state.phase!=="setup")return;let r=!0;return(async()=>{var a;if(await Yn().catch(()=>null),!(r&&await jr())){try{const p=await Rn();r&&(p.recording||p.hasSession)&&await ms(p)}catch{}if(!(!r||L.current!=="setup"))for(const p of[Vs(),...ao().map(f=>`draft-${f}`),"draft-current"])try{const f=await an(p);if(f&&((a=f.actions)==null?void 0:a.length)>0){r&&js(f);break}}catch{}}})(),()=>{r=!1}},[]),s.useEffect(()=>{if(y!=="recording")return;if(Oe.current||(Oe.current=Date.now()),He){$e.current||($e.current=Date.now());return}$e.current&&(Oe.current+=Date.now()-$e.current,$e.current=0);const r=()=>Ye(Math.floor((Date.now()-Oe.current)/1e3));r();const a=setInterval(r,1e3);return()=>clearInterval(a)},[y,He]);const vr=s.useRef($t);vr.current=$t;const wr=s.useRef(D);wr.current=D,s.useEffect(()=>{if(y!=="recording")return;const r=setInterval(()=>{var k;const a=Bn(C.current);if(a.length===0)return;const p=((k=a.find(v=>v.type==="navigate"))==null?void 0:k.url)||wr.current||"";let f="recording";try{p&&(f=new URL(p).hostname)}catch{}Cn({id:Vs(),name:`Draft — ${f}`,url:p,status:"draft",actions:a,duration:vr.current*1e3}).catch(()=>{})},1e4);return()=>clearInterval(r)},[y]),s.useEffect(()=>{var T,Z;if(y!=="done"||h)return;const r=Mi(_,j);if(r!==j&&ce(r),se.current){se.current=!1;return}if(!dt.current)return;const a=Bn(_);if(a.length===0)return;const p=`${pt}:${_.length}:${(T=_[_.length-1])==null?void 0:T.id}`;if(Gt.current===p)return;Gt.current=p;const f=((Z=a.find(J=>J.type==="navigate"))==null?void 0:Z.url)||D||"",k=pt||`session-${Date.now()}`;let v="test";try{f&&(v=new URL(f).hostname)}catch{v="unknown"}const g=(Y&&Q?Q:"")||q||`Recording — ${v}`;Cn({id:k,name:g,rename:!!(Y&&Q||q),url:f,status:"generated",outcome:r,actionCount:a.length,actions:a,fullTimeline:Ii(_),duration:$t*1e3,settings:ut||null}).then(()=>{pt||Be(k);for(const J of We.current)us(J)}).catch(()=>{})},[y,h]);const Je=s.useCallback(()=>{if(Ge.current&&Ae.current){const r=Ae.current,a=Ge.current;x(p=>{const f=p.findIndex(k=>k.id===r);if(f>=0){const k=[...p];return k[f]={kind:"text",id:r,text:a,done:!0},k}return p})}Ge.current="",Ae.current=null},[]),tr=s.useRef(new Set);s.useEffect(()=>{for(const r of _){if(r.kind!=="recorded-action"||!r.screenshot||!r.screenshotCrop)continue;const a=`${r.id}:${r.screenshot.length}`;if(tr.current.has(a))continue;tr.current.add(a);const{id:p,screenshot:f,screenshotCrop:k}=r;Un(f,k).then(v=>{tr.current.delete(a),v!==f&&x(g=>g.map(T=>{if(T.id!==p||T.kind!=="recorded-action"||T.screenshot!==f)return T;const{screenshotCrop:Z,...J}=T;return{...J,screenshot:v}}))})}},[_]),s.useEffect(()=>{var p;const r=f=>{if(f.type==="recorder-action"){const g=f.action,T=g.id||re();if(typeof T=="string"&&T.endsWith("-screenshot")){const Z=T.replace("-screenshot",""),J=ae=>x(fe=>fe.map(E=>E.id===Z&&E.kind==="recorded-action"?{...E,screenshot:ae,elementRect:g.elementRect}:E));g.screenshotCrop&&g.screenshot?Un(g.screenshot,g.screenshotCrop).then(J):J(g.screenshot);return}if(typeof T=="string"&&T.endsWith("-update")){x(Z=>{const J=[...Z];for(let ae=J.length-1;ae>=0;ae--){const fe=J[ae];if(fe.kind==="recorded-action"&&fe.actionType==="fill"){J[ae]={...fe,description:g.description||fe.description,value:g.value??fe.value};break}}return J});return}x(Z=>[...Z,rs({...g,id:T},re)]),be(Z=>Z+1),g.type==="annotate"&&_e(!1),g.type==="assert"&&Re(!1);return}if(f.type==="recorder-annotate-mode"&&_e(!!f.active),f.type==="recorder-assert-mode"){Re(!!f.active);return}if(f.type==="browser-closed"){Mt(!1),L.current==="recording"&&(x(g=>[...g,{kind:"system",id:re(),text:"Browser closed — recording stopped"}]),$("stopped"),Re(!1),_e(!1)),Me(!1);return}if(f.type==="browser-launched"){Mt(!0);return}if(f.type==="recorder-status"){if(f.status==="recording")$("recording"),Ie(!1),Oe.current||(Oe.current=Date.now());else if(f.status==="paused")Ie(!0);else if(f.status==="stopped"){$("stopped"),Ie(!1);const g=f;g.sessionId&&Be(g.sessionId),typeof g.actionCount=="number"&&be(g.actionCount)}else f.status==="reset"&&($("setup"),x([]),be(0),Ye(0),it(),X(!1),ce(null),Be(null));return}if(f.type==="recorder-playback"){const g=f;g.status==="started"?($("playback"),Xe(0),Le(g.totalActions||0),x(T=>[...T,{kind:"system",id:re(),text:`Playback started — replaying ${g.totalActions} action(s)...`}])):g.status==="action"?(Xe(g.index+1),x(T=>[...T,{kind:"playback-action",id:re(),actionType:g.actionType||"action",description:g.description||`Action ${g.index+1}`,status:"done"}])):g.status==="action-error"?x(T=>[...T,{kind:"playback-action",id:re(),actionType:g.actionType||"action",description:g.description||`Action ${g.index+1}`,status:"error"}]):g.status==="done"?($("stopped"),Pt(!1),x(T=>[...T,{kind:"system",id:re(),text:`Playback complete — ${g.replayed||0} of ${g.total||0} actions replayed${g.errors?` (${g.errors} errors)`:""}`}])):g.status==="error"&&($("stopped"),Pt(!1),x(T=>[...T,{kind:"error",id:re(),text:`Playback failed: ${g.error||"Unknown error"}`}]));return}const k=f.requestId;if(!k||k!==Ft.current)return;const v=f.runSeq;if(typeof v=="number"){const g=ie.current;if(g&&g.requestId===k){if(v<=g.lastSeq)return;g.lastSeq=v}else ie.current={requestId:k,lastSeq:v}}if(f.type==="ai-fix-stopped"){Je(),he(null),it(),X(!1),$("done"),De(!1),ce("stopped"),x(g=>[...g,{kind:"system",id:re(),text:"Generation stopped by user"}]);return}if(f.type==="ai-fix-stream"){const g=f.content;if(Ae.current){Ge.current+=g;const T=Ae.current,Z=Ge.current;x(J=>{const ae=J.findIndex(fe=>fe.id===T);if(ae>=0){const fe=[...J];return fe[ae]={kind:"text",id:T,text:Z},fe}return J})}else{const T=re();Ae.current=T,Ge.current=g,x(Z=>[...Z,{kind:"text",id:T,text:g}])}}else if(f.type==="ai-fix-tool"){const g=f,T=`${g.toolName}::${g.args||""}`;g.phase==="start"?(Je(),x(Z=>[...Z,{kind:"tool",id:re(),toolId:T,phase:"start",toolName:g.toolName,args:g.args||"",startedAt:Date.now()}])):x(Z=>{const J=[...Z].reverse().findIndex(ae=>ae.kind==="tool"&&ae.toolId===T&&ae.phase==="start");if(J>=0){const ae=Z.length-1-J,fe=[...Z];return fe[ae]={...fe[ae],phase:g.phase,result:g.result,error:g.error,endedAt:Date.now()},fe}return[...Z,{kind:"tool",id:re(),toolId:T,phase:g.phase,toolName:g.toolName,args:g.args||"",result:g.result,error:g.error}]})}else if(f.type==="ai-fix-file-diff"){const g=f;Je(),x(T=>[...T,{kind:"file-diff",id:re(),filePath:g.filePath,diffType:g.diffType,diff:g.diff,linesAdded:g.linesAdded,linesRemoved:g.linesRemoved,via:g.via==="detected"?"detected":void 0,unavailable:g.unavailable,netNoChange:g.netNoChange===!0||void 0}])}else if(f.type==="ai-fix-file-changes-omitted"){const g=f;x(T=>[...T,{kind:"file-diff",id:re(),filePath:"",diffType:"modified",diff:"",via:"detected",omitted:{count:Number(g.count)||0,examples:Array.isArray(g.examples)?g.examples:[]}}])}else if(f.type==="ai-fix-permission"){const g=f,T={permissionId:g.permissionId,toolName:g.toolName,args:g.args||"",fullPath:g.fullPath||void 0};Je(),ps(Z=>Z?(Xt.current.push(T),Z):T)}else f.type==="ai-fix-done"?(Je(),it(),$("done"),De(!1)):f.type==="ai-fix-error"&&(Je(),x(g=>[...g,{kind:"error",id:re(),text:f.message||"Unknown error"}]),it(),X(!1),$("done"),De(!1),ce("failed"))};Cs.current=r;const a=t(f=>{const k=xe.current;if(k&&f.requestId===k.requestId){k.queue.push(f);return}r(f)});if(N&&!N.replayed){N.replayed=!0;try{(p=N.stop)==null||p.call(N)}catch{}N.stop=null;for(const f of N.buffer.splice(0))try{r(f)}catch{}N.overflow&&x(f=>[...f,{kind:"system",id:re(),text:"Some live updates were missed while this screen was closed."}])}return Ot&&ya(),a},[t,Je]);const sr=async()=>{if(!U||at)return;Ss(!0),kt(null);const r=re();x([{kind:"system",id:r,text:D?`Recording started — navigating to ${D}`:"Recording started — interact with the browser"}]),be(0);try{await mo({url:D.trim(),browser:"chromium",headless:!1}),$("recording"),Ie(!1),Ye(0),Oe.current=Date.now(),$e.current=0,Ve.current=!0,Me(!0),ce(null),X(!1),Wt(null),Vt(new Set),dt.current=!1,Ts(),Be(null),se.current=!1}catch(a){x([]);const p=String((a==null?void 0:a.message)||a).replace(/^Error:\s*/,"");kt(p),d("error",`Couldn't start recording: ${p}`)}finally{Ss(!1)}},Is=async()=>{Zs(!0);try{const r=await uo();if(x(a=>[...a,{kind:"system",id:re(),text:`Recording stopped — ${r.actionCount} action(s) captured in ${(r.duration/1e3).toFixed(1)}s`}]),$("stopped"),Ie(!1),Re(!1),_e(!1),Me(!0),js(null),nn(Vs()).catch(()=>{}),r.sessionId&&Be(r.sessionId),!q&&r.actions.length>0){const a=r.actions.find(p=>p.type==="navigate");if(a!=null&&a.url)try{const p=new URL(a.url).hostname.replace(/\./g,"-");te(`${p}-test`)}catch{}}}catch(r){x(a=>[...a,{kind:"error",id:re(),text:`Failed to stop recording: ${r}`}])}finally{Zs(!1)}},Te=async()=>{try{await co(),Ie(!0),x(r=>[...r,{kind:"system",id:re(),text:"⏸ Recording paused — interact freely without recording"}])}catch(r){d("error",`Couldn't pause the recording: ${r}`)}},_t=async()=>{try{await lo(),Ie(!1),x(r=>[...r,{kind:"system",id:re(),text:"▶ Recording resumed"}])}catch(r){d("error",`Couldn't resume the recording: ${r}`)}},Es=async()=>{try{const r=await po();r!=null&&r.success&&(Oe.current=Date.now()-$t*1e3,$e.current=0,$("recording"),Ie(!1),x(a=>[...a,{kind:"system",id:re(),text:"➕ Adding more steps to the recording"}]))}catch(r){x(a=>[...a,{kind:"system",id:re(),text:`Failed to resume recording: ${r}`}])}},zs=async r=>{if(L.current==="recording"||L.current==="generating"||L.current==="playback"){d("info",L.current==="generating"?"Wait for the generation to finish (or stop it) before opening another recording.":"Stop the current recording before opening another one.");return}r.id!==pt&&Ts(),await Ms(r)&&await Ps(r.id,{onlyThisTab:!0})},Ms=async r=>{var k;let a=!1,p=r.settings||null;try{const v=await io(r.id);a=!!v.canAddSteps,v.settings!==void 0&&(p=v.settings||null)}catch(v){return d("error",`Couldn't open the recording: ${v}`),!1}if(se.current=!0,dt.current=!1,Gt.current=null,We.current=new Set,Be(r.id||null),vs(!1),Me(a),Wt(p),Vt(new Set),be(r.actionCount||((k=r.actions)==null?void 0:k.length)||0),Ye(Math.round((r.duration||0)/1e3)),r.name&&te(r.name),ce(r.outcome||null),X(!1),it(),he(null),Ve.current=!0,r.fullTimeline&&r.fullTimeline.length>0)return $(r.status==="completed"||r.status==="generated"?"done":"stopped"),x(Ei(r,re)),!0;$("stopped");const f=r.actions||[];return x([{kind:"system",id:re(),text:`Loaded recording: ${r.name} (${f.length} actions)`},...f.map(v=>rs(v,re))]),!0},Ps=async(r,a={})=>{var g;let p=[];try{p=(await cr(r)).runs}catch{return}const f=Bt(),k=p.filter(T=>T.kind==="record-web"&&!T.saved&&(!a.onlyThisTab||T.status!=="running"||T.clientId===f)).sort((T,Z)=>T.startedAt-Z.startedAt);if(k.length===0)return;se.current=!1;for(const T of k){T===k[k.length-1]&&T.status==="running"&&(xe.current={requestId:T.requestId,queue:[]});let J;try{J=await Qn(T.requestId)}catch{xe.current=null;continue}const ae=T.meta||{};Je(),ae.followUp?(dt.current=!0,T.userText&&x(E=>[...E,{kind:"user",id:re(),text:T.userText}])):(dt.current=!ae.analyzeOnly,x(E=>[...E,{kind:"system",id:re(),text:"Analyzing your project patterns and recorded actions..."}])),J.truncated&&x(E=>[...E,{kind:"system",id:re(),text:"The earliest steps of this generation are too long to show here."}]),X(!!ae.analyzeOnly),ce(null),he(T.requestId),ie.current={requestId:T.requestId,lastSeq:0},We.current.add(T.requestId),$("generating"),De(!0);const fe=new Set(J.pendingPermissionIds);for(const E of J.events)if(!(E.type==="ai-fix-permission"&&!fe.has(String(E.permissionId))))try{Cs.current(E)}catch{}}const v=((g=xe.current)==null?void 0:g.queue)??[];xe.current=null;for(const T of v)try{Cs.current(T)}catch{}},jr=async()=>{let r;try{r=await cr()}catch{return!1}const a=Bt(),p=r.runs.filter(v=>v.kind==="record-web"&&!v.saved&&!!v.sessionId&&(v.clientId===a||!v.tabOpen)).sort((v,g)=>g.startedAt-v.startedAt)[0],f=(r.recordings??[]).find(v=>v.kind==="record-web"&&!v.tabOpen&&v.clientId!==a),k=p&&p.clientId!==a?p.clientId:f==null?void 0:f.clientId;if(k&&m&&await m(k).catch(()=>null)!==k&&(!p||p.status==="running"||p.clientId!==k))return!1;if(p!=null&&p.sessionId){let v;try{v=await an(p.sessionId)}catch{return!1}return!v||!await Ms(v)?!1:(await Ps(p.sessionId),!0)}if(f)try{const v=await Rn();if(v.recording||v.hasSession)return await ms(v),!0}catch{}return!1},Br=async()=>{if(Pe)return;De(!0),it(),Ge.current="",Ae.current=null,ce(null),se.current=!1,dt.current=!1,Ve.current=!0;const r=`recorder-${Date.now()}`;he(r),ie.current={requestId:r,lastSeq:0},We.current.add(r),$("generating"),X(!0),x(a=>[...a,{kind:"system",id:re(),text:Y?`Analyzing project to merge recorded actions into — ${K}...`:"Analyzing your project patterns and recorded actions..."}]);try{await vo({requestId:r,testName:q||"recorded test",model:Dt||void 0,provider:Fe||void 0,mergeMode:Y||void 0,targetTestFile:Y?K:void 0,insertPosition:Y?ee:void 0,userGuidance:Y&&W.trim()?W.trim():void 0,sessionId:pt||void 0,analyzeOnly:!0,settings:ut})}catch(a){x(p=>[...p,{kind:"error",id:re(),text:`Failed to start code generation: ${a}`}]),De(!1),X(!1),he(null),$("stopped")}},Ur=async()=>{const r=Ft.current;r&&(Je(),he(null),it(),X(!1),$("done"),De(!1),ce("stopped"),x(a=>[...a,{kind:"system",id:re(),text:"Generation stopped by user"}]),jo({requestId:r}).catch(()=>{}))},kr=async()=>{var fe;if(Pe)return;const r=ke.trim();if(!r&&!h)return;const a=h,p=!r||/^(proceed|ok|yes|go|continue|looks good|lgtm|sure|do it|go ahead)$/i.test(r),f=a&&p?'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;M(""),De(!0),ce(null),it(),Ge.current="",Ae.current=null,se.current=!1,dt.current=!0,Ve.current=!0,a&&X(!1);const k=`recorder-followup-${Date.now()}`;he(k),ie.current={requestId:k,lastSeq:0},We.current.add(k),$("generating"),x(E=>[...E,{kind:"user",id:re(),text:r||(a?"Looks good, proceed!":"")}]);const v=_.filter(E=>E.kind==="file-diff").filter(E=>!E.via&&!E.omitted&&!E.netNoChange&&E.diffType!=="deleted"&&!!E.filePath).map(E=>E.filePath),g=v.find(E=>Di.test(E))||(Y&&K?K:void 0)||v[0],T=new Set,Z=[],J=[];for(const E of _)if(E.kind==="recorded-action")Z.push(E.actionType==="custom"?`custom step: ${E.instruction||E.description}${(fe=E.outputs)!=null&&fe.length?` (saves ${E.outputs.map(Ee=>`{${Ee}}`).join(", ")})`:""}`:`${E.actionType}: ${E.description}${E.valueFrom?` (uses {${E.valueFrom}})`:""}`);else if(E.kind==="file-diff"&&E.filePath&&!E.netNoChange)T.add(E.filePath);else if(E.kind==="user")J.push(`User: ${E.text}`);else if(E.kind==="text"&&E.text){const Ee=String(E.text);J.push(`Assistant: ${Ee.length>2e3?Ee.substring(0,2e3)+"... [truncated]":Ee}`)}else if(E.kind==="tool"){if(E.phase==="start")continue;const Ee=E.args?` ${String(E.args).substring(0,100)}`:"";let Ze="";if(E.phase==="complete"){const Zt=E.result?String(E.result):"";Ze=Zt?` → ${Zt.length>300?Zt.substring(0,300)+"... [truncated]":Zt}`:" → (no output)"}else E.phase==="error"?Ze=` → ERROR: ${E.error?String(E.error).substring(0,300):"failed"}`:E.phase==="denied"&&(Ze=" → DENIED by user");J.push(`[Tool ${E.phase}] ${E.toolName}${Ee}${Ze}`)}else E.kind==="error"&&J.push(`[Stream Error] ${E.text}`);const ae=[];Z.length>0&&ae.push(`Recorded steps (${Z.length}):
29
+ ${Z.map((E,Ee)=>` ${Ee+1}. ${E}`).join(`
30
+ `)}`),T.size>0&&ae.push(`Files created/modified:
31
+ ${[...T].map(E=>` - ${E}`).join(`
32
+ `)}`),J.length>0&&ae.push(`Conversation history (in order):
33
+ ${J.join(`
34
+
35
+ `)}`);try{await wo({requestId:k,prompt:f,testFilePath:g,previousContext:ae.length>0?ae.join(`
36
+ `):void 0,model:Dt||void 0,provider:Fe||void 0,proceedAfterAnalysis:a,sessionId:pt||void 0,displayText:r||(a?"Looks good, proceed!":"")})}catch(E){x(Ee=>[...Ee,{kind:"error",id:re(),text:`Failed to start follow-up: ${E}`}]),De(!1),he(null),a&&X(!0),$("done")}},Ds=(r,a=!1)=>{ot&&(o({type:"ai-fix-permission-response",permissionId:ot.permissionId,granted:r,remember:r&&a}),ps(Nr()))},Nr=()=>Xt.current.shift()||null,Sr=async r=>{const a=C.current.find(p=>p.id===r&&p.kind==="recorded-action");if(a){mt(r);try{const p=await ho();if(!(p!=null&&p.success)||!p.element)return;const f=p.description||a.description,v=`${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}"`:""}`;x(g=>g.map(T=>T.id===r&&T.kind==="recorded-action"?{...T,description:v,selector:p.selector}:T));try{await Jr(r,{selector:p.selector,locators:p.locators,domContext:p.domContext,elementMeta:p.elementMeta,description:v})}catch(g){x(T=>T.map(Z=>Z.id===r?a:Z)),d("error",`Couldn't update the step — it was left as it was. ${g}`)}}catch(p){d("error",`Re-inspect failed: ${p}`)}finally{mt(null)}}},Rr=async r=>{const a=C.current.findIndex(f=>f.id===r),p=a>=0?C.current[a]:void 0;x(f=>f.filter(k=>k.id!==r)),be(f=>Math.max(0,f-1));try{await go(r)}catch(f){p&&(x(k=>{if(k.some(g=>g.id===r))return k;const v=[...k];return v.splice(Math.min(a,v.length),0,p),v}),be(k=>k+1)),d("error",`Couldn't remove the step — it was put back. ${f}`)}},rr=r=>{const a=C.current;x(r);const p=r.filter(f=>f.kind==="recorded-action").map(f=>f.id);bo(p).catch(f=>{x(a),d("error",`Couldn't reorder the steps — the previous order was restored. ${f}`)})},nr=(r,a)=>{const p=C.current,f=p.findIndex(T=>T.id===r);if(f<0)return;let k=f+a;for(;k>=0&&k<p.length&&p[k].kind!=="recorded-action";)k+=a;if(k<0||k>=p.length)return;const v=[...p],[g]=v.splice(f,1);v.splice(k,0,g),rr(v),requestAnimationFrame(()=>{var T;return(T=document.querySelector(`[data-action-id="${r}"]`))==null?void 0:T.focus()})},qt=r=>bs(r),ar=(r,a,p)=>{const f=[...r];if(p===null){const k=f.findIndex(v=>v.kind==="recorded-action");f.splice(k>=0?k:f.length,0,a)}else{const k=p?f.findIndex(v=>v.id===p):-1;k>=0?f.splice(k+1,0,a):f.push(a)}return f},Cr=async r=>{const a=Ne;if(a){if(a.mode==="add"){const p=await ko(r,a.afterId),f=rs(p.action,re);x(k=>ar(k,f,a.afterId)),be(k=>k+1)}else if(a.mode==="edit"&&a.editId){const p=await Jr(a.editId,{instruction:r.instruction,customKind:r.customKind,references:r.references||[],outputs:r.outputs||[]}),f=p.action?rs(p.action,re):null;x(k=>k.map(v=>v.id===a.editId&&v.kind==="recorded-action"?{...v,...f?{description:f.description,instruction:f.instruction,customKind:f.customKind,references:f.references,outputs:f.outputs}:{}}:v))}else if(a.mode==="replace"){const p=[...At],f=await No(p,r),k=rs(f.action,re),v=new Set(p);x(g=>{const T=g.findIndex(J=>v.has(J.id));ys.current.set(k.id,g.filter(J=>v.has(J.id)));const Z=g.filter(J=>!v.has(J.id));return Z.splice(T>=0?Math.min(T,Z.length):Z.length,0,k),Z}),be(g=>Math.max(0,g-p.length+1)),Vt(new Set)}bs(null)}},Jt=async r=>{try{const a=await fo(r),p=ys.current.get(r),f=p&&p.length===a.actions.length?p:a.actions.map(k=>rs(k,re));ys.current.delete(r),x(k=>{const v=k.findIndex(J=>J.id===r);if(v<0)return k;const g=[...k];if(!a.order)return g.splice(v,1,...f),g;g.splice(v,1);let T=v;const Z=new Map(a.order.map((J,ae)=>[J,ae]));for(const J of[...f].sort((ae,fe)=>(Z.get(ae.id)??0)-(Z.get(fe.id)??0))){const ae=Z.get(J.id)??-1,fe=ae>0?a.order[ae-1]:null,E=fe?g.findIndex(Ze=>Ze.id===fe):-1,Ee=E>=0?E+1:Math.min(T,g.length);g.splice(Ee,0,J),T=Ee+1}return g}),be(k=>k-1+f.length)}catch(a){d("error",`Couldn't put the steps back: ${a}`)}},or=async(r,a)=>{const p=C.current.find(f=>f.id===r&&f.kind==="recorded-action");x(f=>f.map(k=>k.id===r&&k.kind==="recorded-action"?{...k,valueFrom:a||void 0}:k));try{await Jr(r,{valueFrom:a})}catch(f){x(k=>k.map(v=>v.id===r&&v.kind==="recorded-action"?{...v,valueFrom:p==null?void 0:p.valueFrom}:v)),d("error",`Couldn't change the step: ${f}`)}},ht=s.useRef(null),Kr=r=>{Wt(r),ht.current&&clearTimeout(ht.current),ht.current=setTimeout(()=>{yo(r).catch(()=>{})},500)},Gr=s.useMemo(()=>{var k;const r=new Map,a=[],p=(((k=ut==null?void 0:ut.testData)==null?void 0:k.columns)||[]).map(v=>({name:`data.${v}`,source:"data",detail:ut.testData.file}));let f=0;for(const v of _)if(v.kind==="recorded-action"&&(f++,r.set(v.id,[...a,...p]),v.actionType==="custom"))for(const g of v.outputs||[])a.push({name:g,source:"step",detail:`saved by step ${f}`});return r},[_,ut]),Wr=r=>Vt(a=>{const p=new Set(a);return p.has(r)?p.delete(r):p.add(r),p}),Vr=async()=>{Ts(),await xo().catch(()=>{}),$("setup"),x([]),be(0),Ye(0),Ie(!1),Oe.current=0,$e.current=0,B(""),te(""),it(),he(null),De(!1),Pt(!1),Xe(-1),Ge.current="",Ae.current=null,M(""),X(!1),ce(null),Re(!1),_e(!1),Me(!0),Wt(null),Vt(new Set),dt.current=!1,Gt.current=null,We.current=new Set,Be(null),se.current=!1},Yr=y==="recording"||y==="generating"||y==="playback";return rt==="mobile"?e.jsx(Ri,{showHistory:Et,setShowHistory:vs,recorderMode:rt,setRecorderMode:ws}):e.jsxs(Go,{userControlOnly:!0,children:[e.jsxs("div",{className:"h-full flex flex-col relative bg-white dark:bg-transparent",children:[e.jsx("div",{ref:ks,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:()=>vs(!Et),className:`flex-shrink-0 p-1.5 rounded-lg transition-colors ${Et?"bg-brand-500/15 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,"aria-label":"Recording History","aria-expanded":Et,title:"Recording History",children:e.jsx(Lr,{size:16})}),y==="recording"?e.jsxs(e.Fragment,{children:[He?e.jsxs(e.Fragment,{children:[e.jsx(_r,{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:Ai($t)}),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:is})]}):y==="playback"?e.jsxs(e.Fragment,{children:[e.jsx(Os,{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:[ft,"/",Lt]})]}):y==="generating"?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:14,className:"animate-spin text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-brand-300",children:"Generating Code..."})]}):y==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(lt,{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:[is," action",is!==1?"s":""]})]}):y==="done"?h?e.jsxs(e.Fragment,{children:[e.jsx(as,{size:14,className:"flex-shrink-0 text-amber-400"}),e.jsxs("span",{className:"text-sm font-semibold text-amber-300 truncate",title:q||void 0,children:["Waiting for your input",q?` — ${q}`:""]})]}):j==="failed"?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{size:14,className:"flex-shrink-0 text-red-400"}),e.jsxs("span",{className:"text-sm font-semibold text-red-300 truncate",title:q||void 0,children:["Generation Failed",q?` — ${q}`:""]})]}):j==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(lt,{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:q||void 0,children:["Stopped",q?` — ${q}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(yt,{size:14,className:"flex-shrink-0 text-emerald-400"}),e.jsxs("span",{className:"text-sm font-semibold text-emerald-300 truncate",title:q||void 0,children:["Code Generated",q?` — ${q}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(vt,{size:14,className:"text-gray-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Browser Recorder"})]}),Qe.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(ua,{value:rt,onChange:ws,disabled:Yr})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[y==="recording"&&e.jsxs(e.Fragment,{children:[!He&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:Se?"Exit assertion mode":"Add an assertion",hint:Se?void 0:"Click an element in the browser to check it, instead of clicking it",shortcut:Se?"Esc":void 0,children:e.jsxs("button",{"aria-label":Se?"Exit assertion mode":"Add an assertion",onClick:async()=>{try{Ce&&(await Tn(!1),_e(!1)),await $n(!Se),Re(!Se),Se||In()}catch{}},className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${Se?"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(Gs,{size:14}),Se&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:Ce?"Exit annotate mode":"Annotate a step",hint:Ce?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:Ce?"Esc":void 0,children:e.jsxs("button",{"aria-label":Ce?"Exit annotate mode":"Annotate a step",onClick:async()=>{try{Se&&(await $n(!1),Re(!1)),await Tn(!Ce),_e(!Ce),Ce||In()}catch{}},className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${Ce?"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(dr,{size:14}),Ce&&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:()=>qt({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(Ut,{size:14})})}),e.jsx(Ct,{label:He?"Resume recording":"Pause recording",hint:He?"Your actions are recorded again":"Use the page freely — nothing is recorded until you resume",children:e.jsx("button",{"aria-label":He?"Resume recording":"Pause recording",onClick:He?_t:Te,className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${He?"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:He?e.jsx(Os,{size:14}):e.jsx(_r,{size:14})})}),e.jsx(Ct,{label:"Stop recording",hint:"Then review the steps and generate the test",children:e.jsx("button",{onClick:Is,disabled:Rs,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:Rs?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(lt,{size:14})})})]}),(y==="stopped"||y==="done")&&e.jsxs(e.Fragment,{children:[y==="stopped"&&e.jsx(ur,{tone:"indigo",compact:ze,icon:e.jsx(Ut,{size:13}),label:"Custom Step",hint:"Add a custom step at the end — or hover between two steps to insert one there",onClick:()=>qt({mode:"add"})}),y==="stopped"&&e.jsx(ur,{tone:"brand",compact:ze,icon:e.jsx(fr,{size:13}),label:"Add More Steps",hint:ls?"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:!ls,onClick:Es}),e.jsx(ur,{compact:ze,icon:e.jsx(Fr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",onClick:Vr})]})]})]})}),e.jsxs("div",{ref:qe,onScroll:As,className:`flex-1 overflow-y-auto p-4 space-y-3 transition-all duration-200 ${Et?"ml-[280px]":""}`,children:[y==="setup"&&e.jsxs("div",{className:"max-w-xl mx-auto mt-8 space-y-6",children:[xt&&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(Mr,{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:[xt.actionCount||((ir=xt.actions)==null?void 0:ir.length)||0," steps recorded",xt.url?` on ${xt.url}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("button",{onClick:()=>{zs(xt),js(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(Os,{size:12})," Resume Draft"]}),e.jsx("button",{onClick:()=>{nn(xt.id||Vs()).catch(()=>{}),js(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(Us,{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(vt,{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(hn,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:D,onChange:r=>{B(r.target.value),kt(null)},placeholder:"https://example.com","aria-invalid":D.trim()!==""&&!U,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 ${D.trim()!==""&&!U?"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"&&!at&&sr()}})]})}),D.trim()!==""&&!U?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 ${br?"bg-emerald-400":"bg-gray-600"}`}),br?"Browser is running — recording will use the current session":"A new browser will be launched for recording"]}),e.jsxs("button",{onClick:sr,disabled:at||!U,title:U?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:[at?e.jsx(je,{size:18,className:"animate-spin"}):e.jsx(vt,{size:18,className:"fill-red-400 text-red-400"}),"Start Recording"]}),Yt&&e.jsxs("p",{role:"alert",className:"flex items-start gap-1.5 text-sm text-red-600 dark:text-red-400",children:[e.jsx(Hs,{size:15,className:"mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:["Couldn't start recording: ",Yt]})]})]}),y!=="setup"&&e.jsx("div",{className:"space-y-0.5",children:Wo(_,{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:y==="generating"}).map(r=>{var f,k,v,g;if(r.kind==="group")return e.jsx(Vo,{group:r,className:"!-my-1"},r.id);if(r.kind==="changes")return e.jsx(Yo,{item:r},r.id);const a=r.entry,p=z.get(a.id)??0;if(a.kind==="recorded-action"){const T=_.slice(0,p+1).filter(V=>V.kind==="recorded-action").length,Z=Ti[a.actionType]||"border-l-gray-500",J=$i.has(a.actionType),ae=Ue===p,fe=cs===p&&Ue!==p,E=a.actionType==="custom",Ee=y==="stopped"&&!E,Ze=At.has(a.id),Zt=(y==="stopped"||y==="recording")&&On.has(a.actionType)&&!a.secretEnv;return e.jsxs("div",{children:[y==="stopped"&&T===1&&e.jsx(Kn,{label:"Insert a custom step before step 1",onInsert:()=>qt({mode:"add",afterId:null})}),e.jsxs("div",{draggable:y==="stopped",onDragStart:V=>{nt(p),V.dataTransfer.effectAllowed="move";try{const et=document.createElement("div");et.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;",et.textContent=a.description.substring(0,40),document.body.appendChild(et),V.dataTransfer.setDragImage(et,100,15),setTimeout(()=>et.remove(),0)}catch{}},onDragOver:V=>{V.preventDefault(),V.dataTransfer.dropEffect="move";const et=Date.now();if(et-Ns.current<50)return;Ns.current=et;const es=V.currentTarget.getBoundingClientRect(),St=es.top+es.height/2,ts=V.clientY<St?"above":"below";(cs!==p||zt!==ts)&&(Ke(p),Js(ts))},onDragLeave:()=>{cs===p&&Ke(null)},onDrop:V=>{var et;if(V.preventDefault(),Ue!==null&&Ue!==p){const es=(et=_[Ue])==null?void 0:et.id,St=[..._],[ts]=St.splice(Ue,1);if(ts){let gt=p;Ue<p?gt=zt==="above"?p-1:p:gt=zt==="above"?p:p+1,gt=Math.max(0,Math.min(gt,St.length)),St.splice(gt,0,ts),rr(St)}es&&(gr(es),setTimeout(()=>{const gt=document.querySelector(`[data-action-id="${es}"]`);gt&&gt.scrollIntoView({behavior:"smooth",block:"nearest"})},50),setTimeout(()=>gr(null),3e3))}nt(null),Ke(null)},onDragEnd:()=>{nt(null),Ke(null)},tabIndex:y==="stopped"?0:void 0,"aria-label":`Step ${T}: ${a.description}${y==="stopped"?" — Alt+Up or Alt+Down to move":""}`,onKeyDown:V=>{y!=="stopped"||!V.altKey||V.target!==V.currentTarget||(V.key==="ArrowUp"?(V.preventDefault(),nr(a.id,-1)):V.key==="ArrowDown"&&(V.preventDefault(),nr(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] ${Z} ${Ze?"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 ${ae?"cursor-grabbing":"cursor-default"} ${ae?"opacity-30":"transition-colors duration-100"} ${ds===a.id?"ring-2 ring-blue-400 bg-blue-500/5 animate-pulse":""}`,children:[fe&&zt==="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"})}),fe&&zt==="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"})}),y==="stopped"&&e.jsx("span",{className:"flex-shrink-0 w-4 flex items-center justify-center",onMouseDown:V=>V.stopPropagation(),children:Ee&&e.jsx("input",{type:"checkbox",checked:Ze,onChange:()=>Wr(a.id),onClick:V=>V.stopPropagation(),"aria-label":`Select step ${T} (to replace it with a custom step)`,title:"Select to replace with a custom step",className:`cursor-pointer accent-indigo-500 ${At.size>0||Ze?"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:T}),a.screenshot?e.jsx("button",{draggable:!1,onMouseDown:V=>V.stopPropagation(),onDragStart:V=>{V.preventDefault(),V.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:V=>{V.stopPropagation(),Qs({screenshot:a.screenshot,elementRect:a.elementRect,description:a.description,step:T})},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(rn,{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(rn,{type:a.actionType,size:16})}),J&&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:E?a.instruction:void 0,children:E&&a.instruction||a.description}),E&&!!((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(V=>V.label).join(`
37
+ `),children:[e.jsx(Hr,{kind:a.references[0].kind,size:11}),a.references.length>1?`${a.references.length} refs`:a.references[0].label]}),E&&((k=a.outputs)==null?void 0:k.map(V=>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:`→ {${V}}`},V))),E&&!!((v=a.replaces)!=null&&v.length)&&e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-gray-500",title:a.replaces.map(V=>V.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}}`})]}),Ys===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(dr,{size:10,className:"text-blue-400"}),e.jsx("span",{className:"text-[10px] text-blue-400 font-medium",children:"Pick..."})]}),(y==="recording"||y==="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:V=>V.stopPropagation(),onDragStart:V=>{V.preventDefault(),V.stopPropagation()},children:[E&&e.jsx("button",{onClick:V=>{V.stopPropagation(),qt({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(_o,{size:14})}),E&&!!((g=a.replaces)!=null&&g.length)&&y==="stopped"&&e.jsx("button",{onClick:V=>{V.stopPropagation(),Jt(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(ia,{size:14})}),Zt&&e.jsx(fa,{current:a.valueFrom,options:Gr.get(a.id)||[],onPick:V=>or(a.id,V)}),a.actionType!=="annotate"&&!E&&e.jsx("button",{onClick:V=>{V.stopPropagation(),Sr(a.id)},disabled:!!Ys,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(dr,{size:14})}),e.jsx("button",{onClick:V=>{V.stopPropagation(),Rr(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(Us,{size:14})})]})]}),y==="stopped"&&e.jsx(Kn,{label:`Insert a custom step after step ${T}`,onInsert:()=>qt({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(pr,{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(ca,{text:a.text})})},a.id);if(a.kind==="playback-action"){const T=a.status==="running"?e.jsx(je,{size:11,className:"animate-spin text-cyan-400"}):a.status==="done"?e.jsx(yt,{size:11,className:"text-emerald-400"}):a.status==="error"?e.jsx(Ks,{size:11,className:"text-red-400"}):e.jsx(as,{size:11,className:"text-gray-500"});return e.jsxs("div",{className:"flex items-center gap-2 px-4 py-1",children:[T,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(rn,{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(Hs,{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})})]}),y==="stopped"&&e.jsxs("div",{className:"flex-shrink-0 px-4 py-3 border-t border-white/5 bg-surface-1 space-y-3",children:[At.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:[At.size," step",At.size===1?"":"s"," selected"]}),e.jsxs("button",{onClick:()=>qt({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(Ut,{size:12})," Replace with custom step"]}),e.jsx("button",{onClick:()=>Vt(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":!Y,onClick:()=>{H(!1),w(""),G(""),le("")},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${Y?"text-gray-500 hover:text-gray-300":"bg-brand-500/15 text-brand-300 shadow-sm"}`,children:"New Test"}),e.jsx("button",{"aria-pressed":Y,onClick:()=>H(!0),className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${Y?"bg-indigo-500/15 text-indigo-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:"Add to Existing Test"})]}),Y&&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 ${ee==="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:ee==="auto",onChange:()=>ne("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 ${ee==="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:ee==="append",onChange:()=>ne("append"),className:"sr-only"}),"Append At End"]})]})]}),!Y&&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:q,onChange:r=>te(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"}),qr(q)&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400/90",children:qr(q)})]}),Y&&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:()=>oe(!ue),"aria-haspopup":"listbox","aria-expanded":ue,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:Q?e.jsxs("div",{title:Q,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:qs(Q)}),e.jsx("span",{className:"text-[10px] text-gray-500 block mt-0.5 truncate",children:K})]}):e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:"Select a test..."})}),ue&&(S==null?void 0:S.suites)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>oe(!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(),oe(!1))},children:[e.jsx("div",{className:"px-2 py-2 border-b border-white/5",children:e.jsx("input",{type:"text",value:pe,onChange:r=>b(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:S.suites.filter(r=>{const a=pe.toLowerCase();return a?ns(r.name,a)||r.file.toLowerCase().includes(a)||r.tests.some(p=>ns(p.name,a)):!0}).map(r=>{const a=r.file,p=pe.toLowerCase(),f=A.has(a)||!!p,k=p?r.tests.filter(v=>ns(v.name,p)||ns(r.name,p)):r.tests;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>R(v=>{const g=new Set(v);return g.has(a)?g.delete(a):g.add(a),g}),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(hs,{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:qs(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&&k.map((v,g)=>e.jsx("button",{onClick:()=>{w(r.file),G(v.name),oe(!1),b("")},className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${K===r.file&&Q===v.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:v.name,children:qs(v.name)})},g))]},a)})})]})]})]})]}),ee==="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:"*"}),Q?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"})]}),Q?e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:ve,value:W,onChange:r=>{le(r.target.value);const a=r.target;a.style.height="auto",a.style.height=`${a.scrollHeight}px`},onKeyUp:r=>{const a=r.currentTarget,p=a.value,f=a.selectionStart??p.length,k=p.slice(0,f),v=k.lastIndexOf("@");if(v>=0&&(v===0||k[v-1]===" "||k[v-1]===`
39
+ `)){const g=k.slice(v+1);if(!g.includes("]")){Ws(g.toLowerCase()),gs(!0);return}}gs(!1)},onKeyDown:r=>{r.key==="Escape"&&ct&&(r.preventDefault(),gs(!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:W.split(`
40
+ `).length>2||W.length>100?"auto":"hidden"}}),ct&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>gs(!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:[Tt.filter(r=>!os||r.keyword.toLowerCase().includes(os)||r.name.toLowerCase().includes(os)).map((r,a)=>e.jsxs("button",{onClick:()=>{const p=ve.current;if(!p)return;const f=p.selectionStart||0,k=W.slice(0,f),v=k.lastIndexOf("@"),g=W.slice(f),T=`@[${r.keyword} ${r.name}]`,Z=k.slice(0,v)+T+" "+g;le(Z),gs(!1),setTimeout(()=>{p.focus();const J=v+T.length+1;p.setSelectionRange(J,J)},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)),st&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 text-center",children:"Loading steps..."}),!st&&Tt.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No steps found for this test"}),!st&&Tt.length>0&&Tt.filter(r=>!os||r.keyword.toLowerCase().includes(os)||r.name.toLowerCase().includes(os)).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(ha,{settings:ut,onChange:Kr,inputs:_.filter(r=>r.kind==="recorded-action"&&On.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)or(a.id,a.valueFrom)},disabled:Pe}),e.jsxs("div",{className:"flex gap-2",children:[Ci,Fe==="testver"&&e.jsx(cn,{refreshSignal:Pe,align:"left"}),e.jsx(dn,{providerModels:Qt,selectedProvider:Fe,selectedModel:Dt,onPick:er}),e.jsxs("button",{onClick:Br,disabled:Pe||is===0||!Y&&!q.trim()||Y&&(!K||!Q)||Y&&ee==="auto"&&!W.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 ${Y?"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:[Pe?e.jsx(je,{size:14,className:"animate-spin"}):e.jsx(pr,{size:14}),Y?"Merge & Generate":"Generate Test Code"]})]})]}),y==="playback"&&Lt>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(je,{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:`${ft/Lt*100}%`}})})}),e.jsxs("span",{className:"text-[10px] text-gray-500 font-mono",children:[ft,"/",Lt]})]})}),ot&&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(ln,{pending:ot,queuedCount:Xt.current.length,onAllow:()=>Ds(!0,!1),onAlwaysAllow:()=>Ds(!0,!0),onDeny:()=>Ds(!1,!1)})})}),(y==="done"||y==="generating")&&e.jsxs("div",{className:"sticky bottom-0 border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[Pe&&e.jsx("div",{className:"flex items-center pl-1 pb-3",children:e.jsx(la,{})}),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:[Fe==="testver"&&e.jsx(cn,{refreshSignal:Pe,align:"left"}),e.jsx(dn,{providerModels:Qt,selectedProvider:Fe,selectedModel:Dt,onPick:er,disabled:Pe,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:ke,onChange:r=>{M(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(),!Pe&&(ke.trim()||h)&&kr())},"aria-label":"Message to the AI",placeholder:Pe?"AI is working... click stop to cancel":h?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:Pe,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:Pe?e.jsx("button",{onClick:Ur,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(lt,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:kr,"aria-label":h&&!ke.trim()?"Proceed":"Send",title:h&&!ke.trim()?"Proceed":"Send",disabled:!ke.trim()&&!h,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(lr,{size:14})})})]})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:Pe?"Click the stop button to cancel the current generation":h?"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&&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(ii,{onLoadSession:zs,onClose:()=>vs(!1),activeSessionId:pt})}),e.jsx(ma,{open:!!Ne,mode:(Ne==null?void 0:Ne.mode)||"add",initial:Ne==null?void 0:Ne.initial,replaceCount:At.size,onCancel:()=>bs(null),onSave:Cr}),me&&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:()=>Qs(null)}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":`Step ${me.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:me.step}),e.jsx("span",{className:"text-sm text-gray-200",children:me.description})]}),e.jsx("button",{ref:Xs,onClick:()=>Qs(null),"aria-label":"Close screenshot",className:"text-gray-400 hover:text-gray-200 p-1",children:e.jsx(wt,{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:me.screenshot,alt:"Element screenshot",className:"block max-w-full max-h-[75vh]",onLoad:r=>hr({src:me.screenshot,w:r.currentTarget.naturalWidth,h:r.currentTarget.naturalHeight})}),me.elementRect&&me.elementRect.clipW&&Pi(jt,me.screenshot,me.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:`${me.elementRect.x/me.elementRect.clipW*100}%`,top:`${me.elementRect.y/me.elementRect.clipH*100}%`,width:`${me.elementRect.width/me.elementRect.clipW*100}%`,height:`${me.elementRect.height/me.elementRect.clipH*100}%`,backgroundColor:"transparent",boxShadow:"0 0 0 9999px rgba(0,0,0,0.35)"}})})]})})]})]})]})}function rl(){return e.jsx("div",{className:"flex-1 flex flex-col overflow-hidden h-full",children:e.jsx(Hi,{})})}export{rl as AIRecordPanel};