@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.
- package/LICENSE +88 -69
- package/README.md +6 -2
- package/bin/testver.js +9 -1
- package/dist/index.js +52200 -35695
- package/package.json +179 -178
- package/src/ui/static/agents/antigravity.svg +76 -0
- package/src/ui/static/agents/codex.svg +3 -0
- package/src/ui/static/agents/gemini.svg +1 -0
- package/src/ui/static/agents/opencode.svg +4 -0
- package/src/ui/static/agents/vscode.svg +17 -0
- package/src/ui/static/assets/{AIPanel-KQFq4c0Q.js → AIPanel-RWO8Cd9w.js} +32 -32
- package/src/ui/static/assets/{AIRecordPanel-CAs8fXyS.js → AIRecordPanel-DnreS585.js} +40 -40
- package/src/ui/static/assets/{AIStreamUI-p_sMTEDQ.js → AIStreamUI-C1gHJtlF.js} +9 -9
- package/src/ui/static/assets/{AITestGenPage-CHaHfmu4.js → AITestGenPage-C8bWUelu.js} +5 -5
- package/src/ui/static/assets/{APITestingPage-BSGJY_hd.js → APITestingPage-DwL67hqL.js} +19 -19
- package/src/ui/static/assets/AboutPage-CynLB95E.js +1 -0
- package/src/ui/static/assets/AccessTokensTab-BdevOmpE.js +1 -0
- package/src/ui/static/assets/AdvancedPage-BeM7aB8b.js +3 -0
- package/src/ui/static/assets/{AnalyticsPage-Lm8noJqC.js → AnalyticsPage-C5ddYfRk.js} +1 -1
- package/src/ui/static/assets/AuditLogPage-DYcUdJoj.js +1 -0
- package/src/ui/static/assets/{ChangesSummary-Cu0_4Ucf.js → ChangesSummary-BjNMwGIZ.js} +3 -3
- package/src/ui/static/assets/{CodeMapPage-uEjuo3fk.js → CodeMapPage-BQOEtv-R.js} +3 -3
- package/src/ui/static/assets/{ConfirmDialog-DtotgVmI.js → ConfirmDialog-D_N9188T.js} +1 -1
- package/src/ui/static/assets/{CoveragePage-jNkQJA1P.js → CoveragePage-8bDSphY1.js} +2 -2
- package/src/ui/static/assets/{CronBuilder-D2fERHt9.js → CronBuilder-C7_JADb7.js} +1 -1
- package/src/ui/static/assets/{Dashboard-BaIj_IdQ.js → Dashboard-B22yRPyV.js} +1 -1
- package/src/ui/static/assets/{DefectsPage-DH0njYFG.js → DefectsPage-Arv4Ac-b.js} +72 -72
- package/src/ui/static/assets/{EmptyState-utxlJ0fu.js → EmptyState-BShNSbLf.js} +1 -1
- package/src/ui/static/assets/{ExportButton-ouKqn9CU.js → ExportButton-xrS_AnfS.js} +1 -1
- package/src/ui/static/assets/{FileViewer-mU3JloJ6.js → FileViewer-Bcr9T1jW.js} +18 -18
- package/src/ui/static/assets/{GitPage-TrX-RqNC.js → GitPage-DXL2Sv40.js} +12 -12
- package/src/ui/static/assets/{ImportExportPage-CIhK_raX.js → ImportExportPage-BcjzRd7T.js} +36 -36
- package/src/ui/static/assets/{JiraPushDialog-DgEZS-0u.js → JiraPushDialog-DNYU9Ce0.js} +1 -1
- package/src/ui/static/assets/{KpiTile-BHLE3HVj.js → KpiTile-BKlWqjgN.js} +1 -1
- package/src/ui/static/assets/{LiveExecutionView-CaIf7Jux.js → LiveExecutionView-1LlyEDEe.js} +1 -1
- package/src/ui/static/assets/{MediaModal-DNM45Uz2.js → MediaModal-Dyy_iHl9.js} +1 -1
- package/src/ui/static/assets/MobileRunPicker-Cf5rm469.js +1 -0
- package/src/ui/static/assets/MobileRunTarget-C4M4YJJh.js +6 -0
- package/src/ui/static/assets/{ModuleExplorer-rni7JbsL.js → ModuleExplorer-BKVbxFZK.js} +1 -1
- package/src/ui/static/assets/{OutputPage-Cn2WCpJ6.js → OutputPage-Bi-28tJi.js} +1 -1
- package/src/ui/static/assets/PipelinesPanel-BtO3iSJ4.js +1 -0
- package/src/ui/static/assets/{ProfilePage-BKNdkSnx.js → ProfilePage-BgZ4VDC-.js} +1 -1
- package/src/ui/static/assets/{ProjectExplorer-5e7J8t-o.js → ProjectExplorer-BVGbmVP7.js} +1 -1
- package/src/ui/static/assets/{RemoteFileStrip-C1S2aclP.js → RemoteFileStrip-dzPInzgb.js} +1 -1
- package/src/ui/static/assets/{ReportCard-D4EElEe9.js → ReportCard-LOf1PXlb.js} +2 -2
- package/src/ui/static/assets/{ReportFullView-2w2ysKRg.js → ReportFullView-Ce4OI8lf.js} +1 -1
- package/src/ui/static/assets/{ReportsPage-9Fx-IEwV.js → ReportsPage-DFxCQ8cY.js} +48 -48
- package/src/ui/static/assets/{ResultsPage-DPkfGh-K.js → ResultsPage-DD-uj8gk.js} +115 -115
- package/src/ui/static/assets/{RunState-CRuS_bC2.js → RunState-DDwFB4tA.js} +1 -1
- package/src/ui/static/assets/{RunTargets-CPKBrefj.js → RunTargets-CkIpY3v3.js} +1 -1
- package/src/ui/static/assets/ScriptMappingPage-DQQoR6sR.js +1 -0
- package/src/ui/static/assets/{SearchableDevicePicker-DubIldKj.js → SearchableDevicePicker-CenIxD7b.js} +1 -1
- package/src/ui/static/assets/{SettingsPage-BuZrrlW2.js → SettingsPage-DAV_0y0m.js} +83 -83
- package/src/ui/static/assets/{SharedReportView-ig5hECRk.js → SharedReportView-CqSLFKT1.js} +1 -1
- package/src/ui/static/assets/{SourcesPage-BPkqRqkC.js → SourcesPage-BvqC9oKw.js} +14 -14
- package/src/ui/static/assets/TestExplorerPage-Bdnll77k.js +7 -0
- package/src/ui/static/assets/{TestManagementPage-DJiWpCne.js → TestManagementPage-CCNE688A.js} +10 -10
- package/src/ui/static/assets/{TestPlansPage-G1lvK1C0.js → TestPlansPage-T6D25i6-.js} +5 -5
- package/src/ui/static/assets/{TestverCreditsRing-CEBSy3w3.js → TestverCreditsRing-CoDk5eAS.js} +1 -1
- package/src/ui/static/assets/TestverMcpPage-Dte0qSXp.js +34 -0
- package/src/ui/static/assets/{UncommittedDiffViewer-FKvUZcRi.js → UncommittedDiffViewer-BNroxCoo.js} +2 -2
- package/src/ui/static/assets/{UserManagementPage-gDGhaHE4.js → UserManagementPage-BU4MuDJZ.js} +10 -10
- package/src/ui/static/assets/{WorkflowsPage-BACdnU-1.js → WorkflowsPage-BP5k7AqE.js} +83 -83
- package/src/ui/static/assets/clipboard-BIEd7Ccc.js +1 -0
- package/src/ui/static/assets/{hiddenLlmProviders-DzwaR-b9.js → hiddenLlmProviders-BPORgy-e.js} +1 -1
- package/src/ui/static/assets/index-BlA8ntjb.js +47 -0
- package/src/ui/static/assets/index-Co4_SlGD.css +1 -0
- package/src/ui/static/assets/{reportMeta-3kxT7BIT.js → reportMeta-B9ZRW6ts.js} +1 -1
- package/src/ui/static/assets/runSelected-BoPm1sz-.js +1 -0
- package/src/ui/static/assets/{useFeatureFlags-DrhvBp0C.js → useFeatureFlags-B4Otsv-N.js} +1 -1
- package/src/ui/static/assets/{useJiraConnector-Dwj69Rfh.js → useJiraConnector--JZhbYrT.js} +1 -1
- package/src/ui/static/assets/{useOwnership-C1CmzcvJ.js → useOwnership-BhPOiYzy.js} +1 -1
- package/src/ui/static/assets/useSuites-GN_K2mHc.js +1 -0
- package/src/ui/static/assets/{useTestExplorer-CUqC18DV.js → useTestExplorer-BGhkGHKy.js} +1 -1
- package/src/ui/static/assets/{useTestLifecycle-C2S_vaX2.js → useTestLifecycle-DX5ES6x8.js} +1 -1
- package/src/ui/static/assets/{useTestManagement-DW6AW2mt.js → useTestManagement-ommXjx0q.js} +2 -2
- package/src/ui/static/assets/{useTestResults-yjH1aUy-.js → useTestResults-DWjvm8gm.js} +1 -1
- package/src/ui/static/assets/{vendor-icons-D_Dmmj8d.js → vendor-icons-Cm92aSc5.js} +1426 -1416
- package/src/ui/static/index.html +479 -479
- package/src/ui/static/assets/AboutPage-CDa24SCJ.js +0 -1
- package/src/ui/static/assets/AdvancedPage-BqXP0FLg.js +0 -3
- package/src/ui/static/assets/AuditLogPage-BvldSIik.js +0 -1
- package/src/ui/static/assets/MobileRunPicker-DFKm6_nU.js +0 -1
- package/src/ui/static/assets/MobileRunTarget-DHDoDZ_F.js +0 -6
- package/src/ui/static/assets/PipelinesPanel-D6zWcLtD.js +0 -1
- package/src/ui/static/assets/ScriptMappingPage-C3K_uyf0.js +0 -1
- package/src/ui/static/assets/TestExplorerPage-C_jl93GR.js +0 -7
- package/src/ui/static/assets/index-D6sQYc_0.js +0 -47
- package/src/ui/static/assets/index-aInN0yoR.css +0 -1
- package/src/ui/static/assets/runSelected-WlgnZcSF.js +0 -1
- package/src/ui/static/assets/useSuites-V0AxZYex.js +0 -1
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import{r as n,j as e,d as fe,L as os,n as Zt,R as er,u as sr}from"./vendor-react-DOVfxdUy.js";import{a as Ct}from"./formatDate-T65-Y6Mi.js";import{a as Je,u as Ge,c as Ze}from"./vendor-query-DkZSMtfn.js";import{b as ge,aa as tr,db as rr,a9 as ar,dc as nr,c1 as St,dd as lr,h as or,P as ir,de as dr,df as cr,dg as xr,ae as ws,ab as mr,dh as ur,di as Es,dj as hr,dk as pr,dl as gr,dm as br,dn as fr,dp as yr,dq as jr,dr as vr,ac as Nr,ds as wr,dt as kr,du as Cr,dv as Sr,at as Tr,dw as st,dx as Ar,dy as zr,dz as Er,dA as Pr,dB as Lr,dC as $r,dD as Rr,dE as Mr,dF as Dr,dG as Fr,j as Qs,dH as Ir,dI as ms,dJ as Or,dK as Ur,dL as Br,dM as Kr,dN as _r,dO as Hr,dP as Tt,dQ as Vr,dR as Gr,dS as Wr,dT as qr,dU as Jr,dV as Qr,x as ks,dW as Yr,dX as Xr,dY as Zr,dZ as ea,d_ as sa,y as At,d$ as ta,e0 as ra,e1 as aa,e2 as na,S as la,X as oa,e3 as ia,e4 as da,bO as ca,v as xa,e5 as ma,e6 as tt,ad as ua,e7 as rt,e8 as ha,e9 as pa,ea as ga,eb as ba,ec as fa,ed as at,ee as nt,c0 as lt,d as ya,ef as ot,eg as it,eh as ja,ei as va,ej as Na,ek as wa,el as ka,em as Ca,en as Sa,eo as Ta,ep as Aa}from"./index-D6sQYc_0.js";import{G as za,o as ue,r as ne,bC as zt,aJ as Ea,ci as Pa,aS as ts,aa as ve,X as me,a0 as J,b0 as Et,bd as bs,i as dt,f as La,C as ze,S as Te,v as Ks,b4 as je,an as fs,b7 as we,bO as $a,y as Me,bl as Ys,cH as ys,cI as We,a5 as Pt,bK as Lt,Z as Ee,bt as Ra,Q as js,ag as Ue,a7 as Pe,a as Qe,ap as Se,P as ct,l as Ma,cJ as $t,b6 as Cs,t as Ie,bx as Rt,_ as Ss,c as Ts,K as cs,c9 as Da,N as Fa,cK as Ia,a6 as _s,$ as Oa,bw as Ua,cL as Ba,cM as Ka,au as _a,a1 as Ha,cN as Va,cO as Ga,g as Wa,ac as Mt,aC as qa,J as Oe,cP as Ja,R as $e,F as rs,e as As,cQ as vs,bJ as Qa,a9 as is,az as Ya,bZ as Xa,cR as Ve,cS as Hs,u as zs,cT as qe,b9 as ds,by as Za,cU as Vs,ah as xs,b8 as Ns,a2 as Xs,at as Dt,c8 as en,c7 as sn,j as as,I as Ps,aB as tn,cV as rn,aF as an,b2 as Ft,ck as nn,cW as xt,b5 as gs,cX as ln,ch as on,U as dn,al as cn}from"./vendor-icons-D_Dmmj8d.js";import{u as mt}from"./useTabParam-CyYAP90W.js";import{B as xn,a as ns}from"./RunTargets-CPKBrefj.js";import{r as It}from"./simpleMarkdown-kWs-10D8.js";import{s as mn}from"./visibleInterval-BKsLfJZ3.js";import{u as un}from"./useFeatureFlags-DrhvBp0C.js";import{C as Ot}from"./ConfirmDialog-DtotgVmI.js";import{H as hn,P as pn}from"./hiddenLlmProviders-DzwaR-b9.js";import{h as Ls}from"./aiHandoff-vhtR29Fh.js";import{u as gn,c as bn,d as fn,e as yn,f as jn}from"./useOwnership-C1CmzcvJ.js";import{u as vn,b as Nn}from"./TestverCreditsRing-CEBSy3w3.js";import{T as wn}from"./TestverCreditsDetail-BKpt4oLW.js";const kn=[[0,"Off"],[5,"Every 5 min"],[15,"Every 15 min"],[60,"Every hour"]];function us({on:s,onChange:t,label:a}){return e.jsx("button",{role:"switch","aria-checked":s,"aria-label":a,onClick:()=>t(!s),className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors mt-1 disabled:opacity-50 ${s?"bg-brand-500":"bg-surface-3"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-1"}`})})}function Cn(){const{toast:s}=ge(),t=Je(),a=tr(),{data:l}=Ge({queryKey:["git-status"],queryFn:rr,staleTime:3e4}),m=l!==void 0&&l.available!==!0,{data:i}=ar(a),h=nr(),[d,f]=n.useState(null),[g,y]=n.useState(""),[c,j]=n.useState("1"),{data:p}=Ge({queryKey:["connectors"],queryFn:St,staleTime:6e4}),u=Array.isArray(p)?p:(p==null?void 0:p.connectors)??[],b=u.filter(v=>v.type==="slack"&&v.status==="connected"),z=u.filter(v=>v.type==="email"&&v.status==="connected"),M=n.useCallback(()=>{lr().then(v=>{f(v),y(v.emailRecipients.join(", ")),j(String(v.notifyMinCommits))}).catch(()=>{})},[]);n.useEffect(()=>{M()},[M]);const V=(v,x)=>{f(o=>o&&{...o,...v}),xr(v).then(o=>{f(o),y(o.emailRecipients.join(", ")),j(String(o.notifyMinCommits)),t.invalidateQueries({queryKey:["git-remote-updates"]}),s("success",x??"Remote updates saved")}).catch(o=>{s("error",`Could not save: ${o.message}`),M()})};if(!d)return null;const U=i==null?void 0:i.check,O=or(U),S=()=>{const v=g.split(/[\s,;]+/).map(x=>x.trim()).filter(Boolean);v.join(",")!==d.emailRecipients.join(",")&&V({emailRecipients:v},"Recipients saved")},I=()=>{const v=Math.round(Number(c));if(!Number.isFinite(v)||v<1||v>100){j(String(d.notifyMinCommits)),s("error","Use a number from 1 to 100");return}v!==d.notifyMinCommits&&V({notifyMinCommits:v})},w=(v,x,o)=>e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:v}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:x})]}),o]});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(za,{size:18,className:"text-sky-500"}),"Remote updates",e.jsx("span",{className:"text-[11px] font-medium px-2 py-0.5 rounded-full bg-sky-500/10 text-sky-500 border border-sky-500/20",title:"These settings apply only when the project is a Git repository",children:"Git projects only"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:"For projects kept in a Git repository: Testver checks the remote (GitHub, GitLab, Bitbucket, Azure DevOps or any git server) for new commits on the branch this server is on, tells you before they surprise you, and predicts whether pulling them will conflict with local work. A check only downloads — your files never change until someone pulls."})]}),m&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3.5 py-2.5 text-sm text-gray-400",children:[e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0 text-amber-500"}),e.jsxs("span",{children:[e.jsx("b",{className:"text-gray-300",children:"This project isn't a Git repository"}),", so there is nothing to check. These settings take effect once it is — for example after you clone the project with git, or set it up on the Git page."]})]}),a&&U&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-white/10 bg-surface-2/40 px-3.5 py-2.5 text-sm text-gray-400",children:[U.ok?e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}):e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0 text-amber-500"}),e.jsxs("span",{children:["Last check ",ir(U.checkedAt),":"," ",U.skipped?e.jsxs("b",{className:"text-gray-300",children:["nothing to check (",U.skipped==="unpublished"?"the branch isn't published":U.skipped==="detached"?"not on a branch":U.skipped==="operation"?"a merge or rebase is in progress":"no remote",")"]}):U.ok?U.behind>0?e.jsxs("b",{className:"text-gray-300",children:[U.upstream," has ",dr(U.behind,"new commit")]}):e.jsxs("b",{className:"text-gray-300",children:["up to date with ",U.upstream]}):e.jsxs("b",{className:"text-gray-300",children:["couldn't reach ",O]}),i!=null&&i.nextCheckAt?e.jsxs(e.Fragment,{children:[" · next check ",cr(i.nextCheckAt)]}):null," · ",e.jsx("button",{onClick:()=>h.mutate(void 0,{onError:v=>s("error",v.message)}),className:"text-sky-600 hover:underline",disabled:h.isPending,children:h.isPending?"Checking…":"Check now"})]})]}),w("Check for new commits","How often to look. Checks pause while a merge or rebase is in progress and on branches that aren't published.",e.jsx("div",{role:"group",className:"inline-flex rounded-lg border border-white/10 bg-white dark:bg-surface-2 overflow-hidden flex-shrink-0",children:kn.map(([v,x],o)=>e.jsx("button",{onClick:()=>v!==d.intervalMinutes&&V({intervalMinutes:v},v?`Checks every ${v===60?"hour":`${v} minutes`}`:"Remote checks turned off"),className:`px-3.5 py-1.5 text-sm font-medium transition-colors ${o?"border-l border-white/10":""} ${d.intervalMinutes===v?"bg-sky-500/15 text-sky-700 dark:text-sky-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,children:x},v))})),e.jsx("div",{className:"border-t border-white/5"}),w("Warn before test runs","When the branch is behind, a run first asks “Pull, then run / Run anyway” — and says which incoming commits change files the tests use.",e.jsx(us,{on:d.warnBeforeRuns,label:"Warn before test runs",onChange:v=>V({warnBeforeRuns:v})})),w("Tell the AI Assistant","The assistant mentions when a file it is working on is newer on the remote.",e.jsx(us,{on:d.tellAI,label:"Tell the AI Assistant",onChange:v=>V({tellAI:v})})),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Notifications"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"Sent once per new set of commits that meets the rule below. The Git page, the header and the sidebar always show new commits."}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(us,{on:d.emailEnabled,label:"E-mail notifications",onChange:v=>V({emailEnabled:v})}),e.jsx(zt,{size:15,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-300 w-20",children:"Email"}),e.jsx("input",{value:g,onChange:v=>y(v.target.value),onBlur:S,onKeyDown:v=>{v.key==="Enter"&&S()},placeholder:"qa-team@example.com, lead@example.com",className:"flex-1 min-w-[16rem] bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-sm text-gray-200 focus:outline-none focus:border-sky-500/50"})]}),d.emailEnabled&&z.length===0&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 ml-12",children:"No e-mail connector is connected — add one in Connectors, or nothing can be sent."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(us,{on:d.slackEnabled,label:"Slack notifications",onChange:v=>V({slackEnabled:v})}),e.jsx(Ea,{size:15,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-300 w-20",children:"Slack"}),e.jsx("span",{className:"flex-1 text-sm text-gray-400",children:b.length===0?"No Slack connector is connected — add one in Connectors.":e.jsxs(e.Fragment,{children:["Posts to ",b.map((v,x)=>{var o;return e.jsxs("b",{className:"text-gray-300",children:[x?", ":"",(o=v.config)!=null&&o.channel?`#${String(v.config.channel).replace(/^#/,"")}`:v.name||"Slack"]},v.id??x)})]})})]}),e.jsxs("div",{className:"flex items-start gap-3 flex-wrap",children:[e.jsx("span",{className:"w-9"}),e.jsx(Pa,{size:15,className:"text-gray-500 mt-1.5"}),e.jsx("span",{className:"text-sm text-gray-300 w-20 mt-1",children:"Notify when"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-300",children:["At least",e.jsx("input",{value:c,onChange:v=>j(v.target.value.replace(/[^\d]/g,"")),onBlur:I,onKeyDown:v=>{v.key==="Enter"&&I()},inputMode:"numeric","aria-label":"Minimum new commits",className:"w-16 bg-surface-2 border border-white/10 rounded-lg px-2 py-1.5 text-sm text-gray-200 text-center focus:outline-none focus:border-sky-500/50"}),"new commit(s)"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-400",children:[e.jsx("input",{type:"checkbox",checked:d.notifyOnlyRisky,onChange:v=>V({notifyOnlyRisky:v.target.checked}),className:"rounded border-white/20"}),"Only when pulling would conflict or touch uncommitted work"]})]})]})]})]})]})}const ut=s=>`---
|
|
2
|
-
name: My Custom Skill
|
|
3
|
-
slug: my-custom-skill
|
|
4
|
-
description: Describe what this skill teaches the AI
|
|
5
|
-
version: 1.0.0
|
|
6
|
-
author: ${s}
|
|
7
|
-
tags:
|
|
8
|
-
- testing
|
|
9
|
-
- custom
|
|
10
|
-
frameworks:
|
|
11
|
-
- playwright
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# My Custom Skill
|
|
15
|
-
|
|
16
|
-
## Overview
|
|
17
|
-
Describe the purpose and context for this skill here.
|
|
18
|
-
|
|
19
|
-
## Best Practices
|
|
20
|
-
- Practice 1
|
|
21
|
-
- Practice 2
|
|
22
|
-
- Practice 3
|
|
23
|
-
|
|
24
|
-
## Code Patterns
|
|
25
|
-
When generating code for this workflow, follow these patterns:
|
|
26
|
-
|
|
27
|
-
\`\`\`typescript
|
|
28
|
-
// Example code pattern
|
|
29
|
-
\`\`\`
|
|
30
|
-
|
|
31
|
-
## Common Mistakes to Avoid
|
|
32
|
-
1. Mistake 1 — explanation
|
|
33
|
-
2. Mistake 2 — explanation
|
|
34
|
-
`;function
|
|
35
|
-
`),w={};let v=!1,x=0;for(let r=0;r<I.length;r++){const E=I[r].trim();if(E==="---"){if(v){x=r+1;break}v=!0;continue}if(v&&E.includes(":")&&!E.startsWith("-")){const P=E.indexOf(":"),B=E.slice(0,P).trim(),N=E.slice(P+1).trim();N&&(w[B]=N)}}const o=I.slice(x).join(`
|
|
36
|
-
`).trim();return{meta:w,body:o}},U=async()=>{c(!0),p(null);try{await a(f,m),t()}catch(I){p(String(I))}finally{c(!1)}},{meta:O,body:S}=V();return fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-4xl mx-4 h-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-white/5 flex items-center justify-between flex-shrink-0",children:[e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:M}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>b(!u),className:`
|
|
37
|
-
flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg transition-colors
|
|
38
|
-
${u?"bg-cyan-500/15 text-cyan-300":"bg-surface-2 text-gray-400 hover:text-gray-300"}
|
|
39
|
-
`,children:[u?e.jsx(ts,{size:14}):e.jsx(ve,{size:14}),u?"Editor":"Preview"]}),e.jsx("button",{onClick:t,className:"text-gray-500 hover:text-gray-300 transition-colors p-1",children:e.jsx(me,{size:18})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:u?e.jsxs("div",{className:"h-full overflow-y-auto p-6",children:[(O.name||O.description)&&e.jsxs("div",{className:"mb-6 p-4 rounded-lg bg-surface-2/50 border border-white/5",children:[O.name&&e.jsx("h2",{className:"text-lg font-semibold text-gray-200 mb-1",children:O.name}),O.description&&e.jsx("p",{className:"text-sm text-gray-400",children:O.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-gray-500",children:[O.version&&e.jsxs("span",{children:["v",O.version]}),O.author&&e.jsxs("span",{children:["by ",O.author]})]})]}),e.jsx("div",{className:"skill-markdown-preview text-sm text-gray-300 leading-relaxed",dangerouslySetInnerHTML:{__html:It(S)}})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"px-6 py-2 bg-surface-2/30 border-b border-white/5 text-xs text-gray-500 flex-shrink-0",children:["Write YAML frontmatter between ",e.jsx("code",{className:"text-cyan-400/80",children:"---"})," delimiters, then markdown body below.",z&&e.jsx("span",{className:"ml-2 text-amber-400/80",children:"Editing existing skill — slug cannot be changed."})]}),e.jsx("textarea",{value:f,onChange:I=>g(I.target.value),className:"flex-1 w-full bg-transparent text-gray-300 font-mono text-[13px] leading-relaxed p-6 resize-none focus:outline-none",spellCheck:!1,placeholder:"Paste or write your SKILL.md content here..."})]})}),j&&e.jsxs("div",{className:"px-6 py-3 bg-red-500/10 border-t border-red-500/20 flex items-center gap-2 flex-shrink-0",children:[e.jsx(ue,{size:14,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-red-300",children:j})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{className:"text-xs text-gray-500",children:[f.length.toLocaleString()," chars · ~",Math.round(f.length/4).toLocaleString()," tokens"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:U,disabled:y||!f.trim(),className:"px-4 py-2 text-sm rounded-lg bg-cyan-600 hover:bg-cyan-500 text-white font-medium transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",children:[y?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Et,{size:14}),z?"Update Skill":"Create Skill"]})]})]})]})}),document.body)}function
|
|
40
|
-
border-2 border-dashed rounded-xl p-8 text-center cursor-pointer transition-all
|
|
41
|
-
${z?"border-cyan-400 bg-cyan-500/5":h?"border-emerald-500/30 bg-emerald-500/5":"border-white/10 hover:border-white/20 bg-surface-2/30"}
|
|
42
|
-
`,children:[e.jsx("input",{ref:V,type:"file",accept:".md",onChange:S,className:"hidden"}),h?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:28,className:"mx-auto mb-2 text-emerald-400"}),e.jsx("p",{className:"text-sm text-emerald-300 font-medium",children:f||"Content loaded"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[h.length.toLocaleString()," chars · Click to change file"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{size:28,className:"mx-auto mb-2 text-gray-500"}),e.jsxs("p",{className:"text-sm text-gray-400",children:["Drop a ",e.jsx("code",{className:"text-cyan-400/80",children:".md"})," file here or click to browse"]}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"SKILL.md format: YAML frontmatter + Markdown body"})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"flex-1 h-px bg-white/5"}),e.jsx("span",{className:"text-xs text-gray-600",children:"or paste content"}),e.jsx("div",{className:"flex-1 h-px bg-white/5"})]}),e.jsx("textarea",{value:h,onChange:v=>{d(v.target.value),g(""),b(null)},placeholder:"Paste SKILL.md content here...",rows:6,className:"w-full bg-surface-2/50 border border-white/5 rounded-lg p-3 text-sm text-gray-300 font-mono placeholder-gray-600 focus:outline-none focus:border-cyan-500/30 resize-none"})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-2",children:"GitHub URL"}),e.jsx("input",{type:"url",value:y,onChange:v=>{c(v.target.value),b(null)},placeholder:"https://github.com/user/repo/blob/main/skills/my-skill.md",className:"w-full bg-surface-2/50 border border-white/5 rounded-lg px-3 py-2.5 text-sm text-gray-300 placeholder-gray-600 focus:outline-none focus:border-cyan-500/30"})]}),e.jsxs("div",{className:"bg-surface-2/30 rounded-lg p-3 space-y-1.5",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Supported URL formats:"}),e.jsxs("ul",{className:"text-xs text-gray-600 space-y-1 ml-4 list-disc",children:[e.jsx("li",{children:e.jsx("code",{className:"text-cyan-400/60",children:"github.com/user/repo/blob/branch/path.md"})}),e.jsx("li",{children:e.jsx("code",{className:"text-cyan-400/60",children:"raw.githubusercontent.com/user/repo/branch/path.md"})}),e.jsx("li",{children:e.jsx("code",{className:"text-cyan-400/60",children:"gist.github.com/user/id/raw/file.md"})})]})]})]})}),u&&e.jsxs("div",{className:"px-6 py-3 bg-red-500/10 border-t border-red-500/20 flex items-center gap-2",children:[e.jsx(ue,{size:14,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-red-300",children:u})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:I,disabled:j||!w,className:"px-4 py-2 text-sm rounded-lg bg-cyan-600 hover:bg-cyan-500 text-white font-medium transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",children:[j?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(bs,{size:14}),m==="url"?"Import from URL":"Import"]})]})]})}),document.body)}function An({tags:s,value:t,onChange:a}){const[l,m]=n.useState(!1),[i,h]=n.useState(""),d=n.useRef(null);n.useEffect(()=>{if(!l)return;const c=p=>{d.current&&!d.current.contains(p.target)&&m(!1)},j=p=>{p.key==="Escape"&&m(!1)};return document.addEventListener("mousedown",c),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",j)}},[l]);const f=n.useMemo(()=>s.filter(c=>c.toLowerCase().includes(i.trim().toLowerCase())),[s,i]),g=c=>{a(c),m(!1),h("")},y=t==="all"?"All Tags":t;return e.jsxs("div",{className:"relative",ref:d,children:[e.jsxs("button",{type:"button",onClick:()=>m(c=>!c),className:"flex items-center gap-2 bg-surface-1 border border-white/10 rounded-lg pl-3 pr-2.5 py-2 text-sm text-gray-300 focus:outline-none focus:border-cyan-500/50 hover:border-white/20 transition-colors min-w-[150px]",children:[e.jsx($a,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"flex-1 text-left truncate",children:y}),e.jsx(Me,{size:14,className:`text-gray-500 flex-shrink-0 transition-transform ${l?"rotate-180":""}`})]}),l&&e.jsxs("div",{className:"absolute left-0 z-30 mt-1.5 w-[230px] rounded-lg border border-white/10 bg-surface-1 shadow-xl overflow-hidden",children:[e.jsx("div",{className:"p-2 border-b border-white/5",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ks,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{autoFocus:!0,type:"text",value:i,onChange:c=>h(c.target.value),placeholder:"Search tags...",className:"w-full bg-surface-2 border border-white/10 rounded-md pl-8 pr-2 py-1.5 text-xs text-gray-200 placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"})]})}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[e.jsx(ht,{label:"All Tags",active:t==="all",onClick:()=>g("all")}),f.length===0?e.jsx("div",{className:"px-3 py-3 text-xs text-gray-500 text-center",children:"No tags found"}):f.map(c=>e.jsx(ht,{label:c,active:t===c,onClick:()=>g(c)},c))]})]})]})}function ht({label:s,active:t,onClick:a}){return e.jsxs("button",{type:"button",onClick:a,className:`w-full flex items-center gap-2 px-3 py-1.5 text-sm text-left transition-colors ${t?"bg-cyan-500/10 text-cyan-300":"text-gray-300 hover:bg-white/5"}`,children:[e.jsx(Ue,{size:13,className:`flex-shrink-0 ${t?"text-cyan-400":"text-transparent"}`}),e.jsx("span",{className:"truncate",children:s})]})}const zn={testing:{text:"text-emerald-400",bg:"bg-transparent",border:"border-emerald-500/30"},browser:{text:"text-blue-400",bg:"bg-transparent",border:"border-blue-500/30"},e2e:{text:"text-violet-400",bg:"bg-transparent",border:"border-violet-500/30"},unit:{text:"text-amber-400",bg:"bg-transparent",border:"border-amber-500/30"},integration:{text:"text-orange-400",bg:"bg-transparent",border:"border-orange-500/30"},bdd:{text:"text-pink-400",bg:"bg-transparent",border:"border-pink-500/30"},gherkin:{text:"text-pink-400",bg:"bg-transparent",border:"border-pink-500/30"},python:{text:"text-yellow-400",bg:"bg-transparent",border:"border-yellow-500/30"},java:{text:"text-red-400",bg:"bg-transparent",border:"border-red-500/30"},javascript:{text:"text-amber-400",bg:"bg-transparent",border:"border-amber-500/30"},cicd:{text:"text-teal-400",bg:"bg-transparent",border:"border-teal-500/30"},devops:{text:"text-teal-400",bg:"bg-transparent",border:"border-teal-500/30"},codegen:{text:"text-cyan-400",bg:"bg-transparent",border:"border-cyan-500/30"},pom:{text:"text-indigo-400",bg:"bg-transparent",border:"border-indigo-500/30"},analysis:{text:"text-fuchsia-400",bg:"bg-transparent",border:"border-fuchsia-500/30"},healing:{text:"text-rose-400",bg:"bg-transparent",border:"border-rose-500/30"},debugging:{text:"text-fuchsia-400",bg:"bg-transparent",border:"border-fuchsia-500/30"},pipeline:{text:"text-teal-400",bg:"bg-transparent",border:"border-teal-500/30"},"page-object":{text:"text-indigo-400",bg:"bg-transparent",border:"border-indigo-500/30"},results:{text:"text-sky-400",bg:"bg-transparent",border:"border-sky-500/30"},selectors:{text:"text-rose-400",bg:"bg-transparent",border:"border-rose-500/30"},maintenance:{text:"text-gray-400",bg:"bg-transparent",border:"border-gray-500/30"},custom:{text:"text-purple-400",bg:"bg-transparent",border:"border-purple-500/30"}};function Ut(s){return zn[s]||{text:"text-gray-400",bg:"bg-transparent",border:"border-gray-500/30"}}function En({readOnly:s=!1}={}){const{toast:t}=ge(),[a,l]=n.useState([]),[m,i]=n.useState(!0),[h,d]=n.useState(""),[f,g]=n.useState("all"),[y,c]=n.useState("all"),[j,p]=n.useState(null),[u,b]=n.useState(null),[z,M]=n.useState(!1),[V,U]=n.useState(new Set),[O,S]=n.useState(!1),[I,w]=n.useState(!1),[v,x]=n.useState(),[o,r]=n.useState(),[E,P]=n.useState(),[B,N]=n.useState(!1),[ee,K]=n.useState(null),W=n.useCallback(async()=>{try{i(!0);const F=await mr();l(F.skills)}catch(F){t("error",`Failed to load skills: ${F}`)}finally{i(!1)}},[t]);n.useEffect(()=>{W()},[W]);const R=n.useMemo(()=>{const F=new Set;return a.forEach(Q=>Q.tags.forEach(se=>F.add(se))),Array.from(F).sort()},[a]),G=n.useMemo(()=>{let F=a;if(h){const Q=h.toLowerCase();F=F.filter(se=>se.name.toLowerCase().includes(Q)||se.slug.toLowerCase().includes(Q)||se.description.toLowerCase().includes(Q)||se.tags.some(ie=>ie.toLowerCase().includes(Q))||se.frameworks.some(ie=>ie.toLowerCase().includes(Q)))}return f!=="all"&&(F=F.filter(Q=>Q.tags.includes(f))),y!=="all"&&(F=F.filter(Q=>Q.source===y)),F},[a,h,f,y]),_=a.filter(F=>F.enabled).length,A=a.filter(F=>F.enabled).reduce((F,Q)=>F+Q.tokenEstimate,0),te=a.filter(F=>F.source==="user").length,X=async(F,Q)=>{U(se=>new Set(se).add(F));try{Q?await hr(F):await pr(F),l(se=>se.map(ie=>ie.slug===F?{...ie,enabled:!Q}:ie)),u&&u.slug===F&&b(se=>se?{...se,enabled:!Q}:null)}catch(se){t("error",`Failed to ${Q?"disable":"enable"} skill: ${se}`)}finally{U(se=>{const ie=new Set(se);return ie.delete(F),ie})}},le=async()=>{try{await jr(),S(!1),p(null),b(null),t("success","Skills reset to defaults (custom skills removed)"),await W()}catch(F){t("error",`Failed to reset: ${F}`)}},$=async F=>{if(j===F){p(null),b(null);return}p(F),M(!0);try{const Q=await Es(F);b(Q)}catch(Q){t("error",`Failed to load skill preview: ${Q}`),b(null)}finally{M(!1)}},re=async F=>{await br(F),t("success","Custom skill created"),await W()},ae=async(F,Q)=>{if(Q){if(await gr(Q,F),t("success",`Skill "${Q}" updated`),j===Q){const se=await Es(Q);b(se)}await W()}},ce=async F=>{try{await vr(F),K(null),j===F&&(p(null),b(null)),t("success",`Skill "${F}" deleted`),await W()}catch(Q){t("error",`Failed to delete skill: ${Q}`)}},he=async(F,Q)=>{await yr(F,Q),t("success","Skill imported successfully"),await W()},xe=async F=>{await fr(F),t("success","Skill imported from URL successfully"),await W()},ye=F=>{window.open(ur(F),"_blank")},Ne=()=>{x(void 0),r(void 0),P("Create Custom Skill"),w(!0)},ke=async F=>{var Q,se,ie;try{const be=await Es(F),oe=be.metadata,k=["---"];k.push(`name: ${oe.name}`),k.push(`slug: ${oe.slug}`),k.push(`description: ${oe.description}`),oe.version&&k.push(`version: ${oe.version}`),oe.author&&k.push(`author: ${oe.author}`),(Q=oe.tags)!=null&&Q.length&&(k.push("tags:"),oe.tags.forEach(q=>k.push(` - ${q}`))),(se=oe.frameworks)!=null&&se.length&&(k.push("frameworks:"),oe.frameworks.forEach(q=>k.push(` - ${q}`))),(ie=oe.tools)!=null&&ie.length&&(k.push("tools:"),oe.tools.forEach(q=>k.push(` - ${q}`))),k.push("---");const C=k.join(`
|
|
43
|
-
`)+`
|
|
44
|
-
|
|
45
|
-
`+be.body;x(C),r(F),P(`Edit Skill: ${oe.name}`),w(!0)}catch(be){t("error",`Failed to load skill for editing: ${be}`)}};return m?e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(J,{size:24,className:"animate-spin text-brand-400 mr-3"}),e.jsx("span",{className:"text-gray-400",children:"Loading skills..."})]}):e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[s&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"View only — Agent Skills are managed by your admin. You can browse them here and use them in the AI Assistant, but not add, edit, enable/disable, or delete them."})]}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5",children:[e.jsx(Te,{size:16,className:"text-cyan-400"}),"Agent Skills"]}),e.jsx("p",{className:"mt-1.5 text-sm text-gray-400 max-w-lg",children:"Skills inject domain-specific best practices into the AI system prompt. Enable skills for your frameworks or create custom ones for your workflows."})]}),e.jsx("div",{className:"flex items-center gap-4 flex-shrink-0 ml-4",children:e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-300",children:[e.jsx("span",{className:"text-cyan-400",children:_}),"/",a.length," enabled"]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5",children:["~",A.toLocaleString()," tokens active",te>0&&e.jsxs("span",{className:"ml-1.5 text-purple-400",children:["· ",te," custom"]})]})]})})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(Ks,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",placeholder:"Search skills...",value:h,onChange:F=>d(F.target.value),className:"w-full bg-surface-1 border border-white/10 rounded-lg pl-9 pr-3 py-2 text-sm text-gray-200 placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),h&&e.jsx("button",{onClick:()=>d(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:e.jsx(me,{size:14})})]}),e.jsx(
|
|
46
|
-
px-3 py-2 text-xs capitalize transition-all
|
|
47
|
-
${y===F?"bg-cyan-500/10 text-cyan-300 border-r border-cyan-500/15":"bg-transparent text-gray-500 hover:text-cyan-300/70 border-r border-cyan-500/15 last:border-r-0"}
|
|
48
|
-
`,children:F==="user"?"Custom":F==="all"?"All":"Built-in"},F))}),!s&&e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs("button",{onClick:Ne,className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all flex items-center gap-1.5",children:[e.jsx(je,{size:14}),"Create"]}),e.jsxs("button",{onClick:()=>N(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-violet-500/5 text-violet-400/80 border border-violet-500/20 hover:border-violet-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(bs,{size:12}),"Import"]}),e.jsxs("button",{onClick:()=>S(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-amber-500/5 text-amber-400/70 border border-amber-500/20 hover:border-amber-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(fs,{size:12}),"Reset"]})]})]}),e.jsx("div",{className:"grid gap-3 grid-cols-1 lg:grid-cols-2",children:G.length===0?e.jsxs("div",{className:"col-span-full flex flex-col items-center py-12 text-gray-500",children:[e.jsx(Ks,{size:32,className:"mb-3 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No skills match your search"}),y==="user"&&!s&&e.jsxs("button",{onClick:Ne,className:"mt-3 text-xs text-cyan-400 hover:text-cyan-300 flex items-center gap-1 px-3 py-1.5 rounded-lg border border-cyan-500/20 hover:border-cyan-500/40 transition-all",children:[e.jsx(je,{size:12}),"Create your first custom skill"]})]}):G.map(F=>e.jsx(
|
|
49
|
-
group relative bg-surface-1 rounded-xl border p-4 transition-all cursor-pointer
|
|
50
|
-
${a?"border-cyan-500/40 ring-1 ring-cyan-500/20 bg-cyan-500/[0.03]":"border-white/5 hover:border-white/15 hover:bg-surface-1/80"}
|
|
51
|
-
${s.enabled?"":"opacity-60"}
|
|
52
|
-
`,onClick:m,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`
|
|
53
|
-
mt-0.5 p-2 rounded-lg flex-shrink-0 border
|
|
54
|
-
${s.enabled?"bg-transparent text-cyan-400 border-cyan-500/25":"bg-transparent text-gray-500 border-white/10"}
|
|
55
|
-
`,children:s.source==="builtin"?e.jsx(
|
|
56
|
-
flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium border cursor-default
|
|
57
|
-
${s.enabled?"bg-transparent text-cyan-300/80 border-cyan-500/25":"bg-transparent text-gray-400 border-white/10"}
|
|
58
|
-
`,children:[s.enabled?e.jsx(Ee,{size:12}):e.jsx(We,{size:12}),s.enabled?"Enabled":"Disabled"]}):e.jsxs("button",{onClick:m,disabled:i,className:`
|
|
59
|
-
flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium transition-all border
|
|
60
|
-
${s.enabled?"bg-transparent text-cyan-300 border-cyan-500/30 hover:bg-cyan-500/5 hover:border-cyan-500/50":"bg-transparent text-gray-400 border-white/10 hover:border-white/25"}
|
|
61
|
-
`,children:[i?e.jsx(J,{size:12,className:"animate-spin"}):s.enabled?e.jsx(Ee,{size:12}):e.jsx(We,{size:12}),s.enabled?"Enabled":"Disabled"]})]})]}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Ra,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Tags"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.metadata.tags.map(j=>{const p=Ut(j);return e.jsx("span",{className:`text-xs px-2.5 py-1 rounded border ${p.bg} ${p.text} ${p.border}`,children:j},j)})})]}),s.metadata.frameworks&&s.metadata.frameworks.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ts,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Frameworks"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.metadata.frameworks.map(j=>e.jsx("span",{className:"text-xs px-2.5 py-1 rounded bg-transparent text-brand-300 border border-brand-500/25",children:j},j))})]}),e.jsxs("div",{className:"px-6 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-gray-400",children:[e.jsx(js,{size:14}),"Skill Instructions (",s.body.length," chars)"]}),e.jsxs("div",{className:"flex items-center rounded overflow-hidden border border-cyan-500/15",children:[e.jsx("button",{onClick:()=>y("rendered"),className:`px-2 py-1 text-[10px] transition-all ${g==="rendered"?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}`,title:"Rendered markdown",children:e.jsx(ve,{size:10})}),e.jsx("button",{onClick:()=>y("raw"),className:`px-2 py-1 text-[10px] transition-all ${g==="raw"?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}`,title:"Raw source",children:e.jsx(ts,{size:10})})]})]}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded-lg bg-surface-0/50 border border-white/5 p-4",children:g==="rendered"?e.jsx("div",{className:"skill-markdown-preview text-sm text-gray-400 leading-relaxed",dangerouslySetInnerHTML:{__html:It(s.body)}}):e.jsx("pre",{className:"text-xs text-gray-400 leading-relaxed whitespace-pre-wrap font-mono",children:s.body})})]})]}),e.jsx("div",{className:"flex-shrink-0 px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end",children:e.jsx("button",{onClick:l,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Close"})})]}):e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("span",{className:"text-sm text-gray-500",children:"Skill not found"})})})}),document.body)}const
|
|
62
|
-
group relative bg-surface-1 rounded-xl border p-4 transition-all
|
|
63
|
-
${s.status==="connected"?"border-emerald-500/20":"border-white/5 hover:border-white/15"}
|
|
64
|
-
${s.enabled?"":"opacity-60"}
|
|
65
|
-
`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:`
|
|
66
|
-
p-1.5 rounded-lg flex-shrink-0 border
|
|
67
|
-
${s.status==="connected"?`bg-transparent border-emerald-500/25 ${ls(s.name).color}`:`bg-transparent border-white/10 ${ls(s.name).color}`}
|
|
68
|
-
`,children:ls(s.name).node}),e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200 truncate",children:s.name}),e.jsx(Bt,{type:s.transportType})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 ml-9",children:[e.jsx(
|
|
69
|
-
"mcpServers": {
|
|
70
|
-
"playwright": {
|
|
71
|
-
"command": "npx",
|
|
72
|
-
"args": ["@playwright/mcp@latest"]
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}`;function
|
|
76
|
-
flex items-center gap-2 px-4 py-2.5 text-sm font-medium transition-all flex-1 justify-center
|
|
77
|
-
${b.transportType===x?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}
|
|
78
|
-
`,children:[x==="stdio"?e.jsx(Ts,{size:14}):e.jsx(cs,{size:14}),x.toUpperCase()]},x))})]}),b.transportType==="stdio"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Command"}),e.jsx("input",{type:"text",value:b.command,onChange:x=>z(o=>({...o,command:x.target.value})),placeholder:"npx",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Arguments (comma-separated)"}),e.jsx("input",{type:"text",value:b.args,onChange:x=>z(o=>({...o,args:x.target.value})),placeholder:"-y, @modelcontextprotocol/server-everything",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),b.args.includes("--dsn")&&e.jsxs("div",{className:"mt-2.5 p-3 rounded-lg border border-cyan-500/15 bg-cyan-500/5",children:[e.jsx("p",{className:"text-xs font-medium text-cyan-400 mb-2",children:"DSN Connection String Formats:"}),e.jsxs("div",{className:"space-y-1 font-mono text-[11px] text-gray-400",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-emerald-400",children:"postgres:"})," postgres://user:password@localhost:5432/dbname?sslmode=require"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-orange-400",children:"mysql:"})," mysql://root:password@localhost:3306/mysql?sslmode=require"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-purple-400",children:"mariadb:"})," mariadb://root:password@localhost:3306/db?sslmode=require"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-blue-400",children:"sqlserver:"})," sqlserver://user:password@localhost:1433/database?instanceName=INST1"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-yellow-400",children:"sqlite:"})," sqlite:///path/to/database.db"]})]}),e.jsx("p",{className:"text-[11px] text-gray-500 mt-2",children:"Replace the sample DSN value above with your actual connection string."})]})]})]}),(b.transportType==="sse"||b.transportType==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Server URL"}),e.jsx("input",{type:"text",value:b.url,onChange:x=>z(o=>({...o,url:x.target.value})),placeholder:b.transportType==="http"?"http://localhost:3001/mcp":"http://localhost:3001/sse",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("p",{className:"mt-1.5 text-[11px] text-gray-500",children:b.transportType==="http"?"MCP Streamable HTTP endpoint (the modern replacement for SSE).":"MCP Server-Sent Events endpoint."})]}),(b.transportType==="sse"||b.transportType==="http")&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"Headers"}),e.jsxs("button",{onClick:O,className:"text-xs text-cyan-400 hover:text-cyan-300 flex items-center gap-1 px-2.5 py-1 rounded border border-cyan-500/20 hover:border-cyan-500/40 transition-all",children:[e.jsx(je,{size:12})," Add"]})]}),b.headers.length===0&&e.jsxs("p",{className:"text-sm text-gray-600 italic",children:["No headers — add e.g. ",e.jsx("span",{className:"font-mono",children:"Authorization: Bearer <token>"})," for authenticated servers"]}),e.jsx("div",{className:"space-y-2",children:b.headers.map((x,o)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x.key,onChange:r=>I(o,"key",r.target.value),placeholder:"Header-Name",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("input",{type:"text",value:x.value,onChange:r=>I(o,"value",r.target.value),placeholder:"value",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("button",{onClick:()=>S(o),className:"p-1.5 text-gray-500 hover:text-red-400",children:e.jsx(me,{size:16})})]},o))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"Environment Variables"}),e.jsxs("button",{onClick:M,className:"text-xs text-cyan-400 hover:text-cyan-300 flex items-center gap-1 px-2.5 py-1 rounded border border-cyan-500/20 hover:border-cyan-500/40 transition-all",children:[e.jsx(je,{size:12})," Add"]})]}),b.envVars.length===0&&e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No environment variables configured"}),e.jsx("div",{className:"space-y-2",children:b.envVars.map((x,o)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x.key,onChange:r=>U(o,"key",r.target.value),placeholder:"KEY",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("input",{type:"text",value:x.value,onChange:r=>U(o,"value",r.target.value),placeholder:"value",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("button",{onClick:()=>V(o),className:"p-1.5 text-gray-500 hover:text-red-400",children:e.jsx(me,{size:16})})]},o))})]}),e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:b.autoConnect,onChange:x=>z(o=>({...o,autoConnect:x.target.checked})),className:"rounded border-white/20 bg-white/5 text-cyan-500 focus:ring-cyan-500/30"}),e.jsx("span",{className:"text-sm text-gray-400",children:"Auto-connect on server startup"})]})]})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Cancel"}),i==="json"?e.jsxs("button",{onClick:p,disabled:!d.trim()||c,className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm rounded-lg bg-transparent text-cyan-400 border border-cyan-500/30 hover:bg-cyan-500/10 hover:border-cyan-500/50 font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[c&&e.jsx(J,{size:14,className:"animate-spin"}),"Add Server(s)"]}):e.jsx("button",{onClick:()=>t(b),disabled:!b.name.trim()||b.transportType==="stdio"&&!b.command.trim()||(b.transportType==="sse"||b.transportType==="http")&&!b.url.trim(),className:"px-4 py-2 text-sm rounded-lg bg-transparent text-cyan-400 border border-cyan-500/30 hover:bg-cyan-500/10 hover:border-cyan-500/50 font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:s?"Save Changes":"Add Server"})]})]})})}function Un({presets:s,available:t,onAdd:a,onClose:l}){const m=new Set(t.map(y=>y.name)),[i,h]=n.useState(null),d={browser:"Browser & UI Testing",database:"Database Testing",filesystem:"File System & Version Control",devtools:"Development & Testing",api:"API & Contract Testing"},f=s.reduce((y,c,j)=>{const p=c.category||"other";return y[p]||(y[p]=[]),y[p].push({preset:c,index:j}),y},{}),g=async y=>{h(y),await a(y),h(null)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-4xl mx-4 max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsx("div",{className:"px-6 py-5 border-b border-white/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-transparent border border-cyan-500/25",children:e.jsx(js,{size:20,className:"text-cyan-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-200",children:"MCP Server Catalog"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"Pre-configured MCP servers for test automation"})]})]}),e.jsx("button",{onClick:l,className:"text-gray-500 hover:text-gray-300 transition-colors p-1.5 rounded-lg hover:bg-white/5",children:e.jsx(me,{size:18})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:Object.entries(f).map(([y,c])=>e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3",children:d[y]||y}),e.jsx("div",{className:"space-y-2.5",children:c.map(({preset:j,index:p})=>{var z;const u=m.has(j.name),b=i===p;return e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-xl bg-surface-1 border border-white/5",children:[e.jsx("div",{className:`p-2.5 rounded-xl bg-surface-2/60 border border-white/5 shrink-0 ${ls(j.name,18).color}`,children:ls(j.name,18).node}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200",children:j.name}),e.jsx(Bt,{type:j.transportType})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 line-clamp-1",children:j.description}),j.command&&e.jsxs("p",{className:"text-xs text-gray-600 font-mono mt-1.5",children:[j.command," ",(z=j.args)==null?void 0:z.join(" ")]}),j.referenceUrl&&e.jsxs("a",{href:j.referenceUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-cyan-500/70 hover:text-cyan-400 mt-1 transition-all",onClick:M=>M.stopPropagation(),children:[e.jsx(Ss,{size:10}),"View docs"]})]}),u?e.jsxs("button",{onClick:()=>g(p),disabled:b,className:"px-3.5 py-2 text-sm font-medium rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all disabled:opacity-50 whitespace-nowrap flex items-center gap-1.5",children:[b?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(je,{size:14}),"Add"]}):e.jsxs("span",{className:"px-3.5 py-2 text-sm font-medium text-emerald-400/60 bg-transparent border border-emerald-500/20 rounded-lg whitespace-nowrap flex items-center gap-1.5",children:[e.jsx(ne,{size:14}),"Added"]})]},p)})})]},y))})]})})}function Bn({serverName:s,onConfirm:t,onCancel:a}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-md mx-4 overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-full bg-transparent border border-red-500/25",children:e.jsx(we,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:"Delete MCP Server"})]}),e.jsxs("p",{className:"text-sm text-gray-400 leading-relaxed",children:['Are you sure you want to delete "',e.jsx("span",{className:"text-gray-200",children:s}),'"? This will disconnect the server and remove its configuration.']})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Cancel"}),e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-red-400 border border-red-500/30 hover:bg-red-500/10 hover:border-red-500/50 font-medium transition-all",children:"Delete"})]})]})})}function Kn({readOnly:s=!1}={}){const[t,a]=n.useState([]),[l,m]=n.useState(!0),[i,h]=n.useState(null),[d,f]=n.useState(!1),[g,y]=n.useState(null),[c,j]=n.useState([]),[p,u]=n.useState([]),b=n.useCallback(async()=>{try{const o=await Nr();a(o.servers)}catch(o){console.error("Failed to load MCP servers:",o)}finally{m(!1)}},[]),z=n.useCallback(async()=>{try{const o=await wr();j(o.presets),u(o.available)}catch(o){console.error("Failed to load MCP presets:",o)}},[]);n.useEffect(()=>{b(),z()},[b,z]),n.useEffect(()=>mn(b,5e3),[b]);const M=async o=>{try{const r={};for(const N of o.envVars)N.key.trim()&&(r[N.key.trim()]=N.value);const E=o.transportType==="sse"||o.transportType==="http",P={};if(E)for(const N of o.headers)N.key.trim()&&(P[N.key.trim()]=N.value);const B=o.args.split(",").map(N=>N.trim()).filter(Boolean);(i==null?void 0:i.mode)==="edit"&&i.server?await Ar(i.server.id,{name:o.name.trim(),transportType:o.transportType,command:o.transportType==="stdio"?o.command.trim():void 0,args:o.transportType==="stdio"?B:void 0,url:E?o.url.trim():void 0,envVars:Object.keys(r).length>0?r:void 0,headers:E&&Object.keys(P).length>0?P:void 0,autoConnect:o.autoConnect}):await st({name:o.name.trim(),transportType:o.transportType,command:o.transportType==="stdio"?o.command.trim():void 0,args:o.transportType==="stdio"?B:void 0,url:E?o.url.trim():void 0,envVars:Object.keys(r).length>0?r:void 0,headers:E&&Object.keys(P).length>0?P:void 0,autoConnect:o.autoConnect}),h(null),b(),z()}catch(r){console.error("Failed to save MCP server:",r)}},V=async o=>{for(const r of o)await st(r);h(null),b(),z()},U=async o=>{try{const r=await Tr(o);return b(),r.error?{success:!1,error:r.error}:{success:!0,toolCount:r.toolCount}}catch(r){return console.error("Failed to connect MCP server:",r),b(),{success:!1,error:String(r)}}},O=async o=>{try{return await Sr(o),b(),{success:!0}}catch(r){return console.error("Failed to disconnect MCP server:",r),b(),{success:!1,error:String(r)}}},S=async o=>{try{o.enabled?await kr(o.id):await Cr(o.id),b()}catch(r){console.error("Failed to toggle MCP server:",r)}},I=async o=>{try{await Er(o),y(null),b(),z()}catch(r){console.error("Failed to delete MCP server:",r)}},w=async o=>{try{await zr(o),b(),z()}catch(r){console.error("Failed to add MCP preset:",r)}};if(l)return e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(J,{size:24,className:"animate-spin text-brand-400 mr-3"}),e.jsx("span",{className:"text-gray-400",children:"Loading MCP servers..."})]});const v=t.filter(o=>o.status==="connected").length,x=t.reduce((o,r)=>o+r.toolCount,0);return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[s&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"View only — MCP servers are managed by your admin. You can see what's configured and use their tools in the AI Assistant, but not add, edit, connect, or delete them."})]}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5",children:[e.jsx(Pe,{size:16,className:"text-cyan-400"}),"MCP Servers"]}),e.jsx("p",{className:"mt-1.5 text-sm text-gray-400 max-w-lg",children:"Connect external MCP servers to extend your AI assistant with additional tools for browser automation, database access, and more."})]}),e.jsx("div",{className:"flex items-center gap-4 flex-shrink-0 ml-4",children:e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-300",children:[e.jsx("span",{className:"text-cyan-400",children:v}),"/",t.length," connected"]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5",children:[x," tool",x!==1?"s":""," available"]})]})})]})}),!s&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>f(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-violet-500/5 text-violet-400/80 border border-violet-500/20 hover:border-violet-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(js,{size:14}),"Add from Catalog"]}),e.jsxs("button",{onClick:()=>h({mode:"add"}),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all flex items-center gap-1.5",children:[e.jsx(je,{size:14}),"Add Server"]})]}),t.length===0?e.jsxs("div",{className:"flex flex-col items-center py-16 text-gray-500",children:[e.jsx(Pe,{size:48,className:"mb-4 opacity-50"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-400 mb-2",children:"No MCP Servers Configured"}),e.jsx("p",{className:"text-xs text-gray-600 mb-4 max-w-md text-center",children:"MCP (Model Context Protocol) servers extend your AI assistant with external tools like browser automation, database access, and more."}),!s&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>f(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-violet-500/5 text-violet-400/80 border border-violet-500/20 hover:border-violet-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(js,{size:14}),"Browse Catalog"]}),e.jsxs("button",{onClick:()=>h({mode:"add"}),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all flex items-center gap-1.5",children:[e.jsx(je,{size:14}),"Add Custom Server"]})]})]}):e.jsx("div",{className:"grid gap-3 grid-cols-1 lg:grid-cols-2",children:t.map(o=>e.jsx(Dn,{server:o,readOnly:s,onConnect:()=>U(o.id),onDisconnect:()=>O(o.id),onTest:()=>{},onEdit:()=>h({mode:"edit",server:o}),onDelete:()=>y(o),onToggleEnabled:()=>S(o)},o.id))}),i&&fe.createPortal(e.jsx(On,{initial:i.server,onSave:M,onImportJson:V,onCancel:()=>h(null),presets:c}),document.body),d&&fe.createPortal(e.jsx(Un,{presets:c,available:p,onAdd:w,onClose:()=>f(!1)}),document.body),g&&fe.createPortal(e.jsx(Bn,{serverName:g.name,onConfirm:()=>I(g.id),onCancel:()=>y(null)}),document.body)]})}function Kt(s){return s==="js-config"?"js config":s==="dotenv"?"env":s}const _n=/^(base_?url|baseurl|app_?url|url)$/i,Hn=/(pass(word|wd)?|secret|token|api[_-]?key|apikey|access[_-]?key|client[_-]?secret|private[_-]?key|\bauth\b|credential|\bpwd\b|salt)/i;function Vn({embedded:s=!1}={}){const{toast:t}=ge(),[a,l]=n.useState([]),[m,i]=n.useState(null),[h,d]=n.useState(null),[f,g]=n.useState([]),[y,c]=n.useState(""),[j,p]=n.useState(!0),[u,b]=n.useState(!1),[z,M]=n.useState(null),[V,U]=n.useState(new Set),[O,S]=n.useState(!1);async function I(R){var G;p(!0),M(null);try{const _=await Lr();l(_.files);const A=R||m||((G=_.files[0])==null?void 0:G.file)||null;i(A),A||(d(null),g([]))}catch(_){M(String(_))}finally{p(!1)}}async function w(R){M(null),U(new Set);try{const G=await $r(R);d(G),g(G.vars),c(JSON.stringify(G.vars))}catch(G){M(String(G)),d(null),g([])}}n.useEffect(()=>{I()},[]),n.useEffect(()=>{m&&w(m)},[m]);const v=n.useMemo(()=>JSON.stringify(f)!==y,[f,y]),x=n.useMemo(()=>f.findIndex(R=>_n.test(R.key.split(".").pop()||"")),[f]),o=(h==null?void 0:h.format)==="js-config";function r(R,G){g(_=>_.map((A,te)=>te===R?{...A,...G}:A))}function E(R){g(G=>G.filter((_,A)=>A!==R)),U(G=>{const _=new Set;return G.forEach(A=>{A<R?_.add(A):A>R&&_.add(A-1)}),_})}function P(){g(R=>[...R,{key:"",value:"",secret:!1}])}function B(R){U(G=>{const _=new Set(G);return _.has(R)?_.delete(R):_.add(R),_})}function N(){try{g(JSON.parse(y)),U(new Set)}catch{}}async function ee(){if(!m)return;const R=f.map(_=>_.key.trim());if(R.some(_=>!_)){t("error","Every variable needs a name");return}const G=R.find((_,A)=>R.indexOf(_)!==A);if(G){t("error",`Duplicate variable: ${G}`);return}b(!0);try{const _=await Rr(m,f.map(A=>({...A,key:A.key.trim()})));d(_),g(_.vars),c(JSON.stringify(_.vars)),t("success",`Saved ${_.file}`)}catch(_){t("error",`Save failed: ${_}`)}finally{b(!1)}}async function K(R){try{const G=await Fr(R);S(!1),await I(G.file),t("success",`Loaded ${G.file}`)}catch(G){t("error",`${G}`)}}async function W(R){try{await Dr(R),m===R&&i(null),await I(),t("success",`Removed ${R}`)}catch(G){t("error",`${G}`)}}return e.jsxs("div",{className:"h-full flex flex-col animate-fade-in",children:[s?e.jsxs("div",{className:"px-5 pt-4 flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>I(),title:"Rescan",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:e.jsx($e,{size:15})}),e.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 transition-colors",children:[e.jsx(rs,{size:15})," Load config"]})]}):e.jsxs("div",{className:"px-5 py-3 border-b border-white/5 bg-surface-1 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(As,{size:20,className:"text-brand-400"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-base font-semibold text-gray-100 leading-tight",children:"Environments"}),e.jsx("p",{className:"text-[11px] text-gray-500",children:"Edit your project's env files — changes write straight back to the file."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>I(),title:"Rescan",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:e.jsx($e,{size:15})}),e.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 transition-colors",children:[e.jsx(rs,{size:15})," Load config"]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5",children:j?e.jsx("div",{className:"text-sm text-gray-500",children:"Loading…"}):z?e.jsx("div",{className:"text-sm text-rose-400",children:z}):a.length===0?e.jsx(Wn,{onAdd:()=>S(!0)}):e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[a.map(R=>e.jsxs("button",{onClick:()=>i(R.file),title:R.file,className:`group inline-flex items-center gap-2 h-9 px-3.5 rounded-lg border text-sm transition-colors ${m===R.file?"bg-brand-500/10 border-brand-500/50 text-gray-900 dark:text-gray-50 font-medium ring-1 ring-brand-500/20":"bg-surface-1 border-black/10 dark:border-white/10 text-gray-500 hover:text-gray-800 dark:hover:text-gray-200 hover:bg-black/[0.04] dark:hover:bg-white/[0.06] hover:border-black/20 dark:hover:border-white/20"}`,children:[e.jsx(vs,{size:15,className:`flex-shrink-0 ${m===R.file?"text-brand-500":"text-gray-400 dark:text-gray-500"}`}),e.jsx("span",{className:"truncate max-w-[160px]",children:R.label}),R.manual&&e.jsx("span",{className:"flex-shrink-0 text-[9px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-700 dark:text-brand-300 border border-brand-600/40 dark:border-brand-500/30 leading-none",title:"Loaded by you",children:"loaded"}),m===R.file&&v&&e.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-amber-400",title:"Unsaved changes"})]},R.file)),e.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-1.5 h-9 px-3.5 rounded-lg border border-dashed border-black/15 dark:border-white/15 text-sm text-gray-500 hover:text-gray-800 dark:hover:text-gray-200 hover:border-black/30 dark:hover:border-white/30 transition-colors",children:[e.jsx(rs,{size:14,className:"flex-shrink-0"})," Load config"]})]}),h&&e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-surface-1 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-gray-100",children:h.label}),e.jsx("code",{className:"text-[11px] text-gray-500 font-mono",children:h.file}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-gray-500 border border-white/10 rounded px-1.5 py-0.5",children:Kt(h.format)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v&&!u&&e.jsxs("button",{onClick:N,title:"Discard unsaved changes",className:"inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg border border-white/10 text-gray-400 hover:text-rose-300 hover:border-rose-500/30 hover:bg-rose-500/10 transition-colors",children:[e.jsx(Qa,{size:15})," Discard"]}),e.jsxs("button",{onClick:ee,disabled:!v||u,className:`inline-flex items-center gap-1.5 text-sm px-3.5 py-1.5 rounded-lg border transition-colors ${v&&!u?"bg-brand-500/15 text-brand-300 border-brand-500/30 hover:bg-brand-500/25":"bg-white/5 text-gray-600 border-white/5 cursor-not-allowed"}`,children:[e.jsx(Et,{size:15})," ",u?"Saving…":v?"Save changes":"Saved"]})]})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[x>=0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs text-gray-400 mb-1.5",children:["Base URL ",e.jsxs("span",{className:"text-gray-600 font-mono",children:["· ",f[x].key]})]}),e.jsx("input",{value:f[x].value,onChange:R=>r(x,{value:R.target.value}),spellCheck:!1,className:"w-full px-3.5 py-2.5 rounded-xl text-sm font-mono bg-surface-2 border border-white/10 text-gray-100 outline-none focus:border-brand-500/50 transition-colors"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs text-gray-400",children:["Variables & secrets ",e.jsxs("span",{className:"text-gray-600",children:["· ",f.length]})]}),!o&&e.jsxs("button",{onClick:P,className:"inline-flex items-center gap-1 text-xs text-brand-300 hover:text-brand-200",children:[e.jsx(je,{size:13})," Add variable"]})]}),e.jsxs("div",{className:"rounded-xl border border-white/10 overflow-hidden divide-y divide-white/5",children:[f.length===0&&e.jsx("div",{className:"px-4 py-6 text-center text-sm text-gray-600",children:"No variables yet — add one."}),f.map((R,G)=>{const _=R.secret&&!V.has(G);return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 hover:bg-white/[0.02] group",children:[e.jsx("input",{value:R.key,readOnly:o,onChange:A=>r(G,{key:A.target.value,secret:R.secret||Hn.test(A.target.value)}),placeholder:"KEY",spellCheck:!1,className:`w-[34%] bg-transparent text-sm font-mono text-gray-200 outline-none placeholder-gray-600 focus:text-white ${o?"cursor-default":""}`}),e.jsxs("div",{className:"flex-1 flex items-center gap-1.5",children:[e.jsx("input",{value:R.value,type:_?"password":"text",onChange:A=>r(G,{value:A.target.value}),placeholder:"value",spellCheck:!1,className:"flex-1 bg-transparent text-sm font-mono text-gray-300 outline-none placeholder-gray-600"}),R.secret&&e.jsx("button",{onClick:()=>B(G),title:_?"Reveal":"Hide",className:"p-1 text-gray-500 hover:text-gray-300",children:_?e.jsx(ve,{size:14}):e.jsx(is,{size:14})})]}),e.jsxs("button",{onClick:()=>r(G,{secret:!R.secret}),title:R.secret?"Marked secret — click to make plain":"Marked plain — click to make secret",className:`flex items-center gap-1 text-[11px] w-[58px] justify-end ${R.secret?"text-amber-400/90 hover:text-amber-300":"text-gray-500 hover:text-gray-300"}`,children:[R.secret?e.jsx(Ya,{size:11}):null,R.secret?"secret":"plain"]}),!o&&e.jsx("button",{onClick:()=>E(G),title:"Remove",className:"p-1 text-gray-600 hover:text-rose-400 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(we,{size:14})})]},G)})]}),e.jsx("p",{className:"mt-2 text-[11px] text-gray-600",children:o?e.jsxs(e.Fragment,{children:["This config file is code — the values listed are edited in place; keys can't be added or renamed here. Other code in ",e.jsx("code",{className:"font-mono",children:h.file})," is left untouched."]}):e.jsxs(e.Fragment,{children:["Secrets are masked here only; values are written to ",e.jsx("code",{className:"font-mono",children:h.file})," in plain text, as the file format requires. The ",e.jsx("span",{className:"text-gray-500",children:"secret/plain"})," flag is detected from the key name."]})})]})]})]})]})}),O&&e.jsx(Gn,{loaded:a.filter(R=>R.manual),onClose:()=>S(!1),onLoad:K,onUnload:W})]})}function Gn({loaded:s,onClose:t,onLoad:a,onUnload:l}){const[m,i]=n.useState([]),[h,d]=n.useState(!0),[f,g]=n.useState(""),[y,c]=n.useState("");n.useEffect(()=>{Mr().then(p=>i(p.candidates)).catch(()=>i([])).finally(()=>d(!1))},[]);const j=m.filter(p=>!y||p.file.toLowerCase().includes(y.toLowerCase()));return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[85vh] flex flex-col rounded-2xl border border-white/10 bg-surface-1 shadow-2xl",onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{size:18,className:"text-brand-400"}),e.jsx("h2",{className:"text-[15px] font-semibold text-gray-100",children:"Load a config file"})]}),e.jsx("button",{onClick:t,className:"p-1 text-gray-500 hover:text-gray-300",children:e.jsx(me,{size:18})})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-400 mb-1.5",children:"Paste a path to a config in a custom location"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:f,onChange:p=>g(p.target.value),onKeyDown:p=>{p.key==="Enter"&&f.trim()&&a(f.trim())},placeholder:"e.g. config/qa/settings.properties",spellCheck:!1,className:"flex-1 px-3 py-2 rounded-lg text-sm font-mono bg-surface-2 border border-white/10 text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50"}),e.jsxs("button",{onClick:()=>f.trim()&&a(f.trim()),disabled:!f.trim(),className:"inline-flex items-center gap-1.5 text-sm px-3 py-2 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 disabled:opacity-40",children:[e.jsx(Xa,{size:14})," Load"]})]})]}),s.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-gray-400 mb-1.5",children:["Loaded by you · ",s.length]}),e.jsx("div",{className:"rounded-lg border border-white/10 divide-y divide-white/5",children:s.map(p=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-sm",children:[e.jsx(vs,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"text-gray-300 truncate flex-1",title:p.file,children:p.file}),e.jsx("button",{onClick:()=>l(p.file),title:"Un-load",className:"p-1 text-gray-600 hover:text-rose-400",children:e.jsx(we,{size:14})})]},p.file))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs text-gray-400",children:["Detected, not loaded ",!h&&`· ${j.length}`]}),m.length>8&&e.jsx("input",{value:y,onChange:p=>c(p.target.value),placeholder:"filter…",spellCheck:!1,className:"w-32 px-2 py-1 rounded-md text-xs bg-surface-2 border border-white/10 text-gray-300 outline-none placeholder-gray-600"})]}),h?e.jsx("div",{className:"text-sm text-gray-600 px-1 py-3",children:"Scanning…"}):j.length===0?e.jsx("div",{className:"text-sm text-gray-600 px-3 py-4 rounded-lg border border-dashed border-white/10 text-center",children:"Nothing else found — use the path box above for custom locations."}):e.jsx("div",{className:"rounded-lg border border-white/10 divide-y divide-white/5 max-h-64 overflow-auto",children:j.map(p=>e.jsxs("button",{onClick:()=>a(p.file),className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-left hover:bg-white/[0.03] group",children:[e.jsx(vs,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"text-gray-300 truncate flex-1",title:p.file,children:p.file}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-gray-600",children:Kt(p.format)}),e.jsx(je,{size:14,className:"text-brand-400 opacity-0 group-hover:opacity-100"})]},p.file))})]})]})]})})}function Wn({onAdd:s}){return e.jsxs("div",{className:"max-w-md mx-auto mt-16 text-center",children:[e.jsx("div",{className:"inline-flex p-3 rounded-2xl bg-surface-2 border border-white/10 mb-4",children:e.jsx(As,{size:28,className:"text-gray-500"})}),e.jsx("h2",{className:"text-base font-semibold text-gray-200 mb-1",children:"No environment files found"}),e.jsxs("p",{className:"text-sm text-gray-500 mb-5",children:["Testver looks for ",e.jsx("code",{className:"font-mono text-gray-400",children:".env"}),", ",e.jsx("code",{className:"font-mono text-gray-400",children:".env.*"}),","," ",e.jsx("code",{className:"font-mono text-gray-400",children:"*.properties"}),", ",e.jsx("code",{className:"font-mono text-gray-400",children:"*.env.json"})," and ",e.jsx("code",{className:"font-mono text-gray-400",children:"cypress.config.*"})," files, and can load any ",e.jsx("code",{className:"font-mono text-gray-400",children:"*.config.ts"})," / ",e.jsx("code",{className:"font-mono text-gray-400",children:".js"})," on request."," ","Load one from a custom location if it wasn't picked up."]}),e.jsxs("button",{onClick:s,className:"inline-flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 transition-colors",children:[e.jsx(rs,{size:15})," Load config"]})]})}async function es(s,t){const a=Qs(),l=await fetch(s,{...t,headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{},...t==null?void 0:t.headers}});if(!l.ok)throw new Error((await l.json().catch(()=>({}))).error||l.statusText);return l.json()}function Le(s){const t=Date.now()-s;return t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}const _t=30;function Ht(s){if(s.source==="test-run"||s.source==="orphan-browser"||s.source==="run-browser")return null;const t=s.lastActivityAt??s.startedAt,a=(Date.now()-t)/6e4;return a<_t?null:`Idle ${Math.round(a)}m`}function Vt({source:s}){return s==="server-pool"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-brand-300 bg-brand-500/10 border border-brand-500/30",children:[e.jsx(Ve,{size:10})," Server"]}):s==="local-connector"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-emerald-300 bg-emerald-500/10 border border-emerald-500/30",children:[e.jsx(ds,{size:10})," Local"]}):s==="run-browser"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-sky-300 bg-sky-500/10 border border-sky-500/30",children:[e.jsx(qe,{size:10})," Run browser"]}):s==="orphan-browser"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-rose-300 bg-rose-500/10 border border-rose-500/30",children:[e.jsx(Hs,{size:10})," Orphaned"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-amber-300 bg-amber-500/10 border border-amber-500/30",children:[e.jsx(Za,{size:10})," Test run"]})}function qn({open:s,title:t,body:a,confirmLabel:l,variant:m="normal",busy:i,onConfirm:h,onCancel:d}){return n.useEffect(()=>{if(!s)return;const f=g=>{g.key==="Escape"&&!i&&d()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s,i,d]),s?fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:d,children:e.jsxs("div",{className:"w-[480px] bg-surface-1 border border-white/10 rounded-2xl shadow-2xl",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-white/5",children:[e.jsx(ue,{size:18,className:m==="danger"?"text-red-400":"text-amber-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100 flex-1",children:t}),e.jsx("button",{onClick:d,disabled:i,className:"text-gray-500 hover:text-gray-200 transition-colors disabled:opacity-50",children:e.jsx(me,{size:18})})]}),e.jsx("div",{className:"px-5 py-4 text-sm text-gray-300 leading-relaxed",children:a}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3.5 border-t border-white/5",children:[e.jsx("button",{onClick:d,disabled:i,className:"px-3 py-1.5 text-sm font-medium text-gray-400 hover:text-gray-200 transition-colors disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:h,disabled:i,className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 inline-flex items-center gap-2 ${m==="danger"?"text-white bg-red-600 hover:bg-red-700":"text-white bg-amber-600 hover:bg-amber-700"}`,children:[i&&e.jsx(J,{size:13,className:"animate-spin"}),l]})]})]})}),document.body):null}function Jn({session:s,showUser:t,onCloseClicked:a,closing:l}){const m=Ht(s);return e.jsx("div",{className:`p-3.5 rounded-lg border transition-colors ${m?"bg-surface-2/30 border-white/5":"bg-surface-2/50 border-white/10"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 shrink-0",children:s.browserType?e.jsx(xn,{browser:s.browserType,size:22}):e.jsx(Ve,{size:22,className:"text-gray-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(Vt,{source:s.source}),s.browserType&&e.jsx("span",{className:"text-sm font-medium text-gray-100 capitalize",children:s.browserType}),t&&s.username&&e.jsxs("span",{className:"text-xs text-gray-400",children:["· ",s.username]}),m&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-gray-500",children:[e.jsx(zs,{size:10})," ",m]})]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1.5 leading-relaxed",children:[s.source==="server-pool"&&e.jsxs(e.Fragment,{children:["Started ",Le(s.startedAt),s.pid&&e.jsxs(e.Fragment,{children:[" · pid ",s.pid]}),s.clientIds.length>0&&e.jsxs(e.Fragment,{children:[" · ",s.clientIds.length," tab",s.clientIds.length===1?"":"s"]})]}),s.source==="local-connector"&&e.jsxs(e.Fragment,{children:["Connected ",Le(s.startedAt),s.machine&&e.jsxs(e.Fragment,{children:[" from ",e.jsx("span",{className:"text-gray-300",children:s.machine})]}),s.os&&e.jsxs(e.Fragment,{children:[" · ",s.os]}),s.clientIds.length>0&&e.jsxs(e.Fragment,{children:[" · ",s.clientIds.length," tab",s.clientIds.length===1?"":"s"]})]}),s.source==="test-run"&&e.jsxs(e.Fragment,{children:["Started ",Le(s.startedAt),s.framework&&e.jsxs(e.Fragment,{children:[" · ",s.framework]}),s.pid&&e.jsxs(e.Fragment,{children:[" · runner pid ",s.pid]})]}),s.source==="run-browser"&&e.jsxs(e.Fragment,{children:["Open since ",Le(s.startedAt),s.browserType&&e.jsxs(e.Fragment,{children:[" · ",s.browserType]}),s.pid&&e.jsxs(e.Fragment,{children:[" · pid ",s.pid]}),s.framework&&e.jsxs(e.Fragment,{children:[" · ",s.framework," run"]})]}),s.source==="orphan-browser"&&e.jsxs(e.Fragment,{children:["Left open ",Le(s.startedAt),s.browserType&&e.jsxs(e.Fragment,{children:[" · ",s.browserType]}),s.pid&&e.jsxs(e.Fragment,{children:[" · pid ",s.pid]}),s.framework&&e.jsxs(e.Fragment,{children:[" · from ",s.framework," run"]})]})]}),s.source==="test-run"&&s.command&&e.jsxs("code",{className:"block text-[11px] font-mono text-gray-500 mt-1.5 truncate",title:s.command,children:["$ ",s.command]})]}),e.jsxs("button",{onClick:()=>a(s),disabled:l,className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-50",children:[l?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(me,{size:12}),"Close"]})]})})}function Qn(){const[s,t]=n.useState(null),[a,l]=n.useState(!1),[m,i]=n.useState(null),[h,d]=n.useState(null),[f,g]=n.useState(null),[y,c]=n.useState(null),[j,p]=n.useState(!1),[u,b]=n.useState(null),z=n.useCallback(async()=>{try{const r=await es(`/api/browser-sessions${a?"?scope=all":""}`);t(r)}catch(r){d(r.message)}},[a]);n.useEffect(()=>{z();const r=setInterval(z,5e3);return()=>clearInterval(r)},[z]),n.useEffect(()=>{es("/api/system/orphan-reap").then(b).catch(()=>{})},[]);const M=async()=>{if(!u)return;const r={...u,enabled:!u.enabled};b(r);try{const E=await es("/api/system/orphan-reap",{method:"PUT",body:JSON.stringify({enabled:r.enabled})});b(E)}catch(E){b(u),d(E.message)}},V=async()=>{if(f){p(!0),i(f.id),d(null);try{await es(`/api/browser-sessions/${encodeURIComponent(f.id)}`,{method:"DELETE"}),g(null),await z()}catch(r){d(r.message)}finally{p(!1),i(null)}}},U=async()=>{if(y){p(!0),d(null);try{await es("/api/browser-sessions/bulk-close",{method:"POST",body:JSON.stringify({scope:y,mode:"graceful",idleMinutes:_t})}),c(null),await z()}catch(r){d(r.message)}finally{p(!1)}}},O=(s==null?void 0:s.sessions)||[],S=!!(s!=null&&s.isAdmin),I=O.filter(r=>r.userId!=="project").length,w=O.filter(r=>r.source==="server-pool").length,v=O.filter(r=>Ht(r)).length,x=O.filter(r=>r.source==="orphan-browser").length;let o=null;if(f){const r=f,E=r.source==="server-pool"?"close this server-side browser process":r.source==="local-connector"?"disconnect this local-browser connector":r.source==="orphan-browser"?"kill this leftover browser process":r.source==="run-browser"?"close this browser — its test run will fail":"cancel this test run";o={open:!0,title:"Close browser session?",body:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:["You're about to ",E,"."]}),e.jsxs("div",{className:"bg-surface-2/60 border border-white/5 rounded-lg p-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(Vt,{source:r.source}),r.browserType&&e.jsx("span",{className:"text-gray-200 capitalize",children:r.browserType})]}),e.jsxs("div",{className:"text-gray-400",children:[r.source==="server-pool"&&e.jsxs(e.Fragment,{children:[r.pid?`pid ${r.pid}`:"server pool entry"," · started ",Le(r.startedAt)]}),r.source==="local-connector"&&e.jsxs(e.Fragment,{children:[r.machine?`from ${r.machine}`:"local connector"," · started ",Le(r.startedAt)]}),r.source==="test-run"&&e.jsxs(e.Fragment,{children:[r.framework||"test run"," · started ",Le(r.startedAt)]}),r.source==="run-browser"&&e.jsxs(e.Fragment,{children:[r.browserType||"browser",r.pid?` · pid ${r.pid}`:""," · ",r.framework||"test"," run"]}),r.source==="orphan-browser"&&e.jsxs(e.Fragment,{children:[r.browserType||"browser",r.pid?` · pid ${r.pid}`:""," · left open ",Le(r.startedAt)]})]}),r.source==="test-run"&&r.command&&e.jsxs("code",{className:"block text-[11px] text-gray-500 mt-1.5 truncate",title:r.command,children:["$ ",r.command]}),r.clientIds.length>0&&e.jsxs("p",{className:"text-[11px] text-amber-300 mt-2",children:[r.clientIds.length," active tab",r.clientIds.length===1?"":"s"," ",r.clientIds.length===1?"is":"are"," using this session — its live preview will tear down immediately."]})]})]}),confirmLabel:"Close session",variant:"danger",busy:j,onConfirm:V,onCancel:()=>!j&&g(null)}}else if(y){const r={mine:"Close all of your sessions?","server-pool":"Close all server-side browsers?",idle:"Close all idle sessions?",all:"Close every session for every user?",orphaned:"Close orphaned browsers?"},E={mine:e.jsxs("p",{children:["This closes every browser session you currently own. Any in-flight tool calls get up to ",e.jsx("strong",{children:"5 seconds"})," to complete (graceful shutdown) before being terminated."]}),"server-pool":e.jsxs("p",{children:["This closes every server-side per-tab browser process — useful for freeing server RAM. ",e.jsx("strong",{children:"Local-connector"})," sessions and ",e.jsx("strong",{children:"active test runs"})," are left alone. ",w," session",w===1?"":"s"," will be closed."]}),idle:e.jsxs("p",{children:["Closes every session that has been idle for more than ",e.jsx("strong",{children:"30 minutes"}),". Active sessions are unaffected. ",v," idle session",v===1?"":"s"," match."]}),all:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:["This closes ",e.jsx("strong",{children:"every"})," active browser session across ",e.jsx("strong",{children:"all users"}),", including their local connectors and any running tests."]}),e.jsx("p",{className:"text-red-400 text-xs",children:"Every user mid-action will see their browser terminate. Use only for maintenance windows."})]}),orphaned:e.jsxs("p",{children:["Kills every ",e.jsx("strong",{children:"orphaned browser"})," — leftover browser processes from runs that already finished. Active sessions and running tests are unaffected. ",x," orphaned browser",x===1?"":"s"," will be closed."]})};o={open:!0,title:r[y],body:E[y],confirmLabel:"Close sessions",variant:y==="all"?"danger":"normal",busy:j,onConfirm:U,onCancel:()=>!j&&c(null)}}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Ve,{size:18,className:"text-brand-400"}),"Browser Sessions"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[S&&e.jsx("button",{onClick:()=>l(!a),className:`px-3 py-1.5 text-xs font-medium rounded-lg border transition-colors ${a?"bg-brand-500/15 text-brand-300 border-brand-500/30":"bg-surface-2/40 text-gray-400 border-white/5 hover:text-gray-200"}`,children:a?"Showing all users":"Show all users"}),e.jsxs("button",{onClick:z,className:"px-3 py-1.5 text-xs font-medium text-gray-400 hover:text-gray-200 transition-colors inline-flex items-center gap-1.5",children:[e.jsx($e,{size:12})," Refresh"]})]})]}),e.jsx("p",{className:"text-sm text-gray-500",children:"Manage active browser sessions on this server. Closing a session terminates its underlying browser process and tears down any live previews using it."}),e.jsxs("div",{className:"flex items-center gap-5 text-sm text-gray-400 pt-2 border-t border-white/5",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:O.length})," total"]}),(s==null?void 0:s.summary)&&s.summary.users>1&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:s.summary.users})," users"]}),w>0&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:w})," server-side"]}),v>0&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:v})," idle"]}),x>0&&e.jsxs("span",{className:"text-rose-300",children:[e.jsx("strong",{children:x})," orphaned"]})]})]}),O.length>0&&e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-3",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(we,{size:18,className:"text-brand-400"}),"Bulk close",e.jsx("span",{className:"text-xs font-normal text-gray-500 ml-1",children:"(graceful — waits up to 5s for in-flight actions)"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>c("mine"),disabled:j||I===0,className:"px-3 py-1.5 text-sm font-medium text-gray-200 bg-surface-2/60 hover:bg-surface-2/90 rounded-lg border border-white/5 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(we,{size:13})," My sessions"]}),e.jsxs("button",{onClick:()=>c("orphaned"),disabled:j||x===0,className:"px-3 py-1.5 text-sm font-medium text-rose-300 bg-rose-500/10 hover:bg-rose-500/20 rounded-lg border border-rose-500/30 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(Hs,{size:13})," Close orphaned",x>0?` (${x})`:""]}),S&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>c("server-pool"),disabled:j||w===0,className:"px-3 py-1.5 text-sm font-medium text-gray-200 bg-surface-2/60 hover:bg-surface-2/90 rounded-lg border border-white/5 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(Ve,{size:13})," All server sessions"]}),e.jsxs("button",{onClick:()=>c("idle"),disabled:j||v===0,className:"px-3 py-1.5 text-sm font-medium text-gray-200 bg-surface-2/60 hover:bg-surface-2/90 rounded-lg border border-white/5 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(zs,{size:13})," Idle > 30m"]}),e.jsxs("button",{onClick:()=>c("all"),disabled:j,className:"px-3 py-1.5 text-sm font-medium text-red-300 bg-red-500/10 hover:bg-red-500/20 rounded-lg border border-red-500/30 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(ue,{size:13})," All sessions"]})]})]}),S&&u&&e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3 mt-1 border-t border-white/5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-200 flex items-center gap-2",children:[e.jsx(Hs,{size:14,className:"text-rose-400"})," Auto-close orphaned browsers"]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:["When a run finishes, kill any browsers it left open after ",u.graceSeconds,"s. Off by default — leftovers are surfaced above for manual close."]})]}),e.jsx("button",{role:"switch","aria-checked":u.enabled,onClick:M,className:`relative shrink-0 w-10 h-6 rounded-full transition-colors ${u.enabled?"bg-brand-500":"bg-surface-3 border border-white/10"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white transition-transform ${u.enabled?"translate-x-4":""}`})})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(qe,{size:18,className:"text-brand-400"}),"Active sessions"]}),O.length===0?e.jsxs("div",{className:"flex flex-col items-center text-center py-10",children:[e.jsx(Ve,{size:32,className:"text-gray-700 mb-3"}),e.jsx("p",{className:"text-sm text-gray-300 font-medium",children:"No active browser sessions"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 max-w-sm",children:"Sessions appear here when you launch a browser via /ai, register a Local Browser connector, or start a test run."})]}):e.jsx("div",{className:"space-y-2",children:O.map(r=>e.jsx(Jn,{session:r,showUser:a&&S,onCloseClicked:E=>g(E),closing:m===r.id},r.id))})]}),h&&e.jsx("div",{className:"text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:h}),o&&e.jsx(qn,{...o})]})}async function $s(s,t){const a=Qs(),l=await fetch(s,{...t,headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{},...t==null?void 0:t.headers}});if(!l.ok)throw new Error((await l.json().catch(()=>({}))).error||l.statusText);return l.json()}function pt(s){const t=Date.now()-s;if(t<0){const a=Math.abs(t);return a<6e4?`in ${Math.round(a/1e3)}s`:a<36e5?`in ${Math.round(a/6e4)}m`:a<864e5?`in ${Math.round(a/36e5)}h`:`in ${Math.round(a/864e5)}d`}return t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Yn({open:s,onClose:t,onTokenChange:a}){const[l,m]=n.useState([]),[i,h]=n.useState(!1),[d,f]=n.useState(null),[g,y]=n.useState(null),[c,j]=n.useState(null),[p,u]=n.useState(null),[b,z]=n.useState(!1),M=n.useCallback(async()=>{if(s)try{const I=(await $s("/api/local-browser/tokens")).tokens||[];m(I),u(w=>{if(!w)return w;const v=I.find(x=>w.token.startsWith(x.tokenPrefix));return!v||v.status==="active"||v.status==="used"?null:w})}catch(S){j(S.message)}},[s]);n.useEffect(()=>{if(!s)return;M();const S=setInterval(M,5e3);return()=>clearInterval(S)},[s,M]),n.useEffect(()=>{if(!s)return;const S=I=>{I.key==="Escape"&&t()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[s,t]);const V=async()=>{h(!0),j(null);try{const S=await $s("/api/local-browser/token",{method:"POST"});u(S),a==null||a(),M()}catch(S){j(S.message)}finally{h(!1)}},U=async S=>{y(S),j(null);try{await $s(`/api/local-browser/tokens/${encodeURIComponent(S)}`,{method:"DELETE"}),f(null),p&&p.token.startsWith(S)&&(u(null),z(!1)),a==null||a(),M()}catch(I){j(I.message)}finally{y(null)}},O=()=>{p&&(navigator.clipboard.writeText(p.command).catch(()=>{}),z(!0),setTimeout(()=>z(!1),2e3))};return s?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:t,children:e.jsxs("div",{className:"w-[640px] max-h-[80vh] flex flex-col bg-surface-1 border border-white/10 rounded-2xl shadow-2xl",onClick:S=>S.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-white/5",children:[e.jsx(Vs,{size:18,className:"text-brand-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100 flex-1",children:"Local Browser Tokens"}),e.jsx("button",{onClick:t,className:"text-gray-500 hover:text-gray-200 transition-colors",children:e.jsx(me,{size:18})})]}),p&&e.jsxs("div",{className:"mx-5 mt-4 p-3 bg-brand-500/10 border border-brand-500/20 rounded-lg",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-brand-300 mb-1.5",children:"New token — copy it now (won't be shown again)"}),e.jsxs("div",{className:"relative bg-surface-2 border border-white/5 rounded p-2 pr-9",children:[e.jsx("code",{className:"text-[11px] font-mono text-gray-200 break-all leading-relaxed",children:p.command}),e.jsx("button",{onClick:O,className:"absolute top-1.5 right-1.5 p-1.5 rounded hover:bg-white/5 transition-colors",title:"Copy",children:b?e.jsx(Ue,{size:14,className:"text-emerald-400"}):e.jsx(xs,{size:14,className:"text-gray-400"})})]}),e.jsx("button",{onClick:()=>u(null),className:"text-[10px] text-gray-500 hover:text-gray-300 mt-2",children:"Dismiss"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[l.length===0&&!p?e.jsxs("div",{className:"flex flex-col items-center text-center py-8",children:[e.jsx(Vs,{size:32,className:"text-gray-600 mb-3"}),e.jsx("p",{className:"text-sm text-gray-300 font-medium",children:"No tokens yet"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 max-w-xs",children:"Tokens let you connect a browser running on your machine to this server. Each token can be used once to register a connector."})]}):e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-xs text-gray-400 mb-2",children:"Manage connection tokens for your account. Revoking a token immediately disconnects any connector using it."}),l.map(S=>{const I=d===S.tokenPrefix;return e.jsxs("div",{className:`p-3 rounded-lg border transition-colors ${S.status==="active"?"bg-emerald-500/5 border-emerald-500/20":S.status==="expired"?"bg-red-500/5 border-red-500/15 opacity-70":"bg-surface-2/40 border-white/5"}`,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Xn,{status:S.status}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-2 mb-0.5",children:e.jsx("span",{className:"text-[10px] uppercase tracking-wider font-medium text-gray-400",children:S.status})}),e.jsxs("code",{className:"text-[11px] font-mono text-gray-300 block",children:[S.tokenPrefix,"…"]}),e.jsxs("p",{className:"text-[11px] text-gray-500 mt-1 leading-relaxed",children:[S.status==="active"&&S.machine&&e.jsxs(e.Fragment,{children:["Connected from ",S.machine]}),S.status==="active"&&!S.machine&&e.jsx(e.Fragment,{children:"Connector active"}),S.status==="pending"&&e.jsx(e.Fragment,{children:"Not yet used"}),S.status==="used"&&e.jsx(e.Fragment,{children:"Used (connector disconnected)"}),S.status==="expired"&&e.jsx(e.Fragment,{children:"Expired"}),e.jsx("span",{className:"mx-1.5 text-gray-700",children:"·"}),"Issued ",pt(S.createdAt),S.status!=="expired"&&S.status!=="used"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1.5 text-gray-700",children:"·"}),"Expires ",pt(S.expiresAt)]})]})]}),I?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>f(null),className:"text-[11px] text-gray-400 hover:text-gray-200 px-2 py-1 rounded transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:()=>U(S.tokenPrefix),disabled:g===S.tokenPrefix,className:"text-[11px] font-medium text-white bg-red-600 hover:bg-red-700 px-2.5 py-1 rounded transition-colors disabled:opacity-50 flex items-center gap-1",children:[g===S.tokenPrefix&&e.jsx(J,{size:11,className:"animate-spin"}),"Confirm revoke"]})]}):e.jsx("button",{onClick:()=>f(S.tokenPrefix),disabled:g===S.tokenPrefix,className:"text-[11px] font-medium text-red-400 hover:text-red-300 hover:bg-red-500/10 px-2 py-1 rounded transition-colors disabled:opacity-50",children:"Revoke"})]}),I&&e.jsx("p",{className:"text-[10px] text-red-400/80 mt-2 ml-7",children:"Any active connector using this token will disconnect immediately."})]},S.tokenPrefix)})]}),c&&e.jsx("div",{className:"mt-3 text-[11px] text-red-400 bg-red-500/10 border border-red-500/20 rounded p-2",children:c})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-5 py-3.5 border-t border-white/5",children:[e.jsxs("p",{className:"text-[11px] text-gray-500",children:[l.length," token",l.length===1?"":"s"," · max 5 per account"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:V,disabled:i||l.length>=5,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-brand-300 bg-brand-500/15 hover:bg-brand-500/25 rounded-lg transition-colors border border-brand-500/30 disabled:opacity-50",title:l.length>=5?"Revoke an existing token to free up a slot":"",children:[i?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(qe,{size:12}),"Generate New Token"]}),e.jsx("button",{onClick:t,className:"px-3 py-1.5 text-xs font-medium text-gray-400 hover:text-gray-200 transition-colors",children:"Close"})]})]})]})}):null}function Xn({status:s}){return s==="active"?e.jsx(ne,{size:14,className:"text-emerald-400 mt-0.5 shrink-0"}):s==="pending"?e.jsx(zs,{size:14,className:"text-amber-400 mt-0.5 shrink-0"}):s==="used"?e.jsx(ne,{size:14,className:"text-gray-500 mt-0.5 shrink-0"}):e.jsx(ue,{size:14,className:"text-red-400 mt-0.5 shrink-0"})}async function hs(s,t){const a=Qs(),l=await fetch(s,{...t,headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{},...t==null?void 0:t.headers}});if(!l.ok)throw new Error((await l.json().catch(()=>({}))).error||l.statusText);return l.json()}function Zn(){var U,O;const[s,t]=n.useState(null),[a,l]=n.useState(!1),[m,i]=n.useState(null),[h,d]=n.useState(!1),[f,g]=n.useState(null),[y,c]=n.useState(!1),[j,p]=n.useState(0),u=n.useCallback(async()=>{try{const S=await hs("/api/local-browser/status");t(S)}catch(S){g(S.message)}try{const S=await hs("/api/local-browser/tokens");p((S.tokens||[]).length)}catch{}},[]);n.useEffect(()=>{u();const S=setInterval(u,5e3);return()=>clearInterval(S)},[u]);const b=async()=>{l(!0),g(null);try{const S=await hs("/api/local-browser/token",{method:"POST"});i(S)}catch(S){g(S.message)}finally{l(!1)}},z=async()=>{l(!0),g(null);try{await hs("/api/local-browser/disconnect",{method:"POST"}),await u(),i(null)}catch(S){g(S.message)}finally{l(!1)}},M=()=>{m&&(navigator.clipboard.writeText(m.command).catch(()=>{}),d(!0),setTimeout(()=>d(!1),2e3))},V=(s==null?void 0:s.connected)===!0;return e.jsxs("div",{className:`bg-white dark:bg-surface-1 rounded-xl border p-5 transition-all flex flex-col ${V?"border-emerald-200 dark:border-emerald-500/20":"border-gray-200 dark:border-white/5 hover:border-brand-300 dark:hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(ds,{size:28,className:"text-brand-500"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Local Browser"})}),V&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-200 dark:border-emerald-500/20 shrink-0",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]}),e.jsxs("button",{onClick:()=>c(!0),className:"relative p-1.5 rounded-md text-gray-500 hover:text-brand-400 hover:bg-brand-500/10 transition-colors shrink-0",title:j>0?`Manage tokens (${j})`:"Manage tokens","aria-label":"Manage local browser tokens",children:[e.jsx(Vs,{className:"w-4 h-4"}),j>0&&e.jsx("span",{className:`absolute -top-0.5 -right-0.5 min-w-[16px] h-[16px] px-1 rounded-full text-[9px] font-semibold leading-none flex items-center justify-center border ${V?"bg-emerald-500/20 text-emerald-300 border-emerald-500/40":"bg-brand-500/20 text-brand-300 border-brand-500/40"}`,children:j})]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4 line-clamp-3",children:"Run AI Assistance browser actions on YOUR machine instead of the server. Useful for localhost apps, SSO-protected sites, and reducing server load."}),V?e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5 space-y-2",children:[e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 space-y-1",children:[((U=s==null?void 0:s.client)==null?void 0:U.machine)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Machine:"})," ",s.client.machine]}),((O=s==null?void 0:s.client)==null?void 0:O.os)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"OS:"})," ",s.client.os]}),(s==null?void 0:s.registeredAt)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Connected:"})," ",new Date(s.registeredAt).toLocaleTimeString()]})]}),e.jsxs("button",{onClick:z,disabled:a,className:"w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-500/10 hover:bg-red-100 dark:hover:bg-red-500/20 rounded-lg transition-colors border border-red-200 dark:border-red-500/20 disabled:opacity-50",children:[a?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(qe,{className:"w-3.5 h-3.5"}),"Disconnect"]})]}):m?e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-gray-500 mb-1.5",children:"Run this on your machine:"}),e.jsxs("div",{className:"relative bg-surface-2 dark:bg-surface-2 border border-white/5 rounded-lg p-2 pr-10",children:[e.jsx("code",{className:"text-[11px] font-mono text-gray-200 break-all leading-relaxed",children:m.command}),e.jsx("button",{onClick:M,className:"absolute top-1.5 right-1.5 p-1.5 rounded hover:bg-white/5 transition-colors",title:"Copy command",children:h?e.jsx(Ue,{size:14,className:"text-emerald-400"}):e.jsx(xs,{size:14,className:"text-gray-400"})})]}),e.jsx("p",{className:"text-[10px] text-gray-500 mt-1.5",children:"Token expires in 24 hours. Single-use — once your connector registers, the token is consumed."})]}),e.jsxs("button",{onClick:()=>{i(null),u()},className:"w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-gray-600 dark:text-gray-400 hover:text-gray-200 hover:bg-white/5 rounded-lg transition-colors",children:[e.jsx($e,{className:"w-3.5 h-3.5"})," Refresh status"]})]}):e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("button",{onClick:b,disabled:a,className:"w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-500/10 hover:bg-brand-100 dark:hover:bg-brand-500/20 rounded-lg transition-colors border border-brand-200 dark:border-brand-500/20 disabled:opacity-50",children:[a?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(qe,{className:"w-3.5 h-3.5"}),"Generate Connection Token"]})}),f&&e.jsx("div",{className:"mt-2 text-[11px] text-red-500 bg-red-50 dark:bg-red-500/10 border border-red-200 dark:border-red-500/20 rounded p-2",children:f}),e.jsx(Yn,{open:y,onClose:()=>c(!1),onTokenChange:u})]})}function Gs({size:s=16,className:t}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"currentColor",className:t,"aria-hidden":"true",children:e.jsx("path",{d:"M17.523 15.3414c-.5511 0-.9993-.4486-.9993-.9997s.4482-.9993.9993-.9993c.5511 0 .9993.4482.9993.9993 0 .5511-.4482.9997-.9993.9997m-11.046 0c-.5511 0-.9993-.4486-.9993-.9997s.4482-.9993.9993-.9993c.5511 0 .9993.4482.9993.9993 0 .5511-.4482.9997-.9993.9997m11.4045-6.02l1.9973-3.4592a.416.416 0 00-.1521-.5676.416.416 0 00-.5676.1521l-2.0223 3.503C15.5902 8.2439 13.8533 7.8508 12 7.8508s-3.5902.3931-5.1367 1.0989L4.841 5.4467a.4161.4161 0 00-.5677-.1521.4157.4157 0 00-.1521.5676l1.9973 3.4592C2.6889 11.1867.3432 14.6589 0 18.761h24c-.3435-4.1021-2.6892-7.5743-6.1185-9.4396"})})}function ss({size:s=16,className:t}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"currentColor",className:t,"aria-hidden":"true",children:e.jsx("path",{d:"M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.677-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"})})}const el=4e3,sl=15e3;function tl(){var ie,be,oe,k;const{toast:s}=ge(),[t,a]=n.useState(null),[l,m]=n.useState(null),[i,h]=n.useState({}),[d,f]=n.useState(!0),[g,y]=n.useState(!1),[c,j]=n.useState(!1),[p,u]=n.useState(!1),[b,z]=n.useState(!1),[M,V]=n.useState(!1),U=n.useRef(!1),O=async(C=!1)=>{if(!(U.current&&!C)){U.current=!0,C&&y(!0);try{const q=await Ir();a(q.status),m(q.config),h(q.hints||{})}catch(q){s("error",`Detection failed: ${q}`)}finally{U.current=!1,f(!1),C&&y(!1)}}};n.useEffect(()=>{O()},[]),n.useEffect(()=>{const C=setInterval(()=>{document.visibilityState!=="hidden"&&O(!1)},p?el:sl);return()=>clearInterval(C)},[p]);const[S,I]=n.useState(null),w=async C=>{I(C.name),s("info",`Starting ${C.name.replace(/_/g," ")} — this can take a minute or two.`);try{const q=await Ur(C.name);s("success",`${C.name.replace(/_/g," ")} is running (${q.serial}).`)}catch(q){s("error",q.message)}finally{I(null),O(!0)}},v=async C=>{if(C.serial){I(C.name);try{await Or(C.serial),s("success",`${C.name.replace(/_/g," ")} closed.`)}catch(q){s("error",q.message)}finally{I(null),O(!0)}}},[x,o]=n.useState(null),r=C=>(C.name||C.serial).replace(/\s*\(Simulator[^)]*\)$/,""),E=async C=>{o(C.serial),s("info",`Starting ${r(C)} — this can take a minute the first time.`);try{await Kr(C.serial),s("success",`${r(C)} is running.`)}catch(q){s("error",q.message)}finally{o(null),O(!0)}},P=async C=>{o(C.serial);try{await Br(C.serial),s("success",`${r(C)} closed.`)}catch(q){s("error",q.message)}finally{o(null),O(!0)}},B=async(C,q)=>{try{const T=await ms(C);m(T.config),q&&s("success",q)}catch(T){s("error",`Save failed: ${T}`)}},N=async C=>{try{const q=await ms({enabled:C});m(q.config),s("success",C?"Local Devices enabled":"Local Devices disabled")}catch(q){s("error",`Save failed: ${q}`)}},ee=async C=>{try{const q=await ms({appLaunchMode:C});m(q.config),s("success",C==="fresh"?"App will start fresh each run":"App will keep its data each run")}catch(q){s("error",`Save failed: ${q}`)}},K=async(C,q)=>{try{const T=await ms({[C]:q});m(T.config),O(!0)}catch(T){s("error",`Save failed: ${T}`)}},W=async C=>{try{await navigator.clipboard.writeText(C),s("info","Copied to clipboard")}catch{s("error","Clipboard unavailable")}};if(d)return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-8 flex items-center justify-center gap-3 text-gray-400 text-sm",children:[e.jsx(J,{size:16,className:"animate-spin"}),"Detecting local mobile tools…"]});const R=(t==null?void 0:t.hostPlatform)==="darwin",G=(t==null?void 0:t.hostPlatform)==="linux",_=(ie=t==null?void 0:t.appium.drivers)==null?void 0:ie.map(C=>C.toLowerCase()),A=!!_,te=!_||_.includes("uiautomator2"),X=!_||_.includes("xcuitest"),le=(t==null?void 0:t.appium.local)===!1,$=!!(t!=null&&t.android.adbFound)&&!!(t!=null&&t.android.sdkValid),re=$&&te,ae=R&&!!(t!=null&&t.ios.xcodeFound)&&X,ce=!!t&&t.appium.reachable&&!le&&(re||ae),he=i.appium||"npm install -g appium && appium driver install uiautomator2 && appium driver install xcuitest",xe=i.adb||{},ye=i.iosTools||{},Ne=i.xcode||{},ke=R?xe.macos:(t==null?void 0:t.hostPlatform)==="linux"?xe.linux:xe.windows,F=(t==null?void 0:t.android.devices.filter(C=>C.state==="connected").length)??0,Q=(t==null?void 0:t.ios.devices.filter(C=>C.state==="connected"&&(C.kind!=="simulator"||!!C.booted)).length)??0,se=F+Q;return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:[e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("button",{onClick:()=>u(!p),className:"flex items-start gap-4 flex-1 min-w-0 text-left group","aria-expanded":p,children:[e.jsx("div",{className:`w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 ${ce?"bg-emerald-500/15 text-emerald-400":"bg-amber-500/15 text-amber-400"}`,children:e.jsx(Oe,{size:22})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[p?e.jsx(Me,{size:14,className:"text-gray-500"}):e.jsx(Ie,{size:14,className:"text-gray-500"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-200 group-hover:text-brand-500 dark:group-hover:text-brand-300 transition-colors",children:"Local Devices (Appium)"}),e.jsx(rl,{ok:ce,okLabel:"Ready",warnLabel:"Setup needed"}),se>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-emerald-300 bg-emerald-500/15 border border-emerald-500/30 px-2 py-0.5 rounded",children:[e.jsx(Oe,{size:11}),se," device",se===1?"":"s"," connected"]})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5",children:"Run tests on the phones, Android emulators and iOS simulators on this computer, using your own Appium server. No cloud minutes — fastest feedback loop for active development."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>O(!0),disabled:g,className:"p-2 rounded-lg bg-white/5 text-gray-400 border border-white/10 hover:bg-white/10 disabled:opacity-40",title:"Refresh",children:g?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx($e,{size:14})}),e.jsx(gt,{enabled:(l==null?void 0:l.enabled)??!1,onChange:N,label:"Enable"})]})]})}),p&&e.jsxs("div",{className:"border-t border-white/5 bg-surface-0/30 p-5 space-y-4",children:[e.jsx(Ms,{icon:e.jsx(qe,{size:18}),title:"Appium server",ok:!!(t!=null&&t.appium.reachable),okHint:t?`${t.appium.version??"reachable"} at ${t.appium.url}${t.appium.driverVersions&&Object.keys(t.appium.driverVersions).length?` — drivers: ${Object.entries(t.appium.driverVersions).map(([C,q])=>q?`${C} ${q}`:C).join(", ")}`:t.appium.drivers&&t.appium.drivers.length===0?" — no drivers installed":""}`:"",failHint:(t==null?void 0:t.appium.error)||`Not reachable at ${(t==null?void 0:t.appium.url)??"http://127.0.0.1:4723"}`,action:t!=null&&t.appium.reachable?le||!A?e.jsxs("div",{className:"space-y-1.5",children:[le&&e.jsxs("div",{className:"text-[11px] leading-relaxed text-amber-600 dark:text-amber-400",children:["This Appium server is on another computer. Local Devices finds phones, emulators and app files on ",e.jsx("strong",{children:"this"})," computer, so Appium must run here too — start Appium on this machine and set the Appium URL (Advanced, below) to http://127.0.0.1:4723."]}),!A&&!le&&e.jsxs("div",{className:"text-[11px] text-gray-500 leading-relaxed",children:["Installed drivers couldn't be checked (the ",e.jsx("code",{children:"appium"})," command isn't available to Testver). Make sure"," ",e.jsx("code",{children:"uiautomator2"})," (Android) and ",e.jsx("code",{children:"xcuitest"})," (iOS) are installed: ",e.jsx("code",{children:"appium driver list --installed"}),"."]})]}):null:e.jsx(Ae,{label:"Install + start Appium",cmd:`${he} && appium`,onCopy:W})}),(t==null?void 0:t.appium.reachable)&&t.appium.webviewHint&&e.jsx("div",{className:"ml-1 -mt-1 px-3 py-2 rounded-lg bg-amber-500/5 border border-amber-500/20 text-[11px] leading-relaxed text-amber-700 dark:text-amber-300/80",children:t.appium.webviewHint}),e.jsx(Rs,{icon:e.jsx(Gs,{size:16}),title:"Android",summary:re?`${F} device${F===1?"":"s"} ready`:"Setup needed",ok:re,expanded:b,onToggle:()=>z(!b),children:e.jsxs(Ms,{icon:e.jsx(Gs,{size:18}),title:"Android",ok:re,okHint:t?`ADB ${t.android.adbVersion??"✓"} · ${t.android.sdkSource}=${t.android.sdkRoot}${(be=t.appium.driverVersions)!=null&&be.uiautomator2?` · UiAutomator2 ${t.appium.driverVersions.uiautomator2}`:""}`:"",failHint:t!=null&&t.android.adbFound?!(t!=null&&t.android.sdkRoot)&&(t!=null&&t.android.sdkSavedNotLoaded)?`ANDROID_HOME is saved (${t.android.sdkSavedNotLoaded}) but Testver started before it was — restart Testver and your Appium terminal to pick it up`:t!=null&&t.android.sdkRoot?(t==null?void 0:t.android.sdkValid)===!1?`${t.android.sdkSource}="${t.android.sdkRoot}" doesn't look like an Android SDK (missing platform-tools / cmdline-tools / build-tools)`:te?"Android setup incomplete":"The Appium UiAutomator2 driver is not installed — Appium needs it to drive Android":"ANDROID_HOME (or ANDROID_SDK_ROOT) is not set — required by Appium to drive devices":(t==null?void 0:t.android.error)||"ADB not found in PATH or standard SDK locations",action:e.jsxs("div",{className:"space-y-1.5",children:[!(t!=null&&t.android.adbFound)&&ke&&e.jsx(Ae,{label:"Install platform-tools (ADB)",cmd:ke,onCopy:W}),$&&!te&&e.jsx(Ae,{label:"Install the UiAutomator2 driver, then restart Appium",cmd:"appium driver install uiautomator2",onCopy:W}),(t==null?void 0:t.android.adbFound)&&!(t!=null&&t.android.sdkValid)&&!(t!=null&&t.android.sdkSavedNotLoaded)&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"Install Android SDK (Android Studio — easiest)",hint:"Download from https://developer.android.com/studio — the setup wizard installs the SDK and points ANDROID_HOME at it.",onCopy:W}),e.jsx(Ae,{label:"Set ANDROID_HOME (Windows PowerShell — current user)",cmd:'[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:LOCALAPPDATA\\Android\\Sdk", "User")',onCopy:W}),e.jsx(Ae,{label:"Set ANDROID_HOME (macOS / Linux)",cmd:`export ANDROID_HOME="$HOME/Library/Android/sdk" # macOS
|
|
79
|
-
export ANDROID_HOME="$HOME/Android/Sdk" # Linux`,onCopy:W}),e.jsxs("div",{className:"text-[11px] text-amber-400/80 leading-relaxed pt-1",children:["After setting the variable, ",e.jsx("strong",{children:"restart Testver"})," and ",e.jsx("strong",{children:"close every terminal"})," (especially the one running Appium), then start them again — a program reads environment variables only when it starts. This check reads Testver's own environment; Appium reads the one of the terminal it runs in."]})]})]}),children:[(t==null?void 0:t.android.adbFound)&&e.jsx(bt,{devices:t.android.devices,kind:"android",emptyMessage:"No Android devices connected. Plug a device in via USB and enable USB debugging, or start an emulator below.",udevHint:G?(oe=i.udev)==null?void 0:oe.linux:void 0,onCopy:W}),(t==null?void 0:t.android.adbFound)&&e.jsx(nl,{avds:t.android.avds??[],emulatorFound:!!t.android.emulatorFound,busy:S,onStart:w,onStop:v})]})}),R?e.jsx(Rs,{icon:e.jsx(ss,{size:16}),title:"iOS",summary:ae?`${Q} device${Q===1?"":"s"} ready`:"Setup needed",ok:ae,expanded:M,onToggle:()=>V(!M),children:e.jsx(Ms,{icon:e.jsx(ss,{size:18}),title:"iOS",ok:ae,okHint:t?`Xcode ${t.ios.xcodeVersion??"✓"} · simulators ready${(k=t.appium.driverVersions)!=null&&k.xcuitest?` · XCUITest ${t.appium.driverVersions.xcuitest}`:""}`:"",failHint:t!=null&&t.ios.xcodeFound?X?"iOS setup incomplete":"The Appium XCUITest driver is not installed — Appium needs it to drive iOS":(t==null?void 0:t.ios.error)||"Xcode is not installed — needed for simulators and real devices",action:e.jsxs("div",{className:"space-y-1.5",children:[!(t!=null&&t.ios.xcodeFound)&&Ne.macos&&e.jsx(Ae,{label:"Install Xcode",hint:Ne.macos,onCopy:W}),(t==null?void 0:t.ios.xcodeFound)&&!X&&e.jsx(Ae,{label:"Install the XCUITest driver, then restart Appium",cmd:"appium driver install xcuitest",onCopy:W}),(t==null?void 0:t.ios.xcodeFound)&&e.jsxs("div",{className:"flex items-start gap-2 text-[12px] leading-relaxed px-1",children:[t.ios.libimobileFound?e.jsx(ne,{size:13,className:"text-emerald-400 mt-0.5 flex-shrink-0"}):e.jsx(Qe,{size:13,className:"text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-gray-500",children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Real iPhones / iPads:"})," ",t.ios.libimobileFound?"libimobiledevice ✓. ":"install libimobiledevice to see connected devices. ","Appium also installs ",e.jsx("strong",{children:"WebDriverAgent"})," on the device, signed with your Apple team — fill in the signing details under ",e.jsx("em",{children:"Advanced"})," below, or sign it once in Xcode."," ",e.jsxs("a",{href:"https://appium.github.io/appium-xcuitest-driver/latest/getting-started/device-setup/#real-devices",target:"_blank",rel:"noopener noreferrer",className:"text-brand-400 hover:text-brand-300 inline-flex items-center gap-0.5",children:["Setup guide ",e.jsx(Ss,{size:10})]})]})]}),(t==null?void 0:t.ios.xcodeFound)&&!t.ios.libimobileFound&&ye.macos&&e.jsx(Ae,{label:"Install libimobiledevice (real devices)",cmd:ye.macos,onCopy:W})]}),children:t&&t.ios.xcodeFound&&e.jsx(bt,{devices:t.ios.devices,kind:"ios",emptyMessage:"No iOS simulators or devices found. Add a simulator in Xcode (Window → Devices and Simulators), or plug in a device and tap Trust.",onCopy:W,simulators:{busy:x,onStart:E,onStop:P}})})}):e.jsx(Rs,{icon:e.jsx(ss,{size:16}),title:"iOS",summary:"Requires macOS",summaryTone:"orange",ok:!1,expanded:M,onToggle:()=>V(!M),children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5 text-sm text-gray-500 flex items-start gap-3",children:[e.jsx(ss,{size:18,className:"text-gray-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-300 font-medium",children:"iOS testing requires macOS"}),e.jsx("div",{className:"mt-1 text-xs",children:"Apple's licensing terms require Xcode to build / sign WebDriverAgent. iOS local testing isn't available on Linux or Windows — use a Mac, or pick one of the cloud providers for iOS coverage."})]})]})}),e.jsx(al,{mode:(l==null?void 0:l.appLaunchMode)??"fresh",onChange:ee}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5 flex items-start gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-200",children:"Grant app permissions automatically (Android)"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:"AI Assistant and AI Record sessions grant the app's permissions (camera, location, notifications…) when it's installed, so permission prompts don't interrupt a fresh start. Off: the prompts appear, and AI Record can record them. Test runs keep your project's own setting."})]}),e.jsx(gt,{enabled:(l==null?void 0:l.androidAutoGrantPermissions)===!0,onChange:C=>B({androidAutoGrantPermissions:C},C?"App permissions will be granted automatically":"Permission prompts will be shown")})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5",children:[e.jsxs("button",{onClick:()=>j(!c),className:"w-full flex items-center gap-2 px-5 py-3.5 text-sm font-medium text-gray-300 hover:bg-white/[0.02]",children:[c?e.jsx(Me,{size:14}):e.jsx(Ie,{size:14}),"Advanced — override tool paths"]}),c&&l&&e.jsxs("div",{className:"px-5 pb-5 pt-1 space-y-4",children:[e.jsx(Ke,{label:"Appium URL",value:l.appiumUrl,placeholder:"http://127.0.0.1:4723",onSave:C=>K("appiumUrl",C),hint:"Override if Appium runs on a non-default port. It must run on this computer — devices and app files are found here."}),e.jsx(Ke,{label:"ADB path (Android)",value:l.adbPath||"",placeholder:"auto-detected from PATH + $ANDROID_HOME",onSave:C=>K("adbPath",C),hint:"Set when multiple Android SDKs are installed and you want to pin one."}),R&&e.jsx(Ke,{label:"iOS tools path",value:l.iosToolsPath||"",placeholder:"auto-detected from PATH",onSave:C=>K("iosToolsPath",C),hint:"Set when libimobiledevice lives outside PATH."}),R&&e.jsxs("div",{className:"pt-3 border-t border-white/5 space-y-4",children:[e.jsxs("div",{className:"text-xs text-gray-500 leading-relaxed",children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Real iPhones / iPads — WebDriverAgent signing."})," Appium builds WebDriverAgent and installs it on the device, signed with your Apple team. Leave these empty if you signed it in Xcode yourself, or if your project's capabilities already set them. Simulators need none of this."]}),e.jsx(Ke,{label:"Apple Team ID",value:l.iosTeamId||"",placeholder:"e.g. A1B2C3D4E5",onSave:C=>K("iosTeamId",C),hint:"10 characters — Xcode → Settings → Accounts, or developer.apple.com → Membership."}),e.jsx(Ke,{label:"Signing identity",value:l.iosSigningId||"",placeholder:"Apple Development",onSave:C=>K("iosSigningId",C),hint:"Usually Apple Development (used when a Team ID is set and this is empty)."}),e.jsx(Ke,{label:"WebDriverAgent bundle id",value:l.iosWdaBundleId||"",placeholder:"e.g. com.yourcompany.WebDriverAgentRunner",onSave:C=>K("iosWdaBundleId",C),hint:"Needed with a free / personal team: a bundle id your team can sign."})]})]})]})]})]})})}function Rs({icon:s,title:t,summary:a,summaryTone:l,ok:m,expanded:i,onToggle:h,children:d}){const f=l==="orange"?"text-orange-500 dark:text-orange-400 font-medium":m?"text-gray-500":"text-amber-400/90";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:[e.jsxs("button",{onClick:h,className:"w-full flex items-center gap-3 px-5 py-3.5 text-left hover:bg-white/[0.02] transition-colors","aria-expanded":i,children:[i?e.jsx(Me,{size:14,className:"text-gray-500 flex-shrink-0"}):e.jsx(Ie,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0 ${m?"bg-emerald-500/15 text-emerald-400":"bg-amber-500/15 text-amber-400"}`,children:s}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2.5",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:t}),m?e.jsx(ne,{size:13,className:"text-emerald-400 flex-shrink-0"}):e.jsx(Qe,{size:13,className:"text-amber-400 flex-shrink-0"}),e.jsx("span",{className:`text-xs ${f} truncate`,children:a})]})]}),i&&e.jsx("div",{className:"border-t border-white/5 p-4 space-y-3",children:d})]})}function Ms({icon:s,title:t,ok:a,okHint:l,failHint:m,action:i,children:h}){return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center flex-shrink-0 ${a?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:s}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:t}),a?e.jsx(ne,{size:14,className:"text-emerald-400 flex-shrink-0"}):e.jsx(Se,{size:14,className:"text-red-400 flex-shrink-0"})]}),e.jsx("div",{className:`mt-1 text-xs ${a?"text-gray-400":"text-amber-400"}`,children:a?l:m})]})]}),i,h]})}function rl({ok:s,okLabel:t,warnLabel:a}){return s?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-emerald-300 bg-emerald-500/15 border border-emerald-500/30 px-2 py-0.5 rounded",children:[e.jsx(ne,{size:11}),t]}):e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-amber-300 bg-amber-500/15 border border-amber-500/30 px-2 py-0.5 rounded",children:[e.jsx(Qe,{size:11}),a]})}function Ae({label:s,cmd:t,hint:a,onCopy:l}){return e.jsxs("div",{className:"bg-surface-2 border border-white/5 rounded-md p-2.5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-gray-500 mb-1.5",children:s}),t?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 text-[11px] text-gray-200 font-mono break-all",children:t}),e.jsx("button",{onClick:()=>l(t),className:"p-1.5 rounded text-gray-500 hover:text-gray-200 hover:bg-white/10 flex-shrink-0",title:"Copy command",children:e.jsx(xs,{size:12})})]}):e.jsx("div",{className:"text-[12px] text-gray-400 leading-relaxed",children:a})]})}function al({mode:s,onChange:t}){const a=[{value:"fresh",title:"Fresh start (clear data)",desc:"Wipe app data before every run — starts from onboarding / logged-out, default settings. (A project whose own capabilities set noReset keeps its data.)"},{value:"keep",title:"Keep data",desc:"Preserve app data between runs — stays logged in, keeps settings. App is still relaunched. Applies over the project's own noReset."}];return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx($e,{size:15,className:"text-brand-400"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-200",children:"App launch mode"})]}),e.jsx("p",{className:"text-xs text-gray-500 mb-3",children:"How the app starts at the beginning of each run on a local device — Test Explorer, Suites, Schedules and AI runs alike (WebdriverIO, pytest and Robot projects; Java, C# and Ruby projects set this in their own capabilities)."}),e.jsx("div",{className:"grid sm:grid-cols-2 gap-2.5",children:a.map(l=>{const m=s===l.value;return e.jsxs("button",{onClick:()=>t(l.value),className:`text-left rounded-lg border p-3 bg-white transition-colors ${m?"border-brand-500 ring-1 ring-brand-500/50 shadow-[0_0_0_1px_rgba(59,130,246,0.25)]":"border-gray-200 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-3.5 h-3.5 rounded-full border-2 flex-shrink-0 flex items-center justify-center ${m?"border-brand-400 bg-brand-500":"border-gray-500"}`,children:m&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-white"})}),e.jsx("span",{className:`text-[13px] font-semibold ${m?"text-brand-600":"text-gray-800"}`,children:l.title}),m&&e.jsx("span",{className:"ml-auto text-[10px] font-medium text-brand-600 bg-brand-500/10 border border-brand-500/40 px-1.5 py-0.5 rounded",children:"Selected"})]}),e.jsx("p",{className:"text-[11px] mt-1.5 leading-relaxed pl-[22px] text-gray-600",children:l.desc})]},l.value)})}),e.jsxs("div",{className:"mt-2.5 flex items-start gap-1.5 text-[11px] text-orange-500 dark:text-orange-400",children:[e.jsx(Qe,{size:12,className:"flex-shrink-0 mt-0.5"}),e.jsxs("span",{children:[e.jsx("strong",{children:"iOS note:"}),' "Fresh start (clear data)" is Android-only — iOS apps relaunch with their existing data regardless of this setting.']})]})]})}function gt({enabled:s,onChange:t,label:a}){return e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer select-none",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":s,onClick:()=>t(!s),className:`relative inline-flex h-5 w-9 flex-shrink-0 rounded-full border transition-colors ${s?"bg-emerald-500/80 border-emerald-400/60":"bg-gray-300 dark:bg-white/10 border-gray-400/40 dark:border-white/15"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 mt-[1px] rounded-full bg-white shadow transition-transform ${s?"translate-x-[18px]":"translate-x-[2px]"}`})}),a&&e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:a})]})}function bt({devices:s,kind:t,emptyMessage:a,udevHint:l,onCopy:m,simulators:i}){const h=s.some(d=>d.state==="no-permissions");return s.length===0?e.jsx("div",{className:"text-[12px] text-gray-500 bg-surface-2/40 border border-white/5 rounded-md px-3 py-2.5 italic",children:a}):e.jsxs("div",{className:"space-y-1.5",children:[s.map(d=>e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-md border ${d.state==="connected"?"bg-surface-2/50 border-white/5":"bg-amber-500/[0.04] border-amber-500/20"}`,children:[t==="android"?e.jsx(Gs,{size:14,className:"text-emerald-400 flex-shrink-0"}):e.jsx(ss,{size:14,className:"text-gray-300 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-[13px] text-gray-900 dark:text-gray-100 font-medium truncate",children:[d.name||d.serial,d.platformVersion&&e.jsxs("span",{className:"text-gray-500 font-normal",children:[" · ",t==="ios"?"iOS":"Android"," ",d.platformVersion]}),t==="android"&&d.kind!=="emulator"&&d.state==="connected"&&e.jsx("span",{className:"text-gray-500 font-normal",children:" · real device"})]}),e.jsxs("div",{className:"text-[10px] text-gray-500 font-mono mt-0.5 truncate",children:[d.serial,i&&d.kind==="simulator"&&!d.booted&&e.jsx("span",{className:"font-sans",children:" · Not running — start it to use it in sessions and runs"})]})]}),i&&d.state==="connected"&&d.kind==="simulator"?e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d.booted&&e.jsx("span",{className:"text-[10px] text-emerald-400 px-1.5 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:"Ready"}),d.booted?e.jsxs("button",{onClick:()=>i.onStop(d),disabled:i.busy!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-white/5 text-gray-600 dark:text-gray-300 border border-white/10 hover:bg-white/10 disabled:opacity-40",children:[i.busy===d.serial?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ns,{size:11}),"Close"]}):e.jsxs("button",{onClick:()=>i.onStart(d),disabled:i.busy!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-brand-500/15 text-brand-600 dark:text-brand-200 border border-brand-500/40 hover:bg-brand-500/25 disabled:opacity-40",children:[i.busy===d.serial?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Xs,{size:11}),i.busy===d.serial?"Starting…":"Start"]})]}):d.state==="connected"?e.jsx("span",{className:"text-[10px] text-emerald-400 px-1.5 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:"Ready"}):d.state==="unauthorized"?e.jsx("span",{className:"text-[10px] text-amber-400 px-1.5 py-0.5 rounded bg-amber-500/10 border border-amber-500/30",title:"Unlock the phone and tap Allow on the USB debugging prompt",children:"Tap Allow on the phone"}):d.state==="no-permissions"?e.jsx("span",{className:"text-[10px] text-amber-400 px-1.5 py-0.5 rounded bg-amber-500/10 border border-amber-500/30",title:"This computer has no USB permission for the phone — add a udev rule",children:"No USB permission"}):d.state==="offline"?e.jsx("span",{className:"text-[10px] text-gray-500 px-1.5 py-0.5 rounded bg-white/5 border border-white/10",title:"Unplug and reconnect the device",children:"Offline"}):e.jsx("span",{className:"text-[10px] text-gray-500 px-1.5 py-0.5 rounded bg-white/5 border border-white/10",children:d.state})]},d.serial)),h&&e.jsxs("div",{className:"text-[11px] text-amber-600 dark:text-amber-400/90 leading-relaxed pt-1 space-y-1.5",children:[e.jsxs("div",{children:["Linux needs a ",e.jsx("strong",{children:"udev rule"})," before it lets you use an Android phone over USB (and your user in the ",e.jsx("code",{children:"plugdev"})," group). Install the standard Android rules, then unplug and reconnect the phone."]}),l&&e.jsx(Ae,{label:"Install the Android udev rules",cmd:l,onCopy:m})]})]})}function nl({avds:s,emulatorFound:t,busy:a,onStart:l,onStop:m}){return e.jsxs("div",{className:"pt-1",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-gray-500 mb-1.5",children:"Emulators (AVDs)"}),t?s.length===0?e.jsx("div",{className:"text-[12px] text-gray-500 bg-surface-2/40 border border-white/5 rounded-md px-3 py-2.5 italic",children:"No emulators yet. Create one in Android Studio → Device Manager."}):e.jsx("div",{className:"space-y-1.5",children:s.map(i=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md border bg-surface-2/50 border-white/5",children:[e.jsx(Oe,{size:14,className:"text-gray-400 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-gray-900 dark:text-gray-100 font-medium truncate",children:i.name.replace(/_/g," ")}),e.jsx("div",{className:"text-[10px] text-gray-500 font-mono mt-0.5 truncate",children:i.running?`Running · ${i.serial}`:"Not running — start it to use it in sessions and runs"})]}),i.running?e.jsxs("button",{onClick:()=>m(i),disabled:a!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-white/5 text-gray-600 dark:text-gray-300 border border-white/10 hover:bg-white/10 disabled:opacity-40",children:[a===i.name?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ns,{size:11}),"Close"]}):e.jsxs("button",{onClick:()=>l(i),disabled:a!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-brand-500/15 text-brand-600 dark:text-brand-200 border border-brand-500/40 hover:bg-brand-500/25 disabled:opacity-40",children:[a===i.name?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Xs,{size:11}),a===i.name?"Starting…":"Start"]})]},i.name))}):e.jsx("div",{className:"text-[12px] text-gray-500 bg-surface-2/40 border border-white/5 rounded-md px-3 py-2.5 italic",children:"The Android emulator isn't installed. Add it in Android Studio → SDK Manager → SDK Tools → Android Emulator."})]})}function Ke({label:s,value:t,placeholder:a,onSave:l,hint:m}){const[i,h]=n.useState(t);n.useEffect(()=>h(t),[t]);const d=i!==t;return e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1.5",children:s}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:i,onChange:f=>h(f.target.value),placeholder:a,className:"flex-1 bg-surface-2 border border-white/10 rounded-md px-3 py-2 text-sm text-gray-100 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>l(i),disabled:!d,className:"px-3 py-2 rounded-md text-xs font-medium bg-brand-500/20 text-brand-200 border border-brand-500/40 hover:bg-brand-500/30 disabled:opacity-40",children:"Save"})]}),m&&e.jsx("div",{className:"mt-1 text-[11px] text-gray-500",children:m})]})}function ft(s){if(!s)return"";const t=Math.max(0,Math.round((Date.now()-Date.parse(s))/6e4));return t<1?"just now":t<60?`${t} min ago`:`${Math.floor(t/60)} h ago`}const Ws={chromium:"bg-blue-400",firefox:"bg-orange-400",webkit:"bg-purple-400"},qs={webdriver:"Test run",cdp:"AI browser","pw-server":"Test run"};function Js(s){if(!s)return"";const t=Math.max(0,Math.round((Date.now()-Date.parse(s))/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}const Ds=8;function ll(){const[s,t]=n.useState(()=>document.visibilityState!=="hidden");return n.useEffect(()=>{const a=()=>t(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[]),s}function ol({session:s,allowed:t,onClick:a}){const l=n.useRef(null),[m,i]=n.useState(!1),[h,d]=n.useState(!1);n.useEffect(()=>{const g=l.current;if(!g)return;const y=new IntersectionObserver(c=>i(c.some(j=>j.isIntersecting)),{threshold:.1});return y.observe(g),()=>y.disconnect()},[]),n.useEffect(()=>{d(!1)},[s.sessionId,t]);const f=t&&m&&!h&&s.state==="active";return e.jsxs("button",{ref:l,onClick:a,className:"relative rounded-lg overflow-hidden bg-black aspect-[16/10] group border border-gray-200 dark:border-white/10 hover:border-brand-400 dark:hover:border-brand-500/60 transition-colors text-left",title:"Open live view",children:[f?e.jsx("img",{src:Tt(s.sessionId),onError:()=>d(!0),alt:"",className:"w-full h-full object-contain"}):e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-1.5 text-gray-500",children:[e.jsx(ve,{size:16,className:"opacity-60"}),e.jsx("span",{className:"text-[10px]",children:h?"stream unavailable":"click to watch"})]}),e.jsxs("div",{className:"absolute inset-x-0 bottom-0 flex items-center gap-1.5 px-2 py-1 bg-black/60 backdrop-blur-sm",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ws[s.browser]||"bg-gray-400"}`}),e.jsx("span",{className:"text-[10px] text-gray-200 capitalize",children:s.browser}),e.jsx("span",{className:"text-[9px] text-gray-400",children:qs[s.mode]||s.mode}),e.jsx("span",{className:"text-[9px] text-gray-400 font-mono flex-1 text-right",children:Js(s.createdAt)}),f&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse shrink-0"})]})]})}function il({onChanged:s}){var A,te,X,le;const{toast:t}=ge(),[a,l]=n.useState(null),[m,i]=n.useState(null),[h,d]=n.useState(null),[f,g]=n.useState(null),[y,c]=n.useState([]),[j,p]=n.useState({}),[u,b]=n.useState(null),[z,M]=n.useState(null),[V,U]=n.useState(!1),[O,S]=n.useState(!1),I=ll(),w=n.useCallback(()=>{_r().then($=>{l($),$.connected&&Hr().then(i).catch(()=>i(null))}).catch(()=>l(null))},[]);n.useEffect(()=>{w()},[w]),n.useEffect(()=>{if(!(a!=null&&a.connected))return;let $=!0;const re=()=>{Vr().then(ce=>{$&&c(ce.sessions)}).catch(()=>{$&&c([])}),Gr().then(ce=>{$&&p(Object.fromEntries(ce.runs.filter(he=>he.gridRunId).map(he=>[he.gridRunId,he.runId])))}).catch(()=>{})};re();const ae=setInterval(re,5e3);return()=>{$=!1,clearInterval(ae)}},[a==null?void 0:a.connected]),n.useEffect(()=>{z&&!y.some($=>$.sessionId===z.sessionId&&$.state==="active")&&M(null)},[y,z]);const v=$=>{U(!1),M($)},x=async $=>{b($);try{await Qr($),c(re=>re.filter(ae=>ae.sessionId!==$))}catch(re){t("error",re instanceof Error?re.message:"Stop failed")}finally{b(null)}},[o,r]=n.useState(null),E=async($=!1)=>{d("connect"),r(null);try{const re=await Wr({takeover:$});t("success",$?"Testver Grid moved to this device":"Testver Grid connected"),re.connection,w(),s==null||s()}catch(re){const ae=re;ae.status===409&&(ae.code==="GRID_IN_USE"||ae.code==="GRID_BUSY")?r({code:ae.code,message:ae.message,deviceName:ae.deviceName,connectedBy:ae.connectedBy,lastSeenAt:ae.lastSeenAt,canTakeOver:ae.canTakeOver}):t("error",ae.message||"Grid connect failed")}finally{d(null)}},P=async()=>{d("test"),g(null);try{const $=await qr();g({ok:$.ok,msg:$.message})}catch($){g({ok:!1,msg:$ instanceof Error?$.message:"Test failed"})}finally{d(null)}},B=async $=>{d("save");try{await Jr({enabled:$.enabled??(a==null?void 0:a.enabled)??!0,aiBrowserTarget:$.aiBrowserTarget??(a==null?void 0:a.aiBrowserTarget)??"local",aiTunnelEnabled:$.aiTunnelEnabled??(a==null?void 0:a.aiTunnelEnabled)??!1}),w(),s==null||s()}catch(re){t("error",re instanceof Error?re.message:"Save failed")}finally{d(null)}},N=a!=null&&a.access?!a.access.enabled:!1,ee=((A=a==null?void 0:a.access)==null?void 0:A.refusal)??null,K=(a==null?void 0:a.connection)??null,W=!!K&&!!(a!=null&&a.thisDevice)&&K.deviceId!==a.thisDevice.deviceId&&!K.stale,R=(a==null?void 0:a.limit)??((te=a==null?void 0:a.access)==null?void 0:te.limit)??null,G=((X=a==null?void 0:a.access)==null?void 0:X.subject)??null,_=m?Math.round(m.monthSeconds/60):0;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Testver's own cloud browsers — Chromium, Firefox and WebKit sessions with no vendor account and no credentials. Uses your connected Testver account (same as AI). A prepaid add-on to a paid plan (parallel browsers, bought on testver.com); one Testver installation holds the connection at a time."}),e.jsxs("div",{className:"flex items-center gap-3 text-sm flex-wrap",children:[a!=null&&a.connected?e.jsxs("span",{className:"flex items-center gap-1.5 text-emerald-600 dark:text-emerald-400",children:[e.jsx(ze,{size:14})," Connected",e.jsx("span",{className:"text-gray-500 font-normal",children:"· token renews automatically"})]}):e.jsxs("span",{className:"flex items-center gap-1.5 text-gray-500 dark:text-gray-400",children:[e.jsx(Se,{size:14})," Not connected"]}),e.jsx("span",{className:"text-gray-400 dark:text-gray-600 text-xs",children:a==null?void 0:a.gridUrl}),R!=null&&((le=a==null?void 0:a.access)==null?void 0:le.enabled)&&e.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["· up to ",R," browser",R===1?"":"s"," at once",(G==null?void 0:G.type)==="team"?` (${G.name??"your team"} pool)`:""]})]}),N&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-amber-50 dark:bg-amber-500/10 border border-amber-200 dark:border-amber-500/20 rounded-lg px-3.5 py-2.5 text-sm text-amber-700 dark:text-amber-300",children:[e.jsx(ue,{size:15,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[(ee==null?void 0:ee.message)??"Testver Grid is not enabled for your Testver account. It is an add-on for any paid plan — add it on testver.com under Billing.",(ee==null?void 0:ee.code)==="GRID_NOT_OPERATOR"&&K&&e.jsxs("span",{className:"block text-xs mt-1 opacity-80",children:["Connected on ",K.deviceName,K.connectedBy?` by ${K.connectedBy.name||K.connectedBy.email}`:""," · last seen ",ft(K.lastSeenAt)]})]})]}),!N&&W&&!o&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-sky-50 dark:bg-sky-500/10 border border-sky-200 dark:border-sky-500/20 rounded-lg px-3.5 py-2.5 text-sm text-sky-800 dark:text-sky-200",children:[e.jsx(ds,{size:15,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:["Testver Grid is connected on ",e.jsx("span",{className:"font-medium",children:K.deviceName}),K.connectedBy?` by ${K.connectedBy.name||K.connectedBy.email}`:""," · last seen ",ft(K.lastSeenAt),".",e.jsx("span",{className:"block text-xs mt-1 opacity-80",children:"One installation holds the connection at a time. Take it over here once that device is idle, or disconnect it there."})]})]}),o&&e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-500/10 border border-amber-200 dark:border-amber-500/20 rounded-lg px-3.5 py-3 text-sm text-amber-800 dark:text-amber-200 space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(ue,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:o.message})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-6",children:[o.code==="GRID_IN_USE"&&o.canTakeOver!==!1&&e.jsx("button",{onClick:()=>E(!0),disabled:h!==null,className:"px-3 py-1.5 rounded-md bg-amber-600 hover:bg-amber-500 text-white text-xs font-medium disabled:opacity-50",children:h==="connect"?e.jsx(J,{size:12,className:"animate-spin"}):"Take over on this device"}),e.jsx("button",{onClick:()=>r(null),className:"px-3 py-1.5 rounded-md text-xs text-amber-800 dark:text-amber-200 hover:bg-amber-100 dark:hover:bg-amber-500/20",children:"Not now"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs(os,{to:"/testver",className:"px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium flex items-center gap-2 transition-colors",children:[e.jsx(Dt,{size:14}),"Manage in Testver → Connections"]}),e.jsxs("button",{onClick:P,disabled:h!==null||!(a!=null&&a.connected),className:"px-4 py-2 rounded-lg bg-gray-100 dark:bg-surface-2 border border-gray-200 dark:border-white/10 text-gray-700 dark:text-gray-300 text-sm disabled:opacity-50 flex items-center gap-2 transition-colors",children:[h==="test"?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14}),"Test connection"]})]}),f&&e.jsx("div",{className:`text-sm ${f.ok?"text-emerald-600 dark:text-emerald-400":"text-red-500 dark:text-red-400"}`,children:f.msg}),(a==null?void 0:a.configured)&&e.jsxs("div",{className:"space-y-3 pt-3 border-t border-gray-100 dark:border-white/5",children:[e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-700 dark:text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:$=>B({enabled:$.target.checked}),disabled:h!==null,className:"rounded border-gray-300 dark:border-gray-600 bg-white dark:bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Offer Testver Grid as a run target"]}),e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-700 dark:text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.aiBrowserTarget==="grid",onChange:$=>B({aiBrowserTarget:$.target.checked?"grid":"local"}),disabled:h!==null,className:"rounded border-gray-300 dark:border-gray-600 bg-white dark:bg-surface-2 text-brand-500 focus:ring-brand-500"}),"AI Assistance browsers run on the grid by default"]}),a.aiBrowserTarget==="grid"&&e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-700 dark:text-gray-300 cursor-pointer pl-6",children:[e.jsx("input",{type:"checkbox",checked:a.aiTunnelEnabled,onChange:$=>B({aiTunnelEnabled:$.target.checked}),disabled:h!==null,className:"rounded border-gray-300 dark:border-gray-600 bg-white dark:bg-surface-2 text-brand-500 focus:ring-brand-500"}),e.jsxs("span",{children:["AI grid browsers can reach your local apps",e.jsx("span",{className:"block text-xs text-gray-400 dark:text-gray-500",children:"Outbound tunnel scoped to localhost, per session, closed when the browser closes"})]})]})]}),(a==null?void 0:a.connected)&&y.length>0&&e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide flex items-center gap-1.5",children:[e.jsx(ds,{size:12})," Live sessions (",y.length,")"]}),e.jsxs("button",{onClick:()=>S($=>!$),title:O?"List view":"Wall view — live thumbnails",className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/5 transition-colors",children:[O?e.jsx(en,{size:12}):e.jsx(sn,{size:12}),O?"List":"Wall"]})]}),O&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:y.map(($,re)=>e.jsx(ol,{session:$,allowed:I&&re<Ds,onClick:()=>v($)},$.sessionId))}),y.length>Ds&&e.jsxs("p",{className:"text-[11px] text-gray-400 dark:text-gray-600",children:["Streaming the first ",Ds," — click any other tile to watch it."]})]}),!O&&y.map($=>e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg bg-gray-50 dark:bg-white/[0.04] border border-gray-100 dark:border-white/5 px-3 py-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Ws[$.browser]||"bg-gray-400"}`}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 capitalize",children:$.browser}),e.jsx("span",{className:"text-xs text-gray-500",children:qs[$.mode]||$.mode}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${$.state==="active"?"bg-emerald-50 dark:bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":"bg-amber-50 dark:bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:$.state}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-600 font-mono flex-1 text-right",children:Js($.createdAt)}),$.runId&&j[$.runId]&&e.jsx(os,{to:`/results?runId=${encodeURIComponent(j[$.runId])}`,title:"Open the run this browser belongs to — its live view is there too",className:"text-[11px] text-cyan-600 dark:text-cyan-400 hover:underline whitespace-nowrap",children:"Open run"}),$.state==="active"&&e.jsx("button",{onClick:()=>v($),title:"Watch live",className:"flex items-center justify-center w-6 h-6 rounded text-gray-400 hover:text-brand-500 dark:hover:text-brand-400 hover:bg-brand-50 dark:hover:bg-brand-500/10 transition-colors",children:e.jsx(ve,{size:12})}),e.jsx("button",{onClick:()=>x($.sessionId),disabled:u===$.sessionId,title:"Stop session",className:"flex items-center justify-center w-6 h-6 rounded text-gray-400 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 transition-colors disabled:opacity-50",children:u===$.sessionId?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ns,{size:11})})]},$.sessionId))]}),z&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6",onClick:()=>M(null),children:e.jsxs("div",{className:"bg-white dark:bg-surface-1 rounded-xl shadow-2xl border border-gray-200 dark:border-white/10 max-w-4xl w-full overflow-hidden",onClick:$=>$.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-gray-100 dark:border-white/5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Ws[z.browser]||"bg-gray-400"}`}),e.jsx("span",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 capitalize",children:z.browser}),e.jsx("span",{className:"text-xs text-gray-500",children:qs[z.mode]||z.mode}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] px-1.5 py-0.5 rounded bg-emerald-50 dark:bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"})," LIVE"]}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-600 font-mono flex-1 text-right",children:Js(z.createdAt)}),e.jsxs("button",{onClick:()=>{x(z.sessionId),M(null)},title:"Stop session",className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs text-gray-500 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 transition-colors",children:[e.jsx(Ns,{size:11})," Stop"]}),e.jsx("button",{onClick:()=>M(null),className:"flex items-center justify-center w-7 h-7 rounded-lg text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:e.jsx(me,{size:15})})]}),e.jsx("div",{className:"bg-black aspect-[16/10] flex items-center justify-center",children:V?e.jsx("p",{className:"text-sm text-gray-400 px-8 text-center",children:"Live view isn't available for this session — the machine may run headless (evidence disabled) or predate the live-view rollout."}):I?e.jsx("img",{src:Tt(z.sessionId),onError:()=>U(!0),alt:"Live session",className:"w-full h-full object-contain"}):e.jsx("p",{className:"text-sm text-gray-500",children:"Stream paused — tab in background"})})]})}),m&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 pt-3 border-t border-gray-100 dark:border-white/5",children:["This month: ",e.jsxs("span",{className:"text-gray-700 dark:text-gray-300",children:[_," browser-minutes"]})," across"," ",e.jsxs("span",{className:"text-gray-700 dark:text-gray-300",children:[m.monthSessions," sessions"]}),e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:" · free testing phase, usage is informational"})]})]})}const dl=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"0 0 256 256",xmlns:"http://www.w3.org/2000/svg",children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{x1:"98.03%",y1:"0.16%",x2:"58.89%",y2:"40.77%",id:"cjg1",children:[e.jsx("stop",{stopColor:"#0052CC",offset:"18%"}),e.jsx("stop",{stopColor:"#2684FF",offset:"100%"})]}),e.jsxs("linearGradient",{x1:"100.67%",y1:"0.46%",x2:"55.4%",y2:"44.73%",id:"cjg2",children:[e.jsx("stop",{stopColor:"#0052CC",offset:"18%"}),e.jsx("stop",{stopColor:"#2684FF",offset:"100%"})]})]}),e.jsx("path",{d:"M244.658,0 L121.707,0 C121.707,14.72 127.554,28.837 137.963,39.246 C148.372,49.655 162.489,55.502 177.209,55.502 L199.858,55.502 L199.858,77.369 C199.877,107.994 224.699,132.816 255.324,132.836 L255.324,10.667 C255.324,4.776 250.549,0 244.658,0 Z",fill:"#2684FF"}),e.jsx("path",{d:"M183.822,61.262 L60.871,61.262 C60.891,91.887 85.713,116.709 116.338,116.729 L138.987,116.729 L138.987,138.667 C139.026,169.292 163.864,194.098 194.489,194.098 L194.489,71.929 C194.489,66.038 189.713,61.262 183.822,61.262 Z",fill:"url(#cjg1)"}),e.jsx("path",{d:"M122.951,122.489 L0,122.489 C0,153.142 24.849,177.991 55.502,177.991 L78.222,177.991 L78.222,199.858 C78.242,230.455 103.02,255.266 133.618,255.324 L133.618,133.156 C133.618,127.265 128.842,122.489 122.951,122.489 Z",fill:"url(#cjg2)"})]}),cl=({size:s=28})=>e.jsx("svg",{width:s,height:s,viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"none",children:e.jsxs("g",{fillRule:"evenodd",clipRule:"evenodd",children:[e.jsx("path",{fill:"#E01E5A",d:"M2.471 11.318a1.474 1.474 0 001.47-1.471v-1.47h-1.47A1.474 1.474 0 001 9.846c.001.811.659 1.469 1.47 1.47zm3.682-2.942a1.474 1.474 0 00-1.47 1.471v3.683c.002.811.66 1.468 1.47 1.47a1.474 1.474 0 001.47-1.47V9.846a1.474 1.474 0 00-1.47-1.47z"}),e.jsx("path",{fill:"#36C5F0",d:"M4.683 2.471c.001.811.659 1.469 1.47 1.47h1.47v-1.47A1.474 1.474 0 006.154 1a1.474 1.474 0 00-1.47 1.47zm2.94 3.682a1.474 1.474 0 00-1.47-1.47H2.47A1.474 1.474 0 001 6.153c.002.812.66 1.469 1.47 1.47h3.684a1.474 1.474 0 001.47-1.47z"}),e.jsx("path",{fill:"#2EB67D",d:"M9.847 7.624a1.474 1.474 0 001.47-1.47V2.47A1.474 1.474 0 009.848 1a1.474 1.474 0 00-1.47 1.47v3.684c.002.81.659 1.468 1.47 1.47zm3.682-2.941a1.474 1.474 0 00-1.47 1.47v1.47h1.47A1.474 1.474 0 0015 6.154a1.474 1.474 0 00-1.47-1.47z"}),e.jsx("path",{fill:"#ECB22E",d:"M8.377 9.847c.002.811.659 1.469 1.47 1.47h3.683A1.474 1.474 0 0015 9.848a1.474 1.474 0 00-1.47-1.47H9.847a1.474 1.474 0 00-1.47 1.47zm2.94 3.682a1.474 1.474 0 00-1.47-1.47h-1.47v1.47c.002.812.659 1.469 1.47 1.47a1.474 1.474 0 001.47-1.47z"})]})}),xl=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"4 4 36 38",xmlns:"http://www.w3.org/2000/svg",fill:"none",children:[e.jsx("path",{fill:"url(#ct_a)",d:"M21.9999 20h12c3.3137 0 6 2.6863 6 6v10c0 3.3137-2.6863 6-6 6s-6-2.6863-6-6V26c0-3.3137-2.6863-6-6-6"}),e.jsx("path",{fill:"url(#ct_b)",d:"M7.99988 24c0-3.3137 2.68632-6 6.00002-6h8c3.3137 0 6 2.6863 6 6v12c0 3.3137 2.6863 6 6 6l-16.0001-.0001c-5.5228 0-9.99992-4.4771-9.99992-10z"}),e.jsx("path",{fill:"url(#ct_e)",d:"M32.9999 18c2.7614 0 5-2.2386 5-5s-2.2386-5-5-5-5 2.2386-5 5 2.2386 5 5 5"}),e.jsx("path",{fill:"url(#ct_h)",d:"M17.9999 16c3.3137 0 6-2.6863 6-6 0-3.31371-2.6863-6-6-6s-6 2.68629-6 6c0 3.3137 2.6863 6 6 6"}),e.jsx("rect",{width:"16",height:"16",x:"4",y:"23",fill:"url(#ct_k)",rx:"3.25"}),e.jsx("path",{fill:"#fff",d:"M15.4792 28.1054h-2.4471v7.466h-2.0648v-7.466H8.52014v-1.6768h6.95906z"}),e.jsxs("defs",{children:[e.jsxs("radialGradient",{id:"ct_a",cx:"0",cy:"0",r:"1",gradientTransform:"matrix(13.4784 0 0 33.2694 39.7967 22.1739)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{stopColor:"#a98aff"}),e.jsx("stop",{offset:".14",stopColor:"#8c75ff"}),e.jsx("stop",{offset:".565",stopColor:"#5f50e2"}),e.jsx("stop",{offset:".9",stopColor:"#3c2cb8"})]}),e.jsxs("radialGradient",{id:"ct_b",cx:"0",cy:"0",r:"1",gradientTransform:"rotate(68.1539 -7.71566095 14.71355834)scale(32.752 33.1231)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{stopColor:"#85c2ff"}),e.jsx("stop",{offset:".69",stopColor:"#7588ff"}),e.jsx("stop",{offset:"1",stopColor:"#6459fe"})]}),e.jsxs("radialGradient",{id:"ct_e",cx:"0",cy:"0",r:"1",gradientTransform:"matrix(0 -10 12.6216 0 32.9999 11.5714)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:".268201",stopColor:"#6868f7"}),e.jsx("stop",{offset:"1",stopColor:"#3923b1"})]}),e.jsxs("radialGradient",{id:"ct_h",cx:"0",cy:"0",r:"1",gradientTransform:"matrix(0 -12 15.146 0 17.9999 8.28571)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:".268201",stopColor:"#8282ff"}),e.jsx("stop",{offset:"1",stopColor:"#3923b1"})]}),e.jsxs("radialGradient",{id:"ct_k",cx:"0",cy:"0",r:"1",gradientTransform:"rotate(45 -25.76345597 16.32842712)scale(22.6274)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:".046875",stopColor:"#688eff"}),e.jsx("stop",{offset:".946875",stopColor:"#230f94"})]})]})]}),Gt=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"0 0 177 177",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("defs",{children:e.jsxs("radialGradient",{cx:"49.87%",cy:"49.95%",fx:"49.87%",fy:"49.95%",r:"49.92%",id:"bsg1",children:[e.jsx("stop",{stopColor:"#797979",offset:"0%"}),e.jsx("stop",{stopColor:"#4C4C4C",offset:"100%"})]})}),e.jsx("circle",{fill:"#F4B960",cx:"88.5",cy:"88.5",r:"88.5"}),e.jsx("circle",{fill:"#E66F32",cx:"80",cy:"80",r:"80"}),e.jsx("circle",{fill:"#E43C41",cx:"90",cy:"69",r:"69"}),e.jsx("circle",{fill:"#BDD041",cx:"95.5",cy:"74.5",r:"63.5"}),e.jsx("circle",{fill:"#6DB54C",cx:"91",cy:"79",r:"59"}),e.jsx("circle",{fill:"#AEDAE6",cx:"81.5",cy:"70.5",r:"49.5"}),e.jsx("circle",{fill:"#56B8DE",cx:"90.5",cy:"61.5",r:"41.5"}),e.jsx("circle",{fill:"#00B1D5",cx:"95.5",cy:"67.5",r:"36.5"}),e.jsx("circle",{fill:"#221F1F",cx:"90",cy:"72",r:"31"}),e.jsx("ellipse",{fill:"#FFFFFF",transform:"rotate(-65.83 102.18 60.77)",cx:"102.18",cy:"60.77",rx:"9.57",ry:"6.21"})]}),Wt=({size:s=28})=>e.jsx("svg",{width:s,height:s,viewBox:"0 0 49.8 56",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{fill:"#6C63FF",d:"M17.4,45.5v5c0,1-1.1,1.7-2.1,1.1L13,50.1l-0.6-0.3c0,0-3.2-1.9-10.2-5.9l-0.6-0.3c-0.5-0.3-1-0.8-1.3-1.3C0.2,41.8,0,41.2,0,40.6l0-12.3V15.9c0-0.7,0.2-1.3,0.5-1.8c0.3-0.6,0.8-1,1.3-1.3l10-5.8l0.5-0.3c0.2-0.1,0.2-0.1,0.6-0.3l9.6-5.5l0.6-0.3C23.7,0.1,24.4,0,25.1,0c0.7,0,1.3,0.2,1.7,0.6l10,5.8l0.6,0.3c0,0,3.4,1.9,10.1,5.9l0.6,0.3c0.5,0.3,1,0.8,1.3,1.3c0.3,0.5,0.5,1.1,0.5,1.8l0,11.2c0,1-1.1,1.7-2,1.2l-4.3-2.5c-0.4-0.2-0.7-0.7-0.7-1.2v-6.8L34,12.8c-0.1,0-0.2-0.1-0.7-0.4l-8.4-4.9l-8.7,5c-0.1,0.1-0.1,0.1-0.1,0.1c0,0-0.2,0.1-0.6,0.4L7,17.9v20.7l8.8,5.1c0.1,0,0.2,0.1,0.7,0.4l0.2,0.2l0.1,0.2C17.2,44.7,17.4,45.1,17.4,45.5z M42.8,32.8c0-1,1.1-1.7,2-1.2l4.3,2.5c0.4,0.2,0.7,0.7,0.7,1.2v4.1c0,0.4-0.1,0.7-0.4,0.9l-2,2.1c-0.8,1-1.9,1.4-2.9,0.8l-16-9.3l0,17.5c0.1,0.7-0.2,1.3-0.7,1.7c-0.5,0.4-0.5,0.4-3,2.4C24.4,55.8,24,56,23.5,56c-1.1,0-2-0.9-2-2l0-24.2l-2.7-1.6L17.4,29c-0.1,0,0,0-1.4,0.8c-1,0.6-2.2,0.3-2.7-0.7c-0.1-0.2-0.1-0.2-0.8-1.3l-0.8-1.3c-0.6-1-0.3-2.2,0.7-2.7c0.2-0.1,0.2-0.1,1.3-0.8l3.3-1.9l0.6-0.3c0.6-0.4,1.5-0.5,2.1-0.1l0.7,0.4L42.8,34V32.8z"})}),qt=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"0 0 66.4 65",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{fill:"#3DDC91",d:"M27.7,32.5h-7.8l5.5-16.3h13.4L44.3,0H19.4c-3.6,0-6.7,2.2-7.9,5.6L0.4,38.1c-0.8,2.5-0.4,5.2,1.1,7.3c1.6,2.1,4.1,3.4,6.7,3.4h19.4l5.5-16.3H27.7L27.7,32.5z"}),e.jsx("path",{fill:"#3DDC91",d:"M64.8,19.6c-1.6-2.1-4.1-3.4-6.7-3.4H38.7l-5.5,16.3h13.4L41,48.8H27.7L22.1,65H47c3.6,0,6.7-2.2,7.9-5.6L66,26.9C66.8,24.5,66.4,21.7,64.8,19.6L64.8,19.6z"})]});function Jt({type:s,size:t=28}){switch(s){case"jira":return e.jsx(dl,{size:t});case"slack":return e.jsx(cl,{size:t});case"teams":return e.jsx(xl,{size:t});case"email":return e.jsx(zt,{size:t,className:"text-amber-400"});case"browserstack":return e.jsx(Gt,{size:t});case"lambdatest":return e.jsx(Wt,{size:t});case"saucelabs":return e.jsx(qt,{size:t});default:return e.jsx(Pe,{size:t,className:"text-gray-400"})}}function yt({id:s,size:t=28}){switch(s){case"browserstack":return e.jsx(Gt,{size:t});case"lambdatest":return e.jsx(Wt,{size:t});case"saucelabs":return e.jsx(qt,{size:t});default:return e.jsx(Pe,{size:t,className:"text-gray-400"})}}const Qt=[{type:"jira",name:"JIRA",desc:"Connect to Atlassian JIRA for issue tracking, defect sync, and story import",color:"blue",category:"integration"},{type:"email",name:"Email (SMTP)",desc:"Send test reports, failure alerts, and scheduled digests via email",color:"amber",category:"notification"},{type:"slack",name:"Slack",desc:"Post test results and alerts to Slack channels via webhooks",color:"purple",category:"notification"},{type:"teams",name:"MS Teams",desc:"Send notifications and test reports to Microsoft Teams channels",color:"indigo",category:"notification"}],ml=["teams"],_e=[{id:"browserstack",name:"BrowserStack",desc:"Run tests on real devices and browsers in the BrowserStack cloud grid",color:"orange"},{id:"lambdatest",name:"LambdaTest",desc:"Cross-browser testing on the LambdaTest cloud platform",color:"purple"},{id:"saucelabs",name:"Sauce Labs",desc:"Execute tests at scale on the Sauce Labs cloud testing platform",color:"red"}],Fs="••••••••";function Is(s){const t=new Set,a=[];for(const l of(s||"").split(/[,;\s]+/)){const m=l.trim();if(!m||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m))continue;const i=m.toLowerCase();t.has(i)||(t.add(i),a.push(m))}return a}const ul=[{id:"run_complete",label:"Test Run Complete",desc:"Every time a test run finishes"},{id:"failure",label:"Test Failure",desc:"Only runs with failed tests"},{id:"cycle_complete",label:"Cycle Complete",desc:"When a test plan cycle finishes running its automation"},{id:"ci_gate",label:"CI Gate Verdict",desc:"When a CI/CD gate passes, fails or errors"},{id:"auto_heal",label:"Auto-Heal Outcome",desc:"When a locator is healed, a fix is ready for review, or a heal is reverted"},{id:"schedule_skipped",label:"Schedule Skipped",desc:"When a scheduled run is skipped because the previous one is still running"},{id:"defect_created",label:"Defect Created",desc:"When a new defect is created"},{id:"defect_status_changed",label:"Defect Status Changed",desc:"When a defect moves between statuses (opened, resolved, closed…)"}],jt=[{id:"gmail",name:"Gmail",host:"smtp.gmail.com",port:587},{id:"outlook",name:"Outlook / Office 365",host:"smtp.office365.com",port:587},{id:"yahoo",name:"Yahoo",host:"smtp.mail.yahoo.com",port:587},{id:"custom",name:"Custom SMTP",host:"",port:587},{id:"testver",name:"Testver mail — included with your plan",host:"",port:0}];function hl({readOnly:s=!1}={}){var be,oe,k,C,q;const t=Je(),{showsMobile:a,showsWeb:l}=ks(),{data:m,isLoading:i}=Ge({queryKey:["connectors"],queryFn:St}),h=n.useMemo(()=>{const T=(m==null?void 0:m.connectors)||[];return Array.isArray(T)?T:[]},[m]),d=Ze({mutationFn:Yr,onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),f=Ze({mutationFn:({id:T,data:H})=>Xr(T,H),onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),g=Ze({mutationFn:Zr,onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),y=Ze({mutationFn:ea,onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),c=Ze({mutationFn:({id:T,data:H})=>sa(T,H)}),[j,p]=n.useState(!1),[u,b]=n.useState(null),[z,M]=n.useState(null),[V,U]=n.useState(null),[O,S]=n.useState(null),[I,w]=n.useState(null),{toast:v}=ge(),x=(T,H="success")=>{v(H,T)},{data:o,refetch:r}=Ge({queryKey:["cloud-providers"],queryFn:At}),E=n.useMemo(()=>(o==null?void 0:o.providers)||[],[o]),[P,B]=n.useState(null),[N,ee]=n.useState({username:"",accessKey:"",region:"us-west-1",defaultBuildName:"",enabled:!0,tunnelEnabled:!1,tunnelName:""}),[K,W]=n.useState(!1),[R,G]=n.useState(!1),[_,A]=n.useState(null),[te,X]=n.useState(!1),[le,$]=n.useState(null),[re,ae]=n.useState(!1),ce=T=>E.some(H=>H.id===T),he=E.filter(T=>T.enabled).length,xe=h.filter(T=>T.status==="connected").length+he;function ye(T){const H=E.find(de=>de.id===T);ee(H?{username:H.username,accessKey:H.accessKey,region:H.region||"us-west-1",defaultBuildName:H.defaultBuildName||"",enabled:H.enabled,tunnelEnabled:!!H.tunnelEnabled,tunnelName:H.tunnelName||""}:{username:"",accessKey:"",region:"us-west-1",defaultBuildName:"",enabled:!0,tunnelEnabled:!1,tunnelName:""}),A(null),X(!1),B(T)}async function Ne(){var T;if(!(!P||!N.username)&&!(!N.accessKey||N.accessKey===Fs&&!ce(P))){G(!0);try{await aa({id:P,enabled:N.enabled,username:N.username,accessKey:N.accessKey,region:P==="saucelabs"?N.region:void 0,defaultBuildName:N.defaultBuildName||void 0,tunnelEnabled:!!N.tunnelEnabled,tunnelName:N.tunnelName||""}),x(`${((T=_e.find(H=>H.id===P))==null?void 0:T.name)||"Provider"} saved`),B(null),r()}catch(H){x(`Save failed: ${(H==null?void 0:H.message)||H}`,"error")}finally{G(!1)}}}async function ke(){if(!(!P||!N.username)){W(!0),A(null);try{const T=await ra({id:P,username:N.username,accessKey:N.accessKey,region:P==="saucelabs"?N.region:void 0});A({ok:T.connected,msg:T.message+(T.details?` (${T.details})`:"")})}catch(T){A({ok:!1,msg:String(T)})}finally{W(!1)}}}async function F(T){var H;try{await na(T),x(`${((H=_e.find(de=>de.id===T))==null?void 0:H.name)||"Provider"} removed`),$(null),r()}catch(de){x(`Delete failed: ${(de==null?void 0:de.message)||de}`,"error")}}function Q(T){M(T),b(null),U(null),S(null),p(!0)}function se(T){M(T.type),b(T),U(null),S(null),p(!0)}function ie(T){g.mutate(T,{onSuccess:()=>{w(null),x("Connector deleted")}})}return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5",children:[e.jsx(Pe,{size:16,className:"text-brand-300"}),"Connectors",e.jsxs("span",{className:"text-xs font-normal bg-brand-500/15 text-brand-300 px-2 py-0.5 rounded-full",children:[xe," connected"]})]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Connect Testver to external tools and services"})]}),s&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{children:"View only — connectors are managed by your admin. You can see what's configured but not add, edit, test, or remove them."}),e.jsxs("p",{children:["The ",e.jsx("span",{className:"font-medium",children:"Local Browser"})," and"," ",e.jsx("span",{className:"font-medium",children:"Local Mobile Devices"})," connectors below are yours to connect and use."]})]})]}),e.jsxs("div",{children:[e.jsxs("fieldset",{disabled:s,className:"min-w-0 border-0 p-0 m-0",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Connectors"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:Qt.filter(T=>!ml.includes(T.type)).map(T=>{var Ye,Xe,L,D;const H=h.find(Y=>Y.type===T.type),de=(H==null?void 0:H.status)==="connected",Be=(H==null?void 0:H.status)==="error";return e.jsxs("div",{className:`bg-surface-1 rounded-xl border p-5 transition-all group flex flex-col ${de?"border-emerald-500/30":Be?"border-red-500/30":"border-gray-200 dark:border-white/5 hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{type:T.type,size:28}),e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200",children:T.name})]}),de&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-emerald-400 bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-500/20",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]}),Be&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-400 bg-red-500/10 px-2 py-0.5 rounded-full border border-red-500/20",children:[e.jsx(Se,{className:"w-3 h-3"})," Error"]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1 line-clamp-2",children:T.desc}),H&&e.jsxs("p",{className:"text-[10px] text-gray-500 mb-3 truncate",children:[T.type==="email"&&((Ye=H.config)==null?void 0:Ye.email),T.type==="jira"&&((Xe=H.config)==null?void 0:Xe.baseUrl),T.type==="slack"&&(((L=H.config)==null?void 0:L.channel)||"Webhook configured"),T.type==="teams"&&(((D=H.config)==null?void 0:D.channelName)||"Webhook configured"),H.last_used&&` · Last used: ${Ct(H.last_used)}`]}),!H&&e.jsx("div",{className:"flex-1"}),H?e.jsxs("div",{className:"flex items-center gap-2 pt-3 border-t border-gray-100 dark:border-white/5",children:[e.jsxs("button",{onClick:()=>se(H),className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-white/[0.04] hover:bg-gray-100 dark:hover:bg-white/[0.08] rounded-lg transition-colors",children:[e.jsx(as,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400"})," Settings"]}),e.jsx("button",{onClick:()=>{y.mutate(H.id,{onSuccess:Y=>x(Y.success?"Connection successful!":`Failed: ${Y.error}`,Y.success?"success":"error")})},disabled:y.isPending,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-white/[0.04] hover:bg-gray-100 dark:hover:bg-white/[0.08] rounded-lg transition-colors disabled:opacity-50",title:"Test Connection",children:y.isPending?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($e,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400"})}),e.jsx("button",{onClick:()=>w(H.id),className:"flex items-center justify-center px-3 py-2 text-xs text-gray-400 dark:text-gray-500 hover:text-red-500 dark:hover:text-red-400 bg-gray-50 dark:bg-white/[0.04] hover:bg-red-50 dark:hover:bg-red-500/10 rounded-lg transition-colors",title:"Remove",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]}):e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("button",{onClick:()=>Q(T.type),className:"w-full flex items-center justify-center gap-2 px-3 py-2.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors shadow-sm",children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Configure"]})})]},T.type)})}),e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Cloud Testing Providers"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[_e.map(T=>{const H=ce(T.id),de=E.find(Be=>Be.id===T.id);return e.jsxs("div",{className:`bg-surface-1 rounded-xl border p-5 transition-all group flex flex-col ${H?"border-emerald-200 dark:border-emerald-500/20":"border-gray-200 dark:border-white/5 hover:border-brand-300 dark:hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"text-2xl",children:e.jsx(yt,{id:T.id,size:28})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200",children:T.name})}),H&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-200 dark:border-emerald-500/20 shrink-0",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4 line-clamp-2 flex-1",children:T.desc}),H?e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:[e.jsxs("div",{className:"text-xs text-gray-500 mb-2",children:[e.jsx("span",{className:"text-gray-400",children:"User:"})," ",de==null?void 0:de.username]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>ye(T.id),className:"flex-1 flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-500/10 hover:bg-brand-100 dark:hover:bg-brand-500/20 rounded-lg transition-colors border border-brand-200 dark:border-brand-500/20",children:[e.jsx(as,{className:"w-3.5 h-3.5"})," Edit"]}),e.jsx("button",{onClick:()=>$(T.id),className:"flex items-center justify-center px-3 py-2 text-xs text-gray-400 dark:text-gray-500 hover:text-red-500 dark:hover:text-red-400 bg-gray-50 dark:bg-white/[0.04] hover:bg-red-50 dark:hover:bg-red-500/10 rounded-lg transition-colors",title:"Remove",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]})]}):e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("button",{onClick:()=>ye(T.id),className:"w-full flex items-center justify-center gap-2 px-3 py-2.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors shadow-sm",children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Configure"]})})]},T.id)}),(()=>{const T=E.find(de=>de.id==="testver-grid"),H=!!T;return e.jsxs("div",{className:`bg-surface-1 rounded-xl border p-5 transition-all group flex flex-col ${H?"border-emerald-200 dark:border-emerald-500/20":"border-gray-200 dark:border-white/5 hover:border-brand-300 dark:hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"w-7 h-7 rounded-lg bg-emerald-100 dark:bg-emerald-500/15 flex items-center justify-center",children:e.jsx(Ee,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200 flex items-center gap-2",children:"Testver Grid"})}),H&&(T==null?void 0:T.enabled)&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-200 dark:border-emerald-500/20 shrink-0",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4 line-clamp-2 flex-1",children:"Testver's own cloud browsers — Chromium, Firefox and WebKit. No vendor account needed"}),e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>ae(!0),className:H?"flex-1 flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-500/10 hover:bg-brand-100 dark:hover:bg-brand-500/20 rounded-lg transition-colors border border-brand-200 dark:border-brand-500/20":"w-full flex items-center justify-center gap-2 px-3 py-2.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors shadow-sm",children:H?e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-3.5 h-3.5"})," Manage"]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Connect"]})}),H&&e.jsx("button",{onClick:()=>$("testver-grid"),className:"flex items-center justify-center px-3 py-2 text-xs text-gray-400 dark:text-gray-500 hover:text-red-500 dark:hover:text-red-400 bg-gray-50 dark:bg-white/[0.04] hover:bg-red-50 dark:hover:bg-red-500/10 rounded-lg transition-colors",title:"Remove",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]})})]})})()]})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Browser Execution"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:e.jsx(Zn,{})})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Local Mobile Devices"}),e.jsx("div",{className:"mb-8",children:e.jsx(tl,{})})]}),i&&e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"w-6 h-6 text-brand-400 animate-spin"})})]}),j&&z&&e.jsx(pl,{type:z,connector:u,onSave:async T=>{u?(await f.mutateAsync({id:u.id,data:T}),x("Connector updated")):(await d.mutateAsync(T),x("Connector created")),p(!1)},onTest:async T=>{const H=await y.mutateAsync(T);return U(H),H},onSendTest:async(T,H)=>{const de=await c.mutateAsync({id:T,data:H});return S(de),de},testResult:V,sendResult:O,onClose:()=>{p(!1),b(null),U(null),S(null)},saving:d.isPending||f.isPending,testing:y.isPending,sending:c.isPending}),I&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>w(null)}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-white/5",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx(ue,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-100",children:"Delete Connector"})]}),e.jsx("div",{className:"px-6 py-4",children:e.jsx("p",{className:"text-sm text-gray-300",children:"Are you sure you want to delete this connector? Notifications will no longer be sent through it."})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-white/5",children:[e.jsx("button",{onClick:()=>w(null),className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsx("button",{onClick:()=>ie(I),className:"px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-500 rounded-lg",children:"Delete"})]})]})]}),document.body),re&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>{ae(!1),r()}}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 sticky top-0 bg-surface-1 z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-7 h-7 rounded-lg bg-emerald-100 dark:bg-emerald-500/15 flex items-center justify-center",children:e.jsx(Ee,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400"})}),e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"Testver Grid"})]}),e.jsx("button",{onClick:()=>{ae(!1),r()},className:"text-gray-400 hover:text-gray-200",children:e.jsx(me,{size:20})})]}),e.jsx("div",{className:"p-6",children:e.jsx(il,{onChanged:()=>r()})})]})]}),document.body),P&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>B(null)}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 sticky top-0 bg-surface-1 z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:e.jsx(yt,{id:P,size:28})}),e.jsxs("h2",{className:"text-base font-semibold text-gray-100",children:[ce(P)?"Edit":"Configure"," ",(be=_e.find(T=>T.id===P))==null?void 0:be.name]})]}),e.jsx("button",{onClick:()=>B(null),className:"text-gray-400 hover:text-gray-200",children:e.jsx(me,{size:20})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N.enabled,onChange:T=>ee({...N,enabled:T.target.checked}),className:"rounded border-gray-600 bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Enable ",(oe=_e.find(T=>T.id===P))==null?void 0:oe.name]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Username"}),e.jsx("input",{value:N.username,onChange:T=>ee({...N,username:T.target.value}),placeholder:"Username",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Access Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:te?"text":"password",value:N.accessKey,onChange:T=>ee({...N,accessKey:T.target.value}),onFocus:()=>{N.accessKey===Fs&&ee({...N,accessKey:""})},onBlur:()=>{!N.accessKey&&ce(P)&&ee({...N,accessKey:Fs})},placeholder:"Access key / API token",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 pr-10 text-gray-200 text-sm font-mono focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsx("button",{onClick:()=>X(!te),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:te?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]}),((k=E.find(T=>T.id===P))==null?void 0:k.accessKeyProblem)&&e.jsx("p",{className:"text-xs text-amber-400 mt-1.5",children:(C=E.find(T=>T.id===P))==null?void 0:C.accessKeyProblem})]}),P==="saucelabs"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Region"}),e.jsxs("select",{value:N.region,onChange:T=>ee({...N,region:T.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500",children:[e.jsx("option",{value:"us-west-1",children:"US West"}),e.jsx("option",{value:"eu-central-1",children:"EU Central"}),e.jsx("option",{value:"us-east-4",children:"US East"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Default Build Name (optional)"}),e.jsx("input",{value:N.defaultBuildName,onChange:T=>ee({...N,defaultBuildName:T.target.value}),placeholder:"e.g., testver-{date}",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!!N.tunnelEnabled,onChange:T=>ee({...N,tunnelEnabled:T.target.checked}),className:"rounded border-gray-600 bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Local tunnel"]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1 ml-6",children:["For apps on localhost or a private network. Web sessions use your running ",P==="browserstack"?"BrowserStack Local":P==="saucelabs"?"Sauce Connect":"LambdaTest Tunnel"," — start it before the run.",P==="browserstack"?" Runs through a BrowserStack SDK start it themselves.":""]}),N.tunnelEnabled&&e.jsx("input",{value:N.tunnelName,onChange:T=>ee({...N,tunnelName:T.target.value}),placeholder:"Tunnel name (optional)",className:"mt-2 w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),_&&e.jsxs("div",{className:`flex items-center gap-2 text-sm px-4 py-2.5 rounded-lg ${_.ok?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,children:[_.ok?e.jsx(ne,{size:16}):e.jsx(Se,{size:16}),_.msg]})]}),e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-white/5 sticky bottom-0 bg-surface-1",children:[e.jsxs("button",{onClick:ke,disabled:K||!N.username||!N.accessKey&&!ce(P),className:"flex items-center gap-1.5 px-3 py-2 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[K?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($e,{className:"w-3.5 h-3.5"}),"Test Connection"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>B(null),className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsxs("button",{onClick:Ne,disabled:R||!N.username||!N.accessKey&&!ce(P),className:"flex items-center gap-2 px-5 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg disabled:opacity-40 transition-colors",children:[R?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(ne,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),document.body),le&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>$(null)}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-white/5",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx(ue,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-100",children:"Remove Cloud Provider"})]}),e.jsx("div",{className:"px-6 py-4",children:e.jsxs("p",{className:"text-sm text-gray-300",children:["Are you sure you want to remove ",((q=_e.find(T=>T.id===le))==null?void 0:q.name)||"Testver Grid","? Saved credentials will be deleted."]})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-white/5",children:[e.jsx("button",{onClick:()=>$(null),className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsx("button",{onClick:()=>F(le),className:"px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-500 rounded-lg",children:"Remove"})]})]})]}),document.body)]})}function pl({type:s,connector:t,onSave:a,onTest:l,onSendTest:m,testResult:i,sendResult:h,onClose:d,saving:f,testing:g,sending:y}){var R,G,_;const c=Qt.find(A=>A.type===s),[j,p]=n.useState((t==null?void 0:t.name)||`${c.name} Connection`),[u,b]=n.useState((t==null?void 0:t.config)||N(s)),[z,M]=n.useState((t==null?void 0:t.notify_on)||["run_complete","failure"]),[V,U]=n.useState(Array.isArray((R=t==null?void 0:t.config)==null?void 0:R.notifyEmails)?t.config.notifyEmails.join(", "):((G=t==null?void 0:t.config)==null?void 0:G.notifyEmails)||""),[O,S]=n.useState(!1),[I,w]=n.useState(""),[v,x]=n.useState((t==null?void 0:t.id)||null),{data:o}=ta({enabled:s==="email"}),r=o==null?void 0:o.services.mail,E=!!(o!=null&&o.connected)&&!!r&&(r.on||r.providedBy==="system")&&!o.memberOnly,{hasRole:P}=ws(),B=P("admin");function N(A){switch(A){case"email":return{provider:"gmail",host:"smtp.gmail.com",port:587,secure:!1,email:"",password:"",fromName:"Testver"};case"slack":return{webhookUrl:"",channel:"",botName:"Testver"};case"teams":return{webhookUrl:"",channelName:""};case"jira":return{baseUrl:"",email:"",apiToken:"",defaultProject:""};default:return{}}}const ee=A=>{if(A==="testver"){b(X=>{var le,$;return{...X,provider:A,host:"",port:0,secure:!1,password:"",email:(r==null?void 0:r.replyTo)??X.email??"",sender:(r==null?void 0:r.fromAddress)??"tool@testver.com",fromName:X.fromName||(((le=o==null?void 0:o.own.subject)==null?void 0:le.name)??(($=o==null?void 0:o.own.account)==null?void 0:$.name)??"")}});return}const te=jt.find(X=>X.id===A);b(X=>({...X,provider:A,host:(te==null?void 0:te.host)||X.host,port:(te==null?void 0:te.port)||X.port}))},K=async()=>{const A=s==="email"?{...u,notifyEmails:Is(V)}:u,te={type:s,name:j,config:A,notifyOn:z};t||(te.createdBy="admin"),await a(te)},W=v!=null;return fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:d}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-2xl mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 sticky top-0 bg-surface-1 z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{type:s,size:24}),e.jsxs("h2",{className:"text-base font-semibold text-gray-100",children:[t?"Edit":"Configure"," ",c.name]})]}),e.jsx("button",{onClick:d,className:"text-gray-400 hover:text-gray-200",children:e.jsx(me,{size:20})})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Connection Name"}),e.jsx("input",{type:"text",value:j,onChange:A=>p(A.target.value),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),s==="email"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Provider"}),e.jsx("select",{value:u.provider,onChange:A=>ee(A.target.value),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500",children:jt.map(A=>e.jsx("option",{value:A.id,disabled:A.id==="testver"&&!E&&u.provider!=="testver",children:A.name},A.id))})]}),u.provider==="testver"&&!E&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-amber-500/[0.07] border border-amber-500/25 rounded-lg px-3.5 py-2.5 text-xs text-amber-200",children:[e.jsx(Ps,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsxs("span",{children:[o!=null&&o.connected?o.memberOnly?"Testver mail is managed by your team owner on the team's Testver installation — ":(_=r==null?void 0:r.reason)!=null&&_.message?`${r.reason.message} — `:"Testver mail is switched off — ":"Connect to Testver to use Testver mail — ",e.jsx(os,{to:"/testver",className:"underline underline-offset-2 hover:text-amber-100",children:"open Testver → Connections"}),"."]})]}),u.provider==="testver"&&E&&e.jsx("p",{className:"text-xs text-gray-500",children:"No SMTP host, port or password. Mail goes through Testver's own server; your Gmail, Outlook and custom SMTP connections stay as they are."}),u.provider==="testver"?e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Sends as"}),e.jsx("input",{type:"text",readOnly:!0,value:u.sender||(r==null?void 0:r.fromAddress)||"tool@testver.com",className:"w-full bg-surface-2 border border-dashed border-white/10 rounded-lg px-3 py-2 text-gray-400 text-sm font-mono"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["Replies go to",B&&e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:"(editable by admins)"})]}),B?e.jsx("input",{type:"email",value:u.email??"",placeholder:(r==null?void 0:r.replyTo)||"you@company.com",onChange:A=>b({...u,email:A.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm font-mono placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"}):e.jsx("input",{type:"text",readOnly:!0,value:u.email||(r==null?void 0:r.replyTo)||"",className:"w-full bg-surface-2 border border-dashed border-white/10 rounded-lg px-3 py-2 text-gray-400 text-sm font-mono"})]})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"SMTP Host"}),e.jsx("input",{type:"text",value:u.host,onChange:A=>b({...u,host:A.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Port"}),e.jsx("input",{type:"number",value:u.port,onChange:A=>b({...u,port:parseInt(A.target.value)||587}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]}),u.provider!=="testver"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Email Address"}),e.jsx("input",{type:"email",value:u.email,onChange:A=>b({...u,email:A.target.value}),placeholder:"user@gmail.com",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["Password / App Password",u.provider==="gmail"&&e.jsx("span",{className:"text-xs text-amber-400 ml-2",children:"(Use Gmail App Password)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:O?"text":"password",value:u.password,onChange:A=>b({...u,password:A.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 pr-10 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsx("button",{onClick:()=>S(!O),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:O?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"From Name"}),e.jsx("input",{type:"text",value:u.fromName||"",onChange:A=>b({...u,fromName:A.target.value}),placeholder:"Testver Notifications",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["Notify these addresses",e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:"(team notifications — comma-separated)"})]}),e.jsx("textarea",{rows:2,value:V,onChange:A=>U(A.target.value),onBlur:()=>b({...u,notifyEmails:Is(V)}),placeholder:"qa-team@company.com, lead@company.com",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm font-mono placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500 resize-y"}),e.jsxs("p",{className:"mt-1 text-[11px] text-gray-500",children:["Run, cycle, CI gate, auto-heal, schedule and defect broadcasts go here.",Is(V).length===0&&e.jsxs(e.Fragment,{children:[" Leave empty to send them to ",u.provider==="testver"?'the "Replies go to" address':"the sender address"," above."]})," ","Personal emails (welcome, password, assigned defects) always go to the user concerned."]})]})]}),s==="slack"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-purple-500/5 border border-purple-500/10 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ps,{className:"w-4 h-4 text-purple-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-gray-400",children:[e.jsx("p",{className:"font-medium text-purple-300 mb-1",children:"How to get Webhook URL:"}),e.jsxs("ol",{className:"list-decimal ml-4 space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("span",{className:"text-purple-300",children:"api.slack.com/apps"})," → Create New App"]}),e.jsxs("li",{children:["Enable ",e.jsx("span",{className:"text-purple-300",children:"Incoming Webhooks"})]}),e.jsx("li",{children:"Add to your channel → Copy webhook URL"})]})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Webhook URL"}),e.jsx("input",{type:"text",value:u.webhookUrl,onChange:A=>b({...u,webhookUrl:A.target.value}),placeholder:"https://hooks.slack.com/services/T.../B.../xxx",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Channel (display only)"}),e.jsx("input",{type:"text",value:u.channel||"",onChange:A=>b({...u,channel:A.target.value}),placeholder:"#qa-alerts",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Bot Name"}),e.jsx("input",{type:"text",value:u.botName||"",onChange:A=>b({...u,botName:A.target.value}),placeholder:"Testver",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]})]}),s==="teams"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-indigo-500/5 border border-indigo-500/10 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ps,{className:"w-4 h-4 text-indigo-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-gray-400",children:[e.jsx("p",{className:"font-medium text-indigo-300 mb-1",children:"How to get Webhook URL:"}),e.jsxs("ol",{className:"list-decimal ml-4 space-y-0.5",children:[e.jsxs("li",{children:["In Teams Channel → ",e.jsx("span",{className:"text-indigo-300",children:"⋯"})," → Connectors (or Workflows)"]}),e.jsxs("li",{children:["Search ",e.jsx("span",{className:"text-indigo-300",children:"Incoming Webhook"})," → Configure"]}),e.jsx("li",{children:'Name it "Testver" → Create → Copy URL'})]})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Webhook URL"}),e.jsx("input",{type:"text",value:u.webhookUrl,onChange:A=>b({...u,webhookUrl:A.target.value}),placeholder:"https://outlook.office.com/webhook/...",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Channel Name (display only)"}),e.jsx("input",{type:"text",value:u.channelName||"",onChange:A=>b({...u,channelName:A.target.value}),placeholder:"QA Notifications",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]}),s==="jira"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"JIRA Cloud URL"}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:A=>b({...u,baseUrl:A.target.value}),placeholder:"https://yourcompany.atlassian.net",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Email (Atlassian Account)"}),e.jsx("input",{type:"email",value:u.email,onChange:A=>b({...u,email:A.target.value}),placeholder:"user@company.com",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["API Token ",e.jsxs("a",{href:"https://id.atlassian.com/manage-profile/security/api-tokens",target:"_blank",className:"text-brand-400 hover:text-brand-300 ml-1 inline-flex items-center gap-0.5",children:[e.jsx(Ss,{size:10})," Generate"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:O?"text":"password",value:u.apiToken,onChange:A=>b({...u,apiToken:A.target.value}),placeholder:"ATATT3xFf...",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 pr-10 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsx("button",{onClick:()=>S(!O),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:O?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Default Project Key"}),e.jsx("input",{type:"text",value:u.defaultProject||"",onChange:A=>b({...u,defaultProject:A.target.value}),placeholder:"PROJ",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]}),s!=="jira"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-2",children:"Notify On"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ul.map(A=>e.jsxs("label",{className:`flex items-center gap-2 p-3 rounded-lg border cursor-pointer transition-colors ${z.includes(A.id)?"bg-brand-500/10 border-brand-500/30":"bg-surface-2 border-white/5 hover:border-white/10"}`,children:[e.jsx("input",{type:"checkbox",checked:z.includes(A.id),onChange:te=>M(X=>te.target.checked?[...X,A.id]:X.filter(le=>le!==A.id)),className:"sr-only"}),e.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center ${z.includes(A.id)?"bg-brand-500 border-brand-500":"border-gray-600"}`,children:z.includes(A.id)&&e.jsx(ne,{className:"w-3 h-3 text-white"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-gray-200",children:A.label}),e.jsx("div",{className:"text-[10px] text-gray-500",children:A.desc})]})]},A.id))})]}),i&&e.jsx("div",{className:`p-3 rounded-lg border ${i.success?"bg-emerald-500/5 border-emerald-500/20":"bg-red-500/5 border-red-500/20"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[i.success?e.jsx(ne,{className:"w-4 h-4 text-emerald-400"}):e.jsx(Se,{className:"w-4 h-4 text-red-400"}),e.jsx("span",{className:`text-sm font-medium ${i.success?"text-emerald-400":"text-red-400"}`,children:i.success?`Connection successful${i.user?` — ${i.user}`:""}`:`Failed: ${i.error}`})]})}),h&&e.jsx("div",{className:`p-3 rounded-lg border ${h.success?"bg-emerald-500/5 border-emerald-500/20":"bg-red-500/5 border-red-500/20"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[h.success?e.jsx(ne,{className:"w-4 h-4 text-emerald-400"}):e.jsx(Se,{className:"w-4 h-4 text-red-400"}),e.jsx("span",{className:`text-sm ${h.success?"text-emerald-400":"text-red-400"}`,children:h.success?"Test notification sent successfully!":`Send failed: ${h.error}`})]})})]}),e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-white/5 sticky bottom-0 bg-surface-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:W&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>l(v),disabled:g,className:"flex items-center gap-1.5 px-3 py-2 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[g?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($e,{className:"w-3.5 h-3.5"}),"Test Connection"]}),s==="email"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"email",value:I,onChange:A=>w(A.target.value),placeholder:"Send test to...",className:"bg-surface-2 border border-white/10 rounded-lg px-2 py-1.5 text-gray-200 text-xs w-40 focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsxs("button",{onClick:()=>I&&m(v,{to:I}),disabled:y||!I,className:"flex items-center gap-1 px-2 py-1.5 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[y?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(_s,{className:"w-3 h-3"})," Send"]})]}),(s==="slack"||s==="teams")&&e.jsxs("button",{onClick:()=>m(v),disabled:y,className:"flex items-center gap-1.5 px-3 py-2 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[y?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(_s,{className:"w-3.5 h-3.5"}),"Send Test Message"]})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:d,className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsxs("button",{onClick:K,disabled:f||!j.trim(),className:"flex items-center gap-2 px-5 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg disabled:opacity-40 transition-colors",children:[f?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(ne,{className:"w-4 h-4"}),t?"Update":"Save"]})]})]})]})]}),document.body)}const gl=["Dev","QA","Staging","Prod"];function bl(s){return s<1024*1024?`${(s/1024).toFixed(0)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function fl({readOnly:s=!1}){const{toast:t}=ge(),a=Je(),{data:l,isLoading:m}=Ge({queryKey:["mobile-apps"],queryFn:la}),i=(l==null?void 0:l.apps)??[],h=n.useRef(null),[d,f]=n.useState(""),[g,y]=n.useState(null),[c,j]=n.useState(null),[p,u]=n.useState(""),[b,z]=n.useState(null),{android:M,ios:V}=n.useMemo(()=>({android:i.filter(x=>x.kind==="apk"),ios:i.filter(x=>x.kind==="ipa")}),[i]),U=()=>void a.invalidateQueries({queryKey:["mobile-apps"]}),O=async x=>{y(0);try{await oa(x,d.trim()||void 0,o=>y(o)),t("success",`Uploaded ${x.name}`),f(""),U()}catch(o){t("error",o.message)}finally{y(null),h.current&&(h.current.value="")}},S=async x=>{const o=p.trim();if(j(null),!!o)try{await da(x,o),U()}catch(r){t("error",r.message)}},I=async()=>{if(!b)return;const x=b;z(null);try{await ia(x.id),t("success",`Removed ${x.label||x.filename}`),U()}catch(o){t("error",o.message)}},w=({app:x})=>e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg hover:bg-black/[0.03] dark:hover:bg-white/[0.03] group",children:[x.kind==="ipa"?e.jsx(rn,{size:14,className:"text-gray-400 flex-shrink-0"}):e.jsx(Oe,{size:14,className:"text-emerald-500 flex-shrink-0"}),c===x.id?e.jsxs("span",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[e.jsx("input",{autoFocus:!0,value:p,onChange:o=>u(o.target.value),onKeyDown:o=>{o.key==="Enter"&&S(x.id),o.key==="Escape"&&j(null)},className:"flex-1 min-w-0 bg-surface-2 border border-brand-500/40 rounded-lg px-2.5 py-1 text-sm text-gray-200 outline-none",maxLength:60}),e.jsx("button",{onClick:()=>void S(x.id),className:"p-1 text-emerald-500 hover:bg-emerald-500/10 rounded",title:"Save name",children:e.jsx(Ue,{size:14})}),e.jsx("button",{onClick:()=>j(null),className:"p-1 text-gray-500 hover:bg-white/5 rounded",title:"Cancel",children:e.jsx(me,{size:14})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-gray-200 font-medium truncate",children:x.label||x.filename}),e.jsxs("span",{className:"text-xs text-gray-500 font-mono truncate flex-1 min-w-0",title:x.filename,children:[x.filename," · ",bl(x.size)]}),!s&&e.jsxs("span",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:[e.jsx("button",{onClick:()=>{j(x.id),u(x.label||"")},className:"p-1.5 rounded text-gray-500 hover:text-brand-400 hover:bg-white/5",title:"Rename (e.g. Dev, QA, Prod)",children:e.jsx(Cs,{size:13})}),e.jsx("button",{onClick:()=>z(x),className:"p-1.5 rounded text-gray-500 hover:text-red-400 hover:bg-red-500/10",title:"Delete build",children:e.jsx(we,{size:13})})]})]})]}),v=({title:x,list:o})=>e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-gray-500 mb-1.5",children:x}),o.length===0?e.jsx("div",{className:"text-xs text-gray-600 px-3 py-1.5",children:"No builds uploaded yet."}):e.jsx("div",{className:"space-y-0.5",children:o.map(r=>e.jsx(w,{app:r},r.id))})]});return e.jsxs("div",{className:"rounded-xl border border-white/5 bg-black/20 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-gray-200",children:[e.jsx(tn,{size:15,className:"text-brand-400"})," App Builds"]}),e.jsx("p",{className:"text-xs text-gray-500 -mt-1",children:"Upload app binaries and name them by environment — builds uploaded here appear in every device/app picker (Runner, AI Assistant). Deduplicated by content, so re-uploading the same binary never stores a second copy."}),!s&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:d,onChange:x=>f(x.target.value),placeholder:"Name for the next upload (e.g. QA)",maxLength:60,className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50"}),e.jsxs("button",{onClick:()=>{var x;return(x=h.current)==null?void 0:x.click()},disabled:g!==null,className:"inline-flex items-center gap-1.5 px-3.5 py-2.5 text-sm rounded-lg bg-brand-600 hover:bg-brand-500 text-white disabled:opacity-50 transition-colors flex-shrink-0",children:[g!==null?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(bs,{size:14}),g!==null?`${Math.round(g*100)}%`:"Upload build"]}),e.jsx("input",{ref:h,type:"file",accept:".apk,.aab,.ipa,.zip",className:"hidden",onChange:x=>{var r;const o=(r=x.target.files)==null?void 0:r[0];o&&O(o)}})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[gl.map(x=>e.jsx("button",{onClick:()=>f(x),className:`px-2.5 py-1 rounded-full text-xs border transition-colors ${d===x?"border-brand-500/50 bg-brand-500/10 text-brand-400":"border-white/10 text-gray-500 hover:text-gray-300 hover:border-white/20"}`,children:x},x)),e.jsx("span",{className:"text-xs text-gray-600 ml-1",children:"Android: .apk / .aab · iOS: .ipa (cloud) / zipped .app (local simulator)"})]})]}),m?e.jsxs("div",{className:"text-xs text-gray-600 flex items-center gap-1.5",children:[e.jsx(J,{size:12,className:"animate-spin"})," Loading builds…"]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{title:"Android",list:M}),e.jsx(v,{title:"iOS",list:V})]}),e.jsx(Ot,{open:b!==null,title:"Delete app build?",description:b?`"${b.label||b.filename}" (${b.filename}) will be removed from the library and its binary deleted from disk. Runner and AI Assistant pickers will no longer offer it; cloud copies already uploaded to a provider are not affected.`:"",confirmLabel:"Delete build",onConfirm:()=>void I(),onCancel:()=>z(null)})]})}const ps=()=>({username:"",accessKey:"",region:"us-west-1",hubUrl:"",defaultBuildName:"",enabled:!0});function yl({readOnly:s,fallback:t}){const{toast:a}=ge(),{name:l,maxLength:m,isLoading:i}=pa(),h=ga(),[d,f]=n.useState(!1),[g,y]=n.useState(""),c=()=>{y(l??""),f(!0)},j=()=>{f(!1),y("")},p=async()=>{const u=g.trim();if(!u){a("error","Enter a project name");return}if(u===l){j();return}try{await h.mutateAsync(u),a("success","Project name saved"),f(!1)}catch(b){a("error",`Couldn't save the project name: ${b instanceof Error?b.message:b}`)}};return i?e.jsx("span",{className:"text-gray-500",children:"…"}):d&&!s?e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("input",{type:"text",value:g,onChange:u=>y(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),p()),u.key==="Escape"&&(u.preventDefault(),j())},maxLength:m,autoFocus:!0,"aria-label":"Project name",placeholder:"e.g. Customer Portal","data-testid":"project-name-input",className:`flex-1 min-w-0 px-3 py-1.5 bg-surface-2 border border-white/10 rounded-lg text-gray-100 text-sm
|
|
80
|
-
focus:outline-none focus:border-brand-500/50 placeholder-gray-600`}),e.jsxs("button",{type:"button",onClick:()=>void p(),disabled:h.isPending||!g.trim(),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 transition-colors disabled:opacity-50",children:[h.isPending?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ue,{size:12}),"Save"]}),e.jsx("button",{type:"button",onClick:j,disabled:h.isPending,className:"px-3 py-1.5 rounded-lg text-xs font-medium text-gray-300 bg-surface-2 hover:bg-surface-3 border border-white/10 transition-colors",children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l?e.jsx("span",{className:"text-gray-100 font-medium truncate","data-testid":"project-name-value",title:l,children:l}):e.jsxs("span",{className:"text-gray-500 truncate","data-testid":"project-name-value",children:["Not set",t?` — showing "${t}"`:""]}),!s&&e.jsx("button",{type:"button",onClick:c,title:l?"Rename project":"Set a project name","aria-label":l?"Rename project":"Set a project name","data-testid":"project-name-edit",className:"p-1 rounded-md text-gray-500 hover:text-brand-300 hover:bg-white/[0.05] transition-colors flex-shrink-0",children:e.jsx(Cs,{size:13})})]})}function no(){const{project:s}=Zt(),[t,a]=n.useState(ca),{toast:l}=ge(),{hasRole:m}=ws(),i=m("admin"),{mcpEnabled:h}=un(),[d,f]=mt("tab",["general","llm","skills","mcp","connectors","config","browser-sessions"],"general"),{showsWeb:g}=ks();n.useEffect(()=>{!g&&d==="browser-sessions"&&f("general")},[g,d,f]);const[y,c]=n.useState([]);mt("subtab",["browserstack","lambdatest","saucelabs","testver-grid","local-appium"],"browserstack");const[j,p]=n.useState({browserstack:ps(),lambdatest:ps(),saucelabs:ps(),"testver-grid":ps()}),[u,b]=n.useState({}),[z,M]=n.useState({}),[V,U]=n.useState({}),[O,S]=n.useState(!1),I=n.useCallback(async()=>{try{const x=await At();c(x.providers);const o={...j};for(const r of x.providers)o[r.id]={username:r.username,accessKey:r.accessKey,region:r.region||"us-west-1",hubUrl:r.hubUrl||"",defaultBuildName:r.defaultBuildName||"",enabled:r.enabled};p(o)}catch{}},[]);n.useEffect(()=>{I()},[I]);const v=[{id:"general",label:"General",icon:e.jsx(an,{size:16}),description:"Project info & appearance"},{id:"llm",label:"LLM",icon:e.jsx(Ft,{size:16}),description:"AI provider configuration"},{id:"skills",label:"Skills",icon:e.jsx(Ys,{size:16}),description:"Manage Agent Skills"},{id:"mcp",label:"MCP Servers",icon:e.jsx(Pe,{size:16}),description:"Manage MCP servers"},{id:"connectors",label:"Connectors",icon:e.jsx(Dt,{size:16}),description:"JIRA, Slack, Email, cloud grids & webhooks"},{id:"config",label:"Config",icon:e.jsx(vs,{size:16}),description:"Environment and config files"},{id:"browser-sessions",label:"Browser Sessions",icon:e.jsx(Ve,{size:16}),description:"Live browser processes"}].filter(x=>(x.id!=="mcp"||h)&&(x.id!=="browser-sessions"||g));return e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200 animate-fade-in",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-6",children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(as,{size:24,className:"text-brand-300"}),"Settings"]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Configure application settings, LLM providers, and cloud integrations"})]})}),e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 flex gap-1",children:v.map(x=>e.jsxs("button",{onClick:()=>f(x.id),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium border-b-2 transition-colors ${d===x.id?"border-brand-400 text-brand-300":"border-transparent text-gray-400 hover:text-gray-200 hover:border-white/10"}`,children:[er.cloneElement(x.icon,{size:16}),x.label]},x.id))})}),e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8 space-y-6",children:[d==="general"&&e.jsx(Ml,{project:s,theme:t,setTheme:a,readOnly:!i}),d==="llm"&&e.jsx(Kl,{isAdmin:i}),d==="skills"&&e.jsx(En,{readOnly:!i}),d==="mcp"&&h&&e.jsx(Kn,{readOnly:!i}),d==="connectors"&&e.jsx(hl,{readOnly:!i}),d==="config"&&e.jsx(Vn,{embedded:!0}),d==="browser-sessions"&&g&&e.jsx("div",{className:"h-full overflow-auto",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-8 space-y-6",children:e.jsx(Qn,{})})})]})]})}const jl=[{value:"web",label:"Web",Icon:cs,description:"Show only web testing UI",badge:null,selectedClasses:"bg-sky-500/15 border-sky-500/60 ring-1 ring-sky-500/40",selectedIconClasses:"text-sky-700 dark:text-sky-400",selectedLabelClasses:"text-sky-700 dark:text-sky-300"},{value:"mobile",label:"Mobile",Icon:Oe,description:"Show only mobile testing UI",badge:"Beta",selectedClasses:"bg-indigo-500/20 border-indigo-500/70 ring-1 ring-indigo-500/50",selectedIconClasses:"text-indigo-700 dark:text-indigo-400",selectedLabelClasses:"text-indigo-700 dark:text-indigo-300"}];function vl(){const{mode:s,setAt:t,isLoading:a}=ks(),l=va(),{toast:m}=ge(),[i,h]=n.useState(null),d=g=>{g!==s&&h(g)},f=async()=>{if(i)try{await l.mutateAsync(i),m("success",`App mode set to ${i.charAt(0).toUpperCase()+i.slice(1)}`)}catch(g){m("error",`Failed to update app mode: ${g}`)}finally{h(null)}};return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(As,{size:18}),"App Mode"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5",children:"Controls which Testver surfaces are visible across the workspace — Runner, Recorder, Schedules, and AI Assistant pickers all adapt to this setting."})]}),t&&e.jsxs("span",{className:"text-xs text-gray-500 whitespace-nowrap",children:["Last changed ",Ct(t)]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:jl.map(({value:g,label:y,Icon:c,description:j,badge:p,selectedClasses:u,selectedIconClasses:b,selectedLabelClasses:z})=>{const M=s===g;return e.jsxs("button",{type:"button",onClick:()=>d(g),disabled:a||l.isPending,className:`relative flex flex-col items-center justify-center gap-1.5 px-3 py-4 rounded-lg border text-sm transition-all disabled:opacity-50 ${M?u:"bg-white/[0.03] border-white/10 text-gray-400 hover:bg-white/[0.06] hover:border-white/20 hover:text-gray-200"}`,title:j,children:[p&&e.jsx("span",{className:"absolute top-2 right-2 text-[9px] font-bold uppercase tracking-wider px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-400 border border-amber-500/30",children:p}),e.jsx(c,{size:22,className:M?b:""}),e.jsx("span",{className:`font-medium ${M?z:""}`,children:y}),e.jsx("span",{className:"text-[11px] text-gray-500 text-center leading-tight",children:j})]},g)})}),i&&e.jsx(Nl,{currentMode:s,nextMode:i,pending:l.isPending,onCancel:()=>h(null),onConfirm:f})]})}function Nl({currentMode:s,nextMode:t,pending:a,onCancel:l,onConfirm:m}){const i=s?s.charAt(0).toUpperCase()+s.slice(1):"—",h=t.charAt(0).toUpperCase()+t.slice(1),d=t==="mobile"?Oe:cs,f=t==="mobile"?{btn:"bg-indigo-600 hover:bg-indigo-500",icon:"bg-indigo-500/20 text-indigo-700 dark:text-indigo-300"}:{btn:"bg-sky-600 hover:bg-sky-500",icon:"bg-sky-500/20 text-sky-700 dark:text-sky-300"};return fe.createPortal(e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[9999] animate-fade-in p-4",children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/10 w-full max-w-xl p-7",children:[e.jsxs("div",{className:"flex items-center gap-3.5 mb-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-amber-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(ue,{size:22,className:"text-amber-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-200",children:"Change App Mode?"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"This affects the entire workspace"})]})]}),e.jsxs("p",{className:"text-[15px] text-gray-300 mb-4",children:["You're switching from ",e.jsx("span",{className:"font-semibold text-gray-100",children:i})," to",e.jsxs("span",{className:"font-semibold text-gray-100",children:[" ",h]}),"."]}),e.jsxs("div",{className:`flex items-start gap-3 mb-6 p-4 rounded-lg border ${t==="mobile"?"bg-indigo-500/5 border-indigo-500/20":"bg-sky-500/5 border-sky-500/20"}`,children:[e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0 ${f.icon}`,children:e.jsx(d,{size:20})}),e.jsxs("ul",{className:"text-sm text-gray-400 space-y-1.5 leading-relaxed",children:[e.jsxs("li",{children:["• Runner, Recorder, Schedules, and AI Assistant will reload and show only ",e.jsx("span",{className:"text-gray-200 font-medium",children:h})," controls."]}),e.jsxs("li",{children:["• Active recording or test-run sessions tied to ",e.jsx("span",{className:"text-gray-200 font-medium",children:i})," may become unreachable from the UI."]}),e.jsx("li",{children:"• Saved schedules and history remain on disk — they'll reappear if you switch back."})]})]}),e.jsxs("div",{className:"flex justify-end gap-2.5",children:[e.jsx("button",{type:"button",onClick:l,disabled:a,className:"px-5 py-2.5 rounded-lg text-sm text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:m,disabled:a,className:`flex items-center gap-2 px-5 py-2.5 rounded-lg text-sm font-medium text-white transition-colors disabled:opacity-50 ${f.btn}`,children:[a?e.jsx(J,{size:16,className:"animate-spin"}):e.jsx(d,{size:16}),"Switch to ",h]})]})]})}),document.body)}function vt(s){return s.replace(/\{test\}/g,"dummy").replace(/\{suite\}/g,"dummy").replace(/\{line\}/g,"1").replace(/\{args\}/g,"").replace(/\{absFile\}/g,".").replace(/\{posixFile\}/g,".").replace(/\{fileName\}/g,"dummy.spec.ts").replace(/\{fileNoExt\}/g,"dummy.spec").replace(/\{file\}/g,".").replace(/\{project\}/g,".").replace(/\{cwd\}/g,".").replace(/\{root\}/g,".")}const wl=["playwright-test","pytest-playwright"],kl={"playwright-java":"Java","playwright-dotnet":".NET","playwright-python":"Python without pytest-playwright"};function Cl(){const[s,t]=n.useState(null),[a,l]=n.useState(null),{toast:m}=ge();n.useEffect(()=>{nt().then(j=>{t(j),l(j.stacks??[])}).catch(()=>{})},[]);const i=j=>{t(p=>p&&{...p,...j}),ka(j).then(p=>{t(p),m("success",j.capturePassed!==void 0?`Traces for passed tests ${p.capturePassed?"enabled":"disabled"}`:`Trace auto-capture ${p.enabled?"enabled":"disabled"}`)}).catch(p=>{m("error",`Could not save: ${p}`),nt().then(t).catch(()=>{})})},h=(s==null?void 0:s.enabled)??!0,d=(s==null?void 0:s.capturePassed)??!1,f=a??[],g=f.some(j=>wl.includes(j)),y=f.map(j=>kl[j]).filter(Boolean),c=({on:j,onClick:p,disabled:u})=>e.jsx("button",{type:"button",onClick:p,disabled:u,className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors disabled:opacity-40 ${j?"bg-brand-500":"bg-surface-3"}`,"aria-pressed":j,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${j?"translate-x-4":"translate-x-1"}`})});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(on,{size:18}),"API & Network Traces",e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-wider px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-400 border border-brand-500/30",children:"Playwright"})]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:["Records a Playwright trace for your runs so you can inspect every request and response in Results → Open in Trace Viewer → Network. Supported for Playwright tests written in",e.jsx("b",{className:"text-gray-400",children:" TypeScript / JavaScript"})," and ",e.jsx("b",{className:"text-gray-400",children:"Python"})," (with pytest-playwright) — no changes to your test code, and skipped when your command already sets"," ",e.jsx("span",{className:"font-mono text-gray-400",children:"--trace"})," or ",e.jsx("span",{className:"font-mono text-gray-400",children:"--tracing"}),"."]}),a!==null&&f.length===0&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3.5 py-2.5 text-sm text-amber-600 dark:text-amber-300",children:[e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"No Playwright dependency found in this project, so these settings won't affect its runs."})]}),!g&&y.length>0&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3.5 py-2.5 text-sm text-amber-600 dark:text-amber-300",children:[e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:["This project uses Playwright for ",y.join(" and "),", so these settings don't apply. Save the trace from your test code when a test fails, with the test's name in the file name, and Results links it to the test."]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Auto-capture traces"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:["Adds ",e.jsx("span",{className:"font-mono text-gray-400",children:"--trace retain-on-failure"})," (Playwright Test) or ",e.jsx("span",{className:"font-mono text-gray-400",children:"--tracing retain-on-failure"})," (pytest-playwright) — a trace is kept for every ",e.jsx("b",{children:"failed"})," test. On by default."]})]}),e.jsx(c,{on:h,onClick:()=>i({enabled:!h})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Also capture for passed tests"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:["Keep a trace for ",e.jsx("b",{children:"passing"})," tests too (",e.jsx("span",{className:"font-mono text-gray-400",children:"--trace on"})," / ",e.jsx("span",{className:"font-mono text-gray-400",children:"--tracing on"}),"). Useful for auditing green runs, but heavier on disk — leave off unless you need it."]})]}),e.jsx(c,{on:d,onClick:()=>i({capturePassed:!d}),disabled:!h})]})]})}const Sl=[1,2,4,8,12,24,48,72,168],Tl=[1,3,7,14,30,60,90],Nt=s=>s>=24&&s%24===0?`${s/24} day${s===24?"":"s"}`:`${s} hour${s===1?"":"s"}`;function Al(){const[s,t]=n.useState(null),{toast:a}=ge();n.useEffect(()=>{ot().then(t).catch(()=>{})},[]);const l=g=>{t(y=>y&&{...y,...g}),Sa(g).then(y=>{t(y),a("success",g.idleHours!==void 0?`Signed out after ${Nt(y.idleHours)} without activity`:`Sign in again every ${y.maxDays} day${y.maxDays===1?"":"s"}`)}).catch(y=>{a("error",`Could not save: ${y}`),ot().then(t).catch(()=>{})})},m=(s==null?void 0:s.idleHours)??24,i=(s==null?void 0:s.maxDays)??7,h=[...new Set([...Sl,m])].filter(g=>g<=i*24).sort((g,y)=>g-y),d=[...new Set([...Tl,i])].sort((g,y)=>g-y),f="px-3 py-1.5 text-sm bg-surface-2 border border-white/10 rounded-lg text-gray-200 focus:outline-none focus:border-brand-500/50";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(zs,{size:18}),"Sign-in sessions"]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:["A sign-in renews itself while people use Testver — clicking, typing or scrolling counts; a tab left open does not. Everyone gets a warning five minutes before being signed out, with a ",e.jsx("b",{children:"Stay signed in"})," button. Runs keep going on the server either way. Changes apply to everyone, including sessions already signed in."]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Sign out after no activity for"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"How long a sign-in lasts when nobody uses it. Default 1 day."})]}),e.jsx("select",{className:f,value:m,onChange:g=>l({idleHours:Number(g.target.value)}),children:h.map(g=>e.jsx("option",{value:g,children:Nt(g)},g))})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Always sign in again after"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"The longest a sign-in can last, however active. Default 7 days."})]}),e.jsx("select",{className:f,value:i,onChange:g=>l({maxDays:Number(g.target.value)}),children:d.map(g=>e.jsxs("option",{value:g,children:[g," day",g===1?"":"s"]},g))})]})]})}const zl=[7,14,30,60,90];function El(){const{user:s}=ws(),[t,a]=n.useState(null),[l,m]=n.useState(null),{toast:i}=ge();n.useEffect(()=>{it().then(a).catch(()=>{}),ja().then(p=>m(p.enabled)).catch(()=>{})},[]);const h=p=>{a(u=>u&&{...u,...p}),Ta(p).then(u=>{a(u),i("success",p.require!==void 0?u.require==="off"?"Two-factor authentication is optional":`Two-factor authentication required for ${u.require==="admins"?"admins":"everyone"}`:p.allowTrustedBrowsers!==void 0?u.allowTrustedBrowsers?"Browsers can be trusted to skip the code":"Every sign-in asks for a code":`A trusted browser skips the code for ${u.trustedBrowserDays} days`)}).catch(u=>{i("error",`Could not save: ${u}`),it().then(a).catch(()=>{})})},d=(t==null?void 0:t.require)??"off",f=(t==null?void 0:t.allowTrustedBrowsers)??!0,g=(t==null?void 0:t.trustedBrowserDays)??30,y=[...new Set([...zl,g])].sort((p,u)=>p-u),c="px-3 py-1.5 text-sm bg-surface-2 border border-white/10 rounded-lg text-gray-200 focus:outline-none focus:border-brand-500/50 disabled:opacity-40",j=d==="everyone"||d==="admins"&&((s==null?void 0:s.role)==="admin"||(s==null?void 0:s.role)==="superadmin");return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5","data-testid":"two-factor-policy",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Mt,{size:18}),"Two-factor authentication"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:"Sign-in asks for a 6-digit code from an authenticator app as well as the password. Anyone can turn it on in their Profile; here you can require it. People it applies to set it up at their next sign-in, and anyone signed in now is asked to set it up before they can continue. An admin can reset it for someone who lost their phone (Users)."}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Require two-factor authentication for"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[d==="off"?"Nobody is required to — it is optional for everyone.":d==="admins"?"Admins and the super admin must use it; others may.":"Every account must use it.",j&&l===!1&&" This includes you — you will be asked to set it up right away."]})]}),e.jsxs("select",{className:c,value:d,onChange:p=>h({require:p.target.value}),children:[e.jsx("option",{value:"off",children:"Nobody (optional)"}),e.jsx("option",{value:"admins",children:"Admins only"}),e.jsx("option",{value:"everyone",children:"Everyone"})]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Allow “Trust this browser”"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"Lets people skip the code on a browser they trust. Turning this off makes every sign-in ask for a code, including on browsers trusted before."})]}),e.jsx("button",{type:"button",onClick:()=>h({allowTrustedBrowsers:!f}),className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors ${f?"bg-brand-500":"bg-surface-3"}`,"aria-pressed":f,"aria-label":"Allow trusting a browser",children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${f?"translate-x-4":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:`text-sm font-medium ${f?"text-gray-200":"text-gray-500"}`,children:"A trusted browser skips the code for"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"After this, the browser asks for a code again. Default 30 days."})]}),e.jsx("select",{className:c,value:g,disabled:!f,onChange:p=>h({trustedBrowserDays:Number(p.target.value)}),children:y.map(p=>e.jsxs("option",{value:p,children:[p," days"]},p))})]}),e.jsx(Pl,{})]})}function Pl(){const[s,t]=n.useState(null),[a,l]=n.useState(!1);return n.useEffect(()=>{Aa().then(t).catch(()=>{})},[]),!(s!=null&&s.tracked.length)||!s.untrackCommand?null:e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-red-500/10 border border-red-500/20","data-testid":"auth-files-warning",children:[e.jsx(ue,{size:16,className:"text-red-500 dark:text-red-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-2 text-sm min-w-0",children:[e.jsx("p",{className:"font-medium text-red-600 dark:text-red-300",children:"Sign-in files are committed to git"}),e.jsxs("p",{className:"text-gray-400",children:[s.tracked.map(m=>e.jsx("code",{className:"mr-1.5 px-1 rounded bg-surface-2 text-gray-300",children:m},m)),s.tracked.length===1?"is":"are"," in this project's repository. Anyone who can read it gets the accounts' password hashes",s.tracked.some(m=>m.endsWith("auth-secret.key"))?" and the key that signs sign-in tokens":"",". Stop tracking them (they stay on disk), then commit:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 min-w-0 truncate px-2 py-1 rounded bg-surface-2 border border-white/10 font-mono text-[13px] text-gray-200",children:s.untrackCommand}),e.jsx("button",{type:"button",title:"Copy",onClick:async()=>{try{await navigator.clipboard.writeText(s.untrackCommand),l(!0),setTimeout(()=>l(!1),2e3)}catch{}},className:"p-1.5 rounded-md text-gray-400 hover:text-gray-200 hover:bg-white/5",children:a?e.jsx(Ue,{size:14,className:"text-emerald-400"}):e.jsx(xs,{size:14})})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["If the repository was ever shared or pushed, also delete ",e.jsx("code",{children:".testver/auth-secret.key"})," and restart Testver — everyone signs in again with a new key."]})]})]})}function Ll(s,t){return s.mode!==void 0?t.mode==="off"?"Auto-Heal turned off":`Auto-Heal set to ${t.mode==="suggest"?"Suggest":"Auto"}`:s.maxAttempts!==void 0?`Auto-Heal gives up after ${t.maxAttempts} attempt${t.maxAttempts===1?"":"s"} per test`:s.cooldownHours!==void 0?`Auto-Heal waits ${t.cooldownHours} hours before retrying a test`:s.reviewWindowDays!==void 0?`Apply / Undo offered for ${t.reviewWindowDays} day${t.reviewWindowDays===1?"":"s"}`:s.ciGate!==void 0?`CI-gated runs: ${t.ciGate==="update-build"?"update the build":"report only"}`:s.allowBrowserProbe!==void 0?`Live browser probe ${t.allowBrowserProbe?"enabled":"disabled"}`:s.remoteHubUrl!==void 0?t.remoteHubUrl?"Remote hub relay saved":"Remote hub relay cleared":"Auto-Heal settings saved"}const Os=[6,12,24,48,72,168];function $l({framework:s}){var S,I;const[t,a]=n.useState(null),[l,m]=n.useState(null),[i,h]=n.useState(null),[d,f]=n.useState(""),{toast:g}=ge(),y=Je(),c=n.useCallback(()=>{m(null),lt().then(w=>{a(w),f(String(w.reviewWindowDays))}).catch(w=>m(w instanceof Error?w.message:String(w)))},[]);n.useEffect(()=>{c()},[c]);const j=w=>{a(v=>v&&{...v,...w}),Ca(w).then(v=>{a(v),f(String(v.reviewWindowDays)),w.remoteHubUrl!==void 0&&h(null),y.invalidateQueries({queryKey:["auto-heal-config"]}),g("success",Ll(w,v))}).catch(v=>{const x=v instanceof Error?v.message:String(v);w.remoteHubUrl!==void 0&&h(x),g("error",`Could not save: ${x}`),lt().then(o=>{a(o),f(String(o.reviewWindowDays))}).catch(()=>{})})},p=()=>{const w=Math.round(Number(d));if(!Number.isFinite(w)||w<1||w>30){f(String((t==null?void 0:t.reviewWindowDays)??7)),g("error","The review window must be between 1 and 30 days");return}w!==(t==null?void 0:t.reviewWindowDays)&&j({reviewWindowDays:w})};if(!t)return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Te,{size:18,className:"text-purple-400"}),"Auto-Heal"]}),l?e.jsxs("div",{className:"mt-3 flex items-center gap-3 text-sm text-red-600 dark:text-red-400",role:"alert",children:[e.jsx(ue,{size:14,className:"flex-shrink-0"}),e.jsxs("span",{children:["Could not load the Auto-Heal settings: ",l]}),e.jsx("button",{type:"button",onClick:c,className:"px-2.5 py-1 rounded-lg border border-white/10 text-xs text-gray-300 hover:bg-white/5",children:"Retry"})]}):e.jsxs("p",{className:"mt-3 text-sm text-gray-500 flex items-center gap-2",children:[e.jsx(J,{size:14,className:"animate-spin"})," Loading…"]})]});const u=t.mode,b=t.maxAttempts,z=t.cooldownHours,M=(s||"").toLowerCase(),V=M.includes("playwright"),U=M.includes("cypress"),O=({options:w,value:v,onSelect:x,label:o})=>e.jsx("div",{role:"group","aria-label":o,className:"inline-flex rounded-lg border border-white/10 bg-white dark:bg-surface-2 overflow-hidden flex-shrink-0",children:w.map((r,E)=>e.jsx("button",{type:"button",onClick:()=>x(r.id),className:`px-3.5 py-1.5 text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${E>0?"border-l border-white/10":""} ${v===r.id?"bg-purple-500/15 text-purple-600 dark:text-purple-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,"aria-pressed":v===r.id,children:r.label},r.id))});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Te,{size:18,className:"text-purple-400"}),"Auto-Heal"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:'When a test fails because a locator no longer matches the page, Testver finds the element it meant, changes only that locator, re-runs the affected tests with the same browser and environment, and keeps the change only if every one of them passes. Assertion failures, overlays and environment problems are never "fixed" by editing a locator.'})]}),!V&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-white/10 bg-surface-2/40 px-3.5 py-2.5 text-sm text-gray-400",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsxs("span",{children:["This project is detected as ",e.jsx("b",{children:s||"non-Playwright"}),"."," ",U?e.jsxs(e.Fragment,{children:["Cypress keeps no page evidence of its own, so healing here needs the ",e.jsx("b",{children:"live browser probe"})," below, or a recorded fallback from the Testver recorder."]}):e.jsxs(e.Fragment,{children:["Healing reads the page (or app screen) through the test's ",e.jsx("b",{children:"own live session"})," while it runs — Selenium, WebdriverIO, Robot Framework and Appium, locally or on a cloud grid. Nothing to set up; the live browser probe is an optional last resort."]})]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Mode"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[e.jsx("b",{children:"Suggest"})," prepares and verifies the fix, puts your code back, and waits for you to apply it — the recommended starting point. ",e.jsx("b",{children:"Auto"})," keeps a verified fix for you. A fix that fails verification is reverted either way. Suites and CI pipelines can override this."]})]}),e.jsx(O,{label:"Auto-Heal mode",options:[{id:"off",label:"Off"},{id:"suggest",label:"Suggest"},{id:"auto",label:"Auto"}],value:u,onSelect:w=>j({mode:w})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-gray-200",children:["Give up after ",b," attempt",b===1?"":"s"," per test"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"An attempt is counted only when it costs something (an AI call, a re-run, a probe, or a verification). After the limit, Auto-Heal waits before trying that test again, so a genuinely broken test cannot loop."})]}),e.jsx(O,{label:"Attempts per test",options:[1,2,3,4,5].map(w=>({id:String(w),label:String(w)})),value:String(b),onSelect:w=>j({maxAttempts:Number(w)})})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"auto-heal-cooldown",className:"text-sm font-medium text-gray-200",children:"Then wait before retrying"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"How long a test rests after hitting the attempt limit."})]}),e.jsxs("select",{id:"auto-heal-cooldown",value:Os.includes(z)?z:"",onChange:w=>j({cooldownHours:Number(w.target.value)}),className:"bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-sm text-gray-200 focus:outline-none focus:border-purple-500/50 disabled:opacity-50",children:[!Os.includes(z)&&e.jsxs("option",{value:"",children:[z," hours"]}),Os.map(w=>e.jsx("option",{value:w,children:w===168?"1 week":w>=24?`${w/24} day${w===24?"":"s"}`:`${w} hours`},w))]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"auto-heal-review-window",className:"text-sm font-medium text-gray-200",children:["Offer Apply fix / Undo fix for ",t.reviewWindowDays," day",t.reviewWindowDays===1?"":"s"]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:["Past the window a fix shows as ",e.jsx("b",{children:"Expired"})," and its buttons retire — tests drift, and a stale action only confuses. Nothing is lost: a fresh fix is suggested from current page evidence the next time the test fails. Fixes whose code changed earlier are marked",e.jsx("b",{children:" Stale"})," immediately, regardless of the window."]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("input",{id:"auto-heal-review-window",type:"number",min:1,max:30,value:d,onChange:w=>f(w.target.value),onBlur:p,onKeyDown:w=>{w.key==="Enter"&&w.target.blur()},className:"w-20 bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-sm text-gray-200 focus:outline-none focus:border-brand-500/40 disabled:opacity-50"}),e.jsx("span",{className:"text-sm text-gray-500",children:"days (1–30)"})]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"When a heal succeeds on a CI-gated run"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[e.jsx("b",{children:"Report only"})," keeps the original build result — the repair lands for the next build.",e.jsx("b",{children:" Update the build"})," holds the gate until healing finishes, so a fully-healed run turns the commit status green (always labeled as auto-healed, never silently). Pipelines can override this per mapping."]})]}),e.jsx(O,{label:"CI gate behavior",options:[{id:"report-only",label:"Report only"},{id:"update-build",label:"Update the build"}],value:t.ciGate,onSelect:w=>j({ciGate:w})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{id:"auto-heal-probe-label",className:"text-sm font-medium text-gray-200",children:"Open a browser as a last resort"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"When a failed run left no usable page evidence, open the page in a fresh headless browser and heal from what it finds. Needs the app reachable from this server — it cannot log in, so leave it off for pages behind a login. Only http(s) pages are opened."})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":t.allowBrowserProbe,"aria-labelledby":"auto-heal-probe-label",onClick:()=>j({allowBrowserProbe:!t.allowBrowserProbe}),className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors mt-1 disabled:opacity-50 ${t.allowBrowserProbe?"bg-purple-500":"bg-surface-3"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${t.allowBrowserProbe?"translate-x-4":"translate-x-1"}`})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"auto-heal-hub",className:"text-sm font-medium text-gray-200",children:["Remote hub relay ",e.jsx("span",{className:"text-gray-500 font-normal",children:"(Selenium Grid · BrowserStack · LambdaTest)"})]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[e.jsx("b",{children:"Usually leave this empty"})," — Testver-launched cloud runs are captured automatically, and when a Cloud Testing Provider connector is configured the relay targets it with no setup. Fill this only for your own Selenium Grid, or if tests hard-code a hub URL — then point that URL at ",e.jsx("span",{className:"font-mono text-gray-400 text-xs",children:"http://localhost:4499"})," (a port this server opens for WebDriver clients on this machine only). WebSocket-based CDP/BiDi features are not relayed."]}),((S=t.relayStatus)==null?void 0:S.running)&&t.relayStatus.upstream&&e.jsxs("p",{className:"text-xs mt-1.5 text-emerald-600 dark:text-emerald-400",children:["Relay active on port ",t.relayStatus.port," → ",t.relayStatus.upstream,t.relayStatus.source&&t.relayStatus.source!=="manual"?` (from your ${t.relayStatus.source} connector)`:""]}),((I=t.relayStatus)==null?void 0:I.running)&&!t.relayStatus.upstream&&e.jsxs("p",{className:"text-xs mt-1.5 text-gray-500",children:["Relay listening on port ",t.relayStatus.port," — no target yet (enter a hub URL or enable a cloud connector)."]}),t.relayStatus&&!t.relayStatus.running&&(t.remoteHubUrl||t.relayStatus.upstream)&&e.jsxs("p",{className:"text-xs mt-1.5 text-amber-600 dark:text-amber-400",children:["The relay is not running — port ",t.relayStatus.port," may be in use by another program (see the server log)."]}),t.remoteHubHasKey&&e.jsx("p",{className:"text-xs mt-1.5 text-gray-500",children:"An access key is saved — it is shown as •••••• and never sent back to the browser. Keep the dots to keep the key."}),i&&e.jsx("p",{className:"text-xs mt-1.5 text-red-600 dark:text-red-400",role:"alert",children:i})]}),e.jsx("input",{id:"auto-heal-hub",type:"text",defaultValue:t.remoteHubUrl??"",placeholder:"https://user:key@hub…/wd/hub",autoComplete:"off",spellCheck:!1,onBlur:w=>{const v=w.target.value.trim();v!==(t.remoteHubUrl??"")&&j({remoteHubUrl:v})},className:"w-72 flex-shrink-0 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-purple-500/50 font-mono disabled:opacity-50"},t.remoteHubUrl??"")]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"space-y-2 text-sm text-gray-500",children:[e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsx("span",{children:"Every fix is verified by re-running the affected tests — an unverified edit never survives, even across a server restart."})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsx("span",{children:"Only the locator value changes — assertions, logic and data are never edited — and your own edits made meanwhile are never overwritten."})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsxs("span",{children:["Undo is offered for ",t.reviewWindowDays," day",t.reviewWindowDays===1?"":"s",", and a fix you undo is never proposed again."]})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsx("span",{children:"Only the failing tests re-run during verification — never the whole suite."})]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("a",{href:"/results?view=auto-heal",className:"inline-flex items-center gap-1.5 text-sm font-medium text-purple-600 dark:text-purple-300 hover:text-purple-500 dark:hover:text-purple-200 transition-colors",children:[e.jsx(Te,{size:14}),"View activity & review fixes → Results › Auto-Heal"]})]})}function Rl(){const{data:s,isLoading:t}=ya(),{data:a}=gn(),{data:l}=bn(),m=fn(),i=yn(),h=jn(),d=Je(),f=l==null?void 0:l.scan,g=!!(f!=null&&f.running),y=!!(a!=null&&a.preciseEnabled),c=!!(a!=null&&a.hideNames),j=(l==null?void 0:l.computed)??0;if(n.useEffect(()=>{if(!g)return;const b=setInterval(()=>d.invalidateQueries({queryKey:["ownership-status"]}),1500);return()=>clearInterval(b)},[g,d]),t||!(s!=null&&s.available))return null;const p=f&&f.total>0?Math.round(f.processed/f.total*100):0,u=({on:b,onClick:z,disabled:M})=>e.jsx("button",{type:"button",onClick:z,disabled:M,className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${b?"bg-brand-500":"bg-surface-3"}`,"aria-pressed":b,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${b?"translate-x-4":"translate-x-1"}`})});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(dn,{size:18}),"Test Ownership"]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Hide author names"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:"Hide git owner / last-modified-by names across Test Explorer and Results."})]}),e.jsx(u,{on:c,onClick:()=>m.mutate({hideNames:!c})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Precise (line-level) ownership"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5 max-w-md",children:"Compute each test's owner from its own lines for the whole project, so the Owner filter is instant at scale. Runs a one-time background scan (then updates incrementally). Leave off for smaller projects — ownership still loads lazily."})]}),e.jsx(u,{on:y,onClick:()=>m.mutate({preciseEnabled:!y})})]}),y&&e.jsx("div",{className:"rounded-lg border border-white/5 bg-surface-2/40 p-4 space-y-3",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-400",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:12,className:"animate-spin"}),"Scanning ownership… ",f.processed,"/",f.total," files"]}),e.jsx("button",{onClick:()=>h.mutate(),className:"text-gray-500 hover:text-red-400",children:"Cancel"})]}),e.jsx("div",{className:"h-2 rounded-full bg-surface-3 overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-500 transition-all",style:{width:`${p}%`}})}),f.currentFile&&e.jsx("p",{className:"text-[10px] text-gray-600 font-mono truncate",children:f.currentFile})]}):e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:j>0?`${j} tests have computed ownership.`:"No ownership computed yet."}),e.jsxs("button",{onClick:()=>i.mutate(),disabled:i.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg bg-brand-600 text-white hover:bg-brand-500 transition-colors disabled:opacity-60",children:[i.isPending?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(fs,{size:12}),j>0?"Re-scan":"Run scan"]})]})})]})}function Ml({project:s,theme:t,setTheme:a,readOnly:l=!1}){var Ye,Xe;const{toast:m}=ge(),{mode:i}=ks(),h=i==="mobile",[d,f]=n.useState(!0),[g,y]=n.useState(!1),[c,j]=n.useState(null),[p,u]=n.useState(""),[b,z]=n.useState(""),[M,V]=n.useState(""),[U,O]=n.useState(""),[S,I]=n.useState([]),[w,v]=n.useState(""),[x,o]=n.useState(""),[r,E]=n.useState({options:[]}),[P,B]=n.useState({options:[]}),[N,ee]=n.useState({browsers:{},environments:{}}),K=()=>{ha().then(L=>ee({browsers:Object.fromEntries(L.browsers.filter(D=>D.check).map(D=>[D.name,{value:D.arg,check:D.check}])),environments:Object.fromEntries(L.environments.filter(D=>D.check).map(D=>[D.name,{value:D.value,check:D.check}]))})).catch(()=>{})},[W,R]=n.useState(null),[G,_]=n.useState(!1),[A,te]=n.useState(l),[X,le]=n.useState(null),[$,re]=n.useState(null),ae=sr(),[ce,he]=n.useState(!1),[xe,ye]=n.useState(null),[Ne,ke]=n.useState(null),[F,Q]=n.useState({singleTest:"pending",suiteOrFile:"pending",fullRun:"pending"}),se=L=>{Q({singleTest:"pending",suiteOrFile:"pending",fullRun:"pending"}),["singleTest","suiteOrFile","fullRun"].forEach(D=>{const Y=L[D];if(!Y){Q(Z=>({...Z,[D]:"invalid"}));return}at(vt(Y)).then(Z=>Q(pe=>({...pe,[D]:Z.valid?"valid":"invalid"}))).catch(()=>Q(Z=>({...Z,[D]:"invalid"})))})},ie=async()=>{he(!0),ke(null),ye(null);try{const L=await fa();ye(L),se(L.suggestions)}catch(L){ke(String(L))}finally{he(!1)}},be=L=>{if(!xe)return;const D=xe.suggestions[L];D&&(L==="singleTest"?u(D):L==="suiteOrFile"?z(D):V(D),m("success",`Applied ${L} — review and Save to persist`))},oe=()=>{if(!xe)return;const L=xe.suggestions;L.singleTest&&u(L.singleTest),L.suiteOrFile&&z(L.suiteOrFile),L.fullRun&&V(L.fullRun),m("success","Applied all — review and Save to persist")},k=()=>{const L=["Help me set up the correct test run commands for my project in Testver.","","Please scan my project yourself — detect the test framework, read the relevant config file(s), any defined run scripts, and a sample test file — then propose three commands:"," 1. Single test — run ONE test by name"," 2. Suite / File — run all tests in one file"," 3. Full run — run the entire suite","","Use Testver placeholder tokens for runtime values: {test} (test name), {file} (relative path), {posixFile} (forward-slash path, for WebdriverIO --spec on Windows), {suite}, {line}, {args}.","Prefer an existing project run script when one maps to running tests. Explain each command briefly."].join(`
|
|
81
|
-
`);Ls(ae,{prompt:L,mode:"web"})},C=L=>L.length?["","Testver's own check of the code found:",...L.map(D=>` • ${D}`)]:[],q=(L,D=[])=>{const Z=[`Help me configure test-run ${L?"environments (e.g. staging, production, QA)":"browsers (e.g. Chrome, Firefox, Edge, Safari)"} for my project in Testver.`,...C(D),"","Please scan my project yourself — detect the test framework and read the relevant config file(s) — then tell me, for each target I might want:",L?" • the exact CLI argument OR environment variable to select that environment (one or the other, not both), e.g. `--base-url=...`, `-Denv=staging`, or `BASE_URL=https://staging.example.com`.":" • the exact CLI argument that selects that browser, e.g. `--project=chromium`, `--browser chrome`, `-Dbrowser=firefox`.","",'Use the configure_run_targets tool: first run it with action "detect" and show me what my project supports and whether my saved entries are correct, then save the right ones once I confirm.'].join(`
|
|
82
|
-
`);Ls(ae,{prompt:Z,mode:"web"})},T=(L,D=[])=>{const
|
|
83
|
-
`);Ls(ae,{prompt:Y,mode:"web"})};n.useEffect(()=>{xa().then(L=>{var Z,pe,Re,De,Zs,et;j(L);const D=L.configured||{},Y=L.autoDetected||{};u(D.singleTest||Y.singleTest||""),z(D.suiteOrFile||Y.suiteOrFile||""),V(D.fullRun||Y.fullRun||""),O(D.workingDirectory||""),v(D.beforeCommand||""),o(D.afterCommand||""),D.envVars&&I(Object.entries(D.envVars).map(([Yt,Xt])=>({key:Yt,value:Xt}))),E({argPattern:((Z=D.browsers)==null?void 0:Z.argPattern)||Y.browserArgPattern||"",options:((pe=D.browsers)==null?void 0:pe.options)||[],default:(Re=D.browsers)==null?void 0:Re.default}),B({argPattern:((De=D.environments)==null?void 0:De.argPattern)||Y.envArgPattern||"",options:((Zs=D.environments)==null?void 0:Zs.options)||[],default:(et=D.environments)==null?void 0:et.default}),R(D.suggested??null),_(!1),K()}).catch(L=>{console.error("[Settings] Failed to load run commands config:",L),m("error","Failed to load run commands config")}).finally(()=>f(!1))},[m]);const H=async()=>{var L,D;y(!0);try{const Y={};p.trim()&&p.trim()!==(c==null?void 0:c.autoDetected.singleTest)&&(Y.singleTest=p.trim()),b.trim()&&b.trim()!==(c==null?void 0:c.autoDetected.suiteOrFile)&&(Y.suiteOrFile=b.trim()),M.trim()&&M.trim()!==(c==null?void 0:c.autoDetected.fullRun)&&(Y.fullRun=M.trim()),U.trim()&&(Y.workingDirectory=U.trim()),w.trim()&&(Y.beforeCommand=w.trim()),x.trim()&&(Y.afterCommand=x.trim());const Z=S.filter(pe=>pe.key.trim()&&pe.value.trim());Z.length>0&&(Y.envVars=Object.fromEntries(Z.map(pe=>[pe.key.trim(),pe.value.trim()]))),r.options&&r.options.length>0&&(Y.browsers={argPattern:((L=r.argPattern)==null?void 0:L.trim())||void 0,options:r.options,default:r.default||void 0}),P.options&&P.options.length>0&&(Y.environments={argPattern:((D=P.argPattern)==null?void 0:D.trim())||void 0,options:P.options,default:P.default||void 0}),G&&(Y.suggested=null),await ba(Y),_(!1),K(),m("success","Run configuration saved")}catch(Y){m("error",`Failed to save: ${Y}`)}finally{y(!1)}},de=async(L,D)=>{le(D),re(null);try{const Y=await at(vt(L));re({cmd:D,valid:Y.valid,output:Y.output})}catch{re({cmd:D,valid:!1,output:"Request failed"})}finally{le(null)}},Be=(c==null?void 0:c.framework)||s.framework||"unknown";return e.jsxs("fieldset",{disabled:l,className:"space-y-6 min-w-0 border-0 p-0 m-0",children:[l&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"View only — these project settings are managed by your admin. You can see the configuration here but not change or save it."})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(ds,{size:18}),"Project Information"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-y-3.5 gap-x-6 text-[15px]",children:[e.jsx("span",{className:"text-gray-400 self-center",children:"Project Name"}),e.jsx(yl,{readOnly:l,fallback:ma(s.rootPath)}),e.jsx("span",{className:"text-gray-400",children:"Framework"}),e.jsx("span",{className:"text-gray-200",children:s.framework||"Auto-detected"}),e.jsx("span",{className:"text-gray-400",children:"Language"}),e.jsx("span",{className:"text-gray-200",children:s.language||"Multiple"}),e.jsx("span",{className:"text-gray-400",children:"Path"}),e.jsx("span",{className:"text-gray-200 font-mono text-sm truncate",title:s.rootPath,children:s.rootPath}),e.jsx("span",{className:"text-gray-400",children:"Modules"}),e.jsx("span",{className:"text-gray-200",children:s.stats.totalModules}),e.jsx("span",{className:"text-gray-400",children:"Total Files"}),e.jsx("span",{className:"text-gray-200",children:s.stats.totalFiles})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(nn,{size:18}),"Run Configuration"]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-xs px-2.5 py-1 rounded-lg bg-brand-500/10 text-brand-400 border border-brand-500/20 font-medium",children:Be}),e.jsxs("button",{onClick:H,disabled:g||d,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 transition-colors disabled:opacity-50",children:[g?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(ze,{size:14}),"Save Run Configuration"]})]})]}),e.jsxs("div",{className:"border border-white/5 rounded-xl p-4 bg-surface-1/40 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("h3",{className:"flex items-center gap-2 text-sm font-medium text-gray-200 flex-1",children:[e.jsx(Ts,{size:15,className:"text-brand-400"}),"Run Commands"]}),e.jsxs("button",{onClick:ie,disabled:ce,title:"Let AI inspect your project and propose run commands",className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-lg text-brand-600 bg-white border border-gray-200 shadow-sm hover:bg-gray-50 disabled:opacity-50",children:[ce?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Te,{size:12}),ce?"Analyzing project…":"Suggest with AI"]})]}),Ne&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-red-400 bg-red-500/5 border border-red-500/20 rounded-lg p-3",children:[e.jsx(Se,{size:14,className:"shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Couldn't get suggestions"}),e.jsx("div",{className:"text-red-400/80 mt-0.5",children:Ne}),e.jsx("button",{onClick:k,className:"mt-1.5 text-brand-400 hover:text-brand-300 underline underline-offset-2",children:"Try in the AI Assistant instead →"})]})]}),xe&&e.jsxs("div",{className:"rounded-2xl border border-brand-500/20 bg-gradient-to-br from-brand-500/[0.06] via-purple-500/[0.03] to-transparent overflow-hidden shadow-lg shadow-brand-500/5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-white/5 bg-white/[0.015]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-gradient-to-br from-purple-600 to-brand-600 shadow-md shadow-brand-500/20 shrink-0",children:e.jsx(Te,{size:16,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-100",children:"AI Suggestions"}),xe.suggestions.usedNpmScript&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 font-medium",children:"package.json script"})]}),e.jsx("p",{className:"text-[11px] text-gray-400 truncate",children:"Derived from your project — review before applying"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsxs("button",{onClick:oe,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-emerald-600/90 hover:bg-emerald-500 shadow-sm shadow-emerald-500/20 transition-colors",children:[e.jsx(ze,{size:13})," Apply all"]}),e.jsx("button",{onClick:()=>ye(null),className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-200 hover:bg-white/5 transition-colors",title:"Dismiss suggestions",children:e.jsx(me,{size:15})})]})]}),e.jsxs("div",{className:"p-4 space-y-2.5",children:[[{key:"singleTest",label:"Single Test"},{key:"suiteOrFile",label:"Suite / File"},{key:"fullRun",label:"Full Run"}].map(({key:L,label:D})=>{const Y=xe.suggestions[L];if(!Y)return null;const Z=xe.suggestions.confidence[L],pe=xe.suggestions.rationale[L],Re=F[L],De=Z==null?{text:"text-gray-400",dot:"bg-gray-500"}:Z>=.8?{text:"text-emerald-400",dot:"bg-emerald-400"}:Z>=.5?{text:"text-amber-400",dot:"bg-amber-400"}:{text:"text-red-400",dot:"bg-red-400"};return e.jsxs("div",{className:"group rounded-xl border border-white/[0.07] bg-surface-2/40 hover:bg-surface-2/60 hover:border-white/10 transition-colors p-3.5 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-[13px] font-semibold text-gray-200",children:D}),Re==="pending"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-gray-400",children:[e.jsx(J,{size:10,className:"animate-spin"})," checking"]}),Re==="valid"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:[e.jsx(ze,{size:10})," resolves"]}),Re==="invalid"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/10 text-amber-400 border border-amber-500/20",children:[e.jsx(ue,{size:10})," unverified"]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[Z!=null&&e.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] font-medium ${De.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${De.dot}`}),Math.round(Z*100),"%"]}),e.jsx("button",{onClick:()=>be(L),className:"px-2.5 py-1 rounded-lg text-[11px] font-medium text-brand-200 bg-brand-500/10 border border-brand-500/25 hover:bg-brand-500/20 hover:text-brand-100 transition-colors",children:"Apply"})]})]}),e.jsx("code",{className:"block text-xs text-cyan-300 font-mono bg-black/30 border border-white/5 rounded-lg px-3 py-2 break-all leading-relaxed",children:Y}),pe&&e.jsx("p",{className:"text-[11.5px] text-gray-300 leading-relaxed",children:pe})]},L)}),xe.suggestions.notes&&e.jsxs("div",{className:"flex items-start gap-2 text-[11.5px] text-gray-300 bg-white/[0.02] border border-white/5 rounded-lg px-3 py-2",children:[e.jsx(Te,{size:12,className:"text-purple-400 shrink-0 mt-0.5"}),e.jsx("span",{className:"leading-relaxed",children:xe.suggestions.notes})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5 border-t border-white/5 bg-white/[0.015]",children:[e.jsxs("span",{className:"text-[11px] text-gray-400 inline-flex items-center gap-1.5",children:[e.jsx(xt,{size:12,className:"text-gray-400"}),"Not saved until you click ",e.jsx("span",{className:"text-gray-200 font-medium",children:"Save Run Configuration"})]}),e.jsxs("button",{onClick:k,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-gray-200 bg-surface-2 border border-white/15 hover:bg-purple-500/10 hover:text-purple-600 dark:hover:text-purple-300 hover:border-purple-500/40 transition-colors",children:[e.jsx(Ft,{size:14,className:"text-purple-500 dark:text-purple-400"}),"Discuss in AI Assistant",e.jsx(Ie,{size:13,className:"opacity-70"})]})]})]}),e.jsx("p",{className:"text-[12px] text-gray-500",children:"Auto-detected commands are pre-filled below. Edit them to customize, or click Reset to restore defaults."}),e.jsxs("div",{className:"text-xs text-gray-500 space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{test}"})," test name"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{suite}"})," suite name"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{line}"})," start line"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{args}"})," extra args"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{file}"})," relative path"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{absFile}"})," absolute path"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{posixFile}"})," forward-slash path"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{fileName}"})," file name"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{fileNoExt}"})," name without ext"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5",children:[e.jsx(Ce,{token:"{project}"}),e.jsx(Ce,{token:"{cwd}"}),e.jsx(Ce,{token:"{root}"}),e.jsx("span",{children:"project root"})]})]}),d?e.jsxs("div",{className:"flex items-center gap-2 py-4",children:[e.jsx(J,{size:16,className:"animate-spin text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Loading configuration..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(Us,{label:"Single Test",description:"Run a single test/scenario by name",value:p,onChange:u,placeholder:(c==null?void 0:c.autoDetected.singleTest)||"",isCustom:!!p.trim()&&p.trim()!==(c==null?void 0:c.autoDetected.singleTest),onReset:()=>u((c==null?void 0:c.autoDetected.singleTest)||""),onTest:()=>de(p||(c==null?void 0:c.autoDetected.singleTest)||"","single"),testing:X==="single",testResult:($==null?void 0:$.cmd)==="single"?$:null}),e.jsx(Us,{label:"Suite / File",description:"Run all tests in a file or suite",value:b,onChange:z,placeholder:(c==null?void 0:c.autoDetected.suiteOrFile)||"",isCustom:!!b.trim()&&b.trim()!==(c==null?void 0:c.autoDetected.suiteOrFile),onReset:()=>z((c==null?void 0:c.autoDetected.suiteOrFile)||""),onTest:()=>de(b||(c==null?void 0:c.autoDetected.suiteOrFile)||"","suite"),testing:X==="suite",testResult:($==null?void 0:$.cmd)==="suite"?$:null}),e.jsx(Us,{label:"Full Run",description:"Run the entire test suite",value:M,onChange:V,placeholder:(c==null?void 0:c.autoDetected.fullRun)||"",isCustom:!!M.trim()&&M.trim()!==(c==null?void 0:c.autoDetected.fullRun),onReset:()=>V((c==null?void 0:c.autoDetected.fullRun)||""),onTest:()=>de(M||(c==null?void 0:c.autoDetected.fullRun)||"","full"),testing:X==="full",testResult:($==null?void 0:$.cmd)==="full"?$:null})]})]}),!d&&e.jsxs("div",{className:"space-y-4",children:[W&&(((Ye=W.browsers)==null?void 0:Ye.length)??0)+(((Xe=W.environments)==null?void 0:Xe.length)??0)>0&&e.jsxs("div",{className:"rounded-xl border border-amber-500/25 bg-amber-500/[0.06] p-3.5 space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2 text-amber-300",children:[e.jsx(Te,{size:14,className:"shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium",children:"The AI Assistant suggested changes to existing entries"}),e.jsxs("div",{className:"text-amber-300/70 mt-0.5",children:["They came from a chat by someone who can add entries but not change them",W.at?` (${new Date(W.at).toLocaleString()})`:"",". ",l?"An admin can apply them here.":"Apply them, then Save — or dismiss them."]})]})]}),e.jsxs("div",{className:"space-y-1 pl-6",children:[(W.browsers??[]).map(L=>e.jsxs("div",{className:"font-mono text-gray-300",children:[e.jsx("span",{className:"text-gray-500 font-sans",children:"Browser"})," ",L.name," → ",L.arg,(r.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase())?e.jsxs("span",{className:"text-gray-500",children:[" (now ",(r.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase()).arg,")"]}):null]},`b-${L.name}`)),(W.environments??[]).map(L=>e.jsxs("div",{className:"font-mono text-gray-300",children:[e.jsx("span",{className:"text-gray-500 font-sans",children:"Environment"})," ",L.name," → ",L.value,(P.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase())?e.jsxs("span",{className:"text-gray-500",children:[" (now ",(P.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase()).value,")"]}):null]},`e-${L.name}`))]}),!l&&e.jsxs("div",{className:"flex items-center gap-2 pl-6",children:[e.jsx("button",{onClick:()=>{var D,Y;const L=(Z=[],pe=[])=>[...Z.filter(Re=>!pe.some(De=>De.name.toLowerCase()===Re.name.toLowerCase())),...pe];(D=W.browsers)!=null&&D.length&&E(Z=>({...Z,options:L(Z.options,W.browsers)})),(Y=W.environments)!=null&&Y.length&&B(Z=>({...Z,options:L(Z.options,W.environments)})),R(null),_(!0),m("success","Applied — click Save to keep them")},className:"px-2.5 py-1 rounded-lg text-[11px] font-medium text-white bg-emerald-600/90 hover:bg-emerald-500",children:"Apply"}),e.jsx("button",{onClick:()=>{R(null),_(!0),m("info","Dismissed — click Save to confirm")},className:"px-2.5 py-1 rounded-lg text-[11px] text-gray-300 border border-white/10 hover:bg-white/5",children:"Dismiss"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[!h&&e.jsx(wt,{title:"Browsers",icon:e.jsx(cs,{size:15,className:"text-brand-400"}),isEnv:!1,autoPattern:c==null?void 0:c.autoDetected.browserArgPattern,presetNames:Dl,cfg:r,onChange:L=>E(L),checks:N.browsers,onSuggest:async()=>{const L=await tt("browsers");return{entries:L.browsers.map(D=>({name:D.name,arg:D.arg,...D.kind==="env"?{kind:"env"}:{},check:D.check,source:D.source})),notes:L.browserNotes??[]}},onDiscussInAI:L=>q(!1,L),onImproveInAI:L=>T(!1,L)}),!h&&e.jsx(wt,{title:"Environments",icon:e.jsx(As,{size:15,className:"text-brand-400"}),isEnv:!0,autoPattern:c==null?void 0:c.autoDetected.envArgPattern,presetNames:Fl,cfg:P,onChange:L=>B(L),checks:N.environments,onSuggest:async()=>{const L=await tt("environments");return{entries:L.environments.map(D=>({name:D.name,kind:D.kind,value:D.value,check:D.check,source:D.source})),notes:L.environmentNotes??[]}},onDiscussInAI:L=>q(!0,L),onImproveInAI:L=>T(!0,L)}),(h||i==="both")&&e.jsx("div",{className:"lg:col-span-2",children:e.jsx(fl,{readOnly:l})})]}),e.jsxs("div",{className:"border-t border-white/5 pt-4",children:[e.jsxs("button",{onClick:()=>te(!A),className:"flex items-center gap-2 text-sm text-gray-400 hover:text-gray-200 transition-colors",children:[A?e.jsx(Me,{size:14}):e.jsx(Ie,{size:14}),e.jsx(as,{size:14}),"Advanced Settings"]}),A&&e.jsxs("div",{className:"mt-4 space-y-4 pl-1",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm text-gray-400 flex items-center gap-1.5 mb-1.5",children:[e.jsx(xt,{size:13})," Environment Variables"]}),e.jsxs("div",{className:"space-y-1.5",children:[S.map((L,D)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:L.key,onChange:Y=>{const Z=[...S];Z[D]={...Z[D],key:Y.target.value},I(Z)},placeholder:"KEY",className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("input",{value:L.value,onChange:Y=>{const Z=[...S];Z[D]={...Z[D],value:Y.target.value},I(Z)},placeholder:"value",className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>I(S.filter((Y,Z)=>Z!==D)),className:"p-2 rounded-lg text-gray-600 hover:text-red-400 hover:bg-red-500/10 transition-colors",children:e.jsx(me,{size:14})})]},D)),e.jsxs("button",{onClick:()=>I([...S,{key:"",value:""}]),className:"flex items-center gap-1.5 text-xs text-brand-400 hover:text-brand-300 transition-colors",children:[e.jsx(je,{size:12})," Add Variable"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 mb-1.5 block",children:"Before Command"}),e.jsx("input",{value:w,onChange:L=>v(L.target.value),placeholder:"e.g., npm run build",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 mb-1.5 block",children:"After Command"}),e.jsx("input",{value:x,onChange:L=>o(L.target.value),placeholder:"e.g., npm run cleanup",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"})]})]})]})]}),e.jsx("div",{className:"flex items-center justify-end pt-2 border-t border-white/5",children:e.jsxs("button",{onClick:H,disabled:g,className:"flex items-center gap-2 px-5 py-2.5 rounded-lg text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 transition-colors disabled:opacity-50",children:[g?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(ze,{size:14}),"Save Run Configuration"]})})]})]}),e.jsx(Cl,{}),e.jsx(Cn,{}),e.jsx($l,{framework:s.framework}),e.jsx(Rl,{}),e.jsx(Al,{}),!l&&e.jsx(El,{}),e.jsx(vl,{})]})}const Dl=["Chrome","Chromium","Firefox","WebKit","Microsoft Edge","Safari"],Fl=["QA","Development","Staging","Pre-Production","Production"];function Il({isEnv:s,presetNames:t,usedNames:a,value:l,onChange:m}){const[i,h]=n.useState(!1),[d,f]=n.useState(""),g=new Set(a.map(c=>c.toLowerCase())),y=()=>{const c=d.trim();c&&(m(c),f(""),h(!1))};return e.jsxs("div",{className:"relative w-64",children:[e.jsxs("button",{type:"button",onClick:()=>h(c=>!c),className:"w-full flex items-center gap-2 bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-left outline-none hover:border-gray-300 dark:hover:border-white/20 focus:border-brand-500/50",children:[l?e.jsx(ns,{name:l,isEnv:s}):null,e.jsx("span",{className:`flex-1 truncate ${l?"text-gray-800 dark:text-gray-200":"text-gray-400 dark:text-gray-500"}`,children:l||"Select or type a name…"}),e.jsx(Me,{size:14,className:`text-gray-400 dark:text-gray-500 flex-shrink-0 transition-transform ${i?"rotate-180":""}`})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>h(!1)}),e.jsxs("div",{className:"absolute left-0 top-full mt-1 z-50 w-64 rounded-lg bg-white dark:bg-surface-1 border border-gray-200 dark:border-white/10 shadow-xl shadow-black/20 dark:shadow-black/40 p-1.5",children:[e.jsx("input",{autoFocus:!0,value:d,onChange:c=>f(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),y())},placeholder:"Type a custom name…",className:"w-full mb-1 bg-gray-50 dark:bg-surface-2 border border-gray-200 dark:border-white/10 rounded-md px-3 py-2 text-sm text-gray-800 dark:text-gray-200 outline-none placeholder-gray-400 dark:placeholder-gray-600 focus:border-brand-500/50"}),e.jsx("div",{className:"max-h-56 overflow-auto",children:t.map(c=>e.jsxs("button",{type:"button",onClick:()=>{m(c),h(!1)},className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e.jsx(ns,{name:c,isEnv:s}),e.jsx("span",{className:"flex-1 text-left truncate",children:c}),g.has(c.toLowerCase())&&e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-600",children:"added"})]},c))})]})]})]})}function wt({title:s,icon:t,isEnv:a,autoPattern:l,presetNames:m,cfg:i,onChange:h,onSuggest:d,onDiscussInAI:f,onImproveInAI:g,checks:y}){const[c,j]=n.useState(""),[p,u]=n.useState("arg"),[b,z]=n.useState(!1),[M,V]=n.useState(""),[U,O]=n.useState(!1),[S,I]=n.useState(null),[w,v]=n.useState([]),[x,o]=n.useState(null),[r,E]=n.useState(null),[P,B]=n.useState(null),[N,ee]=n.useState(""),[K,W]=n.useState("arg"),[R,G]=n.useState(""),[_,A]=n.useState(""),te=n.useRef(!1);n.useEffect(()=>{!te.current&&!a&&l&&!_&&(A(l),te.current=!0)},[l]);const X=i.options||[],le=k=>X.some(C=>C.name.toLowerCase()===k.toLowerCase()),$=()=>{const k=c.trim(),C=_.trim();if(!k||!C||le(k))return;const q=a?{name:k,kind:p,value:C}:{name:k,arg:C,...p==="env"?{kind:"env"}:{}};h({...i,options:[...X,q]}),j(""),A(p==="env"?"":l||"")},re=k=>h({...i,options:X.filter(C=>C.name!==k),default:i.default===k?void 0:i.default}),ae=k=>{B(k.name),ee(k.name),W(k.kind==="env"?"env":"arg"),G((a?k.value:k.arg)||"")},ce=()=>B(null),he=!!P&&!!N.trim()&&N.trim().toLowerCase()!==P.toLowerCase()&&le(N.trim()),xe=()=>{if(!P)return;const k=N.trim(),C=R.trim();if(!k||!C||he)return;const q=a?{name:k,kind:K,value:C}:{name:k,arg:C,...K==="env"?{kind:"env"}:{}};h({...i,options:X.map(T=>T.name===P?q:T),default:i.default===P?k:i.default}),B(null)},ye=k=>h({...i,default:i.default===k?void 0:k}),Ne=k=>{u(k),(!_||_===l)&&A(k==="env"?"":l||"")},ke=async()=>{if(!(!d||b)){z(!0),V(""),O(!1),I(null),o(null);try{const{entries:k,notes:C}=await d(),q=new Set(X.map(H=>H.name.toLowerCase())),T=k.filter(H=>H.name&&!q.has(H.name.toLowerCase()));v(C??[]),T.length>0?I(T):k.length>0?V("No new suggestions — your list already covers them."):o(C??[])}catch(k){V((k==null?void 0:k.message)||"AI suggestion failed"),O(!0)}finally{z(!1)}}},F=({check:k,source:C,...q})=>q,Q=k=>{le(k.name)||h({...i,options:[...X,F(k)]}),I(C=>{const q=(C||[]).filter(T=>T.name!==k.name);return q.length?q:null})},se=()=>{if(!S)return;const k=new Set(X.map(q=>q.name.toLowerCase())),C=S.filter(q=>!k.has(q.name.toLowerCase())).map(F);C.length&&h({...i,options:[...X,...C]}),I(null)},ie="bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50",be=!!c.trim()&&le(c.trim()),oe=p==="env"?a?"BASE_URL=https://staging.example.com":"BROWSER=firefox":l||"--browser chrome";return e.jsxs("div",{className:"border border-white/5 rounded-xl p-4 bg-surface-1/40 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-gray-200 flex-1",children:[t," ",s]}),d&&e.jsxs("button",{onClick:ke,disabled:b,title:"Read the right arguments from your project's code — AI is asked only when the code doesn't say",className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-lg text-brand-600 bg-white border border-gray-200 shadow-sm hover:bg-gray-50 disabled:opacity-50",children:[b?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Te,{size:12})," Suggest"]})]}),e.jsxs("p",{className:"text-[11px] text-gray-600 -mt-1",children:["Only the ",e.jsx("span",{className:"text-gray-400",children:"name"})," is shown when picking in Suites & Cycles.",M&&!U&&e.jsx("span",{className:"text-gray-400 ml-2",children:M})]}),U&&M&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-red-400 bg-red-500/5 border border-red-500/20 rounded-lg p-3",children:[e.jsx(Se,{size:14,className:"shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium",children:"Couldn't get suggestions"}),e.jsx("div",{className:"text-red-400/80 mt-0.5",children:M}),e.jsx(kt,{isEnv:a,notes:[],onDiscussInAI:f,onImproveInAI:g})]})]}),x&&e.jsxs("div",{className:"rounded-xl border border-white/10 bg-surface-2/40 p-3.5 space-y-2.5 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ln,{size:15,className:"shrink-0 mt-0.5 text-gray-400"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-gray-200",children:"Nothing found in your project's code"}),e.jsx("div",{className:"text-gray-400 mt-0.5",children:a?"Testver couldn't find a way for a run to choose the environment or application URL.":"Testver couldn't find a way for a run to choose the browser."})]}),e.jsx("button",{onClick:()=>o(null),className:"text-gray-500 hover:text-gray-200",title:"Dismiss",children:e.jsx(me,{size:14})})]}),x.length>0&&e.jsx("ul",{className:"space-y-1 pl-6 text-gray-500 list-disc",children:x.map((k,C)=>e.jsx("li",{className:"line-clamp-3",title:k,children:k},C))}),e.jsxs("div",{className:"pl-6",children:[e.jsx(kt,{isEnv:a,notes:x,onDiscussInAI:f,onImproveInAI:g}),e.jsxs("p",{className:"text-[11px] text-gray-500 mt-2",children:["Or add an entry by hand below if you already know the ",a?"argument or variable":"argument","."]})]})]}),S&&S.length>0&&e.jsxs("div",{className:"rounded-2xl border border-brand-500/20 bg-gradient-to-br from-brand-500/[0.06] via-purple-500/[0.03] to-transparent overflow-hidden shadow-lg shadow-brand-500/5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-white/5 bg-white/[0.015]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-gradient-to-br from-purple-600 to-brand-600 shadow-md shadow-brand-500/20 shrink-0",children:e.jsx(Te,{size:16,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-100",children:"Suggestions"}),e.jsx("p",{className:"text-[11px] text-gray-400 truncate",children:S.every(k=>k.source==="project")?"Read from your project's code — review before applying":"Checked against your project's code — review before applying"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsxs("button",{onClick:se,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-emerald-600/90 hover:bg-emerald-500 shadow-sm shadow-emerald-500/20 transition-colors",children:[e.jsx(ze,{size:13})," Apply all"]}),e.jsx("button",{onClick:()=>I(null),className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-200 hover:bg-white/5 transition-colors",title:"Dismiss suggestions",children:e.jsx(me,{size:15})})]})]}),e.jsxs("div",{className:"p-4 space-y-2.5",children:[S.map(k=>{const C=a?k.value:k.arg,q=a?k.kind:k.kind==="env"?"env":void 0;return e.jsxs("div",{className:"group rounded-xl border border-white/[0.07] bg-surface-2/40 hover:bg-surface-2/60 hover:border-white/10 transition-colors p-3.5 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(ns,{name:k.name,isEnv:a,size:14}),e.jsx("span",{className:"text-[13px] font-semibold text-gray-200 truncate",children:k.name}),q&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-white/5 text-gray-400 border border-white/10 font-medium",children:q==="env"?"Env var":"CLI arg"})]}),e.jsx("button",{onClick:()=>Q(k),className:"px-2.5 py-1 rounded-lg text-[11px] font-medium text-brand-200 bg-brand-500/10 border border-brand-500/25 hover:bg-brand-500/20 hover:text-brand-100 transition-colors shrink-0",children:"Apply"})]}),C&&e.jsx("code",{className:"block text-xs text-cyan-300 font-mono bg-black/30 border border-white/5 rounded-lg px-3 py-2 break-all leading-relaxed",children:C}),k.check&&e.jsx(Ol,{check:k.check,source:k.source})]},k.name)}),w.length>0&&e.jsx("ul",{className:"text-[11px] text-gray-400 leading-relaxed space-y-0.5",children:w.map((k,C)=>e.jsx("li",{children:k},C))}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:[f&&e.jsx("button",{onClick:()=>f(w),className:"text-[11px] text-brand-400 hover:text-brand-300 underline underline-offset-2",children:"Not quite right? Refine in the AI Assistant →"}),g&&e.jsxs("button",{onClick:()=>g(w),className:"text-[11px] text-brand-400 hover:text-brand-300 underline underline-offset-2",children:["Support more ",a?"environments":"browsers"," in my framework →"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Il,{isEnv:a,presetNames:m,usedNames:X.map(k=>k.name),value:c,onChange:j}),e.jsxs("div",{className:"flex rounded-lg border border-white/10 overflow-hidden",title:a?void 0:"Use Env var only when your project reads the browser from an environment variable (BROWSER=firefox)",children:[e.jsx("button",{onClick:()=>Ne("arg"),className:`px-3 py-1.5 text-xs ${p==="arg"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"CLI arg"}),e.jsx("button",{onClick:()=>Ne("env"),className:`px-3 py-1.5 text-xs border-l border-white/10 ${p==="env"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"Env var"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:_,onChange:k=>A(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),$())},placeholder:oe,className:`${ie} flex-1 min-w-[220px] font-mono`}),e.jsx("button",{onClick:$,disabled:!c.trim()||!_.trim()||be,className:"px-3 py-2 text-xs rounded-lg bg-brand-500/20 border border-brand-500/40 text-brand-200 hover:bg-brand-500/30 disabled:opacity-40",children:"Add"})]}),be&&e.jsxs("p",{className:"text-[11px] text-red-400",children:["A “",c.trim(),"” entry already exists — names must be unique."]})]}),X.length>0?e.jsxs("div",{className:"space-y-1.5",children:[X.map(k=>P===k.name?e.jsxs("div",{className:"rounded-lg border border-brand-500/40 bg-brand-500/5 p-2 space-y-2 text-xs",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ns,{name:N||k.name,isEnv:a,size:14}),e.jsx("input",{value:N,onChange:C=>ee(C.target.value),autoFocus:!0,onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),xe()),C.key==="Escape"&&(C.preventDefault(),ce())},"aria-label":"Name",className:`${ie} !py-1.5 w-44`}),e.jsxs("div",{className:"flex rounded-lg border border-white/10 overflow-hidden",children:[e.jsx("button",{type:"button",onClick:()=>W("arg"),className:`px-3 py-1.5 text-xs ${K==="arg"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"CLI arg"}),e.jsx("button",{type:"button",onClick:()=>W("env"),className:`px-3 py-1.5 text-xs border-l border-white/10 ${K==="env"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"Env var"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:R,onChange:C=>G(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),xe()),C.key==="Escape"&&(C.preventDefault(),ce())},"aria-label":a?"Value":"Argument",placeholder:oe,className:`${ie} !py-1.5 flex-1 min-w-[220px] font-mono`}),e.jsx("button",{type:"button",onClick:xe,disabled:!N.trim()||!R.trim()||he,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-500/20 border border-brand-500/40 text-brand-200 hover:bg-brand-500/30 disabled:opacity-40",children:"Save"}),e.jsx("button",{type:"button",onClick:ce,className:"px-3 py-1.5 text-xs rounded-lg border border-white/10 text-gray-400 hover:text-gray-200 hover:bg-white/5",children:"Cancel"})]}),he&&e.jsxs("p",{className:"text-[11px] text-red-400",children:["A “",N.trim(),"” entry already exists — names must be unique."]}),!he&&N.trim()&&N.trim()!==k.name&&e.jsxs("p",{className:"text-[11px] text-amber-400",children:["Renaming: suites, cycles and schedules that picked “",k.name,"” keep that name and will fall back to the default until you re-pick “",N.trim(),"”."]})]},k.name):e.jsxs("div",{className:`flex items-center gap-2 rounded-lg border px-2.5 py-1.5 text-xs ${i.default===k.name?"border-brand-500/40 bg-brand-500/10":"border-white/10 bg-surface-2"}`,children:[e.jsx("button",{onClick:()=>ye(k.name),title:i.default===k.name?"Default":"Set as default",className:i.default===k.name?"text-brand-300":"text-gray-500 hover:text-brand-300",children:e.jsx(gs,{size:12,className:i.default===k.name?"fill-current":""})}),e.jsx(ns,{name:k.name,isEnv:a,size:14}),e.jsx("span",{className:"text-gray-200 font-medium min-w-[80px]",children:k.name}),(a||k.kind==="env")&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${k.kind==="env"?"bg-cyan-500/15 text-cyan-300":"bg-white/5 text-gray-400"}`,children:k.kind==="env"?"ENV":"ARG"}),e.jsx("span",{className:"text-gray-500 font-mono truncate flex-1",title:a?k.value:k.arg,children:a?k.value:k.arg}),(()=>{const C=y==null?void 0:y[k.name];return!C||C.value!==(a?k.value:k.arg)||C.check.status==="confirmed"?null:e.jsx("span",{title:C.check.note,className:`flex-shrink-0 ${C.check.status==="wrong"?"text-red-400":"text-amber-400"}`,children:e.jsx(ue,{size:12})})})(),e.jsx("button",{onClick:()=>ae(k),title:`Edit ${k.name}`,"aria-label":`Edit ${k.name}`,className:"text-gray-500 hover:text-brand-300 flex-shrink-0",children:e.jsx(Cs,{size:12})}),e.jsx("button",{onClick:()=>E(k.name),title:`Remove ${k.name}`,className:"text-gray-500 hover:text-red-400 flex-shrink-0",children:e.jsx(me,{size:12})})]},k.name)),X.filter(k=>{const C=y==null?void 0:y[k.name];return C&&C.value===(a?k.value:k.arg)&&C.check.status==="wrong"}).map(k=>e.jsxs("p",{className:"text-[11px] text-red-400 leading-relaxed",children:[e.jsxs("span",{className:"font-medium",children:[k.name,":"]})," ",y[k.name].check.note]},`w-${k.name}`))]}):e.jsx("p",{className:"text-[11px] text-gray-600",children:"No entries yet — add a name + its argument above."}),e.jsx(Ot,{open:r!=null,title:`Remove ${a?"environment":"browser"} “${r??""}”?`,description:`This deletes the saved ${a?"environment":"browser"} “${r??""}” from ${s.toLowerCase()}. Suites, cycles, and scheduled runs that pick it by name will fall back to the default. This won't affect runs that already completed.`,confirmLabel:"Remove",onConfirm:()=>{r&&re(r),E(null)},onCancel:()=>E(null)})]})}function kt({isEnv:s,notes:t,onDiscussInAI:a,onImproveInAI:l}){if(!a&&!l)return null;const m="inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] font-medium transition-colors";return e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[a&&e.jsxs("button",{onClick:()=>a(t),title:"The AI Assistant scans your project itself and saves the entries it finds",className:`${m} text-brand-200 bg-brand-500/10 border border-brand-500/25 hover:bg-brand-500/20`,children:[e.jsx(Te,{size:12})," Find them with the AI Assistant"]}),l&&e.jsxs("button",{onClick:()=>l(t),title:`The AI Assistant updates your framework so a run can choose the ${s?"environment":"browser"}, keeps today's default, and registers the options`,className:`${m} text-gray-200 bg-white/5 border border-white/10 hover:bg-white/10`,children:[e.jsx(Rt,{size:12})," Add support to my framework"]})]})}function Ol({check:s,source:t}){const a=s.status==="confirmed"?"text-emerald-400":s.status==="wrong"?"text-red-400":"text-amber-400",l=s.status==="confirmed"?t==="ai"?"AI suggestion, confirmed in your code":"Found in your project":s.status==="wrong"?"Your code doesn't accept this":"Not confirmed — check it before relying on it";return e.jsxs("p",{className:`text-[11px] leading-relaxed ${a}`,title:s.note,children:[s.status==="confirmed"?e.jsx(ne,{size:11,className:"inline -mt-0.5 mr-1"}):e.jsx(ue,{size:11,className:"inline -mt-0.5 mr-1"}),e.jsx("span",{className:"font-medium",children:l}),e.jsxs("span",{className:"text-gray-500",children:[" — ",s.note]})]})}function Ce({token:s}){const[t,a]=n.useState(!1),l=async()=>{try{await navigator.clipboard.writeText(s)}catch{const m=document.createElement("textarea");m.value=s,m.style.position="fixed",m.style.opacity="0",document.body.appendChild(m),m.select();try{document.execCommand("copy")}catch{}document.body.removeChild(m)}a(!0),window.setTimeout(()=>a(!1),1200)};return e.jsxs("button",{type:"button",onClick:l,title:t?"Copied!":"Click to copy",className:`group relative inline-flex items-center font-mono px-1.5 py-0.5 rounded border transition-colors cursor-pointer ${t?"bg-emerald-500/10 text-emerald-400 border-emerald-500/30":"bg-surface-2 text-cyan-400 border-transparent hover:border-cyan-500/30 hover:bg-cyan-500/10"}`,children:[e.jsx("code",{className:"bg-transparent",children:s}),e.jsx("span",{className:`absolute -top-1.5 -right-1.5 flex items-center justify-center w-3.5 h-3.5 rounded-full bg-surface-1 border shadow-sm transition-opacity ${t?"opacity-100 border-emerald-500/40 text-emerald-400":"opacity-0 group-hover:opacity-100 border-cyan-500/40 text-cyan-400"}`,children:t?e.jsx(Ue,{size:9}):e.jsx(xs,{size:9})})]})}function Us({label:s,description:t,value:a,onChange:l,placeholder:m,isCustom:i,onReset:h,onTest:d,testing:f,testResult:g}){return e.jsxs("div",{className:"rounded-xl border border-white/5 bg-black/20 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ts,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-200",children:s}),i?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cyan-500/10 text-cyan-400 border border-cyan-500/20",children:"Custom"}):e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-gray-500/10 text-gray-500 border border-gray-500/20",children:"Auto-detected"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{onClick:h,className:`flex items-center gap-1 px-2 py-1 rounded-lg text-xs transition-colors ${i?"text-amber-400 hover:text-amber-300 hover:bg-amber-500/10":"text-gray-600 hover:text-gray-400 hover:bg-white/5"}`,title:"Reset to auto-detected default",children:[e.jsx(fs,{size:11})," Reset"]}),e.jsxs("button",{onClick:d,disabled:f,className:"flex items-center gap-1 px-2 py-1 rounded-lg text-xs text-gray-500 hover:text-emerald-400 hover:bg-emerald-500/10 transition-colors disabled:opacity-50",title:"Test this command",children:[f?e.jsx(J,{size:11,className:"animate-spin"}):e.jsx(Xs,{size:11})," Test"]})]})]}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:t}),e.jsx("input",{value:a,onChange:y=>l(y.target.value),placeholder:m,className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),g&&e.jsxs("div",{className:`mt-2 flex items-center gap-2 text-xs ${g.valid?"text-emerald-400":"text-red-400"}`,children:[g.valid?e.jsx(ze,{size:12}):e.jsx(Se,{size:12}),e.jsx("span",{children:g.valid?"Command is valid":"Command failed"}),g.output&&e.jsx("span",{className:"text-gray-600 truncate max-w-[300px]",title:g.output,children:g.output.slice(0,80)})]})]})}const Bs=[{id:"openai",label:"OpenAI",color:"text-green-400",description:"GPT-4o, GPT-4, GPT-3.5 Turbo",requiresKey:!0},{id:"anthropic",label:"Anthropic",color:"text-purple-400",description:"Claude Sonnet, Claude Opus, Claude Haiku",requiresKey:!0},{id:"google",label:"Google AI",color:"text-blue-400",description:"Gemini 2.0 Flash, Gemini Pro",requiresKey:!0},{id:"xai",label:"xAI",color:"text-orange-400",description:"Grok-2, Grok-3",requiresKey:!0},{id:"testver",label:"Testver",color:"text-sky-400",description:"Managed AI — frontier model, managed by Testver",requiresKey:!0},{id:"ollama",label:"Ollama",color:"text-amber-400",description:"Local models — Llama, Mistral, Phi, etc.",requiresKey:!1},{id:"lmstudio",label:"LM Studio",color:"text-cyan-400",description:"Local model server",requiresKey:!1}],He="••••••••";function Ul(){const s=Je(),{data:t}=vn();return n.useEffect(()=>{Nn(s)},[s]),t!=null&&t.connected?(t.totalCredits??0)<=0?e.jsxs("div",{className:"mt-3 pt-3 border-t border-white/5 text-xs text-gray-500",children:[t.active===!1?"No active plan on this account yet — pick one at testver.com to start generating.":"Loading plan details…",t.billingUrl&&t.active===!1&&e.jsx("a",{href:t.billingUrl,target:"_blank",rel:"noopener noreferrer",className:"ml-1.5 font-medium text-sky-400 hover:text-sky-300 underline underline-offset-2",children:"View plans →"})]}):e.jsx("div",{className:"mt-3 pt-3.5 border-t border-black/[0.06] dark:border-white/5",children:e.jsx(wn,{data:t,statusBadge:!0})}):null}function Bl({connected:s,isSystemAdmin:t}){const a=t?"system":"personal",{data:l}=Ge({queryKey:["testver-status"],queryFn:()=>Na(),refetchInterval:3e4,refetchOnWindowFocus:!0,staleTime:15e3,enabled:s}),m=l!=null&&l.connected?l.accountEmail??null:null;return e.jsxs("div",{className:"rounded-lg border border-sky-500/20 bg-surface-1 p-4",children:[s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-400",children:[e.jsx(ne,{size:16}),e.jsxs("span",{className:"font-medium",children:[a==="system"?"System connected to Testver":"Connected",m?e.jsxs(e.Fragment,{children:[" as ",e.jsx("span",{className:"text-gray-200",children:m})]}):a==="system"?null:" as your account"]}),l!=null&&l.connected&&l.status==="suspended"?e.jsx("span",{className:"text-red-400",children:"— plan suspended, AI requests are paused."}):l!=null&&l.connected&&l.status==="paused"?e.jsx("span",{className:"text-amber-400",children:"— seat paused, AI requests are off until the team owner gives you a seat."}):l!=null&&l.connected&&l.active===!1&&(l.totalCredits??0)>0?e.jsx("span",{className:"text-red-400",children:"— credits used up, AI requests are paused."}):e.jsx("span",{className:"text-gray-500",children:"— AI requests are ready."})]}),e.jsxs(os,{to:"/testver",className:"ml-auto inline-flex items-center gap-1.5 px-3.5 py-1.5 rounded-lg text-xs font-medium text-sky-300 bg-sky-500/10 border border-sky-500/20 hover:bg-sky-500/20 transition-colors",children:["Manage in Testver → Connections",e.jsx(cn,{size:12})]})]}),e.jsx(Ul,{})]}):e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{className:"text-sm text-gray-300",children:a==="system"?"This Testver is not connected to an account yet.":"Your Testver account is not connected yet."}),e.jsxs(os,{to:"/testver",className:"ml-auto inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-semibold text-white bg-gradient-to-r from-sky-500 to-indigo-500 hover:from-sky-400 hover:to-indigo-400 transition-colors",children:[e.jsx(Ee,{size:14}),"Connect in Testver → Connections"]})]}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Connect and disconnect moved to the Testver page — this card only shows the status and the model settings."})]})}const Fe=()=>({apiKey:"",model:"",models:[],activeModel:"",newModel:"",baseUrl:"",timeout:""});function Kl({isAdmin:s=!0}){const{toast:t}=ge(),[a,l]=n.useState(!0),[m,i]=n.useState(null),[h,d]=n.useState("openai"),[f,g]=n.useState(""),[y,c]=n.useState({openai:Fe(),anthropic:Fe(),google:Fe(),xai:Fe(),testver:Fe(),ollama:Fe(),lmstudio:Fe()}),[j,p]=n.useState(null),[u,b]=n.useState({}),[z,M]=n.useState({}),[V,U]=n.useState({}),[O,S]=n.useState(null),I=n.useCallback(async(r=!1)=>{try{const E=await ua();i(E),r||(d(E.defaultProvider),g(E.defaultModel||""));const P={};for(const B of Bs){const N=E.providers[B.id];P[B.id]={apiKey:N!=null&&N.hasApiKey?He:"",model:(N==null?void 0:N.configuredModel)||"",models:(N==null?void 0:N.models)??[],activeModel:(N==null?void 0:N.activeModel)||(N==null?void 0:N.model)||"",newModel:"",baseUrl:(N==null?void 0:N.configuredBaseUrl)||"",timeout:N!=null&&N.timeout?String(N.timeout):""}}c(P)}catch{t("error","Failed to load LLM configuration")}finally{l(!1)}},[t]);n.useEffect(()=>{I()},[I]);const w=(r,E,P)=>{c(B=>({...B,[r]:{...B[r],[E]:P}}))},v=async r=>{var E;S(r);try{const P=y[r],B={};B[r]={model:P.activeModel||P.model.trim(),models:P.models.filter(N=>N.trim()),activeModel:P.activeModel||P.models[0]||"",baseUrl:P.baseUrl.trim(),timeout:P.timeout?parseInt(P.timeout,10):null},P.apiKey&&P.apiKey!==He&&(B[r].apiKey=P.apiKey),await rt({defaultProvider:h,defaultModel:f||null,providers:B}),t("success",`${(E=Bs.find(N=>N.id===r))==null?void 0:E.label} settings saved`),await I()}catch(P){t("error",`Failed to save: ${P}`)}finally{S(null)}},x=async r=>{M(E=>({...E,[r]:!0})),U(E=>{const P={...E};return delete P[r],P});try{const E=y[r],P=await wa({provider:r,apiKey:E.apiKey&&E.apiKey!==He?E.apiKey:void 0,baseUrl:E.baseUrl||void 0,model:E.model||void 0});U(B=>({...B,[r]:{ok:P.connected,msg:P.message,latency:P.latencyMs}}))}catch(E){U(P=>({...P,[r]:{ok:!1,msg:String(E)}}))}finally{M(E=>({...E,[r]:!1}))}},o=r=>{const E=m==null?void 0:m.providers[r];return r==="testver"?E!=null&&E.hasApiKey?{label:"Connected",color:"text-emerald-400",dot:"bg-emerald-400"}:{label:"Not Connected",color:"text-gray-500",dot:"bg-gray-500"}:E?E.isLocal?{label:"Local",color:"text-amber-400",dot:"bg-amber-400"}:E.apiKeySource==="env"?{label:"Env Var",color:"text-emerald-400",dot:"bg-emerald-400"}:E.apiKeySource==="config"?{label:"Configured",color:"text-emerald-400",dot:"bg-emerald-400"}:{label:"Not Configured",color:"text-gray-500",dot:"bg-gray-500"}:{label:"Not Configured",color:"text-gray-500",dot:"bg-gray-500"}};return a?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-gray-500 text-sm",children:[e.jsx(J,{size:16,className:"animate-spin"}),"Loading LLM configuration..."]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5 px-1",children:[e.jsx(Ee,{size:16,className:"text-brand-400"}),"Providers"]}),Bs.filter(r=>(s||r.id==="testver")&&!hn.has(r.id)).map(r=>{const E=j===r.id,P=o(r.id),B=y[r.id],N=m==null?void 0:m.providers[r.id],ee=r.id==="testver";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden transition-all",children:[e.jsxs("button",{onClick:()=>p(E?null:r.id),className:"w-full flex items-center gap-3.5 px-6 py-4 hover:bg-surface-2/30 transition-colors text-left",children:[e.jsx("span",{className:"flex-shrink-0",children:e.jsx(pn,{provider:r.id,size:26})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-[15px] font-semibold text-gray-200",children:r.label}),h===r.id&&e.jsx("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-400 border border-amber-500/20",children:"DEFAULT"})]}),e.jsxs("span",{className:"text-sm text-gray-500 block mt-0.5",children:[r.description,r.id==="testver"&&!(N!=null&&N.hasApiKey)?". Try it for free — click Connect to link your testver.com account":""]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 flex-shrink-0",children:[s&&e.jsx("span",{onClick:async K=>{if(K.stopPropagation(),h!==r.id){d(r.id);try{await rt({defaultProvider:r.id}),t("success",`${r.label} set as default provider`),await I(!0)}catch{}}},className:`p-1 rounded-lg transition-colors ${h===r.id?"text-amber-400":"text-gray-800/30 hover:text-amber-400/50 cursor-pointer"}`,title:h===r.id?"Default provider":`Set ${r.label} as default`,children:e.jsx(gs,{size:15,className:h===r.id?"fill-amber-400":""})}),e.jsxs("span",{className:`flex items-center gap-1.5 text-sm font-medium ${P.color}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${P.dot}`}),P.label]}),E?e.jsx(Me,{size:18,className:"text-gray-500"}):e.jsx(Ie,{size:18,className:"text-gray-500"})]})]}),E&&e.jsxs("div",{className:"px-6 pb-6 pt-3 border-t border-white/5 space-y-4",children:[r.id==="testver"&&e.jsx(Bl,{connected:!!(N!=null&&N.hasApiKey),isSystemAdmin:(N==null?void 0:N.isSystemAdmin)!==!1,onConnected:()=>void I(!0)}),!ee&&e.jsxs(e.Fragment,{children:[r.requiresKey&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm text-gray-400 block mb-1.5",children:["API Key",(N==null?void 0:N.apiKeySource)==="config"&&B.apiKey===He&&e.jsx("span",{className:"ml-2 text-gray-600 font-normal",children:"(saved — click to change)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:u[r.id]?"text":"password",value:B.apiKey,onChange:K=>w(r.id,"apiKey",K.target.value),onFocus:()=>{B.apiKey===He&&w(r.id,"apiKey","")},onBlur:()=>{!B.apiKey&&(N!=null&&N.hasApiKey)&&w(r.id,"apiKey",He)},placeholder:"Enter API key",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 pr-10 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>b(K=>({...K,[r.id]:!K[r.id]})),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:u[r.id]?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]}),(N==null?void 0:N.apiKeySource)==="env"&&N.envVarName&&e.jsxs("p",{className:"text-xs text-amber-500/80 mt-1 flex items-center gap-1",children:[e.jsx(Ee,{size:12}),"Set via environment variable ",e.jsx("span",{className:"font-mono",children:N.envVarName})]})]}),r.id==="testver"?e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Model"}),e.jsx("p",{className:"text-sm text-gray-500 bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5",children:"Managed by Testver — your plan's AI model is selected automatically. No configuration needed."})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Models"}),B.models.length===0&&e.jsxs("p",{className:"text-sm text-gray-500 mb-2",children:["No models yet — add the model names you use with ",r.label,"."]}),e.jsx("div",{className:`flex flex-wrap gap-1.5 ${B.models.length?"mb-2":""}`,children:B.models.map(K=>{const W=K===B.activeModel;return e.jsxs("div",{className:`flex items-center gap-1.5 pl-2 pr-1 py-1 rounded-lg text-sm font-mono transition-all ${W?"bg-brand-500/15 border border-brand-500/40 text-brand-300":"bg-surface-2 border border-white/10 text-gray-400"}`,children:[e.jsx("button",{onClick:()=>{c(R=>({...R,[r.id]:{...R[r.id],activeModel:K,model:K}}))},className:`p-0.5 rounded transition-colors ${W?"text-brand-400":"text-gray-600 hover:text-amber-400"}`,title:W?"Active model":"Set as active",children:e.jsx(gs,{size:12,className:W?"fill-current":""})}),e.jsx("span",{className:"truncate max-w-[200px]",children:K}),e.jsx("button",{onClick:()=>{const R=B.models.filter(_=>_!==K),G=W?R[0]||"":B.activeModel;c(_=>({..._,[r.id]:{..._[r.id],models:R,activeModel:G,model:G}}))},className:"p-0.5 rounded text-gray-600 hover:text-red-400 transition-colors",title:"Remove model",children:e.jsx(me,{size:11})})]},K)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:B.newModel,onChange:K=>c(W=>({...W,[r.id]:{...W[r.id],newModel:K.target.value}})),onKeyDown:K=>{if(K.key==="Enter"&&B.newModel.trim()){K.preventDefault();const W=B.newModel.trim();if(!B.models.includes(W)){const R=[...B.models,W];c(G=>({...G,[r.id]:{...G[r.id],models:R,newModel:"",activeModel:G[r.id].activeModel||W,model:G[r.id].activeModel||W}}))}}},placeholder:`Add model — its exact name in ${r.label}`,className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>{const K=B.newModel.trim();if(K&&!B.models.includes(K)){const W=[...B.models,K];c(R=>({...R,[r.id]:{...R[r.id],models:W,newModel:"",activeModel:R[r.id].activeModel||K,model:R[r.id].activeModel||K}}))}},disabled:!B.newModel.trim(),className:"px-3 py-2 rounded-lg text-sm font-medium text-brand-300 bg-brand-500/10 border border-brand-500/20 hover:bg-brand-500/20 transition-colors disabled:opacity-30",children:e.jsx(je,{size:14})})]}),B.models.length>0&&e.jsxs("p",{className:"text-xs text-gray-600 mt-1.5",children:[e.jsx(gs,{size:10,className:"inline fill-brand-400 text-brand-400 -mt-0.5"})," marks the active model. Click the star to switch."]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm text-gray-400 block mb-1.5",children:["Base URL ",!r.requiresKey&&e.jsx("span",{className:"text-gray-600 font-normal",children:"(required for local providers)"})]}),e.jsx("input",{value:B.baseUrl,onChange:K=>w(r.id,"baseUrl",K.target.value),placeholder:(N==null?void 0:N.defaultBaseUrl)||"Default (cloud endpoint)",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),!B.baseUrl&&(N==null?void 0:N.baseUrl)&&e.jsxs("p",{className:"text-xs text-gray-500 mt-1 flex items-center gap-1",children:["Active: ",e.jsx("span",{className:"font-mono",children:N.baseUrl}),N.baseUrl!==N.defaultBaseUrl?" (from env)":" (default)"]}),B.baseUrl&&(N==null?void 0:N.defaultBaseUrl)&&e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["Default: ",N.defaultBaseUrl]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Timeout (ms)"}),e.jsx("input",{value:B.timeout,onChange:K=>w(r.id,"timeout",K.target.value.replace(/\D/g,"")),placeholder:r.requiresKey?"60000":"300000",className:"w-52 bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["Leave blank for default (",r.requiresKey?"60s":"5 min",")"]})]}),V[r.id]&&e.jsxs("div",{className:`flex items-center gap-2 text-[15px] px-4 py-2.5 rounded-lg ${V[r.id].ok?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,children:[V[r.id].ok?e.jsx(ze,{size:16}):e.jsx(Se,{size:16}),e.jsx("span",{className:"flex-1",children:V[r.id].msg}),V[r.id].latency&&e.jsxs("span",{className:"text-sm opacity-70",children:[V[r.id].latency,"ms"]})]}),e.jsxs("div",{className:"flex gap-2.5 pt-2 border-t border-white/5",children:[e.jsxs("button",{onClick:()=>x(r.id),disabled:z[r.id],className:"flex items-center gap-2 px-4 py-2 text-[15px] rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5 disabled:opacity-40 transition-colors",children:[z[r.id]?e.jsx(J,{size:16,className:"animate-spin"}):e.jsx(Ee,{size:16}),"Test Connection"]}),e.jsxs("button",{onClick:()=>v(r.id),disabled:O===r.id,className:"flex items-center gap-2 px-5 py-2 text-[15px] rounded-lg bg-brand-600 hover:bg-brand-500 text-white font-medium disabled:opacity-40 transition-colors",children:[O===r.id?e.jsx(J,{size:16,className:"animate-spin"}):e.jsx(ze,{size:16}),"Save ",r.label]})]})]})]})]},r.id)})]})})}export{no as SettingsPage};
|
|
1
|
+
import{r as n,j as e,d as fe,L as os,n as Zt,R as er,u as sr}from"./vendor-react-DOVfxdUy.js";import{a as Ct}from"./formatDate-T65-Y6Mi.js";import{a as Je,u as Ge,c as Ze}from"./vendor-query-DkZSMtfn.js";import{b as ge,aa as tr,de as rr,a9 as ar,df as nr,c4 as St,dg as lr,h as or,P as ir,dh as dr,di as cr,dj as xr,ae as ws,ab as mr,dk as ur,dl as Es,dm as hr,dn as pr,dp as gr,dq as br,dr as fr,ds as yr,dt as jr,du as vr,ac as Nr,dv as wr,dw as kr,dx as Cr,dy as Sr,at as Tr,dz as st,dA as Ar,dB as zr,dC as Er,dD as Pr,dE as Lr,dF as $r,dG as Rr,dH as Mr,dI as Dr,dJ as Fr,j as Ys,dK as Ir,dL as ms,dM as Or,dN as Ur,dO as Br,dP as Kr,dQ as _r,dR as Hr,dS as Tt,dT as Vr,dU as Gr,dV as Wr,dW as qr,dX as Jr,dY as Yr,x as ks,dZ as Qr,d_ as Xr,d$ as Zr,e0 as ea,e1 as sa,y as At,e2 as ta,e3 as ra,e4 as aa,e5 as na,S as la,X as oa,e6 as ia,e7 as da,bO as ca,v as xa,e8 as ma,e9 as tt,ad as ua,ea as rt,eb as ha,ec as pa,ed as ga,ee as ba,ef as fa,eg as at,eh as nt,c3 as lt,d as ya,ei as ot,ej as it,ek as ja,el as va,em as Na,en as wa,eo as ka,ep as Ca,eq as Sa,er as Ta,es as Aa}from"./index-BlA8ntjb.js";import{G as za,p as ue,s as ne,bD as zt,aK as Ea,cl as Pa,aT as ts,ab as ve,X as me,a1 as J,b1 as Et,be as bs,j as dt,f as La,C as ze,S as Te,w as Ks,b5 as je,ao as fs,b8 as we,bP as $a,z as Me,bm as Qs,cJ as ys,cK as We,a6 as Pt,bL as Lt,Z as Ee,bu as Ra,V as js,ah as Ue,a8 as Pe,a as Ye,aq as Se,P as ct,m as Ma,cL as $t,b7 as Cs,u as Ie,by as Rt,$ as Ss,c as Ts,O as cs,cc as Da,N as Fa,cM as Ia,a7 as _s,a0 as Oa,bx as Ua,cN as Ba,cO as Ka,av as _a,a2 as Ha,cP as Va,cQ as Ga,g as Wa,ad as Mt,aD as qa,K as Oe,cR as Ja,R as $e,F as rs,e as As,cS as vs,bK as Ya,aa as is,aA as Qa,b_ as Xa,cT as Ve,cU as Hs,v as zs,cV as qe,ba as ds,bz as Za,cW as Vs,ai as xs,b9 as Ns,a3 as Xs,au as Dt,cb as en,ca as sn,k as as,I as Ps,aC as tn,cX as rn,aG as an,b3 as Ft,a9 as nn,cn as ln,cY as xt,b6 as gs,cZ as on,ck as dn,U as cn,am as xn}from"./vendor-icons-Cm92aSc5.js";import{u as mt}from"./useTabParam-CyYAP90W.js";import{B as mn,a as ns}from"./RunTargets-CkIpY3v3.js";import{r as It}from"./simpleMarkdown-kWs-10D8.js";import{s as un}from"./visibleInterval-BKsLfJZ3.js";import{A as hn}from"./AccessTokensTab-BdevOmpE.js";import{u as pn}from"./useFeatureFlags-B4Otsv-N.js";import{C as Ot}from"./ConfirmDialog-D_N9188T.js";import{H as gn,P as bn}from"./hiddenLlmProviders-BPORgy-e.js";import{h as Ls}from"./aiHandoff-vhtR29Fh.js";import{u as fn,c as yn,d as jn,e as vn,f as Nn}from"./useOwnership-BhPOiYzy.js";import{u as wn,b as kn}from"./TestverCreditsRing-CoDk5eAS.js";import{T as Cn}from"./TestverCreditsDetail-BKpt4oLW.js";import"./clipboard-BIEd7Ccc.js";const Sn=[[0,"Off"],[5,"Every 5 min"],[15,"Every 15 min"],[60,"Every hour"]];function us({on:s,onChange:t,label:a}){return e.jsx("button",{role:"switch","aria-checked":s,"aria-label":a,onClick:()=>t(!s),className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors mt-1 disabled:opacity-50 ${s?"bg-brand-500":"bg-surface-3"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-1"}`})})}function Tn(){const{toast:s}=ge(),t=Je(),a=tr(),{data:l}=Ge({queryKey:["git-status"],queryFn:rr,staleTime:3e4}),m=l!==void 0&&l.available!==!0,{data:i}=ar(a),h=nr(),[d,f]=n.useState(null),[g,y]=n.useState(""),[c,j]=n.useState("1"),{data:p}=Ge({queryKey:["connectors"],queryFn:St,staleTime:6e4}),u=Array.isArray(p)?p:(p==null?void 0:p.connectors)??[],b=u.filter(v=>v.type==="slack"&&v.status==="connected"),z=u.filter(v=>v.type==="email"&&v.status==="connected"),M=n.useCallback(()=>{lr().then(v=>{f(v),y(v.emailRecipients.join(", ")),j(String(v.notifyMinCommits))}).catch(()=>{})},[]);n.useEffect(()=>{M()},[M]);const V=(v,x)=>{f(o=>o&&{...o,...v}),xr(v).then(o=>{f(o),y(o.emailRecipients.join(", ")),j(String(o.notifyMinCommits)),t.invalidateQueries({queryKey:["git-remote-updates"]}),s("success",x??"Remote updates saved")}).catch(o=>{s("error",`Could not save: ${o.message}`),M()})};if(!d)return null;const U=i==null?void 0:i.check,O=or(U),S=()=>{const v=g.split(/[\s,;]+/).map(x=>x.trim()).filter(Boolean);v.join(",")!==d.emailRecipients.join(",")&&V({emailRecipients:v},"Recipients saved")},I=()=>{const v=Math.round(Number(c));if(!Number.isFinite(v)||v<1||v>100){j(String(d.notifyMinCommits)),s("error","Use a number from 1 to 100");return}v!==d.notifyMinCommits&&V({notifyMinCommits:v})},w=(v,x,o)=>e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:v}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:x})]}),o]});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(za,{size:18,className:"text-sky-500"}),"Remote updates",e.jsx("span",{className:"text-[11px] font-medium px-2 py-0.5 rounded-full bg-sky-500/10 text-sky-500 border border-sky-500/20",title:"These settings apply only when the project is a Git repository",children:"Git projects only"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:"For projects kept in a Git repository: Testver checks the remote (GitHub, GitLab, Bitbucket, Azure DevOps or any git server) for new commits on the branch this server is on, tells you before they surprise you, and predicts whether pulling them will conflict with local work. A check only downloads — your files never change until someone pulls."})]}),m&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3.5 py-2.5 text-sm text-gray-400",children:[e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0 text-amber-500"}),e.jsxs("span",{children:[e.jsx("b",{className:"text-gray-300",children:"This project isn't a Git repository"}),", so there is nothing to check. These settings take effect once it is — for example after you clone the project with git, or set it up on the Git page."]})]}),a&&U&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-white/10 bg-surface-2/40 px-3.5 py-2.5 text-sm text-gray-400",children:[U.ok?e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}):e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0 text-amber-500"}),e.jsxs("span",{children:["Last check ",ir(U.checkedAt),":"," ",U.skipped?e.jsxs("b",{className:"text-gray-300",children:["nothing to check (",U.skipped==="unpublished"?"the branch isn't published":U.skipped==="detached"?"not on a branch":U.skipped==="operation"?"a merge or rebase is in progress":"no remote",")"]}):U.ok?U.behind>0?e.jsxs("b",{className:"text-gray-300",children:[U.upstream," has ",dr(U.behind,"new commit")]}):e.jsxs("b",{className:"text-gray-300",children:["up to date with ",U.upstream]}):e.jsxs("b",{className:"text-gray-300",children:["couldn't reach ",O]}),i!=null&&i.nextCheckAt?e.jsxs(e.Fragment,{children:[" · next check ",cr(i.nextCheckAt)]}):null," · ",e.jsx("button",{onClick:()=>h.mutate(void 0,{onError:v=>s("error",v.message)}),className:"text-sky-600 hover:underline",disabled:h.isPending,children:h.isPending?"Checking…":"Check now"})]})]}),w("Check for new commits","How often to look. Checks pause while a merge or rebase is in progress and on branches that aren't published.",e.jsx("div",{role:"group",className:"inline-flex rounded-lg border border-white/10 bg-white dark:bg-surface-2 overflow-hidden flex-shrink-0",children:Sn.map(([v,x],o)=>e.jsx("button",{onClick:()=>v!==d.intervalMinutes&&V({intervalMinutes:v},v?`Checks every ${v===60?"hour":`${v} minutes`}`:"Remote checks turned off"),className:`px-3.5 py-1.5 text-sm font-medium transition-colors ${o?"border-l border-white/10":""} ${d.intervalMinutes===v?"bg-sky-500/15 text-sky-700 dark:text-sky-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,children:x},v))})),e.jsx("div",{className:"border-t border-white/5"}),w("Warn before test runs","When the branch is behind, a run first asks “Pull, then run / Run anyway” — and says which incoming commits change files the tests use.",e.jsx(us,{on:d.warnBeforeRuns,label:"Warn before test runs",onChange:v=>V({warnBeforeRuns:v})})),w("Tell the AI Assistant","The assistant mentions when a file it is working on is newer on the remote.",e.jsx(us,{on:d.tellAI,label:"Tell the AI Assistant",onChange:v=>V({tellAI:v})})),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Notifications"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"Sent once per new set of commits that meets the rule below. The Git page, the header and the sidebar always show new commits."}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(us,{on:d.emailEnabled,label:"E-mail notifications",onChange:v=>V({emailEnabled:v})}),e.jsx(zt,{size:15,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-300 w-20",children:"Email"}),e.jsx("input",{value:g,onChange:v=>y(v.target.value),onBlur:S,onKeyDown:v=>{v.key==="Enter"&&S()},placeholder:"qa-team@example.com, lead@example.com",className:"flex-1 min-w-[16rem] bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-sm text-gray-200 focus:outline-none focus:border-sky-500/50"})]}),d.emailEnabled&&z.length===0&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 ml-12",children:"No e-mail connector is connected — add one in Connectors, or nothing can be sent."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(us,{on:d.slackEnabled,label:"Slack notifications",onChange:v=>V({slackEnabled:v})}),e.jsx(Ea,{size:15,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-300 w-20",children:"Slack"}),e.jsx("span",{className:"flex-1 text-sm text-gray-400",children:b.length===0?"No Slack connector is connected — add one in Connectors.":e.jsxs(e.Fragment,{children:["Posts to ",b.map((v,x)=>{var o;return e.jsxs("b",{className:"text-gray-300",children:[x?", ":"",(o=v.config)!=null&&o.channel?`#${String(v.config.channel).replace(/^#/,"")}`:v.name||"Slack"]},v.id??x)})]})})]}),e.jsxs("div",{className:"flex items-start gap-3 flex-wrap",children:[e.jsx("span",{className:"w-9"}),e.jsx(Pa,{size:15,className:"text-gray-500 mt-1.5"}),e.jsx("span",{className:"text-sm text-gray-300 w-20 mt-1",children:"Notify when"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-300",children:["At least",e.jsx("input",{value:c,onChange:v=>j(v.target.value.replace(/[^\d]/g,"")),onBlur:I,onKeyDown:v=>{v.key==="Enter"&&I()},inputMode:"numeric","aria-label":"Minimum new commits",className:"w-16 bg-surface-2 border border-white/10 rounded-lg px-2 py-1.5 text-sm text-gray-200 text-center focus:outline-none focus:border-sky-500/50"}),"new commit(s)"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-400",children:[e.jsx("input",{type:"checkbox",checked:d.notifyOnlyRisky,onChange:v=>V({notifyOnlyRisky:v.target.checked}),className:"rounded border-white/20"}),"Only when pulling would conflict or touch uncommitted work"]})]})]})]})]})]})}const ut=s=>`---
|
|
2
|
+
name: My Custom Skill
|
|
3
|
+
slug: my-custom-skill
|
|
4
|
+
description: Describe what this skill teaches the AI
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
author: ${s}
|
|
7
|
+
tags:
|
|
8
|
+
- testing
|
|
9
|
+
- custom
|
|
10
|
+
frameworks:
|
|
11
|
+
- playwright
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# My Custom Skill
|
|
15
|
+
|
|
16
|
+
## Overview
|
|
17
|
+
Describe the purpose and context for this skill here.
|
|
18
|
+
|
|
19
|
+
## Best Practices
|
|
20
|
+
- Practice 1
|
|
21
|
+
- Practice 2
|
|
22
|
+
- Practice 3
|
|
23
|
+
|
|
24
|
+
## Code Patterns
|
|
25
|
+
When generating code for this workflow, follow these patterns:
|
|
26
|
+
|
|
27
|
+
\`\`\`typescript
|
|
28
|
+
// Example code pattern
|
|
29
|
+
\`\`\`
|
|
30
|
+
|
|
31
|
+
## Common Mistakes to Avoid
|
|
32
|
+
1. Mistake 1 — explanation
|
|
33
|
+
2. Mistake 2 — explanation
|
|
34
|
+
`;function An({isOpen:s,onClose:t,onSave:a,initialContent:l,initialSlug:m,title:i}){const{user:h}=ws(),d=(h==null?void 0:h.displayName)||(h==null?void 0:h.username)||"Your Name",[f,g]=n.useState(l||ut(d)),[y,c]=n.useState(!1),[j,p]=n.useState(null),[u,b]=n.useState(!1);if(n.useEffect(()=>{s&&(g(l||ut(d)),p(null),b(!1))},[s,l,d]),!s)return null;const z=!!m,M=i||(z?`Edit Skill: ${m}`:"Create Custom Skill"),V=()=>{const I=f.split(`
|
|
35
|
+
`),w={};let v=!1,x=0;for(let r=0;r<I.length;r++){const E=I[r].trim();if(E==="---"){if(v){x=r+1;break}v=!0;continue}if(v&&E.includes(":")&&!E.startsWith("-")){const P=E.indexOf(":"),B=E.slice(0,P).trim(),N=E.slice(P+1).trim();N&&(w[B]=N)}}const o=I.slice(x).join(`
|
|
36
|
+
`).trim();return{meta:w,body:o}},U=async()=>{c(!0),p(null);try{await a(f,m),t()}catch(I){p(String(I))}finally{c(!1)}},{meta:O,body:S}=V();return fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-4xl mx-4 h-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-white/5 flex items-center justify-between flex-shrink-0",children:[e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:M}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>b(!u),className:`
|
|
37
|
+
flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg transition-colors
|
|
38
|
+
${u?"bg-cyan-500/15 text-cyan-300":"bg-surface-2 text-gray-400 hover:text-gray-300"}
|
|
39
|
+
`,children:[u?e.jsx(ts,{size:14}):e.jsx(ve,{size:14}),u?"Editor":"Preview"]}),e.jsx("button",{onClick:t,className:"text-gray-500 hover:text-gray-300 transition-colors p-1",children:e.jsx(me,{size:18})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:u?e.jsxs("div",{className:"h-full overflow-y-auto p-6",children:[(O.name||O.description)&&e.jsxs("div",{className:"mb-6 p-4 rounded-lg bg-surface-2/50 border border-white/5",children:[O.name&&e.jsx("h2",{className:"text-lg font-semibold text-gray-200 mb-1",children:O.name}),O.description&&e.jsx("p",{className:"text-sm text-gray-400",children:O.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-gray-500",children:[O.version&&e.jsxs("span",{children:["v",O.version]}),O.author&&e.jsxs("span",{children:["by ",O.author]})]})]}),e.jsx("div",{className:"skill-markdown-preview text-sm text-gray-300 leading-relaxed",dangerouslySetInnerHTML:{__html:It(S)}})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"px-6 py-2 bg-surface-2/30 border-b border-white/5 text-xs text-gray-500 flex-shrink-0",children:["Write YAML frontmatter between ",e.jsx("code",{className:"text-cyan-400/80",children:"---"})," delimiters, then markdown body below.",z&&e.jsx("span",{className:"ml-2 text-amber-400/80",children:"Editing existing skill — slug cannot be changed."})]}),e.jsx("textarea",{value:f,onChange:I=>g(I.target.value),className:"flex-1 w-full bg-transparent text-gray-300 font-mono text-[13px] leading-relaxed p-6 resize-none focus:outline-none",spellCheck:!1,placeholder:"Paste or write your SKILL.md content here..."})]})}),j&&e.jsxs("div",{className:"px-6 py-3 bg-red-500/10 border-t border-red-500/20 flex items-center gap-2 flex-shrink-0",children:[e.jsx(ue,{size:14,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-red-300",children:j})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{className:"text-xs text-gray-500",children:[f.length.toLocaleString()," chars · ~",Math.round(f.length/4).toLocaleString()," tokens"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:U,disabled:y||!f.trim(),className:"px-4 py-2 text-sm rounded-lg bg-cyan-600 hover:bg-cyan-500 text-white font-medium transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",children:[y?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Et,{size:14}),z?"Update Skill":"Create Skill"]})]})]})]})}),document.body)}function zn({isOpen:s,onClose:t,onImport:a,onImportUrl:l}){const[m,i]=n.useState("file"),[h,d]=n.useState(""),[f,g]=n.useState(""),[y,c]=n.useState(""),[j,p]=n.useState(!1),[u,b]=n.useState(null),[z,M]=n.useState(!1),V=n.useRef(null);if(!s)return null;const U=async v=>{if(!v.name.endsWith(".md")){b("Please select a .md (Markdown) file");return}try{const x=await v.text();d(x),g(v.name),b(null)}catch(x){b(`Failed to read file: ${x}`)}},O=v=>{v.preventDefault(),M(!1);const x=v.dataTransfer.files[0];x&&U(x)},S=v=>{var o;const x=(o=v.target.files)==null?void 0:o[0];x&&U(x)},I=async()=>{if(m==="url"){if(!y.trim()){b("Please enter a GitHub URL");return}if(!l){b("URL import is not available");return}p(!0),b(null);try{await l(y.trim()),t()}catch(v){b(String(v))}finally{p(!1)}return}if(!h.trim()){b("No content to import. Drop a file or paste content.");return}p(!0),b(null);try{await a(h,f||void 0),t()}catch(v){b(String(v))}finally{p(!1)}},w=m==="url"?y.trim().length>0:h.trim().length>0;return fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-lg mx-4 overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-white/5 flex items-center justify-between",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-200 flex items-center gap-2",children:[e.jsx(bs,{size:18,className:"text-cyan-400"}),"Import Skill"]}),e.jsx("button",{onClick:t,className:"text-gray-500 hover:text-gray-300 transition-colors p-1",children:e.jsx(me,{size:18})})]}),e.jsxs("div",{className:"px-6 pt-4 flex gap-1 bg-surface-2/30 rounded-lg mx-6 mt-4 p-1",children:[e.jsxs("button",{onClick:()=>{i("file"),b(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-md transition-colors ${m==="file"?"bg-surface-1 text-gray-200 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:[e.jsx(dt,{size:14}),"File / Paste"]}),e.jsxs("button",{onClick:()=>{i("url"),b(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-md transition-colors ${m==="url"?"bg-surface-1 text-gray-200 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:[e.jsx(La,{size:14}),"GitHub URL"]})]}),e.jsx("div",{className:"px-6 py-4",children:m==="file"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{onDragOver:v=>{v.preventDefault(),M(!0)},onDragLeave:()=>M(!1),onDrop:O,onClick:()=>{var v;return(v=V.current)==null?void 0:v.click()},className:`
|
|
40
|
+
border-2 border-dashed rounded-xl p-8 text-center cursor-pointer transition-all
|
|
41
|
+
${z?"border-cyan-400 bg-cyan-500/5":h?"border-emerald-500/30 bg-emerald-500/5":"border-white/10 hover:border-white/20 bg-surface-2/30"}
|
|
42
|
+
`,children:[e.jsx("input",{ref:V,type:"file",accept:".md",onChange:S,className:"hidden"}),h?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:28,className:"mx-auto mb-2 text-emerald-400"}),e.jsx("p",{className:"text-sm text-emerald-300 font-medium",children:f||"Content loaded"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[h.length.toLocaleString()," chars · Click to change file"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{size:28,className:"mx-auto mb-2 text-gray-500"}),e.jsxs("p",{className:"text-sm text-gray-400",children:["Drop a ",e.jsx("code",{className:"text-cyan-400/80",children:".md"})," file here or click to browse"]}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"SKILL.md format: YAML frontmatter + Markdown body"})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"flex-1 h-px bg-white/5"}),e.jsx("span",{className:"text-xs text-gray-600",children:"or paste content"}),e.jsx("div",{className:"flex-1 h-px bg-white/5"})]}),e.jsx("textarea",{value:h,onChange:v=>{d(v.target.value),g(""),b(null)},placeholder:"Paste SKILL.md content here...",rows:6,className:"w-full bg-surface-2/50 border border-white/5 rounded-lg p-3 text-sm text-gray-300 font-mono placeholder-gray-600 focus:outline-none focus:border-cyan-500/30 resize-none"})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-2",children:"GitHub URL"}),e.jsx("input",{type:"url",value:y,onChange:v=>{c(v.target.value),b(null)},placeholder:"https://github.com/user/repo/blob/main/skills/my-skill.md",className:"w-full bg-surface-2/50 border border-white/5 rounded-lg px-3 py-2.5 text-sm text-gray-300 placeholder-gray-600 focus:outline-none focus:border-cyan-500/30"})]}),e.jsxs("div",{className:"bg-surface-2/30 rounded-lg p-3 space-y-1.5",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Supported URL formats:"}),e.jsxs("ul",{className:"text-xs text-gray-600 space-y-1 ml-4 list-disc",children:[e.jsx("li",{children:e.jsx("code",{className:"text-cyan-400/60",children:"github.com/user/repo/blob/branch/path.md"})}),e.jsx("li",{children:e.jsx("code",{className:"text-cyan-400/60",children:"raw.githubusercontent.com/user/repo/branch/path.md"})}),e.jsx("li",{children:e.jsx("code",{className:"text-cyan-400/60",children:"gist.github.com/user/id/raw/file.md"})})]})]})]})}),u&&e.jsxs("div",{className:"px-6 py-3 bg-red-500/10 border-t border-red-500/20 flex items-center gap-2",children:[e.jsx(ue,{size:14,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-red-300",children:u})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:I,disabled:j||!w,className:"px-4 py-2 text-sm rounded-lg bg-cyan-600 hover:bg-cyan-500 text-white font-medium transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",children:[j?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(bs,{size:14}),m==="url"?"Import from URL":"Import"]})]})]})}),document.body)}function En({tags:s,value:t,onChange:a}){const[l,m]=n.useState(!1),[i,h]=n.useState(""),d=n.useRef(null);n.useEffect(()=>{if(!l)return;const c=p=>{d.current&&!d.current.contains(p.target)&&m(!1)},j=p=>{p.key==="Escape"&&m(!1)};return document.addEventListener("mousedown",c),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",j)}},[l]);const f=n.useMemo(()=>s.filter(c=>c.toLowerCase().includes(i.trim().toLowerCase())),[s,i]),g=c=>{a(c),m(!1),h("")},y=t==="all"?"All Tags":t;return e.jsxs("div",{className:"relative",ref:d,children:[e.jsxs("button",{type:"button",onClick:()=>m(c=>!c),className:"flex items-center gap-2 bg-surface-1 border border-white/10 rounded-lg pl-3 pr-2.5 py-2 text-sm text-gray-300 focus:outline-none focus:border-cyan-500/50 hover:border-white/20 transition-colors min-w-[150px]",children:[e.jsx($a,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"flex-1 text-left truncate",children:y}),e.jsx(Me,{size:14,className:`text-gray-500 flex-shrink-0 transition-transform ${l?"rotate-180":""}`})]}),l&&e.jsxs("div",{className:"absolute left-0 z-30 mt-1.5 w-[230px] rounded-lg border border-white/10 bg-surface-1 shadow-xl overflow-hidden",children:[e.jsx("div",{className:"p-2 border-b border-white/5",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ks,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{autoFocus:!0,type:"text",value:i,onChange:c=>h(c.target.value),placeholder:"Search tags...",className:"w-full bg-surface-2 border border-white/10 rounded-md pl-8 pr-2 py-1.5 text-xs text-gray-200 placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"})]})}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[e.jsx(ht,{label:"All Tags",active:t==="all",onClick:()=>g("all")}),f.length===0?e.jsx("div",{className:"px-3 py-3 text-xs text-gray-500 text-center",children:"No tags found"}):f.map(c=>e.jsx(ht,{label:c,active:t===c,onClick:()=>g(c)},c))]})]})]})}function ht({label:s,active:t,onClick:a}){return e.jsxs("button",{type:"button",onClick:a,className:`w-full flex items-center gap-2 px-3 py-1.5 text-sm text-left transition-colors ${t?"bg-cyan-500/10 text-cyan-300":"text-gray-300 hover:bg-white/5"}`,children:[e.jsx(Ue,{size:13,className:`flex-shrink-0 ${t?"text-cyan-400":"text-transparent"}`}),e.jsx("span",{className:"truncate",children:s})]})}const Pn={testing:{text:"text-emerald-400",bg:"bg-transparent",border:"border-emerald-500/30"},browser:{text:"text-blue-400",bg:"bg-transparent",border:"border-blue-500/30"},e2e:{text:"text-violet-400",bg:"bg-transparent",border:"border-violet-500/30"},unit:{text:"text-amber-400",bg:"bg-transparent",border:"border-amber-500/30"},integration:{text:"text-orange-400",bg:"bg-transparent",border:"border-orange-500/30"},bdd:{text:"text-pink-400",bg:"bg-transparent",border:"border-pink-500/30"},gherkin:{text:"text-pink-400",bg:"bg-transparent",border:"border-pink-500/30"},python:{text:"text-yellow-400",bg:"bg-transparent",border:"border-yellow-500/30"},java:{text:"text-red-400",bg:"bg-transparent",border:"border-red-500/30"},javascript:{text:"text-amber-400",bg:"bg-transparent",border:"border-amber-500/30"},cicd:{text:"text-teal-400",bg:"bg-transparent",border:"border-teal-500/30"},devops:{text:"text-teal-400",bg:"bg-transparent",border:"border-teal-500/30"},codegen:{text:"text-cyan-400",bg:"bg-transparent",border:"border-cyan-500/30"},pom:{text:"text-indigo-400",bg:"bg-transparent",border:"border-indigo-500/30"},analysis:{text:"text-fuchsia-400",bg:"bg-transparent",border:"border-fuchsia-500/30"},healing:{text:"text-rose-400",bg:"bg-transparent",border:"border-rose-500/30"},debugging:{text:"text-fuchsia-400",bg:"bg-transparent",border:"border-fuchsia-500/30"},pipeline:{text:"text-teal-400",bg:"bg-transparent",border:"border-teal-500/30"},"page-object":{text:"text-indigo-400",bg:"bg-transparent",border:"border-indigo-500/30"},results:{text:"text-sky-400",bg:"bg-transparent",border:"border-sky-500/30"},selectors:{text:"text-rose-400",bg:"bg-transparent",border:"border-rose-500/30"},maintenance:{text:"text-gray-400",bg:"bg-transparent",border:"border-gray-500/30"},custom:{text:"text-purple-400",bg:"bg-transparent",border:"border-purple-500/30"}};function Ut(s){return Pn[s]||{text:"text-gray-400",bg:"bg-transparent",border:"border-gray-500/30"}}function Ln({readOnly:s=!1}={}){const{toast:t}=ge(),[a,l]=n.useState([]),[m,i]=n.useState(!0),[h,d]=n.useState(""),[f,g]=n.useState("all"),[y,c]=n.useState("all"),[j,p]=n.useState(null),[u,b]=n.useState(null),[z,M]=n.useState(!1),[V,U]=n.useState(new Set),[O,S]=n.useState(!1),[I,w]=n.useState(!1),[v,x]=n.useState(),[o,r]=n.useState(),[E,P]=n.useState(),[B,N]=n.useState(!1),[ee,K]=n.useState(null),W=n.useCallback(async()=>{try{i(!0);const F=await mr();l(F.skills)}catch(F){t("error",`Failed to load skills: ${F}`)}finally{i(!1)}},[t]);n.useEffect(()=>{W()},[W]);const R=n.useMemo(()=>{const F=new Set;return a.forEach(Y=>Y.tags.forEach(se=>F.add(se))),Array.from(F).sort()},[a]),G=n.useMemo(()=>{let F=a;if(h){const Y=h.toLowerCase();F=F.filter(se=>se.name.toLowerCase().includes(Y)||se.slug.toLowerCase().includes(Y)||se.description.toLowerCase().includes(Y)||se.tags.some(ie=>ie.toLowerCase().includes(Y))||se.frameworks.some(ie=>ie.toLowerCase().includes(Y)))}return f!=="all"&&(F=F.filter(Y=>Y.tags.includes(f))),y!=="all"&&(F=F.filter(Y=>Y.source===y)),F},[a,h,f,y]),_=a.filter(F=>F.enabled).length,A=a.filter(F=>F.enabled).reduce((F,Y)=>F+Y.tokenEstimate,0),te=a.filter(F=>F.source==="user").length,X=async(F,Y)=>{U(se=>new Set(se).add(F));try{Y?await hr(F):await pr(F),l(se=>se.map(ie=>ie.slug===F?{...ie,enabled:!Y}:ie)),u&&u.slug===F&&b(se=>se?{...se,enabled:!Y}:null)}catch(se){t("error",`Failed to ${Y?"disable":"enable"} skill: ${se}`)}finally{U(se=>{const ie=new Set(se);return ie.delete(F),ie})}},le=async()=>{try{await jr(),S(!1),p(null),b(null),t("success","Skills reset to defaults (custom skills removed)"),await W()}catch(F){t("error",`Failed to reset: ${F}`)}},$=async F=>{if(j===F){p(null),b(null);return}p(F),M(!0);try{const Y=await Es(F);b(Y)}catch(Y){t("error",`Failed to load skill preview: ${Y}`),b(null)}finally{M(!1)}},re=async F=>{await br(F),t("success","Custom skill created"),await W()},ae=async(F,Y)=>{if(Y){if(await gr(Y,F),t("success",`Skill "${Y}" updated`),j===Y){const se=await Es(Y);b(se)}await W()}},ce=async F=>{try{await vr(F),K(null),j===F&&(p(null),b(null)),t("success",`Skill "${F}" deleted`),await W()}catch(Y){t("error",`Failed to delete skill: ${Y}`)}},he=async(F,Y)=>{await yr(F,Y),t("success","Skill imported successfully"),await W()},xe=async F=>{await fr(F),t("success","Skill imported from URL successfully"),await W()},ye=F=>{window.open(ur(F),"_blank")},Ne=()=>{x(void 0),r(void 0),P("Create Custom Skill"),w(!0)},ke=async F=>{var Y,se,ie;try{const be=await Es(F),oe=be.metadata,k=["---"];k.push(`name: ${oe.name}`),k.push(`slug: ${oe.slug}`),k.push(`description: ${oe.description}`),oe.version&&k.push(`version: ${oe.version}`),oe.author&&k.push(`author: ${oe.author}`),(Y=oe.tags)!=null&&Y.length&&(k.push("tags:"),oe.tags.forEach(q=>k.push(` - ${q}`))),(se=oe.frameworks)!=null&&se.length&&(k.push("frameworks:"),oe.frameworks.forEach(q=>k.push(` - ${q}`))),(ie=oe.tools)!=null&&ie.length&&(k.push("tools:"),oe.tools.forEach(q=>k.push(` - ${q}`))),k.push("---");const C=k.join(`
|
|
43
|
+
`)+`
|
|
44
|
+
|
|
45
|
+
`+be.body;x(C),r(F),P(`Edit Skill: ${oe.name}`),w(!0)}catch(be){t("error",`Failed to load skill for editing: ${be}`)}};return m?e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(J,{size:24,className:"animate-spin text-brand-400 mr-3"}),e.jsx("span",{className:"text-gray-400",children:"Loading skills..."})]}):e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[s&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"View only — Agent Skills are managed by your admin. You can browse them here and use them in the AI Assistant, but not add, edit, enable/disable, or delete them."})]}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5",children:[e.jsx(Te,{size:16,className:"text-cyan-400"}),"Agent Skills"]}),e.jsx("p",{className:"mt-1.5 text-sm text-gray-400 max-w-lg",children:"Skills inject domain-specific best practices into the AI system prompt. Enable skills for your frameworks or create custom ones for your workflows."})]}),e.jsx("div",{className:"flex items-center gap-4 flex-shrink-0 ml-4",children:e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-300",children:[e.jsx("span",{className:"text-cyan-400",children:_}),"/",a.length," enabled"]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5",children:["~",A.toLocaleString()," tokens active",te>0&&e.jsxs("span",{className:"ml-1.5 text-purple-400",children:["· ",te," custom"]})]})]})})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(Ks,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",placeholder:"Search skills...",value:h,onChange:F=>d(F.target.value),className:"w-full bg-surface-1 border border-white/10 rounded-lg pl-9 pr-3 py-2 text-sm text-gray-200 placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),h&&e.jsx("button",{onClick:()=>d(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:e.jsx(me,{size:14})})]}),e.jsx(En,{tags:R,value:f,onChange:g}),e.jsx("div",{className:"flex items-center rounded-lg border border-cyan-500/15 overflow-hidden",children:["all","builtin","user"].map(F=>e.jsx("button",{onClick:()=>c(F),className:`
|
|
46
|
+
px-3 py-2 text-xs capitalize transition-all
|
|
47
|
+
${y===F?"bg-cyan-500/10 text-cyan-300 border-r border-cyan-500/15":"bg-transparent text-gray-500 hover:text-cyan-300/70 border-r border-cyan-500/15 last:border-r-0"}
|
|
48
|
+
`,children:F==="user"?"Custom":F==="all"?"All":"Built-in"},F))}),!s&&e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs("button",{onClick:Ne,className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all flex items-center gap-1.5",children:[e.jsx(je,{size:14}),"Create"]}),e.jsxs("button",{onClick:()=>N(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-violet-500/5 text-violet-400/80 border border-violet-500/20 hover:border-violet-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(bs,{size:12}),"Import"]}),e.jsxs("button",{onClick:()=>S(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-amber-500/5 text-amber-400/70 border border-amber-500/20 hover:border-amber-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(fs,{size:12}),"Reset"]})]})]}),e.jsx("div",{className:"grid gap-3 grid-cols-1 lg:grid-cols-2",children:G.length===0?e.jsxs("div",{className:"col-span-full flex flex-col items-center py-12 text-gray-500",children:[e.jsx(Ks,{size:32,className:"mb-3 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No skills match your search"}),y==="user"&&!s&&e.jsxs("button",{onClick:Ne,className:"mt-3 text-xs text-cyan-400 hover:text-cyan-300 flex items-center gap-1 px-3 py-1.5 rounded-lg border border-cyan-500/20 hover:border-cyan-500/40 transition-all",children:[e.jsx(je,{size:12}),"Create your first custom skill"]})]}):G.map(F=>e.jsx($n,{skill:F,readOnly:s,isSelected:j===F.slug,isToggling:V.has(F.slug),onSelect:()=>$(F.slug),onToggle:()=>X(F.slug,F.enabled),onEdit:!s&&F.source==="user"?()=>ke(F.slug):void 0,onDelete:!s&&F.source==="user"?()=>K(F.slug):void 0,onExport:()=>ye(F.slug)},F.slug))}),j&&e.jsx(Rn,{preview:u,loading:z,readOnly:s,onClose:()=>{p(null),b(null)},onToggle:()=>u&&X(u.slug,u.enabled),isToggling:u?V.has(u.slug):!1,onEdit:!s&&(u==null?void 0:u.source)==="user"?()=>ke(u.slug):void 0,onExport:u?()=>ye(u.slug):void 0,onDelete:!s&&(u==null?void 0:u.source)==="user"?()=>K(u.slug):void 0}),e.jsx(An,{isOpen:I,onClose:()=>w(!1),onSave:o?ae:re,initialContent:v,initialSlug:o,title:E}),e.jsx(zn,{isOpen:B,onClose:()=>N(!1),onImport:he,onImportUrl:xe}),O&&fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-md mx-4 overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-full bg-transparent border border-amber-500/25",children:e.jsx(fs,{size:20,className:"text-amber-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:"Reset Skills"})]}),e.jsxs("p",{className:"text-sm text-gray-400 leading-relaxed",children:["This will reset all skills to their default state and ",e.jsx("span",{className:"text-amber-300",children:"permanently delete all custom skills"}),". This action cannot be undone."]})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>S(!1),className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Cancel"}),e.jsx("button",{onClick:le,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-amber-400 border border-amber-500/30 hover:bg-amber-500/10 hover:border-amber-500/50 font-medium transition-all",children:"Reset to Defaults"})]})]})}),document.body),ee&&fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-md mx-4 overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-full bg-transparent border border-red-500/25",children:e.jsx(we,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:"Delete Skill"})]}),e.jsxs("p",{className:"text-sm text-gray-400 leading-relaxed",children:['Are you sure you want to permanently delete the custom skill "',e.jsx("span",{className:"text-gray-200",children:ee}),'"? This action cannot be undone.']})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>K(null),className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Cancel"}),e.jsx("button",{onClick:()=>ce(ee),className:"px-4 py-2 text-sm rounded-lg bg-transparent text-red-400 border border-red-500/30 hover:bg-red-500/10 hover:border-red-500/50 font-medium transition-all",children:"Delete"})]})]})}),document.body)]})}function $n({skill:s,readOnly:t=!1,isSelected:a,isToggling:l,onSelect:m,onToggle:i,onEdit:h,onDelete:d,onExport:f}){return e.jsx("div",{className:`
|
|
49
|
+
group relative bg-surface-1 rounded-xl border p-4 transition-all cursor-pointer
|
|
50
|
+
${a?"border-cyan-500/40 ring-1 ring-cyan-500/20 bg-cyan-500/[0.03]":"border-white/5 hover:border-white/15 hover:bg-surface-1/80"}
|
|
51
|
+
${s.enabled?"":"opacity-60"}
|
|
52
|
+
`,onClick:m,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`
|
|
53
|
+
mt-0.5 p-2 rounded-lg flex-shrink-0 border
|
|
54
|
+
${s.enabled?"bg-transparent text-cyan-400 border-cyan-500/25":"bg-transparent text-gray-500 border-white/10"}
|
|
55
|
+
`,children:s.source==="builtin"?e.jsx(Qs,{size:16}):e.jsx(ts,{size:16})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200 truncate",children:s.name}),s.version&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-transparent text-gray-500 border border-white/10 flex-shrink-0",children:["v",s.version]}),s.source==="user"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-transparent text-purple-400 border border-purple-500/30 flex-shrink-0",children:"custom"})]}),e.jsx("p",{className:"text-xs text-gray-500 line-clamp-1 mb-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[s.tags.slice(0,3).map(g=>{const y=Ut(g);return e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded border ${y.bg} ${y.text} ${y.border}`,children:g},g)}),s.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:["+",s.tags.length-3]}),e.jsxs("span",{className:"text-[10px] text-gray-600 ml-auto flex-shrink-0",children:["~",s.tokenEstimate," tok"]})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 flex-shrink-0",children:[t?e.jsx("span",{title:s.enabled?"Enabled":"Disabled",className:"cursor-default",children:s.enabled?e.jsx(ys,{size:24,className:"text-cyan-400"}):e.jsx(We,{size:24,className:"text-gray-600"})}):e.jsx("button",{onClick:g=>{g.stopPropagation(),i()},disabled:l,title:s.enabled?"Disable":"Enable",children:l?e.jsx(J,{size:20,className:"animate-spin text-gray-500"}):s.enabled?e.jsx(ys,{size:24,className:"text-cyan-400"}):e.jsx(We,{size:24,className:"text-gray-600"})}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:g=>{g.stopPropagation(),f()},title:"Export as .md",className:"p-1 text-gray-600 hover:text-gray-300 transition-colors",children:e.jsx(Pt,{size:12})}),h&&e.jsx("button",{onClick:g=>{g.stopPropagation(),h()},title:"Edit skill",className:"p-1 text-gray-600 hover:text-cyan-400 transition-colors",children:e.jsx(Lt,{size:12})}),d&&e.jsx("button",{onClick:g=>{g.stopPropagation(),d()},title:"Delete skill",className:"p-1 text-gray-600 hover:text-red-400 transition-colors",children:e.jsx(we,{size:12})})]})]})]})})}function Rn({preview:s,loading:t,readOnly:a=!1,onClose:l,onToggle:m,isToggling:i,onEdit:h,onExport:d,onDelete:f}){var c;const[g,y]=n.useState("rendered");return fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:j=>{j.target===j.currentTarget&&l()},children:e.jsx("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-4xl mx-4 max-h-[85vh] flex flex-col overflow-hidden",children:t?e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(J,{size:20,className:"animate-spin text-brand-400 mr-2"}),e.jsx("span",{className:"text-sm text-gray-400",children:"Loading skill details..."})]}):s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-shrink-0 px-6 py-5 border-b border-white/5",children:e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"p-2 rounded-lg bg-transparent border border-cyan-500/25 flex-shrink-0",children:s.source==="user"?e.jsx(ts,{size:18,className:"text-cyan-400"}):e.jsx(Qs,{size:18,className:"text-cyan-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-200 truncate",children:s.name}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5 whitespace-normal break-words",children:s.metadata.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0 ml-3",children:[d&&e.jsx("button",{onClick:d,title:"Export as .md",className:"text-gray-500 hover:text-gray-300 transition-colors p-1.5 rounded-lg hover:bg-white/5",children:e.jsx(Pt,{size:15})}),h&&e.jsx("button",{onClick:h,title:"Edit skill",className:"text-gray-500 hover:text-cyan-400 transition-colors p-1.5 rounded-lg hover:bg-white/5",children:e.jsx(Lt,{size:15})}),f&&e.jsx("button",{onClick:f,title:"Delete skill",className:"text-gray-500 hover:text-red-400 transition-colors p-1.5 rounded-lg hover:bg-white/5",children:e.jsx(we,{size:15})}),e.jsx("button",{onClick:l,className:"text-gray-500 hover:text-gray-300 transition-colors p-1.5 rounded-lg hover:bg-white/5 ml-1",children:e.jsx(me,{size:16})})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-4 space-y-3 border-b border-white/5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-y-3 gap-x-6 text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Slug"}),e.jsx("span",{className:"text-gray-300 font-mono",children:s.metadata.slug}),e.jsx("span",{className:"text-gray-500",children:"Source"}),e.jsx("span",{className:`capitalize ${s.source==="user"?"text-purple-400":"text-gray-400"}`,children:s.source==="user"?"Custom":"Built-in"}),s.metadata.version&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-500",children:"Version"}),e.jsx("span",{className:"text-gray-300",children:s.metadata.version})]}),s.metadata.author&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-500",children:"Author"}),e.jsx("span",{className:"text-gray-300",children:s.metadata.author})]}),e.jsx("span",{className:"text-gray-500",children:"Token Cost"}),e.jsxs("span",{className:"text-gray-300",children:["~",((c=s.metadata.tokenEstimate)==null?void 0:c.toLocaleString())||Math.round(s.body.length/4).toLocaleString()," tokens"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Status"}),a?e.jsxs("span",{className:`
|
|
56
|
+
flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium border cursor-default
|
|
57
|
+
${s.enabled?"bg-transparent text-cyan-300/80 border-cyan-500/25":"bg-transparent text-gray-400 border-white/10"}
|
|
58
|
+
`,children:[s.enabled?e.jsx(Ee,{size:12}):e.jsx(We,{size:12}),s.enabled?"Enabled":"Disabled"]}):e.jsxs("button",{onClick:m,disabled:i,className:`
|
|
59
|
+
flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium transition-all border
|
|
60
|
+
${s.enabled?"bg-transparent text-cyan-300 border-cyan-500/30 hover:bg-cyan-500/5 hover:border-cyan-500/50":"bg-transparent text-gray-400 border-white/10 hover:border-white/25"}
|
|
61
|
+
`,children:[i?e.jsx(J,{size:12,className:"animate-spin"}):s.enabled?e.jsx(Ee,{size:12}):e.jsx(We,{size:12}),s.enabled?"Enabled":"Disabled"]})]})]}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Ra,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Tags"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.metadata.tags.map(j=>{const p=Ut(j);return e.jsx("span",{className:`text-xs px-2.5 py-1 rounded border ${p.bg} ${p.text} ${p.border}`,children:j},j)})})]}),s.metadata.frameworks&&s.metadata.frameworks.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ts,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Frameworks"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.metadata.frameworks.map(j=>e.jsx("span",{className:"text-xs px-2.5 py-1 rounded bg-transparent text-brand-300 border border-brand-500/25",children:j},j))})]}),e.jsxs("div",{className:"px-6 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-gray-400",children:[e.jsx(js,{size:14}),"Skill Instructions (",s.body.length," chars)"]}),e.jsxs("div",{className:"flex items-center rounded overflow-hidden border border-cyan-500/15",children:[e.jsx("button",{onClick:()=>y("rendered"),className:`px-2 py-1 text-[10px] transition-all ${g==="rendered"?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}`,title:"Rendered markdown",children:e.jsx(ve,{size:10})}),e.jsx("button",{onClick:()=>y("raw"),className:`px-2 py-1 text-[10px] transition-all ${g==="raw"?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}`,title:"Raw source",children:e.jsx(ts,{size:10})})]})]}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded-lg bg-surface-0/50 border border-white/5 p-4",children:g==="rendered"?e.jsx("div",{className:"skill-markdown-preview text-sm text-gray-400 leading-relaxed",dangerouslySetInnerHTML:{__html:It(s.body)}}):e.jsx("pre",{className:"text-xs text-gray-400 leading-relaxed whitespace-pre-wrap font-mono",children:s.body})})]})]}),e.jsx("div",{className:"flex-shrink-0 px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end",children:e.jsx("button",{onClick:l,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Close"})})]}):e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("span",{className:"text-sm text-gray-500",children:"Skill not found"})})})}),document.body)}const Mn={"Playwright (Official)":{icon:"MonitorSmartphone",color:"text-green-400"},"Playwright (Community)":{icon:"MonitorSmartphone",color:"text-emerald-400"},Appium:{icon:"Smartphone",color:"text-purple-400"},"Chrome DevTools":{icon:"Gauge",color:"text-blue-400"},"OWASP ZAP":{icon:"Shield",color:"text-red-400"},Trivy:{icon:"ShieldCheck",color:"text-blue-400"},Snyk:{icon:"Bug",color:"text-violet-400"},Lighthouse:{icon:"Gauge",color:"text-orange-400"},"k6 Load Testing":{icon:"Zap",color:"text-yellow-400"},"Axe Accessibility":{icon:"Accessibility",color:"text-cyan-400"},Pa11y:{icon:"Accessibility",color:"text-teal-400"},"Percy (BrowserStack)":{icon:"Eye",color:"text-pink-400"},"Applitools Eyes":{icon:"Eye",color:"text-indigo-400"},"DBHub (Multi-DB)":{icon:"Database",color:"text-cyan-400"},PostgreSQL:{icon:"Database",color:"text-blue-400"},MySQL:{icon:"Database",color:"text-orange-400"},MongoDB:{icon:"Database",color:"text-green-400"},SQLite:{icon:"HardDrive",color:"text-sky-400"},Filesystem:{icon:"FolderGit2",color:"text-amber-400"},Git:{icon:"FolderGit2",color:"text-orange-400"},GitHub:{icon:"Github",color:"text-gray-300"},Slack:{icon:"MessageSquare",color:"text-purple-400"},Jira:{icon:"Boxes",color:"text-blue-400"},Linear:{icon:"Send",color:"text-violet-400"},Docker:{icon:"Container",color:"text-blue-400"},Kubernetes:{icon:"Network",color:"text-blue-300"},GraphQL:{icon:"FileJson",color:"text-pink-400"},"OpenAPI / Swagger":{icon:"FileJson",color:"text-green-400"},"Postman (Official)":{icon:"Send",color:"text-orange-400"},"Everything (Demo)":{icon:"TestTube",color:"text-cyan-400"}},Dn={MonitorSmartphone:Ja,Smartphone:Oe,Shield:qa,ShieldCheck:Mt,Bug:Wa,Gauge:Ga,Zap:Ee,Accessibility:Va,Eye:ve,Database:Ha,HardDrive:_a,FolderGit2:Ka,Github:Ba,MessageSquare:Ua,Boxes:Oa,Send:_s,Container:Ia,Network:Fa,FileJson:Da,TestTube:$t,Plug:Pe};function ls(s,t=14){const a=Mn[s];if(a){const l=Dn[a.icon]||Pe;return{node:e.jsx(l,{size:t}),color:a.color}}return{node:e.jsx(Pe,{size:t}),color:"text-gray-400"}}function Fn({status:s}){switch(s){case"connected":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-transparent text-emerald-400 border border-emerald-500/30",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400"}),"Connected"]});case"connecting":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-transparent text-amber-400 border border-amber-500/30",children:[e.jsx(J,{size:10,className:"animate-spin"}),"Connecting"]});case"error":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-transparent text-red-400 border border-red-500/30",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-red-400"}),"Error"]});default:return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-transparent text-gray-400 border border-white/15",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-500"}),"Disconnected"]})}}function Bt({type:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] font-mono uppercase rounded bg-transparent text-gray-500 border border-white/10",children:[s==="stdio"?e.jsx(Ts,{size:10}):e.jsx(cs,{size:10}),s]})}function In({server:s,readOnly:t=!1,onConnect:a,onDisconnect:l,onTest:m,onEdit:i,onDelete:h,onToggleEnabled:d}){var S,I;const[f,g]=n.useState(!1),[y,c]=n.useState(!1),[j,p]=n.useState(null),[u,b]=n.useState(!1),[z,M]=n.useState(null),V=async()=>{c(!0),p(null),M(null);try{const w=await Pr(s.id);p(w)}catch(w){p({success:!1,error:String(w)})}finally{c(!1)}},U=async()=>{b(!0),M(null),p(null);try{const w=await a();w.success?M({success:!0,message:`Connected successfully — ${w.toolCount||0} tool(s) available`}):M({success:!1,message:w.error||"Connection failed"})}catch(w){M({success:!1,message:String(w)})}finally{b(!1)}},O=async()=>{b(!0),M(null),p(null);try{const w=await l();w.success?M({success:!0,message:"Disconnected successfully"}):M({success:!1,message:w.error||"Disconnect failed"})}catch(w){M({success:!1,message:String(w)})}finally{b(!1)}};return e.jsxs("div",{className:`
|
|
62
|
+
group relative bg-surface-1 rounded-xl border p-4 transition-all
|
|
63
|
+
${s.status==="connected"?"border-emerald-500/20":"border-white/5 hover:border-white/15"}
|
|
64
|
+
${s.enabled?"":"opacity-60"}
|
|
65
|
+
`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:`
|
|
66
|
+
p-1.5 rounded-lg flex-shrink-0 border
|
|
67
|
+
${s.status==="connected"?`bg-transparent border-emerald-500/25 ${ls(s.name).color}`:`bg-transparent border-white/10 ${ls(s.name).color}`}
|
|
68
|
+
`,children:ls(s.name).node}),e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200 truncate",children:s.name}),e.jsx(Bt,{type:s.transportType})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 ml-9",children:[e.jsx(Fn,{status:s.status}),s.toolCount>0&&e.jsxs("span",{className:"text-xs text-gray-500",children:[s.toolCount," tool",s.toolCount!==1?"s":""]})]}),s.transportType==="stdio"&&s.command&&e.jsxs("p",{className:"mt-1.5 ml-9 text-xs text-gray-600 font-mono truncate",children:[s.command," ",(S=s.args)==null?void 0:S.join(" ")]}),(s.transportType==="sse"||s.transportType==="http")&&s.url&&e.jsx("p",{className:"mt-1.5 ml-9 text-xs text-gray-600 font-mono truncate",children:s.url})]}),t?e.jsx("span",{title:s.enabled?"Enabled":"Disabled",className:"cursor-default",children:s.enabled?e.jsx(ys,{size:24,className:"text-cyan-400"}):e.jsx(We,{size:24,className:"text-gray-600"})}):e.jsx("button",{onClick:d,title:s.enabled?"Disable":"Enable",children:s.enabled?e.jsx(ys,{size:24,className:"text-cyan-400"}):e.jsx(We,{size:24,className:"text-gray-600"})})]}),s.lastError&&s.status==="error"&&e.jsx("div",{className:"mt-2 ml-9 p-2 rounded-lg bg-red-500/10 border border-red-500/20",children:e.jsxs("p",{className:"text-xs text-red-400 flex items-center gap-1",children:[e.jsx(Ye,{size:12}),s.lastError]})}),z&&e.jsx("div",{className:`mt-2 ml-9 p-2 rounded-lg border ${z.success?"bg-emerald-500/10 border-emerald-500/20":"bg-red-500/10 border-red-500/20"}`,children:e.jsxs("p",{className:`text-xs flex items-center gap-1 ${z.success?"text-emerald-400":"text-red-400"}`,children:[z.success?e.jsx(ne,{size:12}):e.jsx(Se,{size:12}),z.message]})}),j&&e.jsxs("div",{className:`mt-2 ml-9 p-2 rounded-lg border ${j.success?"bg-emerald-500/10 border-emerald-500/20":"bg-red-500/10 border-red-500/20"}`,children:[e.jsxs("p",{className:`text-xs flex items-center gap-1 ${j.success?"text-emerald-400":"text-red-400"}`,children:[j.success?e.jsx(ne,{size:12}):e.jsx(Se,{size:12}),j.success?`Connection successful — ${((I=j.tools)==null?void 0:I.length)||0} tool(s) discovered`:`Connection failed: ${j.error}`]}),j.success&&s.status!=="connected"&&e.jsxs("button",{onClick:U,disabled:u||!s.enabled,className:"mt-2 inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium rounded-lg bg-transparent text-cyan-400 hover:bg-cyan-500/5 border border-cyan-500/25 hover:border-cyan-500/45 transition-all disabled:opacity-50",children:[u?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(ct,{size:12}),"Connect now"]})]}),!t&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-3 ml-9",children:[s.status==="connected"?e.jsxs("button",{onClick:O,disabled:u,className:"inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium rounded-lg bg-transparent text-amber-400 hover:bg-amber-500/5 border border-amber-500/25 hover:border-amber-500/45 transition-all disabled:opacity-50",children:[u?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ma,{size:12}),"Disconnect"]}):e.jsxs("button",{onClick:U,disabled:u||!s.enabled,className:"inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium rounded-lg bg-transparent text-cyan-400 hover:bg-cyan-500/5 border border-cyan-500/25 hover:border-cyan-500/45 transition-all disabled:opacity-50",children:[u?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(ct,{size:12}),"Connect"]}),e.jsxs("button",{onClick:V,disabled:y,className:"inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium rounded-lg bg-transparent text-violet-400/80 hover:bg-violet-500/5 border border-violet-500/20 hover:border-violet-500/40 transition-all disabled:opacity-50",children:[y?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx($t,{size:12}),"Test"]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:i,className:"p-1.5 text-gray-600 hover:text-cyan-400 transition-colors",title:"Edit",children:e.jsx(Cs,{size:13})}),e.jsx("button",{onClick:h,className:"p-1.5 text-gray-600 hover:text-red-400 transition-colors",title:"Delete",children:e.jsx(we,{size:13})})]})]}),s.status==="connected"&&s.toolCount>0&&e.jsxs("div",{className:"mt-3 ml-9 border-t border-white/5 pt-2",children:[e.jsxs("button",{onClick:()=>g(!f),className:"flex items-center gap-1.5 text-xs text-gray-500 hover:text-gray-300 transition-colors",children:[f?e.jsx(Me,{size:12}):e.jsx(Ie,{size:12}),e.jsx(Rt,{size:12}),e.jsxs("span",{children:[s.toolCount," tool",s.toolCount!==1?"s":""," available"]})]}),f&&s.tools&&e.jsx("div",{className:"mt-2 space-y-1 max-h-48 overflow-y-auto",children:s.tools.map((w,v)=>e.jsxs("div",{className:"flex items-start gap-2 py-1",children:[e.jsx("span",{className:"text-xs font-mono text-cyan-400 whitespace-nowrap",children:w.name}),e.jsx("span",{className:"text-xs text-gray-500 leading-relaxed",children:w.description})]},v))})]})]})}const On=`{
|
|
69
|
+
"mcpServers": {
|
|
70
|
+
"playwright": {
|
|
71
|
+
"command": "npx",
|
|
72
|
+
"args": ["@playwright/mcp@latest"]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}`;function Un(s){let t;try{t=JSON.parse(s)}catch(i){return{servers:[],error:`Invalid JSON: ${i instanceof Error?i.message:String(i)}`}}if(!t||typeof t!="object")return{servers:[],error:"Expected a JSON object."};const a=t,l=a.mcpServers&&typeof a.mcpServers=="object"?a.mcpServers:a.servers&&typeof a.servers=="object"?a.servers:a,m=[];for(const[i,h]of Object.entries(l)){if(!h||typeof h!="object")continue;const d=h,f=typeof d.command=="string"?d.command.trim():"",g=typeof d.url=="string"?d.url.trim():"";let y;if(f)y="stdio";else if(g)y=String(d.type||d.transport||"").toLowerCase().includes("sse")?"sse":"http";else return{servers:[],error:`Server "${i}" needs a "command" (stdio) or "url" (http/sse).`};const c=d.env&&typeof d.env=="object"?d.env:d.envVars&&typeof d.envVars=="object"?d.envVars:void 0,j=c?Object.fromEntries(Object.entries(c).map(([b,z])=>[b,String(z)])):void 0,p=d.headers&&typeof d.headers=="object"?d.headers:void 0,u=p?Object.fromEntries(Object.entries(p).map(([b,z])=>[b,String(z)])):void 0;m.push({name:String(i),transportType:y,command:y==="stdio"?f:void 0,args:y==="stdio"&&Array.isArray(d.args)?d.args.map(String):void 0,url:y!=="stdio"?g:void 0,envVars:j&&Object.keys(j).length>0?j:void 0,headers:u&&Object.keys(u).length>0?u:void 0,autoConnect:!!d.autoConnect})}return m.length===0?{servers:[],error:'No servers found. Expected an object with an "mcpServers" map.'}:{servers:m}}function Bn({initial:s,onSave:t,onCancel:a,onImportJson:l,presets:m}){var w,v;const[i,h]=n.useState("form"),[d,f]=n.useState(""),[g,y]=n.useState(null),[c,j]=n.useState(!1),p=async()=>{const{servers:x,error:o}=Un(d);if(o){y(o);return}y(null),j(!0);try{await(l==null?void 0:l(x))}catch(r){y(`Failed to add: ${r instanceof Error?r.message:String(r)}`)}finally{j(!1)}},u=s!=null&&s.name?(w=m==null?void 0:m.find(x=>x.name===s.name))==null?void 0:w.referenceUrl:void 0,[b,z]=n.useState({name:(s==null?void 0:s.name)||"",transportType:(s==null?void 0:s.transportType)||"stdio",command:(s==null?void 0:s.command)||"npx",args:((v=s==null?void 0:s.args)==null?void 0:v.join(", "))||"",url:(s==null?void 0:s.url)||"",envVars:s!=null&&s.envVars?Object.entries(s.envVars).map(([x,o])=>({key:x,value:o})):[],headers:s!=null&&s.headers?Object.entries(s.headers).map(([x,o])=>({key:x,value:o})):[],autoConnect:(s==null?void 0:s.autoConnect)||!1}),M=()=>z(x=>({...x,envVars:[...x.envVars,{key:"",value:""}]})),V=x=>z(o=>({...o,envVars:o.envVars.filter((r,E)=>E!==x)})),U=(x,o,r)=>{z(E=>({...E,envVars:E.envVars.map((P,B)=>B===x?{...P,[o]:r}:P)}))},O=()=>z(x=>({...x,headers:[...x.headers,{key:"",value:""}]})),S=x=>z(o=>({...o,headers:o.headers.filter((r,E)=>E!==x)})),I=(x,o,r)=>{z(E=>({...E,headers:E.headers.map((P,B)=>B===x?{...P,[o]:r}:P)}))};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-4xl mx-4 max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsx("div",{className:"px-6 py-5 border-b border-white/5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-transparent border border-cyan-500/25",children:e.jsx(Pe,{size:20,className:"text-cyan-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-200",children:s?"Edit MCP Server":"Add MCP Server"}),u&&e.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-cyan-400 hover:text-cyan-300 border border-cyan-500/20 hover:border-cyan-500/40 rounded-md px-2 py-0.5 transition-all",children:[e.jsx(Ss,{size:11})," View docs"]})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"Configure a Model Context Protocol server connection"})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:[!s&&e.jsx("div",{className:"flex items-center rounded-lg border border-cyan-500/15 overflow-hidden text-sm",children:["form","json"].map(x=>e.jsx("button",{onClick:()=>h(x),className:`flex-1 px-4 py-2 font-medium transition-all ${i===x?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}`,children:x==="form"?"Form":"JSON"},x))}),i==="json"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"MCP servers JSON"}),e.jsx("textarea",{value:d,onChange:x=>{f(x.target.value),y(null)},rows:12,spellCheck:!1,placeholder:On,className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-xs text-gray-200 font-mono placeholder-gray-600 focus:outline-none focus:border-cyan-500/50 resize-y"}),e.jsxs("p",{className:"mt-1.5 text-[11px] text-gray-500 leading-relaxed",children:["Paste a standard ",e.jsx("span",{className:"font-mono text-gray-400",children:"mcpServers"})," block. Add multiple servers at once —",e.jsx("span",{className:"font-mono",children:" command"})," ⇒ stdio, ",e.jsx("span",{className:"font-mono",children:"url"})," ⇒ http/sse."]}),g&&e.jsxs("p",{className:"mt-2 text-xs text-red-400 flex items-center gap-1",children:[e.jsx(Ye,{size:12})," ",g]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Server Name"}),e.jsx("input",{type:"text",value:b.name,onChange:x=>z(o=>({...o,name:x.target.value})),placeholder:"e.g., Playwright MCP",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Transport Type"}),e.jsx("div",{className:"flex items-center rounded-lg border border-cyan-500/15 overflow-hidden",children:["stdio","sse","http"].map(x=>e.jsxs("button",{onClick:()=>z(o=>({...o,transportType:x})),className:`
|
|
76
|
+
flex items-center gap-2 px-4 py-2.5 text-sm font-medium transition-all flex-1 justify-center
|
|
77
|
+
${b.transportType===x?"bg-cyan-500/10 text-cyan-300":"bg-transparent text-gray-500 hover:text-cyan-300/70"}
|
|
78
|
+
`,children:[x==="stdio"?e.jsx(Ts,{size:14}):e.jsx(cs,{size:14}),x.toUpperCase()]},x))})]}),b.transportType==="stdio"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Command"}),e.jsx("input",{type:"text",value:b.command,onChange:x=>z(o=>({...o,command:x.target.value})),placeholder:"npx",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Arguments (comma-separated)"}),e.jsx("input",{type:"text",value:b.args,onChange:x=>z(o=>({...o,args:x.target.value})),placeholder:"-y, @modelcontextprotocol/server-everything",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),b.args.includes("--dsn")&&e.jsxs("div",{className:"mt-2.5 p-3 rounded-lg border border-cyan-500/15 bg-cyan-500/5",children:[e.jsx("p",{className:"text-xs font-medium text-cyan-400 mb-2",children:"DSN Connection String Formats:"}),e.jsxs("div",{className:"space-y-1 font-mono text-[11px] text-gray-400",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-emerald-400",children:"postgres:"})," postgres://user:password@localhost:5432/dbname?sslmode=require"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-orange-400",children:"mysql:"})," mysql://root:password@localhost:3306/mysql?sslmode=require"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-purple-400",children:"mariadb:"})," mariadb://root:password@localhost:3306/db?sslmode=require"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-blue-400",children:"sqlserver:"})," sqlserver://user:password@localhost:1433/database?instanceName=INST1"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-yellow-400",children:"sqlite:"})," sqlite:///path/to/database.db"]})]}),e.jsx("p",{className:"text-[11px] text-gray-500 mt-2",children:"Replace the sample DSN value above with your actual connection string."})]})]})]}),(b.transportType==="sse"||b.transportType==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Server URL"}),e.jsx("input",{type:"text",value:b.url,onChange:x=>z(o=>({...o,url:x.target.value})),placeholder:b.transportType==="http"?"http://localhost:3001/mcp":"http://localhost:3001/sse",className:"w-full bg-surface-1 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("p",{className:"mt-1.5 text-[11px] text-gray-500",children:b.transportType==="http"?"MCP Streamable HTTP endpoint (the modern replacement for SSE).":"MCP Server-Sent Events endpoint."})]}),(b.transportType==="sse"||b.transportType==="http")&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"Headers"}),e.jsxs("button",{onClick:O,className:"text-xs text-cyan-400 hover:text-cyan-300 flex items-center gap-1 px-2.5 py-1 rounded border border-cyan-500/20 hover:border-cyan-500/40 transition-all",children:[e.jsx(je,{size:12})," Add"]})]}),b.headers.length===0&&e.jsxs("p",{className:"text-sm text-gray-600 italic",children:["No headers — add e.g. ",e.jsx("span",{className:"font-mono",children:"Authorization: Bearer <token>"})," for authenticated servers"]}),e.jsx("div",{className:"space-y-2",children:b.headers.map((x,o)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x.key,onChange:r=>I(o,"key",r.target.value),placeholder:"Header-Name",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("input",{type:"text",value:x.value,onChange:r=>I(o,"value",r.target.value),placeholder:"value",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("button",{onClick:()=>S(o),className:"p-1.5 text-gray-500 hover:text-red-400",children:e.jsx(me,{size:16})})]},o))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"Environment Variables"}),e.jsxs("button",{onClick:M,className:"text-xs text-cyan-400 hover:text-cyan-300 flex items-center gap-1 px-2.5 py-1 rounded border border-cyan-500/20 hover:border-cyan-500/40 transition-all",children:[e.jsx(je,{size:12})," Add"]})]}),b.envVars.length===0&&e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No environment variables configured"}),e.jsx("div",{className:"space-y-2",children:b.envVars.map((x,o)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x.key,onChange:r=>U(o,"key",r.target.value),placeholder:"KEY",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("input",{type:"text",value:x.value,onChange:r=>U(o,"value",r.target.value),placeholder:"value",className:"flex-1 bg-surface-1 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 font-mono placeholder-gray-500 focus:outline-none focus:border-cyan-500/50"}),e.jsx("button",{onClick:()=>V(o),className:"p-1.5 text-gray-500 hover:text-red-400",children:e.jsx(me,{size:16})})]},o))})]}),e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:b.autoConnect,onChange:x=>z(o=>({...o,autoConnect:x.target.checked})),className:"rounded border-white/20 bg-white/5 text-cyan-500 focus:ring-cyan-500/30"}),e.jsx("span",{className:"text-sm text-gray-400",children:"Auto-connect on server startup"})]})]})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Cancel"}),i==="json"?e.jsxs("button",{onClick:p,disabled:!d.trim()||c,className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm rounded-lg bg-transparent text-cyan-400 border border-cyan-500/30 hover:bg-cyan-500/10 hover:border-cyan-500/50 font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[c&&e.jsx(J,{size:14,className:"animate-spin"}),"Add Server(s)"]}):e.jsx("button",{onClick:()=>t(b),disabled:!b.name.trim()||b.transportType==="stdio"&&!b.command.trim()||(b.transportType==="sse"||b.transportType==="http")&&!b.url.trim(),className:"px-4 py-2 text-sm rounded-lg bg-transparent text-cyan-400 border border-cyan-500/30 hover:bg-cyan-500/10 hover:border-cyan-500/50 font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:s?"Save Changes":"Add Server"})]})]})})}function Kn({presets:s,available:t,onAdd:a,onClose:l}){const m=new Set(t.map(y=>y.name)),[i,h]=n.useState(null),d={browser:"Browser & UI Testing",database:"Database Testing",filesystem:"File System & Version Control",devtools:"Development & Testing",api:"API & Contract Testing"},f=s.reduce((y,c,j)=>{const p=c.category||"other";return y[p]||(y[p]=[]),y[p].push({preset:c,index:j}),y},{}),g=async y=>{h(y),await a(y),h(null)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-4xl mx-4 max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsx("div",{className:"px-6 py-5 border-b border-white/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-transparent border border-cyan-500/25",children:e.jsx(js,{size:20,className:"text-cyan-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-200",children:"MCP Server Catalog"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"Pre-configured MCP servers for test automation"})]})]}),e.jsx("button",{onClick:l,className:"text-gray-500 hover:text-gray-300 transition-colors p-1.5 rounded-lg hover:bg-white/5",children:e.jsx(me,{size:18})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:Object.entries(f).map(([y,c])=>e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3",children:d[y]||y}),e.jsx("div",{className:"space-y-2.5",children:c.map(({preset:j,index:p})=>{var z;const u=m.has(j.name),b=i===p;return e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-xl bg-surface-1 border border-white/5",children:[e.jsx("div",{className:`p-2.5 rounded-xl bg-surface-2/60 border border-white/5 shrink-0 ${ls(j.name,18).color}`,children:ls(j.name,18).node}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200",children:j.name}),e.jsx(Bt,{type:j.transportType})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 line-clamp-1",children:j.description}),j.command&&e.jsxs("p",{className:"text-xs text-gray-600 font-mono mt-1.5",children:[j.command," ",(z=j.args)==null?void 0:z.join(" ")]}),j.referenceUrl&&e.jsxs("a",{href:j.referenceUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-cyan-500/70 hover:text-cyan-400 mt-1 transition-all",onClick:M=>M.stopPropagation(),children:[e.jsx(Ss,{size:10}),"View docs"]})]}),u?e.jsxs("button",{onClick:()=>g(p),disabled:b,className:"px-3.5 py-2 text-sm font-medium rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all disabled:opacity-50 whitespace-nowrap flex items-center gap-1.5",children:[b?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(je,{size:14}),"Add"]}):e.jsxs("span",{className:"px-3.5 py-2 text-sm font-medium text-emerald-400/60 bg-transparent border border-emerald-500/20 rounded-lg whitespace-nowrap flex items-center gap-1.5",children:[e.jsx(ne,{size:14}),"Added"]})]},p)})})]},y))})]})})}function _n({serverName:s,onConfirm:t,onCancel:a}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-2xl w-full max-w-md mx-4 overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-full bg-transparent border border-red-500/25",children:e.jsx(we,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:"Delete MCP Server"})]}),e.jsxs("p",{className:"text-sm text-gray-400 leading-relaxed",children:['Are you sure you want to delete "',e.jsx("span",{className:"text-gray-200",children:s}),'"? This will disconnect the server and remove its configuration.']})]}),e.jsxs("div",{className:"px-6 py-4 bg-surface-2/30 border-t border-white/5 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-gray-300 border border-white/10 hover:border-white/25 transition-all",children:"Cancel"}),e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm rounded-lg bg-transparent text-red-400 border border-red-500/30 hover:bg-red-500/10 hover:border-red-500/50 font-medium transition-all",children:"Delete"})]})]})})}function Hn({readOnly:s=!1}={}){const[t,a]=n.useState([]),[l,m]=n.useState(!0),[i,h]=n.useState(null),[d,f]=n.useState(!1),[g,y]=n.useState(null),[c,j]=n.useState([]),[p,u]=n.useState([]),b=n.useCallback(async()=>{try{const o=await Nr();a(o.servers)}catch(o){console.error("Failed to load MCP servers:",o)}finally{m(!1)}},[]),z=n.useCallback(async()=>{try{const o=await wr();j(o.presets),u(o.available)}catch(o){console.error("Failed to load MCP presets:",o)}},[]);n.useEffect(()=>{b(),z()},[b,z]),n.useEffect(()=>un(b,5e3),[b]);const M=async o=>{try{const r={};for(const N of o.envVars)N.key.trim()&&(r[N.key.trim()]=N.value);const E=o.transportType==="sse"||o.transportType==="http",P={};if(E)for(const N of o.headers)N.key.trim()&&(P[N.key.trim()]=N.value);const B=o.args.split(",").map(N=>N.trim()).filter(Boolean);(i==null?void 0:i.mode)==="edit"&&i.server?await Ar(i.server.id,{name:o.name.trim(),transportType:o.transportType,command:o.transportType==="stdio"?o.command.trim():void 0,args:o.transportType==="stdio"?B:void 0,url:E?o.url.trim():void 0,envVars:Object.keys(r).length>0?r:void 0,headers:E&&Object.keys(P).length>0?P:void 0,autoConnect:o.autoConnect}):await st({name:o.name.trim(),transportType:o.transportType,command:o.transportType==="stdio"?o.command.trim():void 0,args:o.transportType==="stdio"?B:void 0,url:E?o.url.trim():void 0,envVars:Object.keys(r).length>0?r:void 0,headers:E&&Object.keys(P).length>0?P:void 0,autoConnect:o.autoConnect}),h(null),b(),z()}catch(r){console.error("Failed to save MCP server:",r)}},V=async o=>{for(const r of o)await st(r);h(null),b(),z()},U=async o=>{try{const r=await Tr(o);return b(),r.error?{success:!1,error:r.error}:{success:!0,toolCount:r.toolCount}}catch(r){return console.error("Failed to connect MCP server:",r),b(),{success:!1,error:String(r)}}},O=async o=>{try{return await Sr(o),b(),{success:!0}}catch(r){return console.error("Failed to disconnect MCP server:",r),b(),{success:!1,error:String(r)}}},S=async o=>{try{o.enabled?await kr(o.id):await Cr(o.id),b()}catch(r){console.error("Failed to toggle MCP server:",r)}},I=async o=>{try{await Er(o),y(null),b(),z()}catch(r){console.error("Failed to delete MCP server:",r)}},w=async o=>{try{await zr(o),b(),z()}catch(r){console.error("Failed to add MCP preset:",r)}};if(l)return e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(J,{size:24,className:"animate-spin text-brand-400 mr-3"}),e.jsx("span",{className:"text-gray-400",children:"Loading MCP servers..."})]});const v=t.filter(o=>o.status==="connected").length,x=t.reduce((o,r)=>o+r.toolCount,0);return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[s&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"View only — MCP servers are managed by your admin. You can see what's configured and use their tools in the AI Assistant, but not add, edit, connect, or delete them."})]}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5",children:[e.jsx(Pe,{size:16,className:"text-cyan-400"}),"MCP Servers"]}),e.jsx("p",{className:"mt-1.5 text-sm text-gray-400 max-w-lg",children:"Connect external MCP servers to extend your AI assistant with additional tools for browser automation, database access, and more."})]}),e.jsx("div",{className:"flex items-center gap-4 flex-shrink-0 ml-4",children:e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-300",children:[e.jsx("span",{className:"text-cyan-400",children:v}),"/",t.length," connected"]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5",children:[x," tool",x!==1?"s":""," available"]})]})})]})}),!s&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>f(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-violet-500/5 text-violet-400/80 border border-violet-500/20 hover:border-violet-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(js,{size:14}),"Add from Catalog"]}),e.jsxs("button",{onClick:()=>h({mode:"add"}),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all flex items-center gap-1.5",children:[e.jsx(je,{size:14}),"Add Server"]})]}),t.length===0?e.jsxs("div",{className:"flex flex-col items-center py-16 text-gray-500",children:[e.jsx(Pe,{size:48,className:"mb-4 opacity-50"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-400 mb-2",children:"No MCP Servers Configured"}),e.jsx("p",{className:"text-xs text-gray-600 mb-4 max-w-md text-center",children:"MCP (Model Context Protocol) servers extend your AI assistant with external tools like browser automation, database access, and more."}),!s&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>f(!0),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-violet-500/5 text-violet-400/80 border border-violet-500/20 hover:border-violet-500/40 transition-all flex items-center gap-1.5",children:[e.jsx(js,{size:14}),"Browse Catalog"]}),e.jsxs("button",{onClick:()=>h({mode:"add"}),className:"px-3 py-2 text-xs rounded-lg bg-transparent hover:bg-cyan-500/5 text-cyan-400 border border-cyan-500/25 hover:border-cyan-500/45 transition-all flex items-center gap-1.5",children:[e.jsx(je,{size:14}),"Add Custom Server"]})]})]}):e.jsx("div",{className:"grid gap-3 grid-cols-1 lg:grid-cols-2",children:t.map(o=>e.jsx(In,{server:o,readOnly:s,onConnect:()=>U(o.id),onDisconnect:()=>O(o.id),onTest:()=>{},onEdit:()=>h({mode:"edit",server:o}),onDelete:()=>y(o),onToggleEnabled:()=>S(o)},o.id))}),i&&fe.createPortal(e.jsx(Bn,{initial:i.server,onSave:M,onImportJson:V,onCancel:()=>h(null),presets:c}),document.body),d&&fe.createPortal(e.jsx(Kn,{presets:c,available:p,onAdd:w,onClose:()=>f(!1)}),document.body),g&&fe.createPortal(e.jsx(_n,{serverName:g.name,onConfirm:()=>I(g.id),onCancel:()=>y(null)}),document.body)]})}function Kt(s){return s==="js-config"?"js config":s==="dotenv"?"env":s}const Vn=/^(base_?url|baseurl|app_?url|url)$/i,Gn=/(pass(word|wd)?|secret|token|api[_-]?key|apikey|access[_-]?key|client[_-]?secret|private[_-]?key|\bauth\b|credential|\bpwd\b|salt)/i;function Wn({embedded:s=!1}={}){const{toast:t}=ge(),[a,l]=n.useState([]),[m,i]=n.useState(null),[h,d]=n.useState(null),[f,g]=n.useState([]),[y,c]=n.useState(""),[j,p]=n.useState(!0),[u,b]=n.useState(!1),[z,M]=n.useState(null),[V,U]=n.useState(new Set),[O,S]=n.useState(!1);async function I(R){var G;p(!0),M(null);try{const _=await Lr();l(_.files);const A=R||m||((G=_.files[0])==null?void 0:G.file)||null;i(A),A||(d(null),g([]))}catch(_){M(String(_))}finally{p(!1)}}async function w(R){M(null),U(new Set);try{const G=await $r(R);d(G),g(G.vars),c(JSON.stringify(G.vars))}catch(G){M(String(G)),d(null),g([])}}n.useEffect(()=>{I()},[]),n.useEffect(()=>{m&&w(m)},[m]);const v=n.useMemo(()=>JSON.stringify(f)!==y,[f,y]),x=n.useMemo(()=>f.findIndex(R=>Vn.test(R.key.split(".").pop()||"")),[f]),o=(h==null?void 0:h.format)==="js-config";function r(R,G){g(_=>_.map((A,te)=>te===R?{...A,...G}:A))}function E(R){g(G=>G.filter((_,A)=>A!==R)),U(G=>{const _=new Set;return G.forEach(A=>{A<R?_.add(A):A>R&&_.add(A-1)}),_})}function P(){g(R=>[...R,{key:"",value:"",secret:!1}])}function B(R){U(G=>{const _=new Set(G);return _.has(R)?_.delete(R):_.add(R),_})}function N(){try{g(JSON.parse(y)),U(new Set)}catch{}}async function ee(){if(!m)return;const R=f.map(_=>_.key.trim());if(R.some(_=>!_)){t("error","Every variable needs a name");return}const G=R.find((_,A)=>R.indexOf(_)!==A);if(G){t("error",`Duplicate variable: ${G}`);return}b(!0);try{const _=await Rr(m,f.map(A=>({...A,key:A.key.trim()})));d(_),g(_.vars),c(JSON.stringify(_.vars)),t("success",`Saved ${_.file}`)}catch(_){t("error",`Save failed: ${_}`)}finally{b(!1)}}async function K(R){try{const G=await Fr(R);S(!1),await I(G.file),t("success",`Loaded ${G.file}`)}catch(G){t("error",`${G}`)}}async function W(R){try{await Dr(R),m===R&&i(null),await I(),t("success",`Removed ${R}`)}catch(G){t("error",`${G}`)}}return e.jsxs("div",{className:"h-full flex flex-col animate-fade-in",children:[s?e.jsxs("div",{className:"px-5 pt-4 flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>I(),title:"Rescan",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:e.jsx($e,{size:15})}),e.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 transition-colors",children:[e.jsx(rs,{size:15})," Load config"]})]}):e.jsxs("div",{className:"px-5 py-3 border-b border-white/5 bg-surface-1 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(As,{size:20,className:"text-brand-400"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-base font-semibold text-gray-100 leading-tight",children:"Environments"}),e.jsx("p",{className:"text-[11px] text-gray-500",children:"Edit your project's env files — changes write straight back to the file."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>I(),title:"Rescan",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:e.jsx($e,{size:15})}),e.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 transition-colors",children:[e.jsx(rs,{size:15})," Load config"]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5",children:j?e.jsx("div",{className:"text-sm text-gray-500",children:"Loading…"}):z?e.jsx("div",{className:"text-sm text-rose-400",children:z}):a.length===0?e.jsx(Jn,{onAdd:()=>S(!0)}):e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[a.map(R=>e.jsxs("button",{onClick:()=>i(R.file),title:R.file,className:`group inline-flex items-center gap-2 h-9 px-3.5 rounded-lg border text-sm transition-colors ${m===R.file?"bg-brand-500/10 border-brand-500/50 text-gray-900 dark:text-gray-50 font-medium ring-1 ring-brand-500/20":"bg-surface-1 border-black/10 dark:border-white/10 text-gray-500 hover:text-gray-800 dark:hover:text-gray-200 hover:bg-black/[0.04] dark:hover:bg-white/[0.06] hover:border-black/20 dark:hover:border-white/20"}`,children:[e.jsx(vs,{size:15,className:`flex-shrink-0 ${m===R.file?"text-brand-500":"text-gray-400 dark:text-gray-500"}`}),e.jsx("span",{className:"truncate max-w-[160px]",children:R.label}),R.manual&&e.jsx("span",{className:"flex-shrink-0 text-[9px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-700 dark:text-brand-300 border border-brand-600/40 dark:border-brand-500/30 leading-none",title:"Loaded by you",children:"loaded"}),m===R.file&&v&&e.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-amber-400",title:"Unsaved changes"})]},R.file)),e.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-1.5 h-9 px-3.5 rounded-lg border border-dashed border-black/15 dark:border-white/15 text-sm text-gray-500 hover:text-gray-800 dark:hover:text-gray-200 hover:border-black/30 dark:hover:border-white/30 transition-colors",children:[e.jsx(rs,{size:14,className:"flex-shrink-0"})," Load config"]})]}),h&&e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-surface-1 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-gray-100",children:h.label}),e.jsx("code",{className:"text-[11px] text-gray-500 font-mono",children:h.file}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-gray-500 border border-white/10 rounded px-1.5 py-0.5",children:Kt(h.format)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v&&!u&&e.jsxs("button",{onClick:N,title:"Discard unsaved changes",className:"inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg border border-white/10 text-gray-400 hover:text-rose-300 hover:border-rose-500/30 hover:bg-rose-500/10 transition-colors",children:[e.jsx(Ya,{size:15})," Discard"]}),e.jsxs("button",{onClick:ee,disabled:!v||u,className:`inline-flex items-center gap-1.5 text-sm px-3.5 py-1.5 rounded-lg border transition-colors ${v&&!u?"bg-brand-500/15 text-brand-300 border-brand-500/30 hover:bg-brand-500/25":"bg-white/5 text-gray-600 border-white/5 cursor-not-allowed"}`,children:[e.jsx(Et,{size:15})," ",u?"Saving…":v?"Save changes":"Saved"]})]})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[x>=0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs text-gray-400 mb-1.5",children:["Base URL ",e.jsxs("span",{className:"text-gray-600 font-mono",children:["· ",f[x].key]})]}),e.jsx("input",{value:f[x].value,onChange:R=>r(x,{value:R.target.value}),spellCheck:!1,className:"w-full px-3.5 py-2.5 rounded-xl text-sm font-mono bg-surface-2 border border-white/10 text-gray-100 outline-none focus:border-brand-500/50 transition-colors"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs text-gray-400",children:["Variables & secrets ",e.jsxs("span",{className:"text-gray-600",children:["· ",f.length]})]}),!o&&e.jsxs("button",{onClick:P,className:"inline-flex items-center gap-1 text-xs text-brand-300 hover:text-brand-200",children:[e.jsx(je,{size:13})," Add variable"]})]}),e.jsxs("div",{className:"rounded-xl border border-white/10 overflow-hidden divide-y divide-white/5",children:[f.length===0&&e.jsx("div",{className:"px-4 py-6 text-center text-sm text-gray-600",children:"No variables yet — add one."}),f.map((R,G)=>{const _=R.secret&&!V.has(G);return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 hover:bg-white/[0.02] group",children:[e.jsx("input",{value:R.key,readOnly:o,onChange:A=>r(G,{key:A.target.value,secret:R.secret||Gn.test(A.target.value)}),placeholder:"KEY",spellCheck:!1,className:`w-[34%] bg-transparent text-sm font-mono text-gray-200 outline-none placeholder-gray-600 focus:text-white ${o?"cursor-default":""}`}),e.jsxs("div",{className:"flex-1 flex items-center gap-1.5",children:[e.jsx("input",{value:R.value,type:_?"password":"text",onChange:A=>r(G,{value:A.target.value}),placeholder:"value",spellCheck:!1,className:"flex-1 bg-transparent text-sm font-mono text-gray-300 outline-none placeholder-gray-600"}),R.secret&&e.jsx("button",{onClick:()=>B(G),title:_?"Reveal":"Hide",className:"p-1 text-gray-500 hover:text-gray-300",children:_?e.jsx(ve,{size:14}):e.jsx(is,{size:14})})]}),e.jsxs("button",{onClick:()=>r(G,{secret:!R.secret}),title:R.secret?"Marked secret — click to make plain":"Marked plain — click to make secret",className:`flex items-center gap-1 text-[11px] w-[58px] justify-end ${R.secret?"text-amber-400/90 hover:text-amber-300":"text-gray-500 hover:text-gray-300"}`,children:[R.secret?e.jsx(Qa,{size:11}):null,R.secret?"secret":"plain"]}),!o&&e.jsx("button",{onClick:()=>E(G),title:"Remove",className:"p-1 text-gray-600 hover:text-rose-400 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(we,{size:14})})]},G)})]}),e.jsx("p",{className:"mt-2 text-[11px] text-gray-600",children:o?e.jsxs(e.Fragment,{children:["This config file is code — the values listed are edited in place; keys can't be added or renamed here. Other code in ",e.jsx("code",{className:"font-mono",children:h.file})," is left untouched."]}):e.jsxs(e.Fragment,{children:["Secrets are masked here only; values are written to ",e.jsx("code",{className:"font-mono",children:h.file})," in plain text, as the file format requires. The ",e.jsx("span",{className:"text-gray-500",children:"secret/plain"})," flag is detected from the key name."]})})]})]})]})]})}),O&&e.jsx(qn,{loaded:a.filter(R=>R.manual),onClose:()=>S(!1),onLoad:K,onUnload:W})]})}function qn({loaded:s,onClose:t,onLoad:a,onUnload:l}){const[m,i]=n.useState([]),[h,d]=n.useState(!0),[f,g]=n.useState(""),[y,c]=n.useState("");n.useEffect(()=>{Mr().then(p=>i(p.candidates)).catch(()=>i([])).finally(()=>d(!1))},[]);const j=m.filter(p=>!y||p.file.toLowerCase().includes(y.toLowerCase()));return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[85vh] flex flex-col rounded-2xl border border-white/10 bg-surface-1 shadow-2xl",onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{size:18,className:"text-brand-400"}),e.jsx("h2",{className:"text-[15px] font-semibold text-gray-100",children:"Load a config file"})]}),e.jsx("button",{onClick:t,className:"p-1 text-gray-500 hover:text-gray-300",children:e.jsx(me,{size:18})})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-400 mb-1.5",children:"Paste a path to a config in a custom location"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:f,onChange:p=>g(p.target.value),onKeyDown:p=>{p.key==="Enter"&&f.trim()&&a(f.trim())},placeholder:"e.g. config/qa/settings.properties",spellCheck:!1,className:"flex-1 px-3 py-2 rounded-lg text-sm font-mono bg-surface-2 border border-white/10 text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50"}),e.jsxs("button",{onClick:()=>f.trim()&&a(f.trim()),disabled:!f.trim(),className:"inline-flex items-center gap-1.5 text-sm px-3 py-2 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 disabled:opacity-40",children:[e.jsx(Xa,{size:14})," Load"]})]})]}),s.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-gray-400 mb-1.5",children:["Loaded by you · ",s.length]}),e.jsx("div",{className:"rounded-lg border border-white/10 divide-y divide-white/5",children:s.map(p=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-sm",children:[e.jsx(vs,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"text-gray-300 truncate flex-1",title:p.file,children:p.file}),e.jsx("button",{onClick:()=>l(p.file),title:"Un-load",className:"p-1 text-gray-600 hover:text-rose-400",children:e.jsx(we,{size:14})})]},p.file))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs text-gray-400",children:["Detected, not loaded ",!h&&`· ${j.length}`]}),m.length>8&&e.jsx("input",{value:y,onChange:p=>c(p.target.value),placeholder:"filter…",spellCheck:!1,className:"w-32 px-2 py-1 rounded-md text-xs bg-surface-2 border border-white/10 text-gray-300 outline-none placeholder-gray-600"})]}),h?e.jsx("div",{className:"text-sm text-gray-600 px-1 py-3",children:"Scanning…"}):j.length===0?e.jsx("div",{className:"text-sm text-gray-600 px-3 py-4 rounded-lg border border-dashed border-white/10 text-center",children:"Nothing else found — use the path box above for custom locations."}):e.jsx("div",{className:"rounded-lg border border-white/10 divide-y divide-white/5 max-h-64 overflow-auto",children:j.map(p=>e.jsxs("button",{onClick:()=>a(p.file),className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-left hover:bg-white/[0.03] group",children:[e.jsx(vs,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"text-gray-300 truncate flex-1",title:p.file,children:p.file}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-gray-600",children:Kt(p.format)}),e.jsx(je,{size:14,className:"text-brand-400 opacity-0 group-hover:opacity-100"})]},p.file))})]})]})]})})}function Jn({onAdd:s}){return e.jsxs("div",{className:"max-w-md mx-auto mt-16 text-center",children:[e.jsx("div",{className:"inline-flex p-3 rounded-2xl bg-surface-2 border border-white/10 mb-4",children:e.jsx(As,{size:28,className:"text-gray-500"})}),e.jsx("h2",{className:"text-base font-semibold text-gray-200 mb-1",children:"No environment files found"}),e.jsxs("p",{className:"text-sm text-gray-500 mb-5",children:["Testver looks for ",e.jsx("code",{className:"font-mono text-gray-400",children:".env"}),", ",e.jsx("code",{className:"font-mono text-gray-400",children:".env.*"}),","," ",e.jsx("code",{className:"font-mono text-gray-400",children:"*.properties"}),", ",e.jsx("code",{className:"font-mono text-gray-400",children:"*.env.json"})," and ",e.jsx("code",{className:"font-mono text-gray-400",children:"cypress.config.*"})," files, and can load any ",e.jsx("code",{className:"font-mono text-gray-400",children:"*.config.ts"})," / ",e.jsx("code",{className:"font-mono text-gray-400",children:".js"})," on request."," ","Load one from a custom location if it wasn't picked up."]}),e.jsxs("button",{onClick:s,className:"inline-flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-brand-500/15 text-brand-300 border border-brand-500/30 hover:bg-brand-500/25 transition-colors",children:[e.jsx(rs,{size:15})," Load config"]})]})}async function es(s,t){const a=Ys(),l=await fetch(s,{...t,headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{},...t==null?void 0:t.headers}});if(!l.ok)throw new Error((await l.json().catch(()=>({}))).error||l.statusText);return l.json()}function Le(s){const t=Date.now()-s;return t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}const _t=30;function Ht(s){if(s.source==="test-run"||s.source==="orphan-browser"||s.source==="run-browser")return null;const t=s.lastActivityAt??s.startedAt,a=(Date.now()-t)/6e4;return a<_t?null:`Idle ${Math.round(a)}m`}function Vt({source:s}){return s==="server-pool"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-brand-300 bg-brand-500/10 border border-brand-500/30",children:[e.jsx(Ve,{size:10})," Server"]}):s==="local-connector"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-emerald-300 bg-emerald-500/10 border border-emerald-500/30",children:[e.jsx(ds,{size:10})," Local"]}):s==="run-browser"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-sky-300 bg-sky-500/10 border border-sky-500/30",children:[e.jsx(qe,{size:10})," Run browser"]}):s==="orphan-browser"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-rose-300 bg-rose-500/10 border border-rose-500/30",children:[e.jsx(Hs,{size:10})," Orphaned"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium text-amber-300 bg-amber-500/10 border border-amber-500/30",children:[e.jsx(Za,{size:10})," Test run"]})}function Yn({open:s,title:t,body:a,confirmLabel:l,variant:m="normal",busy:i,onConfirm:h,onCancel:d}){return n.useEffect(()=>{if(!s)return;const f=g=>{g.key==="Escape"&&!i&&d()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s,i,d]),s?fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:d,children:e.jsxs("div",{className:"w-[480px] bg-surface-1 border border-white/10 rounded-2xl shadow-2xl",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-white/5",children:[e.jsx(ue,{size:18,className:m==="danger"?"text-red-400":"text-amber-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100 flex-1",children:t}),e.jsx("button",{onClick:d,disabled:i,className:"text-gray-500 hover:text-gray-200 transition-colors disabled:opacity-50",children:e.jsx(me,{size:18})})]}),e.jsx("div",{className:"px-5 py-4 text-sm text-gray-300 leading-relaxed",children:a}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3.5 border-t border-white/5",children:[e.jsx("button",{onClick:d,disabled:i,className:"px-3 py-1.5 text-sm font-medium text-gray-400 hover:text-gray-200 transition-colors disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:h,disabled:i,className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 inline-flex items-center gap-2 ${m==="danger"?"text-white bg-red-600 hover:bg-red-700":"text-white bg-amber-600 hover:bg-amber-700"}`,children:[i&&e.jsx(J,{size:13,className:"animate-spin"}),l]})]})]})}),document.body):null}function Qn({session:s,showUser:t,onCloseClicked:a,closing:l}){const m=Ht(s);return e.jsx("div",{className:`p-3.5 rounded-lg border transition-colors ${m?"bg-surface-2/30 border-white/5":"bg-surface-2/50 border-white/10"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 shrink-0",children:s.browserType?e.jsx(mn,{browser:s.browserType,size:22}):e.jsx(Ve,{size:22,className:"text-gray-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(Vt,{source:s.source}),s.browserType&&e.jsx("span",{className:"text-sm font-medium text-gray-100 capitalize",children:s.browserType}),t&&s.username&&e.jsxs("span",{className:"text-xs text-gray-400",children:["· ",s.username]}),m&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-gray-500",children:[e.jsx(zs,{size:10})," ",m]})]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1.5 leading-relaxed",children:[s.source==="server-pool"&&e.jsxs(e.Fragment,{children:["Started ",Le(s.startedAt),s.pid&&e.jsxs(e.Fragment,{children:[" · pid ",s.pid]}),s.clientIds.length>0&&e.jsxs(e.Fragment,{children:[" · ",s.clientIds.length," tab",s.clientIds.length===1?"":"s"]})]}),s.source==="local-connector"&&e.jsxs(e.Fragment,{children:["Connected ",Le(s.startedAt),s.machine&&e.jsxs(e.Fragment,{children:[" from ",e.jsx("span",{className:"text-gray-300",children:s.machine})]}),s.os&&e.jsxs(e.Fragment,{children:[" · ",s.os]}),s.clientIds.length>0&&e.jsxs(e.Fragment,{children:[" · ",s.clientIds.length," tab",s.clientIds.length===1?"":"s"]})]}),s.source==="test-run"&&e.jsxs(e.Fragment,{children:["Started ",Le(s.startedAt),s.framework&&e.jsxs(e.Fragment,{children:[" · ",s.framework]}),s.pid&&e.jsxs(e.Fragment,{children:[" · runner pid ",s.pid]})]}),s.source==="run-browser"&&e.jsxs(e.Fragment,{children:["Open since ",Le(s.startedAt),s.browserType&&e.jsxs(e.Fragment,{children:[" · ",s.browserType]}),s.pid&&e.jsxs(e.Fragment,{children:[" · pid ",s.pid]}),s.framework&&e.jsxs(e.Fragment,{children:[" · ",s.framework," run"]})]}),s.source==="orphan-browser"&&e.jsxs(e.Fragment,{children:["Left open ",Le(s.startedAt),s.browserType&&e.jsxs(e.Fragment,{children:[" · ",s.browserType]}),s.pid&&e.jsxs(e.Fragment,{children:[" · pid ",s.pid]}),s.framework&&e.jsxs(e.Fragment,{children:[" · from ",s.framework," run"]})]})]}),s.source==="test-run"&&s.command&&e.jsxs("code",{className:"block text-[11px] font-mono text-gray-500 mt-1.5 truncate",title:s.command,children:["$ ",s.command]})]}),e.jsxs("button",{onClick:()=>a(s),disabled:l,className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-50",children:[l?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(me,{size:12}),"Close"]})]})})}function Xn(){const[s,t]=n.useState(null),[a,l]=n.useState(!1),[m,i]=n.useState(null),[h,d]=n.useState(null),[f,g]=n.useState(null),[y,c]=n.useState(null),[j,p]=n.useState(!1),[u,b]=n.useState(null),z=n.useCallback(async()=>{try{const r=await es(`/api/browser-sessions${a?"?scope=all":""}`);t(r)}catch(r){d(r.message)}},[a]);n.useEffect(()=>{z();const r=setInterval(z,5e3);return()=>clearInterval(r)},[z]),n.useEffect(()=>{es("/api/system/orphan-reap").then(b).catch(()=>{})},[]);const M=async()=>{if(!u)return;const r={...u,enabled:!u.enabled};b(r);try{const E=await es("/api/system/orphan-reap",{method:"PUT",body:JSON.stringify({enabled:r.enabled})});b(E)}catch(E){b(u),d(E.message)}},V=async()=>{if(f){p(!0),i(f.id),d(null);try{await es(`/api/browser-sessions/${encodeURIComponent(f.id)}`,{method:"DELETE"}),g(null),await z()}catch(r){d(r.message)}finally{p(!1),i(null)}}},U=async()=>{if(y){p(!0),d(null);try{await es("/api/browser-sessions/bulk-close",{method:"POST",body:JSON.stringify({scope:y,mode:"graceful",idleMinutes:_t})}),c(null),await z()}catch(r){d(r.message)}finally{p(!1)}}},O=(s==null?void 0:s.sessions)||[],S=!!(s!=null&&s.isAdmin),I=O.filter(r=>r.userId!=="project").length,w=O.filter(r=>r.source==="server-pool").length,v=O.filter(r=>Ht(r)).length,x=O.filter(r=>r.source==="orphan-browser").length;let o=null;if(f){const r=f,E=r.source==="server-pool"?"close this server-side browser process":r.source==="local-connector"?"disconnect this local-browser connector":r.source==="orphan-browser"?"kill this leftover browser process":r.source==="run-browser"?"close this browser — its test run will fail":"cancel this test run";o={open:!0,title:"Close browser session?",body:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:["You're about to ",E,"."]}),e.jsxs("div",{className:"bg-surface-2/60 border border-white/5 rounded-lg p-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(Vt,{source:r.source}),r.browserType&&e.jsx("span",{className:"text-gray-200 capitalize",children:r.browserType})]}),e.jsxs("div",{className:"text-gray-400",children:[r.source==="server-pool"&&e.jsxs(e.Fragment,{children:[r.pid?`pid ${r.pid}`:"server pool entry"," · started ",Le(r.startedAt)]}),r.source==="local-connector"&&e.jsxs(e.Fragment,{children:[r.machine?`from ${r.machine}`:"local connector"," · started ",Le(r.startedAt)]}),r.source==="test-run"&&e.jsxs(e.Fragment,{children:[r.framework||"test run"," · started ",Le(r.startedAt)]}),r.source==="run-browser"&&e.jsxs(e.Fragment,{children:[r.browserType||"browser",r.pid?` · pid ${r.pid}`:""," · ",r.framework||"test"," run"]}),r.source==="orphan-browser"&&e.jsxs(e.Fragment,{children:[r.browserType||"browser",r.pid?` · pid ${r.pid}`:""," · left open ",Le(r.startedAt)]})]}),r.source==="test-run"&&r.command&&e.jsxs("code",{className:"block text-[11px] text-gray-500 mt-1.5 truncate",title:r.command,children:["$ ",r.command]}),r.clientIds.length>0&&e.jsxs("p",{className:"text-[11px] text-amber-300 mt-2",children:[r.clientIds.length," active tab",r.clientIds.length===1?"":"s"," ",r.clientIds.length===1?"is":"are"," using this session — its live preview will tear down immediately."]})]})]}),confirmLabel:"Close session",variant:"danger",busy:j,onConfirm:V,onCancel:()=>!j&&g(null)}}else if(y){const r={mine:"Close all of your sessions?","server-pool":"Close all server-side browsers?",idle:"Close all idle sessions?",all:"Close every session for every user?",orphaned:"Close orphaned browsers?"},E={mine:e.jsxs("p",{children:["This closes every browser session you currently own. Any in-flight tool calls get up to ",e.jsx("strong",{children:"5 seconds"})," to complete (graceful shutdown) before being terminated."]}),"server-pool":e.jsxs("p",{children:["This closes every server-side per-tab browser process — useful for freeing server RAM. ",e.jsx("strong",{children:"Local-connector"})," sessions and ",e.jsx("strong",{children:"active test runs"})," are left alone. ",w," session",w===1?"":"s"," will be closed."]}),idle:e.jsxs("p",{children:["Closes every session that has been idle for more than ",e.jsx("strong",{children:"30 minutes"}),". Active sessions are unaffected. ",v," idle session",v===1?"":"s"," match."]}),all:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:["This closes ",e.jsx("strong",{children:"every"})," active browser session across ",e.jsx("strong",{children:"all users"}),", including their local connectors and any running tests."]}),e.jsx("p",{className:"text-red-400 text-xs",children:"Every user mid-action will see their browser terminate. Use only for maintenance windows."})]}),orphaned:e.jsxs("p",{children:["Kills every ",e.jsx("strong",{children:"orphaned browser"})," — leftover browser processes from runs that already finished. Active sessions and running tests are unaffected. ",x," orphaned browser",x===1?"":"s"," will be closed."]})};o={open:!0,title:r[y],body:E[y],confirmLabel:"Close sessions",variant:y==="all"?"danger":"normal",busy:j,onConfirm:U,onCancel:()=>!j&&c(null)}}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Ve,{size:18,className:"text-brand-400"}),"Browser Sessions"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[S&&e.jsx("button",{onClick:()=>l(!a),className:`px-3 py-1.5 text-xs font-medium rounded-lg border transition-colors ${a?"bg-brand-500/15 text-brand-300 border-brand-500/30":"bg-surface-2/40 text-gray-400 border-white/5 hover:text-gray-200"}`,children:a?"Showing all users":"Show all users"}),e.jsxs("button",{onClick:z,className:"px-3 py-1.5 text-xs font-medium text-gray-400 hover:text-gray-200 transition-colors inline-flex items-center gap-1.5",children:[e.jsx($e,{size:12})," Refresh"]})]})]}),e.jsx("p",{className:"text-sm text-gray-500",children:"Manage active browser sessions on this server. Closing a session terminates its underlying browser process and tears down any live previews using it."}),e.jsxs("div",{className:"flex items-center gap-5 text-sm text-gray-400 pt-2 border-t border-white/5",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:O.length})," total"]}),(s==null?void 0:s.summary)&&s.summary.users>1&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:s.summary.users})," users"]}),w>0&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:w})," server-side"]}),v>0&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-200",children:v})," idle"]}),x>0&&e.jsxs("span",{className:"text-rose-300",children:[e.jsx("strong",{children:x})," orphaned"]})]})]}),O.length>0&&e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-3",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(we,{size:18,className:"text-brand-400"}),"Bulk close",e.jsx("span",{className:"text-xs font-normal text-gray-500 ml-1",children:"(graceful — waits up to 5s for in-flight actions)"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>c("mine"),disabled:j||I===0,className:"px-3 py-1.5 text-sm font-medium text-gray-200 bg-surface-2/60 hover:bg-surface-2/90 rounded-lg border border-white/5 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(we,{size:13})," My sessions"]}),e.jsxs("button",{onClick:()=>c("orphaned"),disabled:j||x===0,className:"px-3 py-1.5 text-sm font-medium text-rose-300 bg-rose-500/10 hover:bg-rose-500/20 rounded-lg border border-rose-500/30 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(Hs,{size:13})," Close orphaned",x>0?` (${x})`:""]}),S&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>c("server-pool"),disabled:j||w===0,className:"px-3 py-1.5 text-sm font-medium text-gray-200 bg-surface-2/60 hover:bg-surface-2/90 rounded-lg border border-white/5 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(Ve,{size:13})," All server sessions"]}),e.jsxs("button",{onClick:()=>c("idle"),disabled:j||v===0,className:"px-3 py-1.5 text-sm font-medium text-gray-200 bg-surface-2/60 hover:bg-surface-2/90 rounded-lg border border-white/5 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(zs,{size:13})," Idle > 30m"]}),e.jsxs("button",{onClick:()=>c("all"),disabled:j,className:"px-3 py-1.5 text-sm font-medium text-red-300 bg-red-500/10 hover:bg-red-500/20 rounded-lg border border-red-500/30 transition-colors disabled:opacity-50 inline-flex items-center gap-1.5",children:[e.jsx(ue,{size:13})," All sessions"]})]})]}),S&&u&&e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3 mt-1 border-t border-white/5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-200 flex items-center gap-2",children:[e.jsx(Hs,{size:14,className:"text-rose-400"})," Auto-close orphaned browsers"]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:["When a run finishes, kill any browsers it left open after ",u.graceSeconds,"s. Off by default — leftovers are surfaced above for manual close."]})]}),e.jsx("button",{role:"switch","aria-checked":u.enabled,onClick:M,className:`relative shrink-0 w-10 h-6 rounded-full transition-colors ${u.enabled?"bg-brand-500":"bg-surface-3 border border-white/10"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white transition-transform ${u.enabled?"translate-x-4":""}`})})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(qe,{size:18,className:"text-brand-400"}),"Active sessions"]}),O.length===0?e.jsxs("div",{className:"flex flex-col items-center text-center py-10",children:[e.jsx(Ve,{size:32,className:"text-gray-700 mb-3"}),e.jsx("p",{className:"text-sm text-gray-300 font-medium",children:"No active browser sessions"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 max-w-sm",children:"Sessions appear here when you launch a browser via /ai, register a Local Browser connector, or start a test run."})]}):e.jsx("div",{className:"space-y-2",children:O.map(r=>e.jsx(Qn,{session:r,showUser:a&&S,onCloseClicked:E=>g(E),closing:m===r.id},r.id))})]}),h&&e.jsx("div",{className:"text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:h}),o&&e.jsx(Yn,{...o})]})}async function $s(s,t){const a=Ys(),l=await fetch(s,{...t,headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{},...t==null?void 0:t.headers}});if(!l.ok)throw new Error((await l.json().catch(()=>({}))).error||l.statusText);return l.json()}function pt(s){const t=Date.now()-s;if(t<0){const a=Math.abs(t);return a<6e4?`in ${Math.round(a/1e3)}s`:a<36e5?`in ${Math.round(a/6e4)}m`:a<864e5?`in ${Math.round(a/36e5)}h`:`in ${Math.round(a/864e5)}d`}return t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Zn({open:s,onClose:t,onTokenChange:a}){const[l,m]=n.useState([]),[i,h]=n.useState(!1),[d,f]=n.useState(null),[g,y]=n.useState(null),[c,j]=n.useState(null),[p,u]=n.useState(null),[b,z]=n.useState(!1),M=n.useCallback(async()=>{if(s)try{const I=(await $s("/api/local-browser/tokens")).tokens||[];m(I),u(w=>{if(!w)return w;const v=I.find(x=>w.token.startsWith(x.tokenPrefix));return!v||v.status==="active"||v.status==="used"?null:w})}catch(S){j(S.message)}},[s]);n.useEffect(()=>{if(!s)return;M();const S=setInterval(M,5e3);return()=>clearInterval(S)},[s,M]),n.useEffect(()=>{if(!s)return;const S=I=>{I.key==="Escape"&&t()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[s,t]);const V=async()=>{h(!0),j(null);try{const S=await $s("/api/local-browser/token",{method:"POST"});u(S),a==null||a(),M()}catch(S){j(S.message)}finally{h(!1)}},U=async S=>{y(S),j(null);try{await $s(`/api/local-browser/tokens/${encodeURIComponent(S)}`,{method:"DELETE"}),f(null),p&&p.token.startsWith(S)&&(u(null),z(!1)),a==null||a(),M()}catch(I){j(I.message)}finally{y(null)}},O=()=>{p&&(navigator.clipboard.writeText(p.command).catch(()=>{}),z(!0),setTimeout(()=>z(!1),2e3))};return s?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:t,children:e.jsxs("div",{className:"w-[640px] max-h-[80vh] flex flex-col bg-surface-1 border border-white/10 rounded-2xl shadow-2xl",onClick:S=>S.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-white/5",children:[e.jsx(Vs,{size:18,className:"text-brand-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100 flex-1",children:"Local Browser Tokens"}),e.jsx("button",{onClick:t,className:"text-gray-500 hover:text-gray-200 transition-colors",children:e.jsx(me,{size:18})})]}),p&&e.jsxs("div",{className:"mx-5 mt-4 p-3 bg-brand-500/10 border border-brand-500/20 rounded-lg",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-brand-300 mb-1.5",children:"New token — copy it now (won't be shown again)"}),e.jsxs("div",{className:"relative bg-surface-2 border border-white/5 rounded p-2 pr-9",children:[e.jsx("code",{className:"text-[11px] font-mono text-gray-200 break-all leading-relaxed",children:p.command}),e.jsx("button",{onClick:O,className:"absolute top-1.5 right-1.5 p-1.5 rounded hover:bg-white/5 transition-colors",title:"Copy",children:b?e.jsx(Ue,{size:14,className:"text-emerald-400"}):e.jsx(xs,{size:14,className:"text-gray-400"})})]}),e.jsx("button",{onClick:()=>u(null),className:"text-[10px] text-gray-500 hover:text-gray-300 mt-2",children:"Dismiss"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[l.length===0&&!p?e.jsxs("div",{className:"flex flex-col items-center text-center py-8",children:[e.jsx(Vs,{size:32,className:"text-gray-600 mb-3"}),e.jsx("p",{className:"text-sm text-gray-300 font-medium",children:"No tokens yet"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 max-w-xs",children:"Tokens let you connect a browser running on your machine to this server. Each token can be used once to register a connector."})]}):e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-xs text-gray-400 mb-2",children:"Manage connection tokens for your account. Revoking a token immediately disconnects any connector using it."}),l.map(S=>{const I=d===S.tokenPrefix;return e.jsxs("div",{className:`p-3 rounded-lg border transition-colors ${S.status==="active"?"bg-emerald-500/5 border-emerald-500/20":S.status==="expired"?"bg-red-500/5 border-red-500/15 opacity-70":"bg-surface-2/40 border-white/5"}`,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(el,{status:S.status}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-2 mb-0.5",children:e.jsx("span",{className:"text-[10px] uppercase tracking-wider font-medium text-gray-400",children:S.status})}),e.jsxs("code",{className:"text-[11px] font-mono text-gray-300 block",children:[S.tokenPrefix,"…"]}),e.jsxs("p",{className:"text-[11px] text-gray-500 mt-1 leading-relaxed",children:[S.status==="active"&&S.machine&&e.jsxs(e.Fragment,{children:["Connected from ",S.machine]}),S.status==="active"&&!S.machine&&e.jsx(e.Fragment,{children:"Connector active"}),S.status==="pending"&&e.jsx(e.Fragment,{children:"Not yet used"}),S.status==="used"&&e.jsx(e.Fragment,{children:"Used (connector disconnected)"}),S.status==="expired"&&e.jsx(e.Fragment,{children:"Expired"}),e.jsx("span",{className:"mx-1.5 text-gray-700",children:"·"}),"Issued ",pt(S.createdAt),S.status!=="expired"&&S.status!=="used"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1.5 text-gray-700",children:"·"}),"Expires ",pt(S.expiresAt)]})]})]}),I?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>f(null),className:"text-[11px] text-gray-400 hover:text-gray-200 px-2 py-1 rounded transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:()=>U(S.tokenPrefix),disabled:g===S.tokenPrefix,className:"text-[11px] font-medium text-white bg-red-600 hover:bg-red-700 px-2.5 py-1 rounded transition-colors disabled:opacity-50 flex items-center gap-1",children:[g===S.tokenPrefix&&e.jsx(J,{size:11,className:"animate-spin"}),"Confirm revoke"]})]}):e.jsx("button",{onClick:()=>f(S.tokenPrefix),disabled:g===S.tokenPrefix,className:"text-[11px] font-medium text-red-400 hover:text-red-300 hover:bg-red-500/10 px-2 py-1 rounded transition-colors disabled:opacity-50",children:"Revoke"})]}),I&&e.jsx("p",{className:"text-[10px] text-red-400/80 mt-2 ml-7",children:"Any active connector using this token will disconnect immediately."})]},S.tokenPrefix)})]}),c&&e.jsx("div",{className:"mt-3 text-[11px] text-red-400 bg-red-500/10 border border-red-500/20 rounded p-2",children:c})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-5 py-3.5 border-t border-white/5",children:[e.jsxs("p",{className:"text-[11px] text-gray-500",children:[l.length," token",l.length===1?"":"s"," · max 5 per account"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:V,disabled:i||l.length>=5,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-brand-300 bg-brand-500/15 hover:bg-brand-500/25 rounded-lg transition-colors border border-brand-500/30 disabled:opacity-50",title:l.length>=5?"Revoke an existing token to free up a slot":"",children:[i?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(qe,{size:12}),"Generate New Token"]}),e.jsx("button",{onClick:t,className:"px-3 py-1.5 text-xs font-medium text-gray-400 hover:text-gray-200 transition-colors",children:"Close"})]})]})]})}):null}function el({status:s}){return s==="active"?e.jsx(ne,{size:14,className:"text-emerald-400 mt-0.5 shrink-0"}):s==="pending"?e.jsx(zs,{size:14,className:"text-amber-400 mt-0.5 shrink-0"}):s==="used"?e.jsx(ne,{size:14,className:"text-gray-500 mt-0.5 shrink-0"}):e.jsx(ue,{size:14,className:"text-red-400 mt-0.5 shrink-0"})}async function hs(s,t){const a=Ys(),l=await fetch(s,{...t,headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{},...t==null?void 0:t.headers}});if(!l.ok)throw new Error((await l.json().catch(()=>({}))).error||l.statusText);return l.json()}function sl(){var U,O;const[s,t]=n.useState(null),[a,l]=n.useState(!1),[m,i]=n.useState(null),[h,d]=n.useState(!1),[f,g]=n.useState(null),[y,c]=n.useState(!1),[j,p]=n.useState(0),u=n.useCallback(async()=>{try{const S=await hs("/api/local-browser/status");t(S)}catch(S){g(S.message)}try{const S=await hs("/api/local-browser/tokens");p((S.tokens||[]).length)}catch{}},[]);n.useEffect(()=>{u();const S=setInterval(u,5e3);return()=>clearInterval(S)},[u]);const b=async()=>{l(!0),g(null);try{const S=await hs("/api/local-browser/token",{method:"POST"});i(S)}catch(S){g(S.message)}finally{l(!1)}},z=async()=>{l(!0),g(null);try{await hs("/api/local-browser/disconnect",{method:"POST"}),await u(),i(null)}catch(S){g(S.message)}finally{l(!1)}},M=()=>{m&&(navigator.clipboard.writeText(m.command).catch(()=>{}),d(!0),setTimeout(()=>d(!1),2e3))},V=(s==null?void 0:s.connected)===!0;return e.jsxs("div",{className:`bg-white dark:bg-surface-1 rounded-xl border p-5 transition-all flex flex-col ${V?"border-emerald-200 dark:border-emerald-500/20":"border-gray-200 dark:border-white/5 hover:border-brand-300 dark:hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(ds,{size:28,className:"text-brand-500"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Local Browser"})}),V&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-200 dark:border-emerald-500/20 shrink-0",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]}),e.jsxs("button",{onClick:()=>c(!0),className:"relative p-1.5 rounded-md text-gray-500 hover:text-brand-400 hover:bg-brand-500/10 transition-colors shrink-0",title:j>0?`Manage tokens (${j})`:"Manage tokens","aria-label":"Manage local browser tokens",children:[e.jsx(Vs,{className:"w-4 h-4"}),j>0&&e.jsx("span",{className:`absolute -top-0.5 -right-0.5 min-w-[16px] h-[16px] px-1 rounded-full text-[9px] font-semibold leading-none flex items-center justify-center border ${V?"bg-emerald-500/20 text-emerald-300 border-emerald-500/40":"bg-brand-500/20 text-brand-300 border-brand-500/40"}`,children:j})]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4 line-clamp-3",children:"Run AI Assistance browser actions on YOUR machine instead of the server. Useful for localhost apps, SSO-protected sites, and reducing server load."}),V?e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5 space-y-2",children:[e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 space-y-1",children:[((U=s==null?void 0:s.client)==null?void 0:U.machine)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Machine:"})," ",s.client.machine]}),((O=s==null?void 0:s.client)==null?void 0:O.os)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"OS:"})," ",s.client.os]}),(s==null?void 0:s.registeredAt)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Connected:"})," ",new Date(s.registeredAt).toLocaleTimeString()]})]}),e.jsxs("button",{onClick:z,disabled:a,className:"w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-500/10 hover:bg-red-100 dark:hover:bg-red-500/20 rounded-lg transition-colors border border-red-200 dark:border-red-500/20 disabled:opacity-50",children:[a?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(qe,{className:"w-3.5 h-3.5"}),"Disconnect"]})]}):m?e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-gray-500 mb-1.5",children:"Run this on your machine:"}),e.jsxs("div",{className:"relative bg-surface-2 dark:bg-surface-2 border border-white/5 rounded-lg p-2 pr-10",children:[e.jsx("code",{className:"text-[11px] font-mono text-gray-200 break-all leading-relaxed",children:m.command}),e.jsx("button",{onClick:M,className:"absolute top-1.5 right-1.5 p-1.5 rounded hover:bg-white/5 transition-colors",title:"Copy command",children:h?e.jsx(Ue,{size:14,className:"text-emerald-400"}):e.jsx(xs,{size:14,className:"text-gray-400"})})]}),e.jsx("p",{className:"text-[10px] text-gray-500 mt-1.5",children:"Token expires in 24 hours. Single-use — once your connector registers, the token is consumed."})]}),e.jsxs("button",{onClick:()=>{i(null),u()},className:"w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-gray-600 dark:text-gray-400 hover:text-gray-200 hover:bg-white/5 rounded-lg transition-colors",children:[e.jsx($e,{className:"w-3.5 h-3.5"})," Refresh status"]})]}):e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("button",{onClick:b,disabled:a,className:"w-full flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-500/10 hover:bg-brand-100 dark:hover:bg-brand-500/20 rounded-lg transition-colors border border-brand-200 dark:border-brand-500/20 disabled:opacity-50",children:[a?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(qe,{className:"w-3.5 h-3.5"}),"Generate Connection Token"]})}),f&&e.jsx("div",{className:"mt-2 text-[11px] text-red-500 bg-red-50 dark:bg-red-500/10 border border-red-200 dark:border-red-500/20 rounded p-2",children:f}),e.jsx(Zn,{open:y,onClose:()=>c(!1),onTokenChange:u})]})}function Gs({size:s=16,className:t}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"currentColor",className:t,"aria-hidden":"true",children:e.jsx("path",{d:"M17.523 15.3414c-.5511 0-.9993-.4486-.9993-.9997s.4482-.9993.9993-.9993c.5511 0 .9993.4482.9993.9993 0 .5511-.4482.9997-.9993.9997m-11.046 0c-.5511 0-.9993-.4486-.9993-.9997s.4482-.9993.9993-.9993c.5511 0 .9993.4482.9993.9993 0 .5511-.4482.9997-.9993.9997m11.4045-6.02l1.9973-3.4592a.416.416 0 00-.1521-.5676.416.416 0 00-.5676.1521l-2.0223 3.503C15.5902 8.2439 13.8533 7.8508 12 7.8508s-3.5902.3931-5.1367 1.0989L4.841 5.4467a.4161.4161 0 00-.5677-.1521.4157.4157 0 00-.1521.5676l1.9973 3.4592C2.6889 11.1867.3432 14.6589 0 18.761h24c-.3435-4.1021-2.6892-7.5743-6.1185-9.4396"})})}function ss({size:s=16,className:t}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"currentColor",className:t,"aria-hidden":"true",children:e.jsx("path",{d:"M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.677-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"})})}const tl=4e3,rl=15e3;function al(){var ie,be,oe,k;const{toast:s}=ge(),[t,a]=n.useState(null),[l,m]=n.useState(null),[i,h]=n.useState({}),[d,f]=n.useState(!0),[g,y]=n.useState(!1),[c,j]=n.useState(!1),[p,u]=n.useState(!1),[b,z]=n.useState(!1),[M,V]=n.useState(!1),U=n.useRef(!1),O=async(C=!1)=>{if(!(U.current&&!C)){U.current=!0,C&&y(!0);try{const q=await Ir();a(q.status),m(q.config),h(q.hints||{})}catch(q){s("error",`Detection failed: ${q}`)}finally{U.current=!1,f(!1),C&&y(!1)}}};n.useEffect(()=>{O()},[]),n.useEffect(()=>{const C=setInterval(()=>{document.visibilityState!=="hidden"&&O(!1)},p?tl:rl);return()=>clearInterval(C)},[p]);const[S,I]=n.useState(null),w=async C=>{I(C.name),s("info",`Starting ${C.name.replace(/_/g," ")} — this can take a minute or two.`);try{const q=await Ur(C.name);s("success",`${C.name.replace(/_/g," ")} is running (${q.serial}).`)}catch(q){s("error",q.message)}finally{I(null),O(!0)}},v=async C=>{if(C.serial){I(C.name);try{await Or(C.serial),s("success",`${C.name.replace(/_/g," ")} closed.`)}catch(q){s("error",q.message)}finally{I(null),O(!0)}}},[x,o]=n.useState(null),r=C=>(C.name||C.serial).replace(/\s*\(Simulator[^)]*\)$/,""),E=async C=>{o(C.serial),s("info",`Starting ${r(C)} — this can take a minute the first time.`);try{await Kr(C.serial),s("success",`${r(C)} is running.`)}catch(q){s("error",q.message)}finally{o(null),O(!0)}},P=async C=>{o(C.serial);try{await Br(C.serial),s("success",`${r(C)} closed.`)}catch(q){s("error",q.message)}finally{o(null),O(!0)}},B=async(C,q)=>{try{const T=await ms(C);m(T.config),q&&s("success",q)}catch(T){s("error",`Save failed: ${T}`)}},N=async C=>{try{const q=await ms({enabled:C});m(q.config),s("success",C?"Local Devices enabled":"Local Devices disabled")}catch(q){s("error",`Save failed: ${q}`)}},ee=async C=>{try{const q=await ms({appLaunchMode:C});m(q.config),s("success",C==="fresh"?"App will start fresh each run":"App will keep its data each run")}catch(q){s("error",`Save failed: ${q}`)}},K=async(C,q)=>{try{const T=await ms({[C]:q});m(T.config),O(!0)}catch(T){s("error",`Save failed: ${T}`)}},W=async C=>{try{await navigator.clipboard.writeText(C),s("info","Copied to clipboard")}catch{s("error","Clipboard unavailable")}};if(d)return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-8 flex items-center justify-center gap-3 text-gray-400 text-sm",children:[e.jsx(J,{size:16,className:"animate-spin"}),"Detecting local mobile tools…"]});const R=(t==null?void 0:t.hostPlatform)==="darwin",G=(t==null?void 0:t.hostPlatform)==="linux",_=(ie=t==null?void 0:t.appium.drivers)==null?void 0:ie.map(C=>C.toLowerCase()),A=!!_,te=!_||_.includes("uiautomator2"),X=!_||_.includes("xcuitest"),le=(t==null?void 0:t.appium.local)===!1,$=!!(t!=null&&t.android.adbFound)&&!!(t!=null&&t.android.sdkValid),re=$&&te,ae=R&&!!(t!=null&&t.ios.xcodeFound)&&X,ce=!!t&&t.appium.reachable&&!le&&(re||ae),he=i.appium||"npm install -g appium && appium driver install uiautomator2 && appium driver install xcuitest",xe=i.adb||{},ye=i.iosTools||{},Ne=i.xcode||{},ke=R?xe.macos:(t==null?void 0:t.hostPlatform)==="linux"?xe.linux:xe.windows,F=(t==null?void 0:t.android.devices.filter(C=>C.state==="connected").length)??0,Y=(t==null?void 0:t.ios.devices.filter(C=>C.state==="connected"&&(C.kind!=="simulator"||!!C.booted)).length)??0,se=F+Y;return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:[e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("button",{onClick:()=>u(!p),className:"flex items-start gap-4 flex-1 min-w-0 text-left group","aria-expanded":p,children:[e.jsx("div",{className:`w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 ${ce?"bg-emerald-500/15 text-emerald-400":"bg-amber-500/15 text-amber-400"}`,children:e.jsx(Oe,{size:22})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[p?e.jsx(Me,{size:14,className:"text-gray-500"}):e.jsx(Ie,{size:14,className:"text-gray-500"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-200 group-hover:text-brand-500 dark:group-hover:text-brand-300 transition-colors",children:"Local Devices (Appium)"}),e.jsx(nl,{ok:ce,okLabel:"Ready",warnLabel:"Setup needed"}),se>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-emerald-300 bg-emerald-500/15 border border-emerald-500/30 px-2 py-0.5 rounded",children:[e.jsx(Oe,{size:11}),se," device",se===1?"":"s"," connected"]})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5",children:"Run tests on the phones, Android emulators and iOS simulators on this computer, using your own Appium server. No cloud minutes — fastest feedback loop for active development."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>O(!0),disabled:g,className:"p-2 rounded-lg bg-white/5 text-gray-400 border border-white/10 hover:bg-white/10 disabled:opacity-40",title:"Refresh",children:g?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx($e,{size:14})}),e.jsx(gt,{enabled:(l==null?void 0:l.enabled)??!1,onChange:N,label:"Enable"})]})]})}),p&&e.jsxs("div",{className:"border-t border-white/5 bg-surface-0/30 p-5 space-y-4",children:[e.jsx(Ms,{icon:e.jsx(qe,{size:18}),title:"Appium server",ok:!!(t!=null&&t.appium.reachable),okHint:t?`${t.appium.version??"reachable"} at ${t.appium.url}${t.appium.driverVersions&&Object.keys(t.appium.driverVersions).length?` — drivers: ${Object.entries(t.appium.driverVersions).map(([C,q])=>q?`${C} ${q}`:C).join(", ")}`:t.appium.drivers&&t.appium.drivers.length===0?" — no drivers installed":""}`:"",failHint:(t==null?void 0:t.appium.error)||`Not reachable at ${(t==null?void 0:t.appium.url)??"http://127.0.0.1:4723"}`,action:t!=null&&t.appium.reachable?le||!A?e.jsxs("div",{className:"space-y-1.5",children:[le&&e.jsxs("div",{className:"text-[11px] leading-relaxed text-amber-600 dark:text-amber-400",children:["This Appium server is on another computer. Local Devices finds phones, emulators and app files on ",e.jsx("strong",{children:"this"})," computer, so Appium must run here too — start Appium on this machine and set the Appium URL (Advanced, below) to http://127.0.0.1:4723."]}),!A&&!le&&e.jsxs("div",{className:"text-[11px] text-gray-500 leading-relaxed",children:["Installed drivers couldn't be checked (the ",e.jsx("code",{children:"appium"})," command isn't available to Testver). Make sure"," ",e.jsx("code",{children:"uiautomator2"})," (Android) and ",e.jsx("code",{children:"xcuitest"})," (iOS) are installed: ",e.jsx("code",{children:"appium driver list --installed"}),"."]})]}):null:e.jsx(Ae,{label:"Install + start Appium",cmd:`${he} && appium`,onCopy:W})}),(t==null?void 0:t.appium.reachable)&&t.appium.webviewHint&&e.jsx("div",{className:"ml-1 -mt-1 px-3 py-2 rounded-lg bg-amber-500/5 border border-amber-500/20 text-[11px] leading-relaxed text-amber-700 dark:text-amber-300/80",children:t.appium.webviewHint}),e.jsx(Rs,{icon:e.jsx(Gs,{size:16}),title:"Android",summary:re?`${F} device${F===1?"":"s"} ready`:"Setup needed",ok:re,expanded:b,onToggle:()=>z(!b),children:e.jsxs(Ms,{icon:e.jsx(Gs,{size:18}),title:"Android",ok:re,okHint:t?`ADB ${t.android.adbVersion??"✓"} · ${t.android.sdkSource}=${t.android.sdkRoot}${(be=t.appium.driverVersions)!=null&&be.uiautomator2?` · UiAutomator2 ${t.appium.driverVersions.uiautomator2}`:""}`:"",failHint:t!=null&&t.android.adbFound?!(t!=null&&t.android.sdkRoot)&&(t!=null&&t.android.sdkSavedNotLoaded)?`ANDROID_HOME is saved (${t.android.sdkSavedNotLoaded}) but Testver started before it was — restart Testver and your Appium terminal to pick it up`:t!=null&&t.android.sdkRoot?(t==null?void 0:t.android.sdkValid)===!1?`${t.android.sdkSource}="${t.android.sdkRoot}" doesn't look like an Android SDK (missing platform-tools / cmdline-tools / build-tools)`:te?"Android setup incomplete":"The Appium UiAutomator2 driver is not installed — Appium needs it to drive Android":"ANDROID_HOME (or ANDROID_SDK_ROOT) is not set — required by Appium to drive devices":(t==null?void 0:t.android.error)||"ADB not found in PATH or standard SDK locations",action:e.jsxs("div",{className:"space-y-1.5",children:[!(t!=null&&t.android.adbFound)&&ke&&e.jsx(Ae,{label:"Install platform-tools (ADB)",cmd:ke,onCopy:W}),$&&!te&&e.jsx(Ae,{label:"Install the UiAutomator2 driver, then restart Appium",cmd:"appium driver install uiautomator2",onCopy:W}),(t==null?void 0:t.android.adbFound)&&!(t!=null&&t.android.sdkValid)&&!(t!=null&&t.android.sdkSavedNotLoaded)&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"Install Android SDK (Android Studio — easiest)",hint:"Download from https://developer.android.com/studio — the setup wizard installs the SDK and points ANDROID_HOME at it.",onCopy:W}),e.jsx(Ae,{label:"Set ANDROID_HOME (Windows PowerShell — current user)",cmd:'[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:LOCALAPPDATA\\Android\\Sdk", "User")',onCopy:W}),e.jsx(Ae,{label:"Set ANDROID_HOME (macOS / Linux)",cmd:`export ANDROID_HOME="$HOME/Library/Android/sdk" # macOS
|
|
79
|
+
export ANDROID_HOME="$HOME/Android/Sdk" # Linux`,onCopy:W}),e.jsxs("div",{className:"text-[11px] text-amber-400/80 leading-relaxed pt-1",children:["After setting the variable, ",e.jsx("strong",{children:"restart Testver"})," and ",e.jsx("strong",{children:"close every terminal"})," (especially the one running Appium), then start them again — a program reads environment variables only when it starts. This check reads Testver's own environment; Appium reads the one of the terminal it runs in."]})]})]}),children:[(t==null?void 0:t.android.adbFound)&&e.jsx(bt,{devices:t.android.devices,kind:"android",emptyMessage:"No Android devices connected. Plug a device in via USB and enable USB debugging, or start an emulator below.",udevHint:G?(oe=i.udev)==null?void 0:oe.linux:void 0,onCopy:W}),(t==null?void 0:t.android.adbFound)&&e.jsx(ol,{avds:t.android.avds??[],emulatorFound:!!t.android.emulatorFound,busy:S,onStart:w,onStop:v})]})}),R?e.jsx(Rs,{icon:e.jsx(ss,{size:16}),title:"iOS",summary:ae?`${Y} device${Y===1?"":"s"} ready`:"Setup needed",ok:ae,expanded:M,onToggle:()=>V(!M),children:e.jsx(Ms,{icon:e.jsx(ss,{size:18}),title:"iOS",ok:ae,okHint:t?`Xcode ${t.ios.xcodeVersion??"✓"} · simulators ready${(k=t.appium.driverVersions)!=null&&k.xcuitest?` · XCUITest ${t.appium.driverVersions.xcuitest}`:""}`:"",failHint:t!=null&&t.ios.xcodeFound?X?"iOS setup incomplete":"The Appium XCUITest driver is not installed — Appium needs it to drive iOS":(t==null?void 0:t.ios.error)||"Xcode is not installed — needed for simulators and real devices",action:e.jsxs("div",{className:"space-y-1.5",children:[!(t!=null&&t.ios.xcodeFound)&&Ne.macos&&e.jsx(Ae,{label:"Install Xcode",hint:Ne.macos,onCopy:W}),(t==null?void 0:t.ios.xcodeFound)&&!X&&e.jsx(Ae,{label:"Install the XCUITest driver, then restart Appium",cmd:"appium driver install xcuitest",onCopy:W}),(t==null?void 0:t.ios.xcodeFound)&&e.jsxs("div",{className:"flex items-start gap-2 text-[12px] leading-relaxed px-1",children:[t.ios.libimobileFound?e.jsx(ne,{size:13,className:"text-emerald-400 mt-0.5 flex-shrink-0"}):e.jsx(Ye,{size:13,className:"text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-gray-500",children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Real iPhones / iPads:"})," ",t.ios.libimobileFound?"libimobiledevice ✓. ":"install libimobiledevice to see connected devices. ","Appium also installs ",e.jsx("strong",{children:"WebDriverAgent"})," on the device, signed with your Apple team — fill in the signing details under ",e.jsx("em",{children:"Advanced"})," below, or sign it once in Xcode."," ",e.jsxs("a",{href:"https://appium.github.io/appium-xcuitest-driver/latest/getting-started/device-setup/#real-devices",target:"_blank",rel:"noopener noreferrer",className:"text-brand-400 hover:text-brand-300 inline-flex items-center gap-0.5",children:["Setup guide ",e.jsx(Ss,{size:10})]})]})]}),(t==null?void 0:t.ios.xcodeFound)&&!t.ios.libimobileFound&&ye.macos&&e.jsx(Ae,{label:"Install libimobiledevice (real devices)",cmd:ye.macos,onCopy:W})]}),children:t&&t.ios.xcodeFound&&e.jsx(bt,{devices:t.ios.devices,kind:"ios",emptyMessage:"No iOS simulators or devices found. Add a simulator in Xcode (Window → Devices and Simulators), or plug in a device and tap Trust.",onCopy:W,simulators:{busy:x,onStart:E,onStop:P}})})}):e.jsx(Rs,{icon:e.jsx(ss,{size:16}),title:"iOS",summary:"Requires macOS",summaryTone:"orange",ok:!1,expanded:M,onToggle:()=>V(!M),children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5 text-sm text-gray-500 flex items-start gap-3",children:[e.jsx(ss,{size:18,className:"text-gray-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-300 font-medium",children:"iOS testing requires macOS"}),e.jsx("div",{className:"mt-1 text-xs",children:"Apple's licensing terms require Xcode to build / sign WebDriverAgent. iOS local testing isn't available on Linux or Windows — use a Mac, or pick one of the cloud providers for iOS coverage."})]})]})}),e.jsx(ll,{mode:(l==null?void 0:l.appLaunchMode)??"fresh",onChange:ee}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5 flex items-start gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-200",children:"Grant app permissions automatically (Android)"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:"AI Assistant and AI Record sessions grant the app's permissions (camera, location, notifications…) when it's installed, so permission prompts don't interrupt a fresh start. Off: the prompts appear, and AI Record can record them. Test runs keep your project's own setting."})]}),e.jsx(gt,{enabled:(l==null?void 0:l.androidAutoGrantPermissions)===!0,onChange:C=>B({androidAutoGrantPermissions:C},C?"App permissions will be granted automatically":"Permission prompts will be shown")})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5",children:[e.jsxs("button",{onClick:()=>j(!c),className:"w-full flex items-center gap-2 px-5 py-3.5 text-sm font-medium text-gray-300 hover:bg-white/[0.02]",children:[c?e.jsx(Me,{size:14}):e.jsx(Ie,{size:14}),"Advanced — override tool paths"]}),c&&l&&e.jsxs("div",{className:"px-5 pb-5 pt-1 space-y-4",children:[e.jsx(Ke,{label:"Appium URL",value:l.appiumUrl,placeholder:"http://127.0.0.1:4723",onSave:C=>K("appiumUrl",C),hint:"Override if Appium runs on a non-default port. It must run on this computer — devices and app files are found here."}),e.jsx(Ke,{label:"ADB path (Android)",value:l.adbPath||"",placeholder:"auto-detected from PATH + $ANDROID_HOME",onSave:C=>K("adbPath",C),hint:"Set when multiple Android SDKs are installed and you want to pin one."}),R&&e.jsx(Ke,{label:"iOS tools path",value:l.iosToolsPath||"",placeholder:"auto-detected from PATH",onSave:C=>K("iosToolsPath",C),hint:"Set when libimobiledevice lives outside PATH."}),R&&e.jsxs("div",{className:"pt-3 border-t border-white/5 space-y-4",children:[e.jsxs("div",{className:"text-xs text-gray-500 leading-relaxed",children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Real iPhones / iPads — WebDriverAgent signing."})," Appium builds WebDriverAgent and installs it on the device, signed with your Apple team. Leave these empty if you signed it in Xcode yourself, or if your project's capabilities already set them. Simulators need none of this."]}),e.jsx(Ke,{label:"Apple Team ID",value:l.iosTeamId||"",placeholder:"e.g. A1B2C3D4E5",onSave:C=>K("iosTeamId",C),hint:"10 characters — Xcode → Settings → Accounts, or developer.apple.com → Membership."}),e.jsx(Ke,{label:"Signing identity",value:l.iosSigningId||"",placeholder:"Apple Development",onSave:C=>K("iosSigningId",C),hint:"Usually Apple Development (used when a Team ID is set and this is empty)."}),e.jsx(Ke,{label:"WebDriverAgent bundle id",value:l.iosWdaBundleId||"",placeholder:"e.g. com.yourcompany.WebDriverAgentRunner",onSave:C=>K("iosWdaBundleId",C),hint:"Needed with a free / personal team: a bundle id your team can sign."})]})]})]})]})]})})}function Rs({icon:s,title:t,summary:a,summaryTone:l,ok:m,expanded:i,onToggle:h,children:d}){const f=l==="orange"?"text-orange-500 dark:text-orange-400 font-medium":m?"text-gray-500":"text-amber-400/90";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:[e.jsxs("button",{onClick:h,className:"w-full flex items-center gap-3 px-5 py-3.5 text-left hover:bg-white/[0.02] transition-colors","aria-expanded":i,children:[i?e.jsx(Me,{size:14,className:"text-gray-500 flex-shrink-0"}):e.jsx(Ie,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0 ${m?"bg-emerald-500/15 text-emerald-400":"bg-amber-500/15 text-amber-400"}`,children:s}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2.5",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:t}),m?e.jsx(ne,{size:13,className:"text-emerald-400 flex-shrink-0"}):e.jsx(Ye,{size:13,className:"text-amber-400 flex-shrink-0"}),e.jsx("span",{className:`text-xs ${f} truncate`,children:a})]})]}),i&&e.jsx("div",{className:"border-t border-white/5 p-4 space-y-3",children:d})]})}function Ms({icon:s,title:t,ok:a,okHint:l,failHint:m,action:i,children:h}){return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center flex-shrink-0 ${a?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:s}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:t}),a?e.jsx(ne,{size:14,className:"text-emerald-400 flex-shrink-0"}):e.jsx(Se,{size:14,className:"text-red-400 flex-shrink-0"})]}),e.jsx("div",{className:`mt-1 text-xs ${a?"text-gray-400":"text-amber-400"}`,children:a?l:m})]})]}),i,h]})}function nl({ok:s,okLabel:t,warnLabel:a}){return s?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-emerald-300 bg-emerald-500/15 border border-emerald-500/30 px-2 py-0.5 rounded",children:[e.jsx(ne,{size:11}),t]}):e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-amber-300 bg-amber-500/15 border border-amber-500/30 px-2 py-0.5 rounded",children:[e.jsx(Ye,{size:11}),a]})}function Ae({label:s,cmd:t,hint:a,onCopy:l}){return e.jsxs("div",{className:"bg-surface-2 border border-white/5 rounded-md p-2.5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-gray-500 mb-1.5",children:s}),t?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 text-[11px] text-gray-200 font-mono break-all",children:t}),e.jsx("button",{onClick:()=>l(t),className:"p-1.5 rounded text-gray-500 hover:text-gray-200 hover:bg-white/10 flex-shrink-0",title:"Copy command",children:e.jsx(xs,{size:12})})]}):e.jsx("div",{className:"text-[12px] text-gray-400 leading-relaxed",children:a})]})}function ll({mode:s,onChange:t}){const a=[{value:"fresh",title:"Fresh start (clear data)",desc:"Wipe app data before every run — starts from onboarding / logged-out, default settings. (A project whose own capabilities set noReset keeps its data.)"},{value:"keep",title:"Keep data",desc:"Preserve app data between runs — stays logged in, keeps settings. App is still relaunched. Applies over the project's own noReset."}];return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx($e,{size:15,className:"text-brand-400"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-200",children:"App launch mode"})]}),e.jsx("p",{className:"text-xs text-gray-500 mb-3",children:"How the app starts at the beginning of each run on a local device — Test Explorer, Suites, Schedules and AI runs alike (WebdriverIO, pytest and Robot projects; Java, C# and Ruby projects set this in their own capabilities)."}),e.jsx("div",{className:"grid sm:grid-cols-2 gap-2.5",children:a.map(l=>{const m=s===l.value;return e.jsxs("button",{onClick:()=>t(l.value),className:`text-left rounded-lg border p-3 bg-white transition-colors ${m?"border-brand-500 ring-1 ring-brand-500/50 shadow-[0_0_0_1px_rgba(59,130,246,0.25)]":"border-gray-200 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-3.5 h-3.5 rounded-full border-2 flex-shrink-0 flex items-center justify-center ${m?"border-brand-400 bg-brand-500":"border-gray-500"}`,children:m&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-white"})}),e.jsx("span",{className:`text-[13px] font-semibold ${m?"text-brand-600":"text-gray-800"}`,children:l.title}),m&&e.jsx("span",{className:"ml-auto text-[10px] font-medium text-brand-600 bg-brand-500/10 border border-brand-500/40 px-1.5 py-0.5 rounded",children:"Selected"})]}),e.jsx("p",{className:"text-[11px] mt-1.5 leading-relaxed pl-[22px] text-gray-600",children:l.desc})]},l.value)})}),e.jsxs("div",{className:"mt-2.5 flex items-start gap-1.5 text-[11px] text-orange-500 dark:text-orange-400",children:[e.jsx(Ye,{size:12,className:"flex-shrink-0 mt-0.5"}),e.jsxs("span",{children:[e.jsx("strong",{children:"iOS note:"}),' "Fresh start (clear data)" is Android-only — iOS apps relaunch with their existing data regardless of this setting.']})]})]})}function gt({enabled:s,onChange:t,label:a}){return e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer select-none",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":s,onClick:()=>t(!s),className:`relative inline-flex h-5 w-9 flex-shrink-0 rounded-full border transition-colors ${s?"bg-emerald-500/80 border-emerald-400/60":"bg-gray-300 dark:bg-white/10 border-gray-400/40 dark:border-white/15"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 mt-[1px] rounded-full bg-white shadow transition-transform ${s?"translate-x-[18px]":"translate-x-[2px]"}`})}),a&&e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:a})]})}function bt({devices:s,kind:t,emptyMessage:a,udevHint:l,onCopy:m,simulators:i}){const h=s.some(d=>d.state==="no-permissions");return s.length===0?e.jsx("div",{className:"text-[12px] text-gray-500 bg-surface-2/40 border border-white/5 rounded-md px-3 py-2.5 italic",children:a}):e.jsxs("div",{className:"space-y-1.5",children:[s.map(d=>e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-md border ${d.state==="connected"?"bg-surface-2/50 border-white/5":"bg-amber-500/[0.04] border-amber-500/20"}`,children:[t==="android"?e.jsx(Gs,{size:14,className:"text-emerald-400 flex-shrink-0"}):e.jsx(ss,{size:14,className:"text-gray-300 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-[13px] text-gray-900 dark:text-gray-100 font-medium truncate",children:[d.name||d.serial,d.platformVersion&&e.jsxs("span",{className:"text-gray-500 font-normal",children:[" · ",t==="ios"?"iOS":"Android"," ",d.platformVersion]}),t==="android"&&d.kind!=="emulator"&&d.state==="connected"&&e.jsx("span",{className:"text-gray-500 font-normal",children:" · real device"})]}),e.jsxs("div",{className:"text-[10px] text-gray-500 font-mono mt-0.5 truncate",children:[d.serial,i&&d.kind==="simulator"&&!d.booted&&e.jsx("span",{className:"font-sans",children:" · Not running — start it to use it in sessions and runs"})]})]}),i&&d.state==="connected"&&d.kind==="simulator"?e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d.booted&&e.jsx("span",{className:"text-[10px] text-emerald-400 px-1.5 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:"Ready"}),d.booted?e.jsxs("button",{onClick:()=>i.onStop(d),disabled:i.busy!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-white/5 text-gray-600 dark:text-gray-300 border border-white/10 hover:bg-white/10 disabled:opacity-40",children:[i.busy===d.serial?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ns,{size:11}),"Close"]}):e.jsxs("button",{onClick:()=>i.onStart(d),disabled:i.busy!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-brand-500/15 text-brand-600 dark:text-brand-200 border border-brand-500/40 hover:bg-brand-500/25 disabled:opacity-40",children:[i.busy===d.serial?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Xs,{size:11}),i.busy===d.serial?"Starting…":"Start"]})]}):d.state==="connected"?e.jsx("span",{className:"text-[10px] text-emerald-400 px-1.5 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:"Ready"}):d.state==="unauthorized"?e.jsx("span",{className:"text-[10px] text-amber-400 px-1.5 py-0.5 rounded bg-amber-500/10 border border-amber-500/30",title:"Unlock the phone and tap Allow on the USB debugging prompt",children:"Tap Allow on the phone"}):d.state==="no-permissions"?e.jsx("span",{className:"text-[10px] text-amber-400 px-1.5 py-0.5 rounded bg-amber-500/10 border border-amber-500/30",title:"This computer has no USB permission for the phone — add a udev rule",children:"No USB permission"}):d.state==="offline"?e.jsx("span",{className:"text-[10px] text-gray-500 px-1.5 py-0.5 rounded bg-white/5 border border-white/10",title:"Unplug and reconnect the device",children:"Offline"}):e.jsx("span",{className:"text-[10px] text-gray-500 px-1.5 py-0.5 rounded bg-white/5 border border-white/10",children:d.state})]},d.serial)),h&&e.jsxs("div",{className:"text-[11px] text-amber-600 dark:text-amber-400/90 leading-relaxed pt-1 space-y-1.5",children:[e.jsxs("div",{children:["Linux needs a ",e.jsx("strong",{children:"udev rule"})," before it lets you use an Android phone over USB (and your user in the ",e.jsx("code",{children:"plugdev"})," group). Install the standard Android rules, then unplug and reconnect the phone."]}),l&&e.jsx(Ae,{label:"Install the Android udev rules",cmd:l,onCopy:m})]})]})}function ol({avds:s,emulatorFound:t,busy:a,onStart:l,onStop:m}){return e.jsxs("div",{className:"pt-1",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-gray-500 mb-1.5",children:"Emulators (AVDs)"}),t?s.length===0?e.jsx("div",{className:"text-[12px] text-gray-500 bg-surface-2/40 border border-white/5 rounded-md px-3 py-2.5 italic",children:"No emulators yet. Create one in Android Studio → Device Manager."}):e.jsx("div",{className:"space-y-1.5",children:s.map(i=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md border bg-surface-2/50 border-white/5",children:[e.jsx(Oe,{size:14,className:"text-gray-400 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-gray-900 dark:text-gray-100 font-medium truncate",children:i.name.replace(/_/g," ")}),e.jsx("div",{className:"text-[10px] text-gray-500 font-mono mt-0.5 truncate",children:i.running?`Running · ${i.serial}`:"Not running — start it to use it in sessions and runs"})]}),i.running?e.jsxs("button",{onClick:()=>m(i),disabled:a!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-white/5 text-gray-600 dark:text-gray-300 border border-white/10 hover:bg-white/10 disabled:opacity-40",children:[a===i.name?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ns,{size:11}),"Close"]}):e.jsxs("button",{onClick:()=>l(i),disabled:a!==null,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-brand-500/15 text-brand-600 dark:text-brand-200 border border-brand-500/40 hover:bg-brand-500/25 disabled:opacity-40",children:[a===i.name?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Xs,{size:11}),a===i.name?"Starting…":"Start"]})]},i.name))}):e.jsx("div",{className:"text-[12px] text-gray-500 bg-surface-2/40 border border-white/5 rounded-md px-3 py-2.5 italic",children:"The Android emulator isn't installed. Add it in Android Studio → SDK Manager → SDK Tools → Android Emulator."})]})}function Ke({label:s,value:t,placeholder:a,onSave:l,hint:m}){const[i,h]=n.useState(t);n.useEffect(()=>h(t),[t]);const d=i!==t;return e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1.5",children:s}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:i,onChange:f=>h(f.target.value),placeholder:a,className:"flex-1 bg-surface-2 border border-white/10 rounded-md px-3 py-2 text-sm text-gray-100 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>l(i),disabled:!d,className:"px-3 py-2 rounded-md text-xs font-medium bg-brand-500/20 text-brand-200 border border-brand-500/40 hover:bg-brand-500/30 disabled:opacity-40",children:"Save"})]}),m&&e.jsx("div",{className:"mt-1 text-[11px] text-gray-500",children:m})]})}function ft(s){if(!s)return"";const t=Math.max(0,Math.round((Date.now()-Date.parse(s))/6e4));return t<1?"just now":t<60?`${t} min ago`:`${Math.floor(t/60)} h ago`}const Ws={chromium:"bg-blue-400",firefox:"bg-orange-400",webkit:"bg-purple-400"},qs={webdriver:"Test run",cdp:"AI browser","pw-server":"Test run"};function Js(s){if(!s)return"";const t=Math.max(0,Math.round((Date.now()-Date.parse(s))/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}const Ds=8;function il(){const[s,t]=n.useState(()=>document.visibilityState!=="hidden");return n.useEffect(()=>{const a=()=>t(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[]),s}function dl({session:s,allowed:t,onClick:a}){const l=n.useRef(null),[m,i]=n.useState(!1),[h,d]=n.useState(!1);n.useEffect(()=>{const g=l.current;if(!g)return;const y=new IntersectionObserver(c=>i(c.some(j=>j.isIntersecting)),{threshold:.1});return y.observe(g),()=>y.disconnect()},[]),n.useEffect(()=>{d(!1)},[s.sessionId,t]);const f=t&&m&&!h&&s.state==="active";return e.jsxs("button",{ref:l,onClick:a,className:"relative rounded-lg overflow-hidden bg-black aspect-[16/10] group border border-gray-200 dark:border-white/10 hover:border-brand-400 dark:hover:border-brand-500/60 transition-colors text-left",title:"Open live view",children:[f?e.jsx("img",{src:Tt(s.sessionId),onError:()=>d(!0),alt:"",className:"w-full h-full object-contain"}):e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-1.5 text-gray-500",children:[e.jsx(ve,{size:16,className:"opacity-60"}),e.jsx("span",{className:"text-[10px]",children:h?"stream unavailable":"click to watch"})]}),e.jsxs("div",{className:"absolute inset-x-0 bottom-0 flex items-center gap-1.5 px-2 py-1 bg-black/60 backdrop-blur-sm",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ws[s.browser]||"bg-gray-400"}`}),e.jsx("span",{className:"text-[10px] text-gray-200 capitalize",children:s.browser}),e.jsx("span",{className:"text-[9px] text-gray-400",children:qs[s.mode]||s.mode}),e.jsx("span",{className:"text-[9px] text-gray-400 font-mono flex-1 text-right",children:Js(s.createdAt)}),f&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse shrink-0"})]})]})}function cl({onChanged:s}){var A,te,X,le;const{toast:t}=ge(),[a,l]=n.useState(null),[m,i]=n.useState(null),[h,d]=n.useState(null),[f,g]=n.useState(null),[y,c]=n.useState([]),[j,p]=n.useState({}),[u,b]=n.useState(null),[z,M]=n.useState(null),[V,U]=n.useState(!1),[O,S]=n.useState(!1),I=il(),w=n.useCallback(()=>{_r().then($=>{l($),$.connected&&Hr().then(i).catch(()=>i(null))}).catch(()=>l(null))},[]);n.useEffect(()=>{w()},[w]),n.useEffect(()=>{if(!(a!=null&&a.connected))return;let $=!0;const re=()=>{Vr().then(ce=>{$&&c(ce.sessions)}).catch(()=>{$&&c([])}),Gr().then(ce=>{$&&p(Object.fromEntries(ce.runs.filter(he=>he.gridRunId).map(he=>[he.gridRunId,he.runId])))}).catch(()=>{})};re();const ae=setInterval(re,5e3);return()=>{$=!1,clearInterval(ae)}},[a==null?void 0:a.connected]),n.useEffect(()=>{z&&!y.some($=>$.sessionId===z.sessionId&&$.state==="active")&&M(null)},[y,z]);const v=$=>{U(!1),M($)},x=async $=>{b($);try{await Yr($),c(re=>re.filter(ae=>ae.sessionId!==$))}catch(re){t("error",re instanceof Error?re.message:"Stop failed")}finally{b(null)}},[o,r]=n.useState(null),E=async($=!1)=>{d("connect"),r(null);try{const re=await Wr({takeover:$});t("success",$?"Testver Grid moved to this device":"Testver Grid connected"),re.connection,w(),s==null||s()}catch(re){const ae=re;ae.status===409&&(ae.code==="GRID_IN_USE"||ae.code==="GRID_BUSY")?r({code:ae.code,message:ae.message,deviceName:ae.deviceName,connectedBy:ae.connectedBy,lastSeenAt:ae.lastSeenAt,canTakeOver:ae.canTakeOver}):t("error",ae.message||"Grid connect failed")}finally{d(null)}},P=async()=>{d("test"),g(null);try{const $=await qr();g({ok:$.ok,msg:$.message})}catch($){g({ok:!1,msg:$ instanceof Error?$.message:"Test failed"})}finally{d(null)}},B=async $=>{d("save");try{await Jr({enabled:$.enabled??(a==null?void 0:a.enabled)??!0,aiBrowserTarget:$.aiBrowserTarget??(a==null?void 0:a.aiBrowserTarget)??"local",aiTunnelEnabled:$.aiTunnelEnabled??(a==null?void 0:a.aiTunnelEnabled)??!1}),w(),s==null||s()}catch(re){t("error",re instanceof Error?re.message:"Save failed")}finally{d(null)}},N=a!=null&&a.access?!a.access.enabled:!1,ee=((A=a==null?void 0:a.access)==null?void 0:A.refusal)??null,K=(a==null?void 0:a.connection)??null,W=!!K&&!!(a!=null&&a.thisDevice)&&K.deviceId!==a.thisDevice.deviceId&&!K.stale,R=(a==null?void 0:a.limit)??((te=a==null?void 0:a.access)==null?void 0:te.limit)??null,G=((X=a==null?void 0:a.access)==null?void 0:X.subject)??null,_=m?Math.round(m.monthSeconds/60):0;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Testver's own cloud browsers — Chromium, Firefox and WebKit sessions with no vendor account and no credentials. Uses your connected Testver account (same as AI). A prepaid add-on to a paid plan (parallel browsers, bought on testver.com); one Testver installation holds the connection at a time."}),e.jsxs("div",{className:"flex items-center gap-3 text-sm flex-wrap",children:[a!=null&&a.connected?e.jsxs("span",{className:"flex items-center gap-1.5 text-emerald-600 dark:text-emerald-400",children:[e.jsx(ze,{size:14})," Connected",e.jsx("span",{className:"text-gray-500 font-normal",children:"· token renews automatically"})]}):e.jsxs("span",{className:"flex items-center gap-1.5 text-gray-500 dark:text-gray-400",children:[e.jsx(Se,{size:14})," Not connected"]}),e.jsx("span",{className:"text-gray-400 dark:text-gray-600 text-xs",children:a==null?void 0:a.gridUrl}),R!=null&&((le=a==null?void 0:a.access)==null?void 0:le.enabled)&&e.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["· up to ",R," browser",R===1?"":"s"," at once",(G==null?void 0:G.type)==="team"?` (${G.name??"your team"} pool)`:""]})]}),N&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-amber-50 dark:bg-amber-500/10 border border-amber-200 dark:border-amber-500/20 rounded-lg px-3.5 py-2.5 text-sm text-amber-700 dark:text-amber-300",children:[e.jsx(ue,{size:15,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[(ee==null?void 0:ee.message)??"Testver Grid is not enabled for your Testver account. It is an add-on for any paid plan — add it on testver.com under Billing.",(ee==null?void 0:ee.code)==="GRID_NOT_OPERATOR"&&K&&e.jsxs("span",{className:"block text-xs mt-1 opacity-80",children:["Connected on ",K.deviceName,K.connectedBy?` by ${K.connectedBy.name||K.connectedBy.email}`:""," · last seen ",ft(K.lastSeenAt)]})]})]}),!N&&W&&!o&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-sky-50 dark:bg-sky-500/10 border border-sky-200 dark:border-sky-500/20 rounded-lg px-3.5 py-2.5 text-sm text-sky-800 dark:text-sky-200",children:[e.jsx(ds,{size:15,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:["Testver Grid is connected on ",e.jsx("span",{className:"font-medium",children:K.deviceName}),K.connectedBy?` by ${K.connectedBy.name||K.connectedBy.email}`:""," · last seen ",ft(K.lastSeenAt),".",e.jsx("span",{className:"block text-xs mt-1 opacity-80",children:"One installation holds the connection at a time. Take it over here once that device is idle, or disconnect it there."})]})]}),o&&e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-500/10 border border-amber-200 dark:border-amber-500/20 rounded-lg px-3.5 py-3 text-sm text-amber-800 dark:text-amber-200 space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(ue,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:o.message})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-6",children:[o.code==="GRID_IN_USE"&&o.canTakeOver!==!1&&e.jsx("button",{onClick:()=>E(!0),disabled:h!==null,className:"px-3 py-1.5 rounded-md bg-amber-600 hover:bg-amber-500 text-white text-xs font-medium disabled:opacity-50",children:h==="connect"?e.jsx(J,{size:12,className:"animate-spin"}):"Take over on this device"}),e.jsx("button",{onClick:()=>r(null),className:"px-3 py-1.5 rounded-md text-xs text-amber-800 dark:text-amber-200 hover:bg-amber-100 dark:hover:bg-amber-500/20",children:"Not now"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs(os,{to:"/testver",className:"px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium flex items-center gap-2 transition-colors",children:[e.jsx(Dt,{size:14}),"Manage in Testver → Connections"]}),e.jsxs("button",{onClick:P,disabled:h!==null||!(a!=null&&a.connected),className:"px-4 py-2 rounded-lg bg-gray-100 dark:bg-surface-2 border border-gray-200 dark:border-white/10 text-gray-700 dark:text-gray-300 text-sm disabled:opacity-50 flex items-center gap-2 transition-colors",children:[h==="test"?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14}),"Test connection"]})]}),f&&e.jsx("div",{className:`text-sm ${f.ok?"text-emerald-600 dark:text-emerald-400":"text-red-500 dark:text-red-400"}`,children:f.msg}),(a==null?void 0:a.configured)&&e.jsxs("div",{className:"space-y-3 pt-3 border-t border-gray-100 dark:border-white/5",children:[e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-700 dark:text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:$=>B({enabled:$.target.checked}),disabled:h!==null,className:"rounded border-gray-300 dark:border-gray-600 bg-white dark:bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Offer Testver Grid as a run target"]}),e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-700 dark:text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.aiBrowserTarget==="grid",onChange:$=>B({aiBrowserTarget:$.target.checked?"grid":"local"}),disabled:h!==null,className:"rounded border-gray-300 dark:border-gray-600 bg-white dark:bg-surface-2 text-brand-500 focus:ring-brand-500"}),"AI Assistance browsers run on the grid by default"]}),a.aiBrowserTarget==="grid"&&e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-700 dark:text-gray-300 cursor-pointer pl-6",children:[e.jsx("input",{type:"checkbox",checked:a.aiTunnelEnabled,onChange:$=>B({aiTunnelEnabled:$.target.checked}),disabled:h!==null,className:"rounded border-gray-300 dark:border-gray-600 bg-white dark:bg-surface-2 text-brand-500 focus:ring-brand-500"}),e.jsxs("span",{children:["AI grid browsers can reach your local apps",e.jsx("span",{className:"block text-xs text-gray-400 dark:text-gray-500",children:"Outbound tunnel scoped to localhost, per session, closed when the browser closes"})]})]})]}),(a==null?void 0:a.connected)&&y.length>0&&e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide flex items-center gap-1.5",children:[e.jsx(ds,{size:12})," Live sessions (",y.length,")"]}),e.jsxs("button",{onClick:()=>S($=>!$),title:O?"List view":"Wall view — live thumbnails",className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/5 transition-colors",children:[O?e.jsx(en,{size:12}):e.jsx(sn,{size:12}),O?"List":"Wall"]})]}),O&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:y.map(($,re)=>e.jsx(dl,{session:$,allowed:I&&re<Ds,onClick:()=>v($)},$.sessionId))}),y.length>Ds&&e.jsxs("p",{className:"text-[11px] text-gray-400 dark:text-gray-600",children:["Streaming the first ",Ds," — click any other tile to watch it."]})]}),!O&&y.map($=>e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg bg-gray-50 dark:bg-white/[0.04] border border-gray-100 dark:border-white/5 px-3 py-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Ws[$.browser]||"bg-gray-400"}`}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 capitalize",children:$.browser}),e.jsx("span",{className:"text-xs text-gray-500",children:qs[$.mode]||$.mode}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${$.state==="active"?"bg-emerald-50 dark:bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":"bg-amber-50 dark:bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:$.state}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-600 font-mono flex-1 text-right",children:Js($.createdAt)}),$.runId&&j[$.runId]&&e.jsx(os,{to:`/results?runId=${encodeURIComponent(j[$.runId])}`,title:"Open the run this browser belongs to — its live view is there too",className:"text-[11px] text-cyan-600 dark:text-cyan-400 hover:underline whitespace-nowrap",children:"Open run"}),$.state==="active"&&e.jsx("button",{onClick:()=>v($),title:"Watch live",className:"flex items-center justify-center w-6 h-6 rounded text-gray-400 hover:text-brand-500 dark:hover:text-brand-400 hover:bg-brand-50 dark:hover:bg-brand-500/10 transition-colors",children:e.jsx(ve,{size:12})}),e.jsx("button",{onClick:()=>x($.sessionId),disabled:u===$.sessionId,title:"Stop session",className:"flex items-center justify-center w-6 h-6 rounded text-gray-400 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 transition-colors disabled:opacity-50",children:u===$.sessionId?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ns,{size:11})})]},$.sessionId))]}),z&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6",onClick:()=>M(null),children:e.jsxs("div",{className:"bg-white dark:bg-surface-1 rounded-xl shadow-2xl border border-gray-200 dark:border-white/10 max-w-4xl w-full overflow-hidden",onClick:$=>$.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-gray-100 dark:border-white/5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Ws[z.browser]||"bg-gray-400"}`}),e.jsx("span",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 capitalize",children:z.browser}),e.jsx("span",{className:"text-xs text-gray-500",children:qs[z.mode]||z.mode}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] px-1.5 py-0.5 rounded bg-emerald-50 dark:bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"})," LIVE"]}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-600 font-mono flex-1 text-right",children:Js(z.createdAt)}),e.jsxs("button",{onClick:()=>{x(z.sessionId),M(null)},title:"Stop session",className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs text-gray-500 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 transition-colors",children:[e.jsx(Ns,{size:11})," Stop"]}),e.jsx("button",{onClick:()=>M(null),className:"flex items-center justify-center w-7 h-7 rounded-lg text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:e.jsx(me,{size:15})})]}),e.jsx("div",{className:"bg-black aspect-[16/10] flex items-center justify-center",children:V?e.jsx("p",{className:"text-sm text-gray-400 px-8 text-center",children:"Live view isn't available for this session — the machine may run headless (evidence disabled) or predate the live-view rollout."}):I?e.jsx("img",{src:Tt(z.sessionId),onError:()=>U(!0),alt:"Live session",className:"w-full h-full object-contain"}):e.jsx("p",{className:"text-sm text-gray-500",children:"Stream paused — tab in background"})})]})}),m&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 pt-3 border-t border-gray-100 dark:border-white/5",children:["This month: ",e.jsxs("span",{className:"text-gray-700 dark:text-gray-300",children:[_," browser-minutes"]})," across"," ",e.jsxs("span",{className:"text-gray-700 dark:text-gray-300",children:[m.monthSessions," sessions"]}),e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:" · free testing phase, usage is informational"})]})]})}const xl=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"0 0 256 256",xmlns:"http://www.w3.org/2000/svg",children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{x1:"98.03%",y1:"0.16%",x2:"58.89%",y2:"40.77%",id:"cjg1",children:[e.jsx("stop",{stopColor:"#0052CC",offset:"18%"}),e.jsx("stop",{stopColor:"#2684FF",offset:"100%"})]}),e.jsxs("linearGradient",{x1:"100.67%",y1:"0.46%",x2:"55.4%",y2:"44.73%",id:"cjg2",children:[e.jsx("stop",{stopColor:"#0052CC",offset:"18%"}),e.jsx("stop",{stopColor:"#2684FF",offset:"100%"})]})]}),e.jsx("path",{d:"M244.658,0 L121.707,0 C121.707,14.72 127.554,28.837 137.963,39.246 C148.372,49.655 162.489,55.502 177.209,55.502 L199.858,55.502 L199.858,77.369 C199.877,107.994 224.699,132.816 255.324,132.836 L255.324,10.667 C255.324,4.776 250.549,0 244.658,0 Z",fill:"#2684FF"}),e.jsx("path",{d:"M183.822,61.262 L60.871,61.262 C60.891,91.887 85.713,116.709 116.338,116.729 L138.987,116.729 L138.987,138.667 C139.026,169.292 163.864,194.098 194.489,194.098 L194.489,71.929 C194.489,66.038 189.713,61.262 183.822,61.262 Z",fill:"url(#cjg1)"}),e.jsx("path",{d:"M122.951,122.489 L0,122.489 C0,153.142 24.849,177.991 55.502,177.991 L78.222,177.991 L78.222,199.858 C78.242,230.455 103.02,255.266 133.618,255.324 L133.618,133.156 C133.618,127.265 128.842,122.489 122.951,122.489 Z",fill:"url(#cjg2)"})]}),ml=({size:s=28})=>e.jsx("svg",{width:s,height:s,viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"none",children:e.jsxs("g",{fillRule:"evenodd",clipRule:"evenodd",children:[e.jsx("path",{fill:"#E01E5A",d:"M2.471 11.318a1.474 1.474 0 001.47-1.471v-1.47h-1.47A1.474 1.474 0 001 9.846c.001.811.659 1.469 1.47 1.47zm3.682-2.942a1.474 1.474 0 00-1.47 1.471v3.683c.002.811.66 1.468 1.47 1.47a1.474 1.474 0 001.47-1.47V9.846a1.474 1.474 0 00-1.47-1.47z"}),e.jsx("path",{fill:"#36C5F0",d:"M4.683 2.471c.001.811.659 1.469 1.47 1.47h1.47v-1.47A1.474 1.474 0 006.154 1a1.474 1.474 0 00-1.47 1.47zm2.94 3.682a1.474 1.474 0 00-1.47-1.47H2.47A1.474 1.474 0 001 6.153c.002.812.66 1.469 1.47 1.47h3.684a1.474 1.474 0 001.47-1.47z"}),e.jsx("path",{fill:"#2EB67D",d:"M9.847 7.624a1.474 1.474 0 001.47-1.47V2.47A1.474 1.474 0 009.848 1a1.474 1.474 0 00-1.47 1.47v3.684c.002.81.659 1.468 1.47 1.47zm3.682-2.941a1.474 1.474 0 00-1.47 1.47v1.47h1.47A1.474 1.474 0 0015 6.154a1.474 1.474 0 00-1.47-1.47z"}),e.jsx("path",{fill:"#ECB22E",d:"M8.377 9.847c.002.811.659 1.469 1.47 1.47h3.683A1.474 1.474 0 0015 9.848a1.474 1.474 0 00-1.47-1.47H9.847a1.474 1.474 0 00-1.47 1.47zm2.94 3.682a1.474 1.474 0 00-1.47-1.47h-1.47v1.47c.002.812.659 1.469 1.47 1.47a1.474 1.474 0 001.47-1.47z"})]})}),ul=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"4 4 36 38",xmlns:"http://www.w3.org/2000/svg",fill:"none",children:[e.jsx("path",{fill:"url(#ct_a)",d:"M21.9999 20h12c3.3137 0 6 2.6863 6 6v10c0 3.3137-2.6863 6-6 6s-6-2.6863-6-6V26c0-3.3137-2.6863-6-6-6"}),e.jsx("path",{fill:"url(#ct_b)",d:"M7.99988 24c0-3.3137 2.68632-6 6.00002-6h8c3.3137 0 6 2.6863 6 6v12c0 3.3137 2.6863 6 6 6l-16.0001-.0001c-5.5228 0-9.99992-4.4771-9.99992-10z"}),e.jsx("path",{fill:"url(#ct_e)",d:"M32.9999 18c2.7614 0 5-2.2386 5-5s-2.2386-5-5-5-5 2.2386-5 5 2.2386 5 5 5"}),e.jsx("path",{fill:"url(#ct_h)",d:"M17.9999 16c3.3137 0 6-2.6863 6-6 0-3.31371-2.6863-6-6-6s-6 2.68629-6 6c0 3.3137 2.6863 6 6 6"}),e.jsx("rect",{width:"16",height:"16",x:"4",y:"23",fill:"url(#ct_k)",rx:"3.25"}),e.jsx("path",{fill:"#fff",d:"M15.4792 28.1054h-2.4471v7.466h-2.0648v-7.466H8.52014v-1.6768h6.95906z"}),e.jsxs("defs",{children:[e.jsxs("radialGradient",{id:"ct_a",cx:"0",cy:"0",r:"1",gradientTransform:"matrix(13.4784 0 0 33.2694 39.7967 22.1739)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{stopColor:"#a98aff"}),e.jsx("stop",{offset:".14",stopColor:"#8c75ff"}),e.jsx("stop",{offset:".565",stopColor:"#5f50e2"}),e.jsx("stop",{offset:".9",stopColor:"#3c2cb8"})]}),e.jsxs("radialGradient",{id:"ct_b",cx:"0",cy:"0",r:"1",gradientTransform:"rotate(68.1539 -7.71566095 14.71355834)scale(32.752 33.1231)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{stopColor:"#85c2ff"}),e.jsx("stop",{offset:".69",stopColor:"#7588ff"}),e.jsx("stop",{offset:"1",stopColor:"#6459fe"})]}),e.jsxs("radialGradient",{id:"ct_e",cx:"0",cy:"0",r:"1",gradientTransform:"matrix(0 -10 12.6216 0 32.9999 11.5714)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:".268201",stopColor:"#6868f7"}),e.jsx("stop",{offset:"1",stopColor:"#3923b1"})]}),e.jsxs("radialGradient",{id:"ct_h",cx:"0",cy:"0",r:"1",gradientTransform:"matrix(0 -12 15.146 0 17.9999 8.28571)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:".268201",stopColor:"#8282ff"}),e.jsx("stop",{offset:"1",stopColor:"#3923b1"})]}),e.jsxs("radialGradient",{id:"ct_k",cx:"0",cy:"0",r:"1",gradientTransform:"rotate(45 -25.76345597 16.32842712)scale(22.6274)",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:".046875",stopColor:"#688eff"}),e.jsx("stop",{offset:".946875",stopColor:"#230f94"})]})]})]}),Gt=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"0 0 177 177",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("defs",{children:e.jsxs("radialGradient",{cx:"49.87%",cy:"49.95%",fx:"49.87%",fy:"49.95%",r:"49.92%",id:"bsg1",children:[e.jsx("stop",{stopColor:"#797979",offset:"0%"}),e.jsx("stop",{stopColor:"#4C4C4C",offset:"100%"})]})}),e.jsx("circle",{fill:"#F4B960",cx:"88.5",cy:"88.5",r:"88.5"}),e.jsx("circle",{fill:"#E66F32",cx:"80",cy:"80",r:"80"}),e.jsx("circle",{fill:"#E43C41",cx:"90",cy:"69",r:"69"}),e.jsx("circle",{fill:"#BDD041",cx:"95.5",cy:"74.5",r:"63.5"}),e.jsx("circle",{fill:"#6DB54C",cx:"91",cy:"79",r:"59"}),e.jsx("circle",{fill:"#AEDAE6",cx:"81.5",cy:"70.5",r:"49.5"}),e.jsx("circle",{fill:"#56B8DE",cx:"90.5",cy:"61.5",r:"41.5"}),e.jsx("circle",{fill:"#00B1D5",cx:"95.5",cy:"67.5",r:"36.5"}),e.jsx("circle",{fill:"#221F1F",cx:"90",cy:"72",r:"31"}),e.jsx("ellipse",{fill:"#FFFFFF",transform:"rotate(-65.83 102.18 60.77)",cx:"102.18",cy:"60.77",rx:"9.57",ry:"6.21"})]}),Wt=({size:s=28})=>e.jsx("svg",{width:s,height:s,viewBox:"0 0 49.8 56",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{fill:"#6C63FF",d:"M17.4,45.5v5c0,1-1.1,1.7-2.1,1.1L13,50.1l-0.6-0.3c0,0-3.2-1.9-10.2-5.9l-0.6-0.3c-0.5-0.3-1-0.8-1.3-1.3C0.2,41.8,0,41.2,0,40.6l0-12.3V15.9c0-0.7,0.2-1.3,0.5-1.8c0.3-0.6,0.8-1,1.3-1.3l10-5.8l0.5-0.3c0.2-0.1,0.2-0.1,0.6-0.3l9.6-5.5l0.6-0.3C23.7,0.1,24.4,0,25.1,0c0.7,0,1.3,0.2,1.7,0.6l10,5.8l0.6,0.3c0,0,3.4,1.9,10.1,5.9l0.6,0.3c0.5,0.3,1,0.8,1.3,1.3c0.3,0.5,0.5,1.1,0.5,1.8l0,11.2c0,1-1.1,1.7-2,1.2l-4.3-2.5c-0.4-0.2-0.7-0.7-0.7-1.2v-6.8L34,12.8c-0.1,0-0.2-0.1-0.7-0.4l-8.4-4.9l-8.7,5c-0.1,0.1-0.1,0.1-0.1,0.1c0,0-0.2,0.1-0.6,0.4L7,17.9v20.7l8.8,5.1c0.1,0,0.2,0.1,0.7,0.4l0.2,0.2l0.1,0.2C17.2,44.7,17.4,45.1,17.4,45.5z M42.8,32.8c0-1,1.1-1.7,2-1.2l4.3,2.5c0.4,0.2,0.7,0.7,0.7,1.2v4.1c0,0.4-0.1,0.7-0.4,0.9l-2,2.1c-0.8,1-1.9,1.4-2.9,0.8l-16-9.3l0,17.5c0.1,0.7-0.2,1.3-0.7,1.7c-0.5,0.4-0.5,0.4-3,2.4C24.4,55.8,24,56,23.5,56c-1.1,0-2-0.9-2-2l0-24.2l-2.7-1.6L17.4,29c-0.1,0,0,0-1.4,0.8c-1,0.6-2.2,0.3-2.7-0.7c-0.1-0.2-0.1-0.2-0.8-1.3l-0.8-1.3c-0.6-1-0.3-2.2,0.7-2.7c0.2-0.1,0.2-0.1,1.3-0.8l3.3-1.9l0.6-0.3c0.6-0.4,1.5-0.5,2.1-0.1l0.7,0.4L42.8,34V32.8z"})}),qt=({size:s=28})=>e.jsxs("svg",{width:s,height:s,viewBox:"0 0 66.4 65",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{fill:"#3DDC91",d:"M27.7,32.5h-7.8l5.5-16.3h13.4L44.3,0H19.4c-3.6,0-6.7,2.2-7.9,5.6L0.4,38.1c-0.8,2.5-0.4,5.2,1.1,7.3c1.6,2.1,4.1,3.4,6.7,3.4h19.4l5.5-16.3H27.7L27.7,32.5z"}),e.jsx("path",{fill:"#3DDC91",d:"M64.8,19.6c-1.6-2.1-4.1-3.4-6.7-3.4H38.7l-5.5,16.3h13.4L41,48.8H27.7L22.1,65H47c3.6,0,6.7-2.2,7.9-5.6L66,26.9C66.8,24.5,66.4,21.7,64.8,19.6L64.8,19.6z"})]});function Jt({type:s,size:t=28}){switch(s){case"jira":return e.jsx(xl,{size:t});case"slack":return e.jsx(ml,{size:t});case"teams":return e.jsx(ul,{size:t});case"email":return e.jsx(zt,{size:t,className:"text-amber-400"});case"browserstack":return e.jsx(Gt,{size:t});case"lambdatest":return e.jsx(Wt,{size:t});case"saucelabs":return e.jsx(qt,{size:t});default:return e.jsx(Pe,{size:t,className:"text-gray-400"})}}function yt({id:s,size:t=28}){switch(s){case"browserstack":return e.jsx(Gt,{size:t});case"lambdatest":return e.jsx(Wt,{size:t});case"saucelabs":return e.jsx(qt,{size:t});default:return e.jsx(Pe,{size:t,className:"text-gray-400"})}}const Yt=[{type:"jira",name:"JIRA",desc:"Connect to Atlassian JIRA for issue tracking, defect sync, and story import",color:"blue",category:"integration"},{type:"email",name:"Email (SMTP)",desc:"Send test reports, failure alerts, and scheduled digests via email",color:"amber",category:"notification"},{type:"slack",name:"Slack",desc:"Post test results and alerts to Slack channels via webhooks",color:"purple",category:"notification"},{type:"teams",name:"MS Teams",desc:"Send notifications and test reports to Microsoft Teams channels",color:"indigo",category:"notification"}],hl=["teams"],_e=[{id:"browserstack",name:"BrowserStack",desc:"Run tests on real devices and browsers in the BrowserStack cloud grid",color:"orange"},{id:"lambdatest",name:"LambdaTest",desc:"Cross-browser testing on the LambdaTest cloud platform",color:"purple"},{id:"saucelabs",name:"Sauce Labs",desc:"Execute tests at scale on the Sauce Labs cloud testing platform",color:"red"}],Fs="••••••••";function Is(s){const t=new Set,a=[];for(const l of(s||"").split(/[,;\s]+/)){const m=l.trim();if(!m||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m))continue;const i=m.toLowerCase();t.has(i)||(t.add(i),a.push(m))}return a}const pl=[{id:"run_complete",label:"Test Run Complete",desc:"Every time a test run finishes"},{id:"failure",label:"Test Failure",desc:"Only runs with failed tests"},{id:"cycle_complete",label:"Cycle Complete",desc:"When a test plan cycle finishes running its automation"},{id:"ci_gate",label:"CI Gate Verdict",desc:"When a CI/CD gate passes, fails or errors"},{id:"auto_heal",label:"Auto-Heal Outcome",desc:"When a locator is healed, a fix is ready for review, or a heal is reverted"},{id:"schedule_skipped",label:"Schedule Skipped",desc:"When a scheduled run is skipped because the previous one is still running"},{id:"defect_created",label:"Defect Created",desc:"When a new defect is created"},{id:"defect_status_changed",label:"Defect Status Changed",desc:"When a defect moves between statuses (opened, resolved, closed…)"}],jt=[{id:"gmail",name:"Gmail",host:"smtp.gmail.com",port:587},{id:"outlook",name:"Outlook / Office 365",host:"smtp.office365.com",port:587},{id:"yahoo",name:"Yahoo",host:"smtp.mail.yahoo.com",port:587},{id:"custom",name:"Custom SMTP",host:"",port:587},{id:"testver",name:"Testver mail — included with your plan",host:"",port:0}];function gl({readOnly:s=!1}={}){var be,oe,k,C,q;const t=Je(),{showsMobile:a,showsWeb:l}=ks(),{data:m,isLoading:i}=Ge({queryKey:["connectors"],queryFn:St}),h=n.useMemo(()=>{const T=(m==null?void 0:m.connectors)||[];return Array.isArray(T)?T:[]},[m]),d=Ze({mutationFn:Qr,onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),f=Ze({mutationFn:({id:T,data:H})=>Xr(T,H),onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),g=Ze({mutationFn:Zr,onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),y=Ze({mutationFn:ea,onSuccess:()=>t.invalidateQueries({queryKey:["connectors"]})}),c=Ze({mutationFn:({id:T,data:H})=>sa(T,H)}),[j,p]=n.useState(!1),[u,b]=n.useState(null),[z,M]=n.useState(null),[V,U]=n.useState(null),[O,S]=n.useState(null),[I,w]=n.useState(null),{toast:v}=ge(),x=(T,H="success")=>{v(H,T)},{data:o,refetch:r}=Ge({queryKey:["cloud-providers"],queryFn:At}),E=n.useMemo(()=>(o==null?void 0:o.providers)||[],[o]),[P,B]=n.useState(null),[N,ee]=n.useState({username:"",accessKey:"",region:"us-west-1",defaultBuildName:"",enabled:!0,tunnelEnabled:!1,tunnelName:""}),[K,W]=n.useState(!1),[R,G]=n.useState(!1),[_,A]=n.useState(null),[te,X]=n.useState(!1),[le,$]=n.useState(null),[re,ae]=n.useState(!1),ce=T=>E.some(H=>H.id===T),he=E.filter(T=>T.enabled).length,xe=h.filter(T=>T.status==="connected").length+he;function ye(T){const H=E.find(de=>de.id===T);ee(H?{username:H.username,accessKey:H.accessKey,region:H.region||"us-west-1",defaultBuildName:H.defaultBuildName||"",enabled:H.enabled,tunnelEnabled:!!H.tunnelEnabled,tunnelName:H.tunnelName||""}:{username:"",accessKey:"",region:"us-west-1",defaultBuildName:"",enabled:!0,tunnelEnabled:!1,tunnelName:""}),A(null),X(!1),B(T)}async function Ne(){var T;if(!(!P||!N.username)&&!(!N.accessKey||N.accessKey===Fs&&!ce(P))){G(!0);try{await aa({id:P,enabled:N.enabled,username:N.username,accessKey:N.accessKey,region:P==="saucelabs"?N.region:void 0,defaultBuildName:N.defaultBuildName||void 0,tunnelEnabled:!!N.tunnelEnabled,tunnelName:N.tunnelName||""}),x(`${((T=_e.find(H=>H.id===P))==null?void 0:T.name)||"Provider"} saved`),B(null),r()}catch(H){x(`Save failed: ${(H==null?void 0:H.message)||H}`,"error")}finally{G(!1)}}}async function ke(){if(!(!P||!N.username)){W(!0),A(null);try{const T=await ra({id:P,username:N.username,accessKey:N.accessKey,region:P==="saucelabs"?N.region:void 0});A({ok:T.connected,msg:T.message+(T.details?` (${T.details})`:"")})}catch(T){A({ok:!1,msg:String(T)})}finally{W(!1)}}}async function F(T){var H;try{await na(T),x(`${((H=_e.find(de=>de.id===T))==null?void 0:H.name)||"Provider"} removed`),$(null),r()}catch(de){x(`Delete failed: ${(de==null?void 0:de.message)||de}`,"error")}}function Y(T){M(T),b(null),U(null),S(null),p(!0)}function se(T){M(T.type),b(T),U(null),S(null),p(!0)}function ie(T){g.mutate(T,{onSuccess:()=>{w(null),x("Connector deleted")}})}return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5",children:[e.jsx(Pe,{size:16,className:"text-brand-300"}),"Connectors",e.jsxs("span",{className:"text-xs font-normal bg-brand-500/15 text-brand-300 px-2 py-0.5 rounded-full",children:[xe," connected"]})]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Connect Testver to external tools and services"})]}),s&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{children:"View only — connectors are managed by your admin. You can see what's configured but not add, edit, test, or remove them."}),e.jsxs("p",{children:["The ",e.jsx("span",{className:"font-medium",children:"Local Browser"})," and"," ",e.jsx("span",{className:"font-medium",children:"Local Mobile Devices"})," connectors below are yours to connect and use."]})]})]}),e.jsxs("div",{children:[e.jsxs("fieldset",{disabled:s,className:"min-w-0 border-0 p-0 m-0",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Connectors"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:Yt.filter(T=>!hl.includes(T.type)).map(T=>{var Qe,Xe,L,D;const H=h.find(Q=>Q.type===T.type),de=(H==null?void 0:H.status)==="connected",Be=(H==null?void 0:H.status)==="error";return e.jsxs("div",{className:`bg-surface-1 rounded-xl border p-5 transition-all group flex flex-col ${de?"border-emerald-500/30":Be?"border-red-500/30":"border-gray-200 dark:border-white/5 hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{type:T.type,size:28}),e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200",children:T.name})]}),de&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-emerald-400 bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-500/20",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]}),Be&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-400 bg-red-500/10 px-2 py-0.5 rounded-full border border-red-500/20",children:[e.jsx(Se,{className:"w-3 h-3"})," Error"]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1 line-clamp-2",children:T.desc}),H&&e.jsxs("p",{className:"text-[10px] text-gray-500 mb-3 truncate",children:[T.type==="email"&&((Qe=H.config)==null?void 0:Qe.email),T.type==="jira"&&((Xe=H.config)==null?void 0:Xe.baseUrl),T.type==="slack"&&(((L=H.config)==null?void 0:L.channel)||"Webhook configured"),T.type==="teams"&&(((D=H.config)==null?void 0:D.channelName)||"Webhook configured"),H.last_used&&` · Last used: ${Ct(H.last_used)}`]}),!H&&e.jsx("div",{className:"flex-1"}),H?e.jsxs("div",{className:"flex items-center gap-2 pt-3 border-t border-gray-100 dark:border-white/5",children:[e.jsxs("button",{onClick:()=>se(H),className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-white/[0.04] hover:bg-gray-100 dark:hover:bg-white/[0.08] rounded-lg transition-colors",children:[e.jsx(as,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400"})," Settings"]}),e.jsx("button",{onClick:()=>{y.mutate(H.id,{onSuccess:Q=>x(Q.success?"Connection successful!":`Failed: ${Q.error}`,Q.success?"success":"error")})},disabled:y.isPending,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-white/[0.04] hover:bg-gray-100 dark:hover:bg-white/[0.08] rounded-lg transition-colors disabled:opacity-50",title:"Test Connection",children:y.isPending?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($e,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400"})}),e.jsx("button",{onClick:()=>w(H.id),className:"flex items-center justify-center px-3 py-2 text-xs text-gray-400 dark:text-gray-500 hover:text-red-500 dark:hover:text-red-400 bg-gray-50 dark:bg-white/[0.04] hover:bg-red-50 dark:hover:bg-red-500/10 rounded-lg transition-colors",title:"Remove",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]}):e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("button",{onClick:()=>Y(T.type),className:"w-full flex items-center justify-center gap-2 px-3 py-2.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors shadow-sm",children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Configure"]})})]},T.type)})}),e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Cloud Testing Providers"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[_e.map(T=>{const H=ce(T.id),de=E.find(Be=>Be.id===T.id);return e.jsxs("div",{className:`bg-surface-1 rounded-xl border p-5 transition-all group flex flex-col ${H?"border-emerald-200 dark:border-emerald-500/20":"border-gray-200 dark:border-white/5 hover:border-brand-300 dark:hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"text-2xl",children:e.jsx(yt,{id:T.id,size:28})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200",children:T.name})}),H&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-200 dark:border-emerald-500/20 shrink-0",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4 line-clamp-2 flex-1",children:T.desc}),H?e.jsxs("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:[e.jsxs("div",{className:"text-xs text-gray-500 mb-2",children:[e.jsx("span",{className:"text-gray-400",children:"User:"})," ",de==null?void 0:de.username]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>ye(T.id),className:"flex-1 flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-500/10 hover:bg-brand-100 dark:hover:bg-brand-500/20 rounded-lg transition-colors border border-brand-200 dark:border-brand-500/20",children:[e.jsx(as,{className:"w-3.5 h-3.5"})," Edit"]}),e.jsx("button",{onClick:()=>$(T.id),className:"flex items-center justify-center px-3 py-2 text-xs text-gray-400 dark:text-gray-500 hover:text-red-500 dark:hover:text-red-400 bg-gray-50 dark:bg-white/[0.04] hover:bg-red-50 dark:hover:bg-red-500/10 rounded-lg transition-colors",title:"Remove",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]})]}):e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("button",{onClick:()=>ye(T.id),className:"w-full flex items-center justify-center gap-2 px-3 py-2.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors shadow-sm",children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Configure"]})})]},T.id)}),(()=>{const T=E.find(de=>de.id==="testver-grid"),H=!!T;return e.jsxs("div",{className:`bg-surface-1 rounded-xl border p-5 transition-all group flex flex-col ${H?"border-emerald-200 dark:border-emerald-500/20":"border-gray-200 dark:border-white/5 hover:border-brand-300 dark:hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"w-7 h-7 rounded-lg bg-emerald-100 dark:bg-emerald-500/15 flex items-center justify-center",children:e.jsx(Ee,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("h3",{className:"text-[15px] font-semibold text-gray-200 flex items-center gap-2",children:"Testver Grid"})}),H&&(T==null?void 0:T.enabled)&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-200 dark:border-emerald-500/20 shrink-0",children:[e.jsx(ne,{className:"w-3 h-3"})," Connected"]})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4 line-clamp-2 flex-1",children:"Testver's own cloud browsers — Chromium, Firefox and WebKit. No vendor account needed"}),e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-white/5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>ae(!0),className:H?"flex-1 flex items-center justify-center gap-2 px-3 py-2 text-xs font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-500/10 hover:bg-brand-100 dark:hover:bg-brand-500/20 rounded-lg transition-colors border border-brand-200 dark:border-brand-500/20":"w-full flex items-center justify-center gap-2 px-3 py-2.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors shadow-sm",children:H?e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-3.5 h-3.5"})," Manage"]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Connect"]})}),H&&e.jsx("button",{onClick:()=>$("testver-grid"),className:"flex items-center justify-center px-3 py-2 text-xs text-gray-400 dark:text-gray-500 hover:text-red-500 dark:hover:text-red-400 bg-gray-50 dark:bg-white/[0.04] hover:bg-red-50 dark:hover:bg-red-500/10 rounded-lg transition-colors",title:"Remove",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]})})]})})()]})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Browser Execution"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:e.jsx(sl,{})})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-base font-semibold text-gray-300 mb-4",children:"Local Mobile Devices"}),e.jsx("div",{className:"mb-8",children:e.jsx(al,{})})]}),i&&e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"w-6 h-6 text-brand-400 animate-spin"})})]}),j&&z&&e.jsx(bl,{type:z,connector:u,onSave:async T=>{u?(await f.mutateAsync({id:u.id,data:T}),x("Connector updated")):(await d.mutateAsync(T),x("Connector created")),p(!1)},onTest:async T=>{const H=await y.mutateAsync(T);return U(H),H},onSendTest:async(T,H)=>{const de=await c.mutateAsync({id:T,data:H});return S(de),de},testResult:V,sendResult:O,onClose:()=>{p(!1),b(null),U(null),S(null)},saving:d.isPending||f.isPending,testing:y.isPending,sending:c.isPending}),I&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>w(null)}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-white/5",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx(ue,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-100",children:"Delete Connector"})]}),e.jsx("div",{className:"px-6 py-4",children:e.jsx("p",{className:"text-sm text-gray-300",children:"Are you sure you want to delete this connector? Notifications will no longer be sent through it."})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-white/5",children:[e.jsx("button",{onClick:()=>w(null),className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsx("button",{onClick:()=>ie(I),className:"px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-500 rounded-lg",children:"Delete"})]})]})]}),document.body),re&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>{ae(!1),r()}}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 sticky top-0 bg-surface-1 z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-7 h-7 rounded-lg bg-emerald-100 dark:bg-emerald-500/15 flex items-center justify-center",children:e.jsx(Ee,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400"})}),e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"Testver Grid"})]}),e.jsx("button",{onClick:()=>{ae(!1),r()},className:"text-gray-400 hover:text-gray-200",children:e.jsx(me,{size:20})})]}),e.jsx("div",{className:"p-6",children:e.jsx(cl,{onChanged:()=>r()})})]})]}),document.body),P&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>B(null)}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 sticky top-0 bg-surface-1 z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:e.jsx(yt,{id:P,size:28})}),e.jsxs("h2",{className:"text-base font-semibold text-gray-100",children:[ce(P)?"Edit":"Configure"," ",(be=_e.find(T=>T.id===P))==null?void 0:be.name]})]}),e.jsx("button",{onClick:()=>B(null),className:"text-gray-400 hover:text-gray-200",children:e.jsx(me,{size:20})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N.enabled,onChange:T=>ee({...N,enabled:T.target.checked}),className:"rounded border-gray-600 bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Enable ",(oe=_e.find(T=>T.id===P))==null?void 0:oe.name]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Username"}),e.jsx("input",{value:N.username,onChange:T=>ee({...N,username:T.target.value}),placeholder:"Username",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Access Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:te?"text":"password",value:N.accessKey,onChange:T=>ee({...N,accessKey:T.target.value}),onFocus:()=>{N.accessKey===Fs&&ee({...N,accessKey:""})},onBlur:()=>{!N.accessKey&&ce(P)&&ee({...N,accessKey:Fs})},placeholder:"Access key / API token",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 pr-10 text-gray-200 text-sm font-mono focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsx("button",{onClick:()=>X(!te),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:te?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]}),((k=E.find(T=>T.id===P))==null?void 0:k.accessKeyProblem)&&e.jsx("p",{className:"text-xs text-amber-400 mt-1.5",children:(C=E.find(T=>T.id===P))==null?void 0:C.accessKeyProblem})]}),P==="saucelabs"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Region"}),e.jsxs("select",{value:N.region,onChange:T=>ee({...N,region:T.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500",children:[e.jsx("option",{value:"us-west-1",children:"US West"}),e.jsx("option",{value:"eu-central-1",children:"EU Central"}),e.jsx("option",{value:"us-east-4",children:"US East"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Default Build Name (optional)"}),e.jsx("input",{value:N.defaultBuildName,onChange:T=>ee({...N,defaultBuildName:T.target.value}),placeholder:"e.g., testver-{date}",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!!N.tunnelEnabled,onChange:T=>ee({...N,tunnelEnabled:T.target.checked}),className:"rounded border-gray-600 bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Local tunnel"]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1 ml-6",children:["For apps on localhost or a private network. Web sessions use your running ",P==="browserstack"?"BrowserStack Local":P==="saucelabs"?"Sauce Connect":"LambdaTest Tunnel"," — start it before the run.",P==="browserstack"?" Runs through a BrowserStack SDK start it themselves.":""]}),N.tunnelEnabled&&e.jsx("input",{value:N.tunnelName,onChange:T=>ee({...N,tunnelName:T.target.value}),placeholder:"Tunnel name (optional)",className:"mt-2 w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),_&&e.jsxs("div",{className:`flex items-center gap-2 text-sm px-4 py-2.5 rounded-lg ${_.ok?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,children:[_.ok?e.jsx(ne,{size:16}):e.jsx(Se,{size:16}),_.msg]})]}),e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-white/5 sticky bottom-0 bg-surface-1",children:[e.jsxs("button",{onClick:ke,disabled:K||!N.username||!N.accessKey&&!ce(P),className:"flex items-center gap-1.5 px-3 py-2 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[K?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($e,{className:"w-3.5 h-3.5"}),"Test Connection"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>B(null),className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsxs("button",{onClick:Ne,disabled:R||!N.username||!N.accessKey&&!ce(P),className:"flex items-center gap-2 px-5 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg disabled:opacity-40 transition-colors",children:[R?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(ne,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),document.body),le&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>$(null)}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-white/5",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx(ue,{size:20,className:"text-red-400"})}),e.jsx("h3",{className:"text-base font-semibold text-gray-100",children:"Remove Cloud Provider"})]}),e.jsx("div",{className:"px-6 py-4",children:e.jsxs("p",{className:"text-sm text-gray-300",children:["Are you sure you want to remove ",((q=_e.find(T=>T.id===le))==null?void 0:q.name)||"Testver Grid","? Saved credentials will be deleted."]})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-white/5",children:[e.jsx("button",{onClick:()=>$(null),className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsx("button",{onClick:()=>F(le),className:"px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-500 rounded-lg",children:"Remove"})]})]})]}),document.body)]})}function bl({type:s,connector:t,onSave:a,onTest:l,onSendTest:m,testResult:i,sendResult:h,onClose:d,saving:f,testing:g,sending:y}){var R,G,_;const c=Yt.find(A=>A.type===s),[j,p]=n.useState((t==null?void 0:t.name)||`${c.name} Connection`),[u,b]=n.useState((t==null?void 0:t.config)||N(s)),[z,M]=n.useState((t==null?void 0:t.notify_on)||["run_complete","failure"]),[V,U]=n.useState(Array.isArray((R=t==null?void 0:t.config)==null?void 0:R.notifyEmails)?t.config.notifyEmails.join(", "):((G=t==null?void 0:t.config)==null?void 0:G.notifyEmails)||""),[O,S]=n.useState(!1),[I,w]=n.useState(""),[v,x]=n.useState((t==null?void 0:t.id)||null),{data:o}=ta({enabled:s==="email"}),r=o==null?void 0:o.services.mail,E=!!(o!=null&&o.connected)&&!!r&&(r.on||r.providedBy==="system")&&!o.memberOnly,{hasRole:P}=ws(),B=P("admin");function N(A){switch(A){case"email":return{provider:"gmail",host:"smtp.gmail.com",port:587,secure:!1,email:"",password:"",fromName:"Testver"};case"slack":return{webhookUrl:"",channel:"",botName:"Testver"};case"teams":return{webhookUrl:"",channelName:""};case"jira":return{baseUrl:"",email:"",apiToken:"",defaultProject:""};default:return{}}}const ee=A=>{if(A==="testver"){b(X=>{var le,$;return{...X,provider:A,host:"",port:0,secure:!1,password:"",email:(r==null?void 0:r.replyTo)??X.email??"",sender:(r==null?void 0:r.fromAddress)??"tool@testver.com",fromName:X.fromName||(((le=o==null?void 0:o.own.subject)==null?void 0:le.name)??(($=o==null?void 0:o.own.account)==null?void 0:$.name)??"")}});return}const te=jt.find(X=>X.id===A);b(X=>({...X,provider:A,host:(te==null?void 0:te.host)||X.host,port:(te==null?void 0:te.port)||X.port}))},K=async()=>{const A=s==="email"?{...u,notifyEmails:Is(V)}:u,te={type:s,name:j,config:A,notifyOn:z};t||(te.createdBy="admin"),await a(te)},W=v!=null;return fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:d}),e.jsxs("div",{className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl w-full max-w-2xl mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 sticky top-0 bg-surface-1 z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{type:s,size:24}),e.jsxs("h2",{className:"text-base font-semibold text-gray-100",children:[t?"Edit":"Configure"," ",c.name]})]}),e.jsx("button",{onClick:d,className:"text-gray-400 hover:text-gray-200",children:e.jsx(me,{size:20})})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Connection Name"}),e.jsx("input",{type:"text",value:j,onChange:A=>p(A.target.value),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),s==="email"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Provider"}),e.jsx("select",{value:u.provider,onChange:A=>ee(A.target.value),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500",children:jt.map(A=>e.jsx("option",{value:A.id,disabled:A.id==="testver"&&!E&&u.provider!=="testver",children:A.name},A.id))})]}),u.provider==="testver"&&!E&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-amber-500/[0.07] border border-amber-500/25 rounded-lg px-3.5 py-2.5 text-xs text-amber-200",children:[e.jsx(Ps,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsxs("span",{children:[o!=null&&o.connected?o.memberOnly?"Testver mail is managed by your team owner on the team's Testver installation — ":(_=r==null?void 0:r.reason)!=null&&_.message?`${r.reason.message} — `:"Testver mail is switched off — ":"Connect to Testver to use Testver mail — ",e.jsx(os,{to:"/testver",className:"underline underline-offset-2 hover:text-amber-100",children:"open Testver → Connections"}),"."]})]}),u.provider==="testver"&&E&&e.jsx("p",{className:"text-xs text-gray-500",children:"No SMTP host, port or password. Mail goes through Testver's own server; your Gmail, Outlook and custom SMTP connections stay as they are."}),u.provider==="testver"?e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Sends as"}),e.jsx("input",{type:"text",readOnly:!0,value:u.sender||(r==null?void 0:r.fromAddress)||"tool@testver.com",className:"w-full bg-surface-2 border border-dashed border-white/10 rounded-lg px-3 py-2 text-gray-400 text-sm font-mono"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["Replies go to",B&&e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:"(editable by admins)"})]}),B?e.jsx("input",{type:"email",value:u.email??"",placeholder:(r==null?void 0:r.replyTo)||"you@company.com",onChange:A=>b({...u,email:A.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm font-mono placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"}):e.jsx("input",{type:"text",readOnly:!0,value:u.email||(r==null?void 0:r.replyTo)||"",className:"w-full bg-surface-2 border border-dashed border-white/10 rounded-lg px-3 py-2 text-gray-400 text-sm font-mono"})]})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"SMTP Host"}),e.jsx("input",{type:"text",value:u.host,onChange:A=>b({...u,host:A.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Port"}),e.jsx("input",{type:"number",value:u.port,onChange:A=>b({...u,port:parseInt(A.target.value)||587}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]}),u.provider!=="testver"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Email Address"}),e.jsx("input",{type:"email",value:u.email,onChange:A=>b({...u,email:A.target.value}),placeholder:"user@gmail.com",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["Password / App Password",u.provider==="gmail"&&e.jsx("span",{className:"text-xs text-amber-400 ml-2",children:"(Use Gmail App Password)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:O?"text":"password",value:u.password,onChange:A=>b({...u,password:A.target.value}),className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 pr-10 text-gray-200 text-sm focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsx("button",{onClick:()=>S(!O),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:O?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"From Name"}),e.jsx("input",{type:"text",value:u.fromName||"",onChange:A=>b({...u,fromName:A.target.value}),placeholder:"Testver Notifications",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["Notify these addresses",e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:"(team notifications — comma-separated)"})]}),e.jsx("textarea",{rows:2,value:V,onChange:A=>U(A.target.value),onBlur:()=>b({...u,notifyEmails:Is(V)}),placeholder:"qa-team@company.com, lead@company.com",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm font-mono placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500 resize-y"}),e.jsxs("p",{className:"mt-1 text-[11px] text-gray-500",children:["Run, cycle, CI gate, auto-heal, schedule and defect broadcasts go here.",Is(V).length===0&&e.jsxs(e.Fragment,{children:[" Leave empty to send them to ",u.provider==="testver"?'the "Replies go to" address':"the sender address"," above."]})," ","Personal emails (welcome, password, assigned defects) always go to the user concerned."]})]})]}),s==="slack"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-purple-500/5 border border-purple-500/10 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ps,{className:"w-4 h-4 text-purple-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-gray-400",children:[e.jsx("p",{className:"font-medium text-purple-300 mb-1",children:"How to get Webhook URL:"}),e.jsxs("ol",{className:"list-decimal ml-4 space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("span",{className:"text-purple-300",children:"api.slack.com/apps"})," → Create New App"]}),e.jsxs("li",{children:["Enable ",e.jsx("span",{className:"text-purple-300",children:"Incoming Webhooks"})]}),e.jsx("li",{children:"Add to your channel → Copy webhook URL"})]})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Webhook URL"}),e.jsx("input",{type:"text",value:u.webhookUrl,onChange:A=>b({...u,webhookUrl:A.target.value}),placeholder:"https://hooks.slack.com/services/T.../B.../xxx",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Channel (display only)"}),e.jsx("input",{type:"text",value:u.channel||"",onChange:A=>b({...u,channel:A.target.value}),placeholder:"#qa-alerts",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Bot Name"}),e.jsx("input",{type:"text",value:u.botName||"",onChange:A=>b({...u,botName:A.target.value}),placeholder:"Testver",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]})]}),s==="teams"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-indigo-500/5 border border-indigo-500/10 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ps,{className:"w-4 h-4 text-indigo-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-gray-400",children:[e.jsx("p",{className:"font-medium text-indigo-300 mb-1",children:"How to get Webhook URL:"}),e.jsxs("ol",{className:"list-decimal ml-4 space-y-0.5",children:[e.jsxs("li",{children:["In Teams Channel → ",e.jsx("span",{className:"text-indigo-300",children:"⋯"})," → Connectors (or Workflows)"]}),e.jsxs("li",{children:["Search ",e.jsx("span",{className:"text-indigo-300",children:"Incoming Webhook"})," → Configure"]}),e.jsx("li",{children:'Name it "Testver" → Create → Copy URL'})]})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Webhook URL"}),e.jsx("input",{type:"text",value:u.webhookUrl,onChange:A=>b({...u,webhookUrl:A.target.value}),placeholder:"https://outlook.office.com/webhook/...",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Channel Name (display only)"}),e.jsx("input",{type:"text",value:u.channelName||"",onChange:A=>b({...u,channelName:A.target.value}),placeholder:"QA Notifications",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]}),s==="jira"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"JIRA Cloud URL"}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:A=>b({...u,baseUrl:A.target.value}),placeholder:"https://yourcompany.atlassian.net",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Email (Atlassian Account)"}),e.jsx("input",{type:"email",value:u.email,onChange:A=>b({...u,email:A.target.value}),placeholder:"user@company.com",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-gray-400 mb-1.5",children:["API Token ",e.jsxs("a",{href:"https://id.atlassian.com/manage-profile/security/api-tokens",target:"_blank",className:"text-brand-400 hover:text-brand-300 ml-1 inline-flex items-center gap-0.5",children:[e.jsx(Ss,{size:10})," Generate"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:O?"text":"password",value:u.apiToken,onChange:A=>b({...u,apiToken:A.target.value}),placeholder:"ATATT3xFf...",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 pr-10 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsx("button",{onClick:()=>S(!O),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:O?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-1.5",children:"Default Project Key"}),e.jsx("input",{type:"text",value:u.defaultProject||"",onChange:A=>b({...u,defaultProject:A.target.value}),placeholder:"PROJ",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-gray-200 text-sm placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]})]}),s!=="jira"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-400 mb-2",children:"Notify On"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:pl.map(A=>e.jsxs("label",{className:`flex items-center gap-2 p-3 rounded-lg border cursor-pointer transition-colors ${z.includes(A.id)?"bg-brand-500/10 border-brand-500/30":"bg-surface-2 border-white/5 hover:border-white/10"}`,children:[e.jsx("input",{type:"checkbox",checked:z.includes(A.id),onChange:te=>M(X=>te.target.checked?[...X,A.id]:X.filter(le=>le!==A.id)),className:"sr-only"}),e.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center ${z.includes(A.id)?"bg-brand-500 border-brand-500":"border-gray-600"}`,children:z.includes(A.id)&&e.jsx(ne,{className:"w-3 h-3 text-white"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-gray-200",children:A.label}),e.jsx("div",{className:"text-[10px] text-gray-500",children:A.desc})]})]},A.id))})]}),i&&e.jsx("div",{className:`p-3 rounded-lg border ${i.success?"bg-emerald-500/5 border-emerald-500/20":"bg-red-500/5 border-red-500/20"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[i.success?e.jsx(ne,{className:"w-4 h-4 text-emerald-400"}):e.jsx(Se,{className:"w-4 h-4 text-red-400"}),e.jsx("span",{className:`text-sm font-medium ${i.success?"text-emerald-400":"text-red-400"}`,children:i.success?`Connection successful${i.user?` — ${i.user}`:""}`:`Failed: ${i.error}`})]})}),h&&e.jsx("div",{className:`p-3 rounded-lg border ${h.success?"bg-emerald-500/5 border-emerald-500/20":"bg-red-500/5 border-red-500/20"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[h.success?e.jsx(ne,{className:"w-4 h-4 text-emerald-400"}):e.jsx(Se,{className:"w-4 h-4 text-red-400"}),e.jsx("span",{className:`text-sm ${h.success?"text-emerald-400":"text-red-400"}`,children:h.success?"Test notification sent successfully!":`Send failed: ${h.error}`})]})})]}),e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-white/5 sticky bottom-0 bg-surface-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:W&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>l(v),disabled:g,className:"flex items-center gap-1.5 px-3 py-2 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[g?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($e,{className:"w-3.5 h-3.5"}),"Test Connection"]}),s==="email"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"email",value:I,onChange:A=>w(A.target.value),placeholder:"Send test to...",className:"bg-surface-2 border border-white/10 rounded-lg px-2 py-1.5 text-gray-200 text-xs w-40 focus:outline-none focus:ring-1 focus:ring-brand-500"}),e.jsxs("button",{onClick:()=>I&&m(v,{to:I}),disabled:y||!I,className:"flex items-center gap-1 px-2 py-1.5 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[y?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(_s,{className:"w-3 h-3"})," Send"]})]}),(s==="slack"||s==="teams")&&e.jsxs("button",{onClick:()=>m(v),disabled:y,className:"flex items-center gap-1.5 px-3 py-2 text-xs bg-surface-2 hover:bg-surface-3 text-gray-300 rounded-lg border border-white/10 disabled:opacity-50",children:[y?e.jsx(J,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(_s,{className:"w-3.5 h-3.5"}),"Send Test Message"]})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:d,className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 rounded-lg",children:"Cancel"}),e.jsxs("button",{onClick:K,disabled:f||!j.trim(),className:"flex items-center gap-2 px-5 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg disabled:opacity-40 transition-colors",children:[f?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(ne,{className:"w-4 h-4"}),t?"Update":"Save"]})]})]})]})]}),document.body)}const fl=["Dev","QA","Staging","Prod"];function yl(s){return s<1024*1024?`${(s/1024).toFixed(0)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function jl({readOnly:s=!1}){const{toast:t}=ge(),a=Je(),{data:l,isLoading:m}=Ge({queryKey:["mobile-apps"],queryFn:la}),i=(l==null?void 0:l.apps)??[],h=n.useRef(null),[d,f]=n.useState(""),[g,y]=n.useState(null),[c,j]=n.useState(null),[p,u]=n.useState(""),[b,z]=n.useState(null),{android:M,ios:V}=n.useMemo(()=>({android:i.filter(x=>x.kind==="apk"),ios:i.filter(x=>x.kind==="ipa")}),[i]),U=()=>void a.invalidateQueries({queryKey:["mobile-apps"]}),O=async x=>{y(0);try{await oa(x,d.trim()||void 0,o=>y(o)),t("success",`Uploaded ${x.name}`),f(""),U()}catch(o){t("error",o.message)}finally{y(null),h.current&&(h.current.value="")}},S=async x=>{const o=p.trim();if(j(null),!!o)try{await da(x,o),U()}catch(r){t("error",r.message)}},I=async()=>{if(!b)return;const x=b;z(null);try{await ia(x.id),t("success",`Removed ${x.label||x.filename}`),U()}catch(o){t("error",o.message)}},w=({app:x})=>e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg hover:bg-black/[0.03] dark:hover:bg-white/[0.03] group",children:[x.kind==="ipa"?e.jsx(rn,{size:14,className:"text-gray-400 flex-shrink-0"}):e.jsx(Oe,{size:14,className:"text-emerald-500 flex-shrink-0"}),c===x.id?e.jsxs("span",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[e.jsx("input",{autoFocus:!0,value:p,onChange:o=>u(o.target.value),onKeyDown:o=>{o.key==="Enter"&&S(x.id),o.key==="Escape"&&j(null)},className:"flex-1 min-w-0 bg-surface-2 border border-brand-500/40 rounded-lg px-2.5 py-1 text-sm text-gray-200 outline-none",maxLength:60}),e.jsx("button",{onClick:()=>void S(x.id),className:"p-1 text-emerald-500 hover:bg-emerald-500/10 rounded",title:"Save name",children:e.jsx(Ue,{size:14})}),e.jsx("button",{onClick:()=>j(null),className:"p-1 text-gray-500 hover:bg-white/5 rounded",title:"Cancel",children:e.jsx(me,{size:14})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-gray-200 font-medium truncate",children:x.label||x.filename}),e.jsxs("span",{className:"text-xs text-gray-500 font-mono truncate flex-1 min-w-0",title:x.filename,children:[x.filename," · ",yl(x.size)]}),!s&&e.jsxs("span",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:[e.jsx("button",{onClick:()=>{j(x.id),u(x.label||"")},className:"p-1.5 rounded text-gray-500 hover:text-brand-400 hover:bg-white/5",title:"Rename (e.g. Dev, QA, Prod)",children:e.jsx(Cs,{size:13})}),e.jsx("button",{onClick:()=>z(x),className:"p-1.5 rounded text-gray-500 hover:text-red-400 hover:bg-red-500/10",title:"Delete build",children:e.jsx(we,{size:13})})]})]})]}),v=({title:x,list:o})=>e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-gray-500 mb-1.5",children:x}),o.length===0?e.jsx("div",{className:"text-xs text-gray-600 px-3 py-1.5",children:"No builds uploaded yet."}):e.jsx("div",{className:"space-y-0.5",children:o.map(r=>e.jsx(w,{app:r},r.id))})]});return e.jsxs("div",{className:"rounded-xl border border-white/5 bg-black/20 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-gray-200",children:[e.jsx(tn,{size:15,className:"text-brand-400"})," App Builds"]}),e.jsx("p",{className:"text-xs text-gray-500 -mt-1",children:"Upload app binaries and name them by environment — builds uploaded here appear in every device/app picker (Runner, AI Assistant). Deduplicated by content, so re-uploading the same binary never stores a second copy."}),!s&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:d,onChange:x=>f(x.target.value),placeholder:"Name for the next upload (e.g. QA)",maxLength:60,className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50"}),e.jsxs("button",{onClick:()=>{var x;return(x=h.current)==null?void 0:x.click()},disabled:g!==null,className:"inline-flex items-center gap-1.5 px-3.5 py-2.5 text-sm rounded-lg bg-brand-600 hover:bg-brand-500 text-white disabled:opacity-50 transition-colors flex-shrink-0",children:[g!==null?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(bs,{size:14}),g!==null?`${Math.round(g*100)}%`:"Upload build"]}),e.jsx("input",{ref:h,type:"file",accept:".apk,.aab,.ipa,.zip",className:"hidden",onChange:x=>{var r;const o=(r=x.target.files)==null?void 0:r[0];o&&O(o)}})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[fl.map(x=>e.jsx("button",{onClick:()=>f(x),className:`px-2.5 py-1 rounded-full text-xs border transition-colors ${d===x?"border-brand-500/50 bg-brand-500/10 text-brand-400":"border-white/10 text-gray-500 hover:text-gray-300 hover:border-white/20"}`,children:x},x)),e.jsx("span",{className:"text-xs text-gray-600 ml-1",children:"Android: .apk / .aab · iOS: .ipa (cloud) / zipped .app (local simulator)"})]})]}),m?e.jsxs("div",{className:"text-xs text-gray-600 flex items-center gap-1.5",children:[e.jsx(J,{size:12,className:"animate-spin"})," Loading builds…"]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{title:"Android",list:M}),e.jsx(v,{title:"iOS",list:V})]}),e.jsx(Ot,{open:b!==null,title:"Delete app build?",description:b?`"${b.label||b.filename}" (${b.filename}) will be removed from the library and its binary deleted from disk. Runner and AI Assistant pickers will no longer offer it; cloud copies already uploaded to a provider are not affected.`:"",confirmLabel:"Delete build",onConfirm:()=>void I(),onCancel:()=>z(null)})]})}const ps=()=>({username:"",accessKey:"",region:"us-west-1",hubUrl:"",defaultBuildName:"",enabled:!0});function vl({readOnly:s,fallback:t}){const{toast:a}=ge(),{name:l,maxLength:m,isLoading:i}=pa(),h=ga(),[d,f]=n.useState(!1),[g,y]=n.useState(""),c=()=>{y(l??""),f(!0)},j=()=>{f(!1),y("")},p=async()=>{const u=g.trim();if(!u){a("error","Enter a project name");return}if(u===l){j();return}try{await h.mutateAsync(u),a("success","Project name saved"),f(!1)}catch(b){a("error",`Couldn't save the project name: ${b instanceof Error?b.message:b}`)}};return i?e.jsx("span",{className:"text-gray-500",children:"…"}):d&&!s?e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("input",{type:"text",value:g,onChange:u=>y(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),p()),u.key==="Escape"&&(u.preventDefault(),j())},maxLength:m,autoFocus:!0,"aria-label":"Project name",placeholder:"e.g. Customer Portal","data-testid":"project-name-input",className:`flex-1 min-w-0 px-3 py-1.5 bg-surface-2 border border-white/10 rounded-lg text-gray-100 text-sm
|
|
80
|
+
focus:outline-none focus:border-brand-500/50 placeholder-gray-600`}),e.jsxs("button",{type:"button",onClick:()=>void p(),disabled:h.isPending||!g.trim(),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 transition-colors disabled:opacity-50",children:[h.isPending?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Ue,{size:12}),"Save"]}),e.jsx("button",{type:"button",onClick:j,disabled:h.isPending,className:"px-3 py-1.5 rounded-lg text-xs font-medium text-gray-300 bg-surface-2 hover:bg-surface-3 border border-white/10 transition-colors",children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l?e.jsx("span",{className:"text-gray-100 font-medium truncate","data-testid":"project-name-value",title:l,children:l}):e.jsxs("span",{className:"text-gray-500 truncate","data-testid":"project-name-value",children:["Not set",t?` — showing "${t}"`:""]}),!s&&e.jsx("button",{type:"button",onClick:c,title:l?"Rename project":"Set a project name","aria-label":l?"Rename project":"Set a project name","data-testid":"project-name-edit",className:"p-1 rounded-md text-gray-500 hover:text-brand-300 hover:bg-white/[0.05] transition-colors flex-shrink-0",children:e.jsx(Cs,{size:13})})]})}function co(){const{project:s}=Zt(),[t,a]=n.useState(ca),{toast:l}=ge(),{hasRole:m}=ws(),i=m("admin"),{mcpEnabled:h}=pn(),[d,f]=mt("tab",["general","llm","skills","mcp","connectors","config","browser-sessions","access-tokens"],"general"),{showsWeb:g}=ks();n.useEffect(()=>{!g&&d==="browser-sessions"&&f("general")},[g,d,f]);const[y,c]=n.useState([]);mt("subtab",["browserstack","lambdatest","saucelabs","testver-grid","local-appium"],"browserstack");const[j,p]=n.useState({browserstack:ps(),lambdatest:ps(),saucelabs:ps(),"testver-grid":ps()}),[u,b]=n.useState({}),[z,M]=n.useState({}),[V,U]=n.useState({}),[O,S]=n.useState(!1),I=n.useCallback(async()=>{try{const x=await At();c(x.providers);const o={...j};for(const r of x.providers)o[r.id]={username:r.username,accessKey:r.accessKey,region:r.region||"us-west-1",hubUrl:r.hubUrl||"",defaultBuildName:r.defaultBuildName||"",enabled:r.enabled};p(o)}catch{}},[]);n.useEffect(()=>{I()},[I]);const v=[{id:"general",label:"General",icon:e.jsx(an,{size:16}),description:"Project info & appearance"},{id:"llm",label:"LLM",icon:e.jsx(Ft,{size:16}),description:"AI provider configuration"},{id:"skills",label:"Skills",icon:e.jsx(Qs,{size:16}),description:"Manage Agent Skills"},{id:"mcp",label:"MCP Servers",icon:e.jsx(Pe,{size:16}),description:"Manage MCP servers"},{id:"connectors",label:"Connectors",icon:e.jsx(Dt,{size:16}),description:"JIRA, Slack, Email, cloud grids & webhooks"},{id:"config",label:"Config",icon:e.jsx(vs,{size:16}),description:"Environment and config files"},{id:"browser-sessions",label:"Browser Sessions",icon:e.jsx(Ve,{size:16}),description:"Live browser processes"},{id:"access-tokens",label:"Access Tokens",icon:e.jsx(nn,{size:16}),description:"Personal access tokens"}].filter(x=>(x.id!=="mcp"||h)&&(x.id!=="browser-sessions"||g));return e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200 animate-fade-in",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-6",children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(as,{size:24,className:"text-brand-300"}),"Settings"]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Configure application settings, LLM providers, and cloud integrations"})]})}),e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 flex gap-1",children:v.map(x=>e.jsxs("button",{onClick:()=>f(x.id),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium border-b-2 transition-colors ${d===x.id?"border-brand-400 text-brand-300":"border-transparent text-gray-400 hover:text-gray-200 hover:border-white/10"}`,children:[er.cloneElement(x.icon,{size:16}),x.label]},x.id))})}),e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8 space-y-6",children:[d==="general"&&e.jsx(Fl,{project:s,theme:t,setTheme:a,readOnly:!i}),d==="llm"&&e.jsx(Hl,{isAdmin:i}),d==="skills"&&e.jsx(Ln,{readOnly:!i}),d==="mcp"&&h&&e.jsx(Hn,{readOnly:!i}),d==="connectors"&&e.jsx(gl,{readOnly:!i}),d==="config"&&e.jsx(Wn,{embedded:!0}),d==="access-tokens"&&e.jsx(hn,{isAdmin:i}),d==="browser-sessions"&&g&&e.jsx("div",{className:"h-full overflow-auto",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-8 space-y-6",children:e.jsx(Xn,{})})})]})]})}const Nl=[{value:"web",label:"Web",Icon:cs,description:"Show only web testing UI",badge:null,selectedClasses:"bg-sky-500/15 border-sky-500/60 ring-1 ring-sky-500/40",selectedIconClasses:"text-sky-700 dark:text-sky-400",selectedLabelClasses:"text-sky-700 dark:text-sky-300"},{value:"mobile",label:"Mobile",Icon:Oe,description:"Show only mobile testing UI",badge:"Beta",selectedClasses:"bg-indigo-500/20 border-indigo-500/70 ring-1 ring-indigo-500/50",selectedIconClasses:"text-indigo-700 dark:text-indigo-400",selectedLabelClasses:"text-indigo-700 dark:text-indigo-300"}];function wl(){const{mode:s,setAt:t,isLoading:a}=ks(),l=va(),{toast:m}=ge(),[i,h]=n.useState(null),d=g=>{g!==s&&h(g)},f=async()=>{if(i)try{await l.mutateAsync(i),m("success",`App mode set to ${i.charAt(0).toUpperCase()+i.slice(1)}`)}catch(g){m("error",`Failed to update app mode: ${g}`)}finally{h(null)}};return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(As,{size:18}),"App Mode"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5",children:"Controls which Testver surfaces are visible across the workspace — Runner, Recorder, Schedules, and AI Assistant pickers all adapt to this setting."})]}),t&&e.jsxs("span",{className:"text-xs text-gray-500 whitespace-nowrap",children:["Last changed ",Ct(t)]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:Nl.map(({value:g,label:y,Icon:c,description:j,badge:p,selectedClasses:u,selectedIconClasses:b,selectedLabelClasses:z})=>{const M=s===g;return e.jsxs("button",{type:"button",onClick:()=>d(g),disabled:a||l.isPending,className:`relative flex flex-col items-center justify-center gap-1.5 px-3 py-4 rounded-lg border text-sm transition-all disabled:opacity-50 ${M?u:"bg-white/[0.03] border-white/10 text-gray-400 hover:bg-white/[0.06] hover:border-white/20 hover:text-gray-200"}`,title:j,children:[p&&e.jsx("span",{className:"absolute top-2 right-2 text-[9px] font-bold uppercase tracking-wider px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-400 border border-amber-500/30",children:p}),e.jsx(c,{size:22,className:M?b:""}),e.jsx("span",{className:`font-medium ${M?z:""}`,children:y}),e.jsx("span",{className:"text-[11px] text-gray-500 text-center leading-tight",children:j})]},g)})}),i&&e.jsx(kl,{currentMode:s,nextMode:i,pending:l.isPending,onCancel:()=>h(null),onConfirm:f})]})}function kl({currentMode:s,nextMode:t,pending:a,onCancel:l,onConfirm:m}){const i=s?s.charAt(0).toUpperCase()+s.slice(1):"—",h=t.charAt(0).toUpperCase()+t.slice(1),d=t==="mobile"?Oe:cs,f=t==="mobile"?{btn:"bg-indigo-600 hover:bg-indigo-500",icon:"bg-indigo-500/20 text-indigo-700 dark:text-indigo-300"}:{btn:"bg-sky-600 hover:bg-sky-500",icon:"bg-sky-500/20 text-sky-700 dark:text-sky-300"};return fe.createPortal(e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[9999] animate-fade-in p-4",children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/10 w-full max-w-xl p-7",children:[e.jsxs("div",{className:"flex items-center gap-3.5 mb-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-amber-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(ue,{size:22,className:"text-amber-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-200",children:"Change App Mode?"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"This affects the entire workspace"})]})]}),e.jsxs("p",{className:"text-[15px] text-gray-300 mb-4",children:["You're switching from ",e.jsx("span",{className:"font-semibold text-gray-100",children:i})," to",e.jsxs("span",{className:"font-semibold text-gray-100",children:[" ",h]}),"."]}),e.jsxs("div",{className:`flex items-start gap-3 mb-6 p-4 rounded-lg border ${t==="mobile"?"bg-indigo-500/5 border-indigo-500/20":"bg-sky-500/5 border-sky-500/20"}`,children:[e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0 ${f.icon}`,children:e.jsx(d,{size:20})}),e.jsxs("ul",{className:"text-sm text-gray-400 space-y-1.5 leading-relaxed",children:[e.jsxs("li",{children:["• Runner, Recorder, Schedules, and AI Assistant will reload and show only ",e.jsx("span",{className:"text-gray-200 font-medium",children:h})," controls."]}),e.jsxs("li",{children:["• Active recording or test-run sessions tied to ",e.jsx("span",{className:"text-gray-200 font-medium",children:i})," may become unreachable from the UI."]}),e.jsx("li",{children:"• Saved schedules and history remain on disk — they'll reappear if you switch back."})]})]}),e.jsxs("div",{className:"flex justify-end gap-2.5",children:[e.jsx("button",{type:"button",onClick:l,disabled:a,className:"px-5 py-2.5 rounded-lg text-sm text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:m,disabled:a,className:`flex items-center gap-2 px-5 py-2.5 rounded-lg text-sm font-medium text-white transition-colors disabled:opacity-50 ${f.btn}`,children:[a?e.jsx(J,{size:16,className:"animate-spin"}):e.jsx(d,{size:16}),"Switch to ",h]})]})]})}),document.body)}function vt(s){return s.replace(/\{test\}/g,"dummy").replace(/\{suite\}/g,"dummy").replace(/\{line\}/g,"1").replace(/\{args\}/g,"").replace(/\{absFile\}/g,".").replace(/\{posixFile\}/g,".").replace(/\{fileName\}/g,"dummy.spec.ts").replace(/\{fileNoExt\}/g,"dummy.spec").replace(/\{file\}/g,".").replace(/\{project\}/g,".").replace(/\{cwd\}/g,".").replace(/\{root\}/g,".")}const Cl=["playwright-test","pytest-playwright"],Sl={"playwright-java":"Java","playwright-dotnet":".NET","playwright-python":"Python without pytest-playwright"};function Tl(){const[s,t]=n.useState(null),[a,l]=n.useState(null),{toast:m}=ge();n.useEffect(()=>{nt().then(j=>{t(j),l(j.stacks??[])}).catch(()=>{})},[]);const i=j=>{t(p=>p&&{...p,...j}),ka(j).then(p=>{t(p),m("success",j.capturePassed!==void 0?`Traces for passed tests ${p.capturePassed?"enabled":"disabled"}`:`Trace auto-capture ${p.enabled?"enabled":"disabled"}`)}).catch(p=>{m("error",`Could not save: ${p}`),nt().then(t).catch(()=>{})})},h=(s==null?void 0:s.enabled)??!0,d=(s==null?void 0:s.capturePassed)??!1,f=a??[],g=f.some(j=>Cl.includes(j)),y=f.map(j=>Sl[j]).filter(Boolean),c=({on:j,onClick:p,disabled:u})=>e.jsx("button",{type:"button",onClick:p,disabled:u,className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors disabled:opacity-40 ${j?"bg-brand-500":"bg-surface-3"}`,"aria-pressed":j,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${j?"translate-x-4":"translate-x-1"}`})});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(dn,{size:18}),"API & Network Traces",e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-wider px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-400 border border-brand-500/30",children:"Playwright"})]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:["Records a Playwright trace for your runs so you can inspect every request and response in Results → Open in Trace Viewer → Network. Supported for Playwright tests written in",e.jsx("b",{className:"text-gray-400",children:" TypeScript / JavaScript"})," and ",e.jsx("b",{className:"text-gray-400",children:"Python"})," (with pytest-playwright) — no changes to your test code, and skipped when your command already sets"," ",e.jsx("span",{className:"font-mono text-gray-400",children:"--trace"})," or ",e.jsx("span",{className:"font-mono text-gray-400",children:"--tracing"}),"."]}),a!==null&&f.length===0&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3.5 py-2.5 text-sm text-amber-600 dark:text-amber-300",children:[e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"No Playwright dependency found in this project, so these settings won't affect its runs."})]}),!g&&y.length>0&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3.5 py-2.5 text-sm text-amber-600 dark:text-amber-300",children:[e.jsx(ue,{size:14,className:"mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:["This project uses Playwright for ",y.join(" and "),", so these settings don't apply. Save the trace from your test code when a test fails, with the test's name in the file name, and Results links it to the test."]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Auto-capture traces"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:["Adds ",e.jsx("span",{className:"font-mono text-gray-400",children:"--trace retain-on-failure"})," (Playwright Test) or ",e.jsx("span",{className:"font-mono text-gray-400",children:"--tracing retain-on-failure"})," (pytest-playwright) — a trace is kept for every ",e.jsx("b",{children:"failed"})," test. On by default."]})]}),e.jsx(c,{on:h,onClick:()=>i({enabled:!h})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Also capture for passed tests"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:["Keep a trace for ",e.jsx("b",{children:"passing"})," tests too (",e.jsx("span",{className:"font-mono text-gray-400",children:"--trace on"})," / ",e.jsx("span",{className:"font-mono text-gray-400",children:"--tracing on"}),"). Useful for auditing green runs, but heavier on disk — leave off unless you need it."]})]}),e.jsx(c,{on:d,onClick:()=>i({capturePassed:!d}),disabled:!h})]})]})}const Al=[1,2,4,8,12,24,48,72,168],zl=[1,3,7,14,30,60,90],Nt=s=>s>=24&&s%24===0?`${s/24} day${s===24?"":"s"}`:`${s} hour${s===1?"":"s"}`;function El(){const[s,t]=n.useState(null),{toast:a}=ge();n.useEffect(()=>{ot().then(t).catch(()=>{})},[]);const l=g=>{t(y=>y&&{...y,...g}),Sa(g).then(y=>{t(y),a("success",g.idleHours!==void 0?`Signed out after ${Nt(y.idleHours)} without activity`:`Sign in again every ${y.maxDays} day${y.maxDays===1?"":"s"}`)}).catch(y=>{a("error",`Could not save: ${y}`),ot().then(t).catch(()=>{})})},m=(s==null?void 0:s.idleHours)??24,i=(s==null?void 0:s.maxDays)??7,h=[...new Set([...Al,m])].filter(g=>g<=i*24).sort((g,y)=>g-y),d=[...new Set([...zl,i])].sort((g,y)=>g-y),f="px-3 py-1.5 text-sm bg-surface-2 border border-white/10 rounded-lg text-gray-200 focus:outline-none focus:border-brand-500/50";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(zs,{size:18}),"Sign-in sessions"]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:["A sign-in renews itself while people use Testver — clicking, typing or scrolling counts; a tab left open does not. Everyone gets a warning five minutes before being signed out, with a ",e.jsx("b",{children:"Stay signed in"})," button. Runs keep going on the server either way. Changes apply to everyone, including sessions already signed in."]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Sign out after no activity for"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"How long a sign-in lasts when nobody uses it. Default 1 day."})]}),e.jsx("select",{className:f,value:m,onChange:g=>l({idleHours:Number(g.target.value)}),children:h.map(g=>e.jsx("option",{value:g,children:Nt(g)},g))})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Always sign in again after"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"The longest a sign-in can last, however active. Default 7 days."})]}),e.jsx("select",{className:f,value:i,onChange:g=>l({maxDays:Number(g.target.value)}),children:d.map(g=>e.jsxs("option",{value:g,children:[g," day",g===1?"":"s"]},g))})]})]})}const Pl=[7,14,30,60,90];function Ll(){const{user:s}=ws(),[t,a]=n.useState(null),[l,m]=n.useState(null),{toast:i}=ge();n.useEffect(()=>{it().then(a).catch(()=>{}),ja().then(p=>m(p.enabled)).catch(()=>{})},[]);const h=p=>{a(u=>u&&{...u,...p}),Ta(p).then(u=>{a(u),i("success",p.require!==void 0?u.require==="off"?"Two-factor authentication is optional":`Two-factor authentication required for ${u.require==="admins"?"admins":"everyone"}`:p.allowTrustedBrowsers!==void 0?u.allowTrustedBrowsers?"Browsers can be trusted to skip the code":"Every sign-in asks for a code":`A trusted browser skips the code for ${u.trustedBrowserDays} days`)}).catch(u=>{i("error",`Could not save: ${u}`),it().then(a).catch(()=>{})})},d=(t==null?void 0:t.require)??"off",f=(t==null?void 0:t.allowTrustedBrowsers)??!0,g=(t==null?void 0:t.trustedBrowserDays)??30,y=[...new Set([...Pl,g])].sort((p,u)=>p-u),c="px-3 py-1.5 text-sm bg-surface-2 border border-white/10 rounded-lg text-gray-200 focus:outline-none focus:border-brand-500/50 disabled:opacity-40",j=d==="everyone"||d==="admins"&&((s==null?void 0:s.role)==="admin"||(s==null?void 0:s.role)==="superadmin");return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5","data-testid":"two-factor-policy",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Mt,{size:18}),"Two-factor authentication"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:"Sign-in asks for a 6-digit code from an authenticator app as well as the password. Anyone can turn it on in their Profile; here you can require it. People it applies to set it up at their next sign-in, and anyone signed in now is asked to set it up before they can continue. An admin can reset it for someone who lost their phone (Users)."}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Require two-factor authentication for"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[d==="off"?"Nobody is required to — it is optional for everyone.":d==="admins"?"Admins and the super admin must use it; others may.":"Every account must use it.",j&&l===!1&&" This includes you — you will be asked to set it up right away."]})]}),e.jsxs("select",{className:c,value:d,onChange:p=>h({require:p.target.value}),children:[e.jsx("option",{value:"off",children:"Nobody (optional)"}),e.jsx("option",{value:"admins",children:"Admins only"}),e.jsx("option",{value:"everyone",children:"Everyone"})]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Allow “Trust this browser”"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"Lets people skip the code on a browser they trust. Turning this off makes every sign-in ask for a code, including on browsers trusted before."})]}),e.jsx("button",{type:"button",onClick:()=>h({allowTrustedBrowsers:!f}),className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors ${f?"bg-brand-500":"bg-surface-3"}`,"aria-pressed":f,"aria-label":"Allow trusting a browser",children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${f?"translate-x-4":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:`text-sm font-medium ${f?"text-gray-200":"text-gray-500"}`,children:"A trusted browser skips the code for"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"After this, the browser asks for a code again. Default 30 days."})]}),e.jsx("select",{className:c,value:g,disabled:!f,onChange:p=>h({trustedBrowserDays:Number(p.target.value)}),children:y.map(p=>e.jsxs("option",{value:p,children:[p," days"]},p))})]}),e.jsx($l,{})]})}function $l(){const[s,t]=n.useState(null),[a,l]=n.useState(!1);return n.useEffect(()=>{Aa().then(t).catch(()=>{})},[]),!(s!=null&&s.tracked.length)||!s.untrackCommand?null:e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-red-500/10 border border-red-500/20","data-testid":"auth-files-warning",children:[e.jsx(ue,{size:16,className:"text-red-500 dark:text-red-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-2 text-sm min-w-0",children:[e.jsx("p",{className:"font-medium text-red-600 dark:text-red-300",children:"Sign-in files are committed to git"}),e.jsxs("p",{className:"text-gray-400",children:[s.tracked.map(m=>e.jsx("code",{className:"mr-1.5 px-1 rounded bg-surface-2 text-gray-300",children:m},m)),s.tracked.length===1?"is":"are"," in this project's repository. Anyone who can read it gets the accounts' password hashes",s.tracked.some(m=>m.endsWith("auth-secret.key"))?" and the key that signs sign-in tokens":"",". Stop tracking them (they stay on disk), then commit:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 min-w-0 truncate px-2 py-1 rounded bg-surface-2 border border-white/10 font-mono text-[13px] text-gray-200",children:s.untrackCommand}),e.jsx("button",{type:"button",title:"Copy",onClick:async()=>{try{await navigator.clipboard.writeText(s.untrackCommand),l(!0),setTimeout(()=>l(!1),2e3)}catch{}},className:"p-1.5 rounded-md text-gray-400 hover:text-gray-200 hover:bg-white/5",children:a?e.jsx(Ue,{size:14,className:"text-emerald-400"}):e.jsx(xs,{size:14})})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["If the repository was ever shared or pushed, also delete ",e.jsx("code",{children:".testver/auth-secret.key"})," and restart Testver — everyone signs in again with a new key."]})]})]})}function Rl(s,t){return s.mode!==void 0?t.mode==="off"?"Auto-Heal turned off":`Auto-Heal set to ${t.mode==="suggest"?"Suggest":"Auto"}`:s.maxAttempts!==void 0?`Auto-Heal gives up after ${t.maxAttempts} attempt${t.maxAttempts===1?"":"s"} per test`:s.cooldownHours!==void 0?`Auto-Heal waits ${t.cooldownHours} hours before retrying a test`:s.reviewWindowDays!==void 0?`Apply / Undo offered for ${t.reviewWindowDays} day${t.reviewWindowDays===1?"":"s"}`:s.ciGate!==void 0?`CI-gated runs: ${t.ciGate==="update-build"?"update the build":"report only"}`:s.allowBrowserProbe!==void 0?`Live browser probe ${t.allowBrowserProbe?"enabled":"disabled"}`:s.remoteHubUrl!==void 0?t.remoteHubUrl?"Remote hub relay saved":"Remote hub relay cleared":"Auto-Heal settings saved"}const Os=[6,12,24,48,72,168];function Ml({framework:s}){var S,I;const[t,a]=n.useState(null),[l,m]=n.useState(null),[i,h]=n.useState(null),[d,f]=n.useState(""),{toast:g}=ge(),y=Je(),c=n.useCallback(()=>{m(null),lt().then(w=>{a(w),f(String(w.reviewWindowDays))}).catch(w=>m(w instanceof Error?w.message:String(w)))},[]);n.useEffect(()=>{c()},[c]);const j=w=>{a(v=>v&&{...v,...w}),Ca(w).then(v=>{a(v),f(String(v.reviewWindowDays)),w.remoteHubUrl!==void 0&&h(null),y.invalidateQueries({queryKey:["auto-heal-config"]}),g("success",Rl(w,v))}).catch(v=>{const x=v instanceof Error?v.message:String(v);w.remoteHubUrl!==void 0&&h(x),g("error",`Could not save: ${x}`),lt().then(o=>{a(o),f(String(o.reviewWindowDays))}).catch(()=>{})})},p=()=>{const w=Math.round(Number(d));if(!Number.isFinite(w)||w<1||w>30){f(String((t==null?void 0:t.reviewWindowDays)??7)),g("error","The review window must be between 1 and 30 days");return}w!==(t==null?void 0:t.reviewWindowDays)&&j({reviewWindowDays:w})};if(!t)return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Te,{size:18,className:"text-purple-400"}),"Auto-Heal"]}),l?e.jsxs("div",{className:"mt-3 flex items-center gap-3 text-sm text-red-600 dark:text-red-400",role:"alert",children:[e.jsx(ue,{size:14,className:"flex-shrink-0"}),e.jsxs("span",{children:["Could not load the Auto-Heal settings: ",l]}),e.jsx("button",{type:"button",onClick:c,className:"px-2.5 py-1 rounded-lg border border-white/10 text-xs text-gray-300 hover:bg-white/5",children:"Retry"})]}):e.jsxs("p",{className:"mt-3 text-sm text-gray-500 flex items-center gap-2",children:[e.jsx(J,{size:14,className:"animate-spin"})," Loading…"]})]});const u=t.mode,b=t.maxAttempts,z=t.cooldownHours,M=(s||"").toLowerCase(),V=M.includes("playwright"),U=M.includes("cypress"),O=({options:w,value:v,onSelect:x,label:o})=>e.jsx("div",{role:"group","aria-label":o,className:"inline-flex rounded-lg border border-white/10 bg-white dark:bg-surface-2 overflow-hidden flex-shrink-0",children:w.map((r,E)=>e.jsx("button",{type:"button",onClick:()=>x(r.id),className:`px-3.5 py-1.5 text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${E>0?"border-l border-white/10":""} ${v===r.id?"bg-purple-500/15 text-purple-600 dark:text-purple-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,"aria-pressed":v===r.id,children:r.label},r.id))});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(Te,{size:18,className:"text-purple-400"}),"Auto-Heal"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5 max-w-2xl",children:'When a test fails because a locator no longer matches the page, Testver finds the element it meant, changes only that locator, re-runs the affected tests with the same browser and environment, and keeps the change only if every one of them passes. Assertion failures, overlays and environment problems are never "fixed" by editing a locator.'})]}),!V&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-white/10 bg-surface-2/40 px-3.5 py-2.5 text-sm text-gray-400",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsxs("span",{children:["This project is detected as ",e.jsx("b",{children:s||"non-Playwright"}),"."," ",U?e.jsxs(e.Fragment,{children:["Cypress keeps no page evidence of its own, so healing here needs the ",e.jsx("b",{children:"live browser probe"})," below, or a recorded fallback from the Testver recorder."]}):e.jsxs(e.Fragment,{children:["Healing reads the page (or app screen) through the test's ",e.jsx("b",{children:"own live session"})," while it runs — Selenium, WebdriverIO, Robot Framework and Appium, locally or on a cloud grid. Nothing to set up; the live browser probe is an optional last resort."]})]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Mode"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[e.jsx("b",{children:"Suggest"})," prepares and verifies the fix, puts your code back, and waits for you to apply it — the recommended starting point. ",e.jsx("b",{children:"Auto"})," keeps a verified fix for you. A fix that fails verification is reverted either way. Suites and CI pipelines can override this."]})]}),e.jsx(O,{label:"Auto-Heal mode",options:[{id:"off",label:"Off"},{id:"suggest",label:"Suggest"},{id:"auto",label:"Auto"}],value:u,onSelect:w=>j({mode:w})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-gray-200",children:["Give up after ",b," attempt",b===1?"":"s"," per test"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"An attempt is counted only when it costs something (an AI call, a re-run, a probe, or a verification). After the limit, Auto-Heal waits before trying that test again, so a genuinely broken test cannot loop."})]}),e.jsx(O,{label:"Attempts per test",options:[1,2,3,4,5].map(w=>({id:String(w),label:String(w)})),value:String(b),onSelect:w=>j({maxAttempts:Number(w)})})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"auto-heal-cooldown",className:"text-sm font-medium text-gray-200",children:"Then wait before retrying"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"How long a test rests after hitting the attempt limit."})]}),e.jsxs("select",{id:"auto-heal-cooldown",value:Os.includes(z)?z:"",onChange:w=>j({cooldownHours:Number(w.target.value)}),className:"bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-sm text-gray-200 focus:outline-none focus:border-purple-500/50 disabled:opacity-50",children:[!Os.includes(z)&&e.jsxs("option",{value:"",children:[z," hours"]}),Os.map(w=>e.jsx("option",{value:w,children:w===168?"1 week":w>=24?`${w/24} day${w===24?"":"s"}`:`${w} hours`},w))]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"auto-heal-review-window",className:"text-sm font-medium text-gray-200",children:["Offer Apply fix / Undo fix for ",t.reviewWindowDays," day",t.reviewWindowDays===1?"":"s"]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:["Past the window a fix shows as ",e.jsx("b",{children:"Expired"})," and its buttons retire — tests drift, and a stale action only confuses. Nothing is lost: a fresh fix is suggested from current page evidence the next time the test fails. Fixes whose code changed earlier are marked",e.jsx("b",{children:" Stale"})," immediately, regardless of the window."]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("input",{id:"auto-heal-review-window",type:"number",min:1,max:30,value:d,onChange:w=>f(w.target.value),onBlur:p,onKeyDown:w=>{w.key==="Enter"&&w.target.blur()},className:"w-20 bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-sm text-gray-200 focus:outline-none focus:border-brand-500/40 disabled:opacity-50"}),e.jsx("span",{className:"text-sm text-gray-500",children:"days (1–30)"})]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"When a heal succeeds on a CI-gated run"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[e.jsx("b",{children:"Report only"})," keeps the original build result — the repair lands for the next build.",e.jsx("b",{children:" Update the build"})," holds the gate until healing finishes, so a fully-healed run turns the commit status green (always labeled as auto-healed, never silently). Pipelines can override this per mapping."]})]}),e.jsx(O,{label:"CI gate behavior",options:[{id:"report-only",label:"Report only"},{id:"update-build",label:"Update the build"}],value:t.ciGate,onSelect:w=>j({ciGate:w})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{id:"auto-heal-probe-label",className:"text-sm font-medium text-gray-200",children:"Open a browser as a last resort"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:"When a failed run left no usable page evidence, open the page in a fresh headless browser and heal from what it finds. Needs the app reachable from this server — it cannot log in, so leave it off for pages behind a login. Only http(s) pages are opened."})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":t.allowBrowserProbe,"aria-labelledby":"auto-heal-probe-label",onClick:()=>j({allowBrowserProbe:!t.allowBrowserProbe}),className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors mt-1 disabled:opacity-50 ${t.allowBrowserProbe?"bg-purple-500":"bg-surface-3"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${t.allowBrowserProbe?"translate-x-4":"translate-x-1"}`})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"auto-heal-hub",className:"text-sm font-medium text-gray-200",children:["Remote hub relay ",e.jsx("span",{className:"text-gray-500 font-normal",children:"(Selenium Grid · BrowserStack · LambdaTest)"})]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-1 max-w-xl",children:[e.jsx("b",{children:"Usually leave this empty"})," — Testver-launched cloud runs are captured automatically, and when a Cloud Testing Provider connector is configured the relay targets it with no setup. Fill this only for your own Selenium Grid, or if tests hard-code a hub URL — then point that URL at ",e.jsx("span",{className:"font-mono text-gray-400 text-xs",children:"http://localhost:4499"})," (a port this server opens for WebDriver clients on this machine only). WebSocket-based CDP/BiDi features are not relayed."]}),((S=t.relayStatus)==null?void 0:S.running)&&t.relayStatus.upstream&&e.jsxs("p",{className:"text-xs mt-1.5 text-emerald-600 dark:text-emerald-400",children:["Relay active on port ",t.relayStatus.port," → ",t.relayStatus.upstream,t.relayStatus.source&&t.relayStatus.source!=="manual"?` (from your ${t.relayStatus.source} connector)`:""]}),((I=t.relayStatus)==null?void 0:I.running)&&!t.relayStatus.upstream&&e.jsxs("p",{className:"text-xs mt-1.5 text-gray-500",children:["Relay listening on port ",t.relayStatus.port," — no target yet (enter a hub URL or enable a cloud connector)."]}),t.relayStatus&&!t.relayStatus.running&&(t.remoteHubUrl||t.relayStatus.upstream)&&e.jsxs("p",{className:"text-xs mt-1.5 text-amber-600 dark:text-amber-400",children:["The relay is not running — port ",t.relayStatus.port," may be in use by another program (see the server log)."]}),t.remoteHubHasKey&&e.jsx("p",{className:"text-xs mt-1.5 text-gray-500",children:"An access key is saved — it is shown as •••••• and never sent back to the browser. Keep the dots to keep the key."}),i&&e.jsx("p",{className:"text-xs mt-1.5 text-red-600 dark:text-red-400",role:"alert",children:i})]}),e.jsx("input",{id:"auto-heal-hub",type:"text",defaultValue:t.remoteHubUrl??"",placeholder:"https://user:key@hub…/wd/hub",autoComplete:"off",spellCheck:!1,onBlur:w=>{const v=w.target.value.trim();v!==(t.remoteHubUrl??"")&&j({remoteHubUrl:v})},className:"w-72 flex-shrink-0 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-purple-500/50 font-mono disabled:opacity-50"},t.remoteHubUrl??"")]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"space-y-2 text-sm text-gray-500",children:[e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsx("span",{children:"Every fix is verified by re-running the affected tests — an unverified edit never survives, even across a server restart."})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsx("span",{children:"Only the locator value changes — assertions, logic and data are never edited — and your own edits made meanwhile are never overwritten."})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsxs("span",{children:["Undo is offered for ",t.reviewWindowDays," day",t.reviewWindowDays===1?"":"s",", and a fix you undo is never proposed again."]})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx(ne,{size:14,className:"mt-0.5 flex-shrink-0 text-emerald-500"}),e.jsx("span",{children:"Only the failing tests re-run during verification — never the whole suite."})]})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("a",{href:"/results?view=auto-heal",className:"inline-flex items-center gap-1.5 text-sm font-medium text-purple-600 dark:text-purple-300 hover:text-purple-500 dark:hover:text-purple-200 transition-colors",children:[e.jsx(Te,{size:14}),"View activity & review fixes → Results › Auto-Heal"]})]})}function Dl(){const{data:s,isLoading:t}=ya(),{data:a}=fn(),{data:l}=yn(),m=jn(),i=vn(),h=Nn(),d=Je(),f=l==null?void 0:l.scan,g=!!(f!=null&&f.running),y=!!(a!=null&&a.preciseEnabled),c=!!(a!=null&&a.hideNames),j=(l==null?void 0:l.computed)??0;if(n.useEffect(()=>{if(!g)return;const b=setInterval(()=>d.invalidateQueries({queryKey:["ownership-status"]}),1500);return()=>clearInterval(b)},[g,d]),t||!(s!=null&&s.available))return null;const p=f&&f.total>0?Math.round(f.processed/f.total*100):0,u=({on:b,onClick:z,disabled:M})=>e.jsx("button",{type:"button",onClick:z,disabled:M,className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${b?"bg-brand-500":"bg-surface-3"}`,"aria-pressed":b,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${b?"translate-x-4":"translate-x-1"}`})});return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(cn,{size:18}),"Test Ownership"]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Hide author names"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:"Hide git owner / last-modified-by names across Test Explorer and Results."})]}),e.jsx(u,{on:c,onClick:()=>m.mutate({hideNames:!c})})]}),e.jsx("div",{className:"border-t border-white/5"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-200",children:"Precise (line-level) ownership"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5 max-w-md",children:"Compute each test's owner from its own lines for the whole project, so the Owner filter is instant at scale. Runs a one-time background scan (then updates incrementally). Leave off for smaller projects — ownership still loads lazily."})]}),e.jsx(u,{on:y,onClick:()=>m.mutate({preciseEnabled:!y})})]}),y&&e.jsx("div",{className:"rounded-lg border border-white/5 bg-surface-2/40 p-4 space-y-3",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-400",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:12,className:"animate-spin"}),"Scanning ownership… ",f.processed,"/",f.total," files"]}),e.jsx("button",{onClick:()=>h.mutate(),className:"text-gray-500 hover:text-red-400",children:"Cancel"})]}),e.jsx("div",{className:"h-2 rounded-full bg-surface-3 overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-500 transition-all",style:{width:`${p}%`}})}),f.currentFile&&e.jsx("p",{className:"text-[10px] text-gray-600 font-mono truncate",children:f.currentFile})]}):e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:j>0?`${j} tests have computed ownership.`:"No ownership computed yet."}),e.jsxs("button",{onClick:()=>i.mutate(),disabled:i.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg bg-brand-600 text-white hover:bg-brand-500 transition-colors disabled:opacity-60",children:[i.isPending?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(fs,{size:12}),j>0?"Re-scan":"Run scan"]})]})})]})}function Fl({project:s,theme:t,setTheme:a,readOnly:l=!1}){var Qe,Xe;const{toast:m}=ge(),{mode:i}=ks(),h=i==="mobile",[d,f]=n.useState(!0),[g,y]=n.useState(!1),[c,j]=n.useState(null),[p,u]=n.useState(""),[b,z]=n.useState(""),[M,V]=n.useState(""),[U,O]=n.useState(""),[S,I]=n.useState([]),[w,v]=n.useState(""),[x,o]=n.useState(""),[r,E]=n.useState({options:[]}),[P,B]=n.useState({options:[]}),[N,ee]=n.useState({browsers:{},environments:{}}),K=()=>{ha().then(L=>ee({browsers:Object.fromEntries(L.browsers.filter(D=>D.check).map(D=>[D.name,{value:D.arg,check:D.check}])),environments:Object.fromEntries(L.environments.filter(D=>D.check).map(D=>[D.name,{value:D.value,check:D.check}]))})).catch(()=>{})},[W,R]=n.useState(null),[G,_]=n.useState(!1),[A,te]=n.useState(l),[X,le]=n.useState(null),[$,re]=n.useState(null),ae=sr(),[ce,he]=n.useState(!1),[xe,ye]=n.useState(null),[Ne,ke]=n.useState(null),[F,Y]=n.useState({singleTest:"pending",suiteOrFile:"pending",fullRun:"pending"}),se=L=>{Y({singleTest:"pending",suiteOrFile:"pending",fullRun:"pending"}),["singleTest","suiteOrFile","fullRun"].forEach(D=>{const Q=L[D];if(!Q){Y(Z=>({...Z,[D]:"invalid"}));return}at(vt(Q)).then(Z=>Y(pe=>({...pe,[D]:Z.valid?"valid":"invalid"}))).catch(()=>Y(Z=>({...Z,[D]:"invalid"})))})},ie=async()=>{he(!0),ke(null),ye(null);try{const L=await fa();ye(L),se(L.suggestions)}catch(L){ke(String(L))}finally{he(!1)}},be=L=>{if(!xe)return;const D=xe.suggestions[L];D&&(L==="singleTest"?u(D):L==="suiteOrFile"?z(D):V(D),m("success",`Applied ${L} — review and Save to persist`))},oe=()=>{if(!xe)return;const L=xe.suggestions;L.singleTest&&u(L.singleTest),L.suiteOrFile&&z(L.suiteOrFile),L.fullRun&&V(L.fullRun),m("success","Applied all — review and Save to persist")},k=()=>{const L=["Help me set up the correct test run commands for my project in Testver.","","Please scan my project yourself — detect the test framework, read the relevant config file(s), any defined run scripts, and a sample test file — then propose three commands:"," 1. Single test — run ONE test by name"," 2. Suite / File — run all tests in one file"," 3. Full run — run the entire suite","","Use Testver placeholder tokens for runtime values: {test} (test name), {file} (relative path), {posixFile} (forward-slash path, for WebdriverIO --spec on Windows), {suite}, {line}, {args}.","Prefer an existing project run script when one maps to running tests. Explain each command briefly."].join(`
|
|
81
|
+
`);Ls(ae,{prompt:L,mode:"web"})},C=L=>L.length?["","Testver's own check of the code found:",...L.map(D=>` • ${D}`)]:[],q=(L,D=[])=>{const Z=[`Help me configure test-run ${L?"environments (e.g. staging, production, QA)":"browsers (e.g. Chrome, Firefox, Edge, Safari)"} for my project in Testver.`,...C(D),"","Please scan my project yourself — detect the test framework and read the relevant config file(s) — then tell me, for each target I might want:",L?" • the exact CLI argument OR environment variable to select that environment (one or the other, not both), e.g. `--base-url=...`, `-Denv=staging`, or `BASE_URL=https://staging.example.com`.":" • the exact CLI argument that selects that browser, e.g. `--project=chromium`, `--browser chrome`, `-Dbrowser=firefox`.","",'Use the configure_run_targets tool: first run it with action "detect" and show me what my project supports and whether my saved entries are correct, then save the right ones once I confirm.'].join(`
|
|
82
|
+
`);Ls(ae,{prompt:Z,mode:"web"})},T=(L,D=[])=>{const Q=(L?["Update my test framework so a run can choose the ENVIRONMENT (the application URL), and register the environments in Testver.",...C(D),"","1. Read the framework first (config files, fixtures, base classes). Tell me in a few lines what you will change, and wait for my OK before editing.","2. Make the base URL selectable with ONE switch: JS/TS, Python and .NET read BASE_URL from the environment (dotenv must never override a value that is already set); Java reads -DbaseUrl through the config (System.getProperty over config.properties). Only if environments differ in more than the URL, add per-environment files chosen by one variable.","3. Keep today's URL as the default, so a run without the switch behaves exactly as it does now.","4. Ask me which other environments exist (name + URL, e.g. Staging) — if I don't know, register just the current one.","5. Run one existing test to prove nothing broke.",'6. Register the environments with configure_run_targets (action "save"), then tell me the names I can pick in Test Explorer, Suites and Cycles.']:["Update my test framework so a run can choose the BROWSER, and register the browsers in Testver.",...C(D),"","1. Read the framework first (config, browser/driver factory, fixtures). Tell me in a few lines what you will change, and wait for my OK before editing.","2. Add ONE command-line switch that selects the browser, the usual way for this framework: Playwright — a project per browser (chromium, firefox, webkit) chosen with --project; Java — a -Dbrowser switch in the browser/driver factory; pytest — a --browser option (built in with pytest-playwright); Cypress — --browser is built in; WebdriverIO — parse --browser= in wdio.conf. Keep any existing BROWSER environment variable as the default. Use the framework's documented options only — don't read its own source code in node_modules or site-packages.","3. With no switch given, the tests must run exactly as they do today (same default browser). Playwright is the exception: without --project it runs EVERY project — that is how Playwright works, so don't try to change it. Add the new projects next to today's one, leave today's project exactly as it is, and tell me that a plain `npx playwright test` now runs every browser.","4. Run one existing test with the default, and once with another browser, to prove it works.",`5. Register the browsers with configure_run_targets (action "save"), with today's browser as default_browser so runs started from Testver keep using it unless another is picked. Then tell me the names I can pick in Test Explorer, Suites and Cycles.`]).join(`
|
|
83
|
+
`);Ls(ae,{prompt:Q,mode:"web"})};n.useEffect(()=>{xa().then(L=>{var Z,pe,Re,De,Zs,et;j(L);const D=L.configured||{},Q=L.autoDetected||{};u(D.singleTest||Q.singleTest||""),z(D.suiteOrFile||Q.suiteOrFile||""),V(D.fullRun||Q.fullRun||""),O(D.workingDirectory||""),v(D.beforeCommand||""),o(D.afterCommand||""),D.envVars&&I(Object.entries(D.envVars).map(([Qt,Xt])=>({key:Qt,value:Xt}))),E({argPattern:((Z=D.browsers)==null?void 0:Z.argPattern)||Q.browserArgPattern||"",options:((pe=D.browsers)==null?void 0:pe.options)||[],default:(Re=D.browsers)==null?void 0:Re.default}),B({argPattern:((De=D.environments)==null?void 0:De.argPattern)||Q.envArgPattern||"",options:((Zs=D.environments)==null?void 0:Zs.options)||[],default:(et=D.environments)==null?void 0:et.default}),R(D.suggested??null),_(!1),K()}).catch(L=>{console.error("[Settings] Failed to load run commands config:",L),m("error","Failed to load run commands config")}).finally(()=>f(!1))},[m]);const H=async()=>{var L,D;y(!0);try{const Q={};p.trim()&&p.trim()!==(c==null?void 0:c.autoDetected.singleTest)&&(Q.singleTest=p.trim()),b.trim()&&b.trim()!==(c==null?void 0:c.autoDetected.suiteOrFile)&&(Q.suiteOrFile=b.trim()),M.trim()&&M.trim()!==(c==null?void 0:c.autoDetected.fullRun)&&(Q.fullRun=M.trim()),U.trim()&&(Q.workingDirectory=U.trim()),w.trim()&&(Q.beforeCommand=w.trim()),x.trim()&&(Q.afterCommand=x.trim());const Z=S.filter(pe=>pe.key.trim()&&pe.value.trim());Z.length>0&&(Q.envVars=Object.fromEntries(Z.map(pe=>[pe.key.trim(),pe.value.trim()]))),r.options&&r.options.length>0&&(Q.browsers={argPattern:((L=r.argPattern)==null?void 0:L.trim())||void 0,options:r.options,default:r.default||void 0}),P.options&&P.options.length>0&&(Q.environments={argPattern:((D=P.argPattern)==null?void 0:D.trim())||void 0,options:P.options,default:P.default||void 0}),G&&(Q.suggested=null),await ba(Q),_(!1),K(),m("success","Run configuration saved")}catch(Q){m("error",`Failed to save: ${Q}`)}finally{y(!1)}},de=async(L,D)=>{le(D),re(null);try{const Q=await at(vt(L));re({cmd:D,valid:Q.valid,output:Q.output})}catch{re({cmd:D,valid:!1,output:"Request failed"})}finally{le(null)}},Be=(c==null?void 0:c.framework)||s.framework||"unknown";return e.jsxs("fieldset",{disabled:l,className:"space-y-6 min-w-0 border-0 p-0 m-0",children:[l&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04] px-4 py-3 text-sm text-cyan-200",children:[e.jsx(ve,{size:15,className:"text-cyan-400 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"View only — these project settings are managed by your admin. You can see the configuration here but not change or save it."})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-4",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(ds,{size:18}),"Project Information"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-y-3.5 gap-x-6 text-[15px]",children:[e.jsx("span",{className:"text-gray-400 self-center",children:"Project Name"}),e.jsx(vl,{readOnly:l,fallback:ma(s.rootPath)}),e.jsx("span",{className:"text-gray-400",children:"Framework"}),e.jsx("span",{className:"text-gray-200",children:s.framework||"Auto-detected"}),e.jsx("span",{className:"text-gray-400",children:"Language"}),e.jsx("span",{className:"text-gray-200",children:s.language||"Multiple"}),e.jsx("span",{className:"text-gray-400",children:"Path"}),e.jsx("span",{className:"text-gray-200 font-mono text-sm truncate",title:s.rootPath,children:s.rootPath}),e.jsx("span",{className:"text-gray-400",children:"Modules"}),e.jsx("span",{className:"text-gray-200",children:s.stats.totalModules}),e.jsx("span",{className:"text-gray-400",children:"Total Files"}),e.jsx("span",{className:"text-gray-200",children:s.stats.totalFiles})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-200 flex items-center gap-2.5",children:[e.jsx(ln,{size:18}),"Run Configuration"]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-xs px-2.5 py-1 rounded-lg bg-brand-500/10 text-brand-400 border border-brand-500/20 font-medium",children:Be}),e.jsxs("button",{onClick:H,disabled:g||d,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 transition-colors disabled:opacity-50",children:[g?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(ze,{size:14}),"Save Run Configuration"]})]})]}),e.jsxs("div",{className:"border border-white/5 rounded-xl p-4 bg-surface-1/40 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("h3",{className:"flex items-center gap-2 text-sm font-medium text-gray-200 flex-1",children:[e.jsx(Ts,{size:15,className:"text-brand-400"}),"Run Commands"]}),e.jsxs("button",{onClick:ie,disabled:ce,title:"Let AI inspect your project and propose run commands",className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-lg text-brand-600 bg-white border border-gray-200 shadow-sm hover:bg-gray-50 disabled:opacity-50",children:[ce?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Te,{size:12}),ce?"Analyzing project…":"Suggest with AI"]})]}),Ne&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-red-400 bg-red-500/5 border border-red-500/20 rounded-lg p-3",children:[e.jsx(Se,{size:14,className:"shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Couldn't get suggestions"}),e.jsx("div",{className:"text-red-400/80 mt-0.5",children:Ne}),e.jsx("button",{onClick:k,className:"mt-1.5 text-brand-400 hover:text-brand-300 underline underline-offset-2",children:"Try in the AI Assistant instead →"})]})]}),xe&&e.jsxs("div",{className:"rounded-2xl border border-brand-500/20 bg-gradient-to-br from-brand-500/[0.06] via-purple-500/[0.03] to-transparent overflow-hidden shadow-lg shadow-brand-500/5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-white/5 bg-white/[0.015]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-gradient-to-br from-purple-600 to-brand-600 shadow-md shadow-brand-500/20 shrink-0",children:e.jsx(Te,{size:16,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-100",children:"AI Suggestions"}),xe.suggestions.usedNpmScript&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 font-medium",children:"package.json script"})]}),e.jsx("p",{className:"text-[11px] text-gray-400 truncate",children:"Derived from your project — review before applying"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsxs("button",{onClick:oe,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-emerald-600/90 hover:bg-emerald-500 shadow-sm shadow-emerald-500/20 transition-colors",children:[e.jsx(ze,{size:13})," Apply all"]}),e.jsx("button",{onClick:()=>ye(null),className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-200 hover:bg-white/5 transition-colors",title:"Dismiss suggestions",children:e.jsx(me,{size:15})})]})]}),e.jsxs("div",{className:"p-4 space-y-2.5",children:[[{key:"singleTest",label:"Single Test"},{key:"suiteOrFile",label:"Suite / File"},{key:"fullRun",label:"Full Run"}].map(({key:L,label:D})=>{const Q=xe.suggestions[L];if(!Q)return null;const Z=xe.suggestions.confidence[L],pe=xe.suggestions.rationale[L],Re=F[L],De=Z==null?{text:"text-gray-400",dot:"bg-gray-500"}:Z>=.8?{text:"text-emerald-400",dot:"bg-emerald-400"}:Z>=.5?{text:"text-amber-400",dot:"bg-amber-400"}:{text:"text-red-400",dot:"bg-red-400"};return e.jsxs("div",{className:"group rounded-xl border border-white/[0.07] bg-surface-2/40 hover:bg-surface-2/60 hover:border-white/10 transition-colors p-3.5 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-[13px] font-semibold text-gray-200",children:D}),Re==="pending"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-gray-400",children:[e.jsx(J,{size:10,className:"animate-spin"})," checking"]}),Re==="valid"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:[e.jsx(ze,{size:10})," resolves"]}),Re==="invalid"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/10 text-amber-400 border border-amber-500/20",children:[e.jsx(ue,{size:10})," unverified"]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[Z!=null&&e.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] font-medium ${De.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${De.dot}`}),Math.round(Z*100),"%"]}),e.jsx("button",{onClick:()=>be(L),className:"px-2.5 py-1 rounded-lg text-[11px] font-medium text-brand-200 bg-brand-500/10 border border-brand-500/25 hover:bg-brand-500/20 hover:text-brand-100 transition-colors",children:"Apply"})]})]}),e.jsx("code",{className:"block text-xs text-cyan-300 font-mono bg-black/30 border border-white/5 rounded-lg px-3 py-2 break-all leading-relaxed",children:Q}),pe&&e.jsx("p",{className:"text-[11.5px] text-gray-300 leading-relaxed",children:pe})]},L)}),xe.suggestions.notes&&e.jsxs("div",{className:"flex items-start gap-2 text-[11.5px] text-gray-300 bg-white/[0.02] border border-white/5 rounded-lg px-3 py-2",children:[e.jsx(Te,{size:12,className:"text-purple-400 shrink-0 mt-0.5"}),e.jsx("span",{className:"leading-relaxed",children:xe.suggestions.notes})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5 border-t border-white/5 bg-white/[0.015]",children:[e.jsxs("span",{className:"text-[11px] text-gray-400 inline-flex items-center gap-1.5",children:[e.jsx(xt,{size:12,className:"text-gray-400"}),"Not saved until you click ",e.jsx("span",{className:"text-gray-200 font-medium",children:"Save Run Configuration"})]}),e.jsxs("button",{onClick:k,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-gray-200 bg-surface-2 border border-white/15 hover:bg-purple-500/10 hover:text-purple-600 dark:hover:text-purple-300 hover:border-purple-500/40 transition-colors",children:[e.jsx(Ft,{size:14,className:"text-purple-500 dark:text-purple-400"}),"Discuss in AI Assistant",e.jsx(Ie,{size:13,className:"opacity-70"})]})]})]}),e.jsx("p",{className:"text-[12px] text-gray-500",children:"Auto-detected commands are pre-filled below. Edit them to customize, or click Reset to restore defaults."}),e.jsxs("div",{className:"text-xs text-gray-500 space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{test}"})," test name"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{suite}"})," suite name"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{line}"})," start line"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{args}"})," extra args"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{file}"})," relative path"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{absFile}"})," absolute path"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{posixFile}"})," forward-slash path"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{fileName}"})," file name"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{token:"{fileNoExt}"})," name without ext"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5",children:[e.jsx(Ce,{token:"{project}"}),e.jsx(Ce,{token:"{cwd}"}),e.jsx(Ce,{token:"{root}"}),e.jsx("span",{children:"project root"})]})]}),d?e.jsxs("div",{className:"flex items-center gap-2 py-4",children:[e.jsx(J,{size:16,className:"animate-spin text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Loading configuration..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(Us,{label:"Single Test",description:"Run a single test/scenario by name",value:p,onChange:u,placeholder:(c==null?void 0:c.autoDetected.singleTest)||"",isCustom:!!p.trim()&&p.trim()!==(c==null?void 0:c.autoDetected.singleTest),onReset:()=>u((c==null?void 0:c.autoDetected.singleTest)||""),onTest:()=>de(p||(c==null?void 0:c.autoDetected.singleTest)||"","single"),testing:X==="single",testResult:($==null?void 0:$.cmd)==="single"?$:null}),e.jsx(Us,{label:"Suite / File",description:"Run all tests in a file or suite",value:b,onChange:z,placeholder:(c==null?void 0:c.autoDetected.suiteOrFile)||"",isCustom:!!b.trim()&&b.trim()!==(c==null?void 0:c.autoDetected.suiteOrFile),onReset:()=>z((c==null?void 0:c.autoDetected.suiteOrFile)||""),onTest:()=>de(b||(c==null?void 0:c.autoDetected.suiteOrFile)||"","suite"),testing:X==="suite",testResult:($==null?void 0:$.cmd)==="suite"?$:null}),e.jsx(Us,{label:"Full Run",description:"Run the entire test suite",value:M,onChange:V,placeholder:(c==null?void 0:c.autoDetected.fullRun)||"",isCustom:!!M.trim()&&M.trim()!==(c==null?void 0:c.autoDetected.fullRun),onReset:()=>V((c==null?void 0:c.autoDetected.fullRun)||""),onTest:()=>de(M||(c==null?void 0:c.autoDetected.fullRun)||"","full"),testing:X==="full",testResult:($==null?void 0:$.cmd)==="full"?$:null})]})]}),!d&&e.jsxs("div",{className:"space-y-4",children:[W&&(((Qe=W.browsers)==null?void 0:Qe.length)??0)+(((Xe=W.environments)==null?void 0:Xe.length)??0)>0&&e.jsxs("div",{className:"rounded-xl border border-amber-500/25 bg-amber-500/[0.06] p-3.5 space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2 text-amber-300",children:[e.jsx(Te,{size:14,className:"shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium",children:"Suggested changes to existing entries"}),e.jsxs("div",{className:"text-amber-300/70 mt-0.5",children:["They came from someone who can add entries but not change them, in a chat with the AI Assistant or from an agent with an access token",W.at?` (${new Date(W.at).toLocaleString()})`:"",". ",l?"An admin can apply them here.":"Apply them, then Save — or dismiss them."]})]})]}),e.jsxs("div",{className:"space-y-1 pl-6",children:[(W.browsers??[]).map(L=>e.jsxs("div",{className:"font-mono text-gray-300",children:[e.jsx("span",{className:"text-gray-500 font-sans",children:"Browser"})," ",L.name," → ",L.arg,(r.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase())?e.jsxs("span",{className:"text-gray-500",children:[" (now ",(r.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase()).arg,")"]}):null]},`b-${L.name}`)),(W.environments??[]).map(L=>e.jsxs("div",{className:"font-mono text-gray-300",children:[e.jsx("span",{className:"text-gray-500 font-sans",children:"Environment"})," ",L.name," → ",L.value,(P.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase())?e.jsxs("span",{className:"text-gray-500",children:[" (now ",(P.options??[]).find(D=>D.name.toLowerCase()===L.name.toLowerCase()).value,")"]}):null]},`e-${L.name}`))]}),!l&&e.jsxs("div",{className:"flex items-center gap-2 pl-6",children:[e.jsx("button",{onClick:()=>{var D,Q;const L=(Z=[],pe=[])=>[...Z.filter(Re=>!pe.some(De=>De.name.toLowerCase()===Re.name.toLowerCase())),...pe];(D=W.browsers)!=null&&D.length&&E(Z=>({...Z,options:L(Z.options,W.browsers)})),(Q=W.environments)!=null&&Q.length&&B(Z=>({...Z,options:L(Z.options,W.environments)})),R(null),_(!0),m("success","Applied — click Save to keep them")},className:"px-2.5 py-1 rounded-lg text-[11px] font-medium text-white bg-emerald-600/90 hover:bg-emerald-500",children:"Apply"}),e.jsx("button",{onClick:()=>{R(null),_(!0),m("info","Dismissed — click Save to confirm")},className:"px-2.5 py-1 rounded-lg text-[11px] text-gray-300 border border-white/10 hover:bg-white/5",children:"Dismiss"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[!h&&e.jsx(wt,{title:"Browsers",icon:e.jsx(cs,{size:15,className:"text-brand-400"}),isEnv:!1,autoPattern:c==null?void 0:c.autoDetected.browserArgPattern,presetNames:Il,cfg:r,onChange:L=>E(L),checks:N.browsers,onSuggest:async()=>{const L=await tt("browsers");return{entries:L.browsers.map(D=>({name:D.name,arg:D.arg,...D.kind==="env"?{kind:"env"}:{},check:D.check,source:D.source})),notes:L.browserNotes??[]}},onDiscussInAI:L=>q(!1,L),onImproveInAI:L=>T(!1,L)}),!h&&e.jsx(wt,{title:"Environments",icon:e.jsx(As,{size:15,className:"text-brand-400"}),isEnv:!0,autoPattern:c==null?void 0:c.autoDetected.envArgPattern,presetNames:Ol,cfg:P,onChange:L=>B(L),checks:N.environments,onSuggest:async()=>{const L=await tt("environments");return{entries:L.environments.map(D=>({name:D.name,kind:D.kind,value:D.value,check:D.check,source:D.source})),notes:L.environmentNotes??[]}},onDiscussInAI:L=>q(!0,L),onImproveInAI:L=>T(!0,L)}),(h||i==="both")&&e.jsx("div",{className:"lg:col-span-2",children:e.jsx(jl,{readOnly:l})})]}),e.jsxs("div",{className:"border-t border-white/5 pt-4",children:[e.jsxs("button",{onClick:()=>te(!A),className:"flex items-center gap-2 text-sm text-gray-400 hover:text-gray-200 transition-colors",children:[A?e.jsx(Me,{size:14}):e.jsx(Ie,{size:14}),e.jsx(as,{size:14}),"Advanced Settings"]}),A&&e.jsxs("div",{className:"mt-4 space-y-4 pl-1",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm text-gray-400 flex items-center gap-1.5 mb-1.5",children:[e.jsx(xt,{size:13})," Environment Variables"]}),e.jsxs("div",{className:"space-y-1.5",children:[S.map((L,D)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:L.key,onChange:Q=>{const Z=[...S];Z[D]={...Z[D],key:Q.target.value},I(Z)},placeholder:"KEY",className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("input",{value:L.value,onChange:Q=>{const Z=[...S];Z[D]={...Z[D],value:Q.target.value},I(Z)},placeholder:"value",className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>I(S.filter((Q,Z)=>Z!==D)),className:"p-2 rounded-lg text-gray-600 hover:text-red-400 hover:bg-red-500/10 transition-colors",children:e.jsx(me,{size:14})})]},D)),e.jsxs("button",{onClick:()=>I([...S,{key:"",value:""}]),className:"flex items-center gap-1.5 text-xs text-brand-400 hover:text-brand-300 transition-colors",children:[e.jsx(je,{size:12})," Add Variable"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 mb-1.5 block",children:"Before Command"}),e.jsx("input",{value:w,onChange:L=>v(L.target.value),placeholder:"e.g., npm run build",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 mb-1.5 block",children:"After Command"}),e.jsx("input",{value:x,onChange:L=>o(L.target.value),placeholder:"e.g., npm run cleanup",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"})]})]})]})]}),e.jsx("div",{className:"flex items-center justify-end pt-2 border-t border-white/5",children:e.jsxs("button",{onClick:H,disabled:g,className:"flex items-center gap-2 px-5 py-2.5 rounded-lg text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 transition-colors disabled:opacity-50",children:[g?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(ze,{size:14}),"Save Run Configuration"]})})]})]}),e.jsx(Tl,{}),e.jsx(Tn,{}),e.jsx(Ml,{framework:s.framework}),e.jsx(Dl,{}),e.jsx(El,{}),!l&&e.jsx(Ll,{}),e.jsx(wl,{})]})}const Il=["Chrome","Chromium","Firefox","WebKit","Microsoft Edge","Safari"],Ol=["QA","Development","Staging","Pre-Production","Production"];function Ul({isEnv:s,presetNames:t,usedNames:a,value:l,onChange:m}){const[i,h]=n.useState(!1),[d,f]=n.useState(""),g=new Set(a.map(c=>c.toLowerCase())),y=()=>{const c=d.trim();c&&(m(c),f(""),h(!1))};return e.jsxs("div",{className:"relative w-64",children:[e.jsxs("button",{type:"button",onClick:()=>h(c=>!c),className:"w-full flex items-center gap-2 bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-left outline-none hover:border-gray-300 dark:hover:border-white/20 focus:border-brand-500/50",children:[l?e.jsx(ns,{name:l,isEnv:s}):null,e.jsx("span",{className:`flex-1 truncate ${l?"text-gray-800 dark:text-gray-200":"text-gray-400 dark:text-gray-500"}`,children:l||"Select or type a name…"}),e.jsx(Me,{size:14,className:`text-gray-400 dark:text-gray-500 flex-shrink-0 transition-transform ${i?"rotate-180":""}`})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>h(!1)}),e.jsxs("div",{className:"absolute left-0 top-full mt-1 z-50 w-64 rounded-lg bg-white dark:bg-surface-1 border border-gray-200 dark:border-white/10 shadow-xl shadow-black/20 dark:shadow-black/40 p-1.5",children:[e.jsx("input",{autoFocus:!0,value:d,onChange:c=>f(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),y())},placeholder:"Type a custom name…",className:"w-full mb-1 bg-gray-50 dark:bg-surface-2 border border-gray-200 dark:border-white/10 rounded-md px-3 py-2 text-sm text-gray-800 dark:text-gray-200 outline-none placeholder-gray-400 dark:placeholder-gray-600 focus:border-brand-500/50"}),e.jsx("div",{className:"max-h-56 overflow-auto",children:t.map(c=>e.jsxs("button",{type:"button",onClick:()=>{m(c),h(!1)},className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e.jsx(ns,{name:c,isEnv:s}),e.jsx("span",{className:"flex-1 text-left truncate",children:c}),g.has(c.toLowerCase())&&e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-600",children:"added"})]},c))})]})]})]})}function wt({title:s,icon:t,isEnv:a,autoPattern:l,presetNames:m,cfg:i,onChange:h,onSuggest:d,onDiscussInAI:f,onImproveInAI:g,checks:y}){const[c,j]=n.useState(""),[p,u]=n.useState("arg"),[b,z]=n.useState(!1),[M,V]=n.useState(""),[U,O]=n.useState(!1),[S,I]=n.useState(null),[w,v]=n.useState([]),[x,o]=n.useState(null),[r,E]=n.useState(null),[P,B]=n.useState(null),[N,ee]=n.useState(""),[K,W]=n.useState("arg"),[R,G]=n.useState(""),[_,A]=n.useState(""),te=n.useRef(!1);n.useEffect(()=>{!te.current&&!a&&l&&!_&&(A(l),te.current=!0)},[l]);const X=i.options||[],le=k=>X.some(C=>C.name.toLowerCase()===k.toLowerCase()),$=()=>{const k=c.trim(),C=_.trim();if(!k||!C||le(k))return;const q=a?{name:k,kind:p,value:C}:{name:k,arg:C,...p==="env"?{kind:"env"}:{}};h({...i,options:[...X,q]}),j(""),A(p==="env"?"":l||"")},re=k=>h({...i,options:X.filter(C=>C.name!==k),default:i.default===k?void 0:i.default}),ae=k=>{B(k.name),ee(k.name),W(k.kind==="env"?"env":"arg"),G((a?k.value:k.arg)||"")},ce=()=>B(null),he=!!P&&!!N.trim()&&N.trim().toLowerCase()!==P.toLowerCase()&&le(N.trim()),xe=()=>{if(!P)return;const k=N.trim(),C=R.trim();if(!k||!C||he)return;const q=a?{name:k,kind:K,value:C}:{name:k,arg:C,...K==="env"?{kind:"env"}:{}};h({...i,options:X.map(T=>T.name===P?q:T),default:i.default===P?k:i.default}),B(null)},ye=k=>h({...i,default:i.default===k?void 0:k}),Ne=k=>{u(k),(!_||_===l)&&A(k==="env"?"":l||"")},ke=async()=>{if(!(!d||b)){z(!0),V(""),O(!1),I(null),o(null);try{const{entries:k,notes:C}=await d(),q=new Set(X.map(H=>H.name.toLowerCase())),T=k.filter(H=>H.name&&!q.has(H.name.toLowerCase()));v(C??[]),T.length>0?I(T):k.length>0?V("No new suggestions — your list already covers them."):o(C??[])}catch(k){V((k==null?void 0:k.message)||"AI suggestion failed"),O(!0)}finally{z(!1)}}},F=({check:k,source:C,...q})=>q,Y=k=>{le(k.name)||h({...i,options:[...X,F(k)]}),I(C=>{const q=(C||[]).filter(T=>T.name!==k.name);return q.length?q:null})},se=()=>{if(!S)return;const k=new Set(X.map(q=>q.name.toLowerCase())),C=S.filter(q=>!k.has(q.name.toLowerCase())).map(F);C.length&&h({...i,options:[...X,...C]}),I(null)},ie="bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50",be=!!c.trim()&&le(c.trim()),oe=p==="env"?a?"BASE_URL=https://staging.example.com":"BROWSER=firefox":l||"--browser chrome";return e.jsxs("div",{className:"border border-white/5 rounded-xl p-4 bg-surface-1/40 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-gray-200 flex-1",children:[t," ",s]}),d&&e.jsxs("button",{onClick:ke,disabled:b,title:"Read the right arguments from your project's code — AI is asked only when the code doesn't say",className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-lg text-brand-600 bg-white border border-gray-200 shadow-sm hover:bg-gray-50 disabled:opacity-50",children:[b?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Te,{size:12})," Suggest"]})]}),e.jsxs("p",{className:"text-[11px] text-gray-600 -mt-1",children:["Only the ",e.jsx("span",{className:"text-gray-400",children:"name"})," is shown when picking in Suites & Cycles.",M&&!U&&e.jsx("span",{className:"text-gray-400 ml-2",children:M})]}),U&&M&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-red-400 bg-red-500/5 border border-red-500/20 rounded-lg p-3",children:[e.jsx(Se,{size:14,className:"shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium",children:"Couldn't get suggestions"}),e.jsx("div",{className:"text-red-400/80 mt-0.5",children:M}),e.jsx(kt,{isEnv:a,notes:[],onDiscussInAI:f,onImproveInAI:g})]})]}),x&&e.jsxs("div",{className:"rounded-xl border border-white/10 bg-surface-2/40 p-3.5 space-y-2.5 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(on,{size:15,className:"shrink-0 mt-0.5 text-gray-400"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-gray-200",children:"Nothing found in your project's code"}),e.jsx("div",{className:"text-gray-400 mt-0.5",children:a?"Testver couldn't find a way for a run to choose the environment or application URL.":"Testver couldn't find a way for a run to choose the browser."})]}),e.jsx("button",{onClick:()=>o(null),className:"text-gray-500 hover:text-gray-200",title:"Dismiss",children:e.jsx(me,{size:14})})]}),x.length>0&&e.jsx("ul",{className:"space-y-1 pl-6 text-gray-500 list-disc",children:x.map((k,C)=>e.jsx("li",{className:"line-clamp-3",title:k,children:k},C))}),e.jsxs("div",{className:"pl-6",children:[e.jsx(kt,{isEnv:a,notes:x,onDiscussInAI:f,onImproveInAI:g}),e.jsxs("p",{className:"text-[11px] text-gray-500 mt-2",children:["Or add an entry by hand below if you already know the ",a?"argument or variable":"argument","."]})]})]}),S&&S.length>0&&e.jsxs("div",{className:"rounded-2xl border border-brand-500/20 bg-gradient-to-br from-brand-500/[0.06] via-purple-500/[0.03] to-transparent overflow-hidden shadow-lg shadow-brand-500/5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-white/5 bg-white/[0.015]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-gradient-to-br from-purple-600 to-brand-600 shadow-md shadow-brand-500/20 shrink-0",children:e.jsx(Te,{size:16,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-100",children:"Suggestions"}),e.jsx("p",{className:"text-[11px] text-gray-400 truncate",children:S.every(k=>k.source==="project")?"Read from your project's code — review before applying":"Checked against your project's code — review before applying"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsxs("button",{onClick:se,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-emerald-600/90 hover:bg-emerald-500 shadow-sm shadow-emerald-500/20 transition-colors",children:[e.jsx(ze,{size:13})," Apply all"]}),e.jsx("button",{onClick:()=>I(null),className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-200 hover:bg-white/5 transition-colors",title:"Dismiss suggestions",children:e.jsx(me,{size:15})})]})]}),e.jsxs("div",{className:"p-4 space-y-2.5",children:[S.map(k=>{const C=a?k.value:k.arg,q=a?k.kind:k.kind==="env"?"env":void 0;return e.jsxs("div",{className:"group rounded-xl border border-white/[0.07] bg-surface-2/40 hover:bg-surface-2/60 hover:border-white/10 transition-colors p-3.5 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(ns,{name:k.name,isEnv:a,size:14}),e.jsx("span",{className:"text-[13px] font-semibold text-gray-200 truncate",children:k.name}),q&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-white/5 text-gray-400 border border-white/10 font-medium",children:q==="env"?"Env var":"CLI arg"})]}),e.jsx("button",{onClick:()=>Y(k),className:"px-2.5 py-1 rounded-lg text-[11px] font-medium text-brand-200 bg-brand-500/10 border border-brand-500/25 hover:bg-brand-500/20 hover:text-brand-100 transition-colors shrink-0",children:"Apply"})]}),C&&e.jsx("code",{className:"block text-xs text-cyan-300 font-mono bg-black/30 border border-white/5 rounded-lg px-3 py-2 break-all leading-relaxed",children:C}),k.check&&e.jsx(Bl,{check:k.check,source:k.source})]},k.name)}),w.length>0&&e.jsx("ul",{className:"text-[11px] text-gray-400 leading-relaxed space-y-0.5",children:w.map((k,C)=>e.jsx("li",{children:k},C))}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:[f&&e.jsx("button",{onClick:()=>f(w),className:"text-[11px] text-brand-400 hover:text-brand-300 underline underline-offset-2",children:"Not quite right? Refine in the AI Assistant →"}),g&&e.jsxs("button",{onClick:()=>g(w),className:"text-[11px] text-brand-400 hover:text-brand-300 underline underline-offset-2",children:["Support more ",a?"environments":"browsers"," in my framework →"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ul,{isEnv:a,presetNames:m,usedNames:X.map(k=>k.name),value:c,onChange:j}),e.jsxs("div",{className:"flex rounded-lg border border-white/10 overflow-hidden",title:a?void 0:"Use Env var only when your project reads the browser from an environment variable (BROWSER=firefox)",children:[e.jsx("button",{onClick:()=>Ne("arg"),className:`px-3 py-1.5 text-xs ${p==="arg"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"CLI arg"}),e.jsx("button",{onClick:()=>Ne("env"),className:`px-3 py-1.5 text-xs border-l border-white/10 ${p==="env"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"Env var"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:_,onChange:k=>A(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),$())},placeholder:oe,className:`${ie} flex-1 min-w-[220px] font-mono`}),e.jsx("button",{onClick:$,disabled:!c.trim()||!_.trim()||be,className:"px-3 py-2 text-xs rounded-lg bg-brand-500/20 border border-brand-500/40 text-brand-200 hover:bg-brand-500/30 disabled:opacity-40",children:"Add"})]}),be&&e.jsxs("p",{className:"text-[11px] text-red-400",children:["A “",c.trim(),"” entry already exists — names must be unique."]})]}),X.length>0?e.jsxs("div",{className:"space-y-1.5",children:[X.map(k=>P===k.name?e.jsxs("div",{className:"rounded-lg border border-brand-500/40 bg-brand-500/5 p-2 space-y-2 text-xs",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ns,{name:N||k.name,isEnv:a,size:14}),e.jsx("input",{value:N,onChange:C=>ee(C.target.value),autoFocus:!0,onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),xe()),C.key==="Escape"&&(C.preventDefault(),ce())},"aria-label":"Name",className:`${ie} !py-1.5 w-44`}),e.jsxs("div",{className:"flex rounded-lg border border-white/10 overflow-hidden",children:[e.jsx("button",{type:"button",onClick:()=>W("arg"),className:`px-3 py-1.5 text-xs ${K==="arg"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"CLI arg"}),e.jsx("button",{type:"button",onClick:()=>W("env"),className:`px-3 py-1.5 text-xs border-l border-white/10 ${K==="env"?"bg-brand-500/15 text-brand-300":"text-gray-400 hover:text-gray-200"}`,children:"Env var"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:R,onChange:C=>G(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),xe()),C.key==="Escape"&&(C.preventDefault(),ce())},"aria-label":a?"Value":"Argument",placeholder:oe,className:`${ie} !py-1.5 flex-1 min-w-[220px] font-mono`}),e.jsx("button",{type:"button",onClick:xe,disabled:!N.trim()||!R.trim()||he,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-500/20 border border-brand-500/40 text-brand-200 hover:bg-brand-500/30 disabled:opacity-40",children:"Save"}),e.jsx("button",{type:"button",onClick:ce,className:"px-3 py-1.5 text-xs rounded-lg border border-white/10 text-gray-400 hover:text-gray-200 hover:bg-white/5",children:"Cancel"})]}),he&&e.jsxs("p",{className:"text-[11px] text-red-400",children:["A “",N.trim(),"” entry already exists — names must be unique."]}),!he&&N.trim()&&N.trim()!==k.name&&e.jsxs("p",{className:"text-[11px] text-amber-400",children:["Renaming: suites, cycles and schedules that picked “",k.name,"” keep that name and will fall back to the default until you re-pick “",N.trim(),"”."]})]},k.name):e.jsxs("div",{className:`flex items-center gap-2 rounded-lg border px-2.5 py-1.5 text-xs ${i.default===k.name?"border-brand-500/40 bg-brand-500/10":"border-white/10 bg-surface-2"}`,children:[e.jsx("button",{onClick:()=>ye(k.name),title:i.default===k.name?"Default":"Set as default",className:i.default===k.name?"text-brand-300":"text-gray-500 hover:text-brand-300",children:e.jsx(gs,{size:12,className:i.default===k.name?"fill-current":""})}),e.jsx(ns,{name:k.name,isEnv:a,size:14}),e.jsx("span",{className:"text-gray-200 font-medium min-w-[80px]",children:k.name}),(a||k.kind==="env")&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${k.kind==="env"?"bg-cyan-500/15 text-cyan-300":"bg-white/5 text-gray-400"}`,children:k.kind==="env"?"ENV":"ARG"}),e.jsx("span",{className:"text-gray-500 font-mono truncate flex-1",title:a?k.value:k.arg,children:a?k.value:k.arg}),(()=>{const C=y==null?void 0:y[k.name];return!C||C.value!==(a?k.value:k.arg)||C.check.status==="confirmed"?null:e.jsx("span",{title:C.check.note,className:`flex-shrink-0 ${C.check.status==="wrong"?"text-red-400":"text-amber-400"}`,children:e.jsx(ue,{size:12})})})(),e.jsx("button",{onClick:()=>ae(k),title:`Edit ${k.name}`,"aria-label":`Edit ${k.name}`,className:"text-gray-500 hover:text-brand-300 flex-shrink-0",children:e.jsx(Cs,{size:12})}),e.jsx("button",{onClick:()=>E(k.name),title:`Remove ${k.name}`,className:"text-gray-500 hover:text-red-400 flex-shrink-0",children:e.jsx(me,{size:12})})]},k.name)),X.filter(k=>{const C=y==null?void 0:y[k.name];return C&&C.value===(a?k.value:k.arg)&&C.check.status==="wrong"}).map(k=>e.jsxs("p",{className:"text-[11px] text-red-400 leading-relaxed",children:[e.jsxs("span",{className:"font-medium",children:[k.name,":"]})," ",y[k.name].check.note]},`w-${k.name}`))]}):e.jsx("p",{className:"text-[11px] text-gray-600",children:"No entries yet — add a name + its argument above."}),e.jsx(Ot,{open:r!=null,title:`Remove ${a?"environment":"browser"} “${r??""}”?`,description:`This deletes the saved ${a?"environment":"browser"} “${r??""}” from ${s.toLowerCase()}. Suites, cycles, and scheduled runs that pick it by name will fall back to the default. This won't affect runs that already completed.`,confirmLabel:"Remove",onConfirm:()=>{r&&re(r),E(null)},onCancel:()=>E(null)})]})}function kt({isEnv:s,notes:t,onDiscussInAI:a,onImproveInAI:l}){if(!a&&!l)return null;const m="inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] font-medium transition-colors";return e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[a&&e.jsxs("button",{onClick:()=>a(t),title:"The AI Assistant scans your project itself and saves the entries it finds",className:`${m} text-brand-200 bg-brand-500/10 border border-brand-500/25 hover:bg-brand-500/20`,children:[e.jsx(Te,{size:12})," Find them with the AI Assistant"]}),l&&e.jsxs("button",{onClick:()=>l(t),title:`The AI Assistant updates your framework so a run can choose the ${s?"environment":"browser"}, keeps today's default, and registers the options`,className:`${m} text-gray-200 bg-white/5 border border-white/10 hover:bg-white/10`,children:[e.jsx(Rt,{size:12})," Add support to my framework"]})]})}function Bl({check:s,source:t}){const a=s.status==="confirmed"?"text-emerald-400":s.status==="wrong"?"text-red-400":"text-amber-400",l=s.status==="confirmed"?t==="ai"?"AI suggestion, confirmed in your code":"Found in your project":s.status==="wrong"?"Your code doesn't accept this":"Not confirmed — check it before relying on it";return e.jsxs("p",{className:`text-[11px] leading-relaxed ${a}`,title:s.note,children:[s.status==="confirmed"?e.jsx(ne,{size:11,className:"inline -mt-0.5 mr-1"}):e.jsx(ue,{size:11,className:"inline -mt-0.5 mr-1"}),e.jsx("span",{className:"font-medium",children:l}),e.jsxs("span",{className:"text-gray-500",children:[" — ",s.note]})]})}function Ce({token:s}){const[t,a]=n.useState(!1),l=async()=>{try{await navigator.clipboard.writeText(s)}catch{const m=document.createElement("textarea");m.value=s,m.style.position="fixed",m.style.opacity="0",document.body.appendChild(m),m.select();try{document.execCommand("copy")}catch{}document.body.removeChild(m)}a(!0),window.setTimeout(()=>a(!1),1200)};return e.jsxs("button",{type:"button",onClick:l,title:t?"Copied!":"Click to copy",className:`group relative inline-flex items-center font-mono px-1.5 py-0.5 rounded border transition-colors cursor-pointer ${t?"bg-emerald-500/10 text-emerald-400 border-emerald-500/30":"bg-surface-2 text-cyan-400 border-transparent hover:border-cyan-500/30 hover:bg-cyan-500/10"}`,children:[e.jsx("code",{className:"bg-transparent",children:s}),e.jsx("span",{className:`absolute -top-1.5 -right-1.5 flex items-center justify-center w-3.5 h-3.5 rounded-full bg-surface-1 border shadow-sm transition-opacity ${t?"opacity-100 border-emerald-500/40 text-emerald-400":"opacity-0 group-hover:opacity-100 border-cyan-500/40 text-cyan-400"}`,children:t?e.jsx(Ue,{size:9}):e.jsx(xs,{size:9})})]})}function Us({label:s,description:t,value:a,onChange:l,placeholder:m,isCustom:i,onReset:h,onTest:d,testing:f,testResult:g}){return e.jsxs("div",{className:"rounded-xl border border-white/5 bg-black/20 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ts,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-200",children:s}),i?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cyan-500/10 text-cyan-400 border border-cyan-500/20",children:"Custom"}):e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-gray-500/10 text-gray-500 border border-gray-500/20",children:"Auto-detected"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{onClick:h,className:`flex items-center gap-1 px-2 py-1 rounded-lg text-xs transition-colors ${i?"text-amber-400 hover:text-amber-300 hover:bg-amber-500/10":"text-gray-600 hover:text-gray-400 hover:bg-white/5"}`,title:"Reset to auto-detected default",children:[e.jsx(fs,{size:11})," Reset"]}),e.jsxs("button",{onClick:d,disabled:f,className:"flex items-center gap-1 px-2 py-1 rounded-lg text-xs text-gray-500 hover:text-emerald-400 hover:bg-emerald-500/10 transition-colors disabled:opacity-50",title:"Test this command",children:[f?e.jsx(J,{size:11,className:"animate-spin"}):e.jsx(Xs,{size:11})," Test"]})]})]}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:t}),e.jsx("input",{value:a,onChange:y=>l(y.target.value),placeholder:m,className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),g&&e.jsxs("div",{className:`mt-2 flex items-center gap-2 text-xs ${g.valid?"text-emerald-400":"text-red-400"}`,children:[g.valid?e.jsx(ze,{size:12}):e.jsx(Se,{size:12}),e.jsx("span",{children:g.valid?"Command is valid":"Command failed"}),g.output&&e.jsx("span",{className:"text-gray-600 truncate max-w-[300px]",title:g.output,children:g.output.slice(0,80)})]})]})}const Bs=[{id:"openai",label:"OpenAI",color:"text-green-400",description:"GPT-4o, GPT-4, GPT-3.5 Turbo",requiresKey:!0},{id:"anthropic",label:"Anthropic",color:"text-purple-400",description:"Claude Sonnet, Claude Opus, Claude Haiku",requiresKey:!0},{id:"google",label:"Google AI",color:"text-blue-400",description:"Gemini 2.0 Flash, Gemini Pro",requiresKey:!0},{id:"xai",label:"xAI",color:"text-orange-400",description:"Grok-2, Grok-3",requiresKey:!0},{id:"testver",label:"Testver",color:"text-sky-400",description:"Managed AI — frontier model, managed by Testver",requiresKey:!0},{id:"ollama",label:"Ollama",color:"text-amber-400",description:"Local models — Llama, Mistral, Phi, etc.",requiresKey:!1},{id:"lmstudio",label:"LM Studio",color:"text-cyan-400",description:"Local model server",requiresKey:!1}],He="••••••••";function Kl(){const s=Je(),{data:t}=wn();return n.useEffect(()=>{kn(s)},[s]),t!=null&&t.connected?(t.totalCredits??0)<=0?e.jsxs("div",{className:"mt-3 pt-3 border-t border-white/5 text-xs text-gray-500",children:[t.active===!1?"No active plan on this account yet — pick one at testver.com to start generating.":"Loading plan details…",t.billingUrl&&t.active===!1&&e.jsx("a",{href:t.billingUrl,target:"_blank",rel:"noopener noreferrer",className:"ml-1.5 font-medium text-sky-400 hover:text-sky-300 underline underline-offset-2",children:"View plans →"})]}):e.jsx("div",{className:"mt-3 pt-3.5 border-t border-black/[0.06] dark:border-white/5",children:e.jsx(Cn,{data:t,statusBadge:!0})}):null}function _l({connected:s,isSystemAdmin:t}){const a=t?"system":"personal",{data:l}=Ge({queryKey:["testver-status"],queryFn:()=>Na(),refetchInterval:3e4,refetchOnWindowFocus:!0,staleTime:15e3,enabled:s}),m=l!=null&&l.connected?l.accountEmail??null:null;return e.jsxs("div",{className:"rounded-lg border border-sky-500/20 bg-surface-1 p-4",children:[s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-400",children:[e.jsx(ne,{size:16}),e.jsxs("span",{className:"font-medium",children:[a==="system"?"System connected to Testver":"Connected",m?e.jsxs(e.Fragment,{children:[" as ",e.jsx("span",{className:"text-gray-200",children:m})]}):a==="system"?null:" as your account"]}),l!=null&&l.connected&&l.status==="suspended"?e.jsx("span",{className:"text-red-400",children:"— plan suspended, AI requests are paused."}):l!=null&&l.connected&&l.status==="paused"?e.jsx("span",{className:"text-amber-400",children:"— seat paused, AI requests are off until the team owner gives you a seat."}):l!=null&&l.connected&&l.active===!1&&(l.totalCredits??0)>0?e.jsx("span",{className:"text-red-400",children:"— credits used up, AI requests are paused."}):e.jsx("span",{className:"text-gray-500",children:"— AI requests are ready."})]}),e.jsxs(os,{to:"/testver",className:"ml-auto inline-flex items-center gap-1.5 px-3.5 py-1.5 rounded-lg text-xs font-medium text-sky-300 bg-sky-500/10 border border-sky-500/20 hover:bg-sky-500/20 transition-colors",children:["Manage in Testver → Connections",e.jsx(xn,{size:12})]})]}),e.jsx(Kl,{})]}):e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{className:"text-sm text-gray-300",children:a==="system"?"This Testver is not connected to an account yet.":"Your Testver account is not connected yet."}),e.jsxs(os,{to:"/testver",className:"ml-auto inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-semibold text-white bg-gradient-to-r from-sky-500 to-indigo-500 hover:from-sky-400 hover:to-indigo-400 transition-colors",children:[e.jsx(Ee,{size:14}),"Connect in Testver → Connections"]})]}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Connect and disconnect moved to the Testver page — this card only shows the status and the model settings."})]})}const Fe=()=>({apiKey:"",model:"",models:[],activeModel:"",newModel:"",baseUrl:"",timeout:""});function Hl({isAdmin:s=!0}){const{toast:t}=ge(),[a,l]=n.useState(!0),[m,i]=n.useState(null),[h,d]=n.useState("openai"),[f,g]=n.useState(""),[y,c]=n.useState({openai:Fe(),anthropic:Fe(),google:Fe(),xai:Fe(),testver:Fe(),ollama:Fe(),lmstudio:Fe()}),[j,p]=n.useState(null),[u,b]=n.useState({}),[z,M]=n.useState({}),[V,U]=n.useState({}),[O,S]=n.useState(null),I=n.useCallback(async(r=!1)=>{try{const E=await ua();i(E),r||(d(E.defaultProvider),g(E.defaultModel||""));const P={};for(const B of Bs){const N=E.providers[B.id];P[B.id]={apiKey:N!=null&&N.hasApiKey?He:"",model:(N==null?void 0:N.configuredModel)||"",models:(N==null?void 0:N.models)??[],activeModel:(N==null?void 0:N.activeModel)||(N==null?void 0:N.model)||"",newModel:"",baseUrl:(N==null?void 0:N.configuredBaseUrl)||"",timeout:N!=null&&N.timeout?String(N.timeout):""}}c(P)}catch{t("error","Failed to load LLM configuration")}finally{l(!1)}},[t]);n.useEffect(()=>{I()},[I]);const w=(r,E,P)=>{c(B=>({...B,[r]:{...B[r],[E]:P}}))},v=async r=>{var E;S(r);try{const P=y[r],B={};B[r]={model:P.activeModel||P.model.trim(),models:P.models.filter(N=>N.trim()),activeModel:P.activeModel||P.models[0]||"",baseUrl:P.baseUrl.trim(),timeout:P.timeout?parseInt(P.timeout,10):null},P.apiKey&&P.apiKey!==He&&(B[r].apiKey=P.apiKey),await rt({defaultProvider:h,defaultModel:f||null,providers:B}),t("success",`${(E=Bs.find(N=>N.id===r))==null?void 0:E.label} settings saved`),await I()}catch(P){t("error",`Failed to save: ${P}`)}finally{S(null)}},x=async r=>{M(E=>({...E,[r]:!0})),U(E=>{const P={...E};return delete P[r],P});try{const E=y[r],P=await wa({provider:r,apiKey:E.apiKey&&E.apiKey!==He?E.apiKey:void 0,baseUrl:E.baseUrl||void 0,model:E.model||void 0});U(B=>({...B,[r]:{ok:P.connected,msg:P.message,latency:P.latencyMs}}))}catch(E){U(P=>({...P,[r]:{ok:!1,msg:String(E)}}))}finally{M(E=>({...E,[r]:!1}))}},o=r=>{const E=m==null?void 0:m.providers[r];return r==="testver"?E!=null&&E.hasApiKey?{label:"Connected",color:"text-emerald-400",dot:"bg-emerald-400"}:{label:"Not Connected",color:"text-gray-500",dot:"bg-gray-500"}:E?E.isLocal?{label:"Local",color:"text-amber-400",dot:"bg-amber-400"}:E.apiKeySource==="env"?{label:"Env Var",color:"text-emerald-400",dot:"bg-emerald-400"}:E.apiKeySource==="config"?{label:"Configured",color:"text-emerald-400",dot:"bg-emerald-400"}:{label:"Not Configured",color:"text-gray-500",dot:"bg-gray-500"}:{label:"Not Configured",color:"text-gray-500",dot:"bg-gray-500"}};return a?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-gray-500 text-sm",children:[e.jsx(J,{size:16,className:"animate-spin"}),"Loading LLM configuration..."]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-300 flex items-center gap-2.5 px-1",children:[e.jsx(Ee,{size:16,className:"text-brand-400"}),"Providers"]}),Bs.filter(r=>(s||r.id==="testver")&&!gn.has(r.id)).map(r=>{const E=j===r.id,P=o(r.id),B=y[r.id],N=m==null?void 0:m.providers[r.id],ee=r.id==="testver";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden transition-all",children:[e.jsxs("button",{onClick:()=>p(E?null:r.id),className:"w-full flex items-center gap-3.5 px-6 py-4 hover:bg-surface-2/30 transition-colors text-left",children:[e.jsx("span",{className:"flex-shrink-0",children:e.jsx(bn,{provider:r.id,size:26})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-[15px] font-semibold text-gray-200",children:r.label}),h===r.id&&e.jsx("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-400 border border-amber-500/20",children:"DEFAULT"})]}),e.jsxs("span",{className:"text-sm text-gray-500 block mt-0.5",children:[r.description,r.id==="testver"&&!(N!=null&&N.hasApiKey)?". Try it for free — click Connect to link your testver.com account":""]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 flex-shrink-0",children:[s&&e.jsx("span",{onClick:async K=>{if(K.stopPropagation(),h!==r.id){d(r.id);try{await rt({defaultProvider:r.id}),t("success",`${r.label} set as default provider`),await I(!0)}catch{}}},className:`p-1 rounded-lg transition-colors ${h===r.id?"text-amber-400":"text-gray-800/30 hover:text-amber-400/50 cursor-pointer"}`,title:h===r.id?"Default provider":`Set ${r.label} as default`,children:e.jsx(gs,{size:15,className:h===r.id?"fill-amber-400":""})}),e.jsxs("span",{className:`flex items-center gap-1.5 text-sm font-medium ${P.color}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${P.dot}`}),P.label]}),E?e.jsx(Me,{size:18,className:"text-gray-500"}):e.jsx(Ie,{size:18,className:"text-gray-500"})]})]}),E&&e.jsxs("div",{className:"px-6 pb-6 pt-3 border-t border-white/5 space-y-4",children:[r.id==="testver"&&e.jsx(_l,{connected:!!(N!=null&&N.hasApiKey),isSystemAdmin:(N==null?void 0:N.isSystemAdmin)!==!1,onConnected:()=>void I(!0)}),!ee&&e.jsxs(e.Fragment,{children:[r.requiresKey&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm text-gray-400 block mb-1.5",children:["API Key",(N==null?void 0:N.apiKeySource)==="config"&&B.apiKey===He&&e.jsx("span",{className:"ml-2 text-gray-600 font-normal",children:"(saved — click to change)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:u[r.id]?"text":"password",value:B.apiKey,onChange:K=>w(r.id,"apiKey",K.target.value),onFocus:()=>{B.apiKey===He&&w(r.id,"apiKey","")},onBlur:()=>{!B.apiKey&&(N!=null&&N.hasApiKey)&&w(r.id,"apiKey",He)},placeholder:"Enter API key",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 pr-10 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>b(K=>({...K,[r.id]:!K[r.id]})),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300",children:u[r.id]?e.jsx(is,{size:16}):e.jsx(ve,{size:16})})]}),(N==null?void 0:N.apiKeySource)==="env"&&N.envVarName&&e.jsxs("p",{className:"text-xs text-amber-500/80 mt-1 flex items-center gap-1",children:[e.jsx(Ee,{size:12}),"Set via environment variable ",e.jsx("span",{className:"font-mono",children:N.envVarName})]})]}),r.id==="testver"?e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Model"}),e.jsx("p",{className:"text-sm text-gray-500 bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5",children:"Managed by Testver — your plan's AI model is selected automatically. No configuration needed."})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Models"}),B.models.length===0&&e.jsxs("p",{className:"text-sm text-gray-500 mb-2",children:["No models yet — add the model names you use with ",r.label,"."]}),e.jsx("div",{className:`flex flex-wrap gap-1.5 ${B.models.length?"mb-2":""}`,children:B.models.map(K=>{const W=K===B.activeModel;return e.jsxs("div",{className:`flex items-center gap-1.5 pl-2 pr-1 py-1 rounded-lg text-sm font-mono transition-all ${W?"bg-brand-500/15 border border-brand-500/40 text-brand-300":"bg-surface-2 border border-white/10 text-gray-400"}`,children:[e.jsx("button",{onClick:()=>{c(R=>({...R,[r.id]:{...R[r.id],activeModel:K,model:K}}))},className:`p-0.5 rounded transition-colors ${W?"text-brand-400":"text-gray-600 hover:text-amber-400"}`,title:W?"Active model":"Set as active",children:e.jsx(gs,{size:12,className:W?"fill-current":""})}),e.jsx("span",{className:"truncate max-w-[200px]",children:K}),e.jsx("button",{onClick:()=>{const R=B.models.filter(_=>_!==K),G=W?R[0]||"":B.activeModel;c(_=>({..._,[r.id]:{..._[r.id],models:R,activeModel:G,model:G}}))},className:"p-0.5 rounded text-gray-600 hover:text-red-400 transition-colors",title:"Remove model",children:e.jsx(me,{size:11})})]},K)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:B.newModel,onChange:K=>c(W=>({...W,[r.id]:{...W[r.id],newModel:K.target.value}})),onKeyDown:K=>{if(K.key==="Enter"&&B.newModel.trim()){K.preventDefault();const W=B.newModel.trim();if(!B.models.includes(W)){const R=[...B.models,W];c(G=>({...G,[r.id]:{...G[r.id],models:R,newModel:"",activeModel:G[r.id].activeModel||W,model:G[r.id].activeModel||W}}))}}},placeholder:`Add model — its exact name in ${r.label}`,className:"flex-1 bg-surface-2 border border-white/10 rounded-lg px-3 py-2 text-sm text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsx("button",{onClick:()=>{const K=B.newModel.trim();if(K&&!B.models.includes(K)){const W=[...B.models,K];c(R=>({...R,[r.id]:{...R[r.id],models:W,newModel:"",activeModel:R[r.id].activeModel||K,model:R[r.id].activeModel||K}}))}},disabled:!B.newModel.trim(),className:"px-3 py-2 rounded-lg text-sm font-medium text-brand-300 bg-brand-500/10 border border-brand-500/20 hover:bg-brand-500/20 transition-colors disabled:opacity-30",children:e.jsx(je,{size:14})})]}),B.models.length>0&&e.jsxs("p",{className:"text-xs text-gray-600 mt-1.5",children:[e.jsx(gs,{size:10,className:"inline fill-brand-400 text-brand-400 -mt-0.5"})," marks the active model. Click the star to switch."]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm text-gray-400 block mb-1.5",children:["Base URL ",!r.requiresKey&&e.jsx("span",{className:"text-gray-600 font-normal",children:"(required for local providers)"})]}),e.jsx("input",{value:B.baseUrl,onChange:K=>w(r.id,"baseUrl",K.target.value),placeholder:(N==null?void 0:N.defaultBaseUrl)||"Default (cloud endpoint)",className:"w-full bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),!B.baseUrl&&(N==null?void 0:N.baseUrl)&&e.jsxs("p",{className:"text-xs text-gray-500 mt-1 flex items-center gap-1",children:["Active: ",e.jsx("span",{className:"font-mono",children:N.baseUrl}),N.baseUrl!==N.defaultBaseUrl?" (from env)":" (default)"]}),B.baseUrl&&(N==null?void 0:N.defaultBaseUrl)&&e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["Default: ",N.defaultBaseUrl]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-1.5",children:"Timeout (ms)"}),e.jsx("input",{value:B.timeout,onChange:K=>w(r.id,"timeout",K.target.value.replace(/\D/g,"")),placeholder:r.requiresKey?"60000":"300000",className:"w-52 bg-surface-2 border border-white/10 rounded-lg px-3.5 py-2.5 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50 font-mono"}),e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["Leave blank for default (",r.requiresKey?"60s":"5 min",")"]})]}),V[r.id]&&e.jsxs("div",{className:`flex items-center gap-2 text-[15px] px-4 py-2.5 rounded-lg ${V[r.id].ok?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,children:[V[r.id].ok?e.jsx(ze,{size:16}):e.jsx(Se,{size:16}),e.jsx("span",{className:"flex-1",children:V[r.id].msg}),V[r.id].latency&&e.jsxs("span",{className:"text-sm opacity-70",children:[V[r.id].latency,"ms"]})]}),e.jsxs("div",{className:"flex gap-2.5 pt-2 border-t border-white/5",children:[e.jsxs("button",{onClick:()=>x(r.id),disabled:z[r.id],className:"flex items-center gap-2 px-4 py-2 text-[15px] rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5 disabled:opacity-40 transition-colors",children:[z[r.id]?e.jsx(J,{size:16,className:"animate-spin"}):e.jsx(Ee,{size:16}),"Test Connection"]}),e.jsxs("button",{onClick:()=>v(r.id),disabled:O===r.id,className:"flex items-center gap-2 px-5 py-2 text-[15px] rounded-lg bg-brand-600 hover:bg-brand-500 text-white font-medium disabled:opacity-40 transition-colors",children:[O===r.id?e.jsx(J,{size:16,className:"animate-spin"}):e.jsx(ze,{size:16}),"Save ",r.label]})]})]})]})]},r.id)})]})})}export{co as SettingsPage};
|