@moltium/core 0.1.20 → 0.1.21

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.mjs CHANGED
@@ -424,6 +424,140 @@ var moltbookActions = [
424
424
  readConversationAction
425
425
  ];
426
426
 
427
+ // src/actions/built-in/world.ts
428
+ function createJoinWorldAction(config) {
429
+ return {
430
+ name: "join_world",
431
+ description: `Join a world by URL. The world will fetch this agent's A2A Agent Card and evaluate admission. Parameters: worldUrl (string${config?.defaultWorldUrl ? ", optional" : ", required"}) - the world server URL${config?.defaultWorldUrl ? ` (defaults to ${config.defaultWorldUrl})` : ""}, walletAddress (string, optional) - wallet address for blockchain worlds.`,
432
+ async execute(context) {
433
+ const { parameters, agent } = context;
434
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
435
+ if (!worldUrl) {
436
+ return { success: false, error: 'Parameter "worldUrl" is required' };
437
+ }
438
+ const agentPort = process.env.PORT || "3000";
439
+ const agentHost = process.env.HOST || "localhost";
440
+ const agentUrl = `http://${agentHost}:${agentPort}`;
441
+ try {
442
+ const { default: axios2 } = await import("axios");
443
+ const response = await axios2.post(`${worldUrl}/world/join`, {
444
+ agentUrl,
445
+ walletAddress: parameters.walletAddress || agent?.config?.world?.walletAddress
446
+ }, { timeout: 1e4 });
447
+ return {
448
+ success: true,
449
+ data: response.data
450
+ };
451
+ } catch (error) {
452
+ const msg = error?.response?.data?.error || error?.message || String(error);
453
+ return { success: false, error: `Failed to join world: ${msg}` };
454
+ }
455
+ }
456
+ };
457
+ }
458
+ function createLeaveWorldAction(config) {
459
+ return {
460
+ name: "leave_world",
461
+ description: `Leave a world. Parameters: worldUrl (string${config?.defaultWorldUrl ? ", optional" : ", required"}) - the world server URL.`,
462
+ async execute(context) {
463
+ const { parameters } = context;
464
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
465
+ if (!worldUrl) {
466
+ return { success: false, error: 'Parameter "worldUrl" is required' };
467
+ }
468
+ const agentPort = process.env.PORT || "3000";
469
+ const agentHost = process.env.HOST || "localhost";
470
+ const agentUrl = `http://${agentHost}:${agentPort}`;
471
+ try {
472
+ const { default: axios2 } = await import("axios");
473
+ const response = await axios2.delete(
474
+ `${worldUrl}/world/agents/${encodeURIComponent(agentUrl)}`,
475
+ { timeout: 1e4 }
476
+ );
477
+ return {
478
+ success: true,
479
+ data: response.data
480
+ };
481
+ } catch (error) {
482
+ const msg = error?.response?.data?.error || error?.message || String(error);
483
+ return { success: false, error: `Failed to leave world: ${msg}` };
484
+ }
485
+ }
486
+ };
487
+ }
488
+ function createQueryWorldAction(config) {
489
+ return {
490
+ name: "query_world",
491
+ description: `Query a world's state, agents, and available actions. Parameters: worldUrl (string${config?.defaultWorldUrl ? ", optional" : ", required"}) - the world server URL, endpoint (string, optional) - specific endpoint: "state", "agents", "actions", or "info" (default: "info").`,
492
+ async execute(context) {
493
+ const { parameters } = context;
494
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
495
+ if (!worldUrl) {
496
+ return { success: false, error: 'Parameter "worldUrl" is required' };
497
+ }
498
+ const endpoint = parameters.endpoint || "info";
499
+ const pathMap = {
500
+ info: "/",
501
+ state: "/world/state",
502
+ agents: "/world/agents",
503
+ actions: "/world/actions"
504
+ };
505
+ const path = pathMap[endpoint] || "/";
506
+ try {
507
+ const { default: axios2 } = await import("axios");
508
+ const response = await axios2.get(`${worldUrl}${path}`, { timeout: 1e4 });
509
+ return {
510
+ success: true,
511
+ data: response.data
512
+ };
513
+ } catch (error) {
514
+ const msg = error?.response?.data?.error || error?.message || String(error);
515
+ return { success: false, error: `Failed to query world: ${msg}` };
516
+ }
517
+ }
518
+ };
519
+ }
520
+ function createSendWorldMessageAction(config) {
521
+ return {
522
+ name: "send_world_message",
523
+ description: `Send a message to another agent through the world hub. Parameters: worldUrl (string${config?.defaultWorldUrl ? ", optional" : ", required"}) - the world server URL, toAgentUrl (string, optional) - target agent URL (omit to broadcast to all), message (string, required) - the message to send.`,
524
+ async execute(context) {
525
+ const { parameters } = context;
526
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
527
+ if (!worldUrl) {
528
+ return { success: false, error: 'Parameter "worldUrl" is required' };
529
+ }
530
+ if (!parameters.message) {
531
+ return { success: false, error: 'Parameter "message" is required' };
532
+ }
533
+ const agentPort = process.env.PORT || "3000";
534
+ const agentHost = process.env.HOST || "localhost";
535
+ const agentUrl = `http://${agentHost}:${agentPort}`;
536
+ try {
537
+ const { default: axios2 } = await import("axios");
538
+ const response = await axios2.post(`${worldUrl}/world/message`, {
539
+ fromAgentUrl: agentUrl,
540
+ toAgentUrl: parameters.toAgentUrl,
541
+ message: parameters.message
542
+ }, { timeout: 15e3 });
543
+ return {
544
+ success: true,
545
+ data: response.data
546
+ };
547
+ } catch (error) {
548
+ const msg = error?.response?.data?.error || error?.message || String(error);
549
+ return { success: false, error: `Failed to send world message: ${msg}` };
550
+ }
551
+ }
552
+ };
553
+ }
554
+ var worldActions = {
555
+ createJoinWorldAction,
556
+ createLeaveWorldAction,
557
+ createQueryWorldAction,
558
+ createSendWorldMessageAction
559
+ };
560
+
427
561
  // src/actions/built-in/index.ts
