mslxdff 0.1.31 → 0.1.33
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/bin/mslxdff.js +78 -1
- package/package.json +1 -1
package/bin/mslxdff.js
CHANGED
|
@@ -14,7 +14,7 @@ import { createAutoSelector } from "../src/auto.js";
|
|
|
14
14
|
import { createPeersService } from "../src/peers.js";
|
|
15
15
|
import { createEventBus } from "../src/events.js";
|
|
16
16
|
import { createGroupsService, createBansService, refreshGroupMembers, syncPeersFromMembers } from "../src/groups.js";
|
|
17
|
-
import { logDir, recentCalls, lastError, appendCall, appendError, appendEvent, recentEvents } from "../src/logs.js";
|
|
17
|
+
import { logDir, recentCalls, lastError, appendCall, appendError, appendEvent, recentEvents, eventsFile, callsFile, errorsFile } from "../src/logs.js";
|
|
18
18
|
|
|
19
19
|
const logs = { appendCall, appendError, appendEvent };
|
|
20
20
|
|
|
@@ -85,6 +85,29 @@ if (args.includes("-uninstall") || args.includes("--uninstall")) {
|
|
|
85
85
|
process.exit(0);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
if (args.includes("-log") || args.includes("--log") || args.includes("-logs") || args.includes("--logs")) {
|
|
89
|
+
const idx = args.findIndex((x) => x === "-log" || x === "--log" || x === "-logs" || x === "--logs");
|
|
90
|
+
const raw = args[idx + 1];
|
|
91
|
+
const n = Number(raw);
|
|
92
|
+
const count = Number.isInteger(n) && n > 0 ? n : 10;
|
|
93
|
+
const file = eventsFile();
|
|
94
|
+
const dir = logDir();
|
|
95
|
+
console.log(`log dir: ${dir}`);
|
|
96
|
+
console.log(`events: ${file}`);
|
|
97
|
+
const evts = recentEvents(count);
|
|
98
|
+
if (!evts.length) {
|
|
99
|
+
console.log(`(no events yet — file empty or not found)`);
|
|
100
|
+
} else {
|
|
101
|
+
console.log(`--- last ${evts.length} event(s) ---`);
|
|
102
|
+
for (const e of evts) console.log(fmtEvent(e));
|
|
103
|
+
}
|
|
104
|
+
// also hint for other logs
|
|
105
|
+
if (count <= 10) {
|
|
106
|
+
console.log(`\nhint: mslxdff -log 100 | calls: ${callsFile()} errors: ${errorsFile()} daemon: ${logFile()}`);
|
|
107
|
+
}
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
|
|
88
111
|
if (args.includes("-status") || args.includes("--status") || args.includes("-s")) {
|
|
89
112
|
await printStatus();
|
|
90
113
|
process.exit(0);
|
|
@@ -664,6 +687,49 @@ const groupSyncTimer = setInterval(() => {
|
|
|
664
687
|
}, groupSyncIntervalMs());
|
|
665
688
|
groupSyncTimer.unref();
|
|
666
689
|
|
|
690
|
+
// Auto-update: periodically check npm for a newer mslxdff and restart.
|
|
691
|
+
// Enable with MSLXDFF_AUTO_UPDATE=1 (hourly) or MSLXDFF_AUTO_UPDATE_MS=<ms>.
|
|
692
|
+
// Uses the same npm view/install path as `mslxdff -update`, but runs inside
|
|
693
|
+
// the daemon so no manual intervention is needed.
|
|
694
|
+
const autoUpdateMs = autoUpdateIntervalMs();
|
|
695
|
+
if (autoUpdateMs) {
|
|
696
|
+
console.log(`auto-update enabled: checking every ${Math.round(autoUpdateMs / 60000)}m`);
|
|
697
|
+
const autoUpdateTimer = setInterval(() => {
|
|
698
|
+
checkAndAutoUpdate().catch((err) => console.log(`auto-update check failed: ${errMsg(err)}`));
|
|
699
|
+
}, autoUpdateMs);
|
|
700
|
+
autoUpdateTimer.unref();
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
async function checkAndAutoUpdate() {
|
|
704
|
+
const info = await run(npmCmd(), ["view", "mslxdff", "version", "dist-tags.latest"]);
|
|
705
|
+
if (info.err) throw new Error(info.err.message);
|
|
706
|
+
const parts = (info.stdout || "").trim().split(/\s+/).filter(Boolean);
|
|
707
|
+
const latest = parts[parts.length - 1];
|
|
708
|
+
if (!latest || latest === VERSION) return;
|
|
709
|
+
// simple semver compare: skip if latest is not newer
|
|
710
|
+
if (compareSemver(latest, VERSION) <= 0) return;
|
|
711
|
+
console.log(`auto-update: v${VERSION} -> v${latest}, installing...`);
|
|
712
|
+
const up = await run(npmCmd(), ["install", "-g", `mslxdff@${latest}`]);
|
|
713
|
+
if (up.err) throw new Error(up.err.message);
|
|
714
|
+
console.log(`auto-update: installed v${latest}, restarting daemon...`);
|
|
715
|
+
try { stopDaemon(); } catch {}
|
|
716
|
+
// startDaemon re-reads VERSION from the newly installed package on next boot;
|
|
717
|
+
// for the current process we just respawn with the new code.
|
|
718
|
+
const newPid = startDaemon([]);
|
|
719
|
+
await waitForHealth(resolvePort(), 8000);
|
|
720
|
+
console.log(`auto-update: restarted as v${latest} (pid ${newPid})`);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function compareSemver(a, b) {
|
|
724
|
+
const pa = a.split(".").map((x) => parseInt(x, 10) || 0);
|
|
725
|
+
const pb = b.split(".").map((x) => parseInt(x, 10) || 0);
|
|
726
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
727
|
+
const av = pa[i] || 0, bv = pb[i] || 0;
|
|
728
|
+
if (av !== bv) return av - bv;
|
|
729
|
+
}
|
|
730
|
+
return 0;
|
|
731
|
+
}
|
|
732
|
+
|
|
667
733
|
function argValue(...names) {
|
|
668
734
|
for (let i = 0; i < args.length; i++) {
|
|
669
735
|
if (names.includes(args[i])) return args[i + 1];
|
|
@@ -712,6 +778,14 @@ function groupSyncIntervalMs() {
|
|
|
712
778
|
return Number.isInteger(n) && n > 0 ? n : 60_000;
|
|
713
779
|
}
|
|
714
780
|
|
|
781
|
+
function autoUpdateIntervalMs() {
|
|
782
|
+
const raw = process.env.MSLXDFF_AUTO_UPDATE_MS ?? process.env.MSLXDFF_AUTO_UPDATE;
|
|
783
|
+
if (raw === undefined || raw === null || raw === "") return 0;
|
|
784
|
+
if (raw === "1" || String(raw).toLowerCase() === "true") return 60 * 60 * 1000;
|
|
785
|
+
const n = Number(raw);
|
|
786
|
+
return Number.isInteger(n) && n > 0 ? n : 0;
|
|
787
|
+
}
|
|
788
|
+
|
|
715
789
|
function banWindowMs() {
|
|
716
790
|
const n = Number(process.env.MSLXDFF_BAN_WINDOW_MS);
|
|
717
791
|
return Number.isInteger(n) && n > 0 ? n : 48 * 60 * 60 * 1000;
|
|
@@ -742,6 +816,7 @@ Usage:
|
|
|
742
816
|
mslxdff start as a background daemon and exit (status + help if one is already running)
|
|
743
817
|
mslxdff -d start as a background daemon
|
|
744
818
|
mslxdff -status show current status (daemon, models, recent calls, last error)
|
|
819
|
+
mslxdff -log [N] show last N events (default 10, e.g. -log 100)
|
|
745
820
|
mslxdff -model list list the free models this proxy serves (cached)
|
|
746
821
|
mslxdff -model status show per-model health status (normal/limit/error)
|
|
747
822
|
mslxdff -model refresh force-refresh the model cache from the upstream
|
|
@@ -778,6 +853,8 @@ Environment:
|
|
|
778
853
|
MSLXDFF_MAX_HOPS max peer-forwarding depth (default 3)
|
|
779
854
|
MSLXDFF_BAN_THRESHOLD failed joins before an ip is banned (default 5)
|
|
780
855
|
MSLXDFF_BAN_WINDOW_MS ban duration after too many failures (default 48h)
|
|
856
|
+
MSLXDFF_AUTO_UPDATE auto-update: 1/true=hourly, or ms interval (0=off)
|
|
857
|
+
MSLXDFF_AUTO_UPDATE_MS same as above, explicit ms (overrides AUTO_UPDATE)
|
|
781
858
|
`);
|
|
782
859
|
}
|
|
783
860
|
|