agentsla 0.0.0-stage → 2.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 +49 -2
- package/index.js +164 -0
- package/package.json +26 -5
- package/test.js +36 -0
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AgentSLA SDK (v2.0.0)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official M2M JavaScript/TypeScript SDK for **AgentSLA** (https://agentsla.io) — the autonomous API telemetry directory, EIP-712 cryptographic SLA oracle, Streamable HTTP MCP server, and Circle USDC escrow protocol on **Base Mainnet (Chain ID 8453)**.
|
|
4
|
+
|
|
5
|
+
## Production Infrastructure (Base Mainnet)
|
|
6
|
+
|
|
7
|
+
- **Verified Escrow Contract:** [0x6ca6cDDd6EC59D75Ea0a36882AC57fc199Ba79CD](https://basescan.org/address/0x6ca6cDDd6EC59D75Ea0a36882AC57fc199Ba79CD)
|
|
8
|
+
- **Settlement Token (Circle USDC):** [0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913](https://basescan.org/token/0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) (6 decimals)
|
|
9
|
+
- **Streamable HTTP MCP Endpoint:** https://agentsla.io/mcp
|
|
10
|
+
- **LLM Discovery Manifests:** https://agentsla.io/llms.txt | https://agentsla.io/llms-full.txt
|
|
11
|
+
- **OpenAPI 3.1.0 Spec:** https://agentsla.io/openapi.json
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install agentsla ethers
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { ethers } from "ethers";
|
|
23
|
+
import { AgentSLA } from "agentsla";
|
|
24
|
+
|
|
25
|
+
const provider = new ethers.JsonRpcProvider("https://mainnet.base.org");
|
|
26
|
+
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
|
|
27
|
+
const client = new AgentSLA({ signer: wallet });
|
|
28
|
+
|
|
29
|
+
// 1. Discover top-ranked APIs by category
|
|
30
|
+
const directory = await client.discover("ai-models");
|
|
31
|
+
|
|
32
|
+
// 2. Probe an endpoint and receive a signed EIP-712 SLA attestation
|
|
33
|
+
const proof = await client.verify("https://mainnet.base.org");
|
|
34
|
+
|
|
35
|
+
// 3. Lock Circle USDC in Base Mainnet Escrow for an M2M API task
|
|
36
|
+
const receipt = await client.lockEscrowUsdc(wallet.address, 1, "0.01");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Streamable HTTP MCP Configuration
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"agentsla": {
|
|
45
|
+
"type": "streamable-http",
|
|
46
|
+
"url": "https://agentsla.io/mcp"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_ORACLE_URL = "https://agentsla-oracle.agentsla-dev.workers.dev";
|
|
4
|
+
export const DEFAULT_MCP_URL = "https://agentsla.io/mcp";
|
|
5
|
+
export const ESCROW_ADDRESS = "0x6ca6cDDd6EC59D75Ea0a36882AC57fc199Ba79CD";
|
|
6
|
+
export const USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
7
|
+
export const BASE_CHAIN_ID = 8453;
|
|
8
|
+
|
|
9
|
+
export const ESCROW_ABI = [
|
|
10
|
+
"function owner() view returns (address)",
|
|
11
|
+
"function payoutWallet() view returns (address)",
|
|
12
|
+
"function usdcToken() view returns (address)",
|
|
13
|
+
"function nextJobId() view returns (uint256)",
|
|
14
|
+
"function accumulatedFees() view returns (uint256)",
|
|
15
|
+
"function isSubscribed(address) view returns (bool)",
|
|
16
|
+
"function jobs(uint256) view returns (address creator, address agent, uint256 apiId, uint256 lockedAmount, bool isActive)",
|
|
17
|
+
"function paySubscription() external",
|
|
18
|
+
"function createJob(address _agent, uint256 _apiId, uint256 _lockedAmount) external returns (uint256)",
|
|
19
|
+
"function resolveJob(uint256 _jobId, bool _slaMet) external"
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export const USDC_ABI = [
|
|
23
|
+
"function balanceOf(address account) view returns (uint256)",
|
|
24
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
25
|
+
"function approve(address spender, uint256 amount) external returns (bool)"
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export class AgentSLA {
|
|
29
|
+
/**
|
|
30
|
+
* @param {Object} config
|
|
31
|
+
* @param {string} [config.oracleUrl] - Custom AgentSLA Oracle Worker URL
|
|
32
|
+
* @param {string} [config.mcpUrl] - Streamable HTTP MCP URL (https://agentsla.io/mcp)
|
|
33
|
+
* @param {string} [config.escrowAddress] - Base Mainnet Escrow Contract Address
|
|
34
|
+
* @param {string} [config.usdcAddress] - Base Mainnet Circle USDC Address
|
|
35
|
+
* @param {ethers.Signer|ethers.Provider} [config.signer] - Ethers v6 Signer or Provider
|
|
36
|
+
*/
|
|
37
|
+
constructor(config = {}) {
|
|
38
|
+
this.oracleUrl = config.oracleUrl || DEFAULT_ORACLE_URL;
|
|
39
|
+
this.mcpUrl = config.mcpUrl || DEFAULT_MCP_URL;
|
|
40
|
+
this.escrowAddress = config.escrowAddress || ESCROW_ADDRESS;
|
|
41
|
+
this.usdcAddress = config.usdcAddress || USDC_ADDRESS;
|
|
42
|
+
this.signer = config.signer || null;
|
|
43
|
+
|
|
44
|
+
if (this.signer) {
|
|
45
|
+
this.contract = new ethers.Contract(this.escrowAddress, ESCROW_ABI, this.signer);
|
|
46
|
+
this.usdc = new ethers.Contract(this.usdcAddress, USDC_ABI, this.signer);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Probe an API endpoint via the AgentSLA Oracle, generate a signed EIP-712 SLA proof,
|
|
52
|
+
* and optionally resolve an active on-chain Base Mainnet USDC escrow job.
|
|
53
|
+
* @param {string} targetApiUrl - Target API endpoint to probe
|
|
54
|
+
* @param {number} [jobId=0] - Active Base Mainnet escrow jobId (0 for probe-only)
|
|
55
|
+
* @param {Object} [targetApiPayload] - Optional POST payload for the target API
|
|
56
|
+
*/
|
|
57
|
+
async verify(targetApiUrl, jobId = 0, targetApiPayload = undefined) {
|
|
58
|
+
if (!targetApiUrl) throw new Error("targetApiUrl is required.");
|
|
59
|
+
|
|
60
|
+
const response = await fetch(`${this.oracleUrl}/v1/verify`, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: { "Content-Type": "application/json" },
|
|
63
|
+
body: JSON.stringify({ jobId, targetApiUrl, targetApiPayload })
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
throw new Error(data.error || "Failed to verify endpoint via AgentSLA Oracle.");
|
|
69
|
+
}
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Approve Circle USDC (if needed) and lock USDC in Base Mainnet Escrow for an M2M API task.
|
|
75
|
+
* @param {string} agentWallet - Provider agent wallet address
|
|
76
|
+
* @param {number|bigint} apiId - Monitored API ID from the AgentSLA directory
|
|
77
|
+
* @param {string|number} amountUsdc - Amount in USDC (e.g., "0.01" or "5.00")
|
|
78
|
+
*/
|
|
79
|
+
async lockEscrowUsdc(agentWallet, apiId, amountUsdc) {
|
|
80
|
+
if (!this.contract || !this.usdc || typeof this.signer.getAddress !== "function") {
|
|
81
|
+
throw new Error("A connected ethers.js Signer is required to lock USDC in escrow.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const amountUnits = ethers.parseUnits(amountUsdc.toString(), 6);
|
|
85
|
+
const ownerAddress = await this.signer.getAddress();
|
|
86
|
+
const currentAllowance = await this.usdc.allowance(ownerAddress, this.escrowAddress);
|
|
87
|
+
|
|
88
|
+
if (currentAllowance < amountUnits) {
|
|
89
|
+
const approveTx = await this.usdc.approve(this.escrowAddress, amountUnits);
|
|
90
|
+
await approveTx.wait(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const createTx = await this.contract.createJob(agentWallet, BigInt(apiId), amountUnits);
|
|
94
|
+
return await createTx.wait(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Pay the 5 USDC 7-day autonomous oracle subscription on Base Mainnet.
|
|
99
|
+
*/
|
|
100
|
+
async paySubscription() {
|
|
101
|
+
if (!this.contract || !this.usdc || typeof this.signer.getAddress !== "function") {
|
|
102
|
+
throw new Error("A connected ethers.js Signer is required to pay subscription.");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const feeUnits = ethers.parseUnits("5.0", 6);
|
|
106
|
+
const ownerAddress = await this.signer.getAddress();
|
|
107
|
+
const currentAllowance = await this.usdc.allowance(ownerAddress, this.escrowAddress);
|
|
108
|
+
|
|
109
|
+
if (currentAllowance < feeUnits) {
|
|
110
|
+
const approveTx = await this.usdc.approve(this.escrowAddress, feeUnits);
|
|
111
|
+
await approveTx.wait(1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const tx = await this.contract.paySubscription();
|
|
115
|
+
return await tx.wait(1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Discover ranked APIs in the AgentSLA directory.
|
|
120
|
+
* @param {string} [category="all"]
|
|
121
|
+
*/
|
|
122
|
+
async discover(category = "all") {
|
|
123
|
+
const query = category && category !== "all" ? `?category=${encodeURIComponent(category)}` : "";
|
|
124
|
+
const response = await fetch(`${this.oracleUrl}/v1/directory${query}`);
|
|
125
|
+
return await response.json();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Register a new API endpoint in the AgentSLA directory.
|
|
130
|
+
*/
|
|
131
|
+
async register({ service_name, endpoint_url, category = "general", sla_threshold = 99.9, capabilities = [] }) {
|
|
132
|
+
const response = await fetch(`${this.oracleUrl}/v1/directory`, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: { "Content-Type": "application/json" },
|
|
135
|
+
body: JSON.stringify({ service_name, endpoint_url, category, sla_threshold, capabilities })
|
|
136
|
+
});
|
|
137
|
+
return await response.json();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Fetch recent EIP-712 signed oracle attestations.
|
|
142
|
+
*/
|
|
143
|
+
async getAttestations() {
|
|
144
|
+
const response = await fetch(`${this.oracleUrl}/api/attestations`);
|
|
145
|
+
return await response.json();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Call a tool directly on the hosted Streamable HTTP MCP server (https://agentsla.io/mcp).
|
|
150
|
+
*/
|
|
151
|
+
async callMcpTool(name, args = {}) {
|
|
152
|
+
const response = await fetch(this.mcpUrl, {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: { "Content-Type": "application/json" },
|
|
155
|
+
body: JSON.stringify({
|
|
156
|
+
jsonrpc: "2.0",
|
|
157
|
+
id: Date.now(),
|
|
158
|
+
method: "tools/call",
|
|
159
|
+
params: { name, arguments: args }
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
return await response.json();
|
|
163
|
+
}
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
2
|
"name": "agentsla",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Official M2M SDK for the AgentSLA API Telemetry Directory, EIP-712 SLA Oracle, Streamable HTTP MCP Server, and Circle USDC Escrow Contract on Base Mainnet (8453).",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node test.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"ai",
|
|
12
|
+
"agents",
|
|
13
|
+
"m2m",
|
|
14
|
+
"mcp",
|
|
15
|
+
"web3",
|
|
16
|
+
"sla",
|
|
17
|
+
"oracle",
|
|
18
|
+
"usdc",
|
|
19
|
+
"eip-712",
|
|
20
|
+
"base-mainnet"
|
|
21
|
+
],
|
|
22
|
+
"author": "AgentSLA (https://agentsla.io)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"ethers": "^6.7.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/test.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { AgentSLA, ESCROW_ADDRESS, USDC_ADDRESS } from "./index.js";
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const provider = new ethers.JsonRpcProvider("https://mainnet.base.org");
|
|
6
|
+
const client = new AgentSLA({ signer: provider });
|
|
7
|
+
|
|
8
|
+
console.log("=== 1. Testing AgentSLA Directory Discovery ===");
|
|
9
|
+
const dir = await client.discover("ai-models");
|
|
10
|
+
console.log(`Discovered ${dir.count} AI Model APIs (Escrow Contract: ${dir.escrowContract})`);
|
|
11
|
+
|
|
12
|
+
console.log("\n=== 2. Testing Live EIP-712 SLA Verification Probe ===");
|
|
13
|
+
const verification = await client.verify("https://mainnet.base.org");
|
|
14
|
+
console.log("Target Endpoint :", verification.targetApiUrl);
|
|
15
|
+
console.log("Latency (ms) :", verification.latencyMs);
|
|
16
|
+
console.log("SLA Met :", verification.slaMet);
|
|
17
|
+
console.log("Oracle Signer :", verification.oracleSigner);
|
|
18
|
+
console.log("EIP-712 Proof :", verification.eip712Signature.slice(0, 42) + "...");
|
|
19
|
+
|
|
20
|
+
console.log("\n=== 3. Testing Hosted Streamable HTTP MCP Server (https://agentsla.io/mcp) ===");
|
|
21
|
+
const mcpRes = await client.callMcpTool("get_usdc_escrow_contract");
|
|
22
|
+
console.log("MCP Response :", mcpRes.result.content[0].text.replace(/\s+/g, " "));
|
|
23
|
+
|
|
24
|
+
console.log("\n=== 4. Verifying Base Mainnet On-Chain Escrow State ===");
|
|
25
|
+
const [nextJobId, fees] = await Promise.all([
|
|
26
|
+
client.contract.nextJobId(),
|
|
27
|
+
client.contract.accumulatedFees()
|
|
28
|
+
]);
|
|
29
|
+
console.log("Base Mainnet Contract :", ESCROW_ADDRESS);
|
|
30
|
+
console.log("Circle USDC Token :", USDC_ADDRESS);
|
|
31
|
+
console.log("Settled Escrow Jobs :", (nextJobId - 1n).toString());
|
|
32
|
+
console.log("Accumulated Fees :", ethers.formatUnits(fees, 6), "USDC");
|
|
33
|
+
console.log("\nALL AGENTSLA v2.0.0 SDK CHECKS PASSED!");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
main().catch(console.error);
|