@fudrouter/fsrouter 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +157 -0
  2. package/package.json +1 -1
  3. package/public/assets/EndpointPageClient.YsGwbpYV.js +6 -0
  4. package/public/assets/Loading.CjQLhSfR.js +1 -0
  5. package/public/assets/NoAuthProxyCard.D1e90xgk.js +89 -0
  6. package/public/assets/index.DAEHkWvS.js +89 -0
  7. package/public/assets/page.-95lgZd_.js +23 -0
  8. package/public/assets/page.61FbV9Wp.js +1 -0
  9. package/public/assets/page.Apg42588.js +1 -0
  10. package/public/assets/page.B0C1xaR8.js +2 -0
  11. package/public/assets/page.B4youO9X.js +1 -0
  12. package/public/assets/page.BMbi-Sns.js +1 -0
  13. package/public/assets/page.BUPLy5EZ.js +6 -0
  14. package/public/assets/page.BXh6BM3U.js +4 -0
  15. package/public/assets/page.BZUkHLYE.js +1 -0
  16. package/public/assets/page.BZeKpmS4.js +5 -0
  17. package/public/assets/page.BbHtA1Vv.js +1 -0
  18. package/public/assets/page.BbmBUUp6.js +1 -0
  19. package/public/assets/page.BedLQaFn.js +1 -0
  20. package/public/assets/page.BpZpjcj5.js +1 -0
  21. package/public/assets/page.C7irTNuo.js +1 -0
  22. package/public/assets/page.CVp0aTOO.js +1 -0
  23. package/public/assets/page.CXmpgSS-.js +1 -0
  24. package/public/assets/page.Cb9NSedz.js +31 -0
  25. package/public/assets/page.CbEpgP40.js +1 -0
  26. package/public/assets/page.CcqLMlVQ.js +1 -0
  27. package/public/assets/page.Cx0ouxNC.js +1 -0
  28. package/public/assets/page.D2q8p9Ho.js +1 -0
  29. package/public/assets/page.D72XZv59.js +5 -0
  30. package/public/assets/page.DJLPVXk9.js +1 -0
  31. package/public/assets/page.DQFGk3ix.js +6 -0
  32. package/public/assets/page.DUg1jlDv.js +1 -0
  33. package/public/assets/page.DZ-7X_uA.js +1 -0
  34. package/public/assets/page.DbcoBydG.js +64 -0
  35. package/public/assets/page.DvfqdMbH.js +1 -0
  36. package/public/assets/page.XCZlByO2.js +2 -0
  37. package/public/assets/page.XxNz79L9.js +1 -0
  38. package/public/assets/page.i4WFZmkG.js +1 -0
  39. package/public/assets/page.kzWpy5SG.js +1 -0
  40. package/public/assets/page.nLWOXyfy.js +1 -0
  41. package/public/assets/page.vnuVB-x6.js +1 -0
  42. package/public/index.html +1 -1
  43. package/src/server.ts +1 -1
  44. package/src/shared/constants/skills.js +2 -2
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # FSRouter
2
+
3
+ > A self-hosted AI gateway — one endpoint, many providers, auto-fallback.
4
+
5
+ FSRouter is a decoupled rewrite of 9Router with a clean separation between a dedicated **Express backend** and a **Vite + React frontend**. It exposes an OpenAI-compatible REST API that proxies requests across dozens of AI providers with automatic load balancing, fallback, and key rotation.
6
+
7
+ ---
8
+
9
+ ## Screenshots
10
+
11
+ | Login Page | Quota Tracker |
12
+ |:---:|:---:|
13
+ | ![Login Page](docs/screnshoot/login-page.png) | ![Quota Tracker](docs/screnshoot/quota-tracker.png) |
14
+
15
+ ---
16
+
17
+ ## Features
18
+
19
+ - **OpenAI-compatible API** — works with any client that supports `/v1/chat/completions`, `/v1/images/generations`, `/v1/audio/speech`, `/v1/embeddings`, etc.
20
+ - **Multi-provider routing** — Cloudflare Workers AI, OpenAI, Anthropic, Gemini, Groq, and many more
21
+ - **Cloudflare Workers AI Automation** — automates account registration and API key extraction with Playwright + 2Captcha + FSMail temp mail
22
+ - **Dashboard UI** — manage providers, connections, proxy pools, CLI tools, and automation from a modern dark-mode interface
23
+ - **OIDC / Password authentication** — single sign-on or local credentials
24
+ - **Agent Skills** — ready-to-use SKILL.md files for Claude, Gemini, Codex, and other AI coding agents
25
+ - **SQLite backend** — zero-dependency local database, no external services required
26
+
27
+ ---
28
+
29
+ ## Architecture
30
+
31
+ ```
32
+ FSRouter/
33
+ ├── backend/ # Express server (port 3001)
34
+ │ └── src/
35
+ │ ├── routes/ # Auto-routed endpoints (/v1, /api, /auth, ...)
36
+ │ ├── db/ # SQLite via better-sqlite3
37
+ │ └── automation/ # Playwright automation scripts
38
+ ├── frontend/ # Vite + React SPA (port 5177)
39
+ │ └── src/
40
+ │ ├── pages/ # Dashboard pages
41
+ │ └── shared/ # Components, hooks, constants
42
+ └── skills/ # Agent SKILL.md files
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Quick Start
48
+
49
+ ### Requirements
50
+
51
+ - Node.js 20+
52
+ - Python 3.10+ (for automation features)
53
+ - Chromium (for Playwright automation)
54
+
55
+ ### Install
56
+
57
+ ```bash
58
+ git clone https://github.com/nexusrouters/fsrouter.git
59
+ cd FSRouter
60
+ npm install
61
+ ```
62
+
63
+ ### Development
64
+
65
+ ```bash
66
+ npm run dev # Start both backend + frontend concurrently
67
+ npm run backend # Backend only (port 3001)
68
+ npm run frontend # Frontend only (port 5177)
69
+ ```
70
+
71
+ ### Environment Variables
72
+
73
+ Copy and configure the backend environment:
74
+
75
+ ```bash
76
+ cp backend/.env.template backend/.env
77
+ ```
78
+
79
+ Key variables:
80
+
81
+ | Variable | Description |
82
+ |---|---|
83
+ | `PORT` | Backend server port (default: `3001`) |
84
+ | `REQUIRE_LOGIN` | Enable authentication (`true`/`false`) |
85
+ | `JWT_SECRET` | Secret for JWT signing |
86
+ | `ADMIN_PASSWORD` | Dashboard admin password |
87
+
88
+ ---
89
+
90
+ ## Production Deployment
91
+
92
+ ### 1. Build Frontend
93
+
94
+ ```bash
95
+ cd frontend && npm run build
96
+ ```
97
+
98
+ ### 2. Start Backend
99
+
100
+ ```bash
101
+ cd backend && npm start
102
+ ```
103
+
104
+ ### 3. Nginx Reverse Proxy
105
+
106
+ Use the included `nginx.conf` to proxy `/api` and `/v1` to the backend while serving the built frontend statically. See `docs/deployment-linux.md` for a full Linux deployment guide.
107
+
108
+ ---
109
+
110
+ ## Cloudflare Workers AI Automation
111
+
112
+ The automation module automatically registers Cloudflare Workers AI accounts:
113
+
114
+ 1. Configure **FSMail** temp mail credentials in Dashboard → Automation → Settings
115
+ 2. Add a **2Captcha** API key for Turnstile solving
116
+ 3. Add email accounts in the Automation tab and click **Run**
117
+ 4. API keys are extracted and added to FSRouter automatically
118
+
119
+ ---
120
+
121
+ ## Agent Skills
122
+
123
+ Skills are SKILL.md files for AI coding agents. Paste the entry skill URL into your AI:
124
+
125
+ ```
126
+ Read this skill and use it:
127
+ https://raw.githubusercontent.com/nexusrouters/fsrouter/refs/heads/main/skills/fsrouter/SKILL.md
128
+ ```
129
+
130
+ Browse all skills in the Dashboard → Skills page or in the [`skills/`](./skills/) directory.
131
+
132
+ ---
133
+
134
+ ## API Reference
135
+
136
+ | Endpoint | Description |
137
+ |---|---|
138
+ | `GET /api/health` | Health check |
139
+ | `GET /v1/models` | List available chat/LLM models |
140
+ | `POST /v1/chat/completions` | Chat completions (streaming supported) |
141
+ | `POST /v1/images/generations` | Image generation |
142
+ | `POST /v1/audio/speech` | Text-to-speech |
143
+ | `POST /v1/audio/transcriptions` | Speech-to-text |
144
+ | `POST /v1/embeddings` | Text embeddings |
145
+ | `GET /v1/search` | Web search |
146
+
147
+ ---
148
+
149
+ ## License
150
+
151
+ MIT — see [LICENSE](./LICENSE)
152
+
153
+ ---
154
+
155
+ ## Acknowledgements
156
+
157
+ > 🙏 **Thanks to [FSRouter](https://github.com/decolua/fsrouter)** — this project is a fork and architectural rewrite of the original FSRouter monolith. The core routing logic, provider integrations, and many features were inspired by and built upon the excellent work of the FSRouter project.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fudrouter/fsrouter",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "9Router v2 — Express Backend (API, SSE, DB, Auth, MITM)",
@@ -0,0 +1,6 @@
1
+ import{p as Lt,q as Us,u as As,j as e,B as c,M as B,C as Rs,f as Is}from"./index.DAEHkWvS.js";import{b as a}from"./router.Cjj1--8t.js";import{C as Ze,I as G,T as L}from"./NoAuthProxyCard.D1e90xgk.js";import{C as _t}from"./Loading.CjQLhSfR.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 ve=[{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?ve:ve.filter(t=>!t.wenyan);a.useEffect(()=>{const t=ve.find(s=>s.id===ie);t!=null&&t.wenyan&&!Je&&(Pe("ultra"),k({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(()=>{kt(),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 v=((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(v),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,v=((l=i.tunnel)==null?void 0:l.tunnelUrl)||"";ue(v),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&&lt(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)}},k=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),k({cavemanEnabled:t})},rs=t=>{Pe(t),k({cavemanLevel:t})},is=t=>{ct(t),k({headroomEnabled:t})},os=t=>{Ue(t),k({headroomUrl:t})},cs=t=>{dt(t),k({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),k({ponytailEnabled:t})},hs=t=>{ht(t),k({ponytailLevel:t})},xs=t=>{xt(t),k({paleoEnabled:t})},ps=t=>{pt(t),k({paleoLevel:t})},kt=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 v of b)if(v.startsWith("event: ")&&(i=v.slice(7).trim()),v.startsWith("data: "))try{P=JSON.parse(v.slice(6))}catch{}if(P)if(i==="progress")qe(v=>[...v.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},vt=(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){vt(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=>{vt(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 kt(),le(""),C(!1))}catch(t){console.log("Error creating key:",t)}},ks=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)}},vs=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,ke=!!I.running,Xe=I.localUrl!==!1,Et=!!I.canStart,Ps=Xe&&!!I.managedPid,Ls=I.loading?"Checking…":ke?"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=ve.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"}),!ke&&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"}),ke&&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 ${ke?"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:vs(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:()=>ks(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};
@@ -0,0 +1 @@
1
+ import{j as e,n as t}from"./index.DAEHkWvS.js";function r({size:n="md",className:s}){const i={sm:"size-4",md:"size-6",lg:"size-8",xl:"size-12"};return e.jsx("span",{className:t("material-symbols-outlined animate-spin text-brand-500",i[n],s),children:"progress_activity"})}function c({message:n="Loading..."}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-bg",children:[e.jsx(r,{size:"xl"}),e.jsx("p",{className:"mt-4 text-text-muted",children:n})]})}function a({className:n,...s}){return e.jsx("div",{className:t("animate-pulse rounded-[10px] bg-surface-2",n),...s})}function d(){return e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface shadow-[var(--shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(a,{className:"h-4 w-24"}),e.jsx(a,{className:"size-10 rounded-[10px]"})]}),e.jsx(a,{className:"h-8 w-16 mb-2"}),e.jsx(a,{className:"h-3 w-20"})]})}function x({type:n="spinner",...s}){switch(n){case"page":return e.jsx(c,{...s});case"skeleton":return e.jsx(a,{...s});case"card":return e.jsx(d,{...s});default:return e.jsx(r,{...s})}}export{d as C,x as L};