@varun-ai07/covenant-mcp 1.2.3 → 1.3.2
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 +1056 -170
- package/dist/abis/MultiTokenEscrow.json +836 -0
- package/dist/abis/v2/AgentRegistry.json +872 -0
- package/dist/abis/v2/DisputeResolution.json +493 -0
- package/dist/abis/v2/InsurancePool.json +645 -0
- package/dist/abis/v2/ReceiptVerifier.json +394 -0
- package/dist/abis/v2/RevisionManager.json +544 -0
- package/dist/abis/v2/TaskEscrow.json +1018 -0
- package/dist/cli.js +0 -0
- package/dist/config.d.ts +13 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +84 -25
- package/dist/config.js.map +1 -1
- package/dist/lib/did.d.ts +72 -0
- package/dist/lib/did.d.ts.map +1 -0
- package/dist/lib/did.js +115 -0
- package/dist/lib/did.js.map +1 -0
- package/dist/lib/formatResponse.d.ts +33 -0
- package/dist/lib/formatResponse.d.ts.map +1 -0
- package/dist/lib/formatResponse.js +92 -0
- package/dist/lib/formatResponse.js.map +1 -0
- package/dist/lib/schemaHelpers.d.ts +11 -0
- package/dist/lib/schemaHelpers.d.ts.map +1 -0
- package/dist/lib/schemaHelpers.js +11 -0
- package/dist/lib/schemaHelpers.js.map +1 -0
- package/dist/lib/store.d.ts +10 -0
- package/dist/lib/store.d.ts.map +1 -0
- package/dist/lib/store.js +39 -0
- package/dist/lib/store.js.map +1 -0
- package/dist/lib/verify.d.ts +21 -0
- package/dist/lib/verify.d.ts.map +1 -0
- package/dist/lib/verify.js +568 -0
- package/dist/lib/verify.js.map +1 -0
- package/dist/schemas.d.ts +5 -5
- package/dist/schemas.d.ts.map +1 -1
- package/dist/server.d.ts +1 -25
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +53 -37
- package/dist/server.js.map +1 -1
- package/dist/shared-types.d.ts +67 -0
- package/dist/shared-types.d.ts.map +1 -0
- package/dist/shared-types.js +86 -0
- package/dist/shared-types.js.map +1 -0
- package/dist/tools/account-abstraction.d.ts +3 -0
- package/dist/tools/account-abstraction.d.ts.map +1 -0
- package/dist/tools/account-abstraction.js +364 -0
- package/dist/tools/account-abstraction.js.map +1 -0
- package/dist/tools/batches.d.ts.map +1 -1
- package/dist/tools/batches.js +68 -37
- package/dist/tools/batches.js.map +1 -1
- package/dist/tools/bounties.d.ts +3 -0
- package/dist/tools/bounties.d.ts.map +1 -0
- package/dist/tools/bounties.js +304 -0
- package/dist/tools/bounties.js.map +1 -0
- package/dist/tools/bridge.d.ts +3 -0
- package/dist/tools/bridge.d.ts.map +1 -0
- package/dist/tools/bridge.js +190 -0
- package/dist/tools/bridge.js.map +1 -0
- package/dist/tools/collectives.d.ts.map +1 -1
- package/dist/tools/collectives.js +74 -46
- package/dist/tools/collectives.js.map +1 -1
- package/dist/tools/covenant-help.d.ts +3 -0
- package/dist/tools/covenant-help.d.ts.map +1 -0
- package/dist/tools/covenant-help.js +321 -0
- package/dist/tools/covenant-help.js.map +1 -0
- package/dist/tools/cross-chain.d.ts +3 -0
- package/dist/tools/cross-chain.d.ts.map +1 -0
- package/dist/tools/cross-chain.js +77 -0
- package/dist/tools/cross-chain.js.map +1 -0
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +39 -33
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/escrow.d.ts.map +1 -1
- package/dist/tools/escrow.js +248 -199
- package/dist/tools/escrow.js.map +1 -1
- package/dist/tools/fiat-onramp.d.ts +3 -0
- package/dist/tools/fiat-onramp.d.ts.map +1 -0
- package/dist/tools/fiat-onramp.js +108 -0
- package/dist/tools/fiat-onramp.js.map +1 -0
- package/dist/tools/governance.d.ts +3 -0
- package/dist/tools/governance.d.ts.map +1 -0
- package/dist/tools/governance.js +271 -0
- package/dist/tools/governance.js.map +1 -0
- package/dist/tools/grants.d.ts +3 -0
- package/dist/tools/grants.d.ts.map +1 -0
- package/dist/tools/grants.js +269 -0
- package/dist/tools/grants.js.map +1 -0
- package/dist/tools/insurance.d.ts.map +1 -1
- package/dist/tools/insurance.js +92 -45
- package/dist/tools/insurance.js.map +1 -1
- package/dist/tools/market.d.ts.map +1 -1
- package/dist/tools/market.js +122 -103
- package/dist/tools/market.js.map +1 -1
- package/dist/tools/matching.d.ts +3 -0
- package/dist/tools/matching.d.ts.map +1 -0
- package/dist/tools/matching.js +233 -0
- package/dist/tools/matching.js.map +1 -0
- package/dist/tools/messaging.d.ts +3 -0
- package/dist/tools/messaging.d.ts.map +1 -0
- package/dist/tools/messaging.js +159 -0
- package/dist/tools/messaging.js.map +1 -0
- package/dist/tools/multi-token.d.ts +3 -0
- package/dist/tools/multi-token.d.ts.map +1 -0
- package/dist/tools/multi-token.js +274 -0
- package/dist/tools/multi-token.js.map +1 -0
- package/dist/tools/offchain-coordinator.d.ts +3 -0
- package/dist/tools/offchain-coordinator.d.ts.map +1 -0
- package/dist/tools/offchain-coordinator.js +436 -0
- package/dist/tools/offchain-coordinator.js.map +1 -0
- package/dist/tools/protocol.d.ts.map +1 -1
- package/dist/tools/protocol.js +19 -6
- package/dist/tools/protocol.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +39 -39
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +90 -43
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/reputation-vc.d.ts +3 -0
- package/dist/tools/reputation-vc.d.ts.map +1 -0
- package/dist/tools/reputation-vc.js +438 -0
- package/dist/tools/reputation-vc.js.map +1 -0
- package/dist/tools/revisions.d.ts +3 -0
- package/dist/tools/revisions.d.ts.map +1 -0
- package/dist/tools/revisions.js +108 -0
- package/dist/tools/revisions.js.map +1 -0
- package/dist/tools/router.d.ts +3 -0
- package/dist/tools/router.d.ts.map +1 -0
- package/dist/tools/router.js +104 -0
- package/dist/tools/router.js.map +1 -0
- package/dist/tools/streaming.d.ts +3 -0
- package/dist/tools/streaming.d.ts.map +1 -0
- package/dist/tools/streaming.js +350 -0
- package/dist/tools/streaming.js.map +1 -0
- package/dist/tools/templates.d.ts +3 -0
- package/dist/tools/templates.d.ts.map +1 -0
- package/dist/tools/templates.js +392 -0
- package/dist/tools/templates.js.map +1 -0
- package/dist/tools/training.d.ts +3 -0
- package/dist/tools/training.d.ts.map +1 -0
- package/dist/tools/training.js +304 -0
- package/dist/tools/training.js.map +1 -0
- package/dist/tools/v2-settlement.d.ts +3 -0
- package/dist/tools/v2-settlement.d.ts.map +1 -0
- package/dist/tools/v2-settlement.js +226 -0
- package/dist/tools/v2-settlement.js.map +1 -0
- package/dist/tools/verification.d.ts +3 -0
- package/dist/tools/verification.d.ts.map +1 -0
- package/dist/tools/verification.js +215 -0
- package/dist/tools/verification.js.map +1 -0
- package/dist/tools/verify-deep.d.ts +3 -0
- package/dist/tools/verify-deep.d.ts.map +1 -0
- package/dist/tools/verify-deep.js +125 -0
- package/dist/tools/verify-deep.js.map +1 -0
- package/dist/types.d.ts +16 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -23
- package/dist/types.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Abstraction MCP Tools
|
|
3
|
+
*
|
|
4
|
+
* corven_create_smart_wallet — Deploy a new AgentSmartWallet
|
|
5
|
+
* corven_get_smart_wallet — Get wallet details (limits, pause, balance)
|
|
6
|
+
* corven_set_spending_limit — Controller sets daily/tx limits
|
|
7
|
+
* corven_set_recipient — Controller manages whitelist
|
|
8
|
+
* corven_emergency_pause — Controller pauses/unpauses
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { parseEther, formatEther } from "viem";
|
|
12
|
+
import { getAccount, getWalletClient, getPublicClient, getExplorerTxUrl } from "../config.js";
|
|
13
|
+
import { formatReadResult } from "../handlers/transactions.js";
|
|
14
|
+
import { formatSuccess, formatStructuredError, parseContractError } from "../lib/formatResponse.js";
|
|
15
|
+
import { ethAddress, ethAmount } from "../lib/schemaHelpers.js";
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
// ─── Inline ABI for AgentSmartWallet ──────────────────────────
|
|
19
|
+
// Matches the Solidity contract at contracts/v2/core/AgentSmartWallet.sol
|
|
20
|
+
const AgentSmartWalletAbi = [
|
|
21
|
+
{ type: "constructor", inputs: [
|
|
22
|
+
{ name: "_controller", type: "address" },
|
|
23
|
+
{ name: "_dailyLimit", type: "uint256" },
|
|
24
|
+
{ name: "_perTxLimit", type: "uint256" },
|
|
25
|
+
], stateMutability: "nonpayable" },
|
|
26
|
+
{ type: "receive", stateMutability: "payable" },
|
|
27
|
+
{ type: "function", name: "controller", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
28
|
+
{ type: "function", name: "dailyLimit", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
|
|
29
|
+
{ type: "function", name: "perTxLimit", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
|
|
30
|
+
{ type: "function", name: "dailySpent", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
|
|
31
|
+
{ type: "function", name: "lastResetDay", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
|
|
32
|
+
{ type: "function", name: "paused", inputs: [], outputs: [{ type: "bool" }], stateMutability: "view" },
|
|
33
|
+
{ type: "function", name: "allowedRecipients", inputs: [{ name: "", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
|
|
34
|
+
{ type: "function", name: "owner", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
35
|
+
{ type: "function", name: "getRemainingDailyAllowance", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
|
|
36
|
+
{ type: "function", name: "getBalance", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
|
|
37
|
+
{ type: "function", name: "execute", inputs: [
|
|
38
|
+
{ name: "to", type: "address" },
|
|
39
|
+
{ name: "value", type: "uint256" },
|
|
40
|
+
{ name: "data", type: "bytes" },
|
|
41
|
+
], outputs: [{ name: "result", type: "bytes" }], stateMutability: "nonpayable" },
|
|
42
|
+
{ type: "function", name: "setDailyLimit", inputs: [{ name: "_limit", type: "uint256" }], outputs: [], stateMutability: "nonpayable" },
|
|
43
|
+
{ type: "function", name: "setPerTxLimit", inputs: [{ name: "_limit", type: "uint256" }], outputs: [], stateMutability: "nonpayable" },
|
|
44
|
+
{ type: "function", name: "setRecipient", inputs: [
|
|
45
|
+
{ name: "_recipient", type: "address" },
|
|
46
|
+
{ name: "_allowed", type: "bool" },
|
|
47
|
+
], outputs: [], stateMutability: "nonpayable" },
|
|
48
|
+
{ type: "function", name: "setPaused", inputs: [{ name: "_paused", type: "bool" }], outputs: [], stateMutability: "nonpayable" },
|
|
49
|
+
{ type: "function", name: "setController", inputs: [{ name: "_controller", type: "address" }], outputs: [], stateMutability: "nonpayable" },
|
|
50
|
+
];
|
|
51
|
+
// ─── Bytecode loader ──────────────────────────────────────────
|
|
52
|
+
function loadSmartWalletBytecode() {
|
|
53
|
+
// Resolve from the MCP package root
|
|
54
|
+
const candidates = [
|
|
55
|
+
// Relative to this source file (mcp/src/tools -> mcp -> contracts)
|
|
56
|
+
path.resolve(process.cwd(), "../contracts/artifacts/contracts/v2/core/AgentSmartWallet.sol/AgentSmartWallet.json"),
|
|
57
|
+
// Absolute project layout
|
|
58
|
+
path.resolve(process.cwd(), "contracts/artifacts/contracts/v2/core/AgentSmartWallet.sol/AgentSmartWallet.json"),
|
|
59
|
+
];
|
|
60
|
+
for (const artifactPath of candidates) {
|
|
61
|
+
if (fs.existsSync(artifactPath)) {
|
|
62
|
+
const artifact = JSON.parse(fs.readFileSync(artifactPath, "utf-8"));
|
|
63
|
+
return artifact.bytecode;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error("AgentSmartWallet artifact not found. Run: cd /home/vxrun/Projects/varun/contracts && npx hardhat compile");
|
|
67
|
+
}
|
|
68
|
+
// ─── Deploy helper ────────────────────────────────────────────
|
|
69
|
+
async function deploySmartWallet(controller, dailyLimitWei, perTxLimitWei) {
|
|
70
|
+
const wallet = getWalletClient();
|
|
71
|
+
const publicClient = getPublicClient();
|
|
72
|
+
const account = getAccount();
|
|
73
|
+
if (!wallet || !account) {
|
|
74
|
+
return { status: "error", error: "No wallet client available. Set PRIVATE_KEY and COVENANT_WALLET_MODE=autonomous." };
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const bytecode = loadSmartWalletBytecode();
|
|
78
|
+
const hash = await wallet.deployContract({
|
|
79
|
+
abi: AgentSmartWalletAbi,
|
|
80
|
+
bytecode,
|
|
81
|
+
args: [controller, dailyLimitWei, perTxLimitWei],
|
|
82
|
+
account,
|
|
83
|
+
});
|
|
84
|
+
console.error(`[TX] Deploy AgentSmartWallet: ${hash}`);
|
|
85
|
+
console.error(`[TX] Explorer: ${getExplorerTxUrl(hash)}`);
|
|
86
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
87
|
+
hash,
|
|
88
|
+
timeout: 60_000,
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
status: "success",
|
|
92
|
+
txHash: hash,
|
|
93
|
+
blockNumber: receipt.blockNumber,
|
|
94
|
+
gasUsed: receipt.gasUsed,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const msg = error?.message || String(error);
|
|
99
|
+
return { status: "error", error: msg.slice(0, 500) };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ─── Write helper (for existing contracts) ────────────────────
|
|
103
|
+
async function executeWalletWrite(walletAddress, functionName, args) {
|
|
104
|
+
const wallet = getWalletClient();
|
|
105
|
+
const publicClient = getPublicClient();
|
|
106
|
+
const account = getAccount();
|
|
107
|
+
if (!wallet || !account) {
|
|
108
|
+
return { status: "error", error: "No wallet client available. Set PRIVATE_KEY and COVENANT_WALLET_MODE=autonomous." };
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const { request } = await publicClient.simulateContract({
|
|
112
|
+
address: walletAddress,
|
|
113
|
+
abi: AgentSmartWalletAbi,
|
|
114
|
+
functionName,
|
|
115
|
+
args: args,
|
|
116
|
+
account,
|
|
117
|
+
});
|
|
118
|
+
const hash = await wallet.writeContract(request);
|
|
119
|
+
console.error(`[TX] ${functionName}: ${hash}`);
|
|
120
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
121
|
+
hash,
|
|
122
|
+
timeout: 60_000,
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
status: "success",
|
|
126
|
+
txHash: hash,
|
|
127
|
+
blockNumber: receipt.blockNumber,
|
|
128
|
+
gasUsed: receipt.gasUsed,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const msg = error?.message || String(error);
|
|
133
|
+
const revertMatch = msg.match(/revert(?:ed| reason)?\s*:?\s*"?([^"\n]+)"?/i);
|
|
134
|
+
return {
|
|
135
|
+
status: "error",
|
|
136
|
+
error: revertMatch ? `Transaction reverted: ${revertMatch[1]}` : msg.slice(0, 500),
|
|
137
|
+
reason: msg,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// ─── Error helper ─────────────────────────────────────────────
|
|
142
|
+
function txErrorMessage(result) {
|
|
143
|
+
if (result.status === "error")
|
|
144
|
+
return result.error;
|
|
145
|
+
if (result.status === "prepared")
|
|
146
|
+
return "Transaction prepared but not sent (prepare-only mode).";
|
|
147
|
+
return "Unknown error.";
|
|
148
|
+
}
|
|
149
|
+
// ─── Register tools ───────────────────────────────────────────
|
|
150
|
+
export function registerAATools(server) {
|
|
151
|
+
// ──────────────────────────────────────────────────────────────
|
|
152
|
+
// corven_create_smart_wallet
|
|
153
|
+
// ──────────────────────────────────────────────────────────────
|
|
154
|
+
server.registerTool("corven_create_smart_wallet", {
|
|
155
|
+
title: "Deploy Smart Wallet",
|
|
156
|
+
description: "Deploy a new AgentSmartWallet for the caller. Creates an ERC-4337 compatible smart account with spending limits, recipient whitelist, and emergency pause.\n" +
|
|
157
|
+
"USE WHEN: An agent needs a dedicated smart wallet with safety guardrails. The deployer becomes the owner (agent EOA) and controller (human guardian).\n" +
|
|
158
|
+
"REQUIRES: PRIVATE_KEY set in .env. Wallet needs ~0.001 ETH for gas.\n" +
|
|
159
|
+
"RETURNS: Wallet address, controller, daily limit, per-tx limit, Basescan link.\n" +
|
|
160
|
+
"COMES BEFORE: corven_set_recipient to whitelist payment targets. corven_set_spending_limit to adjust limits.\n" +
|
|
161
|
+
"NOTE: The controller can pause the wallet, change limits, and manage the whitelist. The agent can only execute transactions within the set limits.",
|
|
162
|
+
inputSchema: {
|
|
163
|
+
controller: ethAddress.describe("Human controller address (can pause, set limits, manage whitelist)"),
|
|
164
|
+
dailyLimit: ethAmount.describe("Daily spending limit in ETH (e.g. '1.0')"),
|
|
165
|
+
perTxLimit: ethAmount.describe("Per-transaction cap in ETH (e.g. '0.1')"),
|
|
166
|
+
},
|
|
167
|
+
}, async ({ controller, dailyLimit, perTxLimit }) => {
|
|
168
|
+
try {
|
|
169
|
+
const account = getAccount();
|
|
170
|
+
if (!account) {
|
|
171
|
+
return formatStructuredError("No private key configured.", "PRIVATE_KEY environment variable is not set.", "Set PRIVATE_KEY in your .env file.", false);
|
|
172
|
+
}
|
|
173
|
+
const dailyLimitWei = parseEther(dailyLimit);
|
|
174
|
+
const perTxLimitWei = parseEther(perTxLimit);
|
|
175
|
+
const result = await deploySmartWallet(controller, dailyLimitWei, perTxLimitWei);
|
|
176
|
+
if (result.status === "success") {
|
|
177
|
+
const publicClient = getPublicClient();
|
|
178
|
+
const receipt = await publicClient.getTransactionReceipt({ hash: result.txHash });
|
|
179
|
+
const walletAddr = receipt.contractAddress;
|
|
180
|
+
return formatSuccess(`AgentSmartWallet deployed. Agent = owner, human = controller.`, {
|
|
181
|
+
walletAddress: walletAddr || "Check Basescan for contract address",
|
|
182
|
+
owner: account.address,
|
|
183
|
+
controller,
|
|
184
|
+
dailyLimit: `${dailyLimit} ETH`,
|
|
185
|
+
perTxLimit: `${perTxLimit} ETH`,
|
|
186
|
+
}, result.txHash, [
|
|
187
|
+
"Call corven_set_recipient to whitelist addresses the wallet can send to.",
|
|
188
|
+
"Call corven_set_spending_limit to adjust daily/tx limits.",
|
|
189
|
+
"The controller can call corven_emergency_pause to freeze the wallet.",
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
content: [{ type: "text", text: `Deployment failed: ${txErrorMessage(result)}` }],
|
|
194
|
+
isError: true,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
const parsed = parseContractError(e);
|
|
199
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
// ──────────────────────────────────────────────────────────────
|
|
203
|
+
// corven_get_smart_wallet
|
|
204
|
+
// ──────────────────────────────────────────────────────────────
|
|
205
|
+
server.registerTool("corven_get_smart_wallet", {
|
|
206
|
+
title: "Get Smart Wallet Details",
|
|
207
|
+
description: "Read all details of an AgentSmartWallet: owner, controller, limits, daily spend, pause status, balance.\n" +
|
|
208
|
+
"USE WHEN: Checking current spending limits. Verifying pause status. Checking remaining daily allowance.\n" +
|
|
209
|
+
"REQUIRES: Nothing. Free read-only call.\n" +
|
|
210
|
+
"RETURNS: Owner, controller, daily limit, per-tx limit, daily spent, remaining allowance, pause status, balance.\n" +
|
|
211
|
+
"NOTE: Daily counter resets at midnight UTC automatically.",
|
|
212
|
+
inputSchema: {
|
|
213
|
+
walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
|
|
214
|
+
},
|
|
215
|
+
}, async ({ walletAddress }) => {
|
|
216
|
+
try {
|
|
217
|
+
const publicClient = getPublicClient();
|
|
218
|
+
const addr = walletAddress;
|
|
219
|
+
const [owner, controller, dailyLimit, perTxLimit, dailySpent, lastResetDay, paused, balance, remainingAllowance] = await Promise.all([
|
|
220
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "owner" }),
|
|
221
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "controller" }),
|
|
222
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "dailyLimit" }),
|
|
223
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "perTxLimit" }),
|
|
224
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "dailySpent" }),
|
|
225
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "lastResetDay" }),
|
|
226
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "paused" }),
|
|
227
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "getBalance" }),
|
|
228
|
+
publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "getRemainingDailyAllowance" }),
|
|
229
|
+
]);
|
|
230
|
+
return formatReadResult({
|
|
231
|
+
walletAddress: walletAddress,
|
|
232
|
+
owner,
|
|
233
|
+
controller,
|
|
234
|
+
dailyLimit: formatEther(dailyLimit) + " ETH",
|
|
235
|
+
perTxLimit: formatEther(perTxLimit) + " ETH",
|
|
236
|
+
dailySpent: formatEther(dailySpent) + " ETH",
|
|
237
|
+
remainingDailyAllowance: formatEther(remainingAllowance) + " ETH",
|
|
238
|
+
lastResetDay: Number(lastResetDay),
|
|
239
|
+
paused: paused ? "YES" : "NO",
|
|
240
|
+
balance: formatEther(balance) + " ETH",
|
|
241
|
+
}, `Smart Wallet ${walletAddress}`);
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
const parsed = parseContractError(e);
|
|
245
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
// ──────────────────────────────────────────────────────────────
|
|
249
|
+
// corven_set_spending_limit
|
|
250
|
+
// ──────────────────────────────────────────────────────────────
|
|
251
|
+
server.registerTool("corven_set_spending_limit", {
|
|
252
|
+
title: "Set Spending Limits",
|
|
253
|
+
description: "Controller sets the daily and/or per-transaction spending limits on an AgentSmartWallet.\n" +
|
|
254
|
+
"USE WHEN: The agent needs higher/lower limits. Adjusting guardrails for a specific workload.\n" +
|
|
255
|
+
"REQUIRES: PRIVATE_KEY must be the controller address. Only the human controller can call this.\n" +
|
|
256
|
+
"RETURNS: Updated limits, transaction confirmation.\n" +
|
|
257
|
+
"NOTE: The agent (owner) CANNOT call this -- only the controller can adjust limits.",
|
|
258
|
+
inputSchema: {
|
|
259
|
+
walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
|
|
260
|
+
dailyLimit: ethAmount.optional().describe("New daily spending limit in ETH (omit to keep current)"),
|
|
261
|
+
perTxLimit: ethAmount.optional().describe("New per-transaction cap in ETH (omit to keep current)"),
|
|
262
|
+
},
|
|
263
|
+
}, async ({ walletAddress, dailyLimit, perTxLimit }) => {
|
|
264
|
+
try {
|
|
265
|
+
if (!dailyLimit && !perTxLimit) {
|
|
266
|
+
return formatStructuredError("No limits provided.", "At least one of dailyLimit or perTxLimit must be specified.", "Provide dailyLimit and/or perTxLimit in ETH.", false);
|
|
267
|
+
}
|
|
268
|
+
const results = [];
|
|
269
|
+
if (dailyLimit) {
|
|
270
|
+
const result = await executeWalletWrite(walletAddress, "setDailyLimit", [parseEther(dailyLimit)]);
|
|
271
|
+
if (result.status === "success") {
|
|
272
|
+
results.push(`Daily limit set to ${dailyLimit} ETH`);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (perTxLimit) {
|
|
279
|
+
const result = await executeWalletWrite(walletAddress, "setPerTxLimit", [parseEther(perTxLimit)]);
|
|
280
|
+
if (result.status === "success") {
|
|
281
|
+
results.push(`Per-tx limit set to ${perTxLimit} ETH`);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return formatSuccess(`Spending limits updated.`, {
|
|
288
|
+
walletAddress,
|
|
289
|
+
...(dailyLimit && { dailyLimit: `${dailyLimit} ETH` }),
|
|
290
|
+
...(perTxLimit && { perTxLimit: `${perTxLimit} ETH` }),
|
|
291
|
+
changes: results,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
const parsed = parseContractError(e);
|
|
296
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
// ──────────────────────────────────────────────────────────────
|
|
300
|
+
// corven_set_recipient
|
|
301
|
+
// ──────────────────────────────────────────────────────────────
|
|
302
|
+
server.registerTool("corven_set_recipient", {
|
|
303
|
+
title: "Manage Recipient Whitelist",
|
|
304
|
+
description: "Controller adds or removes an address from the wallet's recipient whitelist. The agent can only send ETH to whitelisted addresses.\n" +
|
|
305
|
+
"USE WHEN: Whitelisting a new payment target (e.g., a worker agent, a contract). Removing a compromised address.\n" +
|
|
306
|
+
"REQUIRES: PRIVATE_KEY must be the controller address. Only the human controller can call this.\n" +
|
|
307
|
+
"RETURNS: Recipient address, allowed status, transaction confirmation.\n" +
|
|
308
|
+
"NOTE: Without whitelisting, the agent's execute() calls will revert with 'Recipient not whitelisted'.",
|
|
309
|
+
inputSchema: {
|
|
310
|
+
walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
|
|
311
|
+
recipient: ethAddress.describe("Address to add/remove from whitelist"),
|
|
312
|
+
allowed: z.boolean().describe("true = add to whitelist, false = remove from whitelist"),
|
|
313
|
+
},
|
|
314
|
+
}, async ({ walletAddress, recipient, allowed }) => {
|
|
315
|
+
try {
|
|
316
|
+
const result = await executeWalletWrite(walletAddress, "setRecipient", [recipient, allowed]);
|
|
317
|
+
if (result.status === "success") {
|
|
318
|
+
return formatSuccess(`Recipient ${allowed ? "whitelisted" : "removed"}.`, {
|
|
319
|
+
walletAddress,
|
|
320
|
+
recipient,
|
|
321
|
+
allowed: allowed ? "WHITELISTED" : "REMOVED",
|
|
322
|
+
}, result.txHash);
|
|
323
|
+
}
|
|
324
|
+
return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
const parsed = parseContractError(e);
|
|
328
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
// ──────────────────────────────────────────────────────────────
|
|
332
|
+
// corven_emergency_pause
|
|
333
|
+
// ──────────────────────────────────────────────────────────────
|
|
334
|
+
server.registerTool("corven_emergency_pause", {
|
|
335
|
+
title: "Emergency Pause/Unpause",
|
|
336
|
+
description: "Controller pauses or unpauses the AgentSmartWallet. When paused, all execute() calls revert -- the agent cannot send any ETH.\n" +
|
|
337
|
+
"USE WHEN: Suspecting the agent is compromised. Pre-maintenance freeze. Unpausing after resolving an incident.\n" +
|
|
338
|
+
"REQUIRES: PRIVATE_KEY must be the controller address. Only the human controller can call this.\n" +
|
|
339
|
+
"RETURNS: Pause status, transaction confirmation.\n" +
|
|
340
|
+
"NOTE: This is an emergency safety mechanism. The agent cannot unpause itself.",
|
|
341
|
+
inputSchema: {
|
|
342
|
+
walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
|
|
343
|
+
paused: z.boolean().describe("true = pause (freeze), false = unpause (resume)"),
|
|
344
|
+
},
|
|
345
|
+
}, async ({ walletAddress, paused }) => {
|
|
346
|
+
try {
|
|
347
|
+
const result = await executeWalletWrite(walletAddress, "setPaused", [paused]);
|
|
348
|
+
if (result.status === "success") {
|
|
349
|
+
return formatSuccess(paused
|
|
350
|
+
? "Wallet PAUSED. All outbound transfers are frozen."
|
|
351
|
+
: "Wallet UNPAUSED. Agent can resume transactions.", {
|
|
352
|
+
walletAddress,
|
|
353
|
+
status: paused ? "PAUSED" : "ACTIVE",
|
|
354
|
+
}, result.txHash);
|
|
355
|
+
}
|
|
356
|
+
return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
|
|
357
|
+
}
|
|
358
|
+
catch (e) {
|
|
359
|
+
const parsed = parseContractError(e);
|
|
360
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
//# sourceMappingURL=account-abstraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-abstraction.js","sourceRoot":"","sources":["../../src/tools/account-abstraction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAgB,MAAM,MAAM,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,iEAAiE;AACjE,0EAA0E;AAE1E,MAAM,mBAAmB,GAAG;IAC1B,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE;YAC7B,EAAE,IAAI,EA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AAC,KAAK,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAChJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YACrC,OAAO,qBAAqB,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QACzF,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../../src/tools/batches.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../../src/tools/batches.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA2BzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA+P1D"}
|
package/dist/tools/batches.js
CHANGED
|
@@ -12,6 +12,8 @@ import { parseEther, formatEther, isAddress } from "viem";
|
|
|
12
12
|
import { loadAbi, CONTRACTS, getAccount } from "../config.js";
|
|
13
13
|
import { executeOrPrepare, readContract } from "../handlers/wallet.js";
|
|
14
14
|
import { formatTxResult, formatReadResult, formatError } from "../handlers/transactions.js";
|
|
15
|
+
import { parseContractError, formatStructuredError } from "../lib/formatResponse.js";
|
|
16
|
+
import { ethAddress, ethAmount, ipfsCid, unixDeadline } from "../lib/schemaHelpers.js";
|
|
15
17
|
import { stringToBytes32, stringsToBytes32 } from "../utils.js";
|
|
16
18
|
const ABI = loadAbi("ParallelTaskBatch");
|
|
17
19
|
// Batch status enum
|
|
@@ -38,14 +40,19 @@ export function registerBatchTools(server) {
|
|
|
38
40
|
// ──────────────────────────────────────────────────────────────
|
|
39
41
|
server.registerTool("corven_create_batch", {
|
|
40
42
|
title: "Create Parallel Task Batch",
|
|
41
|
-
description: "Create a batch of tasks for multiple workers to execute in parallel. " +
|
|
42
|
-
"
|
|
43
|
+
description: "Create a batch of tasks for multiple workers to execute in parallel. All arrays must have the same length. Total ETH sent = sum of payments.\n" +
|
|
44
|
+
"USE WHEN: You have a large task that can be split across multiple workers for parallel execution.\n" +
|
|
45
|
+
"REQUIRES: All workers must be registered agents. Your wallet must have enough ETH for the sum of all payments plus gas.\n" +
|
|
46
|
+
"RETURNS: Transaction hash. The batch ID and individual task IDs are emitted in the event logs.\n" +
|
|
47
|
+
"COMES AFTER: corven_find_workers to identify available workers for the task.\n" +
|
|
48
|
+
"COMES BEFORE: corven_check_batch_submitted (poll for completion), corven_aggregate_results (finalize when all done).\n" +
|
|
49
|
+
"NOTE: All arrays (workers, payments, deadlines, descriptionHashes) must be the same length. Max 50 workers per batch.",
|
|
43
50
|
inputSchema: {
|
|
44
|
-
workers: z.array(
|
|
45
|
-
payments: z.array(
|
|
46
|
-
deadlines: z.array(
|
|
47
|
-
descriptionHashes: z.array(
|
|
48
|
-
aggregationSpec:
|
|
51
|
+
workers: z.array(ethAddress).describe("Array of worker addresses"),
|
|
52
|
+
payments: z.array(ethAmount).describe("Array of payment amounts in ETH (one per worker)"),
|
|
53
|
+
deadlines: z.array(unixDeadline).describe("Array of deadline timestamps (seconds)"),
|
|
54
|
+
descriptionHashes: z.array(ipfsCid).describe("Array of IPFS CIDs for task descriptions"),
|
|
55
|
+
aggregationSpec: ipfsCid.describe("IPFS CID for aggregation specification"),
|
|
49
56
|
},
|
|
50
57
|
}, async ({ workers, payments, deadlines, descriptionHashes, aggregationSpec }) => {
|
|
51
58
|
try {
|
|
@@ -73,20 +80,31 @@ export function registerBatchTools(server) {
|
|
|
73
80
|
return formatTxResult(result);
|
|
74
81
|
}
|
|
75
82
|
catch (e) {
|
|
76
|
-
|
|
83
|
+
const parsed = parseContractError(e);
|
|
84
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
77
85
|
}
|
|
78
86
|
});
|
|
79
87
|
// ──────────────────────────────────────────────────────────────
|
|
80
88
|
// get_batch
|
|
81
89
|
// ──────────────────────────────────────────────────────────────
|
|
82
90
|
server.registerTool("corven_get_batch", {
|
|
83
|
-
title: "Get Batch
|
|
84
|
-
description: "
|
|
91
|
+
title: "Get Batch",
|
|
92
|
+
description: "Get batch details by ID, or total batch count if no ID provided.\n" +
|
|
93
|
+
"USE WHEN: You need to inspect a batch's tasks, budget, status, or aggregation spec.\n" +
|
|
94
|
+
"REQUIRES: The batch must exist on-chain.\n" +
|
|
95
|
+
"RETURNS: Batch details including client, total budget, task IDs, aggregation spec, status, and creation time. If no ID provided, returns total batch count.\n" +
|
|
96
|
+
"COMES AFTER: corven_create_batch created the batch.\n" +
|
|
97
|
+
"COMES BEFORE: corven_get_batch_status (check progress), corven_aggregate_results (finalize).\n" +
|
|
98
|
+
"NOTE: Omit batchId to get the total number of batches.",
|
|
85
99
|
inputSchema: {
|
|
86
|
-
batchId: z.number().describe("
|
|
100
|
+
batchId: z.number().optional().describe("Batch ID. Omit to get total batch count."),
|
|
87
101
|
},
|
|
88
102
|
}, async ({ batchId }) => {
|
|
89
103
|
try {
|
|
104
|
+
if (batchId === undefined) {
|
|
105
|
+
const count = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "batchCounter", []);
|
|
106
|
+
return formatReadResult({ batchCount: Number(count) }, "Total Batches");
|
|
107
|
+
}
|
|
90
108
|
const data = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "getBatchDetails", [BigInt(batchId)]);
|
|
91
109
|
const enriched = {
|
|
92
110
|
client: data.client,
|
|
@@ -99,7 +117,8 @@ export function registerBatchTools(server) {
|
|
|
99
117
|
return formatReadResult(enriched, `Batch #${batchId}`);
|
|
100
118
|
}
|
|
101
119
|
catch (e) {
|
|
102
|
-
|
|
120
|
+
const parsed = parseContractError(e);
|
|
121
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
103
122
|
}
|
|
104
123
|
});
|
|
105
124
|
// ──────────────────────────────────────────────────────────────
|
|
@@ -107,7 +126,13 @@ export function registerBatchTools(server) {
|
|
|
107
126
|
// ──────────────────────────────────────────────────────────────
|
|
108
127
|
server.registerTool("corven_get_batch_status", {
|
|
109
128
|
title: "Get Batch Status",
|
|
110
|
-
description: "Get the current status of a batch (Pending/InProgress/Aggregated/etc)
|
|
129
|
+
description: "Get the current status of a batch (Pending/InProgress/Aggregated/etc).\n" +
|
|
130
|
+
"USE WHEN: You need to check whether a batch's tasks are all completed and ready for aggregation.\n" +
|
|
131
|
+
"REQUIRES: The batch must exist on-chain.\n" +
|
|
132
|
+
"RETURNS: Batch status as a numeric code and human-readable label (Pending, InProgress, Aggregated, Completed, Failed).\n" +
|
|
133
|
+
"COMES AFTER: corven_create_batch created the batch.\n" +
|
|
134
|
+
"COMES BEFORE: corven_aggregate_results (when status shows all tasks are done).\n" +
|
|
135
|
+
"NOTE: Status 2 (Aggregated) means all tasks completed and results were finalized.",
|
|
111
136
|
inputSchema: {
|
|
112
137
|
batchId: z.number().describe("Numeric batch ID"),
|
|
113
138
|
},
|
|
@@ -122,7 +147,8 @@ export function registerBatchTools(server) {
|
|
|
122
147
|
return formatReadResult(result, `Batch #${batchId} Status`);
|
|
123
148
|
}
|
|
124
149
|
catch (e) {
|
|
125
|
-
|
|
150
|
+
const parsed = parseContractError(e);
|
|
151
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
126
152
|
}
|
|
127
153
|
});
|
|
128
154
|
// ──────────────────────────────────────────────────────────────
|
|
@@ -130,8 +156,13 @@ export function registerBatchTools(server) {
|
|
|
130
156
|
// ──────────────────────────────────────────────────────────────
|
|
131
157
|
server.registerTool("corven_aggregate_results", {
|
|
132
158
|
title: "Aggregate Batch Results",
|
|
133
|
-
description: "Finalize a batch by aggregating all completed task results. " +
|
|
134
|
-
"
|
|
159
|
+
description: "Finalize a batch by aggregating all completed task results. Can only be called after all tasks in the batch are Submitted.\n" +
|
|
160
|
+
"USE WHEN: All workers in the batch have submitted their deliverables and you want to finalize the batch.\n" +
|
|
161
|
+
"REQUIRES: All tasks in the batch must be in Submitted status. You must be the batch creator.\n" +
|
|
162
|
+
"RETURNS: Transaction hash. The aggregated result hash is stored on-chain.\n" +
|
|
163
|
+
"COMES AFTER: corven_check_batch_submitted confirmed all tasks are done.\n" +
|
|
164
|
+
"COMES BEFORE: corven_get_aggregated_result to retrieve the final combined result.\n" +
|
|
165
|
+
"NOTE: This releases payments to all workers in the batch.",
|
|
135
166
|
inputSchema: {
|
|
136
167
|
batchId: z.number().describe("Numeric batch ID"),
|
|
137
168
|
},
|
|
@@ -145,31 +176,23 @@ export function registerBatchTools(server) {
|
|
|
145
176
|
return formatTxResult(result);
|
|
146
177
|
}
|
|
147
178
|
catch (e) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
// ──────────────────────────────────────────────────────────────
|
|
152
|
-
// get_batch_counter
|
|
153
|
-
// ──────────────────────────────────────────────────────────────
|
|
154
|
-
server.registerTool("corven_get_batch_counter", {
|
|
155
|
-
title: "Get Batch Counter",
|
|
156
|
-
description: "Get the total number of batches created on the protocol.",
|
|
157
|
-
inputSchema: {},
|
|
158
|
-
}, async () => {
|
|
159
|
-
try {
|
|
160
|
-
const count = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "batchCounter", []);
|
|
161
|
-
return formatReadResult({ count: Number(count) }, "Batch Counter");
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
return formatError(e);
|
|
179
|
+
const parsed = parseContractError(e);
|
|
180
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
165
181
|
}
|
|
166
182
|
});
|
|
183
|
+
// get_batch_counter merged into get_batch (returns count when no batchId)
|
|
167
184
|
// ──────────────────────────────────────────────────────────────
|
|
168
185
|
// corven_check_batch_submitted
|
|
169
186
|
// ──────────────────────────────────────────────────────────────
|
|
170
187
|
server.registerTool("corven_check_batch_submitted", {
|
|
171
188
|
title: "Check Batch All Submitted",
|
|
172
|
-
description: "Check if all subtasks in a batch have been submitted
|
|
189
|
+
description: "Check if all subtasks in a batch have been submitted.\n" +
|
|
190
|
+
"USE WHEN: You want to know whether a batch is ready for result aggregation.\n" +
|
|
191
|
+
"REQUIRES: The batch must exist on-chain.\n" +
|
|
192
|
+
"RETURNS: Boolean indicating whether all tasks in the batch have been submitted.\n" +
|
|
193
|
+
"COMES AFTER: corven_create_batch created the batch and workers are executing tasks.\n" +
|
|
194
|
+
"COMES BEFORE: corven_aggregate_results (call when allSubmitted is true).\n" +
|
|
195
|
+
"NOTE: Poll this periodically or after workers report completion.",
|
|
173
196
|
inputSchema: { batchId: z.number().describe("Batch ID") },
|
|
174
197
|
}, async ({ batchId }) => {
|
|
175
198
|
try {
|
|
@@ -177,7 +200,8 @@ export function registerBatchTools(server) {
|
|
|
177
200
|
return formatReadResult({ batchId, allSubmitted }, `Batch #${batchId} submission status`);
|
|
178
201
|
}
|
|
179
202
|
catch (e) {
|
|
180
|
-
|
|
203
|
+
const parsed = parseContractError(e);
|
|
204
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
181
205
|
}
|
|
182
206
|
});
|
|
183
207
|
// ──────────────────────────────────────────────────────────────
|
|
@@ -185,7 +209,13 @@ export function registerBatchTools(server) {
|
|
|
185
209
|
// ──────────────────────────────────────────────────────────────
|
|
186
210
|
server.registerTool("corven_get_aggregated_result", {
|
|
187
211
|
title: "Get Aggregated Result",
|
|
188
|
-
description: "Get the aggregated result hash after a batch is finalized
|
|
212
|
+
description: "Get the aggregated result hash after a batch is finalized.\n" +
|
|
213
|
+
"USE WHEN: You need to retrieve the combined result of all tasks in a completed batch.\n" +
|
|
214
|
+
"REQUIRES: The batch must have been finalized via corven_aggregate_results.\n" +
|
|
215
|
+
"RETURNS: The aggregated result hash (bytes32) that represents the combined output of all batch tasks.\n" +
|
|
216
|
+
"COMES AFTER: corven_aggregate_results finalized the batch.\n" +
|
|
217
|
+
"COMES BEFORE: Use the result hash to verify or store the batch output.\n" +
|
|
218
|
+
"NOTE: Returns empty/zero hash if the batch has not been aggregated yet.",
|
|
189
219
|
inputSchema: { batchId: z.number().describe("Batch ID") },
|
|
190
220
|
}, async ({ batchId }) => {
|
|
191
221
|
try {
|
|
@@ -193,7 +223,8 @@ export function registerBatchTools(server) {
|
|
|
193
223
|
return formatReadResult({ batchId, aggregatedResult: result }, `Aggregated result for Batch #${batchId}`);
|
|
194
224
|
}
|
|
195
225
|
catch (e) {
|
|
196
|
-
|
|
226
|
+
const parsed = parseContractError(e);
|
|
227
|
+
return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
|
|
197
228
|
}
|
|
198
229
|
});
|
|
199
230
|
}
|