echoclaw-relay-agent 0.4.1 → 0.4.2
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/dist/main.js +109 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -3838,6 +3838,106 @@ function isServiceInstalled() {
|
|
|
3838
3838
|
}
|
|
3839
3839
|
}
|
|
3840
3840
|
|
|
3841
|
+
// src/service/updater.ts
|
|
3842
|
+
var import_child_process2 = require("child_process");
|
|
3843
|
+
var PACKAGE_NAME = "echoclaw-relay-agent";
|
|
3844
|
+
var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
|
|
3845
|
+
var CHECK_INTERVAL_MS = 4 * 60 * 60 * 1e3;
|
|
3846
|
+
var updateTimer = null;
|
|
3847
|
+
function compareSemver(a, b) {
|
|
3848
|
+
const pa = a.replace(/^v/, "").split(".").map(Number);
|
|
3849
|
+
const pb = b.replace(/^v/, "").split(".").map(Number);
|
|
3850
|
+
for (let i = 0; i < 3; i++) {
|
|
3851
|
+
const na = pa[i] || 0;
|
|
3852
|
+
const nb = pb[i] || 0;
|
|
3853
|
+
if (na > nb) return 1;
|
|
3854
|
+
if (na < nb) return -1;
|
|
3855
|
+
}
|
|
3856
|
+
return 0;
|
|
3857
|
+
}
|
|
3858
|
+
async function fetchLatestVersion() {
|
|
3859
|
+
try {
|
|
3860
|
+
const res = await fetch(REGISTRY_URL, {
|
|
3861
|
+
signal: AbortSignal.timeout(1e4),
|
|
3862
|
+
headers: { "Accept": "application/json" }
|
|
3863
|
+
});
|
|
3864
|
+
if (!res.ok) return null;
|
|
3865
|
+
const data = await res.json();
|
|
3866
|
+
return data.version ?? null;
|
|
3867
|
+
} catch {
|
|
3868
|
+
return null;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
function performUpdate(targetVersion) {
|
|
3872
|
+
console.log(`[updater] Downloading ${PACKAGE_NAME}@${targetVersion}...`);
|
|
3873
|
+
try {
|
|
3874
|
+
const npmRoot = (0, import_child_process2.execSync)("npm root -g", { encoding: "utf-8" }).trim();
|
|
3875
|
+
(0, import_child_process2.execSync)(`npm install -g ${PACKAGE_NAME}@${targetVersion} --prefer-online`, {
|
|
3876
|
+
encoding: "utf-8",
|
|
3877
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
3878
|
+
timeout: 12e4
|
|
3879
|
+
});
|
|
3880
|
+
console.log(`[updater] \u2705 Downloaded ${PACKAGE_NAME}@${targetVersion}`);
|
|
3881
|
+
if (isServiceInstalled()) {
|
|
3882
|
+
console.log("[updater] Updating service...");
|
|
3883
|
+
installService();
|
|
3884
|
+
console.log("[updater] \u2705 Service updated and restarted");
|
|
3885
|
+
}
|
|
3886
|
+
return true;
|
|
3887
|
+
} catch (err2) {
|
|
3888
|
+
console.error(`[updater] Update failed: ${err2.message}`);
|
|
3889
|
+
return false;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
async function checkForUpdate(currentVersion) {
|
|
3893
|
+
const latest = await fetchLatestVersion();
|
|
3894
|
+
if (!latest) return null;
|
|
3895
|
+
if (compareSemver(latest, currentVersion) > 0) {
|
|
3896
|
+
return latest;
|
|
3897
|
+
}
|
|
3898
|
+
return null;
|
|
3899
|
+
}
|
|
3900
|
+
async function startupUpdateCheck(currentVersion, autoUpdate) {
|
|
3901
|
+
const latest = await checkForUpdate(currentVersion);
|
|
3902
|
+
if (!latest) return;
|
|
3903
|
+
console.log("");
|
|
3904
|
+
console.log(` \u{1F4E6} Update available: v${currentVersion} \u2192 v${latest}`);
|
|
3905
|
+
if (autoUpdate && isServiceInstalled()) {
|
|
3906
|
+
console.log(" Auto-updating...");
|
|
3907
|
+
const ok = performUpdate(latest);
|
|
3908
|
+
if (ok) {
|
|
3909
|
+
console.log(" \u2705 Update complete \u2014 service will restart.");
|
|
3910
|
+
process.exit(0);
|
|
3911
|
+
} else {
|
|
3912
|
+
console.log(" \u26A0\uFE0F Auto-update failed \u2014 continuing with current version.");
|
|
3913
|
+
}
|
|
3914
|
+
} else {
|
|
3915
|
+
console.log(` Run: npm cache clean --force && npx ${PACKAGE_NAME}@${latest}`);
|
|
3916
|
+
console.log("");
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
function startPeriodicUpdateCheck(currentVersion) {
|
|
3920
|
+
if (updateTimer) return;
|
|
3921
|
+
updateTimer = setInterval(async () => {
|
|
3922
|
+
const latest = await checkForUpdate(currentVersion);
|
|
3923
|
+
if (latest && isServiceInstalled()) {
|
|
3924
|
+
console.log(`[updater] New version available: v${latest} \u2014 auto-updating...`);
|
|
3925
|
+
const ok = performUpdate(latest);
|
|
3926
|
+
if (ok) {
|
|
3927
|
+
console.log("[updater] Update complete \u2014 restarting.");
|
|
3928
|
+
process.exit(0);
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
}, CHECK_INTERVAL_MS);
|
|
3932
|
+
if (updateTimer.unref) updateTimer.unref();
|
|
3933
|
+
}
|
|
3934
|
+
function stopPeriodicUpdateCheck() {
|
|
3935
|
+
if (updateTimer) {
|
|
3936
|
+
clearInterval(updateTimer);
|
|
3937
|
+
updateTimer = null;
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3841
3941
|
// src/gateway/token-discovery.ts
|
|
3842
3942
|
var import_fs5 = __toESM(require("fs"));
|
|
3843
3943
|
var import_path5 = __toESM(require("path"));
|
|
@@ -3900,7 +4000,7 @@ async function discoverGatewayToken() {
|
|
|
3900
4000
|
}
|
|
3901
4001
|
|
|
3902
4002
|
// src/main.ts
|
|
3903
|
-
var VERSION = "0.4.
|
|
4003
|
+
var VERSION = "0.4.2";
|
|
3904
4004
|
function parseArgs() {
|
|
3905
4005
|
const args = process.argv.slice(2);
|
|
3906
4006
|
const opts = {
|
|
@@ -4123,6 +4223,9 @@ async function main() {
|
|
|
4123
4223
|
console.log(" \u2502 Open Source \xB7 Apache License 2.0 \u2502");
|
|
4124
4224
|
console.log(" \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518");
|
|
4125
4225
|
console.log("");
|
|
4226
|
+
const isService = isServiceInstalled();
|
|
4227
|
+
startupUpdateCheck(VERSION, isService).catch(() => {
|
|
4228
|
+
});
|
|
4126
4229
|
if (!opts.bridgeUrl) {
|
|
4127
4230
|
const discovered = await discoverBridge();
|
|
4128
4231
|
if (discovered) {
|
|
@@ -4202,14 +4305,19 @@ async function main() {
|
|
|
4202
4305
|
resumeSessionKey,
|
|
4203
4306
|
gatewayConfig
|
|
4204
4307
|
});
|
|
4308
|
+
if (isService) {
|
|
4309
|
+
startPeriodicUpdateCheck(VERSION);
|
|
4310
|
+
}
|
|
4205
4311
|
}
|
|
4206
4312
|
process.on("SIGINT", () => {
|
|
4207
4313
|
console.log("\n[relay-agent] Shutting down...");
|
|
4314
|
+
stopPeriodicUpdateCheck();
|
|
4208
4315
|
stopRelayClient();
|
|
4209
4316
|
process.exit(0);
|
|
4210
4317
|
});
|
|
4211
4318
|
process.on("SIGTERM", () => {
|
|
4212
4319
|
console.log("\n[relay-agent] Terminated");
|
|
4320
|
+
stopPeriodicUpdateCheck();
|
|
4213
4321
|
stopRelayClient();
|
|
4214
4322
|
process.exit(0);
|
|
4215
4323
|
});
|