@moltium/core 0.1.30 → 0.1.31
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 +34 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -413,6 +413,7 @@ var moltbookActions = [
|
|
|
413
413
|
|
|
414
414
|
// src/actions/built-in/world.ts
|
|
415
415
|
var logger3 = createLogger("WorldActions");
|
|
416
|
+
var joinedWorlds = /* @__PURE__ */ new Set();
|
|
416
417
|
function createJoinWorldAction(config) {
|
|
417
418
|
return {
|
|
418
419
|
name: "join_world",
|
|
@@ -423,6 +424,12 @@ function createJoinWorldAction(config) {
|
|
|
423
424
|
if (!worldUrl) {
|
|
424
425
|
return { success: false, error: 'Parameter "worldUrl" is required' };
|
|
425
426
|
}
|
|
427
|
+
if (joinedWorlds.has(worldUrl)) {
|
|
428
|
+
return {
|
|
429
|
+
success: true,
|
|
430
|
+
data: { message: "Already joined this world", worldUrl }
|
|
431
|
+
};
|
|
432
|
+
}
|
|
426
433
|
const agentPort = process.env.PORT || "3000";
|
|
427
434
|
const agentHost = process.env.HOST || "localhost";
|
|
428
435
|
const agentUrl = `http://${agentHost}:${agentPort}`;
|
|
@@ -430,42 +437,44 @@ function createJoinWorldAction(config) {
|
|
|
430
437
|
try {
|
|
431
438
|
const { default: axios2 } = await import("axios");
|
|
432
439
|
let paymentTxHash;
|
|
440
|
+
let joinInfo = null;
|
|
433
441
|
try {
|
|
434
442
|
const infoRes = await axios2.get(`${worldUrl}/world/join-info`, { timeout: 5e3 });
|
|
435
|
-
|
|
436
|
-
if (joinInfo.requiresPayment && joinInfo.entryFee && joinInfo.entryFee !== "0") {
|
|
437
|
-
const privateKey = agent?.config?.world?.privateKey;
|
|
438
|
-
if (!privateKey) {
|
|
439
|
-
return {
|
|
440
|
-
success: false,
|
|
441
|
-
error: "World requires entry fee but agent has no wallet private key configured. Set AGENT_WALLET_PRIVATE_KEY in your .env file."
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
logger3.info(`World requires entry fee: ${joinInfo.entryFee} wei`);
|
|
445
|
-
const { AgentWallet: AgentWallet2 } = await import("./AgentWallet-WSXDC5NX.mjs");
|
|
446
|
-
const wallet = new AgentWallet2(privateKey, joinInfo.rpcUrl);
|
|
447
|
-
const balance = await wallet.getBalance();
|
|
448
|
-
if (BigInt(balance) < BigInt(joinInfo.entryFee)) {
|
|
449
|
-
const { formatEther } = await import("ethers");
|
|
450
|
-
return {
|
|
451
|
-
success: false,
|
|
452
|
-
error: `Insufficient balance to pay entry fee. Need ${formatEther(joinInfo.entryFee)} MON, have ${formatEther(balance)} MON`
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
logger3.info(`Paying entry fee to ${joinInfo.paymentAddress}...`);
|
|
456
|
-
paymentTxHash = await wallet.sendPayment(joinInfo.paymentAddress, joinInfo.entryFee);
|
|
457
|
-
logger3.info(`Entry fee paid. TX: ${paymentTxHash}`);
|
|
458
|
-
}
|
|
443
|
+
joinInfo = infoRes.data;
|
|
459
444
|
} catch (infoError) {
|
|
460
445
|
if (infoError?.response?.status !== 404) {
|
|
461
446
|
logger3.debug(`Could not query join-info: ${infoError.message}`);
|
|
462
447
|
}
|
|
463
448
|
}
|
|
449
|
+
if (joinInfo?.requiresPayment && joinInfo.entryFee && joinInfo.entryFee !== "0") {
|
|
450
|
+
const privateKey = agent?.config?.world?.privateKey;
|
|
451
|
+
if (!privateKey) {
|
|
452
|
+
return {
|
|
453
|
+
success: false,
|
|
454
|
+
error: "World requires entry fee but agent has no wallet private key configured. Set AGENT_WALLET_PRIVATE_KEY in your .env file."
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
logger3.info(`World requires entry fee: ${joinInfo.entryFee} wei`);
|
|
458
|
+
const { AgentWallet: AgentWallet2 } = await import("./AgentWallet-WSXDC5NX.mjs");
|
|
459
|
+
const wallet = new AgentWallet2(privateKey, joinInfo.rpcUrl);
|
|
460
|
+
const balance = await wallet.getBalance();
|
|
461
|
+
if (BigInt(balance) < BigInt(joinInfo.entryFee)) {
|
|
462
|
+
const { formatEther } = await import("ethers");
|
|
463
|
+
return {
|
|
464
|
+
success: false,
|
|
465
|
+
error: `Insufficient balance to pay entry fee. Need ${formatEther(joinInfo.entryFee)} MON, have ${formatEther(balance)} MON`
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
logger3.info(`Paying entry fee to ${joinInfo.paymentAddress}...`);
|
|
469
|
+
paymentTxHash = await wallet.sendPayment(joinInfo.paymentAddress, joinInfo.entryFee);
|
|
470
|
+
logger3.info(`Entry fee paid. TX: ${paymentTxHash}`);
|
|
471
|
+
}
|
|
464
472
|
const response = await axios2.post(`${worldUrl}/world/join`, {
|
|
465
473
|
agentUrl,
|
|
466
474
|
walletAddress,
|
|
467
475
|
paymentTxHash
|
|
468
476
|
}, { timeout: 1e4 });
|
|
477
|
+
joinedWorlds.add(worldUrl);
|
|
469
478
|
return {
|
|
470
479
|
success: true,
|
|
471
480
|
data: response.data
|
|
@@ -496,6 +505,7 @@ function createLeaveWorldAction(config) {
|
|
|
496
505
|
`${worldUrl}/world/agents/${encodeURIComponent(agentUrl)}`,
|
|
497
506
|
{ timeout: 1e4 }
|
|
498
507
|
);
|
|
508
|
+
joinedWorlds.delete(worldUrl);
|
|
499
509
|
return {
|
|
500
510
|
success: true,
|
|
501
511
|
data: response.data
|