@jhinresh/agentkit-plugin 0.1.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 ADDED
@@ -0,0 +1,102 @@
1
+ # @maiat/agentkit-plugin
2
+
3
+ > Trust-gated transactions for Coinbase AgentKit agents
4
+
5
+ Automatically check trust scores before every transaction. Block interactions with untrusted addresses. One line to integrate.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @maiat/agentkit-plugin
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { AgentKit } from "@coinbase/agentkit";
17
+ import { maiatTrustPlugin } from "@maiat/agentkit-plugin";
18
+
19
+ const agent = new AgentKit({
20
+ // your config
21
+ });
22
+
23
+ // Add Maiat trust gating
24
+ agent.use(maiatTrustPlugin({
25
+ minScore: 3.0, // Block addresses below 3.0/10
26
+ chain: "base",
27
+ onBlocked: (addr, score, risk) => {
28
+ console.log(`🔴 Blocked ${addr}: ${score}/10 (${risk})`);
29
+ },
30
+ }));
31
+ ```
32
+
33
+ ## How It Works
34
+
35
+ 1. Agent wants to interact with address `0x1234...`
36
+ 2. Plugin queries Maiat API: `GET /v1/score/0x1234...`
37
+ 3. Score ≥ minScore → ✅ transaction proceeds
38
+ 4. Score < minScore → ❌ `MaiatTrustError` thrown, transaction blocked
39
+
40
+ ## Actions
41
+
42
+ ### `maiat_check_trust`
43
+ Check trust score for any address.
44
+
45
+ ```typescript
46
+ const result = await agent.run("Check if 0x4752... is trustworthy");
47
+ // → { score: 8.5, risk: "LOW", safe: true, ... }
48
+ ```
49
+
50
+ ### `maiat_gate_transaction`
51
+ Pre-flight check before executing a transaction.
52
+
53
+ ```typescript
54
+ // Automatically called before transactions when plugin is active
55
+ // Throws MaiatTrustError if target is untrusted
56
+ ```
57
+
58
+ ## Configuration
59
+
60
+ | Option | Default | Description |
61
+ |--------|---------|-------------|
62
+ | `minScore` | `3.0` | Minimum trust score (0-10) |
63
+ | `apiUrl` | `https://maiat-protocol.vercel.app` | API endpoint |
64
+ | `apiKey` | (none) | API key for higher limits |
65
+ | `chain` | `base` | Default chain |
66
+ | `warnOnly` | `false` | Log warnings instead of blocking |
67
+ | `onBlocked` | (none) | Callback when transaction blocked |
68
+ | `onCheck` | (none) | Callback for every check |
69
+
70
+ ## Standalone Client
71
+
72
+ ```typescript
73
+ import { MaiatClient } from "@maiat/agentkit-plugin";
74
+
75
+ const maiat = new MaiatClient({ chain: "base" });
76
+
77
+ const result = await maiat.checkTrust("0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24");
78
+ console.log(result.score, result.risk); // 8.5 "LOW"
79
+
80
+ // Batch check
81
+ const results = await maiat.batchCheck(["0x1234...", "0x5678..."]);
82
+ ```
83
+
84
+ ## x402 Integration
85
+
86
+ Works seamlessly with Coinbase's x402 protocol for agent-to-agent payments:
87
+
88
+ ```typescript
89
+ import { maiatTrustPlugin } from "@maiat/agentkit-plugin";
90
+
91
+ // Agent automatically checks trust before paying via x402
92
+ const plugin = maiatTrustPlugin({
93
+ minScore: 5.0, // Higher threshold for payments
94
+ onBlocked: (addr, score) => {
95
+ console.log(`Payment to ${addr} blocked — trust score ${score}/10`);
96
+ },
97
+ });
98
+ ```
99
+
100
+ ## License
101
+
102
+ MIT
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@jhinresh/agentkit-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Maiat Trust Score plugin for Coinbase AgentKit — auto-check trust before every transaction",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc --watch"
18
+ },
19
+ "dependencies": {},
20
+ "peerDependencies": {
21
+ "@coinbase/agentkit": ">=0.1.0"
22
+ },
23
+ "devDependencies": {
24
+ "typescript": "^5.5.0"
25
+ },
26
+ "keywords": ["maiat", "agentkit", "coinbase", "trust-score", "ai-agent", "web3", "x402"]
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,241 @@
1
+ /**
2
+ * @maiat/agentkit-plugin
3
+ *
4
+ * Coinbase AgentKit plugin that adds trust scoring to every agent transaction.
5
+ *
6
+ * Usage:
7
+ * ```typescript
8
+ * import { AgentKit } from "@coinbase/agentkit";
9
+ * import { maiatTrustPlugin } from "@maiat/agentkit-plugin";
10
+ *
11
+ * const agent = new AgentKit({ ... });
12
+ * agent.use(maiatTrustPlugin({ minScore: 3.0 }));
13
+ *
14
+ * // Now every transaction auto-checks trust before executing
15
+ * // Addresses below minScore are blocked automatically
16
+ * ```
17
+ */
18
+
19
+ // ═══════════════════════════════════════════
20
+ // Types
21
+ // ═══════════════════════════════════════════
22
+
23
+ export interface MaiatPluginConfig {
24
+ /** Minimum trust score (0-10) to allow transactions. Default: 3.0 */
25
+ minScore?: number;
26
+ /** Maiat API base URL. Default: https://maiat-protocol.vercel.app */
27
+ apiUrl?: string;
28
+ /** API key for higher rate limits */
29
+ apiKey?: string;
30
+ /** Chain to check. Default: base */
31
+ chain?: string;
32
+ /** If true, log warnings but don't block. Default: false */
33
+ warnOnly?: boolean;
34
+ /** Callback when a transaction is blocked */
35
+ onBlocked?: (address: string, score: number, risk: string) => void;
36
+ /** Callback for every trust check */
37
+ onCheck?: (address: string, score: number, risk: string) => void;
38
+ }
39
+
40
+ export interface TrustScoreResult {
41
+ address: string;
42
+ score: number;
43
+ risk: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
44
+ type: string;
45
+ flags: string[];
46
+ breakdown: {
47
+ onChainHistory: number;
48
+ contractAnalysis: number;
49
+ blacklistCheck: number;
50
+ activityPattern: number;
51
+ };
52
+ details: {
53
+ txCount: number;
54
+ balanceETH: number;
55
+ isContract: boolean;
56
+ walletAge: string | null;
57
+ lastActive: string | null;
58
+ };
59
+ protocol?: {
60
+ name: string;
61
+ category: string;
62
+ auditedBy?: string[];
63
+ };
64
+ }
65
+
66
+ export class MaiatTrustError extends Error {
67
+ constructor(
68
+ public address: string,
69
+ public score: number,
70
+ public risk: string,
71
+ public minScore: number,
72
+ ) {
73
+ super(
74
+ `Maiat: Transaction blocked — address ${address} has trust score ${score}/10 (${risk} risk), minimum required: ${minScore}`
75
+ );
76
+ this.name = "MaiatTrustError";
77
+ }
78
+ }
79
+
80
+ // ═══════════════════════════════════════════
81
+ // API Client
82
+ // ═══════════════════════════════════════════
83
+
84
+ export class MaiatClient {
85
+ private apiUrl: string;
86
+ private apiKey: string;
87
+ private chain: string;
88
+ private cache: Map<string, { result: TrustScoreResult; expiresAt: number }> = new Map();
89
+
90
+ constructor(config: Pick<MaiatPluginConfig, "apiUrl" | "apiKey" | "chain"> = {}) {
91
+ this.apiUrl = config.apiUrl || "https://maiat-protocol.vercel.app";
92
+ this.apiKey = config.apiKey || "";
93
+ this.chain = config.chain || "base";
94
+ }
95
+
96
+ async checkTrust(address: string, chain?: string): Promise<TrustScoreResult> {
97
+ const cacheKey = `${address}:${chain || this.chain}`;
98
+ const cached = this.cache.get(cacheKey);
99
+ if (cached && cached.expiresAt > Date.now()) {
100
+ return cached.result;
101
+ }
102
+
103
+ const headers: Record<string, string> = {
104
+ "Content-Type": "application/json",
105
+ "User-Agent": "maiat-agentkit-plugin/0.1.0",
106
+ };
107
+ if (this.apiKey) {
108
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
109
+ }
110
+
111
+ const url = `${this.apiUrl}/api/v1/score/${address}?chain=${chain || this.chain}`;
112
+ const res = await fetch(url, { headers });
113
+
114
+ if (!res.ok) {
115
+ throw new Error(`Maiat API error (${res.status}): ${await res.text()}`);
116
+ }
117
+
118
+ const result: TrustScoreResult = await res.json();
119
+
120
+ // Cache for 5 minutes
121
+ this.cache.set(cacheKey, { result, expiresAt: Date.now() + 5 * 60 * 1000 });
122
+
123
+ return result;
124
+ }
125
+
126
+ async batchCheck(addresses: string[], chain?: string): Promise<TrustScoreResult[]> {
127
+ return Promise.all(addresses.map((addr) => this.checkTrust(addr, chain)));
128
+ }
129
+
130
+ isSafe(score: number, minScore: number = 3.0): boolean {
131
+ return score >= minScore;
132
+ }
133
+ }
134
+
135
+ // ═══════════════════════════════════════════
136
+ // AgentKit Plugin Interface
137
+ // ═══════════════════════════════════════════
138
+
139
+ /**
140
+ * AgentKit plugin action definitions.
141
+ * These are the tools/actions that the agent can use.
142
+ */
143
+ export function maiatTrustActions(config: MaiatPluginConfig = {}) {
144
+ const client = new MaiatClient(config);
145
+ const minScore = config.minScore ?? 3.0;
146
+
147
+ return [
148
+ {
149
+ name: "maiat_check_trust",
150
+ description: `Check the trust score of an on-chain address using Maiat. Returns a 0-10 score with risk assessment. Addresses scoring below ${minScore} are considered unsafe.`,
151
+ schema: {
152
+ type: "object" as const,
153
+ properties: {
154
+ address: { type: "string", description: "On-chain address to check (0x...)" },
155
+ chain: { type: "string", description: "Chain: base, ethereum, bnb. Default: base" },
156
+ },
157
+ required: ["address"],
158
+ },
159
+ handler: async (params: { address: string; chain?: string }) => {
160
+ const result = await client.checkTrust(params.address, params.chain);
161
+ config.onCheck?.(result.address, result.score, result.risk);
162
+
163
+ const safe = client.isSafe(result.score, minScore);
164
+ return {
165
+ score: result.score,
166
+ risk: result.risk,
167
+ type: result.type,
168
+ flags: result.flags,
169
+ safe,
170
+ breakdown: result.breakdown,
171
+ details: result.details,
172
+ protocol: result.protocol,
173
+ recommendation: safe
174
+ ? `✅ Address is trusted (${result.score}/10). Safe to proceed.`
175
+ : `⚠️ Address has low trust (${result.score}/10, ${result.risk} risk). ${config.warnOnly ? "Proceeding with caution." : "Transaction blocked."}`,
176
+ };
177
+ },
178
+ },
179
+ {
180
+ name: "maiat_gate_transaction",
181
+ description: "Check if a transaction target is trustworthy before executing. Blocks transactions to untrusted addresses automatically.",
182
+ schema: {
183
+ type: "object" as const,
184
+ properties: {
185
+ to: { type: "string", description: "Target address of the transaction" },
186
+ value: { type: "string", description: "Transaction value (optional context)" },
187
+ chain: { type: "string", description: "Chain: base, ethereum, bnb" },
188
+ },
189
+ required: ["to"],
190
+ },
191
+ handler: async (params: { to: string; value?: string; chain?: string }) => {
192
+ const result = await client.checkTrust(params.to, params.chain);
193
+ config.onCheck?.(result.address, result.score, result.risk);
194
+
195
+ if (!client.isSafe(result.score, minScore) && !config.warnOnly) {
196
+ config.onBlocked?.(result.address, result.score, result.risk);
197
+ throw new MaiatTrustError(result.address, result.score, result.risk, minScore);
198
+ }
199
+
200
+ return {
201
+ approved: true,
202
+ score: result.score,
203
+ risk: result.risk,
204
+ address: result.address,
205
+ };
206
+ },
207
+ },
208
+ ];
209
+ }
210
+
211
+ // ═══════════════════════════════════════════
212
+ // Convenience Export
213
+ // ═══════════════════════════════════════════
214
+
215
+ /**
216
+ * Create a Maiat trust plugin for AgentKit
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * import { maiatTrustPlugin } from "@maiat/agentkit-plugin";
221
+ *
222
+ * const plugin = maiatTrustPlugin({
223
+ * minScore: 3.0,
224
+ * onBlocked: (addr, score) => console.log(`Blocked ${addr}: ${score}/10`)
225
+ * });
226
+ *
227
+ * // Use with AgentKit
228
+ * agent.use(plugin);
229
+ * ```
230
+ */
231
+ export function maiatTrustPlugin(config: MaiatPluginConfig = {}) {
232
+ return {
233
+ name: "maiat-trust",
234
+ version: "0.1.0",
235
+ actions: maiatTrustActions(config),
236
+ client: new MaiatClient(config),
237
+ };
238
+ }
239
+
240
+ // Default export
241
+ export default maiatTrustPlugin;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "declaration": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["src"]
14
+ }