diff --git a/src/ekb_cli/__init__.py b/src/ekb_cli/__init__.py index d268344..95988a7 100644 --- a/src/ekb_cli/__init__.py +++ b/src/ekb_cli/__init__.py @@ -1,7 +1,8 @@ """ekb-cli:快报命令行工具""" import typer -from ekb_cli.commands import auth, agent +from ekb_cli.commands import auth +from ekb_cli.commands.agent import app as agent_app app = typer.Typer( name="ekb", @@ -10,7 +11,7 @@ app = typer.Typer( ) app.add_typer(auth.app, name="auth") -app.add_typer(agent.app, name="agent") +app.add_typer(agent_app, name="agent") def main(): diff --git a/src/ekb_cli/api.py b/src/ekb_cli/api/__init__.py similarity index 100% rename from src/ekb_cli/api.py rename to src/ekb_cli/api/__init__.py diff --git a/src/ekb_cli/api/agent.py b/src/ekb_cli/api/agent.py new file mode 100644 index 0000000..a1a8c46 --- /dev/null +++ b/src/ekb_cli/api/agent.py @@ -0,0 +1,7 @@ +"""Agent 相关 API 调用封装""" + +from ekb_cli.api import EkbClient + + +def list_agents(client: EkbClient, page: int = 1, size: int = 1000) -> dict: + return client.get("/engine/hab/agent/list", page=page, size=size) diff --git a/src/ekb_cli/commands/agent/__init__.py b/src/ekb_cli/commands/agent/__init__.py new file mode 100644 index 0000000..f8eb760 --- /dev/null +++ b/src/ekb_cli/commands/agent/__init__.py @@ -0,0 +1,12 @@ +"""agent 子命令组""" + +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 + +app = typer.Typer(help="智能审核 Agent 管理") + +app.command("list")(cmd_list) +app.command("get")(cmd_detail) +app.command("logs")(cmd_logs) diff --git a/src/ekb_cli/commands/agent/detail.py b/src/ekb_cli/commands/agent/detail.py new file mode 100644 index 0000000..b3a5a37 --- /dev/null +++ b/src/ekb_cli/commands/agent/detail.py @@ -0,0 +1,8 @@ +"""ekb agent get :查看 Agent 详情(待实现)""" + +from rich import print as rprint + + +def cmd_detail(agent_id: str): + """查看 Agent 详情""" + rprint(f"[yellow]待实现:agent get {agent_id}[/yellow]") diff --git a/src/ekb_cli/commands/agent.py b/src/ekb_cli/commands/agent/list.py similarity index 67% rename from src/ekb_cli/commands/agent.py rename to src/ekb_cli/commands/agent/list.py index 54dae0d..d661e5a 100644 --- a/src/ekb_cli/commands/agent.py +++ b/src/ekb_cli/commands/agent/list.py @@ -1,4 +1,4 @@ -"""agent 命令:智能审核 Agent 管理""" +"""ekb agent list:列出所有智能审核 Agent""" import typer from rich.console import Console @@ -6,18 +6,16 @@ from rich.table import Table from rich import print as rprint from ekb_cli.api import get_client +from ekb_cli.api.agent import list_agents -app = typer.Typer(help="智能审核 Agent 管理") console = Console() - STATE_MAP = {0: "[green]启用[/green]", 1: "[red]禁用[/red]"} -@app.command("list") -def agent_list(): +def cmd_list(): """列出所有智能审核 Agent""" with get_client() as client: - resp = client.get("/engine/hab/agent/list", page=1, size=1000) + resp = list_agents(client) items = resp.get("data", {}).get("items") or [] if not items: @@ -32,13 +30,11 @@ def agent_list(): table.add_column("更新时间") for item in items: - state_text = STATE_MAP.get(item.get("state"), str(item.get("state", ""))) - mode = "自动" if item.get("mode") == 2 else str(item.get("mode", "")) table.add_row( str(item.get("id", "")), item.get("name", ""), - mode, - state_text, + "自动" if item.get("mode") == 2 else str(item.get("mode", "")), + STATE_MAP.get(item.get("state"), str(item.get("state", ""))), item.get("updateTime", ""), ) console.print(table) diff --git a/src/ekb_cli/commands/agent/logs.py b/src/ekb_cli/commands/agent/logs.py new file mode 100644 index 0000000..79c516d --- /dev/null +++ b/src/ekb_cli/commands/agent/logs.py @@ -0,0 +1,8 @@ +"""ekb agent logs :查看 Agent 审核日志(待实现)""" + +from rich import print as rprint + + +def cmd_logs(agent_id: str): + """查看 Agent 审核日志""" + rprint(f"[yellow]待实现:agent logs {agent_id}[/yellow]")