aira-sdk 0.2.2 → 0.3.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.
- package/README.md +135 -5
- package/dist/client.d.ts +32 -0
- package/dist/client.js +71 -1
- package/dist/extras/index.d.ts +2 -0
- package/dist/extras/index.js +3 -1
- package/dist/extras/langchain.d.ts +9 -0
- package/dist/extras/langchain.js +13 -0
- package/dist/extras/mcp.js +62 -0
- package/dist/extras/openai-agents.d.ts +9 -0
- package/dist/extras/openai-agents.js +13 -0
- package/dist/extras/trust.d.ts +33 -0
- package/dist/extras/trust.js +77 -0
- package/dist/extras/vercel-ai.d.ts +9 -0
- package/dist/extras/vercel-ai.js +13 -0
- package/dist/types.d.ts +30 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Aira TypeScript SDK
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**AI compliance infrastructure for AI agents.**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/aira-sdk)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -64,7 +64,7 @@ import { Aira } from "aira-sdk";
|
|
|
64
64
|
import { AiraCallbackHandler } from "aira-sdk/extras/langchain";
|
|
65
65
|
|
|
66
66
|
const aira = new Aira({ apiKey: "aira_live_xxx" });
|
|
67
|
-
const handler = new AiraCallbackHandler({ client: aira, agentId: "research-agent", modelId: "gpt-
|
|
67
|
+
const handler = new AiraCallbackHandler({ client: aira, agentId: "research-agent", modelId: "gpt-5.2" });
|
|
68
68
|
|
|
69
69
|
// Every tool call and chain completion gets a signed receipt
|
|
70
70
|
const result = await chain.invoke({ input: "Analyze Q1 revenue" }, { callbacks: [handler] });
|
|
@@ -83,7 +83,7 @@ const middleware = new AiraVercelMiddleware({ client: aira, agentId: "assistant-
|
|
|
83
83
|
|
|
84
84
|
// Wrap your Vercel AI calls — receipts at invocation and completion
|
|
85
85
|
const result = await middleware.wrapGenerateText({
|
|
86
|
-
model: openai("gpt-
|
|
86
|
+
model: openai("gpt-5.2"),
|
|
87
87
|
prompt: "Summarize the contract terms",
|
|
88
88
|
});
|
|
89
89
|
```
|
|
@@ -196,7 +196,7 @@ Supported event types: `action.notarized`, `action.authorized`, `agent.registere
|
|
|
196
196
|
|
|
197
197
|
## Core SDK Methods
|
|
198
198
|
|
|
199
|
-
All
|
|
199
|
+
All 52 methods on `Aira`. Every write operation produces a cryptographic receipt.
|
|
200
200
|
|
|
201
201
|
| Category | Method | Description |
|
|
202
202
|
|---|---|---|
|
|
@@ -217,6 +217,16 @@ All 40 methods on `Aira`. Every write operation produces a cryptographic receipt
|
|
|
217
217
|
| | `decommissionAgent()` | Decommission agent |
|
|
218
218
|
| | `transferAgent()` | Transfer ownership to another org |
|
|
219
219
|
| | `getAgentActions()` | List actions by agent |
|
|
220
|
+
| **Trust Layer** | `getAgentDid()` | Retrieve agent's W3C DID (`did:web`) |
|
|
221
|
+
| | `rotateAgentKeys()` | Rotate agent's Ed25519 signing keys |
|
|
222
|
+
| | `getAgentCredential()` | Get agent's W3C Verifiable Credential |
|
|
223
|
+
| | `verifyCredential()` | Verify a Verifiable Credential |
|
|
224
|
+
| | `revokeCredential()` | Revoke agent's Verifiable Credential |
|
|
225
|
+
| | `requestMutualSign()` | Initiate mutual notarization with counterparty |
|
|
226
|
+
| | `completeMutualSign()` | Complete mutual notarization (counterparty signs) |
|
|
227
|
+
| | `getReputation()` | Get agent reputation score and tier |
|
|
228
|
+
| | `listReputationHistory()` | List reputation score history |
|
|
229
|
+
| | `resolveDid()` | Resolve any DID to its DID Document |
|
|
220
230
|
| **Cases** | `runCase()` | Multi-model consensus adjudication |
|
|
221
231
|
| | `getCase()` | Retrieve case result |
|
|
222
232
|
| | `listCases()` | List cases |
|
|
@@ -245,6 +255,125 @@ All 40 methods on `Aira`. Every write operation produces a cryptographic receipt
|
|
|
245
255
|
|
|
246
256
|
---
|
|
247
257
|
|
|
258
|
+
## Trust Layer
|
|
259
|
+
|
|
260
|
+
Standards-based identity and trust for agents: W3C DIDs, Verifiable Credentials, mutual notarization, and reputation scoring. Every agent gets a cryptographically verifiable identity that other agents (and humans) can check before interacting.
|
|
261
|
+
|
|
262
|
+
### DID Identity
|
|
263
|
+
|
|
264
|
+
Every registered agent gets a W3C-compliant DID (`did:web`):
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
// Retrieve the agent's DID
|
|
268
|
+
const did = await aira.getAgentDid("my-agent");
|
|
269
|
+
console.log(did); // "did:web:airaproof.com:agents:my-agent"
|
|
270
|
+
|
|
271
|
+
// Rotate signing keys (old keys are revoked, new keys are published)
|
|
272
|
+
await aira.rotateAgentKeys("my-agent");
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Verifiable Credentials
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
// Get the agent's W3C Verifiable Credential
|
|
279
|
+
const vc = await aira.getAgentCredential("my-agent");
|
|
280
|
+
|
|
281
|
+
// Verify any VC (returns validity, issuer, expiry)
|
|
282
|
+
const result = await aira.verifyCredential(vc);
|
|
283
|
+
console.log(result.valid); // true
|
|
284
|
+
|
|
285
|
+
// Revoke a credential
|
|
286
|
+
await aira.revokeCredential("my-agent", { reason: "Agent deprecated" });
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Mutual Notarization
|
|
290
|
+
|
|
291
|
+
For high-stakes actions, both parties co-sign:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
// Agent A initiates — sends a signing request to the counterparty
|
|
295
|
+
const request = await aira.requestMutualSign({
|
|
296
|
+
actionId: "act-uuid",
|
|
297
|
+
counterpartyDid: "did:web:partner.com:agents:their-agent",
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Agent B completes — signs the same payload
|
|
301
|
+
const receipt = await aira.completeMutualSign({
|
|
302
|
+
actionId: "act-uuid",
|
|
303
|
+
did: "did:web:partner.com:agents:their-agent",
|
|
304
|
+
signature: "z...",
|
|
305
|
+
signedPayloadHash: "sha256:...",
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Reputation
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
const rep = await aira.getReputation("my-agent");
|
|
313
|
+
console.log(rep.score); // 84
|
|
314
|
+
console.log(rep.tier); // "Verified"
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Endpoint Verification
|
|
318
|
+
|
|
319
|
+
Control which external APIs your agents can call. When `endpointUrl` is passed to `notarize()`, Aira checks it against your org's whitelist. Unrecognized endpoints are blocked in strict mode.
|
|
320
|
+
|
|
321
|
+
#### Notarize with endpointUrl
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
const receipt = await aira.notarize({
|
|
325
|
+
actionType: "api_call",
|
|
326
|
+
details: "Charged customer $49.99 for subscription renewal",
|
|
327
|
+
agentId: "billing-agent",
|
|
328
|
+
modelId: "claude-sonnet-4-6",
|
|
329
|
+
endpointUrl: "https://api.stripe.com/v1/charges",
|
|
330
|
+
});
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### Handle ENDPOINT_NOT_WHITELISTED
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
import { Aira, AiraError } from "aira-sdk";
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
const receipt = await aira.notarize({
|
|
340
|
+
actionType: "api_call",
|
|
341
|
+
details: "Send SMS via new provider",
|
|
342
|
+
agentId: "notifications-agent",
|
|
343
|
+
endpointUrl: "https://api.newprovider.com/v1/sms",
|
|
344
|
+
});
|
|
345
|
+
} catch (e) {
|
|
346
|
+
if (e instanceof AiraError && e.code === "ENDPOINT_NOT_WHITELISTED") {
|
|
347
|
+
console.log(`Blocked: ${e.message}`);
|
|
348
|
+
console.log(`Approval request: ${e.details.approval_id}`);
|
|
349
|
+
console.log(`Suggested pattern: ${e.details.url_pattern_suggested}`);
|
|
350
|
+
} else {
|
|
351
|
+
throw e;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Trust Policy in Integrations
|
|
357
|
+
|
|
358
|
+
Pass a `trustPolicy` to any framework integration to run automated trust checks before agent interactions:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
import { AiraCallbackHandler } from "aira-sdk/extras/langchain";
|
|
362
|
+
|
|
363
|
+
const handler = new AiraCallbackHandler(aira, "research-agent", {
|
|
364
|
+
modelId: "gpt-5.2",
|
|
365
|
+
trustPolicy: {
|
|
366
|
+
verifyCounterparty: true, // resolve counterparty DID
|
|
367
|
+
minReputation: 60, // warn if reputation score below 60
|
|
368
|
+
requireValidVc: true, // check Verifiable Credential validity
|
|
369
|
+
blockRevokedVc: true, // block if counterparty VC is revoked
|
|
370
|
+
blockUnregistered: false, // don't block agents without Aira DIDs
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
248
377
|
## Error Handling
|
|
249
378
|
|
|
250
379
|
```typescript
|
|
@@ -286,7 +415,8 @@ const aira = new Aira({
|
|
|
286
415
|
|
|
287
416
|
| Feature | Python | TypeScript |
|
|
288
417
|
|---|---|---|
|
|
289
|
-
| Core API (
|
|
418
|
+
| Core API (45+ methods) | Yes | Yes |
|
|
419
|
+
| Trust Layer (DID, VC, Reputation) | Yes | Yes |
|
|
290
420
|
| LangChain | Yes | Yes |
|
|
291
421
|
| CrewAI | Yes | -- (Python-only) |
|
|
292
422
|
| Vercel AI | -- (JS-only) | Yes |
|
package/dist/client.d.ts
CHANGED
|
@@ -129,6 +129,38 @@ export declare class Aira {
|
|
|
129
129
|
tools_used: string[];
|
|
130
130
|
model_id?: string;
|
|
131
131
|
}>;
|
|
132
|
+
/** Get full DID info for an agent. */
|
|
133
|
+
getAgentDid(slug: string): Promise<Record<string, unknown>>;
|
|
134
|
+
/** Rotate an agent's DID keypair. */
|
|
135
|
+
rotateAgentKeys(slug: string): Promise<Record<string, unknown>>;
|
|
136
|
+
/** Resolve any did:web DID to its DID document. */
|
|
137
|
+
resolveDid(did: string): Promise<Record<string, unknown>>;
|
|
138
|
+
/** Get the current valid VC for an agent. */
|
|
139
|
+
getAgentCredential(slug: string): Promise<Record<string, unknown>>;
|
|
140
|
+
/** Get full credential history for an agent. */
|
|
141
|
+
getAgentCredentials(slug: string): Promise<Record<string, unknown>>;
|
|
142
|
+
/** Revoke the current credential for an agent. */
|
|
143
|
+
revokeCredential(slug: string, reason?: string): Promise<Record<string, unknown>>;
|
|
144
|
+
/** Verify a Verifiable Credential — checks signature, expiry, revocation. */
|
|
145
|
+
verifyCredential(credential: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
146
|
+
/** Initiate a mutual signing request for an action. */
|
|
147
|
+
requestMutualSign(actionId: string, counterpartyDid: string): Promise<Record<string, unknown>>;
|
|
148
|
+
/** Get the action payload awaiting counterparty signature. */
|
|
149
|
+
getPendingMutualSign(actionId: string): Promise<Record<string, unknown>>;
|
|
150
|
+
/** Submit counterparty signature to complete mutual signing. */
|
|
151
|
+
completeMutualSign(actionId: string, did: string, signature: string, signedPayloadHash: string): Promise<Record<string, unknown>>;
|
|
152
|
+
/** Get the co-signed receipt for a mutually signed action. */
|
|
153
|
+
getMutualSignReceipt(actionId: string): Promise<Record<string, unknown>>;
|
|
154
|
+
/** Reject a mutual signing request. */
|
|
155
|
+
rejectMutualSign(actionId: string, reason?: string): Promise<Record<string, unknown>>;
|
|
156
|
+
/** Get current reputation score for an agent. */
|
|
157
|
+
getReputation(slug: string): Promise<Record<string, unknown>>;
|
|
158
|
+
/** Get full reputation history for an agent. */
|
|
159
|
+
getReputationHistory(slug: string): Promise<Record<string, unknown>>;
|
|
160
|
+
/** Submit a signed attestation of a successful interaction. */
|
|
161
|
+
attestReputation(slug: string, counterpartyDid: string, actionId: string, attestation: string, signature: string): Promise<Record<string, unknown>>;
|
|
162
|
+
/** Verify a reputation score by returning inputs and score_hash. */
|
|
163
|
+
verifyReputation(slug: string): Promise<Record<string, unknown>>;
|
|
132
164
|
/** Create a scoped session with pre-filled defaults. */
|
|
133
165
|
session(agentId: string, defaults?: Record<string, unknown>): AiraSession;
|
|
134
166
|
/** Number of queued offline requests. */
|
package/dist/client.js
CHANGED
|
@@ -259,7 +259,77 @@ class Aira {
|
|
|
259
259
|
}
|
|
260
260
|
// ==================== Chat ====================
|
|
261
261
|
async ask(message, params) {
|
|
262
|
-
return this.post("/chat", buildBody({ message, history: params?.history,
|
|
262
|
+
return this.post("/chat", buildBody({ message, history: params?.history, model_id: params?.model }));
|
|
263
|
+
}
|
|
264
|
+
// ==================== DID ====================
|
|
265
|
+
/** Get full DID info for an agent. */
|
|
266
|
+
async getAgentDid(slug) {
|
|
267
|
+
return this.get(`/agents/${slug}/did`);
|
|
268
|
+
}
|
|
269
|
+
/** Rotate an agent's DID keypair. */
|
|
270
|
+
async rotateAgentKeys(slug) {
|
|
271
|
+
return this.post(`/agents/${slug}/did/rotate`, {});
|
|
272
|
+
}
|
|
273
|
+
/** Resolve any did:web DID to its DID document. */
|
|
274
|
+
async resolveDid(did) {
|
|
275
|
+
return this.post("/dids/resolve", { did });
|
|
276
|
+
}
|
|
277
|
+
// ==================== Verifiable Credentials ====================
|
|
278
|
+
/** Get the current valid VC for an agent. */
|
|
279
|
+
async getAgentCredential(slug) {
|
|
280
|
+
return this.get(`/agents/${slug}/credential`);
|
|
281
|
+
}
|
|
282
|
+
/** Get full credential history for an agent. */
|
|
283
|
+
async getAgentCredentials(slug) {
|
|
284
|
+
return this.get(`/agents/${slug}/credentials`);
|
|
285
|
+
}
|
|
286
|
+
/** Revoke the current credential for an agent. */
|
|
287
|
+
async revokeCredential(slug, reason = "") {
|
|
288
|
+
return this.post(`/agents/${slug}/credentials/revoke`, { reason });
|
|
289
|
+
}
|
|
290
|
+
/** Verify a Verifiable Credential — checks signature, expiry, revocation. */
|
|
291
|
+
async verifyCredential(credential) {
|
|
292
|
+
return this.post("/credentials/verify", { credential });
|
|
293
|
+
}
|
|
294
|
+
// ==================== Mutual Notarization ====================
|
|
295
|
+
/** Initiate a mutual signing request for an action. */
|
|
296
|
+
async requestMutualSign(actionId, counterpartyDid) {
|
|
297
|
+
return this.post(`/actions/${actionId}/mutual-sign/request`, { counterparty_did: counterpartyDid });
|
|
298
|
+
}
|
|
299
|
+
/** Get the action payload awaiting counterparty signature. */
|
|
300
|
+
async getPendingMutualSign(actionId) {
|
|
301
|
+
return this.get(`/actions/${actionId}/mutual-sign/pending`);
|
|
302
|
+
}
|
|
303
|
+
/** Submit counterparty signature to complete mutual signing. */
|
|
304
|
+
async completeMutualSign(actionId, did, signature, signedPayloadHash) {
|
|
305
|
+
return this.post(`/actions/${actionId}/mutual-sign/complete`, { did, signature, signed_payload_hash: signedPayloadHash });
|
|
306
|
+
}
|
|
307
|
+
/** Get the co-signed receipt for a mutually signed action. */
|
|
308
|
+
async getMutualSignReceipt(actionId) {
|
|
309
|
+
return this.get(`/actions/${actionId}/mutual-sign/receipt`);
|
|
310
|
+
}
|
|
311
|
+
/** Reject a mutual signing request. */
|
|
312
|
+
async rejectMutualSign(actionId, reason = "") {
|
|
313
|
+
return this.post(`/actions/${actionId}/mutual-sign/reject`, { reason });
|
|
314
|
+
}
|
|
315
|
+
// ==================== Reputation ====================
|
|
316
|
+
/** Get current reputation score for an agent. */
|
|
317
|
+
async getReputation(slug) {
|
|
318
|
+
return this.get(`/agents/${slug}/reputation`);
|
|
319
|
+
}
|
|
320
|
+
/** Get full reputation history for an agent. */
|
|
321
|
+
async getReputationHistory(slug) {
|
|
322
|
+
return this.get(`/agents/${slug}/reputation/history`);
|
|
323
|
+
}
|
|
324
|
+
/** Submit a signed attestation of a successful interaction. */
|
|
325
|
+
async attestReputation(slug, counterpartyDid, actionId, attestation, signature) {
|
|
326
|
+
return this.post(`/agents/${slug}/reputation/attest`, {
|
|
327
|
+
counterparty_did: counterpartyDid, action_id: actionId, attestation, signature,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/** Verify a reputation score by returning inputs and score_hash. */
|
|
331
|
+
async verifyReputation(slug) {
|
|
332
|
+
return this.get(`/agents/${slug}/reputation/verify`);
|
|
263
333
|
}
|
|
264
334
|
// ==================== Session ====================
|
|
265
335
|
/** Create a scoped session with pre-filled defaults. */
|
package/dist/extras/index.d.ts
CHANGED
|
@@ -17,3 +17,5 @@ export { createServer, getTools, handleToolCall } from "./mcp";
|
|
|
17
17
|
export type { MCPTool, MCPTextContent } from "./mcp";
|
|
18
18
|
export { verifySignature, parseEvent, WebhookEventType } from "./webhooks";
|
|
19
19
|
export type { WebhookEvent, WebhookEventTypeName } from "./webhooks";
|
|
20
|
+
export { checkTrust } from "./trust";
|
|
21
|
+
export type { TrustPolicy, TrustContext } from "./trust";
|
package/dist/extras/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* import { verifySignature, parseEvent } from "aira-sdk/extras/webhooks";
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.WebhookEventType = exports.parseEvent = exports.verifySignature = exports.handleToolCall = exports.getTools = exports.createServer = exports.AiraGuardrail = exports.AiraVercelMiddleware = exports.AiraCallbackHandler = void 0;
|
|
15
|
+
exports.checkTrust = exports.WebhookEventType = exports.parseEvent = exports.verifySignature = exports.handleToolCall = exports.getTools = exports.createServer = exports.AiraGuardrail = exports.AiraVercelMiddleware = exports.AiraCallbackHandler = void 0;
|
|
16
16
|
var langchain_1 = require("./langchain");
|
|
17
17
|
Object.defineProperty(exports, "AiraCallbackHandler", { enumerable: true, get: function () { return langchain_1.AiraCallbackHandler; } });
|
|
18
18
|
var vercel_ai_1 = require("./vercel-ai");
|
|
@@ -27,3 +27,5 @@ var webhooks_1 = require("./webhooks");
|
|
|
27
27
|
Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return webhooks_1.verifySignature; } });
|
|
28
28
|
Object.defineProperty(exports, "parseEvent", { enumerable: true, get: function () { return webhooks_1.parseEvent; } });
|
|
29
29
|
Object.defineProperty(exports, "WebhookEventType", { enumerable: true, get: function () { return webhooks_1.WebhookEventType; } });
|
|
30
|
+
var trust_1 = require("./trust");
|
|
31
|
+
Object.defineProperty(exports, "checkTrust", { enumerable: true, get: function () { return trust_1.checkTrust; } });
|
|
@@ -9,15 +9,24 @@
|
|
|
9
9
|
* const chain = someChain.withConfig({ callbacks: [handler] });
|
|
10
10
|
*/
|
|
11
11
|
import type { Aira } from "../client";
|
|
12
|
+
import type { TrustPolicy, TrustContext } from "./trust";
|
|
13
|
+
export type { TrustPolicy, TrustContext } from "./trust";
|
|
12
14
|
export declare class AiraCallbackHandler {
|
|
13
15
|
private client;
|
|
14
16
|
private agentId;
|
|
15
17
|
private modelId?;
|
|
16
18
|
private actionTypes;
|
|
19
|
+
private trustPolicy?;
|
|
17
20
|
constructor(client: Aira, agentId: string, options?: {
|
|
18
21
|
modelId?: string;
|
|
19
22
|
actionTypes?: Record<string, string>;
|
|
23
|
+
trustPolicy?: TrustPolicy;
|
|
20
24
|
});
|
|
25
|
+
/**
|
|
26
|
+
* Check trust for a counterparty agent before interacting.
|
|
27
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
28
|
+
*/
|
|
29
|
+
checkTrust(counterpartyId: string): Promise<TrustContext>;
|
|
21
30
|
private notarize;
|
|
22
31
|
/** Called when a tool finishes. */
|
|
23
32
|
handleToolEnd(output: string, name?: string): void;
|
package/dist/extras/langchain.js
CHANGED
|
@@ -11,16 +11,19 @@
|
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.AiraCallbackHandler = void 0;
|
|
14
|
+
const trust_1 = require("./trust");
|
|
14
15
|
const MAX_DETAILS = 5000;
|
|
15
16
|
class AiraCallbackHandler {
|
|
16
17
|
client;
|
|
17
18
|
agentId;
|
|
18
19
|
modelId;
|
|
19
20
|
actionTypes;
|
|
21
|
+
trustPolicy;
|
|
20
22
|
constructor(client, agentId, options) {
|
|
21
23
|
this.client = client;
|
|
22
24
|
this.agentId = agentId;
|
|
23
25
|
this.modelId = options?.modelId;
|
|
26
|
+
this.trustPolicy = options?.trustPolicy;
|
|
24
27
|
this.actionTypes = {
|
|
25
28
|
tool_end: "tool_call",
|
|
26
29
|
chain_end: "chain_completed",
|
|
@@ -28,6 +31,16 @@ class AiraCallbackHandler {
|
|
|
28
31
|
...(options?.actionTypes ?? {}),
|
|
29
32
|
};
|
|
30
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Check trust for a counterparty agent before interacting.
|
|
36
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
37
|
+
*/
|
|
38
|
+
async checkTrust(counterpartyId) {
|
|
39
|
+
if (!this.trustPolicy) {
|
|
40
|
+
return { counterpartyId, blocked: false, recommendation: "No trust policy configured" };
|
|
41
|
+
}
|
|
42
|
+
return (0, trust_1.checkTrust)(this.client, this.trustPolicy, counterpartyId);
|
|
43
|
+
}
|
|
31
44
|
notarize(actionType, details) {
|
|
32
45
|
try {
|
|
33
46
|
const params = {
|
package/dist/extras/mcp.js
CHANGED
|
@@ -51,6 +51,51 @@ function getTools() {
|
|
|
51
51
|
required: ["receipt_id"],
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
|
+
{
|
|
55
|
+
name: "resolve_did",
|
|
56
|
+
description: "Resolve a did:web DID to its DID document",
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
did: { type: "string", description: "The DID to resolve (e.g. did:web:airaproof.com:agents:my-agent)" },
|
|
61
|
+
},
|
|
62
|
+
required: ["did"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "verify_credential",
|
|
67
|
+
description: "Verify a Verifiable Credential — checks signature, expiry, and revocation status",
|
|
68
|
+
inputSchema: {
|
|
69
|
+
type: "object",
|
|
70
|
+
properties: {
|
|
71
|
+
agent_id: { type: "string", description: "Agent slug whose credential to verify" },
|
|
72
|
+
},
|
|
73
|
+
required: ["agent_id"],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "get_reputation",
|
|
78
|
+
description: "Get the current reputation score and tier for an agent",
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: {
|
|
82
|
+
agent_id: { type: "string", description: "Agent slug" },
|
|
83
|
+
},
|
|
84
|
+
required: ["agent_id"],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "request_mutual_sign",
|
|
89
|
+
description: "Initiate a mutual signing request for an action with a counterparty",
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: {
|
|
93
|
+
action_id: { type: "string", description: "Action UUID to co-sign" },
|
|
94
|
+
counterparty_did: { type: "string", description: "DID of the counterparty agent" },
|
|
95
|
+
},
|
|
96
|
+
required: ["action_id", "counterparty_did"],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
54
99
|
];
|
|
55
100
|
}
|
|
56
101
|
/** Handle an MCP tool call and return text content. */
|
|
@@ -73,6 +118,23 @@ async function handleToolCall(client, name, args) {
|
|
|
73
118
|
const result = await client.getReceipt(args.receipt_id);
|
|
74
119
|
return [{ type: "text", text: JSON.stringify(result) }];
|
|
75
120
|
}
|
|
121
|
+
if (name === "resolve_did") {
|
|
122
|
+
const result = await client.resolveDid(args.did);
|
|
123
|
+
return [{ type: "text", text: JSON.stringify(result) }];
|
|
124
|
+
}
|
|
125
|
+
if (name === "verify_credential") {
|
|
126
|
+
const cred = await client.getAgentCredential(args.agent_id);
|
|
127
|
+
const result = await client.verifyCredential(cred);
|
|
128
|
+
return [{ type: "text", text: JSON.stringify(result) }];
|
|
129
|
+
}
|
|
130
|
+
if (name === "get_reputation") {
|
|
131
|
+
const result = await client.getReputation(args.agent_id);
|
|
132
|
+
return [{ type: "text", text: JSON.stringify(result) }];
|
|
133
|
+
}
|
|
134
|
+
if (name === "request_mutual_sign") {
|
|
135
|
+
const result = await client.requestMutualSign(args.action_id, args.counterparty_did);
|
|
136
|
+
return [{ type: "text", text: JSON.stringify(result) }];
|
|
137
|
+
}
|
|
76
138
|
return [{ type: "text", text: JSON.stringify({ error: `Unknown tool: ${name}` }) }];
|
|
77
139
|
}
|
|
78
140
|
catch (e) {
|
|
@@ -9,13 +9,22 @@
|
|
|
9
9
|
* guardrail.onToolCall("search", { query: "test" });
|
|
10
10
|
*/
|
|
11
11
|
import type { Aira } from "../client";
|
|
12
|
+
import type { TrustPolicy, TrustContext } from "./trust";
|
|
13
|
+
export type { TrustPolicy, TrustContext } from "./trust";
|
|
12
14
|
export declare class AiraGuardrail {
|
|
13
15
|
private client;
|
|
14
16
|
private agentId;
|
|
15
17
|
private modelId?;
|
|
18
|
+
private trustPolicy?;
|
|
16
19
|
constructor(client: Aira, agentId: string, options?: {
|
|
17
20
|
modelId?: string;
|
|
21
|
+
trustPolicy?: TrustPolicy;
|
|
18
22
|
});
|
|
23
|
+
/**
|
|
24
|
+
* Check trust for a counterparty agent before interacting.
|
|
25
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
26
|
+
*/
|
|
27
|
+
checkTrust(counterpartyId: string): Promise<TrustContext>;
|
|
19
28
|
private notarize;
|
|
20
29
|
/** Call after a tool execution to notarize it. */
|
|
21
30
|
onToolCall(toolName: string, args?: Record<string, unknown>): void;
|
|
@@ -11,15 +11,28 @@
|
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.AiraGuardrail = void 0;
|
|
14
|
+
const trust_1 = require("./trust");
|
|
14
15
|
const MAX_DETAILS = 5000;
|
|
15
16
|
class AiraGuardrail {
|
|
16
17
|
client;
|
|
17
18
|
agentId;
|
|
18
19
|
modelId;
|
|
20
|
+
trustPolicy;
|
|
19
21
|
constructor(client, agentId, options) {
|
|
20
22
|
this.client = client;
|
|
21
23
|
this.agentId = agentId;
|
|
22
24
|
this.modelId = options?.modelId;
|
|
25
|
+
this.trustPolicy = options?.trustPolicy;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check trust for a counterparty agent before interacting.
|
|
29
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
30
|
+
*/
|
|
31
|
+
async checkTrust(counterpartyId) {
|
|
32
|
+
if (!this.trustPolicy) {
|
|
33
|
+
return { counterpartyId, blocked: false, recommendation: "No trust policy configured" };
|
|
34
|
+
}
|
|
35
|
+
return (0, trust_1.checkTrust)(this.client, this.trustPolicy, counterpartyId);
|
|
23
36
|
}
|
|
24
37
|
notarize(actionType, details) {
|
|
25
38
|
try {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trust layer types and helpers shared across all framework integrations.
|
|
3
|
+
*/
|
|
4
|
+
import type { Aira } from "../client";
|
|
5
|
+
/** Policy for automated trust checks before tool execution. */
|
|
6
|
+
export interface TrustPolicy {
|
|
7
|
+
verifyCounterparty?: boolean;
|
|
8
|
+
minReputation?: number;
|
|
9
|
+
requireValidVc?: boolean;
|
|
10
|
+
blockRevokedVc?: boolean;
|
|
11
|
+
blockUnregistered?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Result of a trust check against a counterparty agent. */
|
|
14
|
+
export interface TrustContext {
|
|
15
|
+
counterpartyId?: string;
|
|
16
|
+
didResolved?: boolean;
|
|
17
|
+
did?: string;
|
|
18
|
+
vcValid?: boolean | null;
|
|
19
|
+
reputationScore?: number | null;
|
|
20
|
+
reputationTier?: string | null;
|
|
21
|
+
reputationWarning?: string;
|
|
22
|
+
blocked?: boolean;
|
|
23
|
+
blockReason?: string;
|
|
24
|
+
recommendation?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Run a trust check against a counterparty agent.
|
|
28
|
+
*
|
|
29
|
+
* Advisory by default — populates TrustContext with warnings.
|
|
30
|
+
* Only blocks when `blockRevokedVc` is set and the VC is revoked,
|
|
31
|
+
* or when `blockUnregistered` is set and the DID cannot be resolved.
|
|
32
|
+
*/
|
|
33
|
+
export declare function checkTrust(client: Aira, policy: TrustPolicy, counterpartyId: string): Promise<TrustContext>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Trust layer types and helpers shared across all framework integrations.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkTrust = checkTrust;
|
|
7
|
+
/**
|
|
8
|
+
* Run a trust check against a counterparty agent.
|
|
9
|
+
*
|
|
10
|
+
* Advisory by default — populates TrustContext with warnings.
|
|
11
|
+
* Only blocks when `blockRevokedVc` is set and the VC is revoked,
|
|
12
|
+
* or when `blockUnregistered` is set and the DID cannot be resolved.
|
|
13
|
+
*/
|
|
14
|
+
async function checkTrust(client, policy, counterpartyId) {
|
|
15
|
+
const ctx = {
|
|
16
|
+
counterpartyId,
|
|
17
|
+
blocked: false,
|
|
18
|
+
};
|
|
19
|
+
// Step 1: Resolve DID
|
|
20
|
+
if (policy.verifyCounterparty || policy.requireValidVc || policy.blockUnregistered) {
|
|
21
|
+
try {
|
|
22
|
+
const didResult = await client.resolveDid(`did:web:airaproof.com:agents:${counterpartyId}`);
|
|
23
|
+
ctx.didResolved = true;
|
|
24
|
+
ctx.did = didResult.did;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
ctx.didResolved = false;
|
|
28
|
+
if (policy.blockUnregistered) {
|
|
29
|
+
ctx.blocked = true;
|
|
30
|
+
ctx.blockReason = `Agent '${counterpartyId}' DID could not be resolved`;
|
|
31
|
+
return ctx;
|
|
32
|
+
}
|
|
33
|
+
ctx.recommendation = `Could not resolve DID for '${counterpartyId}' — proceed with caution`;
|
|
34
|
+
return ctx;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Step 2: Verify credential
|
|
38
|
+
if (policy.requireValidVc || policy.blockRevokedVc) {
|
|
39
|
+
try {
|
|
40
|
+
const cred = await client.getAgentCredential(counterpartyId);
|
|
41
|
+
const verification = await client.verifyCredential(cred);
|
|
42
|
+
const valid = verification.valid;
|
|
43
|
+
ctx.vcValid = valid;
|
|
44
|
+
if (!valid && policy.blockRevokedVc) {
|
|
45
|
+
ctx.blocked = true;
|
|
46
|
+
ctx.blockReason = `Agent '${counterpartyId}' has a revoked or invalid credential`;
|
|
47
|
+
return ctx;
|
|
48
|
+
}
|
|
49
|
+
if (!valid) {
|
|
50
|
+
ctx.recommendation = `Credential for '${counterpartyId}' is invalid — proceed with caution`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
ctx.vcValid = null;
|
|
55
|
+
if (policy.blockRevokedVc) {
|
|
56
|
+
ctx.recommendation = `Could not verify credential for '${counterpartyId}' — treating as unknown`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Step 3: Check reputation
|
|
61
|
+
if (policy.minReputation != null) {
|
|
62
|
+
try {
|
|
63
|
+
const rep = await client.getReputation(counterpartyId);
|
|
64
|
+
ctx.reputationScore = rep.score;
|
|
65
|
+
ctx.reputationTier = rep.tier;
|
|
66
|
+
if (ctx.reputationScore != null && ctx.reputationScore < policy.minReputation) {
|
|
67
|
+
ctx.reputationWarning = `Reputation ${ctx.reputationScore} is below minimum ${policy.minReputation}`;
|
|
68
|
+
ctx.recommendation = ctx.reputationWarning;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
ctx.reputationScore = null;
|
|
73
|
+
ctx.reputationWarning = `Could not fetch reputation for '${counterpartyId}'`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return ctx;
|
|
77
|
+
}
|
|
@@ -9,13 +9,22 @@
|
|
|
9
9
|
* // Use as wrap around tool calls or stream callbacks
|
|
10
10
|
*/
|
|
11
11
|
import type { Aira } from "../client";
|
|
12
|
+
import type { TrustPolicy, TrustContext } from "./trust";
|
|
13
|
+
export type { TrustPolicy, TrustContext } from "./trust";
|
|
12
14
|
export declare class AiraVercelMiddleware {
|
|
13
15
|
private client;
|
|
14
16
|
private agentId;
|
|
15
17
|
private modelId?;
|
|
18
|
+
private trustPolicy?;
|
|
16
19
|
constructor(client: Aira, agentId: string, options?: {
|
|
17
20
|
modelId?: string;
|
|
21
|
+
trustPolicy?: TrustPolicy;
|
|
18
22
|
});
|
|
23
|
+
/**
|
|
24
|
+
* Check trust for a counterparty agent before interacting.
|
|
25
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
26
|
+
*/
|
|
27
|
+
checkTrust(counterpartyId: string): Promise<TrustContext>;
|
|
19
28
|
private notarize;
|
|
20
29
|
/** Call after a tool execution to notarize it. */
|
|
21
30
|
onToolCall(toolName: string, argKeys?: string[]): void;
|
package/dist/extras/vercel-ai.js
CHANGED
|
@@ -11,15 +11,28 @@
|
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.AiraVercelMiddleware = void 0;
|
|
14
|
+
const trust_1 = require("./trust");
|
|
14
15
|
const MAX_DETAILS = 5000;
|
|
15
16
|
class AiraVercelMiddleware {
|
|
16
17
|
client;
|
|
17
18
|
agentId;
|
|
18
19
|
modelId;
|
|
20
|
+
trustPolicy;
|
|
19
21
|
constructor(client, agentId, options) {
|
|
20
22
|
this.client = client;
|
|
21
23
|
this.agentId = agentId;
|
|
22
24
|
this.modelId = options?.modelId;
|
|
25
|
+
this.trustPolicy = options?.trustPolicy;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check trust for a counterparty agent before interacting.
|
|
29
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
30
|
+
*/
|
|
31
|
+
async checkTrust(counterpartyId) {
|
|
32
|
+
if (!this.trustPolicy) {
|
|
33
|
+
return { counterpartyId, blocked: false, recommendation: "No trust policy configured" };
|
|
34
|
+
}
|
|
35
|
+
return (0, trust_1.checkTrust)(this.client, this.trustPolicy, counterpartyId);
|
|
23
36
|
}
|
|
24
37
|
notarize(actionType, details) {
|
|
25
38
|
try {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/** Cryptographic receipt from notarizing an action. */
|
|
2
2
|
export interface ActionReceipt {
|
|
3
3
|
action_id: string;
|
|
4
|
+
receipt_id: string;
|
|
4
5
|
payload_hash: string;
|
|
5
6
|
signature: string;
|
|
6
|
-
|
|
7
|
-
action_type: string;
|
|
8
|
-
agent_id: string | null;
|
|
7
|
+
timestamp_token: string | null;
|
|
9
8
|
created_at: string;
|
|
9
|
+
request_id: string;
|
|
10
|
+
action_type?: string;
|
|
11
|
+
agent_id?: string | null;
|
|
12
|
+
warnings?: string[] | null;
|
|
10
13
|
}
|
|
11
14
|
/** Full action details including receipt and authorizations. */
|
|
12
15
|
export interface ActionDetail {
|
|
@@ -66,46 +69,62 @@ export interface EvidencePackage {
|
|
|
66
69
|
id: string;
|
|
67
70
|
title: string;
|
|
68
71
|
description: string | null;
|
|
72
|
+
action_ids: string[];
|
|
69
73
|
package_hash: string;
|
|
70
74
|
signature: string;
|
|
71
|
-
|
|
75
|
+
status: string;
|
|
72
76
|
created_at: string;
|
|
77
|
+
request_id: string;
|
|
78
|
+
agent_slugs?: string[] | null;
|
|
73
79
|
}
|
|
74
80
|
/** Compliance snapshot. */
|
|
75
81
|
export interface ComplianceSnapshot {
|
|
76
82
|
id: string;
|
|
77
83
|
framework: string;
|
|
78
|
-
agent_slug: string | null;
|
|
79
|
-
findings: Record<string, string>;
|
|
80
84
|
status: string;
|
|
85
|
+
findings: Record<string, string>;
|
|
86
|
+
snapshot_hash: string;
|
|
87
|
+
signature: string;
|
|
88
|
+
snapshot_at: string;
|
|
81
89
|
created_at: string;
|
|
90
|
+
request_id: string;
|
|
91
|
+
agent_id?: string | null;
|
|
82
92
|
}
|
|
83
93
|
/** Escrow account. */
|
|
84
94
|
export interface EscrowAccount {
|
|
85
95
|
id: string;
|
|
86
|
-
status: string;
|
|
87
96
|
currency: string;
|
|
88
97
|
balance: string;
|
|
89
|
-
|
|
98
|
+
status: string;
|
|
90
99
|
created_at: string;
|
|
100
|
+
request_id: string;
|
|
101
|
+
agent_id?: string | null;
|
|
102
|
+
counterparty_org_id?: string | null;
|
|
103
|
+
purpose?: string | null;
|
|
104
|
+
transactions?: EscrowTransaction[];
|
|
91
105
|
}
|
|
92
106
|
/** Escrow transaction (deposit, release, dispute). */
|
|
93
107
|
export interface EscrowTransaction {
|
|
94
108
|
id: string;
|
|
95
109
|
transaction_type: string;
|
|
96
110
|
amount: string;
|
|
97
|
-
|
|
111
|
+
currency: string;
|
|
98
112
|
transaction_hash: string;
|
|
99
113
|
signature: string;
|
|
114
|
+
status: string;
|
|
100
115
|
created_at: string;
|
|
116
|
+
description?: string | null;
|
|
117
|
+
reference_action_id?: string | null;
|
|
101
118
|
}
|
|
102
119
|
/** Public verification result. */
|
|
103
120
|
export interface VerifyResult {
|
|
104
121
|
valid: boolean;
|
|
105
|
-
receipt_id: string | null;
|
|
106
|
-
verified_at: string;
|
|
107
122
|
public_key_id: string;
|
|
108
123
|
message: string;
|
|
124
|
+
verified_at: string;
|
|
125
|
+
request_id: string;
|
|
126
|
+
receipt_id?: string | null;
|
|
127
|
+
action_id?: string | null;
|
|
109
128
|
}
|
|
110
129
|
/** Paginated list response. */
|
|
111
130
|
export interface PaginatedList<T = Record<string, unknown>> {
|