@valiron/sdk 1.0.0 → 1.0.2
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 +8 -1
- package/dist/clients.d.ts +16 -1
- package/dist/clients.js +51 -6
- package/dist/index.d.ts +21 -1
- package/dist/index.js +24 -0
- package/dist/middleware.d.ts +50 -12
- package/dist/middleware.js +485 -20
- package/dist/operatorSdk.d.ts +24 -3
- package/dist/operatorSdk.js +153 -5
- package/dist/telemetry.js +1 -1
- package/dist/types.d.ts +23 -2
- package/docs/API-REFERENCE.md +5 -1
- package/docs/ERRORS.md +1 -1
- package/docs/QUICKSTART.md +31 -6
- package/docs/SANDBOX.md +51 -1
- package/docs/SDK-REFERENCE.md +101 -14
- package/docs/TRUST-MODEL.md +36 -4
- package/docs/llms.txt +10 -1
- package/package.json +1 -1
package/docs/SDK-REFERENCE.md
CHANGED
|
@@ -25,7 +25,7 @@ const valiron = new ValironSDK(config?: ValironConfig);
|
|
|
25
25
|
| `apiKey` | string | — | API key (optional for read operations) |
|
|
26
26
|
| `endpoint` | string | `https://valiron-edge-proxy.onrender.com` | API base URL |
|
|
27
27
|
| `chain` | SupportedChain | `"ethereum"` | Default blockchain network |
|
|
28
|
-
| `timeout` | number |
|
|
28
|
+
| `timeout` | number | method-aware | Request timeout in milliseconds. Defaults are 10s generally, 15s for `gate()`/`proxy()`, and 30s for sandbox triggers. If set, this value overrides all method-aware defaults. |
|
|
29
29
|
| `debug` | boolean | `false` | Enable debug logging |
|
|
30
30
|
| `telemetry` | TelemetryConfig | — | Optional telemetry configuration |
|
|
31
31
|
|
|
@@ -230,6 +230,41 @@ console.log(result.riskLevel); // "GREEN"
|
|
|
230
230
|
console.log(result.meetsThreshold); // true
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
+
> **Auto-sandbox:** The middleware (`createValironGate`, `valironFastifyPlugin`, `createValironNextMiddleware`, `valironGateCheck`) automatically triggers `triggerSandboxTest()` in the background for new on-chain agents (those with `totalFeedback === 0`). The agent receives a 403 with `{ error: "Agent pending evaluation", retryAfterMs: 30000 }` while evaluation runs. No manual trigger is needed.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
### triggerKeyAgentSandbox(agentAddress)
|
|
238
|
+
|
|
239
|
+
Run sandbox tests against a key-based (Web2) agent and compute a trust evaluation. Key agents don't have on-chain endpoints, so this uses the `sandbox_relay` mode internally.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const result = await valiron.triggerKeyAgentSandbox(agentAddress: string): Promise<KeyAgentSandboxResult>;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Returns**: `KeyAgentSandboxResult`
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface KeyAgentSandboxResult {
|
|
249
|
+
ok: boolean;
|
|
250
|
+
agentAddress: string;
|
|
251
|
+
valironScore: number;
|
|
252
|
+
tier: MoodysRating;
|
|
253
|
+
riskLevel: "GREEN" | "YELLOW" | "RED";
|
|
254
|
+
message: string;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Example**:
|
|
259
|
+
```typescript
|
|
260
|
+
const result = await valiron.triggerKeyAgentSandbox("0x1234...abcd");
|
|
261
|
+
console.log(result.tier); // "A"
|
|
262
|
+
console.log(result.riskLevel); // "GREEN"
|
|
263
|
+
console.log(result.valironScore); // 85
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
> **Auto-sandbox:** The middleware automatically triggers `triggerKeyAgentSandbox()` in the background for new key agents (those with `verified === true` but `score === null`). The agent receives a 403 with `{ error: "Agent pending evaluation", retryAfterMs: 30000 }` while evaluation runs.
|
|
267
|
+
|
|
233
268
|
---
|
|
234
269
|
|
|
235
270
|
### gate(agentId, options?)
|
|
@@ -315,22 +350,31 @@ console.log(snapshot.interactionCount); // 15
|
|
|
315
350
|
|
|
316
351
|
Express-compatible middleware factory. Automatically gates requests based on agent trust.
|
|
317
352
|
|
|
353
|
+
Uses the public `getAgentProfile()` endpoint under the hood (not the protected `gate()` endpoint), so it works from any server context — no agent challenge-response auth required.
|
|
354
|
+
|
|
355
|
+
**Express 4 safe**: The returned middleware wraps the async handler with `Promise.resolve(handler(...)).catch(next)` so async rejections are properly forwarded to Express's error handler. This prevents race conditions when chained with other async middleware (e.g. x402's `paymentMiddleware`).
|
|
356
|
+
|
|
318
357
|
```typescript
|
|
319
358
|
import { ValironSDK, createValironGate } from "@valiron/sdk";
|
|
320
359
|
|
|
321
360
|
const gate = createValironGate(config: {
|
|
322
361
|
sdk: ValironSDK;
|
|
323
|
-
|
|
324
|
-
|
|
362
|
+
minScore?: number; // default: 65
|
|
363
|
+
trustSignals?: Array<"8004" | "sandbox" | "world" | "icebreaker">;
|
|
364
|
+
cacheTtlMs?: number; // default: 30000 (30s client-side cache)
|
|
365
|
+
extractAgentId?: (req: Request) => string | null;
|
|
366
|
+
extractAgentAddress?: (req: Request) => string | null;
|
|
325
367
|
onAllow?: (req: Request, result: GateResult) => void;
|
|
326
368
|
onDeny?: (req: Request, res: Response, result: GateResult) => void;
|
|
327
369
|
});
|
|
328
370
|
```
|
|
329
371
|
|
|
330
372
|
**Default behavior**:
|
|
331
|
-
- Extracts agent ID from `x-agent-id`
|
|
373
|
+
- Extracts agent ID from `x-agent-id` header (on-chain) or `x-agent-address` header (key-based)
|
|
374
|
+
- Returns 401 if no agent identity is found (with link to identity skill)
|
|
332
375
|
- Returns 403 if agent is denied
|
|
333
|
-
- Returns
|
|
376
|
+
- Returns 503 if the trust gate is unreachable (fail-closed)
|
|
377
|
+
- Caches profiles in memory for 30s to survive x402 retry flows
|
|
334
378
|
|
|
335
379
|
**Example**:
|
|
336
380
|
```typescript
|
|
@@ -339,10 +383,12 @@ const valiron = new ValironSDK({ chain: "monad" });
|
|
|
339
383
|
// Basic gate
|
|
340
384
|
app.use("/api/paid", createValironGate({ sdk: valiron }));
|
|
341
385
|
|
|
342
|
-
// Custom
|
|
386
|
+
// Custom threshold + longer cache
|
|
343
387
|
app.use("/api/premium", createValironGate({
|
|
344
388
|
sdk: valiron,
|
|
345
|
-
|
|
389
|
+
minScore: 85,
|
|
390
|
+
trustSignals: ["8004", "sandbox"],
|
|
391
|
+
cacheTtlMs: 60_000, // 60s
|
|
346
392
|
}));
|
|
347
393
|
|
|
348
394
|
// Custom agent ID extraction
|
|
@@ -432,6 +478,22 @@ For Web2 agents that don't have on-chain identities, Valiron supports key-based
|
|
|
432
478
|
|
|
433
479
|
The SDK auto-detects key-based agents from the `x-agent-address` header. No configuration needed.
|
|
434
480
|
|
|
481
|
+
### Sandbox Evaluation for Key Agents
|
|
482
|
+
|
|
483
|
+
New key agents (verified but not yet scored) are automatically evaluated when they first hit a gated endpoint. The middleware triggers `triggerKeyAgentSandbox()` in the background and returns 403 with `retryAfterMs: 30000`. After evaluation completes, the agent receives a trust score and can access endpoints normally.
|
|
484
|
+
|
|
485
|
+
You can also trigger evaluation manually:
|
|
486
|
+
|
|
487
|
+
```typescript
|
|
488
|
+
const result = await valiron.triggerKeyAgentSandbox("0x1234...abcd");
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Or via HTTP:
|
|
492
|
+
|
|
493
|
+
```bash
|
|
494
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox-key/0x1234...abcd
|
|
495
|
+
```
|
|
496
|
+
|
|
435
497
|
### KeyAgentProfile
|
|
436
498
|
|
|
437
499
|
| Field | Type | Description |
|
|
@@ -495,7 +557,7 @@ const profile = await valiron.getWorldIdProfile(agentId: string, options?: {
|
|
|
495
557
|
|
|
496
558
|
## Telemetry
|
|
497
559
|
|
|
498
|
-
The SDK
|
|
560
|
+
The SDK collects opt-out usage telemetry to improve reliability. Events include SDK version, runtime, environment, method names, chain labels, latency, HTTP status/error buckets, route decisions, and coarse score/reputation buckets. Raw agent IDs, wallet addresses, API keys, and exact scores are not sent in SDK telemetry. Operator paywall usage logs are separate customer analytics and are authenticated with the operator API key.
|
|
499
561
|
|
|
500
562
|
### TelemetryConfig
|
|
501
563
|
|
|
@@ -503,7 +565,7 @@ The SDK optionally collects anonymous usage metrics (gate calls, latency, error
|
|
|
503
565
|
|-------|------|---------|-------------|
|
|
504
566
|
| `enabled` | boolean | `true` | Enable/disable telemetry |
|
|
505
567
|
| `sampleRate` | number | `1.0` | Fraction of events to sample (0–1) |
|
|
506
|
-
| `
|
|
568
|
+
| `onEvent` | function | — | Custom event handler |
|
|
507
569
|
|
|
508
570
|
**Example**:
|
|
509
571
|
```typescript
|
|
@@ -517,7 +579,7 @@ const valiron = new ValironSDK({
|
|
|
517
579
|
const valiron = new ValironSDK({
|
|
518
580
|
telemetry: {
|
|
519
581
|
sampleRate: 0.1, // Sample 10% of events
|
|
520
|
-
|
|
582
|
+
onEvent: (event) => { // Custom handler
|
|
521
583
|
myAnalytics.track(event);
|
|
522
584
|
},
|
|
523
585
|
},
|
|
@@ -528,10 +590,20 @@ const valiron = new ValironSDK({
|
|
|
528
590
|
|
|
529
591
|
## Middleware
|
|
530
592
|
|
|
593
|
+
All middleware adapters use `getAgentProfile()` (public endpoint) rather than
|
|
594
|
+
`gate()` (protected endpoint), so they work from any server context without
|
|
595
|
+
agent challenge-response auth. Results are cached client-side (default 30s)
|
|
596
|
+
to survive x402's two-request payment flow and avoid cold-start failures.
|
|
597
|
+
|
|
531
598
|
### createValironGate(config) — Express
|
|
532
599
|
|
|
533
600
|
See above for full documentation.
|
|
534
601
|
|
|
602
|
+
**Express 4 note**: The returned middleware uses a synchronous wrapper
|
|
603
|
+
(`Promise.resolve().catch(next)`) to ensure async errors are properly caught.
|
|
604
|
+
You do NOT need to wrap it yourself — it's safe to use directly with
|
|
605
|
+
`app.use()` even on Express 4.
|
|
606
|
+
|
|
535
607
|
### valironFastifyPlugin — Fastify
|
|
536
608
|
|
|
537
609
|
```typescript
|
|
@@ -553,7 +625,7 @@ import { ValironSDK, createValironNextMiddleware } from "@valiron/sdk";
|
|
|
553
625
|
const valiron = new ValironSDK();
|
|
554
626
|
export default createValironNextMiddleware({
|
|
555
627
|
sdk: valiron,
|
|
556
|
-
|
|
628
|
+
paths: ["/api/paid"],
|
|
557
629
|
});
|
|
558
630
|
```
|
|
559
631
|
|
|
@@ -565,13 +637,27 @@ import { ValironSDK, valironGateCheck } from "@valiron/sdk";
|
|
|
565
637
|
const valiron = new ValironSDK();
|
|
566
638
|
|
|
567
639
|
app.use(async (c, next) => {
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
640
|
+
const gate = await valironGateCheck(valiron, {
|
|
641
|
+
agentId: c.req.header("x-agent-id") ?? null,
|
|
642
|
+
agentAddress: c.req.header("x-agent-address") ?? null,
|
|
643
|
+
});
|
|
644
|
+
if (!gate.allow) return c.json(gate.body, gate.status);
|
|
645
|
+
c.set("valiron", gate.result);
|
|
571
646
|
await next();
|
|
572
647
|
});
|
|
573
648
|
```
|
|
574
649
|
|
|
650
|
+
### Client-Side Caching
|
|
651
|
+
|
|
652
|
+
All middleware adapters include a built-in in-memory cache (default TTL: 30 seconds).
|
|
653
|
+
This is important for payment protocols like x402 that make two requests per payment
|
|
654
|
+
(discover 402 → retry with payment). Without caching, the second trust check can fail
|
|
655
|
+
due to cold-start latency on the edge proxy.
|
|
656
|
+
|
|
657
|
+
The Express gate exposes `cacheTtlMs` to override this TTL; set it to `0` to disable
|
|
658
|
+
caching for that middleware instance. `createValironNextMiddleware` and
|
|
659
|
+
`valironGateCheck` also accept `cacheTtlMs`.
|
|
660
|
+
|
|
575
661
|
### Middleware Error Responses
|
|
576
662
|
|
|
577
663
|
All middleware variants return consistent error responses:
|
|
@@ -580,6 +666,7 @@ All middleware variants return consistent error responses:
|
|
|
580
666
|
|--------|------|------|
|
|
581
667
|
| 401 | No agent ID found in request | `{ error: "No agent identity provided" }` |
|
|
582
668
|
| 403 | Agent denied by trust gate | `{ error: "Access denied", tier, riskLevel, route }` |
|
|
669
|
+
| 403 | New agent pending evaluation | `{ error: "Agent pending evaluation", retryAfterMs: 30000 }` |
|
|
583
670
|
| 503 | Valiron service unavailable | `{ error: "Trust evaluation unavailable" }` |
|
|
584
671
|
|
|
585
672
|
> **Fail-closed:** When the Valiron service is unreachable, middleware returns 503 — it never fails open and never allows unverified agents through.
|
package/docs/TRUST-MODEL.md
CHANGED
|
@@ -4,7 +4,7 @@ Valiron uses a hybrid trust model to evaluate AI agents hitting your API. This d
|
|
|
4
4
|
|
|
5
5
|
## Trust Tiers
|
|
6
6
|
|
|
7
|
-
Valiron assigns a Moody's-style credit tier
|
|
7
|
+
Valiron assigns a Moody's-style credit tier from a normalized `0-100` trust score:
|
|
8
8
|
|
|
9
9
|
| Tier | Meaning | Route Decision |
|
|
10
10
|
|------|---------|----------------|
|
|
@@ -18,11 +18,33 @@ Valiron assigns a Moody's-style credit tier based on an agent's behavioral evalu
|
|
|
18
18
|
| CA | Extremely speculative | `sandbox_only` |
|
|
19
19
|
| C | Default risk | `sandbox_only` |
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Selectable Trust Signals
|
|
22
|
+
|
|
23
|
+
API sellers can use Valiron plug-and-play, or choose the trust signals used for a specific endpoint.
|
|
24
|
+
|
|
25
|
+
Supported signals:
|
|
26
|
+
|
|
27
|
+
| Signal | Description | Plan |
|
|
28
|
+
|--------|-------------|------|
|
|
29
|
+
| `8004` | ERC-8004 / Solana on-chain reputation | Free |
|
|
30
|
+
| `sandbox` | Valiron behavioral sandbox score | Free |
|
|
31
|
+
| `world` | World ID human-agent link | Pro |
|
|
32
|
+
| `icebreaker` | Icebreaker human/background attestation | Pro |
|
|
33
|
+
|
|
34
|
+
When multiple signals are selected, Valiron computes each signal on a `0-100` scale and normalizes the configured weights across only those selected signals. The default weights are:
|
|
35
|
+
|
|
36
|
+
| Signal | Default Weight |
|
|
37
|
+
|--------|----------------|
|
|
38
|
+
| `sandbox` | 55 |
|
|
39
|
+
| `8004` | 25 |
|
|
40
|
+
| `world` | 15 |
|
|
41
|
+
| `icebreaker` | 5 |
|
|
22
42
|
|
|
23
|
-
|
|
43
|
+
If no signals are specified, Valiron uses the plug-and-play default: sandbox plus any other available trust signals.
|
|
24
44
|
|
|
25
|
-
|
|
45
|
+
## Behavioral Factors
|
|
46
|
+
|
|
47
|
+
Valiron evaluates agents across multiple behavioral dimensions. The behavioral evaluation is holistic — no single sandbox behavior determines the outcome. The specific factors evaluated and their weights are proprietary and not disclosed.
|
|
26
48
|
|
|
27
49
|
## What Makes an Agent Trustworthy
|
|
28
50
|
|
|
@@ -47,6 +69,16 @@ Or via HTTP:
|
|
|
47
69
|
curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox/AGENT_ID
|
|
48
70
|
```
|
|
49
71
|
|
|
72
|
+
Use selected signals in middleware:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
app.use("/api/paid", createValironGate({
|
|
76
|
+
sdk: valiron,
|
|
77
|
+
trustSignals: ["8004", "sandbox"],
|
|
78
|
+
minScore: 70,
|
|
79
|
+
}));
|
|
80
|
+
```
|
|
81
|
+
|
|
50
82
|
---
|
|
51
83
|
|
|
52
84
|
## Solana Trust Evaluation
|
package/docs/llms.txt
CHANGED
|
@@ -17,9 +17,12 @@ GET /operator/wallet/{wallet}?chain={chain}
|
|
|
17
17
|
### Resolve wallet to agent
|
|
18
18
|
GET /operator/resolve-wallet/{wallet}?chain={chain}
|
|
19
19
|
|
|
20
|
-
### Run sandbox test
|
|
20
|
+
### Run sandbox test (on-chain agent)
|
|
21
21
|
POST /operator/trigger-sandbox/{agentId}
|
|
22
22
|
|
|
23
|
+
### Run sandbox test (key-based agent)
|
|
24
|
+
POST /operator/trigger-sandbox-key/{agentAddress}
|
|
25
|
+
|
|
23
26
|
### Trust gate (allow/deny)
|
|
24
27
|
POST /operator/gate/{agentId}
|
|
25
28
|
Body: { "ttlMs": 86400000 }
|
|
@@ -60,8 +63,14 @@ if (gate.allow) { /* proceed */ }
|
|
|
60
63
|
const snapshot = await valiron.getAgentSnapshot("AGENT_ID");
|
|
61
64
|
console.log(snapshot.snapshotHash); // "0xabc..."
|
|
62
65
|
console.log(snapshot.previousHash); // "0x0" (genesis)
|
|
66
|
+
|
|
67
|
+
// Sandbox evaluation for key-based agent
|
|
68
|
+
const keyResult = await valiron.triggerKeyAgentSandbox("0x1234...abcd");
|
|
69
|
+
console.log(keyResult.tier); // "A"
|
|
63
70
|
```
|
|
64
71
|
|
|
72
|
+
Auto-sandbox: Middleware automatically triggers sandbox evaluation for new agents (on-chain with totalFeedback=0, or key-based with no score). Returns 403 with { error: "Agent pending evaluation", retryAfterMs: 30000 }.
|
|
73
|
+
|
|
65
74
|
## Trust Tiers
|
|
66
75
|
|
|
67
76
|
Valiron assigns Moody's-style credit tiers: AAA (highest trust) through C (lowest trust). Higher tiers route to production, lower tiers are sandboxed or blocked. Exact score ranges are not disclosed.
|