feat: OpenCode Go 用量插件 v1.0.0
DSH 左侧栏底部常驻卡片,显示 OpenCode Go 套餐的三条配额用量: - 滚动窗口 / 本周 / 本月 的已用百分比 + 进度条 - 每条配额的重置倒计时(X小时Y分后重置) - 标题旁显示本月重置日期 - 百分比按档位变色(<70% 绿 / 70-89% 橙 / ≥90% 红) - SVG 圆形刷新按钮,加载时旋转;60 秒自动刷新 另有 opencode_usage 工具(供 agent 查询)与 GET /plugin/opencode-usage 接口。 服务端直连 opencode.ai/zen/go/v1/usage,API Key 不经过浏览器。 纯 JS 实现,无需构建。
This commit is contained in:
commit
2994a20bb0
7 files changed
+767
No files matched your search
@@ -0,0 +1,95 @@
|
||||
# dsh-opencode-usage
|
||||
|
||||
在 DSH 左侧栏看 OpenCode Go 套餐用量:滚动窗口 / 本周 / 本月 三条配额的已用百分比与重置倒计时。
|
||||
|
||||
服务端直连 `https://opencode.ai/zen/go/v1/usage`,API Key 不经过浏览器。
|
||||
|
||||

|
||||
|
||||
## 功能
|
||||
|
||||
| 能力 | 说明 |
|
||||
|---|---|
|
||||
| **左侧栏卡片** | 三条配额的百分比、进度条、重置倒计时;标题旁显示本月重置日 |
|
||||
| **刷新按钮** | SVG 圆形箭头,加载时旋转;60 秒自动刷新 |
|
||||
| **颜色分档** | `<70%` 绿 / `70–89%` 橙 / `≥90%` 红 |
|
||||
| **`opencode_usage` 工具** | 让 agent 也能查(「opencode 用了多少」)|
|
||||
| **`GET /plugin/opencode-usage`** | JSON 接口,15 秒缓存 |
|
||||
|
||||
返回结构:
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"fetchedAt": 1794204531,
|
||||
"source": "config.apiKey",
|
||||
"buckets": [
|
||||
{ "key": "rolling", "label": "滚动窗口", "status": "ok", "percent": 2,
|
||||
"resetsAt": "2026-11-09T11:01:12.000Z", "resetInSeconds": 17539 }
|
||||
],
|
||||
"cached": false
|
||||
}
|
||||
```
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
cd ~/.dsh/profiles/<你的 profile>
|
||||
pnpm add file:/path/to/dsh-opencode-usage
|
||||
```
|
||||
|
||||
然后在 profile 的 `dsh.profile.bundles` 里加上 `dsh-opencode-usage`,重启 DSH。
|
||||
|
||||
## 配置凭证
|
||||
|
||||
三选一,按优先级:
|
||||
|
||||
| 顺序 | 来源 |
|
||||
|---|---|
|
||||
| 1 | `config.apiKey` |
|
||||
| 2 | `config.envFile` 指向的 `.env` 里的 `OPENCODE_API_KEY` |
|
||||
| 3 | 进程环境变量 `OPENCODE_API_KEY` |
|
||||
|
||||
写在**你自己 profile 的** `cordis.patch.yml`(不要改本包):
|
||||
|
||||
```yaml
|
||||
- id: opencode-usage
|
||||
config:
|
||||
apiKey: oc_sk_xxx
|
||||
```
|
||||
|
||||
或者从 `.env` 文件读:
|
||||
|
||||
```yaml
|
||||
- id: opencode-usage
|
||||
config:
|
||||
envFile: /path/to/.env
|
||||
```
|
||||
|
||||
### 其他可选配置
|
||||
|
||||
```yaml
|
||||
- id: opencode-usage
|
||||
config:
|
||||
baseUrl: https://opencode.ai/zen/go/v1 # 上游地址
|
||||
cacheSeconds: 15 # 缓存秒数
|
||||
timeoutMs: 12000 # 单次请求超时
|
||||
envKey: OPENCODE_API_KEY # 变量名
|
||||
```
|
||||
|
||||
## 实现要点
|
||||
|
||||
- **纯 JS,无需构建**:客户端通过 `window.__ModuleLoader__.load()` 注册,服务端是标准 ESM `apply(ctx, config)`。
|
||||
- **凭证不落浏览器**:前端只拿到三条百分比,Bearer 只在服务端拼。
|
||||
- **`defineTool` 动态解析**:插件装在 profile 的 `local/` 下,模块解析链上找不到 `@deepseek-ai/dsh-tools`,
|
||||
所以用 `realpath(argv[1])` 建 `createRequire`,从 DSH 自己的依赖树里取。
|
||||
- **value schema DSL 有约束**:不吃 `required: [...]` 数组、不吃 `type: ["number","null"]` 这类 union、
|
||||
`additionalProperties` 必须显式。所以未知值用哨兵(`-1` / `""`)。
|
||||
|
||||
## 隐私
|
||||
|
||||
本包**不含任何凭证、个人路径或主机名**。凭证只在你自己的 profile 配置或环境变量里。
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
Reference in new issue
Block a user