dsh-commandcode-quota 0.0.0-stage → 0.2.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 +108 -2
- package/README.zh.md +109 -0
- package/cordis.patch.yml +21 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +70 -4
- package/src/client.js +666 -0
- package/src/index.js +311 -0
- package/test/client.test.cjs +102 -0
- package/test/host.test.cjs +134 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-commandcode-quota contributors
|
|
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,109 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-commandcode-quota
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A **Command Code balance and quota panel** for DeepSeek Harness (DSH).
|
|
4
|
+
|
|
5
|
+
The plugin renders a compact status row directly underneath the DSH composer:
|
|
6
|
+
|
|
7
|
+
- **5-hour, weekly and monthly usage windows** as live percentages
|
|
8
|
+
- **Available balance**
|
|
9
|
+
- Click the row to expand the full breakdown: used / limit / remaining / reset time, total spend, tokens, success rate, subscription and account information
|
|
10
|
+
|
|
11
|
+
It is **single-account by design**. There is no account switcher, and your API key never reaches the browser.
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- DeepSeek Harness with the Web client (`dsh web` or the desktop app)
|
|
16
|
+
- Node.js 20 or newer
|
|
17
|
+
- A Command Code API key
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
### From npm (recommended)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
dsh plugin add dsh-commandcode-quota
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
DSH expands the bundled `cordis.patch.yml` into your profile, so no manual patch editing is needed.
|
|
28
|
+
|
|
29
|
+
### From a local checkout
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dsh plugin add file:/path/to/dsh-commandcode-quota
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Manual junction (desktop app)
|
|
36
|
+
|
|
37
|
+
The Electron desktop profile is managed by the application and does not run the `dsh plugin add` reconciliation, so register it yourself.
|
|
38
|
+
|
|
39
|
+
Link the package into the shared resolution pool:
|
|
40
|
+
|
|
41
|
+
```powershell
|
|
42
|
+
New-Item -ItemType Junction `
|
|
43
|
+
-Path "$env:USERPROFILE\.dsh\profiles\node_modules\dsh-commandcode-quota" `
|
|
44
|
+
-Target "C:\path\to\dsh-commandcode-quota"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then add this to `~/.dsh/profiles/<profile>/cordis.patch.yml`:
|
|
48
|
+
|
|
49
|
+
```yaml
|
|
50
|
+
- insert:
|
|
51
|
+
- id: dsh-commandcode-quota
|
|
52
|
+
name: 'dsh-commandcode-quota'
|
|
53
|
+
config:
|
|
54
|
+
apiKeyEnv: COMMANDCODE_API_KEY
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> The junction name must be exactly the package name, otherwise the host cannot resolve the import.
|
|
58
|
+
|
|
59
|
+
After installing or changing the plugin, reload the plugin tree (the plugin page's refresh action, or a client restart).
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
| Key | Default | Description |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `apiKeyEnv` | `COMMANDCODE_API_KEY` | Credential entry resolved through DSH's credentials service |
|
|
66
|
+
| `fallbackEnv` | — | Optional second entry, used only when the first one is missing |
|
|
67
|
+
| `baseURL` | `https://api.commandcode.ai` | Command Code API origin |
|
|
68
|
+
| `timeoutMs` | `30000` | Per-request timeout in milliseconds |
|
|
69
|
+
|
|
70
|
+
Credentials live in `~/.dsh/.credentials.yaml`, or in DSH Settings → Credentials. Never commit them.
|
|
71
|
+
|
|
72
|
+
## How it works
|
|
73
|
+
|
|
74
|
+
The package has two halves:
|
|
75
|
+
|
|
76
|
+
- **Host half** (`src/index.js`) resolves the key through the DSH credentials service and registers a read-only HTTP endpoint that fans out to the Command Code API, then aggregates the responses into a single payload. The key is read on every request and never serialized to the client.
|
|
77
|
+
- **Client half** (`src/client.js`) registers a status row into the composer dock slot, polls the host endpoint, and renders it with DSH theme tokens so light and dark themes both work.
|
|
78
|
+
|
|
79
|
+
Data comes from four Command Code endpoints, each called with `Authorization: Bearer <key>`:
|
|
80
|
+
|
|
81
|
+
| Endpoint | Used for |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `GET /alpha/billing/credits` | Balance and the 5-hour / weekly limits |
|
|
84
|
+
| `GET /alpha/usage/summary` | Spend, tokens and success rate |
|
|
85
|
+
| `GET /alpha/billing/subscriptions` | Subscription status and period boundaries |
|
|
86
|
+
| `GET /alpha/whoami` | Account information |
|
|
87
|
+
|
|
88
|
+
The monthly window is composed from the usage total plus the remaining credits, with the reset time taken from the subscription period.
|
|
89
|
+
|
|
90
|
+
### Behaviour under failure
|
|
91
|
+
|
|
92
|
+
- The four requests run in parallel, so total latency is the slowest one rather than the sum.
|
|
93
|
+
- A connection-level failure is retried once; a deliberate timeout is not retried.
|
|
94
|
+
- On failure the panel falls back to the last successful value (kept in-process for 6 hours) and reports it as stale.
|
|
95
|
+
- An HTTP 401 is never masked by cached data, because it means the credential itself is wrong.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm test # host and client unit tests; no network, no DSH process
|
|
101
|
+
node --check src/index.js # host half syntax
|
|
102
|
+
node --check src/client.js # client half syntax
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The tests stub the credentials service, the web server, `fetch` and React, so they run offline and never touch a live DSH instance.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# dsh-commandcode-quota
|
|
2
|
+
|
|
3
|
+
一个面向 DeepSeek Harness(DSH)的 **Command Code 余额与额度面板**插件。
|
|
4
|
+
|
|
5
|
+
插件会在 DSH 输入框正下方渲染一行常驻状态栏:
|
|
6
|
+
|
|
7
|
+
- **5 小时、每周、每月**三个额度窗口的实时百分比
|
|
8
|
+
- **可用余额**
|
|
9
|
+
- 点击状态栏展开完整明细:已用 / 上限 / 剩余 / 重置时间、总消耗、Tokens、成功率,以及订阅和账户信息
|
|
10
|
+
|
|
11
|
+
**刻意做成单账号**:没有账号切换,API key 也不会进入浏览器。
|
|
12
|
+
|
|
13
|
+
## 环境要求
|
|
14
|
+
|
|
15
|
+
- 带 Web 客户端的 DeepSeek Harness(`dsh web` 或桌面端)
|
|
16
|
+
- Node.js 20 及以上
|
|
17
|
+
- 一个 Command Code API key
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
### 从 npm 安装(推荐)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
dsh plugin add dsh-commandcode-quota
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
DSH 会把包内自带的 `cordis.patch.yml` 展开进你的 profile,不需要手工改补丁。
|
|
28
|
+
|
|
29
|
+
### 从本地目录安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dsh plugin add file:/path/to/dsh-commandcode-quota
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 手动链接(桌面端)
|
|
36
|
+
|
|
37
|
+
桌面端的 Electron profile 由应用托管,不会走 `dsh plugin add` 的展开流程,需要自己注册。
|
|
38
|
+
|
|
39
|
+
先把包链接进共享解析池:
|
|
40
|
+
|
|
41
|
+
```powershell
|
|
42
|
+
New-Item -ItemType Junction `
|
|
43
|
+
-Path "$env:USERPROFILE\.dsh\profiles\node_modules\dsh-commandcode-quota" `
|
|
44
|
+
-Target "C:\path\to\dsh-commandcode-quota"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
再往 `~/.dsh/profiles/<profile>/cordis.patch.yml` 里加:
|
|
48
|
+
|
|
49
|
+
```yaml
|
|
50
|
+
- insert:
|
|
51
|
+
- id: dsh-commandcode-quota
|
|
52
|
+
name: 'dsh-commandcode-quota'
|
|
53
|
+
config:
|
|
54
|
+
apiKeyEnv: COMMANDCODE_API_KEY
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> 链接名必须和包名完全一致,否则宿主端解析不到这个 import。
|
|
58
|
+
|
|
59
|
+
安装或改动插件后,重载插件树(插件页的「刷新」,或重启客户端)才生效。
|
|
60
|
+
|
|
61
|
+
## 配置
|
|
62
|
+
|
|
63
|
+
| 配置项 | 默认值 | 说明 |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `apiKeyEnv` | `COMMANDCODE_API_KEY` | 通过 DSH 凭据服务解析的凭据条目名 |
|
|
66
|
+
| `fallbackEnv` | 无 | 可选的备用条目,仅在首选缺失时使用 |
|
|
67
|
+
| `baseURL` | `https://api.commandcode.ai` | Command Code API 地址 |
|
|
68
|
+
| `timeoutMs` | `30000` | 单次请求超时(毫秒) |
|
|
69
|
+
|
|
70
|
+
凭据写在 `~/.dsh/.credentials.yaml`,或在 DSH 设置 → 凭据里添加。**不要提交到仓库。**
|
|
71
|
+
|
|
72
|
+
## 工作原理
|
|
73
|
+
|
|
74
|
+
包分宿主端和客户端两半:
|
|
75
|
+
|
|
76
|
+
- **宿主端**(`src/index.js`)通过 DSH 凭据服务解析 key,注册一个只读 HTTP 端点,并发请求 Command Code API 后聚合成一个响应。key 每次请求现读,绝不序列化给客户端。
|
|
77
|
+
- **客户端**(`src/client.js`)往输入框的 dock 槽位注册状态栏,轮询宿主端点,并全部使用 DSH 主题 token 渲染,自动适配深色/浅色主题。
|
|
78
|
+
|
|
79
|
+
数据来自四个 Command Code 接口,均带 `Authorization: Bearer <key>`:
|
|
80
|
+
|
|
81
|
+
| 接口 | 用途 |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `GET /alpha/billing/credits` | 余额,以及 5 小时 / 每周限额 |
|
|
84
|
+
| `GET /alpha/usage/summary` | 消耗、Tokens、成功率 |
|
|
85
|
+
| `GET /alpha/billing/subscriptions` | 订阅状态与周期起止 |
|
|
86
|
+
| `GET /alpha/whoami` | 账户信息 |
|
|
87
|
+
|
|
88
|
+
每月窗口是合成值:已用取用量汇总,总额为已用加剩余额度,重置时间取订阅周期末。
|
|
89
|
+
|
|
90
|
+
## 失败时的行为
|
|
91
|
+
|
|
92
|
+
- 四个请求并发发出,总耗时等于最慢的一个,而不是四者之和。
|
|
93
|
+
- 连接级失败重试一次;主动超时不重试。
|
|
94
|
+
- 请求失败时回退到上次成功的值(进程内保留 6 小时),并标记为陈旧数据。
|
|
95
|
+
- HTTP 401 不会被缓存掩盖——它意味着凭据本身有问题,必须让用户看到。
|
|
96
|
+
|
|
97
|
+
## 开发
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm test # 宿主端与客户端单元测试;不联网、不依赖运行中的 DSH
|
|
101
|
+
node --check src/index.js # 宿主端语法检查
|
|
102
|
+
node --check src/client.js # 客户端语法检查
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
测试对凭据服务、Web 服务器、`fetch` 和 React 都使用了替身,因此可离线运行,也不会碰到真实的 DSH 实例。
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# dsh-commandcode-quota 补丁层:向 profile 注册 Command Code 额度看板。
|
|
2
|
+
# 注册 ID 与包名一致;用 `dsh plugin add` 安装时本层会被展开到 profile。
|
|
3
|
+
#
|
|
4
|
+
# 默认从凭据条目 COMMANDCODE_API_KEY 读取 key。要换条目名、加回退条目或改用
|
|
5
|
+
# 其它地址,在你自己的 profile 补丁里按同样结构覆盖:
|
|
6
|
+
#
|
|
7
|
+
# - id: dsh-commandcode-quota
|
|
8
|
+
# name: 'dsh-commandcode-quota'
|
|
9
|
+
# config:
|
|
10
|
+
# apiKeyEnv: MY_COMMANDCODE_KEY
|
|
11
|
+
# fallbackEnv: MY_BACKUP_KEY # 可选:首选缺失时回退
|
|
12
|
+
# baseURL: https://api.commandcode.ai
|
|
13
|
+
#
|
|
14
|
+
# 凭据写在 ~/.dsh/.credentials.yaml,或在 DSH 设置 → 凭据 里添加。
|
|
15
|
+
# 改完需要重载插件树(插件页「刷新」或重启客户端)才生效。
|
|
16
|
+
- insert:
|
|
17
|
+
- id: dsh-commandcode-quota
|
|
18
|
+
name: 'dsh-commandcode-quota'
|
|
19
|
+
config:
|
|
20
|
+
apiKeyEnv: COMMANDCODE_API_KEY
|
|
21
|
+
baseURL: https://api.commandcode.ai
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-commandcode-quota",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Command Code balance and quota panel for DeepSeek Harness: a status row under the composer showing balance and the 5-hour, weekly and monthly windows.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"dsh",
|
|
9
|
+
"dsh-plugin",
|
|
10
|
+
"deepseek-harness",
|
|
11
|
+
"command-code",
|
|
12
|
+
"commandcode",
|
|
13
|
+
"balance",
|
|
14
|
+
"usage",
|
|
15
|
+
"quota",
|
|
16
|
+
"status-bar"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"src/",
|
|
20
|
+
"locale/",
|
|
21
|
+
"test/",
|
|
22
|
+
"cordis.patch.yml",
|
|
23
|
+
"README.md",
|
|
24
|
+
"README.zh.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"main": "src/index.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./src/index.js",
|
|
33
|
+
"./client": "./src/client.js",
|
|
34
|
+
"./locale/*": "./locale/*",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"test": "node test/host.test.cjs && node test/client.test.cjs"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/fuqiancheng/dsh-commandcode-quota.git"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/fuqiancheng/dsh-commandcode-quota#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/fuqiancheng/dsh-commandcode-quota/issues"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@deepseek-ai/dsh-credentials": "*"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"@deepseek-ai/dsh-credentials": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"dsh": {
|
|
60
|
+
"bundle": {
|
|
61
|
+
"patch": "./cordis.patch.yml"
|
|
62
|
+
},
|
|
63
|
+
"client": {
|
|
64
|
+
"inject": [
|
|
65
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
66
|
+
"@deepseek-ai/dsh-client-ui-slots",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
68
|
+
],
|
|
69
|
+
"platform": "web"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|