@stamn/stamn-plugin 0.1.0-alpha.16 → 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
@@ -4469,7 +4469,7 @@ ${l}
4469
4469
  }
4470
4470
  } }).prompt();
4471
4471
 
4472
- // node_modules/.pnpm/@stamn+sdk@0.1.0-alpha.1/node_modules/@stamn/sdk/dist/index.js
4472
+ // node_modules/.pnpm/@stamn+sdk@0.1.0-alpha.2/node_modules/@stamn/sdk/dist/index.js
4473
4473
  var Resource = class {
4474
4474
  constructor(client) {
4475
4475
  this.client = client;
@@ -4642,6 +4642,37 @@ var HealthResource = class extends Resource {
4642
4642
  }
4643
4643
  }
4644
4644
  };
4645
+ var ServicesResource = class extends Resource {
4646
+ async list(participantId) {
4647
+ const res = await this.client.request(
4648
+ "GET",
4649
+ `/v1/participants/${participantId}/services`
4650
+ );
4651
+ return res.data;
4652
+ }
4653
+ async create(participantId, options) {
4654
+ const res = await this.client.request(
4655
+ "POST",
4656
+ `/v1/participants/${participantId}/services`,
4657
+ options
4658
+ );
4659
+ return res.data;
4660
+ }
4661
+ async update(participantId, serviceId, options) {
4662
+ const res = await this.client.request(
4663
+ "PATCH",
4664
+ `/v1/participants/${participantId}/services/${serviceId}`,
4665
+ options
4666
+ );
4667
+ return res.data;
4668
+ }
4669
+ async delete(participantId, serviceId) {
4670
+ await this.client.request(
4671
+ "DELETE",
4672
+ `/v1/participants/${participantId}/services/${serviceId}`
4673
+ );
4674
+ }
4675
+ };
4645
4676
  var StamnApiError = class extends Error {
4646
4677
  constructor(message, status) {
4647
4678
  super(message);
@@ -4667,6 +4698,7 @@ var StamnClient = class {
4667
4698
  directory;
4668
4699
  leaderboard;
4669
4700
  health;
4701
+ services;
4670
4702
  constructor(options = {}) {
4671
4703
  this.apiKey = options.apiKey;
4672
4704
  this.retryOptions = { ...DEFAULT_RETRY, ...options.retry };
@@ -4677,6 +4709,7 @@ var StamnClient = class {
4677
4709
  this.directory = new DirectoryResource(this);
4678
4710
  this.leaderboard = new LeaderboardResource(this);
4679
4711
  this.health = new HealthResource(this);
4712
+ this.services = new ServicesResource(this);
4680
4713
  }
4681
4714
  setApiKey(apiKey) {
4682
4715
  this.apiKey = apiKey;
@@ -4745,7 +4778,7 @@ var StamnClient = class {
4745
4778
  }
4746
4779
  };
4747
4780
 
4748
- // node_modules/.pnpm/@stamn+cli@0.1.0-alpha.5/node_modules/@stamn/cli/dist/chunk-Z2RKPU7M.js
4781
+ // node_modules/.pnpm/@stamn+cli@0.1.0-alpha.6/node_modules/@stamn/cli/dist/chunk-Z2IAJQOV.js
4749
4782
  import { execSync } from "child_process";
4750
4783
  import { mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
4751
4784
  import { join } from "path";
@@ -5403,6 +5436,8 @@ var import_websocket_server = __toESM(require_websocket_server(), 1);
5403
5436
  var wrapper_default = import_websocket.default;
5404
5437
 
5405
5438
  // src/ws-service.ts
5439
+ import { hostname } from "os";
5440
+ import { execFile } from "child_process";
5406
5441
  var MAX_EVENT_BUFFER_SIZE = 200;
5407
5442
  var BASE_RECONNECT_DELAY_MS = 1e3;
5408
5443
  var MAX_RECONNECT_DELAY_MS = 6e4;
@@ -5411,6 +5446,7 @@ var PLUGIN_VERSION = "0.1.0";
5411
5446
  var ServerEvent = {
5412
5447
  AUTHENTICATED: "server:authenticated",
5413
5448
  AUTH_ERROR: "server:auth_error",
5449
+ COMMAND: "server:command",
5414
5450
  HEARTBEAT_ACK: "server:heartbeat_ack",
5415
5451
  WORLD_UPDATE: "server:world_update",
5416
5452
  BALANCE: "server:balance",
@@ -5449,6 +5485,7 @@ var StamnWsService = class {
5449
5485
  this.messageHandlers = {
5450
5486
  [ServerEvent.AUTHENTICATED]: (d) => this.onAuthenticated(d),
5451
5487
  [ServerEvent.AUTH_ERROR]: (d) => this.onAuthError(d),
5488
+ [ServerEvent.COMMAND]: (d) => this.onCommand(d),
5452
5489
  [ServerEvent.HEARTBEAT_ACK]: () => this.logger.debug("Heartbeat acknowledged"),
5453
5490
  [ServerEvent.WORLD_UPDATE]: (d) => this.onWorldUpdate(d),
5454
5491
  [ServerEvent.BALANCE]: (d) => this.onBalanceUpdate(d),
@@ -5466,11 +5503,7 @@ var StamnWsService = class {
5466
5503
  async stop() {
5467
5504
  this.clearTimers();
5468
5505
  if (this.isSocketOpen()) {
5469
- this.sendMessage(ClientEvent.STATUS_REPORT, {
5470
- participantId: this.config.agentId,
5471
- status: "shutting_down",
5472
- version: PLUGIN_VERSION
5473
- });
5506
+ this.sendStatusReport("shutting_down");
5474
5507
  this.ws.close(1e3, "Plugin shutting down");
5475
5508
  }
5476
5509
  this.writeStatus(false);
@@ -5555,9 +5588,41 @@ var StamnWsService = class {
5555
5588
  this.logger.info(
5556
5589
  `Authenticated as ${payload.participantId} (server v${payload.serverVersion})`
5557
5590
  );
5591
+ this.sendStatusReport("online");
5558
5592
  this.startHeartbeat();
5559
5593
  this.writeStatus(true);
5560
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
+ }
5561
5626
  onAuthError(payload) {
5562
5627
  this.authFailed = true;
5563
5628
  this.logger.error(`Authentication failed: ${payload.reason}`);
@@ -5738,47 +5803,43 @@ var index_default = {
5738
5803
  }
5739
5804
  };
5740
5805
  function dispatchOwnerChat(api, wsService, payload, agentId) {
5741
- api.logger.info(`[stamn-channel] dispatchOwnerChat called: "${payload.text.slice(0, 80)}"`);
5742
- api.logger.info(`[stamn-channel] api.runtime exists: ${!!api.runtime}`);
5743
- api.logger.info(`[stamn-channel] api.runtime keys: ${api.runtime ? Object.keys(api.runtime).join(", ") : "N/A"}`);
5806
+ api.logger.info(`[stamn-channel] owner message: "${payload.text.slice(0, 80)}"`);
5744
5807
  if (!api.runtime?.channel?.reply) {
5745
- api.logger.warn("[stamn-channel] api.runtime.channel.reply not available \u2014 channel dispatch not supported by this OpenClaw version");
5746
- api.logger.info(`[stamn-channel] api.runtime.channel: ${api.runtime?.channel ? Object.keys(api.runtime.channel).join(", ") : "N/A"}`);
5808
+ api.logger.warn("[stamn-channel] channel.reply not available in this OpenClaw version");
5747
5809
  return;
5748
5810
  }
5749
5811
  const reply = api.runtime.channel.reply;
5750
- api.logger.info(`[stamn-channel] channel.reply keys: ${Object.keys(reply).join(", ")}`);
5751
5812
  try {
5752
5813
  const { dispatcher, replyOptions } = reply.createReplyDispatcherWithTyping({
5753
5814
  deliver: async (outbound) => {
5754
- api.logger.info(`[stamn-channel] deliver called, outbound type: ${typeof outbound}`);
5755
- api.logger.info(`[stamn-channel] deliver payload: ${JSON.stringify(outbound).slice(0, 200)}`);
5756
5815
  const text2 = typeof outbound === "string" ? outbound : outbound?.text;
5757
5816
  if (!text2) {
5758
- api.logger.warn("[stamn-channel] deliver: no text extracted from outbound");
5817
+ api.logger.warn("[stamn-channel] deliver: no text in outbound");
5759
5818
  return;
5760
5819
  }
5761
5820
  wsService.send("participant:owner_chat_reply", {
5762
5821
  participantId: agentId,
5763
5822
  text: text2
5764
5823
  });
5765
- api.logger.info("[stamn-channel] Chat reply sent to owner via deliver callback");
5766
5824
  },
5767
5825
  channel: "stamn",
5768
5826
  accountId: agentId
5769
5827
  });
5770
- api.logger.info("[stamn-channel] dispatcher created, calling dispatchReplyFromConfig...");
5771
5828
  reply.dispatchReplyFromConfig({
5772
5829
  ctx: {
5773
5830
  BodyForAgent: payload.text,
5774
5831
  ChatType: "direct",
5775
- MessageSid: payload.messageId
5832
+ MessageSid: payload.messageId,
5833
+ SessionKey: `agent:main:stamn:direct:${agentId}`,
5834
+ Provider: "stamn",
5835
+ Surface: "stamn",
5836
+ From: "owner"
5776
5837
  },
5777
5838
  cfg: api.config,
5778
5839
  dispatcher,
5779
5840
  replyOptions
5780
- }).then((result) => {
5781
- api.logger.info(`[stamn-channel] dispatchReplyFromConfig resolved: ${JSON.stringify(result)}`);
5841
+ }).then(() => {
5842
+ api.logger.info("[stamn-channel] reply dispatched");
5782
5843
  }).catch((err) => {
5783
5844
  api.logger.error(`[stamn-channel] dispatchReplyFromConfig failed: ${err}`);
5784
5845
  });