@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 CHANGED
@@ -1,74 +1,101 @@
1
- # dsh-quota-watch — DSH Web 额度监控
1
+ # DSH Quota Watch
2
2
 
3
- [![Release](https://img.shields.io/github/v/release/iasiv5/dsh-quota-watch?label=Release&sort=semver)](../../releases)
4
- [![CI](https://img.shields.io/github/actions/workflow/status/iasiv5/dsh-quota-watch/ci.yml?branch=main&label=CI)](../../actions/workflows/ci.yml)
5
- [![License](https://img.shields.io/github/license/iasiv5/dsh-quota-watch?label=License)](./LICENSE)
3
+ [![Release](https://img.shields.io/github/v/release/iasiv5/dsh-quota-watch?label=Release&sort=semver)](https://github.com/iasiv5/dsh-quota-watch/releases)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/iasiv5/dsh-quota-watch/ci.yml?branch=main&label=CI)](https://github.com/iasiv5/dsh-quota-watch/actions/workflows/ci.yml)
6
5
  [![npm](https://img.shields.io/npm/v/@iasiv5/dsh-quota-watch?label=npm)](https://www.npmjs.com/package/@iasiv5/dsh-quota-watch)
7
- [![DSH Web](https://img.shields.io/badge/DSH%20Web-0.2.0--rc.2%20verified-2563eb)](#-兼容性)
6
+ [![License](https://img.shields.io/github/license/iasiv5/dsh-quota-watch?label=License)](./LICENSE)
8
7
 
9
8
  [English summary](#english-summary) · 中文
10
9
 
11
- 在常驻悬浮胶囊里一眼看尽 GLM Coding Plan 与 GitHub Copilot 的额度快照。不统计 DSH 会话 token、不保存历史、也不需要在浏览器里输入任何 provider 密钥。
12
-
13
- ![面板概览:Token 额度与等宽操作按钮](docs/assets/panel-overview.webp)
10
+ 在 DSH 中查看 **GLM Coding Plan** 与 **GitHub Copilot** 的服务商额度快照。Quota Watch 不读取 DSH 会话 token;凭据由 DSH 宿主解析,浏览器只接收整理后的额度数据。
14
11
 
15
- ## ✨ 功能一览
12
+ ![额度概览:悬浮胶囊与额度面板(示例数据)](docs/assets/panel-overview.webp)
16
13
 
17
- - **🚀 悬浮胶囊(默认界面)**:一行「GLM 15% · Copilot 1.8%」常驻屏幕(默认右下角安全区),单击展开面板——胶囊上没有任何隐藏手势(右键 / 长按菜单已于 0.1.14 退役)。拖拽跟手(保持抓取点,transform 渲染)、任意位置停放、位置跨重启记忆、越界自动钳回视口(距边 8px 安全边距),并自动避开 Windows Desktop 壳顶部的标题栏拖拽带(0.1.20:该带按布局吞掉指针输入、无视 z-index,胶囊/面板落进去就再也点不到、拖不回——现与壳自家浮窗同款消费 `--dsh-windows-titlebar-height` 让位,历史卡死位置在启动时自动钳回带外;Web 无此变量,行为零漂移);触摸设备直接拖拽(更宽的防误拖阈值)、点击热区 44px、自动避让 iPhone 刘海 / 小黑条(safe-area)。已用超过 80% 转橙、超过 95% 转红,任一 provider 超 95% 时轻微脉动(尊重系统「减少动态效果」设置)。悬停提示与 aria-label 实时给出摘要。
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
- GLM 详情(双大数字 + 窗口网格 + 分模型用量)与 Copilot 详情(额度 / 已用 / 重置时间):
22
+ ## 兼容性与前置要求
31
23
 
32
- | GLM 详情 | Copilot 详情 |
24
+ | 项目 | 要求或声明 |
33
25
  |---|---|
34
- | ![GLM 详情面板:今日 Tokens、调用次数、窗口网格与分模型用量](docs/assets/panel-glm-detail.webp) | ![Copilot 详情面板:可用额度、本期已用、重置时间](docs/assets/panel-copilot-detail.webp) |
26
+ | DSH | `>=0.1.7-rc.2`(包元数据声明的最低版本) |
27
+ | Node.js | `>=20` |
28
+ | Cordis | peer dependency `^4.0.2` |
29
+ | 客户端平台 | 包元数据声明 `web` |
35
30
 
36
- 侧边栏卡片(可选开启,占侧栏 footer 第一槽位):
31
+ 该插件已分别在 DSH Web 与 Desktop profile 上完成人工适配验证;这项运行时验证不由 CI 自动化覆盖。CI 运行 Node 测试、构建和安全检查,不包含 DSH Web / Desktop 运行时矩阵。
37
32
 
38
- ![侧边栏卡片:GLM 与 Copilot 摘要行](docs/assets/sidebar-card.webp)
33
+ ## 安装
39
34
 
40
- ## 🚀 安装
35
+ ### DSH 插件市场
41
36
 
42
- **方式一(推荐)· DSH 插件市场(dsh-m)**:打开 DSH 侧栏的「插件市场」,搜索 **Quota Watch**(或「额度」)一键安装——市场锁定精确版本、自动处理依赖,后续升级也在市场里完成。
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 # web profile
48
- dsh plugin --profile desktop add @iasiv5/dsh-quota-watch # desktop profile
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
- **web 与 desktop 两种 profile 均已适配**:悬浮胶囊在两端都是常驻入口;侧边栏卡片是渐进增强——只要侧栏底部区块存在即可从面板按钮开启,侧栏收起或不存在(Desktop 收起态)时自动缺席。插件管理器会应用包内 `cordis.patch.yml`;宿主半区的变更需要重启 DSH 后生效(web 重启 `dsh web` 服务,desktop 重启应用),客户端 bundle 随插件加载,装好后刷新页面,右下角即是额度胶囊。npm 发布新版本后,市场 / 镜像同步可能略有延迟,立即装不到最新版时稍候重试即可。禁用插件请使用 DSH 插件管理器。
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
- - **探测周期**:在 profile 的 `quota-watch` Cordis row 设置 `config.pollIntervalSec`(30–3600,默认 60)。
56
- - **DSH 版本**:要求 `0.1.7-rc.2` 或更高;适配 `web` 与 `desktop` 两种 profile——Desktop 收起侧栏时由悬浮胶囊承载入口,卡片为 Web 渐进增强。
63
+ ![GLM 详情:额度窗口、重置卡与展开的自动用卡设置;两个窗口的消费授权均关闭(示例数据)](docs/assets/panel-glm-detail.webp)
57
64
 
58
- ## 🔍 数据来源与语义
65
+ 图中的「自动用卡」勾选框只展开设置,不授权消费;下方 5 小时与每周两个开关才是各自独立的授权,截图中均为关闭状态。
59
66
 
60
- - **凭据链路**:GLM 从 `llm-pi-ai` profile 中配置的 provider `apiKeyEnv` credential reference 解析当前 key,支持 `zai-coding-cn`(国内)与 `zai` / `zai-coding`(国际)路由;每次探测都重新解析引用,用户轮换凭据后下一轮读取新值。Copilot 使用内置 `llm-pi-ai/github-copilot` OAuth grant 的 `payload.refresh` 访问配额快照——不使用给模型请求的短期 `payload.access`,也不使用 `COPILOT_GITHUB_TOKEN` 环境引用;每轮重新读取 grant,以支持重新授权或轮换。
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
- - API 路由只允许 loopback 或已配对的浏览器访问;响应禁用缓存。
68
- - 本仓库、测试 fixtures 与 npm 包不得包含任何真实 key、OAuth grant、临时 token、原始账号响应或个人余额。测试仅使用合成响应。
69
- - npm 包采用显式 `files` 白名单;`npm run security:check` 会扫描工作树和实际 pack 文件,诊断只报告路径和规则名,不打印匹配值。
70
- - 后续 tag release 使用 GitHub Actions OIDC 与 provenance,版本发布者身份为 GitHub Actions,不保存长期 npm token;源码和 npm tarball 不写入发布账号邮箱。
76
+ ## Copilot 与侧边栏界面
77
+
78
+ ![Copilot 详情:服务商报告的可用额度、本期已用与重置时间(示例数据)](docs/assets/panel-copilot-detail.webp)
79
+
80
+ ![侧边栏卡片:GLM 与 Copilot 摘要(示例数据)](docs/assets/sidebar-card.webp)
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 is a personal DSH quota monitor built around a persistent floating capsule: a one-line `GLM x% · Copilot y%` summary that turns amber past 80% and red past 95%. Dragging it is grab-accurate (transform-based, rAF-batched) and free to place anywhere on the screen, with position remembered across restarts and viewport boundaries automatically clamped. Since 0.1.20 placement also steers clear of the Windows Desktop shell titlebar drag band (a layout-level `-webkit-app-region:drag` strip that swallows pointer input regardless of z-index — the same trap dsh-m fixed in 0.9.4; the capsule and the panel header consume `--dsh-windows-titlebar-height` the way the shell's own floats do, and positions saved while stuck self-heal below the band on boot; Web, without the variable, is byte-identical). Touch devices drag directly (wider slop against accidental drags), the hit area is padded to 44px and placement respects `env(safe-area-inset-*)`. Clicking the capsule opens a floating glass panel whose overview reuses the classic 0.0.18 summary rows (label · bar · percent · extra · chevron) and whose detail pages replicate the 0.0.18 big numbers, window grid and per-model list; the panel closes via ✕, Esc or an outside click, and viewports ≤480px dock it to the bottom as a sheet. The panel footer holds two equal-width buttons — sidebar-card visibility and an immediate provider re-probe — replacing the retired right-click/long-press menu, so the capsule itself carries no hidden gestures. A sidebar card remains an opportunistic extra entry on web profiles, opted in from that footer button, and silently disappears whenever the sidebar does — collapsed web sidebars and the desktop profile are covered by the floating capsule alone. Credentials are resolved on every host-side probe, only normalized values reach the browser, no usage history is kept, and a Copilot balance is never inferred from credits used. UI copy follows the DSH language preference (mirrored live onto `<html lang>`, re-rendering on switch without a reload) and falls back to the browser language; window notes share one paren glyph per locale so the grid's left edges stay aligned. Colors ride DSH semantic theme tokens with hardcoded fallbacks; all UI lives inside a shadow root (ADR 0001).
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