@nationaldesignstudio/rampart
Version:
Rampart — client-side PII redaction for AI assistants: deterministic recognizers + a 14.7 MB ONNX classifier (transformers.js), default-deny policy, and reversible placeholders. Runs entirely in the browser.
27 lines • 1.41 kB
TypeScript
/**
* Span reconciliation + default-deny policy.
*
* Detectors (heuristic + NER) emit overlapping, possibly conflicting spans.
* {@link mergeSpans} resolves them into a non-overlapping set, then
* {@link applyPolicy} drops anything in the keep-set so only redactable spans
* remain. This is Option A: redact detected entities whose label is not kept.
*/
import { type PiiLabel, type Span } from "./types";
/**
* Reduce overlapping spans to a disjoint set. When two spans overlap, the
* higher-confidence one wins; ties break toward the longer span, then toward
* heuristics (validator-backed, so most trustworthy). Biased to *keep* a
* redaction rather than drop one — recall over precision, per the threat model.
*
* On partial overlap (neither span contains the other) the previous span
* covers bytes the winner does not. Taking only the winner exposes those
* bytes; we take the byte-union under the preferred label so no detected
* bytes are silently dropped. Full containment still collapses to the winner.
*/
export declare function mergeSpans(spans: readonly Span[]): Span[];
/**
* Apply the keep-set. Returns only spans that must be redacted, sorted right to
* left so callers can splice from the end and keep earlier offsets valid.
*/
export declare function applyPolicy(spans: readonly Span[], keepLabels?: ReadonlySet<PiiLabel>): Span[];
//# sourceMappingURL=policy.d.ts.map