@vorionsys/cognigate 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,394 @@
1
+ import { z } from 'zod';
2
+ import { TrustTier } from '@vorionsys/shared-constants';
3
+
4
+ /**
5
+ * Cognigate TypeScript SDK - Type Definitions
6
+ *
7
+ * Core types for the Cognigate AI governance API
8
+ */
9
+
10
+ type GovernanceDecision = 'ALLOW' | 'DENY' | 'ESCALATE' | 'DEGRADE';
11
+ interface GovernanceResult {
12
+ decision: GovernanceDecision;
13
+ trustScore: number;
14
+ trustTier: TrustTier;
15
+ grantedCapabilities: string[];
16
+ deniedCapabilities: string[];
17
+ reasoning: string;
18
+ constraints?: Record<string, unknown>;
19
+ proofId?: string;
20
+ timestamp: Date;
21
+ }
22
+ interface Intent {
23
+ id: string;
24
+ entityId: string;
25
+ rawInput: string;
26
+ parsedAction: string;
27
+ parameters: Record<string, unknown>;
28
+ riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
29
+ requiredCapabilities: string[];
30
+ timestamp: Date;
31
+ }
32
+ interface IntentParseResult {
33
+ intent: Intent;
34
+ confidence: number;
35
+ alternativeInterpretations?: Intent[];
36
+ }
37
+ interface TrustStatus {
38
+ entityId: string;
39
+ trustScore: number;
40
+ trustTier: TrustTier;
41
+ tierName: string;
42
+ capabilities: string[];
43
+ factorScores: Record<string, number>;
44
+ lastEvaluated: Date;
45
+ compliant: boolean;
46
+ warnings: string[];
47
+ }
48
+ interface ProofRecord {
49
+ id: string;
50
+ entityId: string;
51
+ intentId: string;
52
+ decision: GovernanceDecision;
53
+ action: string;
54
+ outcome: 'SUCCESS' | 'FAILURE' | 'PARTIAL' | 'PENDING';
55
+ trustScoreBefore: number;
56
+ trustScoreAfter: number;
57
+ timestamp: Date;
58
+ hash: string;
59
+ previousHash: string;
60
+ metadata?: Record<string, unknown>;
61
+ }
62
+ interface ProofChainStats {
63
+ totalRecords: number;
64
+ successRate: number;
65
+ averageTrustScore: number;
66
+ chainIntegrity: boolean;
67
+ lastVerified: Date;
68
+ }
69
+ interface Agent {
70
+ id: string;
71
+ name: string;
72
+ description: string;
73
+ ownerId: string;
74
+ trustScore: number;
75
+ trustTier: TrustTier;
76
+ status: 'ACTIVE' | 'PAUSED' | 'SUSPENDED' | 'TERMINATED';
77
+ capabilities: string[];
78
+ executions: number;
79
+ successRate: number;
80
+ createdAt: Date;
81
+ updatedAt: Date;
82
+ metadata?: Record<string, unknown>;
83
+ }
84
+ interface CreateAgentRequest {
85
+ name: string;
86
+ description?: string;
87
+ template?: string;
88
+ initialCapabilities?: string[];
89
+ metadata?: Record<string, unknown>;
90
+ }
91
+ interface UpdateAgentRequest {
92
+ name?: string;
93
+ description?: string;
94
+ status?: 'ACTIVE' | 'PAUSED';
95
+ metadata?: Record<string, unknown>;
96
+ }
97
+ interface ApiResponse<T> {
98
+ success: boolean;
99
+ data?: T;
100
+ error?: ApiError;
101
+ requestId: string;
102
+ timestamp: Date;
103
+ }
104
+ interface ApiError {
105
+ code: string;
106
+ message: string;
107
+ details?: Record<string, unknown>;
108
+ }
109
+ interface PaginatedResponse<T> {
110
+ items: T[];
111
+ total: number;
112
+ page: number;
113
+ pageSize: number;
114
+ hasMore: boolean;
115
+ }
116
+ interface WebhookEvent {
117
+ id: string;
118
+ type: WebhookEventType;
119
+ entityId: string;
120
+ payload: Record<string, unknown>;
121
+ timestamp: Date;
122
+ signature: string;
123
+ }
124
+ type WebhookEventType = 'agent.created' | 'agent.updated' | 'agent.deleted' | 'agent.status_changed' | 'trust.score_changed' | 'trust.tier_changed' | 'governance.decision' | 'proof.recorded' | 'alert.triggered';
125
+ interface CognigateConfig {
126
+ apiKey: string;
127
+ baseUrl?: string;
128
+ timeout?: number;
129
+ retries?: number;
130
+ debug?: boolean;
131
+ webhookSecret?: string;
132
+ }
133
+ declare const TrustStatusSchema: z.ZodObject<{
134
+ entityId: z.ZodString;
135
+ trustScore: z.ZodNumber;
136
+ trustTier: z.ZodNativeEnum<typeof TrustTier>;
137
+ tierName: z.ZodString;
138
+ capabilities: z.ZodArray<z.ZodString, "many">;
139
+ factorScores: z.ZodRecord<z.ZodString, z.ZodNumber>;
140
+ lastEvaluated: z.ZodDate;
141
+ compliant: z.ZodBoolean;
142
+ warnings: z.ZodArray<z.ZodString, "many">;
143
+ }, "strip", z.ZodTypeAny, {
144
+ trustScore: number;
145
+ entityId: string;
146
+ trustTier: TrustTier;
147
+ tierName: string;
148
+ capabilities: string[];
149
+ factorScores: Record<string, number>;
150
+ lastEvaluated: Date;
151
+ compliant: boolean;
152
+ warnings: string[];
153
+ }, {
154
+ trustScore: number;
155
+ entityId: string;
156
+ trustTier: TrustTier;
157
+ tierName: string;
158
+ capabilities: string[];
159
+ factorScores: Record<string, number>;
160
+ lastEvaluated: Date;
161
+ compliant: boolean;
162
+ warnings: string[];
163
+ }>;
164
+ declare const GovernanceResultSchema: z.ZodObject<{
165
+ decision: z.ZodEnum<["ALLOW", "DENY", "ESCALATE", "DEGRADE"]>;
166
+ trustScore: z.ZodNumber;
167
+ trustTier: z.ZodNativeEnum<typeof TrustTier>;
168
+ grantedCapabilities: z.ZodArray<z.ZodString, "many">;
169
+ deniedCapabilities: z.ZodArray<z.ZodString, "many">;
170
+ reasoning: z.ZodString;
171
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
172
+ proofId: z.ZodOptional<z.ZodString>;
173
+ timestamp: z.ZodDate;
174
+ }, "strip", z.ZodTypeAny, {
175
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
176
+ trustScore: number;
177
+ reasoning: string;
178
+ trustTier: TrustTier;
179
+ grantedCapabilities: string[];
180
+ deniedCapabilities: string[];
181
+ timestamp: Date;
182
+ constraints?: Record<string, unknown> | undefined;
183
+ proofId?: string | undefined;
184
+ }, {
185
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
186
+ trustScore: number;
187
+ reasoning: string;
188
+ trustTier: TrustTier;
189
+ grantedCapabilities: string[];
190
+ deniedCapabilities: string[];
191
+ timestamp: Date;
192
+ constraints?: Record<string, unknown> | undefined;
193
+ proofId?: string | undefined;
194
+ }>;
195
+ declare const ProofRecordSchema: z.ZodObject<{
196
+ id: z.ZodString;
197
+ entityId: z.ZodString;
198
+ intentId: z.ZodString;
199
+ decision: z.ZodEnum<["ALLOW", "DENY", "ESCALATE", "DEGRADE"]>;
200
+ action: z.ZodString;
201
+ outcome: z.ZodEnum<["SUCCESS", "FAILURE", "PARTIAL", "PENDING"]>;
202
+ trustScoreBefore: z.ZodNumber;
203
+ trustScoreAfter: z.ZodNumber;
204
+ timestamp: z.ZodDate;
205
+ hash: z.ZodString;
206
+ previousHash: z.ZodString;
207
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
208
+ }, "strip", z.ZodTypeAny, {
209
+ intentId: string;
210
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
211
+ entityId: string;
212
+ timestamp: Date;
213
+ id: string;
214
+ action: string;
215
+ outcome: "SUCCESS" | "FAILURE" | "PARTIAL" | "PENDING";
216
+ trustScoreBefore: number;
217
+ trustScoreAfter: number;
218
+ hash: string;
219
+ previousHash: string;
220
+ metadata?: Record<string, unknown> | undefined;
221
+ }, {
222
+ intentId: string;
223
+ decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
224
+ entityId: string;
225
+ timestamp: Date;
226
+ id: string;
227
+ action: string;
228
+ outcome: "SUCCESS" | "FAILURE" | "PARTIAL" | "PENDING";
229
+ trustScoreBefore: number;
230
+ trustScoreAfter: number;
231
+ hash: string;
232
+ previousHash: string;
233
+ metadata?: Record<string, unknown> | undefined;
234
+ }>;
235
+ declare const AgentSchema: z.ZodObject<{
236
+ id: z.ZodString;
237
+ name: z.ZodString;
238
+ description: z.ZodString;
239
+ ownerId: z.ZodString;
240
+ trustScore: z.ZodNumber;
241
+ trustTier: z.ZodNativeEnum<typeof TrustTier>;
242
+ status: z.ZodEnum<["ACTIVE", "PAUSED", "SUSPENDED", "TERMINATED"]>;
243
+ capabilities: z.ZodArray<z.ZodString, "many">;
244
+ executions: z.ZodNumber;
245
+ successRate: z.ZodNumber;
246
+ createdAt: z.ZodDate;
247
+ updatedAt: z.ZodDate;
248
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
249
+ }, "strip", z.ZodTypeAny, {
250
+ trustScore: number;
251
+ trustTier: TrustTier;
252
+ status: "ACTIVE" | "PAUSED" | "SUSPENDED" | "TERMINATED";
253
+ capabilities: string[];
254
+ id: string;
255
+ name: string;
256
+ description: string;
257
+ ownerId: string;
258
+ executions: number;
259
+ successRate: number;
260
+ createdAt: Date;
261
+ updatedAt: Date;
262
+ metadata?: Record<string, unknown> | undefined;
263
+ }, {
264
+ trustScore: number;
265
+ trustTier: TrustTier;
266
+ status: "ACTIVE" | "PAUSED" | "SUSPENDED" | "TERMINATED";
267
+ capabilities: string[];
268
+ id: string;
269
+ name: string;
270
+ description: string;
271
+ ownerId: string;
272
+ executions: number;
273
+ successRate: number;
274
+ createdAt: Date;
275
+ updatedAt: Date;
276
+ metadata?: Record<string, unknown> | undefined;
277
+ }>;
278
+
279
+ /**
280
+ * Cognigate TypeScript SDK - Webhook Utilities
281
+ *
282
+ * Helpers for handling Cognigate webhooks
283
+ */
284
+
285
+ /**
286
+ * Verify webhook signature
287
+ */
288
+ declare function verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
289
+ /**
290
+ * Parse and validate a webhook payload
291
+ */
292
+ declare function parseWebhookPayload(body: string, signature: string, secret: string): Promise<WebhookEvent>;
293
+ /**
294
+ * Webhook handler type
295
+ */
296
+ type WebhookHandler<T extends WebhookEventType = WebhookEventType> = (event: WebhookEvent & {
297
+ type: T;
298
+ }) => void | Promise<void>;
299
+ /**
300
+ * Webhook router for handling different event types
301
+ */
302
+ declare class WebhookRouter {
303
+ private handlers;
304
+ /**
305
+ * Register a handler for a specific event type
306
+ */
307
+ on<T extends WebhookEventType>(type: T, handler: WebhookHandler<T>): this;
308
+ /**
309
+ * Register a handler for all events
310
+ */
311
+ onAll(handler: WebhookHandler): this;
312
+ /**
313
+ * Handle a webhook event
314
+ */
315
+ handle(event: WebhookEvent): Promise<void>;
316
+ /**
317
+ * Create an Express/Connect compatible middleware
318
+ */
319
+ middleware(secret: string): (req: {
320
+ headers: Record<string, string>;
321
+ body: unknown;
322
+ }, res: {
323
+ status: (code: number) => {
324
+ json: (data: unknown) => void;
325
+ };
326
+ }) => Promise<void>;
327
+ }
328
+
329
+ /**
330
+ * Cognigate Proof Bridge
331
+ *
332
+ * Bridges Cognigate webhook events to the Proof Plane for immutable audit trails.
333
+ * Listens for `governance.decision` events and emits `DECISION_MADE` proof events.
334
+ *
335
+ * @packageDocumentation
336
+ */
337
+
338
+ /**
339
+ * Structural type for proof-plane integration (avoids hard dependency on @vorionsys/proof-plane)
340
+ */
341
+ interface ProofPlaneEmitter {
342
+ logDecisionMade(decision: {
343
+ decisionId: string;
344
+ intentId: string;
345
+ agentId: string;
346
+ correlationId: string;
347
+ permitted: boolean;
348
+ trustBand: number;
349
+ trustScore: number;
350
+ reasoning: string[];
351
+ decidedAt: Date;
352
+ expiresAt: Date;
353
+ latencyMs: number;
354
+ version: number;
355
+ }, correlationId?: string): Promise<unknown>;
356
+ }
357
+ /**
358
+ * Configuration for the proof bridge
359
+ */
360
+ interface ProofBridgeConfig {
361
+ /** Proof plane emitter instance */
362
+ proofPlane: ProofPlaneEmitter;
363
+ /** Webhook router to subscribe to */
364
+ webhookRouter: WebhookRouter;
365
+ }
366
+ /**
367
+ * Handle for disconnecting the proof bridge
368
+ */
369
+ interface ProofBridgeHandle {
370
+ /** Disconnect the bridge (stops forwarding events) */
371
+ disconnect: () => void;
372
+ }
373
+ /**
374
+ * Create a proof bridge that forwards Cognigate governance.decision webhooks
375
+ * to the Proof Plane as DECISION_MADE events.
376
+ *
377
+ * @example
378
+ * ```typescript
379
+ * import { WebhookRouter } from '@vorionsys/cognigate';
380
+ * import { createProofBridge } from '@vorionsys/cognigate/proof-bridge';
381
+ * import { ProofPlane } from '@vorionsys/proof-plane';
382
+ *
383
+ * const router = new WebhookRouter();
384
+ * const proofPlane = new ProofPlane({ storage: memoryStore() });
385
+ *
386
+ * const bridge = createProofBridge({ proofPlane, webhookRouter: router });
387
+ * // governance.decision events now automatically emit DECISION_MADE proofs
388
+ *
389
+ * bridge.disconnect(); // stop forwarding
390
+ * ```
391
+ */
392
+ declare function createProofBridge(config: ProofBridgeConfig): ProofBridgeHandle;
393
+
394
+ export { type Agent as A, type CognigateConfig as C, type GovernanceResult as G, type IntentParseResult as I, type ProofRecord as P, type TrustStatus as T, type UpdateAgentRequest as U, type WebhookEvent as W, type Intent as a, type PaginatedResponse as b, type ProofChainStats as c, type CreateAgentRequest as d, AgentSchema as e, type ApiError as f, type ApiResponse as g, type GovernanceDecision as h, GovernanceResultSchema as i, type ProofBridgeConfig as j, type ProofBridgeHandle as k, type ProofPlaneEmitter as l, ProofRecordSchema as m, TrustStatusSchema as n, type WebhookEventType as o, type WebhookHandler as p, WebhookRouter as q, createProofBridge as r, parseWebhookPayload as s, verifyWebhookSignature as v };