dsh-sidebar-usage 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 yz-china
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 CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # dsh-sidebar-usage
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Sidebar usage HUD for **DeepSeek Harness** — a balance/quota card pinned to the sidebar footer, plus a hover-out drawer that collects the other footer entries.
4
+
5
+ 侧栏用量看板插件:在看板里显示余额 / 订阅额度 / 累计 token / 调用次数,并带一个贴边隐藏、鼠标移入滑出的入口抽屉。
6
+
7
+ ## 特性 / Features
8
+
9
+ - **多提供商余额**:DeepSeek 官方、`new-api` 系中转(OpenAI 计费接口)、`/user/balance` 形态、任意自研网关(通用 JSON + 点路径取值)。
10
+ - **订阅卡 / 余额两种口径**:给 `totalPath` + `usedPath` 时算"已用 %",给 `expiresPath` 时显示"剩 N 天",卡片上标注类型。
11
+ - **站点口径统计**:中转站支持 `new-api` 的 `refresh` 会话时,可读「累计使用 token / 累计调用次数」,与站点后台同源(10 分钟缓存,轮换 cookie 自动回写)。
12
+ - **看板可调**:拖底部横条改高度、右键金额数字改字号,内容随高度缩放。
13
+ - **入口抽屉**:底栏其它按钮被收进左侧贴边抽屉,鼠标移入滑出、移出落回;每行几个可调(默认 3)。
14
+ - **自动识别**:模型设置里已添加的 provider(带 `baseURL`)会自动出现在看板右键菜单里,不用重复手填。
15
+ - **多账号**:自定义 provider 支持"余额接口"与"订阅接口"两套路径并存,设置页一键切换类型。
16
+
17
+ ## 安装 / Install
18
+
19
+ ```bash
20
+ # 从 npm
21
+ npm install dsh-sidebar-usage
22
+
23
+ # 或本地 tgz
24
+ npm install ./dsh-sidebar-usage-1.0.0.tgz
25
+ ```
26
+
27
+ 装完后在 DSH 插件设置里启用 `dsh-sidebar-usage`,重启 DSH web。首次使用在「设置 → 用量」里添加提供商:
28
+
29
+ | 字段 | 说明 |
30
+ |---|---|
31
+ | provider id | 必须与模型设置里的 provider id 一致 |
32
+ | 接口地址 | **只到域名**,例如 `https://your-relay.example.com` |
33
+ | 接口类型 | `OpenAI 计费接口`(new-api 系)/ `DeepSeek /user/balance` / `通用 JSON` |
34
+ | 凭据引用 | 可以是环境变量名(`MY_RELAY_KEY`)或直接粘贴密钥 |
35
+
36
+ `通用 JSON` 需要自己填接口路径与字段路径(点路径,数组用 `.0` 或 `[0]`,例如 `data.balance`)。
37
+
38
+ ## 配置示例
39
+
40
+ ```yaml
41
+ - id: deepseek-usage
42
+ name: "dsh-sidebar-usage"
43
+ config:
44
+ customProviders:
45
+ - provider: my-relay
46
+ label: 我的中转
47
+ baseUrl: https://relay.example.com
48
+ preset: newapi # newapi | openai-billing | deepseek-balance | jichuanai | json
49
+ currency: CNY
50
+ apiKeyRef: MY_RELAY_KEY
51
+ ```
52
+
53
+ ## 说明 / Notes
54
+
55
+ - 站点口径的「累计 token / 调用次数」需要中转站登录态(cookie 或 token)。凭证只存在本机 `.credentials.yaml`,不会随包分发。
56
+ - 该插件通过"代理磁贴"的方式把底栏其它按钮收进抽屉:原按钮仍挂载,点击转调,弹层功能不受影响。
57
+
58
+ ## License
59
+
60
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,71 @@
1
+ <img src="https://cdn.jsdelivr.net/npm/@dougen/dsh-deepseek-usage/icon.svg" alt="dsh-deepseek-usage icon" width="72" align="right" />
2
+
3
+ # dsh-deepseek-usage
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@dougen/dsh-deepseek-usage)](https://www.npmjs.com/package/@dougen/dsh-deepseek-usage)
6
+ [![CI](https://github.com/dougen/dsh-deepseek-usage/actions/workflows/ci.yml/badge.svg)](https://github.com/dougen/dsh-deepseek-usage/actions/workflows/ci.yml)
7
+
8
+ [English](README.md) | 中文
9
+
10
+ 一个 **DeepSeek Harness(DSH)** 的侧边栏插件:在 DSH 主界面就能看到**当前选中模型背后的账户还剩多少钱 / 多少额度**、**这个模型此刻什么价**。覆盖九家提供商。
11
+
12
+ <img src="https://cdn.jsdelivr.net/npm/@dougen/dsh-deepseek-usage/screenshot.png" alt="侧边栏卡片:余额、当前单价与计费时段指示灯" width="520" />
13
+
14
+ *余额形态(DeepSeek、Kimi、Z.ai、OpenRouter 等):账户余额、当前模型的输入 / 输入缓存 / 输出单价,右上角是峰谷时段指示灯。*
15
+
16
+ <img src="https://cdn.jsdelivr.net/npm/@dougen/dsh-deepseek-usage/screenshot2.png" alt="订阅用量:各计费窗口的剩余额度" width="520" />
17
+
18
+ *订阅形态(Kimi For Coding、OpenCode、MiniMax、Claude Code / Codex 等):每个用量窗口一个 D 形仪表盘——中间的数是剩余额度,灰色弧是已用量,绿色弧是剩余量(已用达到 80% 时转红),底部徽章标出窗口(`5H` = 5 小时、`7D` = 周、`1M` = 月)。*
19
+
20
+ ## 这个插件是干嘛的
21
+
22
+ DSH 可以切换很多家模型提供商,但每家的账户状况藏在不同的网站后台。这个插件会解析你在 DSH 里当前选中的模型属于哪家提供商,把那个账户的实时状态卡片放进 DSH 主界面侧边栏底部:
23
+
24
+ - **账户读数**,按提供商公开的内容分两种形态:
25
+ - *余额类*(DeepSeek、Moonshot / Kimi、智谱 Z.ai、OpenRouter)公开账户余额,卡片直接显示带币种符号(`¥` / `$`)的余额。
26
+ - *订阅类*(Kimi For Coding、OpenCode、MiniMax、Claude Code、OpenAI Codex)没有余额可查,只公开用量窗口。卡片按接口返回的窗口各画一个仪表盘——5 小时、周、月,返回几个画几个——显示每份额度还剩多少,已用达到 80% 时剩余弧变红。
27
+ - 卡片始终跟随当前选中的模型,切换提供商即切换读数;除凭据外不需要针对某家提供商再做任何配置。
28
+ - **当前模型的单价**。卡片列出输入 / 输入缓存 / 输出的单价,按此刻生效的计费时段取值,币种跟该提供商保持一致。有的提供商按时段计价——DeepSeek 官方峰谷(北京时间周一至周五 09:00–12:00、14:00–18:00 为高峰,夜间、周末、节假日为空闲)或 OpenRouter 的分时定价——卡片会用一枚橙 / 绿指示灯标出当前时段,悬浮可见距下次切换还剩多久。
29
+ ## 如何安装和使用
30
+
31
+ **第 1 步——配置提供商的凭据。** 插件用你给该提供商配的那把 Key 查询:在 DSH 设置的**模型页**填好,或导出为环境变量(`DEEPSEEK_API_KEY`、`MOONSHOTAI_API_KEY`、`ZAI_API_KEY`、`OPENROUTER_API_KEY`、`KIMI_CODING_API_KEY`、`OPENCODE_API_KEY`、`MINIMAX_API_KEY` 等)。`deepseek-account` 是例外:它不需要密钥——在 DSH 里登录 DeepSeek 账号即可,卡片读的是登录留下的授权。
32
+
33
+ **第 2 步——把插件装进 `web` profile:**
34
+
35
+ ```sh
36
+ dsh plugin --profile web add @dougen/dsh-deepseek-usage
37
+ ```
38
+
39
+ **第 3 步——重启 `dsh web`**,打开它打印的地址。卡片位于侧边栏底部、Cordis 面板按钮下方;点击卡片可立即刷新。提供商映射与订阅令牌在**设置 → DeepSeek 用量**里配置;当前模型背后的路由不被支持时,卡片上会给出「去映射」按钮,点击直接打开这一页。
40
+
41
+ <details>
42
+ <summary>使用 Claude Code / OpenAI Codex 订阅(OAuth)</summary>
43
+
44
+ API Key 读不到这两种订阅——它们走 OAuth 令牌。当 DSH 检测到 Claude Code 或 OpenAI Codex(或有映射目标指向其中之一),**设置 → DeepSeek 用量** 的提供商映射下方会出现令牌填写框。把令牌粘贴进去,侧边栏卡片即可开始显示该订阅的余量:
45
+
46
+ - **Claude Code**——在已登录 Claude Code 的机器上,从 `~/.claude/.credentials.json` 复制 `claudeAiOauth.accessToken`(macOS 在钥匙串项 `Claude Code-credentials` 里)。`claude setup-token` 产生的令牌也能用。
47
+ - **OpenAI Codex**——从 `~/.codex/auth.json` 复制 `tokens.access_token` 填进令牌框,`tokens.account_id` 填进账号 ID 框。
48
+
49
+ 令牌经 DSH 的凭据服务保存在本机(`~/.dsh/.credentials.yaml`),任何响应、日志、页面元素都不会把它带出去;点**清除**按钮即可删除。
50
+ </details>
51
+
52
+ <details>
53
+ <summary>卸载</summary>
54
+
55
+ ```sh
56
+ dsh plugin --profile web remove @dougen/dsh-deepseek-usage
57
+ ```
58
+
59
+ 然后重启 `dsh web`。
60
+ </details>
61
+
62
+ ## 支持的 DSH 版本
63
+
64
+ 插件版本要与 DSH 版本相配:
65
+
66
+ | DSH 版本 | 应安装的插件版本 |
67
+ | --- | --- |
68
+ | `0.2.x`(`0.2.0-rc.1` 起) | `0.11.0` 及以后 |
69
+ | `0.1.x`(`0.1.0-rc.6` 起) | `0.10.x`,或 `0.11.0` 及以后 |
70
+
71
+ 运行 `dsh --version` 查看你的 DSH 版本。不带版本号安装会自动取最新的兼容版本;最新版与你的 DSH 不匹配时,指定确切版本,例如 `@dougen/dsh-deepseek-usage@0.10.2`。
@@ -0,0 +1,5 @@
1
+ # dsh-deepseek-usage — DeepSeek 用量侧边栏插件(npm 包名 dsh-sidebar-usage)。
2
+ # Host 半注册 GET /api/deepseek-usage;包声明 dsh.client 提供浏览器侧边栏卡片。
3
+ - insert:
4
+ - id: deepseek-usage
5
+ name: 'dsh-sidebar-usage'
package/icon.svg ADDED
@@ -0,0 +1,21 @@
1
+ <svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <!-- dsh-deepseek-usage:余额 ¥ 硬币 + 峰谷指示灯。
3
+ 硬币与 ¥ 就是卡片上放大的余额,右上角的绿色圆点是卡片右上角的峰谷指示灯
4
+ (绿=空闲、橙=高峰),这两样正是卡片显示的全部内容。 -->
5
+ <defs>
6
+ <linearGradient id="coin" x1="7" y1="9" x2="27" y2="30" gradientUnits="userSpaceOnUse">
7
+ <stop stop-color="#69B9FF"/>
8
+ <stop offset="1" stop-color="#324DE2"/>
9
+ </linearGradient>
10
+ <linearGradient id="idle" x1="25.6" y1="4.8" x2="31.4" y2="10.6" gradientUnits="userSpaceOnUse">
11
+ <stop stop-color="#7FE39B"/>
12
+ <stop offset="1" stop-color="#1F9E52"/>
13
+ </linearGradient>
14
+ </defs>
15
+ <circle cx="16" cy="19.6" r="10" stroke="url(#coin)" stroke-width="2.1"/>
16
+ <path d="M12.6 14.4 16 18.2 19.4 14.4" stroke="url(#coin)" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round"/>
17
+ <path d="M16 18.2V25.2" stroke="url(#coin)" stroke-width="2.1" stroke-linecap="round"/>
18
+ <path d="M12.9 20.4H19.1" stroke="url(#coin)" stroke-width="2.1" stroke-linecap="round"/>
19
+ <path d="M12.9 23.2H19.1" stroke="url(#coin)" stroke-width="2.1" stroke-linecap="round"/>
20
+ <circle cx="28.5" cy="7.7" r="3.1" fill="url(#idle)"/>
21
+ </svg>