dsh-deepseek-balance-widget 2.3.3 → 2.3.5

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
@@ -20,12 +20,12 @@
20
20
  需要:已安装 dsh(可用 `dsh web`)。
21
21
 
22
22
  ```bash
23
- dsh plugin --profile web add dsh-deepseek-balance-widget@2.3.2
23
+ dsh plugin --profile web add dsh-deepseek-balance-widget@latest
24
24
  ```
25
25
 
26
26
  从 npm 拉取安装,dsh 自动注册到 `dsh.profile.bundles`,完成后**重启 `dsh web`** 即可。
27
27
 
28
- > 务必带版本号 `@2.3.2`。不带版本号的 `add` 会按 npm `latest` tag 安装,该 tag 可能被旧版本抢回去,导致装到老版本。
28
+ > 如果 `npm view` / 弹窗显示你装到了旧版本,请参考下方「更新」章节强制升到最新版。旧版本已被标记为 deprecated,安装时会弹出升级提示。
29
29
 
30
30
  也可以直接对 AI 说:
31
31
 
@@ -51,11 +51,11 @@ AI 会接管全部:问 API Key / 引导获取平台 Cookie → 写入本机
51
51
 
52
52
  ## 更新
53
53
 
54
- 最新稳定版为 **`2.3.2`**。无论你当前是哪个旧版本,都推荐升级到它。
54
+ 无论你当前是哪个旧版本,都推荐升级到 npm 上的最新稳定版。
55
55
 
56
56
  ### 方式一:弹窗一键更新(推荐,已装用户)
57
57
 
58
- 1. 打开余额弹窗,底部会显示版本号;有新版本时显示 `vX → v2.3.2 更新`。
58
+ 1. 打开余额弹窗,底部会显示版本号;有新版本时显示 `vX → vY 更新`(`vY` 为 npm 上 semver 最高的版本)。
59
59
  2. 点击「**检查更新**」,插件会自动从 npm 拉取并安装最高版本。
60
60
  3. 安装完成后**必须彻底重启 `dsh web`**(关掉 `dsh web` 进程 / 退出桌面端再重开,**仅刷新浏览器页面无效**)才能加载新版本。
61
61
 
@@ -64,21 +64,23 @@ AI 会接管全部:问 API Key / 引导获取平台 Cookie → 写入本机
64
64
  ### 方式二:命令行强制更新(最稳妥,适合卡住或装不上的情况)
65
65
 
66
66
  ```bash
67
- dsh plugin --profile web add dsh-deepseek-balance-widget@2.3.2
67
+ dsh plugin --profile web add dsh-deepseek-balance-widget@latest
68
68
  ```
69
69
 
70
- 带版本号可绕过缓存 / 镜像源不同步 / `latest` 被抢低等问题,一步到位。
70
+ 该命令会安装 npm `latest` tag 指向的版本。如果弹窗仍提示可更新,说明本地缓存/镜像源没同步,直接用方式三手动安装最高版。
71
71
 
72
72
  ### 方式三:手动更新(命令行更新失败时兜底)
73
73
 
74
74
  ```bash
75
75
  cd ~/.dsh/profiles/web
76
- npm install dsh-deepseek-balance-widget@2.3.2 # 若目录内有 pnpm-lock.yaml 则用 pnpm add
76
+ npm install dsh-deepseek-balance-widget@latest # 若目录内有 pnpm-lock.yaml 则用 pnpm add
77
77
  # 验证磁盘上确实变了
78
78
  cat node_modules/dsh-deepseek-balance-widget/package.json | grep '"version"'
79
79
  ```
80
80
 
81
- 确认输出 `2.3.2` 后,**彻底重启 `dsh web`** 即可。
81
+ 确认输出的是最新版本号后,**彻底重启 `dsh web`** 即可。
82
+
83
+ > 也可以把 `latest` 换成具体版本号(如 `@2.3.3`),绕过缓存和镜像同步延迟。
82
84
 
83
85
  ## 卸载
84
86
 
