@valiron/sdk 0.1.1 → 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 +140 -321
- package/dist/clients.d.ts +25 -72
- package/dist/clients.d.ts.map +1 -1
- package/dist/clients.js +65 -121
- package/dist/clients.js.map +1 -1
- package/dist/index.d.ts +52 -83
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -85
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +105 -73
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -2
- package/dist/types.js.map +1 -1
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @valiron/sdk
|
|
2
2
|
|
|
3
|
-
Official TypeScript SDK for **Valiron**
|
|
3
|
+
Official TypeScript SDK for **Valiron** — Trust Infrastructure for AI Agent Systems
|
|
4
4
|
|
|
5
5
|
Valiron verifies AI agent trustworthiness using on-chain reputation (ERC-8004) and behavioral analysis. This SDK provides routing decisions based on agent trust scores, enabling you to protect infrastructure while maintaining service availability for verified agents.
|
|
6
6
|
|
|
@@ -16,213 +16,157 @@ pnpm add @valiron/sdk
|
|
|
16
16
|
|
|
17
17
|
## Getting Started
|
|
18
18
|
|
|
19
|
-
1. **Initialize the SDK:**
|
|
20
|
-
|
|
21
19
|
```typescript
|
|
22
20
|
import { ValironSDK } from '@valiron/sdk';
|
|
23
21
|
|
|
24
|
-
// Simple initialization (uses default production endpoint)
|
|
25
22
|
const valiron = new ValironSDK();
|
|
26
23
|
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
debug: false // optional
|
|
32
|
-
});
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
> **Note:** API key authentication is not yet enforced. The `apiKey` field is
|
|
36
|
-
> reserved for future use when authentication is implemented.
|
|
37
|
-
|
|
38
|
-
2. **Check agent trust before processing requests:**
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
const decision = await valiron.checkAgent('417');
|
|
42
|
-
|
|
43
|
-
if (decision.route === 'prod') {
|
|
44
|
-
return handleRequest();
|
|
45
|
-
} else {
|
|
46
|
-
return denyRequest();
|
|
24
|
+
// Quick routing check
|
|
25
|
+
const route = await valiron.checkAgent('25459');
|
|
26
|
+
if (route === 'prod') {
|
|
27
|
+
// Allow full production access
|
|
47
28
|
}
|
|
29
|
+
|
|
30
|
+
// Or get the full trust profile
|
|
31
|
+
const profile = await valiron.getAgentProfile('25459');
|
|
32
|
+
console.log(profile.routing.finalRoute); // 'prod'
|
|
33
|
+
console.log(profile.localReputation?.tier); // 'AAA'
|
|
34
|
+
console.log(profile.onchainReputation.averageScore); // 92.5
|
|
48
35
|
```
|
|
49
36
|
|
|
37
|
+
> **Note:** API key authentication is not yet enforced. The `apiKey` config
|
|
38
|
+
> field is reserved for future use.
|
|
39
|
+
|
|
50
40
|
## Core Concepts
|
|
51
41
|
|
|
52
42
|
### Route Decisions
|
|
53
43
|
|
|
54
44
|
The SDK returns one of four routing decisions:
|
|
55
45
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
| Route | Meaning | Trust Tiers |
|
|
47
|
+
|-------|---------|-------------|
|
|
48
|
+
| `prod` | Full access | AAA – BAA |
|
|
49
|
+
| `prod_throttled` | Rate-limited access | BA – B |
|
|
50
|
+
| `sandbox` | Agent under evaluation | Temporary |
|
|
51
|
+
| `sandbox_only` | Access denied | CAA – C |
|
|
60
52
|
|
|
61
53
|
### Trust Evaluation
|
|
62
54
|
|
|
63
55
|
Valiron evaluates agents using:
|
|
64
56
|
|
|
65
|
-
1. **On-chain Reputation**
|
|
66
|
-
2. **Behavioral Analysis**
|
|
67
|
-
3. **Credit Rating**
|
|
57
|
+
1. **On-chain Reputation** — ERC-8004 feedback submitted by other organizations
|
|
58
|
+
2. **Behavioral Analysis** — Sandbox evaluation of rate-limit compliance, error rates, and request patterns
|
|
59
|
+
3. **Credit Rating** — Moody's-style scoring system (AAA to C)
|
|
68
60
|
|
|
69
61
|
### Architecture
|
|
70
62
|
|
|
71
63
|
```
|
|
72
|
-
Request → SDK.checkAgent() → Valiron API → Route Decision →
|
|
64
|
+
Request → SDK.checkAgent() → Valiron Operator API → Route Decision → Your App
|
|
73
65
|
```
|
|
74
66
|
|
|
75
|
-
The SDK queries Valiron's trust infrastructure, which evaluates on-chain reputation and behavioral metrics to return a routing decision. Your application implements access control based on this decision.
|
|
76
|
-
|
|
77
67
|
## API Reference
|
|
78
68
|
|
|
79
69
|
### Constructor
|
|
80
70
|
|
|
81
71
|
```typescript
|
|
82
|
-
new ValironSDK(config
|
|
72
|
+
new ValironSDK(config?: ValironConfig)
|
|
83
73
|
```
|
|
84
74
|
|
|
85
|
-
|
|
75
|
+
| Option | Type | Default | Description |
|
|
76
|
+
|--------|------|---------|-------------|
|
|
77
|
+
| `apiKey` | `string` | — | API key (reserved for future use) |
|
|
78
|
+
| `endpoint` | `string` | `https://valiron-edge-proxy.onrender.com` | API endpoint URL |
|
|
79
|
+
| `timeout` | `number` | `5000` | Request timeout (ms) |
|
|
80
|
+
| `debug` | `boolean` | `false` | Enable debug logging |
|
|
86
81
|
|
|
87
|
-
|
|
88
|
-
|--------|------|----------|---------|-------------|
|
|
89
|
-
| `apiKey` | string | No | - | API key (reserved for future use) |
|
|
90
|
-
| `endpoint` | string | No | `https://valiron-edge-proxy.onrender.com` | API endpoint URL |
|
|
91
|
-
| `timeout` | number | No | `5000` | Request timeout (ms) |
|
|
92
|
-
| `debug` | boolean | No | `false` | Enable debug logging |
|
|
93
|
-
|
|
94
|
-
### Methods
|
|
95
|
-
|
|
96
|
-
#### `checkAgent(agentId: string): Promise<RoutingResponse>`
|
|
82
|
+
---
|
|
97
83
|
|
|
98
|
-
|
|
84
|
+
### `checkAgent(agentId): Promise<RouteDecision>`
|
|
99
85
|
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
{
|
|
103
|
-
route: 'prod' | 'prod_throttled' | 'sandbox' | 'sandbox_only',
|
|
104
|
-
reason: string,
|
|
105
|
-
explanation: string,
|
|
106
|
-
onChainData?: {
|
|
107
|
-
feedbackCount: number,
|
|
108
|
-
averageScore: number,
|
|
109
|
-
agentId: string
|
|
110
|
-
},
|
|
111
|
-
localReputation?: {
|
|
112
|
-
score: number,
|
|
113
|
-
tier: MoodysRating,
|
|
114
|
-
riskLevel: 'GREEN' | 'YELLOW' | 'RED',
|
|
115
|
-
graduated: boolean
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
```
|
|
86
|
+
Quick routing check — returns just the route decision string.
|
|
119
87
|
|
|
120
|
-
**Example:**
|
|
121
88
|
```typescript
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
console.log(decision.localReputation?.tier); // 'AAA'
|
|
89
|
+
const route = await valiron.checkAgent('25459');
|
|
90
|
+
// route: 'prod' | 'prod_throttled' | 'sandbox' | 'sandbox_only'
|
|
125
91
|
```
|
|
126
92
|
|
|
127
93
|
---
|
|
128
94
|
|
|
129
|
-
|
|
95
|
+
### `getAgentProfile(agentId): Promise<AgentProfile>`
|
|
130
96
|
|
|
131
|
-
|
|
97
|
+
Full trust profile combining on-chain identity, reputation, behavioral data, and routing.
|
|
132
98
|
|
|
133
|
-
**Example:**
|
|
134
99
|
```typescript
|
|
135
|
-
const
|
|
100
|
+
const profile = await valiron.getAgentProfile('25459');
|
|
136
101
|
```
|
|
137
102
|
|
|
138
|
-
|
|
103
|
+
**Response shape:**
|
|
139
104
|
|
|
140
|
-
#### `getAgentProfile(agentId: string): Promise<AgentProfile>`
|
|
141
|
-
|
|
142
|
-
Get complete trust profile for an agent.
|
|
143
|
-
|
|
144
|
-
**Returns:**
|
|
145
105
|
```typescript
|
|
146
106
|
{
|
|
147
107
|
agentId: string,
|
|
148
108
|
identity: {
|
|
109
|
+
agentId: string,
|
|
149
110
|
wallet: string,
|
|
111
|
+
tokenUri: string,
|
|
150
112
|
name: string,
|
|
151
|
-
description: string,
|
|
152
113
|
image: string,
|
|
153
|
-
|
|
114
|
+
description: string,
|
|
115
|
+
endpoints: Record<string, string>,
|
|
116
|
+
trustModels: string[],
|
|
154
117
|
},
|
|
155
118
|
onchainReputation: {
|
|
156
|
-
count:
|
|
119
|
+
count: string,
|
|
157
120
|
averageScore: number,
|
|
158
|
-
feedbackEntries: FeedbackEntry[]
|
|
121
|
+
feedbackEntries: FeedbackEntry[],
|
|
122
|
+
totalFeedback: number,
|
|
159
123
|
},
|
|
160
124
|
localReputation: {
|
|
125
|
+
exists: boolean,
|
|
161
126
|
score: number,
|
|
162
127
|
tier: MoodysRating,
|
|
163
128
|
riskLevel: 'GREEN' | 'YELLOW' | 'RED',
|
|
164
|
-
|
|
165
|
-
|
|
129
|
+
graduated: boolean,
|
|
130
|
+
metrics: BehavioralMetrics,
|
|
131
|
+
} | null,
|
|
166
132
|
routing: {
|
|
167
133
|
finalRoute: RouteDecision,
|
|
168
|
-
decision: string,
|
|
169
|
-
reasons: string[]
|
|
170
|
-
|
|
134
|
+
decision: string, // human-readable explanation
|
|
135
|
+
reasons: string[], // array of reasoning steps
|
|
136
|
+
signals: {
|
|
137
|
+
onchain: { feedbackCount, averageScore, threshold },
|
|
138
|
+
local: { exists, graduated, tier, riskLevel, score },
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
timestamp: string,
|
|
171
142
|
}
|
|
172
143
|
```
|
|
173
144
|
|
|
174
|
-
**Example:**
|
|
175
|
-
```typescript
|
|
176
|
-
const profile = await valiron.getAgentProfile('417');
|
|
177
|
-
console.log(`Score: ${profile.localReputation.score}/100`);
|
|
178
|
-
console.log(`Tier: ${profile.localReputation.tier}`);
|
|
179
|
-
console.log(`On-chain feedback: ${profile.onchainReputation.count} entries`);
|
|
180
|
-
```
|
|
181
|
-
|
|
182
145
|
---
|
|
183
146
|
|
|
184
|
-
|
|
147
|
+
### `getWalletProfile(wallet): Promise<WalletProfile>`
|
|
185
148
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
**Parameters:**
|
|
189
|
-
```typescript
|
|
190
|
-
{
|
|
191
|
-
agentId: string,
|
|
192
|
-
score: number, // 0-100
|
|
193
|
-
outcome: 'success' | 'failure',
|
|
194
|
-
metadata?: { // Custom metadata
|
|
195
|
-
[key: string]: any
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
```
|
|
149
|
+
Reverse-lookup a wallet address to get its trust profile.
|
|
199
150
|
|
|
200
|
-
**Example:**
|
|
201
151
|
```typescript
|
|
202
|
-
await valiron.
|
|
203
|
-
|
|
204
|
-
score: 95,
|
|
205
|
-
outcome: 'success',
|
|
206
|
-
metadata: {
|
|
207
|
-
taskType: 'data_processing',
|
|
208
|
-
duration: 2340,
|
|
209
|
-
recordsProcessed: 10000
|
|
210
|
-
}
|
|
211
|
-
});
|
|
152
|
+
const profile = await valiron.getWalletProfile('0x52ce…');
|
|
153
|
+
console.log(profile.routing.finalRoute);
|
|
212
154
|
```
|
|
213
155
|
|
|
214
156
|
---
|
|
215
157
|
|
|
216
|
-
|
|
158
|
+
### `triggerSandboxTest(agentId): Promise<SandboxResult>`
|
|
217
159
|
|
|
218
|
-
|
|
160
|
+
Run real sandbox tests against an agent and compute a Valiron score.
|
|
219
161
|
|
|
220
|
-
**Example:**
|
|
221
162
|
```typescript
|
|
222
|
-
await valiron.triggerSandboxTest(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
163
|
+
const result = await valiron.triggerSandboxTest('25459');
|
|
164
|
+
console.log(result.valironScore); // 95
|
|
165
|
+
console.log(result.tier); // 'AAA'
|
|
166
|
+
console.log(result.riskLevel); // 'GREEN'
|
|
167
|
+
console.log(result.mode); // 'endpoint-probe' | 'sandbox-relay'
|
|
168
|
+
console.log(result.testSummary);
|
|
169
|
+
// { totalRequests, successCount, rateLimitCount, errorCount, avgLatencyMs }
|
|
226
170
|
```
|
|
227
171
|
|
|
228
172
|
---
|
|
@@ -232,216 +176,77 @@ await valiron.triggerSandboxTest({
|
|
|
232
176
|
### Express.js Middleware
|
|
233
177
|
|
|
234
178
|
```typescript
|
|
235
|
-
import { ValironSDK } from '@valiron/sdk';
|
|
236
179
|
import express from 'express';
|
|
180
|
+
import { ValironSDK } from '@valiron/sdk';
|
|
237
181
|
|
|
238
182
|
const app = express();
|
|
239
|
-
const valiron = new ValironSDK(
|
|
240
|
-
|
|
241
|
-
async
|
|
242
|
-
const agentId = req.headers['x-agent-id'];
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
183
|
+
const valiron = new ValironSDK();
|
|
184
|
+
|
|
185
|
+
app.use('/api/protected/*', async (req, res, next) => {
|
|
186
|
+
const agentId = req.headers['x-agent-id'] as string;
|
|
187
|
+
if (!agentId) return res.status(400).json({ error: 'Missing x-agent-id' });
|
|
188
|
+
|
|
189
|
+
const profile = await valiron.getAgentProfile(agentId);
|
|
190
|
+
const { finalRoute } = profile.routing;
|
|
191
|
+
|
|
192
|
+
if (finalRoute === 'prod' || finalRoute === 'prod_throttled') {
|
|
193
|
+
(req as any).valironProfile = profile;
|
|
247
194
|
return next();
|
|
248
195
|
}
|
|
249
|
-
|
|
196
|
+
|
|
250
197
|
return res.status(403).json({
|
|
251
|
-
error: 'Access denied',
|
|
252
|
-
|
|
198
|
+
error: finalRoute === 'sandbox' ? 'Agent under evaluation' : 'Access denied',
|
|
199
|
+
message: profile.routing.decision,
|
|
253
200
|
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
app.use('/api/protected/*', valironMiddleware);
|
|
201
|
+
});
|
|
257
202
|
```
|
|
258
203
|
|
|
259
204
|
### Next.js Middleware
|
|
260
205
|
|
|
261
206
|
```typescript
|
|
262
|
-
// middleware.ts
|
|
263
207
|
import { NextRequest, NextResponse } from 'next/server';
|
|
264
208
|
import { ValironSDK } from '@valiron/sdk';
|
|
265
209
|
|
|
266
|
-
const valiron = new ValironSDK(
|
|
210
|
+
const valiron = new ValironSDK();
|
|
267
211
|
|
|
268
212
|
export async function middleware(request: NextRequest) {
|
|
269
213
|
const agentId = request.headers.get('x-agent-id');
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (decision.route === 'prod' || decision.route === 'prod_throttled') {
|
|
273
|
-
return NextResponse.next();
|
|
214
|
+
if (!agentId) {
|
|
215
|
+
return NextResponse.json({ error: 'Missing x-agent-id' }, { status: 400 });
|
|
274
216
|
}
|
|
275
|
-
|
|
276
|
-
return NextResponse.json(
|
|
277
|
-
{ error: 'Access denied' },
|
|
278
|
-
{ status: 403 }
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export const config = {
|
|
283
|
-
matcher: '/api/protected/:path*'
|
|
284
|
-
};
|
|
285
|
-
```
|
|
286
217
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
import { ValironSDK } from '@valiron/sdk';
|
|
218
|
+
const route = await valiron.checkAgent(agentId);
|
|
291
219
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
async function handleRequest(agentId: string) {
|
|
295
|
-
const decision = await valiron.checkAgent(agentId);
|
|
296
|
-
|
|
297
|
-
switch (decision.route) {
|
|
298
|
-
case 'prod':
|
|
299
|
-
return processRequest({ rateLimit: null });
|
|
300
|
-
|
|
301
|
-
case 'prod_throttled':
|
|
302
|
-
return processRequest({ rateLimit: '100/hour' });
|
|
303
|
-
|
|
304
|
-
case 'sandbox':
|
|
305
|
-
return { error: 'Agent under evaluation', retryAfter: 30 };
|
|
306
|
-
|
|
307
|
-
case 'sandbox_only':
|
|
308
|
-
return { error: 'Access denied', reason: decision.reason };
|
|
220
|
+
if (route === 'prod' || route === 'prod_throttled') {
|
|
221
|
+
return NextResponse.next();
|
|
309
222
|
}
|
|
310
|
-
}
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### Integration with x402 Payment APIs
|
|
314
|
-
|
|
315
|
-
Valiron integrates with **x402** payment-gated APIs (e.g., [Orthogonal](https://www.orth.sh/)). Verify trust before processing payments to prevent malicious agents from accessing paid endpoints.
|
|
316
|
-
|
|
317
|
-
#### Server-Side: Validate Trust + Payment
|
|
318
|
-
|
|
319
|
-
```typescript
|
|
320
|
-
import { ValironSDK } from '@valiron/sdk';
|
|
321
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
322
|
-
import { getAddress } from 'viem';
|
|
323
|
-
import { exact } from 'x402/schemes'; // Real x402 package
|
|
324
|
-
|
|
325
|
-
const valiron = new ValironSDK();
|
|
326
223
|
|
|
327
|
-
|
|
328
|
-
const agentId = req.headers['x-agent-id'];
|
|
329
|
-
const paymentHeader = req.headers['x-payment'];
|
|
330
|
-
|
|
331
|
-
// Step 1: Verify trust before payment
|
|
332
|
-
const { route, localReputation } = await valiron.checkAgent(agentId);
|
|
333
|
-
|
|
334
|
-
if (route === 'sandbox_only') {
|
|
335
|
-
return res.status(403).json({
|
|
336
|
-
error: 'Agent banned',
|
|
337
|
-
reason: 'Failed behavioral trust requirements'
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (route === 'sandbox') {
|
|
342
|
-
return res.status(403).json({
|
|
343
|
-
error: 'Agent under evaluation',
|
|
344
|
-
retryAfter: 30
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// Step 2: Verify payment (trusted agents only)
|
|
349
|
-
if (!paymentHeader) {
|
|
350
|
-
// Dynamic pricing based on trust tier
|
|
351
|
-
const pricing = {
|
|
352
|
-
'AAA': 5, 'AA': 5, 'A': 8, 'BAA': 10,
|
|
353
|
-
'BA': 25, 'B': 50, 'CAA': 100, 'CA': 100, 'C': 100
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
return res.status(402).json({
|
|
357
|
-
error: 'Payment Required',
|
|
358
|
-
accepts: [{
|
|
359
|
-
scheme: 'exact',
|
|
360
|
-
network: 'base',
|
|
361
|
-
maxAmountRequired: pricing[localReputation?.tier || 'B'],
|
|
362
|
-
asset: '0x...',
|
|
363
|
-
payTo: '0x...',
|
|
364
|
-
// ... x402 payment requirements
|
|
365
|
-
}]
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// Verify payment (use x402 library)
|
|
370
|
-
const valid = await exact.evm.verifyPayment(paymentHeader);
|
|
371
|
-
if (!valid) {
|
|
372
|
-
return res.status(402).json({ error: 'Invalid payment' });
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Step 3: Apply trust-based rate limits
|
|
376
|
-
req.rateLimit = route === 'prod' ? 1000 : 100; // requests/hour
|
|
377
|
-
next();
|
|
224
|
+
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
|
|
378
225
|
}
|
|
379
226
|
|
|
380
|
-
|
|
227
|
+
export const config = { matcher: '/api/protected/:path*' };
|
|
381
228
|
```
|
|
382
229
|
|
|
383
|
-
|
|
230
|
+
### x402 Payment Integration
|
|
384
231
|
|
|
385
|
-
|
|
386
|
-
import { ValironSDK } from '@valiron/sdk';
|
|
387
|
-
import { exact } from 'x402/schemes';
|
|
388
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
232
|
+
Valiron integrates with x402 payment-gated APIs (e.g., [Orthogonal](https://www.orth.sh/)). Verify trust before processing payments to prevent malicious agents from accessing paid endpoints.
|
|
389
233
|
|
|
390
|
-
|
|
391
|
-
const
|
|
234
|
+
```typescript
|
|
235
|
+
const profile = await valiron.getAgentProfile(agentId);
|
|
392
236
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const { route } = await valiron.checkAgent(agentId);
|
|
396
|
-
if (route === 'sandbox_only') {
|
|
397
|
-
throw new Error('Agent access denied');
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// Get payment requirements
|
|
401
|
-
const res = await fetch(url);
|
|
402
|
-
const { accepts } = await res.json();
|
|
403
|
-
|
|
404
|
-
// Create x402 payment header
|
|
405
|
-
const paymentHeader = await exact.evm.createPaymentHeader(
|
|
406
|
-
account,
|
|
407
|
-
1,
|
|
408
|
-
accepts[0]
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
// Retry with payment
|
|
412
|
-
const data = await fetch(url, {
|
|
413
|
-
headers: { 'X-PAYMENT': paymentHeader }
|
|
414
|
-
}).then(r => r.json());
|
|
415
|
-
|
|
416
|
-
return data;
|
|
237
|
+
if (profile.routing.finalRoute === 'sandbox_only') {
|
|
238
|
+
return res.status(403).json({ error: 'Agent banned' });
|
|
417
239
|
}
|
|
418
|
-
```
|
|
419
240
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
- Mitigate DDoS attacks from paid malicious requests
|
|
241
|
+
// Trust-based pricing — better agents pay less
|
|
242
|
+
const pricing = { AAA: 5, AA: 5, A: 8, BAA: 10, BA: 25, B: 50 };
|
|
243
|
+
const tier = profile.localReputation?.tier || 'B';
|
|
244
|
+
const price = pricing[tier] || 50;
|
|
425
245
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
See [examples/x402-integration.ts](examples/x402-integration.ts) for complete implementation.
|
|
431
|
-
|
|
432
|
-
## TypeScript Types
|
|
433
|
-
|
|
434
|
-
The SDK is fully typed. Import types as needed:
|
|
435
|
-
|
|
436
|
-
```typescript
|
|
437
|
-
import {
|
|
438
|
-
ValironSDK,
|
|
439
|
-
RouteDecision,
|
|
440
|
-
MoodysRating,
|
|
441
|
-
AgentProfile,
|
|
442
|
-
RoutingResponse,
|
|
443
|
-
ValironError
|
|
444
|
-
} from '@valiron/sdk';
|
|
246
|
+
// Return x402 payment challenge
|
|
247
|
+
return res.status(402).json({
|
|
248
|
+
accepts: [{ scheme: 'exact', maxAmountRequired: price, payTo: '0x…' }],
|
|
249
|
+
});
|
|
445
250
|
```
|
|
446
251
|
|
|
447
252
|
## Moody's Credit Rating Tiers
|
|
@@ -458,29 +263,43 @@ import {
|
|
|
458
263
|
| CA | 20-34 | Extremely speculative | Sandbox only |
|
|
459
264
|
| C | 0-19 | Default risk | Sandbox only |
|
|
460
265
|
|
|
266
|
+
## TypeScript Types
|
|
267
|
+
|
|
268
|
+
The SDK is fully typed. Import types as needed:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import {
|
|
272
|
+
ValironSDK,
|
|
273
|
+
RouteDecision,
|
|
274
|
+
MoodysRating,
|
|
275
|
+
RiskLevel,
|
|
276
|
+
AgentProfile,
|
|
277
|
+
WalletProfile,
|
|
278
|
+
SandboxResult,
|
|
279
|
+
AgentIdentity,
|
|
280
|
+
OnchainReputation,
|
|
281
|
+
LocalReputation,
|
|
282
|
+
RoutingExplanation,
|
|
283
|
+
BehavioralMetrics,
|
|
284
|
+
FeedbackEntry,
|
|
285
|
+
ValironError,
|
|
286
|
+
ValironClient,
|
|
287
|
+
} from '@valiron/sdk';
|
|
288
|
+
```
|
|
289
|
+
|
|
461
290
|
## Error Handling
|
|
462
291
|
|
|
463
292
|
```typescript
|
|
464
293
|
import { ValironError } from '@valiron/sdk';
|
|
465
294
|
|
|
466
295
|
try {
|
|
467
|
-
const
|
|
296
|
+
const profile = await valiron.getAgentProfile('123');
|
|
468
297
|
} catch (error) {
|
|
469
298
|
if (error instanceof ValironError) {
|
|
470
|
-
console.error('Code:', error.code);
|
|
471
|
-
console.error('Message:', error.message);
|
|
472
|
-
console.error('Status:', error.statusCode);
|
|
473
|
-
|
|
474
299
|
switch (error.code) {
|
|
475
|
-
case 'TIMEOUT_ERROR':
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
case 'NETWORK_ERROR':
|
|
479
|
-
// Handle network issues
|
|
480
|
-
break;
|
|
481
|
-
case 'API_ERROR':
|
|
482
|
-
// Handle API errors
|
|
483
|
-
break;
|
|
300
|
+
case 'TIMEOUT_ERROR': // Request timed out
|
|
301
|
+
case 'NETWORK_ERROR': // Could not reach API
|
|
302
|
+
case 'API_ERROR': // Non-2xx response (check error.statusCode)
|
|
484
303
|
}
|
|
485
304
|
}
|
|
486
305
|
}
|
|
@@ -492,7 +311,7 @@ try {
|
|
|
492
311
|
|
|
493
312
|
## Support
|
|
494
313
|
|
|
495
|
-
- **Email**: founders@valiron.
|
|
314
|
+
- **Email**: founders@valiron.co
|
|
496
315
|
|
|
497
316
|
## License
|
|
498
317
|
|