@stamn/stamn-plugin 0.1.0-alpha.29 → 0.1.0-alpha.30

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
@@ -5518,10 +5518,11 @@ function chatReply(ws, agentId) {
5518
5518
  }
5519
5519
  };
5520
5520
  }
5521
- function spend(ws) {
5521
+ var DEFAULT_MAX_SPEND_CENTS = 1e4;
5522
+ function spend(ws, maxSpendCents) {
5522
5523
  return {
5523
5524
  name: "stamn_spend",
5524
- description: "Request a spend from the agent's balance (USDC).",
5525
+ description: `Request a spend from the agent's balance (USDC). Per-call limit: ${maxSpendCents} cents ($${(maxSpendCents / 100).toFixed(2)}).`,
5525
5526
  parameters: {
5526
5527
  type: "object",
5527
5528
  properties: {
@@ -5539,10 +5540,19 @@ function spend(ws) {
5539
5540
  required: ["amountCents", "description", "category", "rail"]
5540
5541
  },
5541
5542
  execute: (_id, args) => {
5543
+ const amount = Number(args.amountCents);
5544
+ if (!Number.isFinite(amount) || amount <= 0) {
5545
+ return text("Error: amountCents must be a positive number.");
5546
+ }
5547
+ if (amount > maxSpendCents) {
5548
+ return text(
5549
+ `Error: amountCents (${amount}) exceeds per-call limit of ${maxSpendCents} cents ($${(maxSpendCents / 100).toFixed(2)}). The owner can raise this limit via maxSpendCentsPerCall in the plugin config.`
5550
+ );
5551
+ }
5542
5552
  const requestId = randomUUID();
5543
5553
  ws.send("participant:spend_request", {
5544
5554
  requestId,
5545
- amountCents: Number(args.amountCents),
5555
+ amountCents: amount,
5546
5556
  currency: "USDC",
5547
5557
  category: args.category,
5548
5558
  rail: args.rail,
@@ -5820,7 +5830,7 @@ function resolveEscalation(ws) {
5820
5830
  }
5821
5831
  };
5822
5832
  }
5823
- function allTools(ws, agentId) {
5833
+ function allTools(ws, agentId, maxSpendCents) {
5824
5834
  return [
5825
5835
  worldStatus(ws),
5826
5836
  getEvents(ws),
@@ -5834,7 +5844,7 @@ function allTools(ws, agentId) {
5834
5844
  updateServiceListing(ws),
5835
5845
  listServiceListings(ws),
5836
5846
  chatReply(ws, agentId),
5837
- spend(ws),
5847
+ spend(ws, maxSpendCents),
5838
5848
  getReputation(ws),
5839
5849
  reviewService(ws),
5840
5850
  getReviews(ws),
@@ -5863,8 +5873,9 @@ function withAuthGuard(tool, ws) {
5863
5873
  };
5864
5874
  }
5865
5875
  function registerTools(api, wsService, config) {
5876
+ const maxSpendCents = config.maxSpendCentsPerCall ?? DEFAULT_MAX_SPEND_CENTS;
5866
5877
  api.registerTool(ping());
5867
- for (const tool of allTools(wsService, config.agentId)) {
5878
+ for (const tool of allTools(wsService, config.agentId, maxSpendCents)) {
5868
5879
  api.registerTool(withAuthGuard(tool, wsService));
5869
5880
  }
5870
5881
  }