opentool 0.7.6 → 0.7.8
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/cli/index.js +45 -20
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +45 -20
- package/dist/index.js.map +1 -1
- package/dist/x402/index.js +45 -20
- package/dist/x402/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -535,6 +535,7 @@ function extractX402Attempt(request) {
|
|
|
535
535
|
}
|
|
536
536
|
async function verifyX402Payment(attempt, definition, options = {}) {
|
|
537
537
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
538
|
+
const timeout = options.timeout ?? 25e3;
|
|
538
539
|
const facilitator = definition.facilitator;
|
|
539
540
|
const verifierUrl = new URL(
|
|
540
541
|
facilitator.verifyPath ?? "/verify",
|
|
@@ -543,22 +544,33 @@ async function verifyX402Payment(attempt, definition, options = {}) {
|
|
|
543
544
|
const requirement = toX402Requirement(definition);
|
|
544
545
|
const headers = buildFacilitatorHeaders(facilitator);
|
|
545
546
|
try {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
})
|
|
547
|
+
const verifyBody = {
|
|
548
|
+
x402Version: attempt.payload.x402Version,
|
|
549
|
+
paymentPayload: attempt.payload,
|
|
550
|
+
paymentRequirements: requirement
|
|
551
|
+
};
|
|
552
|
+
console.log("[x402] Calling facilitator /verify", {
|
|
553
|
+
url: verifierUrl,
|
|
554
|
+
fullBody: JSON.stringify(verifyBody, null, 2)
|
|
555
555
|
});
|
|
556
|
+
const verifyResponse = await Promise.race([
|
|
557
|
+
fetchImpl(verifierUrl, {
|
|
558
|
+
method: "POST",
|
|
559
|
+
headers,
|
|
560
|
+
body: JSON.stringify(verifyBody)
|
|
561
|
+
}),
|
|
562
|
+
new Promise(
|
|
563
|
+
(_, reject) => setTimeout(() => reject(new Error(`Verification timeout after ${timeout}ms`)), timeout)
|
|
564
|
+
)
|
|
565
|
+
]);
|
|
556
566
|
console.log("[x402] Facilitator /verify response", { status: verifyResponse.status });
|
|
557
567
|
if (!verifyResponse.ok) {
|
|
568
|
+
const errorText = await verifyResponse.text().catch(() => "");
|
|
569
|
+
console.error("[x402] Facilitator /verify error", { status: verifyResponse.status, body: errorText });
|
|
558
570
|
return {
|
|
559
571
|
success: false,
|
|
560
572
|
failure: {
|
|
561
|
-
reason: `Facilitator verify request failed: ${verifyResponse.status}`,
|
|
573
|
+
reason: `Facilitator verify request failed: ${verifyResponse.status}${errorText ? ` - ${errorText}` : ""}`,
|
|
562
574
|
code: "verification_failed"
|
|
563
575
|
}
|
|
564
576
|
};
|
|
@@ -580,27 +592,39 @@ async function verifyX402Payment(attempt, definition, options = {}) {
|
|
|
580
592
|
ensureTrailingSlash(facilitator.url)
|
|
581
593
|
).toString();
|
|
582
594
|
try {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
})
|
|
595
|
+
const settleBody = {
|
|
596
|
+
x402Version: attempt.payload.x402Version,
|
|
597
|
+
paymentPayload: attempt.payload,
|
|
598
|
+
paymentRequirements: requirement
|
|
599
|
+
};
|
|
600
|
+
console.log("[x402] Calling facilitator /settle", {
|
|
601
|
+
url: settleUrl,
|
|
602
|
+
bodyPreview: JSON.stringify(settleBody).substring(0, 300)
|
|
592
603
|
});
|
|
604
|
+
const settleResponse = await Promise.race([
|
|
605
|
+
fetchImpl(settleUrl, {
|
|
606
|
+
method: "POST",
|
|
607
|
+
headers,
|
|
608
|
+
body: JSON.stringify(settleBody)
|
|
609
|
+
}),
|
|
610
|
+
new Promise(
|
|
611
|
+
(_, reject) => setTimeout(() => reject(new Error(`Settlement timeout after ${timeout}ms`)), timeout)
|
|
612
|
+
)
|
|
613
|
+
]);
|
|
593
614
|
console.log("[x402] Facilitator /settle response", { status: settleResponse.status });
|
|
594
615
|
if (!settleResponse.ok) {
|
|
616
|
+
const errorText = await settleResponse.text().catch(() => "");
|
|
617
|
+
console.error("[x402] Facilitator /settle error", { status: settleResponse.status, body: errorText });
|
|
595
618
|
return {
|
|
596
619
|
success: false,
|
|
597
620
|
failure: {
|
|
598
|
-
reason: `Facilitator settlement failed: ${settleResponse.status}`,
|
|
621
|
+
reason: `Facilitator settlement failed: ${settleResponse.status}${errorText ? ` - ${errorText}` : ""}`,
|
|
599
622
|
code: "settlement_failed"
|
|
600
623
|
}
|
|
601
624
|
};
|
|
602
625
|
}
|
|
603
626
|
const settlePayload = await settleResponse.json();
|
|
627
|
+
console.log("[x402] Facilitator /settle success", { txHash: settlePayload.txHash });
|
|
604
628
|
if (settlePayload.txHash) {
|
|
605
629
|
responseHeaders[HEADER_PAYMENT_RESPONSE] = JSON.stringify({
|
|
606
630
|
settled: true,
|
|
@@ -608,6 +632,7 @@ async function verifyX402Payment(attempt, definition, options = {}) {
|
|
|
608
632
|
});
|
|
609
633
|
}
|
|
610
634
|
} catch (error) {
|
|
635
|
+
console.error("[x402] Settlement exception", { error: error instanceof Error ? error.message : String(error) });
|
|
611
636
|
return {
|
|
612
637
|
success: false,
|
|
613
638
|
failure: {
|