@moltium/core 0.1.20 → 0.1.22

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
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ A2AClient: () => A2AClient,
33
34
  A2AIntegration: () => A2AIntegration,
34
35
  ActionHandler: () => ActionHandler,
35
36
  ActionRegistry: () => ActionRegistry,
@@ -52,14 +53,20 @@ __export(index_exports, {
52
53
  buildSkillPrompt: () => buildSkillPrompt,
53
54
  buildSystemPrompt: () => buildSystemPrompt,
54
55
  builtInActions: () => builtInActions,
56
+ createA2AClient: () => createA2AClient,
55
57
  createA2AIntegration: () => createA2AIntegration,
56
58
  createApp: () => createApp,
59
+ createJoinWorldAction: () => createJoinWorldAction,
60
+ createLeaveWorldAction: () => createLeaveWorldAction,
57
61
  createLogger: () => createLogger,
58
62
  createMarkdownAction: () => createMarkdownAction,
63
+ createQueryWorldAction: () => createQueryWorldAction,
59
64
  createRoutes: () => createRoutes,
65
+ createSendWorldMessageAction: () => createSendWorldMessageAction,
60
66
  moltbookActions: () => moltbookActions,
61
67
  startServer: () => startServer,
62
- validateConfig: () => validateConfig
68
+ validateConfig: () => validateConfig,
69
+ worldActions: () => worldActions
63
70
  });
64
71
  module.exports = __toCommonJS(index_exports);
65
72
 
@@ -489,6 +496,140 @@ var moltbookActions = [
489
496
  readConversationAction
490
497
  ];
491
498
 
499
+ // src/actions/built-in/world.ts
500
+ function createJoinWorldAction(config) {
501
+ return {
502
+ name: "join_world",
503
+ 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.`,
504
+ async execute(context) {
505
+ const { parameters, agent } = context;
506
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
507
+ if (!worldUrl) {
508
+ return { success: false, error: 'Parameter "worldUrl" is required' };
509
+ }
510
+ const agentPort = process.env.PORT || "3000";
511
+ const agentHost = process.env.HOST || "localhost";
512
+ const agentUrl = `http://${agentHost}:${agentPort}`;
513
+ try {
514
+ const { default: axios2 } = await import("axios");
515
+ const response = await axios2.post(`${worldUrl}/world/join`, {
516
+ agentUrl,
517
+ walletAddress: parameters.walletAddress || agent?.config?.world?.walletAddress
518
+ }, { timeout: 1e4 });
519
+ return {
520
+ success: true,
521
+ data: response.data
522
+ };
523
+ } catch (error) {
524
+ const msg = error?.response?.data?.error || error?.message || String(error);
525
+ return { success: false, error: `Failed to join world: ${msg}` };
526
+ }
527
+ }
528
+ };
529
+ }
530
+ function createLeaveWorldAction(config) {
531
+ return {
532
+ name: "leave_world",
533
+ description: `Leave a world. Parameters: worldUrl (string${config?.defaultWorldUrl ? ", optional" : ", required"}) - the world server URL.`,
534
+ async execute(context) {
535
+ const { parameters } = context;
536
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
537
+ if (!worldUrl) {
538
+ return { success: false, error: 'Parameter "worldUrl" is required' };
539
+ }
540
+ const agentPort = process.env.PORT || "3000";
541
+ const agentHost = process.env.HOST || "localhost";
542
+ const agentUrl = `http://${agentHost}:${agentPort}`;
543
+ try {
544
+ const { default: axios2 } = await import("axios");
545
+ const response = await axios2.delete(
546
+ `${worldUrl}/world/agents/${encodeURIComponent(agentUrl)}`,
547
+ { timeout: 1e4 }
548
+ );
549
+ return {
550
+ success: true,
551
+ data: response.data
552
+ };
553
+ } catch (error) {
554
+ const msg = error?.response?.data?.error || error?.message || String(error);
555
+ return { success: false, error: `Failed to leave world: ${msg}` };
556
+ }
557
+ }
558
+ };
559
+ }
560
+ function createQueryWorldAction(config) {
561
+ return {
562
+ name: "query_world",
563
+ 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").`,
564
+ async execute(context) {
565
+ const { parameters } = context;
566
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
567
+ if (!worldUrl) {
568
+ return { success: false, error: 'Parameter "worldUrl" is required' };
569
+ }
570
+ const endpoint = parameters.endpoint || "info";
571
+ const pathMap = {
572
+ info: "/",
573
+ state: "/world/state",
574
+ agents: "/world/agents",
575
+ actions: "/world/actions"
576
+ };
577
+ const path = pathMap[endpoint] || "/";
578
+ try {
579
+ const { default: axios2 } = await import("axios");
580
+ const response = await axios2.get(`${worldUrl}${path}`, { timeout: 1e4 });
581
+ return {
582
+ success: true,
583
+ data: response.data
584
+ };
585
+ } catch (error) {
586
+ const msg = error?.response?.data?.error || error?.message || String(error);
587
+ return { success: false, error: `Failed to query world: ${msg}` };
588
+ }
589
+ }
590
+ };
591
+ }
592
+ function createSendWorldMessageAction(config) {
593
+ return {
594
+ name: "send_world_message",
595
+ 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.`,
596
+ async execute(context) {
597
+ const { parameters } = context;
598
+ const worldUrl = parameters.worldUrl || config?.defaultWorldUrl;
599
+ if (!worldUrl) {
600
+ return { success: false, error: 'Parameter "worldUrl" is required' };
601
+ }
602
+ if (!parameters.message) {
603
+ return { success: false, error: 'Parameter "message" is required' };
604
+ }
605
+ const agentPort = process.env.PORT || "3000";
606
+ const agentHost = process.env.HOST || "localhost";
607
+ const agentUrl = `http://${agentHost}:${agentPort}`;
608
+ try {
609
+ const { default: axios2 } = await import("axios");
610
+ const response = await axios2.post(`${worldUrl}/world/message`, {
611
+ fromAgentUrl: agentUrl,
612
+ toAgentUrl: parameters.toAgentUrl,
613
+ message: parameters.message
614
+ }, { timeout: 15e3 });
615
+ return {
616
+ success: true,
617
+ data: response.data
618
+ };
619
+ } catch (error) {
620
+ const msg = error?.response?.data?.error || error?.message || String(error);
621
+ return { success: false, error: `Failed to send world message: ${msg}` };
622
+ }
623
+ }
624
+ };
625
+ }
626
+ var worldActions = {
627
+ createJoinWorldAction,
628
+ createLeaveWorldAction,
629
+ createQueryWorldAction,
630
+ createSendWorldMessageAction
631
+ };
632
+
492
633
  // src/actions/built-in/index.ts
