dsh-deepseek-balance-widget 1.2.4 → 2.1.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/README.md CHANGED
@@ -2,84 +2,53 @@
2
2
 
3
3
  [English](README_EN.md) | 中文
4
4
 
5
- DeepSeek Harness(dsh)Web 侧边栏显示 DeepSeek 余额的小插件:实时展示**余额 / 今日消费 / 今日Token**,点击弹出详情(累计消费、本月消耗、API 请求次数、Tokens),每 30 秒自动刷新。
6
-
7
- > 本插件完全运行在你自己的机器上:余额和用量由 **dsh 宿主端**用**你本机的凭据**(`~/.dsh/.credentials.yaml` 或环境变量)向 DeepSeek 官方接口实时查询。代码中**不内置任何 API Key / Token / 个人数据**,所以**每个人看到的都是自己的余额**,互不可见。
5
+ dsh Web 侧边栏显示 AI 余额的多平台插件:内置 **DeepSeek**,可添加 **MiMo(小米)** 等平台,每 30 秒自动刷新。
8
6
 
9
7
  ## 功能
10
8
 
11
- ![DeepSeek 余额侧边栏展示](assets/screenshot.png)
12
-
13
- - 侧边栏常驻按钮:`余额`、`今日消费`、`今日Token` 三个数值,30 秒自动刷新
14
- - 点击弹出详情卡片:
15
- - 余额(`$`,来自 `api.deepseek.com/user/balance`)
16
- - 累计消费(全部时间,来自平台用量接口按月累加)
17
- - 今日消费 / 今日Token(平台实时接口,按 GMT+8 当日统计)
18
- - 本月消耗:本月消费、API 请求次数、Tokens
19
- - 未配置平台 Token 时,余额照常显示,用量区域显示中性提示(不展示任何人的历史快照)
20
- - 深色主题,跟随 dsh 侧边栏样式;自动适配官方皮肤与 Maid-atelier 等第三方皮肤
21
-
22
- ## 工作原理(隐私说明)
23
-
24
- ```
25
- 浏览器 (dsh web 前端) ──GET /deepseek-balance──▶ dsh 宿主端(你自己的机器)
26
-
27
- ├─ 读取本机 ~/.dsh/.credentials.yaml 的
28
- │ DEEPSEEK_API_KEY / DEEPSEEK_PLATFORM_TOKEN
29
- │ (或环境变量),绝不硬编码
30
-
31
- api.deepseek.com / platform.deepseek.com
32
-
33
- ◀── 返回「你这个账号」的余额与用量
34
- ```
35
-
36
- - 余额数据来自 DeepSeek 官方余额接口 `GET https://api.deepseek.com/user/balance`
37
- - 用量统计来自平台接口(需要 `userToken`),见下方配置说明
38
- - 请求全部由宿主端发起(服务端到服务端),浏览器端不接触任何密钥
39
-
40
- ## 环境要求
9
+ ![AI 余额侧边栏展示](assets/screenshot.png)
41
10
 
42
- - DeepSeek Harness(`dsh`)已安装并可用 `dsh web`
43
- - Node.js 18(全局 `fetch`)
44
- - pnpm(`dsh plugin` 内部转发给 pnpm)
11
+ - 侧边栏实时显示余额 / 今日消费 / 今日 Token,30 秒自动刷新,并随当前平台切换
12
+ - 弹窗顶部 **Tab** 切换平台(DeepSeek / MiMo…),侧边栏数值同步更新
13
+ - 弹窗右上角「**+ 添加**」:随时加入 MiMo 等其他 AI 平台
14
+ - 详情字段:余额、累计消费、今日消费、今日 Token、本月消耗(本月消费 / Tokens)
15
+ - 「**AI 帮我配置**」:凭证抓取与写入全交给智能体,无需手动翻 Cookies
16
+ - 弹窗底部显示版本号,有新版时一键自动更新
45
17
 
46
18
  ## 安装
47
19
 
