@agentlensai/server 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db/anonymous-id-manager.d.ts +44 -0
- package/dist/db/anonymous-id-manager.d.ts.map +1 -0
- package/dist/db/anonymous-id-manager.js +90 -0
- package/dist/db/anonymous-id-manager.js.map +1 -0
- package/dist/db/capability-store.d.ts +78 -0
- package/dist/db/capability-store.d.ts.map +1 -0
- package/dist/db/capability-store.js +201 -0
- package/dist/db/capability-store.js.map +1 -0
- package/dist/db/guardrail-store.d.ts +34 -0
- package/dist/db/guardrail-store.d.ts.map +1 -0
- package/dist/db/guardrail-store.js +221 -0
- package/dist/db/guardrail-store.js.map +1 -0
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +200 -0
- package/dist/db/migrate.js.map +1 -1
- package/dist/db/schema.sqlite.d.ts +1719 -1
- package/dist/db/schema.sqlite.d.ts.map +1 -1
- package/dist/db/schema.sqlite.js +141 -1
- package/dist/db/schema.sqlite.js.map +1 -1
- package/dist/db/sqlite-store.d.ts +12 -0
- package/dist/db/sqlite-store.d.ts.map +1 -1
- package/dist/db/sqlite-store.js +47 -0
- package/dist/db/sqlite-store.js.map +1 -1
- package/dist/db/tenant-scoped-store.d.ts +1 -0
- package/dist/db/tenant-scoped-store.d.ts.map +1 -1
- package/dist/db/tenant-scoped-store.js +3 -0
- package/dist/db/tenant-scoped-store.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/guardrails/actions.d.ts +28 -0
- package/dist/lib/guardrails/actions.d.ts.map +1 -0
- package/dist/lib/guardrails/actions.js +126 -0
- package/dist/lib/guardrails/actions.js.map +1 -0
- package/dist/lib/guardrails/conditions.d.ts +13 -0
- package/dist/lib/guardrails/conditions.d.ts.map +1 -0
- package/dist/lib/guardrails/conditions.js +188 -0
- package/dist/lib/guardrails/conditions.js.map +1 -0
- package/dist/lib/guardrails/engine.d.ts +24 -0
- package/dist/lib/guardrails/engine.d.ts.map +1 -0
- package/dist/lib/guardrails/engine.js +122 -0
- package/dist/lib/guardrails/engine.js.map +1 -0
- package/dist/lib/redaction/human-review-layer.d.ts +37 -0
- package/dist/lib/redaction/human-review-layer.d.ts.map +1 -0
- package/dist/lib/redaction/human-review-layer.js +62 -0
- package/dist/lib/redaction/human-review-layer.js.map +1 -0
- package/dist/lib/redaction/index.d.ts +12 -0
- package/dist/lib/redaction/index.d.ts.map +1 -0
- package/dist/lib/redaction/index.js +12 -0
- package/dist/lib/redaction/index.js.map +1 -0
- package/dist/lib/redaction/pii-detection-layer.d.ts +30 -0
- package/dist/lib/redaction/pii-detection-layer.d.ts.map +1 -0
- package/dist/lib/redaction/pii-detection-layer.js +183 -0
- package/dist/lib/redaction/pii-detection-layer.js.map +1 -0
- package/dist/lib/redaction/pipeline.d.ts +26 -0
- package/dist/lib/redaction/pipeline.d.ts.map +1 -0
- package/dist/lib/redaction/pipeline.js +91 -0
- package/dist/lib/redaction/pipeline.js.map +1 -0
- package/dist/lib/redaction/secret-detection-layer.d.ts +10 -0
- package/dist/lib/redaction/secret-detection-layer.d.ts.map +1 -0
- package/dist/lib/redaction/secret-detection-layer.js +79 -0
- package/dist/lib/redaction/secret-detection-layer.js.map +1 -0
- package/dist/lib/redaction/secret-patterns.d.ts +29 -0
- package/dist/lib/redaction/secret-patterns.d.ts.map +1 -0
- package/dist/lib/redaction/secret-patterns.js +133 -0
- package/dist/lib/redaction/secret-patterns.js.map +1 -0
- package/dist/lib/redaction/semantic-denylist-layer.d.ts +10 -0
- package/dist/lib/redaction/semantic-denylist-layer.d.ts.map +1 -0
- package/dist/lib/redaction/semantic-denylist-layer.js +64 -0
- package/dist/lib/redaction/semantic-denylist-layer.js.map +1 -0
- package/dist/lib/redaction/tenant-deidentification-layer.d.ts +10 -0
- package/dist/lib/redaction/tenant-deidentification-layer.d.ts.map +1 -0
- package/dist/lib/redaction/tenant-deidentification-layer.js +64 -0
- package/dist/lib/redaction/tenant-deidentification-layer.js.map +1 -0
- package/dist/lib/redaction/url-path-scrubbing-layer.d.ts +14 -0
- package/dist/lib/redaction/url-path-scrubbing-layer.d.ts.map +1 -0
- package/dist/lib/redaction/url-path-scrubbing-layer.js +156 -0
- package/dist/lib/redaction/url-path-scrubbing-layer.js.map +1 -0
- package/dist/routes/agents.d.ts +4 -3
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/agents.js +31 -12
- package/dist/routes/agents.js.map +1 -1
- package/dist/routes/audit.d.ts +15 -0
- package/dist/routes/audit.d.ts.map +1 -0
- package/dist/routes/audit.js +177 -0
- package/dist/routes/audit.js.map +1 -0
- package/dist/routes/capabilities.d.ts +15 -0
- package/dist/routes/capabilities.d.ts.map +1 -0
- package/dist/routes/capabilities.js +86 -0
- package/dist/routes/capabilities.js.map +1 -0
- package/dist/routes/community.d.ts +24 -0
- package/dist/routes/community.d.ts.map +1 -0
- package/dist/routes/community.js +190 -0
- package/dist/routes/community.js.map +1 -0
- package/dist/routes/delegation.d.ts +20 -0
- package/dist/routes/delegation.d.ts.map +1 -0
- package/dist/routes/delegation.js +108 -0
- package/dist/routes/delegation.js.map +1 -0
- package/dist/routes/discovery.d.ts +19 -0
- package/dist/routes/discovery.d.ts.map +1 -0
- package/dist/routes/discovery.js +96 -0
- package/dist/routes/discovery.js.map +1 -0
- package/dist/routes/guardrails.d.ts +18 -0
- package/dist/routes/guardrails.d.ts.map +1 -0
- package/dist/routes/guardrails.js +184 -0
- package/dist/routes/guardrails.js.map +1 -0
- package/dist/routes/redaction-test.d.ts +14 -0
- package/dist/routes/redaction-test.d.ts.map +1 -0
- package/dist/routes/redaction-test.js +33 -0
- package/dist/routes/redaction-test.js.map +1 -0
- package/dist/routes/trust.d.ts +16 -0
- package/dist/routes/trust.d.ts.map +1 -0
- package/dist/routes/trust.js +23 -0
- package/dist/routes/trust.js.map +1 -0
- package/dist/services/community-service.d.ts +277 -0
- package/dist/services/community-service.d.ts.map +1 -0
- package/dist/services/community-service.js +785 -0
- package/dist/services/community-service.js.map +1 -0
- package/dist/services/delegation-service.d.ts +149 -0
- package/dist/services/delegation-service.d.ts.map +1 -0
- package/dist/services/delegation-service.js +605 -0
- package/dist/services/delegation-service.js.map +1 -0
- package/dist/services/discovery-service.d.ts +39 -0
- package/dist/services/discovery-service.d.ts.map +1 -0
- package/dist/services/discovery-service.js +186 -0
- package/dist/services/discovery-service.js.map +1 -0
- package/dist/services/trust-service.d.ts +59 -0
- package/dist/services/trust-service.d.ts.map +1 -0
- package/dist/services/trust-service.js +139 -0
- package/dist/services/trust-service.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guardrail Evaluation Engine (v0.8.0 — Story 1.3)
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to EventBus and evaluates guardrail rules asynchronously.
|
|
5
|
+
* Never blocks the event POST response.
|
|
6
|
+
*/
|
|
7
|
+
import { ulid } from 'ulid';
|
|
8
|
+
import { GuardrailStore } from '../../db/guardrail-store.js';
|
|
9
|
+
import { evaluateCondition } from './conditions.js';
|
|
10
|
+
import { executeAction } from './actions.js';
|
|
11
|
+
import { eventBus } from '../event-bus.js';
|
|
12
|
+
export class GuardrailEngine {
|
|
13
|
+
store;
|
|
14
|
+
eventStore;
|
|
15
|
+
listener = null;
|
|
16
|
+
started = false;
|
|
17
|
+
constructor(eventStore, db) {
|
|
18
|
+
this.eventStore = eventStore;
|
|
19
|
+
this.store = new GuardrailStore(db);
|
|
20
|
+
}
|
|
21
|
+
start() {
|
|
22
|
+
if (this.started)
|
|
23
|
+
return;
|
|
24
|
+
this.listener = (busEvent) => {
|
|
25
|
+
if (busEvent.type === 'event_ingested') {
|
|
26
|
+
this.evaluateEvent(busEvent.event).catch((err) => {
|
|
27
|
+
console.error('[guardrail-engine] evaluation error:', err instanceof Error ? err.message : err);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
eventBus.on('event_ingested', this.listener);
|
|
32
|
+
this.started = true;
|
|
33
|
+
}
|
|
34
|
+
stop() {
|
|
35
|
+
if (this.listener) {
|
|
36
|
+
eventBus.off('event_ingested', this.listener);
|
|
37
|
+
this.listener = null;
|
|
38
|
+
}
|
|
39
|
+
this.started = false;
|
|
40
|
+
}
|
|
41
|
+
getStore() {
|
|
42
|
+
return this.store;
|
|
43
|
+
}
|
|
44
|
+
async evaluateEvent(event) {
|
|
45
|
+
const rules = this.store.listEnabledRules(event.tenantId, event.agentId);
|
|
46
|
+
if (rules.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
for (const rule of rules) {
|
|
49
|
+
try {
|
|
50
|
+
await this.evaluateRule(rule, event);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.error(`[guardrail-engine] rule ${rule.id} error:`, err instanceof Error ? err.message : err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async evaluateRule(rule, event) {
|
|
58
|
+
const now = new Date();
|
|
59
|
+
// 0. Check enabled (defense-in-depth — listEnabledRules already filters, but verify)
|
|
60
|
+
if (!rule.enabled)
|
|
61
|
+
return;
|
|
62
|
+
// 1. Check cooldown
|
|
63
|
+
if (this.isInCooldown(rule, now))
|
|
64
|
+
return;
|
|
65
|
+
// 2. Evaluate condition
|
|
66
|
+
const conditionResult = await evaluateCondition(this.eventStore, rule, event.agentId, event.sessionId);
|
|
67
|
+
// 3. Update state
|
|
68
|
+
const existingState = this.store.getState(rule.tenantId, rule.id);
|
|
69
|
+
const newState = {
|
|
70
|
+
ruleId: rule.id,
|
|
71
|
+
tenantId: rule.tenantId,
|
|
72
|
+
lastEvaluatedAt: now.toISOString(),
|
|
73
|
+
currentValue: conditionResult.currentValue,
|
|
74
|
+
triggerCount: existingState?.triggerCount ?? 0,
|
|
75
|
+
lastTriggeredAt: existingState?.lastTriggeredAt,
|
|
76
|
+
};
|
|
77
|
+
if (!conditionResult.triggered) {
|
|
78
|
+
this.store.upsertState(newState);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// 4. Execute action (or dry-run)
|
|
82
|
+
let actionResult = 'dry_run';
|
|
83
|
+
let actionExecuted = false;
|
|
84
|
+
if (!rule.dryRun) {
|
|
85
|
+
const result = await executeAction(rule, conditionResult, event.agentId);
|
|
86
|
+
actionResult = result.result;
|
|
87
|
+
actionExecuted = result.success;
|
|
88
|
+
}
|
|
89
|
+
// 5. Record trigger history
|
|
90
|
+
this.store.insertTrigger({
|
|
91
|
+
id: ulid(),
|
|
92
|
+
ruleId: rule.id,
|
|
93
|
+
tenantId: rule.tenantId,
|
|
94
|
+
triggeredAt: now.toISOString(),
|
|
95
|
+
conditionValue: conditionResult.currentValue,
|
|
96
|
+
conditionThreshold: conditionResult.threshold,
|
|
97
|
+
actionExecuted,
|
|
98
|
+
actionResult,
|
|
99
|
+
metadata: {
|
|
100
|
+
agentId: event.agentId,
|
|
101
|
+
sessionId: event.sessionId,
|
|
102
|
+
eventId: event.id,
|
|
103
|
+
dryRun: rule.dryRun,
|
|
104
|
+
message: conditionResult.message,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
// 6. Update state
|
|
108
|
+
newState.triggerCount = (existingState?.triggerCount ?? 0) + 1;
|
|
109
|
+
newState.lastTriggeredAt = now.toISOString();
|
|
110
|
+
this.store.upsertState(newState);
|
|
111
|
+
}
|
|
112
|
+
isInCooldown(rule, now) {
|
|
113
|
+
if (rule.cooldownMinutes <= 0)
|
|
114
|
+
return false;
|
|
115
|
+
const state = this.store.getState(rule.tenantId, rule.id);
|
|
116
|
+
if (!state?.lastTriggeredAt)
|
|
117
|
+
return false;
|
|
118
|
+
const lastTriggered = new Date(state.lastTriggeredAt);
|
|
119
|
+
return now.getTime() - lastTriggered.getTime() < rule.cooldownMinutes * 60 * 1000;
|
|
120
|
+
}
|
|
121
|
+
}
|
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,SAAS;YAC7C,cAAc;YACd,YAAY;YACZ,QAAQ,EAAE;gBACR,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,OAAO,EAAE,KAAK,CAAC,EAAE;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,OAAO,EAAE,eAAe,CAAC,OAAO;aACjC;SACF,CAAC,CAAC;QAEH,kBAAkB;QAClB,QAAQ,CAAC,YAAY,GAAG,CAAC,aAAa,EAAE,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/D,QAAQ,CAAC,eAAe,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAEO,YAAY,CAAC,IAAmB,EAAE,GAAS;QACjD,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,EAAE,eAAe;YAAE,OAAO,KAAK,CAAC;QAC1C,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACtD,OAAO,GAAG,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;IACpF,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 6: Human Review Gate (Story 2.2)
|
|
3
|
+
*/
|
|
4
|
+
import type { RedactionLayer, RedactionLayerResult, RedactionContext } from '@agentlensai/core';
|
|
5
|
+
/** Interface for the review queue store */
|
|
6
|
+
export interface ReviewQueueStore {
|
|
7
|
+
addToQueue(entry: {
|
|
8
|
+
id: string;
|
|
9
|
+
tenantId: string;
|
|
10
|
+
lessonId: string;
|
|
11
|
+
originalTitle: string;
|
|
12
|
+
originalContent: string;
|
|
13
|
+
redactedTitle: string;
|
|
14
|
+
redactedContent: string;
|
|
15
|
+
redactionFindings: string;
|
|
16
|
+
status: string;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
expiresAt: string;
|
|
19
|
+
}): void | Promise<void>;
|
|
20
|
+
getReviewStatus(reviewId: string): Promise<{
|
|
21
|
+
status: string;
|
|
22
|
+
} | null> | {
|
|
23
|
+
status: string;
|
|
24
|
+
} | null;
|
|
25
|
+
approveReview(reviewId: string, reviewedBy: string): void | Promise<void>;
|
|
26
|
+
rejectReview(reviewId: string, reviewedBy: string): void | Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare class HumanReviewLayer implements RedactionLayer {
|
|
29
|
+
private readonly enabled;
|
|
30
|
+
private readonly store?;
|
|
31
|
+
private readonly generateId;
|
|
32
|
+
readonly name: "human_review";
|
|
33
|
+
readonly order = 600;
|
|
34
|
+
constructor(enabled?: boolean, store?: ReviewQueueStore | undefined, generateId?: () => string);
|
|
35
|
+
process(input: string, _context: RedactionContext): Promise<RedactionLayerResult>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=human-review-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-review-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/redaction/human-review-layer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,mBAAmB,CAAC;AAE3B,2CAA2C;AAC3C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,KAAK,EAAE;QAChB,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAA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
+
enabled;
|
|
6
|
+
store;
|
|
7
|
+
generateId;
|
|
8
|
+
name = 'human_review';
|
|
9
|
+
order = 600;
|
|
10
|
+
constructor(enabled = false, store, generateId = () => crypto.randomUUID()) {
|
|
11
|
+
this.enabled = enabled;
|
|
12
|
+
this.store = store;
|
|
13
|
+
this.generateId = generateId;
|
|
14
|
+
}
|
|
15
|
+
async process(input, _context) {
|
|
16
|
+
if (!this.enabled) {
|
|
17
|
+
// Pass-through when disabled
|
|
18
|
+
return { output: input, findings: [], blocked: false };
|
|
19
|
+
}
|
|
20
|
+
if (!this.store) {
|
|
21
|
+
// If enabled but no store provided, block (fail-closed)
|
|
22
|
+
return {
|
|
23
|
+
output: input,
|
|
24
|
+
findings: [],
|
|
25
|
+
blocked: true,
|
|
26
|
+
blockReason: 'Human review is enabled but no review queue store is configured',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const reviewId = this.generateId();
|
|
30
|
+
const now = new Date();
|
|
31
|
+
const expiresAt = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000); // 7 days
|
|
32
|
+
await this.store.addToQueue({
|
|
33
|
+
id: reviewId,
|
|
34
|
+
tenantId: _context.tenantId,
|
|
35
|
+
lessonId: '', // filled by pipeline
|
|
36
|
+
originalTitle: '',
|
|
37
|
+
originalContent: '',
|
|
38
|
+
redactedTitle: '',
|
|
39
|
+
redactedContent: input,
|
|
40
|
+
redactionFindings: '[]',
|
|
41
|
+
status: 'pending',
|
|
42
|
+
createdAt: now.toISOString(),
|
|
43
|
+
expiresAt: expiresAt.toISOString(),
|
|
44
|
+
});
|
|
45
|
+
const finding = {
|
|
46
|
+
layer: 'human_review',
|
|
47
|
+
category: 'pending_review',
|
|
48
|
+
originalLength: input.length,
|
|
49
|
+
replacement: '',
|
|
50
|
+
startOffset: 0,
|
|
51
|
+
endOffset: input.length,
|
|
52
|
+
confidence: 1.0,
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
output: input,
|
|
56
|
+
findings: [finding],
|
|
57
|
+
blocked: true,
|
|
58
|
+
blockReason: `pending_review:${reviewId}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=human-review-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-review-layer.js","sourceRoot":"","sources":["../../../src/lib/redaction/human-review-layer.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8BH,MAAM,OAAO,gBAAgB;IAKR;IACA;IACA;IANV,IAAI,GAAG,cAAuB,CAAC;IAC/B,KAAK,GAAG,GAAG,CAAC;IAErB,YACmB,UAAmB,KAAK,EACxB,KAAwB,EACxB,aAA2B,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE;QAFpD,YAAO,GAAP,OAAO,CAAiB;QACxB,UAAK,GAAL,KAAK,CAAmB;QACxB,eAAU,GAAV,UAAU,CAA0C;IACpE,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,QAA0B;QACrD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,6BAA6B;YAC7B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,wDAAwD;YACxD,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,IAAI;gBACb,WAAW,EAAE,iEAAiE;aAC/E,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS;QAE9E,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;YAC1B,EAAE,EAAE,QAAQ;YACZ,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,EAAE,EAAE,qBAAqB;YACnC,aAAa,EAAE,EAAE;YACjB,eAAe,EAAE,EAAE;YACnB,aAAa,EAAE,EAAE;YACjB,eAAe,EAAE,KAAK;YACtB,iBAAiB,EAAE,IAAI;YACvB,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE;YAC5B,SAAS,EAAE,SAAS,CAAC,WAAW,EAAE;SACnC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAqB;YAChC,KAAK,EAAE,cAAc;YACrB,QAAQ,EAAE,gBAAgB;YAC1B,cAAc,EAAE,KAAK,CAAC,MAAM;YAC5B,WAAW,EAAE,EAAE;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,KAAK,CAAC,MAAM;YACvB,UAAU,EAAE,GAAG;SAChB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,CAAC,OAAO,CAAC;YACnB,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,kBAAkB,QAAQ,EAAE;SAC1C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction Pipeline — public API
|
|
3
|
+
*/
|
|
4
|
+
export { SecretDetectionLayer } from './secret-detection-layer.js';
|
|
5
|
+
export { PIIDetectionLayer, type PresidioProvider } from './pii-detection-layer.js';
|
|
6
|
+
export { UrlPathScrubbingLayer, DEFAULT_PUBLIC_DOMAINS } from './url-path-scrubbing-layer.js';
|
|
7
|
+
export { TenantDeidentificationLayer } from './tenant-deidentification-layer.js';
|
|
8
|
+
export { SemanticDenyListLayer } from './semantic-denylist-layer.js';
|
|
9
|
+
export { HumanReviewLayer, type ReviewQueueStore } from './human-review-layer.js';
|
|
10
|
+
export { RedactionPipeline, type RedactionPipelineConfig } from './pipeline.js';
|
|
11
|
+
export { shannonEntropy, detectHighEntropyStrings, ACTIVE_SECRET_PATTERNS } from './secret-patterns.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/redaction/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC9F,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction Pipeline — public API
|
|
3
|
+
*/
|
|
4
|
+
export { SecretDetectionLayer } from './secret-detection-layer.js';
|
|
5
|
+
export { PIIDetectionLayer } from './pii-detection-layer.js';
|
|
6
|
+
export { UrlPathScrubbingLayer, DEFAULT_PUBLIC_DOMAINS } from './url-path-scrubbing-layer.js';
|
|
7
|
+
export { TenantDeidentificationLayer } from './tenant-deidentification-layer.js';
|
|
8
|
+
export { SemanticDenyListLayer } from './semantic-denylist-layer.js';
|
|
9
|
+
export { HumanReviewLayer } from './human-review-layer.js';
|
|
10
|
+
export { RedactionPipeline } from './pipeline.js';
|
|
11
|
+
export { shannonEntropy, detectHighEntropyStrings, ACTIVE_SECRET_PATTERNS } from './secret-patterns.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/redaction/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAyB,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC9F,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAgC,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 2: PII Detection (Story 2.1)
|
|
3
|
+
*/
|
|
4
|
+
import type { RedactionLayer, RedactionLayerResult, RedactionContext } from '@agentlensai/core';
|
|
5
|
+
export interface PIIPattern {
|
|
6
|
+
name: string;
|
|
7
|
+
category: string;
|
|
8
|
+
regex: RegExp;
|
|
9
|
+
replacement: string;
|
|
10
|
+
confidence: number;
|
|
11
|
+
validate?: (match: string) => boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const PII_PATTERNS: PIIPattern[];
|
|
14
|
+
/** Optional Presidio integration interface */
|
|
15
|
+
export interface PresidioProvider {
|
|
16
|
+
analyze(text: string): Promise<Array<{
|
|
17
|
+
entityType: string;
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
score: number;
|
|
21
|
+
}>>;
|
|
22
|
+
}
|
|
23
|
+
export declare class PIIDetectionLayer implements RedactionLayer {
|
|
24
|
+
private readonly presidio?;
|
|
25
|
+
readonly name: "pii_detection";
|
|
26
|
+
readonly order = 200;
|
|
27
|
+
constructor(presidio?: PresidioProvider | undefined);
|
|
28
|
+
process(input: string, _context: RedactionContext): Promise<RedactionLayerResult>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=pii-detection-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-detection-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/redaction/pii-detection-layer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC;AAsBD,eAAO,MAAM,YAAY,EAAE,UAAU,EAqFpC,CAAC;AAEF,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QACnC,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC,CAAC;CACL;AAED,qBAAa,iBAAkB,YAAW,cAAc;IAI1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAHtC,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAU;IACzC,QAAQ,CAAC,KAAK,OAAO;gBAEQ,QAAQ,CAAC,EAAE,gBAAgB,YAAA;IAElD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;CA8ExF"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 2: PII Detection (Story 2.1)
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Luhn algorithm for credit card validation.
|
|
6
|
+
*/
|
|
7
|
+
function luhnCheck(digits) {
|
|
8
|
+
const nums = digits.replace(/\D/g, '');
|
|
9
|
+
if (nums.length < 13 || nums.length > 19)
|
|
10
|
+
return false;
|
|
11
|
+
let sum = 0;
|
|
12
|
+
let alternate = false;
|
|
13
|
+
for (let i = nums.length - 1; i >= 0; i--) {
|
|
14
|
+
let n = parseInt(nums[i], 10);
|
|
15
|
+
if (alternate) {
|
|
16
|
+
n *= 2;
|
|
17
|
+
if (n > 9)
|
|
18
|
+
n -= 9;
|
|
19
|
+
}
|
|
20
|
+
sum += n;
|
|
21
|
+
alternate = !alternate;
|
|
22
|
+
}
|
|
23
|
+
return sum % 10 === 0;
|
|
24
|
+
}
|
|
25
|
+
export const PII_PATTERNS = [
|
|
26
|
+
{
|
|
27
|
+
name: 'email',
|
|
28
|
+
category: 'email',
|
|
29
|
+
regex: /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/g,
|
|
30
|
+
replacement: '[EMAIL]',
|
|
31
|
+
confidence: 0.95,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'ssn_dashed',
|
|
35
|
+
category: 'ssn',
|
|
36
|
+
regex: /\b\d{3}-\d{2}-\d{4}\b/g,
|
|
37
|
+
replacement: '[SSN]',
|
|
38
|
+
confidence: 0.95,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'ssn_plain',
|
|
42
|
+
category: 'ssn',
|
|
43
|
+
regex: /\b(?<!\d)(?!000|666|9\d\d)\d{3}(?!00)\d{2}(?!0000)\d{4}(?!\d)\b/g,
|
|
44
|
+
replacement: '[SSN]',
|
|
45
|
+
confidence: 0.70,
|
|
46
|
+
validate: (match) => {
|
|
47
|
+
const digits = match.replace(/\D/g, '');
|
|
48
|
+
// Must be exactly 9 digits, not all same, not sequential
|
|
49
|
+
return digits.length === 9 && !/^(\d)\1{8}$/.test(digits);
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'credit_card_16',
|
|
54
|
+
category: 'credit_card',
|
|
55
|
+
regex: /\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/g,
|
|
56
|
+
replacement: '[CREDIT_CARD]',
|
|
57
|
+
confidence: 0.90,
|
|
58
|
+
validate: (match) => luhnCheck(match),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'credit_card_amex',
|
|
62
|
+
category: 'credit_card',
|
|
63
|
+
regex: /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/g,
|
|
64
|
+
replacement: '[CREDIT_CARD]',
|
|
65
|
+
confidence: 0.90,
|
|
66
|
+
validate: (match) => luhnCheck(match),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'phone_us',
|
|
70
|
+
category: 'phone',
|
|
71
|
+
regex: /(?:\+?1[-.\s])?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/g,
|
|
72
|
+
replacement: '[PHONE]',
|
|
73
|
+
confidence: 0.85,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'phone_international',
|
|
77
|
+
category: 'phone',
|
|
78
|
+
regex: /\+\d{1,3}[-.\s]?\d{1,4}[-.\s]?\d{2,4}[-.\s]?\d{2,4}[-.\s]?\d{0,4}\b/g,
|
|
79
|
+
replacement: '[PHONE]',
|
|
80
|
+
confidence: 0.80,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'ip_address_v4',
|
|
84
|
+
category: 'ip_address',
|
|
85
|
+
regex: /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,
|
|
86
|
+
replacement: '[IP_ADDRESS]',
|
|
87
|
+
confidence: 0.80,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'ip_address_v6',
|
|
91
|
+
category: 'ip_address',
|
|
92
|
+
regex: /\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g,
|
|
93
|
+
replacement: '[IP_ADDRESS]',
|
|
94
|
+
confidence: 0.80,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'ip_address_v6_compressed',
|
|
98
|
+
category: 'ip_address',
|
|
99
|
+
regex: /\b(?:[0-9a-fA-F]{1,4}:){1,6}(?::[0-9a-fA-F]{1,4}){1,6}\b/g,
|
|
100
|
+
replacement: '[IP_ADDRESS]',
|
|
101
|
+
confidence: 0.75,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'ip_address_v4_mapped_v6',
|
|
105
|
+
category: 'ip_address',
|
|
106
|
+
regex: /::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,
|
|
107
|
+
replacement: '[IP_ADDRESS]',
|
|
108
|
+
confidence: 0.80,
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
export class PIIDetectionLayer {
|
|
112
|
+
presidio;
|
|
113
|
+
name = 'pii_detection';
|
|
114
|
+
order = 200;
|
|
115
|
+
constructor(presidio) {
|
|
116
|
+
this.presidio = presidio;
|
|
117
|
+
}
|
|
118
|
+
async process(input, _context) {
|
|
119
|
+
const findings = [];
|
|
120
|
+
const allMatches = [];
|
|
121
|
+
// Regex-based detection
|
|
122
|
+
for (const pattern of PII_PATTERNS) {
|
|
123
|
+
const regex = new RegExp(pattern.regex.source, pattern.regex.flags);
|
|
124
|
+
let match;
|
|
125
|
+
while ((match = regex.exec(input)) !== null) {
|
|
126
|
+
if (pattern.validate && !pattern.validate(match[0]))
|
|
127
|
+
continue;
|
|
128
|
+
allMatches.push({
|
|
129
|
+
start: match.index,
|
|
130
|
+
end: match.index + match[0].length,
|
|
131
|
+
replacement: pattern.replacement,
|
|
132
|
+
category: pattern.category,
|
|
133
|
+
confidence: pattern.confidence,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Optional Presidio NER
|
|
138
|
+
if (this.presidio) {
|
|
139
|
+
const entities = await this.presidio.analyze(input);
|
|
140
|
+
for (const entity of entities) {
|
|
141
|
+
const alreadyCovered = allMatches.some(m => m.start <= entity.start && m.end >= entity.end);
|
|
142
|
+
if (!alreadyCovered) {
|
|
143
|
+
allMatches.push({
|
|
144
|
+
start: entity.start,
|
|
145
|
+
end: entity.end,
|
|
146
|
+
replacement: `[${entity.entityType}]`,
|
|
147
|
+
category: entity.entityType.toLowerCase(),
|
|
148
|
+
confidence: entity.score,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Sort descending by start for safe replacement
|
|
154
|
+
allMatches.sort((a, b) => b.start - a.start);
|
|
155
|
+
// Deduplicate overlapping
|
|
156
|
+
const deduped = [];
|
|
157
|
+
for (const m of allMatches) {
|
|
158
|
+
if (!deduped.some(d => m.start < d.end && m.end > d.start)) {
|
|
159
|
+
deduped.push(m);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
let output = input;
|
|
163
|
+
// Record findings in ascending order
|
|
164
|
+
const ascending = [...deduped].sort((a, b) => a.start - b.start);
|
|
165
|
+
for (const m of ascending) {
|
|
166
|
+
findings.push({
|
|
167
|
+
layer: 'pii_detection',
|
|
168
|
+
category: m.category,
|
|
169
|
+
originalLength: m.end - m.start,
|
|
170
|
+
replacement: m.replacement,
|
|
171
|
+
startOffset: m.start,
|
|
172
|
+
endOffset: m.end,
|
|
173
|
+
confidence: m.confidence,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// Apply replacements descending
|
|
177
|
+
for (const m of deduped) {
|
|
178
|
+
output = output.slice(0, m.start) + m.replacement + output.slice(m.end);
|
|
179
|
+
}
|
|
180
|
+
return { output, findings, blocked: false };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=pii-detection-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-detection-layer.js","sourceRoot":"","sources":["../../../src/lib/redaction/pii-detection-layer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkBH;;GAEG;AACH,SAAS,SAAS,CAAC,MAAc;IAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC;IACvD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,SAAS,EAAE,CAAC;YACd,CAAC,IAAI,CAAC,CAAC;YACP,IAAI,CAAC,GAAG,CAAC;gBAAE,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;QACD,GAAG,IAAI,CAAC,CAAC;QACT,SAAS,GAAG,CAAC,SAAS,CAAC;IACzB,CAAC;IACD,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC;QACE,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,OAAO;QACjB,KAAK,EA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AK,EAAE,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction Pipeline Orchestrator (Story 2.3)
|
|
3
|
+
*/
|
|
4
|
+
import type { RedactionLayer, RedactionContext, RedactionResult, RawLessonContent } from '@agentlensai/core';
|
|
5
|
+
import { type PresidioProvider } from './pii-detection-layer.js';
|
|
6
|
+
import { type ReviewQueueStore } from './human-review-layer.js';
|
|
7
|
+
export interface RedactionPipelineConfig {
|
|
8
|
+
humanReviewEnabled?: boolean;
|
|
9
|
+
reviewQueueStore?: ReviewQueueStore;
|
|
10
|
+
presidioProvider?: PresidioProvider;
|
|
11
|
+
publicDomainAllowlist?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare class RedactionPipeline {
|
|
14
|
+
private layers;
|
|
15
|
+
constructor(config?: RedactionPipelineConfig, customLayers?: RedactionLayer[]);
|
|
16
|
+
getLayers(): readonly RedactionLayer[];
|
|
17
|
+
/**
|
|
18
|
+
* Register a custom redaction layer at runtime.
|
|
19
|
+
* The layer is inserted at the correct position based on its `order` field.
|
|
20
|
+
* Multiple custom layers are supported.
|
|
21
|
+
* Plugin errors trigger fail-closed behavior (same as built-in layers).
|
|
22
|
+
*/
|
|
23
|
+
registerCustomLayer(layer: RedactionLayer): void;
|
|
24
|
+
process(raw: RawLessonContent, ctx: RedactionContext): Promise<RedactionResult>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../src/lib/redaction/pipeline.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EAEd,gBAAgB,EAChB,eAAe,EAEf,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAIpF,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAElF,MAAM,WAAW,uBAAuB;IACtC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAmB;gBAG/B,MAAM,GAAE,uBAA4B,EACpC,YAAY,CAAC,EAAE,cAAc,EAAE;IAqBjC,SAAS,IAAI,SAAS,cAAc,EAAE;IAItC;;;;;OAKG;IACH,mBAAmB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAK1C,OAAO,CAAC,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CAuDtF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction Pipeline Orchestrator (Story 2.3)
|
|
3
|
+
*/
|
|
4
|
+
import { createRedactedLessonContent, REDACTION_PIPELINE_KEY } from '@agentlensai/core';
|
|
5
|
+
import { SecretDetectionLayer } from './secret-detection-layer.js';
|
|
6
|
+
import { PIIDetectionLayer } from './pii-detection-layer.js';
|
|
7
|
+
import { UrlPathScrubbingLayer } from './url-path-scrubbing-layer.js';
|
|
8
|
+
import { TenantDeidentificationLayer } from './tenant-deidentification-layer.js';
|
|
9
|
+
import { SemanticDenyListLayer } from './semantic-denylist-layer.js';
|
|
10
|
+
import { HumanReviewLayer } from './human-review-layer.js';
|
|
11
|
+
export class RedactionPipeline {
|
|
12
|
+
layers;
|
|
13
|
+
constructor(config = {}, customLayers) {
|
|
14
|
+
const defaultLayers = [
|
|
15
|
+
new SecretDetectionLayer(),
|
|
16
|
+
new PIIDetectionLayer(config.presidioProvider),
|
|
17
|
+
new UrlPathScrubbingLayer(config.publicDomainAllowlist),
|
|
18
|
+
new TenantDeidentificationLayer(),
|
|
19
|
+
new SemanticDenyListLayer(),
|
|
20
|
+
new HumanReviewLayer(config.humanReviewEnabled ?? false, config.reviewQueueStore),
|
|
21
|
+
];
|
|
22
|
+
if (customLayers) {
|
|
23
|
+
defaultLayers.push(...customLayers);
|
|
24
|
+
}
|
|
25
|
+
this.layers = defaultLayers.sort((a, b) => a.order - b.order);
|
|
26
|
+
}
|
|
27
|
+
getLayers() {
|
|
28
|
+
return this.layers;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register a custom redaction layer at runtime.
|
|
32
|
+
* The layer is inserted at the correct position based on its `order` field.
|
|
33
|
+
* Multiple custom layers are supported.
|
|
34
|
+
* Plugin errors trigger fail-closed behavior (same as built-in layers).
|
|
35
|
+
*/
|
|
36
|
+
registerCustomLayer(layer) {
|
|
37
|
+
this.layers.push(layer);
|
|
38
|
+
this.layers.sort((a, b) => a.order - b.order);
|
|
39
|
+
}
|
|
40
|
+
async process(raw, ctx) {
|
|
41
|
+
// Combine title and content for processing
|
|
42
|
+
let text = `${raw.title}\n---\n${raw.content}`;
|
|
43
|
+
const allFindings = [];
|
|
44
|
+
for (const layer of this.layers) {
|
|
45
|
+
let result;
|
|
46
|
+
try {
|
|
47
|
+
result = await layer.process(text, ctx);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
// FAIL-CLOSED: any layer error blocks the lesson
|
|
51
|
+
return {
|
|
52
|
+
status: 'error',
|
|
53
|
+
error: error instanceof Error ? error.message : String(error),
|
|
54
|
+
layer: layer.name,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (result.blocked) {
|
|
58
|
+
// Check for pending_review special case
|
|
59
|
+
if (result.blockReason?.startsWith('pending_review:')) {
|
|
60
|
+
const reviewId = result.blockReason.split(':')[1];
|
|
61
|
+
return { status: 'pending_review', reviewId };
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
status: 'blocked',
|
|
65
|
+
reason: result.blockReason ?? 'Blocked by redaction layer',
|
|
66
|
+
layer: layer.name,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
text = result.output;
|
|
70
|
+
allFindings.push(...result.findings);
|
|
71
|
+
}
|
|
72
|
+
// Split back into title and content
|
|
73
|
+
const separatorIndex = text.indexOf('\n---\n');
|
|
74
|
+
let title;
|
|
75
|
+
let content;
|
|
76
|
+
if (separatorIndex !== -1) {
|
|
77
|
+
title = text.slice(0, separatorIndex);
|
|
78
|
+
content = text.slice(separatorIndex + 5);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
title = text;
|
|
82
|
+
content = '';
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
status: 'redacted',
|
|
86
|
+
content: createRedactedLessonContent(title, content, {}, REDACTION_PIPELINE_KEY), // context always stripped
|
|
87
|
+
findings: allFindings,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/lib/redaction/pipeline.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAyB,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,yBAAyB,CAAC;AASlF,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAmB;IAEjC,YACE,SAAkC,EAAE,EACpC,YAA+B;QAE/B,MAAM,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AAI,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QAED,OAAO;YACL,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,sBAAsB,CAAC,EAAE,0BAA0B;YAC5G,QAAQ,EAAE,WAAW;SACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 1: Secret Detection (Story 2.1)
|
|
3
|
+
*/
|
|
4
|
+
import type { RedactionLayer, RedactionLayerResult, RedactionContext } from '@agentlensai/core';
|
|
5
|
+
export declare class SecretDetectionLayer implements RedactionLayer {
|
|
6
|
+
readonly name: "secret_detection";
|
|
7
|
+
readonly order = 100;
|
|
8
|
+
process(input: string, _context: RedactionContext): RedactionLayerResult;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=secret-detection-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-detection-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/redaction/secret-detection-layer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,mBAAmB,CAAC;AAG3B,qBAAa,oBAAqB,YAAW,cAAc;IACzD,QAAQ,CAAC,IAAI,EAAG,kBAAkB,CAAU;IAC5C,QAAQ,CAAC,KAAK,OAAO;IAErB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,oBAAoB;CAyFzE"}
|