agentlife 2.6.16 → 2.6.18
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 +48 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1577,6 +1577,22 @@ async function provisionAgents(state, cfg, runtime, log) {
|
|
|
1577
1577
|
const workspaceDir = agent.workspaceDir ?? path4.join(home, ".openclaw", `workspace-${agent.id}`);
|
|
1578
1578
|
await fs3.mkdir(workspaceDir, { recursive: true });
|
|
1579
1579
|
await fs3.writeFile(path4.join(workspaceDir, "AGENTS.md"), agent.agentsMd, "utf-8");
|
|
1580
|
+
const stateDir = path4.join(workspaceDir, ".openclaw");
|
|
1581
|
+
await fs3.mkdir(stateDir, { recursive: true });
|
|
1582
|
+
const stateFile = path4.join(stateDir, "workspace-state.json");
|
|
1583
|
+
try {
|
|
1584
|
+
await fs3.writeFile(stateFile, JSON.stringify({ version: 1, bootstrapSeededAt: new Date().toISOString() }, null, 2) + `
|
|
1585
|
+
`, { encoding: "utf-8", flag: "wx" });
|
|
1586
|
+
} catch {
|
|
1587
|
+
try {
|
|
1588
|
+
const existing = JSON.parse(await fs3.readFile(stateFile, "utf-8"));
|
|
1589
|
+
if (!existing.bootstrapSeededAt) {
|
|
1590
|
+
existing.bootstrapSeededAt = new Date().toISOString();
|
|
1591
|
+
await fs3.writeFile(stateFile, JSON.stringify(existing, null, 2) + `
|
|
1592
|
+
`, "utf-8");
|
|
1593
|
+
}
|
|
1594
|
+
} catch {}
|
|
1595
|
+
}
|
|
1580
1596
|
if (!agent.existingAgent) {
|
|
1581
1597
|
const stubPath = path4.join(workspaceDir, "SOUL.md");
|
|
1582
1598
|
await fs3.writeFile(stubPath, "", { encoding: "utf-8", flag: "wx" }).catch(() => {});
|
|
@@ -7511,31 +7527,43 @@ var PLUGIN_VERSION = (() => {
|
|
|
7511
7527
|
} catch {}
|
|
7512
7528
|
return "0.0.0";
|
|
7513
7529
|
})();
|
|
7514
|
-
var
|
|
7530
|
+
var SOFT_TTL_MS = 5 * 60 * 1000;
|
|
7531
|
+
var HARD_FLOOR_MS = 30 * 1000;
|
|
7515
7532
|
var cachedLatest = {
|
|
7516
7533
|
version: null,
|
|
7517
7534
|
fetchedAt: 0
|
|
7518
7535
|
};
|
|
7519
|
-
|
|
7536
|
+
var inflightFetch = null;
|
|
7537
|
+
async function fetchNpmLatestVersion(force = false) {
|
|
7520
7538
|
const now = Date.now();
|
|
7521
|
-
|
|
7539
|
+
const sinceLast = now - cachedLatest.fetchedAt;
|
|
7540
|
+
const haveCache = cachedLatest.version !== null;
|
|
7541
|
+
if (inflightFetch)
|
|
7542
|
+
return inflightFetch;
|
|
7543
|
+
if (haveCache && sinceLast < HARD_FLOOR_MS)
|
|
7522
7544
|
return cachedLatest.version;
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7545
|
+
if (haveCache && !force && sinceLast < SOFT_TTL_MS)
|
|
7546
|
+
return cachedLatest.version;
|
|
7547
|
+
inflightFetch = (async () => {
|
|
7548
|
+
try {
|
|
7549
|
+
const res = await fetch("https://registry.npmjs.org/agentlife/latest", {
|
|
7550
|
+
headers: { Accept: "application/json" },
|
|
7551
|
+
signal: AbortSignal.timeout(5000)
|
|
7552
|
+
});
|
|
7553
|
+
if (!res.ok)
|
|
7554
|
+
return cachedLatest.version;
|
|
7555
|
+
const data = await res.json();
|
|
7556
|
+
if (data.version) {
|
|
7557
|
+
cachedLatest = { version: data.version, fetchedAt: Date.now() };
|
|
7558
|
+
}
|
|
7559
|
+
return cachedLatest.version;
|
|
7560
|
+
} catch {
|
|
7530
7561
|
return cachedLatest.version;
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
cachedLatest = { version: data.version, fetchedAt: now };
|
|
7562
|
+
} finally {
|
|
7563
|
+
inflightFetch = null;
|
|
7534
7564
|
}
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
return cachedLatest.version;
|
|
7538
|
-
}
|
|
7565
|
+
})();
|
|
7566
|
+
return inflightFetch;
|
|
7539
7567
|
}
|
|
7540
7568
|
function pluginConfigPath() {
|
|
7541
7569
|
return path13.join(os8.homedir(), ".openclaw", "agentlife", "plugin-config.json");
|
|
@@ -7556,8 +7584,9 @@ function registerAdminGateway(api, state2) {
|
|
|
7556
7584
|
api.registerGatewayMethod("agentlife.version", ({ respond }) => {
|
|
7557
7585
|
respond(true, { version: PLUGIN_VERSION });
|
|
7558
7586
|
}, { scope: "operator.read" });
|
|
7559
|
-
api.registerGatewayMethod("agentlife.latest_version", async ({ respond }) => {
|
|
7560
|
-
const
|
|
7587
|
+
api.registerGatewayMethod("agentlife.latest_version", async ({ params, respond }) => {
|
|
7588
|
+
const force = params?.force === true;
|
|
7589
|
+
const version = await fetchNpmLatestVersion(force);
|
|
7561
7590
|
respond(true, { version });
|
|
7562
7591
|
}, { scope: "operator.read" });
|
|
7563
7592
|
api.registerGatewayMethod("agentlife.quality", ({ respond }) => {
|