@stamn/stamn-plugin 0.1.0-alpha.43 → 0.1.0-alpha.45

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
@@ -4600,7 +4600,7 @@ ${l}
4600
4600
  }
4601
4601
  } }).prompt();
4602
4602
 
4603
- // node_modules/.pnpm/@stamn+sdk@0.1.0-alpha.4/node_modules/@stamn/sdk/dist/index.js
4603
+ // node_modules/.pnpm/@stamn+sdk@0.1.0-alpha.7/node_modules/@stamn/sdk/dist/index.js
4604
4604
  var Resource = class {
4605
4605
  constructor(client) {
4606
4606
  this.client = client;
@@ -4722,10 +4722,11 @@ var ParticipantsResource = class extends Resource {
4722
4722
  }
4723
4723
  };
4724
4724
  var ApiKeysResource = class extends Resource {
4725
- async create() {
4725
+ async create(options) {
4726
4726
  const res = await this.client.request(
4727
4727
  "POST",
4728
- "/v1/api-keys"
4728
+ "/v1/api-keys",
4729
+ options
4729
4730
  );
4730
4731
  return res.data;
4731
4732
  }
@@ -4977,15 +4978,19 @@ var StamnClient = class {
4977
4978
  const body = await res.text();
4978
4979
  try {
4979
4980
  const parsed = JSON.parse(body);
4980
- const msg = parsed.error?.message ?? (Array.isArray(parsed.message) ? parsed.message.join(". ") : parsed.message);
4981
- if (msg) return msg;
4981
+ const raw = parsed.error?.message ?? parsed.message;
4982
+ if (raw) {
4983
+ if (typeof raw === "string") return raw;
4984
+ if (Array.isArray(raw)) return raw.join(". ");
4985
+ return JSON.stringify(raw);
4986
+ }
4982
4987
  } catch {
4983
4988
  }
4984
4989
  return body || `HTTP ${res.status}`;
4985
4990
  }
4986
4991
  };
4987
4992
 
4988
- // node_modules/.pnpm/@stamn+cli@0.1.0-alpha.15/node_modules/@stamn/cli/dist/chunk-PLTDB3B6.js
4993
+ // node_modules/.pnpm/@stamn+cli@0.1.0-alpha.18/node_modules/@stamn/cli/dist/chunk-PLTDB3B6.js
4989
4994
  import { execSync } from "child_process";
4990
4995
  import { mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
4991
4996
  import { join } from "path";
@@ -7006,7 +7011,7 @@ function resolveEscalation(ws) {
7006
7011
  }
7007
7012
  };
7008
7013
  }
7009
- function createBlogPost(apiKey, baseUrl) {
7014
+ function createBlogPost(client) {
7010
7015
  return {
7011
7016
  name: "stamn_blog_create_post",
7012
7017
  description: "Publish a blog post to your public profile. Posts appear at /@yourName and in the global feed. You can create 1 post per 24 hours.",
@@ -7023,33 +7028,24 @@ function createBlogPost(apiKey, baseUrl) {
7023
7028
  required: ["title", "content"]
7024
7029
  },
7025
7030
  execute: async (_id, args) => {
7026
- const body = {
7027
- title: assertStr(args.title, "title", 200),
7028
- content: assertStr(args.content, "content", 1e5),
7029
- publish: args.publish === "true"
7030
- };
7031
- if (args.excerpt) body.excerpt = assertStr(args.excerpt, "excerpt", 500);
7032
- const res = await fetch(`${baseUrl}/v1/blog/posts`, {
7033
- method: "POST",
7034
- headers: {
7035
- "Content-Type": "application/json",
7036
- "X-API-Key": apiKey
7037
- },
7038
- body: JSON.stringify(body)
7039
- });
7040
- const data = await res.json();
7041
- if (!res.ok) {
7042
- const msg = data?.message || data?.error || `HTTP ${res.status}`;
7031
+ try {
7032
+ const post = await client.blog.create({
7033
+ title: assertStr(args.title, "title", 200),
7034
+ content: assertStr(args.content, "content", 1e5),
7035
+ excerpt: args.excerpt ? assertStr(args.excerpt, "excerpt", 500) : void 0,
7036
+ publish: args.publish === "true"
7037
+ });
7038
+ return text(
7039
+ `Post created: "${post.title}" (${post.status}). Slug: ${post.slug}`
7040
+ );
7041
+ } catch (err) {
7042
+ const msg = err instanceof Error ? err.message : String(err);
7043
7043
  return text(`Failed to create post: ${msg}`);
7044
7044
  }
7045
- const post = data.data;
7046
- return text(
7047
- `Post created: "${post.title}" (${post.status}). Slug: ${post.slug}`
7048
- );
7049
7045
  }
7050
7046
  };
7051
7047
  }
7052
- function allTools(ws, agentId, maxSpendCents, apiKey, baseUrl) {
7048
+ function allTools(ws, agentId, maxSpendCents, client) {
7053
7049
  return [
7054
7050
  worldStatus(ws),
7055
7051
  getEvents(ws),
@@ -7077,7 +7073,7 @@ function allTools(ws, agentId, maxSpendCents, apiKey, baseUrl) {
7077
7073
  addCredential(ws),
7078
7074
  requestEscalation(ws),
7079
7075
  resolveEscalation(ws),
7080
- createBlogPost(apiKey, baseUrl)
7076
+ createBlogPost(client)
7081
7077
  ];
7082
7078
  }
7083
7079
  function withAuthGuard(tool, ws) {
@@ -7100,13 +7096,13 @@ function withAuthGuard(tool, ws) {
7100
7096
  function registerTools(api, pool, config) {
7101
7097
  const maxSpendCents = config.maxSpendCentsPerCall ?? DEFAULT_MAX_SPEND_CENTS;
7102
7098
  api.registerTool(ping());
7103
- const baseUrl = getHttpUrl();
7104
7099
  api.registerTool((ctx) => {
7105
7100
  const binding = resolveBinding(config, ctx.agentId);
7106
7101
  if (!binding) return null;
7107
7102
  const ws = pool.resolve(ctx.agentId);
7108
7103
  if (!ws) return null;
7109
- const tools = allTools(ws, binding.agentId, maxSpendCents, binding.apiKey, baseUrl);
7104
+ const client = new StamnClient({ apiKey: binding.apiKey });
7105
+ const tools = allTools(ws, binding.agentId, maxSpendCents, client);
7110
7106
  return tools.map((tool) => withAuthGuard(tool, ws));
7111
7107
  });
7112
7108
  }