@framers/agentos 0.1.56 → 0.1.58
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
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file index.ts
|
|
3
|
-
* @description Pack factory for the PII Redaction extension pack.
|
|
4
|
-
*
|
|
5
|
-
* This module exports the main `createPiiRedactionPack()` factory function
|
|
6
|
-
* that assembles the guardrail, scan tool, and redact tool into a single
|
|
7
|
-
* {@link ExtensionPack} ready for registration with the AgentOS extension
|
|
8
|
-
* manager.
|
|
9
|
-
*
|
|
10
|
-
* It also exports a `createExtensionPack()` bridge function that conforms to
|
|
11
|
-
* the AgentOS manifest factory convention, delegating to
|
|
12
|
-
* `createPiiRedactionPack()` with options extracted from the
|
|
13
|
-
* {@link ExtensionPackContext}.
|
|
14
|
-
*
|
|
15
|
-
* ### Lifecycle
|
|
16
|
-
*
|
|
17
|
-
* Components are built eagerly at pack creation time for direct programmatic
|
|
18
|
-
* use. When the pack is activated by the extension manager, the `onActivate`
|
|
19
|
-
* hook rebuilds all components with the manager's shared service registry and
|
|
20
|
-
* secret resolver, ensuring heavyweight services (NLP models, NER weights)
|
|
21
|
-
* are shared across the agent.
|
|
22
|
-
*
|
|
23
|
-
* @module pii-redaction
|
|
24
|
-
*/
|
|
25
|
-
import { SharedServiceRegistry } from '../../SharedServiceRegistry.js';
|
|
26
|
-
import { EXTENSION_KIND_GUARDRAIL, EXTENSION_KIND_TOOL } from '../../types.js';
|
|
27
|
-
import { PiiRedactionGuardrail } from './PiiRedactionGuardrail.js';
|
|
28
|
-
import { PiiScanTool } from './tools/PiiScanTool.js';
|
|
29
|
-
import { PiiRedactTool } from './tools/PiiRedactTool.js';
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
// Re-exports
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
/**
|
|
34
|
-
* Re-export all types from the PII redaction type definitions so consumers
|
|
35
|
-
* can import everything from a single entry point:
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { createPiiRedactionPack, PiiEntityType } from './pii-redaction';
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export * from './types.js';
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// Pack factory
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
/**
|
|
45
|
-
* Create an ExtensionPack that bundles the PII redaction guardrail with
|
|
46
|
-
* the `pii_scan` and `pii_redact` tools.
|
|
47
|
-
*
|
|
48
|
-
* ### Default behaviour (zero-config)
|
|
49
|
-
* When called without options, the pack detects all 18 PII entity types at
|
|
50
|
-
* a confidence threshold of 0.5, redacts using the `placeholder` style
|
|
51
|
-
* (`[EMAIL]`), and evaluates both input and output.
|
|
52
|
-
*
|
|
53
|
-
* ### Activation lifecycle
|
|
54
|
-
* The pack uses mutable internal state (`state.services`, `state.getSecret`)
|
|
55
|
-
* that is upgraded when the extension manager calls `onActivate` with its
|
|
56
|
-
* shared service registry and secret resolver. All three components
|
|
57
|
-
* (guardrail, scan tool, redact tool) are rebuilt at that point so they
|
|
58
|
-
* share NLP/NER model instances with other extensions.
|
|
59
|
-
*
|
|
60
|
-
* @param options - Optional pack-level configuration. All properties have
|
|
61
|
-
* sensible defaults; see {@link PiiRedactionPackOptions}.
|
|
62
|
-
* @returns A fully-configured {@link ExtensionPack} with one guardrail and
|
|
63
|
-
* two tools.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* import { createPiiRedactionPack } from './pii-redaction';
|
|
68
|
-
*
|
|
69
|
-
* const pack = createPiiRedactionPack({
|
|
70
|
-
* entityTypes: ['EMAIL', 'PHONE', 'SSN'],
|
|
71
|
-
* redactionStyle: 'mask',
|
|
72
|
-
* guardrailScope: 'both',
|
|
73
|
-
* });
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export function createPiiRedactionPack(options) {
|
|
77
|
-
/** Resolved options (defaults to empty object for zero-config). */
|
|
78
|
-
const opts = options ?? {};
|
|
79
|
-
// -----------------------------------------------------------------------
|
|
80
|
-
// Mutable state that onActivate can upgrade with the extension manager's
|
|
81
|
-
// shared registry and secret resolver.
|
|
82
|
-
// -----------------------------------------------------------------------
|
|
83
|
-
const state = {
|
|
84
|
-
/** Service registry — starts as a standalone instance, may be replaced. */
|
|
85
|
-
services: new SharedServiceRegistry(),
|
|
86
|
-
/** Secret resolver — initially undefined (no secrets available). */
|
|
87
|
-
getSecret: undefined,
|
|
88
|
-
};
|
|
89
|
-
// -----------------------------------------------------------------------
|
|
90
|
-
// Component instances — rebuilt by buildComponents()
|
|
91
|
-
// -----------------------------------------------------------------------
|
|
92
|
-
/** The guardrail service instance. */
|
|
93
|
-
let guardrail;
|
|
94
|
-
/** The PII scan tool instance. */
|
|
95
|
-
let scanTool;
|
|
96
|
-
/** The PII redact tool instance. */
|
|
97
|
-
let redactTool;
|
|
98
|
-
/**
|
|
99
|
-
* (Re)build all three pack components using the current `state.services`
|
|
100
|
-
* and `state.getSecret`. Called once at pack creation and again during
|
|
101
|
-
* `onActivate` to upgrade to the shared registry.
|
|
102
|
-
*/
|
|
103
|
-
function buildComponents() {
|
|
104
|
-
guardrail = new PiiRedactionGuardrail(state.services, opts, state.getSecret);
|
|
105
|
-
scanTool = new PiiScanTool(state.services, opts);
|
|
106
|
-
redactTool = new PiiRedactTool(state.services, opts);
|
|
107
|
-
}
|
|
108
|
-
// Initial build for direct programmatic use (before activation).
|
|
109
|
-
buildComponents();
|
|
110
|
-
// -----------------------------------------------------------------------
|
|
111
|
-
// ExtensionPack shape
|
|
112
|
-
// -----------------------------------------------------------------------
|
|
113
|
-
return {
|
|
114
|
-
/** Canonical pack name used in manifests and logs. */
|
|
115
|
-
name: 'pii-redaction',
|
|
116
|
-
/** Semantic version of the pack. */
|
|
117
|
-
version: '1.0.0',
|
|
118
|
-
/**
|
|
119
|
-
* Descriptors getter — returns the current component instances wrapped
|
|
120
|
-
* in the ExtensionDescriptor shape. Uses a getter so that descriptors
|
|
121
|
-
* always reflect the latest (potentially rebuilt) component references.
|
|
122
|
-
*/
|
|
123
|
-
get descriptors() {
|
|
124
|
-
return [
|
|
125
|
-
{
|
|
126
|
-
id: 'pii-redaction-guardrail',
|
|
127
|
-
kind: EXTENSION_KIND_GUARDRAIL,
|
|
128
|
-
priority: 10,
|
|
129
|
-
payload: guardrail,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
id: 'pii_scan',
|
|
133
|
-
kind: EXTENSION_KIND_TOOL,
|
|
134
|
-
priority: 0,
|
|
135
|
-
payload: scanTool,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
id: 'pii_redact',
|
|
139
|
-
kind: EXTENSION_KIND_TOOL,
|
|
140
|
-
priority: 0,
|
|
141
|
-
payload: redactTool,
|
|
142
|
-
},
|
|
143
|
-
];
|
|
144
|
-
},
|
|
145
|
-
/**
|
|
146
|
-
* Lifecycle hook called by the extension manager when the pack is
|
|
147
|
-
* activated. Upgrades the shared service registry and secret resolver
|
|
148
|
-
* to the manager's instances, then rebuilds all components so they
|
|
149
|
-
* share heavyweight services (NLP models, NER weights) with the rest
|
|
150
|
-
* of the agent.
|
|
151
|
-
*
|
|
152
|
-
* @param context - Activation context provided by the extension manager.
|
|
153
|
-
*/
|
|
154
|
-
onActivate: (context) => {
|
|
155
|
-
// Upgrade the service registry if the manager provides one.
|
|
156
|
-
if (context.services) {
|
|
157
|
-
state.services = context.services;
|
|
158
|
-
}
|
|
159
|
-
// Upgrade the secret resolver if the manager provides one.
|
|
160
|
-
if (context.getSecret) {
|
|
161
|
-
state.getSecret = context.getSecret;
|
|
162
|
-
}
|
|
163
|
-
// Rebuild all components with the upgraded state.
|
|
164
|
-
buildComponents();
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
// Manifest factory bridge
|
|
170
|
-
// ---------------------------------------------------------------------------
|
|
171
|
-
/**
|
|
172
|
-
* AgentOS manifest factory function.
|
|
173
|
-
*
|
|
174
|
-
* This function conforms to the convention expected by the extension loader
|
|
175
|
-
* when resolving packs from manifests. It extracts `options` from the
|
|
176
|
-
* {@link ExtensionPackContext} and delegates to {@link createPiiRedactionPack}.
|
|
177
|
-
*
|
|
178
|
-
* @param context - Manifest context containing optional pack options, secret
|
|
179
|
-
* resolver, and shared service registry.
|
|
180
|
-
* @returns A fully-configured {@link ExtensionPack}.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* // In an AgentOS manifest:
|
|
185
|
-
* {
|
|
186
|
-
* "packs": [
|
|
187
|
-
* { "module": "./pii-redaction", "options": { "redactionStyle": "hash" } }
|
|
188
|
-
* ]
|
|
189
|
-
* }
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
export function createExtensionPack(context) {
|
|
193
|
-
return createPiiRedactionPack(context.options);
|
|
194
|
-
}
|
|
195
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/packs/pii-redaction/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file IEntityRecognizer.ts
|
|
3
|
-
* @description Internal interface contract for all PII entity recognisers used
|
|
4
|
-
* within the detection pipeline.
|
|
5
|
-
*
|
|
6
|
-
* Each detection tier (regex, NER model, LLM judge, denylist) implements this
|
|
7
|
-
* interface so the orchestrating {@link PiiDetectionService} can treat them
|
|
8
|
-
* uniformly — iterating, filtering by capability, and composing results
|
|
9
|
-
* without coupling to concrete implementations.
|
|
10
|
-
*
|
|
11
|
-
* @module pii-redaction/recognizers
|
|
12
|
-
*/
|
|
13
|
-
import type { PiiEntity, PiiEntityType } from '../types';
|
|
14
|
-
/**
|
|
15
|
-
* Options passed to {@link IEntityRecognizer.recognize} on every call.
|
|
16
|
-
*
|
|
17
|
-
* Recognisers are encouraged (but not required) to honour all fields;
|
|
18
|
-
* a recogniser that cannot make use of a field should silently ignore it
|
|
19
|
-
* rather than throwing.
|
|
20
|
-
*/
|
|
21
|
-
export interface RecognizeOptions {
|
|
22
|
-
/**
|
|
23
|
-
* Subset of entity types the caller is interested in.
|
|
24
|
-
* The recogniser SHOULD skip detection for types not in this list to avoid
|
|
25
|
-
* redundant work. If the array is empty or omitted the recogniser should
|
|
26
|
-
* use its own default set (typically everything it supports).
|
|
27
|
-
*/
|
|
28
|
-
entityTypes?: PiiEntityType[];
|
|
29
|
-
/**
|
|
30
|
-
* BCP-47 language tag of the input text (e.g. `'en'`, `'de'`, `'zh-Hans'`).
|
|
31
|
-
* Recognisers that are language-sensitive (e.g. an NER model) use this to
|
|
32
|
-
* select the correct model variant or pattern set.
|
|
33
|
-
* @default `'en'`
|
|
34
|
-
*/
|
|
35
|
-
language?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Optional surrounding context provided by the caller — typically the full
|
|
38
|
-
* conversation turn or document paragraph from which the input chunk was
|
|
39
|
-
* extracted. Recognisers (especially the LLM judge) may use this wider
|
|
40
|
-
* context to resolve ambiguous spans more accurately.
|
|
41
|
-
*
|
|
42
|
-
* The context string is NOT itself subject to detection in this call; it is
|
|
43
|
-
* purely informational.
|
|
44
|
-
*/
|
|
45
|
-
context?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Entities already discovered by previously-run recognisers in the same
|
|
48
|
-
* pipeline pass. A recogniser may use these to avoid emitting duplicate
|
|
49
|
-
* spans, to improve confidence scoring on overlapping regions, or to skip
|
|
50
|
-
* re-examining character ranges already confirmed by an earlier tier.
|
|
51
|
-
*/
|
|
52
|
-
priorEntities?: PiiEntity[];
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Contract that every entity recogniser in the PII detection pipeline must
|
|
56
|
-
* satisfy.
|
|
57
|
-
*
|
|
58
|
-
* Recognisers are stateless with respect to individual calls: all per-call
|
|
59
|
-
* configuration is passed via {@link RecognizeOptions}. Long-lived state
|
|
60
|
-
* (e.g. a loaded NER model, an LRU response cache) is kept in the
|
|
61
|
-
* implementing class and initialised once at construction or on first use.
|
|
62
|
-
*
|
|
63
|
-
* ### Lifecycle
|
|
64
|
-
* 1. The {@link PiiDetectionService} instantiates recognisers at pack startup.
|
|
65
|
-
* 2. {@link recognize} is called once per input chunk for every detection pass.
|
|
66
|
-
* 3. {@link dispose} is called when the pack is torn down (agent shutdown or
|
|
67
|
-
* hot-reload). Implementations MUST release native resources (model
|
|
68
|
-
* handles, open file descriptors, HTTP keep-alive connections) here.
|
|
69
|
-
*
|
|
70
|
-
* @example Minimal regex-only recogniser
|
|
71
|
-
* ```ts
|
|
72
|
-
* class EmailRecognizer implements IEntityRecognizer {
|
|
73
|
-
* readonly name = 'EmailRecognizer';
|
|
74
|
-
* readonly supportedEntities: PiiEntityType[] = ['EMAIL'];
|
|
75
|
-
*
|
|
76
|
-
* async recognize(input: string, options?: RecognizeOptions): Promise<PiiEntity[]> {
|
|
77
|
-
* const EMAIL_RE = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
|
|
78
|
-
* const entities: PiiEntity[] = [];
|
|
79
|
-
* let m: RegExpExecArray | null;
|
|
80
|
-
* while ((m = EMAIL_RE.exec(input)) !== null) {
|
|
81
|
-
* entities.push({
|
|
82
|
-
* entityType: 'EMAIL',
|
|
83
|
-
* text: m[0],
|
|
84
|
-
* start: m.index,
|
|
85
|
-
* end: m.index + m[0].length,
|
|
86
|
-
* score: 1.0,
|
|
87
|
-
* source: 'regex',
|
|
88
|
-
* });
|
|
89
|
-
* }
|
|
90
|
-
* return entities;
|
|
91
|
-
* }
|
|
92
|
-
*
|
|
93
|
-
* async dispose(): Promise<void> { /* nothing to release *\/ }
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export interface IEntityRecognizer {
|
|
98
|
-
/**
|
|
99
|
-
* Human-readable name used in log messages and observability traces.
|
|
100
|
-
* Should be unique within a running pipeline but is not enforced by the
|
|
101
|
-
* registry.
|
|
102
|
-
*
|
|
103
|
-
* @example `'RegexRecognizer'`, `'SpacyNerRecognizer'`, `'OpenAiLlmJudge'`
|
|
104
|
-
*/
|
|
105
|
-
readonly name: string;
|
|
106
|
-
/**
|
|
107
|
-
* The set of {@link PiiEntityType} values this recogniser is capable of
|
|
108
|
-
* detecting.
|
|
109
|
-
*
|
|
110
|
-
* The {@link PiiDetectionService} uses this list to route detection work:
|
|
111
|
-
* if the caller requests only `['EMAIL', 'PHONE']` and a recogniser's
|
|
112
|
-
* `supportedEntities` has no overlap, the recogniser is skipped entirely for
|
|
113
|
-
* that call.
|
|
114
|
-
*/
|
|
115
|
-
readonly supportedEntities: PiiEntityType[];
|
|
116
|
-
/**
|
|
117
|
-
* Scan `input` for PII entities and return all matches above the
|
|
118
|
-
* recogniser's internal confidence threshold.
|
|
119
|
-
*
|
|
120
|
-
* Implementations MUST:
|
|
121
|
-
* - Return an empty array (never `null` or `undefined`) when no PII is found.
|
|
122
|
-
* - Not mutate `input` or any object in `options.priorEntities`.
|
|
123
|
-
* - Be safe to call concurrently from multiple async contexts (i.e. avoid
|
|
124
|
-
* shared mutable state that is not protected by a lock or queue).
|
|
125
|
-
*
|
|
126
|
-
* Implementations SHOULD:
|
|
127
|
-
* - Respect `options.entityTypes` and skip patterns outside that set.
|
|
128
|
-
* - Set `PiiEntity.source` to the appropriate tier identifier.
|
|
129
|
-
* - Return overlapping spans only when they carry meaningfully different
|
|
130
|
-
* semantic labels; prefer the highest-confidence span otherwise.
|
|
131
|
-
*
|
|
132
|
-
* @param input - The raw text string to analyse. May be a partial chunk
|
|
133
|
-
* when called from the streaming evaluator.
|
|
134
|
-
* @param options - Per-call tuning parameters. All fields are optional.
|
|
135
|
-
* @returns A promise resolving to an array of detected {@link PiiEntity}
|
|
136
|
-
* objects, possibly empty.
|
|
137
|
-
*/
|
|
138
|
-
recognize(input: string, options?: RecognizeOptions): Promise<PiiEntity[]>;
|
|
139
|
-
/**
|
|
140
|
-
* Release all resources held by this recogniser instance.
|
|
141
|
-
*
|
|
142
|
-
* Called by the {@link PiiDetectionService} during agent shutdown or when
|
|
143
|
-
* the pack is dynamically unloaded. After `dispose()` resolves, `recognize`
|
|
144
|
-
* MUST NOT be called again; the behaviour is undefined if it is.
|
|
145
|
-
*
|
|
146
|
-
* Implementations that hold no resources may return a resolved promise
|
|
147
|
-
* immediately: `async dispose() {}`.
|
|
148
|
-
*/
|
|
149
|
-
dispose(): Promise<void>;
|
|
150
|
-
}
|
|
151
|
-
//# sourceMappingURL=IEntityRecognizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IEntityRecognizer.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/packs/pii-redaction/recognizers/IEntityRecognizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzD;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;IAE9B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC;CAC7B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;;;OAQG;IACH,QAAQ,CAAC,iBAAiB,EAAE,aAAa,EAAE,CAAC;IAE5C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAE3E;;;;;;;;;OASG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file IEntityRecognizer.ts
|
|
3
|
-
* @description Internal interface contract for all PII entity recognisers used
|
|
4
|
-
* within the detection pipeline.
|
|
5
|
-
*
|
|
6
|
-
* Each detection tier (regex, NER model, LLM judge, denylist) implements this
|
|
7
|
-
* interface so the orchestrating {@link PiiDetectionService} can treat them
|
|
8
|
-
* uniformly — iterating, filtering by capability, and composing results
|
|
9
|
-
* without coupling to concrete implementations.
|
|
10
|
-
*
|
|
11
|
-
* @module pii-redaction/recognizers
|
|
12
|
-
*/
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=IEntityRecognizer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IEntityRecognizer.js","sourceRoot":"","sources":["../../../../../src/extensions/packs/pii-redaction/recognizers/IEntityRecognizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file LlmJudgeRecognizer.ts
|
|
3
|
-
* @description Tier 4 LLM-powered judge that re-examines individual PII
|
|
4
|
-
* entity candidates using a chain-of-thought (CoT) prompt.
|
|
5
|
-
*
|
|
6
|
-
* Unlike the other recognisers, this class does **not** implement
|
|
7
|
-
* {@link IEntityRecognizer} because it operates on already-detected entities
|
|
8
|
-
* rather than raw text. Its primary entry point is
|
|
9
|
-
* {@link LlmJudgeRecognizer.judge}, which takes a single {@link PiiEntity}
|
|
10
|
-
* plus the surrounding full text and returns either a confirmed/reclassified
|
|
11
|
-
* entity or `null` if the LLM determines the span is not PII.
|
|
12
|
-
*
|
|
13
|
-
* ### Key features
|
|
14
|
-
* - **Chain-of-thought prompt**: Forces the LLM to reason before classifying,
|
|
15
|
-
* improving accuracy on ambiguous spans.
|
|
16
|
-
* - **LRU cache**: Keyed by `(span_text, context_hash)` to avoid redundant
|
|
17
|
-
* calls for identical spans in similar contexts.
|
|
18
|
-
* - **Semaphore**: Limits concurrent LLM requests to prevent rate-limit
|
|
19
|
-
* exhaustion on high-throughput agents.
|
|
20
|
-
* - **Fail-open**: If the LLM call fails for any reason, the original entity
|
|
21
|
-
* is returned unchanged (conservative — prefer false positive over leak).
|
|
22
|
-
*
|
|
23
|
-
* @module pii-redaction/recognizers
|
|
24
|
-
*/
|
|
25
|
-
import type { PiiEntity, LlmJudgeConfig } from '../types';
|
|
26
|
-
/**
|
|
27
|
-
* Minimal fetch-compatible function signature. Allows injection of a mock
|
|
28
|
-
* fetch in tests without depending on the global `fetch` or any HTTP library.
|
|
29
|
-
*/
|
|
30
|
-
type FetchFn = (url: string, init: {
|
|
31
|
-
method: string;
|
|
32
|
-
headers: Record<string, string>;
|
|
33
|
-
body: string;
|
|
34
|
-
}) => Promise<{
|
|
35
|
-
ok: boolean;
|
|
36
|
-
status: number;
|
|
37
|
-
json(): Promise<unknown>;
|
|
38
|
-
}>;
|
|
39
|
-
/**
|
|
40
|
-
* Tier 4 LLM-powered judge that confirms or reclassifies individual PII
|
|
41
|
-
* entity candidates using chain-of-thought reasoning.
|
|
42
|
-
*
|
|
43
|
-
* ### Usage pattern
|
|
44
|
-
* ```ts
|
|
45
|
-
* const judge = new LlmJudgeRecognizer(config);
|
|
46
|
-
* const result = await judge.judge(candidateEntity, fullText);
|
|
47
|
-
* if (result === null) {
|
|
48
|
-
* // LLM says it's not PII — discard the candidate.
|
|
49
|
-
* } else {
|
|
50
|
-
* // Use the confirmed/reclassified entity.
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* ### Caching
|
|
55
|
-
* Results are cached by a composite key of the span text and a hash of
|
|
56
|
-
* the surrounding context. This means identical spans in similar contexts
|
|
57
|
-
* won't trigger redundant LLM calls.
|
|
58
|
-
*
|
|
59
|
-
* ### Concurrency control
|
|
60
|
-
* A counting semaphore limits the number of in-flight LLM requests to
|
|
61
|
-
* {@link LlmJudgeConfig.maxConcurrency} (default 3), preventing rate-limit
|
|
62
|
-
* errors when many entities are judged in parallel.
|
|
63
|
-
*
|
|
64
|
-
* ### Failure mode
|
|
65
|
-
* The judge is **fail-open**: if the LLM call fails (network error, invalid
|
|
66
|
-
* response, timeout), the original entity is returned unchanged. This is
|
|
67
|
-
* the conservative choice — a false positive (over-redaction) is preferable
|
|
68
|
-
* to leaking real PII.
|
|
69
|
-
*/
|
|
70
|
-
export declare class LlmJudgeRecognizer {
|
|
71
|
-
/** Human-readable name for logging/diagnostics. */
|
|
72
|
-
readonly name = "LlmJudgeRecognizer";
|
|
73
|
-
/** The LLM judge configuration. */
|
|
74
|
-
private readonly config;
|
|
75
|
-
/** LRU cache keyed by `(span_text, context_hash)`. */
|
|
76
|
-
private readonly cache;
|
|
77
|
-
/** Semaphore to limit concurrent LLM requests. */
|
|
78
|
-
private readonly semaphore;
|
|
79
|
-
/** Injectable fetch implementation (defaults to global fetch). */
|
|
80
|
-
private readonly fetchImpl;
|
|
81
|
-
/**
|
|
82
|
-
* Construct a new LlmJudgeRecognizer.
|
|
83
|
-
*
|
|
84
|
-
* @param config - LLM provider/model configuration.
|
|
85
|
-
* @param fetchImpl - Optional injectable fetch function for testing.
|
|
86
|
-
* Defaults to the global `fetch`.
|
|
87
|
-
*/
|
|
88
|
-
constructor(config: LlmJudgeConfig, fetchImpl?: FetchFn);
|
|
89
|
-
/**
|
|
90
|
-
* Judge a single PII entity candidate in context.
|
|
91
|
-
*
|
|
92
|
-
* @param entity - The candidate entity to evaluate.
|
|
93
|
-
* @param fullText - The full text from which the entity was extracted,
|
|
94
|
-
* providing the LLM with surrounding context.
|
|
95
|
-
* @returns The confirmed/reclassified entity, or `null` if the LLM
|
|
96
|
-
* determines the span is not PII.
|
|
97
|
-
*/
|
|
98
|
-
judge(entity: PiiEntity, fullText: string): Promise<PiiEntity | null>;
|
|
99
|
-
/**
|
|
100
|
-
* Builds the cache key from the span text and a simple hash of the
|
|
101
|
-
* surrounding context.
|
|
102
|
-
*
|
|
103
|
-
* The context hash uses a fast DJB2 hash — sufficient for cache-key
|
|
104
|
-
* purposes without requiring a cryptographic hash function.
|
|
105
|
-
*
|
|
106
|
-
* @param spanText - The matched text span.
|
|
107
|
-
* @param context - The full surrounding text.
|
|
108
|
-
* @returns A composite cache key string.
|
|
109
|
-
*/
|
|
110
|
-
private buildCacheKey;
|
|
111
|
-
/**
|
|
112
|
-
* DJB2 hash function by Daniel J. Bernstein.
|
|
113
|
-
* Fast, non-cryptographic hash suitable for hash-table keys.
|
|
114
|
-
*
|
|
115
|
-
* @param str - String to hash.
|
|
116
|
-
* @returns Hex string representation of the hash.
|
|
117
|
-
*/
|
|
118
|
-
private djb2Hash;
|
|
119
|
-
/**
|
|
120
|
-
* Builds the user prompt containing the span text and its surrounding
|
|
121
|
-
* context for the LLM to evaluate.
|
|
122
|
-
*
|
|
123
|
-
* @param entity - The candidate entity.
|
|
124
|
-
* @param fullText - The full text for context.
|
|
125
|
-
* @returns The formatted user prompt string.
|
|
126
|
-
*/
|
|
127
|
-
private buildUserPrompt;
|
|
128
|
-
/**
|
|
129
|
-
* Calls the LLM via OpenAI-compatible chat completions API.
|
|
130
|
-
*
|
|
131
|
-
* Uses raw `fetch` (no SDK dependency) to keep the extension lightweight
|
|
132
|
-
* and to support any OpenAI-compatible endpoint (OpenRouter, vLLM, etc.).
|
|
133
|
-
*
|
|
134
|
-
* @param userPrompt - The user message content.
|
|
135
|
-
* @returns Parsed LLM judgement response.
|
|
136
|
-
* @throws If the API call fails or the response is not valid JSON.
|
|
137
|
-
*/
|
|
138
|
-
private callLlm;
|
|
139
|
-
/**
|
|
140
|
-
* Parses the LLM's response content into a structured judgement object.
|
|
141
|
-
*
|
|
142
|
-
* Handles common LLM response quirks:
|
|
143
|
-
* - Markdown code fences around JSON
|
|
144
|
-
* - Leading/trailing whitespace
|
|
145
|
-
*
|
|
146
|
-
* @param content - Raw response content string from the LLM.
|
|
147
|
-
* @returns Parsed {@link LlmJudgement}.
|
|
148
|
-
* @throws If the content cannot be parsed as valid JSON.
|
|
149
|
-
*/
|
|
150
|
-
private parseJudgement;
|
|
151
|
-
/**
|
|
152
|
-
* Processes the LLM's judgement and returns the appropriate result.
|
|
153
|
-
*
|
|
154
|
-
* - If the LLM says the span is NOT PII, returns `null`.
|
|
155
|
-
* - If the LLM confirms PII, returns an updated entity with the LLM's
|
|
156
|
-
* classification and confidence, preserving the original values in
|
|
157
|
-
* metadata for audit.
|
|
158
|
-
*
|
|
159
|
-
* @param judgement - The parsed LLM response.
|
|
160
|
-
* @param original - The original candidate entity.
|
|
161
|
-
* @returns Updated entity or `null`.
|
|
162
|
-
*/
|
|
163
|
-
private processJudgement;
|
|
164
|
-
/**
|
|
165
|
-
* Maps the LLM's entity type string to our {@link PiiEntityType}.
|
|
166
|
-
*
|
|
167
|
-
* If the LLM returns a recognised type string, it is used directly.
|
|
168
|
-
* Otherwise, the original entity type is preserved.
|
|
169
|
-
*
|
|
170
|
-
* @param llmType - Entity type string from the LLM response.
|
|
171
|
-
* @param fallback - Original entity type to use as fallback.
|
|
172
|
-
* @returns Resolved PiiEntityType.
|
|
173
|
-
*/
|
|
174
|
-
private mapLlmEntityType;
|
|
175
|
-
}
|
|
176
|
-
export {};
|
|
177
|
-
//# sourceMappingURL=LlmJudgeRecognizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LlmJudgeRecognizer.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/packs/pii-redaction/recognizers/LlmJudgeRecognizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAiB,cAAc,EAAE,MAAM,UAAU,CAAC;AAkLzE;;;GAGG;AACH,KAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd,KAAK,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,CAAC;AAMzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,kBAAkB;IAC7B,mDAAmD;IACnD,SAAgB,IAAI,wBAAwB;IAE5C,mCAAmC;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IAExC,sDAAsD;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IAEnD,kDAAkD;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IAEtC,kEAAkE;IAClE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAU;IAEpC;;;;;;OAMG;gBACS,MAAM,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,OAAO;IAOvD;;;;;;;;OAQG;IACU,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAyClF;;;;;;;;;;OAUG;IACH,OAAO,CAAC,aAAa;IAKrB;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAShB;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAevB;;;;;;;;;OASG;YACW,OAAO;IAoCrB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,cAAc;IAatB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gBAAgB;IA+BxB;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;CAezB"}
|