@stamn/stamn-plugin 0.1.0-alpha.17 → 0.1.0-alpha.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 CHANGED
@@ -5436,6 +5436,8 @@ var import_websocket_server = __toESM(require_websocket_server(), 1);
5436
5436
  var wrapper_default = import_websocket.default;
5437
5437
 
5438
5438
  // src/ws-service.ts
5439
+ import { hostname } from "os";
5440
+ import { execFile } from "child_process";
5439
5441
  var MAX_EVENT_BUFFER_SIZE = 200;
5440
5442
  var BASE_RECONNECT_DELAY_MS = 1e3;
5441
5443
  var MAX_RECONNECT_DELAY_MS = 6e4;
@@ -5444,6 +5446,7 @@ var PLUGIN_VERSION = "0.1.0";
5444
5446
  var ServerEvent = {
5445
5447
  AUTHENTICATED: "server:authenticated",
5446
5448
  AUTH_ERROR: "server:auth_error",
5449
+ COMMAND: "server:command",
5447
5450
  HEARTBEAT_ACK: "server:heartbeat_ack",
5448
5451
  WORLD_UPDATE: "server:world_update",
5449
5452
  BALANCE: "server:balance",
@@ -5482,6 +5485,7 @@ var StamnWsService = class {
5482
5485
  this.messageHandlers = {
5483
5486
  [ServerEvent.AUTHENTICATED]: (d) => this.onAuthenticated(d),
5484
5487
  [ServerEvent.AUTH_ERROR]: (d) => this.onAuthError(d),
5488
+ [ServerEvent.COMMAND]: (d) => this.onCommand(d),
5485
5489
  [ServerEvent.HEARTBEAT_ACK]: () => this.logger.debug("Heartbeat acknowledged"),
5486
5490
  [ServerEvent.WORLD_UPDATE]: (d) => this.onWorldUpdate(d),
5487
5491
  [ServerEvent.BALANCE]: (d) => this.onBalanceUpdate(d),
@@ -5499,11 +5503,7 @@ var StamnWsService = class {
5499
5503
  async stop() {
5500
5504
  this.clearTimers();
5501
5505
  if (this.isSocketOpen()) {
5502
- this.sendMessage(ClientEvent.STATUS_REPORT, {
5503
- participantId: this.config.agentId,
5504
- status: "shutting_down",
5505
- version: PLUGIN_VERSION
5506
- });
5506
+ this.sendStatusReport("shutting_down");
5507
5507
  this.ws.close(1e3, "Plugin shutting down");
5508
5508
  }
5509
5509
  this.writeStatus(false);
@@ -5588,9 +5588,41 @@ var StamnWsService = class {
5588
5588
  this.logger.info(
5589
5589
  `Authenticated as ${payload.participantId} (server v${payload.serverVersion})`
5590
5590
  );
5591
+ this.sendStatusReport("online");
5591
5592
  this.startHeartbeat();
5592
5593
  this.writeStatus(true);
5593
5594
  }
5595
+ sendStatusReport(status) {
5596
+ this.sendMessage(ClientEvent.STATUS_REPORT, {
5597
+ participantId: this.config.agentId,
5598
+ status,
5599
+ version: PLUGIN_VERSION,
5600
+ platform: process.platform,
5601
+ hostname: hostname(),
5602
+ nodeVersion: process.version,
5603
+ arch: process.arch
5604
+ });
5605
+ }
5606
+ onCommand(payload) {
5607
+ this.logger.info(`Command received: ${payload.command} (${payload.commandId})`);
5608
+ if (payload.command === "update_plugin") {
5609
+ this.handleUpdatePlugin();
5610
+ return;
5611
+ }
5612
+ this.bufferEvent(ServerEvent.COMMAND, payload);
5613
+ }
5614
+ handleUpdatePlugin() {
5615
+ this.logger.info("Updating plugin via openclaw...");
5616
+ execFile("openclaw", ["plugins", "update", "stamn-plugin"], (err, stdout, stderr) => {
5617
+ if (err) {
5618
+ this.logger.error(`Plugin update failed: ${err.message}`);
5619
+ if (stderr) this.logger.error(stderr);
5620
+ return;
5621
+ }
5622
+ this.logger.info(`Plugin updated: ${stdout.trim()}`);
5623
+ this.sendStatusReport("online");
5624
+ });
5625
+ }
5594
5626
  onAuthError(payload) {
5595
5627
  this.authFailed = true;
5596
5628
  this.logger.error(`Authentication failed: ${payload.reason}`);