PageSourceSearch

https://scholar.0xpi.com/assets/AdminAPIUsage-HQLBQ3U9.js

js 0xpi.com collected 2026-09-28 06:12:26 UTC 14,991 bytes, 15 lines download raw bytes

1import{j as e}from"./vendor-three-Bmn2g83e.js";import{r as o}from"./vendor-react-kRHgybFd.js";import{a as g}from"./adminAxios-ByTPVtHS.js";import"./main-D9e5nRIT.js";/* empty css                    */import{az as h,a3 as m,a1 as p,e as b,Z as y}from"./vendor-misc-DSUDoLcJ.js";import{R as d,B as f,C as j,X as v,Y as u,T as n,a as S,P as z,b as A,c as C}from"./vendor-charts-Basmw1Gw.js";function R(){const[t,c]=o.useState(null),[x,s]=o.useState(!0);o.useEffect(()=>{a()},[]);const a=async()=>{try{s(!0);const r=await g.get("/api/admin/ai-usage");c(r.data),s(!1)}catch(r){console.error("Error loading API usage:",r),s(!1)}};if(x)return e.jsx("div",{className:"admin-content",children:e.jsxs("div",{style:{textAlign:"center",padding:"4rem"},children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{style:{color:"rgba(255,255,255,0.6)",marginTop:"1rem"},children:"Loading API usage data..."})]})});const l=["#8b5cf6","#10b981","#3b82f6","#f59e0b"];return e.jsxs("div",{className:"admin-content",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"2rem"},children:[e.jsxs("div",{children:[e.jsx("h1",{style:{fontSize:"32px",fontWeight:"800",background:"linear-gradient(135deg, #3E1A61 0%, #D41041 100%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",marginBottom:"0.5rem"},children:"🔌 API Usage & Costs"}),e.jsx("p",{style:{color:"rgba(255,255,255,0.6)",margin:0},children:"Monitor AI API usage, costs, and profit margins"})]}),e.jsxs("button",{onClick:a,className:"admin-button",children:[e.jsx(h,{size:18}),"Refresh"]})]}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:"700",color:"white",marginBottom:"1rem"},children:"Today's Performance"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"1.5rem",marginBottom:"2rem"},children:[e.jsx("div",{className:"admin-card",style:{background:"linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(124, 58, 237, 0.1) 100%)",border:"1px solid rgba(139, 92, 246, 0.3)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"API Calls"}),e.jsx("div",{style:{fontSize:"32px",fontWeight:"800",color:"#8b5cf6"},children:t?.today?.apiCalls?.toLocaleString()??0})]}),e.jsx(m,{size:40,color:"rgba(139, 92, 246, 0.3)"})]})}),e.jsx("div",{className:"admin-card",style:{background:"linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%)",border:"1px solid rgba(239, 68, 68, 0.3)"},children:e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Estimated Cost"}),e.jsxs("div",{style:{fontSize:"32px",fontWeight:"800",color:"#ef4444"},children:["$",t?.today?.estimatedCost?.toFixed(2)??"0.00"]})]})}),e.jsx("div",{className:"admin-card",style:{background:"linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.1) 100%)",border:"1px solid rgba(16, 185, 129, 0.3)"},children:e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Revenue"}),e.jsxs("div",{style:{fontSize:"32px",fontWeight:"800",color:"#10b981"},children:["$",t?.today?.revenue?.toFixed(2)??"0.00"]})]})}),e.jsx("div",{className:"admin-card",style:{background:"linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(37, 99, 235, 0.1) 100%)",border:"1px solid rgba(59, 130, 246, 0.3)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Profit"}),e.jsxs("div",{style:{fontSize:"32px",fontWeight:"800",color:"#3b82f6"},children:["$",t?.today?.profit?.toFixed(2)??"0.00"]}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"14px",marginTop:"0.5rem"},children:[t?.today?.profitMargin?.toFixed(1)??0,"% margin"]})]}),e.jsx(p,{size:40,color:"rgba(59, 130, 246, 0.3)"})]})})]}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:"700",color:"white",marginBottom:"1rem"},children:"This Month"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"1.5rem",marginBottom:"2rem"},children:[e.jsxs("div",{className:"admin-card",children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Total API Calls"}),e.jsx("div",{style:{fontSize:"28px",fontWeight:"700",color:"white"}
1,children:t?.thisMonth?.apiCalls?.toLocaleString()??0})]}),e.jsxs("div",{className:"admin-card",children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Total Cost"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"700",color:"#ef4444"},children:["$",t?.thisMonth?.estimatedCost?.toFixed(2)??"0.00"]})]}),e.jsxs("div",{className:"admin-card",children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Total Revenue"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"700",color:"#10b981"},children:["$",t?.thisMonth?.revenue?.toFixed(2)??"0.00"]})]}),e.jsxs("div",{className:"admin-card",children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:"14px",marginBottom:"0.5rem"},children:"Net Profit"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"700",color:"#3b82f6"},children:["$",t?.thisMonth?.profit?.toFixed(2)??"0.00"]})]})]}),t?.alerts?.length>0&&e.jsxs("div",{style:{background:"rgba(239,68,68,0.15)",border:"1px solid rgba(239,68,68,0.4)",borderRadius:"12px",padding:"1rem 1.5rem",marginBottom:"2rem",color:"#ef4444",fontWeight:600},children:["⚠️ ",t.alerts[0]]}),e.jsxs("h2",{style:{fontSize:"20px",fontWeight:"700",color:"white",marginBottom:"1rem"},children:[e.jsx(b,{size:20,style:{display:"inline",marginRight:"8px",color:"#8b5cf6"}}),"Master Intelligence AI"]}),e.jsxs("div",{className:"admin-card",style:{marginBottom:"2rem",border:"1px solid rgba(139,92,246,0.3)",background:"rgba(139,92,246,0.05)"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:"1.5rem",marginBottom:"1.5rem"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"Today's Cost"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"800",color:t?.masterAI?.todayCost>0?"#ef4444":"#10b981"},children:["$",t?.masterAI?.todayCost?.toFixed(4)??"0.0000"]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"Daily Cap"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"800",color:"#8b5cf6"},children:["$",t?.masterAI?.dailyCap?.toFixed(2)??"5.00"]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"Cap Remaining"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"800",color:"#10b981"},children:["$",t?.masterAI?.capRemaining?.toFixed(2)??"5.00"]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"Today's Calls"}),e.jsx("div",{style:{fontSize:"28px",fontWeight:"800",color:"white"},children:t?.masterAI?.todayCalls??0})]}),e.jsxs("div",{children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"This Month"}),e.jsxs("div",{style:{fontSize:"28px",fontWeight:"800",color:"#f59e0b"},children:["$",t?.masterAI?.monthCost?.toFixed(2)??"0.00"]})]})]}),e.jsxs("div",{style:{marginBottom:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"13px",color:"rgba(255,255,255,0.5)",marginBottom:"6px"},children:[e.jsx("span",{children:"Daily cap usage"}),e.jsxs("span",{children:[(t?.masterAI?.capUsedPct??0).toFixed(1),"%"]})]}),e.jsx("div",{style:{background:"rgba(255,255,255,0.1)",borderRadius:"99px",height:"8px",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"99px",width:`${t?.masterAI?.capUsedPct??0}%`,background:(t?.masterAI?.capUsedPct??0)>80?"#ef4444":(t?.masterAI?.capUsedPct??0)>50?"#f59e0b":"#10b981",transition:"width 0.5s ease"}})})]}),e.jsx("div",{style:{fontSize:"12px",color:"rgba(255,255,255,0.35)"},children:t?.masterAI?.schedule})]}),e.jsxs("h2",{style:{fontSize:"20px",fontWeight:"700",color:"white",marginBottom:"1rem"},children:[e.jsx(y,{size:20,style:{display:"inline",marginRight:"8px",color:"#10b981"}}),"Free vs Paid (Today)"]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"1.5rem",marginBottom:"2rem"},children:[e.jsxs("div",{className:"admin-card",style:{border:"1px solid rgba(16,185,129,0.3)",background:"rgba(16,185,129,0.05)"},children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"Free API Calls"}),e.jsx("div",{style:{fontSize:"28px",fontWeight:"800",color:"#10b981"},children:t?.freeVsPaid?.freeCalls??0}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:"12px",marginTop:"4px"}
1,children:[(t?.freeVsPaid?.freeTokens??0).toLocaleString()," tokens — $0.00"]})]}),e.jsxs("div",{className:"admin-card",style:{border:"1px solid rgba(239,68,68,0.3)",background:"rgba(239,68,68,0.05)"},children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"13px",marginBottom:"4px"},children:"Paid API Calls"}),e.jsx("div",{style:{fontSize:"28px",fontWeight:"800",color:"#ef4444"},children:t?.freeVsPaid?.paidCalls??0}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:"12px",marginTop:"4px"},children:["$",(t?.freeVsPaid?.paidCost??0).toFixed(4)," cost"]})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(400px, 1fr))",gap:"1.5rem",marginBottom:"2rem"},children:[e.jsxs("div",{className:"admin-card",children:[e.jsx("h3",{style:{fontSize:"18px",fontWeight:"700",color:"white",marginBottom:"1.5rem"},children:"Usage by AI Model"}),t?.byModel&&t.byModel.length>0&&e.jsx(d,{width:"100%",height:300,children:e.jsxs(f,{data:t.byModel,children:[e.jsx(j,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.1)"}),e.jsx(v,{dataKey:"model",stroke:"rgba(255,255,255,0.5)"}),e.jsx(u,{stroke:"rgba(255,255,255,0.5)"}),e.jsx(n,{contentStyle:{background:"#1f2937",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px"}}),e.jsx(S,{dataKey:"calls",fill:"#8b5cf6"})]})})]}),e.jsxs("div",{className:"admin-card",children:[e.jsx("h3",{style:{fontSize:"18px",fontWeight:"700",color:"white",marginBottom:"1.5rem"},children:"Usage by Feature"}),t?.byFeature&&t.byFeature.length>0&&e.jsx(d,{width:"100%",height:300,children:e.jsxs(z,{children:[e.jsx(A,{data:t.byFeature,dataKey:"usage",nameKey:"feature",cx:"50%",cy:"50%",outerRadius:100,label:r=>r.feature,children:t.byFeature.map((r,i)=>e.jsx(C,{fill:l[i%l.length]},`cell-${i}`))}),e.jsx(n,{contentStyle:{background:"#1f2937",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px"}})]})})]})]}),e.jsxs("div",{style:{display:"grid",gap:"1.5rem"},children:[e.jsxs("div",{className:"admin-card",children:[e.jsx("h3",{style:{fontSize:"18px",fontWeight:"700",color:"white",marginBottom:"1.5rem"},children:"Cost Breakdown by Model"}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid rgba(255,255,255,0.1)"},children:[e.jsx("th",{style:{padding:"1rem",textAlign:"left",color:"rgba(255,255,255,0.6)"},children:"Model"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Calls"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Cost"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Revenue"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Profit"})]})}),e.jsx("tbody",{children:t?.byModel?.map((r,i)=>e.jsxs("tr",{style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[e.jsxs("td",{style:{padding:"1rem",color:"white"},children:[r.model,r.isFree&&e.jsx("span",{style:{marginLeft:"8px",fontSize:"11px",background:"rgba(16,185,129,0.2)",color:"#10b981",borderRadius:"4px",padding:"2px 6px"},children:"FREE"})]}),e.jsx("td",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.7)"},children:r.calls.toLocaleString()}),e.jsxs("td",{style:{padding:"1rem",textAlign:"right",color:"#ef4444"},children:["$",r.cost.toFixed(2)]}),e.jsxs("td",{style:{padding:"1rem",textAlign:"right",color:"#10b981"},children:["$",r.revenue.toFixed(2)]}),e.jsxs("td",{style:{padding:"1rem",textAlign:"right",color:"#3b82f6",fontWeight:"600"},children:["$",(r.revenue-r.cost).toFixed(2)]})]},i))})]})})]}),e.jsxs("div",{className:"admin-card",children:[e.jsx("h3",{style:{fontSize:"18px",fontWeight:"700",color:"white",marginBottom:"1.5rem"},children:"Revenue by Feature"}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid rgba(255,255,255,0.1)"},children:[e.jsx("th",{style:{padding:"1rem",textAlign:"left",color:"rgba(255,255,255,0.6)"},children:"Feature"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Usage"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Cost"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Revenue"}),e.jsx("th",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.6)"},children:"Profit"})]})}),e.jsx("tbody",{children:t?.byFeature?.map((r,i)=>e.jsxs("tr",{style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[e.jsx("td",{style:{padding:"1rem",color:"white"},children:r.feature}),e.jsx("td",{style:{padding:"1rem",textAlign:"right",color:"rgba(255,255,255,0.7)"}
1,children:r.usage.toLocaleString()}),e.jsxs("td",{style:{padding:"1rem",textAlign:"right",color:"#ef4444"},children:["$",r.cost.toFixed(2)]}),e.jsxs("td",{style:{padding:"1rem",textAlign:"right",color:"#10b981"},children:["$",r.revenue.toFixed(2)]}),e.jsxs("td",{style:{padding:"1rem",textAlign:"right",color:"#3b82f6",fontWeight:"600"},children:["$",(r.revenue-r.cost).toFixed(2)]})]},i))})]})})]})]}),e.jsx("style",{children:`
2        .spinner {
3          border: 4px solid rgba(255, 255, 255, 0.1);
4          border-top: 4px solid #3E1A61;
5          border-radius: 50%;
6          width: 40px;
7          height: 40px;
8          animation: spin 1s linear infinite;
9          margin: 0 auto;
10        }
11        @keyframes spin {
12          0% { transform: rotate(0deg); }
13          100% { transform: rotate(360deg); }
14        }
15      `})]})}export{R as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.