plugin-sensitive-filter-xr 0.1.24 → 0.1.25
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitiveFilter.d.ts","sourceRoot":"","sources":["../../src/lib/sensitiveFilter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAa,oBAAoB,EAA8B,MAAM,kBAAkB,CAAA;AAGnG,OAAO,EACL,eAAe,EAGf,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAML,qBAAqB,EAMtB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"sensitiveFilter.d.ts","sourceRoot":"","sources":["../../src/lib/sensitiveFilter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAa,oBAAoB,EAA8B,MAAM,kBAAkB,CAAA;AAGnG,OAAO,EACL,eAAe,EAGf,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAML,qBAAqB,EAMtB,MAAM,YAAY,CAAA;AAs9BnB,qBAEa,yBAA0B,YAAW,wBAAwB,CAAC,qBAAqB,CAAC;IAE/F,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAmQlC;IAEK,gBAAgB,CACpB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,CAAC;IAa3B,OAAO,CAAC,wBAAwB;IA+UhC,OAAO,CAAC,uBAAuB;CA4hBhC;AAED,YAAY,EAAE,qBAAqB,EAAE,CAAA"}
|
|
@@ -117,6 +117,16 @@ function extractInputText(state, runtime) {
|
|
|
117
117
|
}
|
|
118
118
|
return '';
|
|
119
119
|
}
|
|
120
|
+
function toSnippet(text, maxLength = 200) {
|
|
121
|
+
const compact = text.replace(/\s+/g, ' ').trim();
|
|
122
|
+
if (!compact) {
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
if (compact.length <= maxLength) {
|
|
126
|
+
return compact;
|
|
127
|
+
}
|
|
128
|
+
return `${compact.slice(0, maxLength)}...`;
|
|
129
|
+
}
|
|
120
130
|
function buildMatchedNotificationMessage(input) {
|
|
121
131
|
const modeLabel = input.mode === 'rule' ? '规则模式' : 'LLM 模式';
|
|
122
132
|
const finalActionLabel = input.finalAction === 'block' ? '已拦截' : input.finalAction === 'rewrite' ? '已改写' : '放行';
|
|
@@ -143,6 +153,12 @@ function buildMatchedNotificationMessage(input) {
|
|
|
143
153
|
if (!reason) {
|
|
144
154
|
return '无';
|
|
145
155
|
}
|
|
156
|
+
if (reason === 'llm') {
|
|
157
|
+
return 'LLM判定命中(模型未返回具体原因)';
|
|
158
|
+
}
|
|
159
|
+
if (reason.startsWith('llm:')) {
|
|
160
|
+
return `LLM判定:${reason.replace('llm:', '') || '命中'}`;
|
|
161
|
+
}
|
|
146
162
|
if (reason.startsWith('rule:')) {
|
|
147
163
|
return `命中规则 ${reason.replace('rule:', '')}`;
|
|
148
164
|
}
|
|
@@ -156,7 +172,7 @@ function buildMatchedNotificationMessage(input) {
|
|
|
156
172
|
};
|
|
157
173
|
const matched = input.records.filter((entry) => entry.matched);
|
|
158
174
|
const now = new Date();
|
|
159
|
-
const alertTime = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
|
|
175
|
+
const alertTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
|
|
160
176
|
const lines = [
|
|
161
177
|
'【敏感内容告警】',
|
|
162
178
|
`节点:${input.nodeTitle || SENSITIVE_FILTER_MIDDLEWARE_NAME}`,
|
|
@@ -171,6 +187,9 @@ function buildMatchedNotificationMessage(input) {
|
|
|
171
187
|
if (input.runtimeConfigurable?.executionId) {
|
|
172
188
|
lines.push(`执行ID:${input.runtimeConfigurable.executionId}`);
|
|
173
189
|
}
|
|
190
|
+
if (input.inputSnippet?.trim()) {
|
|
191
|
+
lines.push(`最近输入片段:${input.inputSnippet}`);
|
|
192
|
+
}
|
|
174
193
|
lines.push('命中详情:');
|
|
175
194
|
matched.forEach((entry, index) => {
|
|
176
195
|
lines.push(`${index + 1}. 阶段=${phaseLabel(entry.phase)},来源=${sourceLabel(entry.source)},动作=${actionLabel(entry.action)},依据=${reasonLabel(entry.reason)}`);
|
|
@@ -1033,12 +1052,14 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1033
1052
|
let finalAction = 'pass';
|
|
1034
1053
|
let auditEntries = [];
|
|
1035
1054
|
let runtimeConfigurable = null;
|
|
1055
|
+
let latestInputSnippet = '';
|
|
1036
1056
|
const resetRunState = () => {
|
|
1037
1057
|
inputBlockedMessage = null;
|
|
1038
1058
|
pendingInputRewrite = null;
|
|
1039
1059
|
bufferedOutputResolution = null;
|
|
1040
1060
|
finalAction = 'pass';
|
|
1041
1061
|
auditEntries = [];
|
|
1062
|
+
latestInputSnippet = '';
|
|
1042
1063
|
};
|
|
1043
1064
|
const pushAudit = (entry) => {
|
|
1044
1065
|
auditEntries.push({
|
|
@@ -1119,6 +1140,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1119
1140
|
const safeState = state ?? {};
|
|
1120
1141
|
const safeRuntime = runtime ?? {};
|
|
1121
1142
|
const inputText = extractInputText(safeState, safeRuntime);
|
|
1143
|
+
latestInputSnippet = toSnippet(inputText);
|
|
1122
1144
|
const inputMatches = findMatches(inputText, 'input', compiledRules, normalize, caseSensitive);
|
|
1123
1145
|
const winner = pickWinningRule(inputMatches);
|
|
1124
1146
|
if (!winner) {
|
|
@@ -1253,6 +1275,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1253
1275
|
finalAction,
|
|
1254
1276
|
records: matchedRecords,
|
|
1255
1277
|
runtimeConfigurable,
|
|
1278
|
+
inputSnippet: latestInputSnippet,
|
|
1256
1279
|
})
|
|
1257
1280
|
: null;
|
|
1258
1281
|
const [persistResult, notifyResult] = await Promise.allSettled([
|
|
@@ -1308,6 +1331,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1308
1331
|
let finalAction = 'pass';
|
|
1309
1332
|
let auditEntries = [];
|
|
1310
1333
|
let runtimeConfigurable = null;
|
|
1334
|
+
let latestInputSnippet = '';
|
|
1311
1335
|
let resolvedOutputMethod;
|
|
1312
1336
|
let fallbackTriggered = false;
|
|
1313
1337
|
let methodAttempts = [];
|
|
@@ -1316,6 +1340,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1316
1340
|
bufferedOutputResolution = null;
|
|
1317
1341
|
finalAction = 'pass';
|
|
1318
1342
|
auditEntries = [];
|
|
1343
|
+
latestInputSnippet = '';
|
|
1319
1344
|
resolvedOutputMethod = undefined;
|
|
1320
1345
|
fallbackTriggered = false;
|
|
1321
1346
|
methodAttempts = [];
|
|
@@ -1535,6 +1560,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1535
1560
|
return undefined;
|
|
1536
1561
|
}
|
|
1537
1562
|
const inputText = extractInputText(state ?? {}, runtime ?? {});
|
|
1563
|
+
latestInputSnippet = toSnippet(inputText);
|
|
1538
1564
|
if (!inputText) {
|
|
1539
1565
|
pushAudit({
|
|
1540
1566
|
phase: 'input',
|
|
@@ -1691,6 +1717,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1691
1717
|
finalAction,
|
|
1692
1718
|
records: matchedRecords,
|
|
1693
1719
|
runtimeConfigurable,
|
|
1720
|
+
inputSnippet: latestInputSnippet,
|
|
1694
1721
|
})
|
|
1695
1722
|
: null;
|
|
1696
1723
|
const [persistResult, notifyResult] = await Promise.allSettled([
|