@ai-pip/core 0.1.1 → 0.1.3

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.
Files changed (165) hide show
  1. package/README.md +102 -9
  2. package/dist/cpe/envelope.d.ts +34 -0
  3. package/dist/cpe/envelope.d.ts.map +1 -0
  4. package/dist/cpe/envelope.js +70 -0
  5. package/dist/cpe/envelope.js.map +1 -0
  6. package/dist/cpe/exceptions/EnvelopeError.d.ts +8 -0
  7. package/dist/cpe/exceptions/EnvelopeError.d.ts.map +1 -0
  8. package/dist/cpe/exceptions/EnvelopeError.js +13 -0
  9. package/dist/cpe/exceptions/EnvelopeError.js.map +1 -0
  10. package/dist/cpe/exceptions/index.d.ts +5 -0
  11. package/dist/cpe/exceptions/index.d.ts.map +1 -0
  12. package/dist/cpe/exceptions/index.js +5 -0
  13. package/dist/cpe/exceptions/index.js.map +1 -0
  14. package/dist/cpe/index.d.ts +24 -0
  15. package/dist/cpe/index.d.ts.map +1 -0
  16. package/dist/cpe/index.js +28 -0
  17. package/dist/cpe/index.js.map +1 -0
  18. package/dist/cpe/types.d.ts +58 -0
  19. package/dist/cpe/types.d.ts.map +1 -0
  20. package/dist/cpe/types.js +5 -0
  21. package/dist/cpe/types.js.map +1 -0
  22. package/dist/cpe/utils.d.ts +38 -0
  23. package/dist/cpe/utils.d.ts.map +1 -0
  24. package/dist/cpe/utils.js +47 -0
  25. package/dist/cpe/utils.js.map +1 -0
  26. package/dist/cpe/value-objects/Metadata.d.ts +32 -0
  27. package/dist/cpe/value-objects/Metadata.d.ts.map +1 -0
  28. package/dist/cpe/value-objects/Metadata.js +65 -0
  29. package/dist/cpe/value-objects/Metadata.js.map +1 -0
  30. package/dist/cpe/value-objects/Nonce.d.ts +33 -0
  31. package/dist/cpe/value-objects/Nonce.d.ts.map +1 -0
  32. package/dist/cpe/value-objects/Nonce.js +44 -0
  33. package/dist/cpe/value-objects/Nonce.js.map +1 -0
  34. package/dist/cpe/value-objects/Signature.d.ts +39 -0
  35. package/dist/cpe/value-objects/Signature.d.ts.map +1 -0
  36. package/dist/cpe/value-objects/Signature.js +60 -0
  37. package/dist/cpe/value-objects/Signature.js.map +1 -0
  38. package/dist/cpe/value-objects/index.d.ts +7 -0
  39. package/dist/cpe/value-objects/index.d.ts.map +1 -0
  40. package/dist/cpe/value-objects/index.js +7 -0
  41. package/dist/cpe/value-objects/index.js.map +1 -0
  42. package/dist/csl/classify.d.ts +35 -0
  43. package/dist/csl/classify.d.ts.map +1 -0
  44. package/dist/csl/classify.js +62 -0
  45. package/dist/csl/classify.js.map +1 -0
  46. package/dist/csl/exceptions/ClassificationError.d.ts +12 -0
  47. package/dist/csl/exceptions/ClassificationError.d.ts.map +1 -0
  48. package/dist/csl/exceptions/ClassificationError.js +16 -0
  49. package/dist/csl/exceptions/ClassificationError.js.map +1 -0
  50. package/dist/csl/exceptions/SegmentationError.d.ts +13 -0
  51. package/dist/csl/exceptions/SegmentationError.d.ts.map +1 -0
  52. package/dist/csl/exceptions/SegmentationError.js +18 -0
  53. package/dist/csl/exceptions/SegmentationError.js.map +1 -0
  54. package/dist/csl/exceptions/index.d.ts +3 -0
  55. package/dist/csl/exceptions/index.d.ts.map +1 -0
  56. package/dist/csl/exceptions/index.js +3 -0
  57. package/dist/csl/exceptions/index.js.map +1 -0
  58. package/dist/csl/index.d.ts +24 -0
  59. package/dist/csl/index.d.ts.map +1 -0
  60. package/dist/csl/index.js +29 -0
  61. package/dist/csl/index.js.map +1 -0
  62. package/dist/csl/lineage.d.ts +31 -0
  63. package/dist/csl/lineage.d.ts.map +1 -0
  64. package/dist/csl/lineage.js +36 -0
  65. package/dist/csl/lineage.js.map +1 -0
  66. package/dist/csl/segment.d.ts +35 -0
  67. package/dist/csl/segment.d.ts.map +1 -0
  68. package/dist/csl/segment.js +90 -0
  69. package/dist/csl/segment.js.map +1 -0
  70. package/dist/csl/types.d.ts +97 -0
  71. package/dist/csl/types.d.ts.map +1 -0
  72. package/dist/csl/types.js +62 -0
  73. package/dist/csl/types.js.map +1 -0
  74. package/dist/csl/utils.d.ts +16 -0
  75. package/dist/csl/utils.d.ts.map +1 -0
  76. package/dist/csl/utils.js +27 -0
  77. package/dist/csl/utils.js.map +1 -0
  78. package/dist/csl/value-objects/ContentHash.d.ts +18 -0
  79. package/dist/csl/value-objects/ContentHash.d.ts.map +1 -0
  80. package/dist/csl/value-objects/ContentHash.js +33 -0
  81. package/dist/csl/value-objects/ContentHash.js.map +1 -0
  82. package/dist/csl/value-objects/LineageEntry.d.ts +20 -0
  83. package/dist/csl/value-objects/LineageEntry.d.ts.map +1 -0
  84. package/dist/csl/value-objects/LineageEntry.js +20 -0
  85. package/dist/csl/value-objects/LineageEntry.js.map +1 -0
  86. package/dist/csl/value-objects/Origin-map.d.ts +21 -0
  87. package/dist/csl/value-objects/Origin-map.d.ts.map +1 -0
  88. package/dist/csl/value-objects/Origin-map.js +42 -0
  89. package/dist/csl/value-objects/Origin-map.js.map +1 -0
  90. package/dist/csl/value-objects/Origin.d.ts +22 -0
  91. package/dist/csl/value-objects/Origin.d.ts.map +1 -0
  92. package/dist/csl/value-objects/Origin.js +38 -0
  93. package/dist/csl/value-objects/Origin.js.map +1 -0
  94. package/dist/csl/value-objects/TrustLevel.d.ts +18 -0
  95. package/dist/csl/value-objects/TrustLevel.d.ts.map +1 -0
  96. package/dist/csl/value-objects/TrustLevel.js +23 -0
  97. package/dist/csl/value-objects/TrustLevel.js.map +1 -0
  98. package/dist/csl/value-objects/index.d.ts +10 -0
  99. package/dist/csl/value-objects/index.d.ts.map +1 -0
  100. package/dist/csl/value-objects/index.js +8 -0
  101. package/dist/csl/value-objects/index.js.map +1 -0
  102. package/dist/index.d.ts +17 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +18 -0
  105. package/dist/index.js.map +1 -0
  106. package/dist/isl/exceptions/SanitizationError.d.ts +8 -0
  107. package/dist/isl/exceptions/SanitizationError.d.ts.map +1 -0
  108. package/dist/isl/exceptions/SanitizationError.js +13 -0
  109. package/dist/isl/exceptions/SanitizationError.js.map +1 -0
  110. package/dist/isl/exceptions/index.d.ts +2 -0
  111. package/dist/isl/exceptions/index.d.ts.map +1 -0
  112. package/dist/isl/exceptions/index.js +2 -0
  113. package/dist/isl/exceptions/index.js.map +1 -0
  114. package/dist/isl/index.d.ts +12 -0
  115. package/dist/isl/index.d.ts.map +1 -0
  116. package/dist/isl/index.js +16 -0
  117. package/dist/isl/index.js.map +1 -0
  118. package/dist/isl/sanitize.d.ts +13 -0
  119. package/dist/isl/sanitize.d.ts.map +1 -0
  120. package/dist/isl/sanitize.js +74 -0
  121. package/dist/isl/sanitize.js.map +1 -0
  122. package/dist/isl/types.d.ts +75 -0
  123. package/dist/isl/types.d.ts.map +1 -0
  124. package/dist/isl/types.js +5 -0
  125. package/dist/isl/types.js.map +1 -0
  126. package/dist/isl/value-objects/AnomalyScore.d.ts +19 -0
  127. package/dist/isl/value-objects/AnomalyScore.d.ts.map +1 -0
  128. package/dist/isl/value-objects/AnomalyScore.js +25 -0
  129. package/dist/isl/value-objects/AnomalyScore.js.map +1 -0
  130. package/dist/isl/value-objects/Pattern.d.ts +32 -0
  131. package/dist/isl/value-objects/Pattern.d.ts.map +1 -0
  132. package/dist/isl/value-objects/Pattern.js +116 -0
  133. package/dist/isl/value-objects/Pattern.js.map +1 -0
  134. package/dist/isl/value-objects/PiDetection.d.ts +22 -0
  135. package/dist/isl/value-objects/PiDetection.d.ts.map +1 -0
  136. package/dist/isl/value-objects/PiDetection.js +60 -0
  137. package/dist/isl/value-objects/PiDetection.js.map +1 -0
  138. package/dist/isl/value-objects/PiDetectionResult.d.ts +24 -0
  139. package/dist/isl/value-objects/PiDetectionResult.d.ts.map +1 -0
  140. package/dist/isl/value-objects/PiDetectionResult.js +90 -0
  141. package/dist/isl/value-objects/PiDetectionResult.js.map +1 -0
  142. package/dist/isl/value-objects/PolicyRule.d.ts +39 -0
  143. package/dist/isl/value-objects/PolicyRule.d.ts.map +1 -0
  144. package/dist/isl/value-objects/PolicyRule.js +65 -0
  145. package/dist/isl/value-objects/PolicyRule.js.map +1 -0
  146. package/dist/isl/value-objects/index.d.ts +9 -0
  147. package/dist/isl/value-objects/index.d.ts.map +1 -0
  148. package/dist/isl/value-objects/index.js +8 -0
  149. package/dist/isl/value-objects/index.js.map +1 -0
  150. package/dist/shared/index.d.ts +9 -0
  151. package/dist/shared/index.d.ts.map +1 -0
  152. package/dist/shared/index.js +12 -0
  153. package/dist/shared/index.js.map +1 -0
  154. package/dist/shared/lineage.d.ts +29 -0
  155. package/dist/shared/lineage.d.ts.map +1 -0
  156. package/dist/shared/lineage.js +36 -0
  157. package/dist/shared/lineage.js.map +1 -0
  158. package/package.json +21 -19
  159. package/src/cpe/envelope.ts +3 -3
  160. package/src/cpe/types.ts +1 -1
  161. package/src/index.ts +2 -0
  162. package/src/isl/sanitize.ts +5 -5
  163. package/src/isl/types.ts +1 -1
  164. package/src/shared/lineage.ts +1 -1
  165. package/tsconfig.json +6 -3
