@ai-pip/core 0.2.0 → 0.4.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/CHANGELOG.md +106 -3
- package/README.md +52 -951
- package/dist/AAL/constants.d.ts +15 -0
- package/dist/AAL/constants.d.ts.map +1 -0
- package/dist/AAL/constants.js +20 -0
- package/dist/AAL/constants.js.map +1 -0
- package/dist/AAL/index.d.ts +5 -4
- package/dist/AAL/index.d.ts.map +1 -1
- package/dist/AAL/index.js +4 -2
- package/dist/AAL/index.js.map +1 -1
- package/dist/AAL/process/applyRemovalPlan.d.ts +23 -0
- package/dist/AAL/process/applyRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/applyRemovalPlan.js +157 -0
- package/dist/AAL/process/applyRemovalPlan.js.map +1 -0
- package/dist/AAL/process/buildDecisionReason.d.ts.map +1 -1
- package/dist/AAL/process/buildDecisionReason.js +24 -4
- package/dist/AAL/process/buildDecisionReason.js.map +1 -1
- package/dist/AAL/process/buildRemediationPlan.d.ts +22 -0
- package/dist/AAL/process/buildRemediationPlan.d.ts.map +1 -0
- package/dist/AAL/process/buildRemediationPlan.js +81 -0
- package/dist/AAL/process/buildRemediationPlan.js.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts +27 -9
- package/dist/AAL/process/buildRemovalPlan.d.ts.map +1 -1
- package/dist/AAL/process/buildRemovalPlan.js +95 -29
- package/dist/AAL/process/buildRemovalPlan.js.map +1 -1
- package/dist/AAL/process/index.d.ts +2 -2
- package/dist/AAL/process/index.d.ts.map +1 -1
- package/dist/AAL/process/index.js +2 -1
- package/dist/AAL/process/index.js.map +1 -1
- package/dist/AAL/process/resolveAgentAction.d.ts.map +1 -1
- package/dist/AAL/process/resolveAgentAction.js +13 -0
- package/dist/AAL/process/resolveAgentAction.js.map +1 -1
- package/dist/AAL/process/validatePolicy.d.ts +20 -0
- package/dist/AAL/process/validatePolicy.d.ts.map +1 -0
- package/dist/AAL/process/validatePolicy.js +40 -0
- package/dist/AAL/process/validatePolicy.js.map +1 -0
- package/dist/AAL/types.d.ts +18 -31
- package/dist/AAL/types.d.ts.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/isl/detect/detect.d.ts +39 -0
- package/dist/isl/detect/detect.d.ts.map +1 -0
- package/dist/isl/detect/detect.js +369 -0
- package/dist/isl/detect/detect.js.map +1 -0
- package/dist/isl/detect/index.d.ts +6 -0
- package/dist/isl/detect/index.d.ts.map +1 -0
- package/dist/isl/detect/index.js +5 -0
- package/dist/isl/detect/index.js.map +1 -0
- package/dist/isl/index.d.ts +8 -1
- package/dist/isl/index.d.ts.map +1 -1
- package/dist/isl/index.js +5 -0
- package/dist/isl/index.js.map +1 -1
- package/dist/isl/process/emitSignal.d.ts +19 -10
- package/dist/isl/process/emitSignal.d.ts.map +1 -1
- package/dist/isl/process/emitSignal.js +25 -23
- package/dist/isl/process/emitSignal.js.map +1 -1
- package/dist/isl/process/index.d.ts +1 -0
- package/dist/isl/process/index.d.ts.map +1 -1
- package/dist/isl/riskScore/calculators.d.ts +19 -0
- package/dist/isl/riskScore/calculators.d.ts.map +1 -0
- package/dist/isl/riskScore/calculators.js +50 -0
- package/dist/isl/riskScore/calculators.js.map +1 -0
- package/dist/isl/riskScore/index.d.ts +14 -0
- package/dist/isl/riskScore/index.d.ts.map +1 -0
- package/dist/isl/riskScore/index.js +26 -0
- package/dist/isl/riskScore/index.js.map +1 -0
- package/dist/isl/riskScore/types.d.ts +20 -0
- package/dist/isl/riskScore/types.d.ts.map +1 -0
- package/dist/isl/riskScore/types.js +12 -0
- package/dist/isl/riskScore/types.js.map +1 -0
- package/dist/isl/sanitize.d.ts +8 -1
- package/dist/isl/sanitize.d.ts.map +1 -1
- package/dist/isl/sanitize.js +13 -5
- package/dist/isl/sanitize.js.map +1 -1
- package/dist/isl/signals.d.ts +16 -1
- package/dist/isl/signals.d.ts.map +1 -1
- package/dist/isl/signals.js +4 -2
- package/dist/isl/signals.js.map +1 -1
- package/dist/isl/value-objects/Pattern.d.ts +21 -0
- package/dist/isl/value-objects/Pattern.d.ts.map +1 -1
- package/dist/isl/value-objects/Pattern.js +36 -0
- package/dist/isl/value-objects/Pattern.js.map +1 -1
- package/dist/isl/value-objects/index.d.ts +2 -2
- package/dist/isl/value-objects/index.d.ts.map +1 -1
- package/dist/isl/value-objects/index.js +1 -1
- package/dist/isl/value-objects/index.js.map +1 -1
- package/dist/shared/audit.d.ts +126 -28
- package/dist/shared/audit.d.ts.map +1 -1
- package/dist/shared/audit.js +322 -44
- package/dist/shared/audit.js.map +1 -1
- package/dist/shared/envelope/envelope.d.ts +23 -0
- package/dist/shared/envelope/envelope.d.ts.map +1 -0
- package/dist/shared/envelope/envelope.js +58 -0
- package/dist/shared/envelope/envelope.js.map +1 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.d.ts +8 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.d.ts.map +1 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.js +13 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.js.map +1 -0
- package/dist/shared/envelope/exceptions/index.d.ts +2 -0
- package/dist/shared/envelope/exceptions/index.d.ts.map +1 -0
- package/dist/shared/envelope/exceptions/index.js +2 -0
- package/dist/shared/envelope/exceptions/index.js.map +1 -0
- package/dist/shared/envelope/index.d.ts +18 -0
- package/dist/shared/envelope/index.d.ts.map +1 -0
- package/dist/shared/envelope/index.js +15 -0
- package/dist/shared/envelope/index.js.map +1 -0
- package/dist/shared/envelope/types.d.ts +45 -0
- package/dist/shared/envelope/types.d.ts.map +1 -0
- package/dist/shared/envelope/types.js +10 -0
- package/dist/shared/envelope/types.js.map +1 -0
- package/dist/shared/envelope/value-objects/Metadata.d.ts +27 -0
- package/dist/shared/envelope/value-objects/Metadata.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/Metadata.js +57 -0
- package/dist/shared/envelope/value-objects/Metadata.js.map +1 -0
- package/dist/shared/envelope/value-objects/Nonce.d.ts +26 -0
- package/dist/shared/envelope/value-objects/Nonce.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/Nonce.js +38 -0
- package/dist/shared/envelope/value-objects/Nonce.js.map +1 -0
- package/dist/shared/envelope/value-objects/Signature.d.ts +28 -0
- package/dist/shared/envelope/value-objects/Signature.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/Signature.js +50 -0
- package/dist/shared/envelope/value-objects/Signature.js.map +1 -0
- package/dist/shared/envelope/value-objects/index.d.ts +9 -0
- package/dist/shared/envelope/value-objects/index.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/index.js +7 -0
- package/dist/shared/envelope/value-objects/index.js.map +1 -0
- package/dist/shared/index.d.ts +2 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.js.map +1 -1
- package/package.json +11 -6
|
@@ -2,45 +2,111 @@
|
|
|
2
2
|
* buildRemovalPlan - Builds a plan for instruction removal
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Each instruction in the plan must be tied to one segment and one range in that segment:
|
|
6
|
+
* - segmentId: same as segment.id in ISLResult (so applyRemovalPlan knows which segment to cut).
|
|
7
|
+
* - position: { start, end } in segment-local coordinates (indices within segment.sanitizedContent).
|
|
8
|
+
* So "remove instruction X" means: in the segment with id segmentId, delete exactly [start, end) of that segment's sanitizedContent.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* - Does not execute the removal (that is SDK responsibility)
|
|
10
|
+
* Two entry points:
|
|
11
|
+
* - buildRemovalPlan(islSignal, policy): from signal only; no segmentId (descriptive).
|
|
12
|
+
* - buildRemovalPlanFromResult(islResult, policy): from result; includes segmentId and segment-local position for applyRemovalPlan.
|
|
12
13
|
*/
|
|
14
|
+
function mapDetectionToRemovedInstruction(detection, segmentId) {
|
|
15
|
+
return {
|
|
16
|
+
type: detection.pattern_type,
|
|
17
|
+
pattern: detection.matched_pattern,
|
|
18
|
+
position: detection.position,
|
|
19
|
+
description: `Detected ${detection.pattern_type} pattern with confidence ${detection.confidence.toFixed(3)}`,
|
|
20
|
+
...(segmentId != null && { segmentId })
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const EMPTY_PLAN_DISABLED = Object.freeze({
|
|
24
|
+
instructionsToRemove: Object.freeze([]),
|
|
25
|
+
shouldRemove: false,
|
|
26
|
+
removalEnabled: false
|
|
27
|
+
});
|
|
28
|
+
const EMPTY_PLAN_NO_THREATS = Object.freeze({
|
|
29
|
+
instructionsToRemove: Object.freeze([]),
|
|
30
|
+
shouldRemove: false,
|
|
31
|
+
removalEnabled: true
|
|
32
|
+
});
|
|
33
|
+
function assertPolicyForRemoval(policy) {
|
|
34
|
+
if (policy == null || typeof policy !== 'object') {
|
|
35
|
+
throw new TypeError('AAL buildRemovalPlan: policy must be a non-null object');
|
|
36
|
+
}
|
|
37
|
+
const r = policy.removal;
|
|
38
|
+
if (r == null || typeof r !== 'object' || typeof r.enabled !== 'boolean') {
|
|
39
|
+
throw new TypeError('AAL buildRemovalPlan: policy.removal.enabled must be a boolean');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function assertISLSignalForRemoval(signal) {
|
|
43
|
+
if (signal == null || typeof signal !== 'object') {
|
|
44
|
+
throw new TypeError('AAL buildRemovalPlan: islSignal must be a non-null object');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
13
47
|
/**
|
|
14
|
-
* Builds a plan for instruction removal
|
|
48
|
+
* Builds a plan for instruction removal from ISL signal (no segment ids).
|
|
49
|
+
* Use when you only have the signal; plan is descriptive. For actionable removal use buildRemovalPlanFromResult.
|
|
15
50
|
*
|
|
16
51
|
* @param islSignal - ISL signal with detections
|
|
17
52
|
* @param policy - Agent policy
|
|
18
|
-
* @returns RemovalPlan with instructions to remove
|
|
53
|
+
* @returns RemovalPlan with instructions to remove (no segmentId)
|
|
19
54
|
*/
|
|
20
55
|
export function buildRemovalPlan(islSignal, policy) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
56
|
+
assertPolicyForRemoval(policy);
|
|
57
|
+
assertISLSignalForRemoval(islSignal);
|
|
58
|
+
if (!policy.removal.enabled)
|
|
59
|
+
return EMPTY_PLAN_DISABLED;
|
|
60
|
+
if (!islSignal.hasThreats)
|
|
61
|
+
return EMPTY_PLAN_NO_THREATS;
|
|
62
|
+
const detections = islSignal.piDetection?.detections;
|
|
63
|
+
if (!Array.isArray(detections) || detections.length === 0) {
|
|
64
|
+
return EMPTY_PLAN_NO_THREATS;
|
|
65
|
+
}
|
|
66
|
+
const instructionsToRemove = detections.map((d) => mapDetectionToRemovedInstruction(d));
|
|
67
|
+
return {
|
|
68
|
+
instructionsToRemove: Object.freeze(instructionsToRemove),
|
|
69
|
+
shouldRemove: instructionsToRemove.length > 0,
|
|
70
|
+
removalEnabled: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function assertISLResultForRemoval(islResult) {
|
|
74
|
+
if (islResult == null || typeof islResult !== 'object') {
|
|
75
|
+
throw new TypeError('AAL buildRemovalPlanFromResult: islResult must be a non-null object');
|
|
28
76
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
77
|
+
if (!Array.isArray(islResult.segments)) {
|
|
78
|
+
throw new TypeError('AAL buildRemovalPlanFromResult: islResult.segments must be an array');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Builds a plan for instruction removal from ISL result (with segment ids).
|
|
83
|
+
* Use with applyRemovalPlan to produce content with malicious ranges removed.
|
|
84
|
+
*
|
|
85
|
+
* Each instruction is built from one segment only:
|
|
86
|
+
* - segmentId = segment.id (so applyRemovalPlan knows which segment to cut).
|
|
87
|
+
* - position = detection.position as-is (already segment-local: indices within
|
|
88
|
+
* that segment's sanitizedContent, from detectThreats run on that segment).
|
|
89
|
+
* No document-concatenated or global offsets are used.
|
|
90
|
+
*
|
|
91
|
+
* @param islResult - ISL result with segments and per-segment piDetection
|
|
92
|
+
* @param policy - Agent policy
|
|
93
|
+
* @returns RemovalPlan with instructions to remove (segmentId + segment-local position per instruction)
|
|
94
|
+
*/
|
|
95
|
+
export function buildRemovalPlanFromResult(islResult, policy) {
|
|
96
|
+
assertPolicyForRemoval(policy);
|
|
97
|
+
assertISLResultForRemoval(islResult);
|
|
98
|
+
if (!policy.removal.enabled)
|
|
99
|
+
return EMPTY_PLAN_DISABLED;
|
|
100
|
+
const instructionsToRemove = [];
|
|
101
|
+
for (const segment of islResult.segments) {
|
|
102
|
+
const detections = segment.piDetection?.detections;
|
|
103
|
+
if (!Array.isArray(detections) || detections.length === 0)
|
|
104
|
+
continue;
|
|
105
|
+
for (const d of detections) {
|
|
106
|
+
// position is segment-local (from detectThreats on this segment's sanitizedContent)
|
|
107
|
+
instructionsToRemove.push(mapDetectionToRemovedInstruction(d, segment.id));
|
|
108
|
+
}
|
|
36
109
|
}
|
|
37
|
-
// Build list of instructions to remove from detections
|
|
38
|
-
const instructionsToRemove = islSignal.piDetection.detections.map((detection) => ({
|
|
39
|
-
type: detection.pattern_type,
|
|
40
|
-
pattern: detection.matched_pattern,
|
|
41
|
-
position: detection.position,
|
|
42
|
-
description: `Detected ${detection.pattern_type} pattern with confidence ${detection.confidence.toFixed(3)}`
|
|
43
|
-
}));
|
|
44
110
|
return {
|
|
45
111
|
instructionsToRemove: Object.freeze(instructionsToRemove),
|
|
46
112
|
shouldRemove: instructionsToRemove.length > 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRemovalPlan.js","sourceRoot":"","sources":["../../../src/AAL/process/buildRemovalPlan.ts"],"names":[],"mappings":"AAAA
|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AAI,SAAS,CAAC,qEAAqE,CAAC,CAAA;IAC5F,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,0BAA0B,CACxC,SAAoB,EACpB,MAAmB;IAEnB,sBAAsB,CAAC,MAAM,CAAC,CAAA;IAC9B,yBAAyB,CAAC,SAAS,CAAC,CAAA;IAEpC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,mBAAmB,CAAA;IAEvD,MAAM,oBAAoB,GAAyB,EAAE,CAAA;IACrD,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;QACzC,MAAM,UAAU,GAAuC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAA;QACtF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,SAAQ;QACnE,KAAK,MAAM,CAAC,IAAI,UAA2B,EAAE,CAAC;YAC5C,oFAAoF;YACpF,oBAAoB,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAC5E,CAAC;IACH,CAAC;IACD,OAAO;QACL,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;QACzD,YAAY,EAAE,oBAAoB,CAAC,MAAM,GAAG,CAAC;QAC7C,cAAc,EAAE,IAAI;KACrB,CAAA;AACH,CAAC"}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
export { resolveAgentAction, resolveAgentActionWithScore } from './resolveAgentAction.js';
|
|
5
5
|
export { buildDecisionReason } from './buildDecisionReason.js';
|
|
6
6
|
export type { DecisionReason } from './buildDecisionReason.js';
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
7
|
+
export { buildRemediationPlan } from './buildRemediationPlan.js';
|
|
8
|
+
export { validateAgentPolicyThresholds } from './validatePolicy.js';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { resolveAgentAction, resolveAgentActionWithScore } from './resolveAgentAction.js';
|
|
5
5
|
export { buildDecisionReason } from './buildDecisionReason.js';
|
|
6
|
-
export {
|
|
6
|
+
export { buildRemediationPlan } from './buildRemediationPlan.js';
|
|
7
|
+
export { validateAgentPolicyThresholds } from './validatePolicy.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/AAL/process/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/AAL/process/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAgentAction.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/resolveAgentAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveAgentAction.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/resolveAgentAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAa7D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,WAAW,GAClB,aAAa,CAef;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,WAAW,2DAMpB"}
|
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
* - Return decision based on risk score and thresholds
|
|
12
12
|
*/
|
|
13
13
|
import { createAnomalyScore } from '../value-objects/AnomalyScore.js';
|
|
14
|
+
import { validateAgentPolicyThresholds } from './validatePolicy.js';
|
|
15
|
+
function assertISLSignal(signal) {
|
|
16
|
+
if (signal == null || typeof signal !== 'object') {
|
|
17
|
+
throw new TypeError('AAL resolveAgentAction: islSignal must be a non-null object');
|
|
18
|
+
}
|
|
19
|
+
if (typeof signal.riskScore !== 'number') {
|
|
20
|
+
throw new TypeError('AAL resolveAgentAction: islSignal.riskScore must be a number');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
14
23
|
/**
|
|
15
24
|
* Resolves agent action based on ISL signal and policy
|
|
16
25
|
*
|
|
@@ -19,6 +28,8 @@ import { createAnomalyScore } from '../value-objects/AnomalyScore.js';
|
|
|
19
28
|
* @returns AnomalyAction (ALLOW, WARN, BLOCK)
|
|
20
29
|
*/
|
|
21
30
|
export function resolveAgentAction(islSignal, policy) {
|
|
31
|
+
assertISLSignal(islSignal);
|
|
32
|
+
validateAgentPolicyThresholds(policy);
|
|
22
33
|
const riskScore = islSignal.riskScore;
|
|
23
34
|
// Evaluate policy thresholds
|
|
24
35
|
if (riskScore >= policy.thresholds.block) {
|
|
@@ -37,6 +48,8 @@ export function resolveAgentAction(islSignal, policy) {
|
|
|
37
48
|
* @returns AnomalyScore with score and action
|
|
38
49
|
*/
|
|
39
50
|
export function resolveAgentActionWithScore(islSignal, policy) {
|
|
51
|
+
assertISLSignal(islSignal);
|
|
52
|
+
validateAgentPolicyThresholds(policy);
|
|
40
53
|
const action = resolveAgentAction(islSignal, policy);
|
|
41
54
|
return createAnomalyScore(islSignal.riskScore, action);
|
|
42
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAgentAction.js","sourceRoot":"","sources":["../../../src/AAL/process/resolveAgentAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveAgentAction.js","sourceRoot":"","sources":["../../../src/AAL/process/resolveAgentAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,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+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Ensures policy is coherent: warn and block must be in [0, 1] and warn < block.
|
|
6
|
+
* Invalid configuration (e.g. block < warn) would lead to inconsistent decisions
|
|
7
|
+
* (e.g. WARN range empty or unreachable). Call this before using the policy
|
|
8
|
+
* in resolveAgentAction, buildDecisionReason, or buildRemediationPlan.
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentPolicy } from '../types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Validates that policy.thresholds.warn and block are numbers in [0, 1]
|
|
13
|
+
* and that warn < block.
|
|
14
|
+
*
|
|
15
|
+
* @param policy - Agent policy to validate
|
|
16
|
+
* @throws {TypeError} If policy is null/undefined or thresholds are missing/invalid
|
|
17
|
+
* @throws {RangeError} If warn or block are outside [0, 1] or if warn >= block
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateAgentPolicyThresholds(policy: AgentPolicy): void;
|
|
20
|
+
//# sourceMappingURL=validatePolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatePolicy.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/validatePolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CA2BvE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* validateAgentPolicyThresholds - Validates AAL policy thresholds.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Ensures policy is coherent: warn and block must be in [0, 1] and warn < block.
|
|
6
|
+
* Invalid configuration (e.g. block < warn) would lead to inconsistent decisions
|
|
7
|
+
* (e.g. WARN range empty or unreachable). Call this before using the policy
|
|
8
|
+
* in resolveAgentAction, buildDecisionReason, or buildRemediationPlan.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Validates that policy.thresholds.warn and block are numbers in [0, 1]
|
|
12
|
+
* and that warn < block.
|
|
13
|
+
*
|
|
14
|
+
* @param policy - Agent policy to validate
|
|
15
|
+
* @throws {TypeError} If policy is null/undefined or thresholds are missing/invalid
|
|
16
|
+
* @throws {RangeError} If warn or block are outside [0, 1] or if warn >= block
|
|
17
|
+
*/
|
|
18
|
+
export function validateAgentPolicyThresholds(policy) {
|
|
19
|
+
if (policy == null || typeof policy !== 'object') {
|
|
20
|
+
throw new TypeError('AAL policy must be a non-null object');
|
|
21
|
+
}
|
|
22
|
+
const t = policy.thresholds;
|
|
23
|
+
if (t == null || typeof t !== 'object') {
|
|
24
|
+
throw new TypeError('AAL policy.thresholds must be defined');
|
|
25
|
+
}
|
|
26
|
+
if (typeof t.warn !== 'number' || typeof t.block !== 'number') {
|
|
27
|
+
throw new TypeError('AAL policy.thresholds.warn and block must be numbers');
|
|
28
|
+
}
|
|
29
|
+
const { warn, block } = t;
|
|
30
|
+
if (warn < 0 || warn > 1) {
|
|
31
|
+
throw new RangeError(`AAL policy.thresholds.warn must be in [0, 1], got ${warn}`);
|
|
32
|
+
}
|
|
33
|
+
if (block < 0 || block > 1) {
|
|
34
|
+
throw new RangeError(`AAL policy.thresholds.block must be in [0, 1], got ${block}`);
|
|
35
|
+
}
|
|
36
|
+
if (warn >= block) {
|
|
37
|
+
throw new RangeError(`AAL policy.thresholds must satisfy warn < block (got warn=${warn}, block=${block})`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=validatePolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatePolicy.js","sourceRoot":"","sources":["../../../src/AAL/process/validatePolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,6BAA6B,CAAC,MAAmB;IAC/D,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjD,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAA;IAC7D,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAA;IAC3B,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAA;IAC9D,CAAC;IACD,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9D,MAAM,IAAI,SAAS,CAAC,sDAAsD,CAAC,CAAA;IAC7E,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;IACzB,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,UAAU,CAClB,qDAAqD,IAAI,EAAE,CAC5D,CAAA;IACH,CAAC;IACD,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CAClB,sDAAsD,KAAK,EAAE,CAC9D,CAAA;IACH,CAAC;IACD,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,UAAU,CAClB,6DAA6D,IAAI,WAAW,KAAK,GAAG,CACrF,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/dist/AAL/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { RiskScore } from '../isl/value-objects/RiskScore.js';
|
|
2
|
-
import type { Position } from "../shared/types.js";
|
|
3
2
|
/**
|
|
4
3
|
* AnomalyAction
|
|
5
4
|
*
|
|
@@ -40,35 +39,23 @@ export type ProtectedRole = string;
|
|
|
40
39
|
*/
|
|
41
40
|
export type ImmutableInstruction = string;
|
|
42
41
|
/**
|
|
43
|
-
*
|
|
42
|
+
* RemediationPlan
|
|
44
43
|
*
|
|
45
|
-
* Describes
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* This interface is descriptive only.
|
|
50
|
-
* The actual removal is performed by the SDK.
|
|
51
|
-
*
|
|
52
|
-
* Instances of this type are typically recorded in lineage
|
|
53
|
-
* for auditability and explainability.
|
|
44
|
+
* Describes *what* to do for remediation, not *how*. The SDK (or an AI agent) is
|
|
45
|
+
* responsible for executing cleanup. AAL produces goals, constraints, and
|
|
46
|
+
* target segment IDs so the consumer can run AI_CLEANUP or another strategy.
|
|
54
47
|
*/
|
|
55
|
-
export interface
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
readonly
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
readonly
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
*/
|
|
67
|
-
readonly position: Position;
|
|
68
|
-
/**
|
|
69
|
-
* Human-readable explanation of why the instruction was removed.
|
|
70
|
-
*/
|
|
71
|
-
readonly description: string;
|
|
48
|
+
export interface RemediationPlan {
|
|
49
|
+
/** Strategy identifier for the consumer (e.g. 'AI_CLEANUP'). */
|
|
50
|
+
readonly strategy: string;
|
|
51
|
+
/** Goals to achieve (e.g. remove_prompt_injection, remove_role_hijacking). */
|
|
52
|
+
readonly goals: readonly string[];
|
|
53
|
+
/** Constraints the remediation must respect (e.g. preserve_user_intent). */
|
|
54
|
+
readonly constraints: readonly string[];
|
|
55
|
+
/** Segment IDs that need remediation (segments with detections). */
|
|
56
|
+
readonly targetSegments: readonly string[];
|
|
57
|
+
/** Whether remediation is needed (has threats and remediation enabled). */
|
|
58
|
+
readonly needsRemediation: boolean;
|
|
72
59
|
}
|
|
73
60
|
/**
|
|
74
61
|
* AgentPolicy
|
|
@@ -92,10 +79,10 @@ export interface AgentPolicy {
|
|
|
92
79
|
block: RiskScore;
|
|
93
80
|
};
|
|
94
81
|
/**
|
|
95
|
-
* Whether
|
|
96
|
-
*
|
|
82
|
+
* Whether to produce a remediation plan when threats are present.
|
|
83
|
+
* The SDK (or AI agent) performs the actual cleanup using the plan.
|
|
97
84
|
*/
|
|
98
|
-
|
|
85
|
+
remediation: {
|
|
99
86
|
enabled: boolean;
|
|
100
87
|
};
|
|
101
88
|
mode?: 'strict' | 'balanced' | 'permissive';
|
package/dist/AAL/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/AAL/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/AAL/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAElE;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAElC;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAElC;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,4EAA4E;IAC5E,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,oEAAoE;IACpE,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAA;CACnC;AAED;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,WAAW;IAE1B;;OAEG;IACH,UAAU,EAAE;QACV,IAAI,EAAE,SAAS,CAAC;QAChB,KAAK,EAAE,SAAS,CAAC;KAClB,CAAC;IAED;;;MAGE;IACH,WAAW,EAAE;QACX,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAGF,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CAGnB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* You can import from specific layers:
|
|
8
8
|
* - import { segment } from '@ai-pip/core/csl'
|
|
9
9
|
* - import { sanitize } from '@ai-pip/core/isl'
|
|
10
|
-
* - import { envelope } from '@ai-pip/core/cpe'
|
|
10
|
+
* - import { envelope } from '@ai-pip/core/cpe' (re-exported from shared/envelope)
|
|
11
11
|
* - import { createAnomalyScore } from '@ai-pip/core/AAL'
|
|
12
12
|
*
|
|
13
13
|
* Or import everything from the main entry point:
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export { segment, classifySource, classifyOrigin, initLineage, createLineageEntry, generateId, splitByContextRules, OriginType, TrustLevelType, ClassificationError, SegmentationError } from './csl/index.js';
|
|
19
19
|
export type { HashAlgorithm, Source, CSLInput, CSLSegment, CSLResult, TrustLevel, Origin, LineageEntry, ContentHash } from './csl/index.js';
|
|
20
|
-
export { sanitize, emitSignal, createISLSignal, isHighRiskSignal, isMediumRiskSignal, isLowRiskSignal } from './isl/index.js';
|
|
21
|
-
export type { RiskScore, ISLSegment, ISLResult, ISLSignal, PiDetection, PiDetectionResult, Pattern } from './isl/index.js';
|
|
20
|
+
export { sanitize, emitSignal, createISLSignal, isHighRiskSignal, isMediumRiskSignal, isLowRiskSignal, RiskScoreStrategy, getCalculator, maxConfidenceCalculator, severityPlusVolumeCalculator, weightedByTypeCalculator, defaultWeightedByTypeCalculator, DEFAULT_TYPE_WEIGHTS } from './isl/index.js';
|
|
21
|
+
export type { RiskScore, ISLSegment, ISLResult, ISLSignal, ISLSignalMetadata, EmitSignalOptions, RiskScoreCalculator, PiDetection, PiDetectionResult, Pattern, SanitizeOptions } from './isl/index.js';
|
|
22
22
|
export { createPiDetection, getDetectionLength, isHighConfidence, isMediumConfidence, isLowConfidence, createPiDetectionResult, hasDetections, getDetectionCount, getDetectionsByType, getHighestConfidenceDetection, createPattern, matchesPattern, findMatch, MAX_CONTENT_LENGTH, MAX_PATTERN_LENGTH, MAX_MATCHES, createRiskScore, normalizeRiskScore, isHighRiskScore, isMediumRiskScore, isLowRiskScore, MIN_RISK_SCORE, MAX_RISK_SCORE, SanitizationError } from './isl/index.js';
|
|
23
|
-
export { addLineageEntry, addLineageEntries, filterLineageByStep, getLastLineageEntry, formatLineageForAudit, formatCSLForAudit, formatISLForAudit, formatISLSignalForAudit, formatAALForAudit, formatCPEForAudit, formatPipelineAudit } from './shared/index.js';
|
|
24
|
-
export type { LineageEntryLike, CSLResultLike, ISLResultLike, ISLSignalLike, DecisionReasonLike,
|
|
25
|
-
export { envelope, createNonce, isValidNonce, equalsNonce, createMetadata, isValidMetadata, CURRENT_PROTOCOL_VERSION, createSignature, EnvelopeError } from './
|
|
26
|
-
export type { Nonce, SignatureVO, ProtocolVersion, Timestamp, NonceValue, SignatureAlgorithm, Signature, CPEMetadata, CPEEvelope, CPEResult } from './
|
|
27
|
-
export { createAnomalyScore, isHighRisk, isLowRisk, isWarnRisk, isRoleProtected, isContextLeakPreventionEnabled, isInstructionImmutable, isIntentBlocked, isScopeSensitive, resolveAgentAction, resolveAgentActionWithScore, buildDecisionReason,
|
|
28
|
-
export type { AnomalyAction, AnomalyScore,
|
|
23
|
+
export { addLineageEntry, addLineageEntries, filterLineageByStep, getLastLineageEntry, formatLineageForAudit, formatCSLForAudit, formatISLForAudit, formatISLSignalForAudit, formatAALForAudit, formatCPEForAudit, formatPipelineAudit, formatPipelineAuditFull, formatPipelineAuditAsJson, createAuditRunId, buildAuditLogEntry, buildFullAuditPayload } from './shared/index.js';
|
|
24
|
+
export type { LineageEntryLike, CSLResultLike, ISLResultLike, ISLSignalLike, DecisionReasonLike, RemediationPlanLike, CPEResultLike, AuditRunInfo, AuditLogSummary, FullPipelineAuditOptions, PipelineAuditJsonOptions } from './shared/index.js';
|
|
25
|
+
export { envelope, createNonce, isValidNonce, equalsNonce, createMetadata, isValidMetadata, CURRENT_PROTOCOL_VERSION, createSignature, EnvelopeError } from './shared/envelope/index.js';
|
|
26
|
+
export type { Nonce, SignatureVO, ProtocolVersion, Timestamp, NonceValue, SignatureAlgorithm, Signature, CPEMetadata, CPEEvelope, CPEResult } from './shared/envelope/index.js';
|
|
27
|
+
export { createAnomalyScore, isHighRisk, isLowRisk, isWarnRisk, isRoleProtected, isContextLeakPreventionEnabled, isInstructionImmutable, isIntentBlocked, isScopeSensitive, resolveAgentAction, resolveAgentActionWithScore, buildDecisionReason, buildRemediationPlan, validateAgentPolicyThresholds, buildAALLineage, ACTION_DISPLAY_COLORS, getActionDisplayColor } from './AAL/index.js';
|
|
28
|
+
export type { AnomalyAction, AnomalyScore, RemediationPlan, BlockedIntent, SensitiveScope, ProtectedRole, ImmutableInstruction, AgentPolicy, DecisionReason, } from './AAL/index.js';
|
|
29
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AACvB,YAAY,EACV,aAAa,EACb,MAAM,EACN,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,YAAY,EACZ,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAGvB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AACvB,YAAY,EACV,aAAa,EACb,MAAM,EACN,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,YAAY,EACZ,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,oBAAoB,EACrB,MAAM,gBAAgB,CAAA;AACvB,YAAY,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,6BAA6B,EAC7B,aAAa,EACb,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,iBAAiB,EAClB,M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|
7
7
|
* You can import from specific layers:
|
|
8
8
|
* - import { segment } from '@ai-pip/core/csl'
|
|
9
9
|
* - import { sanitize } from '@ai-pip/core/isl'
|
|
10
|
-
* - import { envelope } from '@ai-pip/core/cpe'
|
|
10
|
+
* - import { envelope } from '@ai-pip/core/cpe' (re-exported from shared/envelope)
|
|
11
11
|
* - import { createAnomalyScore } from '@ai-pip/core/AAL'
|
|
12
12
|
*
|
|
13
13
|
* Or import everything from the main entry point:
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
// Re-export CSL
|
|
19
19
|
export { segment, classifySource, classifyOrigin, initLineage, createLineageEntry, generateId, splitByContextRules, OriginType, TrustLevelType, ClassificationError, SegmentationError } from './csl/index.js';
|
|
20
20
|
// Re-export ISL
|
|
21
|
-
export { sanitize, emitSignal, createISLSignal, isHighRiskSignal, isMediumRiskSignal, isLowRiskSignal } from './isl/index.js';
|
|
21
|
+
export { sanitize, emitSignal, createISLSignal, isHighRiskSignal, isMediumRiskSignal, isLowRiskSignal, RiskScoreStrategy, getCalculator, maxConfidenceCalculator, severityPlusVolumeCalculator, weightedByTypeCalculator, defaultWeightedByTypeCalculator, DEFAULT_TYPE_WEIGHTS } from './isl/index.js';
|
|
22
22
|
export { createPiDetection, getDetectionLength, isHighConfidence, isMediumConfidence, isLowConfidence, createPiDetectionResult, hasDetections, getDetectionCount, getDetectionsByType, getHighestConfidenceDetection, createPattern, matchesPattern, findMatch, MAX_CONTENT_LENGTH, MAX_PATTERN_LENGTH, MAX_MATCHES, createRiskScore, normalizeRiskScore, isHighRiskScore, isMediumRiskScore, isLowRiskScore, MIN_RISK_SCORE, MAX_RISK_SCORE, SanitizationError } from './isl/index.js';
|
|
23
23
|
// Re-export Shared
|
|
24
|
-
export { addLineageEntry, addLineageEntries, filterLineageByStep, getLastLineageEntry, formatLineageForAudit, formatCSLForAudit, formatISLForAudit, formatISLSignalForAudit, formatAALForAudit, formatCPEForAudit, formatPipelineAudit } from './shared/index.js';
|
|
25
|
-
// Re-export
|
|
26
|
-
export { envelope, createNonce, isValidNonce, equalsNonce, createMetadata, isValidMetadata, CURRENT_PROTOCOL_VERSION, createSignature, EnvelopeError } from './
|
|
24
|
+
export { addLineageEntry, addLineageEntries, filterLineageByStep, getLastLineageEntry, formatLineageForAudit, formatCSLForAudit, formatISLForAudit, formatISLSignalForAudit, formatAALForAudit, formatCPEForAudit, formatPipelineAudit, formatPipelineAuditFull, formatPipelineAuditAsJson, createAuditRunId, buildAuditLogEntry, buildFullAuditPayload } from './shared/index.js';
|
|
25
|
+
// Re-export envelope (transversal, from shared – no longer a layer)
|
|
26
|
+
export { envelope, createNonce, isValidNonce, equalsNonce, createMetadata, isValidMetadata, CURRENT_PROTOCOL_VERSION, createSignature, EnvelopeError } from './shared/envelope/index.js';
|
|
27
27
|
// Re-export AAL
|
|
28
|
-
export { createAnomalyScore, isHighRisk, isLowRisk, isWarnRisk, isRoleProtected, isContextLeakPreventionEnabled, isInstructionImmutable, isIntentBlocked, isScopeSensitive, resolveAgentAction, resolveAgentActionWithScore, buildDecisionReason,
|
|
28
|
+
export { createAnomalyScore, isHighRisk, isLowRisk, isWarnRisk, isRoleProtected, isContextLeakPreventionEnabled, isInstructionImmutable, isIntentBlocked, isScopeSensitive, resolveAgentAction, resolveAgentActionWithScore, buildDecisionReason, buildRemediationPlan, validateAgentPolicyThresholds, buildAALLineage, ACTION_DISPLAY_COLORS, getActionDisplayColor } from './AAL/index.js';
|
|
29
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,gBAAgB;AAChB,OAAO,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AAavB,gBAAgB;AAChB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,gBAAgB;AAChB,OAAO,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AAavB,gBAAgB;AAChB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,oBAAoB,EACrB,MAAM,gBAAgB,CAAA;AAcvB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,6BAA6B,EAC7B,aAAa,EACb,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AAEvB,mBAAmB;AACnB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,mBAAmB,CAAA;AAe1B,oEAAoE;AACpE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,wBAAwB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAIxL,gBAAgB;AAChB,OAAO,EACH,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,UAAU,EACV,eAAe,EACf,8BAA8B,EAC9B,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACxB,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISL threat detection - pure, deterministic, single source of truth.
|
|
3
|
+
*
|
|
4
|
+
* Runs pattern-based detection on content and returns PiDetection[].
|
|
5
|
+
* No duplication: reuses Pattern, findAllMatches, createPiDetection.
|
|
6
|
+
* Same input → same output; bounded by MAX_TOTAL_DETECTIONS and per-pattern cap.
|
|
7
|
+
*/
|
|
8
|
+
import type { Pattern } from '../value-objects/Pattern.js';
|
|
9
|
+
import type { PiDetection } from '../value-objects/PiDetection.js';
|
|
10
|
+
/** Threat pattern type identifiers (deterministic taxonomy) */
|
|
11
|
+
export declare const THREAT_TYPES: {
|
|
12
|
+
readonly PROMPT_INJECTION: "prompt-injection";
|
|
13
|
+
readonly JAILBREAK: "jailbreak";
|
|
14
|
+
readonly ROLE_HIJACKING: "role_hijacking";
|
|
15
|
+
readonly SCRIPT_LIKE: "script_like";
|
|
16
|
+
readonly HIDDEN_TEXT: "hidden_text";
|
|
17
|
+
};
|
|
18
|
+
export type ThreatType = (typeof THREAT_TYPES)[keyof typeof THREAT_TYPES];
|
|
19
|
+
/** Returns default threat patterns (cached, frozen). */
|
|
20
|
+
export declare function getDefaultThreatPatterns(): readonly Pattern[];
|
|
21
|
+
export interface DetectThreatsOptions {
|
|
22
|
+
/** Max total detections to return (default: MAX_TOTAL_DETECTIONS) */
|
|
23
|
+
maxTotal?: number;
|
|
24
|
+
/** Max matches per pattern (default: MAX_PER_PATTERN) */
|
|
25
|
+
maxPerPattern?: number;
|
|
26
|
+
/** Override patterns (default: getDefaultThreatPatterns()) */
|
|
27
|
+
patterns?: readonly Pattern[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Detects threats in content using the configured patterns.
|
|
31
|
+
* Pure, deterministic: same content → same PiDetection[] (order preserved by pattern order then by match position).
|
|
32
|
+
* Bounded by maxTotal and maxPerPattern to avoid runaway.
|
|
33
|
+
*
|
|
34
|
+
* @param content - Segment or string to scan
|
|
35
|
+
* @param options - Optional caps and pattern override
|
|
36
|
+
* @returns Array of PiDetection (frozen); empty if none
|
|
37
|
+
*/
|
|
38
|
+
export declare function detectThreats(content: string, options?: DetectThreatsOptions): readonly PiDetection[];
|
|
39
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../src/isl/detect/detect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAQlE,+DAA+D;AAC/D,eAAO,MAAM,YAAY;;;;;;CAMf,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAA;AA0TzE,wDAAwD;AACxD,wBAAgB,wBAAwB,IAAI,SAAS,OAAO,EAAE,CAG7D;AAED,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAA;CAC9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,oBAAyB,GACjC,SAAS,WAAW,EAAE,CAsCxB"}
|