@fudrouter/fsrouter 0.6.74 → 0.6.76

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 (46) hide show
  1. package/dist/routes/headroom/extras/route.js +2 -2
  2. package/package.json +1 -1
  3. package/public/assets/EndpointPageClient.BnlQVTIB.js +6 -0
  4. package/public/assets/{Loading.BHPtQ9vj.js → Loading.C1il44u0.js} +1 -1
  5. package/public/assets/{NoAuthProxyCard.BDcXaWvM.js → NoAuthProxyCard.WHGGEUIp.js} +1 -1
  6. package/public/assets/{index.Be3gbrBl.js → index.D4FwOBBU.js} +2 -2
  7. package/public/assets/{page.DiL4Gwqe.js → page.0Rt4rWPG.js} +1 -1
  8. package/public/assets/{page.B3QqvLep.js → page.1numFcXc.js} +1 -1
  9. package/public/assets/{page.C8sLEMa6.js → page.1w9bTOPd.js} +1 -1
  10. package/public/assets/{page.tE7PpWYW.js → page.3ARdH6tE.js} +1 -1
  11. package/public/assets/{page.B-dzeIUC.js → page.A4gD6oiw.js} +1 -1
  12. package/public/assets/{page.C6bYizL7.js → page.AhxgKhsm.js} +1 -1
  13. package/public/assets/{page.BFb7yUd8.js → page.B1og8_GD.js} +1 -1
  14. package/public/assets/{page.11hpNKmq.js → page.B5nk3H0f.js} +1 -1
  15. package/public/assets/{page.BgGJovOg.js → page.BGDrqCcI.js} +1 -1
  16. package/public/assets/{page.uziaGZsT.js → page.BJIIZWfZ.js} +1 -1
  17. package/public/assets/{page.Dl1apZE2.js → page.BdB6udZG.js} +1 -1
  18. package/public/assets/{page.sUIPWIiF.js → page.BfGkHTDS.js} +1 -1
  19. package/public/assets/{page.Df9qtrdG.js → page.Bfr4417O.js} +1 -1
  20. package/public/assets/{page.N1x4YL8_.js → page.BpcyRUKz.js} +1 -1
  21. package/public/assets/{page.CyUqJPmx.js → page.BvcbHe5b.js} +1 -1
  22. package/public/assets/{page.B-LxsnqU.js → page.C6WsIDgW.js} +1 -1
  23. package/public/assets/{page.P2Ny5veR.js → page.CCEJ5tPH.js} +1 -1
  24. package/public/assets/{page.Cged1bOZ.js → page.CMUifPIU.js} +1 -1
  25. package/public/assets/{page.HV0w1d5C.js → page.CR7Yees9.js} +1 -1
  26. package/public/assets/{page.B-nBR75u.js → page.CXCEdPh6.js} +1 -1
  27. package/public/assets/{page.B8xdkCWA.js → page.CsroRewc.js} +1 -1
  28. package/public/assets/{page.CF_YSLwP.js → page.CtLa-V_T.js} +1 -1
  29. package/public/assets/{page.C0gBvR4O.js → page.DINPUA6N.js} +1 -1
  30. package/public/assets/{page.BdS20a1O.js → page.DSEK9UW0.js} +1 -1
  31. package/public/assets/{page.CrBl7f8N.js → page.DSTzvOQ8.js} +1 -1
  32. package/public/assets/{page.fOOCr18J.js → page.DT7cpJ8d.js} +1 -1
  33. package/public/assets/{page.CpvXDkQF.js → page.DT_RnrSs.js} +1 -1
  34. package/public/assets/{page.Ch647dVk.js → page.DU7jwIPk.js} +1 -1
  35. package/public/assets/{page.D8Rp8fFR.js → page.DcmbyZGV.js} +1 -1
  36. package/public/assets/{page.-lpNgYAw.js → page.DjguJpCk.js} +1 -1
  37. package/public/assets/{page.CvUFZzXr.js → page.Dr6yAoTO.js} +1 -1
  38. package/public/assets/{page.CCNsZBXp.js → page.FR_Izkgi.js} +1 -1
  39. package/public/assets/{page.CrP7niA2.js → page.GhgvWftU.js} +1 -1
  40. package/public/assets/{page.CPTtRDxw.js → page.UoGOSKkx.js} +1 -1
  41. package/public/assets/page.cAR8tR7Z.js +1 -0
  42. package/public/assets/{page.BfmI9KYe.js → page.feKgaG20.js} +1 -1
  43. package/public/assets/{page.CdMmlUEm.js → page.t4nKFefI.js} +1 -1
  44. package/public/index.html +1 -1
  45. package/public/assets/EndpointPageClient.C2WMTYy0.js +0 -6
  46. package/public/assets/page.BbPPdoas.js +0 -1
