feat: 添加可配置场景注册表与规则引擎
- 新增场景基类、配置加载、注册表与原语模块 - 添加 r10_refund_split 规则及场景 JSON Schema - 扩展 scan 引擎与 scenarios API - 新增场景注册表/配置/集成测试 - 更新前端 App、api、labels 支持新场景
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""场景注册表:按场景码索引,供调度器与 API 统一发现已注册场景。
|
||||
|
||||
仿 app.ingest.registry 的设计:类装饰器自动注册,新增场景零改动核心代码。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.scenarios.base import BaseScenario
|
||||
|
||||
# 全局注册表:scenario_code -> Scenario 类
|
||||
SCENARIO_REGISTRY: dict[str, type[BaseScenario]] = {}
|
||||
|
||||
|
||||
def register_scenario(cls: type[BaseScenario]) -> type[BaseScenario]:
|
||||
"""类装饰器:将场景注册到全局表(按 code 索引)。"""
|
||||
if cls.code:
|
||||
SCENARIO_REGISTRY[cls.code] = cls
|
||||
return cls
|
||||
|
||||
|
||||
def get_scenario(code: str) -> type[BaseScenario] | None:
|
||||
"""按场景码查找已注册的场景类。"""
|
||||
return SCENARIO_REGISTRY.get(code)
|
||||
|
||||
|
||||
def scenario_meta() -> list[dict]:
|
||||
"""导出全部已注册场景的元数据,供 /scenarios API 与前端动态渲染。"""
|
||||
return [
|
||||
{
|
||||
"code": cls.code,
|
||||
"title": cls.title,
|
||||
"label": cls.label,
|
||||
"risk_domain": cls.risk_domain,
|
||||
}
|
||||
for cls in SCENARIO_REGISTRY.values()
|
||||
]
|
||||
Reference in New Issue
Block a user