aicq-openclaw-plugin 1.5.5 → 1.5.7

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 +192 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7771,7 +7771,7 @@ var require_dist = __commonJS({
7771
7771
  var dotenv = __toESM(require_main(), 1);
7772
7772
  import * as path6 from "path";
7773
7773
  import * as http from "http";
7774
- import { exec } from "child_process";
7774
+ import { exec as exec2 } from "child_process";
7775
7775
  import { definePluginEntry } from "openclaw/plugin-sdk/core";
7776
7776
 
7777
7777
  // dist/config.js
@@ -10338,6 +10338,181 @@ var MessageSendingHook = class {
10338
10338
  }
10339
10339
  };
10340
10340
 
10341
+ // dist/services/autoUpdateService.js
10342
+ import { exec } from "child_process";
10343
+ import { promisify } from "util";
10344
+ var execAsync = promisify(exec);
10345
+ var NPM_REGISTRY_URL = "https://registry.npmjs.org/aicq-openclaw-plugin";
10346
+ var CHECK_INTERVAL_MS = 6 * 60 * 60 * 1e3;
10347
+ var AutoUpdateService = class {
10348
+ constructor(currentVersion, logger) {
10349
+ this.latestVersion = null;
10350
+ this.isUpdating = false;
10351
+ this.lastCheckTime = 0;
10352
+ this.checkTimer = null;
10353
+ this.onUpdateAvailable = null;
10354
+ this.onUpdateComplete = null;
10355
+ this.onUpdateError = null;
10356
+ this.currentVersion = currentVersion;
10357
+ this.logger = logger;
10358
+ }
10359
+ /**
10360
+ * Start the auto-update service.
10361
+ * Checks immediately, then periodically every 6 hours.
10362
+ */
10363
+ start() {
10364
+ this.checkForUpdate().catch(() => {
10365
+ });
10366
+ this.checkTimer = setInterval(() => {
10367
+ this.checkForUpdate().catch(() => {
10368
+ });
10369
+ }, CHECK_INTERVAL_MS);
10370
+ this.logger.info("[AutoUpdate] Service started \u2014 checking every " + CHECK_INTERVAL_MS / 36e5 + " hours");
10371
+ }
10372
+ /**
10373
+ * Stop the auto-update service.
10374
+ */
10375
+ stop() {
10376
+ if (this.checkTimer) {
10377
+ clearInterval(this.checkTimer);
10378
+ this.checkTimer = null;
10379
+ }
10380
+ this.logger.info("[AutoUpdate] Service stopped");
10381
+ }
10382
+ /**
10383
+ * Register callback for when an update is available.
10384
+ */
10385
+ onAvailable(callback) {
10386
+ this.onUpdateAvailable = callback;
10387
+ }
10388
+ /**
10389
+ * Register callback for when an update completes successfully.
10390
+ */
10391
+ onComplete(callback) {
10392
+ this.onUpdateComplete = callback;
10393
+ }
10394
+ /**
10395
+ * Register callback for when an update fails.
10396
+ */
10397
+ onError(callback) {
10398
+ this.onUpdateError = callback;
10399
+ }
10400
+ /**
10401
+ * Get the current update status.
10402
+ */
10403
+ getStatus() {
10404
+ return {
10405
+ currentVersion: this.currentVersion,
10406
+ latestVersion: this.latestVersion,
10407
+ hasUpdate: this.latestVersion ? this.compareVersions(this.latestVersion, this.currentVersion) > 0 : false,
10408
+ isUpdating: this.isUpdating,
10409
+ lastCheckTime: this.lastCheckTime
10410
+ };
10411
+ }
10412
+ /**
10413
+ * Manually trigger an update check.
10414
+ */
10415
+ async checkNow() {
10416
+ return this.checkForUpdate();
10417
+ }
10418
+ /**
10419
+ * Check npm registry for the latest version.
10420
+ * If a newer version is found, automatically install it.
10421
+ */
10422
+ async checkForUpdate() {
10423
+ if (this.isUpdating) {
10424
+ this.logger.info("[AutoUpdate] Already updating \u2014 skip check");
10425
+ return null;
10426
+ }
10427
+ try {
10428
+ this.logger.info("[AutoUpdate] Checking for updates... (current: " + this.currentVersion + ")");
10429
+ const controller = new AbortController();
10430
+ const timeout = setTimeout(() => controller.abort(), 15e3);
10431
+ const resp = await fetch(NPM_REGISTRY_URL, {
10432
+ signal: controller.signal,
10433
+ headers: { "Accept": "application/json" }
10434
+ });
10435
+ clearTimeout(timeout);
10436
+ if (!resp.ok) {
10437
+ this.logger.warn("[AutoUpdate] npm registry returned " + resp.status);
10438
+ return null;
10439
+ }
10440
+ const data = await resp.json();
10441
+ const latest = data?.["dist-tags"]?.latest;
10442
+ if (!latest) {
10443
+ this.logger.warn("[AutoUpdate] No 'latest' dist-tag found");
10444
+ return null;
10445
+ }
10446
+ this.latestVersion = latest;
10447
+ this.lastCheckTime = Date.now();
10448
+ const info = {
10449
+ latest,
10450
+ current: this.currentVersion,
10451
+ hasUpdate: this.compareVersions(latest, this.currentVersion) > 0
10452
+ };
10453
+ if (info.hasUpdate) {
10454
+ this.logger.info("[AutoUpdate] New version available: " + this.currentVersion + " \u2192 " + latest);
10455
+ this.onUpdateAvailable?.(info);
10456
+ await this.installUpdate(latest);
10457
+ } else {
10458
+ this.logger.info("[AutoUpdate] Plugin is up to date (" + this.currentVersion + ")");
10459
+ }
10460
+ return info;
10461
+ } catch (err) {
10462
+ if (err instanceof DOMException && err.name === "AbortError") {
10463
+ this.logger.warn("[AutoUpdate] Check timed out");
10464
+ } else {
10465
+ this.logger.error("[AutoUpdate] Check failed: " + (err instanceof Error ? err.message : String(err)));
10466
+ }
10467
+ return null;
10468
+ }
10469
+ }
10470
+ /**
10471
+ * Install the specified version from npm.
10472
+ * Uses `npm install -g` to update the plugin globally.
10473
+ */
10474
+ async installUpdate(version) {
10475
+ if (this.isUpdating)
10476
+ return false;
10477
+ this.isUpdating = true;
10478
+ try {
10479
+ this.logger.info("[AutoUpdate] Installing aicq-openclaw-plugin@" + version + "...");
10480
+ const { stdout, stderr } = await execAsync("npm install -g aicq-openclaw-plugin@" + version, { timeout: 12e4 });
10481
+ if (stdout)
10482
+ this.logger.info("[AutoUpdate] " + stdout.trim());
10483
+ if (stderr)
10484
+ this.logger.warn("[AutoUpdate] " + stderr.trim());
10485
+ this.logger.info("[AutoUpdate] Successfully updated to " + version);
10486
+ this.currentVersion = version;
10487
+ const info = { latest: version, current: version, hasUpdate: false };
10488
+ this.onUpdateComplete?.(info);
10489
+ return true;
10490
+ } catch (err) {
10491
+ const msg = err instanceof Error ? err.message : String(err);
10492
+ this.logger.error("[AutoUpdate] Install failed: " + msg);
10493
+ this.onUpdateError?.(msg);
10494
+ return false;
10495
+ } finally {
10496
+ this.isUpdating = false;
10497
+ }
10498
+ }
10499
+ /**
10500
+ * Compare two semver version strings.
10501
+ * Returns > 0 if a > b, < 0 if a < b, 0 if equal.
10502
+ */
10503
+ compareVersions(a, b) {
10504
+ const pa = a.replace(/^v/, "").split(".").map(Number);
10505
+ const pb = b.replace(/^v/, "").split(".").map(Number);
10506
+ for (let i = 0; i < 3; i++) {
10507
+ const na = pa[i] || 0;
10508
+ const nb = pb[i] || 0;
10509
+ if (na !== nb)
10510
+ return na - nb;
10511
+ }
10512
+ return 0;
10513
+ }
10514
+ };
10515
+
10341
10516
  // dist/ui/management-page.js
10342
10517
  var CSS = `
10343
10518
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
@@ -15161,8 +15336,9 @@ var plugin = definePluginEntry({
15161
15336
  error: (msg, ...args) => ocLog.error?.(msg, ...args) ?? console.error("[aicq-chat]", msg, ...args),
15162
15337
  debug: (msg, ...args) => ocLog.debug?.(msg, ...args) ?? console.log("[aicq-chat DEBUG]", msg, ...args)
15163
15338
  };
15339
+ const pluginVersion = "1.5.7";
15164
15340
  logger.info("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
15165
- logger.info(" AICQ Encrypted Chat Plugin v1.2.0");
15341
+ logger.info(" AICQ Encrypted Chat Plugin v" + pluginVersion);
15166
15342
  logger.info("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
15167
15343
  const pluginCfg = api.pluginConfig ?? {};
15168
15344
  const config2 = loadConfig({
@@ -15399,6 +15575,17 @@ var plugin = definePluginEntry({
15399
15575
  return chatExportKeyTool.handle(params || {});
15400
15576
  }
15401
15577
  });
15578
+ const autoUpdateService = new AutoUpdateService(pluginVersion, logger);
15579
+ autoUpdateService.onAvailable((info) => {
15580
+ logger.info("[AutoUpdate] \u{1F195} Update available: " + info.current + " \u2192 " + info.latest + " \u2014 installing...");
15581
+ });
15582
+ autoUpdateService.onComplete((info) => {
15583
+ logger.info("[AutoUpdate] \u2705 Updated to " + info.latest + " \u2014 restart OpenClaw to use the new version");
15584
+ });
15585
+ autoUpdateService.onError((err) => {
15586
+ logger.warn("[AutoUpdate] \u274C Update failed: " + err);
15587
+ });
15588
+ autoUpdateService.start();
15402
15589
  if (api.registerService) {
15403
15590
  api.registerService({
15404
15591
  id: "identity-service",
@@ -15417,6 +15604,7 @@ var plugin = definePluginEntry({
15417
15604
  identityService.cleanup();
15418
15605
  chatChannel.cleanup();
15419
15606
  serverClient.disconnectWebSocket();
15607
+ autoUpdateService.stop();
15420
15608
  logger.info("[Service] identity-service stopped");
15421
15609
  }
15422
15610
  });
@@ -15789,7 +15977,7 @@ var plugin = definePluginEntry({
15789
15977
  try {
15790
15978
  const url = "http://127.0.0.1:" + actualMgmtPort + "/";
15791
15979
  const cmd = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open";
15792
- exec(cmd + ' "' + url + '"', (err) => {
15980
+ exec2(cmd + ' "' + url + '"', (err) => {
15793
15981
  if (err)
15794
15982
  logger.debug("[Init] Auto-open browser skipped: " + (err.message || err));
15795
15983
  else
@@ -15800,7 +15988,7 @@ var plugin = definePluginEntry({
15800
15988
  }
15801
15989
  }, 3e3);
15802
15990
  logger.info("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
15803
- logger.info(" AICQ Plugin v1.2.0 activated successfully!");
15991
+ logger.info(" AICQ Plugin v" + pluginVersion + " activated successfully!");
15804
15992
  logger.info(" Management UI: http://127.0.0.1:" + actualMgmtPort + "/");
15805
15993
  if (mgmtUiRegistered) {
15806
15994
  logger.info(" Gateway UI: /plugins/aicq-chat/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicq-openclaw-plugin",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "description": "AICQ OpenClaw plugin - end-to-end encrypted P2P chat for AI agents with offline queue support",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",