Skip to content

加入额度显示 - #56

Closed
sakmist wants to merge 2 commits into
TriDefender:masterfrom
sakmist:master
Closed

sakmist wants to merge 2 commits into
TriDefender:masterfrom
sakmist:master

Conversation

@sakmist

@sakmist sakmist commented Sep 29, 2026

Copy link
Copy Markdown
Contributor
image

sakmist and others added 2 commits September 30, 2026 00:24
The /quota JSON endpoint existed but nothing surfaced it — neither the TUI
panel nor the CLI showed remaining plan quota. Add a Quota card to the TUI
(per-model remaining/total + expiry, `r` key or card button to refresh,
fetched once automatically after login) and a `zcode-proxy quota` subcommand
that prints balances, claimable plans and upstream errors.

Both surfaces reuse collectQuotaSnapshot, so no new upstream request path is
introduced. The card sizes its row count to the terminal height so it cannot
push the Logs card or footer off-screen, and refreshes only on demand — the
billing gateway rate-limits frequent queries.
feat(quota): show plan balances in the TUI panel and a `quota` CLI
@sakmist

sakmist commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

@TriDefender TriDefender self-assigned this Sep 29, 2026
@TriDefender TriDefender added the enhancement New feature or request label Sep 29, 2026
@TriDefender

Copy link
Copy Markdown
Owner

你看commit 61c086e能不能去掉,这样把tag给打回2.2.0了

@TriDefender

Copy link
Copy Markdown
Owner

这个 PR 的额度显示只解算了 zcode-plan/billing/balance 这一个「积分桶」平面(体验套餐/积分制套餐走的就是它),v2 次数制的 coding-plan 配额完全无法解算——官方客户端对这类套餐用的是另一个端点(/api/monitor/usage/quota/limit),PR 根本没接。另外发现一个合并 blocker:贡献者 fork 上的 release 机器人把版本号从 4.7.1 改写成了 2.2.0,合并即版本倒退。

@TriDefender

Copy link
Copy Markdown
Owner

另外,

  • quotaCommand 首跑会经 ensureDeviceMidInConfig 写 config.yaml(种随机 deviceMid)——请确保如果已有这个Mid不会重新生成
  • TUI 余额行丢弃了上游 unitType("token"/"prompt"),CLI 的 claimable 行倒是显示了——展示不一致,纯外观问题。
  • 启动时拉取失败后卡片永久 "unavailable",只能手按 r(README 已声明不做轮询,合理,但可考虑一次性退避重试),我个人更建议一分钟或者几分钟查询一次,保证额度新鲜度也不会被限流。
  • 切 provider/plan(p/t)后额度卡片不刷新,显示旧数据直到手动刷新(同上,切换后10s内应该查询一次来拉最新端点的)。

@sakmist

sakmist commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

coding-plan没开()没号测

@sakmist

sakmist commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

其他几个问题我改一下

@TriDefender

Copy link
Copy Markdown
Owner

已合并 @sakmist 的功能提交到 master:974cf83 feat(quota): show plan balances in the TUI panel and a \quota` CLI`(cherry-pick 自 bc4f573,作者署名保留)。

合并时剔除了 fork 上 release 机器人产生的 61c086e("chore(release): bump version to 2.2.0")——该提交会把 package.json/VERSION 从 4.7.1 倒退到 2.2.0,与 v4.7.1 tag 冲突,故未带入。除版本号两行外,合并内容与 PR 头部逐字节一致(tsc 干净 + 896 测试全过)。

审计遗留跟进(不阻塞):

  • 当前实现只覆盖 zcode-plan/billing/balance 积分桶平面(体验/积分制套餐);次数制 coding-plan 订阅的剩余量在官方 /api/monitor/usage/quota/limit 链上(双头鉴权 + data.limits[] TIME_LIMIT 窗口),暂不支持,需要时可开 issue 跟进。
  • 无积分桶账号的空态文案 "(no balance windows)" 可再打磨得更明确。

@TriDefender

Copy link
Copy Markdown
Owner

剩下的我来

@sakmist

sakmist commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

好

TriDefender added a commit that referenced this pull request Sep 29, 2026
Mirror the official desktop panel's two-plane split in the quota snapshot:

- credits plane (existing): zcode-plan billing/balance + preview with the
  plan JWT — start-plan/trial credit buckets;
- coding plane (new): GET {api.z.ai|open.bigmodel.cn}/api/monitor/usage/
  quota/limit with the raw coding-plan API key in `authorization` (bundle
  wK/Z_ + md) — data.level + data.limits[] windowed usage rows, surfaced
  as a Coding group in the TUI card and in the `quota` CLI / GET /quota.

Behavior fixes from the PR #56 audit:

- a credential without a plan JWT no longer kills the snapshot — credits
  plane degrades to a noted error while the coding plane still resolves
  (the card no longer tells logged-in users they are not logged in);
- coding rows render `remaining` only: live data shows upstream `number`
  is not a comparable total (TIME_LIMIT remaining=3894 / number=1), and
  the official panel likewise never renders X/Y for these windows;
- envelope success semantics mirror the bundle $_ (success !== false and
  code absent/0/200); monitor failures degrade to codingPlan=null the way
  the official fetchQuota().catch(() => null) does;
- non-token unitType on balance rows is now visible instead of dropped;
- empty-everything state reworded ("no quota entries reported by
  upstream").

@see _reverse/NOTEPAD.md "coding-plan 用量平面"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants