dsh-deepseek-balance-widget 1.2.2 → 1.2.4
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/lib/client.js +10 -2
- package/lib/index.js +34 -8
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -14,6 +14,8 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
const UPDATE_ENDPOINT = "/deepseek-balance-update";
|
|
15
15
|
/** Auto-refresh cadence, milliseconds. */
|
|
16
16
|
const REFRESH_MS = 30000;
|
|
17
|
+
/** How long the "update succeeded, restart dsh" message stays visible, milliseconds. */
|
|
18
|
+
const UPDATE_SUCCESS_MS = 5000;
|
|
17
19
|
|
|
18
20
|
/** Inline icon (matches the shell's 16px nav-icon look). */
|
|
19
21
|
const ICON = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 4L8 8.5 11.5 4M8 8.5v4M5.5 9.5h5M5.5 11.5h5"/></svg>';
|
|
@@ -210,8 +212,9 @@ window.__ModuleLoader__.load({
|
|
|
210
212
|
if (result.ok) {
|
|
211
213
|
btn.textContent = "成功,请重启 dsh";
|
|
212
214
|
btn.disabled = true;
|
|
213
|
-
//
|
|
214
|
-
|
|
215
|
+
// Keep the success message visible for a while before reverting to version info.
|
|
216
|
+
updateSuccessUntil = Date.now() + UPDATE_SUCCESS_MS;
|
|
217
|
+
setTimeout(() => checkVersion(), UPDATE_SUCCESS_MS);
|
|
215
218
|
} else {
|
|
216
219
|
btn.textContent = "更新失败";
|
|
217
220
|
btn.title = String(result.error || "更新失败") + (result.output ? "\n" + result.output.slice(-200) : "");
|
|
@@ -398,6 +401,9 @@ window.__ModuleLoader__.load({
|
|
|
398
401
|
|
|
399
402
|
/** Build the npm version snippet shown in the footer (always a clickable button). */
|
|
400
403
|
function versionHtmlOf(versionEnvelope) {
|
|
404
|
+
if (Date.now() < updateSuccessUntil) {
|
|
405
|
+
return '<span class="dshBalanceVersion" data-state="ok">成功,请重启 dsh</span>';
|
|
406
|
+
}
|
|
401
407
|
if (!versionEnvelope) {
|
|
402
408
|
return '<span class="dshBalanceVersion" data-state="ok"><button class="dshBalanceVersionBtn" type="button" data-update-cmd>检查更新</button></span>';
|
|
403
409
|
}
|
|
@@ -469,6 +475,7 @@ window.__ModuleLoader__.load({
|
|
|
469
475
|
let lastUpdated = null;
|
|
470
476
|
let timer = null;
|
|
471
477
|
let versionTimer = null;
|
|
478
|
+
let updateSuccessUntil = 0;
|
|
472
479
|
|
|
473
480
|
/** One refresh cycle: fetch balance + usage, update entry stats and popover. */
|
|
474
481
|
async function refresh(manual) {
|
|
@@ -562,6 +569,7 @@ window.__ModuleLoader__.load({
|
|
|
562
569
|
document.removeEventListener("mousedown", outsideHandler);
|
|
563
570
|
outsideHandler = null;
|
|
564
571
|
}
|
|
572
|
+
updateSuccessUntil = 0;
|
|
565
573
|
if (popRef !== null) popRef.remove();
|
|
566
574
|
entry.remove();
|
|
567
575
|
entryRef = null;
|
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.4",
|
|
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": [
|