新增 SealAI 审核规则服务层:草稿 CRUD + 版本历史查询
This commit is contained in:
1 parent
29ec257788
commit
9525f327cd
7 files changed
+264
-8
No files matched your search
@@ -9,6 +9,13 @@ from ekb_cli.services.sealai.billing_service import (
|
||||
query_billing_status,
|
||||
get_feature_usage,
|
||||
)
|
||||
from ekb_cli.services.sealai.rules_service import (
|
||||
get_draft_rules,
|
||||
add_draft_rule,
|
||||
edit_draft_rule,
|
||||
remove_draft_rule,
|
||||
get_published_versions,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"get_sealai_client",
|
||||
@@ -16,4 +23,9 @@ __all__ = [
|
||||
"invalidate_token",
|
||||
"query_billing_status",
|
||||
"get_feature_usage",
|
||||
"get_draft_rules",
|
||||
"add_draft_rule",
|
||||
"edit_draft_rule",
|
||||
"remove_draft_rule",
|
||||
"get_published_versions",
|
||||
]
|
||||
@@ -0,0 +1,74 @@
|
||||
"""SealAI 审核规则业务逻辑层。
|
||||
|
||||
管理草稿区规则的增删改查,以及已发布版本历史的查询。
|
||||
"""
|
||||
|
||||
from ekb_cli.api.sealai.client import SealAiClient
|
||||
from ekb_cli.api.sealai.rules_api import (
|
||||
list_rules,
|
||||
create_rule,
|
||||
update_rule,
|
||||
delete_rule,
|
||||
list_rule_set_versions,
|
||||
)
|
||||
from ekb_cli.api.sealai.schemas import DraftRule, DraftRulesData, RuleSetVersion
|
||||
|
||||
|
||||
def get_draft_rules(client: SealAiClient) -> DraftRulesData:
|
||||
"""查询草稿区所有审核规则。"""
|
||||
return list_rules(client)
|
||||
|
||||
|
||||
def add_draft_rule(
|
||||
client: SealAiClient,
|
||||
description: str,
|
||||
scope: str,
|
||||
strictness: str = "MUST_FOLLOW",
|
||||
) -> DraftRule:
|
||||
"""新建草稿审核规则。
|
||||
|
||||
Args:
|
||||
description: 规则描述
|
||||
scope: 适用场景(费用类型等自由文本)
|
||||
strictness: MUST_FOLLOW | SHOULD_FOLLOW | SUGGESTION,默认 MUST_FOLLOW
|
||||
"""
|
||||
_validate_strictness(strictness)
|
||||
return create_rule(client, description=description, scope=scope, strictness=strictness)
|
||||
|
||||
|
||||
def edit_draft_rule(
|
||||
client: SealAiClient,
|
||||
rule_id: str,
|
||||
*,
|
||||
description: str | None = None,
|
||||
scope: str | None = None,
|
||||
strictness: str | None = None,
|
||||
) -> DraftRule:
|
||||
"""更新草稿规则(只传要改动的字段)。"""
|
||||
if strictness is not None:
|
||||
_validate_strictness(strictness)
|
||||
return update_rule(client, rule_id, description=description, scope=scope, strictness=strictness)
|
||||
|
||||
|
||||
def remove_draft_rule(client: SealAiClient, rule_id: str) -> None:
|
||||
"""删除草稿规则。"""
|
||||
delete_rule(client, rule_id)
|
||||
|
||||
|
||||
def get_published_versions(client: SealAiClient) -> list[RuleSetVersion]:
|
||||
"""查询已发布的规则集版本历史(最新版本在前)。"""
|
||||
return list_rule_set_versions(client)
|
||||
|
||||
|
||||
# ── 内部校验 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
_VALID_STRICTNESS = {"MUST_FOLLOW", "SHOULD_FOLLOW", "SUGGESTION"}
|
||||
|
||||
|
||||
def _validate_strictness(value: str) -> None:
|
||||
if value not in _VALID_STRICTNESS:
|
||||
from ekb_cli.errors import EkbError
|
||||
raise EkbError(
|
||||
f"strictness 无效:{value!r},合法值为 {sorted(_VALID_STRICTNESS)}",
|
||||
code=422,
|
||||
)
|
||||
Reference in new issue
Block a user