@@ -0,0 +1,8 @@
1
+ // Funciones de creación
2
+ export { createTrustLevel, isTrusted, isSemiTrusted, isUntrusted } from './TrustLevel';
3
+ export { createOrigin, isDom, isUser, isSystem, isInjected, isUnknown, isNetworkFetched, isExternal } from './Origin';
4
+ export { createLineageEntry } from './LineageEntry';
5
+ export { createContentHash, isSha256, isSha512 } from './ContentHash';
6
+ // Origin-map
7
+ export { originMap, validateOriginMap } from './Origin-map';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/csl/value-objects/index.ts"],"names":[],"mappings":"AAMA,wBAAwB;AACxB,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrH,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAErE,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @ai-pip/core - Core implementation of the AI-PIP protocol
3
+ *
4
+ * @remarks
5
+ * Main entry point that re-exports all layers (CSL, ISL, Shared)
6
+ *
7
+ * You can also import specific layers:
8
+ * - import { segment } from '@ai-pip/core/csl'
9
+ * - import { sanitize } from '@ai-pip/core/isl'
10
+ * - import { addLineageEntry } from '@ai-pip/core/shared'
11
+ * - import { envelope } from '@ai-pip/core/cpe'
12
+ */
13
+ export * from './csl';
14
+ export * from './isl';
15
+ export * from './shared';
16
+ export * from './cpe';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @ai-pip/core - Core implementation of the AI-PIP protocol
3
+ *
4
+ * @remarks
5
+ * Main entry point that re-exports all layers (CSL, ISL, Shared)
6
+ *
7
+ * You can also import specific layers:
8
+ * - import { segment } from '@ai-pip/core/csl'
9
+ * - import { sanitize } from '@ai-pip/core/isl'
10
+ * - import { addLineageEntry } from '@ai-pip/core/shared'
11
+ * - import { envelope } from '@ai-pip/core/cpe'
12
+ */
13
+ // Re-export all layers
14
+ export * from './csl';
15
+ export * from './isl';
16
+ export * from './shared';
17
+ export * from './cpe';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,uBAAuB;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * SanitizationError is thrown when sanitization fails.
3
+ */
4
+ export declare class SanitizationError extends Error {
5
+ readonly cause?: unknown | undefined;
6
+ constructor(message: string, cause?: unknown | undefined);
7
+ }
8
+ //# sourceMappingURL=SanitizationError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SanitizationError.d.ts","sourceRoot":"","sources":["../../../src/isl/exceptions/SanitizationError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,KAAK,CAAC,EAAE,OAAO;gBAD/B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,OAAO,YAAA;CAMlC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * SanitizationError is thrown when sanitization fails.
3
+ */
4
+ export class SanitizationError extends Error {
5
+ cause;
6
+ constructor(message, cause) {
7
+ super(message);
8
+ this.cause = cause;
9
+ this.name = 'SanitizationError';
10
+ Object.setPrototypeOf(this, SanitizationError.prototype);
11
+ }
12
+ }
13
+ //# sourceMappingURL=SanitizationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SanitizationError.js","sourceRoot":"","sources":["../../../src/isl/exceptions/SanitizationError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAGxB;IAFlB,YACE,OAAe,EACC,KAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAA;QAFE,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAC/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;IAC1D,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './SanitizationError';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/isl/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './SanitizationError';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/isl/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * ISL (Instruction Sanitization Layer) - Core Semántico
3
+ *
4
+ * @remarks
5
+ * ISL sanitiza instrucciones maliciosas recibidas de CSL,
6
+ * aplicando diferentes niveles de sanitización según el nivel de confianza.
7
+ */
8
+ export { sanitize } from './sanitize';
9
+ export * from './value-objects';
10
+ export * from './exceptions';
11
+ export * from './types';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/isl/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,cAAc,iBAAiB,CAAA;AAG/B,cAAc,cAAc,CAAA;AAG5B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * ISL (Instruction Sanitization Layer) - Core Semántico
3
+ *
4
+ * @remarks
5
+ * ISL sanitiza instrucciones maliciosas recibidas de CSL,
6
+ * aplicando diferentes niveles de sanitización según el nivel de confianza.
7
+ */
8
+ // Funciones puras principales
9
+ export { sanitize } from './sanitize';
10
+ // Value objects
11
+ export * from './value-objects';
12
+ // Exceptions
13
+ export * from './exceptions';
14
+ // Types
15
+ export * from './types';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/isl/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8BAA8B;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,gBAAgB;AAChB,cAAc,iBAAiB,CAAA;AAE/B,aAAa;AACb,cAAc,cAAc,CAAA;AAE5B,QAAQ;AACR,cAAc,SAAS,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { CSLResult } from '../csl/types';
2
+ import type { ISLResult } from './types';
3
+ /**
4
+ * Sanitiza contenido según nivel de confianza - función pura
5
+ *
6
+ * @remarks
7
+ * ISL aplica sanitización diferenciada según el trust level:
8
+ * - TC: Sanitización mínima
9
+ * - STC: Sanitización moderada
10
+ * - UC: Sanitización agresiva
11
+ */
12
+ export declare function sanitize(cslResult: CSLResult): ISLResult;
13
+ //# sourceMappingURL=sanitize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/isl/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAkC,MAAM,SAAS,CAAA;AAMxE;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAmDxD"}
@@ -0,0 +1,74 @@
1
+ import { createLineageEntry } from '../csl/value-objects';
2
+ import { addLineageEntry } from '../shared/lineage';
3
+ import { TrustLevelType } from '../csl/types';
4
+ /**
5
+ * Sanitiza contenido según nivel de confianza - función pura
6
+ *
7
+ * @remarks
8
+ * ISL aplica sanitización diferenciada según el trust level:
9
+ * - TC: Sanitización mínima
10
+ * - STC: Sanitización moderada
11
+ * - UC: Sanitización agresiva
12
+ */
13
+ export function sanitize(cslResult) {
14
+ const segments = [];
15
+ let allLineage = [...cslResult.lineage];
16
+ const blockedCount = 0;
17
+ let instructionsRemovedCount = 0;
18
+ for (const cslSegment of cslResult.segments) {
19
+ // Determinar nivel de sanitización según trust level
20
+ const sanitizationLevel = getSanitizationLevel(cslSegment.trust);
21
+ // Sanitizar contenido según nivel
22
+ const sanitized = sanitizeContent(cslSegment.content, sanitizationLevel);
23
+ // Detectar instrucciones removidas (esto se implementará con detección de PI)
24
+ const removedInstructions = [];
25
+ // Crear segmento sanitizado
26
+ const islSegment = {
27
+ id: cslSegment.id,
28
+ originalContent: cslSegment.content, // ✅ Preservar original
29
+ sanitizedContent: sanitized.content,
30
+ trust: cslSegment.trust,
31
+ lineage: addLineageEntry(cslSegment.lineage, createLineageEntry('ISL', Date.now())),
32
+ instructionsRemoved: removedInstructions,
33
+ sanitizationLevel
34
+ };
35
+ segments.push(islSegment);
36
+ const lastLineageEntry = islSegment.lineage.at(-1);
37
+ if (lastLineageEntry) {
38
+ allLineage = addLineageEntry(allLineage, lastLineageEntry);
39
+ }
40
+ instructionsRemovedCount += removedInstructions.length;
41
+ }
42
+ return {
43
+ segments: Object.freeze(segments),
44
+ lineage: Object.freeze(allLineage),
45
+ metadata: {
46
+ totalSegments: segments.length,
47
+ sanitizedSegments: segments.length,
48
+ blockedSegments: blockedCount,
49
+ instructionsRemoved: instructionsRemovedCount
50
+ }
51
+ };
52
+ }
53
+ /**
54
+ * Determina nivel de sanitización según trust level - función pura
55
+ */
56
+ function getSanitizationLevel(trust) {
57
+ if (trust.value === TrustLevelType.TC)
58
+ return 'minimal';
59
+ if (trust.value === TrustLevelType.STC)
60
+ return 'moderate';
61
+ return 'aggressive'; // UC
62
+ }
63
+ /**
64
+ * Sanitiza contenido según nivel - función pura
65
+ */
66
+ function sanitizeContent(content, _level) {
67
+ // Por ahora retorna el contenido sin cambios
68
+ // La lógica de sanitización real se implementará después
69
+ return {
70
+ content,
71
+ removed: []
72
+ };
73
+ }
74
+ //# sourceMappingURL=sanitize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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AAC,CAAC,CAAC,CAAC,CAAA;QAClD,IAAI,gBAAgB,EAAE,CAAC;YACrB,UAAU,GAAG,eAAe,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAA;QAC5D,CAAC;QACD,wBAAwB,IAAI,mBAAmB,CAAC,MAAM,CAAA;IACxD,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;QAClC,QAAQ,EAAE;YACR,aAAa,EAAE,QAAQ,CAAC,MAAM;YAC9B,iBAAiB,EAAE,QAAQ,CAAC,MAAM;YAClC,eAAe,EAAE,YAAY;YAC7B,mBAAmB,EAAE,wBAAwB;SAC9C;KACF,CAAA;AACH,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,6CAA6C;IAC7C,yDAAyD;IACzD,OAAO;QACL,OAAO;QACP,OAAO,EAAE,EAAE;KACZ,CAAA;AACH,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Types for ISL (Instruction Sanitization Layer) - Core Semántico
3
+ */
4
+ import type { LineageEntry, TrustLevel } from '../csl/value-objects';
5
+ import type { PiDetectionResult } from './value-objects/PiDetectionResult';
6
+ import type { AnomalyScore } from './value-objects/AnomalyScore';
7
+ /**
8
+ * RiskScore - Score de riesgo (0-1)
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
49
+ */
50
+ export interface ISLSegment {
51
+ readonly id: string;
52
+ readonly originalContent: string;
53
+ readonly sanitizedContent: string;
54
+ readonly trust: TrustLevel;
55
+ readonly lineage: LineageEntry[];
56
+ readonly piDetection?: PiDetectionResult;
57
+ readonly anomalyScore?: AnomalyScore;
58
+ readonly instructionsRemoved: RemovedInstruction[];
59
+ readonly sanitizationLevel: 'minimal' | 'moderate' | 'aggressive';
60
+ }
61
+ /**
62
+ * ISLResult - Resultado de la sanitización
63
+ */
64
+ export interface ISLResult {
65
+ readonly segments: readonly ISLSegment[];
66
+ readonly lineage: readonly LineageEntry[];
67
+ readonly metadata: {
68
+ readonly totalSegments: number;
69
+ readonly sanitizedSegments: number;
70
+ readonly blockedSegments: number;
71
+ readonly instructionsRemoved: number;
72
+ readonly processingTimeMs?: number;
73
+ };
74
+ }
75
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src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,EAAE,YAAY,EAAE,CAAA;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAA;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAA;IACpC,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAA;IAClD,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,eAAe,EAAE,MAAM,CAAA;QAChC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAA;QACpC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KACnC,CAAA;CACF"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Types for ISL (Instruction Sanitization Layer) - Core Semántico
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/isl/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,19 @@
1
+ import type { AnomalyAction, RiskScore } from '../types';
2
+ /**
3
+ * AnomalyScore - tipo puro
4
+ */
5
+ export type AnomalyScore = {
6
+ readonly score: RiskScore;
7
+ readonly action: AnomalyAction;
8
+ };
9
+ /**
10
+ * Crea un AnomalyScore - función pura
11
+ */
12
+ export declare function createAnomalyScore(score: RiskScore, action: AnomalyAction): AnomalyScore;
13
+ /**
14
+ * Funciones puras para AnomalyScore
15
+ */
16
+ export declare function isHighRisk(anomaly: AnomalyScore): boolean;
17
+ export declare function isWarnRisk(anomaly: AnomalyScore): boolean;
18
+ export declare function isLowRisk(anomaly: AnomalyScore): boolean;
19
+ //# sourceMappingURL=AnomalyScore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnomalyScore.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/AnomalyScore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAExD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAC/B,CAAA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,GAAG,YAAY,CAUxF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAEzD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAEzD;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAExD"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Crea un AnomalyScore - función pura
3
+ */
4
+ export function createAnomalyScore(score, action) {
5
+ if (score < 0 || score > 1) {
6
+ throw new Error('Anomaly score must be a value between 0 and 1');
7
+ }
8
+ if (!['ALLOW', 'WARN', 'BLOCK'].includes(action)) {
9
+ throw new Error(`Invalid AnomalyAction: ${action}. Must be one of: ALLOW, WARN, BLOCK`);
10
+ }
11
+ return { score, action };
12
+ }
13
+ /**
14
+ * Funciones puras para AnomalyScore
15
+ */
16
+ export function isHighRisk(anomaly) {
17
+ return anomaly.action === 'BLOCK';
18
+ }
19
+ export function isWarnRisk(anomaly) {
20
+ return anomaly.action === 'WARN';
21
+ }
22
+ export function isLowRisk(anomaly) {
23
+ return anomaly.action === 'ALLOW';
24
+ }
25
+ //# sourceMappingURL=AnomalyScore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnomalyScore.js","sourceRoot":"","sources":["../../../src/isl/value-objects/AnomalyScore.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAgB,EAAE,MAAqB;IACxE,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;IAED,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,sCAAsC,CAAC,CAAA;IACzF,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAqB;IAC9C,OAAO,OAAO,CAAC,MAAM,KAAK,OAAO,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAqB;IAC9C,OAAO,OAAO,CAAC,MAAM,KAAK,MAAM,CAAA;AAClC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAqB;IAC7C,OAAO,OAAO,CAAC,MAAM,KAAK,OAAO,CAAA;AACnC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { RiskScore } from '../types';
2
+ /**
3
+ * Pattern - tipo puro
4
+ */
5
+ export type Pattern = {
6
+ readonly pattern_type: string;
7
+ readonly regex: RegExp;
8
+ readonly base_confidence: RiskScore;
9
+ readonly description: string;
10
+ };
11
+ /**
12
+ * Constantes de seguridad para pattern matching
13
+ */
14
+ export declare const MAX_CONTENT_LENGTH = 10000000;
15
+ export declare const MAX_PATTERN_LENGTH = 10000;
16
+ export declare const MAX_MATCHES = 10000;
17
+ /**
18
+ * Crea un Pattern - función pura
19
+ */
20
+ export declare function createPattern(pattern_type: string, regex: string | RegExp, base_confidence: RiskScore, description?: string): Pattern;
21
+ /**
22
+ * Funciones puras para Pattern matching
23
+ */
24
+ export declare function matchesPattern(pattern: Pattern, content: string): boolean;
25
+ export declare function findMatch(pattern: Pattern, content: string): {
26
+ matched: string;
27
+ position: {
28
+ start: number;
29
+ end: number;
30
+ };
31
+ } | null;
32
+ //# sourceMappingURL=Pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pattern.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/Pattern.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAA;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,WAAa,CAAA;AAC5C,eAAO,MAAM,kBAAkB,QAAS,CAAA;AACxC,eAAO,MAAM,WAAW,QAAS,CAAA;AA6DjC;;GAEG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,eAAe,EAAE,SAAS,EAC1B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAyBT;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAYzE;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG;IAC5D,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CACzC,GAAG,IAAI,CAuBP"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Constantes de seguridad para pattern matching
3
+ */
4
+ export const MAX_CONTENT_LENGTH = 10_000_000; // 10MB
5
+ export const MAX_PATTERN_LENGTH = 10_000;
6
+ export const MAX_MATCHES = 10_000;
7
+ /**
8
+ * Valida pattern_type - función pura
9
+ */
10
+ function validatePatternType(pattern_type) {
11
+ if (!pattern_type || typeof pattern_type !== 'string' || pattern_type.trim().length === 0) {
12
+ throw new TypeError('Pattern pattern_type must be a non-empty string');
13
+ }
14
+ }
15
+ /**
16
+ * Valida regex - función pura
17
+ */
18
+ function validateRegex(regex) {
19
+ if (!regex || (typeof regex !== 'string' && !(regex instanceof RegExp))) {
20
+ throw new TypeError('Pattern regex must be a string or a RegExp');
21
+ }
22
+ }
23
+ /**
24
+ * Valida base_confidence - función pura
25
+ */
26
+ function validateBaseConfidence(base_confidence) {
27
+ if (typeof base_confidence !== 'number' || !Number.isFinite(base_confidence)) {
28
+ throw new TypeError('Pattern base_confidence must be a valid number');
29
+ }
30
+ if (base_confidence < 0 || base_confidence > 1) {
31
+ throw new Error('Pattern base_confidence must be between 0 and 1');
32
+ }
33
+ }
34
+ /**
35
+ * Valida description - función pura
36
+ */
37
+ function validateDescription(description) {
38
+ if (description !== undefined && (typeof description !== 'string' || description.trim().length === 0)) {
39
+ throw new TypeError('Pattern description must be a non-empty string if provided');
40
+ }
41
+ }
42
+ /**
43
+ * Compila regex string a RegExp - función pura
44
+ */
45
+ function compileRegexString(regex) {
46
+ try {
47
+ return new RegExp(regex, 'i');
48
+ }
49
+ catch (error) {
50
+ const errorMessage = error instanceof Error ? error.message : String(error);
51
+ throw new TypeError(`Pattern regex must be a valid regular expression: ${regex}. Original error: ${errorMessage}`);
52
+ }
53
+ }
54
+ /**
55
+ * Clona RegExp - función pura
56
+ */
57
+ function cloneRegExp(regex) {
58
+ return new RegExp(regex.source, regex.flags);
59
+ }
60
+ /**
61
+ * Crea un Pattern - función pura
62
+ */
63
+ export function createPattern(pattern_type, regex, base_confidence, description) {
64
+ // Validar inputs
65
+ validatePatternType(pattern_type);
66
+ validateRegex(regex);
67
+ validateBaseConfidence(base_confidence);
68
+ validateDescription(description);
69
+ // Validar y procesar regex
70
+ const regexSource = typeof regex === 'string' ? regex : regex.source;
71
+ if (regexSource.length > MAX_PATTERN_LENGTH) {
72
+ throw new Error(`Pattern regex source exceeds maximum length of ${MAX_PATTERN_LENGTH} characters`);
73
+ }
74
+ // Normalizar regex a RegExp
75
+ const normalizedRegex = typeof regex === 'string'
76
+ ? compileRegexString(regex)
77
+ : cloneRegExp(regex);
78
+ return {
79
+ pattern_type: pattern_type.trim(),
80
+ regex: normalizedRegex,
81
+ base_confidence,
82
+ description: description?.trim() ?? ''
83
+ };
84
+ }
85
+ /**
86
+ * Funciones puras para Pattern matching
87
+ */
88
+ export function matchesPattern(pattern, content) {
89
+ if (!content || typeof content !== 'string') {
90
+ throw new TypeError('Pattern.matches: content must be a non-empty string');
91
+ }
92
+ if (content.length > MAX_CONTENT_LENGTH) {
93
+ throw new Error(`Pattern.matches: Content length (${content.length}) exceeds maximum allowed length (${MAX_CONTENT_LENGTH})`);
94
+ }
95
+ return pattern.regex.test(content);
96
+ }
97
+ export function findMatch(pattern, content) {
98
+ if (!content || typeof content !== 'string') {
99
+ throw new TypeError('Pattern.findMatch: content must be a non-empty string');
100
+ }
101
+ if (content.length > MAX_CONTENT_LENGTH) {
102
+ throw new Error(`Pattern.findMatch: Content length (${content.length}) exceeds maximum allowed length (${MAX_CONTENT_LENGTH})`);
103
+ }
104
+ const match = pattern.regex.exec(content);
105
+ if (match?.index === undefined) {
106
+ return null;
107
+ }
108
+ return {
109
+ matched: match[0],
110
+ position: {
111
+ start: match.index,
112
+ end: match.index + match[0].length
113
+ }
114
+ };
115
+ }
116
+ //# sourceMappingURL=Pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pattern.js","sourceRoot":"","sources":["../../../src/isl/value-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C,KAAK;YAClB,GAAG,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;SACnC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Position, RiskScore } from '../types';
2
+ /**
3
+ * PiDetection - tipo puro
4
+ */
5
+ export type PiDetection = {
6
+ readonly pattern_type: string;
7
+ readonly matched_pattern: string;
8
+ readonly position: Position;
9
+ readonly confidence: RiskScore;
10
+ };
11
+ /**
12
+ * Crea un PiDetection - función pura
13
+ */
14
+ export declare function createPiDetection(pattern_type: string, matched_pattern: string, position: Position, confidence: RiskScore): PiDetection;
15
+ /**
16
+ * Funciones puras para PiDetection
17
+ */
18
+ export declare function getDetectionLength(detection: PiDetection): number;
19
+ export declare function isHighConfidence(detection: PiDetection): boolean;
20
+ export declare function isMediumConfidence(detection: PiDetection): boolean;
21
+ export declare function isLowConfidence(detection: PiDetection): boolean;
22
+ //# sourceMappingURL=PiDetection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PiDetection.d.ts","sourceRoot":"","sources":["../../../src/isl/value-objects/PiDetection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEnD;;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"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Crea un PiDetection - función pura
3
+ */
4
+ export function createPiDetection(pattern_type, matched_pattern, position, confidence) {
5
+ // Validar pattern_type
6
+ if (!pattern_type || typeof pattern_type !== 'string' || pattern_type.trim().length === 0) {
7
+ throw new Error('PiDetection pattern_type must be a non-empty string');
8
+ }
9
+ // Validar matched_pattern
10
+ if (!matched_pattern || typeof matched_pattern !== 'string') {
11
+ throw new Error('PiDetection matched_pattern must be a non-empty string');
12
+ }
13
+ // Validar position
14
+ if (!position || typeof position !== 'object') {
15
+ throw new TypeError('PiDetection position must be an object with start and end properties');
16
+ }
17
+ if (typeof position.start !== 'number' || !Number.isFinite(position.start) || position.start < 0) {
18
+ throw new Error('PiDetection position.start must be a valid non-negative number');
19
+ }
20
+ if (typeof position.end !== 'number' || !Number.isFinite(position.end) || position.end < 0) {
21
+ throw new Error('PiDetection position.end must be a valid non-negative number');
22
+ }
23
+ if (position.end <= position.start) {
24
+ throw new Error('PiDetection position.end must be greater than position.start');
25
+ }
26
+ // Validar confidence
27
+ if (typeof confidence !== 'number' || !Number.isFinite(confidence)) {
28
+ throw new TypeError('PiDetection confidence must be a valid number');
29
+ }
30
+ if (confidence < 0 || confidence > 1) {
31
+ throw new Error('PiDetection confidence must be between 0 and 1');
32
+ }
33
+ // Validar que matched_pattern length coincide con position
34
+ const patternLength = position.end - position.start;
35
+ if (matched_pattern.length !== patternLength) {
36
+ throw new Error(`PiDetection matched_pattern length (${matched_pattern.length}) does not match position range (${patternLength})`);
37
+ }
38
+ return {
39
+ pattern_type: pattern_type.trim(),
40
+ matched_pattern,
41
+ position: Object.freeze({ ...position }),
42
+ confidence
43
+ };
44
+ }
45
+ /**
46
+ * Funciones puras para PiDetection
47
+ */
48
+ export function getDetectionLength(detection) {
49
+ return detection.position.end - detection.position.start;
50
+ }
51
+ export function isHighConfidence(detection) {
52
+ return detection.confidence >= 0.7;
53
+ }
54
+ export function isMediumConfidence(detection) {
55
+ return detection.confidence >= 0.3 && detection.confidence < 0.7;
56
+ }
57
+ export function isLowConfidence(detection) {
58
+ return detection.confidence < 0.3;
59
+ }
60
+ //# sourceMappingURL=PiDetection.js.map