agentlife 2.6.15 → 2.6.16
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 +50 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
4
4
|
// index.ts
|
|
5
5
|
import { homedir as homedir14 } from "node:os";
|
|
6
6
|
import * as path17 from "node:path";
|
|
7
|
-
import { existsSync as
|
|
7
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
8
8
|
|
|
9
9
|
// db.ts
|
|
10
10
|
import * as fsSync from "node:fs";
|
|
@@ -7496,6 +7496,47 @@ import * as fs14 from "node:fs/promises";
|
|
|
7496
7496
|
import * as fsSync4 from "node:fs";
|
|
7497
7497
|
import * as os8 from "node:os";
|
|
7498
7498
|
import * as path13 from "node:path";
|
|
7499
|
+
var __dirname = "/Users/acv/IdeaProjects/AgentLife/plugin/gateway";
|
|
7500
|
+
var PLUGIN_VERSION = (() => {
|
|
7501
|
+
try {
|
|
7502
|
+
const candidates = [
|
|
7503
|
+
path13.join(__dirname, "..", "package.json"),
|
|
7504
|
+
path13.join(__dirname, "..", "..", "package.json")
|
|
7505
|
+
];
|
|
7506
|
+
for (const p of candidates) {
|
|
7507
|
+
if (fsSync4.existsSync(p)) {
|
|
7508
|
+
return JSON.parse(fsSync4.readFileSync(p, "utf-8")).version ?? "0.0.0";
|
|
7509
|
+
}
|
|
7510
|
+
}
|
|
7511
|
+
} catch {}
|
|
7512
|
+
return "0.0.0";
|
|
7513
|
+
})();
|
|
7514
|
+
var LATEST_CACHE_MS = 60 * 60 * 1000;
|
|
7515
|
+
var cachedLatest = {
|
|
7516
|
+
version: null,
|
|
7517
|
+
fetchedAt: 0
|
|
7518
|
+
};
|
|
7519
|
+
async function fetchNpmLatestVersion() {
|
|
7520
|
+
const now = Date.now();
|
|
7521
|
+
if (cachedLatest.version && now - cachedLatest.fetchedAt < LATEST_CACHE_MS) {
|
|
7522
|
+
return cachedLatest.version;
|
|
7523
|
+
}
|
|
7524
|
+
try {
|
|
7525
|
+
const res = await fetch("https://registry.npmjs.org/agentlife/latest", {
|
|
7526
|
+
headers: { Accept: "application/json" },
|
|
7527
|
+
signal: AbortSignal.timeout(5000)
|
|
7528
|
+
});
|
|
7529
|
+
if (!res.ok)
|
|
7530
|
+
return cachedLatest.version;
|
|
7531
|
+
const data = await res.json();
|
|
7532
|
+
if (data.version) {
|
|
7533
|
+
cachedLatest = { version: data.version, fetchedAt: now };
|
|
7534
|
+
}
|
|
7535
|
+
return cachedLatest.version;
|
|
7536
|
+
} catch {
|
|
7537
|
+
return cachedLatest.version;
|
|
7538
|
+
}
|
|
7539
|
+
}
|
|
7499
7540
|
function pluginConfigPath() {
|
|
7500
7541
|
return path13.join(os8.homedir(), ".openclaw", "agentlife", "plugin-config.json");
|
|
7501
7542
|
}
|
|
@@ -7512,6 +7553,13 @@ function writePluginConfig(config2) {
|
|
|
7512
7553
|
fsSync4.writeFileSync(pluginConfigPath(), JSON.stringify(config2, null, 2));
|
|
7513
7554
|
}
|
|
7514
7555
|
function registerAdminGateway(api, state2) {
|
|
7556
|
+
api.registerGatewayMethod("agentlife.version", ({ respond }) => {
|
|
7557
|
+
respond(true, { version: PLUGIN_VERSION });
|
|
7558
|
+
}, { scope: "operator.read" });
|
|
7559
|
+
api.registerGatewayMethod("agentlife.latest_version", async ({ respond }) => {
|
|
7560
|
+
const version = await fetchNpmLatestVersion();
|
|
7561
|
+
respond(true, { version });
|
|
7562
|
+
}, { scope: "operator.read" });
|
|
7515
7563
|
api.registerGatewayMethod("agentlife.quality", ({ respond }) => {
|
|
7516
7564
|
try {
|
|
7517
7565
|
const db = getOrCreateHistoryDb(state2);
|
|
@@ -8594,7 +8642,7 @@ function register(api) {
|
|
|
8594
8642
|
currentState = state2;
|
|
8595
8643
|
api.registerChannel({ plugin: createAgentlifeChannel(state2.channelState) });
|
|
8596
8644
|
console.log("[agentlife] channel registered, session format: %s", buildAgentSessionKey("example"));
|
|
8597
|
-
if (
|
|
8645
|
+
if (existsSync7(fallbackDir)) {
|
|
8598
8646
|
try {
|
|
8599
8647
|
const db = getOrCreateHistoryDb(state2);
|
|
8600
8648
|
state2.surfaceIndex = new SurfaceIndex(db);
|