package/README_EN.md CHANGED
@@ -20,12 +20,12 @@ A multi-provider AI balance widget for the dsh web sidebar. **DeepSeek** is buil
20
20
  Requires: dsh installed (with `dsh web` working).
21
21
 
22
22
  ```bash
23
- dsh plugin --profile web add dsh-deepseek-balance-widget@2.3.2
23
+ dsh plugin --profile web add dsh-deepseek-balance-widget@latest
24
24
  ```
25
25
 
26
26
  Installed from npm and auto-registered by dsh. **Restart `dsh web`** and the balance button appears in the sidebar.
27
27
 
28
- > Always include the version `@2.3.2`. A bare `add` follows npm's `latest` tag, which may be hijacked by older versions and silently install an outdated release.
28
+ > If `npm view` / the popover shows you ended up on an old version, follow the "Update" section below to force-upgrade. Older versions are marked deprecated and will print an upgrade warning during install.
29
29
 
30
30
  Or just tell your AI:
31
31
 
@@ -51,11 +51,11 @@ Credentials are stored locally in `~/.dsh/ai-balances.json`; nothing is shipped
51
51
 
52
52
  ## Update
53
53
 
54
- The latest stable release is **`2.3.2`**. Upgrade to it regardless of which older version you currently have.
54
+ Upgrade to the latest stable release on npm regardless of which older version you currently have.
55
55
 
56
56
  ### Method 1: One-click from the popover (recommended for installed users)
57
57
 
58
- 1. Open the balance popover; the footer shows the version. When a newer one exists it reads `vX → v2.3.2 更新`.
58
+ 1. Open the balance popover; the footer shows the version. When a newer one exists it reads `vX → vY 更新` (where `vY` is the highest semver version on npm).
59
59
  2. Click "**检查更新**" (Check for update). The plugin pulls and installs the highest semver version from npm automatically.
60
60
  3. After install you **must fully restart `dsh web`** (stop the `dsh web` process / quit the desktop app and reopen — **refreshing the browser tab is not enough**) for the new version to load.
61
61
 
@@ -64,21 +64,23 @@ The latest stable release is **`2.3.2`**. Upgrade to it regardless of which olde
64
64
  ### Method 2: Force update from the command line (most reliable if stuck)
65
65
 
66
66
  ```bash
67
- dsh plugin --profile web add dsh-deepseek-balance-widget@2.3.2
67
+ dsh plugin --profile web add dsh-deepseek-balance-widget@latest
68
68
  ```
69
69
 
70
- Pinning the version bypasses cache / mirror desync / a hijacked `latest` tag in one step.
70
+ This installs the version currently tagged as npm `latest`. If the popover still says an update is available, your cache/mirror is out of sync; use Method 3 to install the highest version manually.
71
71
 
72
72
  ### Method 3: Manual update (fallback when the command-line update fails)
73
73
 
74
74
  ```bash
75
75
  cd ~/.dsh/profiles/web
76
- npm install dsh-deepseek-balance-widget@2.3.2 # use `pnpm add` if a pnpm-lock.yaml exists in this dir
76
+ npm install dsh-deepseek-balance-widget@latest # use `pnpm add` if a pnpm-lock.yaml exists in this dir
77
77
  # verify the on-disk version actually changed
78
78
  cat node_modules/dsh-deepseek-balance-widget/package.json | grep '"version"'
79
79
  ```
80
80
 
81
- Once it prints `2.3.2`, **fully restart `dsh web`**.
81
+ Once it prints the latest version, **fully restart `dsh web`**.
82
+
83
+ > You can also replace `latest` with a concrete version (e.g. `@2.3.3`) to bypass cache or mirror sync delays.
82
84
 
83
85
  ## Uninstall
84
86
 
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
2
- import { readFile, writeFile, stat, mkdir, copyFile } from "node:fs/promises";
2
+ import { readFile, writeFile, stat, mkdir, copyFile, readdir, realpath } from "node:fs/promises";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { dirname, resolve } from "node:path";
5
5
  import { homedir } from "node:os";