493
634
  var builtInActions = [
494
635
  postSocialUpdateAction,
@@ -1479,6 +1620,10 @@ var A2AClient = class {
1479
1620
  return this.config.agentUrl;
1480
1621
  }
1481
1622
  };
1623
+ function createA2AClient(agentUrlOrConfig) {
1624
+ const config = typeof agentUrlOrConfig === "string" ? { agentUrl: agentUrlOrConfig } : agentUrlOrConfig;
1625
+ return new A2AClient(config);
1626
+ }
1482
1627
 
1483
1628
  // src/a2a/actions.ts
1484
1629
  function createA2ACommunicationAction(config = {}) {
@@ -1671,6 +1816,9 @@ var Agent = class {
1671
1816
  if (this.hooks.onStart) {
1672
1817
  await this.hooks.onStart(this);
1673
1818
  }
1819
+ if (this.config.world?.url && this.config.world.autoJoin !== false) {
1820
+ await this.autoJoinWorld();
1821
+ }
1674
1822
  this.scheduler.start();
1675
1823
  if (this.config.behaviors.autonomous) {
1676
1824
  this.startAutonomousLoop();
@@ -1835,6 +1983,22 @@ var Agent = class {
1835
1983
  logger4.info(`Registered generic A2A action: ${genericAction.name}`);
1836
1984
  }
1837
1985
  }
1986
+ const world = this.config.world;
1987
+ if (world?.url) {
1988
+ const worldUrl = world.url;
1989
+ const worldActionsList = [
1990
+ createJoinWorldAction({ defaultWorldUrl: worldUrl }),
1991
+ createLeaveWorldAction({ defaultWorldUrl: worldUrl }),
1992
+ createQueryWorldAction({ defaultWorldUrl: worldUrl }),
1993
+ createSendWorldMessageAction({ defaultWorldUrl: worldUrl })
1994
+ ];
1995
+ for (const action of worldActionsList) {
1996
+ if (!this.actionRegistry.has(action.name)) {
1997
+ this.actionRegistry.register(action);
1998
+ }
1999
+ }
2000
+ logger4.info(`Registered 4 world actions (world: ${worldUrl})`);
2001
+ }
1838
2002
  if (this.config.customActions) {
1839
2003
  for (const action of this.config.customActions) {
1840
2004
  this.actionRegistry.register(action);
@@ -2121,6 +2285,23 @@ Decide what action to take. Respond with JSON:
2121
2285
  logger4.error(` ${platform}: Server error \u2014 the platform may be temporarily down.`);
2122
2286
  }
2123
2287
  }
2288
+ async autoJoinWorld() {
2289
+ const worldUrl = this.config.world.url;
2290
+ logger4.info(`Auto-joining world: ${worldUrl}`);
2291
+ try {
2292
+ const result = await this.act("join_world", {
2293
+ worldUrl,
2294
+ walletAddress: this.config.world.walletAddress
2295
+ });
2296
+ if (result.success) {
2297
+ logger4.info(`Successfully joined world: ${worldUrl}`);
2298
+ } else {
2299
+ logger4.warn(`Failed to join world: ${result.error}`);
2300
+ }
2301
+ } catch (error) {
2302
+ logger4.warn(`Auto-join world failed: ${error?.message || error}`);
2303
+ }
2304
+ }
2124
2305
  startAutonomousLoop() {
2125
2306
  const actionsPerHour = typeof this.config.behaviors.actionsPerHour === "function" ? this.config.behaviors.actionsPerHour({}) : this.config.behaviors.actionsPerHour || 5;
2126
2307
  const intervalMs = Math.floor(36e5 / actionsPerHour);
@@ -2183,6 +2364,7 @@ var MarkdownParser = class {
2183
2364
  const memory = this.findSection(sections, "Memory");
2184
2365
  const skills = this.findSection(sections, "Skills");
2185
2366
  const scheduling = this.findSection(sections, "Scheduling");
2367
+ const world = this.findSection(sections, "World");
2186
2368
  const identityData = this.parseIdentity(identity);
2187
2369
  const bioText = bio ? bio.content.trim() : identityData?.personality?.bio || "";
2188
2370
  const config = {
@@ -2194,6 +2376,7 @@ var MarkdownParser = class {
2194
2376
  ...social ? { social: this.parseSocial(social) } : {},
2195
2377
  ...behaviors ? { behaviors: this.parseBehaviors(behaviors) } : {},
2196
2378
  ...memory ? { memory: this.parseMemory(memory) } : {},
2379
+ ...world ? { world: this.parseWorld(world) } : {},
2197
2380
  actions: [],
2198
2381
  ...frontmatter
2199
2382
  };
@@ -2294,6 +2477,16 @@ var MarkdownParser = class {
2294
2477
  retention: fields["retention"]
2295
2478
  };
2296
2479
  }
2480
+ parseWorld(section) {
2481
+ const fields = this.parseKeyValueLines(section.content);
2482
+ const url = fields["url"];
2483
+ if (!url) return void 0;
2484
+ return {
2485
+ url,
2486
+ autoJoin: fields["auto_join"] !== "false",
2487
+ ...fields["wallet_address"] ? { walletAddress: fields["wallet_address"] } : {}
2488
+ };
2489
+ }
2297
2490
  parseSleepSchedule(value) {
2298
2491
  const match = value.match(/(\d{1,2}):?\d{0,2}\s*-\s*(\d{1,2}):?\d{0,2}\s*(.*)?/);
2299
2492
  if (!match) return { start: 22, end: 6 };
@@ -3342,6 +3535,7 @@ async function startServer(agent, options = {}) {
3342
3535
  }
3343
3536
  // Annotate the CommonJS export names for ESM import in node:
3344
3537
  0 && (module.exports = {
3538
+ A2AClient,
3345
3539
  A2AIntegration,
3346
3540
  ActionHandler,
3347
3541
  ActionRegistry,
@@ -3364,13 +3558,19 @@ async function startServer(agent, options = {}) {
3364
3558
  buildSkillPrompt,
3365
3559
  buildSystemPrompt,
3366
3560
  builtInActions,
3561
+ createA2AClient,
3367
3562
  createA2AIntegration,
3368
3563
  createApp,
3564
+ createJoinWorldAction,
3565
+ createLeaveWorldAction,
3369
3566
  createLogger,
3370
3567
  createMarkdownAction,
3568
+ createQueryWorldAction,
3371
3569
  createRoutes,
3570
+ createSendWorldMessageAction,
3372
3571
  moltbookActions,
3373
3572
  startServer,
3374
- validateConfig
3573
+ validateConfig,
3574
+ worldActions
3375
3575
  });
3376
3576
  //# sourceMappingURL=index.js.map