@jhinresh/elizaos-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/package.json +17 -0
- package/src/index.ts +163 -0
- package/tsconfig.json +14 -0
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jhinresh/elizaos-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Maiat Trust Score plugin for ElizaOS — trust-gated agent interactions",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsc --watch"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.5.0"
|
|
15
|
+
},
|
|
16
|
+
"keywords": ["maiat", "elizaos", "ai16z", "trust-score", "ai-agent"]
|
|
17
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @maiat/elizaos-plugin
|
|
3
|
+
*
|
|
4
|
+
* Maiat Trust Score plugin for ElizaOS (ai16z agent framework).
|
|
5
|
+
*
|
|
6
|
+
* Adds trust checking capabilities to any ElizaOS agent:
|
|
7
|
+
* - "Is this address safe?" → trust score lookup
|
|
8
|
+
* - Auto-gate transactions before execution
|
|
9
|
+
* - Report transaction outcomes back to Maiat
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { maiatPlugin } from "@maiat/elizaos-plugin";
|
|
14
|
+
*
|
|
15
|
+
* const agent = new ElizaAgent({
|
|
16
|
+
* plugins: [maiatPlugin({ minScore: 3.0 })],
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// ═══════════════════════════════════════════
|
|
22
|
+
// Types
|
|
23
|
+
// ═══════════════════════════════════════════
|
|
24
|
+
|
|
25
|
+
export interface MaiatElizaConfig {
|
|
26
|
+
apiUrl?: string;
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
chain?: string;
|
|
29
|
+
minScore?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TrustResult {
|
|
33
|
+
address: string;
|
|
34
|
+
score: number;
|
|
35
|
+
risk: string;
|
|
36
|
+
type: string;
|
|
37
|
+
flags: string[];
|
|
38
|
+
safe: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ═══════════════════════════════════════════
|
|
42
|
+
// API Client (lightweight)
|
|
43
|
+
// ═══════════════════════════════════════════
|
|
44
|
+
|
|
45
|
+
async function queryMaiat(
|
|
46
|
+
address: string,
|
|
47
|
+
config: MaiatElizaConfig
|
|
48
|
+
): Promise<TrustResult> {
|
|
49
|
+
const apiUrl = config.apiUrl || "https://maiat-protocol.vercel.app";
|
|
50
|
+
const chain = config.chain || "base";
|
|
51
|
+
const minScore = config.minScore ?? 3.0;
|
|
52
|
+
|
|
53
|
+
const headers: Record<string, string> = {
|
|
54
|
+
"User-Agent": "maiat-elizaos-plugin/0.1.0",
|
|
55
|
+
};
|
|
56
|
+
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
57
|
+
|
|
58
|
+
const res = await fetch(`${apiUrl}/api/v1/score/${address}?chain=${chain}`, { headers });
|
|
59
|
+
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
throw new Error(`Maiat API error: ${res.status}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const data = await res.json();
|
|
65
|
+
return {
|
|
66
|
+
address: data.address,
|
|
67
|
+
score: data.score,
|
|
68
|
+
risk: data.risk,
|
|
69
|
+
type: data.type,
|
|
70
|
+
flags: data.flags || [],
|
|
71
|
+
safe: data.score >= minScore,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ═══════════════════════════════════════════
|
|
76
|
+
// ElizaOS Plugin
|
|
77
|
+
// ═══════════════════════════════════════════
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* ElizaOS plugin definition following the standard plugin interface.
|
|
81
|
+
*
|
|
82
|
+
* Registers:
|
|
83
|
+
* - Action: CHECK_TRUST — responds to "is 0x... safe?" type queries
|
|
84
|
+
* - Evaluator: TRUST_GATE — evaluates if an address should be interacted with
|
|
85
|
+
* - Provider: TRUST_DATA — provides trust context for agent reasoning
|
|
86
|
+
*/
|
|
87
|
+
export function maiatPlugin(config: MaiatElizaConfig = {}) {
|
|
88
|
+
return {
|
|
89
|
+
name: "maiat-trust",
|
|
90
|
+
description: "Trust scoring for on-chain addresses via Maiat Protocol",
|
|
91
|
+
|
|
92
|
+
actions: [
|
|
93
|
+
{
|
|
94
|
+
name: "CHECK_TRUST",
|
|
95
|
+
description: "Check the trust score of an on-chain address",
|
|
96
|
+
examples: [
|
|
97
|
+
"Is 0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24 safe?",
|
|
98
|
+
"Check trust score for 0x1234...",
|
|
99
|
+
"Should I interact with this address: 0xabcd...?",
|
|
100
|
+
],
|
|
101
|
+
validate: async (message: string) => {
|
|
102
|
+
return /0x[a-fA-F0-9]{40}/.test(message);
|
|
103
|
+
},
|
|
104
|
+
handler: async (message: string) => {
|
|
105
|
+
const match = message.match(/0x[a-fA-F0-9]{40}/);
|
|
106
|
+
if (!match) return { text: "Please provide a valid Ethereum address (0x...)" };
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const result = await queryMaiat(match[0], config);
|
|
110
|
+
const emoji = result.safe ? "🟢" : result.risk === "CRITICAL" ? "🔴" : "🟡";
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
text: `${emoji} **Trust Score: ${result.score}/10** (${result.risk} risk)\n\nAddress: \`${result.address}\`\nType: ${result.type}\nFlags: ${result.flags.join(", ") || "None"}\n\n${result.safe ? "✅ Safe to interact." : "⚠️ Exercise caution — low trust score."}`,
|
|
114
|
+
data: result,
|
|
115
|
+
};
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return {
|
|
118
|
+
text: `❌ Could not check trust score: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
|
|
125
|
+
evaluators: [
|
|
126
|
+
{
|
|
127
|
+
name: "TRUST_GATE",
|
|
128
|
+
description: "Evaluates if a target address meets minimum trust requirements",
|
|
129
|
+
handler: async (context: { address?: string }) => {
|
|
130
|
+
if (!context.address) return { pass: true, reason: "No address to check" };
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const result = await queryMaiat(context.address, config);
|
|
134
|
+
return {
|
|
135
|
+
pass: result.safe,
|
|
136
|
+
score: result.score,
|
|
137
|
+
risk: result.risk,
|
|
138
|
+
reason: result.safe
|
|
139
|
+
? `Address trusted (${result.score}/10)`
|
|
140
|
+
: `Address untrusted (${result.score}/10, ${result.risk} risk)`,
|
|
141
|
+
};
|
|
142
|
+
} catch {
|
|
143
|
+
return { pass: false, reason: "Trust check failed — blocking by default" };
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
|
|
149
|
+
providers: [
|
|
150
|
+
{
|
|
151
|
+
name: "TRUST_DATA",
|
|
152
|
+
description: "Provides trust scoring context for agent reasoning",
|
|
153
|
+
handler: async () => {
|
|
154
|
+
return {
|
|
155
|
+
text: "You have access to Maiat trust scoring. Before interacting with any unknown on-chain address, use CHECK_TRUST to verify it's safe. Addresses scoring below 3.0/10 should be avoided.",
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default maiatPlugin;
|
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
|
+
}
|