@fudrouter/fsrouter 0.6.91 → 0.6.93

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 (57) hide show
  1. package/dist/open-sse/handlers/chatCore.js +16 -0
  2. package/dist/routes/oauth/[provider]/[action]/route.js +6 -0
  3. package/package.json +10 -2
  4. package/public/.vite/manifest.json +89 -89
  5. package/public/assets/EndpointPageClient.kiCCiZeY.js +6 -0
  6. package/public/assets/Loading.BUhrzmZs.js +1 -0
  7. package/public/assets/NoAuthProxyCard.BI22GO9q.js +89 -0
  8. package/public/assets/index.DZiGd5-F.js +89 -0
  9. package/public/assets/page.1oqivCfq.js +1 -0
  10. package/public/assets/page.B5R9sdV7.js +1 -0
  11. package/public/assets/page.B5x2tCz5.js +1 -0
  12. package/public/assets/page.BFjNdqva.js +1 -0
  13. package/public/assets/page.BGs8R5av.js +1 -0
  14. package/public/assets/page.BLO61tLD.js +2 -0
  15. package/public/assets/page.BLWAx8lB.js +1 -0
  16. package/public/assets/page.BMcCQehz.js +6 -0
  17. package/public/assets/page.BS1sQouT.js +1 -0
  18. package/public/assets/page.BUWLUkXc.js +1 -0
  19. package/public/assets/page.BWaWJ_9t.js +1 -0
  20. package/public/assets/page.BYhmIkhw.js +1 -0
  21. package/public/assets/page.Buhl7l9y.js +1 -0
  22. package/public/assets/page.CBlkUp7t.js +1 -0
  23. package/public/assets/page.CG2arj7j.js +4 -0
  24. package/public/assets/page.CLgmM6Q_.js +5 -0
  25. package/public/assets/page.CLu_guvG.js +1 -0
  26. package/public/assets/page.COCdcdEM.js +1 -0
  27. package/public/assets/page.C_zhg1wq.js +1 -0
  28. package/public/assets/page.CtaqVBbT.js +6 -0
  29. package/public/assets/page.Cx0GMnA6.js +5 -0
  30. package/public/assets/page.D47UJLch.js +2 -0
  31. package/public/assets/page.D9ZFXJ3P.js +1 -0
  32. package/public/assets/page.D9kdvCh4.js +1 -0
  33. package/public/assets/page.DO1WoRkx.js +23 -0
  34. package/public/assets/page.DU201OUE.js +1 -0
  35. package/public/assets/page.DXxD-0Vl.js +31 -0
  36. package/public/assets/page.DaJXSZm4.js +1 -0
  37. package/public/assets/page.Dkeyd3nc.js +1 -0
  38. package/public/assets/page.DwJ35Irb.js +1 -0
  39. package/public/assets/page.DzLEPjRK.js +64 -0
  40. package/public/assets/page.VAojhnMr.js +1 -0
  41. package/public/assets/page.WBkwLufg.js +1 -0
  42. package/public/assets/page.laQQR26l.js +1 -0
  43. package/public/assets/page.nzF601n5.js +1 -0
  44. package/public/assets/page.tzSMuTXr.js +1 -0
  45. package/public/assets/page.xCigoHGB.js +1 -0
  46. package/public/index.html +4 -4
  47. package/scripts/postinstall.cjs +90 -0
  48. package/src/automation/cf_token_via_session.py +0 -158
  49. package/src/automation/cloudflare_signup.py +0 -3689
  50. package/src/automation/codebuddy_signup.py +0 -636
  51. package/src/automation/flashloop_signup.py +0 -338
  52. package/src/automation/kimi_signup.py +0 -401
  53. package/src/automation/leonardo_signup.py +0 -902
  54. package/src/automation/openvecta_signup.py +0 -652
  55. package/src/automation/qoder_signup.py +0 -323
  56. package/src/automation/test_proxy.py +0 -86
  57. package/src/automation/weavy_signup.py +0 -1964
