feat: add agent update command and ekb commands tree
- ekb agent update: patch-style update, only overrides provided fields - ekb commands [group]: rich tree view of full command hierarchy - api/agent.py: add save_agent() - CLAUDE.md/README.md: simplify to layered structure
This commit is contained in:
1 parent
1879decbcd
commit
1672d14d0b
7 files changed
+188
-49
No files matched your search
@@ -4,9 +4,11 @@ import typer
|
||||
from ekb_cli.commands.agent.list import cmd_list
|
||||
from ekb_cli.commands.agent.detail import cmd_detail
|
||||
from ekb_cli.commands.agent.logs import cmd_logs
|
||||
from ekb_cli.commands.agent.update import cmd_update
|
||||
|
||||
app = typer.Typer(help="智能审核 Agent 管理")
|
||||
|
||||
app.command("list")(cmd_list)
|
||||
app.command("get")(cmd_detail)
|
||||
app.command("update")(cmd_update)
|
||||
app.command("logs")(cmd_logs)
|
||||
@@ -0,0 +1,81 @@
|
||||
"""ekb agent update <id>:修改 Agent 配置"""
|
||||
|
||||
from typing import Optional
|
||||
import typer
|
||||
from rich import print as rprint
|
||||
|
||||
from ekb_cli.api import get_client
|
||||
from ekb_cli.api.agent import get_agent, save_agent
|
||||
|
||||
# mode 映射:CLI 友好名称 → 接口值
|
||||
MODE_NAMES = {"auto": 0, "semi": 1, "assist": 2}
|
||||
MODE_DISPLAY = {0: "全自动", 1: "半自动", 2: "辅助"}
|
||||
STATE_DISPLAY = {0: "启用", 1: "禁用"}
|
||||
|
||||
|
||||
def cmd_update(
|
||||
agent_id: str = typer.Argument(..., help="Agent ID"),
|
||||
name: Optional[str] = typer.Option(None, "--name", "-n", help="名称"),
|
||||
description: Optional[str] = typer.Option(None, "--description", "-d", help="描述"),
|
||||
mode: Optional[str] = typer.Option(None, "--mode", "-m", help="模式:auto/semi/assist"),
|
||||
sampling_rate: Optional[int] = typer.Option(None, "--sampling-rate", "-r", help="半自动抽检比例 0-100"),
|
||||
state: Optional[int] = typer.Option(None, "--state", "-s", help="状态:0=启用 1=禁用"),
|
||||
agree_terms: Optional[str] = typer.Option(None, "--agree-terms", help="同意条款"),
|
||||
reject_terms: Optional[str] = typer.Option(None, "--reject-terms", help="拒绝条款"),
|
||||
exempt_terms: Optional[str] = typer.Option(None, "--exempt-terms", help="豁免条款"),
|
||||
review_terms: Optional[str] = typer.Option(None, "--review-terms", help="转人工条款"),
|
||||
):
|
||||
"""修改 Agent 配置(只传需要修改的字段)"""
|
||||
# 验证 mode 参数
|
||||
mode_val = None
|
||||
if mode is not None:
|
||||
if mode not in MODE_NAMES:
|
||||
rprint(f"[red]mode 必须是 auto / semi / assist,当前:{mode}[/red]")
|
||||
raise typer.Exit(1)
|
||||
mode_val = MODE_NAMES[mode]
|
||||
|
||||
if sampling_rate is not None and not (0 <= sampling_rate <= 100):
|
||||
rprint("[red]sampling-rate 范围是 0-100[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
with get_client() as client:
|
||||
resp = get_agent(client, agent_id)
|
||||
d = resp.get("data", {})
|
||||
if not d:
|
||||
rprint("[red]未找到该 Agent[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
# 基于现有数据构建 payload,仅覆盖传入的字段
|
||||
payload: dict = {
|
||||
"id": d["id"],
|
||||
"icon": d.get("icon", ""),
|
||||
"name": name if name is not None else d.get("name", ""),
|
||||
"description": description if description is not None else d.get("description", ""),
|
||||
"mode": mode_val if mode_val is not None else d.get("mode", 0),
|
||||
"agreeTerms": agree_terms if agree_terms is not None else d.get("agreeTerms", ""),
|
||||
"rejectTerms": reject_terms if reject_terms is not None else d.get("rejectTerms", ""),
|
||||
"exemptTerms": exempt_terms if exempt_terms is not None else d.get("exemptTerms", ""),
|
||||
"reviewTerms": review_terms if review_terms is not None else d.get("reviewTerms", ""),
|
||||
"state": state if state is not None else d.get("state", 0),
|
||||
"ruleIds": [r["id"] for r in d.get("agentRule", [])],
|
||||
}
|
||||
|
||||
# 半自动才需要 samplingRate
|
||||
effective_mode = payload["mode"]
|
||||
if effective_mode == 1:
|
||||
payload["samplingRate"] = (
|
||||
sampling_rate if sampling_rate is not None else d.get("samplingRate", 0)
|
||||
)
|
||||
|
||||
save_resp = save_agent(client, payload)
|
||||
|
||||
if save_resp.get("code") != 200:
|
||||
rprint(f"[red]保存失败:{save_resp.get('msg', '未知错误')}[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
saved = save_resp.get("data", {})
|
||||
rprint(
|
||||
f"[green]✓[/green] 已更新 Agent [bold]{saved.get('name')}[/bold]"
|
||||
f" 模式={MODE_DISPLAY.get(saved.get('mode'), str(saved.get('mode')))}"
|
||||
f" 状态={STATE_DISPLAY.get(saved.get('state'), str(saved.get('state')))}"
|
||||
)
|
||||
Reference in new issue
Block a user