agentlife 2.6.17 → 2.6.19
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/index.js +36 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7512,12 +7512,13 @@ import * as fs14 from "node:fs/promises";
|
|
|
7512
7512
|
import * as fsSync4 from "node:fs";
|
|
7513
7513
|
import * as os8 from "node:os";
|
|
7514
7514
|
import * as path13 from "node:path";
|
|
7515
|
-
|
|
7515
|
+
import { fileURLToPath } from "node:url";
|
|
7516
7516
|
var PLUGIN_VERSION = (() => {
|
|
7517
7517
|
try {
|
|
7518
|
+
const moduleDir = path13.dirname(fileURLToPath(import.meta.url));
|
|
7518
7519
|
const candidates = [
|
|
7519
|
-
path13.join(
|
|
7520
|
-
path13.join(
|
|
7520
|
+
path13.join(moduleDir, "..", "package.json"),
|
|
7521
|
+
path13.join(moduleDir, "..", "..", "package.json")
|
|
7521
7522
|
];
|
|
7522
7523
|
for (const p of candidates) {
|
|
7523
7524
|
if (fsSync4.existsSync(p)) {
|
|
@@ -7527,31 +7528,43 @@ var PLUGIN_VERSION = (() => {
|
|
|
7527
7528
|
} catch {}
|
|
7528
7529
|
return "0.0.0";
|
|
7529
7530
|
})();
|
|
7530
|
-
var
|
|
7531
|
+
var SOFT_TTL_MS = 5 * 60 * 1000;
|
|
7532
|
+
var HARD_FLOOR_MS = 30 * 1000;
|
|
7531
7533
|
var cachedLatest = {
|
|
7532
7534
|
version: null,
|
|
7533
7535
|
fetchedAt: 0
|
|
7534
7536
|
};
|
|
7535
|
-
|
|
7537
|
+
var inflightFetch = null;
|
|
7538
|
+
async function fetchNpmLatestVersion(force = false) {
|
|
7536
7539
|
const now = Date.now();
|
|
7537
|
-
|
|
7540
|
+
const sinceLast = now - cachedLatest.fetchedAt;
|
|
7541
|
+
const haveCache = cachedLatest.version !== null;
|
|
7542
|
+
if (inflightFetch)
|
|
7543
|
+
return inflightFetch;
|
|
7544
|
+
if (haveCache && sinceLast < HARD_FLOOR_MS)
|
|
7538
7545
|
return cachedLatest.version;
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
+
if (haveCache && !force && sinceLast < SOFT_TTL_MS)
|
|
7547
|
+
return cachedLatest.version;
|
|
7548
|
+
inflightFetch = (async () => {
|
|
7549
|
+
try {
|
|
7550
|
+
const res = await fetch("https://registry.npmjs.org/agentlife/latest", {
|
|
7551
|
+
headers: { Accept: "application/json" },
|
|
7552
|
+
signal: AbortSignal.timeout(5000)
|
|
7553
|
+
});
|
|
7554
|
+
if (!res.ok)
|
|
7555
|
+
return cachedLatest.version;
|
|
7556
|
+
const data = await res.json();
|
|
7557
|
+
if (data.version) {
|
|
7558
|
+
cachedLatest = { version: data.version, fetchedAt: Date.now() };
|
|
7559
|
+
}
|
|
7546
7560
|
return cachedLatest.version;
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7561
|
+
} catch {
|
|
7562
|
+
return cachedLatest.version;
|
|
7563
|
+
} finally {
|
|
7564
|
+
inflightFetch = null;
|
|
7550
7565
|
}
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
return cachedLatest.version;
|
|
7554
|
-
}
|
|
7566
|
+
})();
|
|
7567
|
+
return inflightFetch;
|
|
7555
7568
|
}
|
|
7556
7569
|
function pluginConfigPath() {
|
|
7557
7570
|
return path13.join(os8.homedir(), ".openclaw", "agentlife", "plugin-config.json");
|
|
@@ -7572,8 +7585,9 @@ function registerAdminGateway(api, state2) {
|
|
|
7572
7585
|
api.registerGatewayMethod("agentlife.version", ({ respond }) => {
|
|
7573
7586
|
respond(true, { version: PLUGIN_VERSION });
|
|
7574
7587
|
}, { scope: "operator.read" });
|
|
7575
|
-
api.registerGatewayMethod("agentlife.latest_version", async ({ respond }) => {
|
|
7576
|
-
const
|
|
7588
|
+
api.registerGatewayMethod("agentlife.latest_version", async ({ params, respond }) => {
|
|
7589
|
+
const force = params?.force === true;
|
|
7590
|
+
const version = await fetchNpmLatestVersion(force);
|
|
7577
7591
|
respond(true, { version });
|
|
7578
7592
|
}, { scope: "operator.read" });
|
|
7579
7593
|
api.registerGatewayMethod("agentlife.quality", ({ respond }) => {
|