@vorionsys/cognigate 1.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 +270 -0
- package/dist/index.cjs +515 -0
- package/dist/index.d.cts +506 -0
- package/dist/index.js +477 -0
- package/package.json +54 -0
- package/src/__tests__/client.test.ts +162 -0
- package/src/client.ts +421 -0
- package/src/index.ts +76 -0
- package/src/types.ts +272 -0
- package/src/webhooks.ts +146 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# @vorion/cognigate
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the [Cognigate](https://cognigate.dev) AI Governance API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vorionsys/cognigate
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Cognigate } from '@vorionsys/cognigate';
|
|
15
|
+
|
|
16
|
+
const client = new Cognigate({
|
|
17
|
+
apiKey: process.env.COGNIGATE_API_KEY,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Get trust status for an agent
|
|
21
|
+
const status = await client.trust.getStatus('agent-123');
|
|
22
|
+
console.log(`Trust Score: ${status.trustScore}`);
|
|
23
|
+
console.log(`Tier: ${status.tierName}`);
|
|
24
|
+
console.log(`Capabilities: ${status.capabilities.join(', ')}`);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **Full TypeScript Support**: Complete type definitions with Zod runtime validation
|
|
30
|
+
- **Trust Management**: Query and update agent trust scores
|
|
31
|
+
- **Governance Enforcement**: Parse intents and enforce governance rules
|
|
32
|
+
- **Proof Chain**: Immutable audit trail for all agent actions
|
|
33
|
+
- **Webhook Support**: Handle Cognigate webhooks with signature verification
|
|
34
|
+
|
|
35
|
+
## API Reference
|
|
36
|
+
|
|
37
|
+
### Initialization
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const client = new Cognigate({
|
|
41
|
+
apiKey: 'your-api-key', // Required
|
|
42
|
+
baseUrl: 'https://...', // Optional: custom API URL
|
|
43
|
+
timeout: 30000, // Optional: request timeout in ms
|
|
44
|
+
retries: 3, // Optional: number of retries
|
|
45
|
+
debug: false, // Optional: enable debug logging
|
|
46
|
+
webhookSecret: 'secret', // Optional: for webhook verification
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Agents
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// List agents
|
|
54
|
+
const agents = await client.agents.list({ status: 'ACTIVE' });
|
|
55
|
+
|
|
56
|
+
// Get agent
|
|
57
|
+
const agent = await client.agents.get('agent-123');
|
|
58
|
+
|
|
59
|
+
// Create agent
|
|
60
|
+
const newAgent = await client.agents.create({
|
|
61
|
+
name: 'DataProcessor',
|
|
62
|
+
description: 'Processes data pipelines',
|
|
63
|
+
template: 'data-processor',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Update agent
|
|
67
|
+
await client.agents.update('agent-123', { name: 'New Name' });
|
|
68
|
+
|
|
69
|
+
// Pause/Resume
|
|
70
|
+
await client.agents.pause('agent-123');
|
|
71
|
+
await client.agents.resume('agent-123');
|
|
72
|
+
|
|
73
|
+
// Delete agent
|
|
74
|
+
await client.agents.delete('agent-123');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Trust
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Get trust status
|
|
81
|
+
const status = await client.trust.getStatus('agent-123');
|
|
82
|
+
// Returns: { trustScore, trustTier, tierName, capabilities, factorScores, ... }
|
|
83
|
+
|
|
84
|
+
// Get trust history
|
|
85
|
+
const history = await client.trust.getHistory('agent-123', {
|
|
86
|
+
from: new Date('2024-01-01'),
|
|
87
|
+
limit: 100,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Submit outcome (updates trust score)
|
|
91
|
+
const updated = await client.trust.submitOutcome('agent-123', 'proof-456', {
|
|
92
|
+
success: true,
|
|
93
|
+
metrics: { latency: 234, accuracy: 0.98 },
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Governance
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// Parse intent
|
|
101
|
+
const parsed = await client.governance.parseIntent(
|
|
102
|
+
'agent-123',
|
|
103
|
+
'Read customer data from the sales database'
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Enforce governance
|
|
107
|
+
const result = await client.governance.enforce(parsed.intent);
|
|
108
|
+
// Returns: { decision, trustScore, grantedCapabilities, reasoning, proofId }
|
|
109
|
+
|
|
110
|
+
// Combined: parse + enforce
|
|
111
|
+
const { intent, result } = await client.governance.evaluate(
|
|
112
|
+
'agent-123',
|
|
113
|
+
'Send email to customer'
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (result.decision === 'ALLOW') {
|
|
117
|
+
// Proceed with action
|
|
118
|
+
} else if (result.decision === 'ESCALATE') {
|
|
119
|
+
// Request human approval
|
|
120
|
+
} else {
|
|
121
|
+
// Action denied
|
|
122
|
+
console.log(result.reasoning);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Check capability without creating proof
|
|
126
|
+
const check = await client.governance.canPerform(
|
|
127
|
+
'agent-123',
|
|
128
|
+
'write_file',
|
|
129
|
+
['file_write', 'approved_directories']
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Proofs
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Get proof record
|
|
137
|
+
const proof = await client.proofs.get('proof-123');
|
|
138
|
+
|
|
139
|
+
// List proofs for entity
|
|
140
|
+
const proofs = await client.proofs.list('agent-123', {
|
|
141
|
+
from: new Date('2024-01-01'),
|
|
142
|
+
outcome: 'SUCCESS',
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Get chain statistics
|
|
146
|
+
const stats = await client.proofs.getStats('agent-123');
|
|
147
|
+
// Returns: { totalRecords, successRate, averageTrustScore, chainIntegrity }
|
|
148
|
+
|
|
149
|
+
// Verify chain integrity
|
|
150
|
+
const verification = await client.proofs.verify('agent-123');
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Webhooks
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { WebhookRouter, parseWebhookPayload } from '@vorionsys/cognigate';
|
|
157
|
+
|
|
158
|
+
const router = new WebhookRouter();
|
|
159
|
+
|
|
160
|
+
// Handle specific events
|
|
161
|
+
router.on('trust.tier_changed', async (event) => {
|
|
162
|
+
console.log(`Agent ${event.entityId} tier changed:`, event.payload);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
router.on('governance.decision', async (event) => {
|
|
166
|
+
if (event.payload.decision === 'ESCALATE') {
|
|
167
|
+
// Alert human reviewer
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Handle all events
|
|
172
|
+
router.onAll(async (event) => {
|
|
173
|
+
await logEvent(event);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Express middleware
|
|
177
|
+
app.post('/webhooks/cognigate', router.middleware(process.env.WEBHOOK_SECRET));
|
|
178
|
+
|
|
179
|
+
// Or manual verification
|
|
180
|
+
app.post('/webhooks/cognigate', async (req, res) => {
|
|
181
|
+
try {
|
|
182
|
+
const event = await parseWebhookPayload(
|
|
183
|
+
req.body,
|
|
184
|
+
req.headers['x-cognigate-signature'],
|
|
185
|
+
process.env.WEBHOOK_SECRET
|
|
186
|
+
);
|
|
187
|
+
await router.handle(event);
|
|
188
|
+
res.json({ received: true });
|
|
189
|
+
} catch (error) {
|
|
190
|
+
res.status(400).json({ error: error.message });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Trust Tiers
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { Cognigate, TrustTier, TIER_THRESHOLDS } from '@vorionsys/cognigate';
|
|
199
|
+
|
|
200
|
+
// Get tier from score
|
|
201
|
+
const tier = Cognigate.getTierFromScore(750);
|
|
202
|
+
// Returns: TrustTier.T4_OPERATIONAL
|
|
203
|
+
|
|
204
|
+
// Get tier name
|
|
205
|
+
const name = Cognigate.getTierName(TrustTier.T5_TRUSTED);
|
|
206
|
+
// Returns: "Trusted"
|
|
207
|
+
|
|
208
|
+
// Get tier thresholds
|
|
209
|
+
const thresholds = Cognigate.getTierThresholds(TrustTier.T4_OPERATIONAL);
|
|
210
|
+
// Returns: { min: 650, max: 799, name: "Operational" }
|
|
211
|
+
|
|
212
|
+
// All tiers
|
|
213
|
+
console.log(TIER_THRESHOLDS);
|
|
214
|
+
// T0_SANDBOX: 0-199
|
|
215
|
+
// T1_OBSERVED: 200-349
|
|
216
|
+
// T2_PROVISIONAL: 350-499
|
|
217
|
+
// T3_VERIFIED: 500-649
|
|
218
|
+
// T4_OPERATIONAL: 650-799
|
|
219
|
+
// T5_TRUSTED: 800-875
|
|
220
|
+
// T6_CERTIFIED: 876-949
|
|
221
|
+
// T7_AUTONOMOUS: 950-1000
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Error Handling
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { Cognigate, CognigateError } from '@vorionsys/cognigate';
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const status = await client.trust.getStatus('invalid-id');
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (error instanceof CognigateError) {
|
|
233
|
+
console.log('Code:', error.code);
|
|
234
|
+
console.log('Message:', error.message);
|
|
235
|
+
console.log('Status:', error.status);
|
|
236
|
+
console.log('Details:', error.details);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## TypeScript Types
|
|
242
|
+
|
|
243
|
+
All types are exported and can be imported:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import type {
|
|
247
|
+
Agent,
|
|
248
|
+
TrustStatus,
|
|
249
|
+
GovernanceResult,
|
|
250
|
+
Intent,
|
|
251
|
+
ProofRecord,
|
|
252
|
+
WebhookEvent,
|
|
253
|
+
TrustTier,
|
|
254
|
+
GovernanceDecision,
|
|
255
|
+
} from '@vorionsys/cognigate';
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Runtime Validation
|
|
259
|
+
|
|
260
|
+
Zod schemas are exported for runtime validation:
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { TrustStatusSchema, AgentSchema } from '@vorionsys/cognigate';
|
|
264
|
+
|
|
265
|
+
const validatedStatus = TrustStatusSchema.parse(untrustedData);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
MIT
|