@fudrouter/fsrouter 0.6.73 → 0.6.74
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/dist/lib/headroom/detect.js +97 -7
- package/dist/lib/headroom/process.js +136 -4
- package/dist/routes/headroom/extras/route.js +58 -0
- package/dist/routes/headroom/restart/route.js +33 -0
- package/package.json +1 -1
- package/public/assets/EndpointPageClient.C2WMTYy0.js +6 -0
- package/public/assets/{Loading.Bj-WGl4k.js → Loading.BHPtQ9vj.js} +1 -1
- package/public/assets/{NoAuthProxyCard.qAv57b-0.js → NoAuthProxyCard.BDcXaWvM.js} +1 -1
- package/public/assets/index.Be3gbrBl.js +89 -0
- package/public/assets/index.COMgQZYj.css +1 -0
- package/public/assets/{page.CbkENBd5.js → page.-lpNgYAw.js} +1 -1
- package/public/assets/{page.CssmrzTT.js → page.11hpNKmq.js} +1 -1
- package/public/assets/{page.C72FTTJr.js → page.B-LxsnqU.js} +1 -1
- package/public/assets/{page.sOFOrxqq.js → page.B-dzeIUC.js} +1 -1
- package/public/assets/{page.CsxWmPoI.js → page.B-nBR75u.js} +1 -1
- package/public/assets/{page.Dx_GRRdT.js → page.B3QqvLep.js} +1 -1
- package/public/assets/{page.DPyOkPVo.js → page.B8xdkCWA.js} +1 -1
- package/public/assets/{page.DUI8kqOY.js → page.BFb7yUd8.js} +1 -1
- package/public/assets/page.BbPPdoas.js +1 -0
- package/public/assets/page.BdS20a1O.js +1 -0
- package/public/assets/{page.DibhF7f-.js → page.BfmI9KYe.js} +1 -1
- package/public/assets/{page.DX4Nno6M.js → page.BgGJovOg.js} +1 -1
- package/public/assets/{page.BnmTC5jG.js → page.C0gBvR4O.js} +1 -1
- package/public/assets/{page.D5gj98Oe.js → page.C6bYizL7.js} +1 -1
- package/public/assets/{page.vla5Mzki.js → page.C8sLEMa6.js} +1 -1
- package/public/assets/{page.CXd_R9yU.js → page.CCNsZBXp.js} +1 -1
- package/public/assets/{page.CQlVGoXg.js → page.CF_YSLwP.js} +1 -1
- package/public/assets/{page.BbO1pspY.js → page.CPTtRDxw.js} +1 -1
- package/public/assets/{page.D1oKew1j.js → page.CdMmlUEm.js} +1 -1
- package/public/assets/{page.DxMDTbSx.js → page.Cged1bOZ.js} +1 -1
- package/public/assets/{page.Cj5h09Zo.js → page.Ch647dVk.js} +1 -1
- package/public/assets/{page.DVIHRbxB.js → page.CpvXDkQF.js} +1 -1
- package/public/assets/{page.i4KDuWcM.js → page.CrBl7f8N.js} +1 -1
- package/public/assets/{page.BSLJ4tx5.js → page.CrP7niA2.js} +1 -1
- package/public/assets/{page.CnTop8Zt.js → page.CvUFZzXr.js} +1 -1
- package/public/assets/{page.O2ddJYoT.js → page.CyUqJPmx.js} +1 -1
- package/public/assets/{page.DBhu4Arl.js → page.D8Rp8fFR.js} +1 -1
- package/public/assets/{page.CPZav1_c.js → page.Df9qtrdG.js} +1 -1
- package/public/assets/{page.Qkkv8roc.js → page.DiL4Gwqe.js} +1 -1
- package/public/assets/{page.BdmJ3yY3.js → page.Dl1apZE2.js} +1 -1
- package/public/assets/{page.1qjqvrwX.js → page.HV0w1d5C.js} +1 -1
- package/public/assets/{page.ChX1NqmC.js → page.N1x4YL8_.js} +1 -1
- package/public/assets/{page.Dh5f0XJC.js → page.P2Ny5veR.js} +1 -1
- package/public/assets/{page.CSs3-gdt.js → page.fOOCr18J.js} +1 -1
- package/public/assets/{page.Ir7KvKcF.js → page.sUIPWIiF.js} +1 -1
- package/public/assets/{page.CzlQTyAL.js → page.tE7PpWYW.js} +1 -1
- package/public/assets/{page.DzZLqI5Q.js → page.uziaGZsT.js} +1 -1
- package/public/index.html +2 -2
- package/public/assets/EndpointPageClient.LyNNvZ4z.js +0 -6
- package/public/assets/index.BuPfZebu.css +0 -1
- package/public/assets/index.CShjRV_B.js +0 -89
- package/public/assets/page.DD_czjjP.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,B as I,y as te,h as ae,k as re,l as le}from"./index.CShjRV_B.js";import{b as r}from"./router.Cjj1--8t.js";import{M as ie}from"./cliTools.CsdwAybi.js";import{C as Z,B,I as K,M as ne}from"./NoAuthProxyCard.qAv57b-0.js";import"./zustand.akaTi5uX.js";const $=te();function oe({apiKeys:l,cloudEnabled:b,onStatusChange:y}){const[s,c]=r.useState(null),[x,v]=r.useState(!1),[D,N]=r.useState(!1),[T,p]=r.useState(""),[j,U]=r.useState(()=>{var a;return((a=l==null?void 0:l[0])==null?void 0:a.key)||""}),[E,h]=r.useState(null),[A,w]=r.useState(null),[_,S]=r.useState(null),[i,n]=r.useState($),[m,R]=r.useState(null),u=(s==null?void 0:s.isWin)===!0,q=u||(s==null?void 0:s.hasCachedPassword)||(s==null?void 0:s.needsSudoPassword)===!1,k=(s==null?void 0:s.isAdmin)!==!1;!k&&(u||!(s!=null&&s.hasCachedPassword)&&(s==null||s.needsSudoPassword));const g=r.useCallback(async()=>{try{const a=await fetch("/api/cli-tools/antigravity-mitm");if(a.ok){const d=await a.json();c(d),d.mitmRouterBaseUrl&&n(d.mitmRouterBaseUrl),y==null||y(d)}}catch{c({running:!1,certExists:!1,dnsStatus:{}})}},[y]);r.useEffect(()=>{queueMicrotask(()=>{g()})},[g]);const O=a=>{S(null),s&&(q?z(a,""):(h(a),N(!0),w(null)))},z=async(a,d,L=!1)=>{v(!0),S(null);try{let f;if(a==="trust-cert")f=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"trust-cert",sudoPassword:d})});else if(a==="start"){const P=(j==null?void 0:j.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(b?null:"sk_fsrouter");f=await fetch("/api/cli-tools/antigravity-mitm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:P,sudoPassword:d,mitmRouterBaseUrl:i.trim()||$,forceKillPort443:L})})}else f=await fetch("/api/cli-tools/antigravity-mitm",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:d})});if(!f.ok){const P=await f.json().catch(()=>({}));if(P.code==="PORT_443_BUSY"&&P.portOwner){N(!1),R({owner:P.portOwner,password:d});return}S(P.error||`Failed to ${a} MITM server`);return}N(!1),p(""),R(null),await g()}catch(f){S(f.message||"Network error")}finally{v(!1),h(null)}},F=()=>{const a=(m==null?void 0:m.password)||"";z("start",a,!0)},M=()=>{if(!T.trim()){w("Sudo password is required");return}z(E,T)},C=s==null?void 0:s.running;return e.jsxs(e.Fragment,{children:[e.jsx(Z,{padding:"sm",className:"border-primary/20 bg-primary/5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[20px]",children:"security"}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:"MITM Server"}),C?e.jsx(B,{variant:"success",size:"sm",children:"Running"}):e.jsx(B,{variant:"default",size:"sm",children:"Stopped"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1 text-xs text-text-muted","data-i18n-skip":"true",children:[{label:"Cert",ok:s==null?void 0:s.certExists},{label:"Trusted",ok:s==null?void 0:s.certTrusted},{label:"Server",ok:C}].map(({label:a,ok:d})=>e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded ${d?"text-green-600":"text-text-muted"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:d?"check_circle":"cancel"}),a]},a))})]}),e.jsxs("div",{className:"px-2 py-2 rounded-lg bg-surface/50 border border-border/50 flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[e.jsx("span",{className:"font-medium text-text-main",children:"Purpose:"})," Use Antigravity IDE & GitHub Copilot → with ANY provider/model from FSRouter"]}),e.jsxs("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[e.jsx("span",{className:"font-medium text-text-main",children:"How it works:"})," Antigravity/Copilot IDE request → DNS redirect to localhost:443 → MITM proxy intercepts → FSRouter → response to Antigravity/Copilot"]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"FSRouter Base URL"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",value:i,onChange:a=>n(a.target.value),placeholder:$,disabled:C,className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]}),!C&&e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",list:"mitm-api-keys",value:j,onChange:a=>U(a.target.value),placeholder:b?"Enter or pick API key":"sk_fsrouter (default)",className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"}),(l==null?void 0:l.length)>0&&e.jsx("datalist",{id:"mitm-api-keys",children:l.map(a=>e.jsx("option",{value:a.key,children:a.name||a.key},a.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center","data-i18n-skip":"true",children:[(s==null?void 0:s.certExists)&&!(s!=null&&s.certTrusted)&&e.jsxs("button",{onClick:()=>O("trust-cert"),disabled:x,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-xs font-medium text-yellow-600 transition-colors hover:bg-yellow-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"verified_user"}),"Trust Cert"]}),C?e.jsxs("button",{onClick:()=>O("stop"),disabled:x,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop Server"]}):e.jsxs("button",{onClick:()=>O("start"),disabled:x||!s||u&&!k,title:u&&!k?"Administrator required":void 0,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start Server"]}),C&&e.jsx("p",{className:"text-xs text-text-muted",children:"Enable DNS per tool below to activate interception"})]}),_&&e.jsxs("div",{className:"flex items-start gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 dark:text-red-400 border border-red-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mt-0.5 shrink-0",children:"error"}),e.jsx("span",{children:_})]}),u&&!k&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 border border-red-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"shield_lock"}),e.jsx("span",{children:"Administrator required — restart FSRouter as Administrator to use MITM"})]})]})}),D&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Required for SSL certificate and server startup"})]}),e.jsx(K,{type:"password",placeholder:"Enter sudo password",value:T,onChange:a=>p(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!x&&M()}}),A&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),e.jsx("span",{children:A})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{N(!1),p(""),w(null)},disabled:x,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:M,loading:x,children:"Confirm"})]})]})}),m&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Port 443 Already In Use"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsxs("div",{className:"flex flex-col gap-1 text-xs text-text-muted",children:[e.jsx("p",{children:"Port 443 is currently used by another process:"}),e.jsxs("p",{className:"font-mono text-text-main","data-i18n-skip":"true",children:[m.owner.name," (PID ",m.owner.pid,")"]}),e.jsx("p",{children:"Kill this process to start MITM Server?"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{R(null),v(!1)},disabled:x,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:F,loading:x,children:"Kill & Start"})]})]})})]})}const de={antigravity:["daily-cloudcode-pa.googleapis.com","cloudcode-pa.googleapis.com"],copilot:["api.individual.githubcopilot.com"],kiro:["q.us-east-1.amazonaws.com","codewhisperer.us-east-1.amazonaws.com"],cursor:["api2.cursor.sh"]};function ce({tool:l,isExpanded:b,onToggle:y,serverRunning:s,dnsActive:c,hasCachedPassword:x,needsSudoPassword:v,isWin:D,apiKeys:N,activeProviders:T,hasActiveProviders:p,modelAliases:j={},cloudEnabled:U,onDnsChange:E}){var Q,V;const[h,A]=r.useState(!1),[w,_]=r.useState(null),[S,i]=r.useState(!1),[n,m]=r.useState(""),[R,u]=r.useState(null),[q,k]=r.useState(null),[g,O]=r.useState({}),[z,F]=r.useState(!1),[M,C]=r.useState(null),a=de[l.id]??[],d=D||x||v===!1;r.useEffect(()=>{b&&L()},[b]);const L=async()=>{try{const t=await fetch(`/api/cli-tools/antigravity-mitm/alias?tool=${l.id}`);if(t.ok){const o=await t.json();Object.keys(o.aliases||{}).length>0&&O(o.aliases)}}catch{}},f=r.useCallback(async t=>{try{await fetch("/api/cli-tools/antigravity-mitm/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:l.id,mappings:t})})}catch{}},[l.id]),P=(t,o)=>{f({...g,[t]:o})},W=(t,o)=>{O(H=>({...H,[t]:o}))},ee=t=>{C(t),F(!0)},se=t=>{if(!M||t.isPlaceholder)return;const o={...g,[M]:t.value};O(o),f(o)},J=()=>{if(!s)return;const t=c?"disable":"enable";d?G(t,""):(u(t),i(!0),k(null))},G=async(t,o)=>{A(!0),_(null);try{const H=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:l.id,action:t,sudoPassword:o})}),X=await H.json();if(!H.ok)throw new Error(X.error||"Failed to toggle DNS");t==="enable"&&_(`Restart ${l.name} to apply changes`),i(!1),m(""),E==null||E(X)}catch{}finally{A(!1),u(null)}},Y=()=>{if(!n.trim()){k("Sudo password is required");return}G(R,n)};return e.jsxs(e.Fragment,{children:[e.jsxs(Z,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:y,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("img",{src:l.image,alt:l.name,width:32,height:32,className:"size-8 object-contain rounded-lg",onError:t=>{t.target.style.display="none"}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:l.name}),s?c?e.jsx(B,{variant:"success",size:"sm",children:"Active"}):e.jsx(B,{variant:"warning",size:"sm",children:"DNS off"}):e.jsx(B,{variant:"default",size:"sm",children:"Server off"})]}),e.jsxs("p",{className:"text-xs text-text-muted sm:truncate",children:["Intercept ",l.name," requests via MITM proxy"]})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${b?"rotate-180":""}`,children:"expand_more"})]}),b&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[a.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-border bg-surface/50 px-2 py-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium tracking-wide text-text-main/80 mb-1",children:"Edit hosts file manually to add the following entries:"}),e.jsx("ul",{className:"list-none space-y-0.5 font-mono text-[10px] text-text-muted break-all",children:a.map(t=>e.jsxs("li",{children:["127.0.0.1 ",t]},t))})]}),e.jsxs("div",{className:"flex flex-col gap-0.5 text-[11px] text-text-muted px-1",children:[e.jsxs("p",{children:["Toggle DNS to redirect ",l.name," traffic through FSRouter via MITM."]}),!c&&e.jsx("p",{className:"text-amber-600 text-[10px] mt-1",children:"⚠️ Enable DNS to edit model mappings"})]}),((Q=l.defaultModels)==null?void 0:Q.length)>0&&e.jsx("div",{className:"flex flex-col gap-2",children:l.defaultModels.map(t=>e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[9rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right",children:t.name}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:g[t.alias]||"",onChange:o=>W(t.alias,o.target.value),onBlur:o=>P(t.alias,o.target.value),placeholder:"provider/model-id",disabled:!c,className:`w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5 ${c?"":"opacity-50 cursor-not-allowed"}`}),g[t.alias]&&e.jsx("button",{onClick:()=>{W(t.alias,""),f({...g,[t.alias]:""})},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>ee(t.alias),disabled:!p||!c,className:`rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 ${p&&c?"bg-surface border-border hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]},t.alias))}),((V=l.defaultModels)==null?void 0:V.length)===0&&e.jsx("p",{className:"text-xs text-text-muted px-1",children:"Model mappings will be available soon."}),e.jsxs("div",{className:"flex flex-col gap-2 sm:items-start",children:[c?e.jsxs("button",{onClick:J,disabled:!s||h,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop DNS"]}):e.jsxs("button",{onClick:J,disabled:!s||h,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start DNS"]}),w&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs text-amber-500",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),e.jsx("span",{children:w})]})]})]})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Required to modify /etc/hosts and flush DNS cache"})]}),e.jsx(K,{type:"password",placeholder:"Enter sudo password",value:n,onChange:t=>m(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!h&&Y()}}),q&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),e.jsx("span",{children:q})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{i(!1),m(""),k(null)},disabled:h,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:Y,loading:h,children:"Confirm"})]})]})}),e.jsx(ne,{isOpen:z,onClose:()=>F(!1),onSelect:se,selectedModel:M?g[M]:null,activeProviders:T,modelAliases:j,title:`Select model for ${M}`})]})}function me(){const[l,b]=r.useState([]),[y,s]=r.useState([]),[c,x]=r.useState({}),[v,D]=r.useState(!1),[N,T]=r.useState(null),[p,j]=r.useState({running:!1,certExists:!1,dnsStatus:{},hasCachedPassword:!1});r.useEffect(()=>{U(),E(),h(),A()},[]);const U=async()=>{try{const i=await fetch("/api/providers");if(i.ok){const n=await i.json();b(n.connections||[])}}catch{}},E=async()=>{try{const i=await fetch("/api/keys");if(i.ok){const n=await i.json();s(n.keys||[])}}catch{}},h=async()=>{try{const i=await fetch("/api/models/alias");if(i.ok){const n=await i.json();x(n.aliases||{})}}catch{}},A=async()=>{try{const i=await fetch("/api/settings");if(i.ok){const n=await i.json();D(n.cloudEnabled||!1)}}catch{}},w=()=>l.filter(i=>i.isActive!==!1),_=()=>w().some(n=>ae(n.provider).length>0||re(n.provider)||le(n.provider)),S=Object.entries(ie);return e.jsxs("div",{className:"flex w-full flex-col gap-6",children:[e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),e.jsx("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:"⚠️ MITM intercepts HTTPS traffic of IDE tools (Antigravity, GitHub Copilot, Kiro) via local CA to redirect requests to your providers. May violate ToS → account ban. Use at your own risk."})]}),e.jsx(oe,{apiKeys:y,cloudEnabled:v,onStatusChange:j}),e.jsx("div",{className:"grid gap-3 sm:gap-4",children:S.map(([i,n])=>{var m;return e.jsx(ce,{tool:n,isExpanded:N===i,onToggle:()=>T(N===i?null:i),serverRunning:p.running,dnsActive:((m=p.dnsStatus)==null?void 0:m[i])||!1,hasCachedPassword:p.hasCachedPassword||!1,needsSudoPassword:p.needsSudoPassword!==!1,isWin:p.isWin===!0,apiKeys:y,activeProviders:w(),hasActiveProviders:_(),modelAliases:c,cloudEnabled:v,onDnsChange:R=>j(u=>({...u,dnsStatus:R.dnsStatus??u.dnsStatus}))},i)})})]})}function ge(){return e.jsx(me,{})}export{ge as default};
|
|
1
|
+
import{j as e,B as I,y as te,h as ae,k as re,l as le}from"./index.Be3gbrBl.js";import{b as r}from"./router.Cjj1--8t.js";import{M as ie}from"./cliTools.CsdwAybi.js";import{C as Z,B,I as K,M as ne}from"./NoAuthProxyCard.BDcXaWvM.js";import"./zustand.akaTi5uX.js";const $=te();function oe({apiKeys:l,cloudEnabled:b,onStatusChange:y}){const[s,c]=r.useState(null),[x,v]=r.useState(!1),[D,N]=r.useState(!1),[T,p]=r.useState(""),[j,U]=r.useState(()=>{var a;return((a=l==null?void 0:l[0])==null?void 0:a.key)||""}),[E,h]=r.useState(null),[A,w]=r.useState(null),[_,S]=r.useState(null),[i,n]=r.useState($),[m,R]=r.useState(null),u=(s==null?void 0:s.isWin)===!0,q=u||(s==null?void 0:s.hasCachedPassword)||(s==null?void 0:s.needsSudoPassword)===!1,k=(s==null?void 0:s.isAdmin)!==!1;!k&&(u||!(s!=null&&s.hasCachedPassword)&&(s==null||s.needsSudoPassword));const g=r.useCallback(async()=>{try{const a=await fetch("/api/cli-tools/antigravity-mitm");if(a.ok){const d=await a.json();c(d),d.mitmRouterBaseUrl&&n(d.mitmRouterBaseUrl),y==null||y(d)}}catch{c({running:!1,certExists:!1,dnsStatus:{}})}},[y]);r.useEffect(()=>{queueMicrotask(()=>{g()})},[g]);const O=a=>{S(null),s&&(q?z(a,""):(h(a),N(!0),w(null)))},z=async(a,d,L=!1)=>{v(!0),S(null);try{let f;if(a==="trust-cert")f=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"trust-cert",sudoPassword:d})});else if(a==="start"){const P=(j==null?void 0:j.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(b?null:"sk_fsrouter");f=await fetch("/api/cli-tools/antigravity-mitm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:P,sudoPassword:d,mitmRouterBaseUrl:i.trim()||$,forceKillPort443:L})})}else f=await fetch("/api/cli-tools/antigravity-mitm",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:d})});if(!f.ok){const P=await f.json().catch(()=>({}));if(P.code==="PORT_443_BUSY"&&P.portOwner){N(!1),R({owner:P.portOwner,password:d});return}S(P.error||`Failed to ${a} MITM server`);return}N(!1),p(""),R(null),await g()}catch(f){S(f.message||"Network error")}finally{v(!1),h(null)}},F=()=>{const a=(m==null?void 0:m.password)||"";z("start",a,!0)},M=()=>{if(!T.trim()){w("Sudo password is required");return}z(E,T)},C=s==null?void 0:s.running;return e.jsxs(e.Fragment,{children:[e.jsx(Z,{padding:"sm",className:"border-primary/20 bg-primary/5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[20px]",children:"security"}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:"MITM Server"}),C?e.jsx(B,{variant:"success",size:"sm",children:"Running"}):e.jsx(B,{variant:"default",size:"sm",children:"Stopped"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1 text-xs text-text-muted","data-i18n-skip":"true",children:[{label:"Cert",ok:s==null?void 0:s.certExists},{label:"Trusted",ok:s==null?void 0:s.certTrusted},{label:"Server",ok:C}].map(({label:a,ok:d})=>e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded ${d?"text-green-600":"text-text-muted"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:d?"check_circle":"cancel"}),a]},a))})]}),e.jsxs("div",{className:"px-2 py-2 rounded-lg bg-surface/50 border border-border/50 flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[e.jsx("span",{className:"font-medium text-text-main",children:"Purpose:"})," Use Antigravity IDE & GitHub Copilot → with ANY provider/model from FSRouter"]}),e.jsxs("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[e.jsx("span",{className:"font-medium text-text-main",children:"How it works:"})," Antigravity/Copilot IDE request → DNS redirect to localhost:443 → MITM proxy intercepts → FSRouter → response to Antigravity/Copilot"]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"FSRouter Base URL"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",value:i,onChange:a=>n(a.target.value),placeholder:$,disabled:C,className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]}),!C&&e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",list:"mitm-api-keys",value:j,onChange:a=>U(a.target.value),placeholder:b?"Enter or pick API key":"sk_fsrouter (default)",className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"}),(l==null?void 0:l.length)>0&&e.jsx("datalist",{id:"mitm-api-keys",children:l.map(a=>e.jsx("option",{value:a.key,children:a.name||a.key},a.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center","data-i18n-skip":"true",children:[(s==null?void 0:s.certExists)&&!(s!=null&&s.certTrusted)&&e.jsxs("button",{onClick:()=>O("trust-cert"),disabled:x,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-xs font-medium text-yellow-600 transition-colors hover:bg-yellow-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"verified_user"}),"Trust Cert"]}),C?e.jsxs("button",{onClick:()=>O("stop"),disabled:x,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop Server"]}):e.jsxs("button",{onClick:()=>O("start"),disabled:x||!s||u&&!k,title:u&&!k?"Administrator required":void 0,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start Server"]}),C&&e.jsx("p",{className:"text-xs text-text-muted",children:"Enable DNS per tool below to activate interception"})]}),_&&e.jsxs("div",{className:"flex items-start gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 dark:text-red-400 border border-red-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mt-0.5 shrink-0",children:"error"}),e.jsx("span",{children:_})]}),u&&!k&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 border border-red-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"shield_lock"}),e.jsx("span",{children:"Administrator required — restart FSRouter as Administrator to use MITM"})]})]})}),D&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Required for SSL certificate and server startup"})]}),e.jsx(K,{type:"password",placeholder:"Enter sudo password",value:T,onChange:a=>p(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!x&&M()}}),A&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),e.jsx("span",{children:A})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{N(!1),p(""),w(null)},disabled:x,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:M,loading:x,children:"Confirm"})]})]})}),m&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Port 443 Already In Use"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsxs("div",{className:"flex flex-col gap-1 text-xs text-text-muted",children:[e.jsx("p",{children:"Port 443 is currently used by another process:"}),e.jsxs("p",{className:"font-mono text-text-main","data-i18n-skip":"true",children:[m.owner.name," (PID ",m.owner.pid,")"]}),e.jsx("p",{children:"Kill this process to start MITM Server?"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{R(null),v(!1)},disabled:x,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:F,loading:x,children:"Kill & Start"})]})]})})]})}const de={antigravity:["daily-cloudcode-pa.googleapis.com","cloudcode-pa.googleapis.com"],copilot:["api.individual.githubcopilot.com"],kiro:["q.us-east-1.amazonaws.com","codewhisperer.us-east-1.amazonaws.com"],cursor:["api2.cursor.sh"]};function ce({tool:l,isExpanded:b,onToggle:y,serverRunning:s,dnsActive:c,hasCachedPassword:x,needsSudoPassword:v,isWin:D,apiKeys:N,activeProviders:T,hasActiveProviders:p,modelAliases:j={},cloudEnabled:U,onDnsChange:E}){var Q,V;const[h,A]=r.useState(!1),[w,_]=r.useState(null),[S,i]=r.useState(!1),[n,m]=r.useState(""),[R,u]=r.useState(null),[q,k]=r.useState(null),[g,O]=r.useState({}),[z,F]=r.useState(!1),[M,C]=r.useState(null),a=de[l.id]??[],d=D||x||v===!1;r.useEffect(()=>{b&&L()},[b]);const L=async()=>{try{const t=await fetch(`/api/cli-tools/antigravity-mitm/alias?tool=${l.id}`);if(t.ok){const o=await t.json();Object.keys(o.aliases||{}).length>0&&O(o.aliases)}}catch{}},f=r.useCallback(async t=>{try{await fetch("/api/cli-tools/antigravity-mitm/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:l.id,mappings:t})})}catch{}},[l.id]),P=(t,o)=>{f({...g,[t]:o})},W=(t,o)=>{O(H=>({...H,[t]:o}))},ee=t=>{C(t),F(!0)},se=t=>{if(!M||t.isPlaceholder)return;const o={...g,[M]:t.value};O(o),f(o)},J=()=>{if(!s)return;const t=c?"disable":"enable";d?G(t,""):(u(t),i(!0),k(null))},G=async(t,o)=>{A(!0),_(null);try{const H=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:l.id,action:t,sudoPassword:o})}),X=await H.json();if(!H.ok)throw new Error(X.error||"Failed to toggle DNS");t==="enable"&&_(`Restart ${l.name} to apply changes`),i(!1),m(""),E==null||E(X)}catch{}finally{A(!1),u(null)}},Y=()=>{if(!n.trim()){k("Sudo password is required");return}G(R,n)};return e.jsxs(e.Fragment,{children:[e.jsxs(Z,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:y,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("img",{src:l.image,alt:l.name,width:32,height:32,className:"size-8 object-contain rounded-lg",onError:t=>{t.target.style.display="none"}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:l.name}),s?c?e.jsx(B,{variant:"success",size:"sm",children:"Active"}):e.jsx(B,{variant:"warning",size:"sm",children:"DNS off"}):e.jsx(B,{variant:"default",size:"sm",children:"Server off"})]}),e.jsxs("p",{className:"text-xs text-text-muted sm:truncate",children:["Intercept ",l.name," requests via MITM proxy"]})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${b?"rotate-180":""}`,children:"expand_more"})]}),b&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[a.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-border bg-surface/50 px-2 py-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium tracking-wide text-text-main/80 mb-1",children:"Edit hosts file manually to add the following entries:"}),e.jsx("ul",{className:"list-none space-y-0.5 font-mono text-[10px] text-text-muted break-all",children:a.map(t=>e.jsxs("li",{children:["127.0.0.1 ",t]},t))})]}),e.jsxs("div",{className:"flex flex-col gap-0.5 text-[11px] text-text-muted px-1",children:[e.jsxs("p",{children:["Toggle DNS to redirect ",l.name," traffic through FSRouter via MITM."]}),!c&&e.jsx("p",{className:"text-amber-600 text-[10px] mt-1",children:"⚠️ Enable DNS to edit model mappings"})]}),((Q=l.defaultModels)==null?void 0:Q.length)>0&&e.jsx("div",{className:"flex flex-col gap-2",children:l.defaultModels.map(t=>e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[9rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right",children:t.name}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:g[t.alias]||"",onChange:o=>W(t.alias,o.target.value),onBlur:o=>P(t.alias,o.target.value),placeholder:"provider/model-id",disabled:!c,className:`w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5 ${c?"":"opacity-50 cursor-not-allowed"}`}),g[t.alias]&&e.jsx("button",{onClick:()=>{W(t.alias,""),f({...g,[t.alias]:""})},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>ee(t.alias),disabled:!p||!c,className:`rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 ${p&&c?"bg-surface border-border hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]},t.alias))}),((V=l.defaultModels)==null?void 0:V.length)===0&&e.jsx("p",{className:"text-xs text-text-muted px-1",children:"Model mappings will be available soon."}),e.jsxs("div",{className:"flex flex-col gap-2 sm:items-start",children:[c?e.jsxs("button",{onClick:J,disabled:!s||h,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop DNS"]}):e.jsxs("button",{onClick:J,disabled:!s||h,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start DNS"]}),w&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs text-amber-500",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),e.jsx("span",{children:w})]})]})]})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Required to modify /etc/hosts and flush DNS cache"})]}),e.jsx(K,{type:"password",placeholder:"Enter sudo password",value:n,onChange:t=>m(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!h&&Y()}}),q&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),e.jsx("span",{children:q})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{i(!1),m(""),k(null)},disabled:h,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:Y,loading:h,children:"Confirm"})]})]})}),e.jsx(ne,{isOpen:z,onClose:()=>F(!1),onSelect:se,selectedModel:M?g[M]:null,activeProviders:T,modelAliases:j,title:`Select model for ${M}`})]})}function me(){const[l,b]=r.useState([]),[y,s]=r.useState([]),[c,x]=r.useState({}),[v,D]=r.useState(!1),[N,T]=r.useState(null),[p,j]=r.useState({running:!1,certExists:!1,dnsStatus:{},hasCachedPassword:!1});r.useEffect(()=>{U(),E(),h(),A()},[]);const U=async()=>{try{const i=await fetch("/api/providers");if(i.ok){const n=await i.json();b(n.connections||[])}}catch{}},E=async()=>{try{const i=await fetch("/api/keys");if(i.ok){const n=await i.json();s(n.keys||[])}}catch{}},h=async()=>{try{const i=await fetch("/api/models/alias");if(i.ok){const n=await i.json();x(n.aliases||{})}}catch{}},A=async()=>{try{const i=await fetch("/api/settings");if(i.ok){const n=await i.json();D(n.cloudEnabled||!1)}}catch{}},w=()=>l.filter(i=>i.isActive!==!1),_=()=>w().some(n=>ae(n.provider).length>0||re(n.provider)||le(n.provider)),S=Object.entries(ie);return e.jsxs("div",{className:"flex w-full flex-col gap-6",children:[e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),e.jsx("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:"⚠️ MITM intercepts HTTPS traffic of IDE tools (Antigravity, GitHub Copilot, Kiro) via local CA to redirect requests to your providers. May violate ToS → account ban. Use at your own risk."})]}),e.jsx(oe,{apiKeys:y,cloudEnabled:v,onStatusChange:j}),e.jsx("div",{className:"grid gap-3 sm:gap-4",children:S.map(([i,n])=>{var m;return e.jsx(ce,{tool:n,isExpanded:N===i,onToggle:()=>T(N===i?null:i),serverRunning:p.running,dnsActive:((m=p.dnsStatus)==null?void 0:m[i])||!1,hasCachedPassword:p.hasCachedPassword||!1,needsSudoPassword:p.needsSudoPassword!==!1,isWin:p.isWin===!0,apiKeys:y,activeProviders:w(),hasActiveProviders:_(),modelAliases:c,cloudEnabled:v,onDnsChange:R=>j(u=>({...u,dnsStatus:R.dnsStatus??u.dnsStatus}))},i)})})]})}function ge(){return e.jsx(me,{})}export{ge as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{K as g,j as e,B as P,g as w,P as C}from"./index.
|
|
1
|
+
import{K as g,j as e,B as P,g as w,P as C}from"./index.Be3gbrBl.js";import{d as z,b as p,L as k}from"./router.Cjj1--8t.js";import{C as y,B as b}from"./NoAuthProxyCard.BDcXaWvM.js";import"./zustand.akaTi5uX.js";function v(t){const a=Object.entries(t).some(([n,r])=>n.startsWith("modelLock_")&&r&&new Date(r).getTime()>Date.now());return t.testStatus==="unavailable"&&!a?"active":t.testStatus}function F({provider:t,kind:a,connections:n}){var c;const r=w[t.id],i=!!(r!=null&&r.noAuth),s=n.filter(o=>o.provider===t.id),m=s.filter(o=>{const l=v(o);return l==="active"||l==="success"}).length,d=s.filter(o=>{const l=v(o);return l==="error"||l==="expired"||l==="unavailable"}).length,x=s.length,f=x>0&&s.every(o=>o.isActive===!1),u=()=>i?e.jsx(b,{variant:"success",size:"sm",children:"Ready"}):f?e.jsx(b,{variant:"default",size:"sm",children:"Disabled"}):x===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No connections"}):e.jsxs(e.Fragment,{children:[m>0&&e.jsxs(b,{variant:"success",size:"sm",dot:!0,children:[m," Connected"]}),d>0&&e.jsxs(b,{variant:"error",size:"sm",dot:!0,children:[d," Error"]}),m===0&&d===0&&e.jsxs(b,{variant:"default",size:"sm",children:[x," Added"]})]});return e.jsx(k,{to:`/dashboard/media-providers/${a}/${t.id}`,className:"group",children:e.jsx(y,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${f?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${((c=t.color)==null?void 0:c.length)>7?t.color:(t.color??"#888")+"15"}`},children:e.jsx(C,{src:`/providers/${t.id}.png`,alt:t.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:t.textIcon||t.id.slice(0,2).toUpperCase(),fallbackColor:t.color})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:t.name}),e.jsx("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:u()})]})]})})})}function A({combos:t}){return t.length===0?e.jsx("p",{className:"text-xs text-text-muted italic",children:"No combos yet."}):e.jsx("div",{className:"flex flex-col gap-2",children:t.map(a=>e.jsx(k,{to:`/dashboard/media-providers/combo/${a.id}`,children:e.jsx(y,{padding:"xs",className:"hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors cursor-pointer",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"}),e.jsx("code",{className:"text-sm font-mono font-medium flex-1 truncate",children:a.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:shrink-0",children:[a.models.slice(0,6).map((n,r)=>{const i=typeof n=="string"?n.split("/")[0]:"",s=w[i];return e.jsx("div",{title:(s==null?void 0:s.name)||n,className:"size-5 rounded flex items-center justify-center",style:{backgroundColor:`${(s==null?void 0:s.color)??"#888"}15`},children:e.jsx(C,{src:`/providers/${i}.png`,alt:(s==null?void 0:s.name)||i,size:18,className:"object-contain rounded max-w-[18px] max-h-[18px]",fallbackText:(s==null?void 0:s.textIcon)||i.slice(0,2).toUpperCase(),fallbackColor:s==null?void 0:s.color})},`${n}-${r}`)}),a.models.length>6&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1",children:["+",a.models.length-6]})]}),e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:a.models.length}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[16px]",children:"chevron_right"})]})})},a.id))})}function N({title:t,icon:a,kind:n,providers:r,connections:i,combos:s,onCreateCombo:m}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:a}),e.jsx("h2",{className:"text-base font-semibold",children:t}),e.jsxs("span",{className:"text-xs text-text-muted",children:["(",r.length," providers · ",s.length," combos)"]})]}),e.jsx(P,{size:"sm",icon:"add",onClick:m,children:"Create Combo"})]}),s.length>0&&e.jsx("div",{className:"mb-4",children:e.jsx(A,{combos:s})}),r.length===0?e.jsx("div",{className:"text-center py-8 border border-dashed border-border rounded-xl text-text-muted text-sm",children:"No providers."}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:r.map(d=>e.jsx(F,{provider:d,kind:n,connections:i},d.id))})]})}function T(){const t=z(),[a,n]=p.useState([]),[r,i]=p.useState([]),s=async()=>{try{const[c,o]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/combos",{cache:"no-store"})]);c.ok&&n((await c.json()).connections||[]),o.ok&&i((await o.json()).combos||[])}catch{}};p.useEffect(()=>{s()},[]);const m=g("webSearch"),d=g("webFetch"),x=r.filter(c=>c.kind==="webSearch"),f=r.filter(c=>c.kind==="webFetch"),u=async c=>{const o=c==="webSearch"?"search-combo":"fetch-combo";let l=o,S=1;const $=new Set(r.map(h=>h.name));for(;$.has(l);)l=`${o}-${S++}`;const j=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:l,models:[],kind:c})});if(j.ok){const h=await j.json();t(`/dashboard/media-providers/combo/${h.id}`)}else{const h=await j.json();alert(h.error||"Failed to create combo")}};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(N,{title:"Web Search",icon:"search",kind:"webSearch",providers:m,connections:a,combos:x,onCreateCombo:()=>u("webSearch")}),e.jsx("div",{className:"border-t border-border"}),e.jsx(N,{title:"Web Fetch",icon:"travel_explore",kind:"webFetch",providers:d,connections:a,combos:f,onCreateCombo:()=>u("webFetch")})]})}export{T as default};
|
package/public/index.html
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
11
11
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
12
12
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
|
|
13
|
-
<script type="module" crossorigin src="/assets/index.
|
|
13
|
+
<script type="module" crossorigin src="/assets/index.Be3gbrBl.js"></script>
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/router.Cjj1--8t.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/zustand.akaTi5uX.js">
|
|
16
|
-
<link rel="stylesheet" crossorigin href="/assets/index.
|
|
16
|
+
<link rel="stylesheet" crossorigin href="/assets/index.COMgQZYj.css">
|
|
17
17
|
</head>
|
|
18
18
|
<body>
|
|
19
19
|
<div id="root"></div>
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{r as Lt,v as Us,u as As,j as e,B as c,M as B,C as Rs,f as Is}from"./index.CShjRV_B.js";import{b as a}from"./router.Cjj1--8t.js";import{C as Ze,I as G,T as L}from"./NoAuthProxyCard.qAv57b-0.js";import{C as _t}from"./Loading.Bj-WGl4k.js";const Ds=["zh-CN","zh-TW"],Os=[{icon:"public",title:"Access Anywhere",desc:"Use your API from any network"},{icon:"group",title:"Share Endpoint",desc:"Share URL with team members"},{icon:"code",title:"Use in Cursor/Cline",desc:"Connect AI tools remotely"},{icon:"lock",title:"Encrypted",desc:"End-to-end TLS via Cloudflare"}],et=2e3,Ut=3e5,Hs=5e3,tt=5,Ms=1e4,Fs=5e3;async function At(h){if(!h)return!1;try{return(await fetch(`${h}/api/health`,{mode:"cors",cache:"no-store",signal:AbortSignal.timeout(Fs)})).ok}catch{return!1}}async function Ks(...h){const d=h.filter(Boolean).map(At);return d.length?new Promise(x=>{let j=d.length;d.forEach(R=>R.then(g=>{g?x(!0):--j===0&&x(!1)}))}):!1}const ke=[{id:"lite",label:"Lite",desc:"Drop filler, keep grammar"},{id:"full",label:"Full",desc:"Drop articles, fragments OK"},{id:"ultra",label:"Ultra",desc:"Telegraphic, max compression"},{id:"wenyan-lite",label:"文 Lite",desc:"Classical Chinese, light compression",wenyan:!0},{id:"wenyan",label:"文 Full",desc:"Maximum 文言文, 80-90% reduction",wenyan:!0},{id:"wenyan-ultra",label:"文 Ultra",desc:"Extreme classical compression",wenyan:!0}];function Ws({machineId:h}){var Pt;const[d,x]=a.useState([]),[j,R]=a.useState(!0),[g,C]=a.useState(!1),[ne,le]=a.useState(""),[Te,Se]=a.useState(null),[w,J]=a.useState(null),[re,st]=a.useState(!1),[V,Rt]=a.useState(!0),[at,It]=a.useState(!0),[nt,lt]=a.useState(!1),[rt,it]=a.useState(!0),[Ee,ot]=a.useState(!1),[ie,Pe]=a.useState("full"),[Le,ct]=a.useState(!1),[_e,Ue]=a.useState(""),[Dt,dt]=a.useState(!1),[I,Ae]=a.useState({installed:!1,running:!1,python:null,loading:!0}),[Bs,Gs]=a.useState(!1),[oe,ce]=a.useState(!1),[Js,mt]=a.useState(""),[Re,ut]=a.useState(!1),[Ie,ht]=a.useState("full"),[De,xt]=a.useState(!1),[Oe,pt]=a.useState("full"),[Ot,ft]=a.useState("en"),[Ht,He]=a.useState(!0),[p,de]=a.useState(!1),[D,me]=a.useState(!1),[O,ue]=a.useState(""),[H,Me]=a.useState(""),[_,T]=a.useState(!1),[Mt,S]=a.useState(""),[he,N]=a.useState(null),[Ft,Y]=a.useState(!1),[Kt,X]=a.useState(!1),[f,M]=a.useState(!1),[F,xe]=a.useState(!1),[K,W]=a.useState(""),[U,Q]=a.useState(!1),[Wt,A]=a.useState(""),[q,m]=a.useState(null),[bt,gt]=a.useState(""),[qt,yt]=a.useState(""),[Fe,pe]=a.useState(null),[fe,Ke]=a.useState(!1),[We,qe]=a.useState([]),[$t,jt]=a.useState(""),[zt,$e]=a.useState(!1),[Bt,$]=a.useState(!1),[Gt,Z]=a.useState(!1),be=a.useRef(null),ee=a.useRef(0),te=a.useRef(0),ge=a.useRef(!1),ye=a.useRef(!1),je=a.useRef(!1),we=a.useRef(!1),[Jt,ze]=a.useState(!1),[Vt,Be]=a.useState(!1),[Ge,wt]=a.useState(new Set),[Yt,Xt]=a.useState(!1);a.useEffect(()=>{typeof window<"u"&&Xt(!["localhost","127.0.0.1","::1"].includes(window.location.hostname))},[]),a.useEffect(()=>(ft(Lt()),Us(()=>ft(Lt()))),[]);const Je=Ds.includes(Ot),Qt=Je?ke:ke.filter(t=>!t.wenyan);a.useEffect(()=>{const t=ke.find(s=>s.id===ie);t!=null&&t.wenyan&&!Je&&(Pe("ultra"),v({cavemanLevel:"ultra"}))},[Je,ie]);const{copied:z,copy:se}=As(),Zt=!V||!at,es=V?"Change the default dashboard password before activating the tunnel.":'Enable "Require login" and set a custom password before activating the tunnel.';a.useEffect(()=>{be.current&&(be.current.scrollTop=be.current.scrollHeight)},[We]),a.useEffect(()=>{vt(),ts()},[]),a.useEffect(()=>{if(!(p||f))return;const n=(!p||D)&&(!f||F),r=()=>{document.hidden||Nt()};if(document.addEventListener("visibilitychange",r),n)return()=>document.removeEventListener("visibilitychange",r);const o=setInterval(()=>{document.hidden||Nt()},Hs);return()=>{clearInterval(o),document.removeEventListener("visibilitychange",r)}},[p,f,D,F]),a.useEffect(()=>{const t=async()=>{if(!document.hidden){if(p&&(O||H)){const o=await Ks(H,O);ge.current=o,o?(ee.current=0,me(!0),je.current||(je.current=!0,ze(!0))):(ee.current+=1,ee.current>=tt&&me(!1))}else ge.current=!1;if(f&&K){const o=await At(K);ye.current=o,o?(te.current=0,xe(!0),we.current||(we.current=!0,Be(!0))):(te.current+=1,te.current>=tt&&xe(!1))}else ye.current=!1}};if(!(p&&(O||H)||f&&K)||(t(),(!p||D)&&(!f||F)))return;const r=setInterval(t,Ms);return()=>clearInterval(r)},[p,O,H,f,K,D,F]);const Ne=a.useCallback((t,s,l,n,r,o)=>{s.current?(l.current=0,n(!0),r.current||(r.current=!0,o(!0))):(l.current+=1,l.current>=tt&&n(!1))},[]),Nt=async()=>{var t,s,l,n,r,o,u;try{const y=await fetch("/api/tunnel/status",{cache:"no-store"});if(!y.ok)return;const b=await y.json(),i=((t=b.tunnel)==null?void 0:t.settingsEnabled)??((s=b.tunnel)==null?void 0:s.enabled)??!1,P=((l=b.tunnel)==null?void 0:l.tunnelUrl)||"";ue(P),Me(((n=b.tunnel)==null?void 0:n.publicUrl)||""),de(i),Ne(null,ge,ee,me,je,ze);const k=((r=b.tailscale)==null?void 0:r.settingsEnabled)??((o=b.tailscale)==null?void 0:o.enabled)??!1,Qe=((u=b.tailscale)==null?void 0:u.tunnelUrl)||"";W(Qe),M(k),Ne(null,ye,te,xe,we,Be)}catch{}},ts=async()=>{var t,s,l,n,r,o,u;He(!0);try{const[y,b]=await Promise.all([fetch("/api/settings"),fetch("/api/tunnel/status",{cache:"no-store"})]);if(y.ok){const i=await y.json();st(i.requireApiKey||!1),Rt(i.requireLogin!==!1),It(i.hasPassword||!1),lt(i.tunnelDashboardAccess||!1),it(i.rtkEnabled!==!1),ot(!!i.cavemanEnabled),Pe(i.cavemanLevel||"full"),ct(!!i.headroomEnabled),Ue(i.headroomUrl||""),dt(!!i.headroomCompressUserMessages),ut(!!i.ponytailEnabled),ht(i.ponytailLevel||"full"),xt(!!i.paleoEnabled),pt(i.paleoLevel||"full"),ae()}if(b.ok){const i=await b.json(),P=((t=i.tunnel)==null?void 0:t.settingsEnabled)??((s=i.tunnel)==null?void 0:s.enabled)??!1,k=((l=i.tunnel)==null?void 0:l.tunnelUrl)||"";ue(k),Me(((n=i.tunnel)==null?void 0:n.publicUrl)||""),de(P),Ne(null,ge,ee,me,je,ze);const Qe=((r=i.tailscale)==null?void 0:r.settingsEnabled)??((o=i.tailscale)==null?void 0:o.enabled)??!1,_s=((u=i.tailscale)==null?void 0:u.tunnelUrl)||"";W(_s),M(Qe),Ne(null,ye,te,xe,we,Be)}}catch(y){console.log("Error loading settings:",y)}finally{He(!1)}},ss=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tunnelDashboardAccess:t})})).ok&<(t)}catch(s){console.log("Error updating tunnelDashboardAccess:",s)}},as=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({requireApiKey:t})})).ok&&st(t)}catch(s){console.log("Error updating requireApiKey:",s)}},ns=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({rtkEnabled:t})})).ok&&it(t)}catch(s){console.log("Error updating rtkEnabled:",s)}},v=async t=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(s){console.log("Error updating setting:",s)}},ls=t=>{ot(t),v({cavemanEnabled:t})},rs=t=>{Pe(t),v({cavemanLevel:t})},is=t=>{ct(t),v({headroomEnabled:t})},os=t=>{Ue(t),v({headroomUrl:t})},cs=t=>{dt(t),v({headroomCompressUserMessages:t})},ae=a.useCallback(async()=>{Ae(t=>({...t,loading:!0}));try{const s=await(await fetch("/api/headroom/status",{headers:{"Cache-Control":"no-store"}})).json();Ae({...s,loading:!1}),s.url&&!_e&&Ue(s.url)}catch{Ae({installed:!1,running:!1,python:null,loading:!1})}},[_e]),ds=a.useCallback(async()=>{mt(""),ce(!0);try{const t=await fetch("/api/headroom/start",{method:"POST"}),s=await t.json().catch(()=>({}));if(!t.ok)throw new Error(s.error||"Failed to start proxy");await ae()}catch(t){mt(t.message)}finally{ce(!1)}},[ae]),ms=a.useCallback(async()=>{ce(!0);try{await fetch("/api/headroom/stop",{method:"POST"}),await ae()}finally{ce(!1)}},[ae]),us=t=>{ut(t),v({ponytailEnabled:t})},hs=t=>{ht(t),v({ponytailLevel:t})},xs=t=>{xt(t),v({paleoEnabled:t})},ps=t=>{pt(t),v({paleoLevel:t})},vt=async()=>{try{const t=await fetch("/api/keys"),s=await t.json();t.ok&&x(s.keys||[])}catch(t){console.log("Error fetching data:",t)}finally{R(!1)}},fs=async(...t)=>{var n;T(!0),S("Waiting for tunnel ready...");const s=t.filter(Boolean).map(r=>`${r}/api/health`),l=Date.now();for(;Date.now()-l<Ut;){if(await new Promise(o=>setTimeout(o,et)),await Promise.any(s.map(async o=>{if((await fetch(o,{mode:"cors",cache:"no-store"})).ok)return!0;throw new Error("not ready")})).catch(()=>!1))return de(!0),T(!1),S(""),!0;if((Date.now()-l)%1e4<et)try{const o=await fetch("/api/tunnel/status");if(o.ok&&!((n=(await o.json()).tunnel)!=null&&n.enabled))return N({type:"error",message:"Tunnel process stopped unexpectedly."}),T(!1),S(""),!1}catch{}}return N({type:"error",message:"Tunnel created but not reachable. Please try again."}),T(!1),S(""),!1},bs=async()=>{Y(!1),T(!0),N(null),S("Creating tunnel...");let t=!0;(async()=>{var l;for(;t;){try{const n=await fetch("/api/tunnel/status");if(n.ok){const r=await n.json();(l=r.download)!=null&&l.downloading?S(`Downloading cloudflared... ${r.download.progress}%`):t&&S("Creating tunnel...")}}catch{}await new Promise(n=>setTimeout(n,1e3))}})();try{const l=await fetch("/api/tunnel/enable",{method:"POST"});t=!1;const n=await l.json();if(!l.ok){N({type:"error",message:n.error||"Failed to enable tunnel"});return}const r=n.tunnelUrl;if(!r){N({type:"error",message:"No tunnel URL returned"});return}ue(r),Me(n.publicUrl||""),await fs(n.publicUrl,r)}catch(l){N({type:"error",message:l.message})}finally{t=!1,T(!1),S("")}},gs=async()=>{T(!0),N(null);try{const t=await fetch("/api/tunnel/disable",{method:"POST"}),s=await t.json();t.ok?(de(!1),ue(""),X(!1),N({type:"success",message:"Tunnel disabled"})):N({type:"error",message:s.error||"Failed to disable tunnel"})}catch(t){N({type:"error",message:t.message})}finally{T(!1)}},ys=async()=>{pe(null);try{const t=await fetch("/api/tunnel/tailscale-check");if(t.ok){const s=await t.json();return pe(s.installed),s}}catch{}return pe(!1),{installed:!1}},js=async()=>{Ke(!0),m(null),qe([]);try{const t=await fetch("/api/tunnel/tailscale-install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:$t})});jt("");const s=t.body.getReader(),l=new TextDecoder;let n="";for(;;){const{done:r,value:o}=await s.read();if(r)break;n+=l.decode(o,{stream:!0});const u=n.split(`
|
|
2
|
-
|
|
3
|
-
`);n=u.pop()||"";for(const y of u){const b=y.split(`
|
|
4
|
-
`);let i="progress",P=null;for(const k of b)if(k.startsWith("event: ")&&(i=k.slice(7).trim()),k.startsWith("data: "))try{P=JSON.parse(k.slice(6))}catch{}if(P)if(i==="progress")qe(k=>[...k.slice(-50),P.message]);else if(i==="done"){pe(!0),Ke(!1),$(!1),Ye();return}else i==="error"&&m({type:"error",message:P.error||"Install failed"})}}}catch(t){m({type:"error",message:t.message})}finally{Ke(!1)}},Ve=async t=>{A("Waiting for Tailscale ready...");const s=`${t}/api/health`,l=Date.now();for(;Date.now()-l<Ut;){await new Promise(n=>setTimeout(n,et));try{const n=await fetch(s,{mode:"no-cors",cache:"no-store"});if(n.ok||n.type==="opaque")return!0}catch{}}return!1},kt=(t,s)=>{gt(t),yt(s)},E=()=>{gt(""),yt("")},Ye=async()=>{$(!1),$e(!0),Q(!0),m(null),A("Connecting..."),E();try{const t=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),s=await t.json();if(t.ok&&s.success){W(s.tunnelUrl||"");const l=await Ve(s.tunnelUrl);M(!0),m(l?null:{type:"warning",message:"Connected but not reachable yet."});return}if(s.needsLogin&&s.authUrl){kt(s.authUrl,"Open Login Page"),A('Login required — click "Open Login Page" to continue');for(let l=0;l<40;l++){await new Promise(n=>setTimeout(n,3e3));try{const n=await fetch("/api/tunnel/tailscale-check");if(n.ok&&(await n.json()).loggedIn){E(),A("Starting funnel...");const o=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),u=await o.json();if(o.ok&&u.success){W(u.tunnelUrl||"");const y=await Ve(u.tunnelUrl);M(!0),m(y?null:{type:"warning",message:"Connected but not reachable yet."})}else u.funnelNotEnabled&&u.enableUrl?await Ct(u.enableUrl):m({type:"error",message:u.error||"Failed to start funnel"});return}}catch{}}E(),m({type:"error",message:"Login timed out. Please try again."});return}if(s.funnelNotEnabled&&s.enableUrl){await Ct(s.enableUrl);return}m({type:"error",message:s.error||"Failed to connect"})}catch(t){m({type:"error",message:t.message})}finally{Q(!1),$e(!1),A(""),E()}},Ct=async t=>{kt(t,"Open Funnel Settings"),A('Click "Open Funnel Settings" to enable Funnel...');for(let s=0;s<40;s++){await new Promise(l=>setTimeout(l,3e3));try{const l=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),n=await l.json();if(l.ok&&n.success){E(),W(n.tunnelUrl||"");const r=await Ve(n.tunnelUrl);M(!0),m(r?null:{type:"warning",message:"Connected but not reachable yet."});return}if(n.funnelNotEnabled)continue;if(n.error){E(),m({type:"error",message:n.error});return}}catch{}}E(),m({type:"error",message:"Timed out waiting for Funnel to be enabled."})},ws=async()=>{Q(!0),m(null);try{const t=await fetch("/api/tunnel/tailscale-disable",{method:"POST"}),s=await t.json();t.ok?(M(!1),W(""),Z(!1),m({type:"success",message:"Tailscale disabled"})):m({type:"error",message:s.error||"Failed to disable Tailscale"})}catch(t){m({type:"error",message:t.message})}finally{Q(!1)}},Tt=async()=>{m(null),qe([]);const t=await ys();t!=null&&t.installed&&(t!=null&&t.hasCachedPassword)?Ye():$(!0)},Ns=async()=>{if(ne.trim())try{const t=await fetch("/api/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne})}),s=await t.json();t.ok&&(Se(s.key),await vt(),le(""),C(!1))}catch(t){console.log("Error creating key:",t)}},vs=async t=>{J({title:"Delete API Key",message:"Delete this API key?",onConfirm:async()=>{J(null);try{(await fetch(`/api/keys/${t}`,{method:"DELETE"})).ok&&(x(d.filter(l=>l.id!==t)),wt(l=>{const n=new Set(l);return n.delete(t),n}))}catch(s){console.log("Error deleting key:",s)}}})},St=async(t,s)=>{try{(await fetch(`/api/keys/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:s})})).ok&&x(n=>n.map(r=>r.id===t?{...r,isActive:s}:r))}catch(l){console.log("Error toggling key:",l)}},ks=t=>t?t.length>8?t.slice(0,8)+"...":t:"",Cs=t=>{wt(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},[Ts,Ss]=a.useState("/v1");if(a.useEffect(()=>{typeof window<"u"&&Ss(`${window.location.origin}/v1`)},[]),j)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(_t,{}),e.jsx(_t,{})]});const Es=Ts,ve=!!I.running,Xe=I.localUrl!==!1,Et=!!I.canStart,Ps=Xe&&!!I.managedPid,Ls=I.loading?"Checking…":ve?"Running":Xe&&!I.installed?"Not installed":Xe?"Proxy off":"Unreachable";return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsxs(Ze,{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"api"}),"API Endpoint"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qs,{label:"Local",url:Es,copyId:"local_url",copied:z,onCopy:se}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${p?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tunnel"}),p&&!_&&D?e.jsxs(e.Fragment,{children:[e.jsx(G,{value:`${H||O}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>se(`${H||O}/v1`,"tunnel_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:z==="tunnel_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):p&&!_&&!D?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Jt?"Tunnel reconnecting...":"Tunnel checking..."]}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Mt||"Creating tunnel..."]}),e.jsx("button",{onClick:()=>{T(!1),S("")},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(he==null?void 0:he.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),he.message]}),e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>Y(!0),children:"Enable"})]}):Ht?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),e.jsx("button",{onClick:()=>He(!1),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>{Y(!0)},children:"Enable"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${f?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tailscale"}),f&&!U&&F?e.jsxs(e.Fragment,{children:[e.jsx(G,{value:`${K}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>se(`${K}/v1`,"ts_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:z==="ts_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>Z(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):f&&!U&&!F?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Vt?"Tailscale reconnecting...":"Tailscale checking..."]}),e.jsx("button",{onClick:()=>Z(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):U||zt?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Wt||"Connecting..."]}),bt&&e.jsx(c,{size:"sm",icon:"open_in_new",onClick:()=>window.open(bt,"tailscale_auth","width=600,height=700,noopener,noreferrer"),children:qt||"Open"}),e.jsx("button",{onClick:()=>{Q(!1),$e(!1),A(""),E()},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(q==null?void 0:q.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),q.message]}),e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:Tt,children:"Enable"})]}):e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:()=>{Tt()},className:"bg-linear-to-r from-indigo-500 to-purple-500 hover:from-indigo-600 hover:to-purple-600 text-white!",children:"Enable"})]})]}),Zt&&!p&&!f&&e.jsx("div",{className:"mt-4",children:e.jsx(Ce,{message:es,action:{label:"Open settings",href:"/dashboard/profile"}})}),(p||f)&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[!re&&e.jsx(Ce,{message:"Require API key is disabled — your endpoint is publicly accessible without authentication.",action:{label:"Enable",href:"#require-api-key"}}),(!V||!at)&&e.jsx(Ce,{message:V?"Dashboard uses the default password — change it in Profile settings.":"Require login is disabled — anyone can access your dashboard via tunnel.",action:{label:V?"Change password":"Enable",href:"/dashboard/profile"}})]}),(p||f)&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex items-center gap-3",children:[e.jsx(L,{checked:nt,onChange:()=>ss(!nt)}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"font-medium text-sm",children:"Allow dashboard access via tunnel"}),e.jsx(zs,{text:"When enabled, the dashboard can be accessed through your tunnel or Tailscale URL (login still required). When disabled, dashboard access via tunnel/Tailscale is completely blocked."})]})]})]}),e.jsxs(Ze,{id:"rtk",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"bolt"}),"Token Saver"]})}),e.jsxs("div",{className:"flex items-center justify-between pt-2 pb-4 border-b border-border gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Compress tool output"," ",e.jsx("a",{href:"https://github.com/rtk-ai/rtk",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(RTK)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"git/grep/ls/tree/logs → 60-90% fewer input tokens"})]}),e.jsx(L,{checked:rt,onChange:()=>ns(!rt)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Compress LLM output"," ",e.jsx("a",{href:"https://github.com/JuliusBrussee/caveman",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Caveman)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Terse-style system prompt → ~65% fewer output tokens (up to 87%)"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Ee&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:Qt.map(t=>e.jsx("button",{onClick:()=>rs(t.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${ie===t.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t.desc,children:t.label},t.id))}),e.jsx("p",{className:"text-xs text-primary",children:(Pt=ke.find(t=>t.id===ie))==null?void 0:Pt.desc})]}),e.jsx(L,{checked:Ee,onChange:()=>ls(!Ee)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 pb-4 border-t border-border gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Code minimalism"," ",e.jsx("a",{href:"https://github.com/DietrichGebert/ponytail",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Ponytail)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Lazy senior dev system prompt → YAGNI / stdlib-first / shortest diff"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Re&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:["lite","full","ultra"].map(t=>e.jsx("button",{onClick:()=>hs(t),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${Ie===t?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t==="lite"?"Build what's asked, name lazier alternative":t==="full"?"Enforce ladder, shortest diff":"YAGNI extremist, deletion before addition",children:t==="lite"?"Lite":t==="full"?"Full":"Ultra"},t))}),e.jsx("p",{className:"text-xs text-primary",children:Ie==="lite"?"Build what's asked, name lazier alternative":Ie==="full"?"Enforce ladder, shortest diff":"YAGNI extremist, deletion before addition"})]}),e.jsx(L,{checked:Re,onChange:()=>us(!Re)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Token Saver"," ",e.jsx("a",{href:"https://github.com/mocasus/paleo",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Paleo)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Compress LLM output → ~50-80% fewer output tokens"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[De&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:["lite","full","ultra"].map(t=>e.jsx("button",{onClick:()=>ps(t),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${Oe===t?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t==="lite"?"Gentle hints, keep grammar":t==="full"?"Strong compression, fragments OK":"Telegraphic, max savings",children:t==="lite"?"Lite":t==="full"?"Full":"Ultra"},t))}),e.jsx("p",{className:"text-xs text-primary",children:Oe==="lite"?"Gentle hints, keep grammar":Oe==="full"?"Strong compression, fragments OK":"Telegraphic, max savings"})]}),e.jsx(L,{checked:De,onChange:()=>xs(!De)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Context compression"," ",e.jsx("a",{href:"https://github.com/jerhadf/headroom",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Headroom)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"External proxy compresses input messages → fewer prompt tokens"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Le&&e.jsxs("div",{className:"flex flex-col items-end gap-2 min-w-[200px]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{value:_e,onChange:t=>os(t.target.value),placeholder:"http://localhost:8787",className:"text-xs"}),!ve&&Et&&e.jsx("button",{onClick:ds,disabled:oe,className:"px-2 py-1.5 rounded text-xs font-medium bg-primary text-white hover:opacity-80 disabled:opacity-50",children:oe?"...":"Start"}),ve&&Ps&&e.jsx("button",{onClick:ms,disabled:oe,className:"px-2 py-1.5 rounded text-xs font-medium bg-red-500 text-white hover:opacity-80 disabled:opacity-50",children:oe?"...":"Stop"})]}),e.jsx("p",{className:`text-xs ${ve?"text-green-500":Et?"text-yellow-500":"text-red-500"}`,children:Ls}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-text-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Dt,onChange:t=>cs(t.target.checked),className:"rounded"}),"Compress user messages"]})]}),e.jsx(L,{checked:Le,onChange:()=>is(!Le)})]})]})]}),e.jsxs(Ze,{id:"require-api-key",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"vpn_key"}),"API Keys"]}),e.jsx(c,{icon:"add",onClick:()=>C(!0),children:"Create Key"})]}),e.jsxs("div",{className:"flex items-center justify-between pb-4 mb-4 border-b border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Require API key"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Requests without a valid key will be rejected"})]}),e.jsx(L,{checked:re,onChange:()=>as(!re)})]}),Yt&&!re&&e.jsx("div",{className:"mb-4 -mt-2",children:e.jsx(Ce,{message:"Endpoint is exposed without an API key."})}),d.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"vpn_key"})}),e.jsx("p",{className:"text-text-main font-medium mb-1",children:"No API keys yet"}),e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create your first API key to get started"}),e.jsx(c,{icon:"add",onClick:()=>C(!0),children:"Create Key"})]}):e.jsx("div",{className:"flex flex-col",children:d.map(t=>e.jsxs("div",{className:`group flex items-center justify-between py-3 border-b border-black/[0.03] dark:border-white/[0.03] last:border-b-0 ${t.isActive===!1?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"text-xs text-text-muted font-mono",children:Ge.has(t.id)?t.key:ks(t.key)}),e.jsx("button",{onClick:()=>Cs(t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",title:Ge.has(t.id)?"Hide key":"Show key",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:Ge.has(t.id)?"visibility_off":"visibility"})}),e.jsx("button",{onClick:()=>se(t.key,t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:z===t.id?"check":"content_copy"})})]}),e.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["Created ",new Date(t.createdAt).toLocaleDateString()]}),t.isActive===!1&&e.jsx("p",{className:"text-xs text-orange-500 mt-1",children:"Paused"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{size:"sm",checked:t.isActive??!0,onChange:s=>{t.isActive&&!s?J({title:"Pause API Key",message:`Pause API key "${t.name}"?
|
|
5
|
-
|
|
6
|
-
This key will stop working immediately but can be resumed later.`,onConfirm:async()=>{J(null),St(t.id,s)}}):St(t.id,s)},title:t.isActive?"Pause key":"Resume key"}),e.jsx("button",{onClick:()=>vs(t.id),className:"p-2 hover:bg-red-500/10 rounded text-red-500 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]},t.id))})]}),e.jsx(B,{isOpen:g,title:"Create API Key",onClose:()=>{C(!1),le("")},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(G,{label:"Key Name",value:ne,onChange:t=>le(t.target.value),placeholder:"Production Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Ns,fullWidth:!0,disabled:!ne.trim(),children:"Create"}),e.jsx(c,{onClick:()=>{C(!1),le("")},variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:!!Te,title:"API Key Created",onClose:()=>Se(null),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mb-2 font-medium",children:"Save this key now!"}),e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:"This is the only time you will see this key. Store it securely."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{value:Te||"",readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx(c,{variant:"secondary",icon:z==="created_key"?"check":"content_copy",onClick:()=>se(Te,"created_key"),children:z==="created_key"?"Copied!":"Copy"})]}),e.jsx(c,{onClick:()=>Se(null),fullWidth:!0,children:"Done"})]})}),e.jsx(B,{isOpen:Ft,title:"Enable Tunnel",onClose:()=>Y(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"bg-surface-2 border border-border-subtle rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"cloud_upload"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-text-main font-medium mb-1",children:"Cloudflare Tunnel"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Expose your local FSRouter to the internet. No port forwarding, no static IP needed. Share endpoint URL with your team or use it in Cursor, Cline, and other AI tools from anywhere."})]})]})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:Os.map(t=>e.jsxs("div",{className:"flex flex-col items-center text-center p-3 rounded-lg bg-sidebar/50",children:[e.jsx("span",{className:"material-symbols-outlined text-xl text-primary mb-1",children:t.icon}),e.jsx("p",{className:"text-xs font-semibold",children:t.title}),e.jsx("p",{className:"text-xs text-text-muted",children:t.desc})]},t.title))}),e.jsx("p",{className:"text-xs text-text-muted",children:"Requires outbound port 7844 (TCP/UDP). Connection may take 10-30s."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:bs,fullWidth:!0,children:"Start Tunnel"}),e.jsx(c,{onClick:()=>Y(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:Kt,title:"Disable Tunnel",onClose:()=>!_&&X(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"The Cloudflare tunnel will be disconnected. Remote access via tunnel URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:gs,fullWidth:!0,disabled:_,variant:"danger",children:_?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>X(!1),variant:"ghost",fullWidth:!0,disabled:_,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:Bt,title:"Tailscale Funnel",onClose:()=>{fe||($(!1),jt(""),m(null))},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[Fe===null&&e.jsxs("p",{className:"text-sm text-text-muted flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),Fe===!1&&!fe&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale is not installed. Install it to enable Funnel."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:js,fullWidth:!0,children:"Install Tailscale"}),e.jsx(c,{onClick:()=>$(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),fe&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Installing Tailscale..."]}),We.length>0&&e.jsx("div",{ref:be,className:"bg-black/5 dark:bg-white/5 rounded p-2 max-h-40 overflow-y-auto font-mono text-xs text-text-muted",children:We.map((t,s)=>e.jsx("div",{children:t},s))})]}),Fe===!0&&!fe&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),"Tailscale installed"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:()=>Ye(),fullWidth:!0,children:"Connect"}),e.jsx(c,{onClick:()=>$(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),q&&e.jsx($s,{status:q})]})}),e.jsx(B,{isOpen:Gt,title:"Disable Tailscale",onClose:()=>!U&&Z(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale Funnel will be stopped. Remote access via Tailscale URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:ws,fullWidth:!0,disabled:U,variant:"danger",children:U?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>Z(!1),variant:"ghost",fullWidth:!0,disabled:U,children:"Cancel"})]})]})}),e.jsx(Rs,{isOpen:!!w,onClose:()=>J(null),onConfirm:w==null?void 0:w.onConfirm,title:(w==null?void 0:w.title)||"Confirm",message:w==null?void 0:w.message,variant:"danger"})]})}function qs({label:h,url:d,copyId:x,copied:j,onCopy:R,badge:g,actions:C}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${g==="CF"||g==="TS"?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:h}),e.jsx(G,{value:d,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>R(d,x),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:j===x?"check":"content_copy"})}),C]})}function $s({status:h,className:d=""}){const x=j=>j.split(/(https?:\/\/[^\s]+)/g).map((g,C)=>/^https?:\/\//.test(g)?e.jsx("a",{href:g,target:"_blank",rel:"noreferrer",className:"underline font-medium",children:g},C):g);return e.jsx("div",{className:`p-2 rounded text-sm ${d} ${h.type==="success"?"bg-green-500/10 text-green-600 dark:text-green-400":h.type==="warning"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":h.type==="info"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-red-500/10 text-red-600 dark:text-red-400"}`,children:x(h.message)})}function zs({text:h}){return e.jsxs("span",{className:"relative group inline-flex items-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-text-muted cursor-help",children:"help"}),e.jsx("span",{className:"pointer-events-none absolute left-5 top-1/2 -translate-y-1/2 z-50 w-64 rounded bg-gray-900 dark:bg-gray-800 text-white text-xs px-2.5 py-1.5 opacity-0 group-hover:opacity-100 transition-opacity shadow-lg",children:h})]})}function Ce({message:h,action:d}){return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:"warning"}),e.jsx("p",{className:"text-xs flex-1",children:h}),d&&e.jsx("a",{href:d.href,className:"text-xs font-medium underline shrink-0 hover:opacity-80",onClick:d.href.startsWith("#")?x=>{var j;x.preventDefault(),(j=document.getElementById(d.href.slice(1)))==null||j.scrollIntoView({behavior:"smooth"})}:void 0,children:d.label})]})}Ws.propTypes={machineId:Is.string.isRequired};export{Ws as A};
|