Skip to content

fix(usage): read token-plan quota windows dynamically and flag missing data - #256

Open
gujieye wants to merge 1 commit into
mainfrom
fix/issue-fix
Open

gujieye wants to merge 1 commit into
mainfrom
fix/issue-fix

Conversation

@gujieye

@gujieye gujieye commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #231

背景

2026-09-22 起 Token Plan 个人版取消 5 小时 / 周限额,usage API 只返回 per1MonthPercentage / per1MonthResetTime。2.2.0 已把字段映射切到月度窗口,但仍是写死字段名;且无数据时 --output json 返回裸 {},下游无法区分「无数据」与正常结果。

改动

  • 动态识别额度窗口:bl usage token-plan 遍历响应中实际存在的 per<N><Hour|Day|Week|Month>(Percentage|ResetTime) 字段,按时长升序渲染(5-hour quota / 1-week quota / Monthly quota …),计量维度再变化时无需改代码。未返回任何窗口时仍渲染月度空态。
  • JSON 可判别信号:输出新增 hasQuotaData: boolean;原有 per* 字段名保持不变(纯增量,向后兼容)。无数据时输出 {"hasQuotaData": false},不再是 {}。没有使用 unlimited 之类的字段,因为 CLI 无法权威判断是否不限量。
// 月度账号
{ "per1MonthPercentage": 0, "per1MonthResetTime": 1794326400000, "hasQuotaData": true }
// 无任何额度字段
{ "hasQuotaData": false }

验证

  • vp check 通过
  • vp test run packages/commands/tests/token-plan-usage.test.ts packages/commands/tests/e2e/usage-token-plan.e2e.test.ts:17/17 通过(新增 5 小时 + 周多窗口、无数据 JSON 用例)
  • 真实账号 pnpm -s bl usage token-plan --output json 返回上面的月度结果

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] usage token-plan 对按月计量的 Token Plan 账号返回空:API 返回 per1MonthPercentage,CLI 只读 per5Hour* / per1Week*

1 participant