@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.
@@ -0,0 +1,506 @@
1
+ import { z } from 'zod';
2
+ export { z } from 'zod';
3
+
4
+ /**
5
+ * Cognigate TypeScript SDK - Type Definitions
6
+ *
7
+ * Core types for the Cognigate AI governance API
8
+ */
9
+
10
+ declare enum TrustTier {
11
+ T0_SANDBOX = 0,
12
+ T1_OBSERVED = 1,
13
+ T2_PROVISIONAL = 2,
14
+ T3_VERIFIED = 3,
15
+ T4_OPERATIONAL = 4,
16
+ T5_TRUSTED = 5,
17
+ T6_CERTIFIED = 6,
18
+ T7_AUTONOMOUS = 7
19
+ }
20
+ declare const TIER_THRESHOLDS: Record<TrustTier, {
21
+ min: number;
22
+ max: number;
23
+ name: string;
24
+ }>;
25
+ type GovernanceDecision = 'ALLOW' | 'DENY' | 'ESCALATE' | 'DEGRADE';
26
+ interface GovernanceResult {
27
+ decision: GovernanceDecision;
28
+ trustScore: number;
29
+ trustTier: TrustTier;
30
+ grantedCapabilities: string[];
31
+ deniedCapabilities: string[];
32
+ reasoning: string;
33
+ constraints?: Record<string, unknown>;
34
+ proofId?: string;
35
+ timestamp: Date;
36
+ }
37
+ interface Intent {
38
+ id: string;
39
+ entityId: string;
40
+ rawInput: string;
41
+ parsedAction: string;
42
+ parameters: Record<string, unknown>;
43
+ riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
44
+ requiredCapabilities: string[];
45
+ timestamp: Date;
46
+ }
47
+ interface IntentParseResult {
48
+ intent: Intent;
49
+ confidence: number;
50
+ alternativeInterpretations?: Intent[];
51
+ }
52
+ interface TrustStatus {
53
+ entityId: string;
54
+ trustScore: number;
55
+ trustTier: TrustTier;
56
+ tierName: string;
57
+ capabilities: string[];
58
+ factorScores: Record<string, number>;
59
+ lastEvaluated: Date;
60
+ compliant: boolean;
61
+ warnings: string[];
62
+ }
63
+ interface ProofRecord {
64
+ id: string;
65
+ entityId: string;
66
+ intentId: string;
67
+ decision: GovernanceDecision;
68
+ action: string;
69
+ outcome: 'SUCCESS' | 'FAILURE' | 'PARTIAL' | 'PENDING';
70
+ trustScoreBefore: number;
71
+ trustScoreAfter: number;
72
+ timestamp: Date;
73
+ hash: string;
74
+ previousHash: string;
75
+ metadata?: Record<string, unknown>;
76
+ }
77
+ interface ProofChainStats {
78
+ totalRecords: number;
79
+ successRate: number;
80
+ averageTrustScore: number;
81
+ chainIntegrity: boolean;
82
+ lastVerified: Date;
83
+ }
84
+ interface Agent {
85
+ id: string;
86
+ name: string;
87
+ description: string;
88
+ ownerId: string;
89
+ trustScore: number;
90
+ trustTier: TrustTier;
91
+ status: 'ACTIVE' | 'PAUSED' | 'SUSPENDED' | 'TERMINATED';
92
+ capabilities: string[];
93
+ executions: number;
94
+ successRate: number;
95
+ createdAt: Date;
96
+ updatedAt: Date;
97
+ metadata?: Record<string, unknown>;
98
+ }
99
+ interface CreateAgentRequest {
100
+ name: string;
101
+ description?: string;
102
+ template?: string;
103
+ initialCapabilities?: string[];
104
+ metadata?: Record<string, unknown>;
105
+ }
106
+ interface UpdateAgentRequest {
107
+ name?: string;
108
+ description?: string;
109
+ status?: 'ACTIVE' | 'PAUSED';
110
+ metadata?: Record<string, unknown>;
111
+ }
112
+ interface ApiResponse<T> {
113
+ success: boolean;
114
+ data?: T;
115
+ error?: ApiError;
116
+ requestId: string;
117
+ timestamp: Date;
118
+ }
119
+ interface ApiError {
120
+ code: string;
121
+ message: string;
122
+ details?: Record<string, unknown>;
123
+ }
124
+ interface PaginatedResponse<T> {
125
+ items: T[];
126
+ total: number;
127
+ page: number;
128
+ pageSize: number;
129
+ hasMore: boolean;
130
+ }
131
+ interface WebhookEvent {
132
+ id: string;
133
+ type: WebhookEventType;
134
+ entityId: string;
135
+ payload: Record<string, unknown>;
136
+ timestamp: Date;
137
+ signature: string;
138
+ }
139
+ type WebhookEventType = 'agent.created' | 'agent.updated' | 'agent.deleted' | 'agent.status_changed' | 'trust.score_changed' | 'trust.tier_changed' | 'governance.decision' | 'proof.recorded' | 'alert.triggered';
140
+ interface CognigateConfig {
141
+ apiKey: string;
142
+ baseUrl?: string;
143
+ timeout?: number;
144
+ retries?: number;
145
+ debug?: boolean;
146
+ webhookSecret?: string;
147
+ }
148
+ declare const TrustStatusSchema: z.ZodObject<{
149
+ entityId: z.ZodString;
150
+ trustScore: z.ZodNumber;
151
+ trustTier: z.ZodNativeEnum<typeof TrustTier>;
152
+ tierName: z.ZodString;
153
+ capabilities: z.ZodArray<z.ZodString, "many">;
154
+ factorScores: z.ZodRecord<z.ZodString, z.ZodNumber>;
155
+ lastEvaluated: z.ZodDate;
156
+ compliant: z.ZodBoolean;
157
+ warnings: z.ZodArray<z.ZodString, "many">;
158
+ }, "strip", z.ZodTypeAny, {
159
+ entityId: string;
160
+ trustScore: number;
161
+ trustTier: TrustTier;
162
+ tierName: string;
163
+ capabilities: string[];
164
+ factorScores: Record<string, number>;
165
+ lastEvaluated: Date;
166
+ compliant: boolean;
167
+ warnings: string[];
168
+ }, {
169
+ entityId: string;
170
+ trustScore: number;
171
+ trustTier: TrustTier;
172
+ tierName: string;
173
+ capabilities: string[];
174
+ factorScores: Record<string, number>;
175
+ lastEvaluated: Date;
176
+ compliant: boolean;
177
+ warnings: string[];
178
+ }>;
179
+ declare const GovernanceResultSchema: z.ZodObject<{
180
+ decision: z.ZodEnum<["ALLOW", "DENY", "ESCALATE", "DEGRADE"]>;
181
+ trustScore: z.ZodNumber;
182
+ trustTier: z.ZodNativeEnum<typeof TrustTier>;
183
+ grantedCapabilities: z.ZodArray<z.ZodString, "many">;
184
+ deniedCapabilities: z.ZodArray<z.ZodString, "many">;
185
+ reasoning: z.ZodString;
186
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
187
+ proofId: z.ZodOptional<z.ZodString>;
188
+ timestamp: z.ZodDate;
189
+ }, "strip", z.ZodTypeAny, {
190
+ trustScore: number;
191
+ trustTier: TrustTier;
192
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
193
+ grantedCapabilities: string[];
194
+ deniedCapabilities: string[];
195
+ reasoning: string;
196
+ timestamp: Date;
197
+ constraints?: Record<string, unknown> | undefined;
198
+ proofId?: string | undefined;
199
+ }, {
200
+ trustScore: number;
201
+ trustTier: TrustTier;
202
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
203
+ grantedCapabilities: string[];
204
+ deniedCapabilities: string[];
205
+ reasoning: string;
206
+ timestamp: Date;
207
+ constraints?: Record<string, unknown> | undefined;
208
+ proofId?: string | undefined;
209
+ }>;
210
+ declare const ProofRecordSchema: z.ZodObject<{
211
+ id: z.ZodString;
212
+ entityId: z.ZodString;
213
+ intentId: z.ZodString;
214
+ decision: z.ZodEnum<["ALLOW", "DENY", "ESCALATE", "DEGRADE"]>;
215
+ action: z.ZodString;
216
+ outcome: z.ZodEnum<["SUCCESS", "FAILURE", "PARTIAL", "PENDING"]>;
217
+ trustScoreBefore: z.ZodNumber;
218
+ trustScoreAfter: z.ZodNumber;
219
+ timestamp: z.ZodDate;
220
+ hash: z.ZodString;
221
+ previousHash: z.ZodString;
222
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
223
+ }, "strip", z.ZodTypeAny, {
224
+ entityId: string;
225
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
226
+ timestamp: Date;
227
+ id: string;
228
+ intentId: string;
229
+ action: string;
230
+ outcome: "SUCCESS" | "FAILURE" | "PARTIAL" | "PENDING";
231
+ trustScoreBefore: number;
232
+ trustScoreAfter: number;
233
+ hash: string;
234
+ previousHash: string;
235
+ metadata?: Record<string, unknown> | undefined;
236
+ }, {
237
+ entityId: string;
238
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
239
+ timestamp: Date;
240
+ id: string;
241
+ intentId: string;
242
+ action: string;
243
+ outcome: "SUCCESS" | "FAILURE" | "PARTIAL" | "PENDING";
244
+ trustScoreBefore: number;
245
+ trustScoreAfter: number;
246
+ hash: string;
247
+ previousHash: string;
248
+ metadata?: Record<string, unknown> | undefined;
249
+ }>;
250
+ declare const AgentSchema: z.ZodObject<{
251
+ id: z.ZodString;
252
+ name: z.ZodString;
253
+ description: z.ZodString;
254
+ ownerId: z.ZodString;
255
+ trustScore: z.ZodNumber;
256
+ trustTier: z.ZodNativeEnum<typeof TrustTier>;
257
+ status: z.ZodEnum<["ACTIVE", "PAUSED", "SUSPENDED", "TERMINATED"]>;
258
+ capabilities: z.ZodArray<z.ZodString, "many">;
259
+ executions: z.ZodNumber;
260
+ successRate: z.ZodNumber;
261
+ createdAt: z.ZodDate;
262
+ updatedAt: z.ZodDate;
263
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
264
+ }, "strip", z.ZodTypeAny, {
265
+ trustScore: number;
266
+ trustTier: TrustTier;
267
+ status: "ACTIVE" | "PAUSED" | "SUSPENDED" | "TERMINATED";
268
+ capabilities: string[];
269
+ id: string;
270
+ name: string;
271
+ description: string;
272
+ ownerId: string;
273
+ executions: number;
274
+ successRate: number;
275
+ createdAt: Date;
276
+ updatedAt: Date;
277
+ metadata?: Record<string, unknown> | undefined;
278
+ }, {
279
+ trustScore: number;
280
+ trustTier: TrustTier;
281
+ status: "ACTIVE" | "PAUSED" | "SUSPENDED" | "TERMINATED";
282
+ capabilities: string[];
283
+ id: string;
284
+ name: string;
285
+ description: string;
286
+ ownerId: string;
287
+ executions: number;
288
+ successRate: number;
289
+ createdAt: Date;
290
+ updatedAt: Date;
291
+ metadata?: Record<string, unknown> | undefined;
292
+ }>;
293
+
294
+ /**
295
+ * Cognigate TypeScript SDK - Client
296
+ *
297
+ * Main client class for interacting with the Cognigate API
298
+ */
299
+
300
+ declare class CognigateError extends Error {
301
+ code: string;
302
+ status?: number | undefined;
303
+ details?: Record<string, unknown> | undefined;
304
+ constructor(message: string, code: string, status?: number | undefined, details?: Record<string, unknown> | undefined);
305
+ }
306
+ declare class Cognigate {
307
+ private readonly config;
308
+ readonly agents: AgentsClient;
309
+ readonly trust: TrustClient;
310
+ readonly governance: GovernanceClient;
311
+ readonly proofs: ProofsClient;
312
+ constructor(config: CognigateConfig);
313
+ /**
314
+ * Make an authenticated request to the Cognigate API
315
+ */
316
+ request<T>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, body?: unknown): Promise<T>;
317
+ /**
318
+ * Check API health
319
+ */
320
+ health(): Promise<{
321
+ status: string;
322
+ version: string;
323
+ timestamp: Date;
324
+ }>;
325
+ /**
326
+ * Get tier from trust score
327
+ */
328
+ static getTierFromScore(score: number): TrustTier;
329
+ /**
330
+ * Get tier name
331
+ */
332
+ static getTierName(tier: TrustTier): string;
333
+ /**
334
+ * Get tier thresholds
335
+ */
336
+ static getTierThresholds(tier: TrustTier): {
337
+ min: number;
338
+ max: number;
339
+ name: string;
340
+ };
341
+ }
342
+ declare class AgentsClient {
343
+ private client;
344
+ constructor(client: Cognigate);
345
+ /**
346
+ * List all agents
347
+ */
348
+ list(params?: {
349
+ page?: number;
350
+ pageSize?: number;
351
+ status?: 'ACTIVE' | 'PAUSED' | 'SUSPENDED';
352
+ }): Promise<PaginatedResponse<Agent>>;
353
+ /**
354
+ * Get a specific agent
355
+ */
356
+ get(agentId: string): Promise<Agent>;
357
+ /**
358
+ * Create a new agent
359
+ */
360
+ create(data: CreateAgentRequest): Promise<Agent>;
361
+ /**
362
+ * Update an agent
363
+ */
364
+ update(agentId: string, data: UpdateAgentRequest): Promise<Agent>;
365
+ /**
366
+ * Delete an agent
367
+ */
368
+ delete(agentId: string): Promise<void>;
369
+ /**
370
+ * Pause an agent
371
+ */
372
+ pause(agentId: string): Promise<Agent>;
373
+ /**
374
+ * Resume an agent
375
+ */
376
+ resume(agentId: string): Promise<Agent>;
377
+ }
378
+ declare class TrustClient {
379
+ private client;
380
+ constructor(client: Cognigate);
381
+ /**
382
+ * Get trust status for an entity
383
+ */
384
+ getStatus(entityId: string): Promise<TrustStatus>;
385
+ /**
386
+ * Get trust history
387
+ */
388
+ getHistory(entityId: string, params?: {
389
+ from?: Date;
390
+ to?: Date;
391
+ limit?: number;
392
+ }): Promise<Array<{
393
+ score: number;
394
+ tier: TrustTier;
395
+ timestamp: Date;
396
+ }>>;
397
+ /**
398
+ * Submit an outcome to update trust score
399
+ */
400
+ submitOutcome(entityId: string, proofId: string, outcome: {
401
+ success: boolean;
402
+ metrics?: Record<string, number>;
403
+ notes?: string;
404
+ }): Promise<TrustStatus>;
405
+ }
406
+ declare class GovernanceClient {
407
+ private client;
408
+ constructor(client: Cognigate);
409
+ /**
410
+ * Parse user intent into structured format
411
+ */
412
+ parseIntent(entityId: string, rawInput: string): Promise<IntentParseResult>;
413
+ /**
414
+ * Enforce governance rules on an intent
415
+ */
416
+ enforce(intent: Intent): Promise<GovernanceResult>;
417
+ /**
418
+ * Convenience method: parse and enforce in one call
419
+ */
420
+ evaluate(entityId: string, rawInput: string): Promise<{
421
+ intent: Intent;
422
+ result: GovernanceResult;
423
+ }>;
424
+ /**
425
+ * Check if an action is allowed without creating a proof record
426
+ */
427
+ canPerform(entityId: string, action: string, capabilities: string[]): Promise<{
428
+ allowed: boolean;
429
+ reason: string;
430
+ }>;
431
+ }
432
+ declare class ProofsClient {
433
+ private client;
434
+ constructor(client: Cognigate);
435
+ /**
436
+ * Get a specific proof record
437
+ */
438
+ get(proofId: string): Promise<ProofRecord>;
439
+ /**
440
+ * List proof records for an entity
441
+ */
442
+ list(entityId: string, params?: {
443
+ page?: number;
444
+ pageSize?: number;
445
+ from?: Date;
446
+ to?: Date;
447
+ outcome?: 'SUCCESS' | 'FAILURE' | 'PARTIAL';
448
+ }): Promise<PaginatedResponse<ProofRecord>>;
449
+ /**
450
+ * Get proof chain statistics
451
+ */
452
+ getStats(entityId: string): Promise<ProofChainStats>;
453
+ /**
454
+ * Verify proof chain integrity
455
+ */
456
+ verify(entityId: string): Promise<{
457
+ valid: boolean;
458
+ errors: string[];
459
+ lastVerified: Date;
460
+ }>;
461
+ }
462
+
463
+ /**
464
+ * Cognigate TypeScript SDK - Webhook Utilities
465
+ *
466
+ * Helpers for handling Cognigate webhooks
467
+ */
468
+
469
+ /**
470
+ * Verify webhook signature
471
+ */
472
+ declare function verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
473
+ /**
474
+ * Parse and validate a webhook payload
475
+ */
476
+ declare function parseWebhookPayload(body: string, signature: string, secret: string): Promise<WebhookEvent>;
477
+ /**
478
+ * Webhook handler type
479
+ */
480
+ type WebhookHandler<T extends WebhookEventType = WebhookEventType> = (event: WebhookEvent & {
481
+ type: T;
482
+ }) => void | Promise<void>;
483
+ /**
484
+ * Webhook router for handling different event types
485
+ */
486
+ declare class WebhookRouter {
487
+ private handlers;
488
+ /**
489
+ * Register a handler for a specific event type
490
+ */
491
+ on<T extends WebhookEventType>(type: T, handler: WebhookHandler<T>): this;
492
+ /**
493
+ * Register a handler for all events
494
+ */
495
+ onAll(handler: WebhookHandler): this;
496
+ /**
497
+ * Handle a webhook event
498
+ */
499
+ handle(event: WebhookEvent): Promise<void>;
500
+ /**
501
+ * Create an Express/Connect compatible middleware
502
+ */
503
+ middleware(secret: string): (req: any, res: any, _next?: () => void) => Promise<void>;
504
+ }
505
+
506
+ export { type Agent, AgentSchema, AgentsClient, type ApiError, type ApiResponse, Cognigate, type CognigateConfig, CognigateError, type CreateAgentRequest, GovernanceClient, type GovernanceDecision, type GovernanceResult, GovernanceResultSchema, type Intent, type IntentParseResult, type PaginatedResponse, type ProofChainStats, type ProofRecord, ProofRecordSchema, ProofsClient, TIER_THRESHOLDS, TrustClient, type TrustStatus, TrustStatusSchema, TrustTier, type UpdateAgentRequest, type WebhookEvent, type WebhookEventType, type WebhookHandler, WebhookRouter, parseWebhookPayload, verifyWebhookSignature };