plugin-sensitive-filter-xr 0.0.2 → 0.0.5
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 +156 -54
- package/dist/lib/sensitive-filter.module.d.ts.map +1 -1
- package/dist/lib/sensitive-filter.module.js +2 -1
- package/dist/lib/sensitiveFilter.d.ts +6 -3
- package/dist/lib/sensitiveFilter.d.ts.map +1 -1
- package/dist/lib/sensitiveFilter.js +782 -83
- package/dist/lib/types.d.ts +143 -29
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +37 -21
- package/package.json +1 -1
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ICopilotModel } from '@metad/contracts';
|
|
1
2
|
import { z } from 'zod/v3';
|
|
2
3
|
export type SensitiveRule = {
|
|
3
4
|
id: string;
|
|
@@ -12,12 +13,40 @@ export type GeneralPackConfig = {
|
|
|
12
13
|
enabled?: boolean;
|
|
13
14
|
profile?: 'strict' | 'balanced';
|
|
14
15
|
};
|
|
15
|
-
export type
|
|
16
|
-
|
|
16
|
+
export type RuleModeConfig = {
|
|
17
|
+
mode?: 'rule';
|
|
18
|
+
rules?: Array<Partial<SensitiveRule> | null>;
|
|
17
19
|
generalPack?: GeneralPackConfig;
|
|
18
20
|
caseSensitive?: boolean;
|
|
19
21
|
normalize?: boolean;
|
|
20
22
|
};
|
|
23
|
+
export type LlmScope = 'input' | 'output' | 'both';
|
|
24
|
+
export type LlmOutputMethod = 'functionCalling' | 'jsonMode' | 'jsonSchema';
|
|
25
|
+
export type LlmErrorAction = 'block' | 'rewrite';
|
|
26
|
+
export type LlmFilterConfig = {
|
|
27
|
+
model?: ICopilotModel;
|
|
28
|
+
scope?: LlmScope;
|
|
29
|
+
rulePrompt?: string;
|
|
30
|
+
systemPrompt?: string;
|
|
31
|
+
outputMethod?: LlmOutputMethod;
|
|
32
|
+
onLlmError?: LlmErrorAction;
|
|
33
|
+
errorRewriteText?: string;
|
|
34
|
+
blockMessage?: string;
|
|
35
|
+
rewriteFallbackText?: string;
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
};
|
|
38
|
+
export type LlmModeConfig = {
|
|
39
|
+
mode: 'llm';
|
|
40
|
+
llm?: LlmFilterConfig | null;
|
|
41
|
+
};
|
|
42
|
+
export type SensitiveFilterConfig = RuleModeConfig | LlmModeConfig;
|
|
43
|
+
export type LlmDecision = {
|
|
44
|
+
matched: boolean;
|
|
45
|
+
action?: 'block' | 'rewrite';
|
|
46
|
+
replacementText?: string | null;
|
|
47
|
+
reason?: string | null;
|
|
48
|
+
categories?: string[] | null;
|
|
49
|
+
};
|
|
21
50
|
export type CompiledSensitiveRule = SensitiveRule & {
|
|
22
51
|
index: number;
|
|
23
52
|
normalizedPattern: string;
|
|
@@ -25,48 +54,33 @@ export type CompiledSensitiveRule = SensitiveRule & {
|
|
|
25
54
|
rewriteRegex?: RegExp;
|
|
26
55
|
};
|
|
27
56
|
export declare const SensitiveFilterIcon = "<svg width=\"800px\" height=\"800px\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 2l7 3v6c0 5.2-3.3 9.9-7 11-3.7-1.1-7-5.8-7-11V5l7-3zm0 2.1L7 6v5c0 3.9 2.3 7.8 5 8.9 2.7-1.1 5-5 5-8.9V6l-5-1.9zM8.8 12.6l1.4-1.4 1.8 1.8 3.8-3.8 1.4 1.4-5.2 5.2-3.2-3.2z\"/></svg>";
|
|
28
|
-
export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
29
|
-
|
|
57
|
+
export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
|
|
58
|
+
mode: z.ZodOptional<z.ZodLiteral<"rule">>;
|
|
59
|
+
rules: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodNullable<z.ZodObject<{
|
|
30
60
|
id: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
31
|
-
pattern: z.ZodString
|
|
32
|
-
type: z.ZodEnum<["keyword", "regex"]
|
|
61
|
+
pattern: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
62
|
+
type: z.ZodNullable<z.ZodOptional<z.ZodEnum<["keyword", "regex"]>>>;
|
|
33
63
|
scope: z.ZodNullable<z.ZodOptional<z.ZodEnum<["input", "output", "both"]>>>;
|
|
34
64
|
severity: z.ZodNullable<z.ZodOptional<z.ZodEnum<["high", "medium"]>>>;
|
|
35
|
-
action: z.ZodEnum<["block", "rewrite"]
|
|
65
|
+
action: z.ZodNullable<z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>>;
|
|
36
66
|
replacementText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
37
67
|
}, "strip", z.ZodTypeAny, {
|
|
38
|
-
id?: string;
|
|
39
|
-
pattern?: string;
|
|
40
|
-
type?: "keyword" | "regex";
|
|
41
|
-
scope?: "input" | "output" | "both";
|
|
42
|
-
severity?: "high" | "medium";
|
|
43
|
-
action?: "block" | "rewrite";
|
|
44
|
-
replacementText?: string;
|
|
45
|
-
}, {
|
|
46
|
-
id?: string;
|
|
47
|
-
pattern?: string;
|
|
48
68
|
type?: "keyword" | "regex";
|
|
49
|
-
scope?: "input" | "output" | "both";
|
|
50
|
-
severity?: "high" | "medium";
|
|
51
|
-
action?: "block" | "rewrite";
|
|
52
|
-
replacementText?: string;
|
|
53
|
-
}>, {
|
|
54
69
|
id?: string;
|
|
55
70
|
pattern?: string;
|
|
56
|
-
type?: "keyword" | "regex";
|
|
57
71
|
scope?: "input" | "output" | "both";
|
|
58
72
|
severity?: "high" | "medium";
|
|
59
73
|
action?: "block" | "rewrite";
|
|
60
74
|
replacementText?: string;
|
|
61
75
|
}, {
|
|
76
|
+
type?: "keyword" | "regex";
|
|
62
77
|
id?: string;
|
|
63
78
|
pattern?: string;
|
|
64
|
-
type?: "keyword" | "regex";
|
|
65
79
|
scope?: "input" | "output" | "both";
|
|
66
80
|
severity?: "high" | "medium";
|
|
67
81
|
action?: "block" | "rewrite";
|
|
68
82
|
replacementText?: string;
|
|
69
|
-
}>>, "many"
|
|
83
|
+
}>>, "many">>>;
|
|
70
84
|
generalPack: z.ZodOptional<z.ZodObject<{
|
|
71
85
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
72
86
|
profile: z.ZodOptional<z.ZodDefault<z.ZodEnum<["strict", "balanced"]>>>;
|
|
@@ -79,11 +93,15 @@ export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
|
79
93
|
}>>;
|
|
80
94
|
caseSensitive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
81
95
|
normalize: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
96
|
+
llm: z.ZodOptional<z.ZodUnknown>;
|
|
82
97
|
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
normalize?: boolean;
|
|
99
|
+
llm?: unknown;
|
|
100
|
+
mode?: "rule";
|
|
83
101
|
rules?: {
|
|
102
|
+
type?: "keyword" | "regex";
|
|
84
103
|
id?: string;
|
|
85
104
|
pattern?: string;
|
|
86
|
-
type?: "keyword" | "regex";
|
|
87
105
|
scope?: "input" | "output" | "both";
|
|
88
106
|
severity?: "high" | "medium";
|
|
89
107
|
action?: "block" | "rewrite";
|
|
@@ -94,12 +112,14 @@ export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
|
94
112
|
profile?: "strict" | "balanced";
|
|
95
113
|
};
|
|
96
114
|
caseSensitive?: boolean;
|
|
97
|
-
normalize?: boolean;
|
|
98
115
|
}, {
|
|
116
|
+
normalize?: boolean;
|
|
117
|
+
llm?: unknown;
|
|
118
|
+
mode?: "rule";
|
|
99
119
|
rules?: {
|
|
120
|
+
type?: "keyword" | "regex";
|
|
100
121
|
id?: string;
|
|
101
122
|
pattern?: string;
|
|
102
|
-
type?: "keyword" | "regex";
|
|
103
123
|
scope?: "input" | "output" | "both";
|
|
104
124
|
severity?: "high" | "medium";
|
|
105
125
|
action?: "block" | "rewrite";
|
|
@@ -110,7 +130,101 @@ export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
|
110
130
|
profile?: "strict" | "balanced";
|
|
111
131
|
};
|
|
112
132
|
caseSensitive?: boolean;
|
|
113
|
-
|
|
133
|
+
}>, z.ZodObject<{
|
|
134
|
+
mode: z.ZodLiteral<"llm">;
|
|
135
|
+
llm: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
136
|
+
model: z.ZodNullable<z.ZodOptional<z.ZodType<ICopilotModel, z.ZodTypeDef, ICopilotModel>>>;
|
|
137
|
+
scope: z.ZodNullable<z.ZodOptional<z.ZodEnum<["input", "output", "both"]>>>;
|
|
138
|
+
rulePrompt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
139
|
+
systemPrompt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
140
|
+
outputMethod: z.ZodDefault<z.ZodOptional<z.ZodEnum<["functionCalling", "jsonMode", "jsonSchema"]>>>;
|
|
141
|
+
onLlmError: z.ZodNullable<z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>>;
|
|
142
|
+
errorRewriteText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
143
|
+
blockMessage: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
144
|
+
rewriteFallbackText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
145
|
+
timeoutMs: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
|
|
146
|
+
}, "strip", z.ZodTypeAny, {
|
|
147
|
+
model?: ICopilotModel;
|
|
148
|
+
scope?: "input" | "output" | "both";
|
|
149
|
+
rulePrompt?: string;
|
|
150
|
+
systemPrompt?: string;
|
|
151
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
152
|
+
onLlmError?: "block" | "rewrite";
|
|
153
|
+
errorRewriteText?: string;
|
|
154
|
+
blockMessage?: string;
|
|
155
|
+
rewriteFallbackText?: string;
|
|
156
|
+
timeoutMs?: number;
|
|
157
|
+
}, {
|
|
158
|
+
model?: ICopilotModel;
|
|
159
|
+
scope?: "input" | "output" | "both";
|
|
160
|
+
rulePrompt?: string;
|
|
161
|
+
systemPrompt?: string;
|
|
162
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
163
|
+
onLlmError?: "block" | "rewrite";
|
|
164
|
+
errorRewriteText?: string;
|
|
165
|
+
blockMessage?: string;
|
|
166
|
+
rewriteFallbackText?: string;
|
|
167
|
+
timeoutMs?: number;
|
|
168
|
+
}>>>>;
|
|
169
|
+
rules: z.ZodOptional<z.ZodUnknown>;
|
|
170
|
+
generalPack: z.ZodOptional<z.ZodUnknown>;
|
|
171
|
+
caseSensitive: z.ZodOptional<z.ZodUnknown>;
|
|
172
|
+
normalize: z.ZodOptional<z.ZodUnknown>;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
normalize?: unknown;
|
|
175
|
+
llm?: {
|
|
176
|
+
model?: ICopilotModel;
|
|
177
|
+
scope?: "input" | "output" | "both";
|
|
178
|
+
rulePrompt?: string;
|
|
179
|
+
systemPrompt?: string;
|
|
180
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
181
|
+
onLlmError?: "block" | "rewrite";
|
|
182
|
+
errorRewriteText?: string;
|
|
183
|
+
blockMessage?: string;
|
|
184
|
+
rewriteFallbackText?: string;
|
|
185
|
+
timeoutMs?: number;
|
|
186
|
+
};
|
|
187
|
+
mode?: "llm";
|
|
188
|
+
rules?: unknown;
|
|
189
|
+
generalPack?: unknown;
|
|
190
|
+
caseSensitive?: unknown;
|
|
191
|
+
}, {
|
|
192
|
+
normalize?: unknown;
|
|
193
|
+
llm?: {
|
|
194
|
+
model?: ICopilotModel;
|
|
195
|
+
scope?: "input" | "output" | "both";
|
|
196
|
+
rulePrompt?: string;
|
|
197
|
+
systemPrompt?: string;
|
|
198
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
199
|
+
onLlmError?: "block" | "rewrite";
|
|
200
|
+
errorRewriteText?: string;
|
|
201
|
+
blockMessage?: string;
|
|
202
|
+
rewriteFallbackText?: string;
|
|
203
|
+
timeoutMs?: number;
|
|
204
|
+
};
|
|
205
|
+
mode?: "llm";
|
|
206
|
+
rules?: unknown;
|
|
207
|
+
generalPack?: unknown;
|
|
208
|
+
caseSensitive?: unknown;
|
|
209
|
+
}>]>;
|
|
210
|
+
export declare const llmDecisionSchema: z.ZodObject<{
|
|
211
|
+
matched: z.ZodBoolean;
|
|
212
|
+
action: z.ZodNullable<z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>>;
|
|
213
|
+
replacementText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
214
|
+
reason: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
215
|
+
categories: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
216
|
+
}, "strip", z.ZodTypeAny, {
|
|
217
|
+
action?: "block" | "rewrite";
|
|
218
|
+
replacementText?: string;
|
|
219
|
+
matched?: boolean;
|
|
220
|
+
reason?: string;
|
|
221
|
+
categories?: string[];
|
|
222
|
+
}, {
|
|
223
|
+
action?: "block" | "rewrite";
|
|
224
|
+
replacementText?: string;
|
|
225
|
+
matched?: boolean;
|
|
226
|
+
reason?: string;
|
|
227
|
+
categories?: string[];
|
|
114
228
|
}>;
|
|
115
229
|
export declare function resolveGeneralPackRules(config?: GeneralPackConfig): SensitiveRule[];
|
|
116
230
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE1B,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IAC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U,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,mBAAmB,wSAA8R,CAAA;AAmE9T,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAuD,CAAA;AAE/F,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;EAO1B,CAAA;AAYJ,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,aAAa,EAAE,CA6CnF"}
|
package/dist/lib/types.js
CHANGED
|
@@ -18,39 +18,55 @@ const OPEN_SOURCE_LEXICON = {
|
|
|
18
18
|
const sensitiveRuleDraftSchema = z
|
|
19
19
|
.object({
|
|
20
20
|
id: z.string().optional().nullable(),
|
|
21
|
-
pattern: z.string(),
|
|
22
|
-
type: z.enum(['keyword', 'regex']),
|
|
21
|
+
pattern: z.string().optional().nullable(),
|
|
22
|
+
type: z.enum(['keyword', 'regex']).optional().nullable(),
|
|
23
23
|
scope: z.enum(['input', 'output', 'both']).optional().nullable(),
|
|
24
24
|
severity: z.enum(['high', 'medium']).optional().nullable(),
|
|
25
|
-
action: z.enum(['block', 'rewrite']),
|
|
25
|
+
action: z.enum(['block', 'rewrite']).optional().nullable(),
|
|
26
26
|
replacementText: z.string().optional().nullable(),
|
|
27
|
-
})
|
|
28
|
-
.superRefine((value, ctx) => {
|
|
29
|
-
if (!value.pattern?.trim()) {
|
|
30
|
-
ctx.addIssue({
|
|
31
|
-
code: z.ZodIssueCode.custom,
|
|
32
|
-
path: ['pattern'],
|
|
33
|
-
message: 'pattern is required',
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
if (value.action === 'rewrite' && !value.replacementText?.trim()) {
|
|
37
|
-
ctx.addIssue({
|
|
38
|
-
code: z.ZodIssueCode.custom,
|
|
39
|
-
path: ['replacementText'],
|
|
40
|
-
message: 'replacementText is required when action is rewrite',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
27
|
})
|
|
44
28
|
.nullable();
|
|
45
29
|
const generalPackSchema = z.object({
|
|
46
30
|
enabled: z.boolean().default(false),
|
|
47
31
|
profile: z.enum(['strict', 'balanced']).default('balanced').optional(),
|
|
48
32
|
});
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
const llmConfigSchema = z
|
|
34
|
+
.object({
|
|
35
|
+
model: z.custom().optional().nullable(),
|
|
36
|
+
scope: z.enum(['input', 'output', 'both']).optional().nullable(),
|
|
37
|
+
rulePrompt: z.string().optional().nullable(),
|
|
38
|
+
systemPrompt: z.string().optional().nullable(),
|
|
39
|
+
outputMethod: z.enum(['functionCalling', 'jsonMode', 'jsonSchema']).optional().default('jsonMode'),
|
|
40
|
+
onLlmError: z.enum(['block', 'rewrite']).optional().nullable(),
|
|
41
|
+
errorRewriteText: z.string().optional().nullable(),
|
|
42
|
+
blockMessage: z.string().optional().nullable(),
|
|
43
|
+
rewriteFallbackText: z.string().optional().nullable(),
|
|
44
|
+
timeoutMs: z.number().int().positive().max(120000).optional().nullable(),
|
|
45
|
+
});
|
|
46
|
+
const ruleModeConfigSchema = z.object({
|
|
47
|
+
mode: z.literal('rule').optional(),
|
|
48
|
+
rules: z.array(sensitiveRuleDraftSchema).optional().default([]),
|
|
51
49
|
generalPack: generalPackSchema.optional(),
|
|
52
50
|
caseSensitive: z.boolean().optional().default(false),
|
|
53
51
|
normalize: z.boolean().optional().default(true),
|
|
52
|
+
llm: z.unknown().optional(),
|
|
53
|
+
});
|
|
54
|
+
const llmModeConfigSchema = z.object({
|
|
55
|
+
mode: z.literal('llm'),
|
|
56
|
+
llm: llmConfigSchema.optional().nullable().default({}),
|
|
57
|
+
rules: z.unknown().optional(),
|
|
58
|
+
generalPack: z.unknown().optional(),
|
|
59
|
+
caseSensitive: z.unknown().optional(),
|
|
60
|
+
normalize: z.unknown().optional(),
|
|
61
|
+
});
|
|
62
|
+
export const sensitiveFilterConfigSchema = z.union([ruleModeConfigSchema, llmModeConfigSchema]);
|
|
63
|
+
export const llmDecisionSchema = z
|
|
64
|
+
.object({
|
|
65
|
+
matched: z.boolean(),
|
|
66
|
+
action: z.enum(['block', 'rewrite']).optional().nullable(),
|
|
67
|
+
replacementText: z.string().optional().nullable(),
|
|
68
|
+
reason: z.string().optional().nullable(),
|
|
69
|
+
categories: z.array(z.string()).optional().nullable(),
|
|
54
70
|
});
|
|
55
71
|
function escapeRegExp(value) {
|
|
56
72
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|