maiat-sdk 0.1.0 → 0.2.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 +28 -0
- package/dist/index.d.ts +35 -1
- package/dist/index.js +21 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,34 @@ console.log(swap.calldata); // ready-to-sign tx calldata
|
|
|
57
57
|
| `isTrusted(address, threshold?)` | `boolean` | Quick trust check (default ≥60) |
|
|
58
58
|
| `isTokenSafe(address)` | `boolean` | Quick token safety check |
|
|
59
59
|
|
|
60
|
+
## Outcome Reporting (Training Data)
|
|
61
|
+
|
|
62
|
+
The most valuable data for improving trust accuracy:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const maiat = new Maiat({ clientId: "my-trading-bot" });
|
|
66
|
+
|
|
67
|
+
// 1. Check trust
|
|
68
|
+
const score = await maiat.agentTrust("0xCounterparty");
|
|
69
|
+
|
|
70
|
+
// 2. Take action based on trust
|
|
71
|
+
if (score.trustScore >= 60) {
|
|
72
|
+
// ... execute swap ...
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 3. Report what happened
|
|
76
|
+
await maiat.reportOutcome({
|
|
77
|
+
target: "0xCounterparty",
|
|
78
|
+
action: "swap",
|
|
79
|
+
result: "success", // or "failure", "scam"
|
|
80
|
+
txHash: "0x...", // on-chain proof
|
|
81
|
+
maiatVerdict: score.verdict,
|
|
82
|
+
maiatScore: score.trustScore,
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This closes the feedback loop: check → act → report → oracle gets smarter.
|
|
87
|
+
|
|
60
88
|
## Links
|
|
61
89
|
|
|
62
90
|
- Protocol: [maiat-protocol.vercel.app](https://maiat-protocol.vercel.app)
|
package/dist/index.d.ts
CHANGED
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
5
|
* import { Maiat } from "maiat-sdk";
|
|
6
|
-
* const maiat = new Maiat();
|
|
6
|
+
* const maiat = new Maiat({ clientId: "my-agent" });
|
|
7
7
|
* const score = await maiat.agentTrust("0x...");
|
|
8
8
|
* const token = await maiat.tokenCheck("0x...");
|
|
9
9
|
* const swap = await maiat.trustSwap({ ... });
|
|
10
|
+
* await maiat.reportOutcome({ agent: "0x...", action: "swap", result: "success" });
|
|
10
11
|
*/
|
|
11
12
|
export interface MaiatConfig {
|
|
12
13
|
/** Base URL for Maiat Protocol API. Default: https://maiat-protocol.vercel.app */
|
|
13
14
|
baseUrl?: string;
|
|
14
15
|
/** Optional API key for higher rate limits */
|
|
15
16
|
apiKey?: string;
|
|
17
|
+
/** Client identifier — tracks which agent/app is making requests (training data) */
|
|
18
|
+
clientId?: string;
|
|
16
19
|
/** Request timeout in ms. Default: 15000 */
|
|
17
20
|
timeout?: number;
|
|
18
21
|
}
|
|
@@ -64,9 +67,30 @@ export interface TrustSwapResult {
|
|
|
64
67
|
};
|
|
65
68
|
timestamp: string;
|
|
66
69
|
}
|
|
70
|
+
export interface OutcomeReport {
|
|
71
|
+
/** The agent or token address that was checked */
|
|
72
|
+
target: string;
|
|
73
|
+
/** What action was taken after checking trust */
|
|
74
|
+
action: "swap" | "delegate" | "hire" | "skip" | "block" | "other";
|
|
75
|
+
/** The outcome of that action */
|
|
76
|
+
result: "success" | "failure" | "scam" | "partial" | "pending";
|
|
77
|
+
/** On-chain tx hash as proof (optional) */
|
|
78
|
+
txHash?: string;
|
|
79
|
+
/** What Maiat verdict was at the time */
|
|
80
|
+
maiatVerdict?: "proceed" | "caution" | "avoid";
|
|
81
|
+
/** Trust score at the time of check */
|
|
82
|
+
maiatScore?: number;
|
|
83
|
+
/** Free-form context */
|
|
84
|
+
notes?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface OutcomeResponse {
|
|
87
|
+
logged: boolean;
|
|
88
|
+
id?: string;
|
|
89
|
+
}
|
|
67
90
|
export declare class Maiat {
|
|
68
91
|
private baseUrl;
|
|
69
92
|
private apiKey?;
|
|
93
|
+
private clientId?;
|
|
70
94
|
private timeout;
|
|
71
95
|
constructor(config?: MaiatConfig);
|
|
72
96
|
private request;
|
|
@@ -81,6 +105,16 @@ export declare class Maiat {
|
|
|
81
105
|
agents: AgentTrustResult[];
|
|
82
106
|
total: number;
|
|
83
107
|
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Report the outcome of an action taken after a Maiat trust check.
|
|
110
|
+
* This is the most valuable data for training the oracle.
|
|
111
|
+
*
|
|
112
|
+
* Example flow:
|
|
113
|
+
* 1. maiat.isTrusted("0x...") → true
|
|
114
|
+
* 2. You swap with that agent
|
|
115
|
+
* 3. maiat.reportOutcome({ target: "0x...", action: "swap", result: "success" })
|
|
116
|
+
*/
|
|
117
|
+
reportOutcome(report: OutcomeReport): Promise<OutcomeResponse>;
|
|
84
118
|
/** Quick check: is this agent trustworthy? Returns true if score >= threshold */
|
|
85
119
|
isTrusted(address: string, threshold?: number): Promise<boolean>;
|
|
86
120
|
/** Quick check: is this token safe to swap? */
|
package/dist/index.js
CHANGED
|
@@ -3,25 +3,29 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
5
|
* import { Maiat } from "maiat-sdk";
|
|
6
|
-
* const maiat = new Maiat();
|
|
6
|
+
* const maiat = new Maiat({ clientId: "my-agent" });
|
|
7
7
|
* const score = await maiat.agentTrust("0x...");
|
|
8
8
|
* const token = await maiat.tokenCheck("0x...");
|
|
9
9
|
* const swap = await maiat.trustSwap({ ... });
|
|
10
|
+
* await maiat.reportOutcome({ agent: "0x...", action: "swap", result: "success" });
|
|
10
11
|
*/
|
|
11
12
|
// ─── Client ───────────────────────────────────────────────────────────────────
|
|
12
13
|
export class Maiat {
|
|
13
14
|
baseUrl;
|
|
14
15
|
apiKey;
|
|
16
|
+
clientId;
|
|
15
17
|
timeout;
|
|
16
18
|
constructor(config = {}) {
|
|
17
19
|
this.baseUrl = (config.baseUrl ?? "https://maiat-protocol.vercel.app").replace(/\/$/, "");
|
|
18
20
|
this.apiKey = config.apiKey;
|
|
21
|
+
this.clientId = config.clientId;
|
|
19
22
|
this.timeout = config.timeout ?? 15_000;
|
|
20
23
|
}
|
|
21
24
|
async request(path, options) {
|
|
22
25
|
const headers = {
|
|
23
26
|
"Content-Type": "application/json",
|
|
24
27
|
...(this.apiKey ? { "X-Maiat-Key": this.apiKey } : {}),
|
|
28
|
+
...(this.clientId ? { "X-Maiat-Client": this.clientId } : {}),
|
|
25
29
|
};
|
|
26
30
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
27
31
|
...options,
|
|
@@ -54,6 +58,22 @@ export class Maiat {
|
|
|
54
58
|
async listAgents(limit = 50) {
|
|
55
59
|
return this.request(`/api/v1/agents?limit=${limit}`);
|
|
56
60
|
}
|
|
61
|
+
// ─── Outcome Reporting (Training Data) ────────────────────────────────────
|
|
62
|
+
/**
|
|
63
|
+
* Report the outcome of an action taken after a Maiat trust check.
|
|
64
|
+
* This is the most valuable data for training the oracle.
|
|
65
|
+
*
|
|
66
|
+
* Example flow:
|
|
67
|
+
* 1. maiat.isTrusted("0x...") → true
|
|
68
|
+
* 2. You swap with that agent
|
|
69
|
+
* 3. maiat.reportOutcome({ target: "0x...", action: "swap", result: "success" })
|
|
70
|
+
*/
|
|
71
|
+
async reportOutcome(report) {
|
|
72
|
+
return this.request("/api/v1/outcome", {
|
|
73
|
+
method: "POST",
|
|
74
|
+
body: JSON.stringify(report),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
57
77
|
// ─── Convenience ──────────────────────────────────────────────────────────
|
|
58
78
|
/** Quick check: is this agent trustworthy? Returns true if score >= threshold */
|
|
59
79
|
async isTrusted(address, threshold = 60) {
|