Files
hose-use/src/ekb_cli/commands/sealai/rule_delete.py
T
gitea 2f51f0f611 SealAI 全面收口:service 层统一管理 client 生命周期 + 401 自动恢复
核心改动(auth_service.py):
- 新增模块级内存 client 缓存(_client_cache),按 corp_id 键入 + TTL 复用
- 磁盘 token 缓存 + 内存 client 缓存双层同步驱逐(invalidate_token 一并清除)
- 新增 _sealai_call(corp_id, fn, ...):统一调用入口,401 时自动清缓存并单次重试
- get_sealai_client 降级为内部函数,不再对外导出

业务 service 层(4 个文件):
- 函数签名从 (client: SealAiClient, ...) 改为 (corp_id: str | None = None, ...)
- 内部统一走 _sealai_call,不自行管理 client

表现层全面收口(11 个 commands 文件 + sealai_router.py):
- 移除所有 get_sealai_client 调用,直接传 corp_id 给 service 函数
- CLI 和 Server 不再感知 SealAiClient 的存在

效果:
- CLI 进程短命,内存 client 随进程回收;Server 长命,连接池复用
- 两条路径代码完全统一,差别仅由进程生命周期自然体现
- 全仓 grep 验证:commands/* 和 server/* 已无任何 get_sealai_client 引用
2026-04-16 09:58:02 +08:00

28 lines
944 B
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.
"""sealai rule-delete:删除草稿审核规则
表现层:二次确认 + rich 输出。
业务逻辑委托给 services.sealai.rules_service。
不感知 SealAiClient,corp_id 由 service 层统一解析。
"""
import typer
from rich import print as rprint
from ekb_cli.services.sealai import remove_draft_rule
def cmd_rule_delete(
rule_id: str = typer.Argument(..., help="草稿规则 ID"),
yes: bool = typer.Option(False, "--yes", "-y", help="跳过确认直接删除"),
corp_id: str = typer.Option(None, "--corp", "-c", help="指定企业 corpId,默认使用当前企业"),
):
"""删除草稿审核规则"""
if not yes:
confirmed = typer.confirm(f"确定要删除规则 {rule_id}?")
if not confirmed:
rprint("[dim]已取消[/dim]")
raise typer.Exit()
remove_draft_rule(corp_id=corp_id, rule_id=rule_id)
rprint(f"[green]✓[/green] 规则 {rule_id} 已删除")