TuringToken/dist/assets/index-DPPKIyse.js

17 lines
30 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{j as e}from"./semi-ui-fcB3D8nU.js";import{r as c}from"./react-core-C8o2IdY8.js";import{ax as W,bC as te,A as X,s as J,aG as V,bD as se,bE as H,bF as ae,bg as A,bG as ne,bH as re,aU as le,bI as oe,bJ as de,bn as ee,bK as ie,bL as ce,b0 as xe,bM as he,bN as me,bO as ue,ay as be,bP as pe}from"./index-DApEyau7.js";import"./i18n-DJWjvQyM.js";import"./tools-qobPTha0.js";import"./react-components-KaTRN41W.js";/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const ge=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],fe=W("inbox",ge);/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const we=[["path",{d:"M5 12h14",key:"1ays0h"}]],ke=W("minus",we);/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const je=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],Ne=W("trending-down",je),Q=200,T=t=>(t==null?void 0:t.type)===0||(t==null?void 0:t.type)===1||(t==null?void 0:t.type)===2||(t==null?void 0:t.status)===0||(t==null?void 0:t.type)==="success",I=(t,r)=>t.reduce((n,o)=>n+(Number(o[r])||0),0),G=t=>t.reduce((r,n)=>r+(Number(n==null?void 0:n.prompt_tokens)||0)+(Number(n==null?void 0:n.completion_tokens)||0),0),ve=(t,r=7)=>{const n=c.useRef(!1),[o,x]=c.useState(!1),[d,N]=c.useState([]),[w,b]=c.useState([]),[y,D]=c.useState(!1),$=te(),C=t==null?void 0:t.user,f=Number((C==null?void 0:C.quota)||0),E=Number((C==null?void 0:C.used_quota)||0),v=f+E,k=c.useCallback(async()=>{x(!0);try{const l=Math.floor(Date.now()/1e3),i=l-30*86400,h=$?`/api/log/?p=0&page_size=${Q}&start_timestamp=${i}&end_timestamp=${l}`:`/api/log/self/?p=0&page_size=${Q}&start_timestamp=${i}&end_timestamp=${l}`,m=await X.get(h),{success:p,message:s,data:a}=m.data;p?N((a==null?void 0:a.items)||[]):J(s)}catch(l){console.error(l)}finally{x(!1)}},[$]),M=c.useCallback(async()=>{D(!0);try{const l=await X.get("/api/uptime/status"),{success:i,message:h,data:m}=l.data;i?b(m||[]):J(h)}catch(l){console.error(l)}finally{D(!1)}},[]);c.useEffect(()=>{n.current||(k(),M(),n.current=!0)},[k,M]);const _=c.useMemo(()=>{const l=new Date,i=new Date(l.getFullYear(),l.getMonth(),l.getDate()).getTime()/1e3,h=new Date(l.getFullYear(),l.getMonth(),1).getTime()/1e3,m=d.filter(a=>((a==null?void 0:a.created_at)||0)>=i&&T(a)),p=d.filter(a=>((a==null?void 0:a.created_at)||0)>=h&&T(a)),s=m.map(a=>Number(a==null?void 0:a.use_time)||0).filter(a=>a>0);return{today:{requests:m.length,tokens:G(m),cost:I(m,"quota"),avgLatency:s.length>0?Math.round(s.reduce((a,j)=>a+j,0)/s.length):null},month:{requests:p.length,tokens:G(p),cost:I(p,"quota")}}},[d]),R=c.useMemo(()=>{const l=new Date,i=[],h=r;for(let m=h-1;m>=0;m--){const p=new Date(l.getFullYear(),l.getMonth(),l.getDate()-m),s=Math.floor(p.getTime()/1e3),a=s+86400,j=d.filter(g=>((g==null?void 0:g.created_at)||0)>=s&&((g==null?void 0:g.created_at)||0)<a&&T(g)),u={};j.forEach(g=>{const K=(g==null?void 0:g.model_name)||"未知模型";u[K]=(u[K]||0)+1}),i.push({date:p,count:j.length,cost:I(j,"quota"),tokens:G(j),models:u})}return i},[d,r]),L=c.useMemo(()=>{const l=new Date,i=new Date(l.getFullYear(),l.getMonth()-1,1).getTime()/1e3,h=new Date(l.getFullYear(),l.getMonth(),1).getTime()/1e3,m=d.filter(s=>((s==null?void 0:s.created_at)||0)>=i&&((s==null?void 0:s.created_at)||0)<h&&T(s)),p=I(m,"quota");return p===0?null:(_.month.cost-p)/p*100},[d,_.month.cost]),S=c.useMemo(()=>{const l=new Date,i=new Date(l.getFullYear(),l.getMonth()+1,0).getDate(),h=l.getDate(),m=_.month.cost,p=h>0?m/h:0,s=Math.round(p*i);return{spent:m,balance:f,dailyAvg:Math.round(p),daysInMonth:i,daysElapsed:h,projected:s,monthDelta:L}},[_.month.cost,f,L]),F=c.useMemo(()=>{const i=new Date().getDate();if(_.month.cost===0||i===0)return null;const h=_.month.cost/i;if(h===0)return null;const m=Math.floor(f/h);return m>0?m:0},[_.month.cost,f]),O=c.useMemo(()=>{const l=d.length,i=d.filter(u=>T(u)).length,h=l>0?(l-i)/l*100:null,m=d.map(u=>Number(u==null?void 0:u.use_time)||0).filter(u=>u>0).sort((u,g)=>u-g),p=m.length>0?m[Math.min(m.length-1,Math.floor(m.length*.95))]:null,s=w.filter(u=>(u==null?void 0:u.status)===1).length,a=w.length>0?w.reduce((u,g)=>u+(Number(g==null?void 0:g.uptime)||0),0)/w.length:null,j=a!=null?a*100:s/Math.max(w.length,1)*100;return{uptime:a!=null?j:null,errorRate:h,p95Latency:p,totalCalls:l,channelCount:w.length,healthyChannels:s}},[d,w]),B=c.useMemo(()=>{const l=new Map;return d.forEach(i=>{const h=(i==null?void 0:i.model_name)||"未知模型";l.set(h,(l.get(h)||0)+1)}),Array.from(l.entries()).map(([i,h])=>({name:i,count:h})).sort((i,h)=>h.count-i.count).slice(0,5)},[d]),Y=c.useCallback(async()=>{await Promise.all([k(),M()])},[k,M]);return{loading:o,recentLogs:d,uptimeData:w,uptimeLoading:y,metrics:_,dailyStats:R,monthDelta:L,daysRemaining:F,topModels:B,sla:O,monthlyForecast:S,refresh:Y,quotaTotal:v}},ye=({onSearch:t,onRefresh:r,loading:n,user:o,unreadCount:x=0})=>{const d=((o==null?void 0:o.username)||"?").charAt(0).toUpperCase(),N=Number((o==null?void 0:o.quota)||0);return e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200 py-5 dark:border-white/10",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("span",{className:"text-base font-semibold tracking-tight text-slate-900 dark:text-white",children:V()})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:t,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-1.5 text-xs text-slate-500 transition-colors hover:border-slate-300 hover:bg-slate-50 hover:text-slate-700 dark:border-white/10 dark:bg-white/[0.02] dark:text-white/60 dark:hover:bg-white/5 dark:hover:text-white",title:"搜索",children:[e.jsx(se,{size:13,className:"text-slate-400 dark:text-white/40"}),e.jsx("span",{children:"搜索"})]}),e.jsx("button",{onClick:r,disabled:n,className:"flex h-8 w-8 items-center justify-center rounded-full border border-slate-200 bg-white text-slate-500 transition-colors hover:border-slate-300 hover:bg-slate-50 hover:text-slate-700 disabled:opacity-50 dark:border-white/10 dark:bg-white/[0.02] dark:text-white/60 dark:hover:bg-white/5 dark:hover:text-white",title:"刷新",children:e.jsx(H,{size:13,className:n?"animate-spin":""})}),e.jsxs("a",{href:"/console/topup",className:"hidden items-center gap-1.5 rounded-full border border-slate-200 bg-white px-3 py-1.5 text-sm transition-colors hover:border-slate-300 hover:bg-slate-50 sm:inline-flex dark:border-white/10 dark:bg-white/[0.02] dark:hover:bg-white/5",title:"账户余额",children:[e.jsx(ae,{size:13,className:"text-slate-400 dark:text-white/40"}),e.jsx("span",{className:"font-mono font-semibold tabular-nums text-emerald-600 dark:text-emerald-400",children:A(N)})]}),e.jsxs("div",{className:"relative ml-1 flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-slate-100 text-xs font-semibold text-slate-700 dark:border-white/10 dark:bg-white/5 dark:text-white/80",children:[d,x>0&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-[16px] min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-[9px] font-mono text-white",children:x>99?"99+":x})]})]})]})},Me=()=>{const t=new Date().getHours();return t<5?"深夜好":t<12?"早上好":t<14?"中午好":t<18?"下午好":"晚上好"},De=({user:t})=>{const r=c.useMemo(()=>{const n=new Date,o=["周日","周一","周二","周三","周四","周五","周六"];return`${n.getFullYear()}${n.getMonth()+1}${n.getDate()}日 · ${o[n.getDay()]}`},[]);return e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-4",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-1.5 w-1.5 rounded-full bg-emerald-500"}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-white/50",children:r})]}),e.jsxs("h1",{className:"text-2xl font-semibold leading-tight tracking-tight md:text-3xl",children:[e.jsxs("span",{className:"text-slate-500 dark:text-white/60",children:[Me(),""]}),e.jsx("span",{className:"text-slate-900 dark:text-white",children:(t==null?void 0:t.username)||"访客"})]})]})})},q=t=>{if(t==null||isNaN(t))return"—";const r=Number(t);return r>=1e6?(r/1e6).toFixed(1)+"M":r>=1e3?(r/1e3).toFixed(1)+"K":r.toLocaleString()},Ce=t=>t==null?"—":t<1?`${Math.round(t*1e3)}ms`:`${t.toFixed(2)}s`,z=({label:t,value:r,unit:n,sub:o,delta:x,icon:d,className:N=""})=>e.jsxs("div",{className:`relative flex flex-col gap-3 rounded-2xl border border-slate-200 bg-white p-5 transition-shadow hover:shadow-md dark:border-white/5 dark:bg-white/[0.02] dark:hover:shadow-black/20 ${N}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-slate-100 text-slate-600 dark:bg-white/5 dark:text-white/70",children:e.jsx(d,{size:16})}),e.jsx("div",{className:"text-sm font-semibold text-slate-900 dark:text-white",children:t})]}),e.jsx("div",{className:"flex flex-1 flex-col justify-center",children:e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"font-mono text-3xl font-bold tabular-nums leading-none text-slate-900 md:text-4xl dark:text-white",children:r}),n&&e.jsx("span",{className:"text-xs text-slate-400 dark:text-white/40",children:n})]})}),e.jsxs("div",{className:"space-y-1.5",children:[x!=null&&e.jsxs("div",{className:`inline-flex items-center gap-1.5 text-xs tabular-nums ${x<0?"text-emerald-600 dark:text-emerald-400":x>0?"text-red-500 dark:text-red-400":"text-slate-500 dark:text-white/50"}`,children:[e.jsxs("span",{className:"font-semibold",children:[x>0?"↑":x<0?"↓":"·"," ",Math.abs(x).toFixed(0),"%"]}),e.jsx("span",{className:"font-normal text-slate-400 dark:text-white/40",children:"对比上月"})]}),o&&e.jsx("div",{className:"text-[11px] text-slate-500 tabular-nums dark:text-white/40",children:o})]})]}),$e=({metrics:t,monthDelta:r})=>e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"今日请求",value:t.today.requests,unit:"次",sub:e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:q(t.today.tokens)})," ","tokens",e.jsx("span",{className:"mx-1.5 text-slate-300 dark:text-white/30",children:"·"}),A(t.today.cost)]}),icon:ne}),e.jsx(z,{label:"今日 token",value:q(t.today.tokens),unit:"tokens",sub:`今日花费 ${A(t.today.cost)}`,icon:re}),e.jsx(z,{label:"平均响应",value:Ce(t.today.avgLatency),sub:"今日成功调用",icon:le}),e.jsx(z,{label:"本月消费",value:t.month.cost?A(t.month.cost):"—",sub:e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold tabular-nums text-slate-900 dark:text-white",children:t.month.requests})," ","次调用",e.jsx("span",{className:"mx-1.5 text-slate-300 dark:text-white/30",children:"·"}),e.jsx("span",{className:"tabular-nums",children:q(t.month.tokens)})," tokens"]}),delta:r,icon:oe}),e.jsx(z,{label:"累计 token",value:q(t.month.tokens),unit:"本月",sub:"输入+输出",icon:de})]}),_e=({data:t=[],height:r=80,stroke:n="currentColor",onHover:o})=>{const[x,d]=c.useState(null);if(!t||t.length===0)return null;const N=Math.max(...t,1),w=t.length,b=400,y=t.map((v,k)=>w>1?k/(w-1)*b:b/2),D=t.map(v=>r-v/N*(r-8)-4),$=y.map((v,k)=>`${v.toFixed(1)},${D[k].toFixed(1)}`).join(" "),C=`0,${r} ${$} ${b},${r}`,f=c.useCallback(v=>{const M=v.currentTarget.getBoundingClientRect(),_=(v.clientX-M.left)/M.width*b,R=y.map(S=>Math.abs(S-_)),L=R.indexOf(Math.min(...R));d(L),o==null||o(L,v.clientX,v.clientY)},[y,b,o]),E=c.useCallback(()=>{d(null),o==null||o(-1)},[o]);return e.jsxs("svg",{width:"100%",height:r,viewBox:`0 0 ${b} ${r}`,preserveAspectRatio:"none",className:"cursor-crosshair",onMouseMove:f,onMouseLeave:E,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"sg",x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[e.jsx("stop",{offset:"0%",stopColor:n,stopOpacity:"0.12"}),e.jsx("stop",{offset:"100%",stopColor:n,stopOpacity:"0"})]})}),x!=null&&e.jsx("line",{x1:y[x].toFixed(1),y1:0,x2:y[x].toFixed(1),y2:r,stroke:n,strokeWidth:"1",strokeDasharray:"3 3",opacity:"0.3",vectorEffect:"non-scaling-stroke"}),e.jsx("polygon",{points:C,fill:"url(#sg)"}),e.jsx("polyline",{points:$,fill:"none",stroke:n,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"}),t.map((v,k)=>{const M=x===k;return e.jsx("circle",{cx:y[k].toFixed(1),cy:D[k].toFixed(1),r:M?5:3,fill:M?n:"white",stroke:n,strokeWidth:M?3:2,vectorEffect:"non-scaling-stroke",style:{transition:"r 0.15s, fill 0.15s"}},k)})]})},Le=t=>{const r=t.getMonth()+1,n=t.getDate();return`${r}/${n}`},U=["#10b981","#3b82f6","#8b5cf6","#f59e0b"],Ae="#3b82f6",Z=[{key:"today",label:"今天"},{key:"yesterday",label:"昨天"},{key:"24h",label:"近 24 小时"},{key:"7d",label:"近 7 天"},{key:"14d",label:"近 14 天"},{key:"30d",label:"近 30 天"},{key:"thisMonth",label:"本月"},{key:"lastMonth",label:"上月"}],Ee=({dailyStats:t=[],topModels:r=[],className:n="",onRefresh:o,loading:x=!1,rangeKey:d="7d",onRangeChange:N})=>{var m,p;const[w,b]=c.useState(!1),[y,D]=c.useState(""),[$,C]=c.useState(""),[f,E]=c.useState(null),v=c.useRef(null),k=c.useRef(null);c.useEffect(()=>{const s=a=>{v.current&&!v.current.contains(a.target)&&b(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const M=((m=Z.find(s=>s.key===d))==null?void 0:m.label)||"近 7 天",_=()=>{y&&$&&N("custom"),b(!1)},R=c.useCallback((s,a,j)=>{var g;if(s<0||s>=t.length){E(null);return}const u=(g=k.current)==null?void 0:g.getBoundingClientRect();E({dayIdx:s,x:u?a-u.left:a,y:u?j-u.top-120:j-120})},[t.length]),L=c.useMemo(()=>t.map(s=>s.count),[t]),S=c.useMemo(()=>t.map(s=>s.cost),[t]),F=L.reduce((s,a)=>s+a,0),O=S.reduce((s,a)=>s+a,0),B=F>0?(F/Math.max(L.length,1)).toFixed(1):"0.0",Y=L.length>0?Math.max(...L):0,l=((p=r[0])==null?void 0:p.count)||0,i=f?t[f.dayIdx]:null,h=i?Object.entries(i.models||{}).sort((s,a)=>a[1]-s[1]):[];return e.jsxs("div",{className:`relative flex flex-col gap-4 rounded-2xl border border-slate-200 bg-white p-6 transition-shadow hover:shadow-md dark:border-white/5 dark:bg-white/[0.02] dark:hover:shadow-black/20 ${n}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-blue-50 text-blue-600 dark:bg-blue-500/10 dark:text-blue-400",children:e.jsx(ee,{size:18})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-slate-900 dark:text-white",children:"Token 使用趋势"}),e.jsxs("div",{className:"mt-0.5 text-[11px] text-slate-400 tabular-nums dark:text-white/40",children:[M,e.jsxs("span",{className:"font-semibold text-slate-900 dark:text-white",children:[" ",F]})," 次 · 日均"," ",e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:B})]})]})]}),e.jsxs("div",{className:"hidden text-right md:block",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-slate-400 font-mono dark:text-white/30",children:"花费"}),e.jsx("div",{className:"font-mono text-sm font-semibold tabular-nums text-emerald-600 dark:text-emerald-400",children:O>0?A(O):"—"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",ref:v,children:[e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>b(!w),className:"inline-flex items-center gap-1.5 rounded-full border border-slate-200 bg-white px-3 py-1.5 text-xs font-medium text-slate-700 transition-colors hover:border-slate-300 dark:border-white/10 dark:bg-white/[0.02] dark:text-white/70 dark:hover:bg-white/5",children:[M,e.jsx(ie,{size:12,className:"text-slate-400 dark:text-white/40"})]}),w&&e.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 rounded-xl border border-slate-200 bg-white p-3 shadow-lg dark:border-white/10 dark:bg-neutral-900",children:[e.jsx("div",{className:"space-y-0.5",children:Z.map(s=>e.jsx("button",{onClick:()=>{N(s.key),D(""),C(""),b(!1)},className:`w-full rounded-lg px-3 py-1.5 text-left text-xs transition-colors ${d===s.key?"bg-blue-50 font-medium text-blue-700 dark:bg-blue-500/10 dark:text-blue-400":"text-slate-600 hover:bg-slate-50 dark:text-white/60 dark:hover:bg-white/5"}`,children:s.label},s.key))}),e.jsx("div",{className:"my-2 border-t border-slate-100 dark:border-white/5"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"date",value:y,onChange:s=>D(s.target.value),className:"flex-1 rounded-lg border border-slate-200 bg-white px-2 py-1 text-xs text-slate-700 outline-none focus:border-blue-400 dark:border-white/10 dark:bg-white/[0.02] dark:text-white/70",placeholder:"开始日期"}),e.jsx("span",{className:"text-xs text-slate-400",children:"—"}),e.jsx("input",{type:"date",value:$,onChange:s=>C(s.target.value),className:"flex-1 rounded-lg border border-slate-200 bg-white px-2 py-1 text-xs text-slate-700 outline-none focus:border-blue-400 dark:border-white/10 dark:bg-white/[0.02] dark:text-white/70",placeholder:"结束日期"})]}),e.jsx("button",{onClick:_,disabled:!y||!$,className:"w-full rounded-lg bg-blue-600 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-700 disabled:opacity-40 dark:bg-blue-500 dark:hover:bg-blue-600",children:"应用"})]})]})]}),e.jsx("button",{onClick:o,disabled:x,className:"flex h-7 w-7 items-center justify-center rounded-full border border-slate-200 bg-white text-slate-500 transition-colors hover:border-slate-300 hover:bg-slate-50 hover:text-slate-700 disabled:opacity-50 dark:border-white/10 dark:bg-white/[0.02] dark:text-white/60 dark:hover:bg-white/5 dark:hover:text-white",title:"刷新",children:e.jsx(H,{size:12,className:x?"animate-spin":""})})]}),e.jsxs("div",{className:"hidden items-center gap-3 sm:flex",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-slate-400 dark:text-white/40",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-blue-500"}),"峰值 ",e.jsx("span",{className:"font-semibold text-slate-700 dark:text-white/80",children:Y})," 次"]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-slate-400 dark:text-white/40",children:["合计 ",e.jsx("span",{className:"font-semibold text-slate-700 dark:text-white/80",children:F})," 次"]})]})]}),e.jsxs("div",{ref:k,className:"relative flex min-h-[80px] flex-1 items-end text-blue-500",children:[e.jsx(_e,{data:L,height:80,stroke:Ae,onHover:R}),f&&i&&e.jsxs("div",{className:"pointer-events-none absolute z-50 min-w-[180px] rounded-xl border border-slate-200 bg-white px-4 py-3 shadow-lg dark:border-white/10 dark:bg-neutral-900",style:{left:f.x,top:f.y,transform:"translate(-50%, -100%)"},children:[e.jsxs("div",{className:"mb-1 text-xs font-semibold text-slate-900 dark:text-white",children:[i.date.getMonth()+1,"月",i.date.getDate(),"日"]}),e.jsxs("div",{className:"mb-2 flex items-center gap-3 text-[11px] text-slate-500 dark:text-white/50",children:[e.jsxs("span",{children:["调用 ",e.jsx("b",{className:"text-slate-900 dark:text-white",children:i.count})," 次"]}),e.jsxs("span",{children:["花费 ",e.jsx("b",{className:"text-slate-900 dark:text-white",children:A(i.cost)})]})]}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-1.5 h-px bg-slate-100 dark:bg-white/5"}),e.jsx("div",{className:"space-y-1",children:h.slice(0,5).map(([s,a],j)=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:U[j%U.length]}}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-slate-600 dark:text-white/70",children:s}),e.jsx("span",{className:"shrink-0 font-mono tabular-nums text-slate-400 dark:text-white/40",children:a})]},s))})]})]})]}),e.jsx("div",{className:"flex items-center justify-between text-[11px]",children:e.jsx("div",{className:"flex w-full items-center justify-between tabular-nums",children:t.map((s,a)=>{const j=(f==null?void 0:f.dayIdx)===a;return e.jsx("span",{className:`text-center text-xs transition-colors ${j?"font-semibold text-blue-600 dark:text-blue-400":"text-slate-500 dark:text-white/50"}`,children:Le(s.date)},a)})})}),r.length>0&&e.jsxs("div",{className:"border-t border-slate-100 pt-4 dark:border-white/5",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-[11px] uppercase tracking-wider text-slate-400 dark:text-white/40",children:[e.jsx("span",{children:"Top 5 模型"}),e.jsx("span",{className:"font-mono normal-case tracking-normal",children:"近 30 日"})]}),e.jsx("ul",{className:"space-y-1.5",children:r.map((s,a)=>{const j=l>0?s.count/l*100:0,u=U[a%U.length];return e.jsxs("li",{className:"flex items-center gap-3 text-xs",title:s.name,children:[e.jsx("span",{className:"w-3 shrink-0 text-right font-mono text-[10px] tabular-nums",style:{color:u},children:a+1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-slate-700 dark:text-white/80",children:s.name}),e.jsx("div",{className:"hidden h-1 w-24 overflow-hidden rounded-full bg-slate-100 sm:block dark:bg-white/5",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${j}%`,backgroundColor:u}})}),e.jsx("span",{className:"w-12 shrink-0 text-right font-mono tabular-nums text-slate-500 dark:text-white/60",children:s.count})]},s.name+a)})})]})]})},P=({label:t,value:r,hint:n})=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-slate-400 dark:text-white/40",children:t}),e.jsx("div",{className:"mt-1 font-mono text-base font-semibold tabular-nums text-slate-900 dark:text-white",children:r}),n&&e.jsx("div",{className:"mt-0.5 text-[11px] text-slate-400 tabular-nums dark:text-white/40",children:n})]}),Re=({forecast:t={},className:r=""})=>{const{spent:n=0,balance:o=0,dailyAvg:x=0,daysInMonth:d=0,daysElapsed:N=0,projected:w=0,monthDelta:b=null}=t,y=Math.max(0,d-N),D=n>0,$=D&&o>0&&w>o,C=b==null?ke:b>0?ee:Ne,f=b==null?"text-slate-500 dark:text-white/50":b>5?"text-red-500 dark:text-red-400":b<-5?"text-emerald-600 dark:text-emerald-400":"text-slate-500 dark:text-white/50";return e.jsxs("div",{className:`relative flex flex-col gap-5 rounded-2xl border border-slate-200 bg-white p-6 transition-shadow hover:shadow-md dark:border-white/5 dark:bg-white/[0.02] dark:hover:shadow-black/20 ${r}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-slate-100 text-slate-600 dark:bg-white/5 dark:text-white/70",children:e.jsx(ce,{size:18})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-slate-900 dark:text-white",children:"本月账单预测"}),e.jsxs("div",{className:"mt-0.5 text-[11px] text-slate-400 tabular-nums dark:text-white/40",children:["已过 ",N," / ",d," 天 · 剩 ",y," 天"]})]})]}),e.jsxs("div",{className:"border-t border-slate-100 pt-4 dark:border-white/5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-slate-400 dark:text-white/40",children:"月底预计"}),e.jsx("div",{className:`mt-1.5 font-mono text-3xl font-bold tabular-nums leading-none md:text-4xl ${$?"text-red-500 dark:text-red-400":"text-slate-900 dark:text-white"}`,children:D?A(w):"—"}),b!=null&&e.jsxs("div",{className:`mt-2 inline-flex items-center gap-1 text-xs tabular-nums ${f}`,children:[e.jsx(C,{size:12}),e.jsxs("span",{className:"font-semibold",children:[b>0?"+":"",b.toFixed(0),"%"]}),e.jsx("span",{className:"text-slate-400 dark:text-white/40",children:"较上月"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 border-t border-slate-100 pt-4 dark:border-white/5",children:[e.jsx(P,{label:"已花费",value:D?A(n):"—",hint:`${N} 天累计`}),e.jsx(P,{label:"日均",value:D?A(x):"—",hint:"本月至今日"}),e.jsx(P,{label:"账户余额",value:o>0?A(o):"—",hint:$?"预计不足":"可继续使用"})]})]})},Fe=t=>(t==null?void 0:t.type)===0||(t==null?void 0:t.type)===1||(t==null?void 0:t.type)===2||(t==null?void 0:t.status)===0||(t==null?void 0:t.type)==="success"||(t==null?void 0:t.type)===void 0,Se=({logs:t=[],className:r=""})=>{const n=c.useMemo(()=>t.slice(0,10),[t]);return e.jsxs("div",{className:`relative overflow-hidden rounded-2xl border border-slate-200 bg-white transition-shadow hover:shadow-md dark:border-white/5 dark:bg-white/[0.02] dark:hover:shadow-black/20 ${r}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-6 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-slate-100 text-slate-600 dark:bg-white/5 dark:text-white/70",children:e.jsx(xe,{size:18})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-slate-900 dark:text-white",children:"最近调用"}),e.jsxs("div",{className:"mt-0.5 text-[11px] text-slate-400 tabular-nums dark:text-white/40",children:["共"," ",e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:n.length})," ","条记录"]})]})]}),e.jsxs("a",{href:"/console/log",className:"flex items-center gap-1 text-xs text-slate-500 transition-colors hover:text-slate-900 dark:text-white/60 dark:hover:text-white",children:["查看全部 ",e.jsx(he,{size:11})]})]}),n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center px-6 py-14",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-slate-100 dark:bg-white/5",children:e.jsx(fe,{size:28,className:"text-slate-400 dark:text-white/30"})}),e.jsx("h3",{className:"text-sm font-semibold text-slate-900 dark:text-white",children:"暂无使用记录"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500 dark:text-white/40",children:"开始使用 API 后,您的使用历史将显示在这里"})]}):e.jsx("div",{className:"overflow-hidden border-t border-slate-100 dark:border-white/5",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-100 bg-slate-50/50 text-slate-500 dark:border-white/5 dark:bg-white/[0.02] dark:text-white/40",children:[e.jsx("th",{className:"w-[140px] px-6 py-2.5 text-left font-mono text-[10px] font-normal uppercase tracking-wider",children:"time"}),e.jsx("th",{className:"px-2 py-2.5 text-left font-mono text-[10px] font-normal uppercase tracking-wider",children:"model"}),e.jsx("th",{className:"w-[120px] px-2 py-2.5 text-right font-mono text-[10px] font-normal uppercase tracking-wider",children:"tokens"}),e.jsx("th",{className:"w-[120px] px-2 py-2.5 text-right font-mono text-[10px] font-normal uppercase tracking-wider",children:"cost"}),e.jsx("th",{className:"w-[120px] px-6 py-2.5 text-right font-mono text-[10px] font-normal uppercase tracking-wider",children:"status"})]})}),e.jsx("tbody",{children:n.map(o=>{const x=Fe(o);return e.jsxs("tr",{className:"border-b border-slate-100 transition-colors last:border-b-0 hover:bg-slate-50/50 dark:border-white/5 dark:hover:bg-white/[0.02]",children:[e.jsx("td",{className:"whitespace-nowrap px-6 py-3 font-mono text-xs tabular-nums text-slate-500 dark:text-white/50",children:me(o.created_at).slice(5,16)}),e.jsx("td",{className:"max-w-[300px] truncate px-2 py-3 text-slate-700 dark:text-white/90",children:o.model_name||"—"}),e.jsx("td",{className:"px-2 py-3 text-right font-mono text-xs tabular-nums text-slate-500 dark:text-white/70",children:ue(o.token_used||0)}),e.jsx("td",{className:"px-2 py-3 text-right font-mono text-xs tabular-nums text-slate-500 dark:text-white/70",children:A(o.quota||0)}),e.jsx("td",{className:"whitespace-nowrap px-6 py-3 text-right",children:e.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 ${x?"bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400":"bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${x?"bg-emerald-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs font-medium",children:x?"成功":"失败"})]})})]},o.id)})})]})})]})},Te={today:1,yesterday:1,"24h":1,"7d":7,"14d":14,"30d":30},ze=()=>{const[t]=c.useContext(be),r=t==null?void 0:t.user,[n,o]=c.useState("7d"),x=Te[n]||7,d=ve(t,x),{unreadCount:N}=pe(r);return e.jsx("div",{className:"min-h-full bg-slate-50 pb-16 text-slate-900 dark:bg-neutral-950 dark:text-white",children:e.jsxs("div",{className:"mx-auto w-full max-w-[1400px] px-4 sm:px-6 lg:px-10",children:[e.jsx(ye,{onSearch:()=>{},onRefresh:d.refresh,loading:d.loading,user:r,unreadCount:N}),e.jsxs("div",{className:"space-y-6 pt-8 pb-8",children:[e.jsx(De,{user:r}),e.jsx("div",{className:"grid grid-cols-2 gap-5 md:grid-cols-3 xl:grid-cols-5",children:e.jsx($e,{metrics:d.metrics,monthDelta:d.monthDelta})}),e.jsxs("div",{className:"grid grid-cols-1 gap-5 md:grid-cols-4",children:[e.jsx(Ee,{dailyStats:d.dailyStats,topModels:d.topModels,onRefresh:d.refresh,loading:d.loading,rangeKey:n,onRangeChange:o,className:"md:col-span-2"}),e.jsx(Re,{forecast:d.monthlyForecast,className:"md:col-span-2"})]}),e.jsx(Se,{logs:d.recentLogs})]}),e.jsx("div",{className:"flex items-center justify-center border-t border-slate-200 py-6 text-xs text-slate-400 dark:border-white/10 dark:text-white/30",children:e.jsxs("span",{children:[V()," · 2026"]})})]})})},Ge=()=>e.jsx("div",{className:"mt-[60px] w-full max-w-[1600px] mx-auto px-3 sm:px-4 lg:px-6 pb-6",children:e.jsx(ze,{})});export{Ge as default};