@ai-pip/core 0.1.7 → 0.2.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 +175 -1
- package/README.md +751 -22
- package/dist/AAL/index.d.ts +28 -0
- package/dist/AAL/index.d.ts.map +1 -0
- package/dist/AAL/index.js +28 -0
- package/dist/AAL/index.js.map +1 -0
- package/dist/AAL/lineage/buildAALLineage.d.ts +22 -0
- package/dist/AAL/lineage/buildAALLineage.d.ts.map +1 -0
- package/dist/AAL/lineage/buildAALLineage.js +26 -0
- package/dist/AAL/lineage/buildAALLineage.js.map +1 -0
- package/dist/AAL/lineage/index.d.ts +5 -0
- package/dist/AAL/lineage/index.d.ts.map +1 -0
- package/dist/AAL/lineage/index.js +5 -0
- package/dist/AAL/lineage/index.js.map +1 -0
- package/dist/AAL/process/buildDecisionReason.d.ts +36 -0
- package/dist/AAL/process/buildDecisionReason.d.ts.map +1 -0
- package/dist/AAL/process/buildDecisionReason.js +48 -0
- package/dist/AAL/process/buildDecisionReason.js.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts +32 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.js +50 -0
- package/dist/AAL/process/buildRemovalPlan.js.map +1 -0
- package/dist/AAL/process/index.d.ts +9 -0
- package/dist/AAL/process/index.d.ts.map +1 -0
- package/dist/AAL/process/index.js +7 -0
- package/dist/AAL/process/index.js.map +1 -0
- package/dist/AAL/process/resolveAgentAction.d.ts +31 -0
- package/dist/AAL/process/resolveAgentAction.d.ts.map +1 -0
- package/dist/AAL/process/resolveAgentAction.js +43 -0
- package/dist/AAL/process/resolveAgentAction.js.map +1 -0
- package/dist/AAL/types.d.ts +104 -0
- package/dist/AAL/types.d.ts.map +1 -0
- package/dist/AAL/types.js +2 -0
- package/dist/AAL/types.js.map +1 -0
- package/dist/{isl → AAL}/value-objects/AnomalyScore.d.ts +2 -1
- package/dist/AAL/value-objects/AnomalyScore.d.ts.map +1 -0
- package/dist/{isl → AAL}/value-objects/AnomalyScore.js.map +1 -1
- package/dist/{isl → AAL}/value-objects/PolicyRule.d.ts.map +1 -1
- package/dist/{isl → AAL}/value-objects/PolicyRule.js.map +1 -1
- package/dist/AAL/value-objects/index.d.ts +5 -0
- package/dist/AAL/value-objects/index.d.ts.map +1 -0
- package/dist/AAL/value-objects/index.js +3 -0
- package/dist/AAL/value-objects/index.js.map +1 -0
- package/dist/csl/classify.d.ts +2 -2
- package/dist/csl/classify.js +5 -5
- package/dist/csl/classify.js.map +1 -1
- package/dist/csl/value-objects/Origin-map.js +5 -5
- package/dist/csl/value-objects/Origin-map.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/isl/index.d.ts +15 -6
- package/dist/isl/index.d.ts.map +1 -1
- package/dist/isl/index.js +15 -5
- package/dist/isl/index.js.map +1 -1
- package/dist/isl/lineage/buildISLLineage.d.ts +22 -0
- package/dist/isl/lineage/buildISLLineage.d.ts.map +1 -0
- package/dist/isl/lineage/buildISLLineage.js +26 -0
- package/dist/isl/lineage/buildISLLineage.js.map +1 -0
- package/dist/isl/lineage/index.d.ts +5 -0
- package/dist/isl/lineage/index.d.ts.map +1 -0
- package/dist/isl/lineage/index.js +5 -0
- package/dist/isl/lineage/index.js.map +1 -0
- package/dist/isl/process/buildISLResult.d.ts +24 -0
- package/dist/isl/process/buildISLResult.d.ts.map +1 -0
- package/dist/isl/process/buildISLResult.js +38 -0
- package/dist/isl/process/buildISLResult.js.map +1 -0
- package/dist/isl/process/emitSignal.d.ts +23 -0
- package/dist/isl/process/emitSignal.d.ts.map +1 -0
- package/dist/isl/process/emitSignal.js +39 -0
- package/dist/isl/process/emitSignal.js.map +1 -0
- package/dist/isl/process/index.d.ts +6 -0
- package/dist/isl/process/index.d.ts.map +1 -0
- package/dist/isl/process/index.js +6 -0
- package/dist/isl/process/index.js.map +1 -0
- package/dist/isl/sanitize.d.ts +5 -5
- package/dist/isl/sanitize.d.ts.map +1 -1
- package/dist/isl/sanitize.js +24 -38
- package/dist/isl/sanitize.js.map +1 -1
- package/dist/isl/signals.d.ts +98 -0
- package/dist/isl/signals.d.ts.map +1 -0
- package/dist/isl/signals.js +92 -0
- package/dist/isl/signals.js.map +1 -0
- package/dist/isl/types.d.ts +4 -48
- package/dist/isl/types.d.ts.map +1 -1
- package/dist/isl/types.js +1 -1
- package/dist/isl/value-objects/PiDetection.d.ts +2 -1
- package/dist/isl/value-objects/PiDetection.d.ts.map +1 -1
- package/dist/isl/value-objects/PiDetectionResult.d.ts +2 -3
- package/dist/isl/value-objects/PiDetectionResult.d.ts.map +1 -1
- package/dist/isl/value-objects/PiDetectionResult.js +1 -27
- package/dist/isl/value-objects/PiDetectionResult.js.map +1 -1
- package/dist/isl/value-objects/RiskScore.d.ts +70 -0
- package/dist/isl/value-objects/RiskScore.d.ts.map +1 -0
- package/dist/isl/value-objects/RiskScore.js +85 -0
- package/dist/isl/value-objects/RiskScore.js.map +1 -0
- 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 -3
- package/dist/isl/value-objects/index.js.map +1 -1
- package/dist/shared/audit.d.ts +150 -0
- package/dist/shared/audit.d.ts.map +1 -0
- package/dist/shared/audit.js +173 -0
- package/dist/shared/audit.js.map +1 -0
- package/dist/shared/index.d.ts +5 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +5 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/types.d.ts +36 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +2 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +7 -2
- package/dist/isl/value-objects/AnomalyScore.d.ts.map +0 -1
- /package/dist/{isl → AAL}/value-objects/AnomalyScore.js +0 -0
- /package/dist/{isl → AAL}/value-objects/PolicyRule.d.ts +0 -0
- /package/dist/{isl → AAL}/value-objects/PolicyRule.js +0 -0
package/dist/isl/sanitize.js
CHANGED
|
@@ -1,57 +1,44 @@
|
|
|
1
|
-
import { createLineageEntry } from '../csl/value-objects/index.js';
|
|
2
|
-
import { addLineageEntry } from '../shared/lineage.js';
|
|
3
1
|
import { TrustLevelType } from '../csl/types.js';
|
|
2
|
+
import { buildISLLineage } from './lineage/buildISLLineage.js';
|
|
3
|
+
import { buildISLResult } from './process/buildISLResult.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Sanitizes content according to trust level - pure function
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* ISL
|
|
9
|
-
* - TC:
|
|
10
|
-
* - STC:
|
|
11
|
-
* - UC:
|
|
8
|
+
* ISL applies differentiated sanitization according to trust level:
|
|
9
|
+
* - TC: Minimal sanitization
|
|
10
|
+
* - STC: Moderate sanitization
|
|
11
|
+
* - UC: Aggressive sanitization
|
|
12
12
|
*/
|
|
13
13
|
export function sanitize(cslResult) {
|
|
14
|
+
const startTime = Date.now();
|
|
14
15
|
const segments = [];
|
|
15
|
-
let allLineage = [...cslResult.lineage];
|
|
16
|
-
const blockedCount = 0;
|
|
17
|
-
let instructionsRemovedCount = 0;
|
|
18
16
|
for (const cslSegment of cslResult.segments) {
|
|
19
|
-
//
|
|
17
|
+
// Determine sanitization level according to trust level
|
|
20
18
|
const sanitizationLevel = getSanitizationLevel(cslSegment.trust);
|
|
21
|
-
//
|
|
19
|
+
// Sanitize content according to level
|
|
22
20
|
const sanitized = sanitizeContent(cslSegment.content, sanitizationLevel);
|
|
23
|
-
//
|
|
24
|
-
const
|
|
25
|
-
//
|
|
21
|
+
// Build ISL lineage for this segment
|
|
22
|
+
const segmentLineage = buildISLLineage(cslSegment.lineage, startTime);
|
|
23
|
+
// Create sanitized segment
|
|
26
24
|
const islSegment = {
|
|
27
25
|
id: cslSegment.id,
|
|
28
|
-
originalContent: cslSegment.content, // ✅
|
|
26
|
+
originalContent: cslSegment.content, // ✅ Preserve original
|
|
29
27
|
sanitizedContent: sanitized.content,
|
|
30
28
|
trust: cslSegment.trust,
|
|
31
|
-
lineage:
|
|
32
|
-
instructionsRemoved: removedInstructions,
|
|
29
|
+
lineage: [...segmentLineage], // Convert readonly to mutable for segment
|
|
33
30
|
sanitizationLevel
|
|
34
31
|
};
|
|
35
32
|
segments.push(islSegment);
|
|
36
|
-
const lastLineageEntry = islSegment.lineage.at(-1);
|
|
37
|
-
if (lastLineageEntry) {
|
|
38
|
-
allLineage = addLineageEntry(allLineage, lastLineageEntry);
|
|
39
|
-
}
|
|
40
|
-
instructionsRemovedCount += removedInstructions.length;
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
sanitizedSegments: segments.length,
|
|
48
|
-
blockedSegments: blockedCount,
|
|
49
|
-
instructionsRemoved: instructionsRemovedCount
|
|
50
|
-
}
|
|
51
|
-
};
|
|
34
|
+
// Build complete lineage
|
|
35
|
+
const allLineage = buildISLLineage(cslResult.lineage, startTime);
|
|
36
|
+
// Build result using process function
|
|
37
|
+
const processingTime = Date.now() - startTime;
|
|
38
|
+
return buildISLResult(segments, allLineage, processingTime);
|
|
52
39
|
}
|
|
53
40
|
/**
|
|
54
|
-
*
|
|
41
|
+
* Determines sanitization level according to trust level - pure function
|
|
55
42
|
*/
|
|
56
43
|
function getSanitizationLevel(trust) {
|
|
57
44
|
if (trust.value === TrustLevelType.TC)
|
|
@@ -61,14 +48,13 @@ function getSanitizationLevel(trust) {
|
|
|
61
48
|
return 'aggressive'; // UC
|
|
62
49
|
}
|
|
63
50
|
/**
|
|
64
|
-
*
|
|
51
|
+
* Sanitizes content according to level - pure function
|
|
65
52
|
*/
|
|
66
53
|
function sanitizeContent(content, _level) {
|
|
67
|
-
//
|
|
68
|
-
//
|
|
54
|
+
// For now returns content unchanged
|
|
55
|
+
// Real sanitization logic will be implemented later
|
|
69
56
|
return {
|
|
70
57
|
content,
|
|
71
|
-
removed: []
|
|
72
58
|
};
|
|
73
59
|
}
|
|
74
60
|
//# sourceMappingURL=sanitize.js.map
|
package/dist/isl/sanitize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../../src/isl/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../../src/isl/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAoB;IAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAiB,EAAE,CAAA;IAGjC,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC5C,wDAAwD;QACxD,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAEhE,sCAAsC;QACtC,MAAM,SAAS,GAAG,eAAe,CAC/B,UAAU,CAAC,OAAO,EAClB,iBAAiB,CAClB,CAAA;QAED,qCAAqC;QACrC,MAAM,cAAc,GAAG,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QAErE,2BAA2B;QAC3B,MAAM,UAAU,GAAe;YAC7B,EAAE,EAAE,UAAU,CAAC,EAAE;YACjB,eAAe,EAAE,UAAU,CAAC,OAAO,EAAG,sBAAsB;YAC5D,gBAAgB,EAAE,SAAS,CAAC,OAAO;YACnC,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,OAAO,EAAE,CAAC,GAAG,cAAc,CAAC,EAAE,0CAA0C;YACxE,iBAAiB;SAClB,CAAA;QAED,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC3B,CAAC;IAED,yBAAyB;IACzB,MAAM,UAAU,GAAG,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAEhE,sCAAsC;IACtC,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;IAC7C,OAAO,cAAc,CAAC,QAAQ,EAAE,UAAU,EAAE,cAAc,CAAC,CAAA;AAC7D,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,KAAiB;IAC7C,IAAI,KAAK,CAAC,KAAK,KAAK,cAAc,CAAC,EAAE;QAAE,OAAO,SAAS,CAAA;IACvD,IAAI,KAAK,CAAC,KAAK,KAAK,cAAc,CAAC,GAAG;QAAE,OAAO,UAAU,CAAA;IACzD,OAAO,YAAY,CAAA,CAAE,KAAK;AAC5B,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CACtB,OAAe,EACf,MAA6C;IAE7C,oCAAoC;IACpC,oDAAoD;IACpD,OAAO;QACL,OAAO;KACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISLSignal - Semantic contract between layers
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* ISLSignal is the external signal that ISL emits to be consumed by other layers.
|
|
6
|
+
*
|
|
7
|
+
* **Purpose:**
|
|
8
|
+
* - Semantic contract between layers (AAL, SDK, Engine)
|
|
9
|
+
* - Does not expose ISL internals
|
|
10
|
+
* - Designed for external consumption without coupling
|
|
11
|
+
*
|
|
12
|
+
* **Difference with ISLResult:**
|
|
13
|
+
* - ISLResult: Internal result of ISL pipeline (segments, lineage, complete metadata)
|
|
14
|
+
* - ISLSignal: External semantic signal (risk scores, detections, security signals)
|
|
15
|
+
*
|
|
16
|
+
* **Architectural rule:**
|
|
17
|
+
* A layer should never consume the internal "result" of another layer.
|
|
18
|
+
* It consumes a signal.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // ISL processes and emits signal
|
|
23
|
+
* const islResult = ISL.process(cslResult) // Internal
|
|
24
|
+
* const islSignal = ISL.emitSignal(islResult) // External → AAL
|
|
25
|
+
*
|
|
26
|
+
* // AAL consumes the signal, not the result
|
|
27
|
+
* const aalDecision = AAL.resolve(islSignal, policy)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { RiskScore } from './value-objects/RiskScore.js';
|
|
31
|
+
import type { PiDetectionResult } from './value-objects/PiDetectionResult.js';
|
|
32
|
+
/**
|
|
33
|
+
* ISLSignal - Semantic signal emitted by ISL
|
|
34
|
+
*
|
|
35
|
+
* Represents the essential information that other layers need
|
|
36
|
+
* to make decisions without knowing ISL's internal details.
|
|
37
|
+
*/
|
|
38
|
+
export interface ISLSignal {
|
|
39
|
+
/**
|
|
40
|
+
* Aggregated risk score of the processed content.
|
|
41
|
+
* Range: 0.0 (no risk) to 1.0 (maximum risk)
|
|
42
|
+
*/
|
|
43
|
+
readonly riskScore: RiskScore;
|
|
44
|
+
/**
|
|
45
|
+
* Prompt injection detection result.
|
|
46
|
+
* Contains all detected threats and their aggregated score.
|
|
47
|
+
*/
|
|
48
|
+
readonly piDetection: PiDetectionResult;
|
|
49
|
+
/**
|
|
50
|
+
* Indicates whether threats were detected in the content.
|
|
51
|
+
* Semantic shortcut for quick verification.
|
|
52
|
+
*/
|
|
53
|
+
readonly hasThreats: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Timestamp of when the content was processed.
|
|
56
|
+
* Useful for auditing and traceability.
|
|
57
|
+
*/
|
|
58
|
+
readonly timestamp: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates an ISLSignal from an internal ISLResult
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* This function extracts the essential semantic information from the internal result
|
|
65
|
+
* to create a signal that can be consumed by other layers without coupling.
|
|
66
|
+
*
|
|
67
|
+
* @param riskScore - Risk score value
|
|
68
|
+
* @param piDetection - Prompt injection detection result
|
|
69
|
+
* @param timestamp - Timestamp of the signal (default: Date.now())
|
|
70
|
+
* @returns ISLSignal - Semantic signal for external consumption
|
|
71
|
+
*/
|
|
72
|
+
export declare function createISLSignal(riskScore: RiskScore, piDetection: PiDetectionResult, timestamp?: number): ISLSignal;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if the signal indicates high risk
|
|
75
|
+
*
|
|
76
|
+
* @param signal - ISLSignal to evaluate
|
|
77
|
+
* @param threshold - Risk threshold (default: 0.7)
|
|
78
|
+
* @returns true if the risk score exceeds the threshold
|
|
79
|
+
*/
|
|
80
|
+
export declare function isHighRiskSignal(signal: ISLSignal, threshold?: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the signal indicates medium risk
|
|
83
|
+
*
|
|
84
|
+
* @param signal - ISLSignal to evaluate
|
|
85
|
+
* @param lowThreshold - Lower threshold (default: 0.3)
|
|
86
|
+
* @param highThreshold - Upper threshold (default: 0.7)
|
|
87
|
+
* @returns true if the risk score is in the medium range
|
|
88
|
+
*/
|
|
89
|
+
export declare function isMediumRiskSignal(signal: ISLSignal, lowThreshold?: number, highThreshold?: number): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the signal indicates low risk
|
|
92
|
+
*
|
|
93
|
+
* @param signal - ISLSignal to evaluate
|
|
94
|
+
* @param threshold - Risk threshold (default: 0.3)
|
|
95
|
+
* @returns true if the risk score is below the threshold
|
|
96
|
+
*/
|
|
97
|
+
export declare function isLowRiskSignal(signal: ISLSignal, threshold?: number): boolean;
|
|
98
|
+
//# sourceMappingURL=signals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/isl/signals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAE7E;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAE7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IAEvC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAE5B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,GAAE,MAAmB,GAC7B,SAAS,CAqBX;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,GAAE,MAAY,GAAG,OAAO,CAEpF;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EACjB,YAAY,GAAE,MAAY,EAC1B,aAAa,GAAE,MAAY,GAC1B,OAAO,CAET;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,GAAE,MAAY,GAAG,OAAO,CAEnF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISLSignal - Semantic contract between layers
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* ISLSignal is the external signal that ISL emits to be consumed by other layers.
|
|
6
|
+
*
|
|
7
|
+
* **Purpose:**
|
|
8
|
+
* - Semantic contract between layers (AAL, SDK, Engine)
|
|
9
|
+
* - Does not expose ISL internals
|
|
10
|
+
* - Designed for external consumption without coupling
|
|
11
|
+
*
|
|
12
|
+
* **Difference with ISLResult:**
|
|
13
|
+
* - ISLResult: Internal result of ISL pipeline (segments, lineage, complete metadata)
|
|
14
|
+
* - ISLSignal: External semantic signal (risk scores, detections, security signals)
|
|
15
|
+
*
|
|
16
|
+
* **Architectural rule:**
|
|
17
|
+
* A layer should never consume the internal "result" of another layer.
|
|
18
|
+
* It consumes a signal.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // ISL processes and emits signal
|
|
23
|
+
* const islResult = ISL.process(cslResult) // Internal
|
|
24
|
+
* const islSignal = ISL.emitSignal(islResult) // External → AAL
|
|
25
|
+
*
|
|
26
|
+
* // AAL consumes the signal, not the result
|
|
27
|
+
* const aalDecision = AAL.resolve(islSignal, policy)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Creates an ISLSignal from an internal ISLResult
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* This function extracts the essential semantic information from the internal result
|
|
35
|
+
* to create a signal that can be consumed by other layers without coupling.
|
|
36
|
+
*
|
|
37
|
+
* @param riskScore - Risk score value
|
|
38
|
+
* @param piDetection - Prompt injection detection result
|
|
39
|
+
* @param timestamp - Timestamp of the signal (default: Date.now())
|
|
40
|
+
* @returns ISLSignal - Semantic signal for external consumption
|
|
41
|
+
*/
|
|
42
|
+
export function createISLSignal(riskScore, piDetection, timestamp = Date.now()) {
|
|
43
|
+
// Validar riskScore
|
|
44
|
+
if (typeof riskScore !== 'number' || !Number.isFinite(riskScore)) {
|
|
45
|
+
throw new TypeError('ISLSignal riskScore must be a valid number');
|
|
46
|
+
}
|
|
47
|
+
if (riskScore < 0 || riskScore > 1) {
|
|
48
|
+
throw new Error('ISLSignal riskScore must be between 0 and 1');
|
|
49
|
+
}
|
|
50
|
+
// Validar timestamp
|
|
51
|
+
if (typeof timestamp !== 'number' || !Number.isFinite(timestamp) || timestamp < 0) {
|
|
52
|
+
throw new Error('ISLSignal timestamp must be a valid non-negative number');
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
riskScore,
|
|
56
|
+
piDetection,
|
|
57
|
+
hasThreats: piDetection.detected,
|
|
58
|
+
timestamp
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the signal indicates high risk
|
|
63
|
+
*
|
|
64
|
+
* @param signal - ISLSignal to evaluate
|
|
65
|
+
* @param threshold - Risk threshold (default: 0.7)
|
|
66
|
+
* @returns true if the risk score exceeds the threshold
|
|
67
|
+
*/
|
|
68
|
+
export function isHighRiskSignal(signal, threshold = 0.7) {
|
|
69
|
+
return signal.riskScore >= threshold;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the signal indicates medium risk
|
|
73
|
+
*
|
|
74
|
+
* @param signal - ISLSignal to evaluate
|
|
75
|
+
* @param lowThreshold - Lower threshold (default: 0.3)
|
|
76
|
+
* @param highThreshold - Upper threshold (default: 0.7)
|
|
77
|
+
* @returns true if the risk score is in the medium range
|
|
78
|
+
*/
|
|
79
|
+
export function isMediumRiskSignal(signal, lowThreshold = 0.3, highThreshold = 0.7) {
|
|
80
|
+
return signal.riskScore >= lowThreshold && signal.riskScore < highThreshold;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks if the signal indicates low risk
|
|
84
|
+
*
|
|
85
|
+
* @param signal - ISLSignal to evaluate
|
|
86
|
+
* @param threshold - Risk threshold (default: 0.3)
|
|
87
|
+
* @returns true if the risk score is below the threshold
|
|
88
|
+
*/
|
|
89
|
+
export function isLowRiskSignal(signal, threshold = 0.3) {
|
|
90
|
+
return signal.riskScore < threshold;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=signals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.js","sourceRoot":"","sources":["../../src/isl/signals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAqCH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAoB,EACpB,WAA8B,EAC9B,YAAoB,IAAI,CAAC,GAAG,EAAE;IAE9B,oBAAoB;IACpB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAA;IACnE,CAAC;IAED,IAAI,SAAS,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IAED,oBAAoB;IACpB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClF,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;IAC5E,CAAC;IAED,OAAO;QACL,SAAS;QACT,WAAW;QACX,UAAU,EAAE,WAAW,CAAC,QAAQ;QAChC,SAAS;KACV,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,YAAoB,GAAG;IACzE,OAAO,MAAM,CAAC,SAAS,IAAI,SAAS,CAAA;AACtC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAiB,EACjB,eAAuB,GAAG,EAC1B,gBAAwB,GAAG;IAE3B,OAAO,MAAM,CAAC,SAAS,IAAI,YAAY,IAAI,MAAM,CAAC,SAAS,GAAG,aAAa,CAAA;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB,EAAE,YAAoB,GAAG;IACxE,OAAO,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;AACrC,CAAC"}
|
package/dist/isl/types.d.ts
CHANGED
|
@@ -1,51 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Types for ISL (Instruction Sanitization Layer) - Core
|
|
2
|
+
* Types for ISL (Instruction Sanitization Layer) - Semantic Core
|
|
3
3
|
*/
|
|
4
4
|
import type { LineageEntry, TrustLevel } from '../csl/value-objects/index.js';
|
|
5
5
|
import type { PiDetectionResult } from './value-objects/PiDetectionResult.js';
|
|
6
|
-
|
|
6
|
+
export type { RiskScore } from './value-objects/RiskScore.js';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
export type RiskScore = number;
|
|
11
|
-
/**
|
|
12
|
-
* AnomalyAction - Acción recomendada basada en análisis
|
|
13
|
-
*/
|
|
14
|
-
export type AnomalyAction = 'ALLOW' | 'WARN' | 'BLOCK';
|
|
15
|
-
/**
|
|
16
|
-
* Position - Posición de un patrón detectado en el contenido
|
|
17
|
-
*/
|
|
18
|
-
export type Position = {
|
|
19
|
-
readonly start: number;
|
|
20
|
-
readonly end: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* BlockedIntent - Intent que está explícitamente bloqueado por política
|
|
24
|
-
*/
|
|
25
|
-
export type BlockedIntent = string;
|
|
26
|
-
/**
|
|
27
|
-
* SensitiveScope - Tema sensible que requiere validación adicional
|
|
28
|
-
*/
|
|
29
|
-
export type SensitiveScope = string;
|
|
30
|
-
/**
|
|
31
|
-
* ProtectedRole - Rol que no puede ser sobrescrito
|
|
32
|
-
*/
|
|
33
|
-
export type ProtectedRole = string;
|
|
34
|
-
/**
|
|
35
|
-
* ImmutableInstruction - Instrucción que no puede ser modificada
|
|
36
|
-
*/
|
|
37
|
-
export type ImmutableInstruction = string;
|
|
38
|
-
/**
|
|
39
|
-
* RemovedInstruction - Instrucción removida durante sanitización
|
|
40
|
-
*/
|
|
41
|
-
export interface RemovedInstruction {
|
|
42
|
-
readonly type: 'system_command' | 'role_swapping' | 'jailbreak' | 'override' | 'manipulation';
|
|
43
|
-
readonly pattern: string;
|
|
44
|
-
readonly position: Position;
|
|
45
|
-
readonly description: string;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* ISLSegment - Segmento sanitizado por ISL
|
|
8
|
+
* ISLSegment - Segment sanitized by ISL
|
|
49
9
|
*/
|
|
50
10
|
export interface ISLSegment {
|
|
51
11
|
readonly id: string;
|
|
@@ -54,12 +14,10 @@ export interface ISLSegment {
|
|
|
54
14
|
readonly trust: TrustLevel;
|
|
55
15
|
readonly lineage: LineageEntry[];
|
|
56
16
|
readonly piDetection?: PiDetectionResult;
|
|
57
|
-
readonly anomalyScore?: AnomalyScore;
|
|
58
|
-
readonly instructionsRemoved: RemovedInstruction[];
|
|
59
17
|
readonly sanitizationLevel: 'minimal' | 'moderate' | 'aggressive';
|
|
60
18
|
}
|
|
61
19
|
/**
|
|
62
|
-
* ISLResult -
|
|
20
|
+
* ISLResult - Sanitization result
|
|
63
21
|
*/
|
|
64
22
|
export interface ISLResult {
|
|
65
23
|
readonly segments: readonly ISLSegment[];
|
|
@@ -67,8 +25,6 @@ export interface ISLResult {
|
|
|
67
25
|
readonly metadata: {
|
|
68
26
|
readonly totalSegments: number;
|
|
69
27
|
readonly sanitizedSegments: number;
|
|
70
|
-
readonly blockedSegments: number;
|
|
71
|
-
readonly instructionsRemoved: number;
|
|
72
28
|
readonly processingTimeMs?: number;
|
|
73
29
|
};
|
|
74
30
|
}
|
package/dist/isl/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/isl/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/isl/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAG7E,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAU7D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,CAAA;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAA;IACxC,QAAQ,CAAC,iBAAiB,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,CAAA;CAClE;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAA;IACxC,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAA;IACzC,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;QAC9B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;QAClC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KACnC,CAAA;CACF"}
|
package/dist/isl/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiDetection.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"PiDetection.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAA;CAC/B,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,SAAS,GACpB,WAAW,CAmDb;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,CAEjE;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAEhE;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAElE;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAE/D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RiskScore } from './RiskScore.js';
|
|
2
2
|
import type { PiDetection } from './PiDetection.js';
|
|
3
3
|
/**
|
|
4
4
|
* PiDetectionResult - tipo puro
|
|
@@ -6,14 +6,13 @@ import type { PiDetection } from './PiDetection.js';
|
|
|
6
6
|
export type PiDetectionResult = {
|
|
7
7
|
readonly detections: readonly PiDetection[];
|
|
8
8
|
readonly score: RiskScore;
|
|
9
|
-
readonly action: AnomalyAction;
|
|
10
9
|
readonly patterns: readonly string[];
|
|
11
10
|
readonly detected: boolean;
|
|
12
11
|
};
|
|
13
12
|
/**
|
|
14
13
|
* Crea un PiDetectionResult - función pura
|
|
15
14
|
*/
|
|
16
|
-
export declare function createPiDetectionResult(detections: readonly PiDetection[]
|
|
15
|
+
export declare function createPiDetectionResult(detections: readonly PiDetection[]): PiDetectionResult;
|
|
17
16
|
/**
|
|
18
17
|
* Funciones puras para PiDetectionResult
|
|
19
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiDetectionResult.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetectionResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"PiDetectionResult.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetectionResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,UAAU,EAAE,SAAS,WAAW,EAAE,CAAA;IAC3C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B,CAAA;AA2BD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,SAAS,WAAW,EAAE,GACjC,iBAAiB,CAsBnB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAEhE;AAKD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAEnE;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,MAAM,GACnB,SAAS,WAAW,EAAE,CAExB;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,iBAAiB,GACxB,WAAW,GAAG,SAAS,CAQzB"}
|
|
@@ -19,47 +19,21 @@ function calculateAggregatedScore(detections) {
|
|
|
19
19
|
const aggregatedScore = 1 - complementaryProduct;
|
|
20
20
|
return Math.max(0, Math.min(1, aggregatedScore));
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Determina acción basada en score - función pura
|
|
24
|
-
*/
|
|
25
|
-
function determineActionFromScore(score) {
|
|
26
|
-
if (score >= 0.7) {
|
|
27
|
-
return 'BLOCK';
|
|
28
|
-
}
|
|
29
|
-
else if (score >= 0.3) {
|
|
30
|
-
return 'WARN';
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return 'ALLOW';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
22
|
/**
|
|
37
23
|
* Crea un PiDetectionResult - función pura
|
|
38
24
|
*/
|
|
39
|
-
export function createPiDetectionResult(detections
|
|
25
|
+
export function createPiDetectionResult(detections) {
|
|
40
26
|
// Validar detections array
|
|
41
27
|
if (!Array.isArray(detections)) {
|
|
42
28
|
throw new TypeError('PiDetectionResult detections must be an array');
|
|
43
29
|
}
|
|
44
30
|
// Calcular score agregado
|
|
45
31
|
const score = calculateAggregatedScore(detections);
|
|
46
|
-
// Determinar acción (o usar la proporcionada)
|
|
47
|
-
const finalAction = action ?? determineActionFromScore(score);
|
|
48
|
-
// Validar acción
|
|
49
|
-
if (!['ALLOW', 'WARN', 'BLOCK'].includes(finalAction)) {
|
|
50
|
-
throw new Error(`Invalid AnomalyAction: ${finalAction}. Must be one of: ALLOW, WARN, BLOCK`);
|
|
51
|
-
}
|
|
52
|
-
// Validar que la acción coincide con el score calculado
|
|
53
|
-
const expectedAction = determineActionFromScore(score);
|
|
54
|
-
if (finalAction !== expectedAction) {
|
|
55
|
-
throw new Error(`PiDetectionResult action mismatch. Calculated score ${score} requires action '${expectedAction}', but '${finalAction}' was provided`);
|
|
56
|
-
}
|
|
57
32
|
// Derivar patterns array
|
|
58
33
|
const patterns = detections.map((detection) => detection.pattern_type);
|
|
59
34
|
const result = {
|
|
60
35
|
detections: Object.freeze(Array.from(detections)),
|
|
61
36
|
score,
|
|
62
|
-
action: finalAction,
|
|
63
37
|
patterns: Object.freeze(Array.from(patterns)),
|
|
64
38
|
detected: detections.length > 0
|
|
65
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiDetectionResult.js","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetectionResult.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PiDetectionResult.js","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetectionResult.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,SAAS,wBAAwB,CAAC,UAAkC;IAClE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAA;IACV,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;QAC3B,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,CAAA;QACpB,OAAO,KAAK,CAAC,UAAU,CAAA;IACzB,CAAC;IAED,0DAA0D;IAC1D,IAAI,oBAAoB,GAAG,CAAC,CAAA;IAC5B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,oBAAoB,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAA;IACpD,CAAC;IAED,MAAM,eAAe,GAAG,CAAC,GAAG,oBAAoB,CAAA;IAChD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAA;AAClD,CAAC;AAGD;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,UAAkC;IAElC,2BAA2B;IAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAA;IACtE,CAAC;IAED,0BAA0B;IAC1B,MAAM,KAAK,GAAG,wBAAwB,CAAC,UAAU,CAAC,CAAA;IAIlD,yBAAyB;IACzB,MAAM,QAAQ,GAAsB,UAAU,CAAC,GAAG,CAAC,CAAC,SAAsB,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IAEtG,MAAM,MAAM,GAAsB;QAChC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAA2B;QAC3E,KAAK;QACL,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,QAAQ,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC;KAChC,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAyB;IACrD,OAAO,MAAM,CAAC,QAAQ,CAAA;AACxB,CAAC;AAED,+EAA+E;AAC/E,2EAA2E;AAE3E,MAAM,UAAU,iBAAiB,CAAC,MAAyB;IACzD,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,MAAyB,EACzB,YAAoB;IAEpB,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;AACvF,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,MAAyB;IAEzB,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IACpE,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RiskScore - Value Object
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Represents a normalized risk value produced by the core semantic layers.
|
|
6
|
+
*
|
|
7
|
+
* - Value range is **0.0 to 1.0**
|
|
8
|
+
* - `0` = no risk detected
|
|
9
|
+
* - `1` = maximum risk confidence
|
|
10
|
+
*
|
|
11
|
+
* Although this type aliases `number`, it is intentionally defined
|
|
12
|
+
* as a value object to preserve **semantic meaning**, enforce conceptual clarity,
|
|
13
|
+
* and stabilize public contracts across layers and SDKs.
|
|
14
|
+
*
|
|
15
|
+
* This type MUST NOT be interpreted as a decision signal.
|
|
16
|
+
* Decisions based on RiskScore belong to higher layers (AAL / SDK).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* RiskScore type - normalized risk value between 0.0 and 1.0
|
|
20
|
+
*/
|
|
21
|
+
export type RiskScore = number;
|
|
22
|
+
/**
|
|
23
|
+
* Minimum valid risk score value
|
|
24
|
+
*/
|
|
25
|
+
export declare const MIN_RISK_SCORE: RiskScore;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum valid risk score value
|
|
28
|
+
*/
|
|
29
|
+
export declare const MAX_RISK_SCORE: RiskScore;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a valid RiskScore value
|
|
32
|
+
*
|
|
33
|
+
* @param value - Numeric value to validate and normalize
|
|
34
|
+
* @returns Validated RiskScore
|
|
35
|
+
* @throws {Error} If value is outside valid range [0.0, 1.0]
|
|
36
|
+
*/
|
|
37
|
+
export declare function createRiskScore(value: number): RiskScore;
|
|
38
|
+
/**
|
|
39
|
+
* Normalizes a risk score to the valid range [0.0, 1.0]
|
|
40
|
+
*
|
|
41
|
+
* @param value - Numeric value to normalize
|
|
42
|
+
* @returns Normalized RiskScore clamped to [0.0, 1.0]
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeRiskScore(value: number): RiskScore;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a risk score is considered high
|
|
47
|
+
*
|
|
48
|
+
* @param score - RiskScore to evaluate
|
|
49
|
+
* @param threshold - Threshold for high risk (default: 0.7)
|
|
50
|
+
* @returns true if score >= threshold
|
|
51
|
+
*/
|
|
52
|
+
export declare function isHighRiskScore(score: RiskScore, threshold?: number): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a risk score is considered medium
|
|
55
|
+
*
|
|
56
|
+
* @param score - RiskScore to evaluate
|
|
57
|
+
* @param lowThreshold - Lower threshold (default: 0.3)
|
|
58
|
+
* @param highThreshold - Upper threshold (default: 0.7)
|
|
59
|
+
* @returns true if score is in medium range
|
|
60
|
+
*/
|
|
61
|
+
export declare function isMediumRiskScore(score: RiskScore, lowThreshold?: number, highThreshold?: number): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a risk score is considered low
|
|
64
|
+
*
|
|
65
|
+
* @param score - RiskScore to evaluate
|
|
66
|
+
* @param threshold - Threshold for low risk (default: 0.3)
|
|
67
|
+
* @returns true if score < threshold
|
|
68
|
+
*/
|
|
69
|
+
export declare function isLowRiskScore(score: RiskScore, threshold?: number): boolean;
|
|
70
|
+
//# sourceMappingURL=RiskScore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RiskScore.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/RiskScore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAAa,CAAA;AAE1C;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAAa,CAAA;AAE1C;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAYxD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAM3D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,GAAE,MAAY,GAAG,OAAO,CAElF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,MAAY,EAC1B,aAAa,GAAE,MAAY,GAC1B,OAAO,CAET;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,GAAE,MAAY,GAAG,OAAO,CAEjF"}
|