plugin-sensitive-filter-xr 0.1.23 → 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
|
}
|
|
@@ -155,7 +171,8 @@ function buildMatchedNotificationMessage(input) {
|
|
|
155
171
|
return reason;
|
|
156
172
|
};
|
|
157
173
|
const matched = input.records.filter((entry) => entry.matched);
|
|
158
|
-
const
|
|
174
|
+
const now = new Date();
|
|
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')}`;
|
|
159
176
|
const lines = [
|
|
160
177
|
'【敏感内容告警】',
|
|
161
178
|
`节点:${input.nodeTitle || SENSITIVE_FILTER_MIDDLEWARE_NAME}`,
|
|
@@ -170,6 +187,9 @@ function buildMatchedNotificationMessage(input) {
|
|
|
170
187
|
if (input.runtimeConfigurable?.executionId) {
|
|
171
188
|
lines.push(`执行ID:${input.runtimeConfigurable.executionId}`);
|
|
172
189
|
}
|
|
190
|
+
if (input.inputSnippet?.trim()) {
|
|
191
|
+
lines.push(`最近输入片段:${input.inputSnippet}`);
|
|
192
|
+
}
|
|
173
193
|
lines.push('命中详情:');
|
|
174
194
|
matched.forEach((entry, index) => {
|
|
175
195
|
lines.push(`${index + 1}. 阶段=${phaseLabel(entry.phase)},来源=${sourceLabel(entry.source)},动作=${actionLabel(entry.action)},依据=${reasonLabel(entry.reason)}`);
|
|
@@ -1032,12 +1052,14 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1032
1052
|
let finalAction = 'pass';
|
|
1033
1053
|
let auditEntries = [];
|
|
1034
1054
|
let runtimeConfigurable = null;
|
|
1055
|
+
let latestInputSnippet = '';
|
|
1035
1056
|
const resetRunState = () => {
|
|
1036
1057
|
inputBlockedMessage = null;
|
|
1037
1058
|
pendingInputRewrite = null;
|
|
1038
1059
|
bufferedOutputResolution = null;
|
|
1039
1060
|
finalAction = 'pass';
|
|
1040
1061
|
auditEntries = [];
|
|
1062
|
+
latestInputSnippet = '';
|
|
1041
1063
|
};
|
|
1042
1064
|
const pushAudit = (entry) => {
|
|
1043
1065
|
auditEntries.push({
|
|
@@ -1118,6 +1140,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1118
1140
|
const safeState = state ?? {};
|
|
1119
1141
|
const safeRuntime = runtime ?? {};
|
|
1120
1142
|
const inputText = extractInputText(safeState, safeRuntime);
|
|
1143
|
+
latestInputSnippet = toSnippet(inputText);
|
|
1121
1144
|
const inputMatches = findMatches(inputText, 'input', compiledRules, normalize, caseSensitive);
|
|
1122
1145
|
const winner = pickWinningRule(inputMatches);
|
|
1123
1146
|
if (!winner) {
|
|
@@ -1252,6 +1275,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1252
1275
|
finalAction,
|
|
1253
1276
|
records: matchedRecords,
|
|
1254
1277
|
runtimeConfigurable,
|
|
1278
|
+
inputSnippet: latestInputSnippet,
|
|
1255
1279
|
})
|
|
1256
1280
|
: null;
|
|
1257
1281
|
const [persistResult, notifyResult] = await Promise.allSettled([
|
|
@@ -1307,6 +1331,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1307
1331
|
let finalAction = 'pass';
|
|
1308
1332
|
let auditEntries = [];
|
|
1309
1333
|
let runtimeConfigurable = null;
|
|
1334
|
+
let latestInputSnippet = '';
|
|
1310
1335
|
let resolvedOutputMethod;
|
|
1311
1336
|
let fallbackTriggered = false;
|
|
1312
1337
|
let methodAttempts = [];
|
|
@@ -1315,6 +1340,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1315
1340
|
bufferedOutputResolution = null;
|
|
1316
1341
|
finalAction = 'pass';
|
|
1317
1342
|
auditEntries = [];
|
|
1343
|
+
latestInputSnippet = '';
|
|
1318
1344
|
resolvedOutputMethod = undefined;
|
|
1319
1345
|
fallbackTriggered = false;
|
|
1320
1346
|
methodAttempts = [];
|
|
@@ -1534,6 +1560,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1534
1560
|
return undefined;
|
|
1535
1561
|
}
|
|
1536
1562
|
const inputText = extractInputText(state ?? {}, runtime ?? {});
|
|
1563
|
+
latestInputSnippet = toSnippet(inputText);
|
|
1537
1564
|
if (!inputText) {
|
|
1538
1565
|
pushAudit({
|
|
1539
1566
|
phase: 'input',
|
|
@@ -1690,6 +1717,7 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
|
|
|
1690
1717
|
finalAction,
|
|
1691
1718
|
records: matchedRecords,
|
|
1692
1719
|
runtimeConfigurable,
|
|
1720
|
+
inputSnippet: latestInputSnippet,
|
|
1693
1721
|
})
|
|
1694
1722
|
: null;
|
|
1695
1723
|
const [persistResult, notifyResult] = await Promise.allSettled([
|