page-usage-board 0.1.1: WorkBuddy token estimates no longer set credit expiry (#1050)
WorkBuddy's daily `tokens (est.)` window is a token-rate allowance with an estimated cap, set beside the credits meter (packages/workbuddy README). On the quota wall it was picked as the card's soonest-expiring row and drove the expiry sort, so a WorkBuddy card read as credits lapsing today. Now quotaWins() drops that window for WorkBuddy providers (workbuddy, workbuddy-ai) before soonWin, the total fallback and the sort. Every other provider keeps every window. Run at the reviewed head 628b6baa, in a Linux VM (Ubuntu 24.04, Node 22, Bun 1.4.2, temp HOME): - node --test in packages/page-usage-board: 37 pass, 0 fail. - bun scripts/check.mjs page-usage-board: ok. - git merge-tree against origin/main: clean. Broken by hand: quotaWins returning every window turns the new test red (1 fail), restored after. Not tried: the page in a real magpie window with a WorkBuddy account; no macOS or Windows run. Co-authored-by: fazhu4 <166514093+fazhu4@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,7 @@ page for the five things Usage does not show:
|
||||
4. **Direct-vs-remote split of the last 24 hours** — how much went out through a remote
|
||||
magpie versus straight out of this machine.
|
||||
5. **Expiry tiers on the quota cards** — how soon each allowance lapses, not just how much
|
||||
is left.
|
||||
is left. WorkBuddy's daily `tokens (est.)` window is not treated as expiring credits.
|
||||
|
||||
Everything else is convenience around those: daily and per-provider charts, 24-hour
|
||||
cache-hit and token curves, per-account detail for the remote side.
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@magpie-community/page-usage-board",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@magpie-community/page-usage-board",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"echarts": "5.5.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/page-usage-board",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"description": "在 magpie 窗口里查看用量:额度到期卡片墙 + 每日/模型/provider 用量图表 + 可选远端归因,由插件自带的本机服务供数。A usage dashboard page in magpie's window: quota cards with expiry tiers, daily and per-provider charts, optional remote attribution, served by the plugin's own local service.",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -700,6 +700,17 @@ function winAlive(w){
|
||||
if(w.remaining!=null)return w.remaining>0;
|
||||
return true;
|
||||
}
|
||||
function isWorkBuddyProvider(provider){
|
||||
return /(^|[/_-])workbuddy(?:$|[/_-])/i.test(String(provider||''));
|
||||
}
|
||||
function isEstWindow(w){
|
||||
return /tokens?\s*\(est\.?\)/i.test(w.name||'');
|
||||
}
|
||||
function quotaWins(q){
|
||||
const wins=q.windows||[];
|
||||
// WorkBuddy 的 tokens (est.) 是按日重置的 Token 速率额度,不是积分。
|
||||
return isWorkBuddyProvider(q.provider)?wins.filter(w=>!isEstWindow(w)):wins;
|
||||
}
|
||||
function soonWin(wins){
|
||||
// 显式命名的临时池优先(麦吉的「限时积分」就是临期额度,别被「积分余额」上的 runsOut 抢走)
|
||||
const named=wins.filter(w=>/限时|临时/.test(w.name||'')&&winAlive(w));
|
||||
@@ -809,8 +820,8 @@ function segBar(name,rem,used){
|
||||
return `<div class="q2bar q2seg" title="${esc(name)}${t('colonFull')}${t('avail')} ${fmt(rem)} · ${t('usedLbl')} ${fmt(used)}"><i style="width:${w1}%;background:#4da3ff"></i>${used>0?`<i style="width:${w2}%;background:var(--segused)"></i>`:''}</div>`;
|
||||
}
|
||||
function quotaCard(q){
|
||||
const wins=q.windows||[];
|
||||
// 快过期行:全部窗口里到期最早的;第二行:总积分(余额字段 > 积分类窗口总量 > 原窗口行)
|
||||
const wins=quotaWins(q);
|
||||
// 快过期行:积分窗口里到期最早的;第二行:总积分(余额字段 > 积分类窗口总量 > 原窗口行)
|
||||
const [expWin,expT]=soonWin(wins);
|
||||
const tot=pointTotal(q,wins);
|
||||
const sp=pointSplit(q,wins,tot);
|
||||
@@ -926,7 +937,7 @@ function renderQuotas(list,limitInfo){
|
||||
}
|
||||
// 排序=临期积分:每池取"最快过期窗口"的到期日,从快到慢;无任何到期信息的垫底。
|
||||
// 与卡片首行同一套 soonWin(跳过已用空的窗口),保证看到的日期和排位一致。
|
||||
const soonExp=q=>soonWin(q.windows||[])[1];
|
||||
const soonExp=q=>soonWin(quotaWins(q))[1];
|
||||
arr.sort((a,b)=>{
|
||||
const ta=soonExp(a),tb=soonExp(b);
|
||||
const fa=ta===Infinity,fb=tb===Infinity;
|
||||
|
||||
@@ -581,6 +581,52 @@ test('the dashboard asks the local service for attribution', () => {
|
||||
assert.doesNotMatch(html, /cloudflareinsights/);
|
||||
});
|
||||
|
||||
function pageBetween(text, start, end) {
|
||||
const first = text.indexOf(start);
|
||||
const last = text.indexOf(end, first + start.length);
|
||||
assert.ok(first >= 0, `missing page source: ${start}`);
|
||||
assert.ok(last > first, `missing page source: ${end}`);
|
||||
return text.slice(first, last);
|
||||
}
|
||||
|
||||
function quotaPageApi() {
|
||||
const html = readFileSync(path.join(root, 'static', 'index.html'), 'utf8');
|
||||
const source = [
|
||||
pageBetween(html, 'function isWorkBuddyProvider', 'function soonWin'),
|
||||
pageBetween(html, 'function soonWin', '// 总积分:'),
|
||||
].join('\n');
|
||||
const functions = new Function(
|
||||
'winExp',
|
||||
'winAlive',
|
||||
`${source}
|
||||
return {quotaWins,soonWin};`,
|
||||
)(
|
||||
(win) => win.exp,
|
||||
(win) => win.remaining !== 0,
|
||||
);
|
||||
return functions;
|
||||
}
|
||||
|
||||
test('quota expiry ignores WorkBuddy estimated-token windows', () => {
|
||||
const { quotaWins, soonWin } = quotaPageApi();
|
||||
|
||||
const estimated = { name: 'DeepSeek tokens (est.)', exp: 1, remaining: 1 };
|
||||
const credits = { name: 'Extra credits', exp: 2, remaining: 1 };
|
||||
assert.deepEqual(
|
||||
quotaWins({ provider: 'workbuddy', windows: [estimated, credits] }).map((win) => win.name),
|
||||
['Extra credits'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
quotaWins({ provider: 'workbuddy-ai', windows: [estimated, credits] }).map((win) => win.name),
|
||||
['Extra credits'],
|
||||
);
|
||||
assert.equal(quotaWins({ provider: 'trae-cn', windows: [estimated, credits] }).length, 2);
|
||||
assert.equal(
|
||||
soonWin(quotaWins({ provider: 'workbuddy', windows: [estimated, credits] }))[0].name,
|
||||
'Extra credits',
|
||||
);
|
||||
});
|
||||
|
||||
test('registry draft summary matches package.json verbatim (three-text rule)', () => {
|
||||
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
const doc = readFileSync(path.join(root, 'docs', 'community-submission.md'), 'utf8');
|
||||
|
||||
Reference in New Issue
Block a user