批量收口 commands/agent/* 边界:全部改用 _cmd 便捷函数
- rule_service.py 新增 list_rules_cmd / get_rule_cmd / create_rule_cmd - services/__init__.py 导出以上三个 _cmd 函数 - commands/agent/ 下 8 个文件一律移除 `from ekb_cli.api import get_client`, 改为调用 services 层对应的 _cmd 函数(自管 client 生命周期) - 同步清理各文件中残留的局部 try/except EkbError,统一冒泡至全局 handler - 验证:commands/ 目录内已无任何 api 层直接引用
This commit is contained in:
1 parent
19f6c02c2c
commit
c87dfa52a5
10 files changed
+123
-122
No files matched your search
@@ -1,24 +1,20 @@
|
|||||||
"""ekb agent copy <id>:复制智能审核 Agent(表现层)"""
|
"""ekb agent copy <id>:复制智能审核 Agent(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.copy_agent_cmd 复制 Agent。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
|
"""
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import copy_agent_cmd, MODE_DISPLAY
|
||||||
from ekb_cli.services import copy_agent, MODE_DISPLAY
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_copy(
|
def cmd_copy(
|
||||||
agent_id: str = typer.Argument(..., help="要复制的 Agent ID"),
|
agent_id: str = typer.Argument(..., help="要复制的 Agent ID"),
|
||||||
):
|
):
|
||||||
"""复制 Agent(新 Agent 名称为原名称加「(副本)」)"""
|
"""复制 Agent(新 Agent 名称为原名称加「(副本)」)"""
|
||||||
from ekb_cli.errors import EkbError
|
src, new = copy_agent_cmd(agent_id)
|
||||||
|
|
||||||
try:
|
|
||||||
with get_client() as client:
|
|
||||||
src, new = copy_agent(client, agent_id)
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
rprint("[green]✓ Agent 复制成功[/green]")
|
rprint("[green]✓ Agent 复制成功[/green]")
|
||||||
rprint(f" 原 Agent:[dim]{src.name}[/dim] → 新 Agent:[bold]{new.name}[/bold]")
|
rprint(f" 原 Agent:[dim]{src.name}[/dim] → 新 Agent:[bold]{new.name}[/bold]")
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
"""ekb agent create:新建智能审核 Agent(表现层)"""
|
"""ekb agent create:新建智能审核 Agent(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.create_agent_cmd 创建 Agent。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
|
"""
|
||||||
|
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
import typer
|
import typer
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import create_agent_cmd, AgentCreateInput, MODE_DISPLAY
|
||||||
from ekb_cli.services import create_agent, AgentCreateInput, MODE_DISPLAY
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_create(
|
def cmd_create(
|
||||||
@@ -20,7 +23,6 @@ def cmd_create(
|
|||||||
icon: str = typer.Option("", "--icon", help="头像 URL(留空使用默认)"),
|
icon: str = typer.Option("", "--icon", help="头像 URL(留空使用默认)"),
|
||||||
):
|
):
|
||||||
"""新建智能审核 Agent"""
|
"""新建智能审核 Agent"""
|
||||||
from ekb_cli.errors import EkbError
|
|
||||||
from ekb_cli.services.agent_service import DEFAULT_ICON
|
from ekb_cli.services.agent_service import DEFAULT_ICON
|
||||||
|
|
||||||
inp = AgentCreateInput(
|
inp = AgentCreateInput(
|
||||||
@@ -35,12 +37,7 @@ def cmd_create(
|
|||||||
icon=icon or DEFAULT_ICON,
|
icon=icon or DEFAULT_ICON,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
data = create_agent_cmd(inp)
|
||||||
with get_client() as client:
|
|
||||||
data = create_agent(client, inp)
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
rprint("[green]✓ Agent 创建成功[/green]")
|
rprint("[green]✓ Agent 创建成功[/green]")
|
||||||
rprint(f" ID:[dim]{data.id}[/dim]")
|
rprint(f" ID:[dim]{data.id}[/dim]")
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
- 默认:终端可用时用方向键菜单(questionary),否则降级为文字输入
|
- 默认:终端可用时用方向键菜单(questionary),否则降级为文字输入
|
||||||
- --ai:强制文字输入模式(适合 AI/脚本非交互式环境)
|
- --ai:强制文字输入模式(适合 AI/脚本非交互式环境)
|
||||||
- --yes:跳过确认直接删除
|
- --yes:跳过确认直接删除
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.get_agent_cmd / delete_agent_cmd 操作。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -13,8 +16,7 @@ from rich import print as rprint
|
|||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import get_agent_cmd, delete_agent_cmd
|
||||||
from ekb_cli.services import delete_agent
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
@@ -28,58 +30,47 @@ def cmd_delete(
|
|||||||
ai: bool = typer.Option(False, "--ai", help="AI/脚本模式:改用文字输入 y/N 确认"),
|
ai: bool = typer.Option(False, "--ai", help="AI/脚本模式:改用文字输入 y/N 确认"),
|
||||||
):
|
):
|
||||||
"""删除 Agent(不可恢复,操作前会展示 Agent 信息并要求确认)"""
|
"""删除 Agent(不可恢复,操作前会展示 Agent 信息并要求确认)"""
|
||||||
from ekb_cli.errors import EkbError
|
|
||||||
|
|
||||||
# 先拉详情用于展示(service 层已处理 NotFoundError)
|
# 先拉详情用于展示(service 层已处理 NotFoundError)
|
||||||
try:
|
d = get_agent_cmd(agent_id)
|
||||||
with get_client() as client:
|
|
||||||
# 需要先展示再确认,所以分两步使用 client
|
|
||||||
from ekb_cli.services import get_agent as svc_get_agent
|
|
||||||
d = svc_get_agent(client, agent_id)
|
|
||||||
|
|
||||||
rule_count = len(d.agentRule)
|
rule_count = len(d.agentRule)
|
||||||
console.print(Panel(
|
console.print(Panel(
|
||||||
"\n".join([
|
"\n".join([
|
||||||
f"[bold]名称[/bold] {d.name}",
|
f"[bold]名称[/bold] {d.name}",
|
||||||
f"[bold]ID[/bold] [dim]{d.id}[/dim]",
|
f"[bold]ID[/bold] [dim]{d.id}[/dim]",
|
||||||
f"[bold]描述[/bold] {d.description or '(无)'}",
|
f"[bold]描述[/bold] {d.description or '(无)'}",
|
||||||
f"[bold]关联规则[/bold] {rule_count} 条{'(规则本身不会被删除)' if rule_count else ''}",
|
f"[bold]关联规则[/bold] {rule_count} 条{'(规则本身不会被删除)' if rule_count else ''}",
|
||||||
f"[bold]更新时间[/bold] {d.updateTime}",
|
f"[bold]更新时间[/bold] {d.updateTime}",
|
||||||
|
]),
|
||||||
|
title="[bold red]⚠ 即将删除以下 Agent[/bold red]",
|
||||||
|
border_style="red",
|
||||||
|
expand=False,
|
||||||
|
))
|
||||||
|
|
||||||
|
if not yes:
|
||||||
|
if ai or not sys.stdin.isatty():
|
||||||
|
rprint(f"确认删除 Agent「{d.name}」?输入 y 确认,其他任意键取消:", end=" ")
|
||||||
|
answer = input().strip().lower()
|
||||||
|
if answer != "y":
|
||||||
|
rprint("[dim]已取消[/dim]")
|
||||||
|
raise typer.Exit(0)
|
||||||
|
else:
|
||||||
|
choice = questionary.select(
|
||||||
|
f"确认删除 Agent「{d.name}」?",
|
||||||
|
choices=[_CANCEL, _CONFIRM],
|
||||||
|
default=_CANCEL,
|
||||||
|
style=questionary.Style([
|
||||||
|
("selected", "fg:#ff5555 bold"),
|
||||||
|
("pointer", "fg:#ff5555 bold"),
|
||||||
|
("highlighted", "fg:#ff5555"),
|
||||||
|
("question", "bold"),
|
||||||
]),
|
]),
|
||||||
title="[bold red]⚠ 即将删除以下 Agent[/bold red]",
|
).ask()
|
||||||
border_style="red",
|
|
||||||
expand=False,
|
|
||||||
))
|
|
||||||
|
|
||||||
if not yes:
|
if choice != _CONFIRM:
|
||||||
if ai or not sys.stdin.isatty():
|
rprint("[dim]已取消[/dim]")
|
||||||
rprint(f"确认删除 Agent「{d.name}」?输入 y 确认,其他任意键取消:", end=" ")
|
raise typer.Exit(0)
|
||||||
answer = input().strip().lower()
|
|
||||||
if answer != "y":
|
|
||||||
rprint("[dim]已取消[/dim]")
|
|
||||||
raise typer.Exit(0)
|
|
||||||
else:
|
|
||||||
choice = questionary.select(
|
|
||||||
f"确认删除 Agent「{d.name}」?",
|
|
||||||
choices=[_CANCEL, _CONFIRM],
|
|
||||||
default=_CANCEL,
|
|
||||||
style=questionary.Style([
|
|
||||||
("selected", "fg:#ff5555 bold"),
|
|
||||||
("pointer", "fg:#ff5555 bold"),
|
|
||||||
("highlighted", "fg:#ff5555"),
|
|
||||||
("question", "bold"),
|
|
||||||
]),
|
|
||||||
).ask()
|
|
||||||
|
|
||||||
if choice != _CONFIRM:
|
|
||||||
rprint("[dim]已取消[/dim]")
|
|
||||||
raise typer.Exit(0)
|
|
||||||
|
|
||||||
# 确认后执行删除
|
|
||||||
delete_agent(client, agent_id)
|
|
||||||
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
|
# 确认后执行删除
|
||||||
|
delete_agent_cmd(agent_id)
|
||||||
rprint(f"[green]✓ Agent「{d.name}」已删除[/green]")
|
rprint(f"[green]✓ Agent「{d.name}」已删除[/green]")
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
"""ekb agent get <id>:查看 Agent 详情(表现层)"""
|
"""ekb agent get <id>:查看 Agent 详情(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.get_agent_cmd 获取数据。
|
||||||
|
"""
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
@@ -6,8 +9,7 @@ from rich.panel import Panel
|
|||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import get_agent_cmd
|
||||||
from ekb_cli.services import get_agent
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
STATE_MAP = {0: "[dim]草稿[/dim]", 1: "[green]已发布[/green]"}
|
STATE_MAP = {0: "[dim]草稿[/dim]", 1: "[green]已发布[/green]"}
|
||||||
@@ -22,8 +24,7 @@ def cmd_detail(
|
|||||||
full: bool = typer.Option(False, "--full", "-f", help="显示完整内容,不截断规则字段"),
|
full: bool = typer.Option(False, "--full", "-f", help="显示完整内容,不截断规则字段"),
|
||||||
):
|
):
|
||||||
"""查看 Agent 详情"""
|
"""查看 Agent 详情"""
|
||||||
with get_client() as client:
|
d = get_agent_cmd(agent_id)
|
||||||
d = get_agent(client, agent_id)
|
|
||||||
|
|
||||||
state = STATE_MAP.get(d.state, str(d.state))
|
state = STATE_MAP.get(d.state, str(d.state))
|
||||||
mode = MODE_MAP.get(d.mode, str(d.mode))
|
mode = MODE_MAP.get(d.mode, str(d.mode))
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
"""ekb agent rule-create:新建审核规则(表现层)"""
|
"""ekb agent rule-create:新建审核规则(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.create_rule_cmd 新建规则。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
|
"""
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import create_rule_cmd
|
||||||
from ekb_cli.services import create_rule
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_rule_create(
|
def cmd_rule_create(
|
||||||
@@ -13,14 +16,7 @@ def cmd_rule_create(
|
|||||||
level: str = typer.Option("严重", "--level", "-l", help="风险等级:严重 / 一般"),
|
level: str = typer.Option("严重", "--level", "-l", help="风险等级:严重 / 一般"),
|
||||||
):
|
):
|
||||||
"""新建审核规则"""
|
"""新建审核规则"""
|
||||||
from ekb_cli.errors import EkbError
|
rule = create_rule_cmd(purpose=purpose, description=description, level=level)
|
||||||
|
|
||||||
try:
|
|
||||||
with get_client() as client:
|
|
||||||
rule = create_rule(client, purpose=purpose, description=description, level=level)
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
rprint("[green]✓ 规则创建成功[/green]")
|
rprint("[green]✓ 规则创建成功[/green]")
|
||||||
rprint(f" 编码:[bold]{rule.code}[/bold]")
|
rprint(f" 编码:[bold]{rule.code}[/bold]")
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
"""ekb agent rule-get:查看单条规则详情(表现层)"""
|
"""ekb agent rule-get:查看单条规则详情(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.get_rule_cmd 获取数据。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
|
"""
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
@@ -6,8 +10,7 @@ from rich.panel import Panel
|
|||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import get_rule_cmd
|
||||||
from ekb_cli.services import get_rule
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
@@ -16,14 +19,7 @@ def cmd_rule_detail(
|
|||||||
rule_ref: str = typer.Argument(..., help="规则 ID 或编码(如 2040826... 或 #0001 或 0001)"),
|
rule_ref: str = typer.Argument(..., help="规则 ID 或编码(如 2040826... 或 #0001 或 0001)"),
|
||||||
):
|
):
|
||||||
"""查看单条规则详情(含关联 Agent 列表)"""
|
"""查看单条规则详情(含关联 Agent 列表)"""
|
||||||
from ekb_cli.errors import EkbError
|
rule = get_rule_cmd(rule_ref)
|
||||||
|
|
||||||
try:
|
|
||||||
with get_client() as client:
|
|
||||||
rule = get_rule(client, rule_ref)
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
level_color = "red" if rule.level == "严重" else "yellow"
|
level_color = "red" if rule.level == "严重" else "yellow"
|
||||||
level_str = f"[bold {level_color}]{rule.level}[/bold {level_color}]"
|
level_str = f"[bold {level_color}]{rule.level}[/bold {level_color}]"
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
"""ekb agent rules:列出企业所有审核规则(表现层)"""
|
"""ekb agent rules:列出企业所有审核规则(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.list_rules_cmd 获取数据。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
|
"""
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import list_rules_cmd
|
||||||
from ekb_cli.services import list_rules
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
@@ -19,14 +22,7 @@ def cmd_rule_list(
|
|||||||
level: str = typer.Option(None, "--level", "-l", help="按风险等级筛选:严重 / 一般"),
|
level: str = typer.Option(None, "--level", "-l", help="按风险等级筛选:严重 / 一般"),
|
||||||
):
|
):
|
||||||
"""列出企业所有审核规则"""
|
"""列出企业所有审核规则"""
|
||||||
from ekb_cli.errors import EkbError
|
page, items = list_rules_cmd(level=level)
|
||||||
|
|
||||||
try:
|
|
||||||
with get_client() as client:
|
|
||||||
page, items = list_rules(client, level=level)
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
if not items:
|
if not items:
|
||||||
rprint("[dim](暂无规则)[/dim]")
|
rprint("[dim](暂无规则)[/dim]")
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
"""ekb agent update <id>:修改 Agent 配置(表现层)"""
|
"""ekb agent update <id>:修改 Agent 配置(表现层)
|
||||||
|
|
||||||
|
不导入 api 层;通过 services.update_agent_cmd 更新 Agent。
|
||||||
|
EkbError 由 CLI 入口全局 handler 统一处理,本层不 catch。
|
||||||
|
"""
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import typer
|
import typer
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
|
|
||||||
from ekb_cli.api import get_client
|
from ekb_cli.services import update_agent_cmd, AgentUpdateInput, MODE_DISPLAY
|
||||||
from ekb_cli.services import update_agent, AgentUpdateInput, MODE_DISPLAY
|
|
||||||
|
|
||||||
STATE_DISPLAY = {0: "启用", 1: "禁用"}
|
STATE_DISPLAY = {0: "启用", 1: "禁用"}
|
||||||
|
|
||||||
@@ -23,8 +26,6 @@ def cmd_update(
|
|||||||
review_terms: Optional[str] = typer.Option(None, "--review-terms", help="转人工条款"),
|
review_terms: Optional[str] = typer.Option(None, "--review-terms", help="转人工条款"),
|
||||||
):
|
):
|
||||||
"""修改 Agent 配置(只传需要修改的字段)"""
|
"""修改 Agent 配置(只传需要修改的字段)"""
|
||||||
from ekb_cli.errors import EkbError
|
|
||||||
|
|
||||||
inp = AgentUpdateInput(
|
inp = AgentUpdateInput(
|
||||||
agent_id=agent_id,
|
agent_id=agent_id,
|
||||||
name=name,
|
name=name,
|
||||||
@@ -38,12 +39,7 @@ def cmd_update(
|
|||||||
review_terms=review_terms,
|
review_terms=review_terms,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
saved = update_agent_cmd(inp)
|
||||||
with get_client() as client:
|
|
||||||
saved = update_agent(client, inp)
|
|
||||||
except EkbError as e:
|
|
||||||
rprint(f"[red]{e.message}[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
rprint(
|
rprint(
|
||||||
f"[green]✓[/green] 已更新 Agent [bold]{saved.name}[/bold]"
|
f"[green]✓[/green] 已更新 Agent [bold]{saved.name}[/bold]"
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ from ekb_cli.services.rule_service import ( # noqa: F401
|
|||||||
get_rule,
|
get_rule,
|
||||||
create_rule,
|
create_rule,
|
||||||
update_rule,
|
update_rule,
|
||||||
|
# CLI 便捷函数(自管 client 生命周期,commands/* 层使用)
|
||||||
|
list_rules_cmd,
|
||||||
|
get_rule_cmd,
|
||||||
|
create_rule_cmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
# SealAI 子域服务:通过 services.sealai 子包统一导出,
|
# SealAI 子域服务:通过 services.sealai 子包统一导出,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ CLI 和 Server 共用同一套逻辑。
|
|||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ekb_cli.api import EkbClient
|
from ekb_cli.api import EkbClient, get_client
|
||||||
from ekb_cli.api.rule import (
|
from ekb_cli.api.rule import (
|
||||||
list_rules as api_list_rules,
|
list_rules as api_list_rules,
|
||||||
save_rule as api_save_rule,
|
save_rule as api_save_rule,
|
||||||
@@ -114,3 +114,31 @@ def update_rule(
|
|||||||
"level": level if level is not None else current.level,
|
"level": level if level is not None else current.level,
|
||||||
}
|
}
|
||||||
return api_update_rule(client, payload)
|
return api_update_rule(client, payload)
|
||||||
|
|
||||||
|
|
||||||
|
# ── CLI 便捷函数(自管 client 生命周期)────────────────────────
|
||||||
|
# commands/* 层调用这批函数,不需要自行 import get_client,
|
||||||
|
# 保持 commands → services → api 的依赖方向。
|
||||||
|
|
||||||
|
def list_rules_cmd(
|
||||||
|
level: Optional[str] = None,
|
||||||
|
) -> tuple[PageData[RuleWithAgents], list[RuleWithAgents]]:
|
||||||
|
"""CLI 便捷函数:自动获取当前企业 client 并列出所有规则"""
|
||||||
|
with get_client() as client:
|
||||||
|
return list_rules(client, level=level)
|
||||||
|
|
||||||
|
|
||||||
|
def get_rule_cmd(rule_ref: str) -> RuleWithAgents:
|
||||||
|
"""CLI 便捷函数:自动获取当前企业 client 并查找单条规则"""
|
||||||
|
with get_client() as client:
|
||||||
|
return get_rule(client, rule_ref)
|
||||||
|
|
||||||
|
|
||||||
|
def create_rule_cmd(
|
||||||
|
purpose: str,
|
||||||
|
description: str,
|
||||||
|
level: str = "严重",
|
||||||
|
) -> Rule:
|
||||||
|
"""CLI 便捷函数:自动获取当前企业 client 并新建规则"""
|
||||||
|
with get_client() as client:
|
||||||
|
return create_rule(client, purpose=purpose, description=description, level=level)
|
||||||
Reference in new issue
Block a user