@aifinpay/mcp 1.5.1 → 2.0.0-rc.12
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/README.md +116 -69
- package/bin/aifinpay-mcp.js +231 -4
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +6 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +35 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +63 -0
- package/dist/config.js.map +1 -1
- package/dist/identity.d.ts +9 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +75 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/safe-fetch.d.ts +2 -0
- package/dist/safe-fetch.d.ts.map +1 -1
- package/dist/safe-fetch.js +76 -17
- package/dist/safe-fetch.js.map +1 -1
- package/dist/server.d.ts +11 -8
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +106 -102
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-address.d.ts.map +1 -1
- package/dist/tools/agent-address.js +6 -27
- package/dist/tools/agent-address.js.map +1 -1
- package/dist/tools/{payable-fetch.d.ts → agent-history.d.ts} +21 -23
- package/dist/tools/agent-history.d.ts.map +1 -0
- package/dist/tools/agent-history.js +73 -0
- package/dist/tools/agent-history.js.map +1 -0
- package/dist/tools/{agent-quote.d.ts → agent-quota.d.ts} +7 -8
- package/dist/tools/agent-quota.d.ts.map +1 -0
- package/dist/tools/agent-quota.js +95 -0
- package/dist/tools/agent-quota.js.map +1 -0
- package/dist/tools/dev-payment-quote.d.ts +39 -0
- package/dist/tools/dev-payment-quote.d.ts.map +1 -0
- package/dist/tools/dev-payment-quote.js +52 -0
- package/dist/tools/dev-payment-quote.js.map +1 -0
- package/dist/tools/{pay-with-split.d.ts → production-control.d.ts} +49 -34
- package/dist/tools/production-control.d.ts.map +1 -0
- package/dist/tools/production-control.js +132 -0
- package/dist/tools/production-control.js.map +1 -0
- package/package.json +21 -10
- package/skills/SKILL.md +143 -0
- package/dist/directory.d.ts +0 -55
- package/dist/directory.d.ts.map +0 -1
- package/dist/directory.js +0 -56
- package/dist/directory.js.map +0 -1
- package/dist/tools/agent-call.d.ts +0 -68
- package/dist/tools/agent-call.d.ts.map +0 -1
- package/dist/tools/agent-call.js +0 -129
- package/dist/tools/agent-call.js.map +0 -1
- package/dist/tools/agent-claim-self.d.ts +0 -66
- package/dist/tools/agent-claim-self.d.ts.map +0 -1
- package/dist/tools/agent-claim-self.js +0 -299
- package/dist/tools/agent-claim-self.js.map +0 -1
- package/dist/tools/agent-quote.d.ts.map +0 -1
- package/dist/tools/agent-quote.js +0 -81
- package/dist/tools/agent-quote.js.map +0 -1
- package/dist/tools/pay-with-split.d.ts.map +0 -1
- package/dist/tools/pay-with-split.js +0 -138
- package/dist/tools/pay-with-split.js.map +0 -1
- package/dist/tools/payable-fetch.d.ts.map +0 -1
- package/dist/tools/payable-fetch.js +0 -107
- package/dist/tools/payable-fetch.js.map +0 -1
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { detectFacilitator } from "@aifinpay/agent";
|
|
2
|
-
export function agentQuoteTool() {
|
|
3
|
-
return {
|
|
4
|
-
name: "agent_quote",
|
|
5
|
-
description: "Inspect a 402 challenge for a URL WITHOUT paying. Returns the detected " +
|
|
6
|
-
"facilitator flavor and the merchant's quoted amount + fee preview. " +
|
|
7
|
-
"Use before payable_fetch to decide whether the cost is acceptable.",
|
|
8
|
-
inputSchema: {
|
|
9
|
-
type: "object",
|
|
10
|
-
properties: {
|
|
11
|
-
url: { type: "string", description: "Target URL (https)." },
|
|
12
|
-
method: {
|
|
13
|
-
type: "string",
|
|
14
|
-
enum: ["GET", "POST"],
|
|
15
|
-
default: "GET",
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
required: ["url"],
|
|
19
|
-
},
|
|
20
|
-
// Read-only probe, but reaches arbitrary external URLs → openWorldHint true.
|
|
21
|
-
annotations: { readOnlyHint: true, openWorldHint: true, destructiveHint: false },
|
|
22
|
-
outputSchema: { type: "object" },
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export async function runAgentQuote(ctx, args) {
|
|
26
|
-
const url = String(args.url ?? "");
|
|
27
|
-
if (!url)
|
|
28
|
-
return errorResult("missing required arg: url");
|
|
29
|
-
const method = String(args.method ?? "GET").toUpperCase();
|
|
30
|
-
const resp = await ctx.agent.inner.fetchImpl(url, { method });
|
|
31
|
-
if (resp.status !== 402) {
|
|
32
|
-
return {
|
|
33
|
-
content: [
|
|
34
|
-
{
|
|
35
|
-
type: "text",
|
|
36
|
-
text: JSON.stringify({
|
|
37
|
-
status: resp.status,
|
|
38
|
-
note: resp.status === 200
|
|
39
|
-
? "no payment required — you can hit this without paying"
|
|
40
|
-
: `unexpected status ${resp.status} on initial probe`,
|
|
41
|
-
}, null, 2),
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const facilitator = await detectFacilitator(resp);
|
|
48
|
-
let bodyPreview = null;
|
|
49
|
-
try {
|
|
50
|
-
bodyPreview = await resp.clone().json();
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
bodyPreview = (await resp.clone().text()).slice(0, 500);
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
content: [
|
|
57
|
-
{
|
|
58
|
-
type: "text",
|
|
59
|
-
text: JSON.stringify({
|
|
60
|
-
facilitator: facilitator.name,
|
|
61
|
-
status: 402,
|
|
62
|
-
note: "fee-on-top engine not yet wired — quote shows merchant terms only. " +
|
|
63
|
-
"AiFinPay fee will be added on top at payment time.",
|
|
64
|
-
merchant_terms: bodyPreview,
|
|
65
|
-
}, null, 2),
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
const err = e;
|
|
72
|
-
return errorResult(`could not detect facilitator: ${err.message}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function errorResult(...lines) {
|
|
76
|
-
return {
|
|
77
|
-
isError: true,
|
|
78
|
-
content: lines.map((line) => ({ type: "text", text: line })),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=agent-quote.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-quote.js","sourceRoot":"","sources":["../../src/tools/agent-quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,yEAAyE;YACzE,qEAAqE;YACrE,oEAAoE;QACtE,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qBAAqB,EAAE;gBAC3D,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;oBACrB,OAAO,EAAE,KAAK;iBACf;aACF;YACD,QAAQ,EAAE,CAAC,KAAK,CAAC;SAClB;QACD,6EAA6E;QAC7E,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE;QAChF,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KACjC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAgB,EAChB,IAA6B;IAE7B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG;QAAE,OAAO,WAAW,CAAC,2BAA2B,CAA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EACD,IAAI,EACJ,CAAC,CACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAU,CAAC;QACvB,OAAO,WAAW,CAAC,iCAAiC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAG,KAAe;IACrC,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;KAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pay-with-split.d.ts","sourceRoot":"","sources":["../../src/tools/pay-with-split.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAahD,wBAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8C/B;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;GAsC9B;AAED,wBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;EAuB7B;AAED,wBAAsB,aAAa,CACjC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;GAoB9B"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
// NOTE on the chain enum below: pay_with_split and quote_split are
|
|
2
|
-
// BACKEND-INVOICE-DRIVEN — they call the operator API
|
|
3
|
-
// (POST /api/b2b/pay-with-split, GET /api/b2b/quote-split), which supports
|
|
4
|
-
// solana + 6 on-chain-verified EVM chains (polygon, base, optimism,
|
|
5
|
-
// unichain, botchain, xrplevm). Keep this enum in lockstep with the
|
|
6
|
-
// backend's ../evm-chains.js registry — a chain listed here without
|
|
7
|
-
// backend support would just be rejected server-side. Stables: USDC on
|
|
8
|
-
// base/optimism/unichain, USDC+USDT on polygon; botchain/xrplevm are
|
|
9
|
-
// native-token only. Direct (non-invoice) splitter settlement lives in
|
|
10
|
-
// the SDK's AiFinPayAgent.call() (@aifinpay/agent >= 1.3.0).
|
|
11
|
-
export function payWithSplitTool() {
|
|
12
|
-
return {
|
|
13
|
-
name: "pay_with_split",
|
|
14
|
-
description: "Get on-chain instructions for a fee-on-top atomic 3-way payment. " +
|
|
15
|
-
"The merchant receives the FULL quoted price; AiFinPay protocol fee " +
|
|
16
|
-
"(1%) and creator/referral fee (0.01%) are added ON TOP. The agent " +
|
|
17
|
-
"executes the returned instructions with their chain SDK of choice. " +
|
|
18
|
-
"Returns 503 with onboarding message if the splitter is not yet " +
|
|
19
|
-
"deployed on the requested chain.",
|
|
20
|
-
inputSchema: {
|
|
21
|
-
type: "object",
|
|
22
|
-
properties: {
|
|
23
|
-
chain: {
|
|
24
|
-
type: "string",
|
|
25
|
-
enum: ["solana", "polygon", "base", "optimism", "unichain", "botchain", "xrplevm"],
|
|
26
|
-
description: "Chain to settle on.",
|
|
27
|
-
},
|
|
28
|
-
merchant_wallet: {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "Recipient — Solana base58 pubkey or Polygon 0x address.",
|
|
31
|
-
},
|
|
32
|
-
merchant_amount: {
|
|
33
|
-
type: "string",
|
|
34
|
-
description: "Merchant's quoted price in chain units (lamports for Solana, " +
|
|
35
|
-
"wei for Polygon). Use a string to preserve precision.",
|
|
36
|
-
},
|
|
37
|
-
order_id: {
|
|
38
|
-
type: "string",
|
|
39
|
-
description: "Off-chain reference (max 64 chars).",
|
|
40
|
-
},
|
|
41
|
-
fee_recipient: {
|
|
42
|
-
type: "string",
|
|
43
|
-
description: "Optional — receives the IP-creator fee. Omit to route the " +
|
|
44
|
-
"creator slot to AiFinPay treasury.",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
required: ["chain", "merchant_wallet", "merchant_amount", "order_id"],
|
|
48
|
-
},
|
|
49
|
-
// Returns on-chain instructions/invoice; does not itself broadcast funds.
|
|
50
|
-
annotations: { readOnlyHint: false, openWorldHint: false, destructiveHint: false },
|
|
51
|
-
outputSchema: { type: "object" },
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export async function runPayWithSplit(ctx, args) {
|
|
55
|
-
const chain = args.chain;
|
|
56
|
-
if (!chain || !["solana", "polygon", "base", "optimism", "unichain", "botchain", "xrplevm"].includes(chain)) {
|
|
57
|
-
return errorResult("chain must be 'solana', 'polygon', 'base', 'optimism', 'unichain', 'botchain' or 'xrplevm'");
|
|
58
|
-
}
|
|
59
|
-
const merchantWallet = String(args.merchant_wallet ?? "");
|
|
60
|
-
const merchantAmount = String(args.merchant_amount ?? "");
|
|
61
|
-
const orderId = String(args.order_id ?? "");
|
|
62
|
-
if (!merchantWallet || !merchantAmount || !orderId) {
|
|
63
|
-
return errorResult("merchant_wallet, merchant_amount, and order_id are all required");
|
|
64
|
-
}
|
|
65
|
-
const feeRecipient = typeof args.fee_recipient === "string" && args.fee_recipient
|
|
66
|
-
? args.fee_recipient
|
|
67
|
-
: undefined;
|
|
68
|
-
try {
|
|
69
|
-
const invoice = await ctx.agent.inner.payWithSplitInvoice({
|
|
70
|
-
// published @aifinpay/agent (<=1.3.0) still types this "solana"|"polygon";
|
|
71
|
-
// the value is forwarded verbatim to the backend, which accepts all 7.
|
|
72
|
-
// Drop the cast once agent >=1.3.1 (widened types) is published.
|
|
73
|
-
chain: chain,
|
|
74
|
-
merchantWallet,
|
|
75
|
-
merchantAmount,
|
|
76
|
-
orderId,
|
|
77
|
-
feeRecipient,
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
content: [{ type: "text", text: JSON.stringify(invoice, null, 2) }],
|
|
81
|
-
structuredContent: invoice,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
const err = e;
|
|
86
|
-
return errorResult(`${err.constructor.name}: ${err.message}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export function quoteSplitTool() {
|
|
90
|
-
return {
|
|
91
|
-
name: "quote_split",
|
|
92
|
-
description: "Pure-view: compute the fee-on-top breakdown (merchant + treasury + " +
|
|
93
|
-
"creator + total) for a given merchant amount. No payment, no auth. " +
|
|
94
|
-
"Use this BEFORE pay_with_split to decide whether the cost is " +
|
|
95
|
-
"acceptable.",
|
|
96
|
-
inputSchema: {
|
|
97
|
-
type: "object",
|
|
98
|
-
properties: {
|
|
99
|
-
chain: { type: "string", enum: ["solana", "polygon", "base", "optimism", "unichain", "botchain", "xrplevm"] },
|
|
100
|
-
merchant_amount: {
|
|
101
|
-
type: "string",
|
|
102
|
-
description: "Merchant's quoted price (lamports for Solana, wei for Polygon).",
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
required: ["chain", "merchant_amount"],
|
|
106
|
-
},
|
|
107
|
-
annotations: { readOnlyHint: true, openWorldHint: false, destructiveHint: false },
|
|
108
|
-
outputSchema: { type: "object" },
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
export async function runQuoteSplit(ctx, args) {
|
|
112
|
-
const chain = args.chain;
|
|
113
|
-
if (!chain || !["solana", "polygon", "base", "optimism", "unichain", "botchain", "xrplevm"].includes(chain)) {
|
|
114
|
-
return errorResult("chain must be 'solana', 'polygon', 'base', 'optimism', 'unichain', 'botchain' or 'xrplevm'");
|
|
115
|
-
}
|
|
116
|
-
const merchantAmount = String(args.merchant_amount ?? "");
|
|
117
|
-
if (!merchantAmount)
|
|
118
|
-
return errorResult("merchant_amount required");
|
|
119
|
-
try {
|
|
120
|
-
// Same published-type lag as above — cast until agent >=1.3.1 ships.
|
|
121
|
-
const quote = await ctx.agent.inner.quoteSplit({ chain: chain, merchantAmount });
|
|
122
|
-
return {
|
|
123
|
-
content: [{ type: "text", text: JSON.stringify(quote, null, 2) }],
|
|
124
|
-
structuredContent: quote,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
const err = e;
|
|
129
|
-
return errorResult(`${err.constructor.name}: ${err.message}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function errorResult(...lines) {
|
|
133
|
-
return {
|
|
134
|
-
isError: true,
|
|
135
|
-
content: lines.map((line) => ({ type: "text", text: line })),
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=pay-with-split.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pay-with-split.js","sourceRoot":"","sources":["../../src/tools/pay-with-split.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,sDAAsD;AACtD,2EAA2E;AAC3E,oEAAoE;AACpE,oEAAoE;AACpE,oEAAoE;AACpE,uEAAuE;AACvE,qEAAqE;AACrE,uEAAuE;AACvE,6DAA6D;AAE7D,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,mEAAmE;YACnE,qEAAqE;YACrE,oEAAoE;YACpE,qEAAqE;YACrE,iEAAiE;YACjE,kCAAkC;QACpC,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,CAAC;oBAClF,WAAW,EAAE,qBAAqB;iBACnC;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,yDAAyD;iBAC5D;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,+DAA+D;wBAC/D,uDAAuD;iBAC1D;gBACD,QAAQ,EAAE;oB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AG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;KAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payable-fetch.d.ts","sourceRoot":"","sources":["../../src/tools/payable-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,wBAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqD/B;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;GA6D9B"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
export function payableFetchTool() {
|
|
2
|
-
return {
|
|
3
|
-
name: "payable_fetch",
|
|
4
|
-
description: "USE THIS TOOL to fetch any URL that may require payment (HTTP 402). " +
|
|
5
|
-
"DO NOT use WebFetch for URLs that might be paid endpoints — WebFetch " +
|
|
6
|
-
"cannot sign x402 payment headers and will only see the 402 challenge " +
|
|
7
|
-
"without being able to settle it. " +
|
|
8
|
-
"Natural-language triggers: 'fetch <paid URL>', 'pay for <url>', " +
|
|
9
|
-
"'try this URL — it might be paid', 'pay the 402 and get the response'. " +
|
|
10
|
-
"The agent automatically detects the x402 facilitator flavor (AiFinPay " +
|
|
11
|
-
"or Coinbase x402), signs a payment from the agent's wallet, retries, " +
|
|
12
|
-
"and returns the response status, headers, and body. For known " +
|
|
13
|
-
"AiFinPay-registered providers (exa, io-net, venice, ...), prefer " +
|
|
14
|
-
"`agent_call` instead — it's higher-level and resolves the bridge URL " +
|
|
15
|
-
"from the registry.",
|
|
16
|
-
inputSchema: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {
|
|
19
|
-
url: { type: "string", description: "Target URL (https)." },
|
|
20
|
-
method: {
|
|
21
|
-
type: "string",
|
|
22
|
-
enum: ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
23
|
-
default: "GET",
|
|
24
|
-
},
|
|
25
|
-
body: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Request body (string). Set Content-Type via headers if non-JSON.",
|
|
28
|
-
},
|
|
29
|
-
headers: {
|
|
30
|
-
type: "object",
|
|
31
|
-
additionalProperties: { type: "string" },
|
|
32
|
-
description: "Extra request headers.",
|
|
33
|
-
},
|
|
34
|
-
max_amount_usd: {
|
|
35
|
-
type: "number",
|
|
36
|
-
description: "Refuse to pay if the facilitator wants more than this. " +
|
|
37
|
-
"Defaults to AIFINPAY_MAX_USD env or no cap.",
|
|
38
|
-
},
|
|
39
|
-
facilitator: {
|
|
40
|
-
type: "string",
|
|
41
|
-
description: "Force a facilitator: 'aifinpay' | 'coinbase-x402'. Default 'auto'.",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
required: ["url"],
|
|
45
|
-
},
|
|
46
|
-
// Auto-pays a 402 challenge for an arbitrary URL → write + open-world + irreversible.
|
|
47
|
-
annotations: { readOnlyHint: false, openWorldHint: true, destructiveHint: true },
|
|
48
|
-
outputSchema: { type: "object" },
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export async function runPayableFetch(ctx, args) {
|
|
52
|
-
const url = String(args.url ?? "");
|
|
53
|
-
if (!url)
|
|
54
|
-
return errorResult("missing required arg: url");
|
|
55
|
-
const method = String(args.method ?? "GET").toUpperCase();
|
|
56
|
-
const body = args.body ? String(args.body) : undefined;
|
|
57
|
-
const headers = typeof args.headers === "object" && args.headers !== null
|
|
58
|
-
? args.headers
|
|
59
|
-
: undefined;
|
|
60
|
-
const maxAmountUsd = typeof args.max_amount_usd === "number"
|
|
61
|
-
? args.max_amount_usd
|
|
62
|
-
: ctx.config.maxAmountUsd;
|
|
63
|
-
try {
|
|
64
|
-
// Legacy URL-keyed path lives on the wrapped Solana-side Agent. For
|
|
65
|
-
// registry-resolved Polygon-native calls prefer the `agent_call` tool.
|
|
66
|
-
const resp = await ctx.agent.inner.pay(url, {
|
|
67
|
-
method,
|
|
68
|
-
body,
|
|
69
|
-
headers,
|
|
70
|
-
options: {
|
|
71
|
-
maxAmountUsd,
|
|
72
|
-
facilitator: typeof args.facilitator === "string"
|
|
73
|
-
? args.facilitator
|
|
74
|
-
: undefined,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const respHeaders = {};
|
|
78
|
-
resp.headers.forEach((v, k) => (respHeaders[k] = v));
|
|
79
|
-
const text = await resp.text();
|
|
80
|
-
return {
|
|
81
|
-
content: [
|
|
82
|
-
{
|
|
83
|
-
type: "text",
|
|
84
|
-
text: JSON.stringify({
|
|
85
|
-
status: resp.status,
|
|
86
|
-
ok: resp.ok,
|
|
87
|
-
headers: respHeaders,
|
|
88
|
-
body: text,
|
|
89
|
-
}, null, 2),
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
const err = e;
|
|
96
|
-
return errorResult(`${err.constructor.name}: ${err.message}`, `Tip: ensure agent ${ctx.agent.solanaAddress} has a funded Seat PDA, ` +
|
|
97
|
-
`or use the unified \`agent_call\` tool (Polygon settlement). ` +
|
|
98
|
-
`Docs: https://aifinpay.io/docs`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function errorResult(...lines) {
|
|
102
|
-
return {
|
|
103
|
-
isError: true,
|
|
104
|
-
content: lines.map((line) => ({ type: "text", text: line })),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=payable-fetch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payable-fetch.js","sourceRoot":"","sources":["../../src/tools/payable-fetch.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,WAA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