ai-zero-token 2.0.7 → 2.0.8

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.
@@ -1 +0,0 @@
1
- import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./clock-3-BzDANsVk.js";import{t as a}from"./refresh-cw-CAAH2rqe.js";import{t as o}from"./zap-B4_oDbCp.js";import{C as s,x as c}from"./profiles-C5SmQvju.js";import{S as l,_ as u,p as d,r as f}from"./index-CCiBaGwU.js";import{t as p}from"./StatCard-7TEzqn2i.js";var m=t(`camera`,[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),h=t(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),g=t(`sigma`,[[`path`,{d:`M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2`,key:`wuwx1p`}]]),_=e(n(),1),v=r();function y(){return{requestCount:0,successCount:0,failureCount:0,inputTokens:0,outputTokens:0,totalTokens:0,unknownTokenCount:0,imageCount:0,totalDurationMs:0,averageDurationMs:0,p95DurationMs:0,durationBuckets:{}}}function b(e){return new Intl.NumberFormat(`zh-CN`).format(Math.round(e||0))}function x(e){return!Number.isFinite(e)||e<=0?`0`:e>=1e6?`${(e/1e6).toFixed(e>=1e7?1:2)}M`:e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}K`:b(e)}function S(e){return`${b(e.successCount)} 成功 / ${b(e.failureCount)} 失败`}function C(e){let t=e.aggregate??y();return(0,v.jsxs)(`article`,{className:`usage-scope-card`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:e.title}),(0,v.jsxs)(`strong`,{children:[x(t.totalTokens),` 已知 token`]}),(0,v.jsx)(`p`,{children:e.detail})]}),(0,v.jsxs)(`dl`,{children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`dt`,{children:`请求`}),(0,v.jsx)(`dd`,{children:b(t.requestCount)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`dt`,{children:`图片`}),(0,v.jsx)(`dd`,{children:b(t.imageCount)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`dt`,{children:`平均`}),(0,v.jsx)(`dd`,{children:c(t.averageDurationMs)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`dt`,{children:`P95`}),(0,v.jsx)(`dd`,{children:c(t.p95DurationMs)})]})]}),(0,v.jsxs)(`p`,{className:`usage-scope-footer`,children:[S(t),` · 未返回用量的请求 `,b(t.unknownTokenCount),` 次`]})]})}function w(e){return(0,v.jsxs)(`section`,{className:`usage-table-card`,children:[(0,v.jsxs)(`div`,{className:`usage-table-head`,children:[(0,v.jsx)(`h3`,{children:e.title}),(0,v.jsxs)(`span`,{children:[e.rows.length,` 项`]})]}),e.rows.length===0?(0,v.jsx)(`div`,{className:`usage-empty`,children:e.empty}):(0,v.jsx)(`div`,{className:`usage-table-scroll`,children:(0,v.jsxs)(`table`,{className:`usage-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`维度`}),(0,v.jsx)(`th`,{children:`请求`}),(0,v.jsx)(`th`,{children:`失败`}),(0,v.jsx)(`th`,{children:`已知 token`}),(0,v.jsx)(`th`,{children:`未返回用量`}),(0,v.jsx)(`th`,{children:`图片`}),(0,v.jsx)(`th`,{children:`平均耗时`})]})}),(0,v.jsx)(`tbody`,{children:e.rows.map(e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:e.label}),(0,v.jsx)(`td`,{children:b(e.aggregate.requestCount)}),(0,v.jsx)(`td`,{children:b(e.aggregate.failureCount)}),(0,v.jsx)(`td`,{children:x(e.aggregate.totalTokens)}),(0,v.jsx)(`td`,{children:b(e.aggregate.unknownTokenCount)}),(0,v.jsx)(`td`,{children:b(e.aggregate.imageCount)}),(0,v.jsx)(`td`,{children:c(e.aggregate.averageDurationMs)})]},e.key))})]})})]})}function T(e){return(0,v.jsxs)(`section`,{className:`usage-table-card usage-daily-card`,children:[(0,v.jsxs)(`div`,{className:`usage-table-head`,children:[(0,v.jsx)(`h3`,{children:`每日趋势`}),(0,v.jsxs)(`span`,{children:[`最近 `,e.rows.length,` 天`]})]}),e.rows.length===0?(0,v.jsx)(`div`,{className:`usage-empty`,children:`还没有历史用量。`}):(0,v.jsx)(`div`,{className:`usage-table-scroll`,children:(0,v.jsxs)(`table`,{className:`usage-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`日期`}),(0,v.jsx)(`th`,{children:`请求`}),(0,v.jsx)(`th`,{children:`成功`}),(0,v.jsx)(`th`,{children:`失败`}),(0,v.jsx)(`th`,{children:`已知输入`}),(0,v.jsx)(`th`,{children:`已知输出`}),(0,v.jsx)(`th`,{children:`已知总 token`}),(0,v.jsx)(`th`,{children:`未返回用量`}),(0,v.jsx)(`th`,{children:`图片`}),(0,v.jsx)(`th`,{children:`P95`})]})}),(0,v.jsx)(`tbody`,{children:e.rows.map(e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:e.date}),(0,v.jsx)(`td`,{children:b(e.aggregate.requestCount)}),(0,v.jsx)(`td`,{children:b(e.aggregate.successCount)}),(0,v.jsx)(`td`,{children:b(e.aggregate.failureCount)}),(0,v.jsx)(`td`,{children:x(e.aggregate.inputTokens)}),(0,v.jsx)(`td`,{children:x(e.aggregate.outputTokens)}),(0,v.jsx)(`td`,{children:x(e.aggregate.totalTokens)}),(0,v.jsx)(`td`,{children:b(e.aggregate.unknownTokenCount)}),(0,v.jsx)(`td`,{children:b(e.aggregate.imageCount)}),(0,v.jsx)(`td`,{children:c(e.aggregate.p95DurationMs)})]},e.date))})]})})]})}function E(e){let[t,n]=(0,_.useState)(e.config?.usage??null),[r,S]=(0,_.useState)(!1);(0,_.useEffect)(()=>{n(e.config?.usage??null)},[e.config?.usage]);async function E(){S(!0);try{n(await d(`/_gateway/admin/usage`)),e.setStatus(`用量统计已刷新。`)}catch(t){e.setStatus(`用量统计刷新失败: ${f(t)}`)}finally{S(!1)}}let D=t,O=D?.lifetime??y(),k=D?.today??y(),A=D?.startup??y(),j=(0,_.useMemo)(()=>O.requestCount===0?`0%`:`${(O.failureCount/O.requestCount*100).toFixed(1)}%`,[O.failureCount,O.requestCount]);return(0,v.jsxs)(`section`,{className:`usage-page`,children:[(0,v.jsxs)(`div`,{className:`usage-actions`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`统计文件`}),(0,v.jsx)(`code`,{children:D?.storageDir||`~/.ai-zero-token/.state/usage`})]}),(0,v.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>void E(),disabled:r,children:[r?(0,v.jsx)(u,{className:`spin`,size:16}):(0,v.jsx)(a,{size:16}),`刷新统计`]})]}),(0,v.jsxs)(`section`,{className:`summary-grid desktop-summary-grid usage-summary-grid`,children:[(0,v.jsx)(p,{icon:g,label:`历史已知 token`,value:x(O.totalTokens),detail:`${b(O.requestCount)} 次请求,${b(O.unknownTokenCount)} 次未返回用量`,tone:`blue`}),(0,v.jsx)(p,{icon:o,label:`今日已知 token`,value:x(k.totalTokens),detail:`${D?.todayDate||`今天`} · ${b(k.requestCount)} 次请求,${b(k.unknownTokenCount)} 次未返回用量`,tone:`green`}),(0,v.jsx)(p,{icon:l,label:`本次启动已知 token`,value:x(A.totalTokens),detail:`启动于 ${s(D?.startedAt)}`,tone:`brand`}),(0,v.jsx)(p,{icon:m,label:`图片张数`,value:b(O.imageCount),detail:`历史累计生成或编辑图片`,tone:`orange`}),(0,v.jsx)(p,{icon:i,label:`历史 P95`,value:c(O.p95DurationMs),detail:`平均 ${c(O.averageDurationMs)}`,tone:`orange`}),(0,v.jsx)(p,{icon:h,label:`失败率`,value:j,detail:`${b(O.failureCount)} 次失败`,tone:O.failureCount>0?`orange`:`green`})]}),(0,v.jsxs)(`section`,{className:`usage-scope-grid`,children:[(0,v.jsx)(C,{title:`今日用量`,detail:`当天 00:00 到现在`,aggregate:k}),(0,v.jsx)(C,{title:`本次启动`,detail:`当前网关进程启动后到现在`,aggregate:A}),(0,v.jsx)(C,{title:`历史累计`,detail:`从开始记录以来的全部累计`,aggregate:O})]}),(0,v.jsx)(T,{rows:D?.daily??[]}),(0,v.jsxs)(`section`,{className:`usage-dimension-grid`,children:[(0,v.jsx)(w,{title:`按账号`,rows:D?.byAccount??[],empty:`还没有账号维度数据。`}),(0,v.jsx)(w,{title:`按模型`,rows:D?.byModel??[],empty:`还没有模型维度数据。`}),(0,v.jsx)(w,{title:`按接口`,rows:D?.byEndpoint??[],empty:`还没有接口维度数据。`}),(0,v.jsx)(w,{title:`按错误`,rows:D?.byError??[],empty:`还没有错误记录。`}),(0,v.jsx)(w,{title:`按生图链路`,rows:D?.byImageRoute??[],empty:`还没有生图链路数据。`}),(0,v.jsx)(w,{title:`按来源`,rows:D?.bySource??[],empty:`还没有来源维度数据。`})]})]})}export{E as UsagePage};