plugin-sensitive-filter-xr 0.0.2 → 0.0.4
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 +642 -84
- package/dist/lib/types.d.ts +149 -29
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +45 -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,39 @@ 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
|
+
systemPrompt?: string;
|
|
30
|
+
outputMethod?: LlmOutputMethod;
|
|
31
|
+
onLlmError?: LlmErrorAction;
|
|
32
|
+
errorRewriteText?: string;
|
|
33
|
+
blockMessage?: string;
|
|
34
|
+
rewriteFallbackText?: string;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
};
|
|
37
|
+
export type LlmModeConfig = {
|
|
38
|
+
mode: 'llm';
|
|
39
|
+
llm?: LlmFilterConfig | null;
|
|
40
|
+
};
|
|
41
|
+
export type SensitiveFilterConfig = RuleModeConfig | LlmModeConfig;
|
|
42
|
+
export type LlmDecision = {
|
|
43
|
+
matched: boolean;
|
|
44
|
+
action?: 'block' | 'rewrite';
|
|
45
|
+
replacementText?: string | null;
|
|
46
|
+
reason?: string | null;
|
|
47
|
+
categories?: string[] | null;
|
|
48
|
+
};
|
|
21
49
|
export type CompiledSensitiveRule = SensitiveRule & {
|
|
22
50
|
index: number;
|
|
23
51
|
normalizedPattern: string;
|
|
@@ -25,48 +53,33 @@ export type CompiledSensitiveRule = SensitiveRule & {
|
|
|
25
53
|
rewriteRegex?: RegExp;
|
|
26
54
|
};
|
|
27
55
|
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
|
-
|
|
56
|
+
export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
|
|
57
|
+
mode: z.ZodOptional<z.ZodLiteral<"rule">>;
|
|
58
|
+
rules: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodNullable<z.ZodObject<{
|
|
30
59
|
id: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
31
|
-
pattern: z.ZodString
|
|
32
|
-
type: z.ZodEnum<["keyword", "regex"]
|
|
60
|
+
pattern: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
61
|
+
type: z.ZodNullable<z.ZodOptional<z.ZodEnum<["keyword", "regex"]>>>;
|
|
33
62
|
scope: z.ZodNullable<z.ZodOptional<z.ZodEnum<["input", "output", "both"]>>>;
|
|
34
63
|
severity: z.ZodNullable<z.ZodOptional<z.ZodEnum<["high", "medium"]>>>;
|
|
35
|
-
action: z.ZodEnum<["block", "rewrite"]
|
|
64
|
+
action: z.ZodNullable<z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>>;
|
|
36
65
|
replacementText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
37
66
|
}, "strip", z.ZodTypeAny, {
|
|
38
|
-
id?: string;
|
|
39
|
-
pattern?: string;
|
|
40
67
|
type?: "keyword" | "regex";
|
|
41
|
-
scope?: "input" | "output" | "both";
|
|
42
|
-
severity?: "high" | "medium";
|
|
43
|
-
action?: "block" | "rewrite";
|
|
44
|
-
replacementText?: string;
|
|
45
|
-
}, {
|
|
46
68
|
id?: string;
|
|
47
69
|
pattern?: string;
|
|
48
|
-
type?: "keyword" | "regex";
|
|
49
|
-
scope?: "input" | "output" | "both";
|
|
50
|
-
severity?: "high" | "medium";
|
|
51
|
-
action?: "block" | "rewrite";
|
|
52
|
-
replacementText?: string;
|
|
53
|
-
}>, {
|
|
54
|
-
id?: string;
|
|
55
|
-
pattern?: string;
|
|
56
|
-
type?: "keyword" | "regex";
|
|
57
70
|
scope?: "input" | "output" | "both";
|
|
58
71
|
severity?: "high" | "medium";
|
|
59
72
|
action?: "block" | "rewrite";
|
|
60
73
|
replacementText?: string;
|
|
61
74
|
}, {
|
|
75
|
+
type?: "keyword" | "regex";
|
|
62
76
|
id?: string;
|
|
63
77
|
pattern?: string;
|
|
64
|
-
type?: "keyword" | "regex";
|
|
65
78
|
scope?: "input" | "output" | "both";
|
|
66
79
|
severity?: "high" | "medium";
|
|
67
80
|
action?: "block" | "rewrite";
|
|
68
81
|
replacementText?: string;
|
|
69
|
-
}>>, "many"
|
|
82
|
+
}>>, "many">>>;
|
|
70
83
|
generalPack: z.ZodOptional<z.ZodObject<{
|
|
71
84
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
72
85
|
profile: z.ZodOptional<z.ZodDefault<z.ZodEnum<["strict", "balanced"]>>>;
|
|
@@ -79,11 +92,15 @@ export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
|
79
92
|
}>>;
|
|
80
93
|
caseSensitive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
81
94
|
normalize: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
95
|
+
llm: z.ZodOptional<z.ZodUnknown>;
|
|
82
96
|
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
normalize?: boolean;
|
|
98
|
+
llm?: unknown;
|
|
99
|
+
mode?: "rule";
|
|
83
100
|
rules?: {
|
|
101
|
+
type?: "keyword" | "regex";
|
|
84
102
|
id?: string;
|
|
85
103
|
pattern?: string;
|
|
86
|
-
type?: "keyword" | "regex";
|
|
87
104
|
scope?: "input" | "output" | "both";
|
|
88
105
|
severity?: "high" | "medium";
|
|
89
106
|
action?: "block" | "rewrite";
|
|
@@ -94,12 +111,14 @@ export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
|
94
111
|
profile?: "strict" | "balanced";
|
|
95
112
|
};
|
|
96
113
|
caseSensitive?: boolean;
|
|
97
|
-
normalize?: boolean;
|
|
98
114
|
}, {
|
|
115
|
+
normalize?: boolean;
|
|
116
|
+
llm?: unknown;
|
|
117
|
+
mode?: "rule";
|
|
99
118
|
rules?: {
|
|
119
|
+
type?: "keyword" | "regex";
|
|
100
120
|
id?: string;
|
|
101
121
|
pattern?: string;
|
|
102
|
-
type?: "keyword" | "regex";
|
|
103
122
|
scope?: "input" | "output" | "both";
|
|
104
123
|
severity?: "high" | "medium";
|
|
105
124
|
action?: "block" | "rewrite";
|
|
@@ -110,7 +129,108 @@ export declare const sensitiveFilterConfigSchema: z.ZodObject<{
|
|
|
110
129
|
profile?: "strict" | "balanced";
|
|
111
130
|
};
|
|
112
131
|
caseSensitive?: boolean;
|
|
113
|
-
|
|
132
|
+
}>, z.ZodObject<{
|
|
133
|
+
mode: z.ZodLiteral<"llm">;
|
|
134
|
+
llm: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
135
|
+
model: z.ZodNullable<z.ZodOptional<z.ZodType<ICopilotModel, z.ZodTypeDef, ICopilotModel>>>;
|
|
136
|
+
scope: z.ZodNullable<z.ZodOptional<z.ZodEnum<["input", "output", "both"]>>>;
|
|
137
|
+
systemPrompt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
138
|
+
outputMethod: z.ZodDefault<z.ZodOptional<z.ZodEnum<["functionCalling", "jsonMode", "jsonSchema"]>>>;
|
|
139
|
+
onLlmError: z.ZodNullable<z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>>;
|
|
140
|
+
errorRewriteText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
141
|
+
blockMessage: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
142
|
+
rewriteFallbackText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
143
|
+
timeoutMs: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
model?: ICopilotModel;
|
|
146
|
+
scope?: "input" | "output" | "both";
|
|
147
|
+
systemPrompt?: string;
|
|
148
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
149
|
+
onLlmError?: "block" | "rewrite";
|
|
150
|
+
errorRewriteText?: string;
|
|
151
|
+
blockMessage?: string;
|
|
152
|
+
rewriteFallbackText?: string;
|
|
153
|
+
timeoutMs?: number;
|
|
154
|
+
}, {
|
|
155
|
+
model?: ICopilotModel;
|
|
156
|
+
scope?: "input" | "output" | "both";
|
|
157
|
+
systemPrompt?: string;
|
|
158
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
159
|
+
onLlmError?: "block" | "rewrite";
|
|
160
|
+
errorRewriteText?: string;
|
|
161
|
+
blockMessage?: string;
|
|
162
|
+
rewriteFallbackText?: string;
|
|
163
|
+
timeoutMs?: number;
|
|
164
|
+
}>>>>;
|
|
165
|
+
rules: z.ZodOptional<z.ZodUnknown>;
|
|
166
|
+
generalPack: z.ZodOptional<z.ZodUnknown>;
|
|
167
|
+
caseSensitive: z.ZodOptional<z.ZodUnknown>;
|
|
168
|
+
normalize: z.ZodOptional<z.ZodUnknown>;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
normalize?: unknown;
|
|
171
|
+
llm?: {
|
|
172
|
+
model?: ICopilotModel;
|
|
173
|
+
scope?: "input" | "output" | "both";
|
|
174
|
+
systemPrompt?: string;
|
|
175
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
176
|
+
onLlmError?: "block" | "rewrite";
|
|
177
|
+
errorRewriteText?: string;
|
|
178
|
+
blockMessage?: string;
|
|
179
|
+
rewriteFallbackText?: string;
|
|
180
|
+
timeoutMs?: number;
|
|
181
|
+
};
|
|
182
|
+
mode?: "llm";
|
|
183
|
+
rules?: unknown;
|
|
184
|
+
generalPack?: unknown;
|
|
185
|
+
caseSensitive?: unknown;
|
|
186
|
+
}, {
|
|
187
|
+
normalize?: unknown;
|
|
188
|
+
llm?: {
|
|
189
|
+
model?: ICopilotModel;
|
|
190
|
+
scope?: "input" | "output" | "both";
|
|
191
|
+
systemPrompt?: string;
|
|
192
|
+
outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
|
|
193
|
+
onLlmError?: "block" | "rewrite";
|
|
194
|
+
errorRewriteText?: string;
|
|
195
|
+
blockMessage?: string;
|
|
196
|
+
rewriteFallbackText?: string;
|
|
197
|
+
timeoutMs?: number;
|
|
198
|
+
};
|
|
199
|
+
mode?: "llm";
|
|
200
|
+
rules?: unknown;
|
|
201
|
+
generalPack?: unknown;
|
|
202
|
+
caseSensitive?: unknown;
|
|
203
|
+
}>]>;
|
|
204
|
+
export declare const llmDecisionSchema: z.ZodEffects<z.ZodObject<{
|
|
205
|
+
matched: z.ZodBoolean;
|
|
206
|
+
action: z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>;
|
|
207
|
+
replacementText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
208
|
+
reason: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
209
|
+
categories: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
210
|
+
}, "strip", z.ZodTypeAny, {
|
|
211
|
+
action?: "block" | "rewrite";
|
|
212
|
+
replacementText?: string;
|
|
213
|
+
matched?: boolean;
|
|
214
|
+
reason?: string;
|
|
215
|
+
categories?: string[];
|
|
216
|
+
}, {
|
|
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[];
|
|
228
|
+
}, {
|
|
229
|
+
action?: "block" | "rewrite";
|
|
230
|
+
replacementText?: string;
|
|
231
|
+
matched?: boolean;
|
|
232
|
+
reason?: string;
|
|
233
|
+
categories?: string[];
|
|
114
234
|
}>;
|
|
115
235
|
export declare function resolveGeneralPackRules(config?: GeneralPackConfig): SensitiveRule[];
|
|
116
236
|
//# 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,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,CAAA;IACb,iBAAiB,EAAE,MAAM,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,mBAAmB,wSAA8R,CAAA;AAkE9T,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAuD,CAAA;AAE/F,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgB1B,CAAA;AAYJ,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,aAAa,EAAE,CA6CnF"}
|
package/dist/lib/types.js
CHANGED
|
@@ -18,39 +18,63 @@ 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
|
+
systemPrompt: z.string().optional().nullable(),
|
|
38
|
+
outputMethod: z.enum(['functionCalling', 'jsonMode', 'jsonSchema']).optional().default('jsonSchema'),
|
|
39
|
+
onLlmError: z.enum(['block', 'rewrite']).optional().nullable(),
|
|
40
|
+
errorRewriteText: z.string().optional().nullable(),
|
|
41
|
+
blockMessage: z.string().optional().nullable(),
|
|
42
|
+
rewriteFallbackText: z.string().optional().nullable(),
|
|
43
|
+
timeoutMs: z.number().int().positive().max(120000).optional().nullable(),
|
|
44
|
+
});
|
|
45
|
+
const ruleModeConfigSchema = z.object({
|
|
46
|
+
mode: z.literal('rule').optional(),
|
|
47
|
+
rules: z.array(sensitiveRuleDraftSchema).optional().default([]),
|
|
51
48
|
generalPack: generalPackSchema.optional(),
|
|
52
49
|
caseSensitive: z.boolean().optional().default(false),
|
|
53
50
|
normalize: z.boolean().optional().default(true),
|
|
51
|
+
llm: z.unknown().optional(),
|
|
52
|
+
});
|
|
53
|
+
const llmModeConfigSchema = z.object({
|
|
54
|
+
mode: z.literal('llm'),
|
|
55
|
+
llm: llmConfigSchema.optional().nullable().default({}),
|
|
56
|
+
rules: z.unknown().optional(),
|
|
57
|
+
generalPack: z.unknown().optional(),
|
|
58
|
+
caseSensitive: z.unknown().optional(),
|
|
59
|
+
normalize: z.unknown().optional(),
|
|
60
|
+
});
|
|
61
|
+
export const sensitiveFilterConfigSchema = z.union([ruleModeConfigSchema, llmModeConfigSchema]);
|
|
62
|
+
export const llmDecisionSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
matched: z.boolean(),
|
|
65
|
+
action: z.enum(['block', 'rewrite']).optional(),
|
|
66
|
+
replacementText: z.string().optional().nullable(),
|
|
67
|
+
reason: z.string().optional().nullable(),
|
|
68
|
+
categories: z.array(z.string()).optional().nullable(),
|
|
69
|
+
})
|
|
70
|
+
.superRefine((data, ctx) => {
|
|
71
|
+
if (data.matched && !data.action) {
|
|
72
|
+
ctx.addIssue({
|
|
73
|
+
code: z.ZodIssueCode.custom,
|
|
74
|
+
path: ['action'],
|
|
75
|
+
message: 'action is required when matched is true',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
54
78
|
});
|
|
55
79
|
function escapeRegExp(value) {
|
|
56
80
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|