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

47 lines
2.0 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.
lines = []
with open('src/components/SandboxSimulation.tsx', 'r') as f:
lines = f.readlines()
out = []
in_block = False
for line in lines:
if "// Perform rule matching" in line:
in_block = True
out.append(line)
out.append(" let currentAlerts = [...prev.alerts];\n")
out.append(" const activeRules = rules.filter(r => r.enabled);\n\n")
out.append(" activeRules.forEach(rule => {\n")
out.append(" // Check if any keyword matches\n")
out.append(" const matchedKeyword = rule.keywords.find(kw => \n")
out.append(" text.toLowerCase().includes(kw.toLowerCase())\n")
out.append(" );\n\n")
out.append(" if (matchedKeyword) {\n")
out.append(" // Fresh alert!\n")
out.append(" const alertId = `alert-${rule.id}-${Date.now()}`;\n")
out.append(" const newAlert: Alert = {\n")
out.append(" id: alertId,\n")
out.append(" ruleId: rule.id,\n")
out.append(" ruleName: rule.name,\n")
out.append(" keyword: matchedKeyword,\n")
out.append(" text: text.trim(),\n")
out.append(" seq: nextSeq,\n")
out.append(" timestamp,\n")
out.append(" };\n")
out.append(" currentAlerts = [...currentAlerts, newAlert];\n")
out.append(" addToast(`⚠️ 触发预警: 「${rule.name}」(命中词: ${matchedKeyword}`, 'warning');\n")
out.append(" }\n")
out.append(" });\n\n")
out.append(" return {\n")
out.append(" ...prev,\n")
out.append(" lines: updatedLines,\n")
out.append(" alerts: currentAlerts\n")
out.append(" };\n")
elif in_block and " });" in line:
in_block = False
out.append(line)
elif not in_block:
out.append(line)
with open('src/components/SandboxSimulation.tsx', 'w') as f:
f.writelines(out)