agentcash 0.14.3 → 0.14.4
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/cjs/run-server.cjs +74 -24
- package/dist/esm/{add-skill-CDIK57A3.js → add-skill-MO4YPAYM.js} +4 -4
- package/dist/esm/{bridge-6WMUV3ML.js → bridge-Q4YWH4WW.js} +3 -3
- package/dist/esm/{check-D5DZ6Y3T.js → check-3GPSLBNI.js} +4 -4
- package/dist/esm/{chunk-FV6DADHO.js → chunk-2OKYUR7B.js} +2 -2
- package/dist/esm/{chunk-K627XZI4.js → chunk-2SZ6MZS3.js} +2 -2
- package/dist/esm/{chunk-SFESERJN.js → chunk-3PYQIEMA.js} +2 -2
- package/dist/esm/chunk-3PYQIEMA.js.map +1 -0
- package/dist/esm/{chunk-KMS4TVJY.js → chunk-7KT6UCTT.js} +2 -2
- package/dist/esm/{chunk-IL2CNAJY.js → chunk-CUZFVI2X.js} +2 -2
- package/dist/esm/{chunk-SCBLFGL2.js → chunk-JKK2XT7N.js} +3 -3
- package/dist/esm/{chunk-G5FHPXQL.js → chunk-JVMJVMWB.js} +71 -22
- package/dist/esm/chunk-JVMJVMWB.js.map +1 -0
- package/dist/esm/{chunk-CFSSHSBN.js → chunk-L4U6AJW3.js} +2 -2
- package/dist/esm/{chunk-KSW2MGQR.js → chunk-ONGJJBKT.js} +3 -3
- package/dist/esm/{chunk-NP7CKLI4.js → chunk-QOMU3YLK.js} +2 -2
- package/dist/esm/{chunk-LGFUHPDL.js → chunk-WRNDLZ3K.js} +2 -2
- package/dist/esm/{discover-X557BWGS.js → discover-TE2BZJMA.js} +3 -3
- package/dist/esm/{fetch-45YPD37H.js → fetch-ZAECKP5C.js} +5 -5
- package/dist/esm/index.js +19 -19
- package/dist/esm/{install-KJOAEIZF.js → install-EOF353SY.js} +3 -3
- package/dist/esm/{onboard-M5C6TFWE.js → onboard-EMUCEMFN.js} +3 -3
- package/dist/esm/{origins-XG6O5K27.js → origins-MBWKIWLR.js} +4 -4
- package/dist/esm/{register-AD43YD5O.js → register-NSQPYCWI.js} +2 -2
- package/dist/esm/{report-error-FDDNOZAD.js → report-error-7RCKDM2N.js} +3 -3
- package/dist/esm/{search-VYYPNNIU.js → search-SYBTWXON.js} +4 -4
- package/dist/esm/{server-6FQ4UZMS.js → server-NHOKDQHU.js} +10 -10
- package/dist/esm/{server-Q4W2J7OE.js → server-ZIKTGUST.js} +2 -2
- package/dist/esm/{try-UYLQPTBJ.js → try-MXWZSHRS.js} +3 -3
- package/package.json +3 -3
- package/dist/esm/chunk-G5FHPXQL.js.map +0 -1
- package/dist/esm/chunk-SFESERJN.js.map +0 -1
- /package/dist/esm/{add-skill-CDIK57A3.js.map → add-skill-MO4YPAYM.js.map} +0 -0
- /package/dist/esm/{bridge-6WMUV3ML.js.map → bridge-Q4YWH4WW.js.map} +0 -0
- /package/dist/esm/{check-D5DZ6Y3T.js.map → check-3GPSLBNI.js.map} +0 -0
- /package/dist/esm/{chunk-FV6DADHO.js.map → chunk-2OKYUR7B.js.map} +0 -0
- /package/dist/esm/{chunk-K627XZI4.js.map → chunk-2SZ6MZS3.js.map} +0 -0
- /package/dist/esm/{chunk-KMS4TVJY.js.map → chunk-7KT6UCTT.js.map} +0 -0
- /package/dist/esm/{chunk-IL2CNAJY.js.map → chunk-CUZFVI2X.js.map} +0 -0
- /package/dist/esm/{chunk-SCBLFGL2.js.map → chunk-JKK2XT7N.js.map} +0 -0
- /package/dist/esm/{chunk-CFSSHSBN.js.map → chunk-L4U6AJW3.js.map} +0 -0
- /package/dist/esm/{chunk-KSW2MGQR.js.map → chunk-ONGJJBKT.js.map} +0 -0
- /package/dist/esm/{chunk-NP7CKLI4.js.map → chunk-QOMU3YLK.js.map} +0 -0
- /package/dist/esm/{chunk-LGFUHPDL.js.map → chunk-WRNDLZ3K.js.map} +0 -0
- /package/dist/esm/{discover-X557BWGS.js.map → discover-TE2BZJMA.js.map} +0 -0
- /package/dist/esm/{fetch-45YPD37H.js.map → fetch-ZAECKP5C.js.map} +0 -0
- /package/dist/esm/{install-KJOAEIZF.js.map → install-EOF353SY.js.map} +0 -0
- /package/dist/esm/{onboard-M5C6TFWE.js.map → onboard-EMUCEMFN.js.map} +0 -0
- /package/dist/esm/{origins-XG6O5K27.js.map → origins-MBWKIWLR.js.map} +0 -0
- /package/dist/esm/{register-AD43YD5O.js.map → register-NSQPYCWI.js.map} +0 -0
- /package/dist/esm/{report-error-FDDNOZAD.js.map → report-error-7RCKDM2N.js.map} +0 -0
- /package/dist/esm/{search-VYYPNNIU.js.map → search-SYBTWXON.js.map} +0 -0
- /package/dist/esm/{server-6FQ4UZMS.js.map → server-NHOKDQHU.js.map} +0 -0
- /package/dist/esm/{server-Q4W2J7OE.js.map → server-ZIKTGUST.js.map} +0 -0
- /package/dist/esm/{try-UYLQPTBJ.js.map → try-MXWZSHRS.js.map} +0 -0
package/dist/cjs/run-server.cjs
CHANGED
|
@@ -125393,6 +125393,13 @@ var PatchedExactSvmScheme = class {
|
|
|
125393
125393
|
}
|
|
125394
125394
|
};
|
|
125395
125395
|
|
|
125396
|
+
// src/shared/protocols/x402/policies.ts
|
|
125397
|
+
init_cjs_shims();
|
|
125398
|
+
var MAX_UPTO_DEADLINE_SECONDS = 7 * 24 * 60 * 60;
|
|
125399
|
+
var capUptoDeadline = (_x402Version, requirements) => requirements.map(
|
|
125400
|
+
(r) => r.scheme === "upto" && r.maxTimeoutSeconds > MAX_UPTO_DEADLINE_SECONDS ? { ...r, maxTimeoutSeconds: MAX_UPTO_DEADLINE_SECONDS } : r
|
|
125401
|
+
);
|
|
125402
|
+
|
|
125396
125403
|
// ../../internal/networks/src/index.ts
|
|
125397
125404
|
init_cjs_shims();
|
|
125398
125405
|
|
|
@@ -137674,6 +137681,7 @@ var safeCreatePaymentPayload = (surface, wallets, paymentRequired, paymentRequir
|
|
|
137674
137681
|
client: new PatchedExactSvmScheme(toClientSvmSigner(wallets.svm))
|
|
137675
137682
|
}
|
|
137676
137683
|
],
|
|
137684
|
+
policies: [capUptoDeadline],
|
|
137677
137685
|
paymentRequirementsSelector
|
|
137678
137686
|
})
|
|
137679
137687
|
);
|
|
@@ -146285,6 +146293,9 @@ init_cjs_shims();
|
|
|
146285
146293
|
|
|
146286
146294
|
// src/shared/protocols/x402/choose-payment-requirement.ts
|
|
146287
146295
|
init_cjs_shims();
|
|
146296
|
+
var preferUpto = (requirements) => {
|
|
146297
|
+
return requirements.find((pr) => pr.scheme === "upto") ?? requirements[0];
|
|
146298
|
+
};
|
|
146288
146299
|
var choosePaymentRequirement = async ({
|
|
146289
146300
|
paymentRequirements,
|
|
146290
146301
|
options
|
|
@@ -146293,7 +146304,7 @@ var choosePaymentRequirement = async ({
|
|
|
146293
146304
|
const { paymentNetwork } = options.params;
|
|
146294
146305
|
if (paymentNetwork) {
|
|
146295
146306
|
const caip2 = networkToCaip2(paymentNetwork);
|
|
146296
|
-
return paymentRequirements.
|
|
146307
|
+
return preferUpto(paymentRequirements.filter((pr) => pr.network === caip2));
|
|
146297
146308
|
}
|
|
146298
146309
|
const requirementsWithBalance = await Promise.all(
|
|
146299
146310
|
paymentRequirements.map(async (pr) => {
|
|
@@ -146333,10 +146344,26 @@ var choosePaymentRequirement = async ({
|
|
|
146333
146344
|
}
|
|
146334
146345
|
})
|
|
146335
146346
|
);
|
|
146336
|
-
|
|
146347
|
+
const bestNetwork = requirementsWithBalance.sort(
|
|
146348
|
+
(a, b) => b.balance - a.balance
|
|
146349
|
+
)[0].requirement.network;
|
|
146350
|
+
return preferUpto(
|
|
146351
|
+
paymentRequirements.filter((pr) => pr.network === bestNetwork)
|
|
146352
|
+
);
|
|
146337
146353
|
};
|
|
146338
146354
|
|
|
146339
146355
|
// src/shared/protocols/x402/handle-payment.ts
|
|
146356
|
+
var isPermit2AllowanceFailureBody = (body) => body.includes("permit2") && body.includes("allowance_required");
|
|
146357
|
+
var buildPermit2AllowanceErrorMessage = (params) => {
|
|
146358
|
+
const { walletAddress, scheme } = params;
|
|
146359
|
+
return [
|
|
146360
|
+
`Payment failed: this endpoint's \`${scheme}\` scheme settles via the Permit2 contract, but your agentcash wallet (${walletAddress}) has not approved Permit2 to spend USDC.`,
|
|
146361
|
+
"",
|
|
146362
|
+
"The clean fix is server-side. The merchant should adopt the EIP-2612 gas-sponsoring extension \u2014 agentcash will then auto-sign an off-chain permit on each call and the facilitator pays the approval gas, with no setup required from the user. See https://docs.x402.org/extensions/eip2612-gas-sponsoring",
|
|
146363
|
+
"",
|
|
146364
|
+
`Until the merchant adopts that extension, you can do a one-time \`USDC.approve(0x000000000022D473030F116dDEE9F6B43aC78BA3, MAX_UINT256)\` on Base from this wallet (requires a small amount of ETH for gas, ~$0.01\u20130.10). After that, all future Permit2-based payments from this wallet work without further on-chain transactions.`
|
|
146365
|
+
].join("\n");
|
|
146366
|
+
};
|
|
146340
146367
|
async function handleX402Payment({
|
|
146341
146368
|
response,
|
|
146342
146369
|
request: request2,
|
|
@@ -146414,27 +146441,50 @@ async function handleX402Payment({
|
|
|
146414
146441
|
"Access-Control-Expose-Headers",
|
|
146415
146442
|
"PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
|
|
146416
146443
|
);
|
|
146417
|
-
|
|
146418
|
-
|
|
146419
|
-
|
|
146420
|
-
|
|
146421
|
-
|
|
146422
|
-
|
|
146423
|
-
|
|
146424
|
-
|
|
146425
|
-
|
|
146426
|
-
|
|
146427
|
-
|
|
146428
|
-
|
|
146429
|
-
|
|
146430
|
-
|
|
146431
|
-
|
|
146432
|
-
|
|
146433
|
-
|
|
146434
|
-
|
|
146435
|
-
|
|
146444
|
+
const paidResult = await safeFetch(surface, request2, timeout);
|
|
146445
|
+
if (paidResult.isErr()) {
|
|
146446
|
+
return paidResult;
|
|
146447
|
+
}
|
|
146448
|
+
const paidResponse = paidResult.value;
|
|
146449
|
+
const permit2Error = await detectPermit2AllowanceError(paidResponse, {
|
|
146450
|
+
walletAddress: wallets.evm.address,
|
|
146451
|
+
scheme: paymentPayload.accepted.scheme
|
|
146452
|
+
});
|
|
146453
|
+
if (permit2Error) {
|
|
146454
|
+
return x402Err(surface, permit2Error);
|
|
146455
|
+
}
|
|
146456
|
+
const settlementResult = safeGetPaymentSettlement(surface, paidResponse);
|
|
146457
|
+
const settlement = settlementResult.isOk() ? settlementResult.value : null;
|
|
146458
|
+
const maxAmount = tokenStringToNumber(paymentPayload.accepted.amount);
|
|
146459
|
+
const settledAmount = settlement?.amount ? tokenStringToNumber(settlement.amount) : null;
|
|
146460
|
+
const isUpTo = paymentPayload.accepted.scheme === "upto";
|
|
146461
|
+
const price = settledAmount != null ? formatUsd(settledAmount) : isUpTo ? `up to ${formatUsd(maxAmount)}` : formatUsd(maxAmount);
|
|
146462
|
+
return x402Ok({
|
|
146463
|
+
response: paidResponse,
|
|
146464
|
+
paymentInfo: {
|
|
146465
|
+
protocol: "x402" /* X402 */,
|
|
146466
|
+
network: caip2ToNetwork(paymentPayload.accepted.network),
|
|
146467
|
+
price,
|
|
146468
|
+
payment: settlement ? {
|
|
146469
|
+
success: settlement.success,
|
|
146470
|
+
transactionHash: settlement.transaction
|
|
146471
|
+
} : null
|
|
146472
|
+
}
|
|
146436
146473
|
});
|
|
146437
146474
|
}
|
|
146475
|
+
async function detectPermit2AllowanceError(response, context2) {
|
|
146476
|
+
if (response.ok) {
|
|
146477
|
+
return null;
|
|
146478
|
+
}
|
|
146479
|
+
const body = await response.clone().text().catch(() => "");
|
|
146480
|
+
if (!isPermit2AllowanceFailureBody(body)) {
|
|
146481
|
+
return null;
|
|
146482
|
+
}
|
|
146483
|
+
return {
|
|
146484
|
+
cause: "permit2_allowance_required",
|
|
146485
|
+
message: buildPermit2AllowanceErrorMessage(context2)
|
|
146486
|
+
};
|
|
146487
|
+
}
|
|
146438
146488
|
|
|
146439
146489
|
// src/operations/fetch/payment.ts
|
|
146440
146490
|
async function executePayment(response, request2, options) {
|
|
@@ -146717,7 +146767,7 @@ var ORIGIN_METADATA = {
|
|
|
146717
146767
|
},
|
|
146718
146768
|
["https://stablesocial.dev" /* StableSocial */]: {
|
|
146719
146769
|
title: "StableSocial",
|
|
146720
|
-
description: "Social media data for
|
|
146770
|
+
description: "Social media data for TikTok, Instagram, Facebook, Reddit"
|
|
146721
146771
|
},
|
|
146722
146772
|
["https://stablestudio.dev" /* StableStudio */]: {
|
|
146723
146773
|
title: "StableStudio",
|
|
@@ -162358,7 +162408,7 @@ var import_path2 = require("path");
|
|
|
162358
162408
|
var import_url2 = require("url");
|
|
162359
162409
|
function getVersion3() {
|
|
162360
162410
|
if (true) {
|
|
162361
|
-
return "0.14.
|
|
162411
|
+
return "0.14.4";
|
|
162362
162412
|
}
|
|
162363
162413
|
const __dirname2 = (0, import_path2.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
|
|
162364
162414
|
const pkg2 = JSON.parse(
|
|
@@ -169887,7 +169937,7 @@ var import_path3 = require("path");
|
|
|
169887
169937
|
var import_url5 = require("url");
|
|
169888
169938
|
function getVersion4() {
|
|
169889
169939
|
if (true) {
|
|
169890
|
-
return "0.14.
|
|
169940
|
+
return "0.14.4";
|
|
169891
169941
|
}
|
|
169892
169942
|
const __dirname2 = (0, import_path3.dirname)((0, import_url5.fileURLToPath)(importMetaUrl));
|
|
169893
169943
|
const pkg2 = JSON.parse(
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveOrigin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2SZ6MZS3.js";
|
|
4
4
|
import {
|
|
5
5
|
installSkills
|
|
6
6
|
} from "./chunk-FVVSNDQR.js";
|
|
7
7
|
import {
|
|
8
8
|
addUserOrigin
|
|
9
9
|
} from "./chunk-YIU364NZ.js";
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-L4U6AJW3.js";
|
|
11
|
+
import "./chunk-3PYQIEMA.js";
|
|
12
12
|
import "./chunk-KVSTJRSJ.js";
|
|
13
13
|
import "./chunk-FB5CMO3J.js";
|
|
14
14
|
import "./chunk-U6FRXL3X.js";
|
|
@@ -97,4 +97,4 @@ var addSkillCommand = async (input) => {
|
|
|
97
97
|
export {
|
|
98
98
|
addSkillCommand
|
|
99
99
|
};
|
|
100
|
-
//# sourceMappingURL=add-skill-
|
|
100
|
+
//# sourceMappingURL=add-skill-MO4YPAYM.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
bridge,
|
|
3
3
|
bridgeSchema
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2OKYUR7B.js";
|
|
5
5
|
import {
|
|
6
6
|
DESCRIPTIONS
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3PYQIEMA.js";
|
|
8
8
|
import "./chunk-BFOYXXLG.js";
|
|
9
9
|
import {
|
|
10
10
|
getWalletOrExit
|
|
@@ -54,4 +54,4 @@ var bridgeCommand = async (args) => {
|
|
|
54
54
|
export {
|
|
55
55
|
bridgeCommand
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=bridge-
|
|
57
|
+
//# sourceMappingURL=bridge-Q4YWH4WW.js.map
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
} from "./chunk-5CMVFNXO.js";
|
|
4
4
|
import {
|
|
5
5
|
cliRequestSchema
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-JKK2XT7N.js";
|
|
7
|
+
import "./chunk-7KT6UCTT.js";
|
|
8
|
+
import "./chunk-3PYQIEMA.js";
|
|
9
9
|
import "./chunk-IKPLMFAK.js";
|
|
10
10
|
import {
|
|
11
11
|
RequestMethod
|
|
@@ -69,4 +69,4 @@ var checkCommand = async (args) => {
|
|
|
69
69
|
export {
|
|
70
70
|
checkCommand
|
|
71
71
|
};
|
|
72
|
-
//# sourceMappingURL=check-
|
|
72
|
+
//# sourceMappingURL=check-3GPSLBNI.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TOOL_PARAMS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3PYQIEMA.js";
|
|
4
4
|
import {
|
|
5
5
|
safeFetchJson
|
|
6
6
|
} from "./chunk-BFOYXXLG.js";
|
|
@@ -541,4 +541,4 @@ export {
|
|
|
541
541
|
bridgeSchema,
|
|
542
542
|
bridge
|
|
543
543
|
};
|
|
544
|
-
//# sourceMappingURL=chunk-
|
|
544
|
+
//# sourceMappingURL=chunk-2OKYUR7B.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
discoverResources
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L4U6AJW3.js";
|
|
4
4
|
import {
|
|
5
5
|
errorResponse
|
|
6
6
|
} from "./chunk-7EBJ4BCH.js";
|
|
@@ -52,4 +52,4 @@ function resolveDescription(result) {
|
|
|
52
52
|
export {
|
|
53
53
|
resolveOrigin
|
|
54
54
|
};
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
55
|
+
//# sourceMappingURL=chunk-2SZ6MZS3.js.map
|
|
@@ -6,7 +6,7 @@ var ORIGIN_METADATA = {
|
|
|
6
6
|
},
|
|
7
7
|
["https://stablesocial.dev" /* StableSocial */]: {
|
|
8
8
|
title: "StableSocial",
|
|
9
|
-
description: "Social media data for
|
|
9
|
+
description: "Social media data for TikTok, Instagram, Facebook, Reddit"
|
|
10
10
|
},
|
|
11
11
|
["https://stablestudio.dev" /* StableStudio */]: {
|
|
12
12
|
title: "StableStudio",
|
|
@@ -248,4 +248,4 @@ export {
|
|
|
248
248
|
REQUEST_FETCH_PARAMS,
|
|
249
249
|
TOOL_PARAMS
|
|
250
250
|
};
|
|
251
|
-
//# sourceMappingURL=chunk-
|
|
251
|
+
//# sourceMappingURL=chunk-3PYQIEMA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/descriptions.ts"],"sourcesContent":["/**\n * Single source of truth for all LLM-facing text in the MCP package.\n *\n * `DESCRIPTIONS` covers every tool with both an `mcp` variant (detailed,\n * AI-audience) and a `cli` variant (concise, human-readable for --help).\n * `serverInstructions` is shared across both surfaces.\n *\n * Additional exports cover parameter/output schema descriptions, origin\n * metadata, and prompt content — all LLM-facing text in one place.\n */\n\nimport type { UserOrigin } from './user-origins';\nimport { Origin } from './origins';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Origin metadata (used for MCP resource registration descriptions)\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const ORIGIN_METADATA: Record<\n string,\n { title: string; description: string }\n> = {\n [Origin.StableEnrich]: {\n title: 'StableEnrich',\n description:\n 'People/org search, Google Maps, Exa web search, LinkedIn data, Firecrawl scrape, WhitePages, email enrichment',\n },\n [Origin.StableSocial]: {\n title: 'StableSocial',\n description: 'Social media data for TikTok, Instagram, Facebook, Reddit',\n },\n [Origin.StableStudio]: {\n title: 'StableStudio',\n description: 'Generate and edit images and videos',\n },\n [Origin.StableUpload]: {\n title: 'StableUpload',\n description: 'Pay to upload files, get a permanent download URL.',\n },\n [Origin.StableEmail]: {\n title: 'StableEmail',\n description: 'Send emails',\n },\n [Origin.X402Scan]: {\n title: 'X402 Scan',\n description: 'x402 protocol explorer',\n },\n [Origin.Shirt]: {\n title: 'Shirt',\n description: 'Shirt.sh',\n },\n [Origin.X402Puppet]: {\n title: 'X402 Puppet',\n description: 'Browser automation',\n },\n [Origin.X402Facilitator]: {\n title: 'X402 Facilitator',\n description: 'Payment facilitation',\n },\n [Origin.StableMerch]: {\n title: 'StableMerch',\n description:\n 'Create shirts and mugs with custom images and have them shipped to your address.',\n },\n};\n\nexport const PRIMARY_ORIGINS = [\n Origin.StableEnrich,\n Origin.StableSocial,\n Origin.StableStudio,\n Origin.StableUpload,\n Origin.StableEmail,\n Origin.StableMerch,\n] as const;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Tool descriptions — { mcp, cli } per tool + shared serverInstructions\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const DESCRIPTIONS = {\n bridge: {\n toolNames: {\n cli: 'bridge',\n mcp: 'bridge',\n },\n title: 'Bridge Between Networks',\n mcp: `Bridge USDC between supported networks using the current wallet. Requires a source network, destination network, and amount. Use this when funds are on one supported network and the user needs them moved to another. Bridging is subject to fees.`,\n cli: `Bridge USDC between supported networks using the current wallet. Requires --from, --to, and --amount. Bridging is subject to fees.`,\n },\n\n getBalance: {\n mcp: `Get your total USDC balance across all supported networks. Auto-creates the wallet on first use (~/.agentcash/wallet.json). Use this before paid API calls to confirm you have funds available.`,\n cli: `Get your total USDC balance across all supported networks. Creates the wallet on first use (~/.agentcash/wallet.json). Use this before paid API calls to confirm you have funds available.`,\n },\n\n fetch: {\n mcp: `HTTP fetch with automatic authentication and payment handling. Makes the request, retries with SIGN-IN-WITH-X when the route exposes a SIWX challenge, and only pays if the route still returns 402. Returns response data along with payment details (price, tx hash) if a payment was made.\\n\\nFor endpoints you haven't called before in this session, you MUST call check_endpoint_schema first to confirm the request body schema. Skipping this causes 400 errors from wrong field names.`,\n cli: `HTTP fetch with automatic authentication and payment handling. If the endpoint returns 402, agentcash attempts authentication first and only falls back to payment if the route still requires it. Run 'check <url>' first to confirm the request body schema; skipping this causes 400 errors from wrong field names.`,\n epilogue: `Workflow: check <url> → fetch <url> -m POST -b '{\"field\":\"value\"}'\\nAuth mode is advisory only; fetch handles both SIWX and paid routes.`,\n },\n\n fetchWithAuth: {\n mcp: `Deprecated alias for fetch. Uses the same unified flow: probe the route, attempt SIWX when available, and only pay if the route still returns 402.\\n\\nFor new integrations, prefer fetch.`,\n cli: `Deprecated alias for fetch. Uses the same unified auth-and-payment flow, but new integrations should call 'fetch' directly.`,\n epilogue: `Deprecated: use agentcash fetch <url>. This alias is kept for compatibility.`,\n },\n\n listAccounts: {\n mcp: `List wallet accounts for each supported network. Returns the network, address, balance, and deposit link for every supported network so you can see where to fund the wallet. Auto-creates the wallet on first use (~/.agentcash/wallet.json). If onboardingCta is present, show its message to the user — it means they haven't onboarded yet and need to either visit the onboard link or deposit directly.`,\n cli: `List wallet accounts for each supported network, including network, address, balance, and deposit link. Creates the wallet on first use (~/.agentcash/wallet.json). Use this when you need the per-network funding addresses and deposit links.`,\n },\n\n getWalletInfo: {\n mcp: `Legacy combined wallet view. Returns both the total balance and the per-network account list. Prefer calling get_balance for available funds and list_accounts when you need network-specific addresses or deposit links.`,\n cli: `Legacy combined wallet view. Returns both the total balance and the per-network account list. Prefer 'balance' for available funds and 'accounts' for network-specific addresses or deposit links.`,\n },\n\n checkEndpointSchema: {\n mcp: [\n `Get the input/output schema and auth mode (paid or SIWX) for a single endpoint.`,\n `Call this to see exactly what fields the request body expects and what the response contains.`,\n `Returns the schema from the origin's OpenAPI spec. Optionally pass sample_input_body to probe the endpoint live (without payment) for an exact price quote — do this when pricing is dynamic (range-based or variable), or when you're unsure about the input schema. Treat auth mode as advisory: fetch handles both SIWX and paid routes.`,\n ].join('\\n\\n'),\n cli: `Get the input/output schema and auth mode (paid or SIWX) for an endpoint. Returns exact field names from the OpenAPI spec — call this before 'fetch' to avoid 400 errors. Pass --body to probe the endpoint live for an exact price quote when pricing is dynamic or unclear.`,\n epilogue: `Auth mode is advisory:\\n paid → agentcash fetch <url>\\n SIWX → agentcash fetch <url>`,\n },\n\n discoverApiEndpoints: {\n mcp: [\n `List available endpoints at an API origin. Returns endpoint URLs with descriptions of what each does and the auth mode for each (paid or SIWX). Works with any origin, not just the registered ones.`,\n `Call this when you need to see what routes are available at an origin — whether it's one of the registered origins or any other origin you've identified as useful. Treat the auth mode as guidance for what the route may require; fetch handles both SIWX and payment.`,\n `The response always indicates whether guidance is available. Guidance is documentation published by the API provider explaining how endpoints work together, edge cases, and usage tips. compact guidance is included automatically; set include_guidance=true to force-include full usage documentation when you need to compose two or more endpoints or need clarification on how the origin works.`,\n ].join('\\n\\n'),\n cli: `List available endpoints at an API origin with descriptions and auth modes (paid or SIWX). Works with any origin, not just registered ones. Add --include-guidance for full provider docs when composing multiple endpoints or when usage is unclear. Fetch handles both auth modes.`,\n epilogue: `Registered origins:\\n${PRIMARY_ORIGINS.flatMap(o => (ORIGIN_METADATA[o] ? [` ${o} — ${ORIGIN_METADATA[o].description}`] : [])).join('\\n')}`,\n },\n\n redeemInvite: {\n mcp: `Redeem an invite code for free USDC on Base. One-time use per code. Returns amount received and transaction hash. Use get_balance after to verify funds, or list_accounts if you need the per-network deposit links as well.`,\n cli: `Redeem an invite code for free USDC on Base. One-time use per code. Run 'balance' after to verify the balance landed.`,\n },\n\n try: {\n cli: `Fetch a new origin for its resources and return a prompt guiding the user through the process of calling the first endpoint.`,\n },\n\n search: {\n mcp: `Search for relevant paid API services by describing what you need in natural language. Returns the best matching origins with endpoint details and pricing. The top result includes the full input/output schema so you can call it immediately via fetch.\n\nOnly use this when you DON'T already know which registered origin to use. If the task clearly maps to a registered origin (e.g. people search → StableEnrich, image generation → StableStudio), skip search and go straight to discover_api_endpoints on that origin. Search is for discovering NEW or UNKNOWN capabilities outside the registered origins.\n\nSet broad=true to widen the search to include newer, unvetted tools that may not have established trust. Use this if the default results don't cover what you need.`,\n cli: `Search for paid API services by natural language query. Returns matching origins with endpoints and pricing. Use --broad to include newer, unvetted tools that may not have established trust.`,\n },\n\n reportError: {\n mcp: `EMERGENCY ONLY. Report critical MCP tool bugs. Do NOT use for normal errors (balance, network, 4xx) — those are recoverable.`,\n cli: `Report a critical bug to the agentcash team (emergency only). Do NOT use for normal errors like low balance, network timeouts, or 4xx responses — those are recoverable without filing a report.`,\n },\n\n updateSettings: {\n mcp: `Update user settings (persisted to ~/.agentcash/settings.json). Currently supports maxAmount — the maximum USD amount allowed per fetch request. If a fetch response requests more than this, the payment is rejected. Returns the current settings after applying changes.`,\n cli: `Update user settings (persisted to ~/.agentcash/settings.json). Currently supports maxAmount, which caps how much a single fetch request can spend.`,\n },\n\n getSettings: {\n mcp: `Get current user settings. Returns persisted values from ~/.agentcash/settings.json with defaults applied.`,\n cli: `Get current user settings from ~/.agentcash/settings.json, with defaults applied.`,\n },\n} as const;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Dynamic server instructions (includes user-added origins at runtime)\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst WORKFLOW = [\n `Workflow:`,\n `1. If you don't already know your balance, call get_balance. You need a balance for paid endpoints. SIWX endpoints don't require one. You don't need to call this every turn, just before your first paid call or whenever you're unsure.`,\n `2. If the balance is zero, or if the user needs a funding link or wallet addresses, call list_accounts and share the relevant deposit link. If onboardingCta is present, show it to the user.`,\n `3. If the task doesn't clearly map to any registered origin above, call search() to find relevant APIs. Skip this step when you already know the right origin — go straight to step 4.`,\n `4. Call discover_api_endpoints() to get the endpoint index — a list of available routes with descriptions and auth modes. The auth mode is advisory and tells you what the route may require.`,\n `5. Call check_endpoint_schema() to get the exact input/output schema and auth mode for the endpoint you want to call, so you know what fields to pass and what the response contains. Both discover_api_endpoints and check_endpoint_schema return the auth mode.`,\n `6. Call fetch with the correct input schema. It will attempt SIWX first when available and only pay if the route still returns 402.`,\n].join('\\n');\n\nexport function buildServerInstructions(\n userOrigins: UserOrigin[] = []\n): string {\n const allOrigins = [\n ...userOrigins.map(o => ` - ${o.url} — ${o.description}`),\n ...PRIMARY_ORIGINS.flatMap(o =>\n ORIGIN_METADATA[o] ? [` - ${o} — ${ORIGIN_METADATA[o].description}`] : []\n ),\n ].join('\\n');\n\n return [\n `AgentCash lets you call protected APIs — handling both x402 micropayments and SIWX authentication seamlessly. It manages a USDC wallet for paid endpoints and signs wallet proofs for identity-gated endpoints through fetch.`,\n `The user has installed agentcash because they want to use paid and SIWX-protected APIs as their preferred way to accomplish related tasks.`,\n `Paid endpoints require a wallet balance. SIWX endpoints are free — they only require a wallet identity.`,\n `If a task could be accomplished by one of these registered origins, run the workflow below. If you're unsure which origin to use, or the task doesn't match a registered origin, call search() to find relevant APIs.\\n${allOrigins}`,\n `discover_api_endpoints also works with any origin beyond this list. If you identify another origin that would be useful for a task, you can use it.`,\n WORKFLOW,\n `If you need to compose multiple endpoints in sequence, or anything about the origin's capabilities is unclear, call discover_api_endpoints with include_guidance=true to retrieve the origin's full usage documentation.`,\n ].join('\\n\\n');\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Shared request schema parameter descriptions\n// (used by fetch, fetch_with_auth tools)\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const REQUEST_PARAMS = {\n url: 'The endpoint URL',\n method: 'HTTP method. Defaults to GET for fetch operations.',\n body: 'Raw request body string. Passed through to the underlying fetch call as-is.',\n headers:\n 'Additional headers to include. Each entry must be a string in \"Name: value\" format.',\n timeout: 'Request timeout in milliseconds',\n} as const;\n\nexport const REQUEST_FETCH_PARAMS = {\n ...REQUEST_PARAMS,\n paymentProtocol:\n 'Payment protocol to use when payment is required. If not specified, the payment protocol will be auto-detected.',\n paymentNetwork:\n 'Chain to use for SIWX and payment when applicable. If not specified, the network will be auto-detected.',\n maxAmount:\n 'Maximum amount (in USD) to pay per request. Aborts if the endpoint requests more. Defaults to $5. Pass a higher value for known-expensive endpoints.',\n} as const;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Per-tool parameter and output schema descriptions\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const TOOL_PARAMS = {\n bridge: {\n from: 'The network to bridge from',\n to: 'The network to bridge to',\n amount: 'The amount of USDC to bridge',\n },\n fetch: REQUEST_FETCH_PARAMS,\n fetchWithAuth: REQUEST_FETCH_PARAMS,\n checkEndpointSchema: {\n ...REQUEST_PARAMS,\n method:\n 'HTTP method to check. If omitted, all methods declared in the spec are returned.',\n body: 'Optional. A sample request body to probe the endpoint live (without payment) for exact pricing. Use when pricing is range-based or quote-based, or when you need to verify the input schema. Omit to get the static schema and advisory pricing from the spec.',\n },\n try: {\n url: 'The origin URL to explore',\n },\n add: {\n url: 'The origin URL to add',\n },\n\n listAccounts: {\n output: {\n accounts: 'Wallet accounts for each supported network',\n address: 'Wallet address for this network',\n balance: 'USDC balance on this network',\n network: 'Supported payment network name',\n isNewWallet: 'Whether the wallet is new and needs to be funded',\n depositLink:\n 'Link to deposit USDC directly into the wallet for this network',\n onboardingCta:\n 'Present when the user has not yet redeemed an invite code. Show the message to the user — it directs them to onboard or deposit.',\n onboardingCtaOnboardLink: 'Link to the onboarding page',\n onboardingCtaDepositLink: 'Link to deposit USDC directly',\n onboardingCtaMessage: 'Human-readable CTA to show the user',\n },\n },\n\n redeemInvite: {\n code: 'The invite code',\n output: {\n amount: 'Amount with unit (e.g., \"5 USDC\")',\n txHash: 'Transaction hash on Base',\n },\n },\n\n search: {\n query:\n 'Natural language description of what you need (e.g. \"send physical mail\", \"generate music\", \"flight prices\")',\n broad:\n 'Include broader results that may contain newer, unvetted tools. Default is false.',\n limit: 'Maximum number of results to return (1-50). Default is 10.',\n page: 'Page number for pagination. Default is 1.',\n },\n\n discoverApiEndpoints: {\n url: 'The origin URL to discover endpoints on (e.g. https://stableenrich.dev)',\n includeGuidance:\n \"Request the origin's usage guidance. true=always include, false=never include, omit=auto (included when compact). Guidance explains how to compose multiple endpoints and covers edge cases.\",\n },\n\n reportError: {\n tool: 'MCP tool name',\n resource: 'Resource URL',\n summary: '1-2 sentence summary',\n errorMessage: 'Error message',\n stack: 'Stack trace',\n fullReport: 'Detailed report with context, logs, repro steps',\n output: {\n reportId: 'Unique report ID for tracking',\n message: 'Confirmation message',\n },\n },\n} as const;\n"],"mappings":";AAkBO,IAAM,kBAGT;AAAA,EACF,8CAAoB,GAAG;AAAA,IACrB,OAAO;AAAA,IACP,aACE;AAAA,EACJ;AAAA,EACA,8CAAoB,GAAG;AAAA,IACrB,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,8CAAoB,GAAG;AAAA,IACrB,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,8CAAoB,GAAG;AAAA,IACrB,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,4CAAmB,GAAG;AAAA,IACpB,OAAO;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QUEST_FETCH_PARAMS,
|
|
3
3
|
REQUEST_PARAMS
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3PYQIEMA.js";
|
|
5
5
|
import {
|
|
6
6
|
RequestMethod
|
|
7
7
|
} from "./chunk-LNJIXYCU.js";
|
|
@@ -40,4 +40,4 @@ export {
|
|
|
40
40
|
paymentProtocols,
|
|
41
41
|
fetchShape
|
|
42
42
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
43
|
+
//# sourceMappingURL=chunk-7KT6UCTT.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-27DZCYDB.js";
|
|
7
7
|
import {
|
|
8
8
|
INSTALL_PACKAGE_SPECIFIER
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-QOMU3YLK.js";
|
|
10
10
|
import {
|
|
11
11
|
log,
|
|
12
12
|
safeReadFile,
|
|
@@ -628,4 +628,4 @@ export {
|
|
|
628
628
|
tryAddServer,
|
|
629
629
|
addServer
|
|
630
630
|
};
|
|
631
|
-
//# sourceMappingURL=chunk-
|
|
631
|
+
//# sourceMappingURL=chunk-CUZFVI2X.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
coreRequestSchema,
|
|
3
3
|
fetchShape
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7KT6UCTT.js";
|
|
5
5
|
import {
|
|
6
6
|
REQUEST_PARAMS
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3PYQIEMA.js";
|
|
8
8
|
|
|
9
9
|
// src/shared/request/schemas/cli.ts
|
|
10
10
|
import z from "zod";
|
|
@@ -46,4 +46,4 @@ export {
|
|
|
46
46
|
cliRequestSchema,
|
|
47
47
|
cliFetchRequestSchema
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-JKK2XT7N.js.map
|
|
@@ -197,6 +197,12 @@ var PatchedExactSvmScheme = class {
|
|
|
197
197
|
}
|
|
198
198
|
};
|
|
199
199
|
|
|
200
|
+
// src/shared/protocols/x402/policies.ts
|
|
201
|
+
var MAX_UPTO_DEADLINE_SECONDS = 7 * 24 * 60 * 60;
|
|
202
|
+
var capUptoDeadline = (_x402Version, requirements) => requirements.map(
|
|
203
|
+
(r) => r.scheme === "upto" && r.maxTimeoutSeconds > MAX_UPTO_DEADLINE_SECONDS ? { ...r, maxTimeoutSeconds: MAX_UPTO_DEADLINE_SECONDS } : r
|
|
204
|
+
);
|
|
205
|
+
|
|
200
206
|
// src/shared/protocols/x402/index.ts
|
|
201
207
|
import { createSIWxPayload } from "@x402/extensions/sign-in-with-x";
|
|
202
208
|
import { createPublicClient, http } from "viem";
|
|
@@ -273,6 +279,7 @@ var safeCreatePaymentPayload = (surface, wallets, paymentRequired, paymentRequir
|
|
|
273
279
|
client: new PatchedExactSvmScheme(toClientSvmSigner(wallets.svm))
|
|
274
280
|
}
|
|
275
281
|
],
|
|
282
|
+
policies: [capUptoDeadline],
|
|
276
283
|
paymentRequirementsSelector
|
|
277
284
|
})
|
|
278
285
|
);
|
|
@@ -593,6 +600,9 @@ async function pickByBalance(response, options) {
|
|
|
593
600
|
}
|
|
594
601
|
|
|
595
602
|
// src/shared/protocols/x402/choose-payment-requirement.ts
|
|
603
|
+
var preferUpto = (requirements) => {
|
|
604
|
+
return requirements.find((pr) => pr.scheme === "upto") ?? requirements[0];
|
|
605
|
+
};
|
|
596
606
|
var choosePaymentRequirement = async ({
|
|
597
607
|
paymentRequirements,
|
|
598
608
|
options
|
|
@@ -601,7 +611,7 @@ var choosePaymentRequirement = async ({
|
|
|
601
611
|
const { paymentNetwork } = options.params;
|
|
602
612
|
if (paymentNetwork) {
|
|
603
613
|
const caip2 = networkToCaip2(paymentNetwork);
|
|
604
|
-
return paymentRequirements.
|
|
614
|
+
return preferUpto(paymentRequirements.filter((pr) => pr.network === caip2));
|
|
605
615
|
}
|
|
606
616
|
const requirementsWithBalance = await Promise.all(
|
|
607
617
|
paymentRequirements.map(async (pr) => {
|
|
@@ -641,10 +651,26 @@ var choosePaymentRequirement = async ({
|
|
|
641
651
|
}
|
|
642
652
|
})
|
|
643
653
|
);
|
|
644
|
-
|
|
654
|
+
const bestNetwork = requirementsWithBalance.sort(
|
|
655
|
+
(a, b) => b.balance - a.balance
|
|
656
|
+
)[0].requirement.network;
|
|
657
|
+
return preferUpto(
|
|
658
|
+
paymentRequirements.filter((pr) => pr.network === bestNetwork)
|
|
659
|
+
);
|
|
645
660
|
};
|
|
646
661
|
|
|
647
662
|
// src/shared/protocols/x402/handle-payment.ts
|
|
663
|
+
var isPermit2AllowanceFailureBody = (body) => body.includes("permit2") && body.includes("allowance_required");
|
|
664
|
+
var buildPermit2AllowanceErrorMessage = (params) => {
|
|
665
|
+
const { walletAddress, scheme } = params;
|
|
666
|
+
return [
|
|
667
|
+
`Payment failed: this endpoint's \`${scheme}\` scheme settles via the Permit2 contract, but your agentcash wallet (${walletAddress}) has not approved Permit2 to spend USDC.`,
|
|
668
|
+
"",
|
|
669
|
+
"The clean fix is server-side. The merchant should adopt the EIP-2612 gas-sponsoring extension \u2014 agentcash will then auto-sign an off-chain permit on each call and the facilitator pays the approval gas, with no setup required from the user. See https://docs.x402.org/extensions/eip2612-gas-sponsoring",
|
|
670
|
+
"",
|
|
671
|
+
`Until the merchant adopts that extension, you can do a one-time \`USDC.approve(0x000000000022D473030F116dDEE9F6B43aC78BA3, MAX_UINT256)\` on Base from this wallet (requires a small amount of ETH for gas, ~$0.01\u20130.10). After that, all future Permit2-based payments from this wallet work without further on-chain transactions.`
|
|
672
|
+
].join("\n");
|
|
673
|
+
};
|
|
648
674
|
async function handleX402Payment({
|
|
649
675
|
response,
|
|
650
676
|
request,
|
|
@@ -722,27 +748,50 @@ async function handleX402Payment({
|
|
|
722
748
|
"Access-Control-Expose-Headers",
|
|
723
749
|
"PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
|
|
724
750
|
);
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
751
|
+
const paidResult = await safeFetch(surface, request, timeout);
|
|
752
|
+
if (paidResult.isErr()) {
|
|
753
|
+
return paidResult;
|
|
754
|
+
}
|
|
755
|
+
const paidResponse = paidResult.value;
|
|
756
|
+
const permit2Error = await detectPermit2AllowanceError(paidResponse, {
|
|
757
|
+
walletAddress: wallets.evm.address,
|
|
758
|
+
scheme: paymentPayload.accepted.scheme
|
|
759
|
+
});
|
|
760
|
+
if (permit2Error) {
|
|
761
|
+
return x402Err(surface, permit2Error);
|
|
762
|
+
}
|
|
763
|
+
const settlementResult = safeGetPaymentSettlement(surface, paidResponse);
|
|
764
|
+
const settlement = settlementResult.isOk() ? settlementResult.value : null;
|
|
765
|
+
const maxAmount = tokenStringToNumber(paymentPayload.accepted.amount);
|
|
766
|
+
const settledAmount = settlement?.amount ? tokenStringToNumber(settlement.amount) : null;
|
|
767
|
+
const isUpTo = paymentPayload.accepted.scheme === "upto";
|
|
768
|
+
const price = settledAmount != null ? formatUsd(settledAmount) : isUpTo ? `up to ${formatUsd(maxAmount)}` : formatUsd(maxAmount);
|
|
769
|
+
return x402Ok({
|
|
770
|
+
response: paidResponse,
|
|
771
|
+
paymentInfo: {
|
|
772
|
+
protocol: "x402" /* X402 */,
|
|
773
|
+
network: caip2ToNetwork(paymentPayload.accepted.network),
|
|
774
|
+
price,
|
|
775
|
+
payment: settlement ? {
|
|
776
|
+
success: settlement.success,
|
|
777
|
+
transactionHash: settlement.transaction
|
|
778
|
+
} : null
|
|
779
|
+
}
|
|
744
780
|
});
|
|
745
781
|
}
|
|
782
|
+
async function detectPermit2AllowanceError(response, context) {
|
|
783
|
+
if (response.ok) {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
const body = await response.clone().text().catch(() => "");
|
|
787
|
+
if (!isPermit2AllowanceFailureBody(body)) {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
return {
|
|
791
|
+
cause: "permit2_allowance_required",
|
|
792
|
+
message: buildPermit2AllowanceErrorMessage(context)
|
|
793
|
+
};
|
|
794
|
+
}
|
|
746
795
|
|
|
747
796
|
// src/operations/fetch/payment.ts
|
|
748
797
|
async function executePayment(response, request, options) {
|
|
@@ -826,4 +875,4 @@ async function executeFetch(input, options) {
|
|
|
826
875
|
export {
|
|
827
876
|
executeFetch
|
|
828
877
|
};
|
|
829
|
-
//# sourceMappingURL=chunk-
|
|
878
|
+
//# sourceMappingURL=chunk-JVMJVMWB.js.map
|