@vorim/sdk 1.0.2 → 2.1.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 +4 -0
- package/dist/index.cjs +47 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- 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
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { PermissionScope, AgentRegistrationResult, VorimSDK } from '../index.cjs';
|
|
2
|
+
|
|
3
|
+
interface CrewMemberConfig {
|
|
4
|
+
/** Unique role name within the crew (e.g. "researcher", "writer"). */
|
|
5
|
+
role: string;
|
|
6
|
+
/** Display name for the Vorim agent. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Description of this crew member's responsibilities. */
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Tools this agent can use (e.g. ["web_search", "file_read"]). */
|
|
11
|
+
capabilities: string[];
|
|
12
|
+
/** Permission scopes to grant. */
|
|
13
|
+
scopes: PermissionScope[];
|
|
14
|
+
/** Whether this agent can delegate to other crew members. */
|
|
15
|
+
allowDelegation?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface CrewManifest {
|
|
18
|
+
/** Name for the overall crew. */
|
|
19
|
+
crewName: string;
|
|
20
|
+
/** Members of the crew. */
|
|
21
|
+
members: CrewMemberConfig[];
|
|
22
|
+
/** Optional metadata for the crew. */
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
interface RegisteredCrewMember {
|
|
26
|
+
role: string;
|
|
27
|
+
agentId: string;
|
|
28
|
+
registration: AgentRegistrationResult;
|
|
29
|
+
privateKey: string;
|
|
30
|
+
}
|
|
31
|
+
interface RegisteredCrew {
|
|
32
|
+
crewName: string;
|
|
33
|
+
members: RegisteredCrewMember[];
|
|
34
|
+
/** Lookup a member by role. */
|
|
35
|
+
getMember(role: string): RegisteredCrewMember | undefined;
|
|
36
|
+
/** Get all agent IDs in the crew. */
|
|
37
|
+
agentIds(): string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registers an entire CrewAI crew with Vorim. Each crew member gets a
|
|
41
|
+
* unique Vorim agent identity with Ed25519 keypair and scoped permissions.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import createVorim from "@vorim/sdk";
|
|
46
|
+
* import { registerCrew } from "@vorim/sdk/integrations/crewai";
|
|
47
|
+
*
|
|
48
|
+
* const vorim = createVorim({ apiKey: "agid_sk_live_..." });
|
|
49
|
+
*
|
|
50
|
+
* const crew = await registerCrew(vorim, {
|
|
51
|
+
* crewName: "content-pipeline",
|
|
52
|
+
* members: [
|
|
53
|
+
* {
|
|
54
|
+
* role: "researcher",
|
|
55
|
+
* name: "crew-researcher",
|
|
56
|
+
* capabilities: ["web_search", "summarization"],
|
|
57
|
+
* scopes: ["agent:read", "agent:execute"],
|
|
58
|
+
* },
|
|
59
|
+
* {
|
|
60
|
+
* role: "writer",
|
|
61
|
+
* name: "crew-writer",
|
|
62
|
+
* capabilities: ["file_write", "formatting"],
|
|
63
|
+
* scopes: ["agent:read", "agent:write"],
|
|
64
|
+
* },
|
|
65
|
+
* {
|
|
66
|
+
* role: "editor",
|
|
67
|
+
* name: "crew-editor",
|
|
68
|
+
* capabilities: ["review", "approval"],
|
|
69
|
+
* scopes: ["agent:read", "agent:write"],
|
|
70
|
+
* allowDelegation: true,
|
|
71
|
+
* },
|
|
72
|
+
* ],
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Access individual members
|
|
76
|
+
* const researcher = crew.getMember("researcher");
|
|
77
|
+
* console.log(researcher.agentId); // agid_acme_...
|
|
78
|
+
*
|
|
79
|
+
* // Grant delegation permission to editor
|
|
80
|
+
* // (done automatically if allowDelegation is true)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function registerCrew(vorim: VorimSDK, manifest: CrewManifest): Promise<RegisteredCrew>;
|
|
84
|
+
interface CrewTaskEvent {
|
|
85
|
+
/** The role of the crew member performing the task. */
|
|
86
|
+
role: string;
|
|
87
|
+
/** The Vorim agent_id (looked up from the crew). */
|
|
88
|
+
agentId: string;
|
|
89
|
+
/** Task description or name. */
|
|
90
|
+
task: string;
|
|
91
|
+
/** Tool used (if any). */
|
|
92
|
+
tool?: string;
|
|
93
|
+
/** Result of the action. */
|
|
94
|
+
result: 'success' | 'denied' | 'error';
|
|
95
|
+
/** Duration in milliseconds. */
|
|
96
|
+
latencyMs?: number;
|
|
97
|
+
/** Error details if result is 'error'. */
|
|
98
|
+
error?: string;
|
|
99
|
+
/** Whether this was a delegation to another crew member. */
|
|
100
|
+
delegatedTo?: string;
|
|
101
|
+
/** Additional context. */
|
|
102
|
+
metadata?: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Emits a Vorim audit event for a CrewAI task execution.
|
|
106
|
+
* Call this from your orchestration layer after each CrewAI step completes.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { emitCrewTaskEvent } from "@vorim/sdk/integrations/crewai";
|
|
111
|
+
*
|
|
112
|
+
* // After a CrewAI task completes
|
|
113
|
+
* await emitCrewTaskEvent(vorim, {
|
|
114
|
+
* role: "researcher",
|
|
115
|
+
* agentId: crew.getMember("researcher").agentId,
|
|
116
|
+
* task: "research_competitors",
|
|
117
|
+
* tool: "web_search",
|
|
118
|
+
* result: "success",
|
|
119
|
+
* latencyMs: 3200,
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function emitCrewTaskEvent(vorim: VorimSDK, event: CrewTaskEvent): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Emits audit events for an entire crew run (batch of task results).
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* await emitCrewRunEvents(vorim, [
|
|
130
|
+
* { role: "researcher", agentId: "...", task: "research", result: "success" },
|
|
131
|
+
* { role: "writer", agentId: "...", task: "draft_article", result: "success" },
|
|
132
|
+
* { role: "editor", agentId: "...", task: "review", result: "success" },
|
|
133
|
+
* ]);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare function emitCrewRunEvents(vorim: VorimSDK, events: CrewTaskEvent[]): Promise<{
|
|
137
|
+
ingested: number;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* Check if a crew member has permission before executing a task.
|
|
141
|
+
* Returns the check result — does not throw.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const { allowed } = await checkCrewPermission(vorim, crew, "writer", "agent:write");
|
|
146
|
+
* if (!allowed) {
|
|
147
|
+
* console.log("Writer lacks write permission");
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function checkCrewPermission(vorim: VorimSDK, crew: RegisteredCrew, role: string, scope: PermissionScope): Promise<{
|
|
152
|
+
allowed: boolean;
|
|
153
|
+
reason?: string;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Check if delegation between two crew members is permitted.
|
|
157
|
+
* The delegating agent must have the `agent:delegate` scope.
|
|
158
|
+
*/
|
|
159
|
+
declare function checkDelegationPermission(vorim: VorimSDK, crew: RegisteredCrew, fromRole: string, toRole: string): Promise<{
|
|
160
|
+
allowed: boolean;
|
|
161
|
+
reason?: string;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Verify trust scores for all members of a crew.
|
|
165
|
+
* Useful before starting a crew run to ensure all agents are active and trusted.
|
|
166
|
+
*/
|
|
167
|
+
declare function verifyCrewTrust(vorim: VorimSDK, crew: RegisteredCrew): Promise<{
|
|
168
|
+
role: string;
|
|
169
|
+
agentId: string;
|
|
170
|
+
trustScore: number;
|
|
171
|
+
status: string;
|
|
172
|
+
}[]>;
|
|
173
|
+
|
|
174
|
+
export { type CrewManifest, type CrewMemberConfig, type CrewTaskEvent, type RegisteredCrew, type RegisteredCrewMember, checkCrewPermission, checkDelegationPermission, emitCrewRunEvents, emitCrewTaskEvent, registerCrew, verifyCrewTrust };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { PermissionScope, AgentRegistrationResult, VorimSDK } from '../index.js';
|
|
2
|
+
|
|
3
|
+
interface CrewMemberConfig {
|
|
4
|
+
/** Unique role name within the crew (e.g. "researcher", "writer"). */
|
|
5
|
+
role: string;
|
|
6
|
+
/** Display name for the Vorim agent. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Description of this crew member's responsibilities. */
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Tools this agent can use (e.g. ["web_search", "file_read"]). */
|
|
11
|
+
capabilities: string[];
|
|
12
|
+
/** Permission scopes to grant. */
|
|
13
|
+
scopes: PermissionScope[];
|
|
14
|
+
/** Whether this agent can delegate to other crew members. */
|
|
15
|
+
allowDelegation?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface CrewManifest {
|
|
18
|
+
/** Name for the overall crew. */
|
|
19
|
+
crewName: string;
|
|
20
|
+
/** Members of the crew. */
|
|
21
|
+
members: CrewMemberConfig[];
|
|
22
|
+
/** Optional metadata for the crew. */
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
interface RegisteredCrewMember {
|
|
26
|
+
role: string;
|
|
27
|
+
agentId: string;
|
|
28
|
+
registration: AgentRegistrationResult;
|
|
29
|
+
privateKey: string;
|
|
30
|
+
}
|
|
31
|
+
interface RegisteredCrew {
|
|
32
|
+
crewName: string;
|
|
33
|
+
members: RegisteredCrewMember[];
|
|
34
|
+
/** Lookup a member by role. */
|
|
35
|
+
getMember(role: string): RegisteredCrewMember | undefined;
|
|
36
|
+
/** Get all agent IDs in the crew. */
|
|
37
|
+
agentIds(): string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registers an entire CrewAI crew with Vorim. Each crew member gets a
|
|
41
|
+
* unique Vorim agent identity with Ed25519 keypair and scoped permissions.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import createVorim from "@vorim/sdk";
|
|
46
|
+
* import { registerCrew } from "@vorim/sdk/integrations/crewai";
|
|
47
|
+
*
|
|
48
|
+
* const vorim = createVorim({ apiKey: "agid_sk_live_..." });
|
|
49
|
+
*
|
|
50
|
+
* const crew = await registerCrew(vorim, {
|
|
51
|
+
* crewName: "content-pipeline",
|
|
52
|
+
* members: [
|
|
53
|
+
* {
|
|
54
|
+
* role: "researcher",
|
|
55
|
+
* name: "crew-researcher",
|
|
56
|
+
* capabilities: ["web_search", "summarization"],
|
|
57
|
+
* scopes: ["agent:read", "agent:execute"],
|
|
58
|
+
* },
|
|
59
|
+
* {
|
|
60
|
+
* role: "writer",
|
|
61
|
+
* name: "crew-writer",
|
|
62
|
+
* capabilities: ["file_write", "formatting"],
|
|
63
|
+
* scopes: ["agent:read", "agent:write"],
|
|
64
|
+
* },
|
|
65
|
+
* {
|
|
66
|
+
* role: "editor",
|
|
67
|
+
* name: "crew-editor",
|
|
68
|
+
* capabilities: ["review", "approval"],
|
|
69
|
+
* scopes: ["agent:read", "agent:write"],
|
|
70
|
+
* allowDelegation: true,
|
|
71
|
+
* },
|
|
72
|
+
* ],
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Access individual members
|
|
76
|
+
* const researcher = crew.getMember("researcher");
|
|
77
|
+
* console.log(researcher.agentId); // agid_acme_...
|
|
78
|
+
*
|
|
79
|
+
* // Grant delegation permission to editor
|
|
80
|
+
* // (done automatically if allowDelegation is true)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function registerCrew(vorim: VorimSDK, manifest: CrewManifest): Promise<RegisteredCrew>;
|
|
84
|
+
interface CrewTaskEvent {
|
|
85
|
+
/** The role of the crew member performing the task. */
|
|
86
|
+
role: string;
|
|
87
|
+
/** The Vorim agent_id (looked up from the crew). */
|
|
88
|
+
agentId: string;
|
|
89
|
+
/** Task description or name. */
|
|
90
|
+
task: string;
|
|
91
|
+
/** Tool used (if any). */
|
|
92
|
+
tool?: string;
|
|
93
|
+
/** Result of the action. */
|
|
94
|
+
result: 'success' | 'denied' | 'error';
|
|
95
|
+
/** Duration in milliseconds. */
|
|
96
|
+
latencyMs?: number;
|
|
97
|
+
/** Error details if result is 'error'. */
|
|
98
|
+
error?: string;
|
|
99
|
+
/** Whether this was a delegation to another crew member. */
|
|
100
|
+
delegatedTo?: string;
|
|
101
|
+
/** Additional context. */
|
|
102
|
+
metadata?: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Emits a Vorim audit event for a CrewAI task execution.
|
|
106
|
+
* Call this from your orchestration layer after each CrewAI step completes.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { emitCrewTaskEvent } from "@vorim/sdk/integrations/crewai";
|
|
111
|
+
*
|
|
112
|
+
* // After a CrewAI task completes
|
|
113
|
+
* await emitCrewTaskEvent(vorim, {
|
|
114
|
+
* role: "researcher",
|
|
115
|
+
* agentId: crew.getMember("researcher").agentId,
|
|
116
|
+
* task: "research_competitors",
|
|
117
|
+
* tool: "web_search",
|
|
118
|
+
* result: "success",
|
|
119
|
+
* latencyMs: 3200,
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function emitCrewTaskEvent(vorim: VorimSDK, event: CrewTaskEvent): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Emits audit events for an entire crew run (batch of task results).
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* await emitCrewRunEvents(vorim, [
|
|
130
|
+
* { role: "researcher", agentId: "...", task: "research", result: "success" },
|
|
131
|
+
* { role: "writer", agentId: "...", task: "draft_article", result: "success" },
|
|
132
|
+
* { role: "editor", agentId: "...", task: "review", result: "success" },
|
|
133
|
+
* ]);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare function emitCrewRunEvents(vorim: VorimSDK, events: CrewTaskEvent[]): Promise<{
|
|
137
|
+
ingested: number;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* Check if a crew member has permission before executing a task.
|
|
141
|
+
* Returns the check result — does not throw.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const { allowed } = await checkCrewPermission(vorim, crew, "writer", "agent:write");
|
|
146
|
+
* if (!allowed) {
|
|
147
|
+
* console.log("Writer lacks write permission");
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function checkCrewPermission(vorim: VorimSDK, crew: RegisteredCrew, role: string, scope: PermissionScope): Promise<{
|
|
152
|
+
allowed: boolean;
|
|
153
|
+
reason?: string;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Check if delegation between two crew members is permitted.
|
|
157
|
+
* The delegating agent must have the `agent:delegate` scope.
|
|
158
|
+
*/
|
|
159
|
+
declare function checkDelegationPermission(vorim: VorimSDK, crew: RegisteredCrew, fromRole: string, toRole: string): Promise<{
|
|
160
|
+
allowed: boolean;
|
|
161
|
+
reason?: string;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Verify trust scores for all members of a crew.
|
|
165
|
+
* Useful before starting a crew run to ensure all agents are active and trusted.
|
|
166
|
+
*/
|
|
167
|
+
declare function verifyCrewTrust(vorim: VorimSDK, crew: RegisteredCrew): Promise<{
|
|
168
|
+
role: string;
|
|
169
|
+
agentId: string;
|
|
170
|
+
trustScore: number;
|
|
171
|
+
status: string;
|
|
172
|
+
}[]>;
|
|
173
|
+
|
|
174
|
+
export { type CrewManifest, type CrewMemberConfig, type CrewTaskEvent, type RegisteredCrew, type RegisteredCrewMember, checkCrewPermission, checkDelegationPermission, emitCrewRunEvents, emitCrewTaskEvent, registerCrew, verifyCrewTrust };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/integrations/crewai.ts
|
|
2
|
+
async function registerCrew(vorim, manifest) {
|
|
3
|
+
const members = [];
|
|
4
|
+
for (const member of manifest.members) {
|
|
5
|
+
const scopes = [...member.scopes];
|
|
6
|
+
if (member.allowDelegation && !scopes.includes("agent:delegate")) {
|
|
7
|
+
scopes.push("agent:delegate");
|
|
8
|
+
}
|
|
9
|
+
const registration = await vorim.register({
|
|
10
|
+
name: member.name,
|
|
11
|
+
description: member.description ?? `CrewAI ${member.role} \u2014 ${manifest.crewName}`,
|
|
12
|
+
capabilities: member.capabilities,
|
|
13
|
+
scopes
|
|
14
|
+
});
|
|
15
|
+
members.push({
|
|
16
|
+
role: member.role,
|
|
17
|
+
agentId: registration.agent.agent_id,
|
|
18
|
+
registration,
|
|
19
|
+
privateKey: registration.private_key
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
crewName: manifest.crewName,
|
|
24
|
+
members,
|
|
25
|
+
getMember(role) {
|
|
26
|
+
return members.find((m) => m.role === role);
|
|
27
|
+
},
|
|
28
|
+
agentIds() {
|
|
29
|
+
return members.map((m) => m.agentId);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function emitCrewTaskEvent(vorim, event) {
|
|
34
|
+
const auditEvent = {
|
|
35
|
+
agent_id: event.agentId,
|
|
36
|
+
event_type: event.tool ? "tool_call" : "api_request",
|
|
37
|
+
action: event.task,
|
|
38
|
+
resource: event.tool,
|
|
39
|
+
result: event.result,
|
|
40
|
+
latency_ms: event.latencyMs,
|
|
41
|
+
error_code: event.error ? "CREW_TASK_ERROR" : void 0,
|
|
42
|
+
metadata: {
|
|
43
|
+
framework: "crewai",
|
|
44
|
+
role: event.role,
|
|
45
|
+
...event.delegatedTo ? { delegated_to: event.delegatedTo } : {},
|
|
46
|
+
...event.error ? { error: event.error } : {},
|
|
47
|
+
...event.metadata
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
await vorim.emit(auditEvent);
|
|
51
|
+
}
|
|
52
|
+
async function emitCrewRunEvents(vorim, events) {
|
|
53
|
+
const auditEvents = events.map((event) => ({
|
|
54
|
+
agent_id: event.agentId,
|
|
55
|
+
event_type: event.tool ? "tool_call" : "api_request",
|
|
56
|
+
action: event.task,
|
|
57
|
+
resource: event.tool,
|
|
58
|
+
result: event.result,
|
|
59
|
+
latency_ms: event.latencyMs,
|
|
60
|
+
error_code: event.error ? "CREW_TASK_ERROR" : void 0,
|
|
61
|
+
metadata: {
|
|
62
|
+
framework: "crewai",
|
|
63
|
+
role: event.role,
|
|
64
|
+
...event.delegatedTo ? { delegated_to: event.delegatedTo } : {},
|
|
65
|
+
...event.error ? { error: event.error } : {},
|
|
66
|
+
...event.metadata
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
return vorim.emitBatch(auditEvents);
|
|
70
|
+
}
|
|
71
|
+
async function checkCrewPermission(vorim, crew, role, scope) {
|
|
72
|
+
const member = crew.getMember(role);
|
|
73
|
+
if (!member) {
|
|
74
|
+
return { allowed: false, reason: `Unknown crew member: ${role}` };
|
|
75
|
+
}
|
|
76
|
+
return vorim.check(member.agentId, scope);
|
|
77
|
+
}
|
|
78
|
+
async function checkDelegationPermission(vorim, crew, fromRole, toRole) {
|
|
79
|
+
const from = crew.getMember(fromRole);
|
|
80
|
+
const to = crew.getMember(toRole);
|
|
81
|
+
if (!from) return { allowed: false, reason: `Unknown crew member: ${fromRole}` };
|
|
82
|
+
if (!to) return { allowed: false, reason: `Unknown crew member: ${toRole}` };
|
|
83
|
+
const result = await vorim.check(from.agentId, "agent:delegate");
|
|
84
|
+
if (!result.allowed) {
|
|
85
|
+
return { allowed: false, reason: `${fromRole} lacks agent:delegate permission` };
|
|
86
|
+
}
|
|
87
|
+
return { allowed: true };
|
|
88
|
+
}
|
|
89
|
+
async function verifyCrewTrust(vorim, crew) {
|
|
90
|
+
const results = await Promise.all(
|
|
91
|
+
crew.members.map(async (member) => {
|
|
92
|
+
const trust = await vorim.verify(member.agentId);
|
|
93
|
+
return {
|
|
94
|
+
role: member.role,
|
|
95
|
+
agentId: member.agentId,
|
|
96
|
+
trustScore: trust.trust_score,
|
|
97
|
+
status: trust.status
|
|
98
|
+
};
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
return results;
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
checkCrewPermission,
|
|
105
|
+
checkDelegationPermission,
|
|
106
|
+
emitCrewRunEvents,
|
|
107
|
+
emitCrewTaskEvent,
|
|
108
|
+
registerCrew,
|
|
109
|
+
verifyCrewTrust
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=crewai.js.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":"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","names":[]}
|
|
@@ -0,0 +1,197 @@
|
|
|
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/langchain.ts
|
|
21
|
+
var langchain_exports = {};
|
|
22
|
+
__export(langchain_exports, {
|
|
23
|
+
VorimCallbackHandler: () => VorimCallbackHandler,
|
|
24
|
+
createVorimAgent: () => createVorimAgent,
|
|
25
|
+
wrapTool: () => wrapTool,
|
|
26
|
+
wrapTools: () => wrapTools
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(langchain_exports);
|
|
29
|
+
function wrapTool(tool, config) {
|
|
30
|
+
const { vorim, agentId, permissionMap = {}, defaultPermission = "agent:execute", asyncAudit = true } = config;
|
|
31
|
+
const originalCall = tool._call.bind(tool);
|
|
32
|
+
tool._call = async function vorimGuardedCall(arg, runManager, parentConfig) {
|
|
33
|
+
const scope = permissionMap[tool.name] ?? defaultPermission;
|
|
34
|
+
const { allowed, reason } = await vorim.check(agentId, scope);
|
|
35
|
+
if (!allowed) {
|
|
36
|
+
const event2 = {
|
|
37
|
+
agent_id: agentId,
|
|
38
|
+
event_type: "tool_call",
|
|
39
|
+
action: tool.name,
|
|
40
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
41
|
+
permission: scope,
|
|
42
|
+
result: "denied",
|
|
43
|
+
metadata: { reason, framework: "langchain" }
|
|
44
|
+
};
|
|
45
|
+
emitAudit(vorim, event2, asyncAudit);
|
|
46
|
+
throw new Error(`Vorim: permission denied for "${tool.name}" \u2014 scope "${scope}"${reason ? `: ${reason}` : ""}`);
|
|
47
|
+
}
|
|
48
|
+
const start = Date.now();
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = await originalCall(arg, runManager, parentConfig);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const event2 = {
|
|
54
|
+
agent_id: agentId,
|
|
55
|
+
event_type: "tool_call",
|
|
56
|
+
action: tool.name,
|
|
57
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
58
|
+
permission: scope,
|
|
59
|
+
result: "error",
|
|
60
|
+
latency_ms: Date.now() - start,
|
|
61
|
+
error_code: err instanceof Error ? err.name : "UNKNOWN",
|
|
62
|
+
metadata: { error: err instanceof Error ? err.message : String(err), framework: "langchain" }
|
|
63
|
+
};
|
|
64
|
+
emitAudit(vorim, event2, asyncAudit);
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
const event = {
|
|
68
|
+
agent_id: agentId,
|
|
69
|
+
event_type: "tool_call",
|
|
70
|
+
action: tool.name,
|
|
71
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
72
|
+
permission: scope,
|
|
73
|
+
result: "success",
|
|
74
|
+
latency_ms: Date.now() - start,
|
|
75
|
+
metadata: { framework: "langchain" }
|
|
76
|
+
};
|
|
77
|
+
emitAudit(vorim, event, asyncAudit);
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
return tool;
|
|
81
|
+
}
|
|
82
|
+
function wrapTools(tools, config) {
|
|
83
|
+
return tools.map((t) => wrapTool(t, config));
|
|
84
|
+
}
|
|
85
|
+
var VorimCallbackHandler = class _VorimCallbackHandler {
|
|
86
|
+
name = "VorimCallbackHandler";
|
|
87
|
+
vorim;
|
|
88
|
+
agentId;
|
|
89
|
+
runMap = /* @__PURE__ */ new Map();
|
|
90
|
+
// Flags to satisfy BaseCallbackHandler interface
|
|
91
|
+
ignoreLLM = true;
|
|
92
|
+
ignoreChain = true;
|
|
93
|
+
ignoreAgent = true;
|
|
94
|
+
ignoreRetriever = true;
|
|
95
|
+
ignoreCustomEvent = true;
|
|
96
|
+
lc_serializable = false;
|
|
97
|
+
get lc_id() {
|
|
98
|
+
return ["vorim", "callbacks", "VorimCallbackHandler"];
|
|
99
|
+
}
|
|
100
|
+
get lc_namespace() {
|
|
101
|
+
return ["vorim", "callbacks"];
|
|
102
|
+
}
|
|
103
|
+
constructor(vorim, agentId) {
|
|
104
|
+
this.vorim = vorim;
|
|
105
|
+
this.agentId = agentId;
|
|
106
|
+
}
|
|
107
|
+
async handleToolStart(tool, input, runId, _parentRunId, _tags, _metadata, runName) {
|
|
108
|
+
const toolName = runName ?? tool.id?.[tool.id.length - 1] ?? "unknown";
|
|
109
|
+
this.runMap.set(runId, { tool: toolName, input, startTime: Date.now() });
|
|
110
|
+
}
|
|
111
|
+
async handleToolEnd(_output, runId) {
|
|
112
|
+
const run = this.runMap.get(runId);
|
|
113
|
+
if (!run) return;
|
|
114
|
+
this.runMap.delete(runId);
|
|
115
|
+
await this.vorim.emit({
|
|
116
|
+
agent_id: this.agentId,
|
|
117
|
+
event_type: "tool_call",
|
|
118
|
+
action: run.tool,
|
|
119
|
+
resource: truncate(run.input, 500),
|
|
120
|
+
result: "success",
|
|
121
|
+
latency_ms: Date.now() - run.startTime,
|
|
122
|
+
metadata: { framework: "langchain" }
|
|
123
|
+
}).catch(() => {
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async handleToolError(err, runId) {
|
|
127
|
+
const run = this.runMap.get(runId);
|
|
128
|
+
if (!run) return;
|
|
129
|
+
this.runMap.delete(runId);
|
|
130
|
+
await this.vorim.emit({
|
|
131
|
+
agent_id: this.agentId,
|
|
132
|
+
event_type: "tool_call",
|
|
133
|
+
action: run.tool,
|
|
134
|
+
resource: truncate(run.input, 500),
|
|
135
|
+
result: "error",
|
|
136
|
+
latency_ms: Date.now() - run.startTime,
|
|
137
|
+
error_code: err.name,
|
|
138
|
+
metadata: { error: err.message, framework: "langchain" }
|
|
139
|
+
}).catch(() => {
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// Required by BaseCallbackHandler — no-op for events we don't need
|
|
143
|
+
copy() {
|
|
144
|
+
return new _VorimCallbackHandler(this.vorim, this.agentId);
|
|
145
|
+
}
|
|
146
|
+
toJSON() {
|
|
147
|
+
return { lc: 1, type: "not_implemented", id: this.lc_id };
|
|
148
|
+
}
|
|
149
|
+
toJSONNotImplemented() {
|
|
150
|
+
return this.toJSON();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
async function createVorimAgent(config) {
|
|
154
|
+
const { vorim, name, capabilities, scopes, description, tools: rawTools, permissionMap, defaultPermission, asyncAudit } = config;
|
|
155
|
+
const registration = await vorim.register({
|
|
156
|
+
name,
|
|
157
|
+
description,
|
|
158
|
+
capabilities,
|
|
159
|
+
scopes
|
|
160
|
+
});
|
|
161
|
+
const agentId = registration.agent.agent_id;
|
|
162
|
+
const agentConfig = { vorim, agentId, permissionMap, defaultPermission, asyncAudit };
|
|
163
|
+
const tools = wrapTools(rawTools, agentConfig);
|
|
164
|
+
const callbackHandler = new VorimCallbackHandler(vorim, agentId);
|
|
165
|
+
return {
|
|
166
|
+
/** The Vorim agent_id. */
|
|
167
|
+
agentId,
|
|
168
|
+
/** The full agent registration result. */
|
|
169
|
+
registration,
|
|
170
|
+
/** Tools wrapped with Vorim permission checks + audit. */
|
|
171
|
+
tools,
|
|
172
|
+
/** Callback handler for audit trail observability. */
|
|
173
|
+
callbackHandler,
|
|
174
|
+
/** The private key (store securely — shown once). */
|
|
175
|
+
privateKey: registration.private_key
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function truncate(str, max) {
|
|
179
|
+
return str.length > max ? str.slice(0, max) + "\u2026" : str;
|
|
180
|
+
}
|
|
181
|
+
function emitAudit(vorim, event, async) {
|
|
182
|
+
if (async) {
|
|
183
|
+
vorim.emit(event).catch(() => {
|
|
184
|
+
});
|
|
185
|
+
} else {
|
|
186
|
+
vorim.emit(event).catch(() => {
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
+
0 && (module.exports = {
|
|
192
|
+
VorimCallbackHandler,
|
|
193
|
+
createVorimAgent,
|
|
194
|
+
wrapTool,
|
|
195
|
+
wrapTools
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=langchain.cjs.map
|