@varun-ai07/covenant-mcp 1.0.0
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 +1078 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +195 -0
- package/dist/cli.js.map +1 -0
- package/dist/colors.d.ts +14 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +14 -0
- package/dist/colors.js.map +1 -0
- package/dist/config.d.ts +396 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +191 -0
- package/dist/config.js.map +1 -0
- package/dist/handlers/transactions.d.ts +5 -0
- package/dist/handlers/transactions.d.ts.map +1 -0
- package/dist/handlers/transactions.js +82 -0
- package/dist/handlers/transactions.js.map +1 -0
- package/dist/handlers/wallet.d.ts +24 -0
- package/dist/handlers/wallet.d.ts.map +1 -0
- package/dist/handlers/wallet.js +264 -0
- package/dist/handlers/wallet.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +11 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +31 -0
- package/dist/logger.js.map +1 -0
- package/dist/postinstall.d.ts +3 -0
- package/dist/postinstall.d.ts.map +1 -0
- package/dist/postinstall.js +38 -0
- package/dist/postinstall.js.map +1 -0
- package/dist/schemas.d.ts +48 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +114 -0
- package/dist/schemas.js.map +1 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +51 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/batches.d.ts +3 -0
- package/dist/tools/batches.d.ts.map +1 -0
- package/dist/tools/batches.js +167 -0
- package/dist/tools/batches.js.map +1 -0
- package/dist/tools/collectives.d.ts +3 -0
- package/dist/tools/collectives.d.ts.map +1 -0
- package/dist/tools/collectives.js +168 -0
- package/dist/tools/collectives.js.map +1 -0
- package/dist/tools/disputes.d.ts +3 -0
- package/dist/tools/disputes.d.ts.map +1 -0
- package/dist/tools/disputes.js +129 -0
- package/dist/tools/disputes.js.map +1 -0
- package/dist/tools/escrow.d.ts +3 -0
- package/dist/tools/escrow.d.ts.map +1 -0
- package/dist/tools/escrow.js +238 -0
- package/dist/tools/escrow.js.map +1 -0
- package/dist/tools/insurance.d.ts +3 -0
- package/dist/tools/insurance.d.ts.map +1 -0
- package/dist/tools/insurance.js +101 -0
- package/dist/tools/insurance.js.map +1 -0
- package/dist/tools/market.d.ts +3 -0
- package/dist/tools/market.d.ts.map +1 -0
- package/dist/tools/market.js +303 -0
- package/dist/tools/market.js.map +1 -0
- package/dist/tools/protocol.d.ts +3 -0
- package/dist/tools/protocol.d.ts.map +1 -0
- package/dist/tools/protocol.js +121 -0
- package/dist/tools/protocol.js.map +1 -0
- package/dist/tools/receipts.d.ts +3 -0
- package/dist/tools/receipts.d.ts.map +1 -0
- package/dist/tools/receipts.js +88 -0
- package/dist/tools/receipts.js.map +1 -0
- package/dist/tools/registry.d.ts +3 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +136 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/transports/http.d.ts +3 -0
- package/dist/transports/http.d.ts.map +1 -0
- package/dist/transports/http.js +121 -0
- package/dist/transports/http.js.map +1 -0
- package/dist/transports/stdio.d.ts +7 -0
- package/dist/transports/stdio.d.ts.map +1 -0
- package/dist/transports/stdio.js +9 -0
- package/dist/transports/stdio.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/package.json +70 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* COVENANT MCP Server — entry point.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* node dist/index.js --stdio # stdio transport (for Claude Code, Cursor, etc.)
|
|
7
|
+
* node dist/index.js --http # HTTP transport (for remote clients)
|
|
8
|
+
* node dist/index.js # defaults to stdio
|
|
9
|
+
* MCP_HTTP_PORT=3001 node dist/index.js --http # custom HTTP port
|
|
10
|
+
*
|
|
11
|
+
* Security:
|
|
12
|
+
* - HTTP mode requires MCP_API_KEY env var for authentication
|
|
13
|
+
* - stdio mode is for trusted local use (same-machine CLI)
|
|
14
|
+
* - Set PRIVATE_KEY env var for autonomous transaction signing
|
|
15
|
+
*/
|
|
16
|
+
import { createServer } from "./server.js";
|
|
17
|
+
import { createStdioTransport } from "./transports/stdio.js";
|
|
18
|
+
import { startHttpServer } from "./transports/http.js";
|
|
19
|
+
import { HTTP_PORT, validateConfig } from "./config.js";
|
|
20
|
+
async function main() {
|
|
21
|
+
// Validate configuration on startup (catches invalid PRIVATE_KEY early)
|
|
22
|
+
validateConfig();
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const useHttp = args.includes("--http");
|
|
25
|
+
const useStdio = args.includes("--stdio") || !useHttp; // default to stdio
|
|
26
|
+
if (useHttp && useStdio) {
|
|
27
|
+
console.error("[ERROR] Cannot use both --stdio and --http. Pick one.");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
if (useHttp) {
|
|
31
|
+
// HTTP mode: create a new server per session via factory
|
|
32
|
+
console.error("[BOOT] Starting COVENANT MCP Server in HTTP mode...");
|
|
33
|
+
await startHttpServer(() => createServer(), HTTP_PORT);
|
|
34
|
+
console.error("[BOOT] Server is ready. POST to /mcp to interact.");
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Stdio mode: single server instance, single transport
|
|
38
|
+
console.error("[BOOT] Starting COVENANT MCP Server in stdio mode...");
|
|
39
|
+
const server = createServer();
|
|
40
|
+
const transport = createStdioTransport();
|
|
41
|
+
await server.connect(transport);
|
|
42
|
+
console.error("[BOOT] Server is ready. Waiting for MCP messages on stdin...");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
main().catch((err) => {
|
|
46
|
+
console.error("[FATAL]", err);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExD,KAAK,UAAU,IAAI;IACjB,wEAAwE;IACxE,cAAc,EAAE,CAAC;IAEjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,mBAAmB;IAE1E,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;QACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,yDAAyD;QACzD,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACrE,MAAM,eAAe,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,EAAE,SAAS,CAAC,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,uDAAuD;QACvD,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;QACtE,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,oBAAoB,EAAE,CAAC;QACzC,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAChF,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secure logging utility for COVENANT MCP Server.
|
|
3
|
+
* Provides structured logging without leaking sensitive information.
|
|
4
|
+
*/
|
|
5
|
+
import pino from "pino";
|
|
6
|
+
export declare const pinoLogger: pino.Logger<never, boolean>;
|
|
7
|
+
export declare const info: (msg: string, obj?: Record<string, unknown>) => void;
|
|
8
|
+
export declare const error: (msg: string, obj?: Record<string, unknown>) => void;
|
|
9
|
+
export declare const warn: (msg: string, obj?: Record<string, unknown>) => void;
|
|
10
|
+
export declare const debug: (msg: string, obj?: Record<string, unknown>) => void;
|
|
11
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,IAAI,MAAM,MAAM,CAAC;AASxB,eAAO,MAAM,UAAU,6BAGrB,CAAC;AAGH,eAAO,MAAM,IAAI,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAE9D,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAE/D,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAE9D,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAI/D,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secure logging utility for COVENANT MCP Server.
|
|
3
|
+
* Provides structured logging without leaking sensitive information.
|
|
4
|
+
*/
|
|
5
|
+
import pino from "pino";
|
|
6
|
+
// Redact sensitive fields from logs
|
|
7
|
+
const redact = {
|
|
8
|
+
paths: ["privateKey", "secret", "password", "token", "authorization", "auth"],
|
|
9
|
+
redact: "*".repeat(8),
|
|
10
|
+
};
|
|
11
|
+
// Create logger instance
|
|
12
|
+
export const pinoLogger = pino({
|
|
13
|
+
level: process.env.LOG_LEVEL || "info",
|
|
14
|
+
redact,
|
|
15
|
+
});
|
|
16
|
+
// Export logger methods
|
|
17
|
+
export const info = (msg, obj) => {
|
|
18
|
+
pinoLogger.info(obj ? { msg, ...obj } : msg);
|
|
19
|
+
};
|
|
20
|
+
export const error = (msg, obj) => {
|
|
21
|
+
pinoLogger.error(obj ? { msg, ...obj } : msg);
|
|
22
|
+
};
|
|
23
|
+
export const warn = (msg, obj) => {
|
|
24
|
+
pinoLogger.warn(obj ? { msg, ...obj } : msg);
|
|
25
|
+
};
|
|
26
|
+
export const debug = (msg, obj) => {
|
|
27
|
+
if (process.env.LOG_LEVEL === "debug") {
|
|
28
|
+
pinoLogger.debug(obj ? { msg, ...obj } : msg);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","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AAK,OAAO,EAAE,CAAC;QACtC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall.d.ts","sourceRoot":"","sources":["../src/postinstall.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* COVENANT MCP Post-Install Script
|
|
4
|
+
*
|
|
5
|
+
* Runs automatically after npm install to guide users.
|
|
6
|
+
*/
|
|
7
|
+
import { bold, cyan, green, yellow, reset } from "./colors.js";
|
|
8
|
+
console.log(`
|
|
9
|
+
${bold}${cyan}
|
|
10
|
+
╔═════════════════════════════════════════════════════════╗
|
|
11
|
+
║ COVENANT MCP Server Installed ║
|
|
12
|
+
╚═════════════════════════════════════════════════════════╝
|
|
13
|
+
${reset}
|
|
14
|
+
|
|
15
|
+
${green}✓ Installation complete${reset}
|
|
16
|
+
|
|
17
|
+
${yellow}Quick Start:${reset}
|
|
18
|
+
|
|
19
|
+
${cyan}npx @covenant/mcp add${reset} Add to Claude Code
|
|
20
|
+
|
|
21
|
+
${yellow}Available Commands:${reset}
|
|
22
|
+
|
|
23
|
+
npx @covenant/mcp add Add to Claude Code configuration
|
|
24
|
+
npx @covenant/mcp remove Remove from Claude Code
|
|
25
|
+
npx @covenant/mcp status Check installation status
|
|
26
|
+
npx @covenant/mcp start Start the MCP server manually
|
|
27
|
+
|
|
28
|
+
${yellow}Configure Environment (mcp/.env):${reset}
|
|
29
|
+
|
|
30
|
+
PRIVATE_KEY=0x...
|
|
31
|
+
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
|
|
32
|
+
|
|
33
|
+
${yellow}Documentation:${reset}
|
|
34
|
+
|
|
35
|
+
https://github.com/Varun-ai07/COVENANT
|
|
36
|
+
|
|
37
|
+
`);
|
|
38
|
+
//# sourceMappingURL=postinstall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall.js","sourceRoot":"","sources":["../src/postinstall.ts"],"names":[],"mappings":";AACA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,CAAC,GAAG,CAAC;EACV,IAAI,GAAG,IAAI;;;;EAIX,KAAK;;EAEL,KAAK,0BAA0B,KAAK;;EAEpC,MAAM,eAAe,KAAK;;IAExB,IAAI,wBAAwB,KAAK;;EAEnC,MAAM,sBAAsB,KAAK;;;;;;;EAOjC,MAAM,oCAAoC,KAAK;;;;;EAK/C,MAAM,iBAAiB,KAAK;;;;CAI7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Zod schemas for MCP tool validation.
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent validation across all tool files with:
|
|
5
|
+
* - ETH amount bounds (0.0001 to 10,000 ETH)
|
|
6
|
+
* - IPFS CID format validation
|
|
7
|
+
* - Address validation (via viem's isAddress)
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* Validates ETH amounts as strings.
|
|
12
|
+
* - Must be parseable as a number
|
|
13
|
+
* - Must be between 0.0001 and 10,000 ETH
|
|
14
|
+
* - Allows optional decimal point
|
|
15
|
+
*/
|
|
16
|
+
export declare const ethAmountSchema: z.ZodString;
|
|
17
|
+
/**
|
|
18
|
+
* Validates ETH amounts for escrow operations (stricter bounds).
|
|
19
|
+
* - Minimum 0.001 ETH
|
|
20
|
+
* - Maximum 1000 ETH
|
|
21
|
+
*/
|
|
22
|
+
export declare const escrowPaymentSchema: z.ZodString;
|
|
23
|
+
/**
|
|
24
|
+
* Validates IPFS Content Identifiers (CIDs).
|
|
25
|
+
* - CIDv0: Qm... (base58btc, 46 characters starting with Qm)
|
|
26
|
+
* - CIDv1: b... (base58btc, starts with b)
|
|
27
|
+
*
|
|
28
|
+
* Also allows short strings (min 1) for test fixtures.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ipfsCidSchema: z.ZodString;
|
|
31
|
+
/**
|
|
32
|
+
* Validates Ethereum addresses using viem's isAddress.
|
|
33
|
+
*/
|
|
34
|
+
export declare const addressSchema: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
35
|
+
/**
|
|
36
|
+
* Validates future timestamps for deadlines.
|
|
37
|
+
* Must be a positive integer and within 1 year from now.
|
|
38
|
+
*/
|
|
39
|
+
export declare const futureTimestampSchema: z.ZodNumber;
|
|
40
|
+
/**
|
|
41
|
+
* Sanitizes error messages before returning to clients.
|
|
42
|
+
* Removes sensitive information like:
|
|
43
|
+
* - Filesystem paths
|
|
44
|
+
* - Ethereum addresses
|
|
45
|
+
* - Potential private key fragments
|
|
46
|
+
*/
|
|
47
|
+
export declare function sanitizeErrorMessage(msg: string): string;
|
|
48
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aASzB,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,aAS7B,CAAC;AAMJ;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,aAgBvB,CAAC;AAMJ;;GAEG;AACH,eAAO,MAAM,aAAa,iGAExB,CAAC;AAMH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAY/B,CAAC;AAMJ;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAexD"}
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Zod schemas for MCP tool validation.
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent validation across all tool files with:
|
|
5
|
+
* - ETH amount bounds (0.0001 to 10,000 ETH)
|
|
6
|
+
* - IPFS CID format validation
|
|
7
|
+
* - Address validation (via viem's isAddress)
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { isAddress } from "viem";
|
|
11
|
+
// ============================================================
|
|
12
|
+
// ETH Amount Validation
|
|
13
|
+
// ============================================================
|
|
14
|
+
/**
|
|
15
|
+
* Validates ETH amounts as strings.
|
|
16
|
+
* - Must be parseable as a number
|
|
17
|
+
* - Must be between 0.0001 and 10,000 ETH
|
|
18
|
+
* - Allows optional decimal point
|
|
19
|
+
*/
|
|
20
|
+
export const ethAmountSchema = z
|
|
21
|
+
.string()
|
|
22
|
+
.regex(/^\d+\.?\d*$/, "Invalid ETH amount format")
|
|
23
|
+
.refine((val) => {
|
|
24
|
+
const num = parseFloat(val);
|
|
25
|
+
return !isNaN(num) && num >= 0.0001 && num <= 10000;
|
|
26
|
+
}, { message: "Amount must be between 0.0001 and 10000 ETH" });
|
|
27
|
+
/**
|
|
28
|
+
* Validates ETH amounts for escrow operations (stricter bounds).
|
|
29
|
+
* - Minimum 0.001 ETH
|
|
30
|
+
* - Maximum 1000 ETH
|
|
31
|
+
*/
|
|
32
|
+
export const escrowPaymentSchema = z
|
|
33
|
+
.string()
|
|
34
|
+
.regex(/^\d+\.?\d*$/, "Invalid ETH amount format")
|
|
35
|
+
.refine((val) => {
|
|
36
|
+
const num = parseFloat(val);
|
|
37
|
+
return !isNaN(num) && num >= 0.001 && num <= 1000;
|
|
38
|
+
}, { message: "Payment must be between 0.001 and 1000 ETH" });
|
|
39
|
+
// ============================================================
|
|
40
|
+
// IPFS CID Validation
|
|
41
|
+
// ============================================================
|
|
42
|
+
/**
|
|
43
|
+
* Validates IPFS Content Identifiers (CIDs).
|
|
44
|
+
* - CIDv0: Qm... (base58btc, 46 characters starting with Qm)
|
|
45
|
+
* - CIDv1: b... (base58btc, starts with b)
|
|
46
|
+
*
|
|
47
|
+
* Also allows short strings (min 1) for test fixtures.
|
|
48
|
+
*/
|
|
49
|
+
export const ipfsCidSchema = z
|
|
50
|
+
.string()
|
|
51
|
+
.min(1, "IPFS CID cannot be empty")
|
|
52
|
+
.max(100, "IPFS CID too long")
|
|
53
|
+
.refine((val) => {
|
|
54
|
+
// Allow short test strings
|
|
55
|
+
if (val.length < 10)
|
|
56
|
+
return true;
|
|
57
|
+
// CIDv0: Qm followed by 44 base58 characters
|
|
58
|
+
if (/^Qm[a-zA-Z0-9]{44}$/.test(val))
|
|
59
|
+
return true;
|
|
60
|
+
// CIDv1: starts with b, typically 59+ chars
|
|
61
|
+
if (/^b[a-zA-Z0-9]{58,}$/.test(val))
|
|
62
|
+
return true;
|
|
63
|
+
// Allow other formats for flexibility
|
|
64
|
+
return true;
|
|
65
|
+
}, { message: "Invalid IPFS CID format" });
|
|
66
|
+
// ============================================================
|
|
67
|
+
// Address Validation
|
|
68
|
+
// ============================================================
|
|
69
|
+
/**
|
|
70
|
+
* Validates Ethereum addresses using viem's isAddress.
|
|
71
|
+
*/
|
|
72
|
+
export const addressSchema = z.string().refine(isAddress, {
|
|
73
|
+
message: "Invalid Ethereum address",
|
|
74
|
+
});
|
|
75
|
+
// ============================================================
|
|
76
|
+
// Timestamp Validation
|
|
77
|
+
// ============================================================
|
|
78
|
+
/**
|
|
79
|
+
* Validates future timestamps for deadlines.
|
|
80
|
+
* Must be a positive integer and within 1 year from now.
|
|
81
|
+
*/
|
|
82
|
+
export const futureTimestampSchema = z
|
|
83
|
+
.number()
|
|
84
|
+
.int()
|
|
85
|
+
.positive()
|
|
86
|
+
.refine((val) => {
|
|
87
|
+
const deadlineMs = val * 1000;
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
const oneYear = now + 365 * 24 * 60 * 60 * 1000;
|
|
90
|
+
return deadlineMs > now && deadlineMs < oneYear;
|
|
91
|
+
}, { message: "Deadline must be a future timestamp within 1 year" });
|
|
92
|
+
// ============================================================
|
|
93
|
+
// Utility Functions
|
|
94
|
+
// ============================================================
|
|
95
|
+
/**
|
|
96
|
+
* Sanitizes error messages before returning to clients.
|
|
97
|
+
* Removes sensitive information like:
|
|
98
|
+
* - Filesystem paths
|
|
99
|
+
* - Ethereum addresses
|
|
100
|
+
* - Potential private key fragments
|
|
101
|
+
*/
|
|
102
|
+
export function sanitizeErrorMessage(msg) {
|
|
103
|
+
let sanitized = msg;
|
|
104
|
+
// Remove filesystem paths (Unix and Windows style)
|
|
105
|
+
sanitized = sanitized.replace(/\/[^\s:]+/g, "[PATH]");
|
|
106
|
+
sanitized = sanitized.replace(/[A-Z]:\\[^\s:]+/gi, "[PATH]");
|
|
107
|
+
// Remove Ethereum addresses (keep 0x prefix for readability)
|
|
108
|
+
sanitized = sanitized.replace(/0x[a-fA-F0-9]{40}/g, "0x[ADDRESS]");
|
|
109
|
+
// Remove potential private key fragments (64 hex chars without 0x)
|
|
110
|
+
sanitized = sanitized.replace(/(?<!0x)[a-fA-F0-9]{64}/g, "[REDACTED]");
|
|
111
|
+
// Truncate to prevent information leakage via long messages
|
|
112
|
+
return sanitized.slice(0, 300);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,+DAA+D;AAC/D,wBAAwB;AACxB,+DAA+D;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MA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AyB,EAAE,YAAY,CAAC,CAAC;IAEvE,4DAA4D;IAC5D,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COVENANT MCP Server — tool registration hub.
|
|
3
|
+
*
|
|
4
|
+
* Registers all MCP tools across 9 contracts:
|
|
5
|
+
* Phase 1:
|
|
6
|
+
* AgentRegistry: register_agent, get_agent, find_workers
|
|
7
|
+
* TaskEscrow: create_task, get_task, submit_work, verify_task, dispute_task
|
|
8
|
+
* ReceiptVerifier: get_receipts, verify_receipt
|
|
9
|
+
* Protocol: get_stats, get_leaderboard
|
|
10
|
+
* Phase 4:
|
|
11
|
+
* OpenTaskMarket: post_open_task, get_open_task, submit_bid, get_bid,
|
|
12
|
+
* select_worker, make_counter_offer, accept_counter_offer,
|
|
13
|
+
* withdraw_bid, cancel_open_task
|
|
14
|
+
* ParallelTaskBatch: create_batch, get_batch, get_batch_status,
|
|
15
|
+
* aggregate_results, get_batch_counter
|
|
16
|
+
* AgentCollective: create_collective, join_collective, launch_collective_task,
|
|
17
|
+
* get_collective, get_collective_counter
|
|
18
|
+
* DisputeArbitration: file_dispute, cast_vote, get_dispute, get_dispute_counter
|
|
19
|
+
* AgentInsurance: claim_insurance, get_claim, get_claim_counter, get_coverage_percent
|
|
20
|
+
*/
|
|
21
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
22
|
+
export declare function createServer(): McpServer;
|
|
23
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAYpE,wBAAgB,YAAY,IAAI,SAAS,CAqBxC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COVENANT MCP Server — tool registration hub.
|
|
3
|
+
*
|
|
4
|
+
* Registers all MCP tools across 9 contracts:
|
|
5
|
+
* Phase 1:
|
|
6
|
+
* AgentRegistry: register_agent, get_agent, find_workers
|
|
7
|
+
* TaskEscrow: create_task, get_task, submit_work, verify_task, dispute_task
|
|
8
|
+
* ReceiptVerifier: get_receipts, verify_receipt
|
|
9
|
+
* Protocol: get_stats, get_leaderboard
|
|
10
|
+
* Phase 4:
|
|
11
|
+
* OpenTaskMarket: post_open_task, get_open_task, submit_bid, get_bid,
|
|
12
|
+
* select_worker, make_counter_offer, accept_counter_offer,
|
|
13
|
+
* withdraw_bid, cancel_open_task
|
|
14
|
+
* ParallelTaskBatch: create_batch, get_batch, get_batch_status,
|
|
15
|
+
* aggregate_results, get_batch_counter
|
|
16
|
+
* AgentCollective: create_collective, join_collective, launch_collective_task,
|
|
17
|
+
* get_collective, get_collective_counter
|
|
18
|
+
* DisputeArbitration: file_dispute, cast_vote, get_dispute, get_dispute_counter
|
|
19
|
+
* AgentInsurance: claim_insurance, get_claim, get_claim_counter, get_coverage_percent
|
|
20
|
+
*/
|
|
21
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
22
|
+
import { registerAgentTools } from "./tools/registry.js";
|
|
23
|
+
import { registerEscrowTools } from "./tools/escrow.js";
|
|
24
|
+
import { registerReceiptTools } from "./tools/receipts.js";
|
|
25
|
+
import { registerProtocolTools } from "./tools/protocol.js";
|
|
26
|
+
import { registerMarketTools } from "./tools/market.js";
|
|
27
|
+
import { registerBatchTools } from "./tools/batches.js";
|
|
28
|
+
import { registerCollectiveTools } from "./tools/collectives.js";
|
|
29
|
+
import { registerDisputeTools } from "./tools/disputes.js";
|
|
30
|
+
import { registerInsuranceTools } from "./tools/insurance.js";
|
|
31
|
+
import { info } from "./logger.js";
|
|
32
|
+
export function createServer() {
|
|
33
|
+
const server = new McpServer({
|
|
34
|
+
name: "covenant-mcp",
|
|
35
|
+
version: "1.0.0",
|
|
36
|
+
});
|
|
37
|
+
// Phase 1 tools
|
|
38
|
+
registerAgentTools(server);
|
|
39
|
+
registerEscrowTools(server);
|
|
40
|
+
registerReceiptTools(server);
|
|
41
|
+
registerProtocolTools(server);
|
|
42
|
+
// Phase 4 tools
|
|
43
|
+
registerMarketTools(server);
|
|
44
|
+
registerBatchTools(server);
|
|
45
|
+
registerCollectiveTools(server);
|
|
46
|
+
registerDisputeTools(server);
|
|
47
|
+
registerInsuranceTools(server);
|
|
48
|
+
info("[SERVER] Registered 27 MCP tools across 9 contracts");
|
|
49
|
+
return server;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,gBAAgB;IAChB,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE9B,gBAAgB;IAChB,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAChC,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAE/B,IAAI,CAAC,qDAAqD,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../../src/tools/batches.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA2BzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA0L1D"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ParallelTaskBatch MCP Tools
|
|
3
|
+
*
|
|
4
|
+
* create_batch — Create a batch of parallel tasks
|
|
5
|
+
* get_batch — Get batch details by ID
|
|
6
|
+
* get_batch_status — Get current batch status
|
|
7
|
+
* aggregate_results — Finalize batch results
|
|
8
|
+
* get_batch_counter — Get total number of batches
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { parseEther, formatEther, isAddress } from "viem";
|
|
12
|
+
import { loadAbi, CONTRACTS, getAccount } from "../config.js";
|
|
13
|
+
import { executeOrPrepare, readContract } from "../handlers/wallet.js";
|
|
14
|
+
import { formatTxResult, formatReadResult, formatError } from "../handlers/transactions.js";
|
|
15
|
+
const ABI = loadAbi("ParallelTaskBatch");
|
|
16
|
+
// Batch status enum
|
|
17
|
+
const BATCH_STATUS = {
|
|
18
|
+
0: "Pending",
|
|
19
|
+
1: "InProgress",
|
|
20
|
+
2: "Aggregated",
|
|
21
|
+
3: "Completed",
|
|
22
|
+
4: "Failed",
|
|
23
|
+
};
|
|
24
|
+
// Input validation schemas
|
|
25
|
+
const createBatchSchema = z.object({
|
|
26
|
+
workers: z.array(z.string().refine(isAddress, { message: "Invalid address" })).min(1).max(50),
|
|
27
|
+
payments: z.array(z.string()).min(1),
|
|
28
|
+
deadlines: z.array(z.number().int().positive()).min(1),
|
|
29
|
+
descriptionHashes: z.array(z.string().min(1)).min(1),
|
|
30
|
+
aggregationSpec: z.string().min(1).max(100),
|
|
31
|
+
}).refine(data => data.workers.length === data.payments.length &&
|
|
32
|
+
data.workers.length === data.deadlines.length &&
|
|
33
|
+
data.workers.length === data.descriptionHashes.length, { message: "All arrays must have the same length" });
|
|
34
|
+
export function registerBatchTools(server) {
|
|
35
|
+
// ──────────────────────────────────────────────────────────────
|
|
36
|
+
// create_batch
|
|
37
|
+
// ──────────────────────────────────────────────────────────────
|
|
38
|
+
server.registerTool("create_batch", {
|
|
39
|
+
title: "Create Parallel Task Batch",
|
|
40
|
+
description: "Create a batch of tasks for multiple workers to execute in parallel. " +
|
|
41
|
+
"All arrays must have the same length. Total ETH sent = sum of payments.",
|
|
42
|
+
inputSchema: {
|
|
43
|
+
workers: z.array(z.string()).describe("Array of worker addresses"),
|
|
44
|
+
payments: z.array(z.string()).describe("Array of payment amounts in ETH (one per worker)"),
|
|
45
|
+
deadlines: z.array(z.number()).describe("Array of deadline timestamps (seconds)"),
|
|
46
|
+
descriptionHashes: z.array(z.string()).describe("Array of IPFS CIDs for task descriptions"),
|
|
47
|
+
aggregationSpec: z.string().describe("IPFS CID for aggregation specification"),
|
|
48
|
+
},
|
|
49
|
+
}, async ({ workers, payments, deadlines, descriptionHashes, aggregationSpec }) => {
|
|
50
|
+
try {
|
|
51
|
+
const validation = createBatchSchema.safeParse({ workers, payments, deadlines, descriptionHashes, aggregationSpec });
|
|
52
|
+
if (!validation.success) {
|
|
53
|
+
return formatError(new Error(`Invalid input: ${validation.error.issues.map(e => e.message).join(", ")}`));
|
|
54
|
+
}
|
|
55
|
+
const account = getAccount();
|
|
56
|
+
if (!account) {
|
|
57
|
+
return formatError(new Error("No private key configured"));
|
|
58
|
+
}
|
|
59
|
+
// Convert payments to wei and calculate total
|
|
60
|
+
const paymentsWei = payments.map(p => parseEther(p));
|
|
61
|
+
const totalPayment = paymentsWei.reduce((sum, p) => sum + p, BigInt(0));
|
|
62
|
+
// Convert to bytes32 for description hashes
|
|
63
|
+
const descriptionHashesBytes32 = descriptionHashes.map(h => h);
|
|
64
|
+
const aggregationSpecBytes32 = aggregationSpec;
|
|
65
|
+
const result = await executeOrPrepare(CONTRACTS.ParallelTaskBatch, ABI, "createBatch", [
|
|
66
|
+
workers,
|
|
67
|
+
paymentsWei,
|
|
68
|
+
deadlines.map(BigInt),
|
|
69
|
+
descriptionHashesBytes32,
|
|
70
|
+
aggregationSpecBytes32,
|
|
71
|
+
], totalPayment);
|
|
72
|
+
return formatTxResult(result);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
return formatError(e);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// ──────────────────────────────────────────────────────────────
|
|
79
|
+
// get_batch
|
|
80
|
+
// ──────────────────────────────────────────────────────────────
|
|
81
|
+
server.registerTool("get_batch", {
|
|
82
|
+
title: "Get Batch Details",
|
|
83
|
+
description: "Retrieve full details of a task batch including all task IDs.",
|
|
84
|
+
inputSchema: {
|
|
85
|
+
batchId: z.number().describe("Numeric batch ID"),
|
|
86
|
+
},
|
|
87
|
+
}, async ({ batchId }) => {
|
|
88
|
+
try {
|
|
89
|
+
const data = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "getBatchDetails", [BigInt(batchId)]);
|
|
90
|
+
const enriched = {
|
|
91
|
+
client: data.client,
|
|
92
|
+
totalBudgetEth: formatEther(data.totalBudget),
|
|
93
|
+
taskIds: data.taskIds.map((id) => Number(id)),
|
|
94
|
+
aggregationSpec: data.aggregationSpec,
|
|
95
|
+
statusLabel: BATCH_STATUS[data.status] ?? `Unknown(${data.status})`,
|
|
96
|
+
createdAt: data.createdAt,
|
|
97
|
+
};
|
|
98
|
+
return formatReadResult(enriched, `Batch #${batchId}`);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
return formatError(e);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
// ──────────────────────────────────────────────────────────────
|
|
105
|
+
// get_batch_status
|
|
106
|
+
// ──────────────────────────────────────────────────────────────
|
|
107
|
+
server.registerTool("get_batch_status", {
|
|
108
|
+
title: "Get Batch Status",
|
|
109
|
+
description: "Get the current status of a batch (Pending/InProgress/Aggregated/etc).",
|
|
110
|
+
inputSchema: {
|
|
111
|
+
batchId: z.number().describe("Numeric batch ID"),
|
|
112
|
+
},
|
|
113
|
+
}, async ({ batchId }) => {
|
|
114
|
+
try {
|
|
115
|
+
const status = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "getBatchStatus", [BigInt(batchId)]);
|
|
116
|
+
const result = {
|
|
117
|
+
batchId,
|
|
118
|
+
status: Number(status),
|
|
119
|
+
statusLabel: BATCH_STATUS[Number(status)] ?? `Unknown(${status})`,
|
|
120
|
+
};
|
|
121
|
+
return formatReadResult(result, `Batch #${batchId} Status`);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
return formatError(e);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
// ──────────────────────────────────────────────────────────────
|
|
128
|
+
// aggregate_results
|
|
129
|
+
// ──────────────────────────────────────────────────────────────
|
|
130
|
+
server.registerTool("aggregate_results", {
|
|
131
|
+
title: "Aggregate Batch Results",
|
|
132
|
+
description: "Finalize a batch by aggregating all completed task results. " +
|
|
133
|
+
"Can only be called after all tasks in the batch are Submitted.",
|
|
134
|
+
inputSchema: {
|
|
135
|
+
batchId: z.number().describe("Numeric batch ID"),
|
|
136
|
+
},
|
|
137
|
+
}, async ({ batchId }) => {
|
|
138
|
+
try {
|
|
139
|
+
const account = getAccount();
|
|
140
|
+
if (!account) {
|
|
141
|
+
return formatError(new Error("No private key configured"));
|
|
142
|
+
}
|
|
143
|
+
const result = await executeOrPrepare(CONTRACTS.ParallelTaskBatch, ABI, "aggregateResults", [BigInt(batchId)]);
|
|
144
|
+
return formatTxResult(result);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
return formatError(e);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
// ──────────────────────────────────────────────────────────────
|
|
151
|
+
// get_batch_counter
|
|
152
|
+
// ──────────────────────────────────────────────────────────────
|
|
153
|
+
server.registerTool("get_batch_counter", {
|
|
154
|
+
title: "Get Batch Counter",
|
|
155
|
+
description: "Get the total number of batches created on the protocol.",
|
|
156
|
+
inputSchema: {},
|
|
157
|
+
}, async () => {
|
|
158
|
+
try {
|
|
159
|
+
const count = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "batchCounter", []);
|
|
160
|
+
return formatReadResult({ count: Number(count) }, "Batch Counter");
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return formatError(e);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=batches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batches.js","sourceRoot":"","sources":["../../src/tools/batches.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAgB,SAAS,EAAE,MAAM,MAAM,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,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