opentool 0.7.7 → 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 +35 -16
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +35 -16
- package/dist/index.js.map +1 -1
- package/dist/x402/index.js +35 -16
- 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",
|
|
@@ -550,13 +551,18 @@ async function verifyX402Payment(attempt, definition, options = {}) {
|
|
|
550
551
|
};
|
|
551
552
|
console.log("[x402] Calling facilitator /verify", {
|
|
552
553
|
url: verifierUrl,
|
|
553
|
-
|
|
554
|
-
});
|
|
555
|
-
const verifyResponse = await fetchImpl(verifierUrl, {
|
|
556
|
-
method: "POST",
|
|
557
|
-
headers,
|
|
558
|
-
body: JSON.stringify(verifyBody)
|
|
554
|
+
fullBody: JSON.stringify(verifyBody, null, 2)
|
|
559
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
|
+
]);
|
|
560
566
|
console.log("[x402] Facilitator /verify response", { status: verifyResponse.status });
|
|
561
567
|
if (!verifyResponse.ok) {
|
|
562
568
|
const errorText = await verifyResponse.text().catch(() => "");
|
|
@@ -586,27 +592,39 @@ async function verifyX402Payment(attempt, definition, options = {}) {
|
|
|
586
592
|
ensureTrailingSlash(facilitator.url)
|
|
587
593
|
).toString();
|
|
588
594
|
try {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
})
|
|
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)
|
|
598
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
|
+
]);
|
|
599
614
|
console.log("[x402] Facilitator /settle response", { status: settleResponse.status });
|
|
600
615
|
if (!settleResponse.ok) {
|
|
616
|
+
const errorText = await settleResponse.text().catch(() => "");
|
|
617
|
+
console.error("[x402] Facilitator /settle error", { status: settleResponse.status, body: errorText });
|
|
601
618
|
return {
|
|
602
619
|
success: false,
|
|
603
620
|
failure: {
|
|
604
|
-
reason: `Facilitator settlement failed: ${settleResponse.status}`,
|
|
621
|
+
reason: `Facilitator settlement failed: ${settleResponse.status}${errorText ? ` - ${errorText}` : ""}`,
|
|
605
622
|
code: "settlement_failed"
|
|
606
623
|
}
|
|
607
624
|
};
|
|
608
625
|
}
|
|
609
626
|
const settlePayload = await settleResponse.json();
|
|
627
|
+
console.log("[x402] Facilitator /settle success", { txHash: settlePayload.txHash });
|
|
610
628
|
if (settlePayload.txHash) {
|
|
611
629
|
responseHeaders[HEADER_PAYMENT_RESPONSE] = JSON.stringify({
|
|
612
630
|
settled: true,
|
|
@@ -614,6 +632,7 @@ async function verifyX402Payment(attempt, definition, options = {}) {
|
|
|
614
632
|
});
|
|
615
633
|
}
|
|
616
634
|
} catch (error) {
|
|
635
|
+
console.error("[x402] Settlement exception", { error: error instanceof Error ? error.message : String(error) });
|
|
617
636
|
return {
|
|
618
637
|
success: false,
|
|
619
638
|
failure: {
|