refactor: 拆分 agent 模块为 commands/agent/ 和 api/agent.py

This commit is contained in:
gitea committed 2026-04-06 00:14:16 +08:00
1 parent 3c4ad6256a
commit cd78261cae
7 files changed
+44 -12

No files matched your search

+3 -2
View File
@@ -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():
File renamed without changes.
+7
View File
@@ -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)
+12
View File
@@ -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)
+8
View File
@@ -0,0 +1,8 @@
"""ekb agent get <id>:查看 Agent 详情(待实现)"""
from rich import print as rprint
def cmd_detail(agent_id: str):
"""查看 Agent 详情"""
rprint(f"[yellow]待实现:agent get {agent_id}[/yellow]")
@@ -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)
+8
View File
@@ -0,0 +1,8 @@
"""ekb agent logs <id>:查看 Agent 审核日志(待实现)"""
from rich import print as rprint
def cmd_logs(agent_id: str):
"""查看 Agent 审核日志"""
rprint(f"[yellow]待实现:agent logs {agent_id}[/yellow]")