mapigate 0.5.141 → 0.5.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/core/capabilities/index.js +5 -4
- package/dist/providers/catalog/coarena/index.js +3 -0
- package/dist/providers/catalog/coarena/metadata.js +104 -0
- package/dist/providers/catalog/coarena/provider.js +91 -0
- package/dist/providers/catalog/coarena/quota.js +119 -0
- package/dist/providers/generated/chunks/chunk1.js +2 -2
- package/dist/providers/generated/chunks/chunk2.js +2 -2
- package/dist/providers/generated/chunks/chunk3.js +2 -2
- package/dist/providers/generated/chunks/chunk4.js +2 -0
- package/dist/providers/generated/runtime/chunk1.js +2 -2
- package/dist/providers/generated/runtime/chunk2.js +2 -2
- package/dist/providers/generated/runtime/chunk3.js +2 -2
- package/dist/providers/generated/runtime/chunk4.js +2 -0
- package/dist/providers/runtime/trae/index.js +1 -0
- package/dist/providers/runtime/trae/metadata.js +1 -0
- package/dist/providers/runtime/trae/provider.js +7 -0
- package/dist/providers/runtime/trae/quota.js +99 -0
- package/dist/providers/runtime/zed/metadata.js +1 -1
- package/dist/providers/runtime/zed/models.js +68 -8
- package/dist/providers/runtime/zed/provider.js +60 -15
- package/dist/providers/runtime/zed/quota.js +69 -12
- package/dist/providers/runtime/zed/routes.js +7 -0
- package/dist/shared/constants/quotaOrder.js +5 -0
- package/dist/web/assets/{CliToolsTab-rKSWLJC3.js → CliToolsTab-BYO-wJ7y.js} +1 -1
- package/dist/web/assets/CombosTab-CujUAbYQ.js +1 -0
- package/dist/web/assets/{ConfirmModal-OWeauwYv.js → ConfirmModal-BS3mAUd5.js} +1 -1
- package/dist/web/assets/{ConsoleLogTab-rZe8zCb_.js → ConsoleLogTab-CSgZxPGW.js} +1 -1
- package/dist/web/assets/{EditAccountModal-CAg-yIOn.js → EditAccountModal-BhPOk3Ya.js} +1 -1
- package/dist/web/assets/{EndpointTab-B-Jb4wAG.js → EndpointTab-BRVjAng2.js} +1 -1
- package/dist/web/assets/{MitmTab-5dKeNi4T.js → MitmTab-ZOoWyRnb.js} +1 -1
- package/dist/web/assets/{ModelAutocompleteInput-CoinzdsW.js → ModelAutocompleteInput-DJkxW2yD.js} +1 -1
- package/dist/web/assets/{ProviderDetailPage-D-fodBhz.js → ProviderDetailPage-CnWjM-0J.js} +1 -1
- package/dist/web/assets/{ProvidersTab-yzmb4w0D.js → ProvidersTab-BFdg0gXr.js} +1 -1
- package/dist/web/assets/QuotaTab-DXg3adeS.js +1 -0
- package/dist/web/assets/{SettingsTab-LkByv4Sg.js → SettingsTab-DoYGKtDn.js} +1 -1
- package/dist/web/assets/{UsageTab-Hr8XPZD4.js → UsageTab-O6OK0i38.js} +1 -1
- package/dist/web/assets/{index-CKuvklEr.js → index-5TzViNxR.js} +2 -2
- package/dist/web/assets/metadataRegistry-W75_wn57.js +1 -0
- package/dist/web/assets/providers/coarena/icon.png +0 -0
- package/dist/web/assets/providers/coarena/icon.svg +3 -0
- package/dist/web/assets/{providersData-DS1-ETBi.js → providersData-BI_7MaUL.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/CombosTab-D1_cfssh.js +0 -1
- package/dist/web/assets/QuotaTab-BXevQzen.js +0 -1
- package/dist/web/assets/metadataRegistry-NuDSSkP9.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProvidersTab-
|
|
2
|
-
import{d as A,j as e,r as m,a as J,e as Y,R as X}from"./vendor-BcOI2aZ9.js";import{G as H}from"./lucide-Cc35htxl.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))t(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&t(l)}).observe(document,{childList:!0,subtree:!0});function s(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function t(n){if(n.ep)return;n.ep=!0;const o=s(n);fetch(n.href,o)}})();const Z="modulepreload",ee=function(a){return"/"+a},z={},y=function(r,s,t){let n=Promise.resolve();if(s&&s.length>0){let l=function(i){return Promise.all(i.map(c=>Promise.resolve(c).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const x=document.querySelector("meta[property=csp-nonce]"),d=(x==null?void 0:x.nonce)||(x==null?void 0:x.getAttribute("nonce"));n=l(s.map(i=>{if(i=ee(i),i in z)return;z[i]=!0;const c=i.endsWith(".css"),p=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${i}"]${p}`))return;const h=document.createElement("link");if(h.rel=c?"stylesheet":Z,c||(h.as="script"),h.crossOrigin="",h.href=i,d&&h.setAttribute("nonce",d),document.head.appendChild(h),c)return new Promise((u,b)=>{h.addEventListener("load",u),h.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${i}`)))})}))}function o(l){const x=new Event("vite:preloadError",{cancelable:!0});if(x.payload=l,window.dispatchEvent(x),!x.defaultPrevented)throw l}return n.then(l=>{for(const x of l||[])x.status==="rejected"&&o(x.reason);return r().catch(o)})},T=20128,R="127.0.0.1",te=`http://${R}:${T}`,Se=`${te}/v1`,_=A(a=>({info:null,loading:!1,fetchSystemInfo:async()=>{try{a({loading:!0});const r=await fetch("/api/settings/system-info");if(r.ok){const s=await r.json(),t=typeof window<"u"&&window.location.port?Number(window.location.port):void 0,n=s.port||(t&&t!==5173?t:T),o=s.host||(typeof window<"u"&&window.location.hostname?window.location.hostname:R),l={dataDir:s.dataDir||"",dbPath:s.dbPath||"",isDevelopmentMode:!!s.isDevelopmentMode,appName:s.appName||"Mapigate",version:s.version||"",port:n,host:o,configuredHost:s.configuredHost||o,configuredPort:s.configuredPort||n,isRestartRequired:!!s.isRestartRequired};return a({info:l,loading:!1}),(async()=>{try{const x=await fetch("/api/settings/version");if(x.ok){const d=await x.json();a(i=>i.info?{...i,info:{...i.info,latestVersion:d.latestVersion,hasUpdate:!!d.hasUpdate}}:i)}}catch{}})(),l}}catch{}return a({loading:!1}),null},checkForUpdate:async()=>{try{const r=await fetch("/api/settings/version?force=true");if(r.ok){const s=await r.json();a(t=>t.info?{...t,info:{...t.info,latestVersion:s.latestVersion,hasUpdate:!!s.hasUpdate}}:t)}}catch{}}})),se=({currentTab:a,onSelectTab:r,onUpgradeClick:s})=>{const t=_(d=>d.info),n=t==null?void 0:t.version,o=(t==null?void 0:t.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):T),l=(t==null?void 0:t.host)||(typeof window<"u"&&window.location.hostname?window.location.hostname:R),x=[{id:"endpoint",label:"Endpoint & Key",icon:"api"},{id:"providers",label:"Providers",icon:"dns"},{id:"combos",label:"Combo & Vision Adapter",icon:"layers"},{id:"usage",label:"Usage & Analytics",icon:"bar_chart"},{id:"quota",label:"Quota Tracker",icon:"data_usage"},{id:"tokensaver",label:"Token Saver",icon:"savings"},{id:"clitools",label:"Tools & Mappings",icon:"widgets"},{id:"mitm",label:"MITM Proxy",icon:"alt_route"}];return e.jsxs("aside",{className:"rt-sidebar",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"rt-sidebar__brand pt-5 pr-4 flex items-center gap-3",children:[e.jsx("div",{className:"rt-sidebar__brand-icon shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"graph_5"})}),e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h1",{className:"text-sm font-bold tracking-tight text-white leading-none truncate",children:"Mapigate"}),n&&(t!=null&&t.hasUpdate&&t.latestVersion?e.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s(),className:"group relative inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-300 border border-amber-500/35 font-mono font-semibold shrink-0 select-none leading-none hover:bg-amber-500/25 transition-all cursor-pointer",title:`New version v${t.latestVersion} available! Click to upgrade`,children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-500"})]}),e.jsxs("span",{children:["v",n]}),e.jsx("span",{className:"text-[9px] text-amber-400 group-hover:translate-y-[-0.5px] transition-transform",children:"↑"})]}):e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md bg-blue-500/15 text-blue-300 border border-blue-500/30 font-mono font-semibold shrink-0 shadow-xs select-none leading-none",title:`Mapigate Version v${n}`,children:["v",n]}))]}),e.jsx("span",{className:"text-[11px] text-slate-400 leading-normal mt-1 truncate",children:"AI Model API Gateway"})]})]}),e.jsx("nav",{className:"px-3 pt-3 space-y-1",children:x.map(d=>{const i=a===d.id;return e.jsxs("button",{onClick:()=>r(d.id),className:`rt-sidebar__nav-item ${i?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:d.icon}),e.jsx("span",{children:d.label})]},d.id)})}),e.jsx("div",{className:"px-5 pt-6 pb-2",children:e.jsx("span",{className:"text-[10px] font-bold text-slate-500 tracking-wider uppercase",children:"SYSTEM PREFERENCES"})}),e.jsxs("nav",{className:"px-3 space-y-1",children:[e.jsxs("button",{onClick:()=>r("consolelog"),className:`rt-sidebar__nav-item ${a==="consolelog"?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"terminal"}),e.jsx("span",{children:"Console Log"})]}),e.jsxs("button",{onClick:()=>r("settings"),className:`rt-sidebar__nav-item ${a==="settings"?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"tune"}),e.jsx("span",{children:"Settings"})]})]})]}),e.jsxs("div",{className:"p-4 border-t border-[#1E293B] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-400 bg-[#111827] px-3.5 py-2.5 rounded-xl border border-[#1E293B] shadow-inner",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rt-beacon size-2 bg-emerald-400"}),e.jsxs("span",{className:"font-semibold text-slate-200",children:["Port ",o]})]}),e.jsx("span",{className:"text-[10px] text-blue-300 font-mono bg-blue-500/10 px-1.5 py-0.5 rounded border border-blue-500/20",children:l})]}),e.jsxs("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",title:"Mapigate on GitHub (joutvhu/mapigate)",className:"flex items-center justify-center gap-2 w-full py-1.5 px-3 rounded-xl bg-[#111827]/60 hover:bg-white/5 border border-[#1E293B]/60 hover:border-[#1E293B] text-[11px] font-medium text-slate-400 hover:text-white transition-all cursor-pointer",children:[e.jsx(H,{className:"size-3.5 text-slate-400"}),e.jsx("span",{children:"GitHub · joutvhu/mapigate"})]})]})]})},E="mapigate_auth_token";let $=!1;const P=new Set;function ae(a){return P.add(a),()=>{P.delete(a)}}function q(){for(const a of P)try{a()}catch{}}class w{static getToken(){if(typeof window>"u")return null;try{return localStorage.getItem(E)}catch{return null}}static setToken(r){if(!(typeof window>"u"))try{localStorage.setItem(E,r)}catch{}}static removeToken(){if(!(typeof window>"u"))try{localStorage.removeItem(E)}catch{}}static async checkStatus(){try{const r=this.getToken(),s={};r&&(s.Authorization=`Bearer ${r}`);const t=await fetch("/api/auth/status",{headers:s});if(!t.ok)return{enabled:!1,authenticated:!0};const n=await t.json();return{enabled:!!n.enabled,authenticated:!!n.authenticated}}catch{return{enabled:!1,authenticated:!0}}}static async login(r){try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r})}),t=await s.json();return s.ok&&t.success?(t.token&&this.setToken(t.token),{success:!0,token:t.token}):{success:!1,error:t.error||"Invalid master password"}}catch(s){return{success:!1,error:s.message||"Failed to authenticate"}}}static async logout(){try{await fetch("/api/auth/logout",{method:"POST"})}catch{}this.removeToken(),q()}static async setup(r){try{const s=await fetch("/api/auth/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r})}),t=await s.json();return s.ok&&t.success?(t.token&&this.setToken(t.token),{success:!0,token:t.token}):{success:!1,error:t.error||"Failed to setup master password"}}catch(s){return{success:!1,error:s.message||"Failed to setup master password"}}}static async changePassword(r,s){try{const t=await fetch("/api/auth/change-password",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:r,newPassword:s})}),n=await t.json();return t.ok&&n.success?(n.token&&this.setToken(n.token),{success:!0,token:n.token}):{success:!1,error:n.error||"Failed to change master password"}}catch(t){return{success:!1,error:t.message||"Failed to change master password"}}}static async removePassword(r){try{const s=await fetch("/api/auth/remove-password",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:r})}),t=await s.json();return s.ok&&t.success?(this.removeToken(),{success:!0}):{success:!1,error:t.error||"Failed to remove master password"}}catch(s){return{success:!1,error:s.message||"Failed to remove master password"}}}}function re(){if(typeof window>"u"||$)return;$=!0;const a=window.fetch.bind(window);window.fetch=async(r,s)=>{let t="";typeof r=="string"?t=r:r instanceof URL?t=r.toString():r&&typeof r.url=="string"&&(t=r.url);const n=t.startsWith("/api/")||t.includes("/api/"),o=t.includes("/api/auth/status")||t.includes("/api/auth/login");let l=s;const x=w.getToken();if(n&&x){const i=new Headers((s==null?void 0:s.headers)||(r instanceof Request?r.headers:void 0));i.has("Authorization")||i.set("Authorization",`Bearer ${x}`),l={...s,headers:i}}const d=await a(r,l);if(n&&!o&&d.status===401)try{const c=await d.clone().json();c&&c.code==="AUTH_REQUIRED"&&q()}catch{}return d}}re();const j=A((a,r)=>({isChecking:!0,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1,checkAuth:async()=>{a({isChecking:!0});try{const s=await w.checkStatus();if(!s.enabled){a({isChecking:!1,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1});return}a({isChecking:!1,isPasswordSet:!0,isAuthenticated:s.authenticated,isLocked:!s.authenticated})}catch{a({isChecking:!1,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1})}},login:async s=>{const t=await w.login(s);return t.success?(a({isAuthenticated:!0,isLocked:!1}),{success:!0}):{success:!1,error:t.error}},logout:async()=>{await w.logout();const s=r().isPasswordSet;a({isAuthenticated:!s,isLocked:s})},lock:()=>{r().isPasswordSet&&(w.removeToken(),a({isAuthenticated:!1,isLocked:!0}))},unlock:s=>{w.setToken(s),a({isAuthenticated:!0,isLocked:!1})}}));typeof window<"u"&&(ae(()=>{j.getState().lock()}),window.addEventListener("storage",a=>{(a.key===E||a.key===null)&&(w.getToken()?j.setState({isAuthenticated:!0,isLocked:!1}):j.getState().isPasswordSet&&j.setState({isAuthenticated:!1,isLocked:!0}))}));const F=A(a=>({status:null,loading:!1,fetchStatus:async()=>{try{a({loading:!0});const r=await fetch("/api/mitm/status");if(r.ok){const s=await r.json(),t=s.dnsStatus||{},n=Object.entries(t).filter(([l,x])=>!!x).map(([l])=>l),o={running:!!s.running,port:Number(s.port)||443,certExists:!!s.certExists,certTrusted:!!s.certTrusted,dnsStatus:t,orphanedDns:!!s.orphanedDns,activeDnsCount:n.length,activeDnsTools:n};return a({status:o,loading:!1}),o}}catch{}return a({loading:!1}),null}})),ne={antigravity:"Antigravity",kiro:"Kiro",copilot:"GitHub Copilot",cursor:"Cursor"};function V(a){return!a||a.length===0?"":a.map(r=>ne[r]||r.charAt(0).toUpperCase()+r.slice(1)).join(", ")}const G={endpoint:{title:"Endpoint & Key",subtitle:"Manage your local AI gateway endpoint and master keys",icon:"api"},providers:{title:"Providers",subtitle:"Manage your AI provider connections and encrypted API credentials",icon:"dns"},combos:{title:"Combos & Adapter",subtitle:"Group models under smart fallback and load-balancing combos",icon:"layers"},usage:{title:"Usage & Analytics",subtitle:"Real-time token metrics, savings analysis, and interactive routing topology",icon:"bar_chart"},quota:{title:"Quota Tracker",subtitle:"Track rate limits and multi-account sliding quota reset times",icon:"data_usage"},tokensaver:{title:"Token Saver",subtitle:"Lossless context optimization saving 20-40% input tokens",icon:"savings"},clitools:{title:"Tools & Mappings",subtitle:"One-click connection setups and universal model rewrite rules for AI assistants, IDEs & tools",icon:"widgets"},mitm:{title:"MITM Proxy",subtitle:"Intercept CLI & IDE tool traffic (Antigravity, Kiro, Copilot) via local Root CA",icon:"alt_route"},consolelog:{title:"Console Log",subtitle:"Live gateway server stdout, request streaming events, and system logs",icon:"terminal"},settings:{title:"Settings",subtitle:"Local SQLite database, hardware encryption vault, and system preferences",icon:"tune"}},oe=({currentTab:a,searchQuery:r,onSearchChange:s,detailProvider:t,onBackToProviders:n,onRestartClick:o,onSelectTab:l})=>{const x=G[a]||G.providers,d=j(v=>v.isPasswordSet),i=j(v=>v.lock),c=_(v=>v.info),p=_(v=>v.fetchSystemInfo);c==null||c.version;const h=F(v=>v.status),u=F(v=>v.fetchStatus);m.useEffect(()=>{u(),p();const v=setInterval(()=>{document.hidden||(u(),p())},1e4),U=()=>{u(),p()};return window.addEventListener("focus",U),()=>{clearInterval(v),window.removeEventListener("focus",U)}},[u,p]);const b=!!(h!=null&&h.running),g=(h==null?void 0:h.port)||443,f=(h==null?void 0:h.activeDnsCount)||0,M=(h==null?void 0:h.activeDnsTools)||[],W=!!(h!=null&&h.orphanedDns),S=(c==null?void 0:c.host)||"127.0.0.1",L=(c==null?void 0:c.configuredHost)||S,D=!!(c!=null&&c.isRestartRequired),C=S==="0.0.0.0";let I=C?`Network: LAN Active (0.0.0.0:${(c==null?void 0:c.port)||T}) • Accessible from local network • Click to configure Endpoint`:`Network: Local Only (127.0.0.1:${(c==null?void 0:c.port)||T}) • Isolated to this machine • Click to configure Endpoint`,B=C?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20 hover:bg-emerald-500/20":"bg-blue-500/10 text-blue-400 border-blue-500/20 hover:bg-blue-500/20",O=C?"wifi":"shield";D&&(I=`⚠️ Restart Required: Configured for ${L==="0.0.0.0"?"LAN Active":"Local Only"} (${L}), but running on ${S}. Click Restart button to apply.`,B="bg-amber-500/15 text-amber-300 border-amber-500/30 hover:bg-amber-500/25 animate-pulse",O="restart_alt");let N="MITM Proxy: Stopped • Click to open settings",k="text-slate-500 hover:text-slate-300";return W?(N=`⚠️ MITM Warning: Server stopped but ${f} DNS redirect(s) still active (${V(M)})! Tools cannot connect. Click to fix.`,k="text-amber-400 hover:text-amber-300 animate-pulse"):b?f>0?(N=`MITM Proxy: Active on port ${g} • ${f} tool DNS active (${V(M)}) • Click to manage`,k="text-emerald-400 hover:text-emerald-300"):(N=`MITM Proxy: Running on port ${g} (Idle, 0 tool DNS active) • Click to configure`,k="text-blue-400 hover:text-blue-300"):(N="MITM Proxy: Stopped • Click to open settings",k="text-slate-500 hover:text-slate-300"),e.jsxs("header",{className:"rt-header",children:[e.jsxs("div",{className:"flex items-center gap-3.5 min-w-0",children:[e.jsx("div",{className:"rt-header__icon-box",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:x.icon})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[a==="providers"&&t?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:n,className:"text-sm font-bold text-slate-400 hover:text-white flex items-center gap-1 cursor-pointer transition-colors",title:"Back to Providers",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_back"}),"Providers"]}),e.jsx("span",{className:"text-slate-600 text-xs",children:"/"}),e.jsx("h2",{className:"text-sm font-bold text-white tracking-tight leading-tight",children:t.name})]}):e.jsx("h2",{className:"text-sm font-bold text-white tracking-tight leading-tight",children:x.title}),e.jsx("p",{className:"text-[11px] text-slate-400 truncate leading-tight mt-0.5",children:a==="providers"&&t?`Configure credentials, upstream headers, and fallback strategy for ${t.name}`:x.subtitle})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("div",{className:"relative w-64 h-8",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[15px] text-slate-500 pointer-events-none",children:"search"}),e.jsx("input",{type:"text",placeholder:"Search providers & models...",value:r,onChange:v=>s(v.target.value),className:"w-full h-8 bg-[#111827] border border-[#1E293B] rounded-lg pl-9 pr-8 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30 transition-all"}),r&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center w-5 h-5 rounded hover:bg-white/5",title:"Clear search",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{D&&o?o():l==null||l("endpoint")},title:I,className:`w-8 h-8 rounded-lg border text-xs font-medium transition-all cursor-pointer shadow-xs inline-flex items-center justify-center ${B}`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:O})}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l("mitm"),title:N,className:`w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 ${k} transition-colors cursor-pointer inline-flex items-center justify-center shadow-xs`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:"alt_route"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-l border-[#1E293B] pl-2.5",children:[o&&e.jsx("button",{type:"button",onClick:o,title:"Restart Mapigate Gateway (Hot Reload)",className:"w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 hover:text-blue-400 text-slate-400 transition-colors cursor-pointer inline-flex items-center justify-center shadow-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:"restart_alt"})}),d&&e.jsx("button",{type:"button",onClick:i,title:"Lock Dashboard (Master Password Protected)",className:"w-8 h-8 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 text-amber-400 border border-amber-500/20 hover:border-amber-500/30 transition-all cursor-pointer inline-flex items-center justify-center shadow-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock"})})]}),e.jsx("div",{className:"flex items-center border-l border-[#1E293B] pl-2.5",children:e.jsx("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",title:"Mapigate on GitHub (joutvhu/mapigate)",className:"hidden sm:inline-flex items-center justify-center w-8 h-8 rounded-lg bg-[#111827] hover:bg-white/5 text-slate-400 hover:text-white border border-[#1E293B] transition-all cursor-pointer shadow-xs",children:e.jsx(H,{className:"size-4"})})})]})]})},le=()=>{const[a,r]=m.useState(""),[s,t]=m.useState(!1),[n,o]=m.useState(!1),[l,x]=m.useState(null),d=m.useRef(null),i=j(p=>p.login);m.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]);const c=async p=>{var u;if(p.preventDefault(),!a.trim()||n)return;o(!0),x(null);const h=await i(a);h.success||(x(h.error||"Incorrect master password"),o(!1),(u=d.current)==null||u.select())};return e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-[#07090E] p-4 animate-rt-fade-in select-none",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-[25%] left-1/2 -translate-x-1/2 w-[650px] h-[450px] bg-gradient-to-b from-blue-600/15 via-indigo-600/10 to-transparent blur-[140px] rounded-full"}),e.jsx("div",{className:"absolute -bottom-[20%] left-1/2 -translate-x-1/2 w-[500px] h-[300px] bg-blue-500/5 blur-[120px] rounded-full"})]}),e.jsxs("div",{className:"w-full max-w-sm relative z-10 space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3",children:[e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 bg-gradient-to-r from-blue-500 to-indigo-500 rounded-2xl blur-md opacity-40 group-hover:opacity-75 transition-opacity"}),e.jsx("div",{className:"relative size-12 rounded-2xl bg-gradient-to-br from-blue-500 to-indigo-600 text-white flex items-center justify-center shadow-lg shadow-blue-500/30 border border-blue-400/30",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"graph_5"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-xl font-bold tracking-tight text-white font-sans",children:"Mapigate"}),e.jsx("span",{className:"text-[10px] uppercase font-semibold px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 border border-blue-500/30 font-mono",children:"AI"})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1 font-medium",children:"Ultra-lightweight Local AI Gateway"})]})]}),e.jsxs("div",{className:"bg-[#0D111A]/90 backdrop-blur-xl border border-slate-800/80 shadow-2xl shadow-black/60 rounded-2xl p-6 sm:p-7 text-center space-y-5 border-t-blue-500/50",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-slate-800/60",children:[e.jsxs("div",{className:"flex items-center gap-2 text-left",children:[e.jsx("div",{className:"size-8 rounded-lg bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"lock"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xs font-semibold text-white tracking-tight",children:"Dashboard Locked"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Authentication required"})]})]}),e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded-full bg-slate-800/80 text-slate-300 border border-slate-700/50",children:"v1.0"})]}),e.jsxs("form",{onSubmit:c,className:"space-y-4",children:[e.jsxs("div",{className:"relative text-left",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[18px] text-slate-500",children:"key"}),e.jsx("input",{ref:d,type:s?"text":"password",placeholder:"Enter master password...",value:a,onChange:p=>{r(p.target.value),l&&x(null)},disabled:n,className:"w-full bg-[#07090E] border border-slate-800 rounded-xl pl-9 pr-10 py-2.5 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all font-mono"}),e.jsx("button",{type:"button",onClick:()=>t(!s),tabIndex:-1,className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer","aria-label":s?"Hide password":"Show password",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:s?"visibility_off":"visibility"})})]}),l&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 flex items-center gap-2 text-left animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 text-rose-400",children:"error"}),e.jsx("span",{className:"truncate",children:l})]}),e.jsx("button",{type:"submit",disabled:n||!a.trim(),className:"w-full rt-btn rt-btn--primary text-xs py-2.5 px-4 flex items-center justify-center gap-2 cursor-pointer font-semibold shadow-lg shadow-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:n?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] animate-spin",children:"progress_activity"}),"Verifying..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock_open"}),"Unlock Dashboard"]})})]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-slate-500 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"verified_user"}),e.jsx("span",{children:"100% Local-First · Coding assistants proxy unaffected"})]})]})]})};function ie(a){let r={...a},s=!1,t=!1,n=0;const o=u=>{r={...u}},l=()=>{var b;if(r.disabled)return;const u=Date.now();u-n<250||(n=u,(b=r.onClose)==null||b.call(r))};return{updateOptions:o,handleMouseDown:u=>{r.disabled||(u.target===u.currentTarget&&(u.button===0||u.button===void 0)?s=!0:s=!1)},handleMouseUp:u=>{if(r.disabled){s=!1;return}s&&u.target===u.currentTarget&&(u.button===0||u.button===void 0)&&l(),s=!1},handleTouchStart:u=>{r.disabled||(u.target===u.currentTarget?t=!0:t=!1)},handleTouchEnd:u=>{if(r.disabled){t=!1;return}t&&u.target===u.currentTarget&&l(),t=!1},handleClick:u=>{r.disabled||u.detail===0&&u.target===u.currentTarget&&l()},reset:()=>{s=!1,t=!1},get isMouseDown(){return s},get isTouchStart(){return t}}}function ce(a,r=!1){const s=m.useRef(null);s.current?s.current.updateOptions({onClose:a,disabled:r}):s.current=ie({onClose:a,disabled:r}),m.useEffect(()=>{if(typeof window>"u")return;const n=()=>{var l;(l=s.current)==null||l.reset()},o=()=>{var l;(l=s.current)==null||l.reset()};return window.addEventListener("mouseup",n),window.addEventListener("touchend",o),()=>{window.removeEventListener("mouseup",n),window.removeEventListener("touchend",o)}},[]);const t=s.current;return{handleBackdropMouseDown:t.handleMouseDown,handleBackdropMouseUp:t.handleMouseUp,handleBackdropTouchStart:t.handleTouchStart,handleBackdropTouchEnd:t.handleTouchEnd,handleBackdropClick:t.handleClick,backdropProps:{onMouseDown:t.handleMouseDown,onMouseUp:t.handleMouseUp,onTouchStart:t.handleTouchStart,onTouchEnd:t.handleTouchEnd,onClick:t.handleClick}}}const K=({isOpen:a,onClose:r,children:s,maxWidthClass:t="max-w-xl",className:n="",overflowHidden:o=!1})=>{const{backdropProps:l}=ce(r);if(m.useEffect(()=>{if(!a)return;const d=c=>{c.key==="Escape"&&r()};document.addEventListener("keydown",d);const i=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=i}},[a,r]),!a||typeof document>"u")return null;const x=o?"overflow-hidden":n.includes("overflow-")?"":"overflow-visible";return J.createPortal(e.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-black/75 backdrop-blur-xs animate-rt-fade-in",...l,children:e.jsx("div",{className:`w-full ${t} bg-[#0F1420] border border-[#1E293B] rounded-2xl shadow-2xl p-6 animate-rt-scale-in text-slate-100 ${x} ${n}`,onClick:d=>d.stopPropagation(),children:s})}),document.body)},de=({isOpen:a,onClose:r})=>{const[s,t]=m.useState("confirm"),[n,o]=m.useState(null),[l,x]=m.useState(0),d=m.useRef(null),i=m.useRef(null);m.useEffect(()=>(a?(t("confirm"),o(null),x(0)):(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current)),()=>{d.current&&clearInterval(d.current),i.current&&clearInterval(i.current)}),[a]);const c=()=>{const h=Date.now();let u=0;i.current=setInterval(()=>{x(Math.floor((Date.now()-h)/1e3))},500),setTimeout(()=>{d.current=setInterval(async()=>{u+=1;try{const b=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(b.ok){const g=await b.json().catch(()=>null);(g==null?void 0:g.status)==="ok"&&(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current),t("success"),setTimeout(()=>{window.location.reload()},600))}}catch{}u>=50&&(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current),t("timeout"))},500)},600)},p=async()=>{t("restarting"),o(null);try{const h=await fetch("/api/server/restart",{method:"POST",headers:{"Content-Type":"application/json"}});if(!h.ok){const u=await h.json().catch(()=>({}));o(u.error||"Failed to initiate server restart."),t("confirm");return}}catch{}c()};return e.jsx(K,{isOpen:a,onClose:()=>{(s==="confirm"||s==="timeout")&&r()},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[s==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-blue-500/15 border border-blue-500/30 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"restart_alt"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Mapigate Gateway?"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Gracefully reload server and apply new version"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"Hot restarting the gateway reloads all provider modules, registries, and configuration. MITM proxy and tool DNS entries remain active across restart."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["If you recently installed an update (e.g. via ",e.jsx("code",{className:"text-blue-400",children:"npm install -g mapigate"})," or ",e.jsx("code",{className:"text-blue-400",children:"npm run local:publish"}),"), the new code will take effect immediately without needing to open a terminal or turn off DNS."]})]}),n&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300",children:n}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:p,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"restart_alt"}),"Restart Gateway"]})]})]}),s==="restarting"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"restart_alt"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restarting Mapigate Gateway..."}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Re-spawning daemon and binding port (",l,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Please wait. This page will refresh automatically once the new server responds."})]}),s==="success"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsx("div",{className:"size-14 mx-auto rounded-full bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"check_circle"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Succeeded!"}),e.jsx("p",{className:"text-xs text-emerald-400 font-medium",children:"Gateway is back online. Refreshing dashboard..."})]})]}),s==="timeout"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"schedule"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Taking Longer Than Expected"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The gateway server has not responded yet."})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2",children:[e.jsx("p",{children:"If the server failed to restart automatically, you can start it manually in your terminal:"}),e.jsx("div",{className:"bg-[#111827] p-2.5 rounded-lg border border-[#1E293B] font-mono text-[11px] text-blue-400",children:"mpg start"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Refresh Page"]})]})]})]})})},ue=({isOpen:a,onClose:r,currentVersion:s,latestVersion:t})=>{const[n,o]=m.useState("confirm"),[l,x]=m.useState(null),[d,i]=m.useState(0),c=m.useRef(null),p=m.useRef(null);m.useEffect(()=>(a?(o("confirm"),x(null),i(0)):(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current)),()=>{c.current&&clearInterval(c.current),p.current&&clearInterval(p.current)}),[a]);const h=()=>{let b=0;setTimeout(()=>{c.current=setInterval(async()=>{b+=1;try{const g=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(g.ok){const f=await g.json().catch(()=>null);(f==null?void 0:f.status)==="ok"&&(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current),o("success"),setTimeout(()=>{window.location.reload()},800))}}catch{}b>=60&&(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current),o("timeout"))},500)},800)},u=async()=>{o("upgrading"),x(null),i(0);const b=Date.now();p.current=setInterval(()=>{i(Math.floor((Date.now()-b)/1e3))},500);try{const g=await fetch("/api/server/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:!1})}),f=await g.json().catch(()=>({}));if(!g.ok||!f.success){p.current&&clearInterval(p.current),x(f.error||"Failed to upgrade Mapigate."),o("error");return}o("restarting"),h()}catch(g){p.current&&clearInterval(p.current),x((g==null?void 0:g.message)||"Network error while requesting upgrade."),o("error")}};return e.jsx(K,{isOpen:a,onClose:()=>{(n==="confirm"||n==="error"||n==="timeout")&&r()},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[n==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"upgrade"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Mapigate Gateway"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Install the latest release from npm and reload"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Current Version:"}),e.jsxs("span",{className:"font-mono font-semibold text-slate-300",children:["v",s||"0.0.0"]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Target Version:"}),e.jsxs("span",{className:"font-mono font-semibold text-amber-400",children:["v",t||"latest"]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B] text-[11px] text-slate-400 leading-relaxed",children:["Mapigate will run ",e.jsxs("code",{className:"text-amber-400 font-mono",children:["npm install -g mapigate@",t||"latest"]})," and hot-reload the gateway. All database settings, API keys, and active combos will be preserved."]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("a",{href:"https://www.npmjs.com/package/mapigate",target:"_blank",rel:"noreferrer",className:"text-[11px] text-blue-400 hover:text-blue-300 hover:underline inline-flex items-center gap-1",children:[e.jsx("span",{children:"View on npm"}),e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-3.5 cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:u,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold bg-amber-600 hover:bg-amber-500 text-white border-amber-500/40",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"upgrade"}),"Upgrade to v",t]})]})]})]}),n==="upgrading"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-amber-500/20 border-t-amber-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-amber-400",children:"download"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrading Mapigate..."}),e.jsxs("p",{className:"text-xs text-slate-400 font-mono",children:["npm install -g mapigate@",t||"latest"," (",d,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Downloading and installing update. Please do not close this window."})]}),n==="restarting"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"restart_alt"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restarting Gateway..."}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Re-spawning daemon with v",t," (",d,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Gateway is reloading. This dashboard will refresh automatically once online."})]}),n==="success"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsx("div",{className:"size-14 mx-auto rounded-full bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"check_circle"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Succeeded!"}),e.jsxs("p",{className:"text-xs text-emerald-400 font-medium",children:["Mapigate v",t," is live. Refreshing dashboard..."]})]})]}),n==="error"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-rose-500/15 border border-rose-500/30 text-rose-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"error"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Failed"}),e.jsx("p",{className:"text-xs text-slate-400",children:"An error occurred while updating"})]})]}),l&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 font-mono break-words leading-relaxed max-h-36 overflow-y-auto",children:l}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-400 space-y-1.5 leading-relaxed",children:[e.jsx("p",{className:"font-semibold text-slate-300",children:"You can upgrade manually from your terminal:"}),e.jsxs("div",{className:"p-2 rounded bg-black/50 font-mono text-slate-200 text-[10px] space-y-1 select-all",children:[e.jsx("div",{children:"npm install -g mapigate@latest"}),e.jsx("div",{children:"mpg restart"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:u,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Retry"]})]})]}),n==="timeout"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"schedule"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Server Still Starting"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The gateway has not responded yet"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"The upgrade may have completed, but the server is taking longer than expected to bind to port."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["You can try refreshing the page or checking ",e.jsx("code",{className:"text-blue-400",children:"mpg status"})," in your terminal."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Refresh Page"]})]})]})]})})},xe=m.lazy(()=>y(()=>import("./ProvidersTab-yzmb4w0D.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(a=>({default:a.ProvidersTab}))),me=m.lazy(()=>y(()=>import("./ProviderDetailPage-D-fodBhz.js"),__vite__mapDeps([8,1,6,4,9,5,3,10,2,7])).then(a=>({default:a.ProviderDetailPage}))),pe=m.lazy(()=>y(()=>import("./CombosTab-D1_cfssh.js"),__vite__mapDeps([11,1,12,3,4,5,9,2,7])).then(a=>({default:a.CombosTab}))),he=m.lazy(()=>y(()=>import("./UsageTab-Hr8XPZD4.js"),__vite__mapDeps([13,1,7,5,4,14,9])).then(a=>({default:a.UsageTab}))),fe=m.lazy(()=>y(()=>import("./QuotaTab-BXevQzen.js"),__vite__mapDeps([15,1,4,5,9,10,2,7])).then(a=>({default:a.QuotaTab}))),be=m.lazy(()=>y(()=>import("./CliToolsTab-rKSWLJC3.js"),__vite__mapDeps([16,1,6,4,5,3,7])).then(a=>({default:a.CliToolsTab}))),ge=m.lazy(()=>y(()=>import("./MitmTab-5dKeNi4T.js"),__vite__mapDeps([17,1,3,4,5,7])).then(a=>({default:a.MitmTab}))),ve=m.lazy(()=>y(()=>import("./EndpointTab-B-Jb4wAG.js"),__vite__mapDeps([18,1,9,2,7])).then(a=>({default:a.EndpointTab}))),ye=m.lazy(()=>y(()=>import("./TokenSaverTab-B3Fbu_yc.js"),__vite__mapDeps([19,1])).then(a=>({default:a.TokenSaverTab}))),je=m.lazy(()=>y(()=>import("./ConsoleLogTab-rZe8zCb_.js"),__vite__mapDeps([20,1,9,7,5])).then(a=>({default:a.ConsoleLogTab}))),we=m.lazy(()=>y(()=>import("./SettingsTab-LkByv4Sg.js"),__vite__mapDeps([21,1,7])).then(a=>({default:a.SettingsTab}))),Ne=m.lazy(()=>y(()=>import("./CallbackPage-DBsxnmPi.js"),__vite__mapDeps([22,1])));function Q(){return e.jsx("div",{className:"flex items-center justify-center py-24 text-slate-500",children:e.jsx("div",{className:"size-6 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"})})}function ke(){const a=typeof window<"u"?new URLSearchParams(window.location.search):null,r=!!(a&&(a.has("user_id")&&(a.has("access_token")||a.has("accessToken")||a.has("token"))||a.has("userId")&&(a.has("access_token")||a.has("accessToken")||a.has("token"))));return typeof window<"u"&&(window.location.pathname==="/callback"||window.location.pathname==="/auth/callback"||window.location.pathname==="/authorize"||window.location.pathname.startsWith("/callback")||r)?e.jsx(m.Suspense,{fallback:e.jsx(Q,{}),children:e.jsx(Ne,{})}):e.jsx(Te,{})}function Te(){const a=j(f=>f.isChecking),r=j(f=>f.isLocked),s=j(f=>f.checkAuth),t=_(f=>f.fetchSystemInfo);m.useEffect(()=>{s(),t()},[s,t]);const[n,o]=m.useState("providers"),[l,x]=m.useState(""),[d,i]=m.useState(null),[c,p]=m.useState(!1),[h,u]=m.useState(!1),b=_(f=>f.info),g=f=>{o(f),i(null)};return a?e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-[#0A0D14] text-slate-400",children:e.jsx("div",{className:"size-8 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"})}):r?e.jsx(le,{}):e.jsxs("div",{className:"rt-app",children:[e.jsx(se,{currentTab:n,onSelectTab:g,onUpgradeClick:()=>u(!0)}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 h-full overflow-hidden",children:[e.jsx(oe,{currentTab:n,searchQuery:l,onSearchChange:x,detailProvider:d,onBackToProviders:()=>i(null),onRestartClick:()=>p(!0),onSelectTab:g}),e.jsx("main",{className:"flex-1 overflow-y-auto px-4 sm:px-6 py-6 w-full",children:e.jsxs(m.Suspense,{fallback:e.jsx(Q,{}),children:[n==="endpoint"&&e.jsx(ve,{onRestartClick:()=>p(!0)}),n==="providers"&&(d?e.jsx(me,{provider:d,onBack:()=>i(null)}):e.jsx(xe,{searchQuery:l,onSelectProvider:f=>i(f)})),n==="combos"&&e.jsx(pe,{}),n==="usage"&&e.jsx(he,{}),n==="quota"&&e.jsx(fe,{searchQuery:l}),n==="tokensaver"&&e.jsx(ye,{}),n==="clitools"&&e.jsx(be,{}),n==="mitm"&&e.jsx(ge,{}),n==="consolelog"&&e.jsx(je,{}),n==="settings"&&e.jsx(we,{onRestartClick:()=>p(!0),onUpgradeClick:()=>u(!0)})]})})]}),e.jsx(de,{isOpen:c,onClose:()=>p(!1)}),e.jsx(ue,{isOpen:h,onClose:()=>u(!1),currentVersion:b==null?void 0:b.version,latestVersion:b==null?void 0:b.latestVersion})]})}Y.createRoot(document.getElementById("root")).render(e.jsx(X.StrictMode,{children:e.jsx(ke,{})}));export{w as A,T as D,K as P,de as R,ce as a,Se as b,te as c,R as d,F as e,j as f,_ as u};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProvidersTab-BFdg0gXr.js","assets/vendor-BcOI2aZ9.js","assets/ConfirmModal-BS3mAUd5.js","assets/ModelAutocompleteInput-DJkxW2yD.js","assets/metadataRegistry-W75_wn57.js","assets/ToolIcon-Cp4gSgFt.js","assets/providersData-BI_7MaUL.js","assets/lucide-Cc35htxl.js","assets/ProviderDetailPage-CnWjM-0J.js","assets/Select-BNRH8LIG.js","assets/EditAccountModal-BhPOk3Ya.js","assets/CombosTab-CujUAbYQ.js","assets/dnd-kit-DecqzwfZ.js","assets/UsageTab-O6OK0i38.js","assets/recharts-X4_nm3od.js","assets/QuotaTab-DXg3adeS.js","assets/CliToolsTab-BYO-wJ7y.js","assets/MitmTab-ZOoWyRnb.js","assets/EndpointTab-BRVjAng2.js","assets/TokenSaverTab-B3Fbu_yc.js","assets/ConsoleLogTab-CSgZxPGW.js","assets/SettingsTab-DoYGKtDn.js","assets/CallbackPage-DBsxnmPi.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{d as A,j as e,r as m,a as J,e as Y,R as X}from"./vendor-BcOI2aZ9.js";import{G as H}from"./lucide-Cc35htxl.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))t(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&t(l)}).observe(document,{childList:!0,subtree:!0});function s(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function t(n){if(n.ep)return;n.ep=!0;const o=s(n);fetch(n.href,o)}})();const Z="modulepreload",ee=function(a){return"/"+a},z={},y=function(r,s,t){let n=Promise.resolve();if(s&&s.length>0){let l=function(i){return Promise.all(i.map(c=>Promise.resolve(c).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const x=document.querySelector("meta[property=csp-nonce]"),d=(x==null?void 0:x.nonce)||(x==null?void 0:x.getAttribute("nonce"));n=l(s.map(i=>{if(i=ee(i),i in z)return;z[i]=!0;const c=i.endsWith(".css"),p=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${i}"]${p}`))return;const h=document.createElement("link");if(h.rel=c?"stylesheet":Z,c||(h.as="script"),h.crossOrigin="",h.href=i,d&&h.setAttribute("nonce",d),document.head.appendChild(h),c)return new Promise((u,b)=>{h.addEventListener("load",u),h.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${i}`)))})}))}function o(l){const x=new Event("vite:preloadError",{cancelable:!0});if(x.payload=l,window.dispatchEvent(x),!x.defaultPrevented)throw l}return n.then(l=>{for(const x of l||[])x.status==="rejected"&&o(x.reason);return r().catch(o)})},T=20128,R="127.0.0.1",te=`http://${R}:${T}`,Se=`${te}/v1`,_=A(a=>({info:null,loading:!1,fetchSystemInfo:async()=>{try{a({loading:!0});const r=await fetch("/api/settings/system-info");if(r.ok){const s=await r.json(),t=typeof window<"u"&&window.location.port?Number(window.location.port):void 0,n=s.port||(t&&t!==5173?t:T),o=s.host||(typeof window<"u"&&window.location.hostname?window.location.hostname:R),l={dataDir:s.dataDir||"",dbPath:s.dbPath||"",isDevelopmentMode:!!s.isDevelopmentMode,appName:s.appName||"Mapigate",version:s.version||"",port:n,host:o,configuredHost:s.configuredHost||o,configuredPort:s.configuredPort||n,isRestartRequired:!!s.isRestartRequired};return a({info:l,loading:!1}),(async()=>{try{const x=await fetch("/api/settings/version");if(x.ok){const d=await x.json();a(i=>i.info?{...i,info:{...i.info,latestVersion:d.latestVersion,hasUpdate:!!d.hasUpdate}}:i)}}catch{}})(),l}}catch{}return a({loading:!1}),null},checkForUpdate:async()=>{try{const r=await fetch("/api/settings/version?force=true");if(r.ok){const s=await r.json();a(t=>t.info?{...t,info:{...t.info,latestVersion:s.latestVersion,hasUpdate:!!s.hasUpdate}}:t)}}catch{}}})),se=({currentTab:a,onSelectTab:r,onUpgradeClick:s})=>{const t=_(d=>d.info),n=t==null?void 0:t.version,o=(t==null?void 0:t.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):T),l=(t==null?void 0:t.host)||(typeof window<"u"&&window.location.hostname?window.location.hostname:R),x=[{id:"endpoint",label:"Endpoint & Key",icon:"api"},{id:"providers",label:"Providers",icon:"dns"},{id:"combos",label:"Combo & Vision Adapter",icon:"layers"},{id:"usage",label:"Usage & Analytics",icon:"bar_chart"},{id:"quota",label:"Quota Tracker",icon:"data_usage"},{id:"tokensaver",label:"Token Saver",icon:"savings"},{id:"clitools",label:"Tools & Mappings",icon:"widgets"},{id:"mitm",label:"MITM Proxy",icon:"alt_route"}];return e.jsxs("aside",{className:"rt-sidebar",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"rt-sidebar__brand pt-5 pr-4 flex items-center gap-3",children:[e.jsx("div",{className:"rt-sidebar__brand-icon shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"graph_5"})}),e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h1",{className:"text-sm font-bold tracking-tight text-white leading-none truncate",children:"Mapigate"}),n&&(t!=null&&t.hasUpdate&&t.latestVersion?e.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s(),className:"group relative inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-300 border border-amber-500/35 font-mono font-semibold shrink-0 select-none leading-none hover:bg-amber-500/25 transition-all cursor-pointer",title:`New version v${t.latestVersion} available! Click to upgrade`,children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-500"})]}),e.jsxs("span",{children:["v",n]}),e.jsx("span",{className:"text-[9px] text-amber-400 group-hover:translate-y-[-0.5px] transition-transform",children:"↑"})]}):e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md bg-blue-500/15 text-blue-300 border border-blue-500/30 font-mono font-semibold shrink-0 shadow-xs select-none leading-none",title:`Mapigate Version v${n}`,children:["v",n]}))]}),e.jsx("span",{className:"text-[11px] text-slate-400 leading-normal mt-1 truncate",children:"AI Model API Gateway"})]})]}),e.jsx("nav",{className:"px-3 pt-3 space-y-1",children:x.map(d=>{const i=a===d.id;return e.jsxs("button",{onClick:()=>r(d.id),className:`rt-sidebar__nav-item ${i?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:d.icon}),e.jsx("span",{children:d.label})]},d.id)})}),e.jsx("div",{className:"px-5 pt-6 pb-2",children:e.jsx("span",{className:"text-[10px] font-bold text-slate-500 tracking-wider uppercase",children:"SYSTEM PREFERENCES"})}),e.jsxs("nav",{className:"px-3 space-y-1",children:[e.jsxs("button",{onClick:()=>r("consolelog"),className:`rt-sidebar__nav-item ${a==="consolelog"?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"terminal"}),e.jsx("span",{children:"Console Log"})]}),e.jsxs("button",{onClick:()=>r("settings"),className:`rt-sidebar__nav-item ${a==="settings"?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"tune"}),e.jsx("span",{children:"Settings"})]})]})]}),e.jsxs("div",{className:"p-4 border-t border-[#1E293B] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-400 bg-[#111827] px-3.5 py-2.5 rounded-xl border border-[#1E293B] shadow-inner",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rt-beacon size-2 bg-emerald-400"}),e.jsxs("span",{className:"font-semibold text-slate-200",children:["Port ",o]})]}),e.jsx("span",{className:"text-[10px] text-blue-300 font-mono bg-blue-500/10 px-1.5 py-0.5 rounded border border-blue-500/20",children:l})]}),e.jsxs("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",title:"Mapigate on GitHub (joutvhu/mapigate)",className:"flex items-center justify-center gap-2 w-full py-1.5 px-3 rounded-xl bg-[#111827]/60 hover:bg-white/5 border border-[#1E293B]/60 hover:border-[#1E293B] text-[11px] font-medium text-slate-400 hover:text-white transition-all cursor-pointer",children:[e.jsx(H,{className:"size-3.5 text-slate-400"}),e.jsx("span",{children:"GitHub · joutvhu/mapigate"})]})]})]})},E="mapigate_auth_token";let $=!1;const P=new Set;function ae(a){return P.add(a),()=>{P.delete(a)}}function q(){for(const a of P)try{a()}catch{}}class w{static getToken(){if(typeof window>"u")return null;try{return localStorage.getItem(E)}catch{return null}}static setToken(r){if(!(typeof window>"u"))try{localStorage.setItem(E,r)}catch{}}static removeToken(){if(!(typeof window>"u"))try{localStorage.removeItem(E)}catch{}}static async checkStatus(){try{const r=this.getToken(),s={};r&&(s.Authorization=`Bearer ${r}`);const t=await fetch("/api/auth/status",{headers:s});if(!t.ok)return{enabled:!1,authenticated:!0};const n=await t.json();return{enabled:!!n.enabled,authenticated:!!n.authenticated}}catch{return{enabled:!1,authenticated:!0}}}static async login(r){try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r})}),t=await s.json();return s.ok&&t.success?(t.token&&this.setToken(t.token),{success:!0,token:t.token}):{success:!1,error:t.error||"Invalid master password"}}catch(s){return{success:!1,error:s.message||"Failed to authenticate"}}}static async logout(){try{await fetch("/api/auth/logout",{method:"POST"})}catch{}this.removeToken(),q()}static async setup(r){try{const s=await fetch("/api/auth/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r})}),t=await s.json();return s.ok&&t.success?(t.token&&this.setToken(t.token),{success:!0,token:t.token}):{success:!1,error:t.error||"Failed to setup master password"}}catch(s){return{success:!1,error:s.message||"Failed to setup master password"}}}static async changePassword(r,s){try{const t=await fetch("/api/auth/change-password",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:r,newPassword:s})}),n=await t.json();return t.ok&&n.success?(n.token&&this.setToken(n.token),{success:!0,token:n.token}):{success:!1,error:n.error||"Failed to change master password"}}catch(t){return{success:!1,error:t.message||"Failed to change master password"}}}static async removePassword(r){try{const s=await fetch("/api/auth/remove-password",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:r})}),t=await s.json();return s.ok&&t.success?(this.removeToken(),{success:!0}):{success:!1,error:t.error||"Failed to remove master password"}}catch(s){return{success:!1,error:s.message||"Failed to remove master password"}}}}function re(){if(typeof window>"u"||$)return;$=!0;const a=window.fetch.bind(window);window.fetch=async(r,s)=>{let t="";typeof r=="string"?t=r:r instanceof URL?t=r.toString():r&&typeof r.url=="string"&&(t=r.url);const n=t.startsWith("/api/")||t.includes("/api/"),o=t.includes("/api/auth/status")||t.includes("/api/auth/login");let l=s;const x=w.getToken();if(n&&x){const i=new Headers((s==null?void 0:s.headers)||(r instanceof Request?r.headers:void 0));i.has("Authorization")||i.set("Authorization",`Bearer ${x}`),l={...s,headers:i}}const d=await a(r,l);if(n&&!o&&d.status===401)try{const c=await d.clone().json();c&&c.code==="AUTH_REQUIRED"&&q()}catch{}return d}}re();const j=A((a,r)=>({isChecking:!0,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1,checkAuth:async()=>{a({isChecking:!0});try{const s=await w.checkStatus();if(!s.enabled){a({isChecking:!1,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1});return}a({isChecking:!1,isPasswordSet:!0,isAuthenticated:s.authenticated,isLocked:!s.authenticated})}catch{a({isChecking:!1,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1})}},login:async s=>{const t=await w.login(s);return t.success?(a({isAuthenticated:!0,isLocked:!1}),{success:!0}):{success:!1,error:t.error}},logout:async()=>{await w.logout();const s=r().isPasswordSet;a({isAuthenticated:!s,isLocked:s})},lock:()=>{r().isPasswordSet&&(w.removeToken(),a({isAuthenticated:!1,isLocked:!0}))},unlock:s=>{w.setToken(s),a({isAuthenticated:!0,isLocked:!1})}}));typeof window<"u"&&(ae(()=>{j.getState().lock()}),window.addEventListener("storage",a=>{(a.key===E||a.key===null)&&(w.getToken()?j.setState({isAuthenticated:!0,isLocked:!1}):j.getState().isPasswordSet&&j.setState({isAuthenticated:!1,isLocked:!0}))}));const F=A(a=>({status:null,loading:!1,fetchStatus:async()=>{try{a({loading:!0});const r=await fetch("/api/mitm/status");if(r.ok){const s=await r.json(),t=s.dnsStatus||{},n=Object.entries(t).filter(([l,x])=>!!x).map(([l])=>l),o={running:!!s.running,port:Number(s.port)||443,certExists:!!s.certExists,certTrusted:!!s.certTrusted,dnsStatus:t,orphanedDns:!!s.orphanedDns,activeDnsCount:n.length,activeDnsTools:n};return a({status:o,loading:!1}),o}}catch{}return a({loading:!1}),null}})),ne={antigravity:"Antigravity",kiro:"Kiro",copilot:"GitHub Copilot",cursor:"Cursor"};function V(a){return!a||a.length===0?"":a.map(r=>ne[r]||r.charAt(0).toUpperCase()+r.slice(1)).join(", ")}const G={endpoint:{title:"Endpoint & Key",subtitle:"Manage your local AI gateway endpoint and master keys",icon:"api"},providers:{title:"Providers",subtitle:"Manage your AI provider connections and encrypted API credentials",icon:"dns"},combos:{title:"Combos & Adapter",subtitle:"Group models under smart fallback and load-balancing combos",icon:"layers"},usage:{title:"Usage & Analytics",subtitle:"Real-time token metrics, savings analysis, and interactive routing topology",icon:"bar_chart"},quota:{title:"Quota Tracker",subtitle:"Track rate limits and multi-account sliding quota reset times",icon:"data_usage"},tokensaver:{title:"Token Saver",subtitle:"Lossless context optimization saving 20-40% input tokens",icon:"savings"},clitools:{title:"Tools & Mappings",subtitle:"One-click connection setups and universal model rewrite rules for AI assistants, IDEs & tools",icon:"widgets"},mitm:{title:"MITM Proxy",subtitle:"Intercept CLI & IDE tool traffic (Antigravity, Kiro, Copilot) via local Root CA",icon:"alt_route"},consolelog:{title:"Console Log",subtitle:"Live gateway server stdout, request streaming events, and system logs",icon:"terminal"},settings:{title:"Settings",subtitle:"Local SQLite database, hardware encryption vault, and system preferences",icon:"tune"}},oe=({currentTab:a,searchQuery:r,onSearchChange:s,detailProvider:t,onBackToProviders:n,onRestartClick:o,onSelectTab:l})=>{const x=G[a]||G.providers,d=j(v=>v.isPasswordSet),i=j(v=>v.lock),c=_(v=>v.info),p=_(v=>v.fetchSystemInfo);c==null||c.version;const h=F(v=>v.status),u=F(v=>v.fetchStatus);m.useEffect(()=>{u(),p();const v=setInterval(()=>{document.hidden||(u(),p())},1e4),U=()=>{u(),p()};return window.addEventListener("focus",U),()=>{clearInterval(v),window.removeEventListener("focus",U)}},[u,p]);const b=!!(h!=null&&h.running),g=(h==null?void 0:h.port)||443,f=(h==null?void 0:h.activeDnsCount)||0,M=(h==null?void 0:h.activeDnsTools)||[],W=!!(h!=null&&h.orphanedDns),S=(c==null?void 0:c.host)||"127.0.0.1",L=(c==null?void 0:c.configuredHost)||S,D=!!(c!=null&&c.isRestartRequired),C=S==="0.0.0.0";let I=C?`Network: LAN Active (0.0.0.0:${(c==null?void 0:c.port)||T}) • Accessible from local network • Click to configure Endpoint`:`Network: Local Only (127.0.0.1:${(c==null?void 0:c.port)||T}) • Isolated to this machine • Click to configure Endpoint`,B=C?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20 hover:bg-emerald-500/20":"bg-blue-500/10 text-blue-400 border-blue-500/20 hover:bg-blue-500/20",O=C?"wifi":"shield";D&&(I=`⚠️ Restart Required: Configured for ${L==="0.0.0.0"?"LAN Active":"Local Only"} (${L}), but running on ${S}. Click Restart button to apply.`,B="bg-amber-500/15 text-amber-300 border-amber-500/30 hover:bg-amber-500/25 animate-pulse",O="restart_alt");let N="MITM Proxy: Stopped • Click to open settings",k="text-slate-500 hover:text-slate-300";return W?(N=`⚠️ MITM Warning: Server stopped but ${f} DNS redirect(s) still active (${V(M)})! Tools cannot connect. Click to fix.`,k="text-amber-400 hover:text-amber-300 animate-pulse"):b?f>0?(N=`MITM Proxy: Active on port ${g} • ${f} tool DNS active (${V(M)}) • Click to manage`,k="text-emerald-400 hover:text-emerald-300"):(N=`MITM Proxy: Running on port ${g} (Idle, 0 tool DNS active) • Click to configure`,k="text-blue-400 hover:text-blue-300"):(N="MITM Proxy: Stopped • Click to open settings",k="text-slate-500 hover:text-slate-300"),e.jsxs("header",{className:"rt-header",children:[e.jsxs("div",{className:"flex items-center gap-3.5 min-w-0",children:[e.jsx("div",{className:"rt-header__icon-box",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:x.icon})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[a==="providers"&&t?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:n,className:"text-sm font-bold text-slate-400 hover:text-white flex items-center gap-1 cursor-pointer transition-colors",title:"Back to Providers",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_back"}),"Providers"]}),e.jsx("span",{className:"text-slate-600 text-xs",children:"/"}),e.jsx("h2",{className:"text-sm font-bold text-white tracking-tight leading-tight",children:t.name})]}):e.jsx("h2",{className:"text-sm font-bold text-white tracking-tight leading-tight",children:x.title}),e.jsx("p",{className:"text-[11px] text-slate-400 truncate leading-tight mt-0.5",children:a==="providers"&&t?`Configure credentials, upstream headers, and fallback strategy for ${t.name}`:x.subtitle})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("div",{className:"relative w-64 h-8",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[15px] text-slate-500 pointer-events-none",children:"search"}),e.jsx("input",{type:"text",placeholder:"Search providers & models...",value:r,onChange:v=>s(v.target.value),className:"w-full h-8 bg-[#111827] border border-[#1E293B] rounded-lg pl-9 pr-8 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30 transition-all"}),r&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center w-5 h-5 rounded hover:bg-white/5",title:"Clear search",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{D&&o?o():l==null||l("endpoint")},title:I,className:`w-8 h-8 rounded-lg border text-xs font-medium transition-all cursor-pointer shadow-xs inline-flex items-center justify-center ${B}`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:O})}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l("mitm"),title:N,className:`w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 ${k} transition-colors cursor-pointer inline-flex items-center justify-center shadow-xs`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:"alt_route"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-l border-[#1E293B] pl-2.5",children:[o&&e.jsx("button",{type:"button",onClick:o,title:"Restart Mapigate Gateway (Hot Reload)",className:"w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 hover:text-blue-400 text-slate-400 transition-colors cursor-pointer inline-flex items-center justify-center shadow-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:"restart_alt"})}),d&&e.jsx("button",{type:"button",onClick:i,title:"Lock Dashboard (Master Password Protected)",className:"w-8 h-8 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 text-amber-400 border border-amber-500/20 hover:border-amber-500/30 transition-all cursor-pointer inline-flex items-center justify-center shadow-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock"})})]}),e.jsx("div",{className:"flex items-center border-l border-[#1E293B] pl-2.5",children:e.jsx("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",title:"Mapigate on GitHub (joutvhu/mapigate)",className:"hidden sm:inline-flex items-center justify-center w-8 h-8 rounded-lg bg-[#111827] hover:bg-white/5 text-slate-400 hover:text-white border border-[#1E293B] transition-all cursor-pointer shadow-xs",children:e.jsx(H,{className:"size-4"})})})]})]})},le=()=>{const[a,r]=m.useState(""),[s,t]=m.useState(!1),[n,o]=m.useState(!1),[l,x]=m.useState(null),d=m.useRef(null),i=j(p=>p.login);m.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]);const c=async p=>{var u;if(p.preventDefault(),!a.trim()||n)return;o(!0),x(null);const h=await i(a);h.success||(x(h.error||"Incorrect master password"),o(!1),(u=d.current)==null||u.select())};return e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-[#07090E] p-4 animate-rt-fade-in select-none",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-[25%] left-1/2 -translate-x-1/2 w-[650px] h-[450px] bg-gradient-to-b from-blue-600/15 via-indigo-600/10 to-transparent blur-[140px] rounded-full"}),e.jsx("div",{className:"absolute -bottom-[20%] left-1/2 -translate-x-1/2 w-[500px] h-[300px] bg-blue-500/5 blur-[120px] rounded-full"})]}),e.jsxs("div",{className:"w-full max-w-sm relative z-10 space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3",children:[e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 bg-gradient-to-r from-blue-500 to-indigo-500 rounded-2xl blur-md opacity-40 group-hover:opacity-75 transition-opacity"}),e.jsx("div",{className:"relative size-12 rounded-2xl bg-gradient-to-br from-blue-500 to-indigo-600 text-white flex items-center justify-center shadow-lg shadow-blue-500/30 border border-blue-400/30",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"graph_5"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-xl font-bold tracking-tight text-white font-sans",children:"Mapigate"}),e.jsx("span",{className:"text-[10px] uppercase font-semibold px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 border border-blue-500/30 font-mono",children:"AI"})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1 font-medium",children:"Ultra-lightweight Local AI Gateway"})]})]}),e.jsxs("div",{className:"bg-[#0D111A]/90 backdrop-blur-xl border border-slate-800/80 shadow-2xl shadow-black/60 rounded-2xl p-6 sm:p-7 text-center space-y-5 border-t-blue-500/50",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-slate-800/60",children:[e.jsxs("div",{className:"flex items-center gap-2 text-left",children:[e.jsx("div",{className:"size-8 rounded-lg bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"lock"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xs font-semibold text-white tracking-tight",children:"Dashboard Locked"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Authentication required"})]})]}),e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded-full bg-slate-800/80 text-slate-300 border border-slate-700/50",children:"v1.0"})]}),e.jsxs("form",{onSubmit:c,className:"space-y-4",children:[e.jsxs("div",{className:"relative text-left",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[18px] text-slate-500",children:"key"}),e.jsx("input",{ref:d,type:s?"text":"password",placeholder:"Enter master password...",value:a,onChange:p=>{r(p.target.value),l&&x(null)},disabled:n,className:"w-full bg-[#07090E] border border-slate-800 rounded-xl pl-9 pr-10 py-2.5 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all font-mono"}),e.jsx("button",{type:"button",onClick:()=>t(!s),tabIndex:-1,className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer","aria-label":s?"Hide password":"Show password",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:s?"visibility_off":"visibility"})})]}),l&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 flex items-center gap-2 text-left animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 text-rose-400",children:"error"}),e.jsx("span",{className:"truncate",children:l})]}),e.jsx("button",{type:"submit",disabled:n||!a.trim(),className:"w-full rt-btn rt-btn--primary text-xs py-2.5 px-4 flex items-center justify-center gap-2 cursor-pointer font-semibold shadow-lg shadow-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:n?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] animate-spin",children:"progress_activity"}),"Verifying..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock_open"}),"Unlock Dashboard"]})})]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-slate-500 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"verified_user"}),e.jsx("span",{children:"100% Local-First · Coding assistants proxy unaffected"})]})]})]})};function ie(a){let r={...a},s=!1,t=!1,n=0;const o=u=>{r={...u}},l=()=>{var b;if(r.disabled)return;const u=Date.now();u-n<250||(n=u,(b=r.onClose)==null||b.call(r))};return{updateOptions:o,handleMouseDown:u=>{r.disabled||(u.target===u.currentTarget&&(u.button===0||u.button===void 0)?s=!0:s=!1)},handleMouseUp:u=>{if(r.disabled){s=!1;return}s&&u.target===u.currentTarget&&(u.button===0||u.button===void 0)&&l(),s=!1},handleTouchStart:u=>{r.disabled||(u.target===u.currentTarget?t=!0:t=!1)},handleTouchEnd:u=>{if(r.disabled){t=!1;return}t&&u.target===u.currentTarget&&l(),t=!1},handleClick:u=>{r.disabled||u.detail===0&&u.target===u.currentTarget&&l()},reset:()=>{s=!1,t=!1},get isMouseDown(){return s},get isTouchStart(){return t}}}function ce(a,r=!1){const s=m.useRef(null);s.current?s.current.updateOptions({onClose:a,disabled:r}):s.current=ie({onClose:a,disabled:r}),m.useEffect(()=>{if(typeof window>"u")return;const n=()=>{var l;(l=s.current)==null||l.reset()},o=()=>{var l;(l=s.current)==null||l.reset()};return window.addEventListener("mouseup",n),window.addEventListener("touchend",o),()=>{window.removeEventListener("mouseup",n),window.removeEventListener("touchend",o)}},[]);const t=s.current;return{handleBackdropMouseDown:t.handleMouseDown,handleBackdropMouseUp:t.handleMouseUp,handleBackdropTouchStart:t.handleTouchStart,handleBackdropTouchEnd:t.handleTouchEnd,handleBackdropClick:t.handleClick,backdropProps:{onMouseDown:t.handleMouseDown,onMouseUp:t.handleMouseUp,onTouchStart:t.handleTouchStart,onTouchEnd:t.handleTouchEnd,onClick:t.handleClick}}}const K=({isOpen:a,onClose:r,children:s,maxWidthClass:t="max-w-xl",className:n="",overflowHidden:o=!1})=>{const{backdropProps:l}=ce(r);if(m.useEffect(()=>{if(!a)return;const d=c=>{c.key==="Escape"&&r()};document.addEventListener("keydown",d);const i=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=i}},[a,r]),!a||typeof document>"u")return null;const x=o?"overflow-hidden":n.includes("overflow-")?"":"overflow-visible";return J.createPortal(e.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-black/75 backdrop-blur-xs animate-rt-fade-in",...l,children:e.jsx("div",{className:`w-full ${t} bg-[#0F1420] border border-[#1E293B] rounded-2xl shadow-2xl p-6 animate-rt-scale-in text-slate-100 ${x} ${n}`,onClick:d=>d.stopPropagation(),children:s})}),document.body)},de=({isOpen:a,onClose:r})=>{const[s,t]=m.useState("confirm"),[n,o]=m.useState(null),[l,x]=m.useState(0),d=m.useRef(null),i=m.useRef(null);m.useEffect(()=>(a?(t("confirm"),o(null),x(0)):(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current)),()=>{d.current&&clearInterval(d.current),i.current&&clearInterval(i.current)}),[a]);const c=()=>{const h=Date.now();let u=0;i.current=setInterval(()=>{x(Math.floor((Date.now()-h)/1e3))},500),setTimeout(()=>{d.current=setInterval(async()=>{u+=1;try{const b=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(b.ok){const g=await b.json().catch(()=>null);(g==null?void 0:g.status)==="ok"&&(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current),t("success"),setTimeout(()=>{window.location.reload()},600))}}catch{}u>=50&&(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current),t("timeout"))},500)},600)},p=async()=>{t("restarting"),o(null);try{const h=await fetch("/api/server/restart",{method:"POST",headers:{"Content-Type":"application/json"}});if(!h.ok){const u=await h.json().catch(()=>({}));o(u.error||"Failed to initiate server restart."),t("confirm");return}}catch{}c()};return e.jsx(K,{isOpen:a,onClose:()=>{(s==="confirm"||s==="timeout")&&r()},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[s==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-blue-500/15 border border-blue-500/30 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"restart_alt"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Mapigate Gateway?"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Gracefully reload server and apply new version"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"Hot restarting the gateway reloads all provider modules, registries, and configuration. MITM proxy and tool DNS entries remain active across restart."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["If you recently installed an update (e.g. via ",e.jsx("code",{className:"text-blue-400",children:"npm install -g mapigate"})," or ",e.jsx("code",{className:"text-blue-400",children:"npm run local:publish"}),"), the new code will take effect immediately without needing to open a terminal or turn off DNS."]})]}),n&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300",children:n}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:p,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"restart_alt"}),"Restart Gateway"]})]})]}),s==="restarting"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"restart_alt"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restarting Mapigate Gateway..."}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Re-spawning daemon and binding port (",l,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Please wait. This page will refresh automatically once the new server responds."})]}),s==="success"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsx("div",{className:"size-14 mx-auto rounded-full bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"check_circle"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Succeeded!"}),e.jsx("p",{className:"text-xs text-emerald-400 font-medium",children:"Gateway is back online. Refreshing dashboard..."})]})]}),s==="timeout"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"schedule"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Taking Longer Than Expected"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The gateway server has not responded yet."})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2",children:[e.jsx("p",{children:"If the server failed to restart automatically, you can start it manually in your terminal:"}),e.jsx("div",{className:"bg-[#111827] p-2.5 rounded-lg border border-[#1E293B] font-mono text-[11px] text-blue-400",children:"mpg start"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Refresh Page"]})]})]})]})})},ue=({isOpen:a,onClose:r,currentVersion:s,latestVersion:t})=>{const[n,o]=m.useState("confirm"),[l,x]=m.useState(null),[d,i]=m.useState(0),c=m.useRef(null),p=m.useRef(null);m.useEffect(()=>(a?(o("confirm"),x(null),i(0)):(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current)),()=>{c.current&&clearInterval(c.current),p.current&&clearInterval(p.current)}),[a]);const h=()=>{let b=0;setTimeout(()=>{c.current=setInterval(async()=>{b+=1;try{const g=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(g.ok){const f=await g.json().catch(()=>null);(f==null?void 0:f.status)==="ok"&&(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current),o("success"),setTimeout(()=>{window.location.reload()},800))}}catch{}b>=60&&(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current),o("timeout"))},500)},800)},u=async()=>{o("upgrading"),x(null),i(0);const b=Date.now();p.current=setInterval(()=>{i(Math.floor((Date.now()-b)/1e3))},500);try{const g=await fetch("/api/server/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:!1})}),f=await g.json().catch(()=>({}));if(!g.ok||!f.success){p.current&&clearInterval(p.current),x(f.error||"Failed to upgrade Mapigate."),o("error");return}o("restarting"),h()}catch(g){p.current&&clearInterval(p.current),x((g==null?void 0:g.message)||"Network error while requesting upgrade."),o("error")}};return e.jsx(K,{isOpen:a,onClose:()=>{(n==="confirm"||n==="error"||n==="timeout")&&r()},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[n==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"upgrade"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Mapigate Gateway"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Install the latest release from npm and reload"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Current Version:"}),e.jsxs("span",{className:"font-mono font-semibold text-slate-300",children:["v",s||"0.0.0"]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Target Version:"}),e.jsxs("span",{className:"font-mono font-semibold text-amber-400",children:["v",t||"latest"]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B] text-[11px] text-slate-400 leading-relaxed",children:["Mapigate will run ",e.jsxs("code",{className:"text-amber-400 font-mono",children:["npm install -g mapigate@",t||"latest"]})," and hot-reload the gateway. All database settings, API keys, and active combos will be preserved."]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("a",{href:"https://www.npmjs.com/package/mapigate",target:"_blank",rel:"noreferrer",className:"text-[11px] text-blue-400 hover:text-blue-300 hover:underline inline-flex items-center gap-1",children:[e.jsx("span",{children:"View on npm"}),e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-3.5 cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:u,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold bg-amber-600 hover:bg-amber-500 text-white border-amber-500/40",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"upgrade"}),"Upgrade to v",t]})]})]})]}),n==="upgrading"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-amber-500/20 border-t-amber-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-amber-400",children:"download"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrading Mapigate..."}),e.jsxs("p",{className:"text-xs text-slate-400 font-mono",children:["npm install -g mapigate@",t||"latest"," (",d,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Downloading and installing update. Please do not close this window."})]}),n==="restarting"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"restart_alt"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restarting Gateway..."}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Re-spawning daemon with v",t," (",d,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Gateway is reloading. This dashboard will refresh automatically once online."})]}),n==="success"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsx("div",{className:"size-14 mx-auto rounded-full bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"check_circle"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Succeeded!"}),e.jsxs("p",{className:"text-xs text-emerald-400 font-medium",children:["Mapigate v",t," is live. Refreshing dashboard..."]})]})]}),n==="error"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-rose-500/15 border border-rose-500/30 text-rose-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"error"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Failed"}),e.jsx("p",{className:"text-xs text-slate-400",children:"An error occurred while updating"})]})]}),l&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 font-mono break-words leading-relaxed max-h-36 overflow-y-auto",children:l}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-400 space-y-1.5 leading-relaxed",children:[e.jsx("p",{className:"font-semibold text-slate-300",children:"You can upgrade manually from your terminal:"}),e.jsxs("div",{className:"p-2 rounded bg-black/50 font-mono text-slate-200 text-[10px] space-y-1 select-all",children:[e.jsx("div",{children:"npm install -g mapigate@latest"}),e.jsx("div",{children:"mpg restart"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:u,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Retry"]})]})]}),n==="timeout"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"schedule"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Server Still Starting"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The gateway has not responded yet"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"The upgrade may have completed, but the server is taking longer than expected to bind to port."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["You can try refreshing the page or checking ",e.jsx("code",{className:"text-blue-400",children:"mpg status"})," in your terminal."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Refresh Page"]})]})]})]})})},xe=m.lazy(()=>y(()=>import("./ProvidersTab-BFdg0gXr.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(a=>({default:a.ProvidersTab}))),me=m.lazy(()=>y(()=>import("./ProviderDetailPage-CnWjM-0J.js"),__vite__mapDeps([8,1,6,4,9,5,3,10,2,7])).then(a=>({default:a.ProviderDetailPage}))),pe=m.lazy(()=>y(()=>import("./CombosTab-CujUAbYQ.js"),__vite__mapDeps([11,1,12,3,4,5,9,2,7])).then(a=>({default:a.CombosTab}))),he=m.lazy(()=>y(()=>import("./UsageTab-O6OK0i38.js"),__vite__mapDeps([13,1,7,5,4,14,9])).then(a=>({default:a.UsageTab}))),fe=m.lazy(()=>y(()=>import("./QuotaTab-DXg3adeS.js"),__vite__mapDeps([15,1,4,5,9,10,2,7])).then(a=>({default:a.QuotaTab}))),be=m.lazy(()=>y(()=>import("./CliToolsTab-BYO-wJ7y.js"),__vite__mapDeps([16,1,6,4,5,3,7])).then(a=>({default:a.CliToolsTab}))),ge=m.lazy(()=>y(()=>import("./MitmTab-ZOoWyRnb.js"),__vite__mapDeps([17,1,3,4,5,7])).then(a=>({default:a.MitmTab}))),ve=m.lazy(()=>y(()=>import("./EndpointTab-BRVjAng2.js"),__vite__mapDeps([18,1,9,2,7])).then(a=>({default:a.EndpointTab}))),ye=m.lazy(()=>y(()=>import("./TokenSaverTab-B3Fbu_yc.js"),__vite__mapDeps([19,1])).then(a=>({default:a.TokenSaverTab}))),je=m.lazy(()=>y(()=>import("./ConsoleLogTab-CSgZxPGW.js"),__vite__mapDeps([20,1,9,7,5])).then(a=>({default:a.ConsoleLogTab}))),we=m.lazy(()=>y(()=>import("./SettingsTab-DoYGKtDn.js"),__vite__mapDeps([21,1,7])).then(a=>({default:a.SettingsTab}))),Ne=m.lazy(()=>y(()=>import("./CallbackPage-DBsxnmPi.js"),__vite__mapDeps([22,1])));function Q(){return e.jsx("div",{className:"flex items-center justify-center py-24 text-slate-500",children:e.jsx("div",{className:"size-6 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"})})}function ke(){const a=typeof window<"u"?new URLSearchParams(window.location.search):null,r=!!(a&&(a.has("user_id")&&(a.has("access_token")||a.has("accessToken")||a.has("token"))||a.has("userId")&&(a.has("access_token")||a.has("accessToken")||a.has("token"))));return typeof window<"u"&&(window.location.pathname==="/callback"||window.location.pathname==="/auth/callback"||window.location.pathname==="/authorize"||window.location.pathname.startsWith("/callback")||r)?e.jsx(m.Suspense,{fallback:e.jsx(Q,{}),children:e.jsx(Ne,{})}):e.jsx(Te,{})}function Te(){const a=j(f=>f.isChecking),r=j(f=>f.isLocked),s=j(f=>f.checkAuth),t=_(f=>f.fetchSystemInfo);m.useEffect(()=>{s(),t()},[s,t]);const[n,o]=m.useState("providers"),[l,x]=m.useState(""),[d,i]=m.useState(null),[c,p]=m.useState(!1),[h,u]=m.useState(!1),b=_(f=>f.info),g=f=>{o(f),i(null)};return a?e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-[#0A0D14] text-slate-400",children:e.jsx("div",{className:"size-8 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"})}):r?e.jsx(le,{}):e.jsxs("div",{className:"rt-app",children:[e.jsx(se,{currentTab:n,onSelectTab:g,onUpgradeClick:()=>u(!0)}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 h-full overflow-hidden",children:[e.jsx(oe,{currentTab:n,searchQuery:l,onSearchChange:x,detailProvider:d,onBackToProviders:()=>i(null),onRestartClick:()=>p(!0),onSelectTab:g}),e.jsx("main",{className:"flex-1 overflow-y-auto px-4 sm:px-6 py-6 w-full",children:e.jsxs(m.Suspense,{fallback:e.jsx(Q,{}),children:[n==="endpoint"&&e.jsx(ve,{onRestartClick:()=>p(!0)}),n==="providers"&&(d?e.jsx(me,{provider:d,onBack:()=>i(null)}):e.jsx(xe,{searchQuery:l,onSelectProvider:f=>i(f)})),n==="combos"&&e.jsx(pe,{}),n==="usage"&&e.jsx(he,{}),n==="quota"&&e.jsx(fe,{searchQuery:l}),n==="tokensaver"&&e.jsx(ye,{}),n==="clitools"&&e.jsx(be,{}),n==="mitm"&&e.jsx(ge,{}),n==="consolelog"&&e.jsx(je,{}),n==="settings"&&e.jsx(we,{onRestartClick:()=>p(!0),onUpgradeClick:()=>u(!0)})]})})]}),e.jsx(de,{isOpen:c,onClose:()=>p(!1)}),e.jsx(ue,{isOpen:h,onClose:()=>u(!1),currentVersion:b==null?void 0:b.version,latestVersion:b==null?void 0:b.latestVersion})]})}Y.createRoot(document.getElementById("root")).render(e.jsx(X.StrictMode,{children:e.jsx(ke,{})}));export{w as A,T as D,K as P,de as R,ce as a,Se as b,te as c,R as d,F as e,j as f,_ as u};
|