@@ -0,0 +1 @@
1
+ import{g as v,j as e,B as c,m as j}from"./index.DZiGd5-F.js";import{d as N,b as u,L as h}from"./router.Cjj1--8t.js";import{C as p,S as k,I as x,T as A}from"./NoAuthProxyCard.BI22GO9q.js";import"./zustand.akaTi5uX.js";const P=Object.values(v).map(a=>({value:a.id,label:a.name})),S=Object.values(j).map(a=>({value:a.id,label:a.name}));function E(){const a=N(),[b,m]=u.useState(!1),[t,y]=u.useState({provider:"",authMethod:"api_key",apiKey:"",displayName:"",isActive:!0}),[s,n]=u.useState({}),i=(r,o)=>{y(l=>({...l,[r]:o})),s[r]&&n(l=>({...l,[r]:null}))},f=()=>{const r={};return t.provider||(r.provider="Please select a provider"),t.authMethod==="api_key"&&!t.apiKey&&(r.apiKey="API Key is required"),n(r),Object.keys(r).length===0},g=async r=>{if(r.preventDefault(),!!f()){m(!0);try{const o=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(o.ok)a("/dashboard/providers");else{const l=await o.json();n({submit:l.error||"Failed to create provider"})}}catch{n({submit:"An error occurred. Please try again."})}finally{m(!1)}}},d=v[t.provider];return e.jsxs("div",{className:"max-w-2xl mx-auto",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs(h,{to:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[e.jsx("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),"Back to Providers"]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Add New Provider"}),e.jsx("p",{className:"text-text-muted mt-2",children:"Configure a new AI provider to use with your applications."})]}),e.jsx(p,{children:e.jsxs("form",{onSubmit:g,className:"flex flex-col gap-6",children:[e.jsx(k,{label:"Provider",options:P,value:t.provider,onChange:r=>i("provider",r.target.value),placeholder:"Select a provider",error:s.provider,required:!0}),d&&e.jsxs(p.Section,{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-lg flex items-center justify-center bg-bg border border-border",children:e.jsx("span",{className:"material-symbols-outlined text-xl",style:{color:d.color},children:d.icon})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:d.name}),e.jsx("p",{className:"text-sm text-text-muted",children:"Selected provider"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("label",{className:"text-sm font-medium",children:["Authentication Method ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("div",{className:"flex gap-3",children:S.map(r=>e.jsxs("button",{type:"button",onClick:()=>i("authMethod",r.value),className:`flex-1 flex items-center justify-center gap-2 p-4 rounded-lg border transition-all ${t.authMethod===r.value?"border-primary bg-primary/5 text-primary":"border-border hover:border-primary/50"}`,children:[e.jsx("span",{className:"material-symbols-outlined",children:r.value==="api_key"?"key":"lock"}),e.jsx("span",{className:"font-medium",children:r.label})]},r.value))})]}),t.authMethod==="api_key"&&e.jsx(x,{label:"API Key",type:"password",placeholder:"Enter your API key",value:t.apiKey,onChange:r=>i("apiKey",r.target.value),error:s.apiKey,hint:"Your API key will be encrypted and stored securely.",required:!0}),t.authMethod==="oauth2"&&e.jsxs(p.Section,{children:[e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Connect your account using OAuth2 authentication."}),e.jsx(c,{type:"button",variant:"secondary",icon:"link",children:"Connect with OAuth2"})]}),e.jsx(x,{label:"Display Name",placeholder:"e.g., Production API, Dev Environment",value:t.displayName,onChange:r=>i("displayName",r.target.value),hint:"Optional. A friendly name to identify this configuration."}),e.jsx(A,{checked:t.isActive,onChange:r=>i("isActive",r),label:"Active",description:"Enable this provider for use in your applications"}),s.submit&&e.jsx("div",{className:"p-4 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-600 dark:text-red-400 text-sm",children:s.submit}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-border",children:[e.jsx(h,{to:"/dashboard/providers",className:"flex-1",children:e.jsx(c,{type:"button",variant:"ghost",fullWidth:!0,children:"Cancel"})}),e.jsx(c,{type:"submit",loading:b,fullWidth:!0,className:"flex-1",children:"Create Provider"})]})]})})]})}export{E as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.DZiGd5-F.js";import{b as o}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function u(){const[i,n]=o.useState({}),l=t=>{navigator.clipboard.writeText(t),n(r=>({...r,[t]:!0})),setTimeout(()=>{n(r=>({...r,[t]:!1}))},1500)},a=({value:t,text:r="Copy",className:d=""})=>{const s=i[t];return e.jsxs("button",{type:"button",onClick:()=>l(t),className:`text-xs px-3 py-1 rounded cursor-pointer transition-all duration-150 flex items-center gap-1 border font-semibold shrink-0 ${s?"text-green-400 bg-green-500/10 border-green-500/20":"text-white/50 hover:text-white bg-white/5 hover:bg-white/10 border-transparent"} ${d}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:s?"check":"content_copy"}),s?"Copied":r]})};return e.jsxs("div",{className:"max-w-3xl mx-auto py-8 px-4 text-white space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/10 pb-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[28px]",children:"auto_stories"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Panduan Lengkap Deploy Temp Mail"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"Panduan integrasi Cloudflare Worker & D1 Database untuk fsrouter"})]})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx("a",{href:"/dashboard/automation",className:"px-3.5 py-1.5 rounded-lg bg-white/5 border border-white/10 text-xs font-semibold hover:bg-white/10 transition-colors cursor-pointer",children:"Kembali ke Dashboard"})})]}),e.jsxs("div",{className:"space-y-6 text-sm leading-relaxed text-white/80",children:[e.jsxs("div",{className:"bg-primary/5 border border-primary/20 rounded-xl p-4 text-xs text-primary/95 flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined shrink-0 mt-0.5",children:"lightbulb"}),e.jsxs("p",{children:[e.jsx("strong",{children:"Info Penting:"})," Panduan ini ditujukan jika Anda ingin melakukan deployment secara manual ke Cloudflare menggunakan CLI. Jika Anda ingin setup otomatis, silakan kembali ke Dashboard dan gunakan form ",e.jsx("strong",{children:"⚡ Auto Deploy (Cloudflare)"})," untuk setup 1-klik."]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"1"}),"Prasyarat & Login Cloudflare"]}),e.jsx("p",{children:"Pastikan Node.js telah terinstal di komputer Anda. Buka terminal lalu autentikasikan akun Cloudflare Anda menggunakan Wrangler CLI:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler login"}),e.jsx(a,{value:"npx wrangler login"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"2"}),"Masuk Folder & Install Dependencies"]}),e.jsx("p",{children:"Buka terminal pada direktori worker lokal Anda (`tempmail`) lalu install package dependencies:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"cd /home/data/Project/fsrouter/tempmail && npm install"}),e.jsx(a,{value:"cd /home/data/Project/fsrouter/tempmail && npm install"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"3"}),"Buat Database Cloudflare D1"]}),e.jsxs("p",{children:["Buat database baru bernama ",e.jsx("code",{children:"tempmail"})," pada Cloudflare D1 untuk menyimpan data kotak surat dan isi pesan:"]}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler d1 create tempmail"}),e.jsx(a,{value:"npx wrangler d1 create tempmail"})]}),e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-lg p-3.5 text-xs text-amber-300 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined shrink-0 mt-0.5",children:"warning"}),e.jsxs("span",{children:["Perintah di atas akan menghasilkan **database_id** (UUID). Salin ID tersebut, kemudian buka berkas ",e.jsx("code",{className:"bg-white/10 px-1 py-0.5 rounded font-mono text-white",children:"wrangler.jsonc"})," di folder proyek tempmail Anda, ganti nilai ",e.jsx("code",{children:"database_id"})," di baris terbawah dengan ID baru Anda."]})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"4"}),"Jalankan Migrasi Database D1"]}),e.jsx("p",{children:"Buat struktur tabel database yang diperlukan dengan menerapkan migrasi database baik secara lokal maupun langsung di Cloudflare:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler d1 migrations apply tempmail --remote"}),e.jsx(a,{value:"npx wrangler d1 migrations apply tempmail --remote"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"5"}),"Buat API Access Key untuk fsrouter"]}),e.jsx("p",{children:"fsrouter berkomunikasi dengan Worker menggunakan API Key yang aman. Jalankan perintah SQL berikut untuk mendaftarkan fsrouter admin ke database D1 Anda:"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all overflow-hidden text-ellipsis",children:`npx wrangler d1 execute tempmail --remote --command="INSERT OR IGNORE INTO chats (chat_id, username, first_name, last_name, created_at, updated_at) VALUES ('fsrouter', 'fsrouter_admin', 'FSRouter', 'Admin', datetime('now'), datetime('now')); INSERT OR REPLACE INTO api_access (user_id, api_key, quota_daily, quota_used, quota_date, granted_by, granted_at, expires_at) VALUES ('fsrouter', 'tm_YOUR_SECURE_API_KEY', 0, 0, strftime('%Y-%m-%d', 'now'), 'admin', datetime('now'), '2099-12-31T23:59:59Z');"`}),e.jsx(a,{value:`npx wrangler d1 execute tempmail --remote --command="INSERT OR IGNORE INTO chats (chat_id, username, first_name, last_name, created_at, updated_at) VALUES ('fsrouter', 'fsrouter_admin', 'FSRouter', 'Admin', datetime('now'), datetime('now')); INSERT OR REPLACE INTO api_access (user_id, api_key, quota_daily, quota_used, quota_date, granted_by, granted_at, expires_at) VALUES ('fsrouter', 'tm_YOUR_SECURE_API_KEY', 0, 0, strftime('%Y-%m-%d', 'now'), 'admin', datetime('now'), '2099-12-31T23:59:59Z');"`})]}),e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-lg p-3.5 text-xs text-amber-300 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined shrink-0 mt-0.5",children:"info"}),e.jsxs("span",{children:["Ganti ",e.jsx("code",{children:"tm_YOUR_SECURE_API_KEY"})," dengan API Key acak pilihan Anda (misalnya menggunakan format ",e.jsx("code",{children:"tm_"})," diikuti oleh karakter hex acak). Salin API Key ini ke pengaturan fsrouter Anda."]})]})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"6"}),"Atur Secret Tokens (Telegram & Webhook)"]}),e.jsx("p",{children:"Simpan token bot Telegram dan webhook secret ke dalam Cloudflare secret variables secara aman:"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler secret put TELEGRAM_BOT_TOKEN"}),e.jsx(a,{value:"npx wrangler secret put TELEGRAM_BOT_TOKEN"})]}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler secret put TELEGRAM_WEBHOOK_SECRET"}),e.jsx(a,{value:"npx wrangler secret put TELEGRAM_WEBHOOK_SECRET"})]})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"7"}),"Deploy ke Cloudflare Workers"]}),e.jsxs("p",{children:["Buka file ",e.jsx("code",{className:"bg-white/10 px-1 py-0.5 rounded font-mono text-white",children:"wrangler.jsonc"}),", sesuaikan parameter ",e.jsx("code",{children:"vars"})," (domain, base URL) agar sesuai dengan domain milik Anda. Setelah itu, deploy ke Cloudflare:"]}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler deploy"}),e.jsx(a,{value:"npx wrangler deploy"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"8"}),"Daftarkan Webhook Telegram Bot (Opsional)"]}),e.jsx("p",{children:"Daftarkan URL domain worker Anda ke API Telegram agar bot Anda dapat menerima chat command secara instan:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 gap-4",children:[e.jsx("span",{className:"break-all",children:`curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" -H "Content-Type: application/json" -d '{"url":"https://<worker-host>/telegram/webhook","secret_token":"<WEBHOOK_SECRET>"}'`}),e.jsx(a,{value:`curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" -H "Content-Type: application/json" -d '{"url":"https://<worker-host>/telegram/webhook","secret_token":"<WEBHOOK_SECRET>"}'`})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"9"}),"Konfigurasi Cloudflare Email Routing & DNS (Paling Penting!)"]}),e.jsx("p",{children:"Ini adalah langkah krusial agar email dapat diterima dan diproses oleh Worker yang telah dideploy. Masuk ke panel Cloudflare Anda, lalu ikuti panduan berikut:"}),e.jsxs("div",{className:"space-y-4 border-l-2 border-primary/30 pl-4 mt-2",children:[e.jsxs("div",{children:[e.jsxs("h5",{className:"font-bold text-white text-xs flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),"Bagian A: Sinkronkan dan Kunci Rekaman DNS"]}),e.jsxs("p",{className:"text-xs text-white/70 mt-1",children:["Jika status DNS Anda tertulis ",e.jsx("code",{className:"bg-white/10 text-white px-1 rounded",children:"Not configured"})," atau ada rekaman dengan status ",e.jsx("code",{className:"bg-amber-500/10 text-amber-300 px-1 rounded border border-amber-500/20",children:"Unlocked"})," (misalnya TXT SPF):"]}),e.jsxs("ul",{className:"list-disc list-inside text-xs text-white/70 mt-1.5 space-y-1 ml-2",children:[e.jsxs("li",{children:["Buka menu ",e.jsx("strong",{children:"Email Routing"})," di panel domain Cloudflare Anda."]}),e.jsx("li",{children:"Pilih tab **`Settings`** di sebelah atas."}),e.jsx("li",{children:"Di sebelah kanan judul **`DNS records`**, klik tombol **`Lock`** (ikon gembok). Cloudflare akan otomatis mengunci dan menerapkan semua MX dan TXT records yang dibutuhkan untuk rute email."})]})]}),e.jsxs("div",{children:[e.jsxs("h5",{className:"font-bold text-white text-xs flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),"Bagian B: Buat Aturan Rute Catch-All"]}),e.jsx("p",{className:"text-xs text-white/70 mt-1",children:"Agar semua email masuk diteruskan ke database Worker Anda:"}),e.jsxs("ul",{className:"list-disc list-inside text-xs text-white/70 mt-1.5 space-y-1 ml-2",children:[e.jsx("li",{children:"Klik tab **`Routing rules`** (tab ketiga dari kiri)."}),e.jsx("li",{children:"Scroll ke bawah ke bagian **Catch-all address**."}),e.jsx("li",{children:"Klik **Edit** / **Configure**."}),e.jsx("li",{children:"Pada kolom **Action** (Aksi), pilih opsi **`Send to a Worker`** (Kirim ke Worker)."}),e.jsx("li",{children:"Pada kolom **Destination** (Worker tujuan), pilih nama Worker yang baru saja dideploy (contohnya: **`tempmail-pixelnest`**)."}),e.jsx("li",{children:"Klik **Save** untuk menyimpan aturan perutean."})]})]})]})]})]})]})}export{u as default};
@@ -0,0 +1 @@
1
+ import{j as o}from"./index.DZiGd5-F.js";import{b as r}from"./router.Cjj1--8t.js";import{g as a}from"./machine.CagOtseJ.js";import{A as i}from"./EndpointPageClient.kiCCiZeY.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.BI22GO9q.js";import"./Loading.BUhrzmZs.js";function d(){const[t,e]=r.useState("");return r.useEffect(()=>{a().then(e)},[]),t?o.jsx(i,{machineId:t}):null}export{d as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.DZiGd5-F.js";import{b as n}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function j(){const[o,p]=n.useState("tts"),[x,h]=n.useState(""),[t,s]=n.useState(null),[i,r]=n.useState(!1),u=async()=>{r(!0);try{const a=await fetch("/api/audio/speech",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:x,model:"tts-1",voice:"alloy"})});if(a.ok){const c=await a.blob();s({audio:URL.createObjectURL(c)})}else s({error:await a.text()})}catch(a){s({error:a.message})}r(!1)},m=async a=>{const c=a.target.files[0];if(!c)return;r(!0);const l=new FormData;l.append("file",c),l.append("model","whisper-1");try{const d=await fetch("/api/audio/transcriptions",{method:"POST",body:l});s(await d.json())}catch(d){s({error:d.message})}r(!1)};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Audio"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>p("tts"),className:`px-4 py-2 rounded-lg ${o==="tts"?"bg-primary text-white":"bg-black/5"}`,children:"Text to Speech"}),e.jsx("button",{onClick:()=>p("stt"),className:`px-4 py-2 rounded-lg ${o==="stt"?"bg-primary text-white":"bg-black/5"}`,children:"Speech to Text"})]}),o==="tts"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("textarea",{className:"w-full p-3 rounded-lg border h-40",placeholder:"Enter text to convert to speech...",value:x,onChange:a=>h(a.target.value)}),e.jsx("button",{onClick:u,disabled:i,className:"px-4 py-2 bg-primary text-white rounded-lg",children:i?"Generating...":"Generate Speech"}),(t==null?void 0:t.audio)&&e.jsx("audio",{controls:!0,src:t.audio,className:"w-full"})]}),o==="stt"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("input",{type:"file",accept:"audio/*",onChange:m,className:"block"}),i&&e.jsx("p",{children:"Transcribing..."})]}),(t==null?void 0:t.error)&&e.jsx("p",{className:"text-red-500",children:t.error}),(t==null?void 0:t.text)&&e.jsx("pre",{className:"p-4 bg-black/5 rounded-lg text-sm",children:t.text})]})}export{j as default};
@@ -0,0 +1 @@
1
+ import{J as m,j as e,B as p}from"./index.DZiGd5-F.js";import{b as l}from"./router.Cjj1--8t.js";import{C as f}from"./NoAuthProxyCard.BI22GO9q.js";import"./zustand.akaTi5uX.js";const g={LOG:"text-green-400",INFO:"text-blue-400",WARN:"text-yellow-400",ERROR:"text-red-400",DEBUG:"text-purple-400"};function h(n){var s;const o=n.match(/\[(\w+)\]/g),u=o?(s=o[1])==null?void 0:s.replace(/\[|\]/g,""):null,c=g[u]||"text-green-400";return e.jsx("span",{className:c,children:n})}function j(){const[n,o]=l.useState([]),[u,c]=l.useState(!1),s=l.useRef(null),d=async()=>{try{await fetch("/api/translator/console-logs",{method:"DELETE"})}catch(t){console.error("Failed to clear console logs:",t)}};return l.useEffect(()=>{const t=new EventSource("/api/translator/console-logs/stream");return t.onopen=()=>c(!0),t.onmessage=a=>{const r=JSON.parse(a.data);r.type==="init"?o(r.logs.slice(-200)):r.type==="line"?o(x=>{const i=[...x,r.line];return i.length>m.maxLines?i.slice(-200):i}):r.type==="clear"&&o([])},t.onerror=()=>c(!1),()=>t.close()},[]),l.useEffect(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)},[n]),e.jsx("div",{className:"",children:e.jsxs(f,{children:[e.jsx("div",{className:"flex items-center justify-end px-4 pt-3 pb-2",children:e.jsx(p,{size:"sm",variant:"outline",icon:"delete",onClick:d,children:"Clear"})}),e.jsx("div",{ref:s,className:"bg-black rounded-b-lg p-4 text-xs font-mono h-[calc(100vh-220px)] overflow-y-auto",children:n.length===0?e.jsx("span",{className:"text-text-muted",children:"No console logs yet."}):e.jsx("div",{className:"space-y-0.5",children:n.map((t,a)=>e.jsx("div",{children:h(t)},a))})})]})})}const N="force-dynamic";function O(){return e.jsx(j,{})}export{O as default,N as dynamic};
@@ -0,0 +1,2 @@
1
+ import{j as t}from"./index.DZiGd5-F.js";import{b as a}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function g(){const[s,u]=a.useState(""),[n,i]=a.useState(""),[r,l]=a.useState(null),[o,c]=a.useState(!1),d=async()=>{c(!0);try{const e=await fetch("/api/rerank",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:s,documents:n.split(`
2
+ `).filter(Boolean)})});l(await e.json())}catch(e){l({error:e.message})}c(!1)};return t.jsxs("div",{className:"space-y-6 p-6",children:[t.jsx("h1",{className:"text-2xl font-bold",children:"Rerank"}),t.jsx("p",{className:"text-text-muted",children:"Rerank documents by relevance using Cohere-compatible API"}),t.jsx("input",{className:"w-full p-3 rounded-lg border",placeholder:"Query",value:s,onChange:e=>u(e.target.value)}),t.jsx("textarea",{className:"w-full p-3 rounded-lg border h-40",placeholder:"Documents (one per line)",value:n,onChange:e=>i(e.target.value)}),t.jsx("button",{onClick:d,disabled:o,className:"px-4 py-2 bg-primary text-white rounded-lg",children:o?"Reranking...":"Rerank"}),r&&t.jsx("pre",{className:"p-4 bg-black/5 rounded-lg text-sm overflow-auto",children:JSON.stringify(r,null,2)})]})}export{g as default};
@@ -0,0 +1 @@
1
+ import{j as e,L as Qe,D as Xe,E as ye,G as je,H as Ze,n as he,B as v,I as ge,C as es}from"./index.DZiGd5-F.js";import{b as o,c as ss,d as ts}from"./router.Cjj1--8t.js";import{C as T,T as C,I as m}from"./NoAuthProxyCard.BI22GO9q.js";import"./zustand.akaTi5uX.js";function as(){if(typeof document>"u")return"en";const g=document.cookie.split(";").find(S=>S.trim().startsWith(`${ye}=`)),k=g?decodeURIComponent(g.split("=")[1]):"en";return je(k)}const oe=g=>({en:{name:"English",flag:"🇺🇸"},vi:{name:"Tiếng Việt",flag:"🇻🇳"},"zh-CN":{name:"简体中文",flag:"🇨🇳"},"zh-TW":{name:"繁體中文",flag:"🇹🇼"},ja:{name:"日本語",flag:"🇯🇵"},"pt-BR":{name:"Português (Brasil)",flag:"🇧🇷"},"pt-PT":{name:"Português (Portugal)",flag:"🇵🇹"},ko:{name:"한국어",flag:"🇰🇷"},es:{name:"Español",flag:"🇪🇸"},de:{name:"Deutsch",flag:"🇩🇪"},fr:{name:"Français",flag:"🇫🇷"},he:{name:"עברית",flag:"🇮🇱"},ar:{name:"العربية",flag:"🇸🇦"},ru:{name:"Русский",flag:"🇷🇺"},pl:{name:"Polski",flag:"🇵🇱"},cs:{name:"Čeština",flag:"🇨🇿"},nl:{name:"Nederlands",flag:"🇳🇱"},tr:{name:"Türkçe",flag:"🇹🇷"},uk:{name:"Українська",flag:"🇺🇦"},tl:{name:"Tagalog",flag:"🇵🇭"},id:{name:"Indonesia",flag:"🇮🇩"},th:{name:"ไทย",flag:"🇹🇭"},hi:{name:"हिन्दी",flag:"🇮🇳"},bn:{name:"বাংলা",flag:"🇧🇩"},ur:{name:"اردو",flag:"🇵🇰"},ro:{name:"Română",flag:"🇷🇴"},sv:{name:"Svenska",flag:"🇸🇪"},it:{name:"Italiano",flag:"🇮🇹"},el:{name:"Ελληνικά",flag:"🇬🇷"},hu:{name:"Magyar",flag:"🇭🇺"},fi:{name:"Suomi",flag:"🇫🇮"},da:{name:"Dansk",flag:"🇩🇰"},no:{name:"Norsk",flag:"🇳🇴"}})[g]||{name:g,flag:"🌐"};function os({className:g="",isOpen:k,onClose:S,hideTrigger:re=!1}){const[P,U]=o.useState("en"),[R,H]=o.useState(!1),[E,V]=o.useState(!1),F=o.useRef(null),r=typeof k=="boolean",x=r?k:E,i=c=>{r?!c&&S&&S(P):V(c)};o.useEffect(()=>{U(as())},[]),o.useEffect(()=>{function c(N){F.current&&!F.current.contains(N.target)&&i(!1)}if(x)return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[x]);const B=async c=>{if(!(c===P||R)){H(!0),i(!1);try{await fetch("/api/locale",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({locale:c})}),await Xe(),U(c)}catch(N){console.error("Failed to set locale:",N)}finally{H(!1)}}};return e.jsxs("div",{className:g,children:[!re&&e.jsxs("button",{onClick:()=>i(!x),disabled:R,className:"flex items-center gap-2 px-3 py-2 rounded-lg text-text-muted hover:text-text-main hover:bg-surface/60 transition-colors",title:"Language","data-i18n-skip":"true",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"language"}),e.jsx("span",{className:"text-sm font-medium",children:oe(P).name}),e.jsx("span",{className:"text-lg",children:oe(P).flag})]}),x&&ss.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4","data-i18n-skip":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/30 backdrop-blur-sm",onClick:()=>i(!1)}),e.jsxs("div",{ref:F,className:"relative w-full bg-surface border border-black/10 dark:border-white/10 rounded-xl shadow-2xl animate-in fade-in zoom-in-95 duration-200 max-w-2xl flex flex-col max-h-[80vh]",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-black/5 dark:border-white/5",children:[e.jsx("h2",{className:"text-lg font-semibold text-text-main",children:"Select Language"}),e.jsx("button",{onClick:()=>i(!1),className:"p-1.5 rounded-lg text-text-muted hover:bg-black/5 dark:hover:bg-white/5 transition-colors","aria-label":"Close",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"p-6 overflow-y-auto flex-1",children:e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-2",children:Qe.map(c=>{const N=P===c,O=oe(c);return e.jsxs("button",{onClick:()=>B(c),disabled:R,className:`flex flex-col items-center justify-start gap-1 px-2 py-3 rounded-lg text-xs font-medium transition-colors w-full ${N?"bg-primary/15 text-primary ring-2 ring-primary":"text-text-main hover:bg-black/5 dark:hover:bg-white/5"} ${R?"opacity-70 cursor-wait":""}`,title:O.name,children:[e.jsx("span",{className:"text-2xl",children:O.flag}),e.jsx("span",{className:"text-center leading-tight line-clamp-2 h-8 flex items-center",children:O.name}),N&&e.jsx("span",{className:"material-symbols-outlined text-sm",children:"check"})]},c)})})})]})]}),document.body)]})}function rs(){if(typeof document>"u")return"en";const g=document.cookie.split(";").find(S=>S.trim().startsWith(`${ye}=`)),k=g?decodeURIComponent(g.split("=")[1]):"en";return je(k)}function ds(){const g=ts(),{theme:k,setTheme:S}=Ze(),[re,P]=o.useState("en"),[U,R]=o.useState(!1),[H,E]=o.useState(!1),[V,F]=o.useState(!1),[r,x]=o.useState({fallbackStrategy:"fill-first"}),[i,B]=o.useState(!0),[c,N]=o.useState({current:"",new:"",confirm:""}),[O,M]=o.useState({type:"",message:""}),[we,ie]=o.useState(!1),[le,W]=o.useState(!1),[Y,D]=o.useState({type:"",message:""}),[p,Q]=o.useState({authMode:"password",oidcIssuerUrl:"",oidcClientId:"",oidcScopes:"openid profile email",oidcLoginLabel:"Sign in with OIDC"}),[X,Z]=o.useState(""),[ee,A]=o.useState({type:"",message:""}),[L,ne]=o.useState(!1),[ve,ce]=o.useState(!1),[se,I]=o.useState({type:"",message:""}),[Ne,_e]=o.useState("/api/auth/oidc/callback"),[de,me]=o.useState(!1),K=o.useRef(null),[J,z]=o.useState({outboundProxyEnabled:!1,outboundProxyUrl:"",outboundNoProxy:""}),[te,y]=o.useState({type:"",message:""}),[$,G]=o.useState(!1),[ke,xe]=o.useState(!1),[l,j]=o.useState({codebuddy_auto_fsrouter:!1,codebuddy_leave_canva_team:!1,codebuddy_browser_headless:!0,codebuddy_proxy_enabled:!1,codebuddy_proxy_server:"",codebuddy_proxy_username:"",codebuddy_proxy_password:"",fsmail_base_url:"",fsmail_api_key:"",fsmail_default_domain:"",fsmail_webhook_secret:""}),[ae,f]=o.useState({type:"",message:""}),[w,ue]=o.useState(!1),[Ce,pe]=o.useState(!1),[Se,be]=o.useState(!1),[fe,Pe]=o.useState(!1);o.useEffect(()=>{P(rs())},[U]),o.useEffect(()=>{fetch("/api/settings").then(s=>s.json()).then(s=>{x(s),Q({authMode:(s==null?void 0:s.authMode)||"password",oidcIssuerUrl:(s==null?void 0:s.oidcIssuerUrl)||"",oidcClientId:(s==null?void 0:s.oidcClientId)||"",oidcScopes:(s==null?void 0:s.oidcScopes)||"openid profile email",oidcLoginLabel:(s==null?void 0:s.oidcLoginLabel)||"Sign in with OIDC"}),Z(""),((s==null?void 0:s.authMode)==="oidc"||(s==null?void 0:s.authMode)==="both")&&me(!0),z({outboundProxyEnabled:(s==null?void 0:s.outboundProxyEnabled)===!0,outboundProxyUrl:(s==null?void 0:s.outboundProxyUrl)||"",outboundNoProxy:(s==null?void 0:s.outboundNoProxy)||""}),j({codebuddy_auto_fsrouter:(s==null?void 0:s.codebuddy_auto_fsrouter)==="1",codebuddy_leave_canva_team:(s==null?void 0:s.codebuddy_leave_canva_team)==="1",codebuddy_browser_headless:(s==null?void 0:s.codebuddy_browser_headless)!=="0",codebuddy_proxy_enabled:(s==null?void 0:s.codebuddy_proxy_enabled)==="1",codebuddy_proxy_server:(s==null?void 0:s.codebuddy_proxy_server)||"",codebuddy_proxy_username:(s==null?void 0:s.codebuddy_proxy_username)||"",codebuddy_proxy_password:(s==null?void 0:s.codebuddy_proxy_password)||"",fsmail_base_url:(s==null?void 0:s.fsmail_base_url)||"",fsmail_api_key:(s==null?void 0:s.fsmail_api_key)||"",fsmail_default_domain:(s==null?void 0:s.fsmail_default_domain)||"",fsmail_webhook_secret:(s==null?void 0:s.fsmail_webhook_secret)||""}),B(!1)}).catch(s=>{console.error("Failed to fetch settings:",s),B(!1)})},[]),o.useEffect(()=>{typeof window<"u"&&_e(`${window.location.origin}/api/auth/oidc/callback`)},[]);const Oe=async s=>{ue(!0),f({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({codebuddy_auto_fsrouter:l.codebuddy_auto_fsrouter?"1":"0",codebuddy_leave_canva_team:l.codebuddy_leave_canva_team?"1":"0",codebuddy_browser_headless:l.codebuddy_browser_headless?"1":"0",codebuddy_proxy_enabled:l.codebuddy_proxy_enabled?"1":"0",codebuddy_proxy_server:l.codebuddy_proxy_server,codebuddy_proxy_username:l.codebuddy_proxy_username,codebuddy_proxy_password:l.codebuddy_proxy_password,fsmail_base_url:l.fsmail_base_url,fsmail_api_key:l.fsmail_api_key,fsmail_default_domain:l.fsmail_default_domain,fsmail_webhook_secret:l.fsmail_webhook_secret})}),a=await t.json();t.ok?(x(n=>({...n,...a})),f({type:"success",message:"Automation settings saved successfully."})):f({type:"error",message:a.error||"Failed to update automation settings"})}catch{f({type:"error",message:"An error occurred"})}finally{ue(!1)}},Le=async()=>{pe(!0),f({type:"",message:""});try{const s=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fsmail_base_url:l.fsmail_base_url,fsmail_api_key:l.fsmail_api_key,fsmail_default_domain:l.fsmail_default_domain,fsmail_webhook_secret:l.fsmail_webhook_secret})});if(!s.ok){const n=await s.json().catch(()=>({}));f({type:"error",message:n.error||"Failed to save settings before testing connection"});return}const t=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"test-connection"})}),a=await t.json().catch(()=>({}));t.ok?f({type:"success",message:"FSMail Connection Successful!"}):f({type:"error",message:a.error||"FSMail Connection Failed."})}catch(s){f({type:"error",message:s.message||"An error occurred"})}finally{pe(!1)}},Ie=async()=>{var s;be(!0),f({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fsmail_base_url:l.fsmail_base_url,fsmail_api_key:l.fsmail_api_key,fsmail_default_domain:l.fsmail_default_domain,fsmail_webhook_secret:l.fsmail_webhook_secret})});if(!t.ok){const b=await t.json().catch(()=>({}));f({type:"error",message:b.error||"Failed to save settings before registering webhook"});return}const a=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"webhook-register"})}),n=await a.json().catch(()=>({}));a.ok?(f({type:"success",message:"FSMail Webhook Registered Successfully!"}),(s=n.webhook)!=null&&s.secret&&j(b=>({...b,fsmail_webhook_secret:n.webhook.secret}))):f({type:"error",message:n.error||"FSMail Webhook Registration Failed."})}catch(t){f({type:"error",message:t.message||"An error occurred"})}finally{be(!1)}},Te=async s=>{if(s.preventDefault(),r.outboundProxyEnabled===!0){G(!0),y({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({outboundProxyUrl:J.outboundProxyUrl,outboundNoProxy:J.outboundNoProxy})}),a=await t.json();t.ok?(x(n=>({...n,...a})),y({type:"success",message:"Proxy settings applied"})):y({type:"error",message:a.error||"Failed to update proxy settings"})}catch{y({type:"error",message:"An error occurred"})}finally{G(!1)}}},Re=async()=>{if(r.outboundProxyEnabled!==!0)return;const s=(J.outboundProxyUrl||"").trim();if(!s){y({type:"error",message:"Please enter a Proxy URL to test"});return}xe(!0),y({type:"",message:""});try{const t=await fetch("/api/settings/proxy-test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyUrl:s})}),a=await t.json();t.ok&&(a!=null&&a.ok)?y({type:"success",message:`Proxy test OK (${a.status}) in ${a.elapsedMs}ms`}):y({type:"error",message:(a==null?void 0:a.error)||"Proxy test failed"})}catch{y({type:"error",message:"An error occurred"})}finally{xe(!1)}},Fe=async s=>{G(!0),y({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({outboundProxyEnabled:s})}),a=await t.json();t.ok?(x(n=>({...n,...a})),z(n=>({...n,outboundProxyEnabled:(a==null?void 0:a.outboundProxyEnabled)===!0})),y({type:"success",message:s?"Proxy enabled":"Proxy disabled"})):y({type:"error",message:a.error||"Failed to update proxy settings"})}catch{y({type:"error",message:"An error occurred"})}finally{G(!1)}},De=async s=>{if(s.preventDefault(),c.new!==c.confirm){M({type:"error",message:"Passwords do not match"});return}ie(!0),M({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:c.current,newPassword:c.new})}),a=await t.json();t.ok?(M({type:"success",message:"Password updated successfully"}),N({current:"",new:"",confirm:""})):M({type:"error",message:a.error||"Failed to update password"})}catch{M({type:"error",message:"An error occurred"})}finally{ie(!1)}},Ae=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fallbackStrategy:s})})).ok&&x(a=>({...a,fallbackStrategy:s}))}catch(t){console.error("Failed to update settings:",t)}},Ue=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboStrategy:s})})).ok&&x(a=>({...a,comboStrategy:s}))}catch(t){console.error("Failed to update combo strategy:",t)}},Ee=async s=>{const t=parseInt(s);if(!(isNaN(t)||t<1))try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({stickyRoundRobinLimit:t})})).ok&&x(n=>({...n,stickyRoundRobinLimit:t}))}catch(a){console.error("Failed to update sticky limit:",a)}},Me=async s=>{const t=parseInt(s);if(!(isNaN(t)||t<1))try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboStickyRoundRobinLimit:t})})).ok&&x(n=>({...n,comboStickyRoundRobinLimit:t}))}catch(a){console.error("Failed to update combo sticky limit:",a)}},Je=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({requireLogin:s})})).ok&&x(a=>({...a,requireLogin:s}))}catch(t){console.error("Failed to update require login:",t)}},q=(s,t)=>{Q(a=>({...a,[s]:t}))},$e=async(s=p.authMode||"password")=>{const t=p.oidcIssuerUrl.trim(),a=p.oidcClientId.trim(),n=p.oidcScopes.trim(),b=p.oidcLoginLabel.trim(),u=X.trim();if(s!=="password"&&(!t||!a||!u)&&!r.oidcConfigured){A({type:"error",message:"Issuer URL, client ID, and client secret are required to enable OIDC."});return}ne(!0),A({type:"",message:""}),I({type:"",message:""});try{const _={authMode:s,oidcIssuerUrl:t,oidcClientId:a,oidcScopes:n||"openid profile email",oidcLoginLabel:b||"Sign in with OIDC"};u&&(_.oidcClientSecret=u);const h=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)}),d=await h.json();h.ok?(x(Ye=>({...Ye,...d})),Q({authMode:(d==null?void 0:d.authMode)||s,oidcIssuerUrl:(d==null?void 0:d.oidcIssuerUrl)||t,oidcClientId:(d==null?void 0:d.oidcClientId)||a,oidcScopes:(d==null?void 0:d.oidcScopes)||n||"openid profile email",oidcLoginLabel:(d==null?void 0:d.oidcLoginLabel)||b||"Sign in with OIDC"}),Z(""),A({type:"success",message:s==="oidc"?"OIDC login enabled":s==="both"?"Password and OIDC login enabled":"OIDC settings saved"})):A({type:"error",message:d.error||"Failed to save OIDC settings"})}catch{A({type:"error",message:"An error occurred"})}finally{ne(!1)}},qe=async()=>{const s=p.oidcIssuerUrl.trim(),t=p.oidcClientId.trim(),a=p.oidcScopes.trim(),n=X.trim();if(!s||!t){I({type:"error",message:"Issuer URL and client ID are required to test the connection."});return}ce(!0),A({type:"",message:""}),I({type:"",message:""});try{const b=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({authMode:p.authMode||r.authMode||"password",oidcIssuerUrl:s,oidcClientId:t,oidcScopes:a||"openid profile email",oidcLoginLabel:p.oidcLoginLabel.trim()||"Sign in with OIDC",...n?{oidcClientSecret:n}:{}})}),u=await b.json().catch(()=>({}));if(!b.ok){I({type:"error",message:u.error||"Failed to save OIDC settings before testing"});return}const _=await fetch("/api/auth/oidc/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({issuerUrl:u.oidcIssuerUrl||s,clientId:u.oidcClientId||t,scopes:u.oidcScopes||a||"openid profile email"})}),h=await _.json().catch(()=>({}));if(_.ok&&(h!=null&&h.ok)){const d=h.clientSecretTested?h.clientSecretValid===!0?`Connection OK. Discovery loaded from ${h.issuerUrl}. Client secret validated too.`:`Connection OK. Discovery loaded from ${h.issuerUrl}. Client secret was not checked.`:`Connection OK. Discovery loaded from ${h.issuerUrl}.`;I({type:"success",message:d})}else I({type:"error",message:h.error||"OIDC connection test failed"})}catch{I({type:"error",message:"An error occurred"})}finally{ce(!1)}},He=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enableObservability:s})})).ok&&x(a=>({...a,enableObservability:s}))}catch(t){console.error("Failed to update enableObservability:",t)}},Be=async()=>{try{const s=await fetch("/api/settings");if(!s.ok)return;const t=await s.json();x(t)}catch(s){console.error("Failed to reload settings:",s)}},We=async()=>{W(!0),D({type:"",message:""});try{const s=await fetch("/api/settings/database");if(!s.ok){const h=await s.json().catch(()=>({}));throw new Error(h.error||"Failed to export database")}const t=await s.json(),a=JSON.stringify(t,null,2),n=new Blob([a],{type:"application/json"}),b=URL.createObjectURL(n),u=document.createElement("a"),_=new Date().toISOString().replace(/[.:]/g,"-");u.href=b,u.download=`fsrouter-backup-${_}.json`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(b),D({type:"success",message:"Database backup downloaded"})}catch(s){D({type:"error",message:s.message||"Failed to export database"})}finally{W(!1)}},Ke=async s=>{var a;const t=(a=s.target.files)==null?void 0:a[0];if(t){W(!0),D({type:"",message:""});try{const n=await t.text(),b=JSON.parse(n),u=await fetch("/api/settings/database",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}),_=await u.json().catch(()=>({}));if(!u.ok)throw new Error(_.error||"Failed to import database");await Be(),D({type:"success",message:"Database imported successfully"})}catch(n){D({type:"error",message:n.message||"Invalid backup file"})}finally{K.current&&(K.current.value=""),W(!1)}}},ze=r.enableObservability===!0,Ge=async()=>{F(!0);try{await fetch("/api/version/shutdown",{method:"POST"})}catch{}F(!1),E(!1)},Ve=async()=>{try{(await fetch("/api/auth/logout",{method:"POST"})).ok&&(localStorage.removeItem("9r_authed"),g("/login"),g(0))}catch(s){console.error("Failed to logout:",s)}};return e.jsxs("div",{className:"max-w-2xl mx-auto px-4 sm:px-0",children:[e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs(T,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"size-10 sm:size-12 rounded-lg bg-green-500/10 text-green-500 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-xl sm:text-2xl",children:"computer"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold",children:"Local Mode"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Running on your machine"})]})]}),e.jsx("div",{className:"inline-flex p-1 rounded-lg bg-black/5 dark:bg-white/5 w-full sm:w-auto",children:["light","dark","system"].map(s=>e.jsxs("button",{type:"button",onClick:()=>S(s),className:he("flex items-center justify-center gap-1 sm:gap-1.5 px-2 sm:px-3 py-1.5 rounded-md font-medium transition-all flex-1 sm:flex-initial",k===s?"bg-white dark:bg-white/10 text-text-main shadow-sm":"text-text-muted hover:text-text-main"),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:s==="light"?"light_mode":s==="dark"?"dark_mode":"contrast"}),e.jsx("span",{className:"capitalize text-xs sm:text-sm",children:s})]},s))})]}),e.jsxs("div",{className:"flex flex-col gap-3 pt-4 border-t border-border",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between p-3 rounded-lg bg-bg border border-border gap-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Database Location"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted font-mono break-all",children:"~/.fsrouter/db/data.sqlite"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(v,{variant:"secondary",icon:"download",onClick:We,loading:le,className:"w-full sm:w-auto",children:"Download Backup"}),e.jsx(v,{variant:"outline",icon:"upload",onClick:()=>{var s;return(s=K.current)==null?void 0:s.click()},disabled:le,className:"w-full sm:w-auto",children:"Import Backup"}),e.jsx("input",{ref:K,type:"file",accept:"application/json,.json",className:"hidden",onChange:Ke})]}),Y.message&&e.jsx("p",{className:`text-sm ${Y.type==="error"?"text-red-500":"text-green-600 dark:text-green-400"}`,children:Y.message})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 text-primary shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"shield"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Security"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Require login"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"When ON, dashboard requires password. When OFF, access without login."})]}),e.jsx(C,{checked:r.requireLogin===!0,onChange:()=>Je(!r.requireLogin),disabled:i})]}),r.requireLogin===!0&&e.jsxs("form",{onSubmit:De,className:"flex flex-col gap-4 pt-4 border-t border-border/50",children:[r.hasPassword&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs sm:text-sm font-medium",children:"Current Password"}),e.jsx(m,{type:"password",placeholder:"Enter current password",value:c.current,onChange:s=>N({...c,current:s.target.value}),required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs sm:text-sm font-medium",children:"New Password"}),e.jsx(m,{type:"password",placeholder:"Enter new password",value:c.new,onChange:s=>N({...c,new:s.target.value}),required:!0})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs sm:text-sm font-medium",children:"Confirm New Password"}),e.jsx(m,{type:"password",placeholder:"Confirm new password",value:c.confirm,onChange:s=>N({...c,confirm:s.target.value}),required:!0})]})]}),O.message&&e.jsx("p",{className:`text-xs sm:text-sm ${O.type==="error"?"text-red-500":"text-green-500"}`,children:O.message}),e.jsx("div",{className:"pt-2",children:e.jsx(v,{type:"submit",variant:"primary",loading:we,className:"w-full sm:w-auto",children:r.hasPassword?"Update Password":"Set Password"})})]})]})]}),e.jsxs(T,{children:[e.jsxs("button",{type:"button",onClick:()=>me(s=>!s),className:"w-full flex items-center gap-3 text-left",children:[e.jsx("div",{className:"p-2 rounded-lg bg-indigo-500/10 text-indigo-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"lock_open"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"OIDC Dashboard Login"}),e.jsx("p",{className:"text-xs text-text-muted",children:r.authMode==="oidc"?"OIDC active":r.authMode==="both"?"Password + OIDC active":"Optional SSO via Authentik/Keycloak/Google"})]}),e.jsx("span",{className:"material-symbols-outlined text-text-muted shrink-0",children:de?"expand_less":"expand_more"})]}),de&&e.jsxs("div",{className:"flex flex-col gap-4 mt-4",children:[e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Use Authentik or any OIDC provider to sign in to the dashboard. You can enable password-only, OIDC-only, or both for the dashboard; model API access still uses API keys."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Auth Mode"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:[{value:"password",title:"Password only",desc:"Keep the legacy password login."},{value:"oidc",title:"OIDC only",desc:"Require OIDC for dashboard access."},{value:"both",title:"Both",desc:"Allow either password or OIDC."}].map(s=>{const t=p.authMode===s.value;return e.jsxs("button",{type:"button",onClick:()=>q("authMode",s.value),className:he("text-left rounded-lg border p-3 transition-colors",t?"border-primary bg-primary/5":"border-border bg-bg hover:bg-black/5 dark:hover:bg-white/5"),disabled:i||L,children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:s.title}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted mt-1",children:s.desc})]},s.value)})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Issuer URL"}),e.jsx(m,{placeholder:"https://auth.example.com/application/o/fsrouter/",value:p.oidcIssuerUrl,onChange:s=>q("oidcIssuerUrl",s.target.value),disabled:i||L})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Client ID"}),e.jsx(m,{placeholder:"fsrouter-dashboard",value:p.oidcClientId,onChange:s=>q("oidcClientId",s.target.value),disabled:i||L})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Client Secret"}),e.jsx(m,{type:"password",placeholder:"Leave blank to keep existing secret",value:X,onChange:s=>Z(s.target.value),disabled:i||L}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"This value is write-only after saving."})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Scopes"}),e.jsx(m,{placeholder:"openid profile email",value:p.oidcScopes,onChange:s=>q("oidcScopes",s.target.value),disabled:i||L})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Login Button Label"}),e.jsx(m,{placeholder:"Sign in with OIDC",value:p.oidcLoginLabel,onChange:s=>q("oidcLoginLabel",s.target.value),disabled:i||L})]})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-bg p-3 text-xs sm:text-sm text-text-muted",children:[e.jsx("p",{className:"font-medium text-text-main mb-1",children:"Redirect URI"}),e.jsx("code",{className:"block break-all font-mono",children:Ne})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2 border-t border-border/50",children:[e.jsx(v,{type:"button",variant:"primary",loading:L,onClick:()=>$e(),className:"w-full sm:w-auto",children:"Save auth mode"}),e.jsx(v,{type:"button",variant:"outline",loading:ve,onClick:qe,className:"w-full sm:w-auto",children:"Test connection"})]}),se.message&&e.jsx("p",{className:`text-xs sm:text-sm ${se.type==="error"?"text-red-500":"text-green-500"}`,children:se.message}),ee.message&&e.jsx("p",{className:`text-xs sm:text-sm ${ee.type==="error"?"text-red-500":"text-green-500"}`,children:ee.message}),r.authMode==="oidc"&&e.jsx("p",{className:"text-xs sm:text-sm text-amber-600 dark:text-amber-400",children:"OIDC login is currently active. Password login is disabled until you switch back."}),r.authMode==="both"&&e.jsx("p",{className:"text-xs sm:text-sm text-amber-600 dark:text-amber-400",children:"Password and OIDC login are both active."})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-blue-500/10 text-blue-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"route"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Routing Strategy"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Round Robin"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Cycle through accounts to distribute load"})]}),e.jsx(C,{checked:r.fallbackStrategy==="round-robin",onChange:()=>Ae(r.fallbackStrategy==="round-robin"?"fill-first":"round-robin"),disabled:i})]}),r.fallbackStrategy==="round-robin"&&e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Sticky Limit"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Calls per account before switching"})]}),e.jsx(m,{type:"number",min:"1",max:"10",value:r.stickyRoundRobinLimit||3,onChange:s=>Ee(s.target.value),disabled:i,className:"w-16 sm:w-20 text-center shrink-0"})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-4 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Combo Round Robin"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Cycle through providers in combos instead of always starting with first"})]}),e.jsx(C,{checked:r.comboStrategy==="round-robin",onChange:()=>Ue(r.comboStrategy==="round-robin"?"fallback":"round-robin"),disabled:i})]}),r.comboStrategy==="round-robin"&&e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Combo Sticky Limit"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Calls per combo model before switching"})]}),e.jsx(m,{type:"number",min:"1",max:"100",value:r.comboStickyRoundRobinLimit||1,onChange:s=>Me(s.target.value),disabled:i,className:"w-20 text-center"})]}),e.jsxs("p",{className:"text-xs text-text-muted italic pt-2 border-t border-border/50",children:[r.fallbackStrategy==="round-robin"?`Currently distributing requests across all available accounts with ${r.stickyRoundRobinLimit||3} calls per account.`:"Currently using accounts in priority order (Fill First).",r.comboStrategy==="round-robin"?` Combos rotate after ${r.comboStickyRoundRobinLimit||1} call${(r.comboStickyRoundRobinLimit||1)===1?"":"s"} per model.`:" Combos always start with their first model."]})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-purple-500/10 text-purple-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"wifi"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Network"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Outbound Proxy"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Enable proxy for OAuth + provider outbound requests."})]}),e.jsx(C,{checked:r.outboundProxyEnabled===!0,onChange:()=>Fe(r.outboundProxyEnabled!==!0),disabled:i||$})]}),r.outboundProxyEnabled===!0&&e.jsxs("form",{onSubmit:Te,className:"flex flex-col gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Proxy URL"}),e.jsx(m,{placeholder:"http://127.0.0.1:7897",value:J.outboundProxyUrl,onChange:s=>z(t=>({...t,outboundProxyUrl:s.target.value})),disabled:i||$}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Leave empty to inherit existing env proxy (if any)."})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border/50",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"No Proxy"}),e.jsx(m,{placeholder:"localhost,127.0.0.1",value:J.outboundNoProxy,onChange:s=>z(t=>({...t,outboundNoProxy:s.target.value})),disabled:i||$}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Comma-separated hostnames/domains to bypass the proxy."})]}),e.jsxs("div",{className:"pt-2 border-t border-border/50 flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsx(v,{type:"button",variant:"secondary",loading:ke,disabled:i||$,onClick:Re,className:"w-full sm:w-auto",children:"Test proxy URL"}),e.jsx(v,{type:"submit",variant:"primary",loading:$,className:"w-full sm:w-auto",children:"Apply"})]})]}),te.message&&e.jsx("p",{className:`text-xs sm:text-sm ${te.type==="error"?"text-red-500":"text-green-500"} pt-2 border-t border-border/50`,children:te.message})]})]}),e.jsxs(T,{children:[e.jsxs("button",{type:"button",onClick:()=>Pe(s=>!s),className:"w-full flex items-center gap-3 text-left focus:outline-none",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-500/10 text-emerald-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"smart_toy"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Automation Settings"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Manage CodeBuddy browser signup & FSMail temporary email configurations."})]}),e.jsx("span",{className:"material-symbols-outlined text-text-muted shrink-0",children:fe?"expand_less":"expand_more"})]}),fe&&e.jsxs("div",{className:"flex flex-col gap-4 mt-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h4",{className:"font-semibold text-sm text-text-main flex items-center gap-1.5 border-b border-border/55 pb-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"smart_toy"}),"CodeBuddy API Gen Settings"]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Headless Browser"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Run the automated signup browser in headless mode (no visual window)."})]}),e.jsx(C,{checked:l.codebuddy_browser_headless,onChange:s=>j(t=>({...t,codebuddy_browser_headless:s})),disabled:i||w})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Auto Inject to fsrouter"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Automatically add newly generated CodeBuddy API keys to fsrouter connections."})]}),e.jsx(C,{checked:l.codebuddy_auto_fsrouter,onChange:s=>j(t=>({...t,codebuddy_auto_fsrouter:s})),disabled:i||w})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Leave Canva Team after Leonardo Registration"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Automatically leave the Canva team after completing Leonardo registration to free up team invite slots."})]}),e.jsx(C,{checked:l.codebuddy_leave_canva_team,onChange:s=>j(t=>({...t,codebuddy_leave_canva_team:s})),disabled:i||w})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Use Outbound Proxy"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Route the automation browser traffic through a proxy server."})]}),e.jsx(C,{checked:l.codebuddy_proxy_enabled,onChange:s=>j(t=>({...t,codebuddy_proxy_enabled:s})),disabled:i||w})]}),l.codebuddy_proxy_enabled&&e.jsxs("div",{className:"flex flex-col gap-3 pl-4 border-l-2 border-primary/20 pt-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-main",children:"Proxy Server"}),e.jsx(m,{placeholder:"host:port (e.g. 127.0.0.1:8080)",value:l.codebuddy_proxy_server,onChange:s=>j(t=>({...t,codebuddy_proxy_server:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-main",children:"Proxy Username (Optional)"}),e.jsx(m,{placeholder:"username",value:l.codebuddy_proxy_username,onChange:s=>j(t=>({...t,codebuddy_proxy_username:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-main",children:"Proxy Password (Optional)"}),e.jsx(m,{type:"password",placeholder:"password",value:l.codebuddy_proxy_password,onChange:s=>j(t=>({...t,codebuddy_proxy_password:s.target.value})),disabled:i||w})]})]})]})]}),e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border/55",children:[e.jsxs("h4",{className:"font-semibold text-sm text-text-main flex items-center gap-1.5 border-b border-border/55 pb-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"mail"}),"FSMail Temp Mail Settings"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Base URL"}),e.jsx(m,{placeholder:"https://fsmail.example.com",value:l.fsmail_base_url,onChange:s=>j(t=>({...t,fsmail_base_url:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"API Key"}),e.jsx(m,{type:"password",placeholder:"FSMail API Key",value:l.fsmail_api_key,onChange:s=>j(t=>({...t,fsmail_api_key:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Default Domain"}),e.jsx(m,{placeholder:"example.com",value:l.fsmail_default_domain,onChange:s=>j(t=>({...t,fsmail_default_domain:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Webhook Secret"}),e.jsx(m,{type:"password",placeholder:"Leave empty to auto-generate",value:l.fsmail_webhook_secret,onChange:s=>j(t=>({...t,fsmail_webhook_secret:s.target.value})),disabled:i||w})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-4 border-t border-border/50",children:[e.jsx(v,{type:"button",variant:"primary",loading:w,onClick:()=>Oe(),className:"w-full sm:w-auto",children:"Save Settings"}),e.jsx(v,{type:"button",variant:"secondary",loading:Ce,onClick:Le,className:"w-full sm:w-auto",children:"Test FSMail Connection"}),e.jsx(v,{type:"button",variant:"outline",loading:Se,onClick:Ie,className:"w-full sm:w-auto",children:"Register Webhook"})]}),ae.message&&e.jsx("p",{className:`text-xs sm:text-sm ${ae.type==="error"?"text-red-500":"text-green-500"} pt-2 border-t border-border/50`,children:ae.message})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-orange-500/10 text-orange-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"monitoring"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Observability"})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Enable Observability"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Record request details for inspection in the logs view"})]}),e.jsx(C,{checked:ze,onChange:He,disabled:i})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(v,{variant:"outline",fullWidth:!0,icon:"power_settings_new",onClick:()=>E(!0),className:"text-red-500 border-red-200 hover:bg-red-50 hover:border-red-300",children:"Shutdown"}),e.jsx(v,{variant:"outline",fullWidth:!0,icon:"logout",onClick:Ve,children:"Logout"})]}),e.jsxs("div",{className:"text-center text-xs sm:text-sm text-text-muted py-4",children:[e.jsxs("p",{children:[ge.name," v",ge.version]}),e.jsx("p",{className:"mt-1",children:"Local Mode - All data stored on your machine"})]})]}),e.jsx(os,{hideTrigger:!0,isOpen:U,onClose:s=>{R(!1),P(s)}}),e.jsx(es,{isOpen:H,onClose:()=>E(!1),onConfirm:Ge,title:"Close Proxy",message:"Are you sure you want to close the proxy server?",confirmText:"Close",cancelText:"Cancel",variant:"danger",loading:V})]})}export{ds as default};
@@ -0,0 +1,6 @@
1
+ import{a as ot,j as e,B as i,M as I,C as lt}from"./index.DZiGd5-F.js";import{b as l}from"./router.Cjj1--8t.js";import{C as Pe,B as k,T as ie,I as y}from"./NoAuthProxyCard.BI22GO9q.js";import{C as Se}from"./Loading.BUhrzmZs.js";import"./zustand.akaTi5uX.js";function at(x){return x==="active"?"success":x==="error"?"error":"default"}function nt(x){if(!x)return"Never";const W=new Date(x);return Number.isNaN(W.getTime())?"Never":W.toLocaleString()}function ce(x={}){return{name:x.name||"",proxyUrl:x.proxyUrl||"",noProxy:x.noProxy||"",isActive:x.isActive!==!1,strictProxy:x.strictProxy===!0}}function ht(){const[x,W]=l.useState([]),[De,A]=l.useState(!1),[$,B]=l.useState(""),[b,L]=l.useState([]),[E,Y]=l.useState(null),[c,U]=l.useState([]),[Te,Ie]=l.useState(!0),[Ae,K]=l.useState(!1),[$e,Q]=l.useState(!1),[Ee,de]=l.useState(!1),[Ue,xe]=l.useState(!1),[Oe,me]=l.useState(!1),[O,M]=l.useState(!1),[V,he]=l.useState(null),[u,C]=l.useState(ce()),[X,ue]=l.useState(""),[F,Z]=l.useState({vercelToken:"",projectName:"vercel-relay"}),[j,_]=l.useState({accountId:"",apiToken:"",projectName:"cloudflare-relay"}),[N,q]=l.useState({denoToken:"",orgDomain:"",projectName:""}),[R,pe]=l.useState(!1),[J,fe]=l.useState(!1),[p,S]=l.useState(!1),[ee,ye]=l.useState(null),[h,H]=l.useState([]),[v,ge]=l.useState(!1),[be,te]=l.useState({current:0,total:0}),[z,D]=l.useState(!1),[g,w]=l.useState(null),se=l.useRef(null),n=ot();l.useEffect(()=>{const t=s=>{se.current&&!se.current.contains(s.target)&&M(!1)};return O&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[O]);const f=l.useCallback(async()=>{try{const t=await fetch("/api/proxy-pools?includeUsage=true",{cache:"no-store"}),s=await t.json();t.ok&&U(s.proxyPools||[])}catch(t){console.log("Error fetching proxy pools:",t)}finally{Ie(!1)}},[]),G=l.useCallback(async()=>{try{const t=await fetch("/api/proxy-combos",{cache:"no-store"}),s=await t.json();t.ok&&W(s.combos||[])}catch{}},[]);l.useEffect(()=>{f(),G()},[f,G]);const je=()=>{he(null),C(ce())},ve=()=>{je(),K(!0)},Me=t=>{he(t),C(ce(t)),K(!0)},re=()=>{K(!1),je()},Fe=async()=>{const t={name:u.name.trim(),proxyUrl:u.proxyUrl.trim(),noProxy:u.noProxy.trim(),isActive:u.isActive===!0,strictProxy:u.strictProxy===!0};if(!(!t.name||!t.proxyUrl)){pe(!0);try{const s=!!V,r=await fetch(s?`/api/proxy-pools/${V.id}`:"/api/proxy-pools",{method:s?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(r.ok)await f(),re(),n.success(V?"Proxy pool updated":"Proxy pool created");else{const o=await r.json();n.error(o.error||"Failed to save proxy pool")}}catch(s){console.log("Error saving proxy pool:",s)}finally{pe(!1)}}},Re=async t=>{w({title:"Delete Proxy Pool",message:`Delete proxy pool "${t.name}"?`,onConfirm:async()=>{w(null);try{const s=await fetch(`/api/proxy-pools/${t.id}`,{method:"DELETE"});if(s.ok){U(o=>o.filter(a=>a.id!==t.id)),n.success("Proxy pool deleted");return}const r=await s.json();s.status===409?n.warning(`Cannot delete: ${r.boundConnectionCount||0} connection(s) are still using this pool.`):n.error(r.error||"Failed to delete proxy pool")}catch(s){console.log("Error deleting proxy pool:",s),n.error("Failed to delete proxy pool")}}})},ze=async t=>{ye(t);try{const s=await fetch(`/api/proxy-pools/${t}/test`,{method:"POST"}),r=await s.json();if(!s.ok){n.error(r.error||"Failed to test proxy");return}await f(),n.success(r.ok?"Proxy test passed":"Proxy test failed")}catch(s){console.log("Error testing proxy pool:",s),n.error("Failed to test proxy")}finally{ye(null)}},We=async t=>{const s=!t.isActive;U(r=>r.map(o=>o.id===t.id?{...o,isActive:s}:o));try{(await fetch(`/api/proxy-pools/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:s})})).ok||(U(o=>o.map(a=>a.id===t.id?{...a,isActive:t.isActive}:a)),n.error("Failed to update active state"))}catch(r){console.log("Error toggling active:",r),U(o=>o.map(a=>a.id===t.id?{...a,isActive:t.isActive}:a))}},oe=c.length>0&&h.length===c.length,Be=t=>H(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t]),Le=()=>H(oe?[]:c.map(t=>t.id)),ke=()=>H([]),Ce=async t=>{const s=h.length>0?h:c.map(r=>r.id);if(s.length!==0){D(!0);try{let r=0,o=0;for(const a of s)try{(await fetch(`/api/proxy-pools/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok?r+=1:o+=1}catch{o+=1}await f(),n.success(`${t?"Activated":"Deactivated"} ${r}${o?`, failed ${o}`:""}`)}finally{D(!1)}}},Ve=async()=>{h.length!==0&&w({title:"Delete Proxy Pools",message:`Delete ${h.length} proxy pool(s)?`,onConfirm:async()=>{w(null),D(!0);try{let t=0,s=0,r=0;for(const o of h)try{const a=await fetch(`/api/proxy-pools/${o}`,{method:"DELETE"});a.ok?t+=1:a.status===409?s+=1:r+=1}catch{r+=1}await f(),ke(),n.success(`Deleted ${t}${s?`, ${s} bound`:""}${r?`, ${r} failed`:""}`)}finally{D(!1)}}})},_e=async()=>{const t=h.length>0?c.filter(d=>h.includes(d.id)):c;if(t.length===0)return;ge(!0),te({current:0,total:t.length});let s=0;const r=[];let o=0;const a=10,m=[...t],P=async()=>{for(;m.length>0;){const d=m.shift();if(!d)break;try{const T=await fetch(`/api/proxy-pools/${d.id}/test`,{method:"POST"}),we=await T.json();T.ok&&we.ok?s+=1:r.push(d.id)}catch{r.push(d.id)}finally{o+=1,te({current:o,total:t.length})}}};await Promise.all(Array.from({length:Math.min(a,t.length)},P)),await f(),ge(!1),te({current:0,total:0}),r.length>0?w({title:"Disable Dead Proxies",message:`Alive: ${s}, Dead: ${r.length}.
2
+
3
+ Disable ${r.length} dead proxies?`,onConfirm:async()=>{w(null),D(!0);try{for(const d of r)try{await fetch(`/api/proxy-pools/${d}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:!1})})}catch{}await f(),n.success(`Disabled ${r.length} dead proxies`)}finally{D(!1)}}}):n.success(`Health check done. Alive: ${s}, Dead: ${r.length}`)};l.useEffect(()=>{H(t=>t.filter(s=>c.some(r=>r.id===s)))},[c]);const qe=()=>{ue(""),Q(!0)},Ne=()=>{J||Q(!1)},Je=()=>{Z({vercelToken:"",projectName:"vercel-relay"}),de(!0)},le=()=>{p||de(!1)},He=()=>{_({accountId:"",apiToken:"",projectName:"cloudflare-relay"}),xe(!0)},ae=()=>{p||xe(!1)},Ge=()=>{q({denoToken:"",orgDomain:"",projectName:""}),me(!0)},ne=()=>{p||me(!1)},Ye=async()=>{if(F.vercelToken.trim()){S(!0);try{const t=await fetch("/api/proxy-pools/vercel-deploy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)}),s=await t.json();t.ok?(await f(),le(),n.success(`Deployed: ${s.deployUrl}`)):n.error(s.error||"Deploy failed")}catch(t){console.log("Error deploying Vercel relay:",t),n.error("Deploy failed")}finally{S(!1)}}},Ke=async()=>{if(!(!j.accountId.trim()||!j.apiToken.trim())){S(!0);try{const t=await fetch("/api/proxy-pools/cloudflare-deploy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),s=await t.json();t.ok?(await f(),ae(),n.success(`Deployed: ${s.deployUrl}`)):n.error(s.error||"Deploy failed")}catch(t){console.log("Error deploying Cloudflare relay:",t),n.error("Deploy failed")}finally{S(!1)}}},Qe=async()=>{if(N.denoToken.trim()){S(!0);try{const t=await fetch("/api/proxy-pools/deno-deploy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)}),s=await t.json();t.ok?(await f(),ne(),n.success(`Deployed: ${s.deployUrl}`)):n.error(s.error||"Deploy failed")}catch(t){console.log("Error deploying Deno relay:",t),n.error("Deploy failed")}finally{S(!1)}}},Xe=t=>{const s=t.trim();if(!s)return null;if(s.includes("://")){const o=new URL(s),a=o.port?`${o.hostname}:${o.port}`:o.hostname;return{proxyUrl:o.toString(),name:`Imported ${a}`}}const r=s.split(":");if(r.length===4){const[o,a,m,P]=r;if(!o||!a||!m||!P)throw new Error("Invalid host:port:user:pass format");const d=`http://${encodeURIComponent(m)}:${encodeURIComponent(P)}@${o}:${a}`;return{proxyUrl:new URL(d).toString(),name:`Imported ${o}:${a}`}}throw new Error("Unsupported format")},Ze=async()=>{const t=X.split(/\r?\n/).map(o=>o.trim()).filter(Boolean);if(t.length===0){n.warning("Please paste at least one proxy line.");return}const s=[],r=[];if(t.forEach((o,a)=>{try{const m=Xe(o);m&&s.push({...m,lineNumber:a+1})}catch(m){r.push(`Line ${a+1}: ${m.message}`)}}),r.length>0){n.error(`Invalid proxy format:
4
+ ${r.join(`
5
+ `)}`);return}fe(!0);try{const o=new Set(c.map(d=>`${(d.proxyUrl||"").trim()}|||${(d.noProxy||"").trim()}`));let a=0,m=0,P=0;for(const d of s){const T=`${d.proxyUrl}|||`;if(o.has(T)){m+=1;continue}(await fetch("/api/proxy-pools",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:d.name,proxyUrl:d.proxyUrl,noProxy:"",isActive:!0})})).ok?(a+=1,o.add(T)):P+=1}await f(),Q(!1),n.success(`Batch import completed: Created ${a}, Skipped ${m}, Failed ${P}`)}catch(o){console.log("Error batch importing proxies:",o),n.error("Batch import failed")}finally{fe(!1)}},et=l.useMemo(()=>c.filter(t=>t.isActive===!0).length,[c]);if(Te)return e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-4 px-1 sm:gap-6 sm:px-0",children:[e.jsx(Se,{}),e.jsx(Se,{})]});const tt=async()=>{if(!$.trim()||b.length===0)return;const t=E?"PUT":"POST",s=E?{id:E.id,name:$,poolIds:b}:{name:$,poolIds:b};await fetch("/api/proxy-combos",{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),A(!1),B(""),L([]),Y(null),G()},st=async t=>{await fetch("/api/proxy-combos",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t})}),G()},rt=t=>{var s;return((s=c.find(r=>r.id===t))==null?void 0:s.name)||t.slice(0,8)};return e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-4 px-1 sm:gap-6 sm:px-0",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("h1",{className:"text-xl font-semibold sm:text-2xl",children:"Proxy Pools"})}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs("div",{className:"relative",ref:se,children:[e.jsxs(i,{size:"sm",variant:"secondary",icon:"rocket_launch",onClick:()=>M(!O),children:["Deploy Relay",e.jsx("span",{className:"material-symbols-outlined ml-1 text-[18px]",children:O?"expand_less":"expand_more"})]}),O&&e.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-48 rounded-xl border border-black/10 bg-white p-1 shadow-xl dark:border-white/10 dark:bg-zinc-900 sm:left-auto sm:right-0",children:[e.jsxs("button",{onClick:()=>{He(),M(!1)},className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-text-main transition-colors hover:bg-black/5 dark:hover:bg-white/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-orange-500",children:"cloud"}),"Cloudflare Relay"]}),e.jsxs("button",{onClick:()=>{Je(),M(!1)},className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-text-main transition-colors hover:bg-black/5 dark:hover:bg-white/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-500",children:"cloud_upload"}),"Vercel Relay"]}),e.jsxs("button",{onClick:()=>{Ge(),M(!1)},className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-text-main transition-colors hover:bg-black/5 dark:hover:bg-white/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-green-500",children:"terminal"}),"Deno Relay"]})]})]}),e.jsx(i,{size:"sm",variant:"secondary",icon:"upload",onClick:qe,children:"Batch Import"}),e.jsx(i,{size:"sm",icon:"add",onClick:ve,children:"Add Proxy Pool"})]})]}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[c.length>0&&e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-text-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:oe,onChange:Le,className:"size-4 rounded border-black/20 dark:border-white/20"}),oe?"Unselect all":"Select all"]}),e.jsxs(k,{variant:"default",children:["Total: ",c.length]}),e.jsxs(k,{variant:"success",children:["Active: ",et]})]}),(h.length>0||v)&&e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 rounded-lg border border-primary/30 bg-primary/5 px-3 py-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-primary",children:"checklist"}),e.jsx("span",{className:"text-xs font-medium text-primary",children:h.length>0?`${h.length} selected`:"All pools"}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[e.jsx(i,{size:"sm",icon:v?"progress_activity":"health_and_safety",onClick:_e,disabled:v||z||c.length===0,children:v?`Checking ${be.current}/${be.total}`:"Health Check"}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(i,{size:"sm",variant:"secondary",icon:"toggle_on",onClick:()=>Ce(!0),disabled:z||v,children:"Activate"}),e.jsx(i,{size:"sm",variant:"secondary",icon:"toggle_off",onClick:()=>Ce(!1),disabled:z||v,children:"Deactivate"}),e.jsx(i,{size:"sm",variant:"secondary",icon:"delete",onClick:Ve,disabled:z||v,children:"Delete"}),e.jsx(i,{size:"sm",variant:"ghost",onClick:ke,disabled:z||v,children:"Clear"})]})]})]}),c.length===0?e.jsxs("div",{className:"text-center py-10",children:[e.jsx("p",{className:"text-text-main font-medium mb-1",children:"No proxy pool entries yet"}),e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create a proxy pool entry, then assign it to connections."}),e.jsx(i,{icon:"add",onClick:ve,children:"Add Proxy Pool"})]}):e.jsx("div",{className:"flex flex-col divide-y divide-black/[0.04] dark:divide-white/[0.05]",children:c.map(t=>e.jsxs("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("input",{type:"checkbox",checked:h.includes(t.id),onChange:()=>Be(t.id),className:"mt-1 size-4 shrink-0 rounded border-black/20 dark:border-white/20"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"min-w-0 max-w-full truncate text-sm font-medium sm:max-w-[18rem]",children:t.name}),e.jsx(k,{variant:at(t.testStatus),size:"sm",dot:!0,children:t.testStatus||"unknown"}),e.jsx(k,{variant:t.isActive?"success":"default",size:"sm",children:t.isActive?"active":"inactive"}),t.type==="vercel"&&e.jsx(k,{variant:"default",size:"sm",children:"vercel relay"}),t.type==="cloudflare"&&e.jsx(k,{variant:"default",size:"sm",children:"cloudflare relay"}),e.jsxs(k,{variant:"default",size:"sm",children:[t.boundConnectionCount||0," bound"]})]}),e.jsx("p",{className:"text-xs text-text-muted truncate mt-1",children:t.proxyUrl}),t.noProxy?e.jsxs("p",{className:"text-xs text-text-muted truncate",children:["No proxy: ",t.noProxy]}):null,e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:["Last tested: ",nt(t.lastTestedAt),t.lastError?` · ${t.lastError}`:""]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(ie,{size:"sm",checked:t.isActive===!0,onChange:()=>We(t),title:t.isActive?"Disable":"Enable"}),e.jsx("button",{onClick:()=>ze(t.id),className:"p-2 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary",title:"Test proxy",disabled:ee===t.id,children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",style:ee===t.id?{animation:"spin 1s linear infinite"}:void 0,children:ee===t.id?"progress_activity":"science"})}),e.jsx("button",{onClick:()=>Me(t),className:"p-2 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary",title:"Edit",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsx("button",{onClick:()=>Re(t),className:"p-2 rounded hover:bg-red-500/10 text-red-500",title:"Delete",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]},t.id))})]}),e.jsx(I,{isOpen:$e,title:"Batch Import Proxies",onClose:Ne,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-text-main mb-1 block",children:"Paste Proxy List (One per line)"}),e.jsx("textarea",{value:X,onChange:t=>ue(t.target.value),placeholder:`http://user:pass@127.0.0.1:7897
6
+ 127.0.0.1:7897:user:pass`,className:"w-full min-h-[180px] py-2 px-3 text-sm text-text-main bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-md focus:ring-1 focus:ring-primary/30 focus:border-primary/50 focus:outline-none transition-all"}),e.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Supported formats: protocol://user:pass@host:port, host:port:user:pass"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Ze,disabled:!X.trim()||J,children:J?"Importing...":"Import"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:Ne,disabled:J,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Ee,title:"Deploy Vercel Relay",onClose:le,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg bg-blue-500/5 border border-blue-500/10 p-3 flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm text-text-main font-medium",children:"What is Vercel Relay?"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Deploys an edge relay function to Vercel. All AI provider requests will be forwarded through Vercel's edge network, masking your real IP from providers."}),e.jsxs("ul",{className:"text-xs text-text-muted list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"Your IP is replaced by Vercel's dynamic edge IPs (hundreds of IPs across 20+ global regions)"}),e.jsx("li",{children:"Vercel serves millions of apps — providers can't block Vercel IPs without affecting legitimate traffic"}),e.jsx("li",{children:"Free tier: 100GB bandwidth/month, 500K edge invocations"}),e.jsx("li",{children:"Deploy multiple relays on different accounts for more IP diversity"})]})]}),e.jsx(y,{label:"Vercel API Token",value:F.vercelToken,onChange:t=>Z(s=>({...s,vercelToken:t.target.value})),placeholder:"your-vercel-api-token",hint:e.jsxs(e.Fragment,{children:["Token is used once for deployment and not stored. ",e.jsx("a",{href:"https://vercel.com/account/tokens",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Get token →"})]}),type:"password"}),e.jsx(y,{label:"Project Name",value:F.projectName,onChange:t=>Z(s=>({...s,projectName:t.target.value})),placeholder:"my-relay",hint:"Unique name for your Vercel project. Leave empty for auto-generated name."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Ye,disabled:!F.vercelToken.trim()||p,children:p?"Deploying... (may take ~1 min)":"Deploy"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:le,disabled:p,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Ue,title:"Deploy Cloudflare Relay",onClose:ae,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg bg-orange-500/5 border border-orange-500/10 p-3 flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm text-text-main font-medium",children:"What is Cloudflare Relay?"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Deploys a Cloudflare Worker as a proxy relay. All AI provider requests will be forwarded through Cloudflare's global edge network."}),e.jsxs("ul",{className:"text-xs text-text-muted list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"High performance global routing and IP masking via Cloudflare Workers"}),e.jsx("li",{children:"Free tier: 100,000 requests per day"}),e.jsx("li",{children:"Requires Cloudflare Account ID and a Workers API Token (Edit Workers permission)"})]}),e.jsxs("div",{className:"mt-2 pt-2 border-t border-orange-500/10 text-xs text-text-muted",children:[e.jsx("p",{className:"font-medium text-text-main mb-1",children:"How to generate your API Token:"}),e.jsxs("ol",{className:"list-decimal pl-4 space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("b",{children:"My Profile"})," → ",e.jsx("b",{children:"API Tokens"})," → ",e.jsx("b",{children:"Create Token"})]}),e.jsxs("li",{children:["Scroll down to ",e.jsx("b",{children:"Custom Token"})," and click ",e.jsx("b",{children:"Get started"})]}),e.jsxs("li",{children:["Under ",e.jsx("b",{children:"Permissions"}),": Account | Workers Scripts | Edit"]}),e.jsxs("li",{children:["Under ",e.jsx("b",{children:"Account Resources"}),": Include | Account | ",e.jsx("i",{children:"Your Account Name"})]}),e.jsxs("li",{children:["Click ",e.jsx("b",{children:"Continue to summary"})," → ",e.jsx("b",{children:"Create Token"})]})]})]})]}),e.jsx(y,{label:"Account ID",value:j.accountId,onChange:t=>_(s=>({...s,accountId:t.target.value})),placeholder:"your-cloudflare-account-id",hint:e.jsx(e.Fragment,{children:"Found on the right side of the Cloudflare dashboard overview page."})}),e.jsx(y,{label:"API Token",value:j.apiToken,onChange:t=>_(s=>({...s,apiToken:t.target.value})),placeholder:"your-cloudflare-api-token",hint:e.jsxs(e.Fragment,{children:['Requires "Workers Scripts: Edit" permission. ',e.jsx("a",{href:"https://dash.cloudflare.com/profile/api-tokens",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Get token →"})]}),type:"password"}),e.jsx(y,{label:"Worker Name",value:j.projectName,onChange:t=>_(s=>({...s,projectName:t.target.value})),placeholder:"my-relay",hint:"Unique name for your Cloudflare Worker. Leave empty for auto-generated name."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Ke,disabled:!j.accountId.trim()||!j.apiToken.trim()||p,children:p?"Deploying...":"Deploy Worker"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:ae,disabled:p,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Oe,title:"Deploy Deno Relay",onClose:ne,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 p-3 flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm text-text-main font-medium",children:"What is Deno Relay?"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Deploys a relay worker to Deno Deploy's global edge network. All AI provider requests are forwarded through Deno's edge, masking your real IP."}),e.jsxs("ul",{className:"text-xs text-text-muted list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"Deno Deploy v2 runs on a high-performance global edge network"}),e.jsx("li",{children:"Free tier: 1M requests & 100GiB outbound traffic per month"}),e.jsx("li",{children:"No per-request CPU time limits (unlike Vercel/Cloudflare)"}),e.jsx("li",{children:"Support up to 20 active apps & 50 custom domains"}),e.jsx("li",{children:"Deploy multiple relays for maximum IP diversity"})]}),e.jsxs("div",{className:"mt-2 pt-2 border-t border-black/10 dark:border-white/10 text-xs text-text-muted",children:[e.jsx("p",{className:"font-medium text-text-main mb-1",children:"How to generate API token:"}),e.jsxs("ol",{className:"list-decimal pl-4 space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("b",{children:"console.deno.com"})]}),e.jsxs("li",{children:["Select your ",e.jsx("b",{children:"Organization"})," → ",e.jsx("b",{children:"Settings"})," → ",e.jsx("b",{children:"Organization Tokens"})]}),e.jsxs("li",{children:["Create a ",e.jsx("b",{children:"Organization Token"})," (prefix ",e.jsx("b",{children:"ddo_"}),")"]})]})]})]}),e.jsx(y,{label:"Deno Deploy API Token",value:N.denoToken,onChange:t=>q(s=>({...s,denoToken:t.target.value})),placeholder:"ddo_xxxxxxxxxxxxxxxx",hint:e.jsx(e.Fragment,{children:"Token is used once for deployment, not stored. Found in Organization Settings."}),type:"password"}),e.jsx(y,{label:"Organization Domain",value:N.orgDomain,onChange:t=>q(s=>({...s,orgDomain:t.target.value})),placeholder:"your-org.deno.net",hint:"Organization's default domain. Your relay URL will be in the format: https://my-relay.your-org.deno.net"}),e.jsx(y,{label:"App Name",value:N.projectName,onChange:t=>q(s=>({...s,projectName:t.target.value})),placeholder:"deno-relay",hint:"Unique app name. Leave empty for auto-generated name."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Qe,disabled:!N.denoToken.trim()||!N.orgDomain.trim()||p,children:p?"Deploying...":"Deploy Relay"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:ne,disabled:p,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Ae,title:V?"Edit Proxy Pool":"Add Proxy Pool",onClose:re,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(y,{label:"Name",value:u.name,onChange:t=>C(s=>({...s,name:t.target.value})),placeholder:"Office Proxy"}),e.jsx(y,{label:"Proxy URL",value:u.proxyUrl,onChange:t=>C(s=>({...s,proxyUrl:t.target.value})),placeholder:"http://127.0.0.1:7897"}),e.jsx(y,{label:"No Proxy",value:u.noProxy,onChange:t=>C(s=>({...s,noProxy:t.target.value})),placeholder:"localhost,127.0.0.1,.internal",hint:"Comma-separated hosts/domains to bypass proxy"}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border/50 p-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Active"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Inactive pools are ignored by runtime resolution."})]}),e.jsx(ie,{checked:u.isActive===!0,onChange:()=>C(t=>({...t,isActive:!t.isActive})),disabled:R})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border/50 p-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Strict Proxy"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Fail request if proxy is unreachable instead of falling back to direct."})]}),e.jsx(ie,{checked:u.strictProxy===!0,onChange:()=>C(t=>({...t,strictProxy:!t.strictProxy})),disabled:R})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Fe,disabled:!u.name.trim()||!u.proxyUrl.trim()||R,children:R?"Saving...":"Save"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:re,disabled:R,children:"Cancel"})]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Proxy Combos"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Round-robin rotation across multiple pools"})]}),e.jsx(i,{size:"sm",icon:"add",onClick:()=>{Y(null),B(""),L([]),A(!0)},children:"Add Combo"})]}),x.length===0?e.jsx("p",{className:"text-sm text-text-muted py-4 text-center",children:"No combos yet. Create one to rotate proxies automatically."}):e.jsx("div",{className:"space-y-2",children:x.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border border-border-subtle bg-surface hover:bg-surface/50",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-sm text-text-main",children:t.name}),e.jsx("p",{className:"text-xs text-text-muted mt-0.5",children:(t.poolIds||[]).map((s,r)=>e.jsxs("span",{children:[r>0?" → ":"",rt(s)]},s))})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-3",children:[e.jsxs(k,{variant:"success",size:"sm",children:[(t.poolIds||[]).length," pools"]}),e.jsx("button",{onClick:()=>{Y(t),B(t.name),L(t.poolIds||[]),A(!0)},className:"text-xs text-brand-400 hover:text-brand-300 cursor-pointer",children:"Edit"}),e.jsx("button",{onClick:()=>st(t.id),className:"text-xs text-red-400 hover:text-red-300 cursor-pointer",children:"Delete"})]})]},t.id))})]}),e.jsx(I,{isOpen:De,onClose:()=>A(!1),title:E?"Edit Combo":"Create Proxy Combo",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-text-muted block mb-1",children:"Combo Name"}),e.jsx(y,{value:$,onChange:t=>B(t.target.value),placeholder:"e.g. Free Proxy Round Robin"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-text-muted block mb-2",children:"Select Pools (click to toggle)"}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1 rounded-lg border border-border-subtle p-2",children:c.map(t=>e.jsxs("label",{className:`flex items-center gap-2 p-2 rounded cursor-pointer text-sm transition-colors ${b.includes(t.id)?"bg-primary/10 text-primary":"hover:bg-surface-2 text-text-main"}`,children:[e.jsx("input",{type:"checkbox",checked:b.includes(t.id),onChange:s=>{L(s.target.checked?[...b,t.id]:b.filter(r=>r!==t.id))},className:"rounded"}),t.name]},t.id))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{fullWidth:!0,onClick:tt,disabled:!$.trim()||b.length===0,children:E?"Save Changes":"Create Combo"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:()=>A(!1),children:"Cancel"})]})]})}),e.jsx(lt,{isOpen:!!g,onClose:()=>w(null),onConfirm:g==null?void 0:g.onConfirm,title:(g==null?void 0:g.title)||"Confirm",message:g==null?void 0:g.message,variant:"danger"})]})}export{ht as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.DZiGd5-F.js";import{b as n,f as h}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function u(){const[s]=h(),[a,l]=n.useState("processing");return n.useEffect(()=>{const r=s.get("code"),i=s.get("state"),o=s.get("error"),d=s.get("error_description"),c={code:r,state:i,error:o,errorDescription:d,fullUrl:window.location.href},m=[window.location.origin,"http://localhost:1455","http://localhost:51121"];if(window.opener)for(const t of m)try{window.opener.postMessage({type:"oauth_callback",data:c},t)}catch(x){console.log("postMessage failed:",x)}try{const t=new BroadcastChannel("oauth_callback");t.postMessage(c),t.close()}catch(t){console.log("BroadcastChannel failed:",t)}try{localStorage.setItem("oauth_callback",JSON.stringify({...c,timestamp:Date.now()}))}catch(t){console.log("localStorage failed:",t)}if(!(r||o)){setTimeout(()=>l("manual"),0);return}l("success"),setTimeout(()=>{window.close(),setTimeout(()=>l("done"),500)},1500)},[s]),e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bg",children:e.jsxs("div",{className:"text-center p-8 max-w-md",children:[a==="processing"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-primary animate-spin",children:"progress_activity"})}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Processing..."}),e.jsx("p",{className:"text-text-muted",children:"Please wait while we complete the authorization."})]}),(a==="success"||a==="done")&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Authorization Successful!"}),e.jsx("p",{className:"text-text-muted",children:a==="success"?"This window will close automatically...":"You can close this tab now."})]}),a==="manual"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-yellow-100 dark:bg-yellow-900/30 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-yellow-600",children:"info"})}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Copy This URL"}),e.jsx("p",{className:"text-text-muted mb-4",children:"Please copy the URL from the address bar and paste it in the application."}),e.jsx("div",{className:"bg-surface border border-border rounded-lg p-3 text-left",children:e.jsx("code",{className:"text-xs break-all",children:typeof window<"u"?window.location.href:""})})]})]})})}function b(){return e.jsx(n.Suspense,{fallback:e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bg",children:e.jsxs("div",{className:"text-center p-8",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-primary animate-spin",children:"progress_activity"})}),e.jsx("p",{className:"text-text-muted",children:"Loading..."})]})}),children:e.jsx(u,{})})}export{b as default};
@@ -0,0 +1 @@
1
+ import{h as et,j as e,U as tt,P as Ae}from"./index.DZiGd5-F.js";import{b as c}from"./router.Cjj1--8t.js";import{C as rt}from"./Loading.BUhrzmZs.js";import{C as ce,T as st,E as nt}from"./NoAuthProxyCard.BI22GO9q.js";import"./zustand.akaTi5uX.js";function at(s){if(!s)return"-";try{const u=(typeof s=="string"?new Date(s):s)-new Date;if(u<=0)return"-";const l=Math.ceil(u/(1e3*60));if(l<60)return`${l}m`;const a=Math.floor(l/60),x=l%60;if(a<24)return`${a}h ${x}m`;const h=Math.floor(a/24),p=a%24;return`${h}d ${p}h ${x}m`}catch{return"-"}}function $e(s,n){return!n||n===0?0:!s||s<0?100:s>=n?0:Math.round((n-s)/n*100)}function it(s){return(s==null?void 0:s.remaining)!==void 0?Math.max(0,Math.round(s.remaining)):(s==null?void 0:s.remainingPercentage)!==void 0?Math.round(s.remainingPercentage):$e(s==null?void 0:s.used,s==null?void 0:s.total)}function ot(s,n){if(!n||typeof n!="object")return[];const o=[];try{switch(s.toLowerCase()){case"github":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null})});break;case"antigravity":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:a.displayName||l,modelKey:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,remainingPercentage:a.remainingPercentage})});break;case"codex":if(n.quotas){const l={session:"Session (5h)",weekly:"Weekly (7d)",code_review:"Code Review",code_review_weekly:"Code Review Weekly",spark:"Spark",spark_weekly:"Spark Weekly"};Object.entries(n.quotas).forEach(([a,x])=>{o.push({name:x.displayName||l[a]||a,used:x.used||0,total:x.total||0,remaining:x.remaining,resetAt:x.resetAt||null})})}n.bankedResetCredits!==void 0&&n.bankedResetCredits>0&&o.push({name:"Banked Reset Credits",used:0,total:n.bankedResetCredits,remaining:n.bankedResetCredits,resetAt:null});break;case"kiro":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null})});break;case"qoder":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{l==="organization"&&(!a||(Number(a.total)||0)===0)||o.push({name:l==="user"?"Personal":l==="organization"?"Organization":l,used:a.used||0,total:a.total||0,unit:a.unit,resetAt:a.resetAt||null})});break;case"claude":n.message?o.push({name:"error",used:0,total:0,resetAt:null,message:n.message}):n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null})});break;case"leonardo":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l==="tokens"?"Tokens":l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||null,remaining:a.remaining!==void 0?a.remaining:null})});break;case"weavy":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l==="tokens"?"tokens":l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||null,remaining:a.remaining!==void 0?a.remaining:null})});break;case"cloudflare-ai":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||"neurons"})});break;default:n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||null,remaining:a.remaining!==void 0?a.remaining:null})})}}catch(l){return console.error(`Error parsing quota data for ${s}:`,l),[]}const u=et(s);if(u.length>0){const l=new Map(u.map((a,x)=>[a.id,x]));o.sort((a,x)=>{const h=a.modelKey||a.name,p=x.modelKey||x.name,U=l.get(h)??999,G=l.get(p)??999;return U-G})}return o}const W=10;function lt(s){if(!s)return null;try{const n=new Date(s),o=new Date,u=new Date(o.getFullYear(),o.getMonth(),o.getDate()),l=new Date(u);l.setDate(l.getDate()+1);let a="";n>=u&&n<l?a="Today":n>=l&&n<new Date(l.getTime()+1440*60*1e3)?a="Tomorrow":a=n.toLocaleDateString("en-US",{month:"short",day:"numeric"});const x=n.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return`${a}, ${x}`}catch{return null}}function ct(s){return s>70?{text:"text-green-600 dark:text-green-400",bg:"bg-green-500",bgLight:"bg-green-500/10",emoji:"🟢"}:s>=30?{text:"text-yellow-600 dark:text-yellow-400",bg:"bg-yellow-500",bgLight:"bg-yellow-500/10",emoji:"🟡"}:{text:"text-red-600 dark:text-red-400",bg:"bg-red-500",bgLight:"bg-red-500/10",emoji:"🔴"}}function dt(s,n){return n==="remaining-asc"?[...s].sort((o,u)=>o.remaining-u.remaining||o.name.localeCompare(u.name)):n==="remaining-desc"?[...s].sort((o,u)=>u.remaining-o.remaining||o.name.localeCompare(u.name)):s}function ut({quotas:s=[],compact:n=!1,sortMode:o="default",showSortLabel:u=!1}){const[l,a]=c.useState(1),x=c.useMemo(()=>s.map((m,f)=>({...m,index:f,remaining:it(m)})),[s]),h=c.useMemo(()=>dt(x,o),[x,o]),p=Math.max(1,Math.ceil(h.length/W));if(c.useEffect(()=>{a(1)},[o,s]),c.useEffect(()=>{a(m=>Math.min(m,p))},[p]),!s||s.length===0)return null;const U=h.slice((l-1)*W,l*W),G=h.length===0?0:(l-1)*W+1,V=Math.min(l*W,h.length),b=n?"py-1 px-1.5":"py-2 px-3",q=n?"text-[11px]":"text-sm",v=n?"text-[11px]":"text-sm",J=n?"text-[10px] leading-tight":"text-xs";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[h.length," quota",h.length>1?"s":""]}),u&&e.jsx("div",{className:"rounded-md border border-black/10 bg-black/[0.02] px-2 py-1 text-[10px] text-text-muted dark:border-white/10 dark:bg-white/[0.03]",children:"Sorted by account remaining"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"w-full table-fixed text-left",children:e.jsx("tbody",{children:U.map(m=>{var B;const f=ct(m.remaining),I=at(m.resetAt),D=lt(m.resetAt),te=((B=m.name)==null?void 0:B.toLowerCase())==="tokens"?Math.max(0,m.total-m.used):m.used;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:`${b} w-[30%]`,children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-[10px] shrink-0",children:f.emoji}),e.jsx("span",{className:`${q} font-medium text-text-primary truncate`,children:m.name})]})}),e.jsx("td",{className:`${b} w-[45%]`,children:e.jsxs("div",{className:n?"space-y-1":"space-y-1.5",children:[e.jsx("div",{className:`${n?"h-1":"h-1.5"} rounded-full overflow-hidden border ${f.bgLight} ${m.remaining===0?"border-black/10 dark:border-white/10":"border-transparent"}`,children:e.jsx("div",{className:`h-full transition-all duration-300 ${f.bg}`,style:{width:`${Math.min(m.remaining,100)}%`}})}),e.jsxs("div",{className:`flex items-center justify-between ${n?"text-[10px]":"text-xs"}`,children:[e.jsxs("span",{className:"text-text-muted",children:[te.toLocaleString()," / ",m.total>0?m.total.toLocaleString():"∞"]}),e.jsxs("span",{className:`font-medium ${f.text}`,children:[m.remaining,"%"]})]})]})}),e.jsx("td",{className:`${b} w-[25%]`,children:I!=="-"||D?n?e.jsx("div",{className:`${v} text-text-primary font-medium truncate`,title:D||"",children:I!=="-"?`in ${I}`:D}):e.jsxs("div",{className:"space-y-0.5",children:[I!=="-"&&e.jsxs("div",{className:`${v} text-text-primary font-medium`,children:["in ",I]}),D&&e.jsx("div",{className:`${J} text-text-muted`,children:D})]}):e.jsx("div",{className:`${v} text-text-muted italic`,children:"N/A"})})]},`${m.name}-${m.index}`)})})})}),p>1&&e.jsxs("div",{className:"rounded-md border border-black/10 bg-black/[0.02] px-2 py-1.5 dark:border-white/10 dark:bg-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px] text-text-muted",children:[e.jsxs("span",{children:["Showing ",G,"-",V," of ",h.length]}),e.jsxs("span",{children:["Page ",l," / ",p]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>a(m=>Math.max(1,m-1)),disabled:l===1,className:"flex h-6 items-center rounded-md border border-black/10 px-2 text-[10px] text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"Prev"}),e.jsx("button",{type:"button",onClick:()=>a(m=>Math.min(p,m+1)),disabled:l===p,className:"flex h-6 items-center rounded-md border border-black/10 px-2 text-[10px] text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"Next"})]})]})]})}function X(s){const n=o=>typeof o=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o);return n(s.email)?s.email:(n(s.name),s.name)}function mt(s,n,o){if(!o)return s;const u=l=>{var x;const a=(((x=n[l.id])==null?void 0:x.quotas)||[]).map(h=>h.resetAt?new Date(h.resetAt).getTime():Number.POSITIVE_INFINITY).filter(h=>Number.isFinite(h));return a.length>0?Math.min(...a):Number.POSITIVE_INFINITY};return[...s].sort((l,a)=>{const x=u(l)-u(a);return x!==0?x:(l.provider||"").localeCompare(a.provider||"")||(X(l)||"").localeCompare(X(a)||"")})}function Pe(s){const n={};return s.forEach(o=>{n[o.id]=!0}),n}function Z(s,n){const o=new Set(n.map(u=>u.id));return Object.fromEntries(Object.entries(s).filter(([u])=>o.has(u)))}function xt(s){if(!s.total)return{start:0,end:0};const n=(s.page-1)*s.pageSize+1,o=Math.min(s.page*s.pageSize,s.total);return{start:n,end:o}}function ht(s,n,o){return s.eligibleConnections?s.providerFilteredConnections?{icon:"filter_alt_off",title:"No Accounts On This Page",description:"Try moving to another page or refreshing the current filters."}:{icon:"filter_alt_off",title:"No Accounts Match Current Filters",description:n==="all"?"Try changing the account status filter to see more quota trackers.":`No ${o==="inactive"?"turned off":o==="active"?"active":"matching"} accounts found for ${n}.`}:{icon:"cloud_off",title:"No Providers Connected",description:"Connect to providers with OAuth to track your API quota limits and usage."}}function pt(s){const{start:n,end:o}=xt(s);return`Showing ${n}-${o} of ${s.total}`}function bt(s,n){return s||{page:1,pageSize:n,total:0,totalPages:1}}function gt(s,n=0){return s||{eligibleConnections:n,providerFilteredConnections:n}}function de(s,n){return s!==n}function ft(s,n){return(s==null?void 0:s.page)||n}function yt(s){return s||[]}async function ue(s,n){return await s(n)}const he="quotaCacheData";function Me(){if(typeof window>"u")return{};try{const s=window.localStorage.getItem(he);return s?JSON.parse(s):{}}catch(s){return console.error("Error reading quota cache:",s),{}}}function Te(s,n){if(!(typeof window>"u"))try{const o=Me();o[s]={...n,cachedAt:new Date().toISOString()},window.localStorage.setItem(he,JSON.stringify(o))}catch(o){console.error("Error writing quota cache:",o)}}const Oe=6e4,vt=5,Ie="quotaAutoRefresh",wt=[{value:"all",label:"All accounts"},{value:"active",label:"Active"},{value:"inactive",label:"Turned off"}],kt=[{value:"default",label:"Default order"},{value:"remaining-asc",label:"Least credits first"},{value:"remaining-desc",label:"Most credits first"},{value:"balance-asc",label:"Saldo Terendah (Lowest Balance)"},{value:"balance-desc",label:"Saldo Tertinggi (Highest Balance)"}],me=20,De=[10,20,50,100],xe=500;function jt(){const[s,n]=c.useState([]),[o,u]=c.useState({}),[l,a]=c.useState({}),[x,h]=c.useState({}),[p,U]=c.useState(!0),[G,V]=c.useState(null),[b,q]=c.useState(!1),[v,J]=c.useState(!1),[pe,m]=c.useState(60),[f,I]=c.useState(!0),[D,ee]=c.useState(null),[te,B]=c.useState(null),[_e,re]=c.useState(!1),[R,se]=c.useState(null),[Re,Le]=c.useState([]),[A,ne]=c.useState("all"),[Fe,be]=c.useState([]),[L,ge]=c.useState("all"),[P,fe]=c.useState("default"),[F,ze]=c.useState(!1),[Nt,St]=c.useState(!1),[Y,ye]=c.useState(!1),[w,C]=c.useState(1),[$,ae]=c.useState(me),[ie,Q]=c.useState(String(me)),[E,ve]=c.useState({page:1,pageSize:me,total:0,totalPages:1}),[k,we]=c.useState({eligibleConnections:0,providerFilteredConnections:0}),T=c.useRef(null),O=c.useRef(null),j=c.useCallback(async(t=w)=>{try{let r="priority";F?r="expiring":P==="remaining-asc"?r="usage-asc":P==="remaining-desc"?r="usage-desc":P==="balance-asc"?r="balance-asc":P==="balance-desc"&&(r="balance-desc");const i=new URLSearchParams({page:String(t),pageSize:String($),accountStatus:L,sort:r});A!=="all"&&i.set("provider",A);const d=await fetch(`/api/providers/client?${i.toString()}`);if(!d.ok)throw new Error("Failed to fetch connections");const N=await d.json(),g=N.connections||[],y=bt(N.pagination,$),S=gt(N.totals,g.length);return n(g),be(yt(N.providerOptions)),ve(y),we(S),C(ft(N.pagination,t)),g}catch(r){return console.error("Error fetching connections:",r),n([]),be([]),ve({page:1,pageSize:$,total:0,totalPages:1}),we({eligibleConnections:0,providerFilteredConnections:0}),[]}},[L,F,w,$,A,P]),M=c.useCallback(async(t,r)=>{a(i=>({...i,[t]:!0})),h(i=>({...i,[t]:null}));try{const i=await fetch(`/api/usage/${t}`);if(!i.ok){const S=(await i.json().catch(()=>({}))).error||i.statusText;if(i.status===404)return;if(i.status===401){const _={quotas:[],message:S};u(H=>({...H,[t]:_})),Te(t,_);return}throw new Error(`HTTP ${i.status}: ${S}`)}const d=await i.json(),g={quotas:ot(r,d),plan:d.plan||null,message:d.message||null,raw:d};u(y=>({...y,[t]:g})),Te(t,g)}catch(i){h(d=>({...d,[t]:i.message||"Failed to fetch quota"}))}finally{a(i=>({...i,[t]:!1}))}},[]),Ue=c.useCallback(async(t,r)=>{await M(t,r),V(new Date)},[M]),Qe=c.useCallback(async t=>{if(confirm("Delete this connection?")){ee(t);try{if((await fetch(`/api/providers/${t}`,{method:"DELETE"})).ok){if(u(i=>{const d={...i};return delete d[t],d}),a(i=>{const d={...i};return delete d[t],d}),h(i=>{const d={...i};return delete d[t],d}),typeof window<"u")try{const i=Me();i[t]&&(delete i[t],window.localStorage.setItem(he,JSON.stringify(i)))}catch(i){console.error("Error deleting cache entry:",i)}await ue(j,w)}}catch(r){console.error("Error deleting connection:",r)}finally{ee(null)}}},[j,w]),He=c.useCallback(async(t,r)=>{B(t);try{(await fetch(`/api/providers/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:r})})).ok&&(u(d=>({...d})),await ue(j,w))}catch(i){console.error("Error updating connection status:",i)}finally{B(null)}},[j,w]),Ve=c.useCallback(async t=>{if(!(R!=null&&R.id))return;const r=R.id,i=R.provider;try{(await fetch(`/api/providers/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok&&(await j(),re(!1),se(null),tt.includes(i)&&await M(r,i))}catch(d){console.error("Error saving connection:",d)}},[R,j,M]);c.useEffect(()=>{let t=!1;return fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}).then(r=>r.json()).then(r=>{!t&&(r!=null&&r.proxyPools)&&Le(r.proxyPools)}).catch(()=>{}),()=>{t=!0}},[]);const K=c.useCallback(async()=>{if(!v){J(!0),m(60);try{const t=await j(w);a(Pe(t)),h(r=>Z(r,t)),u(r=>Z(r,t)),await Promise.all(t.map(r=>M(r.id,r.provider))),V(new Date)}catch(t){console.error("Error refreshing all providers:",t)}finally{J(!1)}}},[v,j,M,w]);c.useEffect(()=>{if(!b)return;(async()=>{I(!0);const r=await j(w);I(!1),a(Pe(r)),h(i=>Z(i,r)),u(i=>Z(i,r)),await Promise.all(r.map(i=>M(i.id,i.provider))),V(new Date)})()},[j,M,w,b]);const ke="quotaProviderFilter",je="quotaAccountFilter",Ne="quotaSortMode";c.useEffect(()=>{if(typeof window>"u")return;const t=window.localStorage.getItem(Ie);U(t===null?!0:t==="true");const r=window.localStorage.getItem(ke);r&&ne(r);const i=window.localStorage.getItem(je);i&&ge(i);const d=window.localStorage.getItem(Ne);d&&fe(d),q(!0)},[]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(Ie,String(p))},[p,b]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(ke,A)},[A,b]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(je,L)},[L,b]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(Ne,P)},[P,b]),c.useEffect(()=>{if(!b||!p){T.current&&(clearInterval(T.current),T.current=null),O.current&&(clearInterval(O.current),O.current=null);return}return T.current=setInterval(()=>{K()},Oe),O.current=setInterval(()=>{m(t=>t<=1?60:t-1)},1e3),()=>{T.current&&clearInterval(T.current),O.current&&clearInterval(O.current)}},[p,K,b]),c.useEffect(()=>{const t=()=>{document.hidden?(T.current&&(clearInterval(T.current),T.current=null),O.current&&(clearInterval(O.current),O.current=null)):p&&b&&(T.current=setInterval(K,Oe),O.current=setInterval(()=>{m(r=>r<=1?60:r-1)},1e3))};return document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t)}},[p,K,b]);const z=c.useMemo(()=>mt(s,o,F),[s,o,F]),Se=t=>{var i;const r=(i=o[t.id])==null?void 0:i.quotas;return r!=null&&r.length?r.some(d=>!d.total||d.total<=0?!1:$e(d.used,d.total)<=vt):!1},Ce=t=>{const r=o[t.id];return r&&r.message==="Account disabled (Credits exhausted)"},oe=c.useCallback(async(t,r)=>{if(!(!t.length||Y)){ye(!0);try{await Promise.all(t.map(i=>fetch(`/api/providers/${i}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:r})}))),await ue(j,w)}catch(i){console.error("Error bulk toggling connections:",i)}finally{ye(!1)}}},[Y,j,w]),Be=()=>{const t=z.filter(r=>(r.isActive??!0)&&Se(r)).map(r=>r.id);oe(t,!1)},Ye=()=>{const t=z.filter(r=>(r.isActive??!0)&&Ce(r)).map(r=>r.id);oe(t,!1)},Ke=()=>{const t=z.filter(r=>!(r.isActive??!0)&&!Se(r)&&!Ce(r)).map(r=>r.id);oe(t,!0)},{totalCredits:We,providerStats:Ge,exhaustedCount:Ee}=c.useMemo(()=>{var N;let t=0;const r={};let i=0;z.forEach(g=>{const y=o[g.id];if(y&&y.message==="Account disabled (Credits exhausted)"&&(i+=1),!y)return;const S=g.provider;r[S]||(r[S]={accounts:0,credits:0}),r[S].accounts+=1,y.quotas&&y.quotas.forEach(_=>{let H=typeof _.remaining=="number"&&Number.isFinite(_.remaining)?_.remaining:Math.max(0,(_.total||0)-(_.used||0));Number.isFinite(H)&&H>0&&S!=="cloudflare-ai"&&(t+=H,r[S].credits+=H)})});const d=((N=k==null?void 0:k.providerCounts)==null?void 0:N["cloudflare-ai"])||0;if(d>0){const g=(k==null?void 0:k.cloudflareAi)!==void 0?Math.max(0,k.cloudflareAi.total-k.cloudflareAi.used):d*1e4;r["cloudflare-ai"]||(r["cloudflare-ai"]={accounts:d,credits:0}),r["cloudflare-ai"].accounts=d,r["cloudflare-ai"].credits=g,t+=g}return{totalCredits:t,providerStats:r,exhaustedCount:i}},[o,z,k]),Je=k.eligibleConnections>0,Ze=z.length>0,le=ht(k,A,L),Xe=pt(E),qe=!De.includes($);return!f&&!Je?e.jsx(ce,{padding:"lg",children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx("span",{className:"material-symbols-outlined text-[64px] text-text-muted opacity-20",children:"cloud_off"}),e.jsx("h3",{className:"mt-4 text-lg font-semibold text-text-primary",children:"No Providers Connected"}),e.jsx("p",{className:"mt-2 text-sm text-text-muted max-w-md mx-auto",children:"Connect to providers with OAuth to track your API quota limits and usage."})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-text-primary px-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 bg-black/5 dark:bg-white/10 px-2.5 py-1 rounded-md",title:"Total active accounts on this page",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-text-muted",children:"group"}),e.jsxs("span",{children:[k.providerFilteredConnections," Accounts"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 bg-primary/10 px-2.5 py-1 rounded-md",title:"Total credits across these accounts",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-primary",children:"database"}),e.jsxs("span",{className:"text-primary",children:[Math.floor(We)," Credits"]})]}),Ee>0&&e.jsxs("div",{className:"flex items-center gap-1.5 bg-red-500/10 px-2.5 py-1 rounded-md",title:"Total exhausted accounts",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-500",children:"warning"}),e.jsxs("span",{className:"text-red-500",children:[Ee," Exhausted"]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1 ml-2",children:Object.entries(Ge).map(([t,r])=>e.jsxs("div",{className:"flex items-center gap-1 bg-black/5 dark:bg-white/5 px-2 py-0.5 rounded text-xs text-text-muted border border-black/10 dark:border-white/10",title:`${r.accounts} accounts`,children:[e.jsx("span",{className:"capitalize",children:t}),": ",e.jsx("span",{className:"font-semibold text-text-primary",children:Math.floor(r.credits)})]},t))})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 justify-end",children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs("button",{type:"button",onClick:()=>{de(A,"all")&&C(1),ne("all")},className:`flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-xs font-medium transition-colors ${A==="all"?"bg-primary/15 text-primary border border-primary/30":"bg-black/5 text-text-muted border border-transparent hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"apps"}),e.jsx("span",{children:"All"})]}),Fe.map(t=>e.jsxs("button",{type:"button",onClick:()=>{de(A,t)&&C(1),ne(t)},className:`flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-xs font-medium transition-colors ${A===t?"bg-primary/15 text-primary border border-primary/30":"bg-black/5 text-text-muted border border-transparent hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10"}`,children:[e.jsx(Ae,{src:t==="codebuddy"||t==="cb"?"/providers/codebuddy.svg":`/providers/${t}.png`,alt:t,size:16,className:"size-4 rounded object-contain",fallbackText:t.slice(0,2).toUpperCase()}),e.jsx("span",{className:"capitalize",children:t})]},t))]}),e.jsx("select",{value:L,onChange:t=>{const r=t.target.value;de(L,r)&&C(1),ge(r)},className:"h-8 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Filter accounts by status",children:wt.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("select",{value:P,onChange:t=>fe(t.target.value),className:"h-8 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Sort quotas by remaining",children:kt.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsxs("button",{type:"button",onClick:()=>ze(t=>!t),"aria-pressed":F,className:`flex h-8 shrink-0 items-center gap-1 rounded-lg border px-2 text-xs transition-colors ${F?"border-amber-500/40 bg-amber-500/10 text-amber-500":"border-black/10 text-text-primary hover:bg-black/5 dark:border-white/10 dark:hover:bg-white/5"}`,title:"Sort accounts by earliest quota reset time",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"hourglass_top"}),e.jsx("span",{className:"hidden sm:inline",children:"Expiring first"})]}),e.jsxs("button",{type:"button",onClick:Be,disabled:Y,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10 disabled:opacity-50",title:"Disable connections with depleted quota on the current page",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"block"}),e.jsx("span",{className:"hidden sm:inline",children:"Turn off Empty"})]}),e.jsxs("button",{type:"button",onClick:Ye,disabled:Y,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10 disabled:opacity-50",title:"Disable connections that are exhausted",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"block"}),e.jsx("span",{className:"hidden sm:inline",children:"Disable Exhausted"})]}),e.jsxs("button",{type:"button",onClick:Ke,disabled:Y,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-emerald-500/30 px-2 text-xs text-emerald-500 transition-colors hover:bg-emerald-500/10 disabled:opacity-50",title:"Enable connections that still have quota on the current page",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check_circle"}),e.jsx("span",{className:"hidden sm:inline",children:"Turn on Available"})]}),e.jsxs("button",{onClick:()=>U(t=>!t),className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-black/10 px-2 text-xs transition-colors hover:bg-black/5 dark:border-white/10 dark:hover:bg-white/5",title:p?"Disable auto-refresh":"Enable auto-refresh",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px] ${p?"text-primary":"text-text-muted"}`,children:p?"toggle_on":"toggle_off"}),e.jsx("span",{className:"hidden text-text-primary sm:inline",children:"Auto-refresh"}),p&&e.jsxs("span",{className:"text-[10px] text-text-muted tabular-nums",children:["(",pe,"s)"]})]}),e.jsx("button",{type:"button",onClick:K,disabled:v,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-black/10 px-2 text-xs text-text-primary transition-colors hover:bg-black/5 dark:border-white/10 dark:hover:bg-white/5 disabled:opacity-50",title:"Refresh all",children:e.jsx("span",{className:`material-symbols-outlined text-[14px] ${v?"animate-spin":""}`,children:"refresh"})})]})]}),(F||P!=="default")&&e.jsx("div",{className:"rounded-xl border border-amber-500/20 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300 mb-3",children:"Sorting currently reorders accounts inside the current page. Cross-page ordering still follows backend pagination. Try increasing the page size to sort across more accounts."}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:!f&&!Ze?e.jsx("div",{className:"col-span-1 md:col-span-2",children:e.jsx(ce,{padding:"lg",children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx("span",{className:"material-symbols-outlined text-[64px] text-text-muted opacity-20",children:le.icon}),e.jsx("h3",{className:"mt-4 text-lg font-semibold text-text-primary",children:le.title}),e.jsx("p",{className:"mt-2 text-sm text-text-muted max-w-md mx-auto",children:le.description})]})})}):z.map(t=>{var y;const r=o[t.id],i=l[t.id],d=x[t.id],N=t.isActive===!1,g=D===t.id||te===t.id;return e.jsxs(ce,{padding:"none",className:`min-w-0 ${N?"opacity-60":""}`,children:[e.jsx("div",{className:"px-3 py-2 border-b border-black/10 dark:border-white/10",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 shrink-0 rounded-md flex items-center justify-center overflow-hidden",children:e.jsx(Ae,{src:t.provider==="codebuddy"||t.provider==="cb"?"/providers/codebuddy.svg":`/providers/${t.provider}.png`,alt:t.provider,size:32,className:"object-contain",fallbackText:((y=t.provider)==null?void 0:y.slice(0,2).toUpperCase())||"PR"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-primary capitalize truncate",children:t.provider}),X(t)?e.jsx("p",{className:"text-xs text-text-muted truncate",children:X(t)}):null]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Ue(t.id,t.provider),disabled:i||g,"aria-label":"Refresh quota",className:"p-1.5 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 transition-colors disabled:opacity-50",title:"Refresh quota",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] text-text-muted ${i?"animate-spin":""}`,children:"refresh"})}),e.jsx("button",{type:"button",onClick:()=>{se(t),re(!0)},disabled:g,"aria-label":"Edit connection",className:"p-1.5 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary transition-colors disabled:opacity-50",title:"Edit connection",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsx("button",{type:"button",onClick:()=>Qe(t.id),disabled:g,"aria-label":"Delete connection",className:"p-1.5 rounded-lg hover:bg-red-500/10 text-red-500 transition-colors disabled:opacity-50",title:"Delete connection",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] ${D===t.id?"animate-pulse":""}`,children:"delete"})}),e.jsx("div",{className:"inline-flex items-center pl-0.5",title:t.isActive??!0?"Disable connection":"Enable connection",children:e.jsx(st,{size:"sm",checked:t.isActive??!0,disabled:g,onChange:S=>He(t.id,S)})})]})]})}),e.jsx("div",{className:"px-2 py-1.5",children:i?e.jsx("div",{className:"text-center py-5 text-text-muted",children:e.jsx("span",{className:"material-symbols-outlined text-[28px] animate-spin",children:"progress_activity"})}):d?e.jsxs("div",{className:"text-center py-5",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-red-500",children:"error"}),e.jsx("p",{className:"mt-1.5 text-xs text-text-muted",children:d})]}):r!=null&&r.message?e.jsx("div",{className:"text-center py-5",children:e.jsx("p",{className:"text-xs text-text-muted",children:r.message})}):e.jsx(ut,{quotas:r==null?void 0:r.quotas,compact:!0,sortMode:"default",showSortLabel:t.provider==="codex"&&P!=="default"})})]},t.id)})}),e.jsx("div",{className:"rounded-xl border border-black/10 bg-black/[0.02] px-3 py-2 dark:border-white/10 dark:bg-white/[0.03]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-text-muted",children:Xe}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("select",{value:qe?"custom":String($),onChange:t=>{const r=t.target.value;if(r==="custom")return;const i=Number.parseInt(r,10);Number.isFinite(i)&&(C(1),ae(i),Q(String(i)))},className:"h-8 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Accounts per page",children:[De.map(t=>e.jsxs("option",{value:String(t),children:[t," / page"]},t)),e.jsx("option",{value:"500",children:"500 / page"}),e.jsx("option",{value:"1000",children:"1000 / page"}),e.jsx("option",{value:"custom",children:"Custom"})]}),e.jsx("input",{type:"number",min:"1",max:String(xe),inputMode:"numeric",value:ie,onChange:t=>Q(t.target.value),onBlur:()=>{const t=Number.parseInt(ie,10);if(!Number.isFinite(t)){Q(String($));return}const r=Math.min(xe,Math.max(1,t));C(1),ae(r),Q(String(r))},onKeyDown:t=>{if(t.key!=="Enter")return;const r=Number.parseInt(ie,10);if(!Number.isFinite(r)){Q(String($));return}const i=Math.min(xe,Math.max(1,r));C(1),ae(i),Q(String(i))},className:"h-8 w-20 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Custom accounts per page",placeholder:"Custom"}),e.jsxs("span",{className:"text-xs text-text-muted",children:["Page ",E.page," / ",E.totalPages]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(1),disabled:E.page<=1||f||v,className:"flex h-8 items-center rounded-lg border border-black/10 px-3 text-xs text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"First Page"}),e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(t=>Math.max(1,t-1)),disabled:E.page<=1||f||v,className:"flex h-8 w-8 items-center justify-center rounded-lg border border-black/10 text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5","aria-label":"Previous accounts page",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"chevron_left"})}),e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(t=>Math.min(E.totalPages,t+1)),disabled:E.page>=E.totalPages||f||v,className:"flex h-8 w-8 items-center justify-center rounded-lg border border-black/10 text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5","aria-label":"Next accounts page",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"chevron_right"})}),e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(E.totalPages),disabled:E.page>=E.totalPages||f||v,className:"flex h-8 items-center rounded-lg border border-black/10 px-3 text-xs text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"Last Page"})]})]})}),e.jsx(nt,{isOpen:_e,connection:R,proxyPools:Re,onSave:Ve,onClose:()=>{re(!1),se(null)}})]})}function Ot(){return e.jsx(c.Suspense,{fallback:e.jsx(rt,{}),children:e.jsx(jt,{})})}export{Ot as default};
@@ -0,0 +1 @@
1
+ import{j as e,B as I,y as te,h as ae,k as re,l as le}from"./index.DZiGd5-F.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.BI22GO9q.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};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.DZiGd5-F.js";import"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function i(){return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center size-8 rounded-lg bg-primary/10",children:e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"menu_book"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-sm font-semibold text-text-main",children:"API Reference"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Image & Video Generation — all providers, models, and parameters"})]})]}),e.jsxs("a",{href:"/image-video-docs.html",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-text-muted hover:text-text-main hover:bg-surface-2 transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"}),"Open in new tab"]})]}),e.jsx("iframe",{src:"/image-video-docs.html",className:"flex-1 w-full border-0 min-h-0",title:"Image & Video API Reference"})]})}export{i as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.DZiGd5-F.js";import{b as s}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function A(){const[a,y]=s.useState({currentVersion:"",latestVersion:"",hasUpdate:!1}),[k,b]=s.useState(!0),[f,i]=s.useState(!1),[c,g]=s.useState(0),[S,o]=s.useState(""),[m,h]=s.useState([]),[j,r]=s.useState(""),x=s.useRef(null),v=async()=>{try{b(!0);const n=await(await fetch("/api/version")).json();y(n)}catch(t){console.error(t),r("Gagal memuat informasi versi.")}finally{b(!1)}};s.useEffect(()=>{v()},[]),s.useEffect(()=>{x.current&&x.current.scrollIntoView({behavior:"smooth"})},[m]);const w=async()=>{if(window.confirm("Apakah Anda yakin ingin memulai update otomatis?")){i(!0),g(0),h([]),o("Menghubungi server untuk memulai update..."),r("");try{const n=await(await fetch("/api/version/update",{method:"POST"})).json();if(n.success){const d=new EventSource("/api/version/update");d.onmessage=u=>{const l=JSON.parse(u.data);if(g(l.progress||0),h(l.logs||[]),l.status==="updating")o(`Sedang memproses update... (${l.progress}%)`);else if(l.status==="done"||l.progress===100){d.close(),o("Update berhasil diselesaikan! Server sedang merestart...");let p=0;const N=setInterval(async()=>{p++,o(`Menunggu server online kembali... (Mencoba menghubungkan: ${p}s)`);try{(await fetch("/api/health")).ok&&(clearInterval(N),o("Update Selesai! Halaman akan dimuat ulang..."),setTimeout(()=>{window.location.reload()},1500))}catch{}p>90&&(clearInterval(N),i(!1),r("Server memakan waktu terlalu lama untuk online kembali. Silakan periksa status PM2 Anda secara manual."))},2e3)}},d.onerror=u=>{console.error("EventSource error:",u),c>80?d.close():(d.close(),r("Koneksi ke server terputus saat proses update berjalan."),i(!1))}}else r(n.message||"Gagal memulai update otomatis."),i(!1)}catch(t){console.error(t),r("Koneksi gagal saat memulai update."),i(!1)}}};return e.jsxs("div",{className:"max-w-4xl mx-auto p-4 space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("h1",{className:"text-2xl font-bold text-text-main flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"system_update"}),"FSRouter System Update"]}),e.jsx("p",{className:"text-xs text-text-muted",children:"Kelola dan perbarui versi FSRouter Anda langsung dari repositori GitHub atau NPM registry."})]}),k?e.jsx("div",{className:"flex items-center justify-center p-12 border border-border-subtle rounded-[14px] bg-surface",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-4xl animate-spin text-primary",children:"sync"}),e.jsx("span",{className:"text-sm text-text-muted",children:"Memuat informasi versi..."})]})}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface flex flex-col gap-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main",children:"Detail Versi"}),e.jsxs("div",{className:"flex items-center justify-between border-b border-border-subtle pb-3",children:[e.jsx("span",{className:"text-xs text-text-muted",children:"Versi Saat Ini"}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-text-main",children:["v",a.currentVersion||"0.0.0"]})]}),e.jsxs("div",{className:"flex items-center justify-between border-b border-border-subtle pb-3",children:[e.jsx("span",{className:"text-xs text-text-muted",children:"Versi Terbaru di GitHub"}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-text-main",children:["v",a.latestVersion||"0.0.0"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-text-muted",children:"Status"}),a.hasUpdate?e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold bg-amber-500/10 text-amber-500 border border-amber-500/20",children:"Update Tersedia"}):e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold bg-green-500/10 text-green-500 border border-green-500/20",children:"Versi Terbaru"})]})]}),e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface flex flex-col justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main",children:"Aksi Pembaruan"}),e.jsx("p",{className:"text-xs text-text-muted leading-relaxed",children:a.hasUpdate?"Versi baru tersedia! Update otomatis akan menginstal versi terbaru, memperbarui dependensi, membangun ulang kode, dan me-restart server FSRouter Anda secara mulus.":"FSRouter Anda sudah menggunakan versi terbaru. Tidak ada pembaruan yang diperlukan saat ini."})]}),f?e.jsxs("div",{className:"p-4 rounded-lg bg-primary/5 border border-primary/20 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] animate-spin",children:"sync"}),"Proses Update Sedang Berjalan: ",c,"%"]}),e.jsx("div",{className:"w-full bg-border-subtle rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"bg-primary h-2.5 rounded-full transition-all duration-500",style:{width:`${c}%`}})}),e.jsx("p",{className:"text-[11px] text-text-muted leading-relaxed",children:S})]}):e.jsxs("div",{className:"space-y-2",children:[j&&e.jsx("p",{className:"text-xs text-red-500 font-semibold bg-red-500/10 border border-red-500/20 p-3 rounded-lg",children:j}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{disabled:!a.hasUpdate,onClick:w,className:`flex-1 py-2 px-4 rounded-lg text-xs font-semibold text-white transition-colors flex items-center justify-center gap-2 ${a.hasUpdate?"bg-primary hover:bg-primary/90 cursor-pointer":"bg-border-subtle text-text-muted cursor-not-allowed"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"download"}),"Otomatis Update Sekarang"]}),e.jsx("button",{onClick:v,className:"py-2 px-3 rounded-lg border border-border-subtle text-text-main text-xs hover:bg-surface-2 transition-colors cursor-pointer",title:"Periksa Ulang",children:e.jsx("span",{className:"material-symbols-outlined text-[16px] block",children:"refresh"})})]})]})]})]}),f&&m.length>0&&e.jsxs("div",{className:"p-4 rounded-[14px] border border-border-subtle bg-black text-green-400 font-mono text-xs overflow-hidden flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2 border-b border-green-900/50",children:[e.jsxs("span",{className:"text-green-500 font-semibold flex items-center gap-1.5",children:[e.jsx("span",{className:"size-2 rounded-full bg-green-500 animate-pulse"}),"Logs Konsol Pembaruan"]}),e.jsx("span",{className:"text-[10px] text-green-600",children:"FSRouter Updater"})]}),e.jsxs("div",{className:"max-h-[300px] overflow-y-auto space-y-1 custom-scrollbar",children:[m.map((t,n)=>e.jsx("pre",{className:"whitespace-pre-wrap leading-relaxed break-all font-mono",children:t},n)),e.jsx("div",{ref:x})]})]})]})}export{A as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.DZiGd5-F.js";import{b as t,d as H}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function z(){const[x,N]=t.useState(""),[m,c]=t.useState(""),[W,b]=t.useState(""),[r,f]=t.useState(0),[g,w]=t.useState(!1),[y,u]=t.useState(null),[n,k]=t.useState("password"),[i,L]=t.useState(!1),[S,C]=t.useState("Sign in with OIDC"),[h,M]=t.useState(!1),l=H();t.useEffect(()=>{if(r<=0)return;const a=setInterval(()=>f(s=>s>0?s-1:0),1e3);return()=>clearInterval(a)},[r]),t.useEffect(()=>{async function a(){const s=new AbortController,o=setTimeout(()=>s.abort(),5e3),R=typeof window<"u"?window.location.origin:"";try{const v=await fetch(`${R}/api/auth/status`,{signal:s.signal});if(clearTimeout(o),v.ok){const d=await v.json(),j=new URLSearchParams(window.location.search),E=j.get("force")==="true"||j.get("force")==="1";if(d.requireLogin===!1&&!E){localStorage.setItem("9r_authed","1"),l("/dashboard"),l(0);return}u(!!d.hasPassword),k(d.authMode||"password"),L(d.oidcConfigured===!0),C(d.oidcLoginLabel||"Sign in with OIDC")}else u(!0)}catch{clearTimeout(o),u(!0)}}a()},[l]);const P=async a=>{a.preventDefault(),w(!0),c(""),b("");try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:x})});if(s.ok)localStorage.setItem("9r_authed","1"),l("/dashboard"),l(0);else{const o=await s.json();c(o.error||"Invalid password"),o.resetHint&&b(o.resetHint),o.retryAfter&&f(Number(o.retryAfter))}}catch{c("An error occurred. Please try again.")}finally{w(!1)}},I=()=>{window.location.href="/api/auth/oidc/start"},A=i&&["oidc","both"].includes(n),p=n!=="oidc"||!i,O=n==="oidc"&&!i||n==="both"&&!i,D=n==="both"&&i;return y===null?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-400"})}):e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 via-white to-slate-100 p-4",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-80 h-80 bg-violet-200/30 rounded-full blur-3xl"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-80 h-80 bg-blue-200/30 rounded-full blur-3xl"})]}),e.jsxs("div",{className:"relative w-full max-w-sm",children:[e.jsxs("div",{className:"bg-white rounded-2xl shadow-lg shadow-slate-200/50 border border-slate-200/60 p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-gradient-to-br from-violet-500 to-blue-500 mb-4 shadow-lg shadow-violet-500/25",children:e.jsx("svg",{className:"w-6 h-6 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),e.jsx("h1",{className:"text-2xl font-bold text-slate-900 tracking-tight",children:"FSRouter"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:n==="oidc"&&i?"Sign in with your OIDC provider":"Enter your password to continue"})]}),O&&e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-amber-50 border border-amber-200 text-xs text-amber-700",children:"OIDC not configured yet. Password login is available."}),D&&e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-violet-50 border border-violet-200 text-xs text-violet-700 text-center",children:"Password and OIDC login are both enabled."}),p&&e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 block mb-1.5",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{name:"password",type:h?"text":"password",placeholder:"••••••••",value:x,onChange:a=>N(a.target.value),required:!0,autoFocus:!0,className:"w-full bg-slate-50 border border-slate-200 text-slate-900 text-sm p-3 pr-10 rounded-xl focus:outline-none focus:border-violet-400 focus:ring-2 focus:ring-violet-100 placeholder-slate-400 transition-all"}),e.jsx("button",{type:"button",onClick:()=>M(!h),className:"absolute inset-y-0 right-3 flex items-center text-slate-400 hover:text-slate-600",children:h?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878l4.242 4.242M21 21l-3.122-3.122"})}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]}),m&&e.jsx("p",{className:"text-xs text-red-500 mt-1.5",children:m}),r>0&&e.jsxs("p",{className:"text-xs text-amber-600 mt-1.5",children:["Locked. Retry in ",r,"s."]})]}),e.jsx("button",{type:"submit",disabled:g||r>0,className:"w-full bg-gradient-to-r from-violet-500 to-blue-500 hover:from-violet-600 hover:to-blue-600 text-white font-medium text-sm py-3 rounded-xl transition-all shadow-lg shadow-violet-500/25 disabled:opacity-50 cursor-pointer",children:g?"Logging in...":r>0?`Wait ${r}s`:"Login"}),e.jsxs("p",{className:"text-center text-xs text-slate-400",children:["Default password is ",e.jsx("code",{className:"bg-slate-100 px-1.5 py-0.5 rounded text-slate-500 font-mono",children:"123456"})]})]}),A&&e.jsxs(e.Fragment,{children:[p&&e.jsxs("div",{className:"relative flex items-center justify-center py-4",children:[e.jsx("span",{className:"w-full border-t border-slate-200"}),e.jsx("span",{className:"px-3 text-xs text-slate-400 bg-white absolute",children:"or"})]}),e.jsxs("button",{onClick:I,type:"button",className:"w-full flex items-center justify-center gap-2 border border-slate-200 rounded-xl py-3 hover:bg-slate-50 transition-colors text-slate-600 text-sm cursor-pointer",children:[e.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4M10 17l5-5-5-5M15 12H3"})}),S]})]})]}),e.jsx("p",{className:"text-center text-xs text-slate-400 mt-6",children:"Powered by FSRouter"})]})]})}export{z as default};