@moltium/core 0.1.30 → 0.1.32

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
@@ -689,6 +689,7 @@ var moltbookActions = [
689
689
  // src/actions/built-in/world.ts
690
690
  init_logger();
691
691
  var logger4 = createLogger("WorldActions");
692
+ var joinedWorlds = /* @__PURE__ */ new Set();
692
693
  function createJoinWorldAction(config) {
693
694
  return {
694
695
  name: "join_world",
@@ -699,6 +700,12 @@ function createJoinWorldAction(config) {
699
700
  if (!worldUrl) {
700
701
  return { success: false, error: 'Parameter "worldUrl" is required' };
701
702
  }
703
+ if (joinedWorlds.has(worldUrl)) {
704
+ return {
705
+ success: true,
706
+ data: { message: "Already joined this world", worldUrl }
707
+ };
708
+ }
702
709
  const agentPort = process.env.PORT || "3000";
703
710
  const agentHost = process.env.HOST || "localhost";
704
711
  const agentUrl = `http://${agentHost}:${agentPort}`;
@@ -706,42 +713,44 @@ function createJoinWorldAction(config) {
706
713
  try {
707
714
  const { default: axios2 } = await import("axios");
708
715
  let paymentTxHash;
716
+ let joinInfo = null;
709
717
  try {
710
718
  const infoRes = await axios2.get(`${worldUrl}/world/join-info`, { timeout: 5e3 });
711
- const joinInfo = infoRes.data;
712
- if (joinInfo.requiresPayment && joinInfo.entryFee && joinInfo.entryFee !== "0") {
713
- const privateKey = agent?.config?.world?.privateKey;
714
- if (!privateKey) {
715
- return {
716
- success: false,
717
- error: "World requires entry fee but agent has no wallet private key configured. Set AGENT_WALLET_PRIVATE_KEY in your .env file."
718
- };
719
- }
720
- logger4.info(`World requires entry fee: ${joinInfo.entryFee} wei`);
721
- const { AgentWallet: AgentWallet2 } = await Promise.resolve().then(() => (init_AgentWallet(), AgentWallet_exports));
722
- const wallet = new AgentWallet2(privateKey, joinInfo.rpcUrl);
723
- const balance = await wallet.getBalance();
724
- if (BigInt(balance) < BigInt(joinInfo.entryFee)) {
725
- const { formatEther } = await import("ethers");
726
- return {
727
- success: false,
728
- error: `Insufficient balance to pay entry fee. Need ${formatEther(joinInfo.entryFee)} MON, have ${formatEther(balance)} MON`
729
- };
730
- }
731
- logger4.info(`Paying entry fee to ${joinInfo.paymentAddress}...`);
732
- paymentTxHash = await wallet.sendPayment(joinInfo.paymentAddress, joinInfo.entryFee);
733
- logger4.info(`Entry fee paid. TX: ${paymentTxHash}`);
734
- }
719
+ joinInfo = infoRes.data;
735
720
  } catch (infoError) {
736
721
  if (infoError?.response?.status !== 404) {
737
722
  logger4.debug(`Could not query join-info: ${infoError.message}`);
738
723
  }
739
724
  }
725
+ if (joinInfo?.requiresPayment && joinInfo.entryFee && joinInfo.entryFee !== "0") {
726
+ const privateKey = agent?.config?.world?.privateKey;
727
+ if (!privateKey) {
728
+ return {
729
+ success: false,
730
+ error: "World requires entry fee but agent has no wallet private key configured. Set AGENT_WALLET_PRIVATE_KEY in your .env file."
731
+ };
732
+ }
733
+ logger4.info(`World requires entry fee: ${joinInfo.entryFee} wei`);
734
+ const { AgentWallet: AgentWallet2 } = await Promise.resolve().then(() => (init_AgentWallet(), AgentWallet_exports));
735
+ const wallet = new AgentWallet2(privateKey, joinInfo.rpcUrl);
736
+ const balance = await wallet.getBalance();
737
+ if (BigInt(balance) < BigInt(joinInfo.entryFee)) {
738
+ const { formatEther } = await import("ethers");
739
+ return {
740
+ success: false,
741
+ error: `Insufficient balance to pay entry fee. Need ${formatEther(joinInfo.entryFee)} MON, have ${formatEther(balance)} MON`
742
+ };
743
+ }
744
+ logger4.info(`Paying entry fee to ${joinInfo.paymentAddress}...`);
745
+ paymentTxHash = await wallet.sendPayment(joinInfo.paymentAddress, joinInfo.entryFee);
746
+ logger4.info(`Entry fee paid. TX: ${paymentTxHash}`);
747
+ }
740
748
  const response = await axios2.post(`${worldUrl}/world/join`, {
741
749
  agentUrl,
742
750
  walletAddress,
743
751
  paymentTxHash
744
752
  }, { timeout: 1e4 });
753
+ joinedWorlds.add(worldUrl);
745
754
  return {
746
755
  success: true,
747
756
  data: response.data
@@ -772,6 +781,7 @@ function createLeaveWorldAction(config) {
772
781
  `${worldUrl}/world/agents/${encodeURIComponent(agentUrl)}`,
773
782
  { timeout: 1e4 }
774
783
  );
784
+ joinedWorlds.delete(worldUrl);
775
785
  return {
776
786
  success: true,
777
787
  data: response.data