@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.
- package/CHANGELOG.md +45 -0
- package/LICENSE +190 -0
- package/README.md +296 -106
- package/dist/chunk-OIPPFRDP.js +35 -0
- package/dist/index.cjs +280 -1
- package/dist/index.d.cts +83 -311
- package/dist/index.d.ts +272 -0
- package/dist/index.js +250 -1
- package/dist/proof-bridge-BBmb7kVP.d.cts +394 -0
- package/dist/proof-bridge-BBmb7kVP.d.ts +394 -0
- package/dist/proof-bridge-CkzbawwC.d.cts +394 -0
- package/dist/proof-bridge-CkzbawwC.d.ts +394 -0
- package/dist/proof-bridge.cjs +59 -0
- package/dist/proof-bridge.d.cts +3 -0
- package/dist/proof-bridge.d.ts +3 -0
- package/dist/proof-bridge.js +6 -0
- package/package.json +28 -9
- package/src/__tests__/client.test.ts +0 -162
- package/src/client.ts +0 -421
- package/src/index.ts +0 -76
- package/src/types.ts +0 -270
- package/src/webhooks.ts +0 -143
- package/tsconfig.json +0 -25
- package/vitest.config.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProofBridge
|
|
3
|
+
} from "./chunk-OIPPFRDP.js";
|
|
4
|
+
|
|
1
5
|
// src/types.ts
|
|
2
6
|
import { z } from "zod";
|
|
3
7
|
import {
|
|
@@ -159,7 +163,7 @@ var Cognigate = class {
|
|
|
159
163
|
if (score >= 876) return TrustTier.T6_CERTIFIED;
|
|
160
164
|
if (score >= 800) return TrustTier.T5_TRUSTED;
|
|
161
165
|
if (score >= 650) return TrustTier.T4_STANDARD;
|
|
162
|
-
if (score >=
|
|
166
|
+
if (score >= 500) return TrustTier.T3_MONITORED;
|
|
163
167
|
if (score >= 350) return TrustTier.T2_PROVISIONAL;
|
|
164
168
|
if (score >= 200) return TrustTier.T1_OBSERVED;
|
|
165
169
|
return TrustTier.T0_SANDBOX;
|
|
@@ -442,6 +446,249 @@ function timingSafeEqual(a, b) {
|
|
|
442
446
|
return result === 0;
|
|
443
447
|
}
|
|
444
448
|
|
|
449
|
+
// src/sandbox/worker-sandbox.ts
|
|
450
|
+
import { Worker } from "worker_threads";
|
|
451
|
+
var DEFAULT_TIMEOUT2 = 3e4;
|
|
452
|
+
var DEFAULT_MEMORY_LIMIT_MB = 64;
|
|
453
|
+
var WORKER_SCRIPT = `
|
|
454
|
+
const { parentPort, workerData } = require('node:worker_threads');
|
|
455
|
+
const vm = require('node:vm');
|
|
456
|
+
|
|
457
|
+
const { code, context } = workerData;
|
|
458
|
+
const startTime = performance.now();
|
|
459
|
+
const memBefore = process.memoryUsage().heapUsed;
|
|
460
|
+
|
|
461
|
+
// Build restricted globals for the vm context
|
|
462
|
+
const safeGlobals = {
|
|
463
|
+
console: {
|
|
464
|
+
log: function() {},
|
|
465
|
+
warn: function() {},
|
|
466
|
+
error: function() {},
|
|
467
|
+
info: function() {},
|
|
468
|
+
},
|
|
469
|
+
JSON: JSON,
|
|
470
|
+
Math: Math,
|
|
471
|
+
Date: Date,
|
|
472
|
+
Array: Array,
|
|
473
|
+
Object: Object,
|
|
474
|
+
String: String,
|
|
475
|
+
Number: Number,
|
|
476
|
+
Boolean: Boolean,
|
|
477
|
+
Map: Map,
|
|
478
|
+
Set: Set,
|
|
479
|
+
WeakMap: WeakMap,
|
|
480
|
+
WeakSet: WeakSet,
|
|
481
|
+
Promise: Promise,
|
|
482
|
+
Symbol: Symbol,
|
|
483
|
+
RegExp: RegExp,
|
|
484
|
+
Error: Error,
|
|
485
|
+
TypeError: TypeError,
|
|
486
|
+
RangeError: RangeError,
|
|
487
|
+
SyntaxError: SyntaxError,
|
|
488
|
+
URIError: URIError,
|
|
489
|
+
parseInt: parseInt,
|
|
490
|
+
parseFloat: parseFloat,
|
|
491
|
+
isNaN: isNaN,
|
|
492
|
+
isFinite: isFinite,
|
|
493
|
+
encodeURIComponent: encodeURIComponent,
|
|
494
|
+
decodeURIComponent: decodeURIComponent,
|
|
495
|
+
encodeURI: encodeURI,
|
|
496
|
+
decodeURI: decodeURI,
|
|
497
|
+
undefined: undefined,
|
|
498
|
+
NaN: NaN,
|
|
499
|
+
Infinity: Infinity,
|
|
500
|
+
setTimeout: function(fn, ms) { return setTimeout(fn, Math.min(ms, 5000)); },
|
|
501
|
+
clearTimeout: clearTimeout,
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
const vmContext = vm.createContext(safeGlobals);
|
|
505
|
+
|
|
506
|
+
// Wrap code in an async IIFE to support await and return
|
|
507
|
+
const wrappedCode = '(async () => { ' + code + ' })()';
|
|
508
|
+
|
|
509
|
+
async function run() {
|
|
510
|
+
try {
|
|
511
|
+
const script = new vm.Script(wrappedCode, {
|
|
512
|
+
filename: 'sandbox-' + context.agentId + '.js',
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const result = await script.runInContext(vmContext, {
|
|
516
|
+
timeout: context.timeout,
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
const durationMs = performance.now() - startTime;
|
|
520
|
+
const memAfter = process.memoryUsage().heapUsed;
|
|
521
|
+
|
|
522
|
+
parentPort.postMessage({
|
|
523
|
+
type: 'result',
|
|
524
|
+
output: result,
|
|
525
|
+
durationMs: durationMs,
|
|
526
|
+
memoryUsedBytes: Math.max(0, memAfter - memBefore),
|
|
527
|
+
});
|
|
528
|
+
} catch (err) {
|
|
529
|
+
const durationMs = performance.now() - startTime;
|
|
530
|
+
const memAfter = process.memoryUsage().heapUsed;
|
|
531
|
+
|
|
532
|
+
parentPort.postMessage({
|
|
533
|
+
type: 'error',
|
|
534
|
+
error: err && err.message ? err.message : String(err),
|
|
535
|
+
durationMs: durationMs,
|
|
536
|
+
memoryUsedBytes: Math.max(0, memAfter - memBefore),
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
run();
|
|
542
|
+
`;
|
|
543
|
+
var WorkerSandbox = class {
|
|
544
|
+
worker = null;
|
|
545
|
+
isShutdown = false;
|
|
546
|
+
/**
|
|
547
|
+
* Execute code in an isolated worker thread.
|
|
548
|
+
*
|
|
549
|
+
* Spawns a new worker for each execution to ensure full isolation.
|
|
550
|
+
* The worker has memory limits enforced by V8 via `resourceLimits`,
|
|
551
|
+
* a vm-level timeout for synchronous code, and a main-thread timeout
|
|
552
|
+
* as a fallback for async code or hangs.
|
|
553
|
+
*
|
|
554
|
+
* @param code - JavaScript code string to execute inside the sandbox.
|
|
555
|
+
* The code is wrapped in an async IIFE, so `return` and `await` are valid.
|
|
556
|
+
* @param context - Execution context with identity and resource constraints
|
|
557
|
+
* @returns Promise resolving to a SandboxResult
|
|
558
|
+
*/
|
|
559
|
+
async execute(code, context) {
|
|
560
|
+
if (this.isShutdown) {
|
|
561
|
+
return {
|
|
562
|
+
success: false,
|
|
563
|
+
output: void 0,
|
|
564
|
+
error: "Sandbox has been shut down",
|
|
565
|
+
durationMs: 0,
|
|
566
|
+
memoryUsedBytes: 0
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
const timeout = context.timeout || DEFAULT_TIMEOUT2;
|
|
570
|
+
const memoryLimitMb = context.memoryLimitMb || DEFAULT_MEMORY_LIMIT_MB;
|
|
571
|
+
const startTime = performance.now();
|
|
572
|
+
return new Promise((resolve) => {
|
|
573
|
+
let settled = false;
|
|
574
|
+
let timeoutId = null;
|
|
575
|
+
const settle = (result) => {
|
|
576
|
+
if (settled) return;
|
|
577
|
+
settled = true;
|
|
578
|
+
if (timeoutId) {
|
|
579
|
+
clearTimeout(timeoutId);
|
|
580
|
+
timeoutId = null;
|
|
581
|
+
}
|
|
582
|
+
resolve(result);
|
|
583
|
+
};
|
|
584
|
+
try {
|
|
585
|
+
const worker = new Worker(WORKER_SCRIPT, {
|
|
586
|
+
eval: true,
|
|
587
|
+
workerData: {
|
|
588
|
+
code,
|
|
589
|
+
context: {
|
|
590
|
+
tenantId: context.tenantId,
|
|
591
|
+
agentId: context.agentId,
|
|
592
|
+
trustLevel: context.trustLevel ?? 0,
|
|
593
|
+
allowedModules: context.allowedModules ?? [],
|
|
594
|
+
timeout,
|
|
595
|
+
memoryLimitMb
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
resourceLimits: {
|
|
599
|
+
maxOldGenerationSizeMb: memoryLimitMb,
|
|
600
|
+
maxYoungGenerationSizeMb: Math.max(1, Math.floor(memoryLimitMb / 4)),
|
|
601
|
+
codeRangeSizeMb: Math.max(1, Math.floor(memoryLimitMb / 8))
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
this.worker = worker;
|
|
605
|
+
timeoutId = setTimeout(() => {
|
|
606
|
+
const durationMs = performance.now() - startTime;
|
|
607
|
+
worker.terminate().catch(() => {
|
|
608
|
+
});
|
|
609
|
+
settle({
|
|
610
|
+
success: false,
|
|
611
|
+
output: void 0,
|
|
612
|
+
error: `Execution timed out after ${timeout}ms`,
|
|
613
|
+
durationMs,
|
|
614
|
+
memoryUsedBytes: 0
|
|
615
|
+
});
|
|
616
|
+
}, timeout + 500);
|
|
617
|
+
worker.on("message", (message) => {
|
|
618
|
+
if (message.type === "result") {
|
|
619
|
+
settle({
|
|
620
|
+
success: true,
|
|
621
|
+
output: message.output,
|
|
622
|
+
durationMs: message.durationMs,
|
|
623
|
+
memoryUsedBytes: message.memoryUsedBytes
|
|
624
|
+
});
|
|
625
|
+
} else if (message.type === "error") {
|
|
626
|
+
settle({
|
|
627
|
+
success: false,
|
|
628
|
+
output: void 0,
|
|
629
|
+
error: message.error,
|
|
630
|
+
durationMs: message.durationMs,
|
|
631
|
+
memoryUsedBytes: message.memoryUsedBytes
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
worker.terminate().catch(() => {
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
worker.on("error", (error) => {
|
|
638
|
+
const durationMs = performance.now() - startTime;
|
|
639
|
+
settle({
|
|
640
|
+
success: false,
|
|
641
|
+
output: void 0,
|
|
642
|
+
error: error.message || "Worker error",
|
|
643
|
+
durationMs,
|
|
644
|
+
memoryUsedBytes: 0
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
worker.on("exit", (exitCode) => {
|
|
648
|
+
if (exitCode !== 0) {
|
|
649
|
+
const durationMs = performance.now() - startTime;
|
|
650
|
+
settle({
|
|
651
|
+
success: false,
|
|
652
|
+
output: void 0,
|
|
653
|
+
error: `Worker exited with code ${exitCode} (possible memory limit exceeded)`,
|
|
654
|
+
durationMs,
|
|
655
|
+
memoryUsedBytes: 0
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
this.worker = null;
|
|
659
|
+
});
|
|
660
|
+
} catch (err) {
|
|
661
|
+
const durationMs = performance.now() - startTime;
|
|
662
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
663
|
+
settle({
|
|
664
|
+
success: false,
|
|
665
|
+
output: void 0,
|
|
666
|
+
error: `Failed to spawn worker: ${errorMessage}`,
|
|
667
|
+
durationMs,
|
|
668
|
+
memoryUsedBytes: 0
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Gracefully shut down the sandbox.
|
|
675
|
+
* Terminates any running worker and prevents future executions.
|
|
676
|
+
*/
|
|
677
|
+
async shutdown() {
|
|
678
|
+
this.isShutdown = true;
|
|
679
|
+
if (this.worker) {
|
|
680
|
+
await this.worker.terminate();
|
|
681
|
+
this.worker = null;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Check whether the sandbox has been shut down.
|
|
686
|
+
*/
|
|
687
|
+
get terminated() {
|
|
688
|
+
return this.isShutdown;
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
|
|
445
692
|
// src/index.ts
|
|
446
693
|
import { z as z2 } from "zod";
|
|
447
694
|
export {
|
|
@@ -454,6 +701,8 @@ export {
|
|
|
454
701
|
TrustStatusSchema,
|
|
455
702
|
TrustTier,
|
|
456
703
|
WebhookRouter,
|
|
704
|
+
WorkerSandbox,
|
|
705
|
+
createProofBridge,
|
|
457
706
|
parseWebhookPayload,
|
|
458
707
|
verifyWebhookSignature,
|
|
459
708
|
z2 as z
|
|
@@ -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
|
+
entityId: string;
|
|
145
|
+
trustScore: number;
|
|
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
|
+
entityId: string;
|
|
155
|
+
trustScore: number;
|
|
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
|
+
trustScore: number;
|
|
176
|
+
trustTier: TrustTier;
|
|
177
|
+
decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
|
|
178
|
+
grantedCapabilities: string[];
|
|
179
|
+
deniedCapabilities: string[];
|
|
180
|
+
reasoning: string;
|
|
181
|
+
timestamp: Date;
|
|
182
|
+
constraints?: Record<string, unknown> | undefined;
|
|
183
|
+
proofId?: string | undefined;
|
|
184
|
+
}, {
|
|
185
|
+
trustScore: number;
|
|
186
|
+
trustTier: TrustTier;
|
|
187
|
+
decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
|
|
188
|
+
grantedCapabilities: string[];
|
|
189
|
+
deniedCapabilities: string[];
|
|
190
|
+
reasoning: 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
|
+
entityId: string;
|
|
210
|
+
decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
|
|
211
|
+
timestamp: Date;
|
|
212
|
+
id: string;
|
|
213
|
+
intentId: 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
|
+
entityId: string;
|
|
223
|
+
decision: "ALLOW" | "DENY" | "ESCALATE" | "DEGRADE";
|
|
224
|
+
timestamp: Date;
|
|
225
|
+
id: string;
|
|
226
|
+
intentId: 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 };
|