@vorim/sdk 1.0.1 → 2.0.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 +224 -47
- package/dist/integrations/crewai.cjs +141 -0
- package/dist/integrations/crewai.cjs.map +1 -0
- package/dist/integrations/crewai.d.cts +174 -0
- package/dist/integrations/crewai.d.ts +174 -0
- package/dist/integrations/crewai.js +111 -0
- package/dist/integrations/crewai.js.map +1 -0
- package/dist/integrations/langchain.cjs +197 -0
- package/dist/integrations/langchain.cjs.map +1 -0
- package/dist/integrations/langchain.d.cts +145 -0
- package/dist/integrations/langchain.d.ts +145 -0
- package/dist/integrations/langchain.js +169 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/integrations/llamaindex.cjs +162 -0
- package/dist/integrations/llamaindex.cjs.map +1 -0
- package/dist/integrations/llamaindex.d.cts +131 -0
- package/dist/integrations/llamaindex.d.ts +131 -0
- package/dist/integrations/llamaindex.js +134 -0
- package/dist/integrations/llamaindex.js.map +1 -0
- package/dist/integrations/openai.cjs +208 -0
- package/dist/integrations/openai.cjs.map +1 -0
- package/dist/integrations/openai.d.cts +189 -0
- package/dist/integrations/openai.d.ts +189 -0
- package/dist/integrations/openai.js +181 -0
- package/dist/integrations/openai.js.map +1 -0
- package/package.json +51 -4
package/README.md
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
# @vorim/sdk
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
**The identity and trust layer for AI agents.**
|
|
4
4
|
|
|
5
|
-
Register agents with cryptographic identities, enforce scoped permissions, emit tamper-evident audit trails, and verify trust scores — all in a few lines of code.
|
|
5
|
+
Register agents with cryptographic Ed25519 identities, enforce scoped permissions in under 5ms, emit tamper-evident audit trails, and verify trust scores — all in a few lines of code.
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/@vorim/sdk)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
[](https://nodejs.org/)
|
|
11
|
+
[]()
|
|
12
|
+
|
|
13
|
+
> **[vorim.ai](https://vorim.ai)** — Create a free account and get your API key in 30 seconds.
|
|
14
|
+
> **[Documentation](https://vorim.ai/docs)** — Full API reference, framework integrations, and examples.
|
|
15
|
+
> **[Quick Start](https://vorim.ai/quickstart)** — Set up in under 5 minutes.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Why Vorim?
|
|
20
|
+
|
|
21
|
+
AI agents are shipping into production without identity, permissions, or audit trails. This is a problem:
|
|
22
|
+
|
|
23
|
+
- **No identity** — agents share API keys. You can't tell which agent did what.
|
|
24
|
+
- **No permissions** — agents get all-or-nothing access. No scoped, time-bounded controls.
|
|
25
|
+
- **No audit trail** — no tamper-evident record of agent actions. Compliance teams are blind.
|
|
26
|
+
- **No trust signal** — third parties can't verify an agent before interacting with it.
|
|
27
|
+
|
|
28
|
+
Vorim solves all four. One SDK. One protocol. Ships in minutes.
|
|
29
|
+
|
|
30
|
+
> **EU AI Act** (enforced Aug 2025) mandates traceability and audit trails for high-risk AI systems. Vorim makes your agents compliant out of the box.
|
|
31
|
+
|
|
32
|
+
---
|
|
9
33
|
|
|
10
34
|
## Install
|
|
11
35
|
|
|
@@ -14,13 +38,14 @@ npm install @vorim/sdk
|
|
|
14
38
|
```
|
|
15
39
|
|
|
16
40
|
```bash
|
|
41
|
+
# or
|
|
17
42
|
yarn add @vorim/sdk
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```bash
|
|
43
|
+
# or
|
|
21
44
|
pnpm add @vorim/sdk
|
|
22
45
|
```
|
|
23
46
|
|
|
47
|
+
---
|
|
48
|
+
|
|
24
49
|
## Quick Start
|
|
25
50
|
|
|
26
51
|
```typescript
|
|
@@ -30,17 +55,17 @@ const vorim = createVorim({
|
|
|
30
55
|
apiKey: "agid_sk_live_...",
|
|
31
56
|
});
|
|
32
57
|
|
|
33
|
-
// 1. Register an agent —
|
|
58
|
+
// 1. Register an agent — Ed25519 keypair generated, private key shown once
|
|
34
59
|
const { agent, private_key } = await vorim.register({
|
|
35
60
|
name: "invoice-processor",
|
|
36
61
|
capabilities: ["read_documents", "extract_data"],
|
|
37
62
|
scopes: ["agent:read", "agent:execute"],
|
|
38
63
|
});
|
|
39
64
|
|
|
40
|
-
console.log(agent.agent_id);
|
|
41
|
-
console.log(agent.trust_score); // 50 (initial
|
|
65
|
+
console.log(agent.agent_id); // agid_acme_a1b2c3d4
|
|
66
|
+
console.log(agent.trust_score); // 50 (initial)
|
|
42
67
|
|
|
43
|
-
// 2. Check permissions before acting (
|
|
68
|
+
// 2. Check permissions before acting (<5ms via Redis)
|
|
44
69
|
const { allowed } = await vorim.check(agent.agent_id, "agent:execute");
|
|
45
70
|
|
|
46
71
|
if (allowed) {
|
|
@@ -55,31 +80,119 @@ if (allowed) {
|
|
|
55
80
|
});
|
|
56
81
|
}
|
|
57
82
|
|
|
58
|
-
// 4. Verify any agent's trust (public
|
|
83
|
+
// 4. Verify any agent's trust (public endpoint, no auth required)
|
|
59
84
|
const trust = await vorim.verify(agent.agent_id);
|
|
60
|
-
console.log(trust.trust_score);
|
|
85
|
+
console.log(trust.trust_score); // 0–100
|
|
61
86
|
console.log(trust.active_scopes); // ['agent:read', 'agent:execute']
|
|
62
87
|
```
|
|
63
88
|
|
|
64
|
-
|
|
89
|
+
---
|
|
65
90
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
## Framework Integration
|
|
92
|
+
|
|
93
|
+
### LangChain
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import createVorim from "@vorim/sdk";
|
|
97
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
98
|
+
import { AgentExecutor } from "langchain/agents";
|
|
99
|
+
|
|
100
|
+
const vorim = createVorim({ apiKey: "agid_sk_live_..." });
|
|
101
|
+
|
|
102
|
+
// Register your LangChain agent with Vorim
|
|
103
|
+
const { agent: identity } = await vorim.register({
|
|
104
|
+
name: "langchain-research-agent",
|
|
105
|
+
capabilities: ["web_browsing", "api_calls"],
|
|
106
|
+
scopes: ["agent:read", "agent:execute", "agent:communicate"],
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Check permissions before every tool call
|
|
110
|
+
async function guardedToolCall(toolName: string, input: any) {
|
|
111
|
+
const { allowed } = await vorim.check(identity.agent_id, "agent:execute");
|
|
112
|
+
if (!allowed) throw new Error("Permission denied by Vorim");
|
|
113
|
+
|
|
114
|
+
const result = await executeTool(toolName, input);
|
|
115
|
+
|
|
116
|
+
// Audit every action
|
|
117
|
+
await vorim.emit({
|
|
118
|
+
agent_id: identity.agent_id,
|
|
119
|
+
event_type: "tool_call",
|
|
120
|
+
action: `${toolName}: ${JSON.stringify(input)}`,
|
|
121
|
+
result: "success",
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### CrewAI
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import createVorim from "@vorim/sdk";
|
|
132
|
+
|
|
133
|
+
const vorim = createVorim({ apiKey: "agid_sk_live_..." });
|
|
134
|
+
|
|
135
|
+
// Register each crew member as a Vorim agent
|
|
136
|
+
const researcher = await vorim.register({
|
|
137
|
+
name: "crew-researcher",
|
|
138
|
+
capabilities: ["web_browsing"],
|
|
139
|
+
scopes: ["agent:read"],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const writer = await vorim.register({
|
|
143
|
+
name: "crew-writer",
|
|
144
|
+
capabilities: ["file_access"],
|
|
145
|
+
scopes: ["agent:read", "agent:write"],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Verify permissions before delegation
|
|
149
|
+
const { allowed } = await vorim.check(writer.agent.agent_id, "agent:write");
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### OpenAI Agents SDK
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import createVorim from "@vorim/sdk";
|
|
156
|
+
import OpenAI from "openai";
|
|
157
|
+
|
|
158
|
+
const vorim = createVorim({ apiKey: "agid_sk_live_..." });
|
|
159
|
+
const openai = new OpenAI();
|
|
160
|
+
|
|
161
|
+
// Register your OpenAI agent
|
|
162
|
+
const { agent: identity } = await vorim.register({
|
|
163
|
+
name: "openai-assistant",
|
|
164
|
+
capabilities: ["api_calls", "code_execution"],
|
|
165
|
+
scopes: ["agent:read", "agent:execute"],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Wrap function calls with Vorim permission checks
|
|
169
|
+
async function handleFunctionCall(call: any) {
|
|
170
|
+
const { allowed } = await vorim.check(identity.agent_id, "agent:execute");
|
|
171
|
+
if (!allowed) return { error: "Blocked by Vorim trust layer" };
|
|
172
|
+
|
|
173
|
+
const result = await executeFunction(call);
|
|
174
|
+
|
|
175
|
+
await vorim.emit({
|
|
176
|
+
agent_id: identity.agent_id,
|
|
177
|
+
event_type: "tool_call",
|
|
178
|
+
action: call.name,
|
|
179
|
+
resource: JSON.stringify(call.arguments),
|
|
180
|
+
result: "success",
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
75
188
|
|
|
76
189
|
## API Reference
|
|
77
190
|
|
|
78
191
|
### Identity
|
|
79
192
|
|
|
80
193
|
```typescript
|
|
81
|
-
// Register a new agent (
|
|
82
|
-
const
|
|
194
|
+
// Register a new agent (private key returned once — store it securely)
|
|
195
|
+
const { agent, private_key } = await vorim.register({
|
|
83
196
|
name: "my-agent",
|
|
84
197
|
description: "Processes invoices",
|
|
85
198
|
capabilities: ["read_documents"],
|
|
@@ -99,20 +212,20 @@ await vorim.revoke("agid_acme_a1b2c3d4");
|
|
|
99
212
|
### Permissions
|
|
100
213
|
|
|
101
214
|
```typescript
|
|
102
|
-
// Check if an agent has a specific permission
|
|
215
|
+
// Check if an agent has a specific permission (<5ms)
|
|
103
216
|
const { allowed, remaining_quota } = await vorim.check(
|
|
104
217
|
"agid_acme_a1b2c3d4",
|
|
105
218
|
"agent:execute"
|
|
106
219
|
);
|
|
107
220
|
|
|
108
|
-
// Grant a time-bounded
|
|
221
|
+
// Grant a time-bounded, rate-limited permission
|
|
109
222
|
await vorim.grant("agid_acme_a1b2c3d4", "agent:transact", {
|
|
110
223
|
valid_until: "2026-06-01T00:00:00Z",
|
|
111
224
|
rate_limit: { max: 100, window: "1h" },
|
|
112
225
|
});
|
|
113
226
|
```
|
|
114
227
|
|
|
115
|
-
|
|
228
|
+
#### Permission Scopes
|
|
116
229
|
|
|
117
230
|
| Scope | Description |
|
|
118
231
|
|-------|-------------|
|
|
@@ -151,16 +264,16 @@ await vorim.emitBatch([
|
|
|
151
264
|
// Public endpoint — no API key required
|
|
152
265
|
const trust = await vorim.verify("agid_acme_a1b2c3d4");
|
|
153
266
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
267
|
+
trust.verified; // true
|
|
268
|
+
trust.trust_score; // 82
|
|
269
|
+
trust.status; // 'active'
|
|
270
|
+
trust.owner.org_name; // 'Acme Corp'
|
|
271
|
+
trust.active_scopes; // ['agent:read', 'agent:execute']
|
|
272
|
+
trust.key_fingerprint; // 'a1b2c3d4...'
|
|
273
|
+
trust.revocation_status; // false
|
|
161
274
|
```
|
|
162
275
|
|
|
163
|
-
**Trust
|
|
276
|
+
**Trust score factors:**
|
|
164
277
|
- Agent status (active, suspended, revoked)
|
|
165
278
|
- Account age (older = more trusted)
|
|
166
279
|
- Success rate over last 30 days
|
|
@@ -170,7 +283,7 @@ console.log(trust.revocation_status); // false
|
|
|
170
283
|
### Payload Signing
|
|
171
284
|
|
|
172
285
|
```typescript
|
|
173
|
-
// Sign a payload with the agent's Ed25519 private key
|
|
286
|
+
// Sign a payload with the agent's Ed25519 private key (client-side)
|
|
174
287
|
const signature = await vorim.sign(
|
|
175
288
|
JSON.stringify({ action: "transfer", amount: 500 }),
|
|
176
289
|
privateKeyPem
|
|
@@ -187,20 +300,43 @@ await vorim.emit({
|
|
|
187
300
|
});
|
|
188
301
|
```
|
|
189
302
|
|
|
303
|
+
### Embeddable Trust Badge
|
|
304
|
+
|
|
305
|
+
Every registered agent gets a public SVG trust badge you can embed anywhere:
|
|
306
|
+
|
|
307
|
+
```html
|
|
308
|
+
<!-- Embed in your docs, landing page, or agent marketplace listing -->
|
|
309
|
+
<img src="https://api.vorim.ai/v1/trust/badge/agid_acme_a1b2c3d4.svg" alt="Vorim Trust Badge" />
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The badge displays the agent's current trust score and updates in real-time. Use it to signal trust to end users, partners, and other agents.
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
190
316
|
## Configuration
|
|
191
317
|
|
|
192
318
|
```typescript
|
|
193
319
|
import createVorim from "@vorim/sdk";
|
|
194
320
|
|
|
195
321
|
const vorim = createVorim({
|
|
196
|
-
apiKey: "agid_sk_live_...",
|
|
197
|
-
baseUrl: "https://api.vorim.ai",
|
|
198
|
-
timeout: 10000,
|
|
322
|
+
apiKey: "agid_sk_live_...", // Required — your Vorim API key
|
|
323
|
+
baseUrl: "https://api.vorim.ai", // Optional (default)
|
|
324
|
+
timeout: 10000, // Optional — request timeout in ms (default: 10000)
|
|
199
325
|
});
|
|
200
326
|
```
|
|
201
327
|
|
|
328
|
+
| Option | Type | Default | Description |
|
|
329
|
+
|--------|------|---------|-------------|
|
|
330
|
+
| `apiKey` | `string` | — | Your Vorim API key (`agid_sk_live_...` or `agid_sk_test_...`) |
|
|
331
|
+
| `baseUrl` | `string` | `https://api.vorim.ai` | API base URL (override for self-hosted) |
|
|
332
|
+
| `timeout` | `number` | `10000` | Request timeout in milliseconds |
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
202
336
|
## Error Handling
|
|
203
337
|
|
|
338
|
+
All errors throw `VorimError` with structured fields:
|
|
339
|
+
|
|
204
340
|
```typescript
|
|
205
341
|
import createVorim, { VorimError } from "@vorim/sdk";
|
|
206
342
|
|
|
@@ -208,24 +344,65 @@ try {
|
|
|
208
344
|
await vorim.check("invalid_id", "agent:read");
|
|
209
345
|
} catch (err) {
|
|
210
346
|
if (err instanceof VorimError) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
347
|
+
err.status; // 404
|
|
348
|
+
err.code; // 'AGENT_NOT_FOUND'
|
|
349
|
+
err.message; // 'Agent invalid_id not found in the trust registry'
|
|
350
|
+
err.details; // Additional context (optional)
|
|
215
351
|
}
|
|
216
352
|
}
|
|
217
353
|
```
|
|
218
354
|
|
|
355
|
+
| Error Code | Status | Meaning |
|
|
356
|
+
|-----------|--------|---------|
|
|
357
|
+
| `INVALID_CREDENTIALS` | 401 | Bad or expired API key |
|
|
358
|
+
| `AGENT_NOT_FOUND` | 404 | Agent ID doesn't exist |
|
|
359
|
+
| `PERMISSION_DENIED` | 403 | Agent lacks required scope |
|
|
360
|
+
| `RATE_LIMITED` | 429 | Too many requests |
|
|
361
|
+
| `VALIDATION_ERROR` | 400 | Invalid request payload |
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Features
|
|
366
|
+
|
|
367
|
+
| Feature | Details |
|
|
368
|
+
|---------|---------|
|
|
369
|
+
| **Cryptographic Identity** | Ed25519 keypairs with SHA-256 fingerprints |
|
|
370
|
+
| **7 Permission Scopes** | `read`, `write`, `execute`, `transact`, `communicate`, `delegate`, `elevate` |
|
|
371
|
+
| **Immutable Audit Trail** | Append-only events with content hashing |
|
|
372
|
+
| **Trust Scoring** | 5-factor algorithm producing a 0–100 score |
|
|
373
|
+
| **Payload Signing** | Client-side Ed25519 via Web Crypto or Node.js crypto |
|
|
374
|
+
| **Dual Runtime** | Node.js 18+ and modern browsers |
|
|
375
|
+
| **Zero Dependencies** | Types bundled — nothing extra to install |
|
|
376
|
+
| **ESM + CJS** | Dual module output for any bundler or runtime |
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
219
380
|
## Protocol
|
|
220
381
|
|
|
221
|
-
|
|
382
|
+
This SDK implements the **[Vorim Agent Identity Protocol (VAIP)](https://github.com/Kzino/vorim-protocol)** — an open standard for AI agent identity, permissions, and cryptographic audit trails.
|
|
222
383
|
|
|
223
|
-
|
|
384
|
+
VAIP defines 5 conformance levels, from basic identity to full cryptographic signing. The protocol is open-source under Apache 2.0 — anyone can implement it.
|
|
385
|
+
|
|
386
|
+
Read the full specification: **[SPEC.md](https://github.com/Kzino/vorim-protocol/blob/main/SPEC.md)**
|
|
387
|
+
|
|
388
|
+
---
|
|
224
389
|
|
|
225
390
|
## Requirements
|
|
226
391
|
|
|
227
|
-
- Node.js 18+ or modern browser with Web Crypto API
|
|
228
|
-
- TypeScript 5.0+ (optional
|
|
392
|
+
- **Node.js** 18+ or modern browser with Web Crypto API
|
|
393
|
+
- **TypeScript** 5.0+ (optional but recommended)
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## Links
|
|
398
|
+
|
|
399
|
+
- **Website:** [vorim.ai](https://vorim.ai)
|
|
400
|
+
- **Protocol Spec:** [github.com/Kzino/vorim-protocol](https://github.com/Kzino/vorim-protocol)
|
|
401
|
+
- **npm:** [@vorim/sdk](https://www.npmjs.com/package/@vorim/sdk)
|
|
402
|
+
- **X:** [@vorim_ai_x](https://x.com/vorim_ai_x)
|
|
403
|
+
- **Issues:** [GitHub Issues](https://github.com/Kzino/vorim-protocol/issues)
|
|
404
|
+
|
|
405
|
+
---
|
|
229
406
|
|
|
230
407
|
## License
|
|
231
408
|
|
|
@@ -233,4 +410,4 @@ MIT — see [LICENSE](LICENSE) for details.
|
|
|
233
410
|
|
|
234
411
|
---
|
|
235
412
|
|
|
236
|
-
Built by [Vorim AI](https://vorim.ai)
|
|
413
|
+
Built by **[Vorim AI](https://vorim.ai)**
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/integrations/crewai.ts
|
|
21
|
+
var crewai_exports = {};
|
|
22
|
+
__export(crewai_exports, {
|
|
23
|
+
checkCrewPermission: () => checkCrewPermission,
|
|
24
|
+
checkDelegationPermission: () => checkDelegationPermission,
|
|
25
|
+
emitCrewRunEvents: () => emitCrewRunEvents,
|
|
26
|
+
emitCrewTaskEvent: () => emitCrewTaskEvent,
|
|
27
|
+
registerCrew: () => registerCrew,
|
|
28
|
+
verifyCrewTrust: () => verifyCrewTrust
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(crewai_exports);
|
|
31
|
+
async function registerCrew(vorim, manifest) {
|
|
32
|
+
const members = [];
|
|
33
|
+
for (const member of manifest.members) {
|
|
34
|
+
const scopes = [...member.scopes];
|
|
35
|
+
if (member.allowDelegation && !scopes.includes("agent:delegate")) {
|
|
36
|
+
scopes.push("agent:delegate");
|
|
37
|
+
}
|
|
38
|
+
const registration = await vorim.register({
|
|
39
|
+
name: member.name,
|
|
40
|
+
description: member.description ?? `CrewAI ${member.role} \u2014 ${manifest.crewName}`,
|
|
41
|
+
capabilities: member.capabilities,
|
|
42
|
+
scopes
|
|
43
|
+
});
|
|
44
|
+
members.push({
|
|
45
|
+
role: member.role,
|
|
46
|
+
agentId: registration.agent.agent_id,
|
|
47
|
+
registration,
|
|
48
|
+
privateKey: registration.private_key
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
crewName: manifest.crewName,
|
|
53
|
+
members,
|
|
54
|
+
getMember(role) {
|
|
55
|
+
return members.find((m) => m.role === role);
|
|
56
|
+
},
|
|
57
|
+
agentIds() {
|
|
58
|
+
return members.map((m) => m.agentId);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function emitCrewTaskEvent(vorim, event) {
|
|
63
|
+
const auditEvent = {
|
|
64
|
+
agent_id: event.agentId,
|
|
65
|
+
event_type: event.tool ? "tool_call" : "api_request",
|
|
66
|
+
action: event.task,
|
|
67
|
+
resource: event.tool,
|
|
68
|
+
result: event.result,
|
|
69
|
+
latency_ms: event.latencyMs,
|
|
70
|
+
error_code: event.error ? "CREW_TASK_ERROR" : void 0,
|
|
71
|
+
metadata: {
|
|
72
|
+
framework: "crewai",
|
|
73
|
+
role: event.role,
|
|
74
|
+
...event.delegatedTo ? { delegated_to: event.delegatedTo } : {},
|
|
75
|
+
...event.error ? { error: event.error } : {},
|
|
76
|
+
...event.metadata
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
await vorim.emit(auditEvent);
|
|
80
|
+
}
|
|
81
|
+
async function emitCrewRunEvents(vorim, events) {
|
|
82
|
+
const auditEvents = events.map((event) => ({
|
|
83
|
+
agent_id: event.agentId,
|
|
84
|
+
event_type: event.tool ? "tool_call" : "api_request",
|
|
85
|
+
action: event.task,
|
|
86
|
+
resource: event.tool,
|
|
87
|
+
result: event.result,
|
|
88
|
+
latency_ms: event.latencyMs,
|
|
89
|
+
error_code: event.error ? "CREW_TASK_ERROR" : void 0,
|
|
90
|
+
metadata: {
|
|
91
|
+
framework: "crewai",
|
|
92
|
+
role: event.role,
|
|
93
|
+
...event.delegatedTo ? { delegated_to: event.delegatedTo } : {},
|
|
94
|
+
...event.error ? { error: event.error } : {},
|
|
95
|
+
...event.metadata
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
return vorim.emitBatch(auditEvents);
|
|
99
|
+
}
|
|
100
|
+
async function checkCrewPermission(vorim, crew, role, scope) {
|
|
101
|
+
const member = crew.getMember(role);
|
|
102
|
+
if (!member) {
|
|
103
|
+
return { allowed: false, reason: `Unknown crew member: ${role}` };
|
|
104
|
+
}
|
|
105
|
+
return vorim.check(member.agentId, scope);
|
|
106
|
+
}
|
|
107
|
+
async function checkDelegationPermission(vorim, crew, fromRole, toRole) {
|
|
108
|
+
const from = crew.getMember(fromRole);
|
|
109
|
+
const to = crew.getMember(toRole);
|
|
110
|
+
if (!from) return { allowed: false, reason: `Unknown crew member: ${fromRole}` };
|
|
111
|
+
if (!to) return { allowed: false, reason: `Unknown crew member: ${toRole}` };
|
|
112
|
+
const result = await vorim.check(from.agentId, "agent:delegate");
|
|
113
|
+
if (!result.allowed) {
|
|
114
|
+
return { allowed: false, reason: `${fromRole} lacks agent:delegate permission` };
|
|
115
|
+
}
|
|
116
|
+
return { allowed: true };
|
|
117
|
+
}
|
|
118
|
+
async function verifyCrewTrust(vorim, crew) {
|
|
119
|
+
const results = await Promise.all(
|
|
120
|
+
crew.members.map(async (member) => {
|
|
121
|
+
const trust = await vorim.verify(member.agentId);
|
|
122
|
+
return {
|
|
123
|
+
role: member.role,
|
|
124
|
+
agentId: member.agentId,
|
|
125
|
+
trustScore: trust.trust_score,
|
|
126
|
+
status: trust.status
|
|
127
|
+
};
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
return results;
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
checkCrewPermission,
|
|
135
|
+
checkDelegationPermission,
|
|
136
|
+
emitCrewRunEvents,
|
|
137
|
+
emitCrewTaskEvent,
|
|
138
|
+
registerCrew,
|
|
139
|
+
verifyCrewTrust
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=crewai.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/crewai.ts"],"sourcesContent":["// ============================================================================\n// VORIM SDK — CrewAI Integration\n// CrewAI is Python-only, so this module provides:\n// 1. A TypeScript helper for managing CrewAI agent identities via Vorim\n// 2. Audit utilities for logging crew task execution\n// 3. A \"crew manifest\" pattern for registering entire crews at once\n//\n// Use this from a TypeScript orchestration layer that triggers CrewAI\n// runs via REST, CLI, or subprocess. For native Python integration,\n// use the Vorim REST API directly (see docs).\n//\n// No peer dependencies required — uses @vorim/sdk only.\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type {\n PermissionScope, AuditEventInput, AgentRegistrationResult,\n} from '../types.js';\n\n// ─── Crew Configuration ──────────────────────────────────────────────────\n\nexport interface CrewMemberConfig {\n /** Unique role name within the crew (e.g. \"researcher\", \"writer\"). */\n role: string;\n /** Display name for the Vorim agent. */\n name: string;\n /** Description of this crew member's responsibilities. */\n description?: string;\n /** Tools this agent can use (e.g. [\"web_search\", \"file_read\"]). */\n capabilities: string[];\n /** Permission scopes to grant. */\n scopes: PermissionScope[];\n /** Whether this agent can delegate to other crew members. */\n allowDelegation?: boolean;\n}\n\nexport interface CrewManifest {\n /** Name for the overall crew. */\n crewName: string;\n /** Members of the crew. */\n members: CrewMemberConfig[];\n /** Optional metadata for the crew. */\n metadata?: Record<string, unknown>;\n}\n\nexport interface RegisteredCrewMember {\n role: string;\n agentId: string;\n registration: AgentRegistrationResult;\n privateKey: string;\n}\n\nexport interface RegisteredCrew {\n crewName: string;\n members: RegisteredCrewMember[];\n /** Lookup a member by role. */\n getMember(role: string): RegisteredCrewMember | undefined;\n /** Get all agent IDs in the crew. */\n agentIds(): string[];\n}\n\n// ─── Crew Registration ──────────────────────────────────────────────────\n\n/**\n * Registers an entire CrewAI crew with Vorim. Each crew member gets a\n * unique Vorim agent identity with Ed25519 keypair and scoped permissions.\n *\n * @example\n * ```ts\n * import createVorim from \"@vorim/sdk\";\n * import { registerCrew } from \"@vorim/sdk/integrations/crewai\";\n *\n * const vorim = createVorim({ apiKey: \"agid_sk_live_...\" });\n *\n * const crew = await registerCrew(vorim, {\n * crewName: \"content-pipeline\",\n * members: [\n * {\n * role: \"researcher\",\n * name: \"crew-researcher\",\n * capabilities: [\"web_search\", \"summarization\"],\n * scopes: [\"agent:read\", \"agent:execute\"],\n * },\n * {\n * role: \"writer\",\n * name: \"crew-writer\",\n * capabilities: [\"file_write\", \"formatting\"],\n * scopes: [\"agent:read\", \"agent:write\"],\n * },\n * {\n * role: \"editor\",\n * name: \"crew-editor\",\n * capabilities: [\"review\", \"approval\"],\n * scopes: [\"agent:read\", \"agent:write\"],\n * allowDelegation: true,\n * },\n * ],\n * });\n *\n * // Access individual members\n * const researcher = crew.getMember(\"researcher\");\n * console.log(researcher.agentId); // agid_acme_...\n *\n * // Grant delegation permission to editor\n * // (done automatically if allowDelegation is true)\n * ```\n */\nexport async function registerCrew(\n vorim: VorimSDK,\n manifest: CrewManifest,\n): Promise<RegisteredCrew> {\n const members: RegisteredCrewMember[] = [];\n\n for (const member of manifest.members) {\n const scopes = [...member.scopes];\n\n // Auto-add delegate scope if delegation is allowed\n if (member.allowDelegation && !scopes.includes('agent:delegate')) {\n scopes.push('agent:delegate');\n }\n\n const registration = await vorim.register({\n name: member.name,\n description: member.description ?? `CrewAI ${member.role} — ${manifest.crewName}`,\n capabilities: member.capabilities,\n scopes,\n });\n\n members.push({\n role: member.role,\n agentId: registration.agent.agent_id,\n registration,\n privateKey: registration.private_key,\n });\n }\n\n return {\n crewName: manifest.crewName,\n members,\n getMember(role: string) {\n return members.find(m => m.role === role);\n },\n agentIds() {\n return members.map(m => m.agentId);\n },\n };\n}\n\n// ─── Task Audit ──────────────────────────────────────────────────────────\n\nexport interface CrewTaskEvent {\n /** The role of the crew member performing the task. */\n role: string;\n /** The Vorim agent_id (looked up from the crew). */\n agentId: string;\n /** Task description or name. */\n task: string;\n /** Tool used (if any). */\n tool?: string;\n /** Result of the action. */\n result: 'success' | 'denied' | 'error';\n /** Duration in milliseconds. */\n latencyMs?: number;\n /** Error details if result is 'error'. */\n error?: string;\n /** Whether this was a delegation to another crew member. */\n delegatedTo?: string;\n /** Additional context. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Emits a Vorim audit event for a CrewAI task execution.\n * Call this from your orchestration layer after each CrewAI step completes.\n *\n * @example\n * ```ts\n * import { emitCrewTaskEvent } from \"@vorim/sdk/integrations/crewai\";\n *\n * // After a CrewAI task completes\n * await emitCrewTaskEvent(vorim, {\n * role: \"researcher\",\n * agentId: crew.getMember(\"researcher\").agentId,\n * task: \"research_competitors\",\n * tool: \"web_search\",\n * result: \"success\",\n * latencyMs: 3200,\n * });\n * ```\n */\nexport async function emitCrewTaskEvent(\n vorim: VorimSDK,\n event: CrewTaskEvent,\n): Promise<void> {\n const auditEvent: AuditEventInput = {\n agent_id: event.agentId,\n event_type: event.tool ? 'tool_call' : 'api_request',\n action: event.task,\n resource: event.tool,\n result: event.result,\n latency_ms: event.latencyMs,\n error_code: event.error ? 'CREW_TASK_ERROR' : undefined,\n metadata: {\n framework: 'crewai',\n role: event.role,\n ...(event.delegatedTo ? { delegated_to: event.delegatedTo } : {}),\n ...(event.error ? { error: event.error } : {}),\n ...event.metadata,\n },\n };\n\n await vorim.emit(auditEvent);\n}\n\n/**\n * Emits audit events for an entire crew run (batch of task results).\n *\n * @example\n * ```ts\n * await emitCrewRunEvents(vorim, [\n * { role: \"researcher\", agentId: \"...\", task: \"research\", result: \"success\" },\n * { role: \"writer\", agentId: \"...\", task: \"draft_article\", result: \"success\" },\n * { role: \"editor\", agentId: \"...\", task: \"review\", result: \"success\" },\n * ]);\n * ```\n */\nexport async function emitCrewRunEvents(\n vorim: VorimSDK,\n events: CrewTaskEvent[],\n): Promise<{ ingested: number }> {\n const auditEvents: AuditEventInput[] = events.map(event => ({\n agent_id: event.agentId,\n event_type: event.tool ? 'tool_call' : 'api_request',\n action: event.task,\n resource: event.tool,\n result: event.result,\n latency_ms: event.latencyMs,\n error_code: event.error ? 'CREW_TASK_ERROR' : undefined,\n metadata: {\n framework: 'crewai',\n role: event.role,\n ...(event.delegatedTo ? { delegated_to: event.delegatedTo } : {}),\n ...(event.error ? { error: event.error } : {}),\n ...event.metadata,\n },\n }));\n\n return vorim.emitBatch(auditEvents);\n}\n\n// ─── Permission Helpers ──────────────────────────────────────────────────\n\n/**\n * Check if a crew member has permission before executing a task.\n * Returns the check result — does not throw.\n *\n * @example\n * ```ts\n * const { allowed } = await checkCrewPermission(vorim, crew, \"writer\", \"agent:write\");\n * if (!allowed) {\n * console.log(\"Writer lacks write permission\");\n * }\n * ```\n */\nexport async function checkCrewPermission(\n vorim: VorimSDK,\n crew: RegisteredCrew,\n role: string,\n scope: PermissionScope,\n): Promise<{ allowed: boolean; reason?: string }> {\n const member = crew.getMember(role);\n if (!member) {\n return { allowed: false, reason: `Unknown crew member: ${role}` };\n }\n return vorim.check(member.agentId, scope);\n}\n\n/**\n * Check if delegation between two crew members is permitted.\n * The delegating agent must have the `agent:delegate` scope.\n */\nexport async function checkDelegationPermission(\n vorim: VorimSDK,\n crew: RegisteredCrew,\n fromRole: string,\n toRole: string,\n): Promise<{ allowed: boolean; reason?: string }> {\n const from = crew.getMember(fromRole);\n const to = crew.getMember(toRole);\n if (!from) return { allowed: false, reason: `Unknown crew member: ${fromRole}` };\n if (!to) return { allowed: false, reason: `Unknown crew member: ${toRole}` };\n\n const result = await vorim.check(from.agentId, 'agent:delegate');\n if (!result.allowed) {\n return { allowed: false, reason: `${fromRole} lacks agent:delegate permission` };\n }\n return { allowed: true };\n}\n\n// ─── Trust Verification ──────────────────────────────────────────────────\n\n/**\n * Verify trust scores for all members of a crew.\n * Useful before starting a crew run to ensure all agents are active and trusted.\n */\nexport async function verifyCrewTrust(\n vorim: VorimSDK,\n crew: RegisteredCrew,\n): Promise<{ role: string; agentId: string; trustScore: number; status: string }[]> {\n const results = await Promise.all(\n crew.members.map(async (member) => {\n const trust = await vorim.verify(member.agentId);\n return {\n role: member.role,\n agentId: member.agentId,\n trustScore: trust.trust_score,\n status: trust.status,\n };\n }),\n );\n return results;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2GA,eAAsB,aACpB,OACA,UACyB;AACzB,QAAM,UAAkC,CAAC;AAEzC,aAAW,UAAU,SAAS,SAAS;AACrC,UAAM,SAAS,CAAC,GAAG,OAAO,MAAM;AAGhC,QAAI,OAAO,mBAAmB,CAAC,OAAO,SAAS,gBAAgB,GAAG;AAChE,aAAO,KAAK,gBAAgB;AAAA,IAC9B;AAEA,UAAM,eAAe,MAAM,MAAM,SAAS;AAAA,MACxC,MAAM,OAAO;AAAA,MACb,aAAa,OAAO,eAAe,UAAU,OAAO,IAAI,WAAM,SAAS,QAAQ;AAAA,MAC/E,cAAc,OAAO;AAAA,MACrB;AAAA,IACF,CAAC;AAED,YAAQ,KAAK;AAAA,MACX,MAAM,OAAO;AAAA,MACb,SAAS,aAAa,MAAM;AAAA,MAC5B;AAAA,MACA,YAAY,aAAa;AAAA,IAC3B,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,UAAU,SAAS;AAAA,IACnB;AAAA,IACA,UAAU,MAAc;AACtB,aAAO,QAAQ,KAAK,OAAK,EAAE,SAAS,IAAI;AAAA,IAC1C;AAAA,IACA,WAAW;AACT,aAAO,QAAQ,IAAI,OAAK,EAAE,OAAO;AAAA,IACnC;AAAA,EACF;AACF;AA4CA,eAAsB,kBACpB,OACA,OACe;AACf,QAAM,aAA8B;AAAA,IAClC,UAAU,MAAM;AAAA,IAChB,YAAY,MAAM,OAAO,cAAc;AAAA,IACvC,QAAQ,MAAM;AAAA,IACd,UAAU,MAAM;AAAA,IAChB,QAAQ,MAAM;AAAA,IACd,YAAY,MAAM;AAAA,IAClB,YAAY,MAAM,QAAQ,oBAAoB;AAAA,IAC9C,UAAU;AAAA,MACR,WAAW;AAAA,MACX,MAAM,MAAM;AAAA,MACZ,GAAI,MAAM,cAAc,EAAE,cAAc,MAAM,YAAY,IAAI,CAAC;AAAA,MAC/D,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,MAC5C,GAAG,MAAM;AAAA,IACX;AAAA,EACF;AAEA,QAAM,MAAM,KAAK,UAAU;AAC7B;AAcA,eAAsB,kBACpB,OACA,QAC+B;AAC/B,QAAM,cAAiC,OAAO,IAAI,YAAU;AAAA,IAC1D,UAAU,MAAM;AAAA,IAChB,YAAY,MAAM,OAAO,cAAc;AAAA,IACvC,QAAQ,MAAM;AAAA,IACd,UAAU,MAAM;AAAA,IAChB,QAAQ,MAAM;AAAA,IACd,YAAY,MAAM;AAAA,IAClB,YAAY,MAAM,QAAQ,oBAAoB;AAAA,IAC9C,UAAU;AAAA,MACR,WAAW;AAAA,MACX,MAAM,MAAM;AAAA,MACZ,GAAI,MAAM,cAAc,EAAE,cAAc,MAAM,YAAY,IAAI,CAAC;AAAA,MAC/D,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,MAC5C,GAAG,MAAM;AAAA,IACX;AAAA,EACF,EAAE;AAEF,SAAO,MAAM,UAAU,WAAW;AACpC;AAgBA,eAAsB,oBACpB,OACA,MACA,MACA,OACgD;AAChD,QAAM,SAAS,KAAK,UAAU,IAAI;AAClC,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE,SAAS,OAAO,QAAQ,wBAAwB,IAAI,GAAG;AAAA,EAClE;AACA,SAAO,MAAM,MAAM,OAAO,SAAS,KAAK;AAC1C;AAMA,eAAsB,0BACpB,OACA,MACA,UACA,QACgD;AAChD,QAAM,OAAO,KAAK,UAAU,QAAQ;AACpC,QAAM,KAAK,KAAK,UAAU,MAAM;AAChC,MAAI,CAAC,KAAM,QAAO,EAAE,SAAS,OAAO,QAAQ,wBAAwB,QAAQ,GAAG;AAC/E,MAAI,CAAC,GAAI,QAAO,EAAE,SAAS,OAAO,QAAQ,wBAAwB,MAAM,GAAG;AAE3E,QAAM,SAAS,MAAM,MAAM,MAAM,KAAK,SAAS,gBAAgB;AAC/D,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,EAAE,SAAS,OAAO,QAAQ,GAAG,QAAQ,mCAAmC;AAAA,EACjF;AACA,SAAO,EAAE,SAAS,KAAK;AACzB;AAQA,eAAsB,gBACpB,OACA,MACkF;AAClF,QAAM,UAAU,MAAM,QAAQ;AAAA,IAC5B,KAAK,QAAQ,IAAI,OAAO,WAAW;AACjC,YAAM,QAAQ,MAAM,MAAM,OAAO,OAAO,OAAO;AAC/C,aAAO;AAAA,QACL,MAAM,OAAO;AAAA,QACb,SAAS,OAAO;AAAA,QAChB,YAAY,MAAM;AAAA,QAClB,QAAQ,MAAM;AAAA,MAChB;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
|