@@ -1,5 +1,5 @@
1
- import { findPython310, getInstalledHeadroomExtras, getHeadroomLogTail } from "../../../lib/headroom/detect.js";
2
- import { installHeadroomExtras, uninstallHeadroomExtras } from "../../../lib/headroom/process.js";
1
+ import { findPython310, getInstalledHeadroomExtras } from "../../../lib/headroom/detect.js";
2
+ import { installHeadroomExtras, uninstallHeadroomExtras, getHeadroomLogTail } from "../../../lib/headroom/process.js";
3
3
  export async function GET(req, res) {
4
4
  try {
5
5
  if (new URL(req.url, "http://x").searchParams.get("log") === "1") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fudrouter/fsrouter",
3
- "version": "0.6.74",
3
+ "version": "0.6.76",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "9Router v2 — Express Backend (API, SSE, DB, Auth, MITM)",
@@ -0,0 +1,6 @@
1
+ import{r as ct,v as rs,u as is,j as e,B as c,M as $,C as os,f as cs}from"./index.D4FwOBBU.js";import{b as s}from"./router.Cjj1--8t.js";import{C as dt,I as te,T as Me}from"./NoAuthProxyCard.WHGGEUIp.js";import{C as ut}from"./Loading.C1il44u0.js";const ds=["zh-CN","zh-TW"],us=[{icon:"public",title:"Access Anywhere",desc:"Use your API from any network"},{icon:"group",title:"Share Endpoint",desc:"Share URL with team members"},{icon:"code",title:"Use in Cursor/Cline",desc:"Connect AI tools remotely"},{icon:"lock",title:"Encrypted",desc:"End-to-end TLS via Cloudflare"}],He=2e3,mt=3e5,ms=5e3,Fe=5,hs=1e4,xs=5e3;async function ht(h){if(!h)return!1;try{return(await fetch(`${h}/api/health`,{mode:"cors",cache:"no-store",signal:AbortSignal.timeout(xs)})).ok}catch{return!1}}async function ps(...h){const d=h.filter(Boolean).map(ht);return d.length?new Promise(x=>{let j=d.length;d.forEach(U=>U.then(b=>{b?x(!0):--j===0&&x(!1)}))}):!1}const Ke=[{id:"lite",label:"Lite",desc:"Drop filler, keep grammar"},{id:"full",label:"Full",desc:"Drop articles, fragments OK"},{id:"ultra",label:"Ultra",desc:"Telegraphic, max compression"},{id:"wenyan-lite",label:"文 Lite",desc:"Classical Chinese, light compression",wenyan:!0},{id:"wenyan",label:"文 Full",desc:"Maximum 文言文, 80-90% reduction",wenyan:!0},{id:"wenyan-ultra",label:"文 Ultra",desc:"Extreme classical compression",wenyan:!0}];function fs({machineId:h}){const[d,x]=s.useState([]),[j,U]=s.useState(!0),[b,N]=s.useState(!1),[se,ae]=s.useState(""),[je,we]=s.useState(null),[w,z]=s.useState(null),[ne,We]=s.useState(!1),[B,xt]=s.useState(!0),[qe,pt]=s.useState(!0),[$e,ze]=s.useState(!1),[js,ft]=s.useState(!0),[ws,gt]=s.useState(!1),[Be,Ve]=s.useState("full"),[vs,bt]=s.useState(!1),[Je,Ge]=s.useState(""),[ks,yt]=s.useState(!1),[L,ve]=s.useState({installed:!1,running:!1,python:null,loading:!0}),[Ns,Cs]=s.useState(!1),[Ts,le]=s.useState(!1),[Ss,Xe]=s.useState(""),[Es,jt]=s.useState(!1),[Ps,wt]=s.useState("full"),[_s,vt]=s.useState(!1),[As,kt]=s.useState("full"),[Nt,Ye]=s.useState("en"),[Ct,ke]=s.useState(!0),[p,re]=s.useState(!1),[R,ie]=s.useState(!1),[I,oe]=s.useState(""),[D,Ne]=s.useState(""),[P,C]=s.useState(!1),[Tt,T]=s.useState(""),[ce,v]=s.useState(null),[St,V]=s.useState(!1),[Et,J]=s.useState(!1),[f,O]=s.useState(!1),[M,de]=s.useState(!1),[H,F]=s.useState(""),[_,G]=s.useState(!1),[Pt,A]=s.useState(""),[K,u]=s.useState(null),[Qe,Ze]=s.useState(""),[_t,et]=s.useState(""),[Ce,ue]=s.useState(null),[me,Te]=s.useState(!1),[Se,Ee]=s.useState([]),[At,tt]=s.useState(""),[Ut,Pe]=s.useState(!1),[Lt,W]=s.useState(!1),[Rt,X]=s.useState(!1),he=s.useRef(null),Y=s.useRef(0),Q=s.useRef(0),xe=s.useRef(!1),pe=s.useRef(!1),fe=s.useRef(!1),ge=s.useRef(!1),[It,_e]=s.useState(!1),[Dt,Ae]=s.useState(!1),[Ue,st]=s.useState(new Set),[Ot,Mt]=s.useState(!1);s.useEffect(()=>{typeof window<"u"&&Mt(!["localhost","127.0.0.1","::1"].includes(window.location.hostname))},[]),s.useEffect(()=>(Ye(ct()),rs(()=>Ye(ct()))),[]);const Le=ds.includes(Nt);Le||Ke.filter(t=>!t.wenyan),s.useEffect(()=>{const t=Ke.find(a=>a.id===Be);t!=null&&t.wenyan&&!Le&&(Ve("ultra"),$t({cavemanLevel:"ultra"}))},[Le,Be]);const{copied:q,copy:Z}=is(),Ht=!B||!qe,Ft=B?"Change the default dashboard password before activating the tunnel.":'Enable "Require login" and set a custom password before activating the tunnel.';s.useEffect(()=>{he.current&&(he.current.scrollTop=he.current.scrollHeight)},[Se]),s.useEffect(()=>{nt(),Kt()},[]),s.useEffect(()=>{if(!(p||f))return;const n=(!p||R)&&(!f||M),r=()=>{document.hidden||at()};if(document.addEventListener("visibilitychange",r),n)return()=>document.removeEventListener("visibilitychange",r);const o=setInterval(()=>{document.hidden||at()},ms);return()=>{clearInterval(o),document.removeEventListener("visibilitychange",r)}},[p,f,R,M]),s.useEffect(()=>{const t=async()=>{if(!document.hidden){if(p&&(I||D)){const o=await ps(D,I);xe.current=o,o?(Y.current=0,ie(!0),fe.current||(fe.current=!0,_e(!0))):(Y.current+=1,Y.current>=Fe&&ie(!1))}else xe.current=!1;if(f&&H){const o=await ht(H);pe.current=o,o?(Q.current=0,de(!0),ge.current||(ge.current=!0,Ae(!0))):(Q.current+=1,Q.current>=Fe&&de(!1))}else pe.current=!1}};if(!(p&&(I||D)||f&&H)||(t(),(!p||R)&&(!f||M)))return;const r=setInterval(t,hs);return()=>clearInterval(r)},[p,I,D,f,H,R,M]);const be=s.useCallback((t,a,l,n,r,o)=>{a.current?(l.current=0,n(!0),r.current||(r.current=!0,o(!0))):(l.current+=1,l.current>=Fe&&n(!1))},[]),at=async()=>{var t,a,l,n,r,o,m;try{const y=await fetch("/api/tunnel/status",{cache:"no-store"});if(!y.ok)return;const g=await y.json(),i=((t=g.tunnel)==null?void 0:t.settingsEnabled)??((a=g.tunnel)==null?void 0:a.enabled)??!1,E=((l=g.tunnel)==null?void 0:l.tunnelUrl)||"";oe(E),Ne(((n=g.tunnel)==null?void 0:n.publicUrl)||""),re(i),be(null,xe,Y,ie,fe,_e);const k=((r=g.tailscale)==null?void 0:r.settingsEnabled)??((o=g.tailscale)==null?void 0:o.enabled)??!1,Oe=((m=g.tailscale)==null?void 0:m.tunnelUrl)||"";F(Oe),O(k),be(null,pe,Q,de,ge,Ae)}catch{}},Kt=async()=>{var t,a,l,n,r,o,m;ke(!0);try{const[y,g]=await Promise.all([fetch("/api/settings"),fetch("/api/tunnel/status",{cache:"no-store"})]);if(y.ok){const i=await y.json();We(i.requireApiKey||!1),xt(i.requireLogin!==!1),pt(i.hasPassword||!1),ze(i.tunnelDashboardAccess||!1),ft(i.rtkEnabled!==!1),gt(!!i.cavemanEnabled),Ve(i.cavemanLevel||"full"),bt(!!i.headroomEnabled),Ge(i.headroomUrl||""),yt(!!i.headroomCompressUserMessages),jt(!!i.ponytailEnabled),wt(i.ponytailLevel||"full"),vt(!!i.paleoEnabled),kt(i.paleoLevel||"full"),ee()}if(g.ok){const i=await g.json(),E=((t=i.tunnel)==null?void 0:t.settingsEnabled)??((a=i.tunnel)==null?void 0:a.enabled)??!1,k=((l=i.tunnel)==null?void 0:l.tunnelUrl)||"";oe(k),Ne(((n=i.tunnel)==null?void 0:n.publicUrl)||""),re(E),be(null,xe,Y,ie,fe,_e);const Oe=((r=i.tailscale)==null?void 0:r.settingsEnabled)??((o=i.tailscale)==null?void 0:o.enabled)??!1,ls=((m=i.tailscale)==null?void 0:m.tunnelUrl)||"";F(ls),O(Oe),be(null,pe,Q,de,ge,Ae)}}catch(y){console.log("Error loading settings:",y)}finally{ke(!1)}},Wt=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tunnelDashboardAccess:t})})).ok&&ze(t)}catch(a){console.log("Error updating tunnelDashboardAccess:",a)}},qt=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({requireApiKey:t})})).ok&&We(t)}catch(a){console.log("Error updating requireApiKey:",a)}},$t=async t=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(a){console.log("Error updating setting:",a)}},ee=s.useCallback(async()=>{ve(t=>({...t,loading:!0}));try{const a=await(await fetch("/api/headroom/status",{headers:{"Cache-Control":"no-store"}})).json();ve({...a,loading:!1}),a.url&&!Je&&Ge(a.url)}catch{ve({installed:!1,running:!1,python:null,loading:!1})}},[Je]);s.useCallback(async()=>{Xe(""),le(!0);try{const t=await fetch("/api/headroom/start",{method:"POST"}),a=await t.json().catch(()=>({}));if(!t.ok)throw new Error(a.error||"Failed to start proxy");await ee()}catch(t){Xe(t.message)}finally{le(!1)}},[ee]),s.useCallback(async()=>{le(!0);try{await fetch("/api/headroom/stop",{method:"POST"}),await ee()}finally{le(!1)}},[ee]);const nt=async()=>{try{const t=await fetch("/api/keys"),a=await t.json();t.ok&&x(a.keys||[])}catch(t){console.log("Error fetching data:",t)}finally{U(!1)}},zt=async(...t)=>{var n;C(!0),T("Waiting for tunnel ready...");const a=t.filter(Boolean).map(r=>`${r}/api/health`),l=Date.now();for(;Date.now()-l<mt;){if(await new Promise(o=>setTimeout(o,He)),await Promise.any(a.map(async o=>{if((await fetch(o,{mode:"cors",cache:"no-store"})).ok)return!0;throw new Error("not ready")})).catch(()=>!1))return re(!0),C(!1),T(""),!0;if((Date.now()-l)%1e4<He)try{const o=await fetch("/api/tunnel/status");if(o.ok&&!((n=(await o.json()).tunnel)!=null&&n.enabled))return v({type:"error",message:"Tunnel process stopped unexpectedly."}),C(!1),T(""),!1}catch{}}return v({type:"error",message:"Tunnel created but not reachable. Please try again."}),C(!1),T(""),!1},Bt=async()=>{V(!1),C(!0),v(null),T("Creating tunnel...");let t=!0;(async()=>{var l;for(;t;){try{const n=await fetch("/api/tunnel/status");if(n.ok){const r=await n.json();(l=r.download)!=null&&l.downloading?T(`Downloading cloudflared... ${r.download.progress}%`):t&&T("Creating tunnel...")}}catch{}await new Promise(n=>setTimeout(n,1e3))}})();try{const l=await fetch("/api/tunnel/enable",{method:"POST"});t=!1;const n=await l.json();if(!l.ok){v({type:"error",message:n.error||"Failed to enable tunnel"});return}const r=n.tunnelUrl;if(!r){v({type:"error",message:"No tunnel URL returned"});return}oe(r),Ne(n.publicUrl||""),await zt(n.publicUrl,r)}catch(l){v({type:"error",message:l.message})}finally{t=!1,C(!1),T("")}},Vt=async()=>{C(!0),v(null);try{const t=await fetch("/api/tunnel/disable",{method:"POST"}),a=await t.json();t.ok?(re(!1),oe(""),J(!1),v({type:"success",message:"Tunnel disabled"})):v({type:"error",message:a.error||"Failed to disable tunnel"})}catch(t){v({type:"error",message:t.message})}finally{C(!1)}},Jt=async()=>{ue(null);try{const t=await fetch("/api/tunnel/tailscale-check");if(t.ok){const a=await t.json();return ue(a.installed),a}}catch{}return ue(!1),{installed:!1}},Gt=async()=>{Te(!0),u(null),Ee([]);try{const t=await fetch("/api/tunnel/tailscale-install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:At})});tt("");const a=t.body.getReader(),l=new TextDecoder;let n="";for(;;){const{done:r,value:o}=await a.read();if(r)break;n+=l.decode(o,{stream:!0});const m=n.split(`
2
+
3
+ `);n=m.pop()||"";for(const y of m){const g=y.split(`
4
+ `);let i="progress",E=null;for(const k of g)if(k.startsWith("event: ")&&(i=k.slice(7).trim()),k.startsWith("data: "))try{E=JSON.parse(k.slice(6))}catch{}if(E)if(i==="progress")Ee(k=>[...k.slice(-50),E.message]);else if(i==="done"){ue(!0),Te(!1),W(!1),Ie();return}else i==="error"&&u({type:"error",message:E.error||"Install failed"})}}}catch(t){u({type:"error",message:t.message})}finally{Te(!1)}},Re=async t=>{A("Waiting for Tailscale ready...");const a=`${t}/api/health`,l=Date.now();for(;Date.now()-l<mt;){await new Promise(n=>setTimeout(n,He));try{const n=await fetch(a,{mode:"no-cors",cache:"no-store"});if(n.ok||n.type==="opaque")return!0}catch{}}return!1},lt=(t,a)=>{Ze(t),et(a)},S=()=>{Ze(""),et("")},Ie=async()=>{W(!1),Pe(!0),G(!0),u(null),A("Connecting..."),S();try{const t=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),a=await t.json();if(t.ok&&a.success){F(a.tunnelUrl||"");const l=await Re(a.tunnelUrl);O(!0),u(l?null:{type:"warning",message:"Connected but not reachable yet."});return}if(a.needsLogin&&a.authUrl){lt(a.authUrl,"Open Login Page"),A('Login required — click "Open Login Page" to continue');for(let l=0;l<40;l++){await new Promise(n=>setTimeout(n,3e3));try{const n=await fetch("/api/tunnel/tailscale-check");if(n.ok&&(await n.json()).loggedIn){S(),A("Starting funnel...");const o=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),m=await o.json();if(o.ok&&m.success){F(m.tunnelUrl||"");const y=await Re(m.tunnelUrl);O(!0),u(y?null:{type:"warning",message:"Connected but not reachable yet."})}else m.funnelNotEnabled&&m.enableUrl?await rt(m.enableUrl):u({type:"error",message:m.error||"Failed to start funnel"});return}}catch{}}S(),u({type:"error",message:"Login timed out. Please try again."});return}if(a.funnelNotEnabled&&a.enableUrl){await rt(a.enableUrl);return}u({type:"error",message:a.error||"Failed to connect"})}catch(t){u({type:"error",message:t.message})}finally{G(!1),Pe(!1),A(""),S()}},rt=async t=>{lt(t,"Open Funnel Settings"),A('Click "Open Funnel Settings" to enable Funnel...');for(let a=0;a<40;a++){await new Promise(l=>setTimeout(l,3e3));try{const l=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),n=await l.json();if(l.ok&&n.success){S(),F(n.tunnelUrl||"");const r=await Re(n.tunnelUrl);O(!0),u(r?null:{type:"warning",message:"Connected but not reachable yet."});return}if(n.funnelNotEnabled)continue;if(n.error){S(),u({type:"error",message:n.error});return}}catch{}}S(),u({type:"error",message:"Timed out waiting for Funnel to be enabled."})},Xt=async()=>{G(!0),u(null);try{const t=await fetch("/api/tunnel/tailscale-disable",{method:"POST"}),a=await t.json();t.ok?(O(!1),F(""),X(!1),u({type:"success",message:"Tailscale disabled"})):u({type:"error",message:a.error||"Failed to disable Tailscale"})}catch(t){u({type:"error",message:t.message})}finally{G(!1)}},it=async()=>{u(null),Ee([]);const t=await Jt();t!=null&&t.installed&&(t!=null&&t.hasCachedPassword)?Ie():W(!0)},Yt=async()=>{if(se.trim())try{const t=await fetch("/api/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se})}),a=await t.json();t.ok&&(we(a.key),await nt(),ae(""),N(!1))}catch(t){console.log("Error creating key:",t)}},Qt=async t=>{z({title:"Delete API Key",message:"Delete this API key?",onConfirm:async()=>{z(null);try{(await fetch(`/api/keys/${t}`,{method:"DELETE"})).ok&&(x(d.filter(l=>l.id!==t)),st(l=>{const n=new Set(l);return n.delete(t),n}))}catch(a){console.log("Error deleting key:",a)}}})},ot=async(t,a)=>{try{(await fetch(`/api/keys/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:a})})).ok&&x(n=>n.map(r=>r.id===t?{...r,isActive:a}:r))}catch(l){console.log("Error toggling key:",l)}},Zt=t=>t?t.length>8?t.slice(0,8)+"...":t:"",es=t=>{st(a=>{const l=new Set(a);return l.has(t)?l.delete(t):l.add(t),l})},[ts,ss]=s.useState("/v1");if(s.useEffect(()=>{typeof window<"u"&&ss(`${window.location.origin}/v1`)},[]),j)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ut,{}),e.jsx(ut,{})]});const as=ts,ns=!!L.running,De=L.localUrl!==!1;return L.canStart,De&&L.managedPid,L.loading||ns||De&&L.installed,e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsxs(dt,{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"api"}),"API Endpoint"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(gs,{label:"Local",url:as,copyId:"local_url",copied:q,onCopy:Z}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${p?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tunnel"}),p&&!P&&R?e.jsxs(e.Fragment,{children:[e.jsx(te,{value:`${D||I}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>Z(`${D||I}/v1`,"tunnel_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:q==="tunnel_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>J(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):p&&!P&&!R?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),It?"Tunnel reconnecting...":"Tunnel checking..."]}),e.jsx("button",{onClick:()=>J(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Tt||"Creating tunnel..."]}),e.jsx("button",{onClick:()=>{C(!1),T("")},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(ce==null?void 0:ce.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),ce.message]}),e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>V(!0),children:"Enable"})]}):Ct?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),e.jsx("button",{onClick:()=>ke(!1),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>{V(!0)},children:"Enable"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${f?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tailscale"}),f&&!_&&M?e.jsxs(e.Fragment,{children:[e.jsx(te,{value:`${H}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>Z(`${H}/v1`,"ts_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:q==="ts_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):f&&!_&&!M?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Dt?"Tailscale reconnecting...":"Tailscale checking..."]}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):_||Ut?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Pt||"Connecting..."]}),Qe&&e.jsx(c,{size:"sm",icon:"open_in_new",onClick:()=>window.open(Qe,"tailscale_auth","width=600,height=700,noopener,noreferrer"),children:_t||"Open"}),e.jsx("button",{onClick:()=>{G(!1),Pe(!1),A(""),S()},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(K==null?void 0:K.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),K.message]}),e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:it,children:"Enable"})]}):e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:()=>{it()},className:"bg-linear-to-r from-indigo-500 to-purple-500 hover:from-indigo-600 hover:to-purple-600 text-white!",children:"Enable"})]})]}),Ht&&!p&&!f&&e.jsx("div",{className:"mt-4",children:e.jsx(ye,{message:Ft,action:{label:"Open settings",href:"/dashboard/profile"}})}),(p||f)&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[!ne&&e.jsx(ye,{message:"Require API key is disabled — your endpoint is publicly accessible without authentication.",action:{label:"Enable",href:"#require-api-key"}}),(!B||!qe)&&e.jsx(ye,{message:B?"Dashboard uses the default password — change it in Profile settings.":"Require login is disabled — anyone can access your dashboard via tunnel.",action:{label:B?"Change password":"Enable",href:"/dashboard/profile"}})]}),(p||f)&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex items-center gap-3",children:[e.jsx(Me,{checked:$e,onChange:()=>Wt(!$e)}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"font-medium text-sm",children:"Allow dashboard access via tunnel"}),e.jsx(ys,{text:"When enabled, the dashboard can be accessed through your tunnel or Tailscale URL (login still required). When disabled, dashboard access via tunnel/Tailscale is completely blocked."})]})]})]}),e.jsxs(dt,{id:"require-api-key",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"vpn_key"}),"API Keys"]}),e.jsx(c,{icon:"add",onClick:()=>N(!0),children:"Create Key"})]}),e.jsxs("div",{className:"flex items-center justify-between pb-4 mb-4 border-b border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Require API key"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Requests without a valid key will be rejected"})]}),e.jsx(Me,{checked:ne,onChange:()=>qt(!ne)})]}),Ot&&!ne&&e.jsx("div",{className:"mb-4 -mt-2",children:e.jsx(ye,{message:"Endpoint is exposed without an API key."})}),d.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"vpn_key"})}),e.jsx("p",{className:"text-text-main font-medium mb-1",children:"No API keys yet"}),e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create your first API key to get started"}),e.jsx(c,{icon:"add",onClick:()=>N(!0),children:"Create Key"})]}):e.jsx("div",{className:"flex flex-col",children:d.map(t=>e.jsxs("div",{className:`group flex items-center justify-between py-3 border-b border-black/[0.03] dark:border-white/[0.03] last:border-b-0 ${t.isActive===!1?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"text-xs text-text-muted font-mono",children:Ue.has(t.id)?t.key:Zt(t.key)}),e.jsx("button",{onClick:()=>es(t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",title:Ue.has(t.id)?"Hide key":"Show key",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:Ue.has(t.id)?"visibility_off":"visibility"})}),e.jsx("button",{onClick:()=>Z(t.key,t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:q===t.id?"check":"content_copy"})})]}),e.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["Created ",new Date(t.createdAt).toLocaleDateString()]}),t.isActive===!1&&e.jsx("p",{className:"text-xs text-orange-500 mt-1",children:"Paused"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Me,{size:"sm",checked:t.isActive??!0,onChange:a=>{t.isActive&&!a?z({title:"Pause API Key",message:`Pause API key "${t.name}"?
5
+
6
+ This key will stop working immediately but can be resumed later.`,onConfirm:async()=>{z(null),ot(t.id,a)}}):ot(t.id,a)},title:t.isActive?"Pause key":"Resume key"}),e.jsx("button",{onClick:()=>Qt(t.id),className:"p-2 hover:bg-red-500/10 rounded text-red-500 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]},t.id))})]}),e.jsx($,{isOpen:b,title:"Create API Key",onClose:()=>{N(!1),ae("")},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(te,{label:"Key Name",value:se,onChange:t=>ae(t.target.value),placeholder:"Production Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Yt,fullWidth:!0,disabled:!se.trim(),children:"Create"}),e.jsx(c,{onClick:()=>{N(!1),ae("")},variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx($,{isOpen:!!je,title:"API Key Created",onClose:()=>we(null),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mb-2 font-medium",children:"Save this key now!"}),e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:"This is the only time you will see this key. Store it securely."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(te,{value:je||"",readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx(c,{variant:"secondary",icon:q==="created_key"?"check":"content_copy",onClick:()=>Z(je,"created_key"),children:q==="created_key"?"Copied!":"Copy"})]}),e.jsx(c,{onClick:()=>we(null),fullWidth:!0,children:"Done"})]})}),e.jsx($,{isOpen:St,title:"Enable Tunnel",onClose:()=>V(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"bg-surface-2 border border-border-subtle rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"cloud_upload"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-text-main font-medium mb-1",children:"Cloudflare Tunnel"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Expose your local FSRouter to the internet. No port forwarding, no static IP needed. Share endpoint URL with your team or use it in Cursor, Cline, and other AI tools from anywhere."})]})]})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:us.map(t=>e.jsxs("div",{className:"flex flex-col items-center text-center p-3 rounded-lg bg-sidebar/50",children:[e.jsx("span",{className:"material-symbols-outlined text-xl text-primary mb-1",children:t.icon}),e.jsx("p",{className:"text-xs font-semibold",children:t.title}),e.jsx("p",{className:"text-xs text-text-muted",children:t.desc})]},t.title))}),e.jsx("p",{className:"text-xs text-text-muted",children:"Requires outbound port 7844 (TCP/UDP). Connection may take 10-30s."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Bt,fullWidth:!0,children:"Start Tunnel"}),e.jsx(c,{onClick:()=>V(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx($,{isOpen:Et,title:"Disable Tunnel",onClose:()=>!P&&J(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"The Cloudflare tunnel will be disconnected. Remote access via tunnel URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Vt,fullWidth:!0,disabled:P,variant:"danger",children:P?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>J(!1),variant:"ghost",fullWidth:!0,disabled:P,children:"Cancel"})]})]})}),e.jsx($,{isOpen:Lt,title:"Tailscale Funnel",onClose:()=>{me||(W(!1),tt(""),u(null))},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[Ce===null&&e.jsxs("p",{className:"text-sm text-text-muted flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),Ce===!1&&!me&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale is not installed. Install it to enable Funnel."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Gt,fullWidth:!0,children:"Install Tailscale"}),e.jsx(c,{onClick:()=>W(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),me&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Installing Tailscale..."]}),Se.length>0&&e.jsx("div",{ref:he,className:"bg-black/5 dark:bg-white/5 rounded p-2 max-h-40 overflow-y-auto font-mono text-xs text-text-muted",children:Se.map((t,a)=>e.jsx("div",{children:t},a))})]}),Ce===!0&&!me&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),"Tailscale installed"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:()=>Ie(),fullWidth:!0,children:"Connect"}),e.jsx(c,{onClick:()=>W(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),K&&e.jsx(bs,{status:K})]})}),e.jsx($,{isOpen:Rt,title:"Disable Tailscale",onClose:()=>!_&&X(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale Funnel will be stopped. Remote access via Tailscale URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Xt,fullWidth:!0,disabled:_,variant:"danger",children:_?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>X(!1),variant:"ghost",fullWidth:!0,disabled:_,children:"Cancel"})]})]})}),e.jsx(os,{isOpen:!!w,onClose:()=>z(null),onConfirm:w==null?void 0:w.onConfirm,title:(w==null?void 0:w.title)||"Confirm",message:w==null?void 0:w.message,variant:"danger"})]})}function gs({label:h,url:d,copyId:x,copied:j,onCopy:U,badge:b,actions:N}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${b==="CF"||b==="TS"?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:h}),e.jsx(te,{value:d,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>U(d,x),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:j===x?"check":"content_copy"})}),N]})}function bs({status:h,className:d=""}){const x=j=>j.split(/(https?:\/\/[^\s]+)/g).map((b,N)=>/^https?:\/\//.test(b)?e.jsx("a",{href:b,target:"_blank",rel:"noreferrer",className:"underline font-medium",children:b},N):b);return e.jsx("div",{className:`p-2 rounded text-sm ${d} ${h.type==="success"?"bg-green-500/10 text-green-600 dark:text-green-400":h.type==="warning"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":h.type==="info"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-red-500/10 text-red-600 dark:text-red-400"}`,children:x(h.message)})}function ys({text:h}){return e.jsxs("span",{className:"relative group inline-flex items-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-text-muted cursor-help",children:"help"}),e.jsx("span",{className:"pointer-events-none absolute left-5 top-1/2 -translate-y-1/2 z-50 w-64 rounded bg-gray-900 dark:bg-gray-800 text-white text-xs px-2.5 py-1.5 opacity-0 group-hover:opacity-100 transition-opacity shadow-lg",children:h})]})}function ye({message:h,action:d}){return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:"warning"}),e.jsx("p",{className:"text-xs flex-1",children:h}),d&&e.jsx("a",{href:d.href,className:"text-xs font-medium underline shrink-0 hover:opacity-80",onClick:d.href.startsWith("#")?x=>{var j;x.preventDefault(),(j=document.getElementById(d.href.slice(1)))==null||j.scrollIntoView({behavior:"smooth"})}:void 0,children:d.label})]})}fs.propTypes={machineId:cs.string.isRequired};export{fs as A};
@@ -1 +1 @@
1
- import{j as e,n as t}from"./index.Be3gbrBl.js";function r({size:n="md",className:s}){const i={sm:"size-4",md:"size-6",lg:"size-8",xl:"size-12"};return e.jsx("span",{className:t("material-symbols-outlined animate-spin text-brand-500",i[n],s),children:"progress_activity"})}function c({message:n="Loading..."}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-bg",children:[e.jsx(r,{size:"xl"}),e.jsx("p",{className:"mt-4 text-text-muted",children:n})]})}function a({className:n,...s}){return e.jsx("div",{className:t("animate-pulse rounded-[10px] bg-surface-2",n),...s})}function d(){return e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface shadow-[var(--shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(a,{className:"h-4 w-24"}),e.jsx(a,{className:"size-10 rounded-[10px]"})]}),e.jsx(a,{className:"h-8 w-16 mb-2"}),e.jsx(a,{className:"h-3 w-20"})]})}function x({type:n="spinner",...s}){switch(n){case"page":return e.jsx(c,{...s});case"skeleton":return e.jsx(a,{...s});case"card":return e.jsx(d,{...s});default:return e.jsx(r,{...s})}}export{d as C,x as L};
1
+ import{j as e,n as t}from"./index.D4FwOBBU.js";function r({size:n="md",className:s}){const i={sm:"size-4",md:"size-6",lg:"size-8",xl:"size-12"};return e.jsx("span",{className:t("material-symbols-outlined animate-spin text-brand-500",i[n],s),children:"progress_activity"})}function c({message:n="Loading..."}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-bg",children:[e.jsx(r,{size:"xl"}),e.jsx("p",{className:"mt-4 text-text-muted",children:n})]})}function a({className:n,...s}){return e.jsx("div",{className:t("animate-pulse rounded-[10px] bg-surface-2",n),...s})}function d(){return e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface shadow-[var(--shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(a,{className:"h-4 w-24"}),e.jsx(a,{className:"size-10 rounded-[10px]"})]}),e.jsx(a,{className:"h-8 w-16 mb-2"}),e.jsx(a,{className:"h-3 w-20"})]})}function x({type:n="spinner",...s}){switch(n){case"page":return e.jsx(c,{...s});case"skeleton":return e.jsx(a,{...s});case"card":return e.jsx(d,{...s});default:return e.jsx(r,{...s})}}export{d as C,x as L};
@@ -1,4 +1,4 @@
1
- var KS=Object.defineProperty;var qS=(e,t,r)=>t in e?KS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ma=(e,t,r)=>qS(e,typeof t!="symbol"?t+"":t,r);import{j as m,n as at,u as Uv,M as hr,B as ue,f as Y,g as Qa,A as Hv,c as Vv,F as Ja,O as Kv,i as Yd,k as qv,l as Yv,h as Xd,P as YS}from"./index.Be3gbrBl.js";import{b as g,r as Vc,g as Xv,W as XS,c as Gv,i as GS}from"./router.Cjj1--8t.js";function xe({label:e,type:t="text",placeholder:r,value:n,onChange:i,error:a,hint:o,icon:s,disabled:l=!1,required:c=!1,className:u,inputClassName:d,...f}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",u),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,c&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[s&&m.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:s})}),m.jsx("input",{type:t,placeholder:r,value:n,onChange:i,disabled:l,className:at("w-full py-2.5 px-3 text-sm text-text-main bg-surface-2 rounded-[10px]","border border-transparent placeholder-text-muted/70","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 ease-out disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",s&&"pl-10",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",d),...f})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function ZS({label:e,options:t=[],value:r,onChange:n,placeholder:i="Select an option",error:a,hint:o,disabled:s=!1,required:l=!1,className:c,selectClassName:u,...d}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",c),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,l&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[m.jsxs("select",{value:r,onChange:n,disabled:s,className:at("w-full py-2.5 px-3 pr-10 text-sm text-text-main","bg-surface-2 border border-transparent rounded-[10px] appearance-none","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",u),...d,children:[m.jsx("option",{value:"",disabled:!0,children:i}),t.map(f=>m.jsx("option",{value:f.value,children:f.label},f.value))]}),m.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"expand_more"})})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function zt({children:e,title:t,subtitle:r,icon:n,action:i,padding:a="md",hover:o=!1,elev:s=!1,className:l,...c}){const u={none:"",xs:"p-3",sm:"p-4",md:"p-6",lg:"p-8"};return m.jsxs("div",{className:at("bg-surface border border-border-subtle",s?"rounded-[14px] shadow-[var(--shadow-elev)]":"rounded-[14px] shadow-[var(--shadow-soft)]",o&&"hover:shadow-[var(--shadow-warm)] hover:border-brand-500/30 transition-all cursor-pointer",u[a],l),...c,children:[(t||i)&&m.jsxs("div",{className:"flex items-center justify-between mb-4",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[n&&m.jsx("div",{className:"p-2 rounded-[10px] bg-bg text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:n})}),m.jsxs("div",{children:[t&&m.jsx("h3",{className:"text-text-main font-semibold",children:t}),r&&m.jsx("p",{className:"text-sm text-text-muted",children:r})]})]}),i]}),e]})}zt.Section=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-4 rounded-[10px]","bg-bg border border-border-subtle",r),...n,children:t})};zt.Row=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-3 -mx-3 px-3 transition-colors","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50",r),...n,children:t})};zt.ListItem=function({children:t,actions:r,className:n,...i}){return m.jsxs("div",{className:at("group flex items-center justify-between p-3 -mx-3 px-3","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50 transition-colors",n),...i,children:[m.jsx("div",{className:"flex-1 min-w-0",children:t}),r&&m.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r})]})};const QS={default:"bg-surface-2 text-text-muted",primary:"bg-brand-500/10 text-brand-600 dark:text-brand-300",success:"bg-green-500/10 text-green-600 dark:text-green-400",warning:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",error:"bg-red-500/10 text-red-600 dark:text-red-400",info:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},JS={sm:"px-2 py-0.5 text-[10px]",md:"px-2.5 py-1 text-xs",lg:"px-3 py-1.5 text-sm"};function Ci({children:e,variant:t="default",size:r="md",dot:n=!1,icon:i,className:a}){return m.jsxs("span",{className:at("inline-flex items-center gap-1.5 rounded-full font-semibold",QS[t],JS[r],a),children:[n&&m.jsx("span",{className:at("size-1.5 rounded-full",t==="success"&&"bg-green-500",t==="warning"&&"bg-yellow-500",t==="error"&&"bg-red-500",t==="info"&&"bg-blue-500",t==="primary"&&"bg-brand-500",t==="default"&&"bg-gray-500")}),i&&m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:i}),e]})}function Js({checked:e=!1,onChange:t,label:r,description:n,disabled:i=!1,size:a="md",className:o}){const s={sm:{track:"w-8 h-4",thumb:"size-3",translate:"translate-x-4"},md:{track:"w-11 h-6",thumb:"size-5",translate:"translate-x-5"},lg:{track:"w-14 h-7",thumb:"size-6",translate:"translate-x-7"}},l=()=>{!i&&t&&t(!e)};return m.jsxs("div",{className:at("flex items-center gap-3",i&&"opacity-50 cursor-not-allowed",o),children:[m.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:i,onClick:l,className:at("relative inline-flex shrink-0 cursor-pointer rounded-full","transition-colors duration-200 ease-in-out","focus:outline-none focus:ring-2 focus:ring-brand-500/30",e?"bg-brand-500":"bg-surface-3",s[a].track,i&&"cursor-not-allowed"),children:m.jsx("span",{className:at("pointer-events-none inline-block rounded-full bg-white shadow-sm","transform transition duration-200 ease-in-out",e?s[a].translate:"translate-x-0.5",s[a].thumb,"mt-0.5")})}),(r||n)&&m.jsxs("div",{className:"flex flex-col",children:[r&&m.jsx("span",{className:"text-sm font-medium text-text-main",children:r}),n&&m.jsx("span",{className:"text-xs text-text-muted",children:n})]})]})}function Kc({isOpen:e,provider:t,providerInfo:r,onSuccess:n,onClose:i,oauthMeta:a,idcConfig:o}){const[s,l]=g.useState("waiting"),[c,u]=g.useState(null),[d,f]=g.useState(""),[h,p]=g.useState(null),[y,x]=g.useState(!1),[v,S]=g.useState(null),[b,w]=g.useState(!1),E=g.useRef(null),A=g.useRef(!1),_=g.useRef(!1),{copied:O,copy:j}=Uv(),[M,N]=g.useState(!1),[k,z]=g.useState("/callback?code=..."),P=g.useRef(!1);g.useEffect(()=>{typeof window<"u"&&(N(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),z(`${window.location.origin}/callback?code=...`))},[]);const I=g.useCallback(async(q,X)=>{if(c)try{const F=await fetch(`/api/oauth/${t}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,redirectUri:c.redirectUri,codeVerifier:c.codeVerifier,state:X,...a?{meta:a}:{}})}),B=await F.json();if(!F.ok)throw new Error(B.error);l("success"),n==null||n()}catch(F){p(F.message),l("error")}},[c,t,n,a]),C=g.useCallback(async q=>{if(c!=null&&c.state)try{const X=await fetch("/api/oauth/xai/manual-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,state:c.state})}),F=await X.json();if(!X.ok)throw new Error(F.error);l("success"),n==null||n()}catch(X){p(X.message),l("error")}},[c,n]),T=g.useCallback(async(q,X,F,B,K)=>{A.current=!1,w(!0);const R=Date.now()+(Number.isFinite(K)&&K>0?K:12e4);for(;Date.now()<R;){if(A.current){console.log("[OAuthModal] Polling aborted"),w(!1);return}if(await new Promise(Z=>setTimeout(Z,F*1e3)),A.current){console.log("[OAuthModal] Polling aborted after sleep"),w(!1);return}try{const J=await(await fetch(`/api/oauth/${t}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:q,codeVerifier:X,extraData:B})})).json();if(J.success){A.current=!0,l("success"),w(!1),n==null||n();return}if(J.error==="expired_token"||J.error==="access_denied")throw new Error(J.errorDescription||J.error);J.error==="slow_down"&&(F=Math.min(F+5,30))}catch(Z){p(Z.message),l("error"),w(!1);return}}p("Authorization timeout"),l("error"),w(!1)},[t,n]),$=g.useCallback(async()=>{if(t)try{if(p(null),["github","qwen","kiro","kimi-coding","kilocode","codebuddy-cn","qoder","grok-cli"].includes(t)){x(!0),l("waiting");const re=new URL(`/api/oauth/${t}/device-code`,window.location.origin);t==="kiro"&&(o!=null&&o.startUrl)&&(re.searchParams.set("start_url",o.startUrl),o.region&&re.searchParams.set("region",o.region),re.searchParams.set("auth_method","idc"));const le=await fetch(re.toString()),se=await le.json();if(!le.ok)throw new Error(se.error);S(se);const ce=se.verification_uri_complete||se.verification_uri;ce&&window.open(ce,"_blank","noopener,noreferrer");const ke=t==="kiro"?{_clientId:se._clientId,_clientSecret:se._clientSecret,_region:se._region,_authMethod:se._authMethod,_startUrl:se._startUrl}:t==="qoder"?{_qoderNonce:se._qoderNonce,_qoderMachineId:se._qoderMachineId,_qoderVerifier:se.codeVerifier}:null;T(se.device_code,se.codeVerifier,se.interval||5,ke,Number.isFinite(se.expires_in)&&se.expires_in>0?se.expires_in*1e3:void 0);return}const X=window.location.port||(window.location.protocol==="https:"?"443":"80");let F;t==="codex"?F="http://localhost:1455/auth/callback":t==="xai"?F="http://127.0.0.1:56121/callback":F=`http://localhost:${X}/callback`;const B=new URL(`/api/oauth/${t}/authorize`,window.location.origin);B.searchParams.set("redirect_uri",F),a&&Object.entries(a).forEach(([re,le])=>{le&&B.searchParams.set(re,le)});const K=await fetch(B.toString()),U=await K.json();if(!K.ok)throw new Error(U.error);let R=!1,Z=!1;if(t==="codex")try{const re=new URL("/api/oauth/codex/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();R=se.success,Z=!!se.serverSide}catch{R=!1}let J=!1,ee=!1;if(t==="xai")try{const re=new URL("/api/oauth/xai/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();if(J=se.success,ee=!!se.serverSide,!J&&se.reason==="port_busy")throw new Error("Port 56121 in use; close the conflicting process and retry")}catch(re){if(re!=null&&re.message)throw re;J=!1}if(u({...U,redirectUri:F,codexServerSide:Z,xaiServerSide:ee}),!U.authUrl)throw U.flowType==="device_code"?new Error(`Provider ${t} uses device-code login but is not wired in the OAuth modal device-code list`):new Error("No authorization URL returned from OAuth provider");t==="codex"&&R||t==="xai"&&J?(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input")):!M||t==="codex"||t==="xai"?(l("input"),window.open(U.authUrl,"_blank")):(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input"))}catch(q){p(q.message),l("error")}},[t,M,T,a,o]);g.useEffect(()=>{if(e&&t){if(_.current)return;_.current=!0,u(null),f(""),p(null),x(!1),S(null),w(!1),A.current=!1,$()}else e||(A.current=!0,_.current=!1,t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}))},[e,t,$]),g.useEffect(()=>{const q=c!=null&&c.codexServerSide?"codex":c!=null&&c.xaiServerSide?"xai":null;if(!q||!(c!=null&&c.state)||P.current)return;let X=!1;const F=1500,B=200;let K=0;const U=async()=>{if(!(X||P.current)){K+=1;try{const Z=await(await fetch(`/api/oauth/${q}/poll-status?state=${encodeURIComponent(c.state)}`)).json();if(X||P.current)return;if(Z.status==="done"){P.current=!0,l("success"),n==null||n();return}if(Z.status==="error"){P.current=!0,p(Z.error||"Authentication failed"),l("error");return}}catch{}if(K>=B){P.current=!0,p("Authentication timeout"),l("error");return}setTimeout(U,F)}};return setTimeout(U,F),()=>{X=!0}},[c,n]),g.useEffect(()=>{if(!c)return;P.current=!1;const q=async K=>{if(P.current)return;const{code:U,token:R,state:Z,error:J,errorDescription:ee}=K;if(J){P.current=!0,p(ee||J),l("error");return}(R||U)&&(P.current=!0,await I(R||U,Z))},X=K=>{var Z;const U=K.origin.includes("localhost")||K.origin.includes("127.0.0.1"),R=K.origin===window.location.origin;!U&&!R||((Z=K.data)==null?void 0:Z.type)==="oauth_callback"&&q(K.data.data)};window.addEventListener("message",X);let F;try{F=new BroadcastChannel("oauth_callback"),F.onmessage=K=>q(K.data)}catch{console.log("BroadcastChannel not supported")}const B=K=>{if(K.key==="oauth_callback"&&K.newValue)try{const U=JSON.parse(K.newValue);q(U),localStorage.removeItem("oauth_callback")}catch{console.log("Failed to parse localStorage data")}};window.addEventListener("storage",B);try{const K=localStorage.getItem("oauth_callback");if(K){const U=JSON.parse(K);U.timestamp&&Date.now()-U.timestamp<3e4&&q(U),localStorage.removeItem("oauth_callback")}}catch{}return()=>{window.removeEventListener("message",X),window.removeEventListener("storage",B),F&&F.close()}},[c,I]);const D=async()=>{try{p(null);const q=d.trim();if(q.startsWith("eyJ")&&q.includes(".")){await I(q,null);return}if(t==="xai"&&q&&!q.includes("://")&&!q.includes("?")&&!q.includes("code=")){await C(q);return}if(t==="kimchi"&&q&&!q.includes("://")&&!q.includes("?")){await I(q,null);return}const X=new URL(q),F=X.searchParams.get("code"),B=X.searchParams.get("token"),K=X.searchParams.get("state"),U=X.searchParams.get("error");if(U)throw new Error(X.searchParams.get("error_description")||U);if(!F&&!B)throw new Error(t==="xai"?"Paste the callback URL or copied xAI code":t==="kimchi"?"No Kimchi token found in URL":"No authorization code found in URL");await I(B||F,K)}catch(q){p(q.message),l("error")}},L=g.useCallback(()=>{t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}),i()},[i,t]);if(!t||!r)return null;const V=t==="xai",H=t==="kimchi",Q=(v==null?void 0:v.verification_uri_complete)||(v==null?void 0:v.verification_uri)||"",te=V?"Connect Grok Build OAuth":`Connect ${r.name}`,G=V?"http://127.0.0.1:56121/callback?code=... or copied code":H?`${k.replace("code=...","token=...")} or copied token`:k;return m.jsx(hr,{isOpen:e,title:te,onClose:L,size:"lg",children:m.jsxs("div",{className:"flex flex-col gap-4",children:[(s==="waiting"||s==="input")&&!y&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50",children:[m.jsx("span",{className:"material-symbols-outlined text-base text-primary animate-spin",children:"progress_activity"}),m.jsx("span",{className:"text-sm",children:V?"Waiting for Grok Build OAuth…":"Waiting for popup authorization…"})]}),m.jsxs("div",{className:"flex items-center gap-3 my-1",children:[m.jsx("div",{className:"flex-1 h-px bg-border"}),m.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wider",children:"Or paste callback URL manually"}),m.jsx("div",{className:"flex-1 h-px bg-border"})]}),m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 1: Open this ",V?"Grok Build OAuth URL":"URL"," in your browser"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(xe,{value:(c==null?void 0:c.authUrl)||"",readOnly:!0,className:"flex-1 font-mono text-xs"}),m.jsx(ue,{variant:"secondary",icon:O==="auth_url"?"check":"content_copy",onClick:()=>j(c==null?void 0:c.authUrl,"auth_url"),disabled:!(c!=null&&c.authUrl),children:"Copy"})]})]}),m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 2: Paste the ",t==="xai"?"callback URL or copied code":H?"callback URL or copied token":"callback URL"," here"]}),m.jsx("p",{className:"text-xs text-text-muted mb-2",children:t==="xai"?"If xAI shows a code instead of redirecting, paste that code here.":H?"After authorization, copy the full callback URL or token from your browser.":"After authorization, copy the full URL from your browser."}),m.jsx(xe,{value:d,onChange:q=>f(q.target.value),placeholder:G,className:"font-mono text-xs"})]})]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:D,fullWidth:!0,disabled:!d,children:"Connect"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),s==="waiting"&&y&&v&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"text-center py-4",children:[m.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Visit the login URL below and authorize:"}),m.jsxs("div",{className:"bg-sidebar p-4 rounded-lg mb-4",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Login URL"}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-sm break-all",children:Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="login_url"?"check":"content_copy",onClick:()=>j(Q,"login_url"),disabled:!Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:"open_in_new",onClick:()=>window.open(Q,"_blank","noopener,noreferrer"),disabled:!Q,children:"Open"})]})]}),m.jsxs("div",{className:"bg-primary/10 p-4 rounded-lg",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Your Code"}),m.jsxs("div",{className:"flex items-center justify-center gap-2",children:[m.jsx("p",{className:"text-2xl font-mono font-bold text-primary",children:v.user_code}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="user_code"?"check":"content_copy",onClick:()=>j(v.user_code,"user_code")})]})]})]}),b&&m.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),"Waiting for authorization..."]})]}),s==="success"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connected Successfully!"}),m.jsxs("p",{className:"text-sm text-text-muted mb-4",children:["Your ",r.name," account has been connected."]}),m.jsx(ue,{onClick:L,fullWidth:!0,children:"Done"})]}),s==="error"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-red-600",children:"error"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connection Failed"}),m.jsx("p",{className:"text-sm text-red-600 mb-4",children:h}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:$,variant:"secondary",fullWidth:!0,children:"Try Again"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})})}Kc.propTypes={isOpen:Y.bool.isRequired,provider:Y.string,providerInfo:Y.shape({name:Y.string}),onSuccess:Y.func,onClose:Y.func.isRequired,oauthMeta:Y.object,idcConfig:Y.shape({startUrl:Y.string,region:Y.string})};const Gd=[...Object.keys(Kv),...Object.keys(Ja),...Object.keys(Vv),...Object.keys(Hv)],Zd=Object.keys(Ja).filter(e=>Ja[e].noAuth);function eA({isOpen:e,onClose:t,onSelect:r,onDeselect:n,selectedModel:i,activeProviders:a=[],title:o="Select Model",modelAliases:s={},kindFilter:l=null,addedModelValues:c=[],closeOnSelect:u=!0}){const d=g.useMemo(()=>l?a.filter(C=>{const T=Qa[C.provider];return((T==null?void 0:T.serviceKinds)||["llm"]).includes(l)}):a,[a,l]),[f,h]=g.useState(""),[p,y]=g.useState([]),[x,v]=g.useState([]),[S,b]=g.useState([]),[w,E]=g.useState({}),A=async()=>{try{const C=await fetch("/api/combos");if(!C.ok)throw new Error(`Failed to fetch combos: ${C.status}`);const T=await C.json();y(T.combos||[])}catch(C){console.error("Error fetching combos:",C),y([])}};g.useEffect(()=>{e&&A()},[e]);const _=async()=>{try{const C=await fetch("/api/provider-nodes");if(!C.ok)throw new Error(`Failed to fetch provider nodes: ${C.status}`);const T=await C.json();v(T.nodes||[])}catch(C){console.error("Error fetching provider nodes:",C),v([])}};g.useEffect(()=>{e&&_()},[e]);const O=async()=>{try{const C=await fetch("/api/models/custom");if(!C.ok)throw new Error(`Failed to fetch custom models: ${C.status}`);const T=await C.json();b(T.models||[])}catch(C){console.error("Error fetching custom models:",C),b([])}};g.useEffect(()=>{e&&O()},[e]);const j=async()=>{try{const C=await fetch("/api/models/disabled");if(!C.ok)throw new Error(`Failed to fetch disabled models: ${C.status}`);const T=await C.json();E(T.disabled||{})}catch(C){console.error("Error fetching disabled models:",C),E({})}};g.useEffect(()=>{e&&j()},[e]);const M=g.useMemo(()=>({...Kv,...Ja,...Vv,...Hv}),[]),N=g.useMemo(()=>{const C={},T=new Set(["webSearch","webFetch"]),$=new Set(["image","tts","stt","embedding","imageToText"]),D=new Set(["tts","image","webFetch"]),L=G=>l?$.has(l)?G.filter(q=>q.isPlaceholder||q.type===l):G:G.filter(q=>q.isPlaceholder||!q.type||q.type==="llm"),V=d.map(G=>G.provider),H=l?Zd.filter(G=>{var q;return(((q=Qa[G])==null?void 0:q.serviceKinds)||["llm"]).includes(l)}):Zd;return[...new Set([...V,...H])].sort((G,q)=>{const X=Gd.indexOf(G),F=Gd.indexOf(q);return(X===-1?999:X)-(F===-1?999:F)}).forEach(G=>{var B;const q=Yd(G),X=M[G]||{name:G,color:"#666"},F=qv(G)||Yv(G);if(l&&T.has(l)){C[G]={name:X.name,alias:q,color:X.color,models:[{id:G,name:X.name,value:G}]};return}if(X.passthroughModels){let U=Object.entries(s).filter(([,R])=>R.startsWith(`${q}/`)).map(([R,Z])=>({id:Z.replace(`${q}/`,""),name:R,value:Z}));if(l&&$.has(l)&&(U=Xd(G).filter(R=>R.type===l).map(R=>({id:R.id,name:R.name,value:`${q}/${R.id}`,type:R.type})),U.length===0&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(U=[{id:G,name:X.name,value:q}])),U.length>0){const R=x.find(J=>J.id===G),Z=(R==null?void 0:R.name)||X.name;C[G]={name:Z,alias:q,color:X.color,models:U}}}else if(F){if(l&&$.has(l))return;const K=a.find(re=>re.provider===G),U=x.find(re=>re.id===G),R=(K==null?void 0:K.name)||(U==null?void 0:U.name)||X.name,Z=((B=K==null?void 0:K.providerSpecificData)==null?void 0:B.prefix)||(U==null?void 0:U.prefix)||G,J=Object.entries(s).filter(([,re])=>re.startsWith(`${G}/`)).map(([re,le])=>({id:le.replace(`${G}/`,""),name:re,value:`${Z}/${le.replace(`${G}/`,"")}`})),ee=J.length>0?J:[{id:`__placeholder__${G}`,name:`${Z}/model-id`,value:`${Z}/model-id`,isPlaceholder:!0}];C[G]={name:R,alias:Z,color:X.color,models:ee,isCustom:!0,hasModels:J.length>0}}else{const K=Xd(G),U=new Set(K.map(ce=>ce.id)),R=K.length>0,Z=Object.entries(s).filter(([ce,ke])=>ke.startsWith(`${q}/`)&&(R?ce===ke.replace(`${q}/`,""):!0)&&!U.has(ke.replace(`${q}/`,""))).map(([ce,ke])=>({id:ke.replace(`${q}/`,""),name:ce,value:ke,isCustom:!0})),J=new Set(Z.map(ce=>ce.id)),ee=S.filter(ce=>ce.providerAlias===q&&!U.has(ce.id)&&!J.has(ce.id)).map(ce=>({id:ce.id,name:ce.name||ce.id,value:`${q}/${ce.id}`,isCustom:!0})),re=[...K.map(ce=>({id:ce.id,name:ce.name,value:`${q}/${ce.id}`,type:ce.type})),...Z,...ee],le=new Set;let se=L(re.filter(ce=>le.has(ce.value)?!1:(le.add(ce.value),!0)));se.length===0&&l&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(se=[{id:G,name:X.name,value:q}]),se.length>0&&(C[G]={name:X.name,alias:q,color:X.color,models:se})}}),Object.entries(C).forEach(([G,q])=>{const X=Yd(G),F=new Set([...w[X]||[],...w[G]||[]]);F.size!==0&&(q.models=q.models.filter(B=>!F.has(B.id)),q.models.length===0&&delete C[G])}),C},[d,s,M,x,S,w,l,a]),k=g.useMemo(()=>{if(l)return[];if(!f.trim())return p;const C=f.toLowerCase();return p.filter(T=>T.name.toLowerCase().includes(C))},[p,f,l]),z=C=>{const T=C.filter(D=>c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name)),$=C.filter(D=>!c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name));return[...T,...$]},P=g.useMemo(()=>{const C=f.trim().toLowerCase(),T={};return Object.entries(N).forEach(([$,D])=>{let L=D.models;if(C){const V=D.name.toLowerCase().includes(C);if(L=L.filter(H=>H.name.toLowerCase().includes(C)||H.id.toLowerCase().includes(C)),L.length===0&&!V)return}T[$]={...D,models:z(L)}}),T},[N,f,c]),I=C=>{const T=(C==null?void 0:C.value)||(C==null?void 0:C.name)||C;c.includes(T)&&n?n(C):r(C),u&&(t(),h(""))};return m.jsxs(hr,{isOpen:e,onClose:()=>{t(),h("")},title:o,size:"md",className:"p-4!",footer:null,children:[m.jsxs("div",{className:"flex items-center gap-2 mb-3 px-2.5 py-2 bg-primary/8 border border-primary/20 rounded-lg text-xs text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined text-primary shrink-0",style:{fontSize:"14px"},children:"info"}),m.jsx("span",{children:"Click to add, click again to remove. Changes are saved automatically."})]}),m.jsx("div",{className:"mb-3",children:m.jsxs("div",{className:"relative",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-text-muted text-[16px]",children:"search"}),m.jsx("input",{type:"text",placeholder:"Search...",value:f,onChange:C=>h(C.target.value),className:"w-full pl-8 pr-3 py-1.5 bg-surface border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-primary/50"})]})}),m.jsxs("div",{className:"max-h-[400px] overflow-y-auto space-y-3",children:[k.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx("span",{className:"material-symbols-outlined text-primary text-[14px]",children:"layers"}),m.jsx("span",{className:"text-xs font-medium text-primary",children:"Combos"}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",k.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(C=>{const T=i===C.name;return m.jsxs("button",{onClick:()=>I({id:C.name,name:C.name,value:C.name}),className:`
1
+ var KS=Object.defineProperty;var qS=(e,t,r)=>t in e?KS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ma=(e,t,r)=>qS(e,typeof t!="symbol"?t+"":t,r);import{j as m,n as at,u as Uv,M as hr,B as ue,f as Y,g as Qa,A as Hv,c as Vv,F as Ja,O as Kv,i as Yd,k as qv,l as Yv,h as Xd,P as YS}from"./index.D4FwOBBU.js";import{b as g,r as Vc,g as Xv,W as XS,c as Gv,i as GS}from"./router.Cjj1--8t.js";function xe({label:e,type:t="text",placeholder:r,value:n,onChange:i,error:a,hint:o,icon:s,disabled:l=!1,required:c=!1,className:u,inputClassName:d,...f}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",u),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,c&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[s&&m.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:s})}),m.jsx("input",{type:t,placeholder:r,value:n,onChange:i,disabled:l,className:at("w-full py-2.5 px-3 text-sm text-text-main bg-surface-2 rounded-[10px]","border border-transparent placeholder-text-muted/70","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 ease-out disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",s&&"pl-10",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",d),...f})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function ZS({label:e,options:t=[],value:r,onChange:n,placeholder:i="Select an option",error:a,hint:o,disabled:s=!1,required:l=!1,className:c,selectClassName:u,...d}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",c),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,l&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[m.jsxs("select",{value:r,onChange:n,disabled:s,className:at("w-full py-2.5 px-3 pr-10 text-sm text-text-main","bg-surface-2 border border-transparent rounded-[10px] appearance-none","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",u),...d,children:[m.jsx("option",{value:"",disabled:!0,children:i}),t.map(f=>m.jsx("option",{value:f.value,children:f.label},f.value))]}),m.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"expand_more"})})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function zt({children:e,title:t,subtitle:r,icon:n,action:i,padding:a="md",hover:o=!1,elev:s=!1,className:l,...c}){const u={none:"",xs:"p-3",sm:"p-4",md:"p-6",lg:"p-8"};return m.jsxs("div",{className:at("bg-surface border border-border-subtle",s?"rounded-[14px] shadow-[var(--shadow-elev)]":"rounded-[14px] shadow-[var(--shadow-soft)]",o&&"hover:shadow-[var(--shadow-warm)] hover:border-brand-500/30 transition-all cursor-pointer",u[a],l),...c,children:[(t||i)&&m.jsxs("div",{className:"flex items-center justify-between mb-4",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[n&&m.jsx("div",{className:"p-2 rounded-[10px] bg-bg text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:n})}),m.jsxs("div",{children:[t&&m.jsx("h3",{className:"text-text-main font-semibold",children:t}),r&&m.jsx("p",{className:"text-sm text-text-muted",children:r})]})]}),i]}),e]})}zt.Section=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-4 rounded-[10px]","bg-bg border border-border-subtle",r),...n,children:t})};zt.Row=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-3 -mx-3 px-3 transition-colors","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50",r),...n,children:t})};zt.ListItem=function({children:t,actions:r,className:n,...i}){return m.jsxs("div",{className:at("group flex items-center justify-between p-3 -mx-3 px-3","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50 transition-colors",n),...i,children:[m.jsx("div",{className:"flex-1 min-w-0",children:t}),r&&m.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r})]})};const QS={default:"bg-surface-2 text-text-muted",primary:"bg-brand-500/10 text-brand-600 dark:text-brand-300",success:"bg-green-500/10 text-green-600 dark:text-green-400",warning:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",error:"bg-red-500/10 text-red-600 dark:text-red-400",info:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},JS={sm:"px-2 py-0.5 text-[10px]",md:"px-2.5 py-1 text-xs",lg:"px-3 py-1.5 text-sm"};function Ci({children:e,variant:t="default",size:r="md",dot:n=!1,icon:i,className:a}){return m.jsxs("span",{className:at("inline-flex items-center gap-1.5 rounded-full font-semibold",QS[t],JS[r],a),children:[n&&m.jsx("span",{className:at("size-1.5 rounded-full",t==="success"&&"bg-green-500",t==="warning"&&"bg-yellow-500",t==="error"&&"bg-red-500",t==="info"&&"bg-blue-500",t==="primary"&&"bg-brand-500",t==="default"&&"bg-gray-500")}),i&&m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:i}),e]})}function Js({checked:e=!1,onChange:t,label:r,description:n,disabled:i=!1,size:a="md",className:o}){const s={sm:{track:"w-8 h-4",thumb:"size-3",translate:"translate-x-4"},md:{track:"w-11 h-6",thumb:"size-5",translate:"translate-x-5"},lg:{track:"w-14 h-7",thumb:"size-6",translate:"translate-x-7"}},l=()=>{!i&&t&&t(!e)};return m.jsxs("div",{className:at("flex items-center gap-3",i&&"opacity-50 cursor-not-allowed",o),children:[m.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:i,onClick:l,className:at("relative inline-flex shrink-0 cursor-pointer rounded-full","transition-colors duration-200 ease-in-out","focus:outline-none focus:ring-2 focus:ring-brand-500/30",e?"bg-brand-500":"bg-surface-3",s[a].track,i&&"cursor-not-allowed"),children:m.jsx("span",{className:at("pointer-events-none inline-block rounded-full bg-white shadow-sm","transform transition duration-200 ease-in-out",e?s[a].translate:"translate-x-0.5",s[a].thumb,"mt-0.5")})}),(r||n)&&m.jsxs("div",{className:"flex flex-col",children:[r&&m.jsx("span",{className:"text-sm font-medium text-text-main",children:r}),n&&m.jsx("span",{className:"text-xs text-text-muted",children:n})]})]})}function Kc({isOpen:e,provider:t,providerInfo:r,onSuccess:n,onClose:i,oauthMeta:a,idcConfig:o}){const[s,l]=g.useState("waiting"),[c,u]=g.useState(null),[d,f]=g.useState(""),[h,p]=g.useState(null),[y,x]=g.useState(!1),[v,S]=g.useState(null),[b,w]=g.useState(!1),E=g.useRef(null),A=g.useRef(!1),_=g.useRef(!1),{copied:O,copy:j}=Uv(),[M,N]=g.useState(!1),[k,z]=g.useState("/callback?code=..."),P=g.useRef(!1);g.useEffect(()=>{typeof window<"u"&&(N(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),z(`${window.location.origin}/callback?code=...`))},[]);const I=g.useCallback(async(q,X)=>{if(c)try{const F=await fetch(`/api/oauth/${t}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,redirectUri:c.redirectUri,codeVerifier:c.codeVerifier,state:X,...a?{meta:a}:{}})}),B=await F.json();if(!F.ok)throw new Error(B.error);l("success"),n==null||n()}catch(F){p(F.message),l("error")}},[c,t,n,a]),C=g.useCallback(async q=>{if(c!=null&&c.state)try{const X=await fetch("/api/oauth/xai/manual-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,state:c.state})}),F=await X.json();if(!X.ok)throw new Error(F.error);l("success"),n==null||n()}catch(X){p(X.message),l("error")}},[c,n]),T=g.useCallback(async(q,X,F,B,K)=>{A.current=!1,w(!0);const R=Date.now()+(Number.isFinite(K)&&K>0?K:12e4);for(;Date.now()<R;){if(A.current){console.log("[OAuthModal] Polling aborted"),w(!1);return}if(await new Promise(Z=>setTimeout(Z,F*1e3)),A.current){console.log("[OAuthModal] Polling aborted after sleep"),w(!1);return}try{const J=await(await fetch(`/api/oauth/${t}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:q,codeVerifier:X,extraData:B})})).json();if(J.success){A.current=!0,l("success"),w(!1),n==null||n();return}if(J.error==="expired_token"||J.error==="access_denied")throw new Error(J.errorDescription||J.error);J.error==="slow_down"&&(F=Math.min(F+5,30))}catch(Z){p(Z.message),l("error"),w(!1);return}}p("Authorization timeout"),l("error"),w(!1)},[t,n]),$=g.useCallback(async()=>{if(t)try{if(p(null),["github","qwen","kiro","kimi-coding","kilocode","codebuddy-cn","qoder","grok-cli"].includes(t)){x(!0),l("waiting");const re=new URL(`/api/oauth/${t}/device-code`,window.location.origin);t==="kiro"&&(o!=null&&o.startUrl)&&(re.searchParams.set("start_url",o.startUrl),o.region&&re.searchParams.set("region",o.region),re.searchParams.set("auth_method","idc"));const le=await fetch(re.toString()),se=await le.json();if(!le.ok)throw new Error(se.error);S(se);const ce=se.verification_uri_complete||se.verification_uri;ce&&window.open(ce,"_blank","noopener,noreferrer");const ke=t==="kiro"?{_clientId:se._clientId,_clientSecret:se._clientSecret,_region:se._region,_authMethod:se._authMethod,_startUrl:se._startUrl}:t==="qoder"?{_qoderNonce:se._qoderNonce,_qoderMachineId:se._qoderMachineId,_qoderVerifier:se.codeVerifier}:null;T(se.device_code,se.codeVerifier,se.interval||5,ke,Number.isFinite(se.expires_in)&&se.expires_in>0?se.expires_in*1e3:void 0);return}const X=window.location.port||(window.location.protocol==="https:"?"443":"80");let F;t==="codex"?F="http://localhost:1455/auth/callback":t==="xai"?F="http://127.0.0.1:56121/callback":F=`http://localhost:${X}/callback`;const B=new URL(`/api/oauth/${t}/authorize`,window.location.origin);B.searchParams.set("redirect_uri",F),a&&Object.entries(a).forEach(([re,le])=>{le&&B.searchParams.set(re,le)});const K=await fetch(B.toString()),U=await K.json();if(!K.ok)throw new Error(U.error);let R=!1,Z=!1;if(t==="codex")try{const re=new URL("/api/oauth/codex/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();R=se.success,Z=!!se.serverSide}catch{R=!1}let J=!1,ee=!1;if(t==="xai")try{const re=new URL("/api/oauth/xai/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();if(J=se.success,ee=!!se.serverSide,!J&&se.reason==="port_busy")throw new Error("Port 56121 in use; close the conflicting process and retry")}catch(re){if(re!=null&&re.message)throw re;J=!1}if(u({...U,redirectUri:F,codexServerSide:Z,xaiServerSide:ee}),!U.authUrl)throw U.flowType==="device_code"?new Error(`Provider ${t} uses device-code login but is not wired in the OAuth modal device-code list`):new Error("No authorization URL returned from OAuth provider");t==="codex"&&R||t==="xai"&&J?(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input")):!M||t==="codex"||t==="xai"?(l("input"),window.open(U.authUrl,"_blank")):(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input"))}catch(q){p(q.message),l("error")}},[t,M,T,a,o]);g.useEffect(()=>{if(e&&t){if(_.current)return;_.current=!0,u(null),f(""),p(null),x(!1),S(null),w(!1),A.current=!1,$()}else e||(A.current=!0,_.current=!1,t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}))},[e,t,$]),g.useEffect(()=>{const q=c!=null&&c.codexServerSide?"codex":c!=null&&c.xaiServerSide?"xai":null;if(!q||!(c!=null&&c.state)||P.current)return;let X=!1;const F=1500,B=200;let K=0;const U=async()=>{if(!(X||P.current)){K+=1;try{const Z=await(await fetch(`/api/oauth/${q}/poll-status?state=${encodeURIComponent(c.state)}`)).json();if(X||P.current)return;if(Z.status==="done"){P.current=!0,l("success"),n==null||n();return}if(Z.status==="error"){P.current=!0,p(Z.error||"Authentication failed"),l("error");return}}catch{}if(K>=B){P.current=!0,p("Authentication timeout"),l("error");return}setTimeout(U,F)}};return setTimeout(U,F),()=>{X=!0}},[c,n]),g.useEffect(()=>{if(!c)return;P.current=!1;const q=async K=>{if(P.current)return;const{code:U,token:R,state:Z,error:J,errorDescription:ee}=K;if(J){P.current=!0,p(ee||J),l("error");return}(R||U)&&(P.current=!0,await I(R||U,Z))},X=K=>{var Z;const U=K.origin.includes("localhost")||K.origin.includes("127.0.0.1"),R=K.origin===window.location.origin;!U&&!R||((Z=K.data)==null?void 0:Z.type)==="oauth_callback"&&q(K.data.data)};window.addEventListener("message",X);let F;try{F=new BroadcastChannel("oauth_callback"),F.onmessage=K=>q(K.data)}catch{console.log("BroadcastChannel not supported")}const B=K=>{if(K.key==="oauth_callback"&&K.newValue)try{const U=JSON.parse(K.newValue);q(U),localStorage.removeItem("oauth_callback")}catch{console.log("Failed to parse localStorage data")}};window.addEventListener("storage",B);try{const K=localStorage.getItem("oauth_callback");if(K){const U=JSON.parse(K);U.timestamp&&Date.now()-U.timestamp<3e4&&q(U),localStorage.removeItem("oauth_callback")}}catch{}return()=>{window.removeEventListener("message",X),window.removeEventListener("storage",B),F&&F.close()}},[c,I]);const D=async()=>{try{p(null);const q=d.trim();if(q.startsWith("eyJ")&&q.includes(".")){await I(q,null);return}if(t==="xai"&&q&&!q.includes("://")&&!q.includes("?")&&!q.includes("code=")){await C(q);return}if(t==="kimchi"&&q&&!q.includes("://")&&!q.includes("?")){await I(q,null);return}const X=new URL(q),F=X.searchParams.get("code"),B=X.searchParams.get("token"),K=X.searchParams.get("state"),U=X.searchParams.get("error");if(U)throw new Error(X.searchParams.get("error_description")||U);if(!F&&!B)throw new Error(t==="xai"?"Paste the callback URL or copied xAI code":t==="kimchi"?"No Kimchi token found in URL":"No authorization code found in URL");await I(B||F,K)}catch(q){p(q.message),l("error")}},L=g.useCallback(()=>{t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}),i()},[i,t]);if(!t||!r)return null;const V=t==="xai",H=t==="kimchi",Q=(v==null?void 0:v.verification_uri_complete)||(v==null?void 0:v.verification_uri)||"",te=V?"Connect Grok Build OAuth":`Connect ${r.name}`,G=V?"http://127.0.0.1:56121/callback?code=... or copied code":H?`${k.replace("code=...","token=...")} or copied token`:k;return m.jsx(hr,{isOpen:e,title:te,onClose:L,size:"lg",children:m.jsxs("div",{className:"flex flex-col gap-4",children:[(s==="waiting"||s==="input")&&!y&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50",children:[m.jsx("span",{className:"material-symbols-outlined text-base text-primary animate-spin",children:"progress_activity"}),m.jsx("span",{className:"text-sm",children:V?"Waiting for Grok Build OAuth…":"Waiting for popup authorization…"})]}),m.jsxs("div",{className:"flex items-center gap-3 my-1",children:[m.jsx("div",{className:"flex-1 h-px bg-border"}),m.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wider",children:"Or paste callback URL manually"}),m.jsx("div",{className:"flex-1 h-px bg-border"})]}),m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 1: Open this ",V?"Grok Build OAuth URL":"URL"," in your browser"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(xe,{value:(c==null?void 0:c.authUrl)||"",readOnly:!0,className:"flex-1 font-mono text-xs"}),m.jsx(ue,{variant:"secondary",icon:O==="auth_url"?"check":"content_copy",onClick:()=>j(c==null?void 0:c.authUrl,"auth_url"),disabled:!(c!=null&&c.authUrl),children:"Copy"})]})]}),m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 2: Paste the ",t==="xai"?"callback URL or copied code":H?"callback URL or copied token":"callback URL"," here"]}),m.jsx("p",{className:"text-xs text-text-muted mb-2",children:t==="xai"?"If xAI shows a code instead of redirecting, paste that code here.":H?"After authorization, copy the full callback URL or token from your browser.":"After authorization, copy the full URL from your browser."}),m.jsx(xe,{value:d,onChange:q=>f(q.target.value),placeholder:G,className:"font-mono text-xs"})]})]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:D,fullWidth:!0,disabled:!d,children:"Connect"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),s==="waiting"&&y&&v&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"text-center py-4",children:[m.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Visit the login URL below and authorize:"}),m.jsxs("div",{className:"bg-sidebar p-4 rounded-lg mb-4",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Login URL"}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-sm break-all",children:Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="login_url"?"check":"content_copy",onClick:()=>j(Q,"login_url"),disabled:!Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:"open_in_new",onClick:()=>window.open(Q,"_blank","noopener,noreferrer"),disabled:!Q,children:"Open"})]})]}),m.jsxs("div",{className:"bg-primary/10 p-4 rounded-lg",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Your Code"}),m.jsxs("div",{className:"flex items-center justify-center gap-2",children:[m.jsx("p",{className:"text-2xl font-mono font-bold text-primary",children:v.user_code}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="user_code"?"check":"content_copy",onClick:()=>j(v.user_code,"user_code")})]})]})]}),b&&m.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),"Waiting for authorization..."]})]}),s==="success"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connected Successfully!"}),m.jsxs("p",{className:"text-sm text-text-muted mb-4",children:["Your ",r.name," account has been connected."]}),m.jsx(ue,{onClick:L,fullWidth:!0,children:"Done"})]}),s==="error"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-red-600",children:"error"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connection Failed"}),m.jsx("p",{className:"text-sm text-red-600 mb-4",children:h}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:$,variant:"secondary",fullWidth:!0,children:"Try Again"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})})}Kc.propTypes={isOpen:Y.bool.isRequired,provider:Y.string,providerInfo:Y.shape({name:Y.string}),onSuccess:Y.func,onClose:Y.func.isRequired,oauthMeta:Y.object,idcConfig:Y.shape({startUrl:Y.string,region:Y.string})};const Gd=[...Object.keys(Kv),...Object.keys(Ja),...Object.keys(Vv),...Object.keys(Hv)],Zd=Object.keys(Ja).filter(e=>Ja[e].noAuth);function eA({isOpen:e,onClose:t,onSelect:r,onDeselect:n,selectedModel:i,activeProviders:a=[],title:o="Select Model",modelAliases:s={},kindFilter:l=null,addedModelValues:c=[],closeOnSelect:u=!0}){const d=g.useMemo(()=>l?a.filter(C=>{const T=Qa[C.provider];return((T==null?void 0:T.serviceKinds)||["llm"]).includes(l)}):a,[a,l]),[f,h]=g.useState(""),[p,y]=g.useState([]),[x,v]=g.useState([]),[S,b]=g.useState([]),[w,E]=g.useState({}),A=async()=>{try{const C=await fetch("/api/combos");if(!C.ok)throw new Error(`Failed to fetch combos: ${C.status}`);const T=await C.json();y(T.combos||[])}catch(C){console.error("Error fetching combos:",C),y([])}};g.useEffect(()=>{e&&A()},[e]);const _=async()=>{try{const C=await fetch("/api/provider-nodes");if(!C.ok)throw new Error(`Failed to fetch provider nodes: ${C.status}`);const T=await C.json();v(T.nodes||[])}catch(C){console.error("Error fetching provider nodes:",C),v([])}};g.useEffect(()=>{e&&_()},[e]);const O=async()=>{try{const C=await fetch("/api/models/custom");if(!C.ok)throw new Error(`Failed to fetch custom models: ${C.status}`);const T=await C.json();b(T.models||[])}catch(C){console.error("Error fetching custom models:",C),b([])}};g.useEffect(()=>{e&&O()},[e]);const j=async()=>{try{const C=await fetch("/api/models/disabled");if(!C.ok)throw new Error(`Failed to fetch disabled models: ${C.status}`);const T=await C.json();E(T.disabled||{})}catch(C){console.error("Error fetching disabled models:",C),E({})}};g.useEffect(()=>{e&&j()},[e]);const M=g.useMemo(()=>({...Kv,...Ja,...Vv,...Hv}),[]),N=g.useMemo(()=>{const C={},T=new Set(["webSearch","webFetch"]),$=new Set(["image","tts","stt","embedding","imageToText"]),D=new Set(["tts","image","webFetch"]),L=G=>l?$.has(l)?G.filter(q=>q.isPlaceholder||q.type===l):G:G.filter(q=>q.isPlaceholder||!q.type||q.type==="llm"),V=d.map(G=>G.provider),H=l?Zd.filter(G=>{var q;return(((q=Qa[G])==null?void 0:q.serviceKinds)||["llm"]).includes(l)}):Zd;return[...new Set([...V,...H])].sort((G,q)=>{const X=Gd.indexOf(G),F=Gd.indexOf(q);return(X===-1?999:X)-(F===-1?999:F)}).forEach(G=>{var B;const q=Yd(G),X=M[G]||{name:G,color:"#666"},F=qv(G)||Yv(G);if(l&&T.has(l)){C[G]={name:X.name,alias:q,color:X.color,models:[{id:G,name:X.name,value:G}]};return}if(X.passthroughModels){let U=Object.entries(s).filter(([,R])=>R.startsWith(`${q}/`)).map(([R,Z])=>({id:Z.replace(`${q}/`,""),name:R,value:Z}));if(l&&$.has(l)&&(U=Xd(G).filter(R=>R.type===l).map(R=>({id:R.id,name:R.name,value:`${q}/${R.id}`,type:R.type})),U.length===0&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(U=[{id:G,name:X.name,value:q}])),U.length>0){const R=x.find(J=>J.id===G),Z=(R==null?void 0:R.name)||X.name;C[G]={name:Z,alias:q,color:X.color,models:U}}}else if(F){if(l&&$.has(l))return;const K=a.find(re=>re.provider===G),U=x.find(re=>re.id===G),R=(K==null?void 0:K.name)||(U==null?void 0:U.name)||X.name,Z=((B=K==null?void 0:K.providerSpecificData)==null?void 0:B.prefix)||(U==null?void 0:U.prefix)||G,J=Object.entries(s).filter(([,re])=>re.startsWith(`${G}/`)).map(([re,le])=>({id:le.replace(`${G}/`,""),name:re,value:`${Z}/${le.replace(`${G}/`,"")}`})),ee=J.length>0?J:[{id:`__placeholder__${G}`,name:`${Z}/model-id`,value:`${Z}/model-id`,isPlaceholder:!0}];C[G]={name:R,alias:Z,color:X.color,models:ee,isCustom:!0,hasModels:J.length>0}}else{const K=Xd(G),U=new Set(K.map(ce=>ce.id)),R=K.length>0,Z=Object.entries(s).filter(([ce,ke])=>ke.startsWith(`${q}/`)&&(R?ce===ke.replace(`${q}/`,""):!0)&&!U.has(ke.replace(`${q}/`,""))).map(([ce,ke])=>({id:ke.replace(`${q}/`,""),name:ce,value:ke,isCustom:!0})),J=new Set(Z.map(ce=>ce.id)),ee=S.filter(ce=>ce.providerAlias===q&&!U.has(ce.id)&&!J.has(ce.id)).map(ce=>({id:ce.id,name:ce.name||ce.id,value:`${q}/${ce.id}`,isCustom:!0})),re=[...K.map(ce=>({id:ce.id,name:ce.name,value:`${q}/${ce.id}`,type:ce.type})),...Z,...ee],le=new Set;let se=L(re.filter(ce=>le.has(ce.value)?!1:(le.add(ce.value),!0)));se.length===0&&l&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(se=[{id:G,name:X.name,value:q}]),se.length>0&&(C[G]={name:X.name,alias:q,color:X.color,models:se})}}),Object.entries(C).forEach(([G,q])=>{const X=Yd(G),F=new Set([...w[X]||[],...w[G]||[]]);F.size!==0&&(q.models=q.models.filter(B=>!F.has(B.id)),q.models.length===0&&delete C[G])}),C},[d,s,M,x,S,w,l,a]),k=g.useMemo(()=>{if(l)return[];if(!f.trim())return p;const C=f.toLowerCase();return p.filter(T=>T.name.toLowerCase().includes(C))},[p,f,l]),z=C=>{const T=C.filter(D=>c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name)),$=C.filter(D=>!c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name));return[...T,...$]},P=g.useMemo(()=>{const C=f.trim().toLowerCase(),T={};return Object.entries(N).forEach(([$,D])=>{let L=D.models;if(C){const V=D.name.toLowerCase().includes(C);if(L=L.filter(H=>H.name.toLowerCase().includes(C)||H.id.toLowerCase().includes(C)),L.length===0&&!V)return}T[$]={...D,models:z(L)}}),T},[N,f,c]),I=C=>{const T=(C==null?void 0:C.value)||(C==null?void 0:C.name)||C;c.includes(T)&&n?n(C):r(C),u&&(t(),h(""))};return m.jsxs(hr,{isOpen:e,onClose:()=>{t(),h("")},title:o,size:"md",className:"p-4!",footer:null,children:[m.jsxs("div",{className:"flex items-center gap-2 mb-3 px-2.5 py-2 bg-primary/8 border border-primary/20 rounded-lg text-xs text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined text-primary shrink-0",style:{fontSize:"14px"},children:"info"}),m.jsx("span",{children:"Click to add, click again to remove. Changes are saved automatically."})]}),m.jsx("div",{className:"mb-3",children:m.jsxs("div",{className:"relative",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-text-muted text-[16px]",children:"search"}),m.jsx("input",{type:"text",placeholder:"Search...",value:f,onChange:C=>h(C.target.value),className:"w-full pl-8 pr-3 py-1.5 bg-surface border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-primary/50"})]})}),m.jsxs("div",{className:"max-h-[400px] overflow-y-auto space-y-3",children:[k.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx("span",{className:"material-symbols-outlined text-primary text-[14px]",children:"layers"}),m.jsx("span",{className:"text-xs font-medium text-primary",children:"Combos"}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",k.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(C=>{const T=i===C.name;return m.jsxs("button",{onClick:()=>I({id:C.name,name:C.name,value:C.name}),className:`
2
2
  px-2 py-1 rounded-xl text-xs font-medium transition-all border hover:cursor-pointer flex items-center gap-1
3
3
  ${T?"bg-primary text-white border-primary":c.includes(C.name)?"bg-primary border-primary text-white hover:bg-primary-hover":"bg-surface border-border text-text-main hover:border-primary/50 hover:bg-primary/5"}
4
4
  `,children:[c.includes(C.name)&&m.jsx("span",{className:"material-symbols-outlined leading-none",style:{fontSize:"10px"},children:"check"}),C.name]},C.id)})})]}),Object.entries(P).map(([C,T])=>m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx(YS,{src:C==="codebuddy"||C==="cb"?"/providers/codebuddy.svg":`/providers/${C}.png`,alt:T.name,size:14,fallbackText:(T.name||C).slice(0,2).toUpperCase(),fallbackColor:T.color}),m.jsx("span",{className:"text-xs font-medium text-primary",children:T.name}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",T.models.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:T.models.map($=>{const D=i===$.value,L=$.isPlaceholder;return m.jsx("button",{onClick:()=>I($),title:L?"Select to pre-fill, then edit model ID in the input":void 0,className:`
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/page.C0gBvR4O.js","assets/router.Cjj1--8t.js","assets/zustand.akaTi5uX.js","assets/page.CdMmlUEm.js","assets/page.Df9qtrdG.js","assets/page.BbPPdoas.js","assets/machine.CagOtseJ.js","assets/EndpointPageClient.C2WMTYy0.js","assets/NoAuthProxyCard.BDcXaWvM.js","assets/NoAuthProxyCard.C5ap-Sga.css","assets/Loading.BHPtQ9vj.js","assets/page.B-dzeIUC.js","assets/page.N1x4YL8_.js","assets/page.11hpNKmq.js","assets/page.CPTtRDxw.js","assets/page.BfmI9KYe.js","assets/page.B3QqvLep.js","assets/page.Dl1apZE2.js","assets/page.HV0w1d5C.js","assets/page.BdS20a1O.js","assets/page.CvUFZzXr.js","assets/page.D8Rp8fFR.js","assets/cliTools.CsdwAybi.js","assets/page.CrP7niA2.js","assets/page.BFb7yUd8.js","assets/page.C8sLEMa6.js","assets/page.tE7PpWYW.js","assets/page.CCNsZBXp.js","assets/page.B-LxsnqU.js","assets/page.P2Ny5veR.js","assets/page.C6bYizL7.js","assets/page.CrBl7f8N.js","assets/page.uziaGZsT.js","assets/page.Ch647dVk.js","assets/page.B-nBR75u.js","assets/page.CyUqJPmx.js","assets/page.CpvXDkQF.js","assets/page.sUIPWIiF.js","assets/page.DiL4Gwqe.js","assets/page.CF_YSLwP.js","assets/page.Cged1bOZ.js","assets/page.B8xdkCWA.js","assets/page.BgGJovOg.js","assets/page.-lpNgYAw.js","assets/page.fOOCr18J.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/page.DINPUA6N.js","assets/router.Cjj1--8t.js","assets/zustand.akaTi5uX.js","assets/page.t4nKFefI.js","assets/page.Bfr4417O.js","assets/page.cAR8tR7Z.js","assets/machine.CagOtseJ.js","assets/EndpointPageClient.BnlQVTIB.js","assets/NoAuthProxyCard.WHGGEUIp.js","assets/NoAuthProxyCard.C5ap-Sga.css","assets/Loading.C1il44u0.js","assets/page.A4gD6oiw.js","assets/page.BpcyRUKz.js","assets/page.B5nk3H0f.js","assets/page.UoGOSKkx.js","assets/page.feKgaG20.js","assets/page.1numFcXc.js","assets/page.BdB6udZG.js","assets/page.CR7Yees9.js","assets/page.DSEK9UW0.js","assets/page.Dr6yAoTO.js","assets/page.DcmbyZGV.js","assets/cliTools.CsdwAybi.js","assets/page.GhgvWftU.js","assets/page.B1og8_GD.js","assets/page.1w9bTOPd.js","assets/page.3ARdH6tE.js","assets/page.FR_Izkgi.js","assets/page.C6WsIDgW.js","assets/page.CCEJ5tPH.js","assets/page.AhxgKhsm.js","assets/page.DSTzvOQ8.js","assets/page.BJIIZWfZ.js","assets/page.DU7jwIPk.js","assets/page.CXCEdPh6.js","assets/page.BvcbHe5b.js","assets/page.DT_RnrSs.js","assets/page.BfGkHTDS.js","assets/page.0Rt4rWPG.js","assets/page.CtLa-V_T.js","assets/page.CMUifPIU.js","assets/page.CsroRewc.js","assets/page.BGDrqCcI.js","assets/page.DjguJpCk.js","assets/page.DT7cpJ8d.js"])))=>i.map(i=>d[i]);
2
2
  var Kg=Object.defineProperty;var Qg=(o,s,c)=>s in o?Kg(o,s,{enumerable:!0,configurable:!0,writable:!0,value:c}):o[s]=c;var ge=(o,s,c)=>Qg(o,typeof s!="symbol"?s+"":s,c);import{r as Xg,a as Ig,g as Fg,b as O,c as Zp,u as mu,L as Et,d as Pp,O as Yg,B as Zg,R as Pg,e as Z,N as iu}from"./router.Cjj1--8t.js";import{c as pu}from"./zustand.akaTi5uX.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const p of document.querySelectorAll('link[rel="modulepreload"]'))u(p);new MutationObserver(p=>{for(const f of p)if(f.type==="childList")for(const S of f.addedNodes)S.tagName==="LINK"&&S.rel==="modulepreload"&&u(S)}).observe(document,{childList:!0,subtree:!0});function c(p){const f={};return p.integrity&&(f.integrity=p.integrity),p.referrerPolicy&&(f.referrerPolicy=p.referrerPolicy),p.crossOrigin==="use-credentials"?f.credentials="include":p.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function u(p){if(p.ep)return;p.ep=!0;const f=c(p);fetch(p.href,f)}})();var Ir={exports:{}},Nn={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -86,4 +86,4 @@ ${o}</tr>
86
86
  `}tablecell(o){const s=this.parser.parseInline(o.tokens),c=o.header?"th":"td";return(o.align?`<${c} align="${o.align}">`:`<${c}>`)+s+`</${c}>
87
87
  `}strong({tokens:o}){return`<strong>${this.parser.parseInline(o)}</strong>`}em({tokens:o}){return`<em>${this.parser.parseInline(o)}</em>`}codespan({text:o}){return`<code>${Oa(o,!0)}</code>`}br(o){return"<br>"}del({tokens:o}){return`<del>${this.parser.parseInline(o)}</del>`}link({href:o,title:s,tokens:c}){const u=this.parser.parseInline(c),p=Ip(o);if(p===null)return u;o=p;let f='<a href="'+o+'"';return s&&(f+=' title="'+Oa(s)+'"'),f+=">"+u+"</a>",f}image({href:o,title:s,text:c,tokens:u}){u&&(c=this.parser.parseInline(u,this.parser.textRenderer));const p=Ip(o);if(p===null)return Oa(c);o=p;let f=`<img src="${o}" alt="${c}"`;return s&&(f+=` title="${Oa(s)}"`),f+=">",f}text(o){return"tokens"in o&&o.tokens?this.parser.parseInline(o.tokens):"escaped"in o&&o.escaped?o.text:Oa(o.text)}},Tu=class{strong({text:o}){return o}em({text:o}){return o}codespan({text:o}){return o}del({text:o}){return o}html({text:o}){return o}text({text:o}){return o}link({text:o}){return""+o}image({text:o}){return""+o}br(){return""}},tt=class du{constructor(s){ge(this,"options");ge(this,"renderer");ge(this,"textRenderer");this.options=s||$t,this.options.renderer=this.options.renderer||new Ss,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Tu}static parse(s,c){return new du(c).parse(s)}static parseInline(s,c){return new du(c).parseInline(s)}parse(s,c=!0){var p,f;let u="";for(let S=0;S<s.length;S++){const g=s[S];if((f=(p=this.options.extensions)==null?void 0:p.renderers)!=null&&f[g.type]){const y=g,A=this.options.extensions.renderers[y.type].call({parser:this},y);if(A!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(y.type)){u+=A||"";continue}}const k=g;switch(k.type){case"space":{u+=this.renderer.space(k);continue}case"hr":{u+=this.renderer.hr(k);continue}case"heading":{u+=this.renderer.heading(k);continue}case"code":{u+=this.renderer.code(k);continue}case"table":{u+=this.renderer.table(k);continue}case"blockquote":{u+=this.renderer.blockquote(k);continue}case"list":{u+=this.renderer.list(k);continue}case"html":{u+=this.renderer.html(k);continue}case"paragraph":{u+=this.renderer.paragraph(k);continue}case"text":{let y=k,A=this.renderer.text(y);for(;S+1<s.length&&s[S+1].type==="text";)y=s[++S],A+=`
88
88
  `+this.renderer.text(y);c?u+=this.renderer.paragraph({type:"paragraph",raw:A,text:A,tokens:[{type:"text",raw:A,text:A,escaped:!0}]}):u+=A;continue}default:{const y='Token with "'+k.type+'" type was not found.';if(this.options.silent)return console.error(y),"";throw new Error(y)}}}return u}parseInline(s,c=this.renderer){var p,f;let u="";for(let S=0;S<s.length;S++){const g=s[S];if((f=(p=this.options.extensions)==null?void 0:p.renderers)!=null&&f[g.type]){const y=this.options.extensions.renderers[g.type].call({parser:this},g);if(y!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(g.type)){u+=y||"";continue}}const k=g;switch(k.type){case"escape":{u+=c.text(k);break}case"html":{u+=c.html(k);break}case"link":{u+=c.link(k);break}case"image":{u+=c.image(k);break}case"strong":{u+=c.strong(k);break}case"em":{u+=c.em(k);break}case"codespan":{u+=c.codespan(k);break}case"br":{u+=c.br(k);break}case"del":{u+=c.del(k);break}case"text":{u+=c.text(k);break}default:{const y='Token with "'+k.type+'" type was not found.';if(this.options.silent)return console.error(y),"";throw new Error(y)}}}return u}},tu,fs=(tu=class{constructor(o){ge(this,"options");ge(this,"block");this.options=o||$t}preprocess(o){return o}postprocess(o){return o}processAllTokens(o){return o}provideLexer(){return this.block?at.lex:at.lexInline}provideParser(){return this.block?tt.parse:tt.parseInline}},ge(tu,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"])),tu),qy=class{constructor(...o){ge(this,"defaults",hu());ge(this,"options",this.setOptions);ge(this,"parse",this.parseMarkdown(!0));ge(this,"parseInline",this.parseMarkdown(!1));ge(this,"Parser",tt);ge(this,"Renderer",Ss);ge(this,"TextRenderer",Tu);ge(this,"Lexer",at);ge(this,"Tokenizer",xs);ge(this,"Hooks",fs);this.use(...o)}walkTokens(o,s){var u,p;let c=[];for(const f of o)switch(c=c.concat(s.call(this,f)),f.type){case"table":{const S=f;for(const g of S.header)c=c.concat(this.walkTokens(g.tokens,s));for(const g of S.rows)for(const k of g)c=c.concat(this.walkTokens(k.tokens,s));break}case"list":{const S=f;c=c.concat(this.walkTokens(S.items,s));break}default:{const S=f;(p=(u=this.defaults.extensions)==null?void 0:u.childTokens)!=null&&p[S.type]?this.defaults.extensions.childTokens[S.type].forEach(g=>{const k=S[g].flat(1/0);c=c.concat(this.walkTokens(k,s))}):S.tokens&&(c=c.concat(this.walkTokens(S.tokens,s)))}}return c}use(...o){const s=this.defaults.extensions||{renderers:{},childTokens:{}};return o.forEach(c=>{const u={...c};if(u.async=this.defaults.async||u.async||!1,c.extensions&&(c.extensions.forEach(p=>{if(!p.name)throw new Error("extension name required");if("renderer"in p){const f=s.renderers[p.name];f?s.renderers[p.name]=function(...S){let g=p.renderer.apply(this,S);return g===!1&&(g=f.apply(this,S)),g}:s.renderers[p.name]=p.renderer}if("tokenizer"in p){if(!p.level||p.level!=="block"&&p.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const f=s[p.level];f?f.unshift(p.tokenizer):s[p.level]=[p.tokenizer],p.start&&(p.level==="block"?s.startBlock?s.startBlock.push(p.start):s.startBlock=[p.start]:p.level==="inline"&&(s.startInline?s.startInline.push(p.start):s.startInline=[p.start]))}"childTokens"in p&&p.childTokens&&(s.childTokens[p.name]=p.childTokens)}),u.extensions=s),c.renderer){const p=this.defaults.renderer||new Ss(this.defaults);for(const f in c.renderer){if(!(f in p))throw new Error(`renderer '${f}' does not exist`);if(["options","parser"].includes(f))continue;const S=f,g=c.renderer[S],k=p[S];p[S]=(...y)=>{let A=g.apply(p,y);return A===!1&&(A=k.apply(p,y)),A||""}}u.renderer=p}if(c.tokenizer){const p=this.defaults.tokenizer||new xs(this.defaults);for(const f in c.tokenizer){if(!(f in p))throw new Error(`tokenizer '${f}' does not exist`);if(["options","rules","lexer"].includes(f))continue;const S=f,g=c.tokenizer[S],k=p[S];p[S]=(...y)=>{let A=g.apply(p,y);return A===!1&&(A=k.apply(p,y)),A}}u.tokenizer=p}if(c.hooks){const p=this.defaults.hooks||new fs;for(const f in c.hooks){if(!(f in p))throw new Error(`hook '${f}' does not exist`);if(["options","block"].includes(f))continue;const S=f,g=c.hooks[S],k=p[S];fs.passThroughHooks.has(f)?p[S]=y=>{if(this.defaults.async)return Promise.resolve(g.call(p,y)).then(L=>k.call(p,L));const A=g.call(p,y);return k.call(p,A)}:p[S]=(...y)=>{let A=g.apply(p,y);return A===!1&&(A=k.apply(p,y)),A}}u.hooks=p}if(c.walkTokens){const p=this.defaults.walkTokens,f=c.walkTokens;u.walkTokens=function(S){let g=[];return g.push(f.call(this,S)),p&&(g=g.concat(p.call(this,S))),g}}this.defaults={...this.defaults,...u}}),this}setOptions(o){return this.defaults={...this.defaults,...o},this}lexer(o,s){return at.lex(o,s??this.defaults)}parser(o,s){return tt.parse(o,s??this.defaults)}parseMarkdown(o){return(c,u)=>{const p={...u},f={...this.defaults,...p},S=this.onError(!!f.silent,!!f.async);if(this.defaults.async===!0&&p.async===!1)return S(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof c>"u"||c===null)return S(new Error("marked(): input parameter is undefined or null"));if(typeof c!="string")return S(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(c)+", string expected"));f.hooks&&(f.hooks.options=f,f.hooks.block=o);const g=f.hooks?f.hooks.provideLexer():o?at.lex:at.lexInline,k=f.hooks?f.hooks.provideParser():o?tt.parse:tt.parseInline;if(f.async)return Promise.resolve(f.hooks?f.hooks.preprocess(c):c).then(y=>g(y,f)).then(y=>f.hooks?f.hooks.processAllTokens(y):y).then(y=>f.walkTokens?Promise.all(this.walkTokens(y,f.walkTokens)).then(()=>y):y).then(y=>k(y,f)).then(y=>f.hooks?f.hooks.postprocess(y):y).catch(S);try{f.hooks&&(c=f.hooks.preprocess(c));let y=g(c,f);f.hooks&&(y=f.hooks.processAllTokens(y)),f.walkTokens&&this.walkTokens(y,f.walkTokens);let A=k(y,f);return f.hooks&&(A=f.hooks.postprocess(A)),A}catch(y){return S(y)}}}onError(o,s){return c=>{if(c.message+=`
89
- Please report this to https://github.com/markedjs/marked.`,o){const u="<p>An error occurred:</p><pre>"+Oa(c.message+"",!0)+"</pre>";return s?Promise.resolve(u):u}if(s)return Promise.reject(c);throw c}}},Wt=new qy;function oe(o,s){return Wt.parse(o,s)}oe.options=oe.setOptions=function(o){return Wt.setOptions(o),oe.defaults=Wt.defaults,nf(oe.defaults),oe};oe.getDefaults=hu;oe.defaults=$t;oe.use=function(...o){return Wt.use(...o),oe.defaults=Wt.defaults,nf(oe.defaults),oe};oe.walkTokens=function(o,s){return Wt.walkTokens(o,s)};oe.parseInline=Wt.parseInline;oe.Parser=tt;oe.parser=tt.parse;oe.Renderer=Ss;oe.TextRenderer=Tu;oe.Lexer=at;oe.lexer=at.lex;oe.Tokenizer=xs;oe.Hooks=fs;oe.parse=oe;oe.options;oe.setOptions;oe.use;oe.walkTokens;oe.parseInline;tt.parse;at.lex;oe.setOptions({gfm:!0,breaks:!0});function hf({isOpen:o,onClose:s}){const[c,u]=O.useState(""),[p,f]=O.useState(!1),[S,g]=O.useState(""),k=O.useRef(null);return O.useEffect(()=>{!o||c||(f(!0),g(""),fetch(jv.changelogUrl).then(y=>{if(!y.ok)throw new Error(`HTTP ${y.status}`);return y.text()}).then(y=>u(oe.parse(y))).catch(y=>g(y.message||"Failed to load")).finally(()=>f(!1)))},[o,c]),O.useEffect(()=>{const y=A=>{k.current&&!k.current.contains(A.target)&&s()};if(o)return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[o,s]),!o||typeof document>"u"?null:Zp.createPortal(m.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[m.jsx("div",{className:"absolute inset-0 bg-black/30 backdrop-blur-sm",onClick:s}),m.jsxs("div",{ref:k,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-3xl flex flex-col max-h-[85vh]",children:[m.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-black/5 dark:border-white/5",children:[m.jsx("h2",{className:"text-lg font-semibold text-text-main",children:"Change Log"}),m.jsx("button",{onClick:s,className:"p-1.5 rounded-lg text-text-muted hover:bg-black/5 dark:hover:bg-white/5 transition-colors","aria-label":"Close",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),m.jsxs("div",{className:"p-6 overflow-y-auto flex-1",children:[p&&m.jsxs("div",{className:"flex items-center justify-center py-10 text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin mr-2",children:"progress_activity"}),"Loading..."]}),S&&m.jsxs("div",{className:"text-red-500 py-4",children:["Failed to load changelog: ",S]}),!p&&!S&&c&&m.jsx("div",{className:"changelog-body text-text-main",dangerouslySetInnerHTML:{__html:c}})]})]})]}),document.body)}hf.propTypes={isOpen:ye.bool.isRequired,onClose:ye.func.isRequired};function Vi({icon:o,label:s,onClick:c,trailing:u,danger:p}){return m.jsxs("button",{onClick:c,className:`flex items-center gap-3 w-full px-4 py-2.5 text-sm transition-colors ${p?"text-red-500 hover:bg-red-500/10":"text-text-main hover:bg-black/5 dark:hover:bg-white/5"}`,children:[m.jsx("span",{className:`material-symbols-outlined text-[20px] ${p?"":"text-text-muted"}`,children:o}),m.jsx("span",{className:"flex-1 text-left",children:s}),u&&m.jsx("span",{className:"text-base",children:u})]})}Vi.propTypes={icon:ye.string.isRequired,label:ye.string.isRequired,onClick:ye.func.isRequired,trailing:ye.node,danger:ye.bool};function gf({onLogout:o,isLoggedIn:s=!0}){const[c,u]=O.useState(!1),[p,f]=O.useState(!1),[S,g]=O.useState(!1),[k,y]=O.useState(!1),{toggleTheme:A,isDark:L}=tf(),C=O.useRef(null),X=async()=>{y(!0);try{await fetch("/api/version/shutdown",{method:"POST"})}catch{}y(!1),g(!1)};O.useEffect(()=>{const Y=q=>{C.current&&!C.current.contains(q.target)&&u(!1)};if(c)return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[c]);const j=()=>u(!1);return m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"relative",ref:C,children:[m.jsx("button",{onClick:()=>u(Y=>!Y),className:"flex items-center justify-center p-2 rounded-lg text-text-muted hover:text-text-main hover:bg-black/5 dark:hover:bg-white/5 transition-all",title:"Menu",children:m.jsx("span",{className:"material-symbols-outlined",children:"grid_view"})}),c&&m.jsxs("div",{className:"absolute right-0 top-full mt-2 w-60 bg-surface border border-black/10 dark:border-white/10 rounded-xl shadow-2xl z-50 animate-in fade-in zoom-in-95 duration-150 overflow-hidden py-1",children:[m.jsx(Vi,{icon:"history",label:"Change Log",onClick:()=>{j(),f(!0)}}),m.jsx(Vi,{icon:L?"light_mode":"dark_mode",label:"Theme",onClick:()=>{A(),j()}}),s&&m.jsx(Vi,{icon:"power_settings_new",label:"Shutdown",danger:!0,onClick:()=>{j(),g(!0)}}),s?m.jsx(Vi,{icon:"logout",label:"Logout",danger:!0,onClick:()=>{j(),o()}}):m.jsx(Vi,{icon:"login",label:"Login",onClick:()=>{j(),window.location.href="/login?force=true"}})]})]}),m.jsx(hf,{isOpen:p,onClose:()=>f(!1)}),m.jsx($p,{isOpen:S,onClose:()=>g(!1),onConfirm:X,title:"Close Proxy",message:"Are you sure you want to close the proxy server?",confirmText:"Close",cancelText:"Cancel",variant:"danger",loading:k})]})}gf.propTypes={onLogout:ye.func.isRequired,isLoggedIn:ye.bool};function Hy({className:o,variant:s="default"}){const{isDark:c,toggleTheme:u}=tf(),p={default:Ve("flex items-center justify-center size-10 rounded-full","text-text-muted hover:text-text-main","hover:bg-surface-2 transition-colors"),card:Ve("flex items-center justify-center size-11 rounded-full","bg-surface/60 hover:bg-surface","border border-border","backdrop-blur-md shadow-sm hover:shadow-[var(--shadow-warm)]","text-text-muted hover:text-brand-500","transition-all group")};return m.jsx("button",{onClick:u,className:Ve(p[s],o),"aria-label":`Switch to ${c?"light":"dark"} mode`,title:`Switch to ${c?"light":"dark"} mode`,children:m.jsx("span",{className:Ve("material-symbols-outlined text-[22px]",s==="card"&&"transition-transform duration-300 group-hover:rotate-12"),children:c?"light_mode":"dark_mode"})})}const ms=pu(o=>({query:"",placeholder:"",visible:!1,setQuery:s=>o({query:s}),register:(s="Search...")=>o({visible:!0,placeholder:s,query:""}),unregister:()=>o({visible:!1,placeholder:"",query:""})})),a0=["en","vi","zh-CN","zh-TW","ja","pt-BR","pt-PT","ko","es","de","fr","he","ar","ru","pl","cs","nl","tr","uk","tl","id","th","hi","bn","ur","ro","sv","it","el","hu","fi","da","no"],_s="en",Ky="locale";function Qy(o){return o==="zh"||o==="zh-CN"?"zh-CN":o==="en"?"en":o==="vi"?"vi":o==="zh-TW"?"zh-TW":o==="ja"?"ja":o==="pt-BR"?"pt-BR":o==="pt-PT"?"pt-PT":o==="ko"?"ko":o==="es"?"es":o==="de"?"de":o==="fr"?"fr":o==="he"?"he":o==="ar"?"ar":o==="ru"?"ru":o==="pl"?"pl":o==="cs"?"cs":o==="nl"?"nl":o==="tr"?"tr":o==="uk"?"uk":o==="tl"?"tl":o==="id"?"id":o==="th"?"th":o==="hi"?"hi":o==="bn"?"bn":o==="ur"?"ur":o==="ro"?"ro":o==="sv"?"sv":o==="it"?"it":o==="el"?"el":o==="hu"?"hu":o==="fi"?"fi":o==="da"?"da":o==="no"?"no":_s}let hs={},Ts=_s,gs=[];function Xy(){if(typeof document>"u")return _s;const o=document.cookie.split(";").find(c=>c.trim().startsWith(`${Ky}=`)),s=o?decodeURIComponent(o.split("=")[1]):_s;return Qy(s)}async function Iy(o){if(o==="en"){hs={};return}try{hs=await(await fetch(`/i18n/literals/${o}.json`)).json()}catch(s){console.error("Failed to load translations:",s),hs={}}}function vs(o){if(!o||typeof o!="string")return o;const s=o.trim();return!s||Ts==="en"?o:hs[s]||o}function t0(){return Ts}function i0(o){return gs.push(o),()=>{gs=gs.filter(s=>s!==o)}}function Fy(o){var g;if(!o.nodeValue||!o.nodeValue.trim())return;const s=o.parentElement;if(!s)return;let c=s;for(;c;){if(c.hasAttribute&&c.hasAttribute("data-i18n-skip"))return;c=c.parentElement}const u=(g=s.tagName)==null?void 0:g.toLowerCase();if(["script","style","code","pre","colgroup","table","thead","tbody","tfoot","tr","select","datalist","optgroup"].includes(u))return;o._originalText||(o._originalText=o.nodeValue);const f=o._originalText,S=vs(f);S!==o.nodeValue&&(o.nodeValue=S)}function Yy(o){if(!o)return;const s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,null,!1);let c;const u=[];for(;c=s.nextNode();)u.push(c);u.forEach(Fy)}async function n0(){Ts=Xy(),await Iy(Ts),gs.forEach(o=>o()),Yy(document.body)}const Zy=o=>{if(!o)return{title:"",description:"",breadcrumbs:[]};const s=o.match(/\/media-providers\/([^/]+)\/([^/]+)$/);if(s){const p=s[1],f=s[2],S=nu.find(k=>k.id===p),g=Na[f];return{title:(g==null?void 0:g.name)||f,description:"",breadcrumbs:[{label:"Media Providers",href:`/dashboard/media-providers/${p}`},{label:(S==null?void 0:S.label)||p,href:`/dashboard/media-providers/${p}`},{label:(g==null?void 0:g.name)||f,image:f==="codebuddy"||f==="cb"?"/providers/codebuddy.svg":`/providers/${f}.png`}]}}const c=o.match(/\/media-providers\/([^/]+)$/);if(c){const p=c[1],f=nu.find(S=>S.id===p);return{title:(f==null?void 0:f.label)||p,description:`Manage your ${(f==null?void 0:f.label)||p} providers`,icon:(f==null?void 0:f.icon)||"perm_media",breadcrumbs:[]}}const u=o.match(/\/providers\/([^/]+)$/);if(u){const p=u[1],f=Na[p];if(f)return{title:f.name,description:"",breadcrumbs:[{label:"Providers",href:"/dashboard/providers"},{label:f.name,image:f.id==="codebuddy"||f.id==="cb"?"/providers/codebuddy.svg":`/providers/${f.id}.png`}]}}return o.includes("/providers")&&!o.includes("/media-providers")?{title:"Providers",description:"Manage your AI provider connections",icon:"dns",breadcrumbs:[]}:o.includes("/combos")?{title:"Combos",description:"Model combos with fallback",icon:"layers",breadcrumbs:[]}:o.includes("/usage")?{title:"Usage & Analytics",description:"Monitor your API usage, token consumption, and request logs",icon:"bar_chart",breadcrumbs:[]}:o.includes("/auth-files")?{title:"Auth Files",description:"Map provider credentials stored in the local database",icon:"vpn_key",breadcrumbs:[]}:o.includes("/quota")?{title:"Quota Tracker",description:"Track and manage your API quota limits",icon:"data_usage",breadcrumbs:[]}:o.includes("/mitm")?{title:"MITM Proxy",description:"Intercept CLI tool traffic and route through FSRouter",icon:"security",breadcrumbs:[]}:o.includes("/cli-tools")?{title:"CLI Tools",description:"Configure CLI tools",icon:"terminal",breadcrumbs:[]}:o.includes("/proxy-pools")?{title:"Proxy Pools",description:"Manage your proxy pool configurations",icon:"lan",breadcrumbs:[]}:o.includes("/skills")?{title:"Agent Skills",description:"Copy a link and paste to your AI to use FSRouter — no install needed",icon:"extension",breadcrumbs:[]}:o.includes("/endpoint")?{title:"Endpoint",description:"API endpoint configuration",icon:"api",breadcrumbs:[]}:o.includes("/profile")?{title:"Settings",description:"Manage your preferences",icon:"settings",breadcrumbs:[]}:o.includes("/translator")?{title:"Translator",description:"Debug translation flow between formats",icon:"translate",breadcrumbs:[]}:o.includes("/console-log")?{title:"Console Log",description:"Live server console output",icon:"monitor",breadcrumbs:[]}:o==="/dashboard"?{title:"Endpoint",description:"API endpoint configuration",icon:"api",breadcrumbs:[]}:{title:"",description:"",breadcrumbs:[]}};function vf({onMenuClick:o,showMenuButton:s=!0}){const{pathname:c}=mu(),u=Pp(),[p,f]=O.useState(""),[S,g]=O.useState(""),[k,y]=O.useState(!0),A=O.useMemo(()=>Zy(c),[c]),{title:L,description:C,icon:X,breadcrumbs:j}=A;O.useEffect(()=>{let q=!1;async function be(){try{const qe=await fetch("/api/auth/status",{cache:"no-store"});if(!qe.ok)return;const P=await qe.json();q||(f((P==null?void 0:P.displayName)||(P==null?void 0:P.oidcName)||(P==null?void 0:P.oidcEmail)||""),g((P==null?void 0:P.loginMethod)||""),y((P==null?void 0:P.isLoggedIn)!==!1))}catch{q||(f(""),g(""),y(!1))}}return be(),()=>{q=!0}},[]);const Y=async()=>{try{(await fetch("/api/auth/logout",{method:"POST"})).ok&&(localStorage.removeItem("9r_authed"),u("/login?force=true"),u(0))}catch(q){console.error("Failed to logout:",q)}};return m.jsxs("header",{className:"shrink-0 flex items-center justify-between gap-3 px-4 lg:px-8 pt-3 pb-2 border-b border-border-subtle bg-surface/60 backdrop-blur-xl lg:bg-transparent lg:backdrop-blur-none z-20",children:[m.jsx("div",{className:"flex items-center gap-3 lg:hidden shrink-0",children:s&&m.jsx("button",{onClick:o,className:"text-text-main hover:text-primary transition-colors",children:m.jsx("span",{className:"material-symbols-outlined",children:"menu"})})}),m.jsx("div",{className:"flex flex-col min-w-0 flex-1",children:j.length>0?m.jsx("div",{className:"flex items-center gap-2",children:j.map((q,be)=>m.jsxs("div",{className:"flex items-center gap-2",children:[be>0&&m.jsx("span",{className:"material-symbols-outlined text-text-muted text-base",children:"chevron_right"}),q.href?m.jsx(Et,{to:q.href,className:"text-text-muted hover:text-primary transition-colors",children:q.label}):m.jsxs("div",{className:"flex items-center gap-2",children:[q.image&&m.jsx(af,{src:q.image,alt:q.label,size:28,className:"object-contain rounded max-w-[28px] max-h-[28px]",fallbackText:q.label.slice(0,2).toUpperCase()}),m.jsx("h1",{className:"text-base lg:text-2xl font-semibold text-text-main tracking-tight truncate",children:vs(q.label)})]})]},`${q.label}-${q.href||"current"}`))}):L?m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-2",children:[X&&m.jsx("span",{className:"material-symbols-outlined text-primary text-xl lg:text-2xl",children:X}),m.jsx("h1",{className:"text-base lg:text-2xl font-semibold tracking-tight truncate",children:vs(L)})]}),C&&m.jsx("p",{className:"hidden lg:block text-sm text-text-muted truncate",children:vs(C)})]}):null}),m.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[p&&S==="OIDC"&&m.jsxs("div",{className:"hidden sm:flex items-center max-w-[220px] px-3 py-1.5 rounded-full border border-border bg-surface/70 text-xs text-text-muted truncate",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1.5 text-primary",children:"person"}),m.jsx("span",{className:"truncate",children:p}),m.jsx("span",{className:"ml-2 shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary",children:"OIDC"})]}),m.jsx(Py,{}),m.jsxs("a",{href:"https://www.paypal.com/paypalme/fudpay",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 h-8 rounded-lg border border-pink-500/30 bg-pink-500/10 text-pink-600 dark:text-pink-400 hover:bg-pink-500/20 transition-colors text-sm font-medium","aria-label":"Donate",children:[m.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"volunteer_activism"}),m.jsx("span",{className:"hidden sm:inline",children:"Donate"})]}),m.jsx(Hy,{}),m.jsx(gf,{onLogout:Y,isLoggedIn:k})]})]})}function Py(){const o=ms(p=>p.visible),s=ms(p=>p.query),c=ms(p=>p.placeholder),u=ms(p=>p.setQuery);return o?m.jsxs("div",{className:"relative w-[160px] sm:w-[220px]",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2 top-1/2 -translate-y-1/2 text-text-muted text-[16px] pointer-events-none",children:"search"}),m.jsx("input",{type:"text",value:s,onChange:p=>u(p.target.value),placeholder:c,className:"w-full h-8 pl-7 pr-7 rounded-lg border border-border bg-surface/60 text-sm focus:outline-none focus:border-primary/50 transition-colors"}),s&&m.jsx("button",{type:"button",onClick:()=>u(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-text-muted hover:text-text-main p-0.5 rounded","aria-label":"Clear search",children:m.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]}):null}vf.propTypes={onMenuClick:ye.func,showMenuButton:ye.bool};function Jy(o){return o==="success"?{wrapper:"border-green-500/30 bg-green-500/10 text-green-600 dark:text-green-400",icon:"check_circle"}:o==="error"?{wrapper:"border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400",icon:"error"}:o==="warning"?{wrapper:"border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400",icon:"warning"}:{wrapper:"border-blue-500/30 bg-blue-500/10 text-blue-600 dark:text-blue-400",icon:"info"}}function Wy(){const[o,s]=O.useState(!1),[c,u]=O.useState(!1),{pathname:p}=mu(),f=Pp(),S=Cp(k=>k.notifications),g=Cp(k=>k.removeNotification);return O.useEffect(()=>{fetch("/api/settings").then(k=>k.json()).then(k=>{k.isDefaultPassword&&p!=="/dashboard/profile"?u(!0):u(!1)}).catch(()=>{})},[p]),m.jsxs("div",{className:"flex h-screen w-full overflow-hidden bg-bg",children:[m.jsx("div",{className:"fixed top-4 right-4 z-[80] flex w-[min(92vw,380px)] flex-col gap-2",children:S.map(k=>{const y=Jy(k.type);return m.jsx("div",{className:`rounded-lg border px-3 py-2 shadow-lg backdrop-blur-sm ${y.wrapper}`,children:m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx("span",{className:"material-symbols-outlined text-[18px] leading-5",children:y.icon}),m.jsxs("div",{className:"min-w-0 flex-1",children:[k.title?m.jsx("p",{className:"text-xs font-semibold mb-0.5",children:k.title}):null,m.jsx("p",{className:"text-xs whitespace-pre-wrap break-words",children:k.message})]}),k.dismissible?m.jsx("button",{type:"button",onClick:()=>g(k.id),className:"text-current/70 hover:text-current","aria-label":"Dismiss notification",children:m.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})}):null]})},k.id)})}),o&&m.jsx("div",{className:"fixed inset-0 z-40 bg-black/20 lg:hidden",onClick:()=>s(!1)}),m.jsx("div",{className:"hidden lg:flex",children:m.jsx(ou,{})}),m.jsx("div",{className:`fixed inset-y-0 left-0 z-50 transform lg:hidden transition-transform duration-300 ease-in-out ${o?"translate-x-0":"-translate-x-full"}`,children:m.jsx(ou,{onClose:()=>s(!1)})}),m.jsxs("main",{className:"flex flex-col flex-1 h-full min-w-0 relative transition-colors duration-300 isolate",children:[m.jsx("div",{className:"landing-grid absolute inset-0 pointer-events-none -z-10","aria-hidden":"true"}),m.jsx(vf,{onMenuClick:()=>s(!0)},p),m.jsx("div",{className:`flex-1 overflow-y-auto custom-scrollbar ${p==="/dashboard/basic-chat"||p==="/dashboard/docs"?"":"p-6 lg:p-10"} ${p==="/dashboard/basic-chat"||p==="/dashboard/docs"?"flex flex-col overflow-hidden":""}`,children:m.jsx("div",{className:`${p==="/dashboard/basic-chat"||p==="/dashboard/docs"?"flex-1 w-full h-full flex flex-col":"max-w-7xl mx-auto"}`,children:m.jsx(Yg,{})})})]}),c&&m.jsx("div",{className:"fixed inset-0 z-[90] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:m.jsxs("div",{className:"w-full max-w-md rounded-xl bg-surface border border-border-subtle p-6 shadow-2xl flex flex-col gap-4 text-text-main animate-in fade-in zoom-in duration-200",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[m.jsx("div",{className:"size-11 rounded-full bg-red-500/10 text-red-500 flex items-center justify-center flex-shrink-0",children:m.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"warning"})}),m.jsxs("div",{children:[m.jsx("h3",{className:"text-sm font-semibold",children:"Ganti Password Default Anda!"}),m.jsx("p",{className:"text-xs text-text-muted mt-0.5",children:"Password admin saat ini sangat tidak aman."})]})]}),m.jsx("p",{className:"text-xs text-text-muted leading-relaxed",children:'FSRouter mendeteksi bahwa Anda masih menggunakan password default "123456" atau tidak memiliki password pengaman. Harap segera menggantinya di halaman profil untuk melindungi akses dashboard Anda.'}),m.jsxs("div",{className:"flex gap-2 mt-2",children:[m.jsx(Ut,{variant:"secondary",size:"sm",onClick:()=>u(!1),children:"Tutup Sementara"}),m.jsx(Ut,{variant:"primary",size:"sm",className:"flex-1",onClick:()=>{u(!1),f("/dashboard/profile")},children:"Ganti Password Sekarang"})]})]})})]})}ye.node.isRequired;O.lazy(()=>$(()=>import("./page.C0gBvR4O.js"),__vite__mapDeps([0,1,2])));const $y=O.lazy(()=>$(()=>import("./page.CdMmlUEm.js"),__vite__mapDeps([3,1,2]))),eb=O.lazy(()=>$(()=>import("./page.Df9qtrdG.js"),__vite__mapDeps([4,1,2]))),ab=O.lazy(()=>$(()=>import("./page.BbPPdoas.js"),__vite__mapDeps([5,1,6,7,8,9,10,2]))),tb=O.lazy(()=>$(()=>import("./page.B-dzeIUC.js"),__vite__mapDeps([11,1,8,9,10,2]))),ib=O.lazy(()=>$(()=>import("./page.N1x4YL8_.js"),__vite__mapDeps([12,1,8,9,10,2]))),nb=O.lazy(()=>$(()=>import("./page.11hpNKmq.js"),__vite__mapDeps([13,1,8,9,2]))),lb=O.lazy(()=>$(()=>import("./page.CPTtRDxw.js"),__vite__mapDeps([14,1,8,9,10,2]))),sb=O.lazy(()=>$(()=>import("./page.BfmI9KYe.js"),__vite__mapDeps([15,1,10,8,9,2]))),ob=O.lazy(()=>$(()=>import("./page.B3QqvLep.js"),__vite__mapDeps([16,1,8,9,10,2]))),rb=O.lazy(()=>$(()=>import("./page.Dl1apZE2.js"),__vite__mapDeps([17,1,8,9,10,2]))),ub=O.lazy(()=>$(()=>import("./page.HV0w1d5C.js"),__vite__mapDeps([18,1,6,7,8,9,10,2]))),cb=O.lazy(()=>$(()=>import("./page.BdS20a1O.js"),__vite__mapDeps([19,1,8,9,2]))),db=O.lazy(()=>$(()=>import("./page.CvUFZzXr.js"),__vite__mapDeps([20,1,8,9,2]))),mb=O.lazy(()=>$(()=>import("./page.D8Rp8fFR.js"),__vite__mapDeps([21,1,6,8,9,10,22,2]))),pb=O.lazy(()=>$(()=>import("./page.CrP7niA2.js"),__vite__mapDeps([23,1,22,6,8,9,10,2]))),fb=O.lazy(()=>$(()=>import("./page.BFb7yUd8.js"),__vite__mapDeps([24,1,8,9,10,2]))),hb=O.lazy(()=>$(()=>import("./page.C8sLEMa6.js"),__vite__mapDeps([25,1,8,9,2]))),gb=O.lazy(()=>$(()=>import("./page.tE7PpWYW.js"),__vite__mapDeps([26,1,22,8,9,2]))),vb=O.lazy(()=>$(()=>import("./page.CCNsZBXp.js"),__vite__mapDeps([27,1,8,9,2]))),yb=O.lazy(()=>$(()=>import("./page.B-LxsnqU.js"),__vite__mapDeps([28,1,2]))),bb=O.lazy(()=>$(()=>import("./page.P2Ny5veR.js"),__vite__mapDeps([29,8,1,9,2]))),xb=O.lazy(()=>$(()=>import("./page.C6bYizL7.js"),__vite__mapDeps([30,1,8,9,2]))),Sb=O.lazy(()=>$(()=>import("./page.CrBl7f8N.js"),__vite__mapDeps([31,1,8,9,2]))),_b=O.lazy(()=>$(()=>import("./page.uziaGZsT.js"),__vite__mapDeps([32,1,8,9,2]))),Tb=O.lazy(()=>$(()=>import("./page.Ch647dVk.js"),__vite__mapDeps([33,1,8,9,2]))),kb=O.lazy(()=>$(()=>import("./page.B-nBR75u.js"),__vite__mapDeps([34,1,8,9,2]))),wb=O.lazy(()=>$(()=>import("./page.CyUqJPmx.js"),__vite__mapDeps([35,1,8,9,2]))),zb=O.lazy(()=>$(()=>import("./page.CpvXDkQF.js"),__vite__mapDeps([36,1,2]))),Ab=O.lazy(()=>$(()=>import("./page.sUIPWIiF.js"),__vite__mapDeps([37,1,2]))),Mb=O.lazy(()=>$(()=>import("./page.DiL4Gwqe.js"),__vite__mapDeps([38,1,10,2]))),Db=O.lazy(()=>$(()=>import("./page.CF_YSLwP.js"),__vite__mapDeps([39,1,10,2]))),Eb=O.lazy(()=>$(()=>import("./page.Cged1bOZ.js"),__vite__mapDeps([40,1,2]))),Ub=O.lazy(()=>$(()=>import("./page.B8xdkCWA.js"),__vite__mapDeps([41,1,2]))),Cb=O.lazy(()=>$(()=>import("./page.BgGJovOg.js"),__vite__mapDeps([42,1,2]))),Lb=O.lazy(()=>$(()=>import("./page.-lpNgYAw.js"),__vite__mapDeps([43,1,2]))),Ob=O.lazy(()=>$(()=>import("./page.fOOCr18J.js"),__vite__mapDeps([44,1,2])));function Nb({children:o}){const[s,c]=O.useState("checking");return O.useEffect(()=>{let u=!1;const p=new AbortController,f=setTimeout(()=>p.abort(),5e3);return fetch("/api/auth/status",{signal:p.signal,credentials:"include"}).then(S=>S.ok?S.json():Promise.reject()).then(S=>{clearTimeout(f),!u&&(S.requireLogin===!1||S.isLoggedIn===!0?(localStorage.setItem("9r_authed","1"),c("ok")):(localStorage.removeItem("9r_authed"),c("denied")))}).catch(()=>{clearTimeout(f),u||c("denied")}),()=>{u=!0,p.abort()}},[]),s==="checking"?m.jsx(yf,{}):s==="denied"?m.jsx(iu,{to:"/login",replace:!0}):m.jsx(m.Fragment,{children:o})}function yf(){return m.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100vh"},children:m.jsx("span",{children:"Loading..."})})}function Rb(){return m.jsx(Zg,{children:m.jsx(O.Suspense,{fallback:m.jsx(yf,{}),children:m.jsxs(Pg,{children:[m.jsx(Z,{path:"/",element:m.jsx(iu,{to:"/login",replace:!0})}),m.jsx(Z,{path:"/login",element:m.jsx($y,{})}),m.jsx(Z,{path:"/callback",element:m.jsx(eb,{})}),m.jsxs(Z,{path:"/dashboard",element:m.jsx(Nb,{children:m.jsx(Wy,{})}),children:[m.jsx(Z,{index:!0,element:m.jsx(ab,{})}),m.jsx(Z,{path:"providers",element:m.jsx(tb,{})}),m.jsx(Z,{path:"providers/new",element:m.jsx(nb,{})}),m.jsx(Z,{path:"providers/weavy/pool",element:m.jsx(zb,{})}),m.jsx(Z,{path:"providers/:id",element:m.jsx(ib,{})}),m.jsx(Z,{path:"usage",element:m.jsx(lb,{})}),m.jsx(Z,{path:"quota",element:m.jsx(sb,{})}),m.jsx(Z,{path:"proxy-pools",element:m.jsx(ob,{})}),m.jsx(Z,{path:"combos",element:m.jsx(rb,{})}),m.jsx(Z,{path:"endpoint",element:m.jsx(ub,{})}),m.jsx(Z,{path:"token-saver",element:m.jsx(cb,{})}),m.jsx(Z,{path:"translator",element:m.jsx(db,{})}),m.jsx(Z,{path:"cli-tools",element:m.jsx(mb,{})}),m.jsx(Z,{path:"cli-tools/:toolId",element:m.jsx(pb,{})}),m.jsx(Z,{path:"automation",element:m.jsx(fb,{})}),m.jsx(Z,{path:"automation/fsmail-tutorial",element:m.jsx(Ab,{})}),m.jsx(Z,{path:"basic-chat",element:m.jsx(hb,{})}),m.jsx(Z,{path:"mitm",element:m.jsx(gb,{})}),m.jsx(Z,{path:"profile",element:m.jsx(vb,{})}),m.jsx(Z,{path:"docs",element:m.jsx(yb,{})}),m.jsx(Z,{path:"skills",element:m.jsx(bb,{})}),m.jsx(Z,{path:"console-log",element:m.jsx(xb,{})}),m.jsx(Z,{path:"media-providers/web",element:m.jsx(_b,{})}),m.jsx(Z,{path:"media-providers/:kind",element:m.jsx(Tb,{})}),m.jsx(Z,{path:"media-providers/:kind/:id",element:m.jsx(kb,{})}),m.jsx(Z,{path:"media-providers/combo/:id",element:m.jsx(wb,{})}),m.jsx(Z,{path:"search",element:m.jsx(Mb,{})}),m.jsx(Z,{path:"moderations",element:m.jsx(Db,{})}),m.jsx(Z,{path:"rerank",element:m.jsx(Eb,{})}),m.jsx(Z,{path:"ocr",element:m.jsx(Ub,{})}),m.jsx(Z,{path:"webfetch",element:m.jsx(Cb,{})}),m.jsx(Z,{path:"audio",element:m.jsx(Lb,{})}),m.jsx(Z,{path:"update",element:m.jsx(Ob,{})}),m.jsx(Z,{path:"backup-restore",element:m.jsx(Sb,{})})]}),m.jsx(Z,{path:"*",element:m.jsx(iu,{to:"/",replace:!0})})]})})})}const bf=document.getElementById("root");if(!bf)throw new Error("Root element not found");iv.createRoot(bf).render(m.jsx(O.StrictMode,{children:m.jsx(Rb,{})}));export{gv as A,Ut as B,$p as C,n0 as D,Ky as E,pv as F,Qy as G,tf as H,Gv as I,e0 as J,Ib as K,a0 as L,Qv as M,nu as N,hv as O,af as P,Hb as Q,Yb as R,wv as S,Jp as T,Fb as U,Qb as V,vv as W,$ as _,Cp as a,ms as b,fv as c,yv as d,bv as e,ye as f,Na as g,Zb as h,Xb as i,m as j,Vb as k,qb as l,Kb as m,Ve as n,Sv as o,Pb as p,Wb as q,t0 as r,Jb as s,vs as t,Vv as u,i0 as v,Bv as w,Kv as x,$b as y,Rv as z};
89
+ Please report this to https://github.com/markedjs/marked.`,o){const u="<p>An error occurred:</p><pre>"+Oa(c.message+"",!0)+"</pre>";return s?Promise.resolve(u):u}if(s)return Promise.reject(c);throw c}}},Wt=new qy;function oe(o,s){return Wt.parse(o,s)}oe.options=oe.setOptions=function(o){return Wt.setOptions(o),oe.defaults=Wt.defaults,nf(oe.defaults),oe};oe.getDefaults=hu;oe.defaults=$t;oe.use=function(...o){return Wt.use(...o),oe.defaults=Wt.defaults,nf(oe.defaults),oe};oe.walkTokens=function(o,s){return Wt.walkTokens(o,s)};oe.parseInline=Wt.parseInline;oe.Parser=tt;oe.parser=tt.parse;oe.Renderer=Ss;oe.TextRenderer=Tu;oe.Lexer=at;oe.lexer=at.lex;oe.Tokenizer=xs;oe.Hooks=fs;oe.parse=oe;oe.options;oe.setOptions;oe.use;oe.walkTokens;oe.parseInline;tt.parse;at.lex;oe.setOptions({gfm:!0,breaks:!0});function hf({isOpen:o,onClose:s}){const[c,u]=O.useState(""),[p,f]=O.useState(!1),[S,g]=O.useState(""),k=O.useRef(null);return O.useEffect(()=>{!o||c||(f(!0),g(""),fetch(jv.changelogUrl).then(y=>{if(!y.ok)throw new Error(`HTTP ${y.status}`);return y.text()}).then(y=>u(oe.parse(y))).catch(y=>g(y.message||"Failed to load")).finally(()=>f(!1)))},[o,c]),O.useEffect(()=>{const y=A=>{k.current&&!k.current.contains(A.target)&&s()};if(o)return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[o,s]),!o||typeof document>"u"?null:Zp.createPortal(m.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[m.jsx("div",{className:"absolute inset-0 bg-black/30 backdrop-blur-sm",onClick:s}),m.jsxs("div",{ref:k,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-3xl flex flex-col max-h-[85vh]",children:[m.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-black/5 dark:border-white/5",children:[m.jsx("h2",{className:"text-lg font-semibold text-text-main",children:"Change Log"}),m.jsx("button",{onClick:s,className:"p-1.5 rounded-lg text-text-muted hover:bg-black/5 dark:hover:bg-white/5 transition-colors","aria-label":"Close",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),m.jsxs("div",{className:"p-6 overflow-y-auto flex-1",children:[p&&m.jsxs("div",{className:"flex items-center justify-center py-10 text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin mr-2",children:"progress_activity"}),"Loading..."]}),S&&m.jsxs("div",{className:"text-red-500 py-4",children:["Failed to load changelog: ",S]}),!p&&!S&&c&&m.jsx("div",{className:"changelog-body text-text-main",dangerouslySetInnerHTML:{__html:c}})]})]})]}),document.body)}hf.propTypes={isOpen:ye.bool.isRequired,onClose:ye.func.isRequired};function Vi({icon:o,label:s,onClick:c,trailing:u,danger:p}){return m.jsxs("button",{onClick:c,className:`flex items-center gap-3 w-full px-4 py-2.5 text-sm transition-colors ${p?"text-red-500 hover:bg-red-500/10":"text-text-main hover:bg-black/5 dark:hover:bg-white/5"}`,children:[m.jsx("span",{className:`material-symbols-outlined text-[20px] ${p?"":"text-text-muted"}`,children:o}),m.jsx("span",{className:"flex-1 text-left",children:s}),u&&m.jsx("span",{className:"text-base",children:u})]})}Vi.propTypes={icon:ye.string.isRequired,label:ye.string.isRequired,onClick:ye.func.isRequired,trailing:ye.node,danger:ye.bool};function gf({onLogout:o,isLoggedIn:s=!0}){const[c,u]=O.useState(!1),[p,f]=O.useState(!1),[S,g]=O.useState(!1),[k,y]=O.useState(!1),{toggleTheme:A,isDark:L}=tf(),C=O.useRef(null),X=async()=>{y(!0);try{await fetch("/api/version/shutdown",{method:"POST"})}catch{}y(!1),g(!1)};O.useEffect(()=>{const Y=q=>{C.current&&!C.current.contains(q.target)&&u(!1)};if(c)return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[c]);const j=()=>u(!1);return m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"relative",ref:C,children:[m.jsx("button",{onClick:()=>u(Y=>!Y),className:"flex items-center justify-center p-2 rounded-lg text-text-muted hover:text-text-main hover:bg-black/5 dark:hover:bg-white/5 transition-all",title:"Menu",children:m.jsx("span",{className:"material-symbols-outlined",children:"grid_view"})}),c&&m.jsxs("div",{className:"absolute right-0 top-full mt-2 w-60 bg-surface border border-black/10 dark:border-white/10 rounded-xl shadow-2xl z-50 animate-in fade-in zoom-in-95 duration-150 overflow-hidden py-1",children:[m.jsx(Vi,{icon:"history",label:"Change Log",onClick:()=>{j(),f(!0)}}),m.jsx(Vi,{icon:L?"light_mode":"dark_mode",label:"Theme",onClick:()=>{A(),j()}}),s&&m.jsx(Vi,{icon:"power_settings_new",label:"Shutdown",danger:!0,onClick:()=>{j(),g(!0)}}),s?m.jsx(Vi,{icon:"logout",label:"Logout",danger:!0,onClick:()=>{j(),o()}}):m.jsx(Vi,{icon:"login",label:"Login",onClick:()=>{j(),window.location.href="/login?force=true"}})]})]}),m.jsx(hf,{isOpen:p,onClose:()=>f(!1)}),m.jsx($p,{isOpen:S,onClose:()=>g(!1),onConfirm:X,title:"Close Proxy",message:"Are you sure you want to close the proxy server?",confirmText:"Close",cancelText:"Cancel",variant:"danger",loading:k})]})}gf.propTypes={onLogout:ye.func.isRequired,isLoggedIn:ye.bool};function Hy({className:o,variant:s="default"}){const{isDark:c,toggleTheme:u}=tf(),p={default:Ve("flex items-center justify-center size-10 rounded-full","text-text-muted hover:text-text-main","hover:bg-surface-2 transition-colors"),card:Ve("flex items-center justify-center size-11 rounded-full","bg-surface/60 hover:bg-surface","border border-border","backdrop-blur-md shadow-sm hover:shadow-[var(--shadow-warm)]","text-text-muted hover:text-brand-500","transition-all group")};return m.jsx("button",{onClick:u,className:Ve(p[s],o),"aria-label":`Switch to ${c?"light":"dark"} mode`,title:`Switch to ${c?"light":"dark"} mode`,children:m.jsx("span",{className:Ve("material-symbols-outlined text-[22px]",s==="card"&&"transition-transform duration-300 group-hover:rotate-12"),children:c?"light_mode":"dark_mode"})})}const ms=pu(o=>({query:"",placeholder:"",visible:!1,setQuery:s=>o({query:s}),register:(s="Search...")=>o({visible:!0,placeholder:s,query:""}),unregister:()=>o({visible:!1,placeholder:"",query:""})})),a0=["en","vi","zh-CN","zh-TW","ja","pt-BR","pt-PT","ko","es","de","fr","he","ar","ru","pl","cs","nl","tr","uk","tl","id","th","hi","bn","ur","ro","sv","it","el","hu","fi","da","no"],_s="en",Ky="locale";function Qy(o){return o==="zh"||o==="zh-CN"?"zh-CN":o==="en"?"en":o==="vi"?"vi":o==="zh-TW"?"zh-TW":o==="ja"?"ja":o==="pt-BR"?"pt-BR":o==="pt-PT"?"pt-PT":o==="ko"?"ko":o==="es"?"es":o==="de"?"de":o==="fr"?"fr":o==="he"?"he":o==="ar"?"ar":o==="ru"?"ru":o==="pl"?"pl":o==="cs"?"cs":o==="nl"?"nl":o==="tr"?"tr":o==="uk"?"uk":o==="tl"?"tl":o==="id"?"id":o==="th"?"th":o==="hi"?"hi":o==="bn"?"bn":o==="ur"?"ur":o==="ro"?"ro":o==="sv"?"sv":o==="it"?"it":o==="el"?"el":o==="hu"?"hu":o==="fi"?"fi":o==="da"?"da":o==="no"?"no":_s}let hs={},Ts=_s,gs=[];function Xy(){if(typeof document>"u")return _s;const o=document.cookie.split(";").find(c=>c.trim().startsWith(`${Ky}=`)),s=o?decodeURIComponent(o.split("=")[1]):_s;return Qy(s)}async function Iy(o){if(o==="en"){hs={};return}try{hs=await(await fetch(`/i18n/literals/${o}.json`)).json()}catch(s){console.error("Failed to load translations:",s),hs={}}}function vs(o){if(!o||typeof o!="string")return o;const s=o.trim();return!s||Ts==="en"?o:hs[s]||o}function t0(){return Ts}function i0(o){return gs.push(o),()=>{gs=gs.filter(s=>s!==o)}}function Fy(o){var g;if(!o.nodeValue||!o.nodeValue.trim())return;const s=o.parentElement;if(!s)return;let c=s;for(;c;){if(c.hasAttribute&&c.hasAttribute("data-i18n-skip"))return;c=c.parentElement}const u=(g=s.tagName)==null?void 0:g.toLowerCase();if(["script","style","code","pre","colgroup","table","thead","tbody","tfoot","tr","select","datalist","optgroup"].includes(u))return;o._originalText||(o._originalText=o.nodeValue);const f=o._originalText,S=vs(f);S!==o.nodeValue&&(o.nodeValue=S)}function Yy(o){if(!o)return;const s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,null,!1);let c;const u=[];for(;c=s.nextNode();)u.push(c);u.forEach(Fy)}async function n0(){Ts=Xy(),await Iy(Ts),gs.forEach(o=>o()),Yy(document.body)}const Zy=o=>{if(!o)return{title:"",description:"",breadcrumbs:[]};const s=o.match(/\/media-providers\/([^/]+)\/([^/]+)$/);if(s){const p=s[1],f=s[2],S=nu.find(k=>k.id===p),g=Na[f];return{title:(g==null?void 0:g.name)||f,description:"",breadcrumbs:[{label:"Media Providers",href:`/dashboard/media-providers/${p}`},{label:(S==null?void 0:S.label)||p,href:`/dashboard/media-providers/${p}`},{label:(g==null?void 0:g.name)||f,image:f==="codebuddy"||f==="cb"?"/providers/codebuddy.svg":`/providers/${f}.png`}]}}const c=o.match(/\/media-providers\/([^/]+)$/);if(c){const p=c[1],f=nu.find(S=>S.id===p);return{title:(f==null?void 0:f.label)||p,description:`Manage your ${(f==null?void 0:f.label)||p} providers`,icon:(f==null?void 0:f.icon)||"perm_media",breadcrumbs:[]}}const u=o.match(/\/providers\/([^/]+)$/);if(u){const p=u[1],f=Na[p];if(f)return{title:f.name,description:"",breadcrumbs:[{label:"Providers",href:"/dashboard/providers"},{label:f.name,image:f.id==="codebuddy"||f.id==="cb"?"/providers/codebuddy.svg":`/providers/${f.id}.png`}]}}return o.includes("/providers")&&!o.includes("/media-providers")?{title:"Providers",description:"Manage your AI provider connections",icon:"dns",breadcrumbs:[]}:o.includes("/combos")?{title:"Combos",description:"Model combos with fallback",icon:"layers",breadcrumbs:[]}:o.includes("/usage")?{title:"Usage & Analytics",description:"Monitor your API usage, token consumption, and request logs",icon:"bar_chart",breadcrumbs:[]}:o.includes("/auth-files")?{title:"Auth Files",description:"Map provider credentials stored in the local database",icon:"vpn_key",breadcrumbs:[]}:o.includes("/quota")?{title:"Quota Tracker",description:"Track and manage your API quota limits",icon:"data_usage",breadcrumbs:[]}:o.includes("/mitm")?{title:"MITM Proxy",description:"Intercept CLI tool traffic and route through FSRouter",icon:"security",breadcrumbs:[]}:o.includes("/cli-tools")?{title:"CLI Tools",description:"Configure CLI tools",icon:"terminal",breadcrumbs:[]}:o.includes("/proxy-pools")?{title:"Proxy Pools",description:"Manage your proxy pool configurations",icon:"lan",breadcrumbs:[]}:o.includes("/skills")?{title:"Agent Skills",description:"Copy a link and paste to your AI to use FSRouter — no install needed",icon:"extension",breadcrumbs:[]}:o.includes("/endpoint")?{title:"Endpoint",description:"API endpoint configuration",icon:"api",breadcrumbs:[]}:o.includes("/profile")?{title:"Settings",description:"Manage your preferences",icon:"settings",breadcrumbs:[]}:o.includes("/translator")?{title:"Translator",description:"Debug translation flow between formats",icon:"translate",breadcrumbs:[]}:o.includes("/console-log")?{title:"Console Log",description:"Live server console output",icon:"monitor",breadcrumbs:[]}:o==="/dashboard"?{title:"Endpoint",description:"API endpoint configuration",icon:"api",breadcrumbs:[]}:{title:"",description:"",breadcrumbs:[]}};function vf({onMenuClick:o,showMenuButton:s=!0}){const{pathname:c}=mu(),u=Pp(),[p,f]=O.useState(""),[S,g]=O.useState(""),[k,y]=O.useState(!0),A=O.useMemo(()=>Zy(c),[c]),{title:L,description:C,icon:X,breadcrumbs:j}=A;O.useEffect(()=>{let q=!1;async function be(){try{const qe=await fetch("/api/auth/status",{cache:"no-store"});if(!qe.ok)return;const P=await qe.json();q||(f((P==null?void 0:P.displayName)||(P==null?void 0:P.oidcName)||(P==null?void 0:P.oidcEmail)||""),g((P==null?void 0:P.loginMethod)||""),y((P==null?void 0:P.isLoggedIn)!==!1))}catch{q||(f(""),g(""),y(!1))}}return be(),()=>{q=!0}},[]);const Y=async()=>{try{(await fetch("/api/auth/logout",{method:"POST"})).ok&&(localStorage.removeItem("9r_authed"),u("/login?force=true"),u(0))}catch(q){console.error("Failed to logout:",q)}};return m.jsxs("header",{className:"shrink-0 flex items-center justify-between gap-3 px-4 lg:px-8 pt-3 pb-2 border-b border-border-subtle bg-surface/60 backdrop-blur-xl lg:bg-transparent lg:backdrop-blur-none z-20",children:[m.jsx("div",{className:"flex items-center gap-3 lg:hidden shrink-0",children:s&&m.jsx("button",{onClick:o,className:"text-text-main hover:text-primary transition-colors",children:m.jsx("span",{className:"material-symbols-outlined",children:"menu"})})}),m.jsx("div",{className:"flex flex-col min-w-0 flex-1",children:j.length>0?m.jsx("div",{className:"flex items-center gap-2",children:j.map((q,be)=>m.jsxs("div",{className:"flex items-center gap-2",children:[be>0&&m.jsx("span",{className:"material-symbols-outlined text-text-muted text-base",children:"chevron_right"}),q.href?m.jsx(Et,{to:q.href,className:"text-text-muted hover:text-primary transition-colors",children:q.label}):m.jsxs("div",{className:"flex items-center gap-2",children:[q.image&&m.jsx(af,{src:q.image,alt:q.label,size:28,className:"object-contain rounded max-w-[28px] max-h-[28px]",fallbackText:q.label.slice(0,2).toUpperCase()}),m.jsx("h1",{className:"text-base lg:text-2xl font-semibold text-text-main tracking-tight truncate",children:vs(q.label)})]})]},`${q.label}-${q.href||"current"}`))}):L?m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-2",children:[X&&m.jsx("span",{className:"material-symbols-outlined text-primary text-xl lg:text-2xl",children:X}),m.jsx("h1",{className:"text-base lg:text-2xl font-semibold tracking-tight truncate",children:vs(L)})]}),C&&m.jsx("p",{className:"hidden lg:block text-sm text-text-muted truncate",children:vs(C)})]}):null}),m.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[p&&S==="OIDC"&&m.jsxs("div",{className:"hidden sm:flex items-center max-w-[220px] px-3 py-1.5 rounded-full border border-border bg-surface/70 text-xs text-text-muted truncate",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1.5 text-primary",children:"person"}),m.jsx("span",{className:"truncate",children:p}),m.jsx("span",{className:"ml-2 shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary",children:"OIDC"})]}),m.jsx(Py,{}),m.jsxs("a",{href:"https://www.paypal.com/paypalme/fudpay",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 h-8 rounded-lg border border-pink-500/30 bg-pink-500/10 text-pink-600 dark:text-pink-400 hover:bg-pink-500/20 transition-colors text-sm font-medium","aria-label":"Donate",children:[m.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"volunteer_activism"}),m.jsx("span",{className:"hidden sm:inline",children:"Donate"})]}),m.jsx(Hy,{}),m.jsx(gf,{onLogout:Y,isLoggedIn:k})]})]})}function Py(){const o=ms(p=>p.visible),s=ms(p=>p.query),c=ms(p=>p.placeholder),u=ms(p=>p.setQuery);return o?m.jsxs("div",{className:"relative w-[160px] sm:w-[220px]",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2 top-1/2 -translate-y-1/2 text-text-muted text-[16px] pointer-events-none",children:"search"}),m.jsx("input",{type:"text",value:s,onChange:p=>u(p.target.value),placeholder:c,className:"w-full h-8 pl-7 pr-7 rounded-lg border border-border bg-surface/60 text-sm focus:outline-none focus:border-primary/50 transition-colors"}),s&&m.jsx("button",{type:"button",onClick:()=>u(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-text-muted hover:text-text-main p-0.5 rounded","aria-label":"Clear search",children:m.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]}):null}vf.propTypes={onMenuClick:ye.func,showMenuButton:ye.bool};function Jy(o){return o==="success"?{wrapper:"border-green-500/30 bg-green-500/10 text-green-600 dark:text-green-400",icon:"check_circle"}:o==="error"?{wrapper:"border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400",icon:"error"}:o==="warning"?{wrapper:"border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400",icon:"warning"}:{wrapper:"border-blue-500/30 bg-blue-500/10 text-blue-600 dark:text-blue-400",icon:"info"}}function Wy(){const[o,s]=O.useState(!1),[c,u]=O.useState(!1),{pathname:p}=mu(),f=Pp(),S=Cp(k=>k.notifications),g=Cp(k=>k.removeNotification);return O.useEffect(()=>{fetch("/api/settings").then(k=>k.json()).then(k=>{k.isDefaultPassword&&p!=="/dashboard/profile"?u(!0):u(!1)}).catch(()=>{})},[p]),m.jsxs("div",{className:"flex h-screen w-full overflow-hidden bg-bg",children:[m.jsx("div",{className:"fixed top-4 right-4 z-[80] flex w-[min(92vw,380px)] flex-col gap-2",children:S.map(k=>{const y=Jy(k.type);return m.jsx("div",{className:`rounded-lg border px-3 py-2 shadow-lg backdrop-blur-sm ${y.wrapper}`,children:m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx("span",{className:"material-symbols-outlined text-[18px] leading-5",children:y.icon}),m.jsxs("div",{className:"min-w-0 flex-1",children:[k.title?m.jsx("p",{className:"text-xs font-semibold mb-0.5",children:k.title}):null,m.jsx("p",{className:"text-xs whitespace-pre-wrap break-words",children:k.message})]}),k.dismissible?m.jsx("button",{type:"button",onClick:()=>g(k.id),className:"text-current/70 hover:text-current","aria-label":"Dismiss notification",children:m.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})}):null]})},k.id)})}),o&&m.jsx("div",{className:"fixed inset-0 z-40 bg-black/20 lg:hidden",onClick:()=>s(!1)}),m.jsx("div",{className:"hidden lg:flex",children:m.jsx(ou,{})}),m.jsx("div",{className:`fixed inset-y-0 left-0 z-50 transform lg:hidden transition-transform duration-300 ease-in-out ${o?"translate-x-0":"-translate-x-full"}`,children:m.jsx(ou,{onClose:()=>s(!1)})}),m.jsxs("main",{className:"flex flex-col flex-1 h-full min-w-0 relative transition-colors duration-300 isolate",children:[m.jsx("div",{className:"landing-grid absolute inset-0 pointer-events-none -z-10","aria-hidden":"true"}),m.jsx(vf,{onMenuClick:()=>s(!0)},p),m.jsx("div",{className:`flex-1 overflow-y-auto custom-scrollbar ${p==="/dashboard/basic-chat"||p==="/dashboard/docs"?"":"p-6 lg:p-10"} ${p==="/dashboard/basic-chat"||p==="/dashboard/docs"?"flex flex-col overflow-hidden":""}`,children:m.jsx("div",{className:`${p==="/dashboard/basic-chat"||p==="/dashboard/docs"?"flex-1 w-full h-full flex flex-col":"max-w-7xl mx-auto"}`,children:m.jsx(Yg,{})})})]}),c&&m.jsx("div",{className:"fixed inset-0 z-[90] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:m.jsxs("div",{className:"w-full max-w-md rounded-xl bg-surface border border-border-subtle p-6 shadow-2xl flex flex-col gap-4 text-text-main animate-in fade-in zoom-in duration-200",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[m.jsx("div",{className:"size-11 rounded-full bg-red-500/10 text-red-500 flex items-center justify-center flex-shrink-0",children:m.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"warning"})}),m.jsxs("div",{children:[m.jsx("h3",{className:"text-sm font-semibold",children:"Ganti Password Default Anda!"}),m.jsx("p",{className:"text-xs text-text-muted mt-0.5",children:"Password admin saat ini sangat tidak aman."})]})]}),m.jsx("p",{className:"text-xs text-text-muted leading-relaxed",children:'FSRouter mendeteksi bahwa Anda masih menggunakan password default "123456" atau tidak memiliki password pengaman. Harap segera menggantinya di halaman profil untuk melindungi akses dashboard Anda.'}),m.jsxs("div",{className:"flex gap-2 mt-2",children:[m.jsx(Ut,{variant:"secondary",size:"sm",onClick:()=>u(!1),children:"Tutup Sementara"}),m.jsx(Ut,{variant:"primary",size:"sm",className:"flex-1",onClick:()=>{u(!1),f("/dashboard/profile")},children:"Ganti Password Sekarang"})]})]})})]})}ye.node.isRequired;O.lazy(()=>$(()=>import("./page.DINPUA6N.js"),__vite__mapDeps([0,1,2])));const $y=O.lazy(()=>$(()=>import("./page.t4nKFefI.js"),__vite__mapDeps([3,1,2]))),eb=O.lazy(()=>$(()=>import("./page.Bfr4417O.js"),__vite__mapDeps([4,1,2]))),ab=O.lazy(()=>$(()=>import("./page.cAR8tR7Z.js"),__vite__mapDeps([5,1,6,7,8,9,10,2]))),tb=O.lazy(()=>$(()=>import("./page.A4gD6oiw.js"),__vite__mapDeps([11,1,8,9,10,2]))),ib=O.lazy(()=>$(()=>import("./page.BpcyRUKz.js"),__vite__mapDeps([12,1,8,9,10,2]))),nb=O.lazy(()=>$(()=>import("./page.B5nk3H0f.js"),__vite__mapDeps([13,1,8,9,2]))),lb=O.lazy(()=>$(()=>import("./page.UoGOSKkx.js"),__vite__mapDeps([14,1,8,9,10,2]))),sb=O.lazy(()=>$(()=>import("./page.feKgaG20.js"),__vite__mapDeps([15,1,10,8,9,2]))),ob=O.lazy(()=>$(()=>import("./page.1numFcXc.js"),__vite__mapDeps([16,1,8,9,10,2]))),rb=O.lazy(()=>$(()=>import("./page.BdB6udZG.js"),__vite__mapDeps([17,1,8,9,10,2]))),ub=O.lazy(()=>$(()=>import("./page.CR7Yees9.js"),__vite__mapDeps([18,1,6,7,8,9,10,2]))),cb=O.lazy(()=>$(()=>import("./page.DSEK9UW0.js"),__vite__mapDeps([19,1,8,9,2]))),db=O.lazy(()=>$(()=>import("./page.Dr6yAoTO.js"),__vite__mapDeps([20,1,8,9,2]))),mb=O.lazy(()=>$(()=>import("./page.DcmbyZGV.js"),__vite__mapDeps([21,1,6,8,9,10,22,2]))),pb=O.lazy(()=>$(()=>import("./page.GhgvWftU.js"),__vite__mapDeps([23,1,22,6,8,9,10,2]))),fb=O.lazy(()=>$(()=>import("./page.B1og8_GD.js"),__vite__mapDeps([24,1,8,9,10,2]))),hb=O.lazy(()=>$(()=>import("./page.1w9bTOPd.js"),__vite__mapDeps([25,1,8,9,2]))),gb=O.lazy(()=>$(()=>import("./page.3ARdH6tE.js"),__vite__mapDeps([26,1,22,8,9,2]))),vb=O.lazy(()=>$(()=>import("./page.FR_Izkgi.js"),__vite__mapDeps([27,1,8,9,2]))),yb=O.lazy(()=>$(()=>import("./page.C6WsIDgW.js"),__vite__mapDeps([28,1,2]))),bb=O.lazy(()=>$(()=>import("./page.CCEJ5tPH.js"),__vite__mapDeps([29,8,1,9,2]))),xb=O.lazy(()=>$(()=>import("./page.AhxgKhsm.js"),__vite__mapDeps([30,1,8,9,2]))),Sb=O.lazy(()=>$(()=>import("./page.DSTzvOQ8.js"),__vite__mapDeps([31,1,8,9,2]))),_b=O.lazy(()=>$(()=>import("./page.BJIIZWfZ.js"),__vite__mapDeps([32,1,8,9,2]))),Tb=O.lazy(()=>$(()=>import("./page.DU7jwIPk.js"),__vite__mapDeps([33,1,8,9,2]))),kb=O.lazy(()=>$(()=>import("./page.CXCEdPh6.js"),__vite__mapDeps([34,1,8,9,2]))),wb=O.lazy(()=>$(()=>import("./page.BvcbHe5b.js"),__vite__mapDeps([35,1,8,9,2]))),zb=O.lazy(()=>$(()=>import("./page.DT_RnrSs.js"),__vite__mapDeps([36,1,2]))),Ab=O.lazy(()=>$(()=>import("./page.BfGkHTDS.js"),__vite__mapDeps([37,1,2]))),Mb=O.lazy(()=>$(()=>import("./page.0Rt4rWPG.js"),__vite__mapDeps([38,1,10,2]))),Db=O.lazy(()=>$(()=>import("./page.CtLa-V_T.js"),__vite__mapDeps([39,1,10,2]))),Eb=O.lazy(()=>$(()=>import("./page.CMUifPIU.js"),__vite__mapDeps([40,1,2]))),Ub=O.lazy(()=>$(()=>import("./page.CsroRewc.js"),__vite__mapDeps([41,1,2]))),Cb=O.lazy(()=>$(()=>import("./page.BGDrqCcI.js"),__vite__mapDeps([42,1,2]))),Lb=O.lazy(()=>$(()=>import("./page.DjguJpCk.js"),__vite__mapDeps([43,1,2]))),Ob=O.lazy(()=>$(()=>import("./page.DT7cpJ8d.js"),__vite__mapDeps([44,1,2])));function Nb({children:o}){const[s,c]=O.useState("checking");return O.useEffect(()=>{let u=!1;const p=new AbortController,f=setTimeout(()=>p.abort(),5e3);return fetch("/api/auth/status",{signal:p.signal,credentials:"include"}).then(S=>S.ok?S.json():Promise.reject()).then(S=>{clearTimeout(f),!u&&(S.requireLogin===!1||S.isLoggedIn===!0?(localStorage.setItem("9r_authed","1"),c("ok")):(localStorage.removeItem("9r_authed"),c("denied")))}).catch(()=>{clearTimeout(f),u||c("denied")}),()=>{u=!0,p.abort()}},[]),s==="checking"?m.jsx(yf,{}):s==="denied"?m.jsx(iu,{to:"/login",replace:!0}):m.jsx(m.Fragment,{children:o})}function yf(){return m.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100vh"},children:m.jsx("span",{children:"Loading..."})})}function Rb(){return m.jsx(Zg,{children:m.jsx(O.Suspense,{fallback:m.jsx(yf,{}),children:m.jsxs(Pg,{children:[m.jsx(Z,{path:"/",element:m.jsx(iu,{to:"/login",replace:!0})}),m.jsx(Z,{path:"/login",element:m.jsx($y,{})}),m.jsx(Z,{path:"/callback",element:m.jsx(eb,{})}),m.jsxs(Z,{path:"/dashboard",element:m.jsx(Nb,{children:m.jsx(Wy,{})}),children:[m.jsx(Z,{index:!0,element:m.jsx(ab,{})}),m.jsx(Z,{path:"providers",element:m.jsx(tb,{})}),m.jsx(Z,{path:"providers/new",element:m.jsx(nb,{})}),m.jsx(Z,{path:"providers/weavy/pool",element:m.jsx(zb,{})}),m.jsx(Z,{path:"providers/:id",element:m.jsx(ib,{})}),m.jsx(Z,{path:"usage",element:m.jsx(lb,{})}),m.jsx(Z,{path:"quota",element:m.jsx(sb,{})}),m.jsx(Z,{path:"proxy-pools",element:m.jsx(ob,{})}),m.jsx(Z,{path:"combos",element:m.jsx(rb,{})}),m.jsx(Z,{path:"endpoint",element:m.jsx(ub,{})}),m.jsx(Z,{path:"token-saver",element:m.jsx(cb,{})}),m.jsx(Z,{path:"translator",element:m.jsx(db,{})}),m.jsx(Z,{path:"cli-tools",element:m.jsx(mb,{})}),m.jsx(Z,{path:"cli-tools/:toolId",element:m.jsx(pb,{})}),m.jsx(Z,{path:"automation",element:m.jsx(fb,{})}),m.jsx(Z,{path:"automation/fsmail-tutorial",element:m.jsx(Ab,{})}),m.jsx(Z,{path:"basic-chat",element:m.jsx(hb,{})}),m.jsx(Z,{path:"mitm",element:m.jsx(gb,{})}),m.jsx(Z,{path:"profile",element:m.jsx(vb,{})}),m.jsx(Z,{path:"docs",element:m.jsx(yb,{})}),m.jsx(Z,{path:"skills",element:m.jsx(bb,{})}),m.jsx(Z,{path:"console-log",element:m.jsx(xb,{})}),m.jsx(Z,{path:"media-providers/web",element:m.jsx(_b,{})}),m.jsx(Z,{path:"media-providers/:kind",element:m.jsx(Tb,{})}),m.jsx(Z,{path:"media-providers/:kind/:id",element:m.jsx(kb,{})}),m.jsx(Z,{path:"media-providers/combo/:id",element:m.jsx(wb,{})}),m.jsx(Z,{path:"search",element:m.jsx(Mb,{})}),m.jsx(Z,{path:"moderations",element:m.jsx(Db,{})}),m.jsx(Z,{path:"rerank",element:m.jsx(Eb,{})}),m.jsx(Z,{path:"ocr",element:m.jsx(Ub,{})}),m.jsx(Z,{path:"webfetch",element:m.jsx(Cb,{})}),m.jsx(Z,{path:"audio",element:m.jsx(Lb,{})}),m.jsx(Z,{path:"update",element:m.jsx(Ob,{})}),m.jsx(Z,{path:"backup-restore",element:m.jsx(Sb,{})})]}),m.jsx(Z,{path:"*",element:m.jsx(iu,{to:"/",replace:!0})})]})})})}const bf=document.getElementById("root");if(!bf)throw new Error("Root element not found");iv.createRoot(bf).render(m.jsx(O.StrictMode,{children:m.jsx(Rb,{})}));export{gv as A,Ut as B,$p as C,n0 as D,Ky as E,pv as F,Qy as G,tf as H,Gv as I,e0 as J,Ib as K,a0 as L,Qv as M,nu as N,hv as O,af as P,Hb as Q,Yb as R,wv as S,Jp as T,Fb as U,Qb as V,vv as W,$ as _,Cp as a,ms as b,fv as c,yv as d,bv as e,ye as f,Na as g,Zb as h,Xb as i,m as j,Vb as k,qb as l,Kb as m,Ve as n,Sv as o,Pb as p,Wb as q,t0 as r,Jb as s,vs as t,Vv as u,i0 as v,Bv as w,Kv as x,$b as y,Rv as z};
@@ -1 +1 @@
1
- import{j as e}from"./index.Be3gbrBl.js";import{b as r}from"./router.Cjj1--8t.js";import{C as j}from"./Loading.BHPtQ9vj.js";import"./zustand.akaTi5uX.js";function P(){return e.jsx(r.Suspense,{fallback:e.jsx(j,{}),children:e.jsx(y,{})})}function y(){const[a,h]=r.useState([]),[p,b]=r.useState(!0),[s,f]=r.useState(""),[o,n]=r.useState(null),[i,d]=r.useState(!1),[l,c]=r.useState(""),[x,m]=r.useState(null);r.useEffect(()=>{fetch("/api/media-providers/webSearch").then(t=>t.json()).then(t=>{h(Array.isArray(t)?t:[]),t.length>0&&c(t[0].id)}).catch(()=>{}).finally(()=>b(!1))},[]);const u=async()=>{if(s.trim()){d(!0),m(null),n(null);try{const t=await fetch("/api/media/webSearch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:s,providerId:l||void 0})});if(!t.ok)throw new Error(`HTTP ${t.status}`);const g=await t.json();n(g)}catch(t){m(t.message)}finally{d(!1)}}};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"search"}),e.jsx("h1",{className:"text-xl font-semibold text-text-main",children:"Search"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Search Providers"}),p?e.jsx("p",{className:"text-xs text-text-muted",children:"Loading providers..."}):a.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:"No search providers configured. Add one in Media Providers."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(t=>e.jsx("button",{onClick:()=>c(t.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors cursor-pointer ${l===t.id?"bg-primary/10 text-primary border border-primary/30":"bg-surface-2 text-text-muted hover:text-text-main border border-transparent"}`,children:t.name||t.id},t.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Test Search"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:t=>f(t.target.value),onKeyDown:t=>t.key==="Enter"&&u(),placeholder:"Enter search query...",className:"flex-1 rounded-lg border border-border-subtle bg-surface-2 px-3 py-2 text-sm text-text-main placeholder:text-text-muted/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsx("button",{onClick:u,disabled:i||!s.trim(),className:"px-4 py-2 rounded-lg bg-primary text-white text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer",children:i?"Searching...":"Search"})]})]}),x&&e.jsx("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-4",children:e.jsx("p",{className:"text-sm text-red-400",children:x})}),o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Results"}),e.jsx("pre",{className:"text-xs text-text-muted overflow-auto max-h-96 bg-surface-2 rounded-lg p-3 font-mono whitespace-pre-wrap",children:JSON.stringify(o,null,2)})]})]})}export{P as default};
1
+ import{j as e}from"./index.D4FwOBBU.js";import{b as r}from"./router.Cjj1--8t.js";import{C as j}from"./Loading.C1il44u0.js";import"./zustand.akaTi5uX.js";function P(){return e.jsx(r.Suspense,{fallback:e.jsx(j,{}),children:e.jsx(y,{})})}function y(){const[a,h]=r.useState([]),[p,b]=r.useState(!0),[s,f]=r.useState(""),[o,n]=r.useState(null),[i,d]=r.useState(!1),[l,c]=r.useState(""),[x,m]=r.useState(null);r.useEffect(()=>{fetch("/api/media-providers/webSearch").then(t=>t.json()).then(t=>{h(Array.isArray(t)?t:[]),t.length>0&&c(t[0].id)}).catch(()=>{}).finally(()=>b(!1))},[]);const u=async()=>{if(s.trim()){d(!0),m(null),n(null);try{const t=await fetch("/api/media/webSearch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:s,providerId:l||void 0})});if(!t.ok)throw new Error(`HTTP ${t.status}`);const g=await t.json();n(g)}catch(t){m(t.message)}finally{d(!1)}}};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"search"}),e.jsx("h1",{className:"text-xl font-semibold text-text-main",children:"Search"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Search Providers"}),p?e.jsx("p",{className:"text-xs text-text-muted",children:"Loading providers..."}):a.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:"No search providers configured. Add one in Media Providers."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(t=>e.jsx("button",{onClick:()=>c(t.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors cursor-pointer ${l===t.id?"bg-primary/10 text-primary border border-primary/30":"bg-surface-2 text-text-muted hover:text-text-main border border-transparent"}`,children:t.name||t.id},t.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Test Search"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:t=>f(t.target.value),onKeyDown:t=>t.key==="Enter"&&u(),placeholder:"Enter search query...",className:"flex-1 rounded-lg border border-border-subtle bg-surface-2 px-3 py-2 text-sm text-text-main placeholder:text-text-muted/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsx("button",{onClick:u,disabled:i||!s.trim(),className:"px-4 py-2 rounded-lg bg-primary text-white text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer",children:i?"Searching...":"Search"})]})]}),x&&e.jsx("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-4",children:e.jsx("p",{className:"text-sm text-red-400",children:x})}),o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Results"}),e.jsx("pre",{className:"text-xs text-text-muted overflow-auto max-h-96 bg-surface-2 rounded-lg p-3 font-mono whitespace-pre-wrap",children:JSON.stringify(o,null,2)})]})]})}export{P as default};
@@ -1,4 +1,4 @@
1
- import{a as ot,j as e,B as i,M as I,C as lt}from"./index.Be3gbrBl.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.BDcXaWvM.js";import{C as Se}from"./Loading.BHPtQ9vj.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}.
1
+ import{a as ot,j as e,B as i,M as I,C as lt}from"./index.D4FwOBBU.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.WHGGEUIp.js";import{C as Se}from"./Loading.C1il44u0.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
2
 
3
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
4
  ${r.join(`