428
562
  var builtInActions = [
429
563
  postSocialUpdateAction,
@@ -1414,6 +1548,10 @@ var A2AClient = class {
1414
1548
  return this.config.agentUrl;
1415
1549
  }
1416
1550
  };
1551
+ function createA2AClient(agentUrlOrConfig) {
1552
+ const config = typeof agentUrlOrConfig === "string" ? { agentUrl: agentUrlOrConfig } : agentUrlOrConfig;
1553
+ return new A2AClient(config);
1554
+ }
1417
1555
 
1418
1556
  // src/a2a/actions.ts
1419
1557
  function createA2ACommunicationAction(config = {}) {
@@ -1606,6 +1744,9 @@ var Agent = class {
1606
1744
  if (this.hooks.onStart) {
1607
1745
  await this.hooks.onStart(this);
1608
1746
  }
1747
+ if (this.config.world?.url && this.config.world.autoJoin !== false) {
1748
+ await this.autoJoinWorld();
1749
+ }
1609
1750
  this.scheduler.start();
1610
1751
  if (this.config.behaviors.autonomous) {
1611
1752
  this.startAutonomousLoop();
@@ -1770,6 +1911,22 @@ var Agent = class {
1770
1911
  logger4.info(`Registered generic A2A action: ${genericAction.name}`);
1771
1912
  }
1772
1913
  }
1914
+ const world = this.config.world;
1915
+ if (world?.url) {
1916
+ const worldUrl = world.url;
1917
+ const worldActionsList = [
1918
+ createJoinWorldAction({ defaultWorldUrl: worldUrl }),
1919
+ createLeaveWorldAction({ defaultWorldUrl: worldUrl }),
1920
+ createQueryWorldAction({ defaultWorldUrl: worldUrl }),
1921
+ createSendWorldMessageAction({ defaultWorldUrl: worldUrl })
1922
+ ];
1923
+ for (const action of worldActionsList) {
1924
+ if (!this.actionRegistry.has(action.name)) {
1925
+ this.actionRegistry.register(action);
1926
+ }
1927
+ }
1928
+ logger4.info(`Registered 4 world actions (world: ${worldUrl})`);
1929
+ }
1773
1930
  if (this.config.customActions) {
1774
1931
  for (const action of this.config.customActions) {
1775
1932
  this.actionRegistry.register(action);
@@ -2056,6 +2213,23 @@ Decide what action to take. Respond with JSON:
2056
2213
  logger4.error(` ${platform}: Server error \u2014 the platform may be temporarily down.`);
2057
2214
  }
2058
2215
  }
2216
+ async autoJoinWorld() {
2217
+ const worldUrl = this.config.world.url;
2218
+ logger4.info(`Auto-joining world: ${worldUrl}`);
2219
+ try {
2220
+ const result = await this.act("join_world", {
2221
+ worldUrl,
2222
+ walletAddress: this.config.world.walletAddress
2223
+ });
2224
+ if (result.success) {
2225
+ logger4.info(`Successfully joined world: ${worldUrl}`);
2226
+ } else {
2227
+ logger4.warn(`Failed to join world: ${result.error}`);
2228
+ }
2229
+ } catch (error) {
2230
+ logger4.warn(`Auto-join world failed: ${error?.message || error}`);
2231
+ }
2232
+ }
2059
2233
  startAutonomousLoop() {
2060
2234
  const actionsPerHour = typeof this.config.behaviors.actionsPerHour === "function" ? this.config.behaviors.actionsPerHour({}) : this.config.behaviors.actionsPerHour || 5;
2061
2235
  const intervalMs = Math.floor(36e5 / actionsPerHour);
@@ -2118,6 +2292,7 @@ var MarkdownParser = class {
2118
2292
  const memory = this.findSection(sections, "Memory");
2119
2293
  const skills = this.findSection(sections, "Skills");
2120
2294
  const scheduling = this.findSection(sections, "Scheduling");
2295
+ const world = this.findSection(sections, "World");
2121
2296
  const identityData = this.parseIdentity(identity);
2122
2297
  const bioText = bio ? bio.content.trim() : identityData?.personality?.bio || "";
2123
2298
  const config = {
@@ -2129,6 +2304,7 @@ var MarkdownParser = class {
2129
2304
  ...social ? { social: this.parseSocial(social) } : {},
2130
2305
  ...behaviors ? { behaviors: this.parseBehaviors(behaviors) } : {},
2131
2306
  ...memory ? { memory: this.parseMemory(memory) } : {},
2307
+ ...world ? { world: this.parseWorld(world) } : {},
2132
2308
  actions: [],
2133
2309
  ...frontmatter
2134
2310
  };
@@ -2229,6 +2405,16 @@ var MarkdownParser = class {
2229
2405
  retention: fields["retention"]
2230
2406
  };
2231
2407
  }
2408
+ parseWorld(section) {
2409
+ const fields = this.parseKeyValueLines(section.content);
2410
+ const url = fields["url"];
2411
+ if (!url) return void 0;
2412
+ return {
2413
+ url,
2414
+ autoJoin: fields["auto_join"] !== "false",
2415
+ ...fields["wallet_address"] ? { walletAddress: fields["wallet_address"] } : {}
2416
+ };
2417
+ }
2232
2418
  parseSleepSchedule(value) {
2233
2419
  const match = value.match(/(\d{1,2}):?\d{0,2}\s*-\s*(\d{1,2}):?\d{0,2}\s*(.*)?/);
2234
2420
  if (!match) return { start: 22, end: 6 };
@@ -3276,6 +3462,7 @@ async function startServer(agent, options = {}) {
3276
3462
  process.on("SIGTERM", shutdown);
3277
3463
  }
3278
3464
  export {
3465
+ A2AClient,
3279
3466
  A2AIntegration,
3280
3467
  ActionHandler,
3281
3468
  ActionRegistry,
@@ -3298,13 +3485,19 @@ export {
3298
3485
  buildSkillPrompt,
3299
3486
  buildSystemPrompt,
3300
3487
  builtInActions,
3488
+ createA2AClient,
3301
3489
  createA2AIntegration,
3302
3490
  createApp,
3491
+ createJoinWorldAction,
3492
+ createLeaveWorldAction,
3303
3493
  createLogger,
3304
3494
  createMarkdownAction,
3495
+ createQueryWorldAction,
3305
3496
  createRoutes,
3497
+ createSendWorldMessageAction,
3306
3498
  moltbookActions,
3307
3499
  startServer,
3308
- validateConfig
3500
+ validateConfig,
3501
+ worldActions
3309
3502
  };
3310
3503
  //# sourceMappingURL=index.mjs.map