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/index.js
CHANGED
|
@@ -30965,6 +30965,9 @@ var MoltsPayServer = class {
|
|
|
30965
30965
|
if (url.pathname === "/services" && req.method === "GET") {
|
|
30966
30966
|
return this.handleGetServices(res);
|
|
30967
30967
|
}
|
|
30968
|
+
if (url.pathname === "/.well-known/agent-services.json" && req.method === "GET") {
|
|
30969
|
+
return this.handleAgentServicesDiscovery(res);
|
|
30970
|
+
}
|
|
30968
30971
|
if (url.pathname === "/health" && req.method === "GET") {
|
|
30969
30972
|
return await this.handleHealthCheck(res);
|
|
30970
30973
|
}
|
|
@@ -30988,6 +30991,43 @@ var MoltsPayServer = class {
|
|
|
30988
30991
|
this.sendJson(res, 500, { error: err.message || "Internal error" });
|
|
30989
30992
|
}
|
|
30990
30993
|
}
|
|
30994
|
+
/**
|
|
30995
|
+
* GET /.well-known/agent-services.json - Standard discovery endpoint
|
|
30996
|
+
*/
|
|
30997
|
+
handleAgentServicesDiscovery(res) {
|
|
30998
|
+
const services = this.manifest.services.map((s) => ({
|
|
30999
|
+
id: s.id,
|
|
31000
|
+
name: s.name,
|
|
31001
|
+
description: s.description,
|
|
31002
|
+
price: s.price,
|
|
31003
|
+
currency: s.currency,
|
|
31004
|
+
input: s.input,
|
|
31005
|
+
output: s.output,
|
|
31006
|
+
available: this.skills.has(s.id)
|
|
31007
|
+
}));
|
|
31008
|
+
this.sendJson(res, 200, {
|
|
31009
|
+
version: "1.0",
|
|
31010
|
+
provider: {
|
|
31011
|
+
name: this.manifest.provider.name,
|
|
31012
|
+
description: this.manifest.provider.description,
|
|
31013
|
+
wallet: this.manifest.provider.wallet,
|
|
31014
|
+
chain: this.manifest.provider.chain || "base"
|
|
31015
|
+
},
|
|
31016
|
+
services,
|
|
31017
|
+
endpoints: {
|
|
31018
|
+
services: "/services",
|
|
31019
|
+
execute: "/execute",
|
|
31020
|
+
health: "/health"
|
|
31021
|
+
},
|
|
31022
|
+
payment: {
|
|
31023
|
+
protocol: "x402",
|
|
31024
|
+
version: X402_VERSION2,
|
|
31025
|
+
network: this.networkId,
|
|
31026
|
+
schemes: ["exact"],
|
|
31027
|
+
mainnet: this.useMainnet
|
|
31028
|
+
}
|
|
31029
|
+
});
|
|
31030
|
+
}
|
|
30991
31031
|
/**
|
|
30992
31032
|
* GET /services - List available services
|
|
30993
31033
|
*/
|
|
@@ -31074,10 +31114,16 @@ var MoltsPayServer = class {
|
|
|
31074
31114
|
});
|
|
31075
31115
|
}
|
|
31076
31116
|
console.log(`[MoltsPay] Verified by ${verifyResult.facilitator}`);
|
|
31077
|
-
|
|
31117
|
+
const timeoutSeconds = parseInt(process.env.SKILL_TIMEOUT_SECONDS || "1200");
|
|
31118
|
+
console.log(`[MoltsPay] Executing skill: ${service} (timeout: ${timeoutSeconds}s)`);
|
|
31078
31119
|
let result;
|
|
31079
31120
|
try {
|
|
31080
|
-
result = await
|
|
31121
|
+
result = await Promise.race([
|
|
31122
|
+
skill.handler(params || {}),
|
|
31123
|
+
new Promise(
|
|
31124
|
+
(_, reject) => setTimeout(() => reject(new Error(`Skill timeout after ${timeoutSeconds}s`)), timeoutSeconds * 1e3)
|
|
31125
|
+
)
|
|
31126
|
+
]);
|
|
31081
31127
|
} catch (err) {
|
|
31082
31128
|
console.error("[MoltsPay] Skill execution failed:", err.message);
|
|
31083
31129
|
return this.sendJson(res, 500, {
|
|
@@ -31274,7 +31320,72 @@ var MoltsPayServer = class {
|
|
|
31274
31320
|
});
|
|
31275
31321
|
}
|
|
31276
31322
|
console.log(`[MoltsPay] /proxy: Verified by ${verifyResult.facilitator}`);
|
|
31277
|
-
|
|
31323
|
+
const { execute, service, params } = body;
|
|
31324
|
+
if (execute && service) {
|
|
31325
|
+
console.log(`[MoltsPay] /proxy: Executing skill first (pay on success): ${service}`);
|
|
31326
|
+
const skill = this.skills.get(service);
|
|
31327
|
+
if (!skill) {
|
|
31328
|
+
console.log(`[MoltsPay] /proxy: Service not found: ${service} - NOT settling`);
|
|
31329
|
+
return this.sendJson(res, 404, {
|
|
31330
|
+
success: false,
|
|
31331
|
+
paymentSettled: false,
|
|
31332
|
+
error: `Service not found: ${service}`
|
|
31333
|
+
});
|
|
31334
|
+
}
|
|
31335
|
+
const timeoutSeconds = parseInt(process.env.SKILL_TIMEOUT_SECONDS || "1200");
|
|
31336
|
+
let result;
|
|
31337
|
+
try {
|
|
31338
|
+
result = await Promise.race([
|
|
31339
|
+
skill.handler(params || {}),
|
|
31340
|
+
new Promise(
|
|
31341
|
+
(_, reject) => setTimeout(() => reject(new Error(`Skill timeout after ${timeoutSeconds}s`)), timeoutSeconds * 1e3)
|
|
31342
|
+
)
|
|
31343
|
+
]);
|
|
31344
|
+
console.log(`[MoltsPay] /proxy: Skill succeeded, now settling payment...`);
|
|
31345
|
+
} catch (err) {
|
|
31346
|
+
console.error(`[MoltsPay] /proxy: Skill failed: ${err.message} - NOT settling`);
|
|
31347
|
+
return this.sendJson(res, 500, {
|
|
31348
|
+
success: false,
|
|
31349
|
+
paymentSettled: false,
|
|
31350
|
+
error: `Service execution failed: ${err.message}`
|
|
31351
|
+
});
|
|
31352
|
+
}
|
|
31353
|
+
let settlement2 = null;
|
|
31354
|
+
try {
|
|
31355
|
+
settlement2 = await this.registry.settle(payment, requirements);
|
|
31356
|
+
console.log(`[MoltsPay] /proxy: Payment settled by ${settlement2.facilitator}: ${settlement2.transaction || "pending"}`);
|
|
31357
|
+
} catch (err) {
|
|
31358
|
+
console.error("[MoltsPay] /proxy: Settlement failed:", err.message);
|
|
31359
|
+
return this.sendJson(res, 200, {
|
|
31360
|
+
success: true,
|
|
31361
|
+
verified: true,
|
|
31362
|
+
settled: false,
|
|
31363
|
+
settlementError: err.message,
|
|
31364
|
+
from: payment.payload?.authorization?.from,
|
|
31365
|
+
// Buyer's wallet address
|
|
31366
|
+
paidTo: wallet,
|
|
31367
|
+
amount: amountNum,
|
|
31368
|
+
currency: currency || "USDC",
|
|
31369
|
+
memo,
|
|
31370
|
+
result
|
|
31371
|
+
});
|
|
31372
|
+
}
|
|
31373
|
+
return this.sendJson(res, 200, {
|
|
31374
|
+
success: true,
|
|
31375
|
+
verified: true,
|
|
31376
|
+
settled: settlement2?.success || false,
|
|
31377
|
+
txHash: settlement2?.transaction,
|
|
31378
|
+
from: payment.payload?.authorization?.from,
|
|
31379
|
+
// Buyer's wallet address
|
|
31380
|
+
paidTo: wallet,
|
|
31381
|
+
amount: amountNum,
|
|
31382
|
+
currency: currency || "USDC",
|
|
31383
|
+
facilitator: settlement2?.facilitator,
|
|
31384
|
+
memo,
|
|
31385
|
+
result
|
|
31386
|
+
});
|
|
31387
|
+
}
|
|
31388
|
+
console.log(`[MoltsPay] /proxy: Settling payment (no execution)...`);
|
|
31278
31389
|
let settlement = null;
|
|
31279
31390
|
try {
|
|
31280
31391
|
settlement = await this.registry.settle(payment, requirements);
|
|
@@ -31291,6 +31402,8 @@ var MoltsPayServer = class {
|
|
|
31291
31402
|
verified: true,
|
|
31292
31403
|
settled: settlement?.success || false,
|
|
31293
31404
|
txHash: settlement?.transaction,
|
|
31405
|
+
from: payment.payload?.authorization?.from,
|
|
31406
|
+
// Buyer's wallet address
|
|
31294
31407
|
paidTo: wallet,
|
|
31295
31408
|
amount: amountNum,
|
|
31296
31409
|
currency: currency || "USDC",
|