@iasiv5/dsh-quota-watch 0.1.24 → 0.1.26
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 +72 -45
- package/cordis.patch.yml +22 -0
- package/docs/assets/panel-copilot-detail.webp +0 -0
- package/docs/assets/panel-glm-detail.webp +0 -0
- package/docs/assets/panel-overview.webp +0 -0
- package/docs/assets/sidebar-card.webp +0 -0
- package/lib/client.js +436 -2
- package/package.json +1 -1
- package/src/client/prefs.mjs +18 -0
- package/src/client.mjs +476 -2
- package/src/core/reset.mjs +323 -0
- package/src/host.mjs +536 -4
- package/src/shared.mjs +6 -0
package/README.md
CHANGED
|
@@ -1,74 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# DSH Quota Watch
|
|
2
2
|
|
|
3
|
-
[](
|
|
4
|
-
[](
|
|
5
|
-
[](./LICENSE)
|
|
3
|
+
[](https://github.com/iasiv5/dsh-quota-watch/releases)
|
|
4
|
+
[](https://github.com/iasiv5/dsh-quota-watch/actions/workflows/ci.yml)
|
|
6
5
|
[](https://www.npmjs.com/package/@iasiv5/dsh-quota-watch)
|
|
7
|
-
[](./LICENSE)
|
|
8
7
|
|
|
9
8
|
[English summary](#english-summary) · 中文
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-

|
|
10
|
+
在 DSH 中查看 **GLM Coding Plan** 与 **GitHub Copilot** 的服务商额度快照。Quota Watch 不读取 DSH 会话 token;凭据由 DSH 宿主解析,浏览器只接收整理后的额度数据。
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+

|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
- **🖥️ 详情面板**:半透明毛玻璃底;总览(Token 额度)宽 `240px` 与侧边栏卡片同宽(窄屏 `min(240px, 100vw−24px)` 兜底),点进 GLM / Copilot 详情后恢复 0.0.18 内容自适应宽度(上限 `min(320px, 100vw−24px)`),靠边自动翻侧,滚动 / 缩放跟随;≤480px 窄屏自动改为底部弹层并避开 safe-area;Esc 或点击面板外关闭。概览列两个 provider 行,点击进入详情:
|
|
19
|
-
- **GLM**:今日 Tokens / 调用次数双大数字 + 五列对齐窗口网格(MCP(月)→ 5 小时 → 每月 → 每周固定排序,周窗口未下发时显示「每周额度 · ♾️(无限)」占位)+ 分模型用量行;
|
|
20
|
-
- **Copilot**:可用额度、本期已用(credits 消耗 + 弱化百分比)、重置时间三行。
|
|
21
|
-
- 窗口备注的括号按语言成对统一(zh 全角 `(…)` / en 半角 `(…)`),备注列左缘恒对齐(0.1.16)。接口未下发有效 `remaining` / `percent_remaining` 时该行不渲染,`credits_used` 绝不用于推算余额。
|
|
22
|
-
- **🎛️ 面板底部等宽双按钮**:「显示 / 隐藏侧边栏卡片」(文案随状态翻转)+「立即刷新」(触发宿主立即探测)。grid `1fr 1fr` 强制等宽,宽度与文案长度、界面语言无关;加载 / 出错空态下按钮同样在场;静息字样与行内弱化数值(如「3.8亿」)同字号同透明度,hover 恢复全强度。
|
|
23
|
-
- **🧩 侧边栏卡片(可选,默认隐藏)**:胶囊是默认界面;需要侧栏卡片时从面板底部按钮开启(Web profile 侧栏底部区块存在时才出现该按钮)。卡片提供摘要行 + 行点击开面板 + 行首 provider 名称点击立即探测。侧栏收起(Web 窄栏)或容器过窄(<160px,跨 profile 通用判据)时自动隐藏,侧栏整体不存在(Desktop 收起态)同样自然缺席、无报错——入口始终由悬浮胶囊承载。
|
|
24
|
-
- **🌏 语言跟随宿主**:界面文案跟随 DSH「设置 → 语言」——宿主 locale 特性把解析结果实时镜像到 `<html lang>`,插件监听该属性,切换即热重渲染(无需刷新页面);宿主未同步时回退浏览器语言。
|
|
25
|
-
- **🛟 降级与容错**:凭据缺失的 provider 不渲染摘要行与胶囊分段(两者皆缺时悬浮胶囊与卡片一并隐藏);探测失败时保留最后一次成功数据并在行上加 ⚠ 过期标记(⚠ 只出现在面板与卡片行内,不在胶囊上显示)。
|
|
26
|
-
- **🔁 刷新节奏**:宿主默认每 60 秒探测(窗口 + 用量 + Copilot),profile 可配 30–3600 秒;浏览器页签可见时每 30 秒刷新视图,隐藏时暂停。重启冷启动零等待:宿主 0 秒即发首轮探测(网络未就绪时以 5 秒冷重试直至拿到数据),客户端在无数据期间以 2 秒起步的指数退避快速重试、拿到数据后回到常规节奏——重启后数秒内胶囊即出现,不再有 ~30 秒空窗。所有 UI 收在 Shadow DOM 里(ADR 0001),颜色走 DSH 主题语义变量(含硬编码兜底),自动适配浅色 / 深色主题。
|
|
14
|
+
## 功能
|
|
27
15
|
|
|
28
|
-
|
|
16
|
+
- **悬浮胶囊与详情面板**:胶囊显示 GLM、Copilot 已用百分比;点击查看额度窗口、重置时间及服务商报告的用量统计。胶囊可拖动,位置会记忆并保持在可视区域内。
|
|
17
|
+
- **GLM 详情**:显示今日 tokens、调用次数、额度窗口及分模型用量。额度窗口与今日用量是不同的服务商统计口径。
|
|
18
|
+
- **Copilot 详情**:显示服务商报告的可用额度、本期已用额度与重置时间;插件不会从已用 credits 推算剩余额度。
|
|
19
|
+
- **侧边栏卡片(可选开启,占侧栏 footer 第一槽位)**:由面板底部的显示/隐藏开关控制,默认关闭;悬浮胶囊始终是主要入口。
|
|
20
|
+
- **容错与语言适配**:界面跟随 DSH 语言设置。探测失败时保留最后一次成功的快照并标记为过期;缺少服务商凭据时不显示对应额度行。
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
## 兼容性与前置要求
|
|
31
23
|
|
|
32
|
-
|
|
|
24
|
+
| 项目 | 要求或声明 |
|
|
33
25
|
|---|---|
|
|
34
|
-
|
|
|
26
|
+
| DSH | `>=0.1.7-rc.2`(包元数据声明的最低版本) |
|
|
27
|
+
| Node.js | `>=20` |
|
|
28
|
+
| Cordis | peer dependency `^4.0.2` |
|
|
29
|
+
| 客户端平台 | 包元数据声明 `web` |
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
该插件已分别在 DSH Web 与 Desktop profile 上完成人工适配验证;这项运行时验证不由 CI 自动化覆盖。CI 运行 Node 测试、构建和安全检查,不包含 DSH Web / Desktop 运行时矩阵。
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
## 安装
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
### DSH 插件市场
|
|
41
36
|
|
|
42
|
-
|
|
37
|
+
在 DSH 的「插件市场」搜索 **Quota Watch** 或「额度」,从市场安装。dsh-m 对 npm 包使用精确版本并校验 integrity;后续更新也可在市场中管理。
|
|
43
38
|
|
|
44
|
-
|
|
39
|
+
### 命令行(Web / Desktop profile)
|
|
45
40
|
|
|
46
41
|
```sh
|
|
47
|
-
dsh plugin --profile web add @iasiv5/dsh-quota-watch
|
|
48
|
-
dsh plugin --profile desktop add @iasiv5/dsh-quota-watch
|
|
42
|
+
dsh plugin --profile web add @iasiv5/dsh-quota-watch
|
|
43
|
+
dsh plugin --profile desktop add @iasiv5/dsh-quota-watch
|
|
49
44
|
```
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
Web 与 Desktop profile 均已实测适配。按 DSH 插件管理器提示完成安装与生效;宿主侧 patch 发生变化时,Web 重启 DSH Web,Desktop 退出并重新打开应用,之后刷新页面加载客户端界面。
|
|
47
|
+
|
|
48
|
+
## 配置
|
|
49
|
+
|
|
50
|
+
在 GLM 详情面板的「自动用卡」配置界面,可分别设置两个独立开关:
|
|
51
|
+
|
|
52
|
+
- **5 小时自动用卡**:默认关闭。
|
|
53
|
+
- **每周自动用卡**:默认关闭。
|
|
54
|
+
|
|
55
|
+
开启某个开关即授权对应窗口自动使用重置卡;阈值与消费风险见下一节。
|
|
56
|
+
|
|
57
|
+
## 重置卡与自动用卡
|
|
58
|
+
|
|
59
|
+
> **重置卡是可消耗、不可撤销的订阅权益。** 使用前请确认适用范围、卡种与额度窗口。
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
仅支持配置为 `zai-coding-cn` 的**国内站个人版**。国际站 `zai` / `zai-coding` 不提供此入口;团队版未验证、不在支持范围内。重置卡列表按卡种显示可用张数与最早到期日;「刷新」只查询卡数,不会消费卡。手动使用前,宿主会重新查询当前卡列表,面板也会先显示二次确认。5 小时卡重置 5 小时窗口;每周卡同时重置每周与 5 小时窗口。
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
- **DSH 版本**:要求 `0.1.7-rc.2` 或更高;适配 `web` 与 `desktop` 两种 profile——Desktop 收起侧栏时由悬浮胶囊承载入口,卡片为 Web 渐进增强。
|
|
63
|
+

|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
图中的「自动用卡」勾选框只展开设置,不授权消费;下方 5 小时与每周两个开关才是各自独立的授权,截图中均为关闭状态。
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
- **GLM**:查询 `https://open.bigmodel.cn/api/monitor/usage/quota/limit` 或 `https://api.z.ai/api/monitor/usage/quota/limit`(窗口百分比),以及同域 `/api/monitor/usage/model-usage?startTime=…&endTime=…`(今日 tokens 与调用次数,时间格式 `yyyy-MM-dd HH:mm:ss`)。两个接口均按 raw API key 鉴权,不加 Bearer 前缀。
|
|
62
|
-
- **Copilot**:查询 `https://api.github.com/copilot_internal/user`。这是 GitHub Copilot 内部、非公开稳定契约的端点,字段可能变更;插件在无法确认额度含义时显示不可用,不猜测或计算余额。对企业 / 组织管理的 seat,GitHub AI Credits 可能属于共享计费池——侧栏呈现的是 GitHub 用户 quota snapshot 中的可用额度,不保证等同组织账单的总余额。
|
|
63
|
-
- **隐私**:凭据只在 DSH 宿主进程解析并用于 HTTPS 请求;浏览器只接收规范化后的额度字段。插件不把 key、OAuth grant 或原始 provider 响应写入磁盘,也不保存额度历史。
|
|
67
|
+
自动用卡须特别留意:
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
- 两个窗口分别授权,默认均关闭;默认触发阈值是**已用 99.9%**(可设为 `50–99.9%`)。若启用时额度已达到阈值,下一次有效探测可能立即消费一张卡。
|
|
70
|
+
- 开关与阈值保存在 DSH 宿主侧;关闭浏览器后,宿主仍可按轮询执行已授权的自动用卡。若保存设置损坏或无法读取,自动用卡会安全关闭。
|
|
71
|
+
- 只使用本轮成功探测得到的新鲜 GLM 额度;过期快照不会触发消费。消费请求串行执行,每周卡优先;周卡成功后会同时解除 5 小时窗口的自动触发。
|
|
72
|
+
- 默认宿主探测间隔为 60 秒;额度可能在两次探测之间耗尽,自动用卡**不保证不断流**。
|
|
73
|
+
- 确定失败后至少等待 10 分钟才会重试。若 POST 超时、连接中断或结果无法判定,上游可能已经扣卡;插件会停止该窗口的自动重试。请先核实官方卡数与额度,不要盲目重试。
|
|
74
|
+
- 国内站重置卡接口未公开且可能变化。使用前请核对智谱 Coding Plan 的适用工具与服务条款;不接受消耗型操作或未公开接口风险时,请勿使用重置卡功能。
|
|
66
75
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
|
|
76
|
+
## Copilot 与侧边栏界面
|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
80
|
+

|
|
81
|
+
|
|
82
|
+
## 数据、隐私与安全
|
|
83
|
+
|
|
84
|
+
- **额度是快照,不是会话账本**:GLM 的额度窗口、今日 tokens / 调用次数,以及 Copilot 的额度视图都来自服务商报告;网络或上游处理可能造成延迟。
|
|
85
|
+
- **Copilot 额度语义**:插件只采用 GitHub 报告的 `remaining` 与 `percent_remaining`;不会用 `credits_used` 推算余额。组织管理的 seat 可能使用共享计费池,个人额度视图不等于组织剩余余额。
|
|
86
|
+
- **凭据与存储**:GLM 的 `llm-pi-ai` `apiKeyEnv` 引用和 Copilot OAuth grant 由 DSH 宿主解析并用于 HTTPS 请求。浏览器只接收归一化额度字段;插件不把 key、OAuth grant 或原始服务商响应写入磁盘,也不保存额度历史。自动用卡的开关与阈值是例外:它们保存在前述宿主设置文件中。
|
|
87
|
+
- **路由保护**:API 路由只接受 loopback 或已配对浏览器的同源请求,并禁用缓存。
|
|
88
|
+
- **公开包检查**:npm 包使用显式 `files` allowlist;CI 的 `npm run security:check` 扫描工作树与由 allowlist 推导的候选打包文件,诊断仅报告路径和规则名,不打印匹配值。
|
|
89
|
+
- **服务商限制**:Copilot quota endpoint 和 GLM 重置卡接口均不是稳定的公开契约,字段或行为可能变化;无法确认额度含义时,插件会显示不可用,而不会自行推算。
|
|
90
|
+
|
|
91
|
+
401/403 等授权错误出现时,请在 DSH 中重新授权相应服务商;若某一行标记为过期,显示值是最近一次成功快照,而非当前实时余额。
|
|
71
92
|
|
|
72
93
|
## English summary
|
|
73
94
|
|
|
74
|
-
DSH Quota Watch
|
|
95
|
+
DSH Quota Watch displays provider-reported quota snapshots for GLM Coding Plan and GitHub Copilot in a floating capsule, detail panel, and optional sidebar card that is hidden by default and toggled from the panel. It does not read DSH session tokens or derive Copilot remaining credits from credits used. The declared requirements are DSH `>=0.1.7-rc.2`, Node.js `>=20`, and Cordis peer `^4.0.2`; the package declares a Web client target. The plugin has been manually verified with both DSH Web and Desktop profiles; CI does not run host-profile integration tests.
|
|
96
|
+
|
|
97
|
+
Install for a DSH Web or Desktop profile from the DSH plugin marketplace. Both profiles have been manually verified; the CLI install commands are shown above.
|
|
98
|
+
|
|
99
|
+
**Reset cards are optional, irreversible spending.** They are supported only for domestic `zai-coding-cn` personal plans. Automatic use is separately authorized per window and defaults off. The upstream reset-card APIs are undocumented and may change; an ambiguous timeout may still have consumed a card, so verify the provider state before retrying.
|
|
100
|
+
|
|
101
|
+
All screenshots contain synthetic example data.
|
package/cordis.patch.yml
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
# Mount the host-side quota watcher; the browser half is supplied by dsh.client.
|
|
2
|
+
#
|
|
3
|
+
# autoReset is a REAL, irreversible redemption, not a read-only quota probe.
|
|
4
|
+
# The panel header's "Auto-use" checkbox merely expands settings; only the two
|
|
5
|
+
# per-window enabled switches authorize host-side spending. Both default OFF.
|
|
6
|
+
# Panel changes atomically replace $DSH_HOME/glm-quota-reset/settings.json and
|
|
7
|
+
# override this initial profile config; a corrupt/unreadable saved file fails OFF.
|
|
8
|
+
# A missing saved file uses these values — setting enabled:true here deliberately
|
|
9
|
+
# arms auto-use after startup even without any browser open.
|
|
10
|
+
# fiveHour.enabled / week.enabled : explicit authorization (default false)
|
|
11
|
+
# fiveHour.threshold / week.threshold : used-percent trigger, 50-99.9 (default 99.9)
|
|
12
|
+
# pollIntervalSec : quota check cadence in seconds (30-3600). Fast consumption
|
|
13
|
+
# between two probes may exceed the limit before any automatic reset can fire.
|
|
14
|
+
# Only fresh domestic personal-plan data may trigger a spend. Weekly cards clear
|
|
15
|
+
# both week and 5h; a timed-out / ambiguous POST disables further auto retries
|
|
16
|
+
# until the quota falls below threshold or the switch is deliberately re-armed.
|
|
2
17
|
- insert:
|
|
3
18
|
- id: quota-watch
|
|
4
19
|
name: '@iasiv5/dsh-quota-watch'
|
|
5
20
|
config:
|
|
6
21
|
pollIntervalSec: 60
|
|
22
|
+
autoReset:
|
|
23
|
+
fiveHour:
|
|
24
|
+
enabled: false
|
|
25
|
+
threshold: 99.9
|
|
26
|
+
week:
|
|
27
|
+
enabled: false
|
|
28
|
+
threshold: 99.9
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|