48
- 插件已发布到 npm,包名 **`dsh-deepseek-balance-widget`**。一条命令安装:
20
+ 需要:已安装 dsh(可用 `dsh web`)。
49
21
 
50
22
  ```bash
51
23
  dsh plugin --profile web add dsh-deepseek-balance-widget
52
24
  ```
53
25
 
54
- 安装成功后 dsh 会**自动把该包注册进 `dsh.profile.bundles`**,**无需手动改任何配置文件**。本包**没有构建脚本**,pnpm 不会拦截(无需在 `pnpm-workspace.yaml` `allowBuilds` 里批准)。
26
+ npm 拉取安装,dsh 自动注册到 `dsh.profile.bundles`,完成后**重启 `dsh web`** 即可。
55
27
 
56
- 完成后**重启 `dsh web`**,侧边栏出现余额按钮即可。
28
+ 也可以直接对 AI 说:*帮我用 npm 安装 dsh-deepseek-balance-widget 插件。*
57
29
 
58
- ## 配置凭据(关键一步)
30
+ ## 配置
59
31
 
60
- 编辑 `~/.dsh/.credentials.yaml`:
32
+ 插件首次使用会自动创建 DeepSeek 条目,读取你本机的 `DEEPSEEK_API_KEY`。其他平台通过弹窗「+ 添加」加入。两种方式任选:
61
33
 
62
- ```yaml
63
- DEEPSEEK_API_KEY: sk-xxxxxxxxxxxxxxxx
64
- DEEPSEEK_PLATFORM_TOKEN: xxxxxxxxxxxxxxxx # 可选,见下
65
- ```
66
-
67
- > 如果你本来就在用 DeepSeek API(dsh 里已经能跑对话),`DEEPSEEK_API_KEY` 通常已经配置好了,余额部分**开箱即用**。
34
+ **方式一:弹窗内添加**
35
+ 1. 打开弹窗,点右上角「+ 添加」。
36
+ 2. 选择平台,点「AI 帮我配置」,把提示语发给智能体。
37
+ 3. AI 一步步引导你获取凭证,自动写入本机配置。
68
38
 
