@vorionsys/a3i 0.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/LICENSE +190 -0
- package/dist/api/handlers.d.ts +231 -0
- package/dist/api/handlers.d.ts.map +1 -0
- package/dist/api/handlers.js +279 -0
- package/dist/api/handlers.js.map +1 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +27 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middleware.d.ts +106 -0
- package/dist/api/middleware.d.ts.map +1 -0
- package/dist/api/middleware.js +186 -0
- package/dist/api/middleware.js.map +1 -0
- package/dist/api/routes.d.ts +41 -0
- package/dist/api/routes.d.ts.map +1 -0
- package/dist/api/routes.js +91 -0
- package/dist/api/routes.js.map +1 -0
- package/dist/authorization/constraints.d.ts +75 -0
- package/dist/authorization/constraints.d.ts.map +1 -0
- package/dist/authorization/constraints.js +302 -0
- package/dist/authorization/constraints.js.map +1 -0
- package/dist/authorization/decision.d.ts +98 -0
- package/dist/authorization/decision.d.ts.map +1 -0
- package/dist/authorization/decision.js +202 -0
- package/dist/authorization/decision.js.map +1 -0
- package/dist/authorization/engine.d.ts +141 -0
- package/dist/authorization/engine.d.ts.map +1 -0
- package/dist/authorization/engine.js +339 -0
- package/dist/authorization/engine.js.map +1 -0
- package/dist/authorization/index.d.ts +10 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +13 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/banding/band-calculator.d.ts +137 -0
- package/dist/banding/band-calculator.d.ts.map +1 -0
- package/dist/banding/band-calculator.js +252 -0
- package/dist/banding/band-calculator.js.map +1 -0
- package/dist/banding/bands.d.ts +56 -0
- package/dist/banding/bands.d.ts.map +1 -0
- package/dist/banding/bands.js +200 -0
- package/dist/banding/bands.js.map +1 -0
- package/dist/banding/hysteresis.d.ts +64 -0
- package/dist/banding/hysteresis.d.ts.map +1 -0
- package/dist/banding/hysteresis.js +143 -0
- package/dist/banding/hysteresis.js.map +1 -0
- package/dist/banding/index.d.ts +10 -0
- package/dist/banding/index.d.ts.map +1 -0
- package/dist/banding/index.js +10 -0
- package/dist/banding/index.js.map +1 -0
- package/dist/canary/canary-service.d.ts +123 -0
- package/dist/canary/canary-service.d.ts.map +1 -0
- package/dist/canary/canary-service.js +353 -0
- package/dist/canary/canary-service.js.map +1 -0
- package/dist/canary/index.d.ts +12 -0
- package/dist/canary/index.d.ts.map +1 -0
- package/dist/canary/index.js +14 -0
- package/dist/canary/index.js.map +1 -0
- package/dist/canary/probe-library.d.ts +43 -0
- package/dist/canary/probe-library.d.ts.map +1 -0
- package/dist/canary/probe-library.js +655 -0
- package/dist/canary/probe-library.js.map +1 -0
- package/dist/execution/engine.d.ts +120 -0
- package/dist/execution/engine.d.ts.map +1 -0
- package/dist/execution/engine.js +220 -0
- package/dist/execution/engine.js.map +1 -0
- package/dist/execution/index.d.ts +7 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +7 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/gate/index.d.ts +12 -0
- package/dist/gate/index.d.ts.map +1 -0
- package/dist/gate/index.js +14 -0
- package/dist/gate/index.js.map +1 -0
- package/dist/gate/pre-action-gate.d.ts +87 -0
- package/dist/gate/pre-action-gate.d.ts.map +1 -0
- package/dist/gate/pre-action-gate.js +286 -0
- package/dist/gate/pre-action-gate.js.map +1 -0
- package/dist/gate/risk-classifier.d.ts +43 -0
- package/dist/gate/risk-classifier.d.ts.map +1 -0
- package/dist/gate/risk-classifier.js +157 -0
- package/dist/gate/risk-classifier.js.map +1 -0
- package/dist/hooks/executor.d.ts +56 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +217 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +45 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +49 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/manager.d.ts +156 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +267 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/registry.d.ts +130 -0
- package/dist/hooks/registry.d.ts.map +1 -0
- package/dist/hooks/registry.js +238 -0
- package/dist/hooks/registry.js.map +1 -0
- package/dist/hooks/types.d.ts +226 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +41 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/observation/attestation.d.ts +102 -0
- package/dist/observation/attestation.d.ts.map +1 -0
- package/dist/observation/attestation.js +127 -0
- package/dist/observation/attestation.js.map +1 -0
- package/dist/observation/ceilings.d.ts +60 -0
- package/dist/observation/ceilings.d.ts.map +1 -0
- package/dist/observation/ceilings.js +110 -0
- package/dist/observation/ceilings.js.map +1 -0
- package/dist/observation/index.d.ts +11 -0
- package/dist/observation/index.d.ts.map +1 -0
- package/dist/observation/index.js +14 -0
- package/dist/observation/index.js.map +1 -0
- package/dist/observation/tiers.d.ts +96 -0
- package/dist/observation/tiers.d.ts.map +1 -0
- package/dist/observation/tiers.js +225 -0
- package/dist/observation/tiers.js.map +1 -0
- package/dist/orchestrator/index.d.ts +8 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +8 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +225 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +302 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/orchestrator/proof-plane-adapter.d.ts +80 -0
- package/dist/orchestrator/proof-plane-adapter.d.ts.map +1 -0
- package/dist/orchestrator/proof-plane-adapter.js +78 -0
- package/dist/orchestrator/proof-plane-adapter.js.map +1 -0
- package/dist/trust/calculator.d.ts +60 -0
- package/dist/trust/calculator.d.ts.map +1 -0
- package/dist/trust/calculator.js +163 -0
- package/dist/trust/calculator.js.map +1 -0
- package/dist/trust/dimensions.d.ts +133 -0
- package/dist/trust/dimensions.d.ts.map +1 -0
- package/dist/trust/dimensions.js +257 -0
- package/dist/trust/dimensions.js.map +1 -0
- package/dist/trust/index.d.ts +14 -0
- package/dist/trust/index.d.ts.map +1 -0
- package/dist/trust/index.js +25 -0
- package/dist/trust/index.js.map +1 -0
- package/dist/trust/profile-service.d.ts +179 -0
- package/dist/trust/profile-service.d.ts.map +1 -0
- package/dist/trust/profile-service.js +378 -0
- package/dist/trust/profile-service.js.map +1 -0
- package/dist/trust/profile-store.d.ts +122 -0
- package/dist/trust/profile-store.d.ts.map +1 -0
- package/dist/trust/profile-store.js +132 -0
- package/dist/trust/profile-store.js.map +1 -0
- package/dist/trust/trust-calculator.d.ts +111 -0
- package/dist/trust/trust-calculator.d.ts.map +1 -0
- package/dist/trust/trust-calculator.js +271 -0
- package/dist/trust/trust-calculator.js.map +1 -0
- package/dist/trust/trust-dynamics.d.ts +152 -0
- package/dist/trust/trust-dynamics.d.ts.map +1 -0
- package/dist/trust/trust-dynamics.js +302 -0
- package/dist/trust/trust-dynamics.js.map +1 -0
- package/dist/trust/weights.d.ts +57 -0
- package/dist/trust/weights.d.ts.map +1 -0
- package/dist/trust/weights.js +75 -0
- package/dist/trust/weights.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision Builder - Construct authorization decisions
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for creating Decision objects with proper
|
|
5
|
+
* validation and structure.
|
|
6
|
+
*/
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
import { TrustBand, DenialReason, } from '@vorionsys/contracts';
|
|
9
|
+
/**
|
|
10
|
+
* Build a permit decision
|
|
11
|
+
*/
|
|
12
|
+
export function buildPermitDecision(intent, profile, constraints, reasoning, options = {}) {
|
|
13
|
+
const now = options.now ?? new Date();
|
|
14
|
+
const validityDurationMs = options.validityDurationMs ?? 5 * 60 * 1000; // 5 minutes
|
|
15
|
+
return {
|
|
16
|
+
decisionId: options.decisionId ?? uuidv4(),
|
|
17
|
+
intentId: intent.intentId,
|
|
18
|
+
agentId: intent.agentId,
|
|
19
|
+
correlationId: intent.correlationId,
|
|
20
|
+
permitted: true,
|
|
21
|
+
constraints,
|
|
22
|
+
trustBand: profile.band,
|
|
23
|
+
trustScore: profile.adjustedScore,
|
|
24
|
+
policySetId: options.policySetId,
|
|
25
|
+
reasoning,
|
|
26
|
+
decidedAt: now,
|
|
27
|
+
expiresAt: new Date(now.getTime() + validityDurationMs),
|
|
28
|
+
latencyMs: 0, // Will be set by engine
|
|
29
|
+
version: 1,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a deny decision
|
|
34
|
+
*/
|
|
35
|
+
export function buildDenyDecision(intent, profile, _reason, // Reserved for future denialReason field in Decision
|
|
36
|
+
reasoning, options = {}) {
|
|
37
|
+
const now = options.now ?? new Date();
|
|
38
|
+
const validityDurationMs = options.validityDurationMs ?? 5 * 60 * 1000;
|
|
39
|
+
return {
|
|
40
|
+
decisionId: options.decisionId ?? uuidv4(),
|
|
41
|
+
intentId: intent.intentId,
|
|
42
|
+
agentId: intent.agentId,
|
|
43
|
+
correlationId: intent.correlationId,
|
|
44
|
+
permitted: false,
|
|
45
|
+
constraints: undefined,
|
|
46
|
+
trustBand: profile?.band ?? TrustBand.T0_SANDBOX,
|
|
47
|
+
trustScore: profile?.adjustedScore ?? 0,
|
|
48
|
+
policySetId: options.policySetId,
|
|
49
|
+
reasoning,
|
|
50
|
+
decidedAt: now,
|
|
51
|
+
expiresAt: new Date(now.getTime() + validityDurationMs),
|
|
52
|
+
latencyMs: 0, // Will be set by engine
|
|
53
|
+
version: 1,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get remediation suggestions for a denial reason
|
|
58
|
+
*/
|
|
59
|
+
export function getRemediations(reason, _context) {
|
|
60
|
+
switch (reason) {
|
|
61
|
+
case DenialReason.INSUFFICIENT_TRUST:
|
|
62
|
+
return [
|
|
63
|
+
'Increase trust score through positive behavioral evidence',
|
|
64
|
+
'Request human supervision for this action',
|
|
65
|
+
'Use a higher observation tier (e.g., WHITE_BOX) if available',
|
|
66
|
+
];
|
|
67
|
+
case DenialReason.POLICY_VIOLATION:
|
|
68
|
+
return [
|
|
69
|
+
'Review the policy requirements for this action type',
|
|
70
|
+
'Request policy exception through governance channel',
|
|
71
|
+
];
|
|
72
|
+
case DenialReason.RESOURCE_RESTRICTED:
|
|
73
|
+
return [
|
|
74
|
+
'Request access to the required resources',
|
|
75
|
+
'Use alternative resources that are permitted',
|
|
76
|
+
];
|
|
77
|
+
case DenialReason.DATA_SENSITIVITY_EXCEEDED:
|
|
78
|
+
return [
|
|
79
|
+
'Reduce data sensitivity requirements',
|
|
80
|
+
'Request elevated data access permissions',
|
|
81
|
+
'Use anonymized or redacted data instead',
|
|
82
|
+
];
|
|
83
|
+
case DenialReason.RATE_LIMIT_EXCEEDED:
|
|
84
|
+
return [
|
|
85
|
+
'Wait for the rate limit window to reset',
|
|
86
|
+
'Reduce request frequency',
|
|
87
|
+
'Request higher rate limits through governance',
|
|
88
|
+
];
|
|
89
|
+
case DenialReason.CONTEXT_MISMATCH:
|
|
90
|
+
return [
|
|
91
|
+
'Verify the execution context is appropriate',
|
|
92
|
+
'Switch to the correct environment',
|
|
93
|
+
'Update intent context to match actual conditions',
|
|
94
|
+
];
|
|
95
|
+
case DenialReason.EXPIRED_INTENT:
|
|
96
|
+
return [
|
|
97
|
+
'Create a new intent with updated expiration',
|
|
98
|
+
'Submit intents more promptly',
|
|
99
|
+
];
|
|
100
|
+
case DenialReason.SYSTEM_ERROR:
|
|
101
|
+
return [
|
|
102
|
+
'Retry the request',
|
|
103
|
+
'Contact system administrators if the issue persists',
|
|
104
|
+
];
|
|
105
|
+
default:
|
|
106
|
+
return ['Contact support for assistance'];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Determine the denial reason based on evaluation context
|
|
111
|
+
*/
|
|
112
|
+
export function determineDenialReason(profile, _intent, // Reserved for future intent-specific denial logic
|
|
113
|
+
minRequiredBand, checks) {
|
|
114
|
+
if (checks.intentExpired) {
|
|
115
|
+
return DenialReason.EXPIRED_INTENT;
|
|
116
|
+
}
|
|
117
|
+
if (checks.rateLimitExceeded) {
|
|
118
|
+
return DenialReason.RATE_LIMIT_EXCEEDED;
|
|
119
|
+
}
|
|
120
|
+
if (checks.resourceRestricted) {
|
|
121
|
+
return DenialReason.RESOURCE_RESTRICTED;
|
|
122
|
+
}
|
|
123
|
+
if (checks.contextMismatch) {
|
|
124
|
+
return DenialReason.CONTEXT_MISMATCH;
|
|
125
|
+
}
|
|
126
|
+
if (checks.policyViolation) {
|
|
127
|
+
return DenialReason.POLICY_VIOLATION;
|
|
128
|
+
}
|
|
129
|
+
if (!profile || profile.band < minRequiredBand) {
|
|
130
|
+
return DenialReason.INSUFFICIENT_TRUST;
|
|
131
|
+
}
|
|
132
|
+
return DenialReason.POLICY_VIOLATION;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Create decision summary for logging
|
|
136
|
+
*/
|
|
137
|
+
export function summarizeDecision(decision) {
|
|
138
|
+
const action = decision.permitted ? 'PERMITTED' : 'DENIED';
|
|
139
|
+
const band = TrustBand[decision.trustBand];
|
|
140
|
+
return `[${decision.decisionId}] ${action} for agent ${decision.agentId} (${band}, score=${decision.trustScore}) - ${decision.reasoning[0] ?? 'No reason'}`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if a decision is still valid
|
|
144
|
+
*/
|
|
145
|
+
export function isDecisionValid(decision, now = new Date()) {
|
|
146
|
+
return now < decision.expiresAt;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Decision builder class for fluent API
|
|
150
|
+
*/
|
|
151
|
+
export class DecisionBuilder {
|
|
152
|
+
intent;
|
|
153
|
+
profile = null;
|
|
154
|
+
permitted = false;
|
|
155
|
+
constraints;
|
|
156
|
+
reasoning = [];
|
|
157
|
+
denialReason;
|
|
158
|
+
options = {};
|
|
159
|
+
constructor(intent) {
|
|
160
|
+
this.intent = intent;
|
|
161
|
+
}
|
|
162
|
+
withProfile(profile) {
|
|
163
|
+
this.profile = profile;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
permit() {
|
|
167
|
+
this.permitted = true;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
deny(reason) {
|
|
171
|
+
this.permitted = false;
|
|
172
|
+
this.denialReason = reason;
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
withConstraints(constraints) {
|
|
176
|
+
this.constraints = constraints;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
addReasoning(...reasons) {
|
|
180
|
+
this.reasoning.push(...reasons);
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
withOptions(options) {
|
|
184
|
+
this.options = { ...this.options, ...options };
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
build() {
|
|
188
|
+
if (this.permitted && this.profile && this.constraints) {
|
|
189
|
+
return buildPermitDecision(this.intent, this.profile, this.constraints, this.reasoning, this.options);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return buildDenyDecision(this.intent, this.profile, this.denialReason ?? DenialReason.POLICY_VIOLATION, this.reasoning, this.options);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Static factory for creating builders
|
|
197
|
+
*/
|
|
198
|
+
static for(intent) {
|
|
199
|
+
return new DecisionBuilder(intent);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=decision.js.map
|
|
@@ -0,0 +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AChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,OAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACvD,OAAO,mBAAmB,CACxB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,iBAAiB,CACtB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,gBAAgB,EAClD,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,MAAc;QACvB,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authorization Engine - Core authorization decision-making
|
|
3
|
+
*
|
|
4
|
+
* The AuthorizationEngine is the central component of A3I that makes
|
|
5
|
+
* permit/deny decisions for agent intents based on:
|
|
6
|
+
* - Agent's trust profile and band
|
|
7
|
+
* - Intent characteristics (action type, data sensitivity, reversibility)
|
|
8
|
+
* - Policy rules and constraints
|
|
9
|
+
* - Context factors
|
|
10
|
+
* - Hook system for extensibility
|
|
11
|
+
*
|
|
12
|
+
* Key principles:
|
|
13
|
+
* - Deterministic: Same inputs always produce same outputs
|
|
14
|
+
* - Fast: <50ms latency target for decisions
|
|
15
|
+
* - Auditable: All decisions logged with reasoning
|
|
16
|
+
* - Extensible: Hooks for pre/post authorization
|
|
17
|
+
*/
|
|
18
|
+
import { TrustBand, ActionType, DataSensitivity, Reversibility, DenialReason, type Intent, type Decision, type TrustProfile, type AuthorizationResponse } from '@vorionsys/contracts';
|
|
19
|
+
import { type ConstraintGenerationOptions } from './constraints.js';
|
|
20
|
+
import { TrustProfileService } from '../trust/profile-service.js';
|
|
21
|
+
import { type HookManager } from '../hooks/index.js';
|
|
22
|
+
/**
|
|
23
|
+
* Minimum trust band required for each action type
|
|
24
|
+
*/
|
|
25
|
+
export declare const ACTION_TYPE_REQUIREMENTS: Record<ActionType, TrustBand>;
|
|
26
|
+
/**
|
|
27
|
+
* Minimum trust band required for each data sensitivity level
|
|
28
|
+
*/
|
|
29
|
+
export declare const DATA_SENSITIVITY_REQUIREMENTS: Record<DataSensitivity, TrustBand>;
|
|
30
|
+
/**
|
|
31
|
+
* Trust band adjustments for reversibility
|
|
32
|
+
*/
|
|
33
|
+
export declare const REVERSIBILITY_ADJUSTMENTS: Record<Reversibility, number>;
|
|
34
|
+
/**
|
|
35
|
+
* Proof plane event logger interface
|
|
36
|
+
* (Actual implementation in Vorion package)
|
|
37
|
+
*/
|
|
38
|
+
export interface ProofPlaneLogger {
|
|
39
|
+
logDecision(decision: Decision, intent: Intent): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* No-op proof plane logger for when proof plane is not connected
|
|
43
|
+
*/
|
|
44
|
+
export declare const noopProofLogger: ProofPlaneLogger;
|
|
45
|
+
/**
|
|
46
|
+
* Configuration for the authorization engine
|
|
47
|
+
*/
|
|
48
|
+
export interface AuthorizationEngineConfig {
|
|
49
|
+
/** Profile service for trust lookups */
|
|
50
|
+
profileService?: TrustProfileService;
|
|
51
|
+
/** Custom action type requirements */
|
|
52
|
+
actionTypeRequirements?: Partial<Record<ActionType, TrustBand>>;
|
|
53
|
+
/** Custom data sensitivity requirements */
|
|
54
|
+
dataSensitivityRequirements?: Partial<Record<DataSensitivity, TrustBand>>;
|
|
55
|
+
/** Proof plane logger for audit trail */
|
|
56
|
+
proofLogger?: ProofPlaneLogger;
|
|
57
|
+
/** Hook manager for extensibility */
|
|
58
|
+
hookManager?: HookManager;
|
|
59
|
+
/** Default policy set ID */
|
|
60
|
+
defaultPolicySetId?: string;
|
|
61
|
+
/** Decision validity duration in ms */
|
|
62
|
+
decisionValidityMs?: number;
|
|
63
|
+
/** Enable strict mode (deny on any ambiguity) */
|
|
64
|
+
strictMode?: boolean;
|
|
65
|
+
/** Enable hooks (default: true if hookManager provided) */
|
|
66
|
+
enableHooks?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Authorization request with full intent
|
|
70
|
+
*/
|
|
71
|
+
export interface AuthorizeRequest {
|
|
72
|
+
/** The intent to authorize */
|
|
73
|
+
intent: Intent;
|
|
74
|
+
/** Optional: Override constraint generation */
|
|
75
|
+
constraintOptions?: ConstraintGenerationOptions;
|
|
76
|
+
/** Optional: Use specific policy set */
|
|
77
|
+
policySetId?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* AuthorizationEngine - Makes permit/deny decisions for agent intents
|
|
81
|
+
*/
|
|
82
|
+
export declare class AuthorizationEngine {
|
|
83
|
+
private readonly profileService;
|
|
84
|
+
private readonly actionRequirements;
|
|
85
|
+
private readonly sensitivityRequirements;
|
|
86
|
+
private readonly proofLogger;
|
|
87
|
+
private readonly hookManager?;
|
|
88
|
+
private readonly config;
|
|
89
|
+
constructor(config?: AuthorizationEngineConfig);
|
|
90
|
+
/**
|
|
91
|
+
* Authorize an intent
|
|
92
|
+
*
|
|
93
|
+
* This is the main entry point for authorization decisions.
|
|
94
|
+
* Returns a Decision object indicating whether the intent is permitted.
|
|
95
|
+
*
|
|
96
|
+
* Hook integration:
|
|
97
|
+
* - PRE_AUTHORIZE hooks run before evaluation (can abort)
|
|
98
|
+
* - POST_AUTHORIZE hooks run after decision is made
|
|
99
|
+
*/
|
|
100
|
+
authorize(request: AuthorizeRequest): Promise<AuthorizationResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Evaluate an intent against a trust profile
|
|
103
|
+
* This is the core authorization logic - deterministic and fast
|
|
104
|
+
*/
|
|
105
|
+
evaluate(intent: Intent, profile: TrustProfile): {
|
|
106
|
+
permitted: boolean;
|
|
107
|
+
reasoning: string[];
|
|
108
|
+
denialReason: DenialReason;
|
|
109
|
+
requiredBand: TrustBand;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Check resource scope restrictions
|
|
113
|
+
*/
|
|
114
|
+
private checkResourceScope;
|
|
115
|
+
/**
|
|
116
|
+
* Check context restrictions
|
|
117
|
+
*/
|
|
118
|
+
private checkContext;
|
|
119
|
+
/**
|
|
120
|
+
* Quick check if an agent can perform an action type
|
|
121
|
+
* (Without full profile lookup - uses cached band if available)
|
|
122
|
+
*/
|
|
123
|
+
canPerformActionType(band: TrustBand, actionType: ActionType): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Quick check if an agent can access data sensitivity level
|
|
126
|
+
*/
|
|
127
|
+
canAccessDataSensitivity(band: TrustBand, sensitivity: DataSensitivity): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Get the minimum band required for an action + sensitivity combination
|
|
130
|
+
*/
|
|
131
|
+
getRequiredBand(actionType: ActionType, dataSensitivity: DataSensitivity, reversibility?: Reversibility): TrustBand;
|
|
132
|
+
/**
|
|
133
|
+
* Get the profile service
|
|
134
|
+
*/
|
|
135
|
+
getProfileService(): TrustProfileService;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create an AuthorizationEngine with default configuration
|
|
139
|
+
*/
|
|
140
|
+
export declare function createAuthorizationEngine(config?: AuthorizationEngineConfig): AuthorizationEngine;
|
|
141
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/authorization/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;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