@@ -541,31 +541,59 @@ async function fileExists(path) {
541
541
  }
542
542
 
543
543
  /**
544
- * Detect the package manager used by UPDATE_CWD.
544
+ * Detect the package manager used in a given project root.
545
+ * @param {string} cwd
545
546
  * @returns {Promise<"pnpm" | "npm">}
546
547
  */
547
- async function detectPackageManager() {
548
- const pnpmLock = resolve(UPDATE_CWD, "pnpm-lock.yaml");
549
- const pnpmLockYml = resolve(UPDATE_CWD, "pnpm-lock.yml");
548
+ async function detectPackageManager(cwd) {
549
+ const pnpmLock = resolve(cwd, "pnpm-lock.yaml");
550
+ const pnpmLockYml = resolve(cwd, "pnpm-lock.yml");
550
551
  if (await fileExists(pnpmLock) || await fileExists(pnpmLockYml)) return "pnpm";
551
552
  return "npm";
552
553
  }
553
554
 
554
555
  /**
555
- * Run the package-manager update command for this package in the discovered project root.
556
- * Uses shell mode on Windows so that .cmd scripts (npm.cmd / pnpm.cmd) can actually spawn.
556
+ * Collect every dsh profile root that currently contains this plugin in its
557
+ * node_modules. We never rely on a single reverse-derived path because dsh may
558
+ * load the plugin from a different profile than the one our module URL points
559
+ * at (desktop vs web profile, pnpm symlinks, custom-plugins, etc). The previous
560
+ * single-point UPDATE_CWD caused "update succeeded but version unchanged"
561
+ * failures on machines where dsh loaded the plugin from a different location
562
+ * than the one npm wrote to.
563
+ * @returns {Promise<string[]>}
564
+ */
565
+ async function getUpdateTargets() {
566
+ const roots = new Set();
567
+ const normalize = (p) => String(p).replace(/\\/g, "/");
568
+ // 1. Reverse-derive from PLUGIN_ROOT (handles symlink edge cases via realpath).
569
+ try {
570
+ const realRoot = normalize(await realpath(PLUGIN_ROOT));
571
+ const parts = realRoot.split("/");
572
+ const nmIndex = parts.lastIndexOf("node_modules");
573
+ if (nmIndex > 0) roots.add(parts.slice(0, nmIndex).join("/"));
574
+ } catch {}
575
+ // 2. Scan every dsh profile for a node_modules entry of this plugin.
576
+ try {
577
+ const profilesDir = resolve(homedir(), ".dsh", "profiles");
578
+ const entries = await readdir(profilesDir, { withFileTypes: true });
579
+ for (const entry of entries) {
580
+ if (!entry.isDirectory()) continue;
581
+ const profileRoot = normalize(resolve(profilesDir, entry.name));
582
+ const pluginDir = resolve(profileRoot, "node_modules", "dsh-deepseek-balance-widget");
583
+ if (await fileExists(pluginDir)) {
584
+ roots.add(profileRoot);
585
+ }
586
+ }
587
+ } catch {}
588
+ return [...roots];
589
+ }
590
+
591
+ /**
592
+ * Run the package-manager update command for this package in a single project root.
557
593
  * @returns {Promise<{ok:boolean, output:string, error?:string}>}
558
594
  */
559
- async function runPackageUpdate() {
560
- const versionInfo = await queryNpmVersion();
561
- if (!versionInfo.ok) {
562
- return { ok: false, error: versionInfo.error || "failed to query npm version" };
563
- }
564
- if (!versionInfo.updateAvailable) {
565
- return { ok: true, output: "already up to date", noOp: true };
566
- }
567
- const target = versionInfo.latest;
568
- const pm = await detectPackageManager();
595
+ async function runInstallOnce(cwd, target) {
596
+ const pm = await detectPackageManager(cwd);
569
597
  const isWin = process.platform === "win32";
570
598
  const cmd = isWin ? (pm === "pnpm" ? "pnpm" : "npm") : pm;
571
599
  const args = pm === "pnpm"
@@ -578,13 +606,13 @@ async function runPackageUpdate() {
578
606
  // Build a single command string and let cmd.exe parse it; hide the console window.
579
607
  const quotedArgs = args.map((a) => `"${a.replace(/"/g, '\\"')}"`).join(" ");
580
608
  child = spawn("cmd.exe", ["/d", "/s", "/c", `${cmd} ${quotedArgs}`], {
581
- cwd: UPDATE_CWD,
609
+ cwd,
582
610
  windowsHide: true,
583
611
  env: { ...process.env, NPM_CONFIG_FUND: "false", NPM_CONFIG_AUDIT: "false" }
584
612
  });
585
613
  } else {
586
614
  child = spawn(cmd, args, {
587
- cwd: UPDATE_CWD,
615
+ cwd,
588
616
  env: { ...process.env, NPM_CONFIG_FUND: "false", NPM_CONFIG_AUDIT: "false" }
589
617
  });
590
618
  }
@@ -604,7 +632,7 @@ async function runPackageUpdate() {
604
632
  // Verify the on-disk version actually changed so the user can't be misled into
605
633
  // restarting dsh when the install silently wrote to a different location.
606
634
  try {
607
- const installedPkgPath = resolve(UPDATE_CWD, "node_modules", "dsh-deepseek-balance-widget", "package.json");
635
+ const installedPkgPath = resolve(cwd, "node_modules", "dsh-deepseek-balance-widget", "package.json");
608
636
  const installedPkg = JSON.parse(await readFile(installedPkgPath, "utf8"));
609
637
  if (installedPkg.version !== target) {
610
638
  resolve({ ok: false, output, error: `installed version mismatch: expected ${target}, found ${installedPkg.version}` });
@@ -619,6 +647,44 @@ async function runPackageUpdate() {
619
647
  });
620
648
  }
621
649
 
650
+ /**
651
+ * Update the plugin in every dsh profile that currently has it installed.
652
+ * The first success wins; if at least one location lands on the target version
653
+ * the update is reported as successful.
654
+ * @returns {Promise<{ok:boolean, output:string, error?:string}>}
655
+ */
656
+ async function runPackageUpdate() {
657
+ const versionInfo = await queryNpmVersion();
658
+ if (!versionInfo.ok) {
659
+ return { ok: false, error: versionInfo.error || "failed to query npm version" };
660
+ }
661
+ if (!versionInfo.updateAvailable) {
662
+ return { ok: true, output: "already up to date", noOp: true };
663
+ }
664
+ const target = versionInfo.latest;
665
+ let targets = await getUpdateTargets();
666
+ if (targets.length === 0) {
667
+ // Fallback to the legacy single reverse-derived path if scanning found nothing.
668
+ targets = [UPDATE_CWD];
669
+ }
670
+ const lines = [];
671
+ let anySuccess = false;
672
+ for (const cwd of targets) {
673
+ const result = await runInstallOnce(cwd, target);
674
+ const label = cwd.replace(/\//g, "\\");
675
+ if (result.ok) {
676
+ anySuccess = true;
677
+ lines.push(`✓ ${label} -> ${target}`);
678
+ } else {
679
+ lines.push(`✗ ${label}: ${result.error || "failed"}`);
680
+ }
681
+ }
682
+ if (anySuccess) {
683
+ return { ok: true, output: lines.join("\n") };
684
+ }
685
+ return { ok: false, output: lines.join("\n"), error: "update failed in all candidate locations" };
686
+ }
687
+
622
688
  /**
623
689
  * Query the DeepSeek balance API for one key.
624
690
  * @param {string} apiKey - the resolved DeepSeek API key.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-deepseek-balance-widget",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "type": "module",
5
5
  "description": "Multi-provider AI balance widget for the dsh web sidebar: a live, auto-refreshing balance pill plus a detail popover listing DeepSeek and any added providers (MiMo etc.). Keys are stored per-machine in ~/.dsh/ai-balances.json and resolved from the local credential seam, never hardcoded.",
6
6
  "keywords": [