dsh-deepseek-balance-widget 1.2.0 → 1.2.3
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 +4 -22
- package/README_EN.md +4 -22
- package/lib/index.js +34 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
## 功能
|
|
10
10
|
|
|
11
|
+

|
|
12
|
+
|
|
11
13
|
- 侧边栏常驻按钮:`余额`、`今日消费`、`今日Token` 三个数值,30 秒自动刷新
|
|
12
14
|
- 点击弹出详情卡片:
|
|
13
15
|
- 余额(`$`,来自 `api.deepseek.com/user/balance`)
|
|
@@ -43,36 +45,16 @@
|
|
|
43
45
|
|
|
44
46
|
## 安装
|
|
45
47
|
|
|
46
|
-
插件已发布到 npm,包名 **`dsh-deepseek-balance-widget
|
|
48
|
+
插件已发布到 npm,包名 **`dsh-deepseek-balance-widget`**。一条命令安装:
|
|
47
49
|
|
|
48
50
|
```bash
|
|
49
51
|
dsh plugin --profile web add dsh-deepseek-balance-widget
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
安装成功后 dsh 会**自动把该包注册进 `dsh.profile.bundles
|
|
54
|
+
安装成功后 dsh 会**自动把该包注册进 `dsh.profile.bundles`**,**无需手动改任何配置文件**。本包**没有构建脚本**,pnpm 不会拦截(无需在 `pnpm-workspace.yaml` 的 `allowBuilds` 里批准)。
|
|
53
55
|
|
|
54
56
|
完成后**重启 `dsh web`**,侧边栏出现余额按钮即可。
|
|
55
57
|
|
|
56
|
-
> 旧版 dsh(不含自动注册机制)或绕过 `dsh plugin` 直接 `pnpm/npm install` 时,才需要手动在 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` 末尾加入 `"dsh-deepseek-balance-widget"`。
|
|
57
|
-
|
|
58
|
-
### 🤖 让 AI 帮你装
|
|
59
|
-
|
|
60
|
-
2026年了,你有 Agent,让它自己装。打开 DeepSeek Harness,把下面这句丢给它:
|
|
61
|
-
|
|
62
|
-
> 帮我安装 dsh-deepseek-balance-widget 插件:npm 包名 dsh-deepseek-balance-widget
|
|
63
|
-
|
|
64
|
-
AI 会自动执行 `dsh plugin --profile web add dsh-deepseek-balance-widget`(从 npm 安装,无需 git)→ 验证 bundles 注册 → 提醒你重启。
|
|
65
|
-
|
|
66
|
-
### 备选:GitHub 直装
|
|
67
|
-
|
|
68
|
-
如果暂时连不上 npm registry,也可以从 GitHub 安装:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
dsh plugin --profile web add github:crazy-L118/dsh-deepseek-balance-widget
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
(此方式需要电脑装了 git。)
|
|
75
|
-
|
|
76
58
|
## 配置凭据(关键一步)
|
|
77
59
|
|
|
78
60
|
编辑 `~/.dsh/.credentials.yaml`:
|
package/README_EN.md
CHANGED
|
@@ -8,6 +8,8 @@ A small plugin that shows your DeepSeek balance in the DeepSeek Harness (dsh) we
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
+

