moltspay 0.9.2 → 0.9.5
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/.env.example +7 -0
- package/dist/cli/index.js +116 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +116 -3
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.js +116 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -3
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +4 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +116 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +116 -3
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -984,6 +984,9 @@ var MoltsPayServer = class {
|
|
|
984
984
|
if (url.pathname === "/services" && req.method === "GET") {
|
|
985
985
|
return this.handleGetServices(res);
|
|
986
986
|
}
|
|
987
|
+
if (url.pathname === "/.well-known/agent-services.json" && req.method === "GET") {
|
|
988
|
+
return this.handleAgentServicesDiscovery(res);
|
|
989
|
+
}
|
|
987
990
|
if (url.pathname === "/health" && req.method === "GET") {
|
|
988
991
|
return await this.handleHealthCheck(res);
|
|
989
992
|
}
|
|
@@ -1007,6 +1010,43 @@ var MoltsPayServer = class {
|
|
|
1007
1010
|
this.sendJson(res, 500, { error: err.message || "Internal error" });
|
|
1008
1011
|
}
|
|
1009
1012
|
}
|
|
1013
|
+
/**
|
|
1014
|
+
* GET /.well-known/agent-services.json - Standard discovery endpoint
|
|
1015
|
+
*/
|
|
1016
|
+
handleAgentServicesDiscovery(res) {
|
|
1017
|
+
const services = this.manifest.services.map((s) => ({
|
|
1018
|
+
id: s.id,
|
|
1019
|
+
name: s.name,
|
|
1020
|
+
description: s.description,
|
|
1021
|
+
price: s.price,
|
|
1022
|
+
currency: s.currency,
|
|
1023
|
+
input: s.input,
|
|
1024
|
+
output: s.output,
|
|
1025
|
+
available: this.skills.has(s.id)
|
|
1026
|
+
}));
|
|
1027
|
+
this.sendJson(res, 200, {
|
|
1028
|
+
version: "1.0",
|
|
1029
|
+
provider: {
|
|
1030
|
+
name: this.manifest.provider.name,
|
|
1031
|
+
description: this.manifest.provider.description,
|
|
1032
|
+
wallet: this.manifest.provider.wallet,
|
|
1033
|
+
chain: this.manifest.provider.chain || "base"
|
|
1034
|
+
},
|
|
1035
|
+
services,
|
|
1036
|
+
endpoints: {
|
|
1037
|
+
services: "/services",
|
|
1038
|
+
execute: "/execute",
|
|
1039
|
+
health: "/health"
|
|
1040
|
+
},
|
|
1041
|
+
payment: {
|
|
1042
|
+
protocol: "x402",
|
|
1043
|
+
version: X402_VERSION3,
|
|
1044
|
+
network: this.networkId,
|
|
1045
|
+
schemes: ["exact"],
|
|
1046
|
+
mainnet: this.useMainnet
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1010
1050
|
/**
|
|
1011
1051
|
* GET /services - List available services
|
|
1012
1052
|
*/
|
|
@@ -1093,10 +1133,16 @@ var MoltsPayServer = class {
|
|
|
1093
1133
|
});
|
|
1094
1134
|
}
|
|
1095
1135
|
console.log(`[MoltsPay] Verified by ${verifyResult.facilitator}`);
|
|
1096
|
-
|
|
1136
|
+
const timeoutSeconds = parseInt(process.env.SKILL_TIMEOUT_SECONDS || "1200");
|
|
1137
|
+
console.log(`[MoltsPay] Executing skill: ${service} (timeout: ${timeoutSeconds}s)`);
|
|
1097
1138
|
let result;
|
|
1098
1139
|
try {
|
|
1099
|
-
result = await
|
|
1140
|
+
result = await Promise.race([
|
|
1141
|
+
skill.handler(params || {}),
|
|
1142
|
+
new Promise(
|
|
1143
|
+
(_, reject) => setTimeout(() => reject(new Error(`Skill timeout after ${timeoutSeconds}s`)), timeoutSeconds * 1e3)
|
|
1144
|
+
)
|
|
1145
|
+
]);
|
|
1100
1146
|
} catch (err) {
|
|
1101
1147
|
console.error("[MoltsPay] Skill execution failed:", err.message);
|
|
1102
1148
|
return this.sendJson(res, 500, {
|
|
@@ -1293,7 +1339,72 @@ var MoltsPayServer = class {
|
|
|
1293
1339
|
});
|
|
1294
1340
|
}
|
|
1295
1341
|
console.log(`[MoltsPay] /proxy: Verified by ${verifyResult.facilitator}`);
|
|
1296
|
-
|
|
1342
|
+
const { execute, service, params } = body;
|
|
1343
|
+
if (execute && service) {
|
|
1344
|
+
console.log(`[MoltsPay] /proxy: Executing skill first (pay on success): ${service}`);
|
|
1345
|
+
const skill = this.skills.get(service);
|
|
1346
|
+
if (!skill) {
|
|
1347
|
+
console.log(`[MoltsPay] /proxy: Service not found: ${service} - NOT settling`);
|
|
1348
|
+
return this.sendJson(res, 404, {
|
|
1349
|
+
success: false,
|
|
1350
|
+
paymentSettled: false,
|
|
1351
|
+
error: `Service not found: ${service}`
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
const timeoutSeconds = parseInt(process.env.SKILL_TIMEOUT_SECONDS || "1200");
|
|
1355
|
+
let result;
|
|
1356
|
+
try {
|
|
1357
|
+
result = await Promise.race([
|
|
1358
|
+
skill.handler(params || {}),
|
|
1359
|
+
new Promise(
|
|
1360
|
+
(_, reject) => setTimeout(() => reject(new Error(`Skill timeout after ${timeoutSeconds}s`)), timeoutSeconds * 1e3)
|
|
1361
|
+
)
|
|
1362
|
+
]);
|
|
1363
|
+
console.log(`[MoltsPay] /proxy: Skill succeeded, now settling payment...`);
|
|
1364
|
+
} catch (err) {
|
|
1365
|
+
console.error(`[MoltsPay] /proxy: Skill failed: ${err.message} - NOT settling`);
|
|
1366
|
+
return this.sendJson(res, 500, {
|
|
1367
|
+
success: false,
|
|
1368
|
+
paymentSettled: false,
|
|
1369
|
+
error: `Service execution failed: ${err.message}`
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
let settlement2 = null;
|
|
1373
|
+
try {
|
|
1374
|
+
settlement2 = await this.registry.settle(payment, requirements);
|
|
1375
|
+
console.log(`[MoltsPay] /proxy: Payment settled by ${settlement2.facilitator}: ${settlement2.transaction || "pending"}`);
|
|
1376
|
+
} catch (err) {
|
|
1377
|
+
console.error("[MoltsPay] /proxy: Settlement failed:", err.message);
|
|
1378
|
+
return this.sendJson(res, 200, {
|
|
1379
|
+
success: true,
|
|
1380
|
+
verified: true,
|
|
1381
|
+
settled: false,
|
|
1382
|
+
settlementError: err.message,
|
|
1383
|
+
from: payment.payload?.authorization?.from,
|
|
1384
|
+
// Buyer's wallet address
|
|
1385
|
+
paidTo: wallet,
|
|
1386
|
+
amount: amountNum,
|
|
1387
|
+
currency: currency || "USDC",
|
|
1388
|
+
memo,
|
|
1389
|
+
result
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
return this.sendJson(res, 200, {
|
|
1393
|
+
success: true,
|
|
1394
|
+
verified: true,
|
|
1395
|
+
settled: settlement2?.success || false,
|
|
1396
|
+
txHash: settlement2?.transaction,
|
|
1397
|
+
from: payment.payload?.authorization?.from,
|
|
1398
|
+
// Buyer's wallet address
|
|
1399
|
+
paidTo: wallet,
|
|
1400
|
+
amount: amountNum,
|
|
1401
|
+
currency: currency || "USDC",
|
|
1402
|
+
facilitator: settlement2?.facilitator,
|
|
1403
|
+
memo,
|
|
1404
|
+
result
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
console.log(`[MoltsPay] /proxy: Settling payment (no execution)...`);
|
|
1297
1408
|
let settlement = null;
|
|
1298
1409
|
try {
|
|
1299
1410
|
settlement = await this.registry.settle(payment, requirements);
|
|
@@ -1310,6 +1421,8 @@ var MoltsPayServer = class {
|
|
|
1310
1421
|
verified: true,
|
|
1311
1422
|
settled: settlement?.success || false,
|
|
1312
1423
|
txHash: settlement?.transaction,
|
|
1424
|
+
from: payment.payload?.authorization?.from,
|
|
1425
|
+
// Buyer's wallet address
|
|
1313
1426
|
paidTo: wallet,
|
|
1314
1427
|
amount: amountNum,
|
|
1315
1428
|
currency: currency || "USDC",
|