Files
plugins/packages/kimi-work/tests
yetone 1fbe22b3ad kimi-work 0.1.11: a usage read that fails says why on the card and keeps the Work sign-in
泠夜Soul (Discord), latest magpie and kimi-work 0.1.10: the Kimi Work
usage card says only "暂时无法获取额度", with no error anywhere.

Cause: auth.usage threw on every failure. magpie puts a plugin's reason
on the card only when usage returns it as `error` (quotaOfPlugin sets
PluginError; app.js quotaError then says "暂时无法获取额度:<why>"). A
thrown error reaches the card as the bare text, with the reason in a
tooltip. The read uses Kimi's web sign-in (credentials.kimiWeb.accessToken),
not the Work token chat uses. Kimi desktop 3.2.20 rewrites that token in
daimon config.json only while it runs (its token-change sync). Once the
desktop is closed, www.kimi.com answers it 401 "Session expired"
(REASON_INVALID_AUTH_TOKEN), the same stale token 0.1.10 found on the
menu. That 401 was thrown as expired() with signIn "expired", so magpie
also marked the Work account signed out while chat still worked. The
header changes in 0.1.8-0.1.10 aren't the cause: signed out or with a
bad token, GetSubscriptionStats answers the same 401 with or without the
x-msh headers. Their effect with a valid token wasn't seen.

What changed:
- usage never throws on a failed read. It returns
  {windows: [], error, signIn: "kept"}. A 401 says
  "Kimi 网页登录已过期,打开一次 Kimi 桌面版即可刷新额度(对话不受影响)",
  in words that magpie's signInGone doesn't take for a lapsed sign-in.
  Other statuses keep their HTTP code. Each failure is logged without the
  token.
- subscriptionBalance is read in camelCase or snake_case. A balance
  whose amountUsedRatio Connect JSON left out (zero) reads 0% used.
  Before, that gave no window at all. A reply with no balance says so.
  Field names are from the desktop's membership.v2 descriptor:
  subscription_balance is optional in GetSubscriptionStatsResponse.

Run at this tree (origin/main 743e8af + this change), macOS, bun:
- bun test packages/kimi-work: 53 pass, 0 fail. With index.mjs put back
  to 743e8af's: 50 pass, 3 fail, the three usage tests: 403 refused,
  stale web sign-in (fixture: www.kimi.com's literal 401 body, curl
  10-25), and zero-omitted / snake_case / missing balance.
- Live: createPlugin's auth.usage against the real www.kimi.com with a
  stale-shaped web token. New code returns the error above with
  signIn "kept". 743e8af's throws "请先在本机 Kimi 桌面版登录 Work…" with
  signIn "expired".
- HOME=$(mktemp -d) bun test: 2628 pass, 0 fail.
- bun scripts/check.mjs: every plugin ok. git diff --check clean.

Not tried: a signed-in Kimi Work account (none on this machine), so the
reporter's actual failure isn't seen. This release puts it on their card
and in the log. If it's the stale web token, opening Kimi desktop
refreshes it.
2026-10-25 17:13:43 +08:00
..