@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,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Engine - Executes authorized intents with hook integration
|
|
3
|
+
*
|
|
4
|
+
* The ExecutionEngine handles the actual execution of authorized intents,
|
|
5
|
+
* with pre/post execution hooks for extensibility and monitoring.
|
|
6
|
+
*
|
|
7
|
+
* Execution flow:
|
|
8
|
+
* 1. Validate the decision is still valid (not expired)
|
|
9
|
+
* 2. Execute PRE_EXECUTE hooks (can abort)
|
|
10
|
+
* 3. Execute the action via the registered executor
|
|
11
|
+
* 4. Execute POST_EXECUTE hooks on success
|
|
12
|
+
* 5. Execute EXECUTION_FAILED hooks on failure
|
|
13
|
+
*/
|
|
14
|
+
import type { Intent, Decision, TrustProfile } from '@vorionsys/contracts';
|
|
15
|
+
import { type HookManager } from '../hooks/index.js';
|
|
16
|
+
/**
|
|
17
|
+
* Executor function type - implements the actual action execution
|
|
18
|
+
*/
|
|
19
|
+
export type ActionExecutor<TParams = unknown, TResult = unknown> = (intent: Intent, decision: Decision, params?: TParams) => Promise<TResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Execution result
|
|
22
|
+
*/
|
|
23
|
+
export interface ExecutionResult<T = unknown> {
|
|
24
|
+
/** Whether execution was successful */
|
|
25
|
+
success: boolean;
|
|
26
|
+
/** The result of execution (if successful) */
|
|
27
|
+
result?: T;
|
|
28
|
+
/** Error (if failed) */
|
|
29
|
+
error?: Error;
|
|
30
|
+
/** Execution duration in ms */
|
|
31
|
+
durationMs: number;
|
|
32
|
+
/** Whether the operation was aborted by a hook */
|
|
33
|
+
aborted: boolean;
|
|
34
|
+
/** Abort reason (if aborted) */
|
|
35
|
+
abortReason?: string;
|
|
36
|
+
/** Execution ID for tracing */
|
|
37
|
+
executionId: string;
|
|
38
|
+
/** Whether the error is retryable */
|
|
39
|
+
retryable?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Execution request
|
|
43
|
+
*/
|
|
44
|
+
export interface ExecuteRequest<TParams = unknown> {
|
|
45
|
+
/** The authorization decision */
|
|
46
|
+
decision: Decision;
|
|
47
|
+
/** The original intent */
|
|
48
|
+
intent: Intent;
|
|
49
|
+
/** The agent's trust profile */
|
|
50
|
+
profile: TrustProfile;
|
|
51
|
+
/** Custom execution parameters */
|
|
52
|
+
params?: TParams;
|
|
53
|
+
/** Optional executor override (uses default if not provided) */
|
|
54
|
+
executor?: ActionExecutor<TParams>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Configuration for the execution engine
|
|
58
|
+
*/
|
|
59
|
+
export interface ExecutionEngineConfig {
|
|
60
|
+
/** Hook manager for extensibility */
|
|
61
|
+
hookManager?: HookManager;
|
|
62
|
+
/** Enable hooks (default: true if hookManager provided) */
|
|
63
|
+
enableHooks?: boolean;
|
|
64
|
+
/** Default executor for actions */
|
|
65
|
+
defaultExecutor?: ActionExecutor;
|
|
66
|
+
/** Default timeout for execution in ms */
|
|
67
|
+
defaultTimeoutMs?: number;
|
|
68
|
+
/** Whether to allow execution of expired decisions */
|
|
69
|
+
allowExpiredDecisions?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* ExecutionEngine - Executes authorized intents with hook integration
|
|
73
|
+
*/
|
|
74
|
+
export declare class ExecutionEngine {
|
|
75
|
+
private readonly hookManager?;
|
|
76
|
+
private readonly config;
|
|
77
|
+
private readonly executors;
|
|
78
|
+
constructor(config?: ExecutionEngineConfig);
|
|
79
|
+
/**
|
|
80
|
+
* Default no-op executor
|
|
81
|
+
*/
|
|
82
|
+
private noopExecutor;
|
|
83
|
+
/**
|
|
84
|
+
* Register an executor for a specific action type
|
|
85
|
+
*/
|
|
86
|
+
registerExecutor(actionType: string, executor: ActionExecutor): void;
|
|
87
|
+
/**
|
|
88
|
+
* Unregister an executor
|
|
89
|
+
*/
|
|
90
|
+
unregisterExecutor(actionType: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Execute an authorized intent
|
|
93
|
+
*/
|
|
94
|
+
execute<TParams = unknown, TResult = unknown>(request: ExecuteRequest<TParams>): Promise<ExecutionResult<TResult>>;
|
|
95
|
+
/**
|
|
96
|
+
* Execute action with timeout
|
|
97
|
+
*/
|
|
98
|
+
private executeWithTimeout;
|
|
99
|
+
/**
|
|
100
|
+
* Execute pre-execute hooks
|
|
101
|
+
*/
|
|
102
|
+
private executePreHooks;
|
|
103
|
+
/**
|
|
104
|
+
* Execute post-execute hooks
|
|
105
|
+
*/
|
|
106
|
+
private executePostHooks;
|
|
107
|
+
/**
|
|
108
|
+
* Execute execution-failed hooks
|
|
109
|
+
*/
|
|
110
|
+
private executeFailedHooks;
|
|
111
|
+
/**
|
|
112
|
+
* Get the hook manager
|
|
113
|
+
*/
|
|
114
|
+
getHookManager(): HookManager | undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create an execution engine
|
|
118
|
+
*/
|
|
119
|
+
export declare function createExecutionEngine(config?: ExecutionEngineConfig): ExecutionEngine;
|
|
120
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/execution/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EACL,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,CACjE,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,MAAM,CAAC,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,wBAAwB;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,C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G;YACW,kBAAkB;IA0BhC;;OAEG;YACW,eAAe;IAgB7B;;OAEG;YACW,gBAAgB;IAgB9B;;OAEG;YACW,kBAAkB;IAkBhC;;OAEG;IACH,cAAc,IAAI,WAAW,GAAG,SAAS;CAG1C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,CAAC,EAAE,qBAAqB,GAC7B,eAAe,CAEjB"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Engine - Executes authorized intents with hook integration
|
|
3
|
+
*
|
|
4
|
+
* The ExecutionEngine handles the actual execution of authorized intents,
|
|
5
|
+
* with pre/post execution hooks for extensibility and monitoring.
|
|
6
|
+
*
|
|
7
|
+
* Execution flow:
|
|
8
|
+
* 1. Validate the decision is still valid (not expired)
|
|
9
|
+
* 2. Execute PRE_EXECUTE hooks (can abort)
|
|
10
|
+
* 3. Execute the action via the registered executor
|
|
11
|
+
* 4. Execute POST_EXECUTE hooks on success
|
|
12
|
+
* 5. Execute EXECUTION_FAILED hooks on failure
|
|
13
|
+
*/
|
|
14
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
15
|
+
/**
|
|
16
|
+
* Determines if an error is retryable
|
|
17
|
+
*/
|
|
18
|
+
function isRetryableError(error) {
|
|
19
|
+
const message = error.message.toLowerCase();
|
|
20
|
+
const retryablePatterns = [
|
|
21
|
+
'timeout',
|
|
22
|
+
'network',
|
|
23
|
+
'connection',
|
|
24
|
+
'temporarily unavailable',
|
|
25
|
+
'rate limit',
|
|
26
|
+
'too many requests',
|
|
27
|
+
'service unavailable',
|
|
28
|
+
'gateway',
|
|
29
|
+
'econnreset',
|
|
30
|
+
'econnrefused',
|
|
31
|
+
'etimedout',
|
|
32
|
+
];
|
|
33
|
+
return retryablePatterns.some((pattern) => message.includes(pattern));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ExecutionEngine - Executes authorized intents with hook integration
|
|
37
|
+
*/
|
|
38
|
+
export class ExecutionEngine {
|
|
39
|
+
hookManager;
|
|
40
|
+
config;
|
|
41
|
+
executors = new Map();
|
|
42
|
+
constructor(config = {}) {
|
|
43
|
+
this.hookManager = config.hookManager;
|
|
44
|
+
this.config = {
|
|
45
|
+
enableHooks: config.enableHooks ?? (config.hookManager !== undefined),
|
|
46
|
+
defaultExecutor: config.defaultExecutor ?? this.noopExecutor,
|
|
47
|
+
defaultTimeoutMs: config.defaultTimeoutMs ?? 30000,
|
|
48
|
+
allowExpiredDecisions: config.allowExpiredDecisions ?? false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Default no-op executor
|
|
53
|
+
*/
|
|
54
|
+
noopExecutor = async () => {
|
|
55
|
+
return { executed: true };
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Register an executor for a specific action type
|
|
59
|
+
*/
|
|
60
|
+
registerExecutor(actionType, executor) {
|
|
61
|
+
this.executors.set(actionType, executor);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Unregister an executor
|
|
65
|
+
*/
|
|
66
|
+
unregisterExecutor(actionType) {
|
|
67
|
+
return this.executors.delete(actionType);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Execute an authorized intent
|
|
71
|
+
*/
|
|
72
|
+
async execute(request) {
|
|
73
|
+
const executionId = uuidv4();
|
|
74
|
+
const startTime = Date.now();
|
|
75
|
+
const { decision, intent, profile, params } = request;
|
|
76
|
+
// Check if decision permits the action
|
|
77
|
+
if (!decision.permitted) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
error: new Error('Decision does not permit execution'),
|
|
81
|
+
durationMs: Date.now() - startTime,
|
|
82
|
+
aborted: false,
|
|
83
|
+
executionId,
|
|
84
|
+
retryable: false,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Check if decision has expired
|
|
88
|
+
if (!this.config.allowExpiredDecisions && decision.expiresAt < new Date()) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: new Error('Decision has expired'),
|
|
92
|
+
durationMs: Date.now() - startTime,
|
|
93
|
+
aborted: false,
|
|
94
|
+
executionId,
|
|
95
|
+
retryable: false,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Execute pre-execute hooks
|
|
99
|
+
if (this.config.enableHooks && this.hookManager) {
|
|
100
|
+
const preExecuteResult = await this.executePreHooks(executionId, decision, intent, profile, params);
|
|
101
|
+
if (preExecuteResult.aborted) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
durationMs: Date.now() - startTime,
|
|
105
|
+
aborted: true,
|
|
106
|
+
abortReason: preExecuteResult.abortReason,
|
|
107
|
+
executionId,
|
|
108
|
+
retryable: false,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Get the executor
|
|
113
|
+
const executor = request.executor ??
|
|
114
|
+
this.executors.get(intent.actionType) ??
|
|
115
|
+
this.config.defaultExecutor;
|
|
116
|
+
// Execute the action
|
|
117
|
+
try {
|
|
118
|
+
const result = await this.executeWithTimeout(executor, intent, decision, params);
|
|
119
|
+
const durationMs = Date.now() - startTime;
|
|
120
|
+
// Execute post-execute hooks
|
|
121
|
+
if (this.config.enableHooks && this.hookManager) {
|
|
122
|
+
await this.executePostHooks(executionId, decision, intent, result, durationMs);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
success: true,
|
|
126
|
+
result: result,
|
|
127
|
+
durationMs,
|
|
128
|
+
aborted: false,
|
|
129
|
+
executionId,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const durationMs = Date.now() - startTime;
|
|
134
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
135
|
+
const retryable = isRetryableError(err);
|
|
136
|
+
// Execute execution-failed hooks
|
|
137
|
+
if (this.config.enableHooks && this.hookManager) {
|
|
138
|
+
await this.executeFailedHooks(executionId, decision, intent, err, durationMs, retryable);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
error: err,
|
|
143
|
+
durationMs,
|
|
144
|
+
aborted: false,
|
|
145
|
+
executionId,
|
|
146
|
+
retryable,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Execute action with timeout
|
|
152
|
+
*/
|
|
153
|
+
async executeWithTimeout(executor, intent, decision, params) {
|
|
154
|
+
const timeoutMs = decision.constraints?.maxExecutionTimeMs ?? this.config.defaultTimeoutMs;
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
const timeoutId = setTimeout(() => {
|
|
157
|
+
reject(new Error(`Execution timeout after ${timeoutMs}ms`));
|
|
158
|
+
}, timeoutMs);
|
|
159
|
+
executor(intent, decision, params)
|
|
160
|
+
.then((result) => {
|
|
161
|
+
clearTimeout(timeoutId);
|
|
162
|
+
resolve(result);
|
|
163
|
+
})
|
|
164
|
+
.catch((error) => {
|
|
165
|
+
clearTimeout(timeoutId);
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Execute pre-execute hooks
|
|
172
|
+
*/
|
|
173
|
+
async executePreHooks(_executionId, decision, intent, profile, params) {
|
|
174
|
+
return this.hookManager.executePreExecute({
|
|
175
|
+
correlationId: intent.correlationId,
|
|
176
|
+
decision,
|
|
177
|
+
intent,
|
|
178
|
+
profile,
|
|
179
|
+
params: params,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Execute post-execute hooks
|
|
184
|
+
*/
|
|
185
|
+
async executePostHooks(_executionId, decision, intent, result, durationMs) {
|
|
186
|
+
return this.hookManager.executePostExecute({
|
|
187
|
+
correlationId: intent.correlationId,
|
|
188
|
+
decision,
|
|
189
|
+
intent,
|
|
190
|
+
result,
|
|
191
|
+
durationMs,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Execute execution-failed hooks
|
|
196
|
+
*/
|
|
197
|
+
async executeFailedHooks(_executionId, decision, intent, error, durationMs, retryable) {
|
|
198
|
+
return this.hookManager.executeExecutionFailed({
|
|
199
|
+
correlationId: intent.correlationId,
|
|
200
|
+
decision,
|
|
201
|
+
intent,
|
|
202
|
+
error,
|
|
203
|
+
durationMs,
|
|
204
|
+
retryable,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get the hook manager
|
|
209
|
+
*/
|
|
210
|
+
getHookManager() {
|
|
211
|
+
return this.hookManager;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Create an execution engine
|
|
216
|
+
*/
|
|
217
|
+
export function createExecutionEngine(config) {
|
|
218
|
+
return new ExecutionEngine(config);
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/execution/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAsEpC;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAY;IACpC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,iBAAiB,GAAG;QACxB,SAAS;QACT,SAAS;QACT,YAAY;QACZ,yBAAyB;QACzB,YAAY;QACZ,mBAAmB;QACnB,qBAAqB;QACrB,SAAS;QACT,YAAY;QACZ,cAAc;QACd,WAAW;KACZ,CAAC;IACF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,eAAe;IACT,WAAW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CAAC,kBAAkB,CAC9B,YAAoB,EACpB,QAAkB,EAClB,MAAc,EACd,KAAY,EACZ,UAAkB,EAClB,SAAkB;QAElB,OAAO,IAAI,CAAC,WAAY,CAAC,sBAAsB,CAAC;YAC9C,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,QAAQ;YACR,MAAM;YACN,KAAK;YACL,UAAU;YACV,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAA8B;IAE9B,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Module - Action execution with hook integration
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { ExecutionEngine, createExecutionEngine, type ActionExecutor, type ExecutionResult, type ExecuteRequest, type ExecutionEngineConfig, } from './engine.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/execution/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/execution/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,qBAAqB,GAKtB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-Action Gate Module - ATSF v2.0 Capability Gating
|
|
3
|
+
*
|
|
4
|
+
* Implements pre-action verification to prevent "Treacherous Turn" attacks.
|
|
5
|
+
* Low-trust agents cannot request high-risk actions.
|
|
6
|
+
*
|
|
7
|
+
* Key principle: Trust must be earned through demonstrated success
|
|
8
|
+
* on low-risk actions first.
|
|
9
|
+
*/
|
|
10
|
+
export { classifyRisk, getRiskLevel, isReadOnly, involvesTransfer, isDestructive, explainRiskFactors, requiresVerification, requiresHumanApproval, } from './risk-classifier.js';
|
|
11
|
+
export { PreActionGate, createPreActionGate, createMapTrustProvider, type TrustProvider, type GateEventListener, } from './pre-action-gate.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-Action Gate Module - ATSF v2.0 Capability Gating
|
|
3
|
+
*
|
|
4
|
+
* Implements pre-action verification to prevent "Treacherous Turn" attacks.
|
|
5
|
+
* Low-trust agents cannot request high-risk actions.
|
|
6
|
+
*
|
|
7
|
+
* Key principle: Trust must be earned through demonstrated success
|
|
8
|
+
* on low-risk actions first.
|
|
9
|
+
*/
|
|
10
|
+
// Risk Classifier
|
|
11
|
+
export { classifyRisk, getRiskLevel, isReadOnly, involvesTransfer, isDestructive, explainRiskFactors, requiresVerification, requiresHumanApproval, } from './risk-classifier.js';
|
|
12
|
+
// Pre-Action Gate
|
|
13
|
+
export { PreActionGate, createPreActionGate, createMapTrustProvider, } from './pre-action-gate.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,kBAAkB;AAClB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAE9B,kBAAkB;AAClB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,sBAAsB,GAGvB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-Action Verification Gate - ATSF v2.0 Section 4.4
|
|
3
|
+
*
|
|
4
|
+
* Key principle: Trust score gates CAPABILITY, not just post-hoc scoring.
|
|
5
|
+
*
|
|
6
|
+
* Problem solved: At the moment of a "Treacherous Turn," an agent's trust
|
|
7
|
+
* is maximal because ATSF v1.x updates trust AFTER action execution.
|
|
8
|
+
*
|
|
9
|
+
* Solution: Pre-action gating checks trust BEFORE execution.
|
|
10
|
+
* Low-trust agents cannot REQUEST high-risk actions.
|
|
11
|
+
* Trust must be earned through demonstrated success on low-risk actions first.
|
|
12
|
+
*/
|
|
13
|
+
import { type GateVerificationRequest, type GateVerificationResult, type PreActionGateConfig, type GateEvent, RiskLevel } from '@vorionsys/contracts';
|
|
14
|
+
/**
|
|
15
|
+
* Trust provider interface - abstracts trust score retrieval
|
|
16
|
+
*/
|
|
17
|
+
export interface TrustProvider {
|
|
18
|
+
getTrustScore(agentId: string): number | Promise<number>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gate event listener
|
|
22
|
+
*/
|
|
23
|
+
export type GateEventListener = (event: GateEvent) => void;
|
|
24
|
+
/**
|
|
25
|
+
* PreActionGate - Verifies agent trust before allowing action execution
|
|
26
|
+
*/
|
|
27
|
+
export declare class PreActionGate {
|
|
28
|
+
private readonly config;
|
|
29
|
+
private readonly trustProvider?;
|
|
30
|
+
private readonly trustThresholds;
|
|
31
|
+
private readonly eventListeners;
|
|
32
|
+
constructor(config?: Partial<PreActionGateConfig>, trustProvider?: TrustProvider);
|
|
33
|
+
/**
|
|
34
|
+
* Verify an action before execution
|
|
35
|
+
*
|
|
36
|
+
* This is the main entry point. Call this BEFORE allowing an agent
|
|
37
|
+
* to execute any action.
|
|
38
|
+
*/
|
|
39
|
+
verify(request: GateVerificationRequest, trustScore?: number): Promise<GateVerificationResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Quick check without full verification
|
|
42
|
+
* Returns true if action would be immediately approved
|
|
43
|
+
*/
|
|
44
|
+
canProceed(request: GateVerificationRequest, trustScore?: number): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the trust threshold for a risk level
|
|
47
|
+
*/
|
|
48
|
+
getThreshold(riskLevel: RiskLevel): number;
|
|
49
|
+
/**
|
|
50
|
+
* Get all trust thresholds
|
|
51
|
+
*/
|
|
52
|
+
getThresholds(): Readonly<Record<RiskLevel, number>>;
|
|
53
|
+
/**
|
|
54
|
+
* Check what risk level an agent can handle with their current trust
|
|
55
|
+
*/
|
|
56
|
+
getMaxRiskLevel(trustScore: number): RiskLevel;
|
|
57
|
+
/**
|
|
58
|
+
* Get trust deficit for a specific risk level
|
|
59
|
+
*/
|
|
60
|
+
getTrustDeficit(currentTrust: number, riskLevel: RiskLevel): number;
|
|
61
|
+
/**
|
|
62
|
+
* Add event listener
|
|
63
|
+
*/
|
|
64
|
+
addEventListener(listener: GateEventListener): void;
|
|
65
|
+
/**
|
|
66
|
+
* Remove event listener
|
|
67
|
+
*/
|
|
68
|
+
removeEventListener(listener: GateEventListener): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get current configuration
|
|
71
|
+
*/
|
|
72
|
+
getConfig(): Readonly<PreActionGateConfig>;
|
|
73
|
+
private resolveTrustScore;
|
|
74
|
+
private determineStatus;
|
|
75
|
+
private getRiskLevelValue;
|
|
76
|
+
private getEventType;
|
|
77
|
+
private emitEvent;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a pre-action gate
|
|
81
|
+
*/
|
|
82
|
+
export declare function createPreActionGate(config?: Partial<PreActionGateConfig>, trustProvider?: TrustProvider): PreActionGate;
|
|
83
|
+
/**
|
|
84
|
+
* Create a simple trust provider from a map
|
|
85
|
+
*/
|
|
86
|
+
export declare function createMapTrustProvider(trustScores: Map<string, number> | Record<string, number>): TrustProvider;
|
|
87
|
+
//# sourceMappingURL=pre-action-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-action-gate.d.ts","sourceRoot":"","sources":["../../src/gate/pre-action-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAE3B,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,SAAS,EAIV,MAAM,sBAAsB,CAAC;AAI9B;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1D;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAE3D;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4B;IAC5D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA2B;gBAGxD,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM,EACzC,aAAa,CAAC,EAAE,aAAa;IAU/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