New page plugin @magpie-community/page-usage-tree 0.1.0 by CHENZUDE: magpie's usage as a provider -> account -> model tree, served by a small server that reads the gateway's /v1/magpie/usage and /usage/requests.
The last round (f9e0907) gives the model row's calls cell the calls-cell class, so CALLS values sit under their right-aligned header, adds a test for it, and comments why the server's retry budget is 16 x 100ms.
What was run at f9e09079 (mote, macOS, sandbox HOME):
- In the package: node --test 50 pass; bun test 47 tests, 0 fail.
- f9e09079 merged onto main 8765cf8f: bun scripts/check.mjs ok; whole-repo bun test 6149 pass, 20 skip, 0 fail.
- Playwright against a fake gateway: CALLS header and value right edges 616/616 (1280px), 423/423 (900), 341/341 (760, 621) in Chromium and WebKit. Chromium 1280-620px, WebKit 900/760, both engines at 420px in en and zh: no clipped cell, no sideways scroll, no <select>, no page errors.
- Broken by hand: the old `model.errors ? "bad" : ""` puts values at 544 and 273 and turns "model calls sit under the right-aligned calls header" red (27 pass, 1 fail).
Not tried: a real magpie with real accounts, the desktop app, Windows and Linux.
151 lines
6.0 KiB
JavaScript
151 lines
6.0 KiB
JavaScript
(function (root) {
|
||
const WORDS = {
|
||
zh: {
|
||
title: "账号用量",
|
||
subtitle: "先看账号,再展开查看它使用的模型",
|
||
periods: { today: "今天", "7d": "7 天", "30d": "30 天", all: "全部" },
|
||
refresh: "刷新用量",
|
||
period: "统计周期",
|
||
summary: "用量汇总",
|
||
accounts: "账号",
|
||
providers: "供应商",
|
||
calls: "调用",
|
||
tokens: "输入 + 输出 Token",
|
||
tokensWithCache: "输入 + 输出 + 缓存 Token",
|
||
tokensWithoutCache: "输入 + 输出 Token",
|
||
includeCache: "Token 含缓存",
|
||
includeCacheHint: "切换是否把缓存 Token 计入总量、排序和占比",
|
||
cost: "估算费用",
|
||
models: "模型",
|
||
detail: "账号明细",
|
||
search: "搜索账号、供应商或模型",
|
||
sort: "排序",
|
||
sortBy: { tokens: "按 Token", cost: "按费用", calls: "按调用", name: "按名称" },
|
||
expand: "展开全部",
|
||
collapse: "收起全部",
|
||
columns: {
|
||
identity: "供应商 / 账号",
|
||
calls: "调用",
|
||
tokens: "Token",
|
||
share: "占比",
|
||
cost: "费用",
|
||
status: "状态",
|
||
},
|
||
model: "模型",
|
||
token: "Token",
|
||
modelTokensWithCache: "Token + 缓存",
|
||
modelTokensWithoutCache: "Token",
|
||
allOk: "正常",
|
||
failed: "失败",
|
||
unpriced: "次未定价",
|
||
noCalls: "这个周期还没有账号用量",
|
||
noMatch: "没有匹配的账号",
|
||
noCallsHint: "通过 Magpie 网关产生调用后,这里会按账号汇总。",
|
||
noMatchHint: "试试搜索其他账号、供应商或模型。",
|
||
noData: "没有读到用量数据",
|
||
reload: "重新加载",
|
||
firstRead: "首次读取约需数秒",
|
||
source: "只读聚合",
|
||
updated: "更新于",
|
||
input: "入",
|
||
output: "出",
|
||
cache: "缓存",
|
||
share: { tokens: "Token 占比", cost: "费用占比", calls: "调用占比", name: "Token 占比" },
|
||
unpricedOnly: "未定价",
|
||
unpricedCalls: (n) => `${n} 次未定价`,
|
||
noTime: "无时间",
|
||
justUsed: "刚刚使用",
|
||
usedRecently: "最近使用",
|
||
minutesAgo: (n) => `${n} 分钟前`,
|
||
hoursAgo: (n) => `${n} 小时前`,
|
||
readFailed: "无法读取用量数据",
|
||
refreshFailed: "刷新失败,仍显示上次数据",
|
||
apiKeyNote: "API key 调用,不计入账号",
|
||
accountsAndModels: (a, m) => `${a} 个账号 · ${m} 个模型`,
|
||
modelsOnly: (m) => `${m} 个模型`,
|
||
providerModels: (p, m) => `${p} 个供应商 · ${m} 个模型`,
|
||
hostNotes: (items) => `含 ${items}`,
|
||
noUsage: "这个周期还没有用量:Magpie 网关记录第一次调用后会显示在这里。",
|
||
serviceTimeout: "数据请求超过 10 秒。请检查 Magpie 网关是否可访问。",
|
||
localService: (port) => `本地用量服务没有在运行(127.0.0.1:${port})`,
|
||
},
|
||
en: {
|
||
title: "Account usage",
|
||
subtitle: "Start with each account, then expand it to see the models it used",
|
||
periods: { today: "Today", "7d": "7 days", "30d": "30 days", all: "All" },
|
||
refresh: "Refresh usage",
|
||
period: "Period",
|
||
summary: "Usage summary",
|
||
accounts: "Accounts",
|
||
providers: "providers",
|
||
calls: "Calls",
|
||
tokens: "Input + output tokens",
|
||
tokensWithCache: "Input + output + cache tokens",
|
||
tokensWithoutCache: "Input + output tokens",
|
||
includeCache: "Tokens include cache",
|
||
includeCacheHint: "Include cache tokens in totals, sorting and shares",
|
||
cost: "Estimated cost",
|
||
models: "models",
|
||
detail: "Account details",
|
||
search: "Search accounts, providers or models",
|
||
sort: "Sort",
|
||
sortBy: { tokens: "By tokens", cost: "By cost", calls: "By calls", name: "By name" },
|
||
expand: "Expand all",
|
||
collapse: "Collapse all",
|
||
columns: {
|
||
identity: "Provider / account",
|
||
calls: "Calls",
|
||
tokens: "Tokens",
|
||
share: "Share",
|
||
cost: "Cost",
|
||
status: "Status",
|
||
},
|
||
model: "Model",
|
||
token: "Token",
|
||
modelTokensWithCache: "Token + cache",
|
||
modelTokensWithoutCache: "Token",
|
||
allOk: "OK",
|
||
failed: "failed",
|
||
unpriced: "unpriced",
|
||
noCalls: "No account usage in this period",
|
||
noMatch: "No matching account",
|
||
noCallsHint: "Usage will be grouped by account after calls pass through the Magpie gateway.",
|
||
noMatchHint: "Try another account, provider or model.",
|
||
noData: "Could not read usage data",
|
||
reload: "Reload",
|
||
firstRead: "The first read may take a few seconds",
|
||
source: "Read-only aggregate",
|
||
updated: "Updated at",
|
||
input: "In",
|
||
output: "Out",
|
||
cache: "Cache",
|
||
share: { tokens: "Token share", cost: "Cost share", calls: "Call share", name: "Token share" },
|
||
unpricedOnly: "Not priced",
|
||
unpricedCalls: (n) => `${n} unpriced`,
|
||
noTime: "no time",
|
||
justUsed: "used just now",
|
||
usedRecently: "used recently",
|
||
minutesAgo: (n) => `${n} min ago`,
|
||
hoursAgo: (n) => `${n} hr ago`,
|
||
readFailed: "Could not read usage data",
|
||
refreshFailed: "Refresh failed; showing the previous data",
|
||
apiKeyNote: "API key calls, not counted as accounts",
|
||
accountsAndModels: (a, m) =>
|
||
`${a} ${a === 1 ? "account" : "accounts"} · ${m} ${m === 1 ? "model" : "models"}`,
|
||
modelsOnly: (m) => `${m} ${m === 1 ? "model" : "models"}`,
|
||
providerModels: (p, m) =>
|
||
`${p} ${p === 1 ? "provider" : "providers"} · ${m} ${m === 1 ? "model" : "models"}`,
|
||
hostNotes: (items) => `Includes ${items}`,
|
||
noUsage: "No usage in this period yet: Magpie shows it after the gateway records its first call.",
|
||
serviceTimeout: "The data request took more than 10 seconds. Check the Magpie gateway.",
|
||
localService: (port) => `The local usage service is not running (127.0.0.1:${port})`,
|
||
},
|
||
};
|
||
|
||
root.UsageI18n = {
|
||
get(lang) {
|
||
return String(lang || "").toLowerCase().startsWith("zh") ? WORDS.zh : WORDS.en;
|
||
},
|
||
};
|
||
})(globalThis);
|