@aifinpay/mcp 1.5.3 → 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 +119 -49
- 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 +7 -21
- 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 -135
- package/dist/tools/payable-fetch.js.map +0 -1
|
@@ -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;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qCAAqC;iBACnD;gBACD,aAAa,EAAE;oBACb,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,4DAA4D;wBAC5D,oCAAoC;iBACvC;aACF;YACD,QAAQ,EAAE,CAAC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,CAAC;SACtE;QACD,0EAA0E;QAC1E,WAAW,EAAE,EAAE,YAAY,EAAE,KAAK,EA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AAc,CAAC;AAEhD,wBAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsD/B;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;GA8F9B"}
|
|
@@ -1,135 +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 protocol — the AIFP-1 gateway " +
|
|
11
|
-
"(gateway.aifinpay.io) or an x402 facilitator (AiFinPay or Coinbase " +
|
|
12
|
-
"x402) — pays from the agent's wallet, retries, and returns the response " +
|
|
13
|
-
"status, headers, and body. For known " +
|
|
14
|
-
"AiFinPay-registered providers (exa, io-net, venice, ...), prefer " +
|
|
15
|
-
"`agent_call` instead — it's higher-level and resolves the bridge URL " +
|
|
16
|
-
"from the registry.",
|
|
17
|
-
inputSchema: {
|
|
18
|
-
type: "object",
|
|
19
|
-
properties: {
|
|
20
|
-
url: { type: "string", description: "Target URL (https)." },
|
|
21
|
-
method: {
|
|
22
|
-
type: "string",
|
|
23
|
-
enum: ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
24
|
-
default: "GET",
|
|
25
|
-
},
|
|
26
|
-
body: {
|
|
27
|
-
type: "string",
|
|
28
|
-
description: "Request body (string). Set Content-Type via headers if non-JSON.",
|
|
29
|
-
},
|
|
30
|
-
headers: {
|
|
31
|
-
type: "object",
|
|
32
|
-
additionalProperties: { type: "string" },
|
|
33
|
-
description: "Extra request headers.",
|
|
34
|
-
},
|
|
35
|
-
max_amount_usd: {
|
|
36
|
-
type: "number",
|
|
37
|
-
description: "Refuse to pay if the facilitator wants more than this. " +
|
|
38
|
-
"Defaults to AIFINPAY_MAX_USD env or no cap.",
|
|
39
|
-
},
|
|
40
|
-
facilitator: {
|
|
41
|
-
type: "string",
|
|
42
|
-
description: "Force a facilitator: 'aifinpay' | 'coinbase-x402'. Default 'auto'.",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
required: ["url"],
|
|
46
|
-
},
|
|
47
|
-
// Auto-pays a 402 challenge for an arbitrary URL → write + open-world + irreversible.
|
|
48
|
-
annotations: { readOnlyHint: false, openWorldHint: true, destructiveHint: true },
|
|
49
|
-
outputSchema: { type: "object" },
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export async function runPayableFetch(ctx, args) {
|
|
53
|
-
const url = String(args.url ?? "");
|
|
54
|
-
if (!url)
|
|
55
|
-
return errorResult("missing required arg: url");
|
|
56
|
-
const method = String(args.method ?? "GET").toUpperCase();
|
|
57
|
-
const body = args.body ? String(args.body) : undefined;
|
|
58
|
-
const headers = typeof args.headers === "object" && args.headers !== null
|
|
59
|
-
? args.headers
|
|
60
|
-
: undefined;
|
|
61
|
-
const maxAmountUsd = typeof args.max_amount_usd === "number"
|
|
62
|
-
? args.max_amount_usd
|
|
63
|
-
: ctx.config.maxAmountUsd;
|
|
64
|
-
const forcedFacilitator = typeof args.facilitator === "string" ? args.facilitator : undefined;
|
|
65
|
-
try {
|
|
66
|
-
// Two payment protocols answer a 402 here, and this tool used to speak only
|
|
67
|
-
// one of them.
|
|
68
|
-
//
|
|
69
|
-
// AIFP-1 gateway (gateway.aifinpay.io/{slug}/…): quote → settle on-chain →
|
|
70
|
-
// receipt → retry. Lives on the unified agent as fetchPaid().
|
|
71
|
-
// x402 facilitators (AiFinPay / Coinbase): the X-PAYMENT header flow, on
|
|
72
|
-
// the wrapped Solana-side agent as inner.pay().
|
|
73
|
-
//
|
|
74
|
-
// Before this, payable_fetch called inner.pay() only, so an MCP agent
|
|
75
|
-
// pointed at a gateway URL got stuck on the 402 it could not read — the
|
|
76
|
-
// single most common paid surface we run (AIFINP-118 neighbour).
|
|
77
|
-
//
|
|
78
|
-
// Routing, safe by construction: fetchPaid() is documented to return a
|
|
79
|
-
// non-AIFP-1 402 UNTOUCHED and cost nothing, so trying it first can pay an
|
|
80
|
-
// AIFP-1 URL but can never mis-pay an x402 one. Anything it hands back still
|
|
81
|
-
// 402 falls through to the x402 path. A caller who forces a facilitator has
|
|
82
|
-
// stated x402 intent, so skip AIFP-1 entirely for them.
|
|
83
|
-
let resp = null;
|
|
84
|
-
if (!forcedFacilitator) {
|
|
85
|
-
resp = await ctx.agent.fetchPaid(url, { method, body, headers });
|
|
86
|
-
if (resp === null) {
|
|
87
|
-
// Budget cap hit with on_limit_exceeded="skip" — do NOT then try to pay
|
|
88
|
-
// the same call via x402; that would defeat the cap the caller set.
|
|
89
|
-
return errorResult("payment skipped: the per-call or daily budget cap was reached " +
|
|
90
|
-
"(on_limit_exceeded is set to skip).");
|
|
91
|
-
}
|
|
92
|
-
if (resp.status === 402) {
|
|
93
|
-
// Not an AIFP-1 gateway 402 — fetchPaid passed it through. Try x402.
|
|
94
|
-
resp = null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (resp === null) {
|
|
98
|
-
resp = await ctx.agent.inner.pay(url, {
|
|
99
|
-
method,
|
|
100
|
-
body,
|
|
101
|
-
headers,
|
|
102
|
-
options: { maxAmountUsd, facilitator: forcedFacilitator },
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
const respHeaders = {};
|
|
106
|
-
resp.headers.forEach((v, k) => (respHeaders[k] = v));
|
|
107
|
-
const text = await resp.text();
|
|
108
|
-
return {
|
|
109
|
-
content: [
|
|
110
|
-
{
|
|
111
|
-
type: "text",
|
|
112
|
-
text: JSON.stringify({
|
|
113
|
-
status: resp.status,
|
|
114
|
-
ok: resp.ok,
|
|
115
|
-
headers: respHeaders,
|
|
116
|
-
body: text,
|
|
117
|
-
}, null, 2),
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
const err = e;
|
|
124
|
-
return errorResult(`${err.constructor.name}: ${err.message}`, `Tip: ensure agent ${ctx.agent.solanaAddress} has a funded Seat PDA, ` +
|
|
125
|
-
`or use the unified \`agent_call\` tool (Polygon settlement). ` +
|
|
126
|
-
`Docs: https://aifinpay.io/docs`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function errorResult(...lines) {
|
|
130
|
-
return {
|
|
131
|
-
isError: true,
|
|
132
|
-
content: lines.map((line) => ({ type: "text", text: line })),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
//# 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,WAAW,EACT,sEAAsE;YACtE,uEAAuE;YACvE,uEAAuE;YACvE,mCAAmC;YACnC,kEAAkE;YAClE,yEAAyE;YACzE,oEAAoE;YACpE,qEAAqE;YACrE,0EAA0E;YAC1E,uCAAuC;YACvC,mEAAmE;YACnE,uEAAuE;YACvE,oBAAoB;QACtB,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,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC;oBAC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