@framers/agentos 0.1.56 → 0.1.57
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/README.md +67 -16
- package/dist/api/types/AgentOSResponse.d.ts +7 -0
- package/dist/api/types/AgentOSResponse.d.ts.map +1 -1
- package/dist/core/guardrails/IGuardrailService.d.ts +39 -0
- package/dist/core/guardrails/IGuardrailService.d.ts.map +1 -1
- package/dist/core/guardrails/ParallelGuardrailDispatcher.d.ts +92 -0
- package/dist/core/guardrails/ParallelGuardrailDispatcher.d.ts.map +1 -0
- package/dist/core/guardrails/ParallelGuardrailDispatcher.js +463 -0
- package/dist/core/guardrails/ParallelGuardrailDispatcher.js.map +1 -0
- package/dist/core/guardrails/guardrailDispatcher.d.ts +59 -1
- package/dist/core/guardrails/guardrailDispatcher.d.ts.map +1 -1
- package/dist/core/guardrails/guardrailDispatcher.js +49 -154
- package/dist/core/guardrails/guardrailDispatcher.js.map +1 -1
- package/dist/core/guardrails/index.d.ts +1 -0
- package/dist/core/guardrails/index.d.ts.map +1 -1
- package/dist/core/guardrails/index.js +2 -0
- package/dist/core/guardrails/index.js.map +1 -1
- package/dist/core/utils/index.d.ts +13 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/index.js +13 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/core/utils/text-utils.d.ts +164 -0
- package/dist/core/utils/text-utils.d.ts.map +1 -0
- package/dist/core/utils/text-utils.js +254 -0
- package/dist/core/utils/text-utils.js.map +1 -0
- package/dist/extensions/index.d.ts +0 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +0 -2
- package/dist/extensions/index.js.map +1 -1
- package/package.json +1 -6
- package/dist/extensions/packs/pii-redaction/EntityMerger.d.ts +0 -127
- package/dist/extensions/packs/pii-redaction/EntityMerger.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/EntityMerger.js +0 -263
- package/dist/extensions/packs/pii-redaction/EntityMerger.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/PiiDetectionPipeline.d.ts +0 -199
- package/dist/extensions/packs/pii-redaction/PiiDetectionPipeline.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/PiiDetectionPipeline.js +0 -456
- package/dist/extensions/packs/pii-redaction/PiiDetectionPipeline.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/PiiRedactionGuardrail.d.ts +0 -121
- package/dist/extensions/packs/pii-redaction/PiiRedactionGuardrail.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/PiiRedactionGuardrail.js +0 -271
- package/dist/extensions/packs/pii-redaction/PiiRedactionGuardrail.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/RedactionEngine.d.ts +0 -61
- package/dist/extensions/packs/pii-redaction/RedactionEngine.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/RedactionEngine.js +0 -207
- package/dist/extensions/packs/pii-redaction/RedactionEngine.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/index.d.ts +0 -90
- package/dist/extensions/packs/pii-redaction/index.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/index.js +0 -195
- package/dist/extensions/packs/pii-redaction/index.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/IEntityRecognizer.d.ts +0 -151
- package/dist/extensions/packs/pii-redaction/recognizers/IEntityRecognizer.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/IEntityRecognizer.js +0 -14
- package/dist/extensions/packs/pii-redaction/recognizers/IEntityRecognizer.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/LlmJudgeRecognizer.d.ts +0 -177
- package/dist/extensions/packs/pii-redaction/recognizers/LlmJudgeRecognizer.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/LlmJudgeRecognizer.js +0 -420
- package/dist/extensions/packs/pii-redaction/recognizers/LlmJudgeRecognizer.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/NerModelRecognizer.d.ts +0 -145
- package/dist/extensions/packs/pii-redaction/recognizers/NerModelRecognizer.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/NerModelRecognizer.js +0 -299
- package/dist/extensions/packs/pii-redaction/recognizers/NerModelRecognizer.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/NlpPrefilterRecognizer.d.ts +0 -102
- package/dist/extensions/packs/pii-redaction/recognizers/NlpPrefilterRecognizer.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/NlpPrefilterRecognizer.js +0 -228
- package/dist/extensions/packs/pii-redaction/recognizers/NlpPrefilterRecognizer.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/RegexRecognizer.d.ts +0 -103
- package/dist/extensions/packs/pii-redaction/recognizers/RegexRecognizer.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/recognizers/RegexRecognizer.js +0 -275
- package/dist/extensions/packs/pii-redaction/recognizers/RegexRecognizer.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/tools/PiiRedactTool.d.ts +0 -118
- package/dist/extensions/packs/pii-redaction/tools/PiiRedactTool.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/tools/PiiRedactTool.js +0 -152
- package/dist/extensions/packs/pii-redaction/tools/PiiRedactTool.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/tools/PiiScanTool.d.ts +0 -98
- package/dist/extensions/packs/pii-redaction/tools/PiiScanTool.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/tools/PiiScanTool.js +0 -153
- package/dist/extensions/packs/pii-redaction/tools/PiiScanTool.js.map +0 -1
- package/dist/extensions/packs/pii-redaction/types.d.ts +0 -332
- package/dist/extensions/packs/pii-redaction/types.d.ts.map +0 -1
- package/dist/extensions/packs/pii-redaction/types.js +0 -83
- package/dist/extensions/packs/pii-redaction/types.js.map +0 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared text utility functions used across AgentOS modules.
|
|
3
|
+
*
|
|
4
|
+
* These utilities cover common text-processing operations: numeric clamping,
|
|
5
|
+
* safe JSON parsing (including markdown code-fence stripping), tokenisation,
|
|
6
|
+
* text normalisation, and a lightweight token-count estimator used wherever
|
|
7
|
+
* the exact subword count is not critical.
|
|
8
|
+
*
|
|
9
|
+
* All functions are pure (no side-effects) and operate synchronously so they
|
|
10
|
+
* can be called from any context — including hot paths and web workers.
|
|
11
|
+
*
|
|
12
|
+
* @module agentos/core/utils/text-utils
|
|
13
|
+
*/
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Numeric helpers
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/**
|
|
18
|
+
* Clamps a numeric `value` to the closed interval [`min`, `max`].
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* clamp(5, 0, 10); // → 5
|
|
23
|
+
* clamp(-3, 0, 10); // → 0
|
|
24
|
+
* clamp(15, 0, 10); // → 10
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param value - The number to clamp.
|
|
28
|
+
* @param min - The inclusive lower bound.
|
|
29
|
+
* @param max - The inclusive upper bound.
|
|
30
|
+
* @returns The clamped value, guaranteed to satisfy `min <= result <= max`.
|
|
31
|
+
*/
|
|
32
|
+
export function clamp(value, min, max) {
|
|
33
|
+
// Guard: if min > max the range is degenerate; return min as a safe fallback.
|
|
34
|
+
if (min > max) {
|
|
35
|
+
return min;
|
|
36
|
+
}
|
|
37
|
+
return Math.min(Math.max(value, min), max);
|
|
38
|
+
}
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// JSON parsing
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Safely parses a JSON string, stripping markdown code fences if present.
|
|
44
|
+
*
|
|
45
|
+
* LLMs frequently wrap JSON in triple-backtick blocks (e.g. ` ```json … ``` `
|
|
46
|
+
* or ` ``` … ``` `). This function strips those fences before attempting
|
|
47
|
+
* `JSON.parse`, so callers do not need to pre-process LLM output.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Plain JSON
|
|
52
|
+
* parseJsonResponse<{ ok: boolean }>('{"ok":true}'); // → { ok: true }
|
|
53
|
+
*
|
|
54
|
+
* // Markdown-fenced JSON
|
|
55
|
+
* parseJsonResponse('```json\n{"ok":true}\n```'); // → { ok: true }
|
|
56
|
+
*
|
|
57
|
+
* // Invalid input
|
|
58
|
+
* parseJsonResponse('not json'); // → null
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @typeParam T - Expected shape of the parsed value.
|
|
62
|
+
* @param response - Raw string that may contain JSON, optionally wrapped in
|
|
63
|
+
* markdown code fences.
|
|
64
|
+
* @returns The parsed value cast to `T`, or `null` if parsing fails for any
|
|
65
|
+
* reason (syntax error, empty input, etc.).
|
|
66
|
+
*/
|
|
67
|
+
export function parseJsonResponse(response) {
|
|
68
|
+
if (!response || typeof response !== 'string') {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// Strip leading/trailing whitespace first.
|
|
72
|
+
let raw = response.trim();
|
|
73
|
+
// Remove markdown code fences. Handles both:
|
|
74
|
+
// ```json\n…\n``` and ```\n…\n```
|
|
75
|
+
const fencePattern = /^```(?:json|javascript|js|ts|typescript)?\s*\n?([\s\S]*?)\n?```$/i;
|
|
76
|
+
const fenceMatch = fencePattern.exec(raw);
|
|
77
|
+
if (fenceMatch) {
|
|
78
|
+
// fenceMatch[1] is the content between the fences.
|
|
79
|
+
raw = fenceMatch[1].trim();
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return JSON.parse(raw);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Parsing failed — return null rather than throwing so callers can handle
|
|
86
|
+
// gracefully without a try/catch at every call site.
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Tokenisation & normalisation
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
/**
|
|
94
|
+
* Splits text into lowercase word tokens, stripping punctuation.
|
|
95
|
+
*
|
|
96
|
+
* This is an intentionally simple, dependency-free tokeniser suited for tasks
|
|
97
|
+
* like keyword matching, vocabulary analysis, and lightweight NLP pipelines.
|
|
98
|
+
* It is *not* a subword tokeniser and does not respect language-specific rules.
|
|
99
|
+
*
|
|
100
|
+
* Steps performed:
|
|
101
|
+
* 1. Convert to lowercase.
|
|
102
|
+
* 2. Replace non-alphanumeric characters (except spaces) with spaces.
|
|
103
|
+
* 3. Split on whitespace.
|
|
104
|
+
* 4. Drop empty strings that can arise from consecutive separators.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* tokenize('Hello, World!'); // → ['hello', 'world']
|
|
109
|
+
* tokenize('foo bar\tbaz'); // → ['foo', 'bar', 'baz']
|
|
110
|
+
* tokenize(''); // → []
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param text - The string to tokenise.
|
|
114
|
+
* @returns An array of lowercase word tokens with punctuation removed.
|
|
115
|
+
*/
|
|
116
|
+
export function tokenize(text) {
|
|
117
|
+
if (!text || typeof text !== 'string') {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
return (text
|
|
121
|
+
.toLowerCase()
|
|
122
|
+
// Replace every run of non-alphanumeric, non-space chars with a space.
|
|
123
|
+
.replace(/[^a-z0-9\s]/g, ' ')
|
|
124
|
+
// Split on any run of whitespace.
|
|
125
|
+
.split(/\s+/)
|
|
126
|
+
// Remove empty strings produced by leading/trailing whitespace or
|
|
127
|
+
// consecutive separators.
|
|
128
|
+
.filter((token) => token.length > 0));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Normalises text by lowercasing, stripping punctuation, and collapsing
|
|
132
|
+
* internal whitespace runs to a single space.
|
|
133
|
+
*
|
|
134
|
+
* This produces a canonical form useful for fuzzy comparisons, deduplication,
|
|
135
|
+
* and pre-processing before embedding or classification.
|
|
136
|
+
*
|
|
137
|
+
* Steps performed:
|
|
138
|
+
* 1. Convert to lowercase.
|
|
139
|
+
* 2. Replace non-alphanumeric characters (except spaces) with spaces.
|
|
140
|
+
* 3. Collapse consecutive whitespace to a single space.
|
|
141
|
+
* 4. Trim leading and trailing whitespace.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* normalizeText('Hello, World!'); // → 'hello world'
|
|
146
|
+
* normalizeText(' foo bar '); // → 'foo bar'
|
|
147
|
+
* normalizeText("it's a test!"); // → 'it s a test'
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @param text - The string to normalise.
|
|
151
|
+
* @returns A normalised string.
|
|
152
|
+
*/
|
|
153
|
+
export function normalizeText(text) {
|
|
154
|
+
if (!text || typeof text !== 'string') {
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
return (text
|
|
158
|
+
.toLowerCase()
|
|
159
|
+
// Replace punctuation/symbols with spaces.
|
|
160
|
+
.replace(/[^a-z0-9\s]/g, ' ')
|
|
161
|
+
// Collapse runs of whitespace to a single space.
|
|
162
|
+
.replace(/\s+/g, ' ')
|
|
163
|
+
.trim());
|
|
164
|
+
}
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
// Token estimation
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
/**
|
|
169
|
+
* Estimates the number of LLM tokens in a string using the rough heuristic
|
|
170
|
+
* of **1 token ≈ 4 characters** (the widely-cited GPT-family average).
|
|
171
|
+
*
|
|
172
|
+
* This is intentionally approximate. It is suitable for budget checks,
|
|
173
|
+
* sliding-window sizing, and other cost-control logic where precision is not
|
|
174
|
+
* required. For exact subword counts, use the model's native tokeniser.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* estimateTokens('Hello!'); // → 2 (6 chars / 4 → ceil(1.5) = 2)
|
|
179
|
+
* estimateTokens(''); // → 0
|
|
180
|
+
* estimateTokens('a'.repeat(8)); // → 2
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @param text - The string whose token count should be estimated.
|
|
184
|
+
* @returns A non-negative integer estimate of the token count.
|
|
185
|
+
* Returns `0` for empty or non-string input.
|
|
186
|
+
*/
|
|
187
|
+
export function estimateTokens(text) {
|
|
188
|
+
if (!text || typeof text !== 'string') {
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
return Math.ceil(text.length / 4);
|
|
192
|
+
}
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// Vector similarity
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
/**
|
|
197
|
+
* Computes the cosine similarity between two numeric vectors.
|
|
198
|
+
*
|
|
199
|
+
* Cosine similarity measures the cosine of the angle between two vectors in
|
|
200
|
+
* an inner-product space. It ranges from **-1.0** (perfectly opposite
|
|
201
|
+
* directions) to **1.0** (perfectly identical directions), with **0** meaning
|
|
202
|
+
* the vectors are orthogonal (no linear similarity).
|
|
203
|
+
*
|
|
204
|
+
* This single implementation consolidates 6+ duplicate `cosineSimilarity`
|
|
205
|
+
* helpers that previously existed across the AgentOS codebase (discovery,
|
|
206
|
+
* social-posting, rag, etc.), providing a single well-tested source of truth.
|
|
207
|
+
*
|
|
208
|
+
* ### Edge-case behaviour
|
|
209
|
+
* | Condition | Return value | Reason |
|
|
210
|
+
* |---|---|---|
|
|
211
|
+
* | Empty arrays | `0` | Division by zero is undefined; 0 is the safe neutral value. |
|
|
212
|
+
* | Mismatched dimensions | `0` | Meaningless to compare vectors in different spaces. |
|
|
213
|
+
* | Either vector is the zero vector | `0` | Magnitude is 0, denominator would be 0. |
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* // Identical unit vectors → 1
|
|
218
|
+
* cosineSimilarity([1, 0], [1, 0]); // → 1.0
|
|
219
|
+
*
|
|
220
|
+
* // Orthogonal vectors → 0
|
|
221
|
+
* cosineSimilarity([1, 0], [0, 1]); // → 0
|
|
222
|
+
*
|
|
223
|
+
* // Opposite unit vectors → -1
|
|
224
|
+
* cosineSimilarity([1, 0], [-1, 0]); // → -1.0
|
|
225
|
+
*
|
|
226
|
+
* // Non-unit but parallel vectors → 1
|
|
227
|
+
* cosineSimilarity([2, 4], [1, 2]); // → 1.0
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @param a - First numeric vector (any dimension ≥ 1).
|
|
231
|
+
* @param b - Second numeric vector — must have the same length as `a`.
|
|
232
|
+
* @returns Cosine similarity in the range `[-1, 1]`.
|
|
233
|
+
* Returns `0` for mismatched dimensions, empty arrays, or zero-magnitude vectors.
|
|
234
|
+
*/
|
|
235
|
+
export function cosineSimilarity(a, b) {
|
|
236
|
+
// Guard: vectors must be non-empty and share the same dimensionality.
|
|
237
|
+
if (a.length !== b.length || a.length === 0)
|
|
238
|
+
return 0;
|
|
239
|
+
// Accumulate dot product and squared norms in a single pass for efficiency.
|
|
240
|
+
let dot = 0;
|
|
241
|
+
let normA = 0;
|
|
242
|
+
let normB = 0;
|
|
243
|
+
for (let i = 0; i < a.length; i++) {
|
|
244
|
+
dot += a[i] * b[i]; // contribution to the dot product
|
|
245
|
+
normA += a[i] * a[i]; // squared magnitude of a
|
|
246
|
+
normB += b[i] * b[i]; // squared magnitude of b
|
|
247
|
+
}
|
|
248
|
+
// Denominator is the product of the two vector magnitudes.
|
|
249
|
+
const denom = Math.sqrt(normA) * Math.sqrt(normB);
|
|
250
|
+
// Guard: if either vector is the zero vector the denominator is 0.
|
|
251
|
+
// Cosine similarity is undefined in that case; return 0 as the neutral value.
|
|
252
|
+
return denom === 0 ? 0 : dot / denom;
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=text-utils.js.map
|
|
@@ -0,0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;;GAsCG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAW,EAAE,CAAW;IACvD,sEAAsE;IACtE,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtD,4EAA4E;IAC5E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAI,kCAAkC;QACzD,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,yBAAyB;QAChD,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,yBAAyB;IAClD,CAAC;IAED,2DAA2D;IAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAElD,mEAAmE;IACnE,8EAA8E;IAC9E,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC;AACvC,CAAC"}
|
|
@@ -8,5 +8,4 @@ export * from './manifest';
|
|
|
8
8
|
export * from './RegistryConfig';
|
|
9
9
|
export { MultiRegistryLoader } from './MultiRegistryLoader';
|
|
10
10
|
export { ExtensionLoader } from './ExtensionLoader';
|
|
11
|
-
export { createPiiRedactionPack, createExtensionPack as createPiiExtensionPack } from './packs/pii-redaction';
|
|
12
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/extensions/index.js
CHANGED
|
@@ -8,6 +8,4 @@ export * from './manifest.js';
|
|
|
8
8
|
export * from './RegistryConfig.js';
|
|
9
9
|
export { MultiRegistryLoader } from './MultiRegistryLoader.js';
|
|
10
10
|
export { ExtensionLoader } from './ExtensionLoader.js';
|
|
11
|
-
// PII Redaction extension pack
|
|
12
|
-
export { createPiiRedactionPack, createExtensionPack as createPiiExtensionPack } from './packs/pii-redaction/index.js';
|
|
13
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framers/agentos",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.57",
|
|
4
4
|
"description": "Modular AgentOS orchestration library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,11 +38,6 @@
|
|
|
38
38
|
"default": "./dist/core/guardrails/index.js",
|
|
39
39
|
"types": "./dist/core/guardrails/index.d.ts"
|
|
40
40
|
},
|
|
41
|
-
"./extensions/packs/pii-redaction": {
|
|
42
|
-
"import": "./dist/extensions/packs/pii-redaction/index.js",
|
|
43
|
-
"default": "./dist/extensions/packs/pii-redaction/index.js",
|
|
44
|
-
"types": "./dist/extensions/packs/pii-redaction/index.d.ts"
|
|
45
|
-
},
|
|
46
41
|
"./core/safety": {
|
|
47
42
|
"import": "./dist/core/safety/index.js",
|
|
48
43
|
"default": "./dist/core/safety/index.js",
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file EntityMerger.ts
|
|
3
|
-
* @description Post-processing step that de-duplicates, filters, and merges
|
|
4
|
-
* {@link PiiEntity} spans emitted by the multi-tier detection pipeline.
|
|
5
|
-
*
|
|
6
|
-
* When multiple recognisers (regex, NER, LLM judge) run over the same text
|
|
7
|
-
* they frequently emit overlapping or duplicate spans. This module resolves
|
|
8
|
-
* those conflicts deterministically so that downstream redaction always
|
|
9
|
-
* receives a clean, non-overlapping, sorted list of entities.
|
|
10
|
-
*
|
|
11
|
-
* ## Processing pipeline
|
|
12
|
-
* 1. **Denylist boost** — entities whose text matches a denylist entry are
|
|
13
|
-
* promoted to score `1.0`, guaranteeing they survive threshold filtering.
|
|
14
|
-
* 2. **Allowlist filter** — entities whose text matches an allowlist entry are
|
|
15
|
-
* unconditionally removed before any other processing.
|
|
16
|
-
* 3. **Sort** — remaining entities are sorted by start offset; ties are broken
|
|
17
|
-
* by span length descending so that longer (more specific) spans are
|
|
18
|
-
* processed first in the overlap-resolution pass.
|
|
19
|
-
* 4. **Overlap resolution** — a single-pass scan collapses overlapping and
|
|
20
|
-
* adjacent spans into the best representative entity (details below).
|
|
21
|
-
* 5. **Threshold filter** — entities whose final score is below
|
|
22
|
-
* `confidenceThreshold` are removed.
|
|
23
|
-
* 6. **Final sort** — output is sorted by start offset for stable iteration.
|
|
24
|
-
*
|
|
25
|
-
* @module pii-redaction/EntityMerger
|
|
26
|
-
*/
|
|
27
|
-
import type { PiiEntity } from './types';
|
|
28
|
-
/**
|
|
29
|
-
* Options controlling how {@link mergeEntities} filters and merges a raw list
|
|
30
|
-
* of {@link PiiEntity} detections.
|
|
31
|
-
*
|
|
32
|
-
* All properties are optional; omitting them applies neutral defaults (no
|
|
33
|
-
* allow/denylist, no threshold filtering).
|
|
34
|
-
*/
|
|
35
|
-
export interface MergeOptions {
|
|
36
|
-
/**
|
|
37
|
-
* Case-insensitive list of literal text values to **exclude** from the
|
|
38
|
-
* output. Any entity whose `.text` matches one of these strings (after
|
|
39
|
-
* lowercasing) is silently dropped, even if it would otherwise pass all
|
|
40
|
-
* other filters.
|
|
41
|
-
*
|
|
42
|
-
* Typical use-case: whitelisting known-safe values such as
|
|
43
|
-
* `'support@company.com'` that appear in boilerplate and should never be
|
|
44
|
-
* redacted.
|
|
45
|
-
*
|
|
46
|
-
* @example `['support@example.com', '127.0.0.1']`
|
|
47
|
-
*/
|
|
48
|
-
allowlist?: string[];
|
|
49
|
-
/**
|
|
50
|
-
* Case-insensitive list of literal text values that should **always** be
|
|
51
|
-
* redacted. Any entity whose `.text` matches one of these strings (after
|
|
52
|
-
* lowercasing) has its score boosted to `1.0`, ensuring it survives
|
|
53
|
-
* threshold filtering regardless of the original confidence score.
|
|
54
|
-
*
|
|
55
|
-
* Typical use-case: internal project codenames or employee IDs that the
|
|
56
|
-
* organisation treats as sensitive.
|
|
57
|
-
*
|
|
58
|
-
* @example `['PROJ-SECRET', 'acme-internal']`
|
|
59
|
-
*/
|
|
60
|
-
denylist?: string[];
|
|
61
|
-
/**
|
|
62
|
-
* Minimum confidence score (inclusive) an entity must have after all
|
|
63
|
-
* other transformations to be included in the output.
|
|
64
|
-
*
|
|
65
|
-
* Entities with `score < confidenceThreshold` are discarded. When omitted
|
|
66
|
-
* (or `undefined`) no threshold filtering is applied and all entities with
|
|
67
|
-
* any score are retained.
|
|
68
|
-
*
|
|
69
|
-
* Must be in the range `[0, 1]` when provided.
|
|
70
|
-
*
|
|
71
|
-
* @default undefined (no threshold applied)
|
|
72
|
-
*/
|
|
73
|
-
confidenceThreshold?: number;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Merges a raw list of {@link PiiEntity} detections produced by one or more
|
|
77
|
-
* recognisers into a clean, non-overlapping, threshold-filtered output list.
|
|
78
|
-
*
|
|
79
|
-
* The function is **pure** — it does not mutate any of its inputs.
|
|
80
|
-
*
|
|
81
|
-
* ### Merge rules (applied in order)
|
|
82
|
-
*
|
|
83
|
-
* 1. **Denylist boost**: If an entity's `.text` (lowercased) appears in
|
|
84
|
-
* `options.denylist` (lowercased), its `score` is set to `1.0`.
|
|
85
|
-
*
|
|
86
|
-
* 2. **Allowlist filter**: If an entity's `.text` (lowercased) appears in
|
|
87
|
-
* `options.allowlist` (lowercased), the entity is removed entirely.
|
|
88
|
-
*
|
|
89
|
-
* 3. **Sort**: Entities are sorted by `start` offset ascending; ties broken
|
|
90
|
-
* by span length descending so longer spans are preferred in step 4.
|
|
91
|
-
*
|
|
92
|
-
* 4. **Overlap resolution** (single-pass, left-to-right):
|
|
93
|
-
* - *Exact or subset overlap* (current span is fully inside last span, or
|
|
94
|
-
* they share the same offsets): keep whichever has the higher score.
|
|
95
|
-
* - *Current is longer AND score ≥ last*: the current span replaces the
|
|
96
|
-
* last accumulated span (it provides more context at equal or better
|
|
97
|
-
* confidence).
|
|
98
|
-
* - *Adjacent spans* (gap between end of last and start of current is ≤ 2
|
|
99
|
-
* characters **and** both have the same `entityType`): the two spans are
|
|
100
|
-
* merged into a single entity whose text bridges the gap.
|
|
101
|
-
* - *Otherwise*: both spans are kept as separate entities.
|
|
102
|
-
*
|
|
103
|
-
* 5. **Confidence threshold filter**: Entities with `score <
|
|
104
|
-
* options.confidenceThreshold` are removed.
|
|
105
|
-
*
|
|
106
|
-
* 6. **Final sort**: Output is sorted by `start` offset ascending.
|
|
107
|
-
*
|
|
108
|
-
* @param entities - Raw (possibly overlapping, unsorted) entity list from the
|
|
109
|
-
* detection pipeline.
|
|
110
|
-
* @param options - Optional filtering / merging knobs. Safe to omit.
|
|
111
|
-
* @param text - The original input string. Required only when adjacent
|
|
112
|
-
* merging may occur (needed to fill gap characters).
|
|
113
|
-
* Defaults to `''` which produces a gap of spaces.
|
|
114
|
-
* @returns A new array of non-overlapping {@link PiiEntity} objects sorted by
|
|
115
|
-
* `start` offset.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const clean = mergeEntities(rawEntities, {
|
|
120
|
-
* allowlist: ['support@example.com'],
|
|
121
|
-
* denylist: ['secret-project'],
|
|
122
|
-
* confidenceThreshold: 0.6,
|
|
123
|
-
* }, originalText);
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
export declare function mergeEntities(entities: PiiEntity[], options?: MergeOptions, text?: string): PiiEntity[];
|
|
127
|
-
//# sourceMappingURL=EntityMerger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMerger.d.ts","sourceRoot":"","sources":["../../../../src/extensions/packs/pii-redaction/EntityMerger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMzC;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;;;;;;;;OAWG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAgFD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,SAAS,EAAE,EACrB,OAAO,GAAE,YAAiB,EAC1B,IAAI,SAAK,GACR,SAAS,EAAE,CAqIb"}
|