dsh-deepseek-balance-widget 2.2.0 → 2.2.1

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.
Files changed (2) hide show
  1. package/lib/index.js +37 -17
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -12,7 +12,7 @@ const name = "deepseek-balance-widget";
12
12
  const inject = ["webServer", "credentials"];
13
13
 
14
14
  /** NPM registry endpoint for this package (public access, no auth). */
15
- const NPM_REGISTRY_URL = "https://registry.npmjs.org/dsh-deepseek-balance-widget/latest";
15
+ const NPM_REGISTRY_URL = "https://registry.npmjs.org/dsh-deepseek-balance-widget";
16
16
 
17
17
  /** Absolute path to this plugin's package root (where package.json lives). */
18
18
  const PLUGIN_ROOT = (() => {
@@ -480,7 +480,25 @@ const PLATFORM_HEADERS = {
480
480
  };
481
481
 
482
482
  /**
483
- * Query the NPM registry for the latest published version of this package.
483
+ * Simple semver comparison for x.y.z style versions.
484
+ * @returns {number} 1 if a > b, -1 if a < b, 0 if equal.
485
+ */
486
+ function compareSemver(a, b) {
487
+ const toParts = (v) => String(v).split(".").map((p) => Number.parseInt(p, 10) || 0);
488
+ const ap = toParts(a);
489
+ const bp = toParts(b);
490
+ for (let i = 0; i < Math.max(ap.length, bp.length); i++) {
491
+ const av = ap[i] ?? 0;
492
+ const bv = bp[i] ?? 0;
493
+ if (av > bv) return 1;
494
+ if (av < bv) return -1;
495
+ }
496
+ return 0;
497
+ }
498
+
499
+ /**
500
+ * Query the NPM registry for the highest published version of this package.
501
+ * The popover "update" button will install this version regardless of the "latest" dist-tag.
484
502
  * @returns {Promise<{ok:boolean, local:string, latest?:string, updateAvailable?:boolean, error?:string}>}
485
503
  */
486
504
  async function queryNpmVersion() {
@@ -500,21 +518,15 @@ async function queryNpmVersion() {
500
518
  const text = await response.text();
501
519
  return { ok: false, local: LOCAL_VERSION, error: `bad json (HTTP ${response.status})` };
502
520
  }
503
- const latest = data?.version;
504
- if (typeof latest !== "string") {
505
- return { ok: false, local: LOCAL_VERSION, error: "version field missing" };
521
+ const versions = data && typeof data.versions === "object" ? Object.keys(data.versions) : [];
522
+ if (!versions.length) {
523
+ return { ok: false, local: LOCAL_VERSION, error: "version list missing" };
506
524
  }
507
- // Simple semantic-ish comparison: split by dot and compare numeric parts.
508
- const toParts = (v) => String(v).split(".").map((p) => Number.parseInt(p, 10) || 0);
509
- const localParts = toParts(LOCAL_VERSION);
510
- const latestParts = toParts(latest);
511
- let updateAvailable = false;
512
- for (let i = 0; i < Math.max(localParts.length, latestParts.length); i++) {
513
- const a = localParts[i] ?? 0;
514
- const b = latestParts[i] ?? 0;
515
- if (b > a) { updateAvailable = true; break; }
516
- if (b < a) { break; }
525
+ const latest = versions.reduce((max, v) => (compareSemver(v, max) > 0 ? v : max), versions[0]);
526
+ if (typeof latest !== "string") {
527
+ return { ok: false, local: LOCAL_VERSION, error: "could not determine highest version" };
517
528
  }
529
+ const updateAvailable = compareSemver(latest, LOCAL_VERSION) > 0;
518
530
  return { ok: true, local: LOCAL_VERSION, latest, updateAvailable };
519
531
  }
520
532
 
@@ -545,12 +557,20 @@ async function detectPackageManager() {
545
557
  * @returns {Promise<{ok:boolean, output:string, error?:string}>}
546
558
  */
547
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;
548
568
  const pm = await detectPackageManager();
549
569
  const isWin = process.platform === "win32";
550
570
  const cmd = isWin ? (pm === "pnpm" ? "pnpm.cmd" : "npm.cmd") : pm;
551
571
  const args = pm === "pnpm"
552
- ? ["add", "dsh-deepseek-balance-widget@latest"]
553
- : ["install", "dsh-deepseek-balance-widget@latest"];
572
+ ? ["add", `dsh-deepseek-balance-widget@${target}`]
573
+ : ["install", `dsh-deepseek-balance-widget@${target}`];
554
574
  return new Promise((resolve) => {
555
575
  const child = spawn(cmd, args, {
556
576
  cwd: UPDATE_CWD,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-deepseek-balance-widget",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
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": [