69
- | 凭据 | 必填 | 用途 | 获取方式 |
70
- |---|---|---|---|
71
- | `DEEPSEEK_API_KEY` | ✅ | 余额 | [platform.deepseek.com](https://platform.deepseek.com) → API Keys |
72
- | `DEEPSEEK_PLATFORM_TOKEN` | ⭕ 可选 | 用量统计(累计/本月/今日消费、请求次数、Tokens) | 登录 [platform.deepseek.com](https://platform.deepseek.com) → 按 `F12` → `Application` → `Cookies` → 复制 `userToken` 的值 |
39
+ **方式二:直接对 AI 说**
73
40
 
74
- 未配置 `DEEPSEEK_PLATFORM_TOKEN` 时:余额正常显示,今日消费 / 今日Token 显示 `—`,用量区块显示配置提示。
41
+ > 帮我配置 dsh-deepseek-balance-widget。
75
42
 
76
- > ⚠️ `userToken` 等同于你的平台登录会话,请勿提交到 Git 或分享给他人。
43
+ AI 会接管全部:问 API Key / 引导获取平台 Cookie → 写入本机 → 提醒重启 `dsh web`。
77
44
 
78
- ## 使用
45
+ | 平台 | 凭据 | 备注 |
46
+ |---|---|---|
47
+ | DeepSeek | `DEEPSEEK_API_KEY` | 必填,余额 |
48
+ | DeepSeek 用量 | `DEEPSEEK_PLATFORM_TOKEN` | 可选,统计累计消费 / 本月 / 今日 |
49
+ | MiMo(小米) | 登录 Cookie | AI 引导获取 |
79
50
 
80
- 1. 重启 `dsh web`。
81
- 2. 左侧边栏(或底部设置栏旁)会出现余额按钮,显示 `余额 / 今日消费 / 今日Token`。
82
- 3. 点击按钮查看详情卡片,卡片右下角有「刷新」按钮,或等待 30 秒自动刷新。
51
+ 凭据保存在你本机的 `~/.dsh/ai-balances.json`,不随插件分发。
83
52
 
84
53
  ## 卸载
85
54
 
@@ -87,26 +56,8 @@ DEEPSEEK_PLATFORM_TOKEN: xxxxxxxxxxxxxxxx # 可选,见下
87
56
  dsh plugin --profile web rm dsh-deepseek-balance-widget
88
57
  ```
89
58
 
90
- dsh 会自动从 `dsh.profile.bundles` 移除该层;若还残留(旧版 dsh),手动删除 `~/.dsh/profiles/web/package.json` 中 `dependencies` 与 `dsh.profile.bundles` 里的同名条目。
91
-
92
- ## 常见问题
93
-
94
- - **侧边栏没出现按钮?** 确认 `dsh web` 已重启;不同皮肤下按钮会出现在侧边栏或底部工具栏,插件会自动寻找合适位置。
95
- - **余额显示「失败」?** 检查 `DEEPSEEK_API_KEY` 是否有效、机器能否访问 `api.deepseek.com`;在弹窗的错误行能看到原因。
96
- - **用量一直显示提示?** `DEEPSEEK_PLATFORM_TOKEN` 未配置或已过期(平台会话有时效,过期后重新登录复制新值)。
97
-
98
- ## 开发
99
-
100
- - 宿主端:`lib/index.js`(cordis 插件,注册 `/deepseek-balance`、`/deepseek-usage` 两个路由)
101
- - 客户端:`lib/client.js`(注入 web 前端,挂载侧边栏小组件)
102
- - 修改后重新执行安装命令并重启 `dsh web` 生效(或本地调试时用 `dsh plugin --profile web add "file:<仓库路径>"`)
103
-
104
- ## 免责声明
105
-
106
- - 本项目与 DeepSeek 官方无任何关联,非官方产品。
107
- - 用量统计使用 DeepSeek 平台的内部接口,可能随平台改版而失效,属尽力而为。
108
- - 请遵守 [DeepSeek 平台服务条款](https://platform.deepseek.com/terms) 与 API 使用政策。
59
+ 或者直接对 AI 说:*帮我用 npm 卸载 dsh-deepseek-balance-widget 插件。*
109
60
 
110
61
  ## License
111
62
 
112
- [MIT](LICENSE)
63
+ [MIT](LICENSE)
package/README_EN.md CHANGED
@@ -2,84 +2,53 @@
2
2
 
3
3
  English | [中文](README.md)
4
4
 
5
- A small plugin that shows your DeepSeek balance in the DeepSeek Harness (dsh) web sidebar: live **balance / today spend / today tokens**, click to open a detail card (cumulative spend, monthly usage, request count, tokens), auto-refreshed every 30 seconds.
6
-
7
- > This plugin runs entirely on your own machine: the dsh host resolves **your local credentials** (`~/.dsh/.credentials.yaml` or environment variables) and queries the official DeepSeek APIs server-side. No API key / token / personal data is bundled in the code, so **every user sees only their own balance**.
5
+ A multi-provider AI balance widget for the dsh web sidebar. **DeepSeek** is built in; add **MiMo (Xiaomi)** and others with one click. Auto-refreshes every 30 seconds.
8
6
 
9
7
  ## Features
10
8
 
11
- ![DeepSeek balance sidebar](assets/screenshot.png)
12
-
13
- - Persistent sidebar widget: `余额` (balance), `今日消费` (today spend), `今日Token` (today tokens), auto-refresh every 30 s
14
- - Click for a detail card:
15
- - Balance (`$`, from `api.deepseek.com/user/balance`)
16
- - Cumulative spend (all time, summed per month from the platform usage API)
17
- - Today spend / today tokens (platform realtime API, GMT+8 day buckets)
18
- - Current-month usage: spend, API request count, tokens
19
- - When the platform token is not configured, the balance still works and the usage area shows a neutral hint (never anyone's historical snapshot)
20
- - Dark theme matching the dsh sidebar; adapts to official skins and third-party skins like Maid-atelier
21
-
22
- ## How it works (privacy)
23
-
24
- ```
25
- Browser (dsh web frontend) ──GET /deepseek-balance──▶ dsh host (your machine)
26
-
27
- ├─ reads DEEPSEEK_API_KEY / DEEPSEEK_PLATFORM_TOKEN
28
- │ from local ~/.dsh/.credentials.yaml (or env),
29
- │ never hardcoded
30
-
31
- api.deepseek.com / platform.deepseek.com
32
-
33
- ◀── returns balance & usage of YOUR account
34
- ```
35
-
36
- - Balance comes from the official endpoint `GET https://api.deepseek.com/user/balance`
37
- - Usage stats come from the platform endpoints (requires `userToken`), see configuration below
38
- - All requests are made by the host (server-to-server); the browser never touches any secret
39
-
40
- ## Requirements
9
+ ![AI balance sidebar](assets/screenshot-en.png)
41
10
 
42
- - DeepSeek Harness (`dsh`) with `dsh web` working
43
- - Node.js 18 (global `fetch`)
44
- - pnpm (`dsh plugin` forwards to pnpm internally)
11
+ - Sidebar shows Balance / Today spend / Today tokens, auto-refresh every 30 s; values follow the selected provider
12
+ - **Tabs** in the popover switch between providers (DeepSeek / MiMo…), sidebar updates with the tab
13
+ - **"+ Add"** button: add MiMo or any other AI provider at any time
14
+ - Details: balance, cumulative spend, today spend, today tokens, monthly usage (monthly spend / tokens)
15
+ - **"AI 帮我配置"**: credentials are handled by your AI — no digging through cookies by hand
16
+ - Version shown in the popover footer; one-click auto-update when a new version is available
45
17
 
46
18
  ## Install
47
19
 
48
- The plugin is published to npm as **`dsh-deepseek-balance-widget`**. Install with a single command:
20
+ Requires: dsh installed (with `dsh web` working).
49
21
 
50
22
  ```bash
51
23
  dsh plugin --profile web add dsh-deepseek-balance-widget
52
24
  ```
53
25
 
54
- After a successful `dsh plugin` install, dsh **automatically registers the package in `dsh.profile.bundles`**, so **no manual config editing is needed**. This package has **no build script**, so pnpm does not block it (no `allowBuilds` approval needed).
26
+ Installed from npm and auto-registered by dsh. **Restart `dsh web`** and the balance button appears in the sidebar.
55
27
 
56
- Then **restart `dsh web`** the balance button appears in the sidebar.
28
+ Or just tell your AI: *Install the dsh-deepseek-balance-widget plugin for me via npm.*
57
29
 
58
- ## Configure credentials (important)
30
+ ## Configuration
59
31
 
60
- Edit `~/.dsh/.credentials.yaml`:
32
+ On first use the plugin creates a DeepSeek entry and reads your local `DEEPSEEK_API_KEY`. Other providers are added via "+ Add". Either:
61
33
 
62
- ```yaml
63
- DEEPSEEK_API_KEY: sk-xxxxxxxxxxxxxxxx
64
- DEEPSEEK_PLATFORM_TOKEN: xxxxxxxxxxxxxxxx # optional, see below
65
- ```
66
-
67
- > If you already use the DeepSeek API in dsh, `DEEPSEEK_API_KEY` is usually already configured and the balance part works out of the box.
34
+ **Option 1: Add inside the popover**
35
+ 1. Open the popover and click "+ Add".
36
+ 2. Pick a provider, then click "AI 帮我配置" and send the copied prompt to your AI.
37
+ 3. Your AI walks you through getting the credentials and writes them locally.
68
38
 
69
- | Credential | Required | Purpose | How to get it |
70
- |---|---|---|---|
71
- | `DEEPSEEK_API_KEY` | ✅ | Balance | [platform.deepseek.com](https://platform.deepseek.com) → API Keys |
72
- | `DEEPSEEK_PLATFORM_TOKEN` | ⭕ optional | Usage stats (cumulative/month/today spend, requests, tokens) | Log in to [platform.deepseek.com](https://platform.deepseek.com) → press `F12` → `Application` → `Cookies` → copy the value of `userToken` |
39
+ **Option 2: Just tell your AI**
73
40
 
74
- Without `DEEPSEEK_PLATFORM_TOKEN`, the balance still shows; today spend / tokens show `—` and the usage block shows a configuration hint.
41
+ > Configure dsh-deepseek-balance-widget for me.
75
42
 
76
- > ⚠️ `userToken` is your platform login session. Never commit it to Git or share it.
43
+ The AI takes care of everything: asks for your API key / guides you through getting the platform cookie writes the local config → reminds you to **restart `dsh web`**.
77
44
 
78
- ## Usage
45
+ | Provider | Credential | Notes |
46
+ |---|---|---|
47
+ | DeepSeek | `DEEPSEEK_API_KEY` | Required, balance |
48
+ | DeepSeek usage | `DEEPSEEK_PLATFORM_TOKEN` | Optional, cumulative / monthly / today stats |
49
+ | MiMo (Xiaomi) | Login cookie | Guided by your AI |
79
50
 
80
- 1. Restart `dsh web`.
81
- 2. A balance button appears in the left sidebar (or next to the bottom Settings row) showing `余额 / 今日消费 / 今日Token`.
82
- 3. Click it for the detail card; use the "刷新" (refresh) button or wait 30 s for auto-refresh.
51
+ Credentials are stored locally in `~/.dsh/ai-balances.json`; nothing is shipped with the plugin.
83
52
 
84
53
  ## Uninstall
85
54
 
@@ -87,26 +56,8 @@ Without `DEEPSEEK_PLATFORM_TOKEN`, the balance still shows; today spend / tokens
87
56
  dsh plugin --profile web rm dsh-deepseek-balance-widget
88
57
  ```
89
58
 
90
- dsh removes the layer from `dsh.profile.bundles` automatically; if anything remains (older dsh), delete the `dsh-deepseek-balance-widget` entries from `dependencies` and `dsh.profile.bundles` in `~/.dsh/profiles/web/package.json`.
91
-
92
- ## FAQ
93
-
94
- - **No button in the sidebar?** Make sure `dsh web` was restarted. On different skins the button appears in the sidebar or the bottom toolbar; the plugin finds a spot automatically.
95
- - **Balance shows "失败" (failed)?** Check that `DEEPSEEK_API_KEY` is valid and your machine can reach `api.deepseek.com`; the error line in the popover explains why.
96
- - **Usage always shows the hint?** `DEEPSEEK_PLATFORM_TOKEN` is missing or expired (platform sessions expire; log in again and copy a fresh `userToken`).
97
-
98
- ## Development
99
-
100
- - Host half: `lib/index.js` (cordis plugin registering `/deepseek-balance` and `/deepseek-usage`)
101
- - Client half: `lib/client.js` (injected into the web frontend, mounts the sidebar widget)
102
- - After changes, re-run the install command and restart `dsh web` (or use `dsh plugin --profile web add "file:<repo path>"` for local iteration)
103
-
104
- ## Disclaimer
105
-
106
- - Not affiliated with or endorsed by DeepSeek.
107
- - Usage stats rely on DeepSeek platform internal endpoints that may change at any time; best effort only.
108
- - Please follow the [DeepSeek Platform Terms](https://platform.deepseek.com/terms) and API usage policy.
59
+ Or just tell your AI: *Uninstall the dsh-deepseek-balance-widget plugin for me via npm.*
109
60
 
110
61
  ## License
111
62
 
112
- [MIT](LICENSE)
63
+ [MIT](LICENSE)