dsh-bottom-info-bar 1.27.0 → 1.27.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,6 +63,8 @@ Plugin information is further grouped by billing mode — read only the block th
63
63
 
64
64
  API keys go in DSH under **Settings → Models**; subscriptions (Codex, OpenCode, Xiaomi Token Plan, Command Code, MiniMax, Zhipu GLM, Kimi For Coding) read the local sign-in or the model key already configured in DSH (MiniMax's needs to be a Subscription Key). Unused plans never show up, and nothing needs to be typed on the plugin page. The one exception is Alibaba Token Plan (China and international sites): the inference plan key cannot read quota, so set an Alibaba Cloud AccessKey (`ALIBABA_CLOUD_ACCESS_KEY_ID` / `ALIBABA_CLOUD_ACCESS_KEY_SECRET`, a RAM user is enough) under **Quota credentials** in the plugin settings (collapsed by default), or in DSH's credentials / same-named environment variables. Anything off the list gets a not-supported hint instead of borrowed numbers.
65
65
 
66
+ One caveat for Codex: its numeric windows are read through an internal usage endpoint used by OpenAI's own Codex client. That endpoint is not publicly documented, and OpenAI may change or close it at any time. If you would rather not rely on it, do not sign in to Codex CLI (or delete `~/.codex/auth.json`) and Codex will show plan information only.
67
+
66
68
  ## Spend and updates
67
69
 
68
70
  The ledger requires a DSH runtime with Node.js 22.13 or newer. It keeps records and historical session indexes in a local disk database, reads bounded batches, and streams exports. Existing ledger files are migrated once and retained for recovery; see [Ledger storage and recovery](docs/LEDGER.md).
package/README.zh-CN.md CHANGED
@@ -63,6 +63,8 @@ https://github.com/songoao25/dsh-bottom-info-bar
63
63
 
64
64
  API 密钥填在 DSH 的**设置 → 模型**;订阅类(Codex、OpenCode、小米 Token Plan、Command Code、MiniMax、智谱、Kimi For Coding)读本机登录或 DSH 里配的推理 Key 直接查额度(MiniMax 那把需是 Subscription Key),不在用的套餐不会出现在信息栏,也不用再在插件页填任何东西。只有阿里 Token Plan(中国站/国际站)例外:推理套餐 Key 读不到额度,要另配阿里云 AccessKey——`ALIBABA_CLOUD_ACCESS_KEY_ID` / `ALIBABA_CLOUD_ACCESS_KEY_SECRET`(RAM 用户即可),在**插件设置页的「额度凭据」**里填(默认折叠),也可以填在 DSH 凭据或同名环境变量里。列表里没有的服务商只会显示未适配提示,绝不借用别家的数据。
65
65
 
66
+ Codex 要多说一句:它的数字窗口是通过 Codex 官方客户端使用的内部用量接口读取的,该接口没有公开文档,OpenAI 未来可能调整或关闭。介意的用户可以不登录 Codex CLI(或删除 `~/.codex/auth.json`),届时 Codex 只显示套餐信息。
67
+
66
68
  ## 花费与更新
67
69
 
68
70
  账本需要 DSH 内部运行环境为 Node.js 22.13 或更新版本。账目和历史会话保存在本机磁盘,按需分批读取,导出直接下载。升级会迁移旧账,但保留旧文件供恢复核对;详见 [账本存储与恢复](docs/LEDGER.md)。
package/lib/index.js CHANGED
@@ -900,6 +900,55 @@ function parseAppAuthCodexUsage(result, windowLabels) {
900
900
  return { status: 'unavailable', reason: reason, plan: plan, planType: planType, windows: [] }
901
901
  }
902
902
 
903
+ // /backend-api/wham/usage → 统一的 { provider, plan, planType, expiryAt, windows }。
904
+ // 这是 Codex 后端的额度接口:primary_window/secondary_window 带 used_percent、
905
+ // reset_at(Unix 秒)和 limit_window_seconds。SIWC 的 token 官方明确不接受,
906
+ // 所以只有本机存在 Codex 登录文件时才有数据。
907
+ function parseCodexWhamUsage(body, windowLabels) {
908
+ if (!body || typeof body !== 'object' || Array.isArray(body)) return null
909
+ const wl = windowLabels || WINDOW_LABELS
910
+ const windows = []
911
+ const seen = {}
912
+ const addWindow = function (win, id) {
913
+ if (!win || typeof win !== 'object') return
914
+ const percent = parsePercent(win.used_percent)
915
+ const key = appAuthWindowKey(id, win.limit_window_seconds)
916
+ if (percent == null || !key || seen[key]) return
917
+ seen[key] = true
918
+ windows.push({
919
+ key: key,
920
+ label: wl[key],
921
+ usedPercent: Math.round(percent),
922
+ resetsAt: normalizeResetAt(win.reset_at),
923
+ })
924
+ }
925
+ const rateLimit = body.rate_limit && typeof body.rate_limit === 'object' ? body.rate_limit : {}
926
+ addWindow(rateLimit.primary_window, 'primary')
927
+ addWindow(rateLimit.secondary_window, 'secondary')
928
+ // Business 计划没有 rate_limit,只有管理员设的月度上限。
929
+ const spend = body.spend_control && typeof body.spend_control === 'object' ? body.spend_control.individual_limit : null
930
+ if (windows.length === 0 && spend && typeof spend === 'object') {
931
+ let percent = parsePercent(spend.used_percent)
932
+ if (percent == null) {
933
+ const used = Number(spend.used)
934
+ const limit = Number(spend.limit)
935
+ if (isFinite(used) && isFinite(limit) && limit > 0) percent = (used / limit) * 100
936
+ }
937
+ if (percent != null) {
938
+ windows.push({ key: 'monthly', label: wl.monthly, usedPercent: Math.round(percent), resetsAt: normalizeResetAt(spend.reset_at) })
939
+ }
940
+ }
941
+ if (windows.length === 0) return null
942
+ const planType = typeof body.plan_type === 'string' && body.plan_type.length > 0 ? body.plan_type : null
943
+ return {
944
+ provider: 'codex',
945
+ plan: planType ? planDisplayName(planType) : null,
946
+ planType: planType,
947
+ expiryAt: null,
948
+ windows: windows,
949
+ }
950
+ }
951
+
903
952
  // ---------- FR-9 / D8:小米 MiMo 解析(数值一律容错:字符串/数字、百分比 0-1 或 0-100 双形态) ----------
904
953
  function xiaomiRegionBaseUrl(region) {
905
954
  if (region === 'sgp') return 'https://token-plan-sgp.xiaomimimo.com'
@@ -2930,11 +2979,49 @@ export default {
2930
2979
  }
2931
2980
  }
2932
2981
 
2982
+ // Codex 后端额度通道:需要本机 ~/.codex/auth.json(Codex CLI / 旧版插件留下的登录)。
2983
+ // SIWC 的 token 被官方明确拒绝在 ChatGPT 用量端点之外,所以这是当前唯一能拿到
2984
+ // 5 小时 / 每周 / 月度窗口百分比的路径。文件不存在或过期时返回 null,退回套餐/有效期。
2985
+ async function fetchCodexUsageFromWham() {
2986
+ const read = readCodexAuthFile(CODEX_AUTH_FILE);
2987
+ if (!read.ok) return null;
2988
+ const tokens = read.auth && read.auth.tokens;
2989
+ const access = tokens && typeof tokens.access_token === 'string' && tokens.access_token.length > 0 ? tokens.access_token : null;
2990
+ if (!access) return null;
2991
+ // 账号一致性:两边的 id_token 都能读到邮箱且不一致时,不拿另一个账号的额度冒充。
2992
+ try {
2993
+ if (ctx.credentials && typeof ctx.credentials.readRecord === 'function') {
2994
+ const record = await ctx.credentials.readRecord('chatgpt-sub/session');
2995
+ const payload = record && record.kind === 'grant' ? record.payload : null;
2996
+ const nativeClaims = payload && typeof payload.idToken === 'string' ? decodeJwtPayload(payload.idToken) : null;
2997
+ const codexClaims = typeof tokens.id_token === 'string' ? decodeJwtPayload(tokens.id_token) : null;
2998
+ if (nativeClaims && codexClaims && typeof nativeClaims.email === 'string' && typeof codexClaims.email === 'string'
2999
+ && nativeClaims.email.toLowerCase() !== codexClaims.email.toLowerCase()) {
3000
+ return null;
3001
+ }
3002
+ }
3003
+ } catch (err) { /* 读不到会话就按纯 Codex 账号处理 */ }
3004
+ const headers = { Authorization: 'Bearer ' + access, Accept: 'application/json' };
3005
+ if (typeof tokens.account_id === 'string' && tokens.account_id.length > 0) headers['ChatGPT-Account-Id'] = tokens.account_id;
3006
+ try {
3007
+ const res = await fetch('https://chatgpt.com/backend-api/wham/usage', { headers: headers, signal: timeoutSignal(HTTP_TIMEOUT_MS) });
3008
+ if (!res.ok) return null;
3009
+ const body = await res.json();
3010
+ const data = parseCodexWhamUsage(body, windowLabels);
3011
+ return data ? { data: data } : null;
3012
+ } catch (err) {
3013
+ return null;
3014
+ }
3015
+ }
3016
+
2933
3017
  async function fetchCodexUsage() {
2934
3018
  // ① appAuth 优先:拿到额度窗口就用它(DSH Go 的唯一可用通道)
2935
3019
  const viaAppAuth = await fetchCodexUsageViaAppAuth();
2936
3020
  if (viaAppAuth && viaAppAuth.data) return viaAppAuth;
2937
- // ② 新版 dsh-chatgpt-sub 的 SIWC 会话(没有 Codex 文件也能显示套餐与有效期)
3021
+ // ② Codex 后端额度:桌面端唯一能拿到窗口百分比的通道
3022
+ const viaWham = await fetchCodexUsageFromWham();
3023
+ if (viaWham && viaWham.data) return viaWham;
3024
+ // ③ 新版 dsh-chatgpt-sub 的 SIWC 会话(没有 Codex 文件也能显示套餐与有效期)
2938
3025
  const fromSession = await fetchCodexUsageFromSession();
2939
3026
  if (fromSession && fromSession.data) return fromSession;
2940
3027
  // ③ 旧版桌面文件通道:取到数据就用文件的数据,不被 appAuth 的失败状态遮住
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bottom-info-bar",
3
- "version": "1.27.0",
3
+ "version": "1.27.2",
4
4
  "description": "Shows the current model, balance and spend under the composer.",
5
5
  "keywords": [
6
6
  "deepseek",