agentlife 2.6.15 → 2.6.17

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.
Files changed (2) hide show
  1. package/dist/index.js +66 -2
  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 existsSync6 } from "node:fs";
7
+ import { existsSync as existsSync7 } from "node:fs";
8
8
 
9
9
  // db.ts
10
10
  import * as fsSync from "node:fs";
@@ -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(() => {});
@@ -7496,6 +7512,47 @@ import * as fs14 from "node:fs/promises";
7496
7512
  import * as fsSync4 from "node:fs";
7497
7513
  import * as os8 from "node:os";
7498
7514
  import * as path13 from "node:path";
7515
+ var __dirname = "/Users/acv/IdeaProjects/AgentLife/plugin/gateway";
7516
+ var PLUGIN_VERSION = (() => {
7517
+ try {
7518
+ const candidates = [
7519
+ path13.join(__dirname, "..", "package.json"),
7520
+ path13.join(__dirname, "..", "..", "package.json")
7521
+ ];
7522
+ for (const p of candidates) {
7523
+ if (fsSync4.existsSync(p)) {
7524
+ return JSON.parse(fsSync4.readFileSync(p, "utf-8")).version ?? "0.0.0";
7525
+ }
7526
+ }
7527
+ } catch {}
7528
+ return "0.0.0";
7529
+ })();
7530
+ var LATEST_CACHE_MS = 60 * 60 * 1000;
7531
+ var cachedLatest = {
7532
+ version: null,
7533
+ fetchedAt: 0
7534
+ };
7535
+ async function fetchNpmLatestVersion() {
7536
+ const now = Date.now();
7537
+ if (cachedLatest.version && now - cachedLatest.fetchedAt < LATEST_CACHE_MS) {
7538
+ return cachedLatest.version;
7539
+ }
7540
+ try {
7541
+ const res = await fetch("https://registry.npmjs.org/agentlife/latest", {
7542
+ headers: { Accept: "application/json" },
7543
+ signal: AbortSignal.timeout(5000)
7544
+ });
7545
+ if (!res.ok)
7546
+ return cachedLatest.version;
7547
+ const data = await res.json();
7548
+ if (data.version) {
7549
+ cachedLatest = { version: data.version, fetchedAt: now };
7550
+ }
7551
+ return cachedLatest.version;
7552
+ } catch {
7553
+ return cachedLatest.version;
7554
+ }
7555
+ }
7499
7556
  function pluginConfigPath() {
7500
7557
  return path13.join(os8.homedir(), ".openclaw", "agentlife", "plugin-config.json");
7501
7558
  }
@@ -7512,6 +7569,13 @@ function writePluginConfig(config2) {
7512
7569
  fsSync4.writeFileSync(pluginConfigPath(), JSON.stringify(config2, null, 2));
7513
7570
  }
7514
7571
  function registerAdminGateway(api, state2) {
7572
+ api.registerGatewayMethod("agentlife.version", ({ respond }) => {
7573
+ respond(true, { version: PLUGIN_VERSION });
7574
+ }, { scope: "operator.read" });
7575
+ api.registerGatewayMethod("agentlife.latest_version", async ({ respond }) => {
7576
+ const version = await fetchNpmLatestVersion();
7577
+ respond(true, { version });
7578
+ }, { scope: "operator.read" });
7515
7579
  api.registerGatewayMethod("agentlife.quality", ({ respond }) => {
7516
7580
  try {
7517
7581
  const db = getOrCreateHistoryDb(state2);
@@ -8594,7 +8658,7 @@ function register(api) {
8594
8658
  currentState = state2;
8595
8659
  api.registerChannel({ plugin: createAgentlifeChannel(state2.channelState) });
8596
8660
  console.log("[agentlife] channel registered, session format: %s", buildAgentSessionKey("example"));
8597
- if (existsSync6(fallbackDir)) {
8661
+ if (existsSync7(fallbackDir)) {
8598
8662
  try {
8599
8663
  const db = getOrCreateHistoryDb(state2);
8600
8664
  state2.surfaceIndex = new SurfaceIndex(db);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentlife",
3
- "version": "2.6.15",
3
+ "version": "2.6.17",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "bun build index.ts --outfile dist/index.js --target node --external openclaw/plugin-sdk",