aira-sdk 0.1.3 → 0.2.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 +214 -106
- package/dist/client.d.ts +9 -0
- package/dist/client.js +33 -0
- package/dist/extras/index.d.ts +19 -0
- package/dist/extras/index.js +29 -0
- package/dist/extras/langchain.d.ts +33 -0
- package/dist/extras/langchain.js +82 -0
- package/dist/extras/mcp.d.ts +49 -0
- package/dist/extras/mcp.js +101 -0
- package/dist/extras/openai-agents.d.ts +29 -0
- package/dist/extras/openai-agents.js +69 -0
- package/dist/extras/vercel-ai.d.ts +39 -0
- package/dist/extras/vercel-ai.js +89 -0
- package/dist/extras/webhooks.d.ts +34 -0
- package/dist/extras/webhooks.js +59 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/offline.d.ts +16 -0
- package/dist/offline.js +27 -0
- package/dist/session.d.ts +20 -0
- package/dist/session.js +24 -0
- package/package.json +57 -2
package/README.md
CHANGED
|
@@ -1,171 +1,250 @@
|
|
|
1
1
|
# Aira TypeScript SDK
|
|
2
2
|
|
|
3
|
-
**Legal infrastructure for AI agents.**
|
|
3
|
+
**Legal infrastructure for AI agents.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/aira-sdk)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- **Notarize actions** — cryptographic receipts for every agent decision, email, transaction
|
|
9
|
-
- **Register agents** — verifiable identity with versioned configs and public profiles
|
|
10
|
-
- **Multi-model consensus** — run the same decision through multiple AI models, flag disagreements
|
|
11
|
-
- **Evidence packages** — sealed, tamper-proof bundles for legal discovery and audit
|
|
12
|
-
- **Agent lifecycle** — wills, succession plans, death certificates, compliance snapshots
|
|
13
|
-
- **Liability commitments** — record accountability commitments with cryptographic proof
|
|
14
|
-
- **Human authorization** — require human co-signatures on high-stakes actions
|
|
15
|
-
- **Public verification** — anyone can verify a receipt without an account
|
|
8
|
+
Aira produces cryptographic receipts for every action your AI agent takes. Ed25519 signatures and RFC 3161 timestamps create tamper-proof, court-admissible proof of what happened, who authorized it, and which model made the decision. Built for EU AI Act, SR 11-7, and GDPR compliance.
|
|
16
9
|
|
|
17
|
-
|
|
10
|
+
---
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
## Integration Matrix
|
|
13
|
+
|
|
14
|
+
Drop Aira into your existing agent framework with one import:
|
|
15
|
+
|
|
16
|
+
| Framework | Import | Integration |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| **LangChain.js** | `import { AiraCallbackHandler } from "aira-sdk/extras/langchain"` | Callback handler |
|
|
19
|
+
| **Vercel AI** | `import { AiraVercelMiddleware } from "aira-sdk/extras/vercel-ai"` | Middleware |
|
|
20
|
+
| **OpenAI Agents** | `import { AiraGuardrail } from "aira-sdk/extras/openai-agents"` | Guardrail |
|
|
21
|
+
| **MCP** | `import { createServer } from "aira-sdk/extras/mcp"` | MCP Server |
|
|
22
|
+
| **Webhooks** | `import { verifySignature } from "aira-sdk/extras/webhooks"` | Verification |
|
|
23
|
+
|
|
24
|
+
Or install the core SDK alone:
|
|
21
25
|
|
|
22
26
|
```bash
|
|
23
27
|
npm install aira-sdk
|
|
24
28
|
```
|
|
25
29
|
|
|
30
|
+
---
|
|
31
|
+
|
|
26
32
|
## Quick Start
|
|
27
33
|
|
|
34
|
+
Every call to `notarize()` returns a cryptographic receipt -- Ed25519-signed, timestamped, tamper-proof.
|
|
35
|
+
|
|
28
36
|
```typescript
|
|
29
37
|
import { Aira } from "aira-sdk";
|
|
30
38
|
|
|
31
39
|
const aira = new Aira({ apiKey: "aira_live_xxx" });
|
|
32
40
|
|
|
33
|
-
// Notarize an agent action
|
|
34
41
|
const receipt = await aira.notarize({
|
|
35
42
|
actionType: "email_sent",
|
|
36
43
|
details: "Sent onboarding email to customer@example.com",
|
|
37
44
|
agentId: "support-agent",
|
|
38
45
|
modelId: "claude-sonnet-4-6",
|
|
46
|
+
instructionHash: "sha256:a1b2c3...",
|
|
39
47
|
});
|
|
40
48
|
|
|
41
|
-
console.log(receipt.
|
|
42
|
-
console.log(receipt.
|
|
49
|
+
console.log(receipt.payload_hash); // sha256:e5f6a7b8...
|
|
50
|
+
console.log(receipt.signature); // ed25519:base64url...
|
|
51
|
+
console.log(receipt.action_id); // uuid — publicly verifiable
|
|
43
52
|
```
|
|
44
53
|
|
|
45
|
-
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Framework Integrations
|
|
57
|
+
|
|
58
|
+
### LangChain.js
|
|
59
|
+
|
|
60
|
+
`AiraCallbackHandler` notarizes every tool call, chain completion, and LLM invocation with a cryptographic receipt. No changes to your chain logic.
|
|
46
61
|
|
|
47
62
|
```typescript
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
displayName: "Loan Decision Engine",
|
|
51
|
-
capabilities: ["credit_scoring", "risk_assessment"],
|
|
52
|
-
public: true,
|
|
53
|
-
});
|
|
63
|
+
import { Aira } from "aira-sdk";
|
|
64
|
+
import { AiraCallbackHandler } from "aira-sdk/extras/langchain";
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
modelId: "claude-sonnet-4-6",
|
|
58
|
-
changelog: "Initial release",
|
|
59
|
-
});
|
|
66
|
+
const aira = new Aira({ apiKey: "aira_live_xxx" });
|
|
67
|
+
const handler = new AiraCallbackHandler({ client: aira, agentId: "research-agent", modelId: "gpt-4o" });
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
// Every tool call and chain completion gets a signed receipt
|
|
70
|
+
const result = await chain.invoke({ input: "Analyze Q1 revenue" }, { callbacks: [handler] });
|
|
63
71
|
```
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
### Vercel AI
|
|
74
|
+
|
|
75
|
+
`AiraVercelMiddleware` wraps your Vercel AI `streamText` / `generateText` calls so every model invocation is notarized with a tamper-proof receipt.
|
|
66
76
|
|
|
67
77
|
```typescript
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
actionType: "loan_approved",
|
|
71
|
-
details: "Approved loan #4521 for €25,000",
|
|
72
|
-
agentId: "lending-agent",
|
|
73
|
-
modelId: "claude-sonnet-4-6",
|
|
74
|
-
idempotencyKey: "loan-4521",
|
|
75
|
-
});
|
|
78
|
+
import { Aira } from "aira-sdk";
|
|
79
|
+
import { AiraVercelMiddleware } from "aira-sdk/extras/vercel-ai";
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const aira = new Aira({ apiKey: "aira_live_xxx" });
|
|
82
|
+
const middleware = new AiraVercelMiddleware({ client: aira, agentId: "assistant-agent" });
|
|
83
|
+
|
|
84
|
+
// Wrap your Vercel AI calls — receipts at invocation and completion
|
|
85
|
+
const result = await middleware.wrapGenerateText({
|
|
86
|
+
model: openai("gpt-4o"),
|
|
87
|
+
prompt: "Summarize the contract terms",
|
|
83
88
|
});
|
|
89
|
+
```
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
const chain = await aira.getActionChain(decision.action_id);
|
|
91
|
+
### OpenAI Agents SDK
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
`AiraGuardrail` wraps any tool function to automatically notarize both invocation and result with cryptographic proof.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { Aira } from "aira-sdk";
|
|
97
|
+
import { AiraGuardrail } from "aira-sdk/extras/openai-agents";
|
|
90
98
|
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
const aira = new Aira({ apiKey: "aira_live_xxx" });
|
|
100
|
+
const guardrail = new AiraGuardrail({ client: aira, agentId: "assistant-agent" });
|
|
101
|
+
|
|
102
|
+
// Wrap tools — every call and result gets a signed receipt
|
|
103
|
+
const search = guardrail.wrapTool(searchTool, { toolName: "web_search" });
|
|
104
|
+
const execute = guardrail.wrapTool(codeExecutor, { toolName: "code_exec" });
|
|
93
105
|
```
|
|
94
106
|
|
|
95
|
-
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## MCP Server
|
|
110
|
+
|
|
111
|
+
Expose Aira as an MCP tool server. Any MCP-compatible AI agent can notarize actions and verify receipts without SDK integration.
|
|
96
112
|
|
|
97
113
|
```typescript
|
|
98
|
-
|
|
99
|
-
"Should we approve loan #4521?",
|
|
100
|
-
["claude-sonnet-4-6", "gpt-4o", "gemini-2.0-flash"],
|
|
101
|
-
);
|
|
114
|
+
import { createServer } from "aira-sdk/extras/mcp";
|
|
102
115
|
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
const server = createServer({ apiKey: "aira_live_xxx" });
|
|
117
|
+
server.listen(); // stdio transport
|
|
105
118
|
```
|
|
106
119
|
|
|
107
|
-
|
|
120
|
+
The server exposes three tools: `notarize_action`, `verify_action`, and `get_receipt` -- each producing cryptographically signed results.
|
|
108
121
|
|
|
109
|
-
|
|
110
|
-
const pkg = await aira.createEvidencePackage({
|
|
111
|
-
title: "Q1 2026 Lending Audit",
|
|
112
|
-
actionIds: [decision.action_id, email.action_id],
|
|
113
|
-
description: "All lending decisions for regulatory review",
|
|
114
|
-
});
|
|
122
|
+
Add to your MCP client config:
|
|
115
123
|
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"mcpServers": {
|
|
127
|
+
"aira": {
|
|
128
|
+
"command": "npx",
|
|
129
|
+
"args": ["aira-sdk", "mcp"],
|
|
130
|
+
"env": { "AIRA_API_KEY": "aira_live_xxx" }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
118
134
|
```
|
|
119
135
|
|
|
120
|
-
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Session
|
|
139
|
+
|
|
140
|
+
Pre-fill defaults for a block of related actions. Every `notarize()` call within the session inherits the agent identity, producing receipts that share a common provenance chain.
|
|
121
141
|
|
|
122
142
|
```typescript
|
|
123
|
-
|
|
124
|
-
successorSlug: "lending-agent-v2",
|
|
125
|
-
successionPolicy: "transfer_to_successor",
|
|
126
|
-
dataRetentionDays: 2555,
|
|
127
|
-
notifyEmails: ["compliance@acme.com"],
|
|
128
|
-
});
|
|
143
|
+
const sess = aira.session("onboarding-agent", { modelId: "claude-sonnet-4-6" });
|
|
129
144
|
|
|
130
|
-
await
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
findings: { art_12_logging: "pass", art_14_oversight: "pass" },
|
|
134
|
-
});
|
|
145
|
+
await sess.notarize({ actionType: "identity_verified", details: "Verified customer ID #4521" });
|
|
146
|
+
await sess.notarize({ actionType: "account_created", details: "Created account for customer #4521" });
|
|
147
|
+
await sess.notarize({ actionType: "welcome_sent", details: "Sent welcome email to customer #4521" });
|
|
135
148
|
```
|
|
136
149
|
|
|
137
|
-
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Offline Mode
|
|
138
153
|
|
|
139
|
-
|
|
154
|
+
Queue notarizations locally when connectivity is unavailable. Cryptographic receipts are generated server-side when you sync -- nothing is lost.
|
|
140
155
|
|
|
141
156
|
```typescript
|
|
142
|
-
const
|
|
143
|
-
await aira.escrowDeposit(account.id, 15000, "Liability commitment for loan #4521");
|
|
144
|
-
await aira.escrowRelease(account.id, 15000, "Loan disbursed successfully");
|
|
145
|
-
```
|
|
157
|
+
const aira = new Aira({ apiKey: "aira_live_xxx", offline: true });
|
|
146
158
|
|
|
147
|
-
|
|
159
|
+
// These queue locally — no network calls
|
|
160
|
+
await aira.notarize({ actionType: "scan_completed", details: "Scanned document batch #77" });
|
|
161
|
+
await aira.notarize({ actionType: "classification_done", details: "Classified 142 documents" });
|
|
148
162
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
console.log(response.content);
|
|
163
|
+
console.log(aira.pendingCount); // 2
|
|
164
|
+
|
|
165
|
+
// Flush to API when back online — receipts are generated for each action
|
|
166
|
+
const results = await aira.sync();
|
|
154
167
|
```
|
|
155
168
|
|
|
156
|
-
|
|
169
|
+
---
|
|
157
170
|
|
|
158
|
-
|
|
171
|
+
## Webhook Verification
|
|
159
172
|
|
|
160
|
-
|
|
173
|
+
Verify that incoming webhooks are authentic Aira events, not forged requests. HMAC-SHA256 signature verification ensures tamper-proof delivery.
|
|
161
174
|
|
|
162
175
|
```typescript
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
176
|
+
import { verifySignature, parseEvent } from "aira-sdk/extras/webhooks";
|
|
177
|
+
|
|
178
|
+
// Verify the webhook signature (HMAC-SHA256)
|
|
179
|
+
const isValid = verifySignature({
|
|
180
|
+
payload: request.body,
|
|
181
|
+
signature: request.headers["x-aira-signature"],
|
|
182
|
+
secret: "whsec_xxx",
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
if (isValid) {
|
|
186
|
+
const event = parseEvent(request.body);
|
|
187
|
+
console.log(event.eventType); // "action.notarized"
|
|
188
|
+
console.log(event.data); // Action data with cryptographic receipt
|
|
189
|
+
console.log(event.deliveryId); // Unique delivery ID
|
|
190
|
+
}
|
|
167
191
|
```
|
|
168
192
|
|
|
193
|
+
Supported event types: `action.notarized`, `action.authorized`, `agent.registered`, `agent.decommissioned`, `evidence.sealed`, `escrow.deposited`, `escrow.released`, `escrow.disputed`, `compliance.snapshot_created`, `case.complete`, `case.requires_human_review`.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Core SDK Methods
|
|
198
|
+
|
|
199
|
+
All 40 methods on `Aira`. Every write operation produces a cryptographic receipt.
|
|
200
|
+
|
|
201
|
+
| Category | Method | Description |
|
|
202
|
+
|---|---|---|
|
|
203
|
+
| **Actions** | `notarize()` | Notarize an action -- returns Ed25519-signed receipt |
|
|
204
|
+
| | `getAction()` | Retrieve action details + receipt |
|
|
205
|
+
| | `listActions()` | List actions with filters (type, agent, status) |
|
|
206
|
+
| | `authorizeAction()` | Human co-signature on high-stakes action |
|
|
207
|
+
| | `setLegalHold()` | Prevent deletion -- litigation hold |
|
|
208
|
+
| | `releaseLegalHold()` | Release litigation hold |
|
|
209
|
+
| | `getActionChain()` | Chain of custody for an action |
|
|
210
|
+
| | `verifyAction()` | Public verification -- no auth required |
|
|
211
|
+
| **Agents** | `registerAgent()` | Register verifiable agent identity |
|
|
212
|
+
| | `getAgent()` | Retrieve agent profile |
|
|
213
|
+
| | `listAgents()` | List registered agents |
|
|
214
|
+
| | `updateAgent()` | Update agent metadata |
|
|
215
|
+
| | `publishVersion()` | Publish versioned agent config |
|
|
216
|
+
| | `listVersions()` | List agent versions |
|
|
217
|
+
| | `decommissionAgent()` | Decommission agent |
|
|
218
|
+
| | `transferAgent()` | Transfer ownership to another org |
|
|
219
|
+
| | `getAgentActions()` | List actions by agent |
|
|
220
|
+
| **Cases** | `runCase()` | Multi-model consensus adjudication |
|
|
221
|
+
| | `getCase()` | Retrieve case result |
|
|
222
|
+
| | `listCases()` | List cases |
|
|
223
|
+
| **Receipts** | `getReceipt()` | Retrieve cryptographic receipt |
|
|
224
|
+
| | `exportReceipt()` | Export receipt as JSON or PDF |
|
|
225
|
+
| **Evidence** | `createEvidencePackage()` | Sealed, tamper-proof evidence bundle |
|
|
226
|
+
| | `listEvidencePackages()` | List evidence packages |
|
|
227
|
+
| | `getEvidencePackage()` | Retrieve evidence package |
|
|
228
|
+
| | `timeTravel()` | Query actions at a point in time |
|
|
229
|
+
| | `liabilityChain()` | Walk full liability chain |
|
|
230
|
+
| **Estate** | `setAgentWill()` | Define succession plan |
|
|
231
|
+
| | `getAgentWill()` | Retrieve agent will |
|
|
232
|
+
| | `issueDeathCertificate()` | Decommission with succession trigger |
|
|
233
|
+
| | `getDeathCertificate()` | Retrieve death certificate |
|
|
234
|
+
| | `createComplianceSnapshot()` | Compliance snapshot (EU AI Act, SR 11-7, GDPR) |
|
|
235
|
+
| | `listComplianceSnapshots()` | List snapshots by framework |
|
|
236
|
+
| **Escrow** | `createEscrowAccount()` | Create liability commitment ledger |
|
|
237
|
+
| | `listEscrowAccounts()` | List escrow accounts |
|
|
238
|
+
| | `getEscrowAccount()` | Retrieve escrow account |
|
|
239
|
+
| | `escrowDeposit()` | Record liability commitment |
|
|
240
|
+
| | `escrowRelease()` | Release commitment after completion |
|
|
241
|
+
| | `escrowDispute()` | Dispute -- flag liability issue |
|
|
242
|
+
| **Chat** | `ask()` | Query your notarized data via AI |
|
|
243
|
+
| **Offline** | `sync()` | Flush offline queue to API |
|
|
244
|
+
| **Session** | `session()` | Scoped session with pre-filled defaults |
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
169
248
|
## Error Handling
|
|
170
249
|
|
|
171
250
|
```typescript
|
|
@@ -182,24 +261,53 @@ try {
|
|
|
182
261
|
}
|
|
183
262
|
```
|
|
184
263
|
|
|
264
|
+
All framework integrations (LangChain.js, Vercel AI, OpenAI Agents) are non-blocking by default -- notarization failures are logged, never raised. Your agent keeps running.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
185
268
|
## Configuration
|
|
186
269
|
|
|
187
270
|
```typescript
|
|
188
271
|
const aira = new Aira({
|
|
189
|
-
apiKey: "aira_live_xxx",
|
|
190
|
-
baseUrl: "https://your-self-hosted.com",
|
|
191
|
-
timeout: 60_000,
|
|
272
|
+
apiKey: "aira_live_xxx", // Required — aira_live_ or aira_test_ prefix
|
|
273
|
+
baseUrl: "https://your-self-hosted.com", // Self-hosted deployment
|
|
274
|
+
timeout: 60_000, // Request timeout in ms
|
|
275
|
+
offline: true, // Queue locally, sync later
|
|
192
276
|
});
|
|
193
277
|
```
|
|
194
278
|
|
|
195
|
-
|
|
279
|
+
| Env Variable | Description |
|
|
280
|
+
|---|---|
|
|
281
|
+
| `AIRA_API_KEY` | API key (used by MCP server) |
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## SDK Parity
|
|
286
|
+
|
|
287
|
+
| Feature | Python | TypeScript |
|
|
288
|
+
|---|---|---|
|
|
289
|
+
| Core API (40 methods) | Yes | Yes |
|
|
290
|
+
| LangChain | Yes | Yes |
|
|
291
|
+
| CrewAI | Yes | -- (Python-only) |
|
|
292
|
+
| Vercel AI | -- (JS-only) | Yes |
|
|
293
|
+
| OpenAI Agents | Yes | Yes |
|
|
294
|
+
| Google ADK | Yes (Python-only) | -- |
|
|
295
|
+
| AWS Bedrock | Yes (Python-only) | -- |
|
|
296
|
+
| MCP Server | Yes | Yes |
|
|
297
|
+
| Webhooks | Yes | Yes |
|
|
298
|
+
| CLI | Yes | -- (use Python CLI) |
|
|
299
|
+
| Offline Mode | Yes | Yes |
|
|
300
|
+
| Session | Yes | Yes |
|
|
196
301
|
|
|
197
|
-
|
|
302
|
+
---
|
|
198
303
|
|
|
199
304
|
## Links
|
|
200
305
|
|
|
201
|
-
- [
|
|
306
|
+
- [Website](https://airaproof.com)
|
|
307
|
+
- [npm Package](https://www.npmjs.com/package/aira-sdk)
|
|
308
|
+
- [Python SDK (PyPI)](https://pypi.org/project/aira-sdk/)
|
|
202
309
|
- [Documentation](https://docs.airaproof.com)
|
|
203
310
|
- [API Reference](https://docs.airaproof.com/docs/api-reference)
|
|
204
|
-
- [
|
|
311
|
+
- [Interactive Demo](https://app.airaproof.com/demo) -- try Aira in your browser, no code needed
|
|
205
312
|
- [Dashboard](https://app.airaproof.com)
|
|
313
|
+
- [GitHub](https://github.com/aira-proof/typescript-sdk)
|
package/dist/client.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { ActionReceipt, ActionDetail, AgentDetail, AgentVersion, EvidencePackage, ComplianceSnapshot, EscrowAccount, EscrowTransaction, VerifyResult, PaginatedList } from "./types";
|
|
2
|
+
import { AiraSession } from "./session";
|
|
2
3
|
export interface AiraOptions {
|
|
3
4
|
apiKey: string;
|
|
4
5
|
baseUrl?: string;
|
|
5
6
|
timeout?: number;
|
|
7
|
+
offline?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export declare class Aira {
|
|
8
10
|
private baseUrl;
|
|
9
11
|
private apiKey;
|
|
10
12
|
private timeout;
|
|
13
|
+
private queue;
|
|
11
14
|
constructor(options: AiraOptions);
|
|
12
15
|
private request;
|
|
13
16
|
private get;
|
|
@@ -126,4 +129,10 @@ export declare class Aira {
|
|
|
126
129
|
tools_used: string[];
|
|
127
130
|
model_id?: string;
|
|
128
131
|
}>;
|
|
132
|
+
/** Create a scoped session with pre-filled defaults. */
|
|
133
|
+
session(agentId: string, defaults?: Record<string, unknown>): AiraSession;
|
|
134
|
+
/** Number of queued offline requests. */
|
|
135
|
+
get pendingCount(): number;
|
|
136
|
+
/** Flush offline queue to API. Returns list of API responses. */
|
|
137
|
+
sync(): Promise<Record<string, unknown>[]>;
|
|
129
138
|
}
|
package/dist/client.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Aira = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
+
const offline_1 = require("./offline");
|
|
6
|
+
const session_1 = require("./session");
|
|
5
7
|
const DEFAULT_BASE_URL = "https://api.airaproof.com";
|
|
6
8
|
const DEFAULT_TIMEOUT = 30_000;
|
|
7
9
|
const MAX_DETAILS_LENGTH = 50_000;
|
|
@@ -15,6 +17,7 @@ class Aira {
|
|
|
15
17
|
baseUrl;
|
|
16
18
|
apiKey;
|
|
17
19
|
timeout;
|
|
20
|
+
queue;
|
|
18
21
|
constructor(options) {
|
|
19
22
|
if (!options.apiKey)
|
|
20
23
|
throw new Error("apiKey is required");
|
|
@@ -24,6 +27,7 @@ class Aira {
|
|
|
24
27
|
this.apiKey = options.apiKey;
|
|
25
28
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "") + "/api/v1";
|
|
26
29
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
30
|
+
this.queue = options.offline ? new offline_1.OfflineQueue() : null;
|
|
27
31
|
}
|
|
28
32
|
async request(method, path, body, auth = true) {
|
|
29
33
|
const controller = new AbortController();
|
|
@@ -51,10 +55,17 @@ class Aira {
|
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
get(path, params, auth = true) {
|
|
58
|
+
if (this.queue) {
|
|
59
|
+
throw new types_1.AiraError(0, "OFFLINE", "GET requests not available in offline mode");
|
|
60
|
+
}
|
|
54
61
|
const qs = params ? "?" + new URLSearchParams(Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])).toString() : "";
|
|
55
62
|
return this.request("GET", path + qs, undefined, auth);
|
|
56
63
|
}
|
|
57
64
|
post(path, body) {
|
|
65
|
+
if (this.queue) {
|
|
66
|
+
const qid = this.queue.enqueue("POST", path, body);
|
|
67
|
+
return Promise.resolve({ _offline: true, _queue_id: qid });
|
|
68
|
+
}
|
|
58
69
|
return this.request("POST", path, body);
|
|
59
70
|
}
|
|
60
71
|
put(path, body) {
|
|
@@ -250,5 +261,27 @@ class Aira {
|
|
|
250
261
|
async ask(message, params) {
|
|
251
262
|
return this.post("/chat", buildBody({ message, history: params?.history, model: params?.model }));
|
|
252
263
|
}
|
|
264
|
+
// ==================== Session ====================
|
|
265
|
+
/** Create a scoped session with pre-filled defaults. */
|
|
266
|
+
session(agentId, defaults) {
|
|
267
|
+
return new session_1.AiraSession(this, agentId, defaults);
|
|
268
|
+
}
|
|
269
|
+
// ==================== Offline sync ====================
|
|
270
|
+
/** Number of queued offline requests. */
|
|
271
|
+
get pendingCount() {
|
|
272
|
+
return this.queue?.pendingCount ?? 0;
|
|
273
|
+
}
|
|
274
|
+
/** Flush offline queue to API. Returns list of API responses. */
|
|
275
|
+
async sync() {
|
|
276
|
+
if (!this.queue)
|
|
277
|
+
throw new Error("sync() is only available in offline mode");
|
|
278
|
+
const items = this.queue.drain();
|
|
279
|
+
const results = [];
|
|
280
|
+
for (const item of items) {
|
|
281
|
+
const res = await this.request(item.method, item.path, item.body);
|
|
282
|
+
results.push(res);
|
|
283
|
+
}
|
|
284
|
+
return results;
|
|
285
|
+
}
|
|
253
286
|
}
|
|
254
287
|
exports.Aira = Aira;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aira SDK extras — framework integrations.
|
|
3
|
+
*
|
|
4
|
+
* Each integration is in its own file to avoid importing unnecessary dependencies.
|
|
5
|
+
* Import directly from the subpath:
|
|
6
|
+
*
|
|
7
|
+
* import { AiraCallbackHandler } from "aira-sdk/extras/langchain";
|
|
8
|
+
* import { AiraVercelMiddleware } from "aira-sdk/extras/vercel-ai";
|
|
9
|
+
* import { AiraGuardrail } from "aira-sdk/extras/openai-agents";
|
|
10
|
+
* import { createServer } from "aira-sdk/extras/mcp";
|
|
11
|
+
* import { verifySignature, parseEvent } from "aira-sdk/extras/webhooks";
|
|
12
|
+
*/
|
|
13
|
+
export { AiraCallbackHandler } from "./langchain";
|
|
14
|
+
export { AiraVercelMiddleware } from "./vercel-ai";
|
|
15
|
+
export { AiraGuardrail } from "./openai-agents";
|
|
16
|
+
export { createServer, getTools, handleToolCall } from "./mcp";
|
|
17
|
+
export type { MCPTool, MCPTextContent } from "./mcp";
|
|
18
|
+
export { verifySignature, parseEvent, WebhookEventType } from "./webhooks";
|
|
19
|
+
export type { WebhookEvent, WebhookEventTypeName } from "./webhooks";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Aira SDK extras — framework integrations.
|
|
4
|
+
*
|
|
5
|
+
* Each integration is in its own file to avoid importing unnecessary dependencies.
|
|
6
|
+
* Import directly from the subpath:
|
|
7
|
+
*
|
|
8
|
+
* import { AiraCallbackHandler } from "aira-sdk/extras/langchain";
|
|
9
|
+
* import { AiraVercelMiddleware } from "aira-sdk/extras/vercel-ai";
|
|
10
|
+
* import { AiraGuardrail } from "aira-sdk/extras/openai-agents";
|
|
11
|
+
* import { createServer } from "aira-sdk/extras/mcp";
|
|
12
|
+
* import { verifySignature, parseEvent } from "aira-sdk/extras/webhooks";
|
|
13
|
+
*/
|
|
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;
|
|
16
|
+
var langchain_1 = require("./langchain");
|
|
17
|
+
Object.defineProperty(exports, "AiraCallbackHandler", { enumerable: true, get: function () { return langchain_1.AiraCallbackHandler; } });
|
|
18
|
+
var vercel_ai_1 = require("./vercel-ai");
|
|
19
|
+
Object.defineProperty(exports, "AiraVercelMiddleware", { enumerable: true, get: function () { return vercel_ai_1.AiraVercelMiddleware; } });
|
|
20
|
+
var openai_agents_1 = require("./openai-agents");
|
|
21
|
+
Object.defineProperty(exports, "AiraGuardrail", { enumerable: true, get: function () { return openai_agents_1.AiraGuardrail; } });
|
|
22
|
+
var mcp_1 = require("./mcp");
|
|
23
|
+
Object.defineProperty(exports, "createServer", { enumerable: true, get: function () { return mcp_1.createServer; } });
|
|
24
|
+
Object.defineProperty(exports, "getTools", { enumerable: true, get: function () { return mcp_1.getTools; } });
|
|
25
|
+
Object.defineProperty(exports, "handleToolCall", { enumerable: true, get: function () { return mcp_1.handleToolCall; } });
|
|
26
|
+
var webhooks_1 = require("./webhooks");
|
|
27
|
+
Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return webhooks_1.verifySignature; } });
|
|
28
|
+
Object.defineProperty(exports, "parseEvent", { enumerable: true, get: function () { return webhooks_1.parseEvent; } });
|
|
29
|
+
Object.defineProperty(exports, "WebhookEventType", { enumerable: true, get: function () { return webhooks_1.WebhookEventType; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain.js integration — auto-notarize tool and chain completions.
|
|
3
|
+
*
|
|
4
|
+
* Requires: @langchain/core (peer dependency)
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { AiraCallbackHandler } from "aira-sdk/extras/langchain";
|
|
8
|
+
* const handler = new AiraCallbackHandler(aira, "my-agent");
|
|
9
|
+
* const chain = someChain.withConfig({ callbacks: [handler] });
|
|
10
|
+
*/
|
|
11
|
+
import type { Aira } from "../client";
|
|
12
|
+
export declare class AiraCallbackHandler {
|
|
13
|
+
private client;
|
|
14
|
+
private agentId;
|
|
15
|
+
private modelId?;
|
|
16
|
+
private actionTypes;
|
|
17
|
+
constructor(client: Aira, agentId: string, options?: {
|
|
18
|
+
modelId?: string;
|
|
19
|
+
actionTypes?: Record<string, string>;
|
|
20
|
+
});
|
|
21
|
+
private notarize;
|
|
22
|
+
/** Called when a tool finishes. */
|
|
23
|
+
handleToolEnd(output: string, name?: string): void;
|
|
24
|
+
/** Called when a chain finishes. */
|
|
25
|
+
handleChainEnd(outputs: Record<string, unknown>): void;
|
|
26
|
+
/** Called when an LLM finishes. */
|
|
27
|
+
handleLLMEnd(generationCount: number): void;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a LangChain-compatible callbacks object.
|
|
30
|
+
* Use with: chain.invoke(input, { callbacks: [handler.asCallbacks()] })
|
|
31
|
+
*/
|
|
32
|
+
asCallbacks(): Record<string, (...args: unknown[]) => void>;
|
|
33
|
+
}
|