@moltium/world-core 0.1.21 → 0.1.23
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/{CardFetcher-3QKJ2I5P.js → CardFetcher-IMUPYNEQ.js} +2 -2
- package/dist/CardFetcher-ZD4YSGJE.cjs +9 -0
- package/dist/{CardFetcher-AR7IANM7.cjs.map → CardFetcher-ZD4YSGJE.cjs.map} +1 -1
- package/dist/{chunk-NEXCYEQT.cjs → chunk-WI7EASJJ.cjs} +31 -7
- package/dist/chunk-WI7EASJJ.cjs.map +1 -0
- package/dist/{chunk-JW3PZRCW.js → chunk-Y563WZWH.js} +31 -7
- package/dist/chunk-Y563WZWH.js.map +1 -0
- package/dist/index.cjs +265 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -66
- package/dist/index.d.ts +89 -66
- package/dist/index.js +224 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/CardFetcher-AR7IANM7.cjs +0 -9
- package/dist/chunk-JW3PZRCW.js.map +0 -1
- package/dist/chunk-NEXCYEQT.cjs.map +0 -1
- /package/dist/{CardFetcher-3QKJ2I5P.js.map → CardFetcher-IMUPYNEQ.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkWI7EASJJcjs = require('./chunk-WI7EASJJ.cjs');
|
|
7
7
|
|
|
8
8
|
// src/config/types.ts
|
|
9
9
|
function profileFromCard(card, walletAddress) {
|
|
@@ -430,7 +430,7 @@ async function createLevelDBAdapter(config) {
|
|
|
430
430
|
var _uuid = require('uuid');
|
|
431
431
|
|
|
432
432
|
// src/discovery/AgentEvaluator.ts
|
|
433
|
-
var logger2 =
|
|
433
|
+
var logger2 = _chunkWI7EASJJcjs.createLogger.call(void 0, "AgentEvaluator");
|
|
434
434
|
var AgentEvaluator = class {
|
|
435
435
|
constructor(rules) {
|
|
436
436
|
this.rules = rules;
|
|
@@ -544,7 +544,7 @@ var AgentEvaluator = class {
|
|
|
544
544
|
|
|
545
545
|
// src/blockchain/BlockchainClient.ts
|
|
546
546
|
var _ethers = require('ethers');
|
|
547
|
-
var logger3 =
|
|
547
|
+
var logger3 = _chunkWI7EASJJcjs.createLogger.call(void 0, "BlockchainClient");
|
|
548
548
|
var AGENT_REGISTRY_ABI = [
|
|
549
549
|
"function registerAgent(string agentUrl, string name) external",
|
|
550
550
|
"function isAgentValid(address wallet) external view returns (bool)",
|
|
@@ -567,8 +567,8 @@ var WORLD_TOKEN_ABI = [
|
|
|
567
567
|
"function balanceOf(address account) external view returns (uint256)",
|
|
568
568
|
"function transfer(address to, uint256 amount) external returns (bool)"
|
|
569
569
|
];
|
|
570
|
-
var BlockchainClient = class {
|
|
571
|
-
constructor(config) {
|
|
570
|
+
var BlockchainClient = (_class2 = class {
|
|
571
|
+
constructor(config) {;_class2.prototype.__init4.call(this);
|
|
572
572
|
this.config = config;
|
|
573
573
|
this.provider = new _ethers.ethers.JsonRpcProvider(config.rpcUrl);
|
|
574
574
|
this.wallet = new _ethers.ethers.Wallet(config.privateKey, this.provider);
|
|
@@ -766,7 +766,7 @@ var BlockchainClient = class {
|
|
|
766
766
|
return this.wallet.address;
|
|
767
767
|
}
|
|
768
768
|
/**
|
|
769
|
-
* Get entry fee in MON
|
|
769
|
+
* Get entry fee in MON (formatted)
|
|
770
770
|
*/
|
|
771
771
|
async getEntryFee() {
|
|
772
772
|
if (!this.membershipContract) {
|
|
@@ -780,24 +780,97 @@ var BlockchainClient = class {
|
|
|
780
780
|
return "0";
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Get entry fee in wei (raw BigInt string)
|
|
785
|
+
*/
|
|
786
|
+
async getEntryFeeWei() {
|
|
787
|
+
if (!this.membershipContract) {
|
|
788
|
+
return "0";
|
|
789
|
+
}
|
|
790
|
+
try {
|
|
791
|
+
const fee = await this.membershipContract.entryFee();
|
|
792
|
+
return fee.toString();
|
|
793
|
+
} catch (error) {
|
|
794
|
+
logger3.error("Failed to get entry fee (wei)", { error: error.message });
|
|
795
|
+
return "0";
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
// Track used payment tx hashes to prevent replay attacks
|
|
799
|
+
__init4() {this.usedPayments = /* @__PURE__ */ new Set()}
|
|
800
|
+
/**
|
|
801
|
+
* Verify a payment transaction from an agent.
|
|
802
|
+
* Checks: tx confirmed, correct sender, correct recipient (world wallet), sufficient amount.
|
|
803
|
+
* Prevents replay attacks by tracking used tx hashes.
|
|
804
|
+
*/
|
|
805
|
+
async verifyPayment(txHash, expectedSender, expectedAmountWei) {
|
|
806
|
+
const normalizedHash = txHash.toLowerCase();
|
|
807
|
+
if (this.usedPayments.has(normalizedHash)) {
|
|
808
|
+
logger3.warn("Payment verification: transaction already used", { txHash });
|
|
809
|
+
return false;
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
const receipt = await this.provider.getTransactionReceipt(txHash);
|
|
813
|
+
if (!receipt || receipt.status !== 1) {
|
|
814
|
+
logger3.warn("Payment verification: transaction not confirmed or failed", { txHash });
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
const tx = await this.provider.getTransaction(txHash);
|
|
818
|
+
if (!tx) {
|
|
819
|
+
logger3.warn("Payment verification: transaction not found", { txHash });
|
|
820
|
+
return false;
|
|
821
|
+
}
|
|
822
|
+
if (tx.from.toLowerCase() !== expectedSender.toLowerCase()) {
|
|
823
|
+
logger3.warn("Payment verification: wrong sender", {
|
|
824
|
+
expected: expectedSender,
|
|
825
|
+
actual: tx.from
|
|
826
|
+
});
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
if (_optionalChain([tx, 'access', _13 => _13.to, 'optionalAccess', _14 => _14.toLowerCase, 'call', _15 => _15()]) !== this.wallet.address.toLowerCase()) {
|
|
830
|
+
logger3.warn("Payment verification: wrong recipient", {
|
|
831
|
+
expected: this.wallet.address,
|
|
832
|
+
actual: tx.to
|
|
833
|
+
});
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
if (tx.value < BigInt(expectedAmountWei)) {
|
|
837
|
+
logger3.warn("Payment verification: insufficient amount", {
|
|
838
|
+
expected: expectedAmountWei,
|
|
839
|
+
actual: tx.value.toString()
|
|
840
|
+
});
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
this.usedPayments.add(normalizedHash);
|
|
844
|
+
logger3.info("Payment verified successfully", {
|
|
845
|
+
txHash,
|
|
846
|
+
sender: tx.from,
|
|
847
|
+
amount: _ethers.ethers.formatEther(tx.value)
|
|
848
|
+
});
|
|
849
|
+
return true;
|
|
850
|
+
} catch (error) {
|
|
851
|
+
logger3.error("Payment verification error", { txHash, error: error.message });
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}, _class2);
|
|
784
856
|
|
|
785
857
|
// src/a2a/WorldA2AClient.ts
|
|
786
858
|
var _core = require('@moltium/core');
|
|
787
|
-
var logger4 =
|
|
788
|
-
var WorldA2AClient = (
|
|
789
|
-
|
|
859
|
+
var logger4 = _chunkWI7EASJJcjs.createLogger.call(void 0, "WorldA2AClient");
|
|
860
|
+
var WorldA2AClient = (_class3 = class {constructor() { _class3.prototype.__init5.call(this); }
|
|
861
|
+
__init5() {this.clients = /* @__PURE__ */ new Map()}
|
|
790
862
|
/**
|
|
791
863
|
* Add an agent to the client pool
|
|
792
864
|
*/
|
|
793
865
|
addAgent(agentUrl) {
|
|
794
|
-
|
|
795
|
-
|
|
866
|
+
const baseUrl = this.extractBaseUrl(agentUrl);
|
|
867
|
+
if (this.clients.has(baseUrl)) {
|
|
868
|
+
logger4.debug(`Agent already in client pool: ${baseUrl}`);
|
|
796
869
|
return;
|
|
797
870
|
}
|
|
798
|
-
const client = new (0, _core.A2AClient)({ agentUrl });
|
|
799
|
-
this.clients.set(
|
|
800
|
-
logger4.info(`Added agent to A2A client pool: ${
|
|
871
|
+
const client = new (0, _core.A2AClient)({ agentUrl: baseUrl });
|
|
872
|
+
this.clients.set(baseUrl, client);
|
|
873
|
+
logger4.info(`Added agent to A2A client pool: ${baseUrl}`);
|
|
801
874
|
}
|
|
802
875
|
/**
|
|
803
876
|
* Remove an agent from the client pool
|
|
@@ -826,7 +899,7 @@ var WorldA2AClient = (_class2 = class {constructor() { _class2.prototype.__init4
|
|
|
826
899
|
logger4.error(`Failed to send A2A message to ${agentUrl}:`, error);
|
|
827
900
|
return {
|
|
828
901
|
success: false,
|
|
829
|
-
error: _optionalChain([error, 'optionalAccess',
|
|
902
|
+
error: _optionalChain([error, 'optionalAccess', _16 => _16.message]) || String(error),
|
|
830
903
|
agentUrl
|
|
831
904
|
};
|
|
832
905
|
}
|
|
@@ -867,12 +940,23 @@ var WorldA2AClient = (_class2 = class {constructor() { _class2.prototype.__init4
|
|
|
867
940
|
getAgentUrls() {
|
|
868
941
|
return Array.from(this.clients.keys());
|
|
869
942
|
}
|
|
870
|
-
|
|
943
|
+
/**
|
|
944
|
+
* Extract base URL (protocol://host:port) from a full URL
|
|
945
|
+
*/
|
|
946
|
+
extractBaseUrl(url) {
|
|
947
|
+
try {
|
|
948
|
+
const parsed = new URL(url);
|
|
949
|
+
return `${parsed.protocol}//${parsed.host}`;
|
|
950
|
+
} catch (e4) {
|
|
951
|
+
return url;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}, _class3);
|
|
871
955
|
|
|
872
956
|
// src/engine/WorldActions.ts
|
|
873
|
-
var logger5 =
|
|
874
|
-
var WorldActionsRegistry = (
|
|
875
|
-
|
|
957
|
+
var logger5 = _chunkWI7EASJJcjs.createLogger.call(void 0, "WorldActions");
|
|
958
|
+
var WorldActionsRegistry = (_class4 = class {constructor() { _class4.prototype.__init6.call(this); }
|
|
959
|
+
__init6() {this.actions = /* @__PURE__ */ new Map()}
|
|
876
960
|
/**
|
|
877
961
|
* Register a world action
|
|
878
962
|
*/
|
|
@@ -962,11 +1046,11 @@ var WorldActionsRegistry = (_class3 = class {constructor() { _class3.prototype._
|
|
|
962
1046
|
...a.parameters && { parameters: a.parameters }
|
|
963
1047
|
}));
|
|
964
1048
|
}
|
|
965
|
-
},
|
|
1049
|
+
}, _class4);
|
|
966
1050
|
|
|
967
1051
|
// src/engine/ActionProcessor.ts
|
|
968
1052
|
|
|
969
|
-
var logger6 =
|
|
1053
|
+
var logger6 = _chunkWI7EASJJcjs.createLogger.call(void 0, "ActionProcessor");
|
|
970
1054
|
var ActionProcessor = class {
|
|
971
1055
|
constructor(rules, actionsRegistry) {
|
|
972
1056
|
this.rules = rules;
|
|
@@ -1068,16 +1152,16 @@ var ActionProcessor = class {
|
|
|
1068
1152
|
|
|
1069
1153
|
// src/engine/TickOrchestrator.ts
|
|
1070
1154
|
|
|
1071
|
-
var logger7 =
|
|
1155
|
+
var logger7 = _chunkWI7EASJJcjs.createLogger.call(void 0, "TickOrchestrator");
|
|
1072
1156
|
var TickOrchestrator = class {
|
|
1073
1157
|
constructor(a2aClient, actionsRegistry, rules, config) {
|
|
1074
1158
|
this.a2aClient = a2aClient;
|
|
1075
1159
|
this.actionsRegistry = actionsRegistry;
|
|
1076
1160
|
this.actionProcessor = new ActionProcessor(rules, actionsRegistry);
|
|
1077
1161
|
this.orchestrationConfig = {
|
|
1078
|
-
broadcastOnTick: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1079
|
-
tickTimeout: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1080
|
-
promptTemplate: _optionalChain([config, 'optionalAccess',
|
|
1162
|
+
broadcastOnTick: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _17 => _17.broadcastOnTick]), () => ( true)),
|
|
1163
|
+
tickTimeout: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _18 => _18.tickTimeout]), () => ( 1e4)),
|
|
1164
|
+
promptTemplate: _optionalChain([config, 'optionalAccess', _19 => _19.promptTemplate])
|
|
1081
1165
|
};
|
|
1082
1166
|
}
|
|
1083
1167
|
|
|
@@ -1211,7 +1295,7 @@ var TickOrchestrator = class {
|
|
|
1211
1295
|
parameters: parsed.parameters || {},
|
|
1212
1296
|
message: parsed.message
|
|
1213
1297
|
};
|
|
1214
|
-
} catch (
|
|
1298
|
+
} catch (e5) {
|
|
1215
1299
|
return {
|
|
1216
1300
|
agentUrl,
|
|
1217
1301
|
message: reply
|
|
@@ -1233,7 +1317,19 @@ var TickOrchestrator = class {
|
|
|
1233
1317
|
};
|
|
1234
1318
|
|
|
1235
1319
|
// src/a2a/MessageRouter.ts
|
|
1236
|
-
var logger8 =
|
|
1320
|
+
var logger8 = _chunkWI7EASJJcjs.createLogger.call(void 0, "MessageRouter");
|
|
1321
|
+
var c = {
|
|
1322
|
+
reset: "\x1B[0m",
|
|
1323
|
+
bold: "\x1B[1m",
|
|
1324
|
+
dim: "\x1B[2m",
|
|
1325
|
+
blue: "\x1B[34m",
|
|
1326
|
+
green: "\x1B[32m",
|
|
1327
|
+
yellow: "\x1B[33m",
|
|
1328
|
+
magenta: "\x1B[35m",
|
|
1329
|
+
cyan: "\x1B[36m",
|
|
1330
|
+
red: "\x1B[31m",
|
|
1331
|
+
gray: "\x1B[90m"
|
|
1332
|
+
};
|
|
1237
1333
|
var MessageRouter = class {
|
|
1238
1334
|
constructor(a2aClient, getAgents) {
|
|
1239
1335
|
this.a2aClient = a2aClient;
|
|
@@ -1246,6 +1342,7 @@ var MessageRouter = class {
|
|
|
1246
1342
|
const agents = this.getAgents();
|
|
1247
1343
|
const sender = agents.find((a) => a.url === fromAgentUrl);
|
|
1248
1344
|
if (!sender) {
|
|
1345
|
+
logger8.warn(`Message rejected \u2014 sender not in world: ${fromAgentUrl}`);
|
|
1249
1346
|
return {
|
|
1250
1347
|
success: false,
|
|
1251
1348
|
error: `Sender not in world: ${fromAgentUrl}`
|
|
@@ -1253,11 +1350,19 @@ var MessageRouter = class {
|
|
|
1253
1350
|
}
|
|
1254
1351
|
const recipient = agents.find((a) => a.url === toAgentUrl);
|
|
1255
1352
|
if (!recipient) {
|
|
1353
|
+
logger8.warn(`Message rejected \u2014 recipient not in world: ${toAgentUrl}`);
|
|
1256
1354
|
return {
|
|
1257
1355
|
success: false,
|
|
1258
1356
|
error: `Recipient not in world: ${toAgentUrl}`
|
|
1259
1357
|
};
|
|
1260
1358
|
}
|
|
1359
|
+
console.log(
|
|
1360
|
+
`
|
|
1361
|
+
${c.cyan}\u2501\u2501\u2501 MESSAGE \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${c.reset}
|
|
1362
|
+
${c.bold}${c.blue}${sender.name}${c.reset} ${c.dim}\u2192${c.reset} ${c.bold}${c.green}${recipient.name}${c.reset}
|
|
1363
|
+
${c.dim}\u2502${c.reset} ${this.truncate(message, 300)}
|
|
1364
|
+
${c.cyan}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${c.reset}`
|
|
1365
|
+
);
|
|
1261
1366
|
const wrappedMessage = JSON.stringify({
|
|
1262
1367
|
type: "world_message",
|
|
1263
1368
|
from: {
|
|
@@ -1267,11 +1372,24 @@ var MessageRouter = class {
|
|
|
1267
1372
|
},
|
|
1268
1373
|
message
|
|
1269
1374
|
});
|
|
1270
|
-
|
|
1271
|
-
return this.a2aClient.sendToAgent(toAgentUrl, wrappedMessage, {
|
|
1375
|
+
const response = await this.a2aClient.sendToAgent(toAgentUrl, wrappedMessage, {
|
|
1272
1376
|
type: "world_message",
|
|
1273
1377
|
fromAgentUrl
|
|
1274
1378
|
});
|
|
1379
|
+
if (response.success && response.reply) {
|
|
1380
|
+
console.log(
|
|
1381
|
+
`
|
|
1382
|
+
${c.green}\u2501\u2501\u2501 REPLY \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${c.reset}
|
|
1383
|
+
${c.bold}${c.green}${recipient.name}${c.reset} ${c.dim}\u2192${c.reset} ${c.bold}${c.blue}${sender.name}${c.reset}
|
|
1384
|
+
${c.dim}\u2502${c.reset} ${this.truncate(response.reply, 300)}
|
|
1385
|
+
${c.green}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${c.reset}`
|
|
1386
|
+
);
|
|
1387
|
+
} else if (!response.success) {
|
|
1388
|
+
console.log(
|
|
1389
|
+
`${c.red} \u2717 ${recipient.name} failed to respond: ${response.error || "no response"}${c.reset}`
|
|
1390
|
+
);
|
|
1391
|
+
}
|
|
1392
|
+
return response;
|
|
1275
1393
|
}
|
|
1276
1394
|
/**
|
|
1277
1395
|
* Broadcast a message from one agent to all other agents in the world
|
|
@@ -1280,6 +1398,7 @@ var MessageRouter = class {
|
|
|
1280
1398
|
const agents = this.getAgents();
|
|
1281
1399
|
const sender = agents.find((a) => a.url === fromAgentUrl);
|
|
1282
1400
|
if (!sender) {
|
|
1401
|
+
logger8.warn(`Broadcast rejected \u2014 sender not in world: ${fromAgentUrl}`);
|
|
1283
1402
|
const result = /* @__PURE__ */ new Map();
|
|
1284
1403
|
result.set(fromAgentUrl, {
|
|
1285
1404
|
success: false,
|
|
@@ -1287,6 +1406,14 @@ var MessageRouter = class {
|
|
|
1287
1406
|
});
|
|
1288
1407
|
return result;
|
|
1289
1408
|
}
|
|
1409
|
+
const recipients = agents.filter((a) => a.url !== fromAgentUrl);
|
|
1410
|
+
console.log(
|
|
1411
|
+
`
|
|
1412
|
+
${c.yellow}\u2501\u2501\u2501 BROADCAST \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${c.reset}
|
|
1413
|
+
${c.bold}${c.blue}${sender.name}${c.reset} ${c.dim}\u2192${c.reset} ${c.bold}${c.yellow}ALL (${recipients.length} agents)${c.reset}
|
|
1414
|
+
${c.dim}\u2502${c.reset} ${this.truncate(message, 300)}
|
|
1415
|
+
${c.yellow}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${c.reset}`
|
|
1416
|
+
);
|
|
1290
1417
|
const wrappedMessage = JSON.stringify({
|
|
1291
1418
|
type: "world_broadcast",
|
|
1292
1419
|
from: {
|
|
@@ -1297,7 +1424,6 @@ var MessageRouter = class {
|
|
|
1297
1424
|
message
|
|
1298
1425
|
});
|
|
1299
1426
|
const results = /* @__PURE__ */ new Map();
|
|
1300
|
-
const recipients = agents.filter((a) => a.url !== fromAgentUrl);
|
|
1301
1427
|
const promises = recipients.map(async (recipient) => {
|
|
1302
1428
|
const response = await this.a2aClient.sendToAgent(
|
|
1303
1429
|
recipient.url,
|
|
@@ -1305,17 +1431,38 @@ var MessageRouter = class {
|
|
|
1305
1431
|
{ type: "world_broadcast", fromAgentUrl }
|
|
1306
1432
|
);
|
|
1307
1433
|
results.set(recipient.url, response);
|
|
1434
|
+
if (response.success && response.reply) {
|
|
1435
|
+
console.log(
|
|
1436
|
+
`${c.green} \u21A9 ${c.bold}${recipient.name}${c.reset}${c.green} replied:${c.reset} ${this.truncate(response.reply, 200)}`
|
|
1437
|
+
);
|
|
1438
|
+
} else if (!response.success) {
|
|
1439
|
+
console.log(
|
|
1440
|
+
`${c.red} \u2717 ${recipient.name} failed: ${response.error || "no response"}${c.reset}`
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1308
1443
|
});
|
|
1309
1444
|
await Promise.allSettled(promises);
|
|
1310
|
-
|
|
1445
|
+
const succeeded = Array.from(results.values()).filter((r) => r.success).length;
|
|
1446
|
+
const failed = Array.from(results.values()).filter((r) => !r.success).length;
|
|
1447
|
+
console.log(
|
|
1448
|
+
`${c.dim} Broadcast complete: ${c.green}${succeeded} replied${c.reset}${c.dim}${failed > 0 ? `, ${c.red}${failed} failed${c.reset}` : ""}${c.reset}
|
|
1449
|
+
`
|
|
1450
|
+
);
|
|
1311
1451
|
return results;
|
|
1312
1452
|
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Truncate long messages for logging
|
|
1455
|
+
*/
|
|
1456
|
+
truncate(text, maxLen) {
|
|
1457
|
+
if (text.length <= maxLen) return text;
|
|
1458
|
+
return text.slice(0, maxLen) + "...";
|
|
1459
|
+
}
|
|
1313
1460
|
};
|
|
1314
1461
|
|
|
1315
1462
|
// src/engine/World.ts
|
|
1316
|
-
var logger9 =
|
|
1317
|
-
var World = (
|
|
1318
|
-
constructor(config) {;
|
|
1463
|
+
var logger9 = _chunkWI7EASJJcjs.createLogger.call(void 0, "World");
|
|
1464
|
+
var World = (_class5 = class {
|
|
1465
|
+
constructor(config) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);_class5.prototype.__init9.call(this);_class5.prototype.__init10.call(this);
|
|
1319
1466
|
this.config = config;
|
|
1320
1467
|
validateWorldConfig(config);
|
|
1321
1468
|
this.state = {
|
|
@@ -1326,7 +1473,7 @@ var World = (_class4 = class {
|
|
|
1326
1473
|
metadata: {}
|
|
1327
1474
|
};
|
|
1328
1475
|
this.agents = /* @__PURE__ */ new Map();
|
|
1329
|
-
this.cardFetcher = new (0,
|
|
1476
|
+
this.cardFetcher = new (0, _chunkWI7EASJJcjs.CardFetcher)();
|
|
1330
1477
|
this.evaluator = new AgentEvaluator(config.admission);
|
|
1331
1478
|
this.a2aClient = new WorldA2AClient();
|
|
1332
1479
|
this.actionsRegistry = new WorldActionsRegistry();
|
|
@@ -1347,17 +1494,17 @@ var World = (_class4 = class {
|
|
|
1347
1494
|
logger9.info(`World "${config.name}" created`, {
|
|
1348
1495
|
type: config.type || "generic",
|
|
1349
1496
|
maxAgents: config.admission.maxAgents,
|
|
1350
|
-
orchestration: !!_optionalChain([config, 'access',
|
|
1497
|
+
orchestration: !!_optionalChain([config, 'access', _20 => _20.orchestration, 'optionalAccess', _21 => _21.broadcastOnTick])
|
|
1351
1498
|
});
|
|
1352
1499
|
}
|
|
1353
1500
|
|
|
1354
1501
|
|
|
1355
|
-
|
|
1356
|
-
|
|
1502
|
+
__init7() {this.persistence = null}
|
|
1503
|
+
__init8() {this.blockchainClient = null}
|
|
1357
1504
|
|
|
1358
1505
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1506
|
+
__init9() {this.tickInterval = null}
|
|
1507
|
+
__init10() {this.autoSaveInterval = null}
|
|
1361
1508
|
// Agent-World bridge components
|
|
1362
1509
|
|
|
1363
1510
|
|
|
@@ -1413,7 +1560,7 @@ var World = (_class4 = class {
|
|
|
1413
1560
|
this.setState("ready");
|
|
1414
1561
|
logger9.info("World initialized successfully", {
|
|
1415
1562
|
agents: this.agents.size,
|
|
1416
|
-
persistence: _optionalChain([this, 'access',
|
|
1563
|
+
persistence: _optionalChain([this, 'access', _22 => _22.config, 'access', _23 => _23.persistence, 'optionalAccess', _24 => _24.type]) || "none"
|
|
1417
1564
|
});
|
|
1418
1565
|
} catch (error) {
|
|
1419
1566
|
logger9.error("Failed to initialize world:", error);
|
|
@@ -1436,7 +1583,7 @@ var World = (_class4 = class {
|
|
|
1436
1583
|
type: "world_started",
|
|
1437
1584
|
timestamp: Date.now()
|
|
1438
1585
|
});
|
|
1439
|
-
if (_optionalChain([this, 'access',
|
|
1586
|
+
if (_optionalChain([this, 'access', _25 => _25.config, 'access', _26 => _26.simulation, 'optionalAccess', _27 => _27.tickIntervalMs])) {
|
|
1440
1587
|
this.startTicking();
|
|
1441
1588
|
}
|
|
1442
1589
|
}
|
|
@@ -1464,24 +1611,52 @@ var World = (_class4 = class {
|
|
|
1464
1611
|
});
|
|
1465
1612
|
logger9.info("World stopped");
|
|
1466
1613
|
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Get the blockchain client (for server endpoints)
|
|
1616
|
+
*/
|
|
1617
|
+
getBlockchainClient() {
|
|
1618
|
+
return this.blockchainClient;
|
|
1619
|
+
}
|
|
1467
1620
|
/**
|
|
1468
1621
|
* Admit an agent to the world
|
|
1469
1622
|
*/
|
|
1470
|
-
async admitAgent(card, walletAddress) {
|
|
1623
|
+
async admitAgent(card, walletAddress, paymentTxHash) {
|
|
1471
1624
|
const decision = await this.evaluator.evaluate(card, this.agents.size, walletAddress);
|
|
1472
1625
|
if (!decision.admitted) {
|
|
1473
1626
|
throw new Error(`Agent admission denied: ${decision.reason}`);
|
|
1474
1627
|
}
|
|
1475
|
-
if (this.blockchainClient && _optionalChain([this, 'access',
|
|
1628
|
+
if (this.blockchainClient && _optionalChain([this, 'access', _28 => _28.config, 'access', _29 => _29.blockchain, 'optionalAccess', _30 => _30.enforceOnChainValidation]) && walletAddress) {
|
|
1476
1629
|
const isValid = await this.blockchainClient.validateAgent(walletAddress);
|
|
1477
1630
|
if (!isValid) {
|
|
1478
1631
|
throw new Error("Agent not registered in on-chain AgentRegistry");
|
|
1479
1632
|
}
|
|
1480
1633
|
logger9.info(`Agent validated on-chain: ${card.name}`);
|
|
1481
1634
|
}
|
|
1482
|
-
if (this.blockchainClient && _optionalChain([this, 'access',
|
|
1635
|
+
if (this.blockchainClient && _optionalChain([this, 'access', _31 => _31.config, 'access', _32 => _32.blockchain, 'optionalAccess', _33 => _33.requireMembership]) && walletAddress) {
|
|
1483
1636
|
const hasMembership = await this.blockchainClient.hasMembership(walletAddress);
|
|
1484
1637
|
if (!hasMembership) {
|
|
1638
|
+
const entryFeeWei = await this.blockchainClient.getEntryFeeWei();
|
|
1639
|
+
if (entryFeeWei !== "0" && BigInt(entryFeeWei) > 0n) {
|
|
1640
|
+
if (!paymentTxHash) {
|
|
1641
|
+
throw new Error(
|
|
1642
|
+
`Entry fee required: ${entryFeeWei} wei. Query GET /world/join-info for payment details, pay the fee, then include paymentTxHash in your join request.`
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1645
|
+
const paymentValid = await this.blockchainClient.verifyPayment(
|
|
1646
|
+
paymentTxHash,
|
|
1647
|
+
walletAddress,
|
|
1648
|
+
entryFeeWei
|
|
1649
|
+
);
|
|
1650
|
+
if (!paymentValid) {
|
|
1651
|
+
throw new Error(
|
|
1652
|
+
`Payment verification failed for tx ${paymentTxHash}. Ensure the transaction is confirmed, sent from ${walletAddress}, to ${this.blockchainClient.getWalletAddress()}, for at least ${entryFeeWei} wei.`
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
logger9.info(`Entry fee payment verified for ${card.name}`, {
|
|
1656
|
+
txHash: paymentTxHash,
|
|
1657
|
+
amount: entryFeeWei
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1485
1660
|
logger9.info(`Minting membership NFT for agent: ${card.name}`);
|
|
1486
1661
|
await this.blockchainClient.mintMembership(walletAddress);
|
|
1487
1662
|
} else {
|
|
@@ -1587,7 +1762,7 @@ var World = (_class4 = class {
|
|
|
1587
1762
|
* Start auto-save interval
|
|
1588
1763
|
*/
|
|
1589
1764
|
startAutoSave() {
|
|
1590
|
-
const interval = _optionalChain([this, 'access',
|
|
1765
|
+
const interval = _optionalChain([this, 'access', _34 => _34.config, 'access', _35 => _35.persistence, 'optionalAccess', _36 => _36.autoSaveIntervalMs]) || 1e4;
|
|
1591
1766
|
this.autoSaveInterval = setInterval(async () => {
|
|
1592
1767
|
if (this.persistence) {
|
|
1593
1768
|
await this.persistence.saveState(this.state);
|
|
@@ -1623,22 +1798,22 @@ var World = (_class4 = class {
|
|
|
1623
1798
|
id: _uuid.v4.call(void 0, ),
|
|
1624
1799
|
type: "tick_error",
|
|
1625
1800
|
timestamp: Date.now(),
|
|
1626
|
-
data: { tick: this.state.tick, error: _optionalChain([error, 'optionalAccess',
|
|
1801
|
+
data: { tick: this.state.tick, error: _optionalChain([error, 'optionalAccess', _37 => _37.message]) || String(error) }
|
|
1627
1802
|
});
|
|
1628
1803
|
}
|
|
1629
1804
|
logger9.debug(`Tick ${this.state.tick}`);
|
|
1630
|
-
if (_optionalChain([this, 'access',
|
|
1805
|
+
if (_optionalChain([this, 'access', _38 => _38.config, 'access', _39 => _39.simulation, 'optionalAccess', _40 => _40.maxTicks]) && this.state.tick >= this.config.simulation.maxTicks) {
|
|
1631
1806
|
logger9.info("Max ticks reached, stopping world");
|
|
1632
1807
|
await this.stop();
|
|
1633
1808
|
}
|
|
1634
1809
|
}, interval);
|
|
1635
1810
|
logger9.info(`Simulation ticking enabled (interval: ${interval}ms)`);
|
|
1636
1811
|
}
|
|
1637
|
-
},
|
|
1812
|
+
}, _class5);
|
|
1638
1813
|
|
|
1639
1814
|
// src/server/app.ts
|
|
1640
1815
|
var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
1641
|
-
var logger10 =
|
|
1816
|
+
var logger10 = _chunkWI7EASJJcjs.createLogger.call(void 0, "WorldServer");
|
|
1642
1817
|
function createWorldApp(world) {
|
|
1643
1818
|
const app = _express2.default.call(void 0, );
|
|
1644
1819
|
app.use(_express2.default.json());
|
|
@@ -1665,9 +1840,40 @@ function createWorldApp(world) {
|
|
|
1665
1840
|
}
|
|
1666
1841
|
});
|
|
1667
1842
|
});
|
|
1843
|
+
app.get("/world/join-info", async (req, res) => {
|
|
1844
|
+
try {
|
|
1845
|
+
const blockchain = world.config.blockchain;
|
|
1846
|
+
const client = world.getBlockchainClient();
|
|
1847
|
+
if (!blockchain || !client) {
|
|
1848
|
+
return res.json({
|
|
1849
|
+
worldName: world.config.name,
|
|
1850
|
+
requiresPayment: false,
|
|
1851
|
+
entryFee: "0",
|
|
1852
|
+
paymentAddress: null,
|
|
1853
|
+
chainId: null,
|
|
1854
|
+
rpcUrl: null
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
const entryFeeWei = await client.getEntryFeeWei();
|
|
1858
|
+
res.json({
|
|
1859
|
+
worldName: world.config.name,
|
|
1860
|
+
requiresPayment: entryFeeWei !== "0" && BigInt(entryFeeWei) > 0n,
|
|
1861
|
+
entryFee: entryFeeWei,
|
|
1862
|
+
paymentAddress: client.getWalletAddress(),
|
|
1863
|
+
chainId: blockchain.chainId || null,
|
|
1864
|
+
rpcUrl: blockchain.rpcUrl
|
|
1865
|
+
});
|
|
1866
|
+
} catch (error) {
|
|
1867
|
+
logger10.error("Failed to get join info:", error);
|
|
1868
|
+
res.status(500).json({
|
|
1869
|
+
success: false,
|
|
1870
|
+
error: error.message || "Failed to get join info"
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
});
|
|
1668
1874
|
app.post("/world/join", async (req, res) => {
|
|
1669
1875
|
try {
|
|
1670
|
-
const { agentUrl, walletAddress } = req.body;
|
|
1876
|
+
const { agentUrl, walletAddress, paymentTxHash } = req.body;
|
|
1671
1877
|
if (!agentUrl) {
|
|
1672
1878
|
return res.status(400).json({
|
|
1673
1879
|
success: false,
|
|
@@ -1675,9 +1881,10 @@ function createWorldApp(world) {
|
|
|
1675
1881
|
});
|
|
1676
1882
|
}
|
|
1677
1883
|
logger10.info(`Agent join request from: ${agentUrl}`, {
|
|
1678
|
-
wallet: walletAddress || "none"
|
|
1884
|
+
wallet: walletAddress || "none",
|
|
1885
|
+
paymentTx: paymentTxHash ? `${paymentTxHash.slice(0, 10)}...` : "none"
|
|
1679
1886
|
});
|
|
1680
|
-
const cardFetcher = new (await Promise.resolve().then(() => _interopRequireWildcard(require("./CardFetcher-
|
|
1887
|
+
const cardFetcher = new (await Promise.resolve().then(() => _interopRequireWildcard(require("./CardFetcher-ZD4YSGJE.cjs")))).CardFetcher();
|
|
1681
1888
|
const result = await cardFetcher.fetchCard(agentUrl);
|
|
1682
1889
|
if (!result.success || !result.card) {
|
|
1683
1890
|
return res.status(400).json({
|
|
@@ -1685,7 +1892,7 @@ function createWorldApp(world) {
|
|
|
1685
1892
|
error: `Failed to fetch agent card: ${result.error}`
|
|
1686
1893
|
});
|
|
1687
1894
|
}
|
|
1688
|
-
await world.admitAgent(result.card, walletAddress);
|
|
1895
|
+
await world.admitAgent(result.card, walletAddress, paymentTxHash);
|
|
1689
1896
|
res.json({
|
|
1690
1897
|
success: true,
|
|
1691
1898
|
message: "Agent admitted to world",
|
|
@@ -1843,6 +2050,7 @@ async function startWorldServer(world) {
|
|
|
1843
2050
|
logger10.info("");
|
|
1844
2051
|
logger10.info("Endpoints:");
|
|
1845
2052
|
logger10.info(` GET / - World info`);
|
|
2053
|
+
logger10.info(` GET /world/join-info - Join requirements & entry fee`);
|
|
1846
2054
|
logger10.info(` POST /world/join - Agent join request`);
|
|
1847
2055
|
logger10.info(` GET /world/agents - List agents`);
|
|
1848
2056
|
logger10.info(` GET /world/state - World state`);
|
|
@@ -1892,5 +2100,5 @@ async function startWorldServer(world) {
|
|
|
1892
2100
|
|
|
1893
2101
|
|
|
1894
2102
|
|
|
1895
|
-
exports.ActionProcessor = ActionProcessor; exports.AdmissionRulesSchema = AdmissionRulesSchema; exports.AgentEvaluator = AgentEvaluator; exports.BlockchainClient = BlockchainClient; exports.BlockchainConfigSchema = BlockchainConfigSchema; exports.CardFetcher =
|
|
2103
|
+
exports.ActionProcessor = ActionProcessor; exports.AdmissionRulesSchema = AdmissionRulesSchema; exports.AgentEvaluator = AgentEvaluator; exports.BlockchainClient = BlockchainClient; exports.BlockchainConfigSchema = BlockchainConfigSchema; exports.CardFetcher = _chunkWI7EASJJcjs.CardFetcher; exports.InMemoryAdapter = InMemoryAdapter; exports.MessageRouter = MessageRouter; exports.PersistenceConfigSchema = PersistenceConfigSchema; exports.TickOrchestrator = TickOrchestrator; exports.TokenConfigSchema = TokenConfigSchema; exports.World = World; exports.WorldA2AClient = WorldA2AClient; exports.WorldActionsRegistry = WorldActionsRegistry; exports.WorldConfigSchema = WorldConfigSchema; exports.createLogger = _chunkWI7EASJJcjs.createLogger; exports.createPersistence = createPersistence; exports.createWorldApp = createWorldApp; exports.isValidWorldConfig = isValidWorldConfig; exports.logger = _chunkWI7EASJJcjs.logger; exports.normalizeAgentUrl = _chunkWI7EASJJcjs.normalizeAgentUrl; exports.profileFromCard = profileFromCard; exports.startWorldServer = startWorldServer; exports.validateWorldConfig = validateWorldConfig;
|
|
1896
2104
|
//# sourceMappingURL=index.cjs.map
|