Files
live-call-asr-monitor/frontend-redesign/patch_sandbox3.py
2026-07-16 11:24:02 +08:00

88 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import re
with open('src/components/SandboxSimulation.tsx', 'r') as f:
content = f.read()
old_handle = """ // Perform rule matching
let currentAlerts = [...prev.alerts];
let silentCount = prev.interceptCount;
const activeRules = rules.filter(r => r.enabled);
activeRules.forEach(rule => {
// Check if any keyword matches
const matchedKeyword = rule.keywords.find(kw =>
text.toLowerCase().includes(kw.toLowerCase())
);
if (matchedKeyword) {
// Check if this rule was already triggered in the current session
const alreadyTriggered = currentAlerts.some(a => a.ruleId === rule.id);
if (alreadyTriggered) {
// Duplicate hit: silent interception
silentCount += 1;
// Silent notify
addToast(`规则「${rule.name}」在 seq: ${nextSeq} 中再次触发,已被系统去重静默拦截!`, 'info');
} else {
// Fresh alert!
const alertId = `alert-${rule.id}-${Date.now()}`;
const newAlert: Alert = {
id: alertId,
ruleId: rule.id,
ruleName: rule.name,
keyword: matchedKeyword,
text: text.trim(),
seq: nextSeq,
timestamp,
};
currentAlerts = [...currentAlerts, newAlert];
addToast(`⚠️ 触发预警: 「${rule.name}」(命中词: ${matchedKeyword}`, 'warning');
}
}
});
return {
...prev,
lines: updatedLines,
alerts: currentAlerts,
interceptCount: silentCount
};"""
new_handle = """ // Perform rule matching
let currentAlerts = [...prev.alerts];
const activeRules = rules.filter(r => r.enabled);
activeRules.forEach(rule => {
// Check if any keyword matches
const matchedKeyword = rule.keywords.find(kw =>
text.toLowerCase().includes(kw.toLowerCase())
);
if (matchedKeyword) {
// Fresh alert!
const alertId = `alert-${rule.id}-${Date.now()}`;
const newAlert: Alert = {
id: alertId,
ruleId: rule.id,
ruleName: rule.name,
keyword: matchedKeyword,
text: text.trim(),
seq: nextSeq,
timestamp,
};
currentAlerts = [...currentAlerts, newAlert];
addToast(`⚠️ 触发预警: 「${rule.name}」(命中词: ${matchedKeyword}`, 'warning');
}
});
return {
...prev,
lines: updatedLines,
alerts: currentAlerts
};"""
content = content.replace(old_handle, new_handle)
with open('src/components/SandboxSimulation.tsx', 'w') as f:
f.write(content)