|
|
12
|
+
|
|
11
13
|
- Persistent sidebar widget: `余额` (balance), `今日消费` (today spend), `今日Token` (today tokens), auto-refresh every 30 s
|
|
12
14
|
- Click for a detail card:
|
|
13
15
|
- Balance (`$`, from `api.deepseek.com/user/balance`)
|
|
@@ -43,36 +45,16 @@ Browser (dsh web frontend) ──GET /deepseek-balance──▶ dsh host (your
|
|
|
43
45
|
|
|
44
46
|
## Install
|
|
45
47
|
|
|
46
|
-
The plugin is published to npm as **`dsh-deepseek-balance-widget`**. Install with a single command
|
|
48
|
+
The plugin is published to npm as **`dsh-deepseek-balance-widget`**. Install with a single command:
|
|
47
49
|
|
|
48
50
|
```bash
|
|
49
51
|
dsh plugin --profile web add dsh-deepseek-balance-widget
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
After a successful `dsh plugin` install, dsh **automatically registers the package in `dsh.profile.bundles
|
|
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).
|
|
53
55
|
|
|
54
56
|
Then **restart `dsh web`** — the balance button appears in the sidebar.
|
|
55
57
|
|
|
56
|
-
> Only for older dsh versions (without the auto-registration mechanism) or when bypassing `dsh plugin` with raw `pnpm/npm install`: manually append `"dsh-deepseek-balance-widget"` to the `dsh.profile.bundles` array in `~/.dsh/profiles/web/package.json`.
|
|
57
|
-
|
|
58
|
-
### 🤖 Let the AI install it
|
|
59
|
-
|
|
60
|
-
You have an Agent — let it install itself. Open DeepSeek Harness and drop this sentence in:
|
|
61
|
-
|
|
62
|
-
> Install the dsh-deepseek-balance-widget plugin for me (npm package: dsh-deepseek-balance-widget)
|
|
63
|
-
|
|
64
|
-
The agent will run `dsh plugin --profile web add dsh-deepseek-balance-widget` (from npm, no git needed), verify the bundle registration, then tell you to restart.
|
|
65
|
-
|
|
66
|
-
### Alternative: GitHub install
|
|
67
|
-
|
|
68
|
-
If the npm registry is unreachable, install straight from GitHub instead:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
dsh plugin --profile web add github:crazy-L118/dsh-deepseek-balance-widget
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
(Note: this requires git on the machine.)
|
|
75
|
-
|
|
76
58
|
## Configure credentials (important)
|
|
77
59
|
|
|
78
60
|
Edit `~/.dsh/.credentials.yaml`:
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -101,17 +101,43 @@ async function queryNpmVersion() {
|
|
|
101
101
|
return { ok: true, local: LOCAL_VERSION, latest, updateAvailable };
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/** @returns {Promise<boolean>} whether the given path exists. */
|
|
105
|
+
async function fileExists(path) {
|
|
106
|
+
try {
|
|
107
|
+
await stat(path);
|
|
108
|
+
return true;
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Detect the package manager used by UPDATE_CWD.
|
|
116
|
+
* @returns {Promise<"pnpm" | "npm">}
|
|
117
|
+
*/
|
|
118
|
+
async function detectPackageManager() {
|
|
119
|
+
const pnpmLock = resolve(UPDATE_CWD, "pnpm-lock.yaml");
|
|
120
|
+
const pnpmLockYml = resolve(UPDATE_CWD, "pnpm-lock.yml");
|
|
121
|
+
if (await fileExists(pnpmLock) || await fileExists(pnpmLockYml)) return "pnpm";
|
|
122
|
+
return "npm";
|
|
123
|
+
}
|
|
124
|
+
|
|
104
125
|
/**
|
|
105
|
-
* Run
|
|
126
|
+
* Run the package-manager update command for this package in the discovered project root.
|
|
127
|
+
* Uses shell mode on Windows so that .cmd scripts (npm.cmd / pnpm.cmd) can actually spawn.
|
|
106
128
|
* @returns {Promise<{ok:boolean, output:string, error?:string}>}
|
|
107
129
|
*/
|
|
108
|
-
async function
|
|
109
|
-
const
|
|
110
|
-
const
|
|
130
|
+
async function runPackageUpdate() {
|
|
131
|
+
const pm = await detectPackageManager();
|
|
132
|
+
const isWin = process.platform === "win32";
|
|
133
|
+
const cmd = isWin ? (pm === "pnpm" ? "pnpm.cmd" : "npm.cmd") : pm;
|
|
134
|
+
const args = pm === "pnpm"
|
|
135
|
+
? ["add", "dsh-deepseek-balance-widget@latest"]
|
|
136
|
+
: ["install", "dsh-deepseek-balance-widget@latest"];
|
|
111
137
|
return new Promise((resolve) => {
|
|
112
138
|
const child = spawn(cmd, args, {
|
|
113
139
|
cwd: UPDATE_CWD,
|
|
114
|
-
shell:
|
|
140
|
+
shell: isWin,
|
|
115
141
|
env: { ...process.env, NPM_CONFIG_FUND: "false", NPM_CONFIG_AUDIT: "false" }
|
|
116
142
|
});
|
|
117
143
|
let stdout = "";
|
|
@@ -126,7 +152,7 @@ async function runNpmUpdate() {
|
|
|
126
152
|
if (code === 0) {
|
|
127
153
|
resolve({ ok: true, output: output.slice(-800) });
|
|
128
154
|
} else {
|
|
129
|
-
resolve({ ok: false, output, error:
|
|
155
|
+
resolve({ ok: false, output, error: `${pm} ${args.join(" ")} exited with code ${code}` });
|
|
130
156
|
}
|
|
131
157
|
});
|
|
132
158
|
});
|
|
@@ -533,7 +559,7 @@ function apply(ctx) {
|
|
|
533
559
|
res.end(JSON.stringify({ ok: true, noOp: true, local: before.local, latest: before.latest, message: "已是最新版本" }));
|
|
534
560
|
return;
|
|
535
561
|
}
|
|
536
|
-
const result = await
|
|
562
|
+
const result = await runPackageUpdate();
|
|
537
563
|
if (result.ok) {
|
|
538
564
|
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
539
565
|
res.end(JSON.stringify({ ok: true, message: "更新成功,请彻底重启 dsh 以加载新版本", output: result.output }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deepseek-balance-widget",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "DeepSeek API balance widget for the dsh web sidebar: a live, auto-refreshing balance pill (balance / today spend / today tokens) with a detail popover (cumulative spend, monthly usage, request count). Every user sees only their own balance — keys are resolved per-machine from the local credential seam, never hardcoded.",
|
|
6
6
|
"keywords": [
|