@floatingsidewal/bulkhead-core 0.3.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/README.md +142 -0
- package/dist/cascade/bert-worker.js +84 -0
- package/dist/cascade/bert-worker.js.map +1 -0
- package/dist/cascade/index.d.mts +1 -0
- package/dist/cascade/index.d.ts +1 -0
- package/dist/cascade/index.js +386 -0
- package/dist/cascade/index.js.map +1 -0
- package/dist/cascade/index.mjs +11 -0
- package/dist/cascade/index.mjs.map +1 -0
- package/dist/chunk-4KUXRYNS.mjs +358 -0
- package/dist/chunk-4KUXRYNS.mjs.map +1 -0
- package/dist/index-BNiM_sPB.d.mts +237 -0
- package/dist/index-BNiM_sPB.d.ts +237 -0
- package/dist/index.d.mts +265 -0
- package/dist/index.d.ts +265 -0
- package/dist/index.js +3470 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3082 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +70 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { G as GuardMode, E as EngineConfig, a as Guard, b as GuardResult, C as CascadeConfig, c as CascadeClassifier, d as GuardConfig, D as Detection, e as DetectionSource, f as Disposition, P as PiiPattern } from './index-BNiM_sPB.mjs';
|
|
2
|
+
export { B as BertLayerConfig, g as Confidence, L as LlmLayerConfig, h as LlmProvider, S as SecretPattern, T as Tactic, i as TacticName, j as TacticResult } from './index-BNiM_sPB.mjs';
|
|
3
|
+
|
|
4
|
+
/** Severity level for risk rating */
|
|
5
|
+
type RiskLevel = "critical" | "high" | "medium" | "low" | "none";
|
|
6
|
+
/** Per-guard policy configuration */
|
|
7
|
+
interface GuardPolicyConfig {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
threshold: number;
|
|
10
|
+
mode: GuardMode;
|
|
11
|
+
/** For PiiGuard: which entity types to detect */
|
|
12
|
+
entityTypes?: string[];
|
|
13
|
+
/** For SecretGuard: which secret types to detect */
|
|
14
|
+
secretTypes?: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Score thresholds that map aggregate scores to risk levels */
|
|
17
|
+
interface RiskThresholds {
|
|
18
|
+
/** Score >= this is critical */
|
|
19
|
+
critical: number;
|
|
20
|
+
/** Score >= this is high */
|
|
21
|
+
high: number;
|
|
22
|
+
/** Score >= this is medium */
|
|
23
|
+
medium: number;
|
|
24
|
+
/** Score >= this is low; below is none */
|
|
25
|
+
low: number;
|
|
26
|
+
}
|
|
27
|
+
/** A complete policy definition */
|
|
28
|
+
interface PolicyDefinition {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
guards: {
|
|
32
|
+
pii?: Partial<GuardPolicyConfig>;
|
|
33
|
+
secret?: Partial<GuardPolicyConfig>;
|
|
34
|
+
injection?: Partial<GuardPolicyConfig>;
|
|
35
|
+
leakage?: Partial<GuardPolicyConfig>;
|
|
36
|
+
};
|
|
37
|
+
riskThresholds: RiskThresholds;
|
|
38
|
+
/** How to handle test/synthetic data detection */
|
|
39
|
+
testDataDetection?: "flag" | "strip" | "ignore";
|
|
40
|
+
}
|
|
41
|
+
/** Risk assessment returned alongside scan results */
|
|
42
|
+
interface RiskAssessment {
|
|
43
|
+
/** Overall risk level */
|
|
44
|
+
level: RiskLevel;
|
|
45
|
+
/** Aggregate score 0-1 */
|
|
46
|
+
score: number;
|
|
47
|
+
/** Per-guard risk breakdown */
|
|
48
|
+
guards: Record<string, {
|
|
49
|
+
level: RiskLevel;
|
|
50
|
+
score: number;
|
|
51
|
+
detectionCount: number;
|
|
52
|
+
}>;
|
|
53
|
+
/** Classified issues grouped by category */
|
|
54
|
+
issues: ClassifiedIssue[];
|
|
55
|
+
/** Synthetic/eval data flags */
|
|
56
|
+
testDataFlags: TestDataFlag[];
|
|
57
|
+
}
|
|
58
|
+
/** A single classified issue derived from detections */
|
|
59
|
+
interface ClassifiedIssue {
|
|
60
|
+
category: "pii" | "secret" | "injection" | "leakage" | "testdata";
|
|
61
|
+
entityType: string;
|
|
62
|
+
severity: RiskLevel;
|
|
63
|
+
count: number;
|
|
64
|
+
/** Whether this issue overlaps with detected test data */
|
|
65
|
+
isTestData: boolean;
|
|
66
|
+
/** Representative sample (first detection text, truncated) */
|
|
67
|
+
sample?: string;
|
|
68
|
+
}
|
|
69
|
+
/** A flagged piece of synthetic/test data */
|
|
70
|
+
interface TestDataFlag {
|
|
71
|
+
/** JSON path if available (e.g., "issueContext.SubscriptionID") */
|
|
72
|
+
field?: string;
|
|
73
|
+
/** The flagged value */
|
|
74
|
+
value: string;
|
|
75
|
+
/** Why it was flagged */
|
|
76
|
+
reason: string;
|
|
77
|
+
start: number;
|
|
78
|
+
end: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Orchestrates multiple guards and aggregates results */
|
|
82
|
+
declare class GuardrailsEngine {
|
|
83
|
+
private guards;
|
|
84
|
+
private config;
|
|
85
|
+
private cascade;
|
|
86
|
+
constructor(config?: Partial<EngineConfig>);
|
|
87
|
+
/** Register a guard with the engine */
|
|
88
|
+
addGuard(guard: Guard): this;
|
|
89
|
+
/** Register multiple guards */
|
|
90
|
+
addGuards(guards: Guard[]): this;
|
|
91
|
+
/** Get configuration for a specific guard */
|
|
92
|
+
private getGuardConfig;
|
|
93
|
+
/** Run all enabled guards against the input text */
|
|
94
|
+
analyze(text: string): Promise<GuardResult[]>;
|
|
95
|
+
/** Run all guards and return a single pass/fail with all detections */
|
|
96
|
+
scan(text: string): Promise<{
|
|
97
|
+
passed: boolean;
|
|
98
|
+
results: GuardResult[];
|
|
99
|
+
redactedText?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/** Get list of registered guard names */
|
|
102
|
+
get guardNames(): string[];
|
|
103
|
+
/** Whether the cascade is ready (BERT model loaded if enabled) */
|
|
104
|
+
get cascadeReady(): boolean;
|
|
105
|
+
/** Initialize or update the cascade classifier */
|
|
106
|
+
initCascade(config?: Partial<CascadeConfig>): CascadeClassifier;
|
|
107
|
+
/** Run the full cascade (regex + BERT + optional LLM) */
|
|
108
|
+
deepScan(text: string): Promise<GuardResult[]>;
|
|
109
|
+
/** Run regex + BERT only (no LLM) */
|
|
110
|
+
modelScan(text: string): Promise<GuardResult[]>;
|
|
111
|
+
/** Update engine configuration */
|
|
112
|
+
updateConfig(config: Partial<EngineConfig>): void;
|
|
113
|
+
/** Run all guards and return risk assessment alongside results */
|
|
114
|
+
policyScan(text: string, policy: PolicyDefinition): Promise<{
|
|
115
|
+
passed: boolean;
|
|
116
|
+
risk: RiskAssessment;
|
|
117
|
+
results: GuardResult[];
|
|
118
|
+
redactedText?: string;
|
|
119
|
+
}>;
|
|
120
|
+
/** Clean up resources (terminate BERT worker, etc.) */
|
|
121
|
+
dispose(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Base class for guards that detect patterns in text */
|
|
125
|
+
declare abstract class BaseGuard implements Guard {
|
|
126
|
+
abstract readonly name: string;
|
|
127
|
+
protected mergeConfig(config?: Partial<GuardConfig>): GuardConfig;
|
|
128
|
+
abstract analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
129
|
+
/** Build a GuardResult from detections */
|
|
130
|
+
protected buildResult(text: string, detections: Detection[], mode: GuardMode): GuardResult;
|
|
131
|
+
/** Extract surrounding context for a detection */
|
|
132
|
+
protected extractContext(text: string, start: number, end: number): string;
|
|
133
|
+
/** Create a detection with provenance fields pre-filled for regex source */
|
|
134
|
+
protected makeDetection(text: string, partial: Omit<Detection, "source" | "context" | "disposition">, source?: DetectionSource, disposition?: Disposition): Detection;
|
|
135
|
+
/** Replace detected text with [REDACTED-TYPE] markers */
|
|
136
|
+
protected applyRedactions(text: string, detections: Detection[]): string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* PII Guard — detects personally identifiable information using regex patterns.
|
|
141
|
+
* Pattern library ported from Microsoft Presidio. See ATTRIBUTION.md.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
interface PiiGuardOptions {
|
|
145
|
+
/** Specific entity types to detect. If empty, all are enabled. */
|
|
146
|
+
entityTypes?: string[];
|
|
147
|
+
/** Additional custom patterns */
|
|
148
|
+
customPatterns?: PiiPattern[];
|
|
149
|
+
}
|
|
150
|
+
declare class PiiGuard extends BaseGuard {
|
|
151
|
+
readonly name = "pii";
|
|
152
|
+
private patterns;
|
|
153
|
+
constructor(options?: PiiGuardOptions);
|
|
154
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
155
|
+
private detectAll;
|
|
156
|
+
private deduplicateDetections;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Secret Guard — detects API keys, tokens, credentials, and connection strings.
|
|
161
|
+
* Pattern approach inspired by HAI-Guardrails. See ATTRIBUTION.md.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
interface SecretGuardOptions {
|
|
165
|
+
/** Specific secret types to detect. If empty/undefined, all are enabled. */
|
|
166
|
+
secretTypes?: string[];
|
|
167
|
+
}
|
|
168
|
+
declare class SecretGuard extends BaseGuard {
|
|
169
|
+
readonly name = "secret";
|
|
170
|
+
private patterns;
|
|
171
|
+
constructor(options?: SecretGuardOptions);
|
|
172
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Injection Guard — detects prompt injection attempts.
|
|
177
|
+
* Detection approach inspired by HAI-Guardrails. See ATTRIBUTION.md.
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
declare class InjectionGuard extends BaseGuard {
|
|
181
|
+
readonly name = "injection";
|
|
182
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
183
|
+
private heuristicScore;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Leakage Guard — detects system prompt extraction attempts.
|
|
188
|
+
* Detection approach inspired by HAI-Guardrails. See ATTRIBUTION.md.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
declare class LeakageGuard extends BaseGuard {
|
|
192
|
+
readonly name = "leakage";
|
|
193
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Test Data Guard — detects synthetic, eval, and placeholder data.
|
|
198
|
+
* This guard identifies data that was clearly fabricated for testing rather than
|
|
199
|
+
* real sensitive content. Detections are informational, not blocking.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
declare class TestDataGuard extends BaseGuard {
|
|
203
|
+
readonly name = "testdata";
|
|
204
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
205
|
+
/** Build a result that always passes — test data is informational, not blocking */
|
|
206
|
+
private buildInformationalResult;
|
|
207
|
+
private deduplicateDetections;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** All built-in policies indexed by name */
|
|
211
|
+
declare const BUILTIN_POLICIES: Record<string, PolicyDefinition>;
|
|
212
|
+
/** Retrieve a built-in policy by name */
|
|
213
|
+
declare function getPolicy(name: string): PolicyDefinition;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Compose policies by merging a base with overlays.
|
|
217
|
+
* "Stricter wins": lower thresholds, entity-type intersection, block over redact.
|
|
218
|
+
*/
|
|
219
|
+
declare function resolvePolicy(base: string | PolicyDefinition, ...overlays: (string | PolicyDefinition)[]): PolicyDefinition;
|
|
220
|
+
/** Translate a resolved policy into guard constructor options and per-guard configs */
|
|
221
|
+
declare function policyToEngineConfig(policy: PolicyDefinition): {
|
|
222
|
+
piiOptions: PiiGuardOptions;
|
|
223
|
+
secretOptions: SecretGuardOptions;
|
|
224
|
+
guardConfigs: Record<string, Partial<GuardConfig>>;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Compute a risk assessment from guard results and a policy definition.
|
|
229
|
+
* Pure function — no side effects, no engine mutation.
|
|
230
|
+
*/
|
|
231
|
+
declare function assessRisk(results: GuardResult[], policy: PolicyDefinition): RiskAssessment;
|
|
232
|
+
|
|
233
|
+
interface BulkheadConfig {
|
|
234
|
+
enabled: boolean;
|
|
235
|
+
debounceMs: number;
|
|
236
|
+
guards: {
|
|
237
|
+
pii: {
|
|
238
|
+
enabled: boolean;
|
|
239
|
+
};
|
|
240
|
+
secret: {
|
|
241
|
+
enabled: boolean;
|
|
242
|
+
};
|
|
243
|
+
injection: {
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
};
|
|
246
|
+
contentSafety: {
|
|
247
|
+
enabled: boolean;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
cascade: {
|
|
251
|
+
escalationThreshold: number;
|
|
252
|
+
contextSentences: number;
|
|
253
|
+
modelEnabled: boolean;
|
|
254
|
+
modelId: string;
|
|
255
|
+
};
|
|
256
|
+
/** Named policy or custom PolicyDefinition. Overrides guard-level config. */
|
|
257
|
+
policy?: string | PolicyDefinition;
|
|
258
|
+
/** Additional policy overlays for composition */
|
|
259
|
+
policyOverlays?: (string | PolicyDefinition)[];
|
|
260
|
+
}
|
|
261
|
+
declare const DEFAULT_CONFIG: BulkheadConfig;
|
|
262
|
+
/** Create a configured engine from a BulkheadConfig */
|
|
263
|
+
declare function createEngine(config?: BulkheadConfig): GuardrailsEngine;
|
|
264
|
+
|
|
265
|
+
export { BUILTIN_POLICIES, BaseGuard, type BulkheadConfig, CascadeConfig, type ClassifiedIssue, DEFAULT_CONFIG, Detection, DetectionSource, Disposition, EngineConfig, Guard, GuardConfig, GuardMode, type GuardPolicyConfig, GuardResult, GuardrailsEngine, InjectionGuard, LeakageGuard, PiiGuard, type PiiGuardOptions, PiiPattern, type PolicyDefinition, type RiskAssessment, type RiskLevel, type RiskThresholds, SecretGuard, type SecretGuardOptions, type TestDataFlag, TestDataGuard, assessRisk, createEngine, getPolicy, policyToEngineConfig, resolvePolicy };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { G as GuardMode, E as EngineConfig, a as Guard, b as GuardResult, C as CascadeConfig, c as CascadeClassifier, d as GuardConfig, D as Detection, e as DetectionSource, f as Disposition, P as PiiPattern } from './index-BNiM_sPB.js';
|
|
2
|
+
export { B as BertLayerConfig, g as Confidence, L as LlmLayerConfig, h as LlmProvider, S as SecretPattern, T as Tactic, i as TacticName, j as TacticResult } from './index-BNiM_sPB.js';
|
|
3
|
+
|
|
4
|
+
/** Severity level for risk rating */
|
|
5
|
+
type RiskLevel = "critical" | "high" | "medium" | "low" | "none";
|
|
6
|
+
/** Per-guard policy configuration */
|
|
7
|
+
interface GuardPolicyConfig {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
threshold: number;
|
|
10
|
+
mode: GuardMode;
|
|
11
|
+
/** For PiiGuard: which entity types to detect */
|
|
12
|
+
entityTypes?: string[];
|
|
13
|
+
/** For SecretGuard: which secret types to detect */
|
|
14
|
+
secretTypes?: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Score thresholds that map aggregate scores to risk levels */
|
|
17
|
+
interface RiskThresholds {
|
|
18
|
+
/** Score >= this is critical */
|
|
19
|
+
critical: number;
|
|
20
|
+
/** Score >= this is high */
|
|
21
|
+
high: number;
|
|
22
|
+
/** Score >= this is medium */
|
|
23
|
+
medium: number;
|
|
24
|
+
/** Score >= this is low; below is none */
|
|
25
|
+
low: number;
|
|
26
|
+
}
|
|
27
|
+
/** A complete policy definition */
|
|
28
|
+
interface PolicyDefinition {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
guards: {
|
|
32
|
+
pii?: Partial<GuardPolicyConfig>;
|
|
33
|
+
secret?: Partial<GuardPolicyConfig>;
|
|
34
|
+
injection?: Partial<GuardPolicyConfig>;
|
|
35
|
+
leakage?: Partial<GuardPolicyConfig>;
|
|
36
|
+
};
|
|
37
|
+
riskThresholds: RiskThresholds;
|
|
38
|
+
/** How to handle test/synthetic data detection */
|
|
39
|
+
testDataDetection?: "flag" | "strip" | "ignore";
|
|
40
|
+
}
|
|
41
|
+
/** Risk assessment returned alongside scan results */
|
|
42
|
+
interface RiskAssessment {
|
|
43
|
+
/** Overall risk level */
|
|
44
|
+
level: RiskLevel;
|
|
45
|
+
/** Aggregate score 0-1 */
|
|
46
|
+
score: number;
|
|
47
|
+
/** Per-guard risk breakdown */
|
|
48
|
+
guards: Record<string, {
|
|
49
|
+
level: RiskLevel;
|
|
50
|
+
score: number;
|
|
51
|
+
detectionCount: number;
|
|
52
|
+
}>;
|
|
53
|
+
/** Classified issues grouped by category */
|
|
54
|
+
issues: ClassifiedIssue[];
|
|
55
|
+
/** Synthetic/eval data flags */
|
|
56
|
+
testDataFlags: TestDataFlag[];
|
|
57
|
+
}
|
|
58
|
+
/** A single classified issue derived from detections */
|
|
59
|
+
interface ClassifiedIssue {
|
|
60
|
+
category: "pii" | "secret" | "injection" | "leakage" | "testdata";
|
|
61
|
+
entityType: string;
|
|
62
|
+
severity: RiskLevel;
|
|
63
|
+
count: number;
|
|
64
|
+
/** Whether this issue overlaps with detected test data */
|
|
65
|
+
isTestData: boolean;
|
|
66
|
+
/** Representative sample (first detection text, truncated) */
|
|
67
|
+
sample?: string;
|
|
68
|
+
}
|
|
69
|
+
/** A flagged piece of synthetic/test data */
|
|
70
|
+
interface TestDataFlag {
|
|
71
|
+
/** JSON path if available (e.g., "issueContext.SubscriptionID") */
|
|
72
|
+
field?: string;
|
|
73
|
+
/** The flagged value */
|
|
74
|
+
value: string;
|
|
75
|
+
/** Why it was flagged */
|
|
76
|
+
reason: string;
|
|
77
|
+
start: number;
|
|
78
|
+
end: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Orchestrates multiple guards and aggregates results */
|
|
82
|
+
declare class GuardrailsEngine {
|
|
83
|
+
private guards;
|
|
84
|
+
private config;
|
|
85
|
+
private cascade;
|
|
86
|
+
constructor(config?: Partial<EngineConfig>);
|
|
87
|
+
/** Register a guard with the engine */
|
|
88
|
+
addGuard(guard: Guard): this;
|
|
89
|
+
/** Register multiple guards */
|
|
90
|
+
addGuards(guards: Guard[]): this;
|
|
91
|
+
/** Get configuration for a specific guard */
|
|
92
|
+
private getGuardConfig;
|
|
93
|
+
/** Run all enabled guards against the input text */
|
|
94
|
+
analyze(text: string): Promise<GuardResult[]>;
|
|
95
|
+
/** Run all guards and return a single pass/fail with all detections */
|
|
96
|
+
scan(text: string): Promise<{
|
|
97
|
+
passed: boolean;
|
|
98
|
+
results: GuardResult[];
|
|
99
|
+
redactedText?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/** Get list of registered guard names */
|
|
102
|
+
get guardNames(): string[];
|
|
103
|
+
/** Whether the cascade is ready (BERT model loaded if enabled) */
|
|
104
|
+
get cascadeReady(): boolean;
|
|
105
|
+
/** Initialize or update the cascade classifier */
|
|
106
|
+
initCascade(config?: Partial<CascadeConfig>): CascadeClassifier;
|
|
107
|
+
/** Run the full cascade (regex + BERT + optional LLM) */
|
|
108
|
+
deepScan(text: string): Promise<GuardResult[]>;
|
|
109
|
+
/** Run regex + BERT only (no LLM) */
|
|
110
|
+
modelScan(text: string): Promise<GuardResult[]>;
|
|
111
|
+
/** Update engine configuration */
|
|
112
|
+
updateConfig(config: Partial<EngineConfig>): void;
|
|
113
|
+
/** Run all guards and return risk assessment alongside results */
|
|
114
|
+
policyScan(text: string, policy: PolicyDefinition): Promise<{
|
|
115
|
+
passed: boolean;
|
|
116
|
+
risk: RiskAssessment;
|
|
117
|
+
results: GuardResult[];
|
|
118
|
+
redactedText?: string;
|
|
119
|
+
}>;
|
|
120
|
+
/** Clean up resources (terminate BERT worker, etc.) */
|
|
121
|
+
dispose(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Base class for guards that detect patterns in text */
|
|
125
|
+
declare abstract class BaseGuard implements Guard {
|
|
126
|
+
abstract readonly name: string;
|
|
127
|
+
protected mergeConfig(config?: Partial<GuardConfig>): GuardConfig;
|
|
128
|
+
abstract analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
129
|
+
/** Build a GuardResult from detections */
|
|
130
|
+
protected buildResult(text: string, detections: Detection[], mode: GuardMode): GuardResult;
|
|
131
|
+
/** Extract surrounding context for a detection */
|
|
132
|
+
protected extractContext(text: string, start: number, end: number): string;
|
|
133
|
+
/** Create a detection with provenance fields pre-filled for regex source */
|
|
134
|
+
protected makeDetection(text: string, partial: Omit<Detection, "source" | "context" | "disposition">, source?: DetectionSource, disposition?: Disposition): Detection;
|
|
135
|
+
/** Replace detected text with [REDACTED-TYPE] markers */
|
|
136
|
+
protected applyRedactions(text: string, detections: Detection[]): string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* PII Guard — detects personally identifiable information using regex patterns.
|
|
141
|
+
* Pattern library ported from Microsoft Presidio. See ATTRIBUTION.md.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
interface PiiGuardOptions {
|
|
145
|
+
/** Specific entity types to detect. If empty, all are enabled. */
|
|
146
|
+
entityTypes?: string[];
|
|
147
|
+
/** Additional custom patterns */
|
|
148
|
+
customPatterns?: PiiPattern[];
|
|
149
|
+
}
|
|
150
|
+
declare class PiiGuard extends BaseGuard {
|
|
151
|
+
readonly name = "pii";
|
|
152
|
+
private patterns;
|
|
153
|
+
constructor(options?: PiiGuardOptions);
|
|
154
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
155
|
+
private detectAll;
|
|
156
|
+
private deduplicateDetections;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Secret Guard — detects API keys, tokens, credentials, and connection strings.
|
|
161
|
+
* Pattern approach inspired by HAI-Guardrails. See ATTRIBUTION.md.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
interface SecretGuardOptions {
|
|
165
|
+
/** Specific secret types to detect. If empty/undefined, all are enabled. */
|
|
166
|
+
secretTypes?: string[];
|
|
167
|
+
}
|
|
168
|
+
declare class SecretGuard extends BaseGuard {
|
|
169
|
+
readonly name = "secret";
|
|
170
|
+
private patterns;
|
|
171
|
+
constructor(options?: SecretGuardOptions);
|
|
172
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Injection Guard — detects prompt injection attempts.
|
|
177
|
+
* Detection approach inspired by HAI-Guardrails. See ATTRIBUTION.md.
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
declare class InjectionGuard extends BaseGuard {
|
|
181
|
+
readonly name = "injection";
|
|
182
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
183
|
+
private heuristicScore;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Leakage Guard — detects system prompt extraction attempts.
|
|
188
|
+
* Detection approach inspired by HAI-Guardrails. See ATTRIBUTION.md.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
declare class LeakageGuard extends BaseGuard {
|
|
192
|
+
readonly name = "leakage";
|
|
193
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Test Data Guard — detects synthetic, eval, and placeholder data.
|
|
198
|
+
* This guard identifies data that was clearly fabricated for testing rather than
|
|
199
|
+
* real sensitive content. Detections are informational, not blocking.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
declare class TestDataGuard extends BaseGuard {
|
|
203
|
+
readonly name = "testdata";
|
|
204
|
+
analyze(text: string, config?: Partial<GuardConfig>): Promise<GuardResult>;
|
|
205
|
+
/** Build a result that always passes — test data is informational, not blocking */
|
|
206
|
+
private buildInformationalResult;
|
|
207
|
+
private deduplicateDetections;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** All built-in policies indexed by name */
|
|
211
|
+
declare const BUILTIN_POLICIES: Record<string, PolicyDefinition>;
|
|
212
|
+
/** Retrieve a built-in policy by name */
|
|
213
|
+
declare function getPolicy(name: string): PolicyDefinition;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Compose policies by merging a base with overlays.
|
|
217
|
+
* "Stricter wins": lower thresholds, entity-type intersection, block over redact.
|
|
218
|
+
*/
|
|
219
|
+
declare function resolvePolicy(base: string | PolicyDefinition, ...overlays: (string | PolicyDefinition)[]): PolicyDefinition;
|
|
220
|
+
/** Translate a resolved policy into guard constructor options and per-guard configs */
|
|
221
|
+
declare function policyToEngineConfig(policy: PolicyDefinition): {
|
|
222
|
+
piiOptions: PiiGuardOptions;
|
|
223
|
+
secretOptions: SecretGuardOptions;
|
|
224
|
+
guardConfigs: Record<string, Partial<GuardConfig>>;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Compute a risk assessment from guard results and a policy definition.
|
|
229
|
+
* Pure function — no side effects, no engine mutation.
|
|
230
|
+
*/
|
|
231
|
+
declare function assessRisk(results: GuardResult[], policy: PolicyDefinition): RiskAssessment;
|
|
232
|
+
|
|
233
|
+
interface BulkheadConfig {
|
|
234
|
+
enabled: boolean;
|
|
235
|
+
debounceMs: number;
|
|
236
|
+
guards: {
|
|
237
|
+
pii: {
|
|
238
|
+
enabled: boolean;
|
|
239
|
+
};
|
|
240
|
+
secret: {
|
|
241
|
+
enabled: boolean;
|
|
242
|
+
};
|
|
243
|
+
injection: {
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
};
|
|
246
|
+
contentSafety: {
|
|
247
|
+
enabled: boolean;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
cascade: {
|
|
251
|
+
escalationThreshold: number;
|
|
252
|
+
contextSentences: number;
|
|
253
|
+
modelEnabled: boolean;
|
|
254
|
+
modelId: string;
|
|
255
|
+
};
|
|
256
|
+
/** Named policy or custom PolicyDefinition. Overrides guard-level config. */
|
|
257
|
+
policy?: string | PolicyDefinition;
|
|
258
|
+
/** Additional policy overlays for composition */
|
|
259
|
+
policyOverlays?: (string | PolicyDefinition)[];
|
|
260
|
+
}
|
|
261
|
+
declare const DEFAULT_CONFIG: BulkheadConfig;
|
|
262
|
+
/** Create a configured engine from a BulkheadConfig */
|
|
263
|
+
declare function createEngine(config?: BulkheadConfig): GuardrailsEngine;
|
|
264
|
+
|
|
265
|
+
export { BUILTIN_POLICIES, BaseGuard, type BulkheadConfig, CascadeConfig, type ClassifiedIssue, DEFAULT_CONFIG, Detection, DetectionSource, Disposition, EngineConfig, Guard, GuardConfig, GuardMode, type GuardPolicyConfig, GuardResult, GuardrailsEngine, InjectionGuard, LeakageGuard, PiiGuard, type PiiGuardOptions, PiiPattern, type PolicyDefinition, type RiskAssessment, type RiskLevel, type RiskThresholds, SecretGuard, type SecretGuardOptions, type TestDataFlag, TestDataGuard, assessRisk, createEngine, getPolicy, policyToEngineConfig, resolvePolicy };
|