agentsla 2.0.0 → 2.0.1

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.
Files changed (3) hide show
  1. package/index.js +32 -4
  2. package/package.json +3 -3
  3. package/test.js +22 -26
package/index.js CHANGED
@@ -32,6 +32,7 @@ export class AgentSLA {
32
32
  * @param {string} [config.mcpUrl] - Streamable HTTP MCP URL (https://agentsla.io/mcp)
33
33
  * @param {string} [config.escrowAddress] - Base Mainnet Escrow Contract Address
34
34
  * @param {string} [config.usdcAddress] - Base Mainnet Circle USDC Address
35
+ * @param {string} [config.walletAddress] - Subscribed Base Mainnet wallet address (0x...)
35
36
  * @param {ethers.Signer|ethers.Provider} [config.signer] - Ethers v6 Signer or Provider
36
37
  */
37
38
  constructor(config = {}) {
@@ -39,6 +40,7 @@ export class AgentSLA {
39
40
  this.mcpUrl = config.mcpUrl || DEFAULT_MCP_URL;
40
41
  this.escrowAddress = config.escrowAddress || ESCROW_ADDRESS;
41
42
  this.usdcAddress = config.usdcAddress || USDC_ADDRESS;
43
+ this.walletAddress = config.walletAddress || null;
42
44
  this.signer = config.signer || null;
43
45
 
44
46
  if (this.signer) {
@@ -47,25 +49,48 @@ export class AgentSLA {
47
49
  }
48
50
  }
49
51
 
52
+ async _resolveWallet(explicitWallet) {
53
+ if (explicitWallet) return explicitWallet;
54
+ if (this.walletAddress) return this.walletAddress;
55
+ if (this.signer) {
56
+ if (this.signer.address) return this.signer.address;
57
+ if (typeof this.signer.getAddress === "function") {
58
+ try { return await this.signer.getAddress(); } catch (e) {}
59
+ }
60
+ }
61
+ return undefined;
62
+ }
63
+
50
64
  /**
51
65
  * Probe an API endpoint via the AgentSLA Oracle, generate a signed EIP-712 SLA proof,
52
66
  * and optionally resolve an active on-chain Base Mainnet USDC escrow job.
53
67
  * @param {string} targetApiUrl - Target API endpoint to probe
54
68
  * @param {number} [jobId=0] - Active Base Mainnet escrow jobId (0 for probe-only)
55
69
  * @param {Object} [targetApiPayload] - Optional POST payload for the target API
70
+ * @param {string} [walletAddress] - Optional subscribed Base Mainnet wallet address
56
71
  */
57
- async verify(targetApiUrl, jobId = 0, targetApiPayload = undefined) {
72
+ async verify(targetApiUrl, jobId = 0, targetApiPayload = undefined, walletAddress = undefined) {
58
73
  if (!targetApiUrl) throw new Error("targetApiUrl is required.");
59
74
 
75
+ const resolvedWallet = await this._resolveWallet(walletAddress);
76
+
60
77
  const response = await fetch(`${this.oracleUrl}/v1/verify`, {
61
78
  method: "POST",
62
79
  headers: { "Content-Type": "application/json" },
63
- body: JSON.stringify({ jobId, targetApiUrl, targetApiPayload })
80
+ body: JSON.stringify({
81
+ jobId,
82
+ targetApiUrl,
83
+ targetApiPayload,
84
+ walletAddress: resolvedWallet
85
+ })
64
86
  });
65
87
 
66
88
  const data = await response.json();
67
89
  if (!response.ok) {
68
- throw new Error(data.error || "Failed to verify endpoint via AgentSLA Oracle.");
90
+ const err = new Error(data.error || "Failed to verify endpoint via AgentSLA Oracle.");
91
+ err.status = response.status;
92
+ err.paymentDetails = data;
93
+ throw err;
69
94
  }
70
95
  return data;
71
96
  }
@@ -149,6 +174,9 @@ export class AgentSLA {
149
174
  * Call a tool directly on the hosted Streamable HTTP MCP server (https://agentsla.io/mcp).
150
175
  */
151
176
  async callMcpTool(name, args = {}) {
177
+ const resolvedWallet = await this._resolveWallet(args.walletAddress);
178
+ const finalArgs = resolvedWallet && !args.walletAddress ? { ...args, walletAddress: resolvedWallet } : args;
179
+
152
180
  const response = await fetch(this.mcpUrl, {
153
181
  method: "POST",
154
182
  headers: { "Content-Type": "application/json" },
@@ -156,7 +184,7 @@ export class AgentSLA {
156
184
  jsonrpc: "2.0",
157
185
  id: Date.now(),
158
186
  method: "tools/call",
159
- params: { name, arguments: args }
187
+ params: { name, arguments: finalArgs }
160
188
  })
161
189
  });
162
190
  return await response.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "name": "agentsla",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
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
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,4 +24,4 @@
24
24
  "dependencies": {
25
25
  "ethers": "^6.7.0"
26
26
  }
27
- }
27
+ }
package/test.js CHANGED
@@ -1,36 +1,32 @@
1
- import { ethers } from "ethers";
2
- import { AgentSLA, ESCROW_ADDRESS, USDC_ADDRESS } from "./index.js";
1
+ import { AgentSLA } from "./index.js";
3
2
 
4
3
  async function main() {
5
- const provider = new ethers.JsonRpcProvider("https://mainnet.base.org");
6
- const client = new AgentSLA({ signer: provider });
4
+ const unpaidClient = new AgentSLA();
7
5
 
8
- console.log("=== 1. Testing AgentSLA Directory Discovery ===");
9
- const dir = await client.discover("ai-models");
6
+ console.log("=== 1. Testing Free AgentSLA Directory Discovery ===");
7
+ const dir = await unpaidClient.discover("ai-models");
10
8
  console.log(`Discovered ${dir.count} AI Model APIs (Escrow Contract: ${dir.escrowContract})`);
11
9
 
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) + "...");
10
+ console.log("\n=== 2. Testing Unpaid Call to /v1/verify (Verifying 402 Paywall) ===");
11
+ try {
12
+ await unpaidClient.verify("https://mainnet.base.org");
13
+ } catch (err) {
14
+ console.log(`Blocked with HTTP ${err.status}: ${err.message}`);
15
+ }
19
16
 
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, " "));
17
+ console.log("\n=== 3. Testing Authenticated Wallet Call to /v1/verify ===");
18
+ const paidClient = new AgentSLA({
19
+ walletAddress: "0x9A0d2dD2402991eC8095fE2Be0d96A59d9DCF13C"
20
+ });
21
+ const verification = await paidClient.verify("https://mainnet.base.org");
22
+ console.log("Latency (ms) :", verification.latencyMs);
23
+ console.log("SLA Met :", verification.slaMet);
24
+ console.log("EIP-712 Signature:", verification.eip712Signature);
25
+ console.log("Oracle Signer :", verification.oracleSigner);
23
26
 
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!");
27
+ console.log("\n=== 4. Testing Hosted Streamable HTTP MCP Server (https://agentsla.io/mcp) ===");
28
+ const mcpRes = await paidClient.callMcpTool("get_usdc_escrow_contract", {});
29
+ console.log("MCP Tool Output :", mcpRes.result.content[0].text);
34
30
  }
35
31
 
36
32
  main().catch(console.error);