@ai-pip/core 0.1.8 → 0.3.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 +157 -2
- package/README.md +351 -11
- 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 +29 -0
- package/dist/AAL/index.d.ts.map +1 -0
- package/dist/AAL/index.js +30 -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/applyRemovalPlan.d.ts +21 -0
- package/dist/AAL/process/applyRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/applyRemovalPlan.js +150 -0
- package/dist/AAL/process/applyRemovalPlan.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 +70 -0
- package/dist/AAL/process/buildDecisionReason.js.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts +39 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.js +104 -0
- package/dist/AAL/process/buildRemovalPlan.js.map +1 -0
- package/dist/AAL/process/index.d.ts +10 -0
- package/dist/AAL/process/index.d.ts.map +1 -0
- package/dist/AAL/process/index.js +8 -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 +67 -0
- package/dist/AAL/process/resolveAgentAction.js.map +1 -0
- package/dist/AAL/types.d.ts +108 -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/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/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 +22 -6
- package/dist/isl/index.d.ts.map +1 -1
- package/dist/isl/index.js +20 -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 +32 -0
- package/dist/isl/process/emitSignal.d.ts.map +1 -0
- package/dist/isl/process/emitSignal.js +41 -0
- package/dist/isl/process/emitSignal.js.map +1 -0
- package/dist/isl/process/index.d.ts +7 -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/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 +13 -6
- package/dist/isl/sanitize.d.ts.map +1 -1
- package/dist/isl/sanitize.js +34 -40
- package/dist/isl/sanitize.js.map +1 -1
- package/dist/isl/signals.d.ts +113 -0
- package/dist/isl/signals.d.ts.map +1 -0
- package/dist/isl/signals.js +94 -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/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/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 +4 -4
- package/dist/isl/value-objects/index.d.ts.map +1 -1
- package/dist/isl/value-objects/index.js +2 -4
- package/dist/isl/value-objects/index.js.map +1 -1
- package/dist/shared/audit.d.ts +250 -0
- package/dist/shared/audit.d.ts.map +1 -0
- package/dist/shared/audit.js +455 -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 +12 -3
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/isl/lineage/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* buildISLResult - Builds the internal ISL result
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This function builds the internal ISLResult that contains
|
|
6
|
+
* all ISL processing information.
|
|
7
|
+
*
|
|
8
|
+
* **Responsibility:**
|
|
9
|
+
* - Build ISLResult from processed segments
|
|
10
|
+
* - Add processing metadata
|
|
11
|
+
* - Preserve complete lineage
|
|
12
|
+
*/
|
|
13
|
+
import type { ISLResult, ISLSegment } from '../types.js';
|
|
14
|
+
import type { LineageEntry } from '../../csl/value-objects/index.js';
|
|
15
|
+
/**
|
|
16
|
+
* Builds an ISLResult from processed segments
|
|
17
|
+
*
|
|
18
|
+
* @param segments - Segments sanitized by ISL
|
|
19
|
+
* @param lineage - Complete processing lineage
|
|
20
|
+
* @param processingTimeMs - Processing time in milliseconds (optional)
|
|
21
|
+
* @returns ISLResult with all processing information
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildISLResult(segments: readonly ISLSegment[], lineage: readonly LineageEntry[], processingTimeMs?: number): ISLResult;
|
|
24
|
+
//# sourceMappingURL=buildISLResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildISLResult.d.ts","sourceRoot":"","sources":["../../../src/isl/process/buildISLResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,SAAS,UAAU,EAAE,EAC/B,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,gBAAgB,CAAC,EAAE,MAAM,GACxB,SAAS,CAiBX"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* buildISLResult - Builds the internal ISL result
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This function builds the internal ISLResult that contains
|
|
6
|
+
* all ISL processing information.
|
|
7
|
+
*
|
|
8
|
+
* **Responsibility:**
|
|
9
|
+
* - Build ISLResult from processed segments
|
|
10
|
+
* - Add processing metadata
|
|
11
|
+
* - Preserve complete lineage
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Builds an ISLResult from processed segments
|
|
15
|
+
*
|
|
16
|
+
* @param segments - Segments sanitized by ISL
|
|
17
|
+
* @param lineage - Complete processing lineage
|
|
18
|
+
* @param processingTimeMs - Processing time in milliseconds (optional)
|
|
19
|
+
* @returns ISLResult with all processing information
|
|
20
|
+
*/
|
|
21
|
+
export function buildISLResult(segments, lineage, processingTimeMs) {
|
|
22
|
+
const metadata = processingTimeMs === undefined
|
|
23
|
+
? {
|
|
24
|
+
totalSegments: segments.length,
|
|
25
|
+
sanitizedSegments: segments.length
|
|
26
|
+
}
|
|
27
|
+
: {
|
|
28
|
+
totalSegments: segments.length,
|
|
29
|
+
sanitizedSegments: segments.length,
|
|
30
|
+
processingTimeMs
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
segments: Object.freeze(segments),
|
|
34
|
+
lineage: Object.freeze(lineage),
|
|
35
|
+
metadata: Object.freeze(metadata)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=buildISLResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildISLResult.js","sourceRoot":"","sources":["../../../src/isl/process/buildISLResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,QAA+B,EAC/B,OAAgC,EAChC,gBAAyB;IAEzB,MAAM,QAAQ,GAAG,gBAAgB,KAAK,SAAS;QAC7C,CAAC,CAAC;YACE,aAAa,EAAE,QAAQ,CAAC,MAAM;YAC9B,iBAAiB,EAAE,QAAQ,CAAC,MAAM;SACnC;QACH,CAAC,CAAC;YACE,aAAa,EAAE,QAAQ,CAAC,MAAM;YAC9B,iBAAiB,EAAE,QAAQ,CAAC,MAAM;YAClC,gBAAgB;SACjB,CAAA;IAEL,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;KAClC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emitSignal - Emits an ISLSignal from an internal ISLResult
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Converts ISLResult into a semantic signal (ISLSignal) for AAL/SDK.
|
|
6
|
+
* Aggregates all segment detections (from detectThreats → piDetection);
|
|
7
|
+
* hasThreats and riskScore are derived solely from that aggregation
|
|
8
|
+
* (no separate source of truth). Same ISLResult + same options → same ISLSignal (deterministic).
|
|
9
|
+
* Strategy is fixed at emit time; reflected in ISLSignal.metadata for auditability.
|
|
10
|
+
*/
|
|
11
|
+
import type { ISLResult } from '../types.js';
|
|
12
|
+
import type { ISLSignal } from '../signals.js';
|
|
13
|
+
import { RiskScoreStrategy } from '../riskScore/types.js';
|
|
14
|
+
/** Options for emitSignal. Strategy decided once; no per-segment or dynamic strategy. */
|
|
15
|
+
export interface EmitSignalOptions {
|
|
16
|
+
/** Signal timestamp (default: Date.now()) */
|
|
17
|
+
readonly timestamp?: number;
|
|
18
|
+
/** Risk score strategy and optional type weights (default: MAX_CONFIDENCE) */
|
|
19
|
+
readonly riskScore?: {
|
|
20
|
+
readonly strategy: RiskScoreStrategy;
|
|
21
|
+
readonly typeWeights?: Record<string, number>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Emits an ISLSignal from an internal ISLResult
|
|
26
|
+
*
|
|
27
|
+
* @param islResult - Internal ISL result
|
|
28
|
+
* @param options - Optional timestamp and risk score strategy (default: MAX_CONFIDENCE)
|
|
29
|
+
* @returns ISLSignal - Semantic signal for external consumption; metadata.strategy reflects strategy used
|
|
30
|
+
*/
|
|
31
|
+
export declare function emitSignal(islResult: ISLResult, options?: EmitSignalOptions | number): ISLSignal;
|
|
32
|
+
//# sourceMappingURL=emitSignal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitSignal.d.ts","sourceRoot":"","sources":["../../../src/isl/process/emitSignal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAI9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAGzD,yFAAyF;AACzF,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnB,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;QACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC9C,CAAA;CACF;AAID;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,SAAS,EACpB,OAAO,GAAE,iBAAiB,GAAG,MAAW,GACvC,SAAS,CAsBX"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emitSignal - Emits an ISLSignal from an internal ISLResult
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Converts ISLResult into a semantic signal (ISLSignal) for AAL/SDK.
|
|
6
|
+
* Aggregates all segment detections (from detectThreats → piDetection);
|
|
7
|
+
* hasThreats and riskScore are derived solely from that aggregation
|
|
8
|
+
* (no separate source of truth). Same ISLResult + same options → same ISLSignal (deterministic).
|
|
9
|
+
* Strategy is fixed at emit time; reflected in ISLSignal.metadata for auditability.
|
|
10
|
+
*/
|
|
11
|
+
import { createISLSignal } from '../signals.js';
|
|
12
|
+
import { createPiDetectionResult } from '../value-objects/PiDetectionResult.js';
|
|
13
|
+
import { MIN_RISK_SCORE, normalizeRiskScore } from '../value-objects/RiskScore.js';
|
|
14
|
+
import { RiskScoreStrategy } from '../riskScore/types.js';
|
|
15
|
+
import { getCalculator } from '../riskScore/index.js';
|
|
16
|
+
const DEFAULT_STRATEGY = RiskScoreStrategy.MAX_CONFIDENCE;
|
|
17
|
+
/**
|
|
18
|
+
* Emits an ISLSignal from an internal ISLResult
|
|
19
|
+
*
|
|
20
|
+
* @param islResult - Internal ISL result
|
|
21
|
+
* @param options - Optional timestamp and risk score strategy (default: MAX_CONFIDENCE)
|
|
22
|
+
* @returns ISLSignal - Semantic signal for external consumption; metadata.strategy reflects strategy used
|
|
23
|
+
*/
|
|
24
|
+
export function emitSignal(islResult, options = {}) {
|
|
25
|
+
const opts = typeof options === 'number' ? { timestamp: options } : options;
|
|
26
|
+
const timestamp = opts.timestamp ?? Date.now();
|
|
27
|
+
const strategy = opts.riskScore?.strategy ?? DEFAULT_STRATEGY;
|
|
28
|
+
const typeWeights = opts.riskScore?.typeWeights;
|
|
29
|
+
const allDetections = islResult.segments
|
|
30
|
+
.filter((s) => s.piDetection != null)
|
|
31
|
+
.flatMap(s => s.piDetection.detections);
|
|
32
|
+
const piDetection = createPiDetectionResult(allDetections);
|
|
33
|
+
const calculator = getCalculator(strategy, typeWeights);
|
|
34
|
+
const rawScore = calculator.calculate(allDetections);
|
|
35
|
+
const riskScore = allDetections.length === 0
|
|
36
|
+
? MIN_RISK_SCORE
|
|
37
|
+
: normalizeRiskScore(rawScore);
|
|
38
|
+
const metadata = Object.freeze({ strategy });
|
|
39
|
+
return createISLSignal(riskScore, piDetection, timestamp, metadata);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=emitSignal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitSignal.js","sourceRoot":"","sources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G,aAAa,CAAC,MAAM,KAAK,CAAC;QAC1C,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IAEhC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5C,OAAO,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/isl/process/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/isl/process/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk score calculators - pure, deterministic, no side effects.
|
|
3
|
+
* Only registered implementations; no custom inline strategies.
|
|
4
|
+
*/
|
|
5
|
+
import type { RiskScoreCalculator } from './types.js';
|
|
6
|
+
/** Max confidence among all detections. Simple default. */
|
|
7
|
+
export declare const maxConfidenceCalculator: RiskScoreCalculator;
|
|
8
|
+
/** Max confidence plus a small bump per extra detection (volume). Clamped by caller. */
|
|
9
|
+
export declare const severityPlusVolumeCalculator: RiskScoreCalculator;
|
|
10
|
+
/**
|
|
11
|
+
* Weighted by pattern_type. Weights default to 1 if type not present.
|
|
12
|
+
* Returns a registered calculator (no inline custom logic).
|
|
13
|
+
*/
|
|
14
|
+
export declare function weightedByTypeCalculator(weights: Record<string, number>): RiskScoreCalculator;
|
|
15
|
+
/** Default weights for WEIGHTED_BY_TYPE (all 1). Use for reproducible audits. */
|
|
16
|
+
export declare const DEFAULT_TYPE_WEIGHTS: Record<string, number>;
|
|
17
|
+
/** Pre-built weighted calculator with default weights. */
|
|
18
|
+
export declare const defaultWeightedByTypeCalculator: RiskScoreCalculator;
|
|
19
|
+
//# sourceMappingURL=calculators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculators.d.ts","sourceRoot":"","sources":["../../../src/isl/riskScore/calculators.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrD,2DAA2D;AAC3D,eAAO,MAAM,uBAAuB,EAAE,mBAMrC,CAAA;AAED,wFAAwF;AACxF,eAAO,MAAM,4BAA4B,EAAE,mBAO1C,CAAA;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,mBAAmB,CASrB;AAED,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMtD,CAAA;AAEF,0DAA0D;AAC1D,eAAO,MAAM,+BAA+B,EAAE,mBACS,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk score calculators - pure, deterministic, no side effects.
|
|
3
|
+
* Only registered implementations; no custom inline strategies.
|
|
4
|
+
*/
|
|
5
|
+
import { RiskScoreStrategy } from './types.js';
|
|
6
|
+
/** Max confidence among all detections. Simple default. */
|
|
7
|
+
export const maxConfidenceCalculator = {
|
|
8
|
+
strategy: RiskScoreStrategy.MAX_CONFIDENCE,
|
|
9
|
+
calculate(detections) {
|
|
10
|
+
if (detections.length === 0)
|
|
11
|
+
return 0;
|
|
12
|
+
return Math.max(...detections.map((d) => d.confidence));
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/** Max confidence plus a small bump per extra detection (volume). Clamped by caller. */
|
|
16
|
+
export const severityPlusVolumeCalculator = {
|
|
17
|
+
strategy: RiskScoreStrategy.SEVERITY_PLUS_VOLUME,
|
|
18
|
+
calculate(detections) {
|
|
19
|
+
if (detections.length === 0)
|
|
20
|
+
return 0;
|
|
21
|
+
const max = Math.max(...detections.map((d) => d.confidence));
|
|
22
|
+
return Math.min(1, max + 0.1 * (detections.length - 1));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Weighted by pattern_type. Weights default to 1 if type not present.
|
|
27
|
+
* Returns a registered calculator (no inline custom logic).
|
|
28
|
+
*/
|
|
29
|
+
export function weightedByTypeCalculator(weights) {
|
|
30
|
+
return {
|
|
31
|
+
strategy: RiskScoreStrategy.WEIGHTED_BY_TYPE,
|
|
32
|
+
calculate(detections) {
|
|
33
|
+
if (detections.length === 0)
|
|
34
|
+
return 0;
|
|
35
|
+
const w = (d) => d.confidence * (weights[d.pattern_type] ?? 1);
|
|
36
|
+
return Math.min(1, Math.max(...detections.map(w)));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Default weights for WEIGHTED_BY_TYPE (all 1). Use for reproducible audits. */
|
|
41
|
+
export const DEFAULT_TYPE_WEIGHTS = Object.freeze({
|
|
42
|
+
'prompt-injection': 1,
|
|
43
|
+
jailbreak: 1,
|
|
44
|
+
role_hijacking: 1,
|
|
45
|
+
script_like: 1,
|
|
46
|
+
hidden_text: 1
|
|
47
|
+
});
|
|
48
|
+
/** Pre-built weighted calculator with default weights. */
|
|
49
|
+
export const defaultWeightedByTypeCalculator = weightedByTypeCalculator({ ...DEFAULT_TYPE_WEIGHTS });
|
|
50
|
+
//# sourceMappingURL=calculators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculators.js","source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AAO,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;YAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACpD,CAAC;KACF,CAAA;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAA2B,MAAM,CAAC,MAAM,CAAC;IACxE,kBAAkB,EAAE,CAAC;IACrB,SAAS,EAAE,CAAC;IACZ,cAAc,EAAE,CAAC;IACjB,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;CACf,CAAC,CAAA;AAEF,0DAA0D;AAC1D,MAAM,CAAC,MAAM,+BAA+B,GAC1C,wBAAwB,CAAC,EAAE,GAAG,oBAAoB,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISL risk score strategy - registered calculators only.
|
|
3
|
+
*/
|
|
4
|
+
export { RiskScoreStrategy } from './types.js';
|
|
5
|
+
export type { RiskScoreCalculator } from './types.js';
|
|
6
|
+
export { maxConfidenceCalculator, severityPlusVolumeCalculator, weightedByTypeCalculator, defaultWeightedByTypeCalculator, DEFAULT_TYPE_WEIGHTS } from './calculators.js';
|
|
7
|
+
import { RiskScoreStrategy } from './types.js';
|
|
8
|
+
import type { RiskScoreCalculator } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Returns the registered calculator for the given strategy.
|
|
11
|
+
* For WEIGHTED_BY_TYPE without custom weights, uses default weights.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCalculator(strategy: RiskScoreStrategy, typeWeights?: Record<string, number>): RiskScoreCalculator;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/isl/riskScore/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAQrD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,mBAAmB,CAarB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISL risk score strategy - registered calculators only.
|
|
3
|
+
*/
|
|
4
|
+
export { RiskScoreStrategy } from './types.js';
|
|
5
|
+
export { maxConfidenceCalculator, severityPlusVolumeCalculator, weightedByTypeCalculator, defaultWeightedByTypeCalculator, DEFAULT_TYPE_WEIGHTS } from './calculators.js';
|
|
6
|
+
import { RiskScoreStrategy } from './types.js';
|
|
7
|
+
import { defaultWeightedByTypeCalculator, maxConfidenceCalculator, severityPlusVolumeCalculator, weightedByTypeCalculator } from './calculators.js';
|
|
8
|
+
/**
|
|
9
|
+
* Returns the registered calculator for the given strategy.
|
|
10
|
+
* For WEIGHTED_BY_TYPE without custom weights, uses default weights.
|
|
11
|
+
*/
|
|
12
|
+
export function getCalculator(strategy, typeWeights) {
|
|
13
|
+
switch (strategy) {
|
|
14
|
+
case RiskScoreStrategy.MAX_CONFIDENCE:
|
|
15
|
+
return maxConfidenceCalculator;
|
|
16
|
+
case RiskScoreStrategy.SEVERITY_PLUS_VOLUME:
|
|
17
|
+
return severityPlusVolumeCalculator;
|
|
18
|
+
case RiskScoreStrategy.WEIGHTED_BY_TYPE:
|
|
19
|
+
return typeWeights == null
|
|
20
|
+
? defaultWeightedByTypeCalculator
|
|
21
|
+
: weightedByTypeCalculator(typeWeights);
|
|
22
|
+
default:
|
|
23
|
+
return maxConfidenceCalculator;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/isl/riskScore/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,kBAAkB,CAAA;AAEzB;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,QAA2B,EAC3B,WAAoC;IAEpC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,iBAAiB,CAAC,cAAc;YACnC,OAAO,uBAAuB,CAAA;QAChC,KAAK,iBAAiB,CAAC,oBAAoB;YACzC,OAAO,4BAA4B,CAAA;QACrC,KAAK,iBAAiB,CAAC,gBAAgB;YACrC,OAAO,WAAW,IAAI,IAAI;gBACxB,CAAC,CAAC,+BAA+B;gBACjC,CAAC,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAA;QAC3C;YACE,OAAO,uBAAuB,CAAA;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk score strategy - registered strategies only (auditability, reproducibility).
|
|
3
|
+
* AAL and SDK do not choose the formula; the caller of emitSignal/sanitize does.
|
|
4
|
+
*/
|
|
5
|
+
import type { PiDetection } from '../value-objects/PiDetection.js';
|
|
6
|
+
/** Registered risk score strategies. No custom inline strategies . */
|
|
7
|
+
export declare enum RiskScoreStrategy {
|
|
8
|
+
MAX_CONFIDENCE = "max-confidence",
|
|
9
|
+
SEVERITY_PLUS_VOLUME = "severity-plus-volume",
|
|
10
|
+
WEIGHTED_BY_TYPE = "weighted-by-type"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Pure, deterministic calculator: detections → raw score (caller clamps to [0,1]).
|
|
14
|
+
* Strategy is fixed per calculator; no side effects.
|
|
15
|
+
*/
|
|
16
|
+
export interface RiskScoreCalculator {
|
|
17
|
+
readonly strategy: RiskScoreStrategy;
|
|
18
|
+
calculate(detections: readonly PiDetection[]): number;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/isl/riskScore/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAElE,sEAAsE;AACtE,oBAAY,iBAAiB;IAC3B,cAAc,mBAAmB;IACjC,oBAAoB,yBAAyB;IAC7C,gBAAgB,qBAAqB;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,SAAS,CAAC,UAAU,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAAA;CACtD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk score strategy - registered strategies only (auditability, reproducibility).
|
|
3
|
+
* AAL and SDK do not choose the formula; the caller of emitSignal/sanitize does.
|
|
4
|
+
*/
|
|
5
|
+
/** Registered risk score strategies. No custom inline strategies . */
|
|
6
|
+
export var RiskScoreStrategy;
|
|
7
|
+
(function (RiskScoreStrategy) {
|
|
8
|
+
RiskScoreStrategy["MAX_CONFIDENCE"] = "max-confidence";
|
|
9
|
+
RiskScoreStrategy["SEVERITY_PLUS_VOLUME"] = "severity-plus-volume";
|
|
10
|
+
RiskScoreStrategy["WEIGHTED_BY_TYPE"] = "weighted-by-type";
|
|
11
|
+
})(RiskScoreStrategy || (RiskScoreStrategy = {}));
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/isl/riskScore/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,sEAAsE;AACtE,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,sDAAiC,CAAA;IACjC,kEAA6C,CAAA;IAC7C,0DAAqC,CAAA;AACvC,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B"}
|
package/dist/isl/sanitize.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { CSLResult } from '../csl/types.js';
|
|
2
2
|
import type { ISLResult } from './types.js';
|
|
3
|
+
import type { DetectThreatsOptions } from './detect/index.js';
|
|
4
|
+
/** Options for sanitize. Enables flexible threat detection (e.g. custom patterns). */
|
|
5
|
+
export interface SanitizeOptions {
|
|
6
|
+
/** Passed to detectThreats per segment (e.g. patterns override/extend). */
|
|
7
|
+
readonly detectThreatsOptions?: DetectThreatsOptions;
|
|
8
|
+
}
|
|
3
9
|
/**
|
|
4
|
-
*
|
|
10
|
+
* Sanitizes content according to trust level - pure function
|
|
5
11
|
*
|
|
6
12
|
* @remarks
|
|
7
|
-
* ISL
|
|
8
|
-
* - TC:
|
|
9
|
-
* - STC:
|
|
10
|
-
* - UC:
|
|
13
|
+
* ISL applies differentiated sanitization according to trust level:
|
|
14
|
+
* - TC: Minimal sanitization
|
|
15
|
+
* - STC: Moderate sanitization
|
|
16
|
+
* - UC: Aggressive sanitization
|
|
17
|
+
* Threat detection uses default patterns unless detectThreatsOptions (e.g. patterns) is provided.
|
|
11
18
|
*/
|
|
12
|
-
export declare function sanitize(cslResult: CSLResult): ISLResult;
|
|
19
|
+
export declare function sanitize(cslResult: CSLResult, options?: SanitizeOptions): ISLResult;
|
|
13
20
|
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/isl/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/isl/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGhD,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,YAAY,CAAA;AAIvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAG7D,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,QAAQ,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,CAAA;CACrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,GAAE,eAAoB,GAAG,SAAS,CA2CvF"}
|
package/dist/isl/sanitize.js
CHANGED
|
@@ -1,57 +1,52 @@
|
|
|
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
|
+
import { detectThreats } from './detect/index.js';
|
|
5
|
+
import { createPiDetectionResult } from './value-objects/PiDetectionResult.js';
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
7
|
+
* Sanitizes content according to trust level - pure function
|
|
6
8
|
*
|
|
7
9
|
* @remarks
|
|
8
|
-
* ISL
|
|
9
|
-
* - TC:
|
|
10
|
-
* - STC:
|
|
11
|
-
* - UC:
|
|
10
|
+
* ISL applies differentiated sanitization according to trust level:
|
|
11
|
+
* - TC: Minimal sanitization
|
|
12
|
+
* - STC: Moderate sanitization
|
|
13
|
+
* - UC: Aggressive sanitization
|
|
14
|
+
* Threat detection uses default patterns unless detectThreatsOptions (e.g. patterns) is provided.
|
|
12
15
|
*/
|
|
13
|
-
export function sanitize(cslResult) {
|
|
16
|
+
export function sanitize(cslResult, options = {}) {
|
|
17
|
+
const startTime = Date.now();
|
|
14
18
|
const segments = [];
|
|
15
|
-
|
|
16
|
-
const blockedCount = 0;
|
|
17
|
-
let instructionsRemovedCount = 0;
|
|
19
|
+
const detectOptions = options.detectThreatsOptions;
|
|
18
20
|
for (const cslSegment of cslResult.segments) {
|
|
19
|
-
//
|
|
21
|
+
// Determine sanitization level according to trust level
|
|
20
22
|
const sanitizationLevel = getSanitizationLevel(cslSegment.trust);
|
|
21
|
-
//
|
|
23
|
+
// Sanitize content according to level
|
|
22
24
|
const sanitized = sanitizeContent(cslSegment.content, sanitizationLevel);
|
|
23
|
-
//
|
|
24
|
-
const
|
|
25
|
-
|
|
25
|
+
// Detect threats (deterministic, bounded; optional custom patterns)
|
|
26
|
+
const detections = detectThreats(cslSegment.content, detectOptions);
|
|
27
|
+
const piDetection = detections.length > 0 ? createPiDetectionResult(detections) : undefined;
|
|
28
|
+
// Build ISL lineage for this segment
|
|
29
|
+
const segmentLineage = buildISLLineage(cslSegment.lineage, startTime);
|
|
30
|
+
// Create sanitized segment with detections when present
|
|
26
31
|
const islSegment = {
|
|
27
32
|
id: cslSegment.id,
|
|
28
|
-
originalContent: cslSegment.content,
|
|
33
|
+
originalContent: cslSegment.content,
|
|
29
34
|
sanitizedContent: sanitized.content,
|
|
30
35
|
trust: cslSegment.trust,
|
|
31
|
-
lineage:
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
lineage: [...segmentLineage],
|
|
37
|
+
sanitizationLevel,
|
|
38
|
+
...(piDetection !== undefined && { piDetection })
|
|
34
39
|
};
|
|
35
40
|
segments.push(islSegment);
|
|
36
|
-
const lastLineageEntry = islSegment.lineage.at(-1);
|
|
37
|
-
if (lastLineageEntry) {
|
|
38
|
-
allLineage = addLineageEntry(allLineage, lastLineageEntry);
|
|
39
|
-
}
|
|
40
|
-
instructionsRemovedCount += removedInstructions.length;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
sanitizedSegments: segments.length,
|
|
48
|
-
blockedSegments: blockedCount,
|
|
49
|
-
instructionsRemoved: instructionsRemovedCount
|
|
50
|
-
}
|
|
51
|
-
};
|
|
42
|
+
// Build complete lineage
|
|
43
|
+
const allLineage = buildISLLineage(cslResult.lineage, startTime);
|
|
44
|
+
// Build result using process function
|
|
45
|
+
const processingTime = Date.now() - startTime;
|
|
46
|
+
return buildISLResult(segments, allLineage, processingTime);
|
|
52
47
|
}
|
|
53
48
|
/**
|
|
54
|
-
*
|
|
49
|
+
* Determines sanitization level according to trust level - pure function
|
|
55
50
|
*/
|
|
56
51
|
function getSanitizationLevel(trust) {
|
|
57
52
|
if (trust.value === TrustLevelType.TC)
|
|
@@ -61,14 +56,13 @@ function getSanitizationLevel(trust) {
|
|
|
61
56
|
return 'aggressive'; // UC
|
|
62
57
|
}
|
|
63
58
|
/**
|
|
64
|
-
*
|
|
59
|
+
* Sanitizes content according to level - pure function
|
|
65
60
|
*/
|
|
66
61
|
function sanitizeContent(content, _level) {
|
|
67
|
-
//
|
|
68
|
-
//
|
|
62
|
+
// For now returns content unchanged
|
|
63
|
+
// Real sanitization logic will be implemented later
|
|
69
64
|
return {
|
|
70
65
|
content,
|
|
71
|
-
removed: []
|
|
72
66
|
};
|
|
73
67
|
}
|
|
74
68
|
//# 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;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAA;AAQ9E;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAoB,EAAE,UAA2B,EAAE;IAC1E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAiB,EAAE,CAAA;IACjC,MAAM,aAAa,GAAG,OAAO,CAAC,oBAAoB,CAAA;IAElD,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,oEAAoE;QACpE,MAAM,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;QACnE,MAAM,WAAW,GACf,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAEzE,qCAAqC;QACrC,MAAM,cAAc,GAAG,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;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