mapigate 0.5.120 → 0.5.123
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 +1 -1
- package/dist/mitm/handlers/base.js +58 -18
- package/dist/mitm/manager.js +5 -1
- package/dist/server/routes/apiMitm.js +50 -0
- package/dist/server/routes/mitmRouterTargetHelper.js +109 -0
- package/dist/storage/repositories/mitmRepo.js +44 -0
- package/dist/web/assets/{CliToolsTab-BzhczMaa.js → CliToolsTab-D-0zU55K.js} +1 -1
- package/dist/web/assets/{CombosTab-Cz8KYH4M.js → CombosTab-V_ldcQni.js} +1 -1
- package/dist/web/assets/{ConfirmModal-BU1PPpF0.js → ConfirmModal-B7vVauYn.js} +1 -1
- package/dist/web/assets/{ConsoleLogTab-CFvXde1l.js → ConsoleLogTab-Byt7Fr4V.js} +1 -1
- package/dist/web/assets/{EditAccountModal-CS2TR4bt.js → EditAccountModal-p6rlIU5X.js} +1 -1
- package/dist/web/assets/{EndpointTab-DZCRpAbh.js → EndpointTab-BHYn9Syj.js} +1 -1
- package/dist/web/assets/MitmTab-sRzVrlgW.js +14 -0
- package/dist/web/assets/ModelAutocompleteInput-ClwXyzE7.js +1 -0
- package/dist/web/assets/ProviderDetailPage-DgClsBMU.js +6 -0
- package/dist/web/assets/{ProvidersTab-DwHMHdPu.js → ProvidersTab-CPMTBmXq.js} +1 -1
- package/dist/web/assets/{QuotaTab-DS1y9gGp.js → QuotaTab-NaCPxtWq.js} +1 -1
- package/dist/web/assets/{SettingsTab-DULcs9O4.js → SettingsTab-BUKXj5iT.js} +1 -1
- package/dist/web/assets/{UsageTab-DKBaBAeT.js → UsageTab-BDTnu1v_.js} +1 -1
- package/dist/web/assets/{index-DPdrZakW.js → index-BdD7LHGu.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/MitmTab-CTfwqdey.js +0 -14
- package/dist/web/assets/ModelAutocompleteInput-CAi2R2s9.js +0 -1
- package/dist/web/assets/ProviderDetailPage-Dv2LpFj_.js +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,r as i,a as ie}from"./vendor-BcOI2aZ9.js";import{Z as ce,A as de,D as xe,a as me,S as Q,b as pe,N as Z,c as he,d as ue,R as be,C as ee,e as te,T as fe,L as je,f as J,g as V,X as se,h as ge,i as ve,j as Ne,k as ae,l as we,F as ye,m as le,n as ke,o as Ce,p as Se,q as Te}from"./lucide-Cc35htxl.js";import{T as W}from"./ToolIcon-Cp4gSgFt.js";import{g as X}from"./metadataRegistry-7DDoxaR3.js";import{R as Ee,A as Le,C as Re,X as qe,Y as Be,T as $e,a as Me}from"./recharts-X4_nm3od.js";import{a as Fe,A as De}from"./index-DPdrZakW.js";import{S as Y}from"./Select-BNRH8LIG.js";const Ae=({stats:t,loading:m})=>{const d=r=>(r||0).toLocaleString("en-US"),h=r=>`$${(r||0).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,c=(t==null?void 0:t.totalRequests)??0,p=(t==null?void 0:t.totalPromptTokens)??0,o=(t==null?void 0:t.totalCachedTokens)??0,x=(t==null?void 0:t.totalCompletionTokens)??0,j=(t==null?void 0:t.totalCost)??0,s=(t==null?void 0:t.totalTokensSaved)??0;return e.jsxs("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-blue-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-slate-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Total Requests"}),e.jsx(ce,{className:"w-4 h-4 text-blue-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-white truncate",title:d(c),children:m?"...":d(c)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"API Invocations"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-blue-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-blue-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Input Tokens"}),e.jsx(de,{className:"w-4 h-4 text-blue-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-blue-400 truncate",title:d(p),children:m?"...":d(p)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Prompt & context"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-cyan-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-cyan-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Cached Tokens"}),e.jsx(xe,{className:"w-4 h-4 text-cyan-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-cyan-400 truncate",title:d(o),children:m?"...":d(o)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Prompt cache hits"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-emerald-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-emerald-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Output Tokens"}),e.jsx(me,{className:"w-4 h-4 text-emerald-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-emerald-400 truncate",title:d(x),children:m?"...":d(x)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Generated output"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-purple-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-purple-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Tokens Saved"}),e.jsx(Q,{className:"w-4 h-4 text-purple-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-purple-400 truncate",title:d(s),children:m?"...":d(s)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Token Saver optimized"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-amber-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Est. Cost"}),e.jsx(pe,{className:"w-4 h-4 text-amber-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-amber-400 truncate",title:h(j),children:m?"...":`~${h(j)}`}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",title:"Estimated, not actual billing",children:"Estimated, not actual"})]})]})]})},Pe={"github-copilot":"github",copilot:"github","devin-cli":"devin","devin-desktop":"devin","devin-cli-agentic":"devin",dvd:"devin"};function H(t){if(!t)return{id:"unknown",name:"Unknown",color:"#64748B"};const m=t.toLowerCase().trim(),d=Pe[m]||m,h=X(d)||X(m);return h?{id:h.id,name:h.name,color:h.color||"#64748B",image:h.image,iconBg:h.iconBg}:{id:t,name:t.charAt(0).toUpperCase()+t.slice(1),color:"#64748B"}}const Oe=5,Ue=({providers:t=[],activeRequests:m=[]})=>{const[d,h]=i.useState(null),[c,p]=i.useState(1),[o,x]=i.useState({x:0,y:0}),[j,s]=i.useState(!1),r=i.useRef({x:0,y:0}),S=i.useRef({x:0,y:0}),N=i.useRef(!1),L=i.useRef(null),O=i.useCallback(()=>{p(1),x({x:0,y:0})},[]),F=i.useCallback(()=>{p(a=>Math.min(2.5,+(a+.2).toFixed(2)))},[]),D=i.useCallback(()=>{p(a=>Math.max(.4,+(a-.2).toFixed(2)))},[]);i.useEffect(()=>{const a=L.current;if(!a)return;const v=u=>{if(!u.ctrlKey&&!u.metaKey)return;u.preventDefault();const f=u.deltaY<0?1.1:.9;p(w=>{const B=+(w*f).toFixed(2);return Math.min(2.5,Math.max(.4,B))})};return a.addEventListener("wheel",v,{passive:!1}),()=>{a.removeEventListener("wheel",v)}},[]);const T=i.useCallback(a=>{a.button===0&&(s(!0),N.current=!1,r.current={x:a.clientX,y:a.clientY},S.current={...o})},[o]);i.useEffect(()=>{const a=u=>{if(!j)return;const f=u.clientX-r.current.x,w=u.clientY-r.current.y;(Math.abs(f)>3||Math.abs(w)>3)&&(N.current=!0),x({x:S.current.x+f,y:S.current.y+w})},v=()=>{s(!1)};return j&&(window.addEventListener("mousemove",a),window.addEventListener("mouseup",v)),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",v)}},[j]);const k=i.useMemo(()=>{const a=new Set;for(const v of m)if(v.provider){const u=v.provider.toLowerCase();a.add(u);const f=H(u);a.add(f.id.toLowerCase())}return a},[m]),{displayProviders:C,totalCount:E}=i.useMemo(()=>{const a=[...t];for(const f of m)f.provider&&a.push(f.provider);const u=Array.from(new Set(a)).filter(f=>{if(!f)return!1;const w=f.toLowerCase().trim();return w!=="unknown"&&w!=="null"&&w!=="undefined"}).sort((f,w)=>{const B=k.has(f.toLowerCase()),$=k.has(w.toLowerCase());return B&&!$?-1:!B&&$?1:f.localeCompare(w)});return{displayProviders:u.slice(0,10),totalCount:u.length}},[t,m,k]),y=400,n=220,g=i.useMemo(()=>{const a=C.length;if(a===0)return{items:[]};const v=Math.min(300,160+a*15),u=Math.min(150,90+a*8);return{items:C.map((w,B)=>{const $=H(w),R=k.has(w.toLowerCase())||k.has($.id.toLowerCase()),M=(d==null?void 0:d.toLowerCase())===w.toLowerCase()||(d==null?void 0:d.toLowerCase())===$.id.toLowerCase(),A=-Math.PI/2+2*Math.PI*B/a,q=y+v*Math.cos(A),P=n+u*Math.sin(A),re=Math.abs(q-y)<20,U=P<n?-1:1,oe=q<y?-1:1;let I,_,K,z;if(re)I=y,_=n+U*Math.min(u*.5,50),K=q,z=P-U*Math.min(u*.5,50);else{const G=Math.abs(Math.sin(A))>.35;I=G?y:y+(q-y)*.5,_=G?n+U*Math.min(u*.7,75):n,K=q-oe*Math.min(v*.45,60),z=P}const ne=`M ${y} ${n} C ${I.toFixed(1)} ${_.toFixed(1)}, ${K.toFixed(1)} ${z.toFixed(1)}, ${q.toFixed(1)} ${P.toFixed(1)}`;return{id:w,meta:$,isActive:R,isFocused:M,px:q,py:P,pathData:ne}})}},[C,k,d]),l=m.length,b=l>0;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-cyan-400"}),e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:"Active Routing Topology"}),e.jsx("span",{className:"text-xs text-slate-500",children:E>10?`(Top 10 of ${E} Mesh)`:"(Real-time Mesh)"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center bg-[#070A11] border border-[#1E293B] rounded-lg p-0.5 mr-1",title:"Ctrl + Scroll or use buttons to Zoom",children:[e.jsx("button",{type:"button",onClick:F,className:"p-1 hover:text-white text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer",title:"Zoom In","aria-label":"Zoom In",children:e.jsx(he,{className:"w-3.5 h-3.5"})}),e.jsxs("span",{className:"px-1.5 text-[10px] font-mono text-slate-400 select-none min-w-[34px] text-center",children:[Math.round(c*100),"%"]}),e.jsx("button",{type:"button",onClick:D,className:"p-1 hover:text-white text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer",title:"Zoom Out","aria-label":"Zoom Out",children:e.jsx(ue,{className:"w-3.5 h-3.5"})}),(c!==1||o.x!==0||o.y!==0)&&e.jsx("button",{type:"button",onClick:O,className:"p-1 hover:text-cyan-400 text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer ml-0.5 border-l border-[#1E293B]",title:"Reset View","aria-label":"Reset View",children:e.jsx(be,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-400",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-slate-600"}),e.jsx("span",{children:"Idle"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-cyan-400 font-semibold",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-cyan-400 animate-ping"}),e.jsx("span",{children:"Active Stream"})]})]})]}),e.jsx("div",{ref:L,onMouseDown:T,className:`relative h-72 sm:h-80 w-full rounded-lg overflow-hidden bg-[#070A11] border border-[#162032] flex items-center justify-center select-none ${j?"cursor-grabbing":"cursor-grab"}`,children:C.length===0?e.jsxs("div",{className:"text-center p-6 text-slate-500 text-xs sm:text-sm",children:[e.jsx(Z,{className:"w-8 h-8 text-slate-600 mx-auto mb-2 opacity-60"}),e.jsx("p",{children:"No upstream provider traffic recorded yet"})]}):e.jsxs("div",{className:"relative w-full h-full will-change-transform",style:{transform:`translate(${o.x}px, ${o.y}px) scale(${c})`,transformOrigin:"center center",transition:j?"none":"transform 0.15s ease-out"},children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full pointer-events-none",viewBox:"0 0 800 440",preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"plasma-glow",x:"-30%",y:"-30%",width:"160%",height:"160%",children:[e.jsx("feGaussianBlur",{stdDeviation:"3.5",result:"blur"}),e.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]})}),g.items.map(a=>a.isActive?e.jsxs("g",{children:[e.jsx("path",{d:a.pathData,fill:"none",stroke:"#22d3ee",strokeWidth:"6",strokeOpacity:"0.25",strokeLinecap:"round",filter:"url(#plasma-glow)"}),e.jsx("path",{d:a.pathData,fill:"none",stroke:"#38bdf8",strokeWidth:"2.5",strokeOpacity:"0.85",strokeLinecap:"round"}),e.jsx("path",{d:a.pathData,fill:"none",stroke:"#ffffff",strokeWidth:"1.2",strokeLinecap:"round"}),Array.from({length:Oe},(v,u)=>e.jsx("circle",{r:u%2===0?3.5:2,fill:u%2===0?"#22d3ee":"#ffffff",opacity:"0.9",children:e.jsx("animateMotion",{dur:`${.8+u*.15}s`,repeatCount:"indefinite",path:a.pathData,begin:`${u*.12}s`})},`orb-${a.id}-${u}`))]},`edge-active-${a.id}`):e.jsx("path",{d:a.pathData,fill:"none",stroke:"#1E293B",strokeWidth:"1.5",strokeDasharray:"4 5",strokeLinecap:"round"},`edge-${a.id}`))]}),e.jsx("div",{className:"absolute inset-0 pointer-events-none",children:e.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 800 440",preserveAspectRatio:"xMidYMid meet",children:[e.jsx("foreignObject",{x:y-80,y:n-26,width:"160",height:"54",className:"overflow-visible pointer-events-auto",children:e.jsxs("div",{className:`flex items-center justify-center gap-2.5 px-3.5 py-2.5 rounded-2xl border-2 transition-all duration-300 select-none ${b?"border-cyan-400 bg-gradient-to-br from-blue-900/80 via-cyan-900/50 to-blue-950 shadow-[0_0_24px_rgba(34,211,238,0.5)]":"border-blue-500/40 bg-[#0A0E18] shadow-lg"}`,children:[e.jsx(W,{src:"/favicon.svg",name:"Mapigate",color:"#38BDF8",size:"sm",fallback:e.jsx("span",{className:"material-symbols-outlined text-[18px] text-cyan-400",children:"graph_5"}),className:b?"shadow-[0_0_14px_rgba(34,211,238,0.7)] border-cyan-400":""}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-black tracking-wide text-white",children:"MAPIGATE"}),e.jsx("div",{className:"text-[9px] text-slate-400 font-mono",children:"Gateway"})]}),l>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded-full bg-cyan-400 text-black text-[10px] font-black animate-pulse",children:l})]})}),g.items.map(a=>e.jsx("foreignObject",{x:a.px-75,y:a.py-22,width:"150",height:"44",className:"overflow-visible pointer-events-auto",children:e.jsxs("div",{onClick:v=>{v.stopPropagation(),!N.current&&h(u=>u===a.id?null:a.id)},className:`flex items-center gap-2 px-2.5 py-1.5 rounded-xl border-2 transition-all duration-300 cursor-pointer select-none bg-[#0B0F19] ${a.isActive?"shadow-[0_0_18px_rgba(56,189,248,0.4)]":a.isFocused?"border-blue-500/70 bg-[#0F1626]":"border-[#1E293B] hover:border-slate-500"}`,style:{borderColor:a.isActive?a.meta.color:a.isFocused?"#3B82F6":void 0},children:[e.jsx(W,{src:a.meta.image,name:a.meta.name,color:a.meta.color,iconBg:a.meta.iconBg,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"text-xs font-bold block truncate",style:{color:a.isActive?a.meta.color:a.isFocused?"#93C5FD":"#E2E8F0"},title:a.meta.name,children:a.meta.name}),e.jsx("span",{className:"text-[9px] text-slate-500 font-mono block",children:"Upstream"})]}),a.isActive&&e.jsxs("span",{className:"relative flex h-2 w-2 ml-auto shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:a.meta.color}}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2",style:{backgroundColor:a.meta.color}})]})]})},`node-${a.id}`))]})})]})})]})},Ie=({data:t,period:m,loading:d})=>{const[h,c]=i.useState("tokens"),p=s=>h==="cost"?`$${s>=10?s.toFixed(0):s.toFixed(2)}`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}k`:String(s),x={tokens:{stroke:"#38BDF8",fill:"#0284C7",label:"Total Tokens"},requests:{stroke:"#A855F7",fill:"#7E22CE",label:"Requests"},cost:{stroke:"#F59E0B",fill:"#B45309",label:"Estimated Cost ($)"}}[h],j=t.reduce((s,r)=>s+(r[h]||0),0);return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:["Usage Trend",e.jsxs("span",{className:"text-xs font-normal text-slate-500",children:["(",m.toUpperCase(),")"]})]}),e.jsxs("span",{className:"text-xs text-slate-400 mt-0.5 block",children:["Aggregated ",x.label.toLowerCase(),":"," ",e.jsx("span",{className:"font-semibold text-slate-200",children:h==="cost"?`$${j.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`:j.toLocaleString("en-US")})]})]}),e.jsx("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:["tokens","requests","cost"].map(s=>e.jsx("button",{onClick:()=>c(s),className:`px-3 py-1.5 rounded-md font-semibold capitalize transition-all ${h===s?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:s},s))})]}),e.jsx("div",{className:"h-64 sm:h-72 w-full",children:d?e.jsx("div",{className:"h-full w-full flex items-center justify-center text-slate-500 text-sm",children:"Loading metrics..."}):t.length===0?e.jsx("div",{className:"h-full w-full flex items-center justify-center text-slate-500 text-sm",children:"No request activity recorded for this period."}):e.jsx(Ee,{width:"100%",height:"100%",children:e.jsxs(Le,{data:t,margin:{top:10,right:10,left:-10,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`gradient-${h}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:x.stroke,stopOpacity:.35}),e.jsx("stop",{offset:"95%",stopColor:x.stroke,stopOpacity:0})]})}),e.jsx(Re,{strokeDasharray:"3 3",stroke:"#1E293B",vertical:!1}),e.jsx(qe,{dataKey:"label",stroke:"#64748B",fontSize:11,tickLine:!1,axisLine:{stroke:"#1E293B"}}),e.jsx(Be,{stroke:"#64748B",fontSize:11,tickFormatter:p,tickLine:!1,axisLine:{stroke:"#1E293B"},width:45}),e.jsx($e,{content:({active:s,payload:r,label:S})=>{if(s&&r&&r.length){const N=r[0].payload;return e.jsxs("div",{className:"bg-[#0B0F19]/95 backdrop-blur-md border border-[#2A374F] rounded-lg p-3 text-xs shadow-xl min-w-[160px]",children:[e.jsx("p",{className:"font-bold text-slate-200 mb-1.5 border-b border-slate-800 pb-1",children:N.time||S}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center text-cyan-400",children:[e.jsx("span",{children:"Tokens:"}),e.jsx("span",{className:"font-mono font-semibold",children:N.tokens.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between items-center text-purple-400",children:[e.jsx("span",{children:"Requests:"}),e.jsx("span",{className:"font-mono font-semibold",children:N.requests.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between items-center text-amber-400",children:[e.jsx("span",{children:"Cost:"}),e.jsxs("span",{className:"font-mono font-semibold",children:["$",N.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4})]})]})]})]})}return null}}),e.jsx(Me,{type:"monotone",dataKey:h,stroke:x.stroke,strokeWidth:2.5,fillOpacity:1,fill:`url(#gradient-${h})`,dot:!1,activeDot:{r:5,fill:x.stroke,stroke:"#0E1320",strokeWidth:2}})]})})})]})},_e=({byModel:t})=>{const[m,d]=i.useState("tokens"),c=Object.entries(t||{}).map(([o,x])=>{const j=(x.promptTokens||0)+(x.completionTokens||0);return{key:o,name:x.rawModel||o,provider:x.provider||"default",requests:x.requests||0,totalTokens:j,promptTokens:x.promptTokens||0,completionTokens:x.completionTokens||0,cost:x.cost||0}}).sort((o,x)=>m==="tokens"?x.totalTokens-o.totalTokens:x.requests-o.requests).slice(0,5),p=c.length>0?m==="tokens"?c[0].totalTokens:c[0].requests:1;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs w-full h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx(ee,{className:"w-4 h-4 text-blue-400"}),"Top Models"]}),e.jsxs("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:[e.jsx("button",{onClick:()=>d("tokens"),className:`px-2.5 py-1 rounded-md font-semibold transition-all ${m==="tokens"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Tokens"}),e.jsx("button",{onClick:()=>d("requests"),className:`px-2.5 py-1 rounded-md font-semibold transition-all ${m==="requests"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Requests"})]})]}),c.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No model usage recorded yet."}):e.jsx("div",{className:"space-y-3.5",children:c.map((o,x)=>{const j=m==="tokens"?o.totalTokens:o.requests,s=p>0?Math.round(j/p*100):0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate max-w-[70%]",children:[e.jsx("span",{className:"w-4.5 h-4.5 rounded-sm bg-slate-800 text-slate-300 font-bold text-[10px] flex items-center justify-center shrink-0",children:x+1}),e.jsx("span",{className:"font-semibold text-slate-200 truncate",title:o.name,children:o.name}),e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-slate-800/80 text-slate-400 border border-slate-700/50 shrink-0",children:o.provider})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("span",{className:"font-mono font-bold text-slate-200",children:m==="tokens"?o.totalTokens.toLocaleString():o.requests.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-slate-500 ml-1",children:m==="tokens"?"tok":"req"})]})]}),e.jsx("div",{className:"w-full bg-[#151D2F] h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-cyan-400 h-full rounded-full transition-all duration-500",style:{width:`${Math.max(4,s)}%`}})})]},o.key)})})]})},Ke=({byProvider:t})=>{const m=Object.entries(t||{}).map(([p,o])=>{const x=(o.promptTokens||0)+(o.completionTokens||0);return{id:p,requests:o.requests||0,totalTokens:x,cost:o.cost||0}}),d=m.reduce((p,o)=>p+o.requests,0)||1,h=m.sort((p,o)=>o.requests-p.requests),c={antigravity:"#3B82F6",claude:"#F97316",anthropic:"#F97316",openai:"#10B981",github:"#6366F1",gemini:"#38BDF8",deepseek:"#8B5CF6",default:"#64748B"};return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs w-full h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-cyan-400"}),"By Provider"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:[h.length," ",h.length===1?"provider":"providers"," active"]})]}),h.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No provider activity recorded yet."}):e.jsx("div",{className:"space-y-3.5",children:h.map(p=>{const o=Math.round(p.requests/d*100),x=c[p.id.toLowerCase()]||c.default;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:x}}),e.jsx("span",{className:"font-semibold text-slate-200 uppercase tracking-wide truncate",children:p.id})]}),e.jsxs("div",{className:"flex items-center gap-3 text-right shrink-0",children:[e.jsxs("span",{className:"font-mono text-slate-400",children:[p.requests.toLocaleString()," reqs (",o,"%)"]}),e.jsxs("span",{className:"font-mono text-xs font-semibold text-slate-200",children:["$",p.cost.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})]})]})]}),e.jsx("div",{className:"w-full bg-[#151D2F] h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${Math.max(4,o)}%`,backgroundColor:x}})})]},p.id)})})]})},ze=({byProvider:t,byModel:m,byAccount:d,byApiKey:h})=>{const[c,p]=i.useState("model");let o=[];c==="provider"?o=Object.entries(t||{}).map(([s,r])=>({id:s,name:s.toUpperCase(),sublabel:"Provider Gateway",requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0})):c==="model"?o=Object.entries(m||{}).map(([s,r])=>({id:s,name:r.rawModel||s,sublabel:r.provider?`Provider: ${r.provider}`:void 0,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})):c==="account"?o=Object.entries(d||{}).map(([s,r])=>({id:s,name:r.accountName||r.accountId||s,sublabel:r.rawModel?`${r.rawModel} (${r.provider||"default"})`:void 0,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})):o=Object.entries(h||{}).map(([s,r])=>({id:s,name:r.apiKeyName||(s==="no_key"?"Direct / No Key":s),sublabel:s==="no_key"?"Unauthenticated / Local Ping":`Key ID: ${s}`,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})),o=o.filter(s=>s.promptTokens+s.completionTokens>0),o.sort((s,r)=>r.requests-s.requests);const x=s=>(s||0).toLocaleString("en-US"),j=s=>`$${(s||0).toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4})}`;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4 text-blue-400"}),e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:"Usage Breakdown"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["(",o.length," records)"]})]}),e.jsxs("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:[e.jsxs("span",{className:"px-2 text-slate-500 flex items-center gap-1",children:[e.jsx(je,{className:"w-3 h-3"})," Group:"]}),["model","provider","account","apiKey"].map(s=>e.jsx("button",{onClick:()=>p(s),className:`px-3 py-1.5 rounded-md font-semibold capitalize transition-all ${c===s?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:s==="apiKey"?"API Key":s},s))]})]}),o.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-sm",children:"No usage records found for this period."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-800 text-slate-400 uppercase text-[10px] tracking-wider",children:[e.jsx("th",{className:"py-2.5 px-3",children:"Name"}),e.jsx("th",{className:"py-2.5 px-3 text-right",children:"Requests"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-blue-400",children:"Input Tokens"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-cyan-400",children:"Cached"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-emerald-400",children:"Output Tokens"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-amber-400",children:"Est. Cost"}),e.jsx("th",{className:"py-2.5 px-3 text-right",children:"Last Used"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-800/60",children:o.map(s=>e.jsxs("tr",{className:"hover:bg-slate-800/25 transition-colors",children:[e.jsxs("td",{className:"py-2.5 px-3",children:[e.jsx("div",{className:"font-semibold text-slate-200",children:s.name}),s.sublabel&&e.jsx("div",{className:"text-[10px] text-slate-500 mt-0.5",children:s.sublabel})]}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono font-medium text-slate-300",children:x(s.requests)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-blue-400/90",children:x(s.promptTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-cyan-400/90",children:x(s.cachedTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-emerald-400/90",children:x(s.completionTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono font-semibold text-amber-400/90",children:j(s.cost)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-slate-400 text-[11px]",children:s.lastUsed?new Date(s.lastUsed).toLocaleDateString():"-"})]},s.id))})]})})]})},Ye=({detail:t,isOpen:m,onClose:d})=>{var T,k,C,E,y,n,g,l,b,a,v,u,f,w,B,$;const[h,c]=i.useState(!1),[p,o]=i.useState(null),[x,j]=i.useState(!1),[s,r]=i.useState("client"),{backdropProps:S}=Fe(d,!m);if(i.useEffect(()=>{if(!m)return;const R=A=>{A.key==="Escape"&&d()};document.addEventListener("keydown",R);const M=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=M}},[m,d]),!m||!t||typeof document>"u")return null;const N=(R,M)=>{navigator.clipboard.writeText(R),M==="id"?(c(!0),setTimeout(()=>c(!1),2e3)):(o(M),setTimeout(()=>o(null),2e3))},L=Number(t.status),O=L>=200&&L<300||t.status==="success"||t.status==="ok",F=L===429||t.status==="rate_limited",D=()=>F?e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30",children:"429 Rate Limit"}):O?e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",children:t.status==="success"||t.status==="ok"?"200 OK":`${t.status} OK`}):e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-red-500/20 text-red-400 border border-red-500/30",children:t.status||"500 Error"});return ie.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex justify-end bg-black/70 backdrop-blur-xs animate-rt-fade-in",...S,children:e.jsxs("div",{className:"w-full max-w-2xl sm:max-w-3xl h-full bg-[#0D121F] border-l border-[#1E293B] shadow-2xl flex flex-col text-slate-100 overflow-hidden animate-rt-slide-in-right",onClick:R=>R.stopPropagation(),children:[e.jsxs("div",{className:"p-4 sm:p-5 border-b border-[#1E293B] flex items-center justify-between bg-[#0A0E18]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[D(),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{children:t.model||"Unknown Model"}),t.provider&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-slate-800 text-slate-300 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-400 mt-0.5",children:[e.jsx("span",{className:"font-mono text-[11px] truncate max-w-[200px]",title:t.id,children:t.id}),e.jsx("button",{onClick:()=>N(t.id,"id"),className:"p-1 hover:text-white transition-colors",title:"Copy Request ID",children:h?e.jsx(J,{className:"w-3.5 h-3.5 text-emerald-400"}):e.jsx(V,{className:"w-3.5 h-3.5"})})]})]})]}),e.jsx("button",{onClick:d,className:"p-2 rounded-lg bg-slate-800/60 hover:bg-slate-700 text-slate-400 hover:text-white transition-colors",children:e.jsx(se,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-5 text-xs",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 bg-[#111726] border border-[#1E293B] rounded-xl p-3.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(ge,{className:"w-3 h-3"})," Latency"]}),e.jsx("span",{className:"font-mono text-sm font-bold text-slate-200 mt-1 block",children:((T=t.latency)==null?void 0:T.totalMs)!=null?`${t.latency.totalMs} ms`:"-"}),((k=t.latency)==null?void 0:k.ttftMs)!=null&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["TTFT: ",t.latency.ttftMs,"ms"]})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"})," Account"]}),e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-200 mt-1 block truncate",children:t.accountName||t.connectionId||"Default"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:t.provider||"-"})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"w-3 h-3"})," Client Tool"]}),e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-200 mt-1 block truncate",title:t.clientTool,children:t.clientTool||"unknown"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold",children:"Cost Est."}),e.jsxs("span",{className:"font-mono text-sm font-bold text-amber-400 mt-1 block",children:["$",t.cost!=null?t.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4}):"0.0000"]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl p-4",children:[e.jsxs("h4",{className:"text-xs font-bold uppercase tracking-wider text-slate-400 mb-3 flex items-center gap-1.5",children:[e.jsx(ee,{className:"w-3.5 h-3.5 text-blue-400"})," Token Breakdown"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-center",children:[e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Input"}),e.jsx("span",{className:"font-mono text-base font-bold text-blue-400 mt-1 block",children:(((C=t.tokens)==null?void 0:C.promptTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Cached"}),e.jsx("span",{className:"font-mono text-base font-bold text-cyan-400 mt-1 block",children:(((E=t.tokens)==null?void 0:E.cachedTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Output"}),e.jsx("span",{className:"font-mono text-base font-bold text-emerald-400 mt-1 block",children:(((y=t.tokens)==null?void 0:y.completionTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Tokens Saved"}),e.jsx("span",{className:"font-mono text-base font-bold text-purple-400 mt-1 block",children:(((n=t.tokens)==null?void 0:n.tokensSavedByRtk)||0).toLocaleString()})]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>j(!x),className:"w-full p-3.5 flex items-center justify-between text-left hover:bg-slate-800/40 transition-colors",children:[e.jsxs("span",{className:"font-bold text-xs text-slate-300 flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-400"}),"HTTP Headers (Sanitized)"]}),x?e.jsx(Ne,{className:"w-4 h-4 text-slate-400"}):e.jsx(ae,{className:"w-4 h-4 text-slate-400"})]}),x&&e.jsxs("div",{className:"p-3.5 border-t border-[#1E293B] space-y-3 bg-[#0B0F19]",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Client Inbound Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(((g=t.request)==null?void 0:g.headers)||{},null,2)})]}),((l=t.providerRequest)==null?void 0:l.headers)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Provider Outbound Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(t.providerRequest.headers,null,2)})]}),(((b=t.response)==null?void 0:b.headers)||((a=t.providerResponse)==null?void 0:a.headers))&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Response Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(((v=t.response)==null?void 0:v.headers)||((u=t.providerResponse)==null?void 0:u.headers),null,2)})]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-[#0B0F19] p-1 rounded-lg border border-slate-800",children:[e.jsx("button",{onClick:()=>r("client"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="client"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Client Request"}),e.jsx("button",{onClick:()=>r("providerReq"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="providerReq"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Provider Request"}),e.jsx("button",{onClick:()=>r("response"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="response"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Response Output"})]}),e.jsx("button",{onClick:()=>{var M,A,q,P;const R=s==="client"?(M=t.request)==null?void 0:M.body:s==="providerReq"?(A=t.providerRequest)==null?void 0:A.body:((q=t.response)==null?void 0:q.body)||((P=t.providerResponse)==null?void 0:P.body);N(JSON.stringify(R,null,2),s)},className:"px-2.5 py-1 rounded-md bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors text-xs",children:p===s?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3.5 h-3.5 text-emerald-400"}),e.jsx("span",{children:"Copied"})]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Copy JSON"})]})})]}),e.jsx("div",{className:"relative rounded-lg bg-[#070A11] border border-slate-800/80 p-3 max-h-96 overflow-y-auto",children:e.jsx("pre",{className:"font-mono text-[11px] text-slate-300 whitespace-pre-wrap leading-relaxed",children:JSON.stringify(s==="client"?((f=t.request)==null?void 0:f.body)||{message:"No request body captured"}:s==="providerReq"?((w=t.providerRequest)==null?void 0:w.body)||{message:"Same as client or pass-through"}:((B=t.response)==null?void 0:B.body)||(($=t.providerResponse)==null?void 0:$.body)||{message:"Stream completed successfully"},null,2)})})]})]})]})}),document.body)},Ge=()=>{const[t,m]=i.useState(null),[d,h]=i.useState(!1),[c,p]=i.useState(1),[o,x]=i.useState(20),[j,s]=i.useState(""),[r,S]=i.useState("all"),[N,L]=i.useState("all"),[O,F]=i.useState([]),[D,T]=i.useState(null),[k,C]=i.useState(!1),E=i.useCallback(async()=>{try{const l=await fetch("/api/usage/providers");if(l.ok){const b=await l.json();Array.isArray(b)&&F(b)}}catch{}},[]),y=i.useCallback(async()=>{h(!0);try{const l=new URLSearchParams;l.set("page",String(c)),l.set("pageSize",String(o)),r!=="all"&&l.set("provider",r),N!=="all"&&l.set("status",N),j.trim()&&l.set("search",j.trim());const b=await fetch(`/api/usage/request-details?${l.toString()}`);if(b.ok){const a=await b.json();m(a)}}catch(l){console.error("Failed to fetch request details:",l)}finally{h(!1)}},[c,o,r,N,j]);i.useEffect(()=>{E()},[E]),i.useEffect(()=>{y()},[y]);const n=async l=>{try{const b=await fetch(`/api/usage/request-details/${l.id}`);if(b.ok){const a=await b.json();T(a)}else T(l)}catch{T(l)}C(!0)},g=l=>{const b=String(l||"");return b==="200"||b==="success"||b==="ok"?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",children:"200 OK"}):b==="429"||b==="rate_limited"?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30",children:"429"}):e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-red-500/20 text-red-400 border border-red-500/30",children:b||"500"})};return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-3.5 flex flex-wrap items-center justify-between gap-3 shadow-xs",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 flex-1 min-w-[280px]",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[e.jsx(we,{className:"w-4 h-4 text-slate-500 absolute left-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"text",placeholder:"Search by model, ID, provider, tool...",value:j,onChange:l=>{s(l.target.value),p(1)},className:"w-full pl-9 pr-8 py-1.5 rounded-lg bg-[#070A11] border border-slate-800 text-xs text-slate-200 placeholder-slate-500 focus:outline-hidden focus:border-blue-500"}),j&&e.jsx("button",{type:"button",onClick:()=>{s(""),p(1)},className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear search",children:e.jsx(se,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(ye,{className:"w-3.5 h-3.5 text-slate-500"}),e.jsx(Y,{value:r,onChange:l=>{S(l),p(1)},options:[{value:"all",label:"All Providers"},...O.map(l=>({value:l,label:l.toUpperCase()}))],className:"min-w-[140px]"})]}),e.jsx("div",{className:"flex items-center text-xs",children:e.jsx(Y,{value:N,onChange:l=>{L(l),p(1)},options:[{value:"all",label:"All Statuses"},{value:"200",label:"200 OK"},{value:"429",label:"429 Rate Limit"},{value:"500",label:"500 Error"}],className:"min-w-[130px]"})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>y(),disabled:d,className:"p-1.5 rounded-lg bg-[#151D2F] border border-slate-700/60 text-slate-300 hover:text-white hover:bg-slate-800 transition-colors",title:"Refresh logs",children:e.jsx(le,{className:`w-4 h-4 ${d?"animate-spin text-blue-400":""}`})}),e.jsx("span",{className:"text-xs text-slate-400 font-mono",children:t!=null&&t.pagination?`${t.pagination.totalItems} records`:""})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl overflow-hidden shadow-xs",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-800 text-slate-400 uppercase text-[10px] tracking-wider bg-[#0A0E18]",children:[e.jsx("th",{className:"py-3 px-3.5",children:"Status"}),e.jsx("th",{className:"py-3 px-3.5",children:"Time"}),e.jsx("th",{className:"py-3 px-3.5",children:"Model"}),e.jsx("th",{className:"py-3 px-3.5",children:"Provider"}),e.jsx("th",{className:"py-3 px-3.5",children:"Tool / Client"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-blue-400",children:"In Tok"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-emerald-400",children:"Out Tok"}),e.jsx("th",{className:"py-3 px-3.5 text-right",children:"Latency"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-amber-400",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-800/60",children:d&&(!(t!=null&&t.details)||t.details.length===0)?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-12 text-center text-slate-500",children:"Loading request records..."})}):!(t!=null&&t.details)||t.details.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-12 text-center text-slate-500",children:"No matching request logs found."})}):t.details.map(l=>{var b,a,v;return e.jsxs("tr",{onClick:()=>n(l),className:"hover:bg-blue-600/10 cursor-pointer transition-colors group",children:[e.jsx("td",{className:"py-2.5 px-3.5",children:g(l.status)}),e.jsx("td",{className:"py-2.5 px-3.5 font-mono text-[11px] text-slate-400 whitespace-nowrap",children:new Date(l.timestamp).toLocaleTimeString()}),e.jsx("td",{className:"py-2.5 px-3.5 font-semibold text-slate-200 group-hover:text-blue-400 transition-colors truncate max-w-[180px]",children:l.model||"unknown"}),e.jsx("td",{className:"py-2.5 px-3.5",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-slate-800 text-slate-300 font-mono",children:l.provider||"-"})}),e.jsx("td",{className:"py-2.5 px-3.5 font-mono text-slate-400 truncate max-w-[140px]",title:l.clientTool,children:l.clientTool||"-"}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-blue-400/90",children:(((b=l.tokens)==null?void 0:b.promptTokens)||0).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-emerald-400/90",children:(((a=l.tokens)==null?void 0:a.completionTokens)||0).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-slate-300",children:((v=l.latency)==null?void 0:v.totalMs)!=null?`${l.latency.totalMs}ms`:"-"}),e.jsxs("td",{className:"py-2.5 px-3.5 text-right font-mono font-semibold text-amber-400/90",children:["$",l.cost!=null?l.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4}):"0.0000"]})]},l.id)})})]})}),(t==null?void 0:t.pagination)&&t.pagination.totalPages>1&&e.jsxs("div",{className:"p-3 border-t border-slate-800 bg-[#0A0E18] flex items-center justify-between text-xs text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Rows per page:"}),e.jsx(Y,{value:String(o),onChange:l=>{x(Number(l)),p(1)},options:[{value:"10",label:"10"},{value:"20",label:"20"},{value:"50",label:"50"}],className:"w-20"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{children:["Page ",e.jsx("span",{className:"font-bold text-slate-200",children:t.pagination.page})," of"," ",e.jsx("span",{className:"font-bold text-slate-200",children:t.pagination.totalPages})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{disabled:!t.pagination.hasPrev,onClick:()=>p(l=>Math.max(1,l-1)),className:"p-1.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ke,{className:"w-4 h-4"})}),e.jsx("button",{disabled:!t.pagination.hasNext,onClick:()=>p(l=>l+1),className:"p-1.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ae,{className:"w-4 h-4"})})]})]})]})]}),e.jsx(Ye,{detail:D,isOpen:k,onClose:()=>C(!1)})]})},et=()=>{const[t,m]=i.useState("overview"),[d,h]=i.useState("7d"),[c,p]=i.useState(null),[o,x]=i.useState([]),[j,s]=i.useState([]),[r,S]=i.useState([]),[N,L]=i.useState(!0),[O,F]=i.useState(!0),[D,T]=i.useState(!1),k=i.useRef(null),C=i.useCallback(async n=>{try{L(!0);const g=await fetch(`/api/usage/stats?period=${n}`);if(g.ok){const l=await g.json();p(l),l.activeRequests&&s(l.activeRequests),l.recentRequests&&S(l.recentRequests)}}catch(g){console.error("Failed to fetch stats:",g)}finally{L(!1)}},[]),E=i.useCallback(async n=>{try{F(!0);const g=await fetch(`/api/usage/chart?period=${n}`);if(g.ok){const l=await g.json();x(l)}}catch(g){console.error("Failed to fetch chart data:",g)}finally{F(!1)}},[]);i.useEffect(()=>{C(d),E(d)},[d,C,E]),i.useEffect(()=>{let n=null,g=null;const l=()=>{try{const b=De.getToken(),a=`/api/usage/stream?period=${encodeURIComponent(d)}`,v=b?`${a}&token=${encodeURIComponent(b)}`:a;n=new EventSource(v),k.current=n,n.onopen=()=>{T(!0)},n.addEventListener("stats",u=>{try{const f=JSON.parse(u.data);p(f),f.activeRequests&&s(f.activeRequests),f.recentRequests&&S(f.recentRequests)}catch{}}),n.addEventListener("pending",u=>{try{const f=JSON.parse(u.data);f.activeRequests&&s(f.activeRequests)}catch{}}),n.onerror=()=>{T(!1),n==null||n.close(),k.current=null,g=setTimeout(l,5e3)}}catch{T(!1)}};return l(),()=>{g&&clearTimeout(g),n&&n.close(),k.current=null}},[d]);const y=Object.keys((c==null?void 0:c.byProvider)||{});return e.jsxs("div",{className:"w-full min-w-0 space-y-6 px-2 sm:px-4 lg:px-6 pb-20 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-[#0B0F19] border border-[#1E293B] rounded-2xl p-2 sm:p-2.5 shadow-sm",children:[e.jsxs("div",{className:"bg-[#151C2C] p-1 rounded-xl border border-[#243048] flex items-center",children:[e.jsxs("button",{onClick:()=>m("overview"),className:`px-3.5 py-1.5 rounded-lg text-xs font-bold flex items-center gap-2 transition-all ${t==="overview"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:[e.jsx(Ce,{className:"w-3.5 h-3.5"}),"Overview"]}),e.jsxs("button",{onClick:()=>m("details"),className:`px-3.5 py-1.5 rounded-lg text-xs font-bold flex items-center gap-2 transition-all ${t==="details"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:[e.jsx(Se,{className:"w-3.5 h-3.5"}),"Details (Inspector)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-[#151C2C] border border-slate-800 text-[11px] text-slate-400",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${D?"bg-emerald-400 shadow-[0_0_8px_#34d399]":"bg-amber-400"}`}),e.jsx("span",{className:"font-mono text-[10px]",children:D?"LIVE TELEMETRY":"POLLING"})]}),t==="overview"&&e.jsx("div",{className:"bg-[#151C2C] p-1 rounded-xl border border-[#243048] flex items-center text-xs",children:["today","24h","7d","30d","60d","90d","all"].map(n=>e.jsx("button",{onClick:()=>h(n),className:`px-2.5 sm:px-3 py-1 rounded-lg uppercase font-semibold transition-all ${d===n?"bg-blue-600/30 text-blue-400 border border-blue-500/40 shadow-xs":"text-slate-400 hover:text-white"}`,children:n},n))}),e.jsx("button",{onClick:()=>{C(d),E(d)},className:"p-2 rounded-xl bg-[#151C2C] border border-[#243048] text-slate-300 hover:text-white hover:bg-slate-800 transition-colors",title:"Refresh statistics",children:e.jsx(le,{className:`w-3.5 h-3.5 ${N?"animate-spin text-blue-400":""}`})})]})]}),t==="overview"&&e.jsxs("div",{className:"space-y-6 w-full",children:[e.jsx(Ae,{stats:c,loading:N}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-5 w-full",children:[e.jsx("div",{className:"lg:col-span-7 w-full flex",children:e.jsx(Ue,{providers:y,activeRequests:j})}),e.jsxs("div",{className:"lg:col-span-5 w-full bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B] shrink-0",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-200 uppercase tracking-wider flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-blue-400"}),"Recent Requests"]}),e.jsxs("span",{className:"text-[10px] text-cyan-400 font-mono bg-cyan-500/10 border border-cyan-500/20 px-2 py-0.5 rounded-full flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-cyan-400 animate-pulse"}),"Live Stream"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto mt-2 min-h-[220px] max-h-[300px] pr-1",children:r.length===0?e.jsx("div",{className:"py-16 text-center text-slate-500 text-xs",children:"No recent proxy requests yet. Call /v1/messages or /v1/chat/completions to see live logs."}):e.jsxs("table",{className:"w-full text-left text-xs font-mono border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-slate-500 text-[10px] uppercase border-b border-[#1E293B]",children:[e.jsx("th",{className:"pb-2 font-semibold pr-2",children:"Model / Provider"}),e.jsx("th",{className:"pb-2 font-semibold text-right px-2 w-[125px]",children:"In / Out"}),e.jsx("th",{className:"pb-2 font-semibold text-right pl-2 pr-2 w-[95px]",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-[#1E293B]/50",children:r.slice(0,15).map((n,g)=>{const l=n.status==="success"||n.status==="ok",b=n.requestedModel&&n.requestedModel!==n.model?`${n.model} (via ${n.requestedModel}) · ${n.provider||"unknown"}`:`${n.model} · ${n.provider||"unknown"}`;return e.jsxs("tr",{className:"hover:bg-slate-800/30 transition-colors",children:[e.jsx("td",{className:"py-2 pr-2 overflow-hidden",title:b,children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${l?"bg-emerald-400":"bg-red-400"}`}),e.jsx("span",{className:"text-slate-200 text-xs truncate font-medium",children:n.model}),n.provider&&e.jsx("span",{className:"text-[9px] text-slate-400 font-mono uppercase px-1 py-0.5 rounded bg-slate-800 border border-slate-700/50 shrink-0",children:n.provider})]})}),e.jsxs("td",{className:"py-2 text-right whitespace-nowrap px-2 text-[11px] w-[125px]",children:[e.jsxs("span",{className:"text-blue-400",children:[n.promptTokens.toLocaleString(),"↑"]})," ",e.jsxs("span",{className:"text-emerald-400",children:[n.completionTokens.toLocaleString(),"↓"]})]}),e.jsx("td",{className:"py-2 text-right text-[10px] text-slate-400 whitespace-nowrap pl-2 pr-2 w-[95px]",children:typeof n.timestamp=="number"?new Date(n.timestamp).toLocaleTimeString():new Date(String(n.timestamp)).toLocaleTimeString()})]},n.id||g)})})]})})]})]}),e.jsx(Ie,{data:o,period:d,loading:O}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5 w-full",children:[e.jsx(_e,{byModel:(c==null?void 0:c.byModel)||{}}),e.jsx(Ke,{byProvider:(c==null?void 0:c.byProvider)||{}})]}),e.jsx(ze,{byProvider:(c==null?void 0:c.byProvider)||{},byModel:(c==null?void 0:c.byModel)||{},byAccount:(c==null?void 0:c.byAccount)||{},byApiKey:(c==null?void 0:c.byApiKey)||{}})]}),t==="details"&&e.jsx(Ge,{})]})};export{et as UsageTab};
|
|
1
|
+
import{j as e,r as i,a as ie}from"./vendor-BcOI2aZ9.js";import{Z as ce,A as de,D as xe,a as me,S as Q,b as pe,N as Z,c as he,d as ue,R as be,C as ee,e as te,T as fe,L as je,f as J,g as V,X as se,h as ge,i as ve,j as Ne,k as ae,l as we,F as ye,m as le,n as ke,o as Ce,p as Se,q as Te}from"./lucide-Cc35htxl.js";import{T as W}from"./ToolIcon-Cp4gSgFt.js";import{g as X}from"./metadataRegistry-7DDoxaR3.js";import{R as Ee,A as Le,C as Re,X as qe,Y as Be,T as $e,a as Me}from"./recharts-X4_nm3od.js";import{a as Fe,A as De}from"./index-BdD7LHGu.js";import{S as Y}from"./Select-BNRH8LIG.js";const Ae=({stats:t,loading:m})=>{const d=r=>(r||0).toLocaleString("en-US"),h=r=>`$${(r||0).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,c=(t==null?void 0:t.totalRequests)??0,p=(t==null?void 0:t.totalPromptTokens)??0,o=(t==null?void 0:t.totalCachedTokens)??0,x=(t==null?void 0:t.totalCompletionTokens)??0,j=(t==null?void 0:t.totalCost)??0,s=(t==null?void 0:t.totalTokensSaved)??0;return e.jsxs("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-blue-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-slate-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Total Requests"}),e.jsx(ce,{className:"w-4 h-4 text-blue-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-white truncate",title:d(c),children:m?"...":d(c)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"API Invocations"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-blue-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-blue-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Input Tokens"}),e.jsx(de,{className:"w-4 h-4 text-blue-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-blue-400 truncate",title:d(p),children:m?"...":d(p)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Prompt & context"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-cyan-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-cyan-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Cached Tokens"}),e.jsx(xe,{className:"w-4 h-4 text-cyan-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-cyan-400 truncate",title:d(o),children:m?"...":d(o)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Prompt cache hits"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-emerald-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-emerald-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Output Tokens"}),e.jsx(me,{className:"w-4 h-4 text-emerald-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-emerald-400 truncate",title:d(x),children:m?"...":d(x)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Generated output"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-purple-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-purple-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Tokens Saved"}),e.jsx(Q,{className:"w-4 h-4 text-purple-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-purple-400 truncate",title:d(s),children:m?"...":d(s)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Token Saver optimized"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-amber-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Est. Cost"}),e.jsx(pe,{className:"w-4 h-4 text-amber-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-amber-400 truncate",title:h(j),children:m?"...":`~${h(j)}`}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",title:"Estimated, not actual billing",children:"Estimated, not actual"})]})]})]})},Pe={"github-copilot":"github",copilot:"github","devin-cli":"devin","devin-desktop":"devin","devin-cli-agentic":"devin",dvd:"devin"};function H(t){if(!t)return{id:"unknown",name:"Unknown",color:"#64748B"};const m=t.toLowerCase().trim(),d=Pe[m]||m,h=X(d)||X(m);return h?{id:h.id,name:h.name,color:h.color||"#64748B",image:h.image,iconBg:h.iconBg}:{id:t,name:t.charAt(0).toUpperCase()+t.slice(1),color:"#64748B"}}const Oe=5,Ue=({providers:t=[],activeRequests:m=[]})=>{const[d,h]=i.useState(null),[c,p]=i.useState(1),[o,x]=i.useState({x:0,y:0}),[j,s]=i.useState(!1),r=i.useRef({x:0,y:0}),S=i.useRef({x:0,y:0}),N=i.useRef(!1),L=i.useRef(null),O=i.useCallback(()=>{p(1),x({x:0,y:0})},[]),F=i.useCallback(()=>{p(a=>Math.min(2.5,+(a+.2).toFixed(2)))},[]),D=i.useCallback(()=>{p(a=>Math.max(.4,+(a-.2).toFixed(2)))},[]);i.useEffect(()=>{const a=L.current;if(!a)return;const v=u=>{if(!u.ctrlKey&&!u.metaKey)return;u.preventDefault();const f=u.deltaY<0?1.1:.9;p(w=>{const B=+(w*f).toFixed(2);return Math.min(2.5,Math.max(.4,B))})};return a.addEventListener("wheel",v,{passive:!1}),()=>{a.removeEventListener("wheel",v)}},[]);const T=i.useCallback(a=>{a.button===0&&(s(!0),N.current=!1,r.current={x:a.clientX,y:a.clientY},S.current={...o})},[o]);i.useEffect(()=>{const a=u=>{if(!j)return;const f=u.clientX-r.current.x,w=u.clientY-r.current.y;(Math.abs(f)>3||Math.abs(w)>3)&&(N.current=!0),x({x:S.current.x+f,y:S.current.y+w})},v=()=>{s(!1)};return j&&(window.addEventListener("mousemove",a),window.addEventListener("mouseup",v)),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",v)}},[j]);const k=i.useMemo(()=>{const a=new Set;for(const v of m)if(v.provider){const u=v.provider.toLowerCase();a.add(u);const f=H(u);a.add(f.id.toLowerCase())}return a},[m]),{displayProviders:C,totalCount:E}=i.useMemo(()=>{const a=[...t];for(const f of m)f.provider&&a.push(f.provider);const u=Array.from(new Set(a)).filter(f=>{if(!f)return!1;const w=f.toLowerCase().trim();return w!=="unknown"&&w!=="null"&&w!=="undefined"}).sort((f,w)=>{const B=k.has(f.toLowerCase()),$=k.has(w.toLowerCase());return B&&!$?-1:!B&&$?1:f.localeCompare(w)});return{displayProviders:u.slice(0,10),totalCount:u.length}},[t,m,k]),y=400,n=220,g=i.useMemo(()=>{const a=C.length;if(a===0)return{items:[]};const v=Math.min(300,160+a*15),u=Math.min(150,90+a*8);return{items:C.map((w,B)=>{const $=H(w),R=k.has(w.toLowerCase())||k.has($.id.toLowerCase()),M=(d==null?void 0:d.toLowerCase())===w.toLowerCase()||(d==null?void 0:d.toLowerCase())===$.id.toLowerCase(),A=-Math.PI/2+2*Math.PI*B/a,q=y+v*Math.cos(A),P=n+u*Math.sin(A),re=Math.abs(q-y)<20,U=P<n?-1:1,oe=q<y?-1:1;let I,_,K,z;if(re)I=y,_=n+U*Math.min(u*.5,50),K=q,z=P-U*Math.min(u*.5,50);else{const G=Math.abs(Math.sin(A))>.35;I=G?y:y+(q-y)*.5,_=G?n+U*Math.min(u*.7,75):n,K=q-oe*Math.min(v*.45,60),z=P}const ne=`M ${y} ${n} C ${I.toFixed(1)} ${_.toFixed(1)}, ${K.toFixed(1)} ${z.toFixed(1)}, ${q.toFixed(1)} ${P.toFixed(1)}`;return{id:w,meta:$,isActive:R,isFocused:M,px:q,py:P,pathData:ne}})}},[C,k,d]),l=m.length,b=l>0;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-cyan-400"}),e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:"Active Routing Topology"}),e.jsx("span",{className:"text-xs text-slate-500",children:E>10?`(Top 10 of ${E} Mesh)`:"(Real-time Mesh)"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center bg-[#070A11] border border-[#1E293B] rounded-lg p-0.5 mr-1",title:"Ctrl + Scroll or use buttons to Zoom",children:[e.jsx("button",{type:"button",onClick:F,className:"p-1 hover:text-white text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer",title:"Zoom In","aria-label":"Zoom In",children:e.jsx(he,{className:"w-3.5 h-3.5"})}),e.jsxs("span",{className:"px-1.5 text-[10px] font-mono text-slate-400 select-none min-w-[34px] text-center",children:[Math.round(c*100),"%"]}),e.jsx("button",{type:"button",onClick:D,className:"p-1 hover:text-white text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer",title:"Zoom Out","aria-label":"Zoom Out",children:e.jsx(ue,{className:"w-3.5 h-3.5"})}),(c!==1||o.x!==0||o.y!==0)&&e.jsx("button",{type:"button",onClick:O,className:"p-1 hover:text-cyan-400 text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer ml-0.5 border-l border-[#1E293B]",title:"Reset View","aria-label":"Reset View",children:e.jsx(be,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-400",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-slate-600"}),e.jsx("span",{children:"Idle"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-cyan-400 font-semibold",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-cyan-400 animate-ping"}),e.jsx("span",{children:"Active Stream"})]})]})]}),e.jsx("div",{ref:L,onMouseDown:T,className:`relative h-72 sm:h-80 w-full rounded-lg overflow-hidden bg-[#070A11] border border-[#162032] flex items-center justify-center select-none ${j?"cursor-grabbing":"cursor-grab"}`,children:C.length===0?e.jsxs("div",{className:"text-center p-6 text-slate-500 text-xs sm:text-sm",children:[e.jsx(Z,{className:"w-8 h-8 text-slate-600 mx-auto mb-2 opacity-60"}),e.jsx("p",{children:"No upstream provider traffic recorded yet"})]}):e.jsxs("div",{className:"relative w-full h-full will-change-transform",style:{transform:`translate(${o.x}px, ${o.y}px) scale(${c})`,transformOrigin:"center center",transition:j?"none":"transform 0.15s ease-out"},children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full pointer-events-none",viewBox:"0 0 800 440",preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"plasma-glow",x:"-30%",y:"-30%",width:"160%",height:"160%",children:[e.jsx("feGaussianBlur",{stdDeviation:"3.5",result:"blur"}),e.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]})}),g.items.map(a=>a.isActive?e.jsxs("g",{children:[e.jsx("path",{d:a.pathData,fill:"none",stroke:"#22d3ee",strokeWidth:"6",strokeOpacity:"0.25",strokeLinecap:"round",filter:"url(#plasma-glow)"}),e.jsx("path",{d:a.pathData,fill:"none",stroke:"#38bdf8",strokeWidth:"2.5",strokeOpacity:"0.85",strokeLinecap:"round"}),e.jsx("path",{d:a.pathData,fill:"none",stroke:"#ffffff",strokeWidth:"1.2",strokeLinecap:"round"}),Array.from({length:Oe},(v,u)=>e.jsx("circle",{r:u%2===0?3.5:2,fill:u%2===0?"#22d3ee":"#ffffff",opacity:"0.9",children:e.jsx("animateMotion",{dur:`${.8+u*.15}s`,repeatCount:"indefinite",path:a.pathData,begin:`${u*.12}s`})},`orb-${a.id}-${u}`))]},`edge-active-${a.id}`):e.jsx("path",{d:a.pathData,fill:"none",stroke:"#1E293B",strokeWidth:"1.5",strokeDasharray:"4 5",strokeLinecap:"round"},`edge-${a.id}`))]}),e.jsx("div",{className:"absolute inset-0 pointer-events-none",children:e.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 800 440",preserveAspectRatio:"xMidYMid meet",children:[e.jsx("foreignObject",{x:y-80,y:n-26,width:"160",height:"54",className:"overflow-visible pointer-events-auto",children:e.jsxs("div",{className:`flex items-center justify-center gap-2.5 px-3.5 py-2.5 rounded-2xl border-2 transition-all duration-300 select-none ${b?"border-cyan-400 bg-gradient-to-br from-blue-900/80 via-cyan-900/50 to-blue-950 shadow-[0_0_24px_rgba(34,211,238,0.5)]":"border-blue-500/40 bg-[#0A0E18] shadow-lg"}`,children:[e.jsx(W,{src:"/favicon.svg",name:"Mapigate",color:"#38BDF8",size:"sm",fallback:e.jsx("span",{className:"material-symbols-outlined text-[18px] text-cyan-400",children:"graph_5"}),className:b?"shadow-[0_0_14px_rgba(34,211,238,0.7)] border-cyan-400":""}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-black tracking-wide text-white",children:"MAPIGATE"}),e.jsx("div",{className:"text-[9px] text-slate-400 font-mono",children:"Gateway"})]}),l>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded-full bg-cyan-400 text-black text-[10px] font-black animate-pulse",children:l})]})}),g.items.map(a=>e.jsx("foreignObject",{x:a.px-75,y:a.py-22,width:"150",height:"44",className:"overflow-visible pointer-events-auto",children:e.jsxs("div",{onClick:v=>{v.stopPropagation(),!N.current&&h(u=>u===a.id?null:a.id)},className:`flex items-center gap-2 px-2.5 py-1.5 rounded-xl border-2 transition-all duration-300 cursor-pointer select-none bg-[#0B0F19] ${a.isActive?"shadow-[0_0_18px_rgba(56,189,248,0.4)]":a.isFocused?"border-blue-500/70 bg-[#0F1626]":"border-[#1E293B] hover:border-slate-500"}`,style:{borderColor:a.isActive?a.meta.color:a.isFocused?"#3B82F6":void 0},children:[e.jsx(W,{src:a.meta.image,name:a.meta.name,color:a.meta.color,iconBg:a.meta.iconBg,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"text-xs font-bold block truncate",style:{color:a.isActive?a.meta.color:a.isFocused?"#93C5FD":"#E2E8F0"},title:a.meta.name,children:a.meta.name}),e.jsx("span",{className:"text-[9px] text-slate-500 font-mono block",children:"Upstream"})]}),a.isActive&&e.jsxs("span",{className:"relative flex h-2 w-2 ml-auto shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:a.meta.color}}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2",style:{backgroundColor:a.meta.color}})]})]})},`node-${a.id}`))]})})]})})]})},Ie=({data:t,period:m,loading:d})=>{const[h,c]=i.useState("tokens"),p=s=>h==="cost"?`$${s>=10?s.toFixed(0):s.toFixed(2)}`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}k`:String(s),x={tokens:{stroke:"#38BDF8",fill:"#0284C7",label:"Total Tokens"},requests:{stroke:"#A855F7",fill:"#7E22CE",label:"Requests"},cost:{stroke:"#F59E0B",fill:"#B45309",label:"Estimated Cost ($)"}}[h],j=t.reduce((s,r)=>s+(r[h]||0),0);return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:["Usage Trend",e.jsxs("span",{className:"text-xs font-normal text-slate-500",children:["(",m.toUpperCase(),")"]})]}),e.jsxs("span",{className:"text-xs text-slate-400 mt-0.5 block",children:["Aggregated ",x.label.toLowerCase(),":"," ",e.jsx("span",{className:"font-semibold text-slate-200",children:h==="cost"?`$${j.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`:j.toLocaleString("en-US")})]})]}),e.jsx("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:["tokens","requests","cost"].map(s=>e.jsx("button",{onClick:()=>c(s),className:`px-3 py-1.5 rounded-md font-semibold capitalize transition-all ${h===s?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:s},s))})]}),e.jsx("div",{className:"h-64 sm:h-72 w-full",children:d?e.jsx("div",{className:"h-full w-full flex items-center justify-center text-slate-500 text-sm",children:"Loading metrics..."}):t.length===0?e.jsx("div",{className:"h-full w-full flex items-center justify-center text-slate-500 text-sm",children:"No request activity recorded for this period."}):e.jsx(Ee,{width:"100%",height:"100%",children:e.jsxs(Le,{data:t,margin:{top:10,right:10,left:-10,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`gradient-${h}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:x.stroke,stopOpacity:.35}),e.jsx("stop",{offset:"95%",stopColor:x.stroke,stopOpacity:0})]})}),e.jsx(Re,{strokeDasharray:"3 3",stroke:"#1E293B",vertical:!1}),e.jsx(qe,{dataKey:"label",stroke:"#64748B",fontSize:11,tickLine:!1,axisLine:{stroke:"#1E293B"}}),e.jsx(Be,{stroke:"#64748B",fontSize:11,tickFormatter:p,tickLine:!1,axisLine:{stroke:"#1E293B"},width:45}),e.jsx($e,{content:({active:s,payload:r,label:S})=>{if(s&&r&&r.length){const N=r[0].payload;return e.jsxs("div",{className:"bg-[#0B0F19]/95 backdrop-blur-md border border-[#2A374F] rounded-lg p-3 text-xs shadow-xl min-w-[160px]",children:[e.jsx("p",{className:"font-bold text-slate-200 mb-1.5 border-b border-slate-800 pb-1",children:N.time||S}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center text-cyan-400",children:[e.jsx("span",{children:"Tokens:"}),e.jsx("span",{className:"font-mono font-semibold",children:N.tokens.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between items-center text-purple-400",children:[e.jsx("span",{children:"Requests:"}),e.jsx("span",{className:"font-mono font-semibold",children:N.requests.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between items-center text-amber-400",children:[e.jsx("span",{children:"Cost:"}),e.jsxs("span",{className:"font-mono font-semibold",children:["$",N.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4})]})]})]})]})}return null}}),e.jsx(Me,{type:"monotone",dataKey:h,stroke:x.stroke,strokeWidth:2.5,fillOpacity:1,fill:`url(#gradient-${h})`,dot:!1,activeDot:{r:5,fill:x.stroke,stroke:"#0E1320",strokeWidth:2}})]})})})]})},_e=({byModel:t})=>{const[m,d]=i.useState("tokens"),c=Object.entries(t||{}).map(([o,x])=>{const j=(x.promptTokens||0)+(x.completionTokens||0);return{key:o,name:x.rawModel||o,provider:x.provider||"default",requests:x.requests||0,totalTokens:j,promptTokens:x.promptTokens||0,completionTokens:x.completionTokens||0,cost:x.cost||0}}).sort((o,x)=>m==="tokens"?x.totalTokens-o.totalTokens:x.requests-o.requests).slice(0,5),p=c.length>0?m==="tokens"?c[0].totalTokens:c[0].requests:1;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs w-full h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx(ee,{className:"w-4 h-4 text-blue-400"}),"Top Models"]}),e.jsxs("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:[e.jsx("button",{onClick:()=>d("tokens"),className:`px-2.5 py-1 rounded-md font-semibold transition-all ${m==="tokens"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Tokens"}),e.jsx("button",{onClick:()=>d("requests"),className:`px-2.5 py-1 rounded-md font-semibold transition-all ${m==="requests"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Requests"})]})]}),c.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No model usage recorded yet."}):e.jsx("div",{className:"space-y-3.5",children:c.map((o,x)=>{const j=m==="tokens"?o.totalTokens:o.requests,s=p>0?Math.round(j/p*100):0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate max-w-[70%]",children:[e.jsx("span",{className:"w-4.5 h-4.5 rounded-sm bg-slate-800 text-slate-300 font-bold text-[10px] flex items-center justify-center shrink-0",children:x+1}),e.jsx("span",{className:"font-semibold text-slate-200 truncate",title:o.name,children:o.name}),e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-slate-800/80 text-slate-400 border border-slate-700/50 shrink-0",children:o.provider})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("span",{className:"font-mono font-bold text-slate-200",children:m==="tokens"?o.totalTokens.toLocaleString():o.requests.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-slate-500 ml-1",children:m==="tokens"?"tok":"req"})]})]}),e.jsx("div",{className:"w-full bg-[#151D2F] h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-cyan-400 h-full rounded-full transition-all duration-500",style:{width:`${Math.max(4,s)}%`}})})]},o.key)})})]})},Ke=({byProvider:t})=>{const m=Object.entries(t||{}).map(([p,o])=>{const x=(o.promptTokens||0)+(o.completionTokens||0);return{id:p,requests:o.requests||0,totalTokens:x,cost:o.cost||0}}),d=m.reduce((p,o)=>p+o.requests,0)||1,h=m.sort((p,o)=>o.requests-p.requests),c={antigravity:"#3B82F6",claude:"#F97316",anthropic:"#F97316",openai:"#10B981",github:"#6366F1",gemini:"#38BDF8",deepseek:"#8B5CF6",default:"#64748B"};return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs w-full h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-cyan-400"}),"By Provider"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:[h.length," ",h.length===1?"provider":"providers"," active"]})]}),h.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No provider activity recorded yet."}):e.jsx("div",{className:"space-y-3.5",children:h.map(p=>{const o=Math.round(p.requests/d*100),x=c[p.id.toLowerCase()]||c.default;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:x}}),e.jsx("span",{className:"font-semibold text-slate-200 uppercase tracking-wide truncate",children:p.id})]}),e.jsxs("div",{className:"flex items-center gap-3 text-right shrink-0",children:[e.jsxs("span",{className:"font-mono text-slate-400",children:[p.requests.toLocaleString()," reqs (",o,"%)"]}),e.jsxs("span",{className:"font-mono text-xs font-semibold text-slate-200",children:["$",p.cost.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})]})]})]}),e.jsx("div",{className:"w-full bg-[#151D2F] h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${Math.max(4,o)}%`,backgroundColor:x}})})]},p.id)})})]})},ze=({byProvider:t,byModel:m,byAccount:d,byApiKey:h})=>{const[c,p]=i.useState("model");let o=[];c==="provider"?o=Object.entries(t||{}).map(([s,r])=>({id:s,name:s.toUpperCase(),sublabel:"Provider Gateway",requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0})):c==="model"?o=Object.entries(m||{}).map(([s,r])=>({id:s,name:r.rawModel||s,sublabel:r.provider?`Provider: ${r.provider}`:void 0,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})):c==="account"?o=Object.entries(d||{}).map(([s,r])=>({id:s,name:r.accountName||r.accountId||s,sublabel:r.rawModel?`${r.rawModel} (${r.provider||"default"})`:void 0,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})):o=Object.entries(h||{}).map(([s,r])=>({id:s,name:r.apiKeyName||(s==="no_key"?"Direct / No Key":s),sublabel:s==="no_key"?"Unauthenticated / Local Ping":`Key ID: ${s}`,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})),o=o.filter(s=>s.promptTokens+s.completionTokens>0),o.sort((s,r)=>r.requests-s.requests);const x=s=>(s||0).toLocaleString("en-US"),j=s=>`$${(s||0).toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4})}`;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4 text-blue-400"}),e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:"Usage Breakdown"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["(",o.length," records)"]})]}),e.jsxs("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:[e.jsxs("span",{className:"px-2 text-slate-500 flex items-center gap-1",children:[e.jsx(je,{className:"w-3 h-3"})," Group:"]}),["model","provider","account","apiKey"].map(s=>e.jsx("button",{onClick:()=>p(s),className:`px-3 py-1.5 rounded-md font-semibold capitalize transition-all ${c===s?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:s==="apiKey"?"API Key":s},s))]})]}),o.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-sm",children:"No usage records found for this period."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-800 text-slate-400 uppercase text-[10px] tracking-wider",children:[e.jsx("th",{className:"py-2.5 px-3",children:"Name"}),e.jsx("th",{className:"py-2.5 px-3 text-right",children:"Requests"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-blue-400",children:"Input Tokens"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-cyan-400",children:"Cached"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-emerald-400",children:"Output Tokens"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-amber-400",children:"Est. Cost"}),e.jsx("th",{className:"py-2.5 px-3 text-right",children:"Last Used"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-800/60",children:o.map(s=>e.jsxs("tr",{className:"hover:bg-slate-800/25 transition-colors",children:[e.jsxs("td",{className:"py-2.5 px-3",children:[e.jsx("div",{className:"font-semibold text-slate-200",children:s.name}),s.sublabel&&e.jsx("div",{className:"text-[10px] text-slate-500 mt-0.5",children:s.sublabel})]}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono font-medium text-slate-300",children:x(s.requests)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-blue-400/90",children:x(s.promptTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-cyan-400/90",children:x(s.cachedTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-emerald-400/90",children:x(s.completionTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono font-semibold text-amber-400/90",children:j(s.cost)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-slate-400 text-[11px]",children:s.lastUsed?new Date(s.lastUsed).toLocaleDateString():"-"})]},s.id))})]})})]})},Ye=({detail:t,isOpen:m,onClose:d})=>{var T,k,C,E,y,n,g,l,b,a,v,u,f,w,B,$;const[h,c]=i.useState(!1),[p,o]=i.useState(null),[x,j]=i.useState(!1),[s,r]=i.useState("client"),{backdropProps:S}=Fe(d,!m);if(i.useEffect(()=>{if(!m)return;const R=A=>{A.key==="Escape"&&d()};document.addEventListener("keydown",R);const M=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=M}},[m,d]),!m||!t||typeof document>"u")return null;const N=(R,M)=>{navigator.clipboard.writeText(R),M==="id"?(c(!0),setTimeout(()=>c(!1),2e3)):(o(M),setTimeout(()=>o(null),2e3))},L=Number(t.status),O=L>=200&&L<300||t.status==="success"||t.status==="ok",F=L===429||t.status==="rate_limited",D=()=>F?e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30",children:"429 Rate Limit"}):O?e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",children:t.status==="success"||t.status==="ok"?"200 OK":`${t.status} OK`}):e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-red-500/20 text-red-400 border border-red-500/30",children:t.status||"500 Error"});return ie.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex justify-end bg-black/70 backdrop-blur-xs animate-rt-fade-in",...S,children:e.jsxs("div",{className:"w-full max-w-2xl sm:max-w-3xl h-full bg-[#0D121F] border-l border-[#1E293B] shadow-2xl flex flex-col text-slate-100 overflow-hidden animate-rt-slide-in-right",onClick:R=>R.stopPropagation(),children:[e.jsxs("div",{className:"p-4 sm:p-5 border-b border-[#1E293B] flex items-center justify-between bg-[#0A0E18]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[D(),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{children:t.model||"Unknown Model"}),t.provider&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-slate-800 text-slate-300 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-400 mt-0.5",children:[e.jsx("span",{className:"font-mono text-[11px] truncate max-w-[200px]",title:t.id,children:t.id}),e.jsx("button",{onClick:()=>N(t.id,"id"),className:"p-1 hover:text-white transition-colors",title:"Copy Request ID",children:h?e.jsx(J,{className:"w-3.5 h-3.5 text-emerald-400"}):e.jsx(V,{className:"w-3.5 h-3.5"})})]})]})]}),e.jsx("button",{onClick:d,className:"p-2 rounded-lg bg-slate-800/60 hover:bg-slate-700 text-slate-400 hover:text-white transition-colors",children:e.jsx(se,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-5 text-xs",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 bg-[#111726] border border-[#1E293B] rounded-xl p-3.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(ge,{className:"w-3 h-3"})," Latency"]}),e.jsx("span",{className:"font-mono text-sm font-bold text-slate-200 mt-1 block",children:((T=t.latency)==null?void 0:T.totalMs)!=null?`${t.latency.totalMs} ms`:"-"}),((k=t.latency)==null?void 0:k.ttftMs)!=null&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["TTFT: ",t.latency.ttftMs,"ms"]})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"})," Account"]}),e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-200 mt-1 block truncate",children:t.accountName||t.connectionId||"Default"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:t.provider||"-"})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"w-3 h-3"})," Client Tool"]}),e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-200 mt-1 block truncate",title:t.clientTool,children:t.clientTool||"unknown"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold",children:"Cost Est."}),e.jsxs("span",{className:"font-mono text-sm font-bold text-amber-400 mt-1 block",children:["$",t.cost!=null?t.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4}):"0.0000"]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl p-4",children:[e.jsxs("h4",{className:"text-xs font-bold uppercase tracking-wider text-slate-400 mb-3 flex items-center gap-1.5",children:[e.jsx(ee,{className:"w-3.5 h-3.5 text-blue-400"})," Token Breakdown"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-center",children:[e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Input"}),e.jsx("span",{className:"font-mono text-base font-bold text-blue-400 mt-1 block",children:(((C=t.tokens)==null?void 0:C.promptTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Cached"}),e.jsx("span",{className:"font-mono text-base font-bold text-cyan-400 mt-1 block",children:(((E=t.tokens)==null?void 0:E.cachedTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Output"}),e.jsx("span",{className:"font-mono text-base font-bold text-emerald-400 mt-1 block",children:(((y=t.tokens)==null?void 0:y.completionTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Tokens Saved"}),e.jsx("span",{className:"font-mono text-base font-bold text-purple-400 mt-1 block",children:(((n=t.tokens)==null?void 0:n.tokensSavedByRtk)||0).toLocaleString()})]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>j(!x),className:"w-full p-3.5 flex items-center justify-between text-left hover:bg-slate-800/40 transition-colors",children:[e.jsxs("span",{className:"font-bold text-xs text-slate-300 flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-400"}),"HTTP Headers (Sanitized)"]}),x?e.jsx(Ne,{className:"w-4 h-4 text-slate-400"}):e.jsx(ae,{className:"w-4 h-4 text-slate-400"})]}),x&&e.jsxs("div",{className:"p-3.5 border-t border-[#1E293B] space-y-3 bg-[#0B0F19]",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Client Inbound Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(((g=t.request)==null?void 0:g.headers)||{},null,2)})]}),((l=t.providerRequest)==null?void 0:l.headers)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Provider Outbound Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(t.providerRequest.headers,null,2)})]}),(((b=t.response)==null?void 0:b.headers)||((a=t.providerResponse)==null?void 0:a.headers))&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Response Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(((v=t.response)==null?void 0:v.headers)||((u=t.providerResponse)==null?void 0:u.headers),null,2)})]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-[#0B0F19] p-1 rounded-lg border border-slate-800",children:[e.jsx("button",{onClick:()=>r("client"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="client"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Client Request"}),e.jsx("button",{onClick:()=>r("providerReq"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="providerReq"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Provider Request"}),e.jsx("button",{onClick:()=>r("response"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="response"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Response Output"})]}),e.jsx("button",{onClick:()=>{var M,A,q,P;const R=s==="client"?(M=t.request)==null?void 0:M.body:s==="providerReq"?(A=t.providerRequest)==null?void 0:A.body:((q=t.response)==null?void 0:q.body)||((P=t.providerResponse)==null?void 0:P.body);N(JSON.stringify(R,null,2),s)},className:"px-2.5 py-1 rounded-md bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors text-xs",children:p===s?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3.5 h-3.5 text-emerald-400"}),e.jsx("span",{children:"Copied"})]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Copy JSON"})]})})]}),e.jsx("div",{className:"relative rounded-lg bg-[#070A11] border border-slate-800/80 p-3 max-h-96 overflow-y-auto",children:e.jsx("pre",{className:"font-mono text-[11px] text-slate-300 whitespace-pre-wrap leading-relaxed",children:JSON.stringify(s==="client"?((f=t.request)==null?void 0:f.body)||{message:"No request body captured"}:s==="providerReq"?((w=t.providerRequest)==null?void 0:w.body)||{message:"Same as client or pass-through"}:((B=t.response)==null?void 0:B.body)||(($=t.providerResponse)==null?void 0:$.body)||{message:"Stream completed successfully"},null,2)})})]})]})]})}),document.body)},Ge=()=>{const[t,m]=i.useState(null),[d,h]=i.useState(!1),[c,p]=i.useState(1),[o,x]=i.useState(20),[j,s]=i.useState(""),[r,S]=i.useState("all"),[N,L]=i.useState("all"),[O,F]=i.useState([]),[D,T]=i.useState(null),[k,C]=i.useState(!1),E=i.useCallback(async()=>{try{const l=await fetch("/api/usage/providers");if(l.ok){const b=await l.json();Array.isArray(b)&&F(b)}}catch{}},[]),y=i.useCallback(async()=>{h(!0);try{const l=new URLSearchParams;l.set("page",String(c)),l.set("pageSize",String(o)),r!=="all"&&l.set("provider",r),N!=="all"&&l.set("status",N),j.trim()&&l.set("search",j.trim());const b=await fetch(`/api/usage/request-details?${l.toString()}`);if(b.ok){const a=await b.json();m(a)}}catch(l){console.error("Failed to fetch request details:",l)}finally{h(!1)}},[c,o,r,N,j]);i.useEffect(()=>{E()},[E]),i.useEffect(()=>{y()},[y]);const n=async l=>{try{const b=await fetch(`/api/usage/request-details/${l.id}`);if(b.ok){const a=await b.json();T(a)}else T(l)}catch{T(l)}C(!0)},g=l=>{const b=String(l||"");return b==="200"||b==="success"||b==="ok"?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",children:"200 OK"}):b==="429"||b==="rate_limited"?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30",children:"429"}):e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-red-500/20 text-red-400 border border-red-500/30",children:b||"500"})};return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-3.5 flex flex-wrap items-center justify-between gap-3 shadow-xs",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 flex-1 min-w-[280px]",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[e.jsx(we,{className:"w-4 h-4 text-slate-500 absolute left-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"text",placeholder:"Search by model, ID, provider, tool...",value:j,onChange:l=>{s(l.target.value),p(1)},className:"w-full pl-9 pr-8 py-1.5 rounded-lg bg-[#070A11] border border-slate-800 text-xs text-slate-200 placeholder-slate-500 focus:outline-hidden focus:border-blue-500"}),j&&e.jsx("button",{type:"button",onClick:()=>{s(""),p(1)},className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear search",children:e.jsx(se,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(ye,{className:"w-3.5 h-3.5 text-slate-500"}),e.jsx(Y,{value:r,onChange:l=>{S(l),p(1)},options:[{value:"all",label:"All Providers"},...O.map(l=>({value:l,label:l.toUpperCase()}))],className:"min-w-[140px]"})]}),e.jsx("div",{className:"flex items-center text-xs",children:e.jsx(Y,{value:N,onChange:l=>{L(l),p(1)},options:[{value:"all",label:"All Statuses"},{value:"200",label:"200 OK"},{value:"429",label:"429 Rate Limit"},{value:"500",label:"500 Error"}],className:"min-w-[130px]"})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>y(),disabled:d,className:"p-1.5 rounded-lg bg-[#151D2F] border border-slate-700/60 text-slate-300 hover:text-white hover:bg-slate-800 transition-colors",title:"Refresh logs",children:e.jsx(le,{className:`w-4 h-4 ${d?"animate-spin text-blue-400":""}`})}),e.jsx("span",{className:"text-xs text-slate-400 font-mono",children:t!=null&&t.pagination?`${t.pagination.totalItems} records`:""})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl overflow-hidden shadow-xs",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-800 text-slate-400 uppercase text-[10px] tracking-wider bg-[#0A0E18]",children:[e.jsx("th",{className:"py-3 px-3.5",children:"Status"}),e.jsx("th",{className:"py-3 px-3.5",children:"Time"}),e.jsx("th",{className:"py-3 px-3.5",children:"Model"}),e.jsx("th",{className:"py-3 px-3.5",children:"Provider"}),e.jsx("th",{className:"py-3 px-3.5",children:"Tool / Client"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-blue-400",children:"In Tok"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-emerald-400",children:"Out Tok"}),e.jsx("th",{className:"py-3 px-3.5 text-right",children:"Latency"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-amber-400",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-800/60",children:d&&(!(t!=null&&t.details)||t.details.length===0)?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-12 text-center text-slate-500",children:"Loading request records..."})}):!(t!=null&&t.details)||t.details.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-12 text-center text-slate-500",children:"No matching request logs found."})}):t.details.map(l=>{var b,a,v;return e.jsxs("tr",{onClick:()=>n(l),className:"hover:bg-blue-600/10 cursor-pointer transition-colors group",children:[e.jsx("td",{className:"py-2.5 px-3.5",children:g(l.status)}),e.jsx("td",{className:"py-2.5 px-3.5 font-mono text-[11px] text-slate-400 whitespace-nowrap",children:new Date(l.timestamp).toLocaleTimeString()}),e.jsx("td",{className:"py-2.5 px-3.5 font-semibold text-slate-200 group-hover:text-blue-400 transition-colors truncate max-w-[180px]",children:l.model||"unknown"}),e.jsx("td",{className:"py-2.5 px-3.5",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-slate-800 text-slate-300 font-mono",children:l.provider||"-"})}),e.jsx("td",{className:"py-2.5 px-3.5 font-mono text-slate-400 truncate max-w-[140px]",title:l.clientTool,children:l.clientTool||"-"}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-blue-400/90",children:(((b=l.tokens)==null?void 0:b.promptTokens)||0).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-emerald-400/90",children:(((a=l.tokens)==null?void 0:a.completionTokens)||0).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-slate-300",children:((v=l.latency)==null?void 0:v.totalMs)!=null?`${l.latency.totalMs}ms`:"-"}),e.jsxs("td",{className:"py-2.5 px-3.5 text-right font-mono font-semibold text-amber-400/90",children:["$",l.cost!=null?l.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4}):"0.0000"]})]},l.id)})})]})}),(t==null?void 0:t.pagination)&&t.pagination.totalPages>1&&e.jsxs("div",{className:"p-3 border-t border-slate-800 bg-[#0A0E18] flex items-center justify-between text-xs text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Rows per page:"}),e.jsx(Y,{value:String(o),onChange:l=>{x(Number(l)),p(1)},options:[{value:"10",label:"10"},{value:"20",label:"20"},{value:"50",label:"50"}],className:"w-20"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{children:["Page ",e.jsx("span",{className:"font-bold text-slate-200",children:t.pagination.page})," of"," ",e.jsx("span",{className:"font-bold text-slate-200",children:t.pagination.totalPages})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{disabled:!t.pagination.hasPrev,onClick:()=>p(l=>Math.max(1,l-1)),className:"p-1.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ke,{className:"w-4 h-4"})}),e.jsx("button",{disabled:!t.pagination.hasNext,onClick:()=>p(l=>l+1),className:"p-1.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ae,{className:"w-4 h-4"})})]})]})]})]}),e.jsx(Ye,{detail:D,isOpen:k,onClose:()=>C(!1)})]})},et=()=>{const[t,m]=i.useState("overview"),[d,h]=i.useState("7d"),[c,p]=i.useState(null),[o,x]=i.useState([]),[j,s]=i.useState([]),[r,S]=i.useState([]),[N,L]=i.useState(!0),[O,F]=i.useState(!0),[D,T]=i.useState(!1),k=i.useRef(null),C=i.useCallback(async n=>{try{L(!0);const g=await fetch(`/api/usage/stats?period=${n}`);if(g.ok){const l=await g.json();p(l),l.activeRequests&&s(l.activeRequests),l.recentRequests&&S(l.recentRequests)}}catch(g){console.error("Failed to fetch stats:",g)}finally{L(!1)}},[]),E=i.useCallback(async n=>{try{F(!0);const g=await fetch(`/api/usage/chart?period=${n}`);if(g.ok){const l=await g.json();x(l)}}catch(g){console.error("Failed to fetch chart data:",g)}finally{F(!1)}},[]);i.useEffect(()=>{C(d),E(d)},[d,C,E]),i.useEffect(()=>{let n=null,g=null;const l=()=>{try{const b=De.getToken(),a=`/api/usage/stream?period=${encodeURIComponent(d)}`,v=b?`${a}&token=${encodeURIComponent(b)}`:a;n=new EventSource(v),k.current=n,n.onopen=()=>{T(!0)},n.addEventListener("stats",u=>{try{const f=JSON.parse(u.data);p(f),f.activeRequests&&s(f.activeRequests),f.recentRequests&&S(f.recentRequests)}catch{}}),n.addEventListener("pending",u=>{try{const f=JSON.parse(u.data);f.activeRequests&&s(f.activeRequests)}catch{}}),n.onerror=()=>{T(!1),n==null||n.close(),k.current=null,g=setTimeout(l,5e3)}}catch{T(!1)}};return l(),()=>{g&&clearTimeout(g),n&&n.close(),k.current=null}},[d]);const y=Object.keys((c==null?void 0:c.byProvider)||{});return e.jsxs("div",{className:"w-full min-w-0 space-y-6 px-2 sm:px-4 lg:px-6 pb-20 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-[#0B0F19] border border-[#1E293B] rounded-2xl p-2 sm:p-2.5 shadow-sm",children:[e.jsxs("div",{className:"bg-[#151C2C] p-1 rounded-xl border border-[#243048] flex items-center",children:[e.jsxs("button",{onClick:()=>m("overview"),className:`px-3.5 py-1.5 rounded-lg text-xs font-bold flex items-center gap-2 transition-all ${t==="overview"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:[e.jsx(Ce,{className:"w-3.5 h-3.5"}),"Overview"]}),e.jsxs("button",{onClick:()=>m("details"),className:`px-3.5 py-1.5 rounded-lg text-xs font-bold flex items-center gap-2 transition-all ${t==="details"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:[e.jsx(Se,{className:"w-3.5 h-3.5"}),"Details (Inspector)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-[#151C2C] border border-slate-800 text-[11px] text-slate-400",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${D?"bg-emerald-400 shadow-[0_0_8px_#34d399]":"bg-amber-400"}`}),e.jsx("span",{className:"font-mono text-[10px]",children:D?"LIVE TELEMETRY":"POLLING"})]}),t==="overview"&&e.jsx("div",{className:"bg-[#151C2C] p-1 rounded-xl border border-[#243048] flex items-center text-xs",children:["today","24h","7d","30d","60d","90d","all"].map(n=>e.jsx("button",{onClick:()=>h(n),className:`px-2.5 sm:px-3 py-1 rounded-lg uppercase font-semibold transition-all ${d===n?"bg-blue-600/30 text-blue-400 border border-blue-500/40 shadow-xs":"text-slate-400 hover:text-white"}`,children:n},n))}),e.jsx("button",{onClick:()=>{C(d),E(d)},className:"p-2 rounded-xl bg-[#151C2C] border border-[#243048] text-slate-300 hover:text-white hover:bg-slate-800 transition-colors",title:"Refresh statistics",children:e.jsx(le,{className:`w-3.5 h-3.5 ${N?"animate-spin text-blue-400":""}`})})]})]}),t==="overview"&&e.jsxs("div",{className:"space-y-6 w-full",children:[e.jsx(Ae,{stats:c,loading:N}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-5 w-full",children:[e.jsx("div",{className:"lg:col-span-7 w-full flex",children:e.jsx(Ue,{providers:y,activeRequests:j})}),e.jsxs("div",{className:"lg:col-span-5 w-full bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B] shrink-0",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-200 uppercase tracking-wider flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-blue-400"}),"Recent Requests"]}),e.jsxs("span",{className:"text-[10px] text-cyan-400 font-mono bg-cyan-500/10 border border-cyan-500/20 px-2 py-0.5 rounded-full flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-cyan-400 animate-pulse"}),"Live Stream"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto mt-2 min-h-[220px] max-h-[300px] pr-1",children:r.length===0?e.jsx("div",{className:"py-16 text-center text-slate-500 text-xs",children:"No recent proxy requests yet. Call /v1/messages or /v1/chat/completions to see live logs."}):e.jsxs("table",{className:"w-full text-left text-xs font-mono border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-slate-500 text-[10px] uppercase border-b border-[#1E293B]",children:[e.jsx("th",{className:"pb-2 font-semibold pr-2",children:"Model / Provider"}),e.jsx("th",{className:"pb-2 font-semibold text-right px-2 w-[125px]",children:"In / Out"}),e.jsx("th",{className:"pb-2 font-semibold text-right pl-2 pr-2 w-[95px]",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-[#1E293B]/50",children:r.slice(0,15).map((n,g)=>{const l=n.status==="success"||n.status==="ok",b=n.requestedModel&&n.requestedModel!==n.model?`${n.model} (via ${n.requestedModel}) · ${n.provider||"unknown"}`:`${n.model} · ${n.provider||"unknown"}`;return e.jsxs("tr",{className:"hover:bg-slate-800/30 transition-colors",children:[e.jsx("td",{className:"py-2 pr-2 overflow-hidden",title:b,children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${l?"bg-emerald-400":"bg-red-400"}`}),e.jsx("span",{className:"text-slate-200 text-xs truncate font-medium",children:n.model}),n.provider&&e.jsx("span",{className:"text-[9px] text-slate-400 font-mono uppercase px-1 py-0.5 rounded bg-slate-800 border border-slate-700/50 shrink-0",children:n.provider})]})}),e.jsxs("td",{className:"py-2 text-right whitespace-nowrap px-2 text-[11px] w-[125px]",children:[e.jsxs("span",{className:"text-blue-400",children:[n.promptTokens.toLocaleString(),"↑"]})," ",e.jsxs("span",{className:"text-emerald-400",children:[n.completionTokens.toLocaleString(),"↓"]})]}),e.jsx("td",{className:"py-2 text-right text-[10px] text-slate-400 whitespace-nowrap pl-2 pr-2 w-[95px]",children:typeof n.timestamp=="number"?new Date(n.timestamp).toLocaleTimeString():new Date(String(n.timestamp)).toLocaleTimeString()})]},n.id||g)})})]})})]})]}),e.jsx(Ie,{data:o,period:d,loading:O}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5 w-full",children:[e.jsx(_e,{byModel:(c==null?void 0:c.byModel)||{}}),e.jsx(Ke,{byProvider:(c==null?void 0:c.byProvider)||{}})]}),e.jsx(ze,{byProvider:(c==null?void 0:c.byProvider)||{},byModel:(c==null?void 0:c.byModel)||{},byAccount:(c==null?void 0:c.byAccount)||{},byApiKey:(c==null?void 0:c.byApiKey)||{}})]}),t==="details"&&e.jsx(Ge,{})]})};export{et as UsageTab};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProvidersTab-
|
|
2
|
-
import{d as M,j as e,r as m,a as W,e as J,R as Y}from"./vendor-BcOI2aZ9.js";import{G as q}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 l of n)if(l.type==="childList")for(const i of l.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&t(i)}).observe(document,{childList:!0,subtree:!0});function s(n){const l={};return n.integrity&&(l.integrity=n.integrity),n.referrerPolicy&&(l.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?l.credentials="include":n.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function t(n){if(n.ep)return;n.ep=!0;const l=s(n);fetch(n.href,l)}})();const X="modulepreload",Z=function(a){return"/"+a},$={},j=function(r,s,t){let n=Promise.resolve();if(s&&s.length>0){let i=function(c){return Promise.all(c.map(d=>Promise.resolve(d).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),u=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));n=i(s.map(c=>{if(c=Z(c),c in $)return;$[c]=!0;const d=c.endsWith(".css"),p=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${p}`))return;const h=document.createElement("link");if(h.rel=d?"stylesheet":X,d||(h.as="script"),h.crossOrigin="",h.href=c,u&&h.setAttribute("nonce",u),document.head.appendChild(h),d)return new Promise((x,f)=>{h.addEventListener("load",x),h.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${c}`)))})}))}function l(i){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i}return n.then(i=>{for(const o of i||[])o.status==="rejected"&&l(o.reason);return r().catch(l)})},E=20128,L="127.0.0.1",ee=`http://${L}:${E}`,Ee=`${ee}/v1`,S=M(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:E),l=s.host||(typeof window<"u"&&window.location.hostname?window.location.hostname:L),i={dataDir:s.dataDir||"",dbPath:s.dbPath||"",isDevelopmentMode:!!s.isDevelopmentMode,appName:s.appName||"Mapigate",version:s.version||"",port:n,host:l,configuredHost:s.configuredHost||l,configuredPort:s.configuredPort||n,isRestartRequired:!!s.isRestartRequired};return a({info:i,loading:!1}),(async()=>{try{const o=await fetch("/api/settings/version");if(o.ok){const u=await o.json();a(c=>c.info?{...c,info:{...c.info,latestVersion:u.latestVersion,hasUpdate:!!u.hasUpdate}}:c)}}catch{}})(),i}}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{}}})),te=({currentTab:a,onSelectTab:r,onUpgradeClick:s})=>{const t=S(u=>u.info),n=t==null?void 0:t.version,l=(t==null?void 0:t.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):E),i=(t==null?void 0:t.host)||(typeof window<"u"&&window.location.hostname?window.location.hostname:L),o=[{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:o.map(u=>{const c=a===u.id;return e.jsxs("button",{onClick:()=>r(u.id),className:`rt-sidebar__nav-item ${c?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:u.icon}),e.jsx("span",{children:u.label})]},u.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 ",l]})]}),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:i})]}),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(q,{className:"size-3.5 text-slate-400"}),e.jsx("span",{children:"GitHub · joutvhu/mapigate"})]})]})]})},P="mapigate_auth_token";let F=!1;const R=new Set;function se(a){return R.add(a),()=>{R.delete(a)}}function K(){for(const a of R)try{a()}catch{}}class k{static getToken(){if(typeof window>"u")return null;try{return localStorage.getItem(P)}catch{return null}}static setToken(r){if(!(typeof window>"u"))try{localStorage.setItem(P,r)}catch{}}static removeToken(){if(!(typeof window>"u"))try{localStorage.removeItem(P)}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(),K()}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 ae(){if(typeof window>"u"||F)return;F=!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/"),l=t.includes("/api/auth/status")||t.includes("/api/auth/login");let i=s;const o=k.getToken();if(n&&o){const c=new Headers((s==null?void 0:s.headers)||(r instanceof Request?r.headers:void 0));c.has("Authorization")||c.set("Authorization",`Bearer ${o}`),i={...s,headers:c}}const u=await a(r,i);if(n&&!l&&u.status===401)try{const d=await u.clone().json();d&&d.code==="AUTH_REQUIRED"&&K()}catch{}return u}}ae();const w=M((a,r)=>({isChecking:!0,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1,checkAuth:async()=>{a({isChecking:!0});try{const s=await k.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 k.login(s);return t.success?(a({isAuthenticated:!0,isLocked:!1}),{success:!0}):{success:!1,error:t.error}},logout:async()=>{await k.logout();const s=r().isPasswordSet;a({isAuthenticated:!s,isLocked:s})},lock:()=>{r().isPasswordSet&&(k.removeToken(),a({isAuthenticated:!1,isLocked:!0}))},unlock:s=>{k.setToken(s),a({isAuthenticated:!0,isLocked:!1})}}));typeof window<"u"&&(se(()=>{w.getState().lock()}),window.addEventListener("storage",a=>{(a.key===P||a.key===null)&&(k.getToken()?w.setState({isAuthenticated:!0,isLocked:!1}):w.getState().isPasswordSet&&w.setState({isAuthenticated:!1,isLocked:!0}))}));const V=M(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(([i,o])=>!!o).map(([i])=>i),l={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:l,loading:!1}),l}}catch{}return a({loading:!1}),null}})),re={antigravity:"Antigravity",kiro:"Kiro",copilot:"GitHub Copilot",cursor:"Cursor"};function G(a){return!a||a.length===0?"":a.map(r=>re[r]||r.charAt(0).toUpperCase()+r.slice(1)).join(", ")}const H={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"}},ne=({currentTab:a,searchQuery:r,onSearchChange:s,detailProvider:t,onBackToProviders:n,onRestartClick:l,onSelectTab:i})=>{const o=H[a]||H.providers,u=w(v=>v.isPasswordSet),c=w(v=>v.lock),d=S(v=>v.info),p=S(v=>v.fetchSystemInfo);d==null||d.version;const h=V(v=>v.status),x=V(v=>v.fetchStatus);m.useEffect(()=>{x(),p();const v=setInterval(()=>{document.hidden||(x(),p())},1e4),z=()=>{x(),p()};return window.addEventListener("focus",z),()=>{clearInterval(v),window.removeEventListener("focus",z)}},[x,p]);const f=!!(h!=null&&h.running),b=(h==null?void 0:h.port)||443,y=(h==null?void 0:h.activeDnsCount)||0,N=(h==null?void 0:h.activeDnsTools)||[],C=!!(h!=null&&h.orphanedDns),g=(d==null?void 0:d.host)||"127.0.0.1",D=(d==null?void 0:d.configuredHost)||g,I=!!(d!=null&&d.isRestartRequired),A=g==="0.0.0.0";let B=A?`Network: LAN Active (0.0.0.0:${(d==null?void 0:d.port)||E}) • Accessible from local network • Click to configure Endpoint`:`Network: Local Only (127.0.0.1:${(d==null?void 0:d.port)||E}) • Isolated to this machine • Click to configure Endpoint`,O=A?"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",U=A?"wifi":"shield";I&&(B=`⚠️ Restart Required: Configured for ${D==="0.0.0.0"?"LAN Active":"Local Only"} (${D}), but running on ${g}. Click Restart button to apply.`,O="bg-amber-500/15 text-amber-300 border-amber-500/30 hover:bg-amber-500/25 animate-pulse",U="restart_alt");let T="MITM Proxy: Stopped • Click to open settings",_="text-slate-500 hover:text-slate-300";return C?(T=`⚠️ MITM Warning: Server stopped but ${y} DNS redirect(s) still active (${G(N)})! Tools cannot connect. Click to fix.`,_="text-amber-400 hover:text-amber-300 animate-pulse"):f?y>0?(T=`MITM Proxy: Active on port ${b} • ${y} tool DNS active (${G(N)}) • Click to manage`,_="text-emerald-400 hover:text-emerald-300"):(T=`MITM Proxy: Running on port ${b} (Idle, 0 tool DNS active) • Click to configure`,_="text-blue-400 hover:text-blue-300"):(T="MITM Proxy: Stopped • Click to open settings",_="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:o.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:o.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}`:o.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:()=>{I&&l?l():i==null||i("endpoint")},title:B,className:`w-8 h-8 rounded-lg border text-xs font-medium transition-all cursor-pointer shadow-xs inline-flex items-center justify-center ${O}`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:U})}),e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i("mitm"),title:T,className:`w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 ${_} 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:[l&&e.jsx("button",{type:"button",onClick:l,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"})}),u&&e.jsx("button",{type:"button",onClick:c,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(q,{className:"size-4"})})})]})]})},oe=()=>{const[a,r]=m.useState(""),[s,t]=m.useState(!1),[n,l]=m.useState(!1),[i,o]=m.useState(null),u=m.useRef(null),c=w(p=>p.login);m.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const d=async p=>{var x;if(p.preventDefault(),!a.trim()||n)return;l(!0),o(null);const h=await c(a);h.success||(o(h.error||"Incorrect master password"),l(!1),(x=u.current)==null||x.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:d,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:u,type:s?"text":"password",placeholder:"Enter master password...",value:a,onChange:p=>{r(p.target.value),i&&o(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"})})]}),i&&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:i})]}),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 le(a){let r={...a},s=!1,t=!1,n=0;const l=x=>{r={...x}},i=()=>{var f;if(r.disabled)return;const x=Date.now();x-n<250||(n=x,(f=r.onClose)==null||f.call(r))};return{updateOptions:l,handleMouseDown:x=>{r.disabled||(x.target===x.currentTarget&&(x.button===0||x.button===void 0)?s=!0:s=!1)},handleMouseUp:x=>{if(r.disabled){s=!1;return}s&&x.target===x.currentTarget&&(x.button===0||x.button===void 0)&&i(),s=!1},handleTouchStart:x=>{r.disabled||(x.target===x.currentTarget?t=!0:t=!1)},handleTouchEnd:x=>{if(r.disabled){t=!1;return}t&&x.target===x.currentTarget&&i(),t=!1},handleClick:x=>{r.disabled||x.detail===0&&x.target===x.currentTarget&&i()},reset:()=>{s=!1,t=!1},get isMouseDown(){return s},get isTouchStart(){return t}}}function ie(a,r=!1){const s=m.useRef(null);s.current?s.current.updateOptions({onClose:a,disabled:r}):s.current=le({onClose:a,disabled:r}),m.useEffect(()=>{if(typeof window>"u")return;const n=()=>{var i;(i=s.current)==null||i.reset()},l=()=>{var i;(i=s.current)==null||i.reset()};return window.addEventListener("mouseup",n),window.addEventListener("touchend",l),()=>{window.removeEventListener("mouseup",n),window.removeEventListener("touchend",l)}},[]);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 Q=({isOpen:a,onClose:r,children:s,maxWidthClass:t="max-w-xl",className:n="",overflowHidden:l=!1})=>{const{backdropProps:i}=ie(r);if(m.useEffect(()=>{if(!a)return;const u=d=>{d.key==="Escape"&&r()};document.addEventListener("keydown",u);const c=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",u),document.body.style.overflow=c}},[a,r]),!a||typeof document>"u")return null;const o=l?"overflow-hidden":n.includes("overflow-")?"":"overflow-visible";return W.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",...i,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 ${o} ${n}`,onClick:u=>u.stopPropagation(),children:s})}),document.body)},ce=({isOpen:a,onClose:r})=>{const[s,t]=m.useState("confirm"),[n,l]=m.useState(null),[i,o]=m.useState(0),u=m.useRef(null),c=m.useRef(null);m.useEffect(()=>(a?(t("confirm"),l(null),o(0)):(u.current&&clearInterval(u.current),c.current&&clearInterval(c.current)),()=>{u.current&&clearInterval(u.current),c.current&&clearInterval(c.current)}),[a]);const d=()=>{const h=Date.now();let x=0;c.current=setInterval(()=>{o(Math.floor((Date.now()-h)/1e3))},500),setTimeout(()=>{u.current=setInterval(async()=>{x+=1;try{const f=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(f.ok){const b=await f.json().catch(()=>null);(b==null?void 0:b.status)==="ok"&&(u.current&&clearInterval(u.current),c.current&&clearInterval(c.current),t("success"),setTimeout(()=>{window.location.reload()},600))}}catch{}x>=50&&(u.current&&clearInterval(u.current),c.current&&clearInterval(c.current),t("timeout"))},500)},600)},p=async()=>{t("restarting"),l(null);try{const h=await fetch("/api/server/restart",{method:"POST",headers:{"Content-Type":"application/json"}});if(!h.ok){const x=await h.json().catch(()=>({}));l(x.error||"Failed to initiate server restart."),t("confirm");return}}catch{}d()};return e.jsx(Q,{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 (",i,"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"]})]})]})]})})},de=({isOpen:a,onClose:r,currentVersion:s,latestVersion:t})=>{const[n,l]=m.useState("confirm"),[i,o]=m.useState(null),[u,c]=m.useState(0),d=m.useRef(null),p=m.useRef(null);m.useEffect(()=>(a?(l("confirm"),o(null),c(0)):(d.current&&clearInterval(d.current),p.current&&clearInterval(p.current)),()=>{d.current&&clearInterval(d.current),p.current&&clearInterval(p.current)}),[a]);const h=()=>{let f=0;setTimeout(()=>{d.current=setInterval(async()=>{f+=1;try{const b=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(b.ok){const y=await b.json().catch(()=>null);(y==null?void 0:y.status)==="ok"&&(d.current&&clearInterval(d.current),p.current&&clearInterval(p.current),l("success"),setTimeout(()=>{window.location.reload()},800))}}catch{}f>=60&&(d.current&&clearInterval(d.current),p.current&&clearInterval(p.current),l("timeout"))},500)},800)},x=async()=>{l("upgrading"),o(null),c(0);const f=Date.now();p.current=setInterval(()=>{c(Math.floor((Date.now()-f)/1e3))},500);try{const b=await fetch("/api/server/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:!1})}),y=await b.json().catch(()=>({}));if(!b.ok||!y.success){p.current&&clearInterval(p.current),o(y.error||"Failed to upgrade Mapigate."),l("error");return}l("restarting"),h()}catch(b){p.current&&clearInterval(p.current),o((b==null?void 0:b.message)||"Network error while requesting upgrade."),l("error")}};return e.jsx(Q,{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:x,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"," (",u,"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," (",u,"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"})]})]}),i&&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:i}),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:x,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"]})]})]})]})})},ue=m.lazy(()=>j(()=>import("./ProvidersTab-DwHMHdPu.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(a=>({default:a.ProvidersTab}))),xe=m.lazy(()=>j(()=>import("./ProviderDetailPage-Dv2LpFj_.js"),__vite__mapDeps([8,1,6,4,9,5,3,10,2,7])).then(a=>({default:a.ProviderDetailPage}))),me=m.lazy(()=>j(()=>import("./CombosTab-Cz8KYH4M.js"),__vite__mapDeps([11,1,12,3,4,5,9,2,7])).then(a=>({default:a.CombosTab}))),pe=m.lazy(()=>j(()=>import("./UsageTab-DKBaBAeT.js"),__vite__mapDeps([13,1,7,5,4,14,9])).then(a=>({default:a.UsageTab}))),he=m.lazy(()=>j(()=>import("./QuotaTab-DS1y9gGp.js"),__vite__mapDeps([15,1,4,5,9,10,2,7])).then(a=>({default:a.QuotaTab}))),fe=m.lazy(()=>j(()=>import("./CliToolsTab-BzhczMaa.js"),__vite__mapDeps([16,1,6,4,5,3,7])).then(a=>({default:a.CliToolsTab}))),be=m.lazy(()=>j(()=>import("./MitmTab-CTfwqdey.js"),__vite__mapDeps([17,1,3,4,5,7])).then(a=>({default:a.MitmTab}))),ge=m.lazy(()=>j(()=>import("./EndpointTab-DZCRpAbh.js"),__vite__mapDeps([18,1,9,2,7])).then(a=>({default:a.EndpointTab}))),ve=m.lazy(()=>j(()=>import("./TokenSaverTab-B3Fbu_yc.js"),__vite__mapDeps([19,1])).then(a=>({default:a.TokenSaverTab}))),ye=m.lazy(()=>j(()=>import("./ConsoleLogTab-CFvXde1l.js"),__vite__mapDeps([20,1,9,7,5])).then(a=>({default:a.ConsoleLogTab}))),je=m.lazy(()=>j(()=>import("./SettingsTab-DULcs9O4.js"),__vite__mapDeps([21,1,7])).then(a=>({default:a.SettingsTab}))),we=m.lazy(()=>j(()=>import("./CallbackPage-DBsxnmPi.js"),__vite__mapDeps([22,1])));function Ne(){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"))));if(typeof window<"u"&&(window.location.pathname==="/callback"||window.location.pathname==="/auth/callback"||window.location.pathname==="/authorize"||window.location.pathname.startsWith("/callback")||r))return e.jsx(we,{});const t=w(g=>g.isChecking),n=w(g=>g.isLocked),l=w(g=>g.checkAuth),i=S(g=>g.fetchSystemInfo);m.useEffect(()=>{l(),i()},[l,i]);const[o,u]=m.useState("providers"),[c,d]=m.useState(""),[p,h]=m.useState(null),[x,f]=m.useState(!1),[b,y]=m.useState(!1),N=S(g=>g.info),C=g=>{u(g),h(null)};return t?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"})}):n?e.jsx(oe,{}):e.jsxs("div",{className:"rt-app",children:[e.jsx(te,{currentTab:o,onSelectTab:C,onUpgradeClick:()=>y(!0)}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 h-full overflow-hidden",children:[e.jsx(ne,{currentTab:o,searchQuery:c,onSearchChange:d,detailProvider:p,onBackToProviders:()=>h(null),onRestartClick:()=>f(!0),onSelectTab:C}),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(Ne,{}),children:[o==="endpoint"&&e.jsx(ge,{onRestartClick:()=>f(!0)}),o==="providers"&&(p?e.jsx(xe,{provider:p,onBack:()=>h(null)}):e.jsx(ue,{searchQuery:c,onSelectProvider:g=>h(g)})),o==="combos"&&e.jsx(me,{}),o==="usage"&&e.jsx(pe,{}),o==="quota"&&e.jsx(he,{searchQuery:c}),o==="tokensaver"&&e.jsx(ve,{}),o==="clitools"&&e.jsx(fe,{}),o==="mitm"&&e.jsx(be,{}),o==="consolelog"&&e.jsx(ye,{}),o==="settings"&&e.jsx(je,{onRestartClick:()=>f(!0),onUpgradeClick:()=>y(!0)})]})})]}),e.jsx(ce,{isOpen:x,onClose:()=>f(!1)}),e.jsx(de,{isOpen:b,onClose:()=>y(!1),currentVersion:N==null?void 0:N.version,latestVersion:N==null?void 0:N.latestVersion})]})}J.createRoot(document.getElementById("root")).render(e.jsx(Y.StrictMode,{children:e.jsx(ke,{})}));export{k as A,E as D,Q as P,ce as R,ie as a,Ee as b,ee as c,L as d,V as e,w as f,S as u};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProvidersTab-CPMTBmXq.js","assets/vendor-BcOI2aZ9.js","assets/ConfirmModal-B7vVauYn.js","assets/ModelAutocompleteInput-ClwXyzE7.js","assets/metadataRegistry-7DDoxaR3.js","assets/ToolIcon-Cp4gSgFt.js","assets/providersData-Br5RocnM.js","assets/lucide-Cc35htxl.js","assets/ProviderDetailPage-DgClsBMU.js","assets/Select-BNRH8LIG.js","assets/EditAccountModal-p6rlIU5X.js","assets/CombosTab-V_ldcQni.js","assets/dnd-kit-DecqzwfZ.js","assets/UsageTab-BDTnu1v_.js","assets/recharts-X4_nm3od.js","assets/QuotaTab-NaCPxtWq.js","assets/CliToolsTab-D-0zU55K.js","assets/MitmTab-sRzVrlgW.js","assets/EndpointTab-BHYn9Syj.js","assets/TokenSaverTab-B3Fbu_yc.js","assets/ConsoleLogTab-Byt7Fr4V.js","assets/SettingsTab-BUKXj5iT.js","assets/CallbackPage-DBsxnmPi.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{d as M,j as e,r as m,a as W,e as J,R as Y}from"./vendor-BcOI2aZ9.js";import{G as q}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 l of n)if(l.type==="childList")for(const i of l.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&t(i)}).observe(document,{childList:!0,subtree:!0});function s(n){const l={};return n.integrity&&(l.integrity=n.integrity),n.referrerPolicy&&(l.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?l.credentials="include":n.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function t(n){if(n.ep)return;n.ep=!0;const l=s(n);fetch(n.href,l)}})();const X="modulepreload",Z=function(a){return"/"+a},$={},j=function(r,s,t){let n=Promise.resolve();if(s&&s.length>0){let i=function(c){return Promise.all(c.map(d=>Promise.resolve(d).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),u=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));n=i(s.map(c=>{if(c=Z(c),c in $)return;$[c]=!0;const d=c.endsWith(".css"),p=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${p}`))return;const h=document.createElement("link");if(h.rel=d?"stylesheet":X,d||(h.as="script"),h.crossOrigin="",h.href=c,u&&h.setAttribute("nonce",u),document.head.appendChild(h),d)return new Promise((x,f)=>{h.addEventListener("load",x),h.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${c}`)))})}))}function l(i){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i}return n.then(i=>{for(const o of i||[])o.status==="rejected"&&l(o.reason);return r().catch(l)})},E=20128,L="127.0.0.1",ee=`http://${L}:${E}`,Ee=`${ee}/v1`,S=M(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:E),l=s.host||(typeof window<"u"&&window.location.hostname?window.location.hostname:L),i={dataDir:s.dataDir||"",dbPath:s.dbPath||"",isDevelopmentMode:!!s.isDevelopmentMode,appName:s.appName||"Mapigate",version:s.version||"",port:n,host:l,configuredHost:s.configuredHost||l,configuredPort:s.configuredPort||n,isRestartRequired:!!s.isRestartRequired};return a({info:i,loading:!1}),(async()=>{try{const o=await fetch("/api/settings/version");if(o.ok){const u=await o.json();a(c=>c.info?{...c,info:{...c.info,latestVersion:u.latestVersion,hasUpdate:!!u.hasUpdate}}:c)}}catch{}})(),i}}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{}}})),te=({currentTab:a,onSelectTab:r,onUpgradeClick:s})=>{const t=S(u=>u.info),n=t==null?void 0:t.version,l=(t==null?void 0:t.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):E),i=(t==null?void 0:t.host)||(typeof window<"u"&&window.location.hostname?window.location.hostname:L),o=[{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:o.map(u=>{const c=a===u.id;return e.jsxs("button",{onClick:()=>r(u.id),className:`rt-sidebar__nav-item ${c?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:u.icon}),e.jsx("span",{children:u.label})]},u.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 ",l]})]}),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:i})]}),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(q,{className:"size-3.5 text-slate-400"}),e.jsx("span",{children:"GitHub · joutvhu/mapigate"})]})]})]})},P="mapigate_auth_token";let F=!1;const R=new Set;function se(a){return R.add(a),()=>{R.delete(a)}}function K(){for(const a of R)try{a()}catch{}}class k{static getToken(){if(typeof window>"u")return null;try{return localStorage.getItem(P)}catch{return null}}static setToken(r){if(!(typeof window>"u"))try{localStorage.setItem(P,r)}catch{}}static removeToken(){if(!(typeof window>"u"))try{localStorage.removeItem(P)}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(),K()}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 ae(){if(typeof window>"u"||F)return;F=!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/"),l=t.includes("/api/auth/status")||t.includes("/api/auth/login");let i=s;const o=k.getToken();if(n&&o){const c=new Headers((s==null?void 0:s.headers)||(r instanceof Request?r.headers:void 0));c.has("Authorization")||c.set("Authorization",`Bearer ${o}`),i={...s,headers:c}}const u=await a(r,i);if(n&&!l&&u.status===401)try{const d=await u.clone().json();d&&d.code==="AUTH_REQUIRED"&&K()}catch{}return u}}ae();const w=M((a,r)=>({isChecking:!0,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1,checkAuth:async()=>{a({isChecking:!0});try{const s=await k.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 k.login(s);return t.success?(a({isAuthenticated:!0,isLocked:!1}),{success:!0}):{success:!1,error:t.error}},logout:async()=>{await k.logout();const s=r().isPasswordSet;a({isAuthenticated:!s,isLocked:s})},lock:()=>{r().isPasswordSet&&(k.removeToken(),a({isAuthenticated:!1,isLocked:!0}))},unlock:s=>{k.setToken(s),a({isAuthenticated:!0,isLocked:!1})}}));typeof window<"u"&&(se(()=>{w.getState().lock()}),window.addEventListener("storage",a=>{(a.key===P||a.key===null)&&(k.getToken()?w.setState({isAuthenticated:!0,isLocked:!1}):w.getState().isPasswordSet&&w.setState({isAuthenticated:!1,isLocked:!0}))}));const V=M(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(([i,o])=>!!o).map(([i])=>i),l={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:l,loading:!1}),l}}catch{}return a({loading:!1}),null}})),re={antigravity:"Antigravity",kiro:"Kiro",copilot:"GitHub Copilot",cursor:"Cursor"};function G(a){return!a||a.length===0?"":a.map(r=>re[r]||r.charAt(0).toUpperCase()+r.slice(1)).join(", ")}const H={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"}},ne=({currentTab:a,searchQuery:r,onSearchChange:s,detailProvider:t,onBackToProviders:n,onRestartClick:l,onSelectTab:i})=>{const o=H[a]||H.providers,u=w(v=>v.isPasswordSet),c=w(v=>v.lock),d=S(v=>v.info),p=S(v=>v.fetchSystemInfo);d==null||d.version;const h=V(v=>v.status),x=V(v=>v.fetchStatus);m.useEffect(()=>{x(),p();const v=setInterval(()=>{document.hidden||(x(),p())},1e4),z=()=>{x(),p()};return window.addEventListener("focus",z),()=>{clearInterval(v),window.removeEventListener("focus",z)}},[x,p]);const f=!!(h!=null&&h.running),b=(h==null?void 0:h.port)||443,y=(h==null?void 0:h.activeDnsCount)||0,N=(h==null?void 0:h.activeDnsTools)||[],C=!!(h!=null&&h.orphanedDns),g=(d==null?void 0:d.host)||"127.0.0.1",D=(d==null?void 0:d.configuredHost)||g,I=!!(d!=null&&d.isRestartRequired),A=g==="0.0.0.0";let B=A?`Network: LAN Active (0.0.0.0:${(d==null?void 0:d.port)||E}) • Accessible from local network • Click to configure Endpoint`:`Network: Local Only (127.0.0.1:${(d==null?void 0:d.port)||E}) • Isolated to this machine • Click to configure Endpoint`,O=A?"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",U=A?"wifi":"shield";I&&(B=`⚠️ Restart Required: Configured for ${D==="0.0.0.0"?"LAN Active":"Local Only"} (${D}), but running on ${g}. Click Restart button to apply.`,O="bg-amber-500/15 text-amber-300 border-amber-500/30 hover:bg-amber-500/25 animate-pulse",U="restart_alt");let T="MITM Proxy: Stopped • Click to open settings",_="text-slate-500 hover:text-slate-300";return C?(T=`⚠️ MITM Warning: Server stopped but ${y} DNS redirect(s) still active (${G(N)})! Tools cannot connect. Click to fix.`,_="text-amber-400 hover:text-amber-300 animate-pulse"):f?y>0?(T=`MITM Proxy: Active on port ${b} • ${y} tool DNS active (${G(N)}) • Click to manage`,_="text-emerald-400 hover:text-emerald-300"):(T=`MITM Proxy: Running on port ${b} (Idle, 0 tool DNS active) • Click to configure`,_="text-blue-400 hover:text-blue-300"):(T="MITM Proxy: Stopped • Click to open settings",_="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:o.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:o.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}`:o.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:()=>{I&&l?l():i==null||i("endpoint")},title:B,className:`w-8 h-8 rounded-lg border text-xs font-medium transition-all cursor-pointer shadow-xs inline-flex items-center justify-center ${O}`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:U})}),e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i("mitm"),title:T,className:`w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 ${_} 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:[l&&e.jsx("button",{type:"button",onClick:l,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"})}),u&&e.jsx("button",{type:"button",onClick:c,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(q,{className:"size-4"})})})]})]})},oe=()=>{const[a,r]=m.useState(""),[s,t]=m.useState(!1),[n,l]=m.useState(!1),[i,o]=m.useState(null),u=m.useRef(null),c=w(p=>p.login);m.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const d=async p=>{var x;if(p.preventDefault(),!a.trim()||n)return;l(!0),o(null);const h=await c(a);h.success||(o(h.error||"Incorrect master password"),l(!1),(x=u.current)==null||x.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:d,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:u,type:s?"text":"password",placeholder:"Enter master password...",value:a,onChange:p=>{r(p.target.value),i&&o(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"})})]}),i&&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:i})]}),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 le(a){let r={...a},s=!1,t=!1,n=0;const l=x=>{r={...x}},i=()=>{var f;if(r.disabled)return;const x=Date.now();x-n<250||(n=x,(f=r.onClose)==null||f.call(r))};return{updateOptions:l,handleMouseDown:x=>{r.disabled||(x.target===x.currentTarget&&(x.button===0||x.button===void 0)?s=!0:s=!1)},handleMouseUp:x=>{if(r.disabled){s=!1;return}s&&x.target===x.currentTarget&&(x.button===0||x.button===void 0)&&i(),s=!1},handleTouchStart:x=>{r.disabled||(x.target===x.currentTarget?t=!0:t=!1)},handleTouchEnd:x=>{if(r.disabled){t=!1;return}t&&x.target===x.currentTarget&&i(),t=!1},handleClick:x=>{r.disabled||x.detail===0&&x.target===x.currentTarget&&i()},reset:()=>{s=!1,t=!1},get isMouseDown(){return s},get isTouchStart(){return t}}}function ie(a,r=!1){const s=m.useRef(null);s.current?s.current.updateOptions({onClose:a,disabled:r}):s.current=le({onClose:a,disabled:r}),m.useEffect(()=>{if(typeof window>"u")return;const n=()=>{var i;(i=s.current)==null||i.reset()},l=()=>{var i;(i=s.current)==null||i.reset()};return window.addEventListener("mouseup",n),window.addEventListener("touchend",l),()=>{window.removeEventListener("mouseup",n),window.removeEventListener("touchend",l)}},[]);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 Q=({isOpen:a,onClose:r,children:s,maxWidthClass:t="max-w-xl",className:n="",overflowHidden:l=!1})=>{const{backdropProps:i}=ie(r);if(m.useEffect(()=>{if(!a)return;const u=d=>{d.key==="Escape"&&r()};document.addEventListener("keydown",u);const c=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",u),document.body.style.overflow=c}},[a,r]),!a||typeof document>"u")return null;const o=l?"overflow-hidden":n.includes("overflow-")?"":"overflow-visible";return W.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",...i,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 ${o} ${n}`,onClick:u=>u.stopPropagation(),children:s})}),document.body)},ce=({isOpen:a,onClose:r})=>{const[s,t]=m.useState("confirm"),[n,l]=m.useState(null),[i,o]=m.useState(0),u=m.useRef(null),c=m.useRef(null);m.useEffect(()=>(a?(t("confirm"),l(null),o(0)):(u.current&&clearInterval(u.current),c.current&&clearInterval(c.current)),()=>{u.current&&clearInterval(u.current),c.current&&clearInterval(c.current)}),[a]);const d=()=>{const h=Date.now();let x=0;c.current=setInterval(()=>{o(Math.floor((Date.now()-h)/1e3))},500),setTimeout(()=>{u.current=setInterval(async()=>{x+=1;try{const f=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(f.ok){const b=await f.json().catch(()=>null);(b==null?void 0:b.status)==="ok"&&(u.current&&clearInterval(u.current),c.current&&clearInterval(c.current),t("success"),setTimeout(()=>{window.location.reload()},600))}}catch{}x>=50&&(u.current&&clearInterval(u.current),c.current&&clearInterval(c.current),t("timeout"))},500)},600)},p=async()=>{t("restarting"),l(null);try{const h=await fetch("/api/server/restart",{method:"POST",headers:{"Content-Type":"application/json"}});if(!h.ok){const x=await h.json().catch(()=>({}));l(x.error||"Failed to initiate server restart."),t("confirm");return}}catch{}d()};return e.jsx(Q,{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 (",i,"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"]})]})]})]})})},de=({isOpen:a,onClose:r,currentVersion:s,latestVersion:t})=>{const[n,l]=m.useState("confirm"),[i,o]=m.useState(null),[u,c]=m.useState(0),d=m.useRef(null),p=m.useRef(null);m.useEffect(()=>(a?(l("confirm"),o(null),c(0)):(d.current&&clearInterval(d.current),p.current&&clearInterval(p.current)),()=>{d.current&&clearInterval(d.current),p.current&&clearInterval(p.current)}),[a]);const h=()=>{let f=0;setTimeout(()=>{d.current=setInterval(async()=>{f+=1;try{const b=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(b.ok){const y=await b.json().catch(()=>null);(y==null?void 0:y.status)==="ok"&&(d.current&&clearInterval(d.current),p.current&&clearInterval(p.current),l("success"),setTimeout(()=>{window.location.reload()},800))}}catch{}f>=60&&(d.current&&clearInterval(d.current),p.current&&clearInterval(p.current),l("timeout"))},500)},800)},x=async()=>{l("upgrading"),o(null),c(0);const f=Date.now();p.current=setInterval(()=>{c(Math.floor((Date.now()-f)/1e3))},500);try{const b=await fetch("/api/server/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:!1})}),y=await b.json().catch(()=>({}));if(!b.ok||!y.success){p.current&&clearInterval(p.current),o(y.error||"Failed to upgrade Mapigate."),l("error");return}l("restarting"),h()}catch(b){p.current&&clearInterval(p.current),o((b==null?void 0:b.message)||"Network error while requesting upgrade."),l("error")}};return e.jsx(Q,{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:x,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"," (",u,"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," (",u,"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"})]})]}),i&&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:i}),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:x,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"]})]})]})]})})},ue=m.lazy(()=>j(()=>import("./ProvidersTab-CPMTBmXq.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(a=>({default:a.ProvidersTab}))),xe=m.lazy(()=>j(()=>import("./ProviderDetailPage-DgClsBMU.js"),__vite__mapDeps([8,1,6,4,9,5,3,10,2,7])).then(a=>({default:a.ProviderDetailPage}))),me=m.lazy(()=>j(()=>import("./CombosTab-V_ldcQni.js"),__vite__mapDeps([11,1,12,3,4,5,9,2,7])).then(a=>({default:a.CombosTab}))),pe=m.lazy(()=>j(()=>import("./UsageTab-BDTnu1v_.js"),__vite__mapDeps([13,1,7,5,4,14,9])).then(a=>({default:a.UsageTab}))),he=m.lazy(()=>j(()=>import("./QuotaTab-NaCPxtWq.js"),__vite__mapDeps([15,1,4,5,9,10,2,7])).then(a=>({default:a.QuotaTab}))),fe=m.lazy(()=>j(()=>import("./CliToolsTab-D-0zU55K.js"),__vite__mapDeps([16,1,6,4,5,3,7])).then(a=>({default:a.CliToolsTab}))),be=m.lazy(()=>j(()=>import("./MitmTab-sRzVrlgW.js"),__vite__mapDeps([17,1,3,4,5,7])).then(a=>({default:a.MitmTab}))),ge=m.lazy(()=>j(()=>import("./EndpointTab-BHYn9Syj.js"),__vite__mapDeps([18,1,9,2,7])).then(a=>({default:a.EndpointTab}))),ve=m.lazy(()=>j(()=>import("./TokenSaverTab-B3Fbu_yc.js"),__vite__mapDeps([19,1])).then(a=>({default:a.TokenSaverTab}))),ye=m.lazy(()=>j(()=>import("./ConsoleLogTab-Byt7Fr4V.js"),__vite__mapDeps([20,1,9,7,5])).then(a=>({default:a.ConsoleLogTab}))),je=m.lazy(()=>j(()=>import("./SettingsTab-BUKXj5iT.js"),__vite__mapDeps([21,1,7])).then(a=>({default:a.SettingsTab}))),we=m.lazy(()=>j(()=>import("./CallbackPage-DBsxnmPi.js"),__vite__mapDeps([22,1])));function Ne(){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"))));if(typeof window<"u"&&(window.location.pathname==="/callback"||window.location.pathname==="/auth/callback"||window.location.pathname==="/authorize"||window.location.pathname.startsWith("/callback")||r))return e.jsx(we,{});const t=w(g=>g.isChecking),n=w(g=>g.isLocked),l=w(g=>g.checkAuth),i=S(g=>g.fetchSystemInfo);m.useEffect(()=>{l(),i()},[l,i]);const[o,u]=m.useState("providers"),[c,d]=m.useState(""),[p,h]=m.useState(null),[x,f]=m.useState(!1),[b,y]=m.useState(!1),N=S(g=>g.info),C=g=>{u(g),h(null)};return t?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"})}):n?e.jsx(oe,{}):e.jsxs("div",{className:"rt-app",children:[e.jsx(te,{currentTab:o,onSelectTab:C,onUpgradeClick:()=>y(!0)}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 h-full overflow-hidden",children:[e.jsx(ne,{currentTab:o,searchQuery:c,onSearchChange:d,detailProvider:p,onBackToProviders:()=>h(null),onRestartClick:()=>f(!0),onSelectTab:C}),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(Ne,{}),children:[o==="endpoint"&&e.jsx(ge,{onRestartClick:()=>f(!0)}),o==="providers"&&(p?e.jsx(xe,{provider:p,onBack:()=>h(null)}):e.jsx(ue,{searchQuery:c,onSelectProvider:g=>h(g)})),o==="combos"&&e.jsx(me,{}),o==="usage"&&e.jsx(pe,{}),o==="quota"&&e.jsx(he,{searchQuery:c}),o==="tokensaver"&&e.jsx(ve,{}),o==="clitools"&&e.jsx(fe,{}),o==="mitm"&&e.jsx(be,{}),o==="consolelog"&&e.jsx(ye,{}),o==="settings"&&e.jsx(je,{onRestartClick:()=>f(!0),onUpgradeClick:()=>y(!0)})]})})]}),e.jsx(ce,{isOpen:x,onClose:()=>f(!1)}),e.jsx(de,{isOpen:b,onClose:()=>y(!1),currentVersion:N==null?void 0:N.version,latestVersion:N==null?void 0:N.latestVersion})]})}J.createRoot(document.getElementById("root")).render(e.jsx(Y.StrictMode,{children:e.jsx(ke,{})}));export{k as A,E as D,Q as P,ce as R,ie as a,Ee as b,ee as c,L as d,V as e,w as f,S as u};
|