From 10224aee5c878bf917b3337f55600ed64279f6db Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Sat, 18 Jul 2026 09:31:17 +0800 Subject: [PATCH] Refactor Rule Management and Configuration Components - Rename RuleManagement component to RuleConfiguration for clarity. - Introduce a new RuleConfiguration component to manage rules, LLM configurations, and matcher settings. - Update App component to reflect the new RuleConfiguration import and adjust layout styles. - Remove unused LLM configuration logic from RuleManagement, streamlining the component's responsibilities. - Enhance UI elements for better user experience and accessibility. This refactor sets the stage for improved rule and model management in the application. --- frontend/src/App.tsx | 6 +- frontend/src/components/LlmConfiguration.tsx | 413 ++++++------------ frontend/src/components/RuleConfiguration.tsx | 366 ++++++++++++++++ frontend/src/components/RuleManagement.tsx | 122 +----- 4 files changed, 517 insertions(+), 390 deletions(-) create mode 100644 frontend/src/components/RuleConfiguration.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a37f64c..d6c5375 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,7 +6,7 @@ import React, { useState, useEffect, useMemo } from 'react'; import { motion, AnimatePresence } from 'motion/react'; import Header from './components/Header'; -import RuleManagement from './components/RuleManagement'; +import RuleConfiguration from './components/RuleConfiguration'; import SandboxSimulation from './components/SandboxSimulation'; import ToastContainer, { Toast } from './components/ToastContainer'; import { @@ -229,7 +229,7 @@ export default function App() { /> {/* Main Container Area */} -
+
{activeTab === 'rules' ? ( - (config); - const [errors, setErrors] = useState>({}); - - const openDrawer = () => { - setDraft(config); - setErrors({}); - setIsOpen(true); + const update = (key: Key, value: LlmConfig[Key]) => { + onChange({ ...config, [key]: value }); }; - const saveDraft = () => { - const nextErrors: Record = {}; - if (!draft.baseUrl.trim()) nextErrors.baseUrl = '请填写模型服务地址'; - try { - const url = new URL(draft.baseUrl); - if (!['http:', 'https:'].includes(url.protocol)) throw new Error(); - } catch { - nextErrors.baseUrl = '请填写有效的 HTTP(S) 地址'; - } - if (!draft.model.trim()) nextErrors.model = '请填写模型名称'; - if (draft.timeoutMs < 300 || draft.timeoutMs > 30000) { - nextErrors.timeoutMs = '超时时间需在 300–30000ms 之间'; - } - if (draft.maxOutputTokens < 8 || draft.maxOutputTokens > 256) { - nextErrors.maxOutputTokens = '最大输出需在 8–256 Token 之间'; - } - const missingVariable = ['{{rules}}', '{{alerted_event_ids}}', '{{conversation}}'] - .find(variable => !draft.prompt.includes(variable)); - if (missingVariable) { - nextErrors.prompt = `提示词需要包含 ${missingVariable}`; - } - if (Object.keys(nextErrors).length > 0) { - setErrors(nextErrors); - return; - } - - onChange({ - ...draft, - baseUrl: draft.baseUrl.trim().replace(/\/+$/, ''), - model: draft.model.trim(), - prompt: draft.prompt.trim(), - }); - setIsOpen(false); - addToast('模型与提示词已加入当前草稿,点击“保存并发布”后生效', 'success'); + const restorePrompt = () => { + update('prompt', DEFAULT_PROMPT); + addToast('已恢复默认提示词,保存并发布后生效', 'info'); }; return ( - <> -
-
+
+
+
-
- +
+
-
-
-

大模型事件匹配

+
+
+

模型连接

- LLM + OpenAI Compatible
-

- 模型只输出短事件 ID;后端负责 ID 映射、事件名称还原和通话内最终去重。 +

+ 配置后端实际调用的模型服务。模型配置和规则一起进入版本历史。

-
- - - - +
+ + + +
+
+ +
+
+ + update('baseUrl', event.target.value)} + placeholder="https://api.openai.com/v1" + className={inputClass()} + /> + + + update('model', event.target.value)} + placeholder="gpt-4.1-mini" + className={`${inputClass()} font-mono`} + /> + + + update('timeoutMs', Number(event.target.value))} + className={`${inputClass()} font-mono`} + /> + + + update('maxOutputTokens', Number(event.target.value))} + className={`${inputClass()} font-mono`} + /> + +
+ +
+ +

+ API Key 不在页面保存。请在后端启动环境设置 + LLM_API_KEY + ,避免密钥进入浏览器、数据库和版本历史。 +

- - {isOpen && ( - <> - setIsOpen(false)} - className="fixed inset-0 z-50 bg-slate-950 backdrop-blur-3xs" - /> +
+
+
+
+ +
+
+

事件判断提示词

+

+ 后端会把规则、已发送事件和共享通话上下文注入变量;实际通话上下文始终追加在请求最末尾,以便复用 KV Cache。 +

+
+
+ +
- -
-
-
- -

- 模型与提示词配置 -

-
-

- 该配置与规则一起保存、发布和版本回溯。 -

-
- -
+
+