dsh-deepseek-balance-widget 2.2.1 → 2.3.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.
- package/lib/client.js +20 -3
- package/lib/index.js +34 -10
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -110,7 +110,9 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
pasteCookieHint: "请粘贴 Cookie 或 cURL,AI 会自动提取",
|
|
111
111
|
copied: "已复制",
|
|
112
112
|
copyFailed: "复制失败",
|
|
113
|
-
refresh: "刷新"
|
|
113
|
+
refresh: "刷新",
|
|
114
|
+
peakPeriod: "繁忙时段",
|
|
115
|
+
offPeakPeriod: "空闲时段"
|
|
114
116
|
},
|
|
115
117
|
en: {
|
|
116
118
|
entryAriaLabel: "AI Balance (Balance / Today Spend / Today Tokens)",
|
|
@@ -193,7 +195,9 @@ window.__ModuleLoader__.load({
|
|
|
193
195
|
pasteCookieHint: "Paste a Cookie or cURL; the AI will extract it",
|
|
194
196
|
copied: "Copied",
|
|
195
197
|
copyFailed: "Copy failed",
|
|
196
|
-
refresh: "Refresh"
|
|
198
|
+
refresh: "Refresh",
|
|
199
|
+
peakPeriod: "Peak",
|
|
200
|
+
offPeakPeriod: "Off-peak"
|
|
197
201
|
}
|
|
198
202
|
};
|
|
199
203
|
/** Authoritative source: host route reads ~/.dsh/settings.yaml locale.preference. */
|
|
@@ -385,6 +389,9 @@ window.__ModuleLoader__.load({
|
|
|
385
389
|
".dshBalanceTabBal{font-size:12px;font-weight:600;color:#3fb950;font-variant-numeric:tabular-nums}",
|
|
386
390
|
".dshBalanceTabBal[data-state=err]{color:#f85149}",
|
|
387
391
|
".dshBalanceTabTitle{font-size:14px;font-weight:600}",
|
|
392
|
+
".dshBalancePeriodBadge{font-size:11px;padding:2px 6px;border-radius:4px;color:#9aa4b2;background:rgba(255,255,255,.08);white-space:nowrap}",
|
|
393
|
+
".dshBalancePeriodBadge[data-period=peak]{color:#f85149;background:rgba(248,81,73,.12)}",
|
|
394
|
+
".dshBalancePeriodBadge[data-period=offPeak]{color:#3fb950;background:rgba(35,197,94,.12)}",
|
|
388
395
|
".dshBalanceTabMenu{appearance:none;cursor:pointer;margin-left:4px;font-size:16px;font-weight:600;line-height:1;color:#7b8494;user-select:none;width:18px;height:18px;display:flex;align-items:center;justify-content:center;border-radius:4px}",
|
|
389
396
|
".dshBalanceTabMenu:hover{color:#f85149;background:rgba(248,81,73,.12)}",
|
|
390
397
|
".dshBalanceCtxMenu{position:absolute;z-index:10000;background:#161b22;border:1px solid rgba(255,255,255,.12);border-radius:6px;box-shadow:0 8px 24px rgba(0,0,0,.35);padding:4px 0;min-width:120px}",
|
|
@@ -1058,6 +1065,12 @@ window.__ModuleLoader__.load({
|
|
|
1058
1065
|
return html;
|
|
1059
1066
|
}
|
|
1060
1067
|
|
|
1068
|
+
/** DeepSeek peak/off-peak period based on Beijing time (UTC+8). Peak: 09-12, 14-18. */
|
|
1069
|
+
function currentDeepseekPeriod() {
|
|
1070
|
+
const hour = (new Date().getUTCHours() + 8) % 24;
|
|
1071
|
+
return ((hour >= 9 && hour < 12) || (hour >= 14 && hour < 18)) ? "peak" : "offPeak";
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1061
1074
|
/** Build one tab button for the provider switcher. */
|
|
1062
1075
|
function providerTabHtml(p, bal, isActive) {
|
|
1063
1076
|
const meta = PROVIDER_META[p.kind] || { label: p.kind };
|
|
@@ -1072,8 +1085,12 @@ window.__ModuleLoader__.load({
|
|
|
1072
1085
|
'<span class="dshBalanceTabMenu" data-tab-remove type="button" role="button" aria-label="' + t("remove") + '" title="' + t("remove") + '">×</span>';
|
|
1073
1086
|
const titleCls = isActive ? ' class="dshBalanceTabTitle"' : '';
|
|
1074
1087
|
const balanceSpan = isActive ? '' : '<span class="dshBalanceTabBal"' + stateAttr + ">" + balanceText + "</span>";
|
|
1088
|
+
const period = currentDeepseekPeriod();
|
|
1089
|
+
const periodBadge = (isActive && p.kind === "deepseek")
|
|
1090
|
+
? '<span class="dshBalancePeriodBadge" data-period="' + period + '">' + t(period + "Period") + "</span>"
|
|
1091
|
+
: "";
|
|
1075
1092
|
return '<button class="dshBalanceTab' + (isActive ? " active" : "") + '" type="button" data-tab="' + escapeHtml(p.id) + '">' +
|
|
1076
|
-
'<span' + titleCls + '>' + escapeHtml(label) + '</span>' + balanceSpan + removeBtn + "</button>";
|
|
1093
|
+
'<span' + titleCls + '>' + escapeHtml(label) + '</span>' + periodBadge + balanceSpan + removeBtn + "</button>";
|
|
1077
1094
|
}
|
|
1078
1095
|
|
|
1079
1096
|
/** Build the detail pane for the currently active provider. */
|
package/lib/index.js
CHANGED
|
@@ -567,16 +567,27 @@ async function runPackageUpdate() {
|
|
|
567
567
|
const target = versionInfo.latest;
|
|
568
568
|
const pm = await detectPackageManager();
|
|
569
569
|
const isWin = process.platform === "win32";
|
|
570
|
-
const cmd = isWin ? (pm === "pnpm" ? "pnpm
|
|
570
|
+
const cmd = isWin ? (pm === "pnpm" ? "pnpm" : "npm") : pm;
|
|
571
571
|
const args = pm === "pnpm"
|
|
572
572
|
? ["add", `dsh-deepseek-balance-widget@${target}`]
|
|
573
573
|
: ["install", `dsh-deepseek-balance-widget@${target}`];
|
|
574
574
|
return new Promise((resolve) => {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
shell:
|
|
578
|
-
|
|
579
|
-
|
|
575
|
+
let child;
|
|
576
|
+
if (isWin) {
|
|
577
|
+
// Avoid Node.js DEP0190: spawn with shell:true and a separate args array is deprecated.
|
|
578
|
+
// Build a single command string and let cmd.exe parse it; hide the console window.
|
|
579
|
+
const quotedArgs = args.map((a) => `"${a.replace(/"/g, '\\"')}"`).join(" ");
|
|
580
|
+
child = spawn("cmd.exe", ["/d", "/s", "/c", `${cmd} ${quotedArgs}`], {
|
|
581
|
+
cwd: UPDATE_CWD,
|
|
582
|
+
windowsHide: true,
|
|
583
|
+
env: { ...process.env, NPM_CONFIG_FUND: "false", NPM_CONFIG_AUDIT: "false" }
|
|
584
|
+
});
|
|
585
|
+
} else {
|
|
586
|
+
child = spawn(cmd, args, {
|
|
587
|
+
cwd: UPDATE_CWD,
|
|
588
|
+
env: { ...process.env, NPM_CONFIG_FUND: "false", NPM_CONFIG_AUDIT: "false" }
|
|
589
|
+
});
|
|
590
|
+
}
|
|
580
591
|
let stdout = "";
|
|
581
592
|
let stderr = "";
|
|
582
593
|
child.stdout.on("data", (chunk) => { stdout += String(chunk); });
|
|
@@ -584,13 +595,26 @@ async function runPackageUpdate() {
|
|
|
584
595
|
child.on("error", (error) => {
|
|
585
596
|
resolve({ ok: false, output: stdout + stderr, error: String(error?.message ?? error) });
|
|
586
597
|
});
|
|
587
|
-
child.on("close", (code) => {
|
|
598
|
+
child.on("close", async (code) => {
|
|
588
599
|
const output = (stdout + "\n" + stderr).trim();
|
|
589
|
-
if (code
|
|
590
|
-
resolve({ ok: true, output: output.slice(-800) });
|
|
591
|
-
} else {
|
|
600
|
+
if (code !== 0) {
|
|
592
601
|
resolve({ ok: false, output, error: `${pm} ${args.join(" ")} exited with code ${code}` });
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
// Verify the on-disk version actually changed so the user can't be misled into
|
|
605
|
+
// restarting dsh when the install silently wrote to a different location.
|
|
606
|
+
try {
|
|
607
|
+
const installedPkgPath = resolve(UPDATE_CWD, "node_modules", "dsh-deepseek-balance-widget", "package.json");
|
|
608
|
+
const installedPkg = JSON.parse(await readFile(installedPkgPath, "utf8"));
|
|
609
|
+
if (installedPkg.version !== target) {
|
|
610
|
+
resolve({ ok: false, output, error: `installed version mismatch: expected ${target}, found ${installedPkg.version}` });
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
} catch (verifyError) {
|
|
614
|
+
resolve({ ok: false, output, error: `update appeared to succeed but could not verify installed version: ${String(verifyError?.message ?? verifyError)}` });
|
|
615
|
+
return;
|
|
593
616
|
}
|
|
617
|
+
resolve({ ok: true, output: output.slice(-800) });
|
|
594
618
|
});
|
|
595
619
|
});
|
|
596
620
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deepseek-balance-widget",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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": [
|