dsh-musage-card 1.6.0
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/LICENSE +21 -0
- package/README.md +196 -0
- package/cordis.patch.yml +8 -0
- package/dsh/client.js +924 -0
- package/dsh/index.js +2008 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thedeergod666
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# dsh-musage-card
|
|
2
|
+
|
|
3
|
+
`dsh-musage` 的本地二次开发版 —— 挂在 **DSH 侧边栏底部("移动访问"按钮上方)** 的多 provider
|
|
4
|
+
用量/余额玻璃卡片:跟随当前会话选中的模型**自动切换**,剩余量进度条(5h 流动绿 / 7d 流动彩)。
|
|
5
|
+
|
|
6
|
+
**不发布到任何 registry**,通过 `file:` 依赖或手动放置安装,插件市场的更新永远不会覆盖它。
|
|
7
|
+
|
|
8
|
+
## 支持的 Provider(11 家)
|
|
9
|
+
|
|
10
|
+
| Provider(DSH route id 变体) | 显示 | 端点 | 凭据 |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| `minimax` / `minimax-cn` / `minimax-en` | 5h / 7d 双窗口 | `api.minimaxi.com/v1/api/openplatform/coding_plan/remains` | `MINIMAX_CN_API_KEY` 等 |
|
|
13
|
+
| `deepseek` / `deepseek-official` | 余额(¥ / $) | `api.deepseek.com/user/balance` | `DEEPSEEK_API_KEY` |
|
|
14
|
+
| `kimi` / `kimi-coding` | 5h / 7d 双窗口 | `api.kimi.com/coding/v1/usages` | `KIMI_CODING_API_KEY` |
|
|
15
|
+
| `zhipu` / `zai-coding-cn` | 5h / 7d 双窗口 | `open.bigmodel.cn/api/monitor/usage/quota/limit` | `ZAI_CODING_CN_API_KEY` |
|
|
16
|
+
| `openrouter` | 余额($) | `openrouter.ai/api/v1/credits` | `OPENROUTER_API_KEY` |
|
|
17
|
+
| `stepfun` / `stepfun-plan` | 余额(¥,现金/券细分)+ 账户总览 | `api.stepfun.com/v1/accounts` / `/api/…Dashboard/QueryAccountBalance` | `STEPFUN_API_KEY`;Step Plan / Credit 走**网页登录态**(**可一键登录**,见下) |
|
|
18
|
+
| `siliconflow` / `siliconflow-cn` | 余额(¥,充值/总额细分) | `api.siliconflow.cn/v1/user/info` | `SILICONFLOW_API_KEY` |
|
|
19
|
+
| `tavily` | 已用 / 总量 credits + 明细 | `api.tavily.com/usage` | `TAVILY_API_KEY` |
|
|
20
|
+
| `zenmux` | PAYG 余额($,充值/奖励细分) | `zenmux.ai/api/v1/management/payg/balance` | `ZENMUX_MANAGEMENT_API_KEY`(`sk-mg-v1-`) |
|
|
21
|
+
| `xiaomi-token-plan-{ams,cn,sgp}` / `xiaomi` / `mimo` … | 套餐 / 补偿 / 月总额 三行 | `platform.xiaomimimo.com/api/v1/tokenPlan/usage` | **浏览器 Cookie**(key 实测被 401,自动退 Cookie;**可一键登录**,见下) |
|
|
22
|
+
| `claude` / `anthropic` / `claude-code` | 5h / 7d 双窗口 | `api.anthropic.com/api/oauth/usage` | **sessionKey Cookie**(**可一键登录**,见下) |
|
|
23
|
+
|
|
24
|
+
> `modlens-<provider>` 视觉包装路由会自动剥壳后映射到上游 provider。
|
|
25
|
+
|
|
26
|
+
## 凭据怎么配
|
|
27
|
+
|
|
28
|
+
- **API Key 类(前 9 家)**:复用 DSH 模型设置里已配的 provider key
|
|
29
|
+
(DSH 规范:`<PROVIDER 大写去特殊字符>_API_KEY`),无需重复填写。
|
|
30
|
+
- **小米 MiMo**:**需要浏览器登录态 Cookie**(2026-10 实机:Token Plan API key 走 Bearer 会被
|
|
31
|
+
dashboard 端点 401 + loginUrl 拒绝;若命中了 key,插件会自动退 Cookie 重试一次)。
|
|
32
|
+
**推荐用「一键登录」**(见下节)——卡片失败态点击即自动打开官方登录页,完成后
|
|
33
|
+
Cookie 自动写入 `XIAOMI_MIMO_COOKIE`。手动方式:登录 `platform.xiaomimimo.com` →
|
|
34
|
+
F12 → Network → 任一 `/api/v1/tokenPlan/*` 请求 → 复制**完整 Cookie header 值**存入 ref。
|
|
35
|
+
- **Claude**:**推荐用「一键登录」**——点击卡片自动打开 `claude.ai` 登录页,完成后
|
|
36
|
+
`sessionKey` 自动写入 ref `CLAUDE_SESSION_KEY`(官方 OAuth 用量端点,插件自动带
|
|
37
|
+
`Anthropic-Beta: oauth-2025-04-20` 与 `claude-code` UA)。手动方式:从 `claude.ai`
|
|
38
|
+
取 `sessionKey` cookie 值存入 ref。
|
|
39
|
+
- **Cookie 的存入方式**(MiMo 兜底、Claude 必需):编辑 `~/.dsh/.credentials.yaml` 追加一行
|
|
40
|
+
即可 —— DSH 凭据存储**会观察外部编辑并热生效**(不需要重启;值请用引号包裹):
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
# ~/.dsh/.credentials.yaml(示例;与现有内容合并,勿覆盖)
|
|
44
|
+
XIAOMI_MIMO_COOKIE: "api-platform_serviceToken=...; userId=...; api-platform_slh=...; api-platform_ph=..."
|
|
45
|
+
CLAUDE_SESSION_KEY: "sk-ant-sid01-..."
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- Cookie 会过期(Claude 约 8 小时、MiMo 随登出失效):卡片显示 ⚠ 时重新复制一次即可。
|
|
49
|
+
|
|
50
|
+
### 一键登录(登录助手,v1.5.0 / v1.6.0,推荐)
|
|
51
|
+
|
|
52
|
+
对 **小米 MiMo**、**Claude**、**StepFun** 三家(网页登录态凭据,普通用户无法手工提取):
|
|
53
|
+
|
|
54
|
+
1. 卡片显示 ⚠ / 🔑 / 「点击卡片登录读取」时 **点击卡片**;
|
|
55
|
+
2. 插件弹出**专用浏览器窗口**(本机 Edge/Chrome),停在官方登录页;
|
|
56
|
+
3. 你在窗口里正常登录(账号密码直接提交给官方站点,插件不接触);
|
|
57
|
+
4. 登录完成 → 窗口自动关闭 → 卡片自动显示用量。**无需 F12、无需复制、无需编辑文件。**
|
|
58
|
+
|
|
59
|
+
为什么可以放心:
|
|
60
|
+
|
|
61
|
+
- 窗口是**真实浏览器 + 真实官网页面**(保留地址栏,可自行核对域名);
|
|
62
|
+
- 专用 profile 存在 `~/.dsh/musage-login/`:登录态被保留(Cookie 过期后重登通常免输密码),
|
|
63
|
+
与你的日常浏览器完全隔离,可随时整个删除;
|
|
64
|
+
- 插件只在登录完成后经浏览器调试协议读取该站点的 Cookie,**只写入 DSH 凭据库**
|
|
65
|
+
(打开的是独立调试端口、仅回环地址,随会话结束关闭);
|
|
66
|
+
- 登录中直接关闭浏览器窗口 = 取消;30 分钟未完成自动收尾;
|
|
67
|
+
- 环境不支持时(未装 Edge/Chrome、企业策略禁用调试)卡片会提示失败原因,
|
|
68
|
+
仍可按上面的手动方式配置。
|
|
69
|
+
|
|
70
|
+
## 与上游 dsh-musage 的差异
|
|
71
|
+
|
|
72
|
+
- 注册点:`conversation.input.right`(composer 内联)→ **`sidebar.footer.action`**
|
|
73
|
+
(左下角侧边栏 footer,"移动访问"按钮上方,order -100)
|
|
74
|
+
- 卡片化:半透明玻璃材质(backdrop-filter blur + 高光描边),明暗主题通用
|
|
75
|
+
- 剩余量倒数显示:已用% → 剩余% = 100 − 已用%(数值与进度条填充均为剩余量)
|
|
76
|
+
- 流动进度条:5h 流动绿、7d 流动彩、补偿/通用行流动橙(prefers-reduced-motion 自动停用)
|
|
77
|
+
- 会话来源:订阅 `uiSession` 服务的 current binding(主视图会话)——见 v1.3.0
|
|
78
|
+
- 点击卡片立即刷新(60s 定时刷新保留)
|
|
79
|
+
- 登录助手(v1.5.0):小米 / Claude 失败态点击卡片 → 专用浏览器登录 → 自动写入凭据
|
|
80
|
+
- host 半边已扩展为 11 家(上游 5 家)
|
|
81
|
+
|
|
82
|
+
## 变更记录
|
|
83
|
+
|
|
84
|
+
### v1.6.0(2026-10)StepFun 一键登录:读取 Step Plan Credit / 账户总览
|
|
85
|
+
|
|
86
|
+
- **Host(`dsh/index.js`)**:登录助手新增 StepFun(登录页 `account.stepfun.com`;
|
|
87
|
+
成功判定 = Connect-JSON `QueryAccountBalance` 试调自证,认证 = 整段 cookie +
|
|
88
|
+
从 cookie 提取的 `Oasis-Token` / `Oasis-Webid` 请求头——2026-10-01 逆向自官网
|
|
89
|
+
bundle 并经未认证 401 探针实证);`curlFetch` 扩展 POST / 自定义头 / body 支持
|
|
90
|
+
(新增 `oasis` 鉴权型);StepFun 余额响应附加 `display.oasis`
|
|
91
|
+
(credit / voucherPlan / voucher 等账户总览字段,失败静默不阻塞余额)。
|
|
92
|
+
- **Client(`dsh/client.js`)**:StepFun 卡片渲染 🧾 账户总览行(Plan/Credit/赠送);
|
|
93
|
+
缺数据时渲染「🔑 点击卡片登录读取 Step Plan Credit」引导;
|
|
94
|
+
`canLoginAssistFor` 语义调整为以 host 附着为唯一事实源(StepFun 成功态也可给登录入口)。
|
|
95
|
+
- **测试**:95 用例 —— 新增 pickCookieValue / parseStepfunOasis / stepfun 配置纯函数
|
|
96
|
+
用例、StepFun 接口在线契约探测(端点漂移报警)、stepfun 卡片渲染仿真 4 用例。
|
|
97
|
+
|
|
98
|
+
### v1.5.0(2026-10)登录助手:点击卡片 → 浏览器登录 → 自动获取 Cookie
|
|
99
|
+
|
|
100
|
+
- **Host(`dsh/index.js`)**:新增登录助手——CDP(DevTools 协议)客户端
|
|
101
|
+
(DevToolsActivePort 发现 / WebSocket 问答 / `Network.getCookies` 读含 HttpOnly /
|
|
102
|
+
`Browser.close` 优雅关闭);登录会话单例(Cookie 轮询 → 试调用量 API 自证 →
|
|
103
|
+
`credentials.set` 原子写入 → 优雅关窗 → 缓存失效);新路由 `POST /musage/login`
|
|
104
|
+
(action=start|cancel)与 `GET /musage/login/status`;失败响应附 `loginAssist` 标记
|
|
105
|
+
(client 据此给出登录入口)。
|
|
106
|
+
- **Client(`dsh/client.js`)**:失败态卡片显示「🔑 需要 XX 登录 · 点击卡片自动获取」;
|
|
107
|
+
登录中/刚成功过渡态文案;登录完成后自动刷新用量。点击分发与文案选择收在三个纯函数
|
|
108
|
+
(`decideCardClick` / `canLoginAssistFor` / `loginNoteFor`),可直接单测。
|
|
109
|
+
- **测试**:`node --test`(全量自动发现,82 用例)——新增 login-assist 30 用例
|
|
110
|
+
(纯函数:cookie 拼接/提取、marker 判定、浏览器探测、请求解析)、cdp-integration
|
|
111
|
+
2 用例(真实 headless 浏览器全链路:读 HttpOnly cookie 与 Browser.close)、
|
|
112
|
+
session-orchestration 4 用例(mock ctx + 真实浏览器驱动生产路由的会话编排:
|
|
113
|
+
start/取消/关窗/dispose 清理;含同 profile 二次会话回归)、client-login 12 用例
|
|
114
|
+
(交互决策)。浏览器类用例无浏览器时自动 skip。
|
|
115
|
+
|
|
116
|
+
### v1.4.0(2026-10)新增 5 家 provider
|
|
117
|
+
|
|
118
|
+
- **Host(`dsh/index.js`)**:新增 `siliconflow` / `tavily` / `zenmux` / `xiaomi` / `claude`
|
|
119
|
+
五家 PROVIDERS 条目与解析器(schema 对齐 [Musage](https://github.com/Thedeergod666/Musage)
|
|
120
|
+
同名实现);`curlFetch` 增加 `cookie`(整段 Cookie header)与 `claude`
|
|
121
|
+
(sessionKey + beta header + UA)两种鉴权形态。
|
|
122
|
+
- **Client(`dsh/client.js`)**:新增各家 route 别名与标签;新增通用百分比行
|
|
123
|
+
`pctRows` 渲染(MiMo 的 套餐/补偿/月总额 三行);余额行标签可定制(Tavily 显示"用量")。
|
|
124
|
+
- **测试**:新增 `tests/parsers.test.mjs`(node:test,21 用例——5 家新 provider 的
|
|
125
|
+
正常/缺失/业务错误路径 + 既有家回归)。`node --test tests/parsers.test.mjs`。
|
|
126
|
+
|
|
127
|
+
### v1.3.0(2026-10)注册点回归侧边栏(修正 v1.2.19 误判)
|
|
128
|
+
|
|
129
|
+
- 注册点:`conversation.input.right` → **回归 `sidebar.footer.action`**(root 作用域,
|
|
130
|
+
"移动访问"按钮上方,order -100)。v1.2.19 曾在 sidebar 上误判"root 拿不到当前会话"
|
|
131
|
+
(只翻了 sessions store 快照找 `current` 字段)而把卡片临时挪到输入框旁——位置不对。
|
|
132
|
+
- 会话来源:`uiSession` 服务的 current binding(`dsh-client-ui-session` 的
|
|
133
|
+
`UiSession.publishMain`:优先保持上一次有效选择,否则取 `retainedBy.mainView>0`
|
|
134
|
+
的主视图会话;无会话时 `props.sessionId` 为 undefined)。用 scoped
|
|
135
|
+
`ctx.inject(["uiSession"], …)` 等服务就绪后注册,服务缺失时卡片占位不崩。
|
|
136
|
+
(root 作用域拿当前会话的另一条通道:`useSessions` + `retainedBy.mainView` 推导——
|
|
137
|
+
官方 layout 包 `DocumentTitle` 同款模式;详见 `dsh/client.js` 头注释第 5 条。)
|
|
138
|
+
- CSS:恢复 `[data-slot="sidebar.footer.action"]` 垂直 flex 列覆盖(卡片在按钮上方)。
|
|
139
|
+
|
|
140
|
+
### v1.1.0(2026-09)新增 StepFun 支持
|
|
141
|
+
|
|
142
|
+
- Host:新增 `stepfun` provider,走 `GET https://api.stepfun.com/v1/accounts`,
|
|
143
|
+
展示按量余额(CNY,含现金 / 代金券细分),复用 `STEPFUN_API_KEY`。
|
|
144
|
+
- **已知边界**:Step Plan(Token Plan)的 Credit 用量没有 API-Key 认证的查询端点
|
|
145
|
+
(实测 2026-09-22:`step_plan/v1` 下 `usages`/`usage`/`quota`/`credits`/`subscription`/`balance`
|
|
146
|
+
与 `/v1/credits`、`/v1/subscription` 全部 404)。卡片附一行"Step Plan Credit 用量仅官网可查"。
|
|
147
|
+
|
|
148
|
+
### v1.0.0 本地包化(防市场覆盖)
|
|
149
|
+
|
|
150
|
+
- 背景:profile 中官方 `dsh-musage` 依赖为 `github:Thedeergod666/dsh-musage`(无版本锁定),
|
|
151
|
+
市场更新会覆盖二次开发。方案:改为独立本地包 `dsh-musage-card`,`file:` 安装;
|
|
152
|
+
registry 不存在该包名,永远不被覆盖。cordis insert id 用 `musage-card`(防与官方 `musage` 冲突)。
|
|
153
|
+
|
|
154
|
+
## 安装
|
|
155
|
+
|
|
156
|
+
### 方式 A:插件市场(推荐)
|
|
157
|
+
|
|
158
|
+
本插件已发布到 **dsh-plugin 生态**(GitHub topic [`dsh-plugin`](https://github.com/topics/dsh-plugin),
|
|
159
|
+
被 DSH 插件市场(如 dsh-plugin-marketplace)live 同步):
|
|
160
|
+
|
|
161
|
+
- 在 DSH **设置 → 插件** 的「插件市场」标签搜索 **dsh-musage-card** 一键安装;或
|
|
162
|
+
- 让 agent 执行 `market_install` / 手动 `dsh plugin --profile web add -w Lin-Dongg/dsh-musage-card`。
|
|
163
|
+
|
|
164
|
+
安装后重启 DSH。
|
|
165
|
+
|
|
166
|
+
### 方式 B:本地 file: 挂载(开发调试)
|
|
167
|
+
|
|
168
|
+
1. 把 `dsh-musage-card` 目录放到任意位置(见下方 profile 依赖写法)。
|
|
169
|
+
2. 编辑 `~/.dsh/profiles/desktop/package.json`:
|
|
170
|
+
- `dsh.profile.bundles` 数组加入 `"dsh-musage-card"`;
|
|
171
|
+
- `dependencies` 加入 `"dsh-musage-card": "file:<绝对路径,如 D:/dsh-plugins/dsh-musage-card>"`。
|
|
172
|
+
3. 在 profile 目录执行 `pnpm install`。
|
|
173
|
+
4. 重启 DSH(host 半边)或刷新页面(client 半边)。
|
|
174
|
+
|
|
175
|
+
> 注意:与官方 `dsh-musage` 同时挂载会出现重复卡片(insert id 不同:
|
|
176
|
+
> `musage-card` vs `musage`),二选一即可。
|
|
177
|
+
|
|
178
|
+
## 开发
|
|
179
|
+
|
|
180
|
+
- **生效方式**:client 半边(`dsh/client.js`)改完刷新页面(F5)即可;host 半边
|
|
181
|
+
(`dsh/index.js`)改完需重启 DSH。pnpm 对 `file:` 依赖是**复制安装**——改源码后需在
|
|
182
|
+
profile 目录 `pnpm install`(或直接同步改 `node_modules` 里的副本)。
|
|
183
|
+
- **测试**:`node --test`(全量自动发现;其中 cdp-integration 需要本机 Edge/Chrome,
|
|
184
|
+
无浏览器时自动 skip)。
|
|
185
|
+
- **host 形态**:手写懒加载 bundle 协议(`window.__ModuleLoader__.load` + factory),
|
|
186
|
+
无构建步骤;`dsh/index.js` 侧为 ESM,`__parsers` / `__login` 导出仅供测试。
|
|
187
|
+
|
|
188
|
+
## 源码与文档
|
|
189
|
+
|
|
190
|
+
- GitHub:https://github.com/Lin-Dongg/dsh-musage-card
|
|
191
|
+
- 开发说明 / 迭代记录:`docs/开发说明.md`(若从作者机器迁移,见其 `D:\deepseek工作区\musage-plugin-dev\`)
|
|
192
|
+
- 数据 schemas 参考:[Musage](https://github.com/Thedeergod666/Musage) 的 `src-tauri/src/providers/*.rs`
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT(见 `LICENSE`)。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# dsh bundle layer: mount the musage-card quota glass card plugin (local fork
|
|
2
|
+
# of dsh-musage). The host half is the package root export (./dsh/index.js);
|
|
3
|
+
# the browser half loads via the ./client export declared by the dsh.client
|
|
4
|
+
# manifest in package.json. Insert id is musage-card (distinct from the
|
|
5
|
+
# upstream musage id, so the two can never collide in one loader table).
|
|
6
|
+
- insert:
|
|
7
|
+
- id: musage-card
|
|
8
|
+
name: dsh-musage-card
|