feat(platform): 接入 CLI 命令层和 HTTP 路由层
commands/platform/(新建子目录,对齐 agent/ sealai/):
- list.py → ekb platform list
- workflow_list.py → ekb platform workflow-list <id> [--page] [--page-size]
- workflow_stats.py → ekb platform workflow-stats <id>
- workflow_charge.py → ekb platform workflow-charge
server/platform_router.py(新建,prefix=/platforms):
- GET /platforms
- GET /platforms/{id}/workflows
- GET /platforms/{id}/workflows/stats
- GET /platforms/workflows/charge
server/deps.py:新增 EasoClientDep(EASO Bearer JWT 依赖注入)
commands/help.py:补充 platform 命令组到命令树
ekb_cli/__init__.py:注册 platform_app
server/__init__.py:注册 platform_router
This commit is contained in:
1 parent
474349e7e4
commit
6912c51e43
11 files changed
+265
-4
No files matched your search
@@ -7,6 +7,7 @@ import typer
|
||||
from ekb_cli.commands import auth
|
||||
from ekb_cli.commands.agent import app as agent_app
|
||||
from ekb_cli.commands.sealai import app as sealai_app
|
||||
from ekb_cli.commands.platform import app as platform_app
|
||||
from ekb_cli.commands.help import cmd_commands
|
||||
from ekb_cli.commands.serve import cmd_serve
|
||||
|
||||
@@ -19,6 +20,7 @@ app = typer.Typer(
|
||||
app.add_typer(auth.app, name="auth")
|
||||
app.add_typer(agent_app, name="agent")
|
||||
app.add_typer(sealai_app, name="sealai")
|
||||
app.add_typer(platform_app, name="platform")
|
||||
app.command("commands")(cmd_commands)
|
||||
app.command("serve")(cmd_serve)
|
||||
|
||||
|
||||
@@ -50,6 +50,13 @@ COMMAND_TREE = {
|
||||
"knowledge-create": "新建知识文档 → ekb sealai knowledge-create --help",
|
||||
"knowledge-update": "更新知识文档 → ekb sealai knowledge-update <id> --help",
|
||||
},
|
||||
"platform": {
|
||||
"_help": "自建应用(DataLink Platform)管理",
|
||||
"list": "列出当前企业所有启用的自建应用",
|
||||
"workflow-list": "列出指定应用的工作流 → ekb platform workflow-list <platform_id> --help",
|
||||
"workflow-stats": "查看工作流执行统计 → ekb platform workflow-stats <platform_id>",
|
||||
"workflow-charge": "查看企业工作流资源包配额",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# commands/platform — 自建应用命令层
|
||||
|
||||
## 命令一览
|
||||
|
||||
| 命令 | 说明 |
|
||||
|---|---|
|
||||
| `ekb platform list` | 列出当前企业所有启用的自建应用 |
|
||||
| `ekb platform workflow-list <platform_id>` | 分页列出指定应用的工作流 |
|
||||
| `ekb platform workflow-stats <platform_id>` | 查看工作流执行统计 |
|
||||
| `ekb platform workflow-charge` | 查看企业工作流资源包配额 |
|
||||
|
||||
## 文件说明
|
||||
|
||||
| 文件 | 对应命令 |
|
||||
|---|---|
|
||||
| `list.py` | `ekb platform list` |
|
||||
| `workflow_list.py` | `ekb platform workflow-list` |
|
||||
| `workflow_stats.py` | `ekb platform workflow-stats` |
|
||||
| `workflow_charge.py` | `ekb platform workflow-charge` |
|
||||
|
||||
## 待实现(预留)
|
||||
|
||||
以下子模块待接口抓包后开发:
|
||||
|
||||
| 命令(待建) | 对应业务 |
|
||||
|---|---|
|
||||
| `ekb platform entity-list <platform_id>` | 业务对象(实体)列表 |
|
||||
| `ekb platform page-list <platform_id>` | 页面设计器列表 |
|
||||
@@ -0,0 +1,15 @@
|
||||
"""platform 子命令组:自建应用管理"""
|
||||
|
||||
import typer
|
||||
|
||||
from ekb_cli.commands.platform.list import cmd_list
|
||||
from ekb_cli.commands.platform.workflow_list import cmd_workflow_list
|
||||
from ekb_cli.commands.platform.workflow_stats import cmd_workflow_stats
|
||||
from ekb_cli.commands.platform.workflow_charge import cmd_workflow_charge
|
||||
|
||||
app = typer.Typer(help="自建应用(DataLink Platform)管理")
|
||||
|
||||
app.command("list")(cmd_list)
|
||||
app.command("workflow-list")(cmd_workflow_list)
|
||||
app.command("workflow-stats")(cmd_workflow_stats)
|
||||
app.command("workflow-charge")(cmd_workflow_charge)
|
||||
@@ -0,0 +1,36 @@
|
||||
"""ekb platform list:列出当前企业下所有启用的自建应用"""
|
||||
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich import print as rprint
|
||||
|
||||
from ekb_cli.services.platform import list_platforms_cmd
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def cmd_list():
|
||||
"""列出当前企业所有启用的自建应用"""
|
||||
platforms = list_platforms_cmd()
|
||||
|
||||
if not platforms:
|
||||
rprint("[yellow]暂无自建应用[/yellow]")
|
||||
return
|
||||
|
||||
table = Table(title="自建应用列表")
|
||||
table.add_column("ID", style="dim")
|
||||
table.add_column("名称")
|
||||
table.add_column("编码")
|
||||
table.add_column("类型")
|
||||
table.add_column("状态")
|
||||
|
||||
for p in platforms:
|
||||
table.add_row(
|
||||
p.id,
|
||||
p.name,
|
||||
p.code,
|
||||
p.platformType or p.groupType,
|
||||
"[green]启用[/green]" if p.active else "[dim]停用[/dim]",
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
@@ -0,0 +1,26 @@
|
||||
"""ekb platform workflow-charge:查看企业工作流资源包/配额"""
|
||||
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
from ekb_cli.services.platform import get_workflow_charge_cmd
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def cmd_workflow_charge():
|
||||
"""查看企业工作流资源包配额"""
|
||||
charge = get_workflow_charge_cmd()
|
||||
|
||||
table = Table(title="工作流资源包配额")
|
||||
table.add_column("指标")
|
||||
table.add_column("数值", justify="right")
|
||||
|
||||
table.add_row("企业 ID", charge.corporationId)
|
||||
table.add_row("订购状态", charge.status)
|
||||
table.add_row("套餐类型", charge.orderType)
|
||||
table.add_row("总配额", str(charge.total))
|
||||
table.add_row("已使用", str(charge.used))
|
||||
table.add_row("剩余", str(charge.remaining))
|
||||
|
||||
console.print(table)
|
||||
@@ -0,0 +1,47 @@
|
||||
"""ekb platform workflow-list:列出指定自建应用下的工作流"""
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich import print as rprint
|
||||
|
||||
from ekb_cli.services.platform import list_workflows_cmd
|
||||
|
||||
console = Console()
|
||||
|
||||
STATE_MAP = {0: "[dim]停用[/dim]", 1: "[green]启用[/green]"}
|
||||
|
||||
|
||||
def cmd_workflow_list(
|
||||
platform_id: str = typer.Argument(..., help="自建应用 ID"),
|
||||
page: int = typer.Option(1, "--page", "-p", help="页码(从 1 开始)"),
|
||||
page_size: int = typer.Option(20, "--page-size", "-s", help="每页数量"),
|
||||
):
|
||||
"""列出指定自建应用下的工作流(分页)"""
|
||||
result = list_workflows_cmd(platform_id, page=page, page_size=page_size)
|
||||
|
||||
if not result.pipelineList:
|
||||
rprint("[yellow]暂无工作流[/yellow]")
|
||||
return
|
||||
|
||||
table = Table(
|
||||
title=f"工作流列表(应用 {platform_id},第 {result.number}/{result.totalPages} 页,共 {result.pipelineNum} 条)"
|
||||
)
|
||||
table.add_column("ID", style="dim")
|
||||
table.add_column("名称")
|
||||
table.add_column("状态")
|
||||
table.add_column("运行中")
|
||||
table.add_column("失败")
|
||||
table.add_column("更新时间")
|
||||
|
||||
for wf in result.pipelineList:
|
||||
table.add_row(
|
||||
wf.id,
|
||||
wf.pipelineName,
|
||||
STATE_MAP.get(wf.state, str(wf.state)),
|
||||
str(wf.runningCount),
|
||||
str(wf.errorCount),
|
||||
wf.updateTime,
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
@@ -0,0 +1,30 @@
|
||||
"""ekb platform workflow-stats:查看指定自建应用的工作流执行统计"""
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
from ekb_cli.services.platform import get_workflow_stats_cmd
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def cmd_workflow_stats(
|
||||
platform_id: str = typer.Argument(..., help="自建应用 ID"),
|
||||
):
|
||||
"""查看指定自建应用的工作流执行统计"""
|
||||
stats = get_workflow_stats_cmd(platform_id)
|
||||
|
||||
table = Table(title=f"工作流执行统计(应用 {platform_id})")
|
||||
table.add_column("指标")
|
||||
table.add_column("数值", justify="right")
|
||||
|
||||
table.add_row("总执行次数", str(stats.total))
|
||||
table.add_row("已完成", str(stats.completed))
|
||||
table.add_row("失败", str(stats.failed))
|
||||
table.add_row("进行中", str(stats.started))
|
||||
table.add_row("已启用工作流", str(stats.pipelineOpenCount))
|
||||
table.add_row("已停用工作流", str(stats.pipelineCloseCount))
|
||||
table.add_row("工作流总数", str(stats.pipelineAllCount))
|
||||
|
||||
console.print(table)
|
||||
@@ -29,11 +29,13 @@ def create_app() -> FastAPI:
|
||||
from ekb_cli.server.agent_router import router as agent_router
|
||||
from ekb_cli.server.rule_router import router as rule_router
|
||||
from ekb_cli.server.sealai_router import router as sealai_router
|
||||
from ekb_cli.server.platform_router import router as platform_router
|
||||
|
||||
app.include_router(auth_router, prefix="/auth", tags=["auth"])
|
||||
app.include_router(agent_router, prefix="/agents", tags=["agent"])
|
||||
app.include_router(rule_router, prefix="/rules", tags=["rule"])
|
||||
app.include_router(sealai_router, prefix="/sealai", tags=["sealai"])
|
||||
app.include_router(platform_router, prefix="/platforms", tags=["platform"])
|
||||
|
||||
# ── 统一异常处理:EkbError → HTTP JSON ──────────────────
|
||||
# code → HTTP status 的映射表
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
"""FastAPI 依赖注入:获取已认证的 EkbClient
|
||||
"""FastAPI 依赖注入:获取已认证的 EkbClient / EasoClient
|
||||
|
||||
用法:
|
||||
from ekb_cli.server.deps import ClientDep
|
||||
from ekb_cli.server.deps import ClientDep, EasoClientDep
|
||||
|
||||
@router.get("/foo")
|
||||
def my_route(client: ClientDep):
|
||||
...
|
||||
def my_route(client: ClientDep): ...
|
||||
|
||||
@router.get("/workflow")
|
||||
def my_workflow_route(client: EasoClientDep): ...
|
||||
"""
|
||||
|
||||
from typing import Annotated, Generator
|
||||
@@ -13,6 +15,7 @@ from typing import Annotated, Generator
|
||||
from fastapi import Depends
|
||||
|
||||
from ekb_cli.api import EkbClient, get_client
|
||||
from ekb_cli.api.platform.easo_client import EasoClient, get_easo_client
|
||||
|
||||
|
||||
def _get_ekb_client() -> Generator[EkbClient, None, None]:
|
||||
@@ -24,5 +27,15 @@ def _get_ekb_client() -> Generator[EkbClient, None, None]:
|
||||
client.close()
|
||||
|
||||
|
||||
def _get_easo_client() -> Generator[EasoClient, None, None]:
|
||||
"""FastAPI 依赖:获取 EASO 工作流客户端(Bearer JWT),请求结束后自动关闭连接"""
|
||||
client = get_easo_client()
|
||||
try:
|
||||
yield client
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
|
||||
# 类型别名,路由函数用 `client: ClientDep` 即可,简洁且支持类型推断
|
||||
ClientDep = Annotated[EkbClient, Depends(_get_ekb_client)]
|
||||
EasoClientDep = Annotated[EasoClient, Depends(_get_easo_client)]
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Server:Platform 路由
|
||||
|
||||
对应 CLI 命令:
|
||||
ekb platform list → GET /platforms
|
||||
ekb platform workflow-list <platform_id> → GET /platforms/{platform_id}/workflows
|
||||
ekb platform workflow-stats <platform_id> → GET /platforms/{platform_id}/workflows/stats
|
||||
ekb platform workflow-charge → GET /platforms/workflows/charge
|
||||
|
||||
设计约定:
|
||||
- 自建应用列表使用 EkbClient(主站认证)
|
||||
- 工作流相关接口使用 EasoClient(EASO Bearer JWT),通过 EasoClientDep 注入
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Query
|
||||
|
||||
from ekb_cli.server.deps import ClientDep, EasoClientDep
|
||||
from ekb_cli.services.platform import (
|
||||
list_platforms,
|
||||
list_workflows,
|
||||
get_workflow_stats,
|
||||
get_workflow_charge,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("", summary="列出所有自建应用")
|
||||
def route_list_platforms(client: ClientDep):
|
||||
"""返回当前企业下所有启用的自建应用列表"""
|
||||
platforms = list_platforms(client)
|
||||
return {"total": len(platforms), "items": [p.model_dump() for p in platforms]}
|
||||
|
||||
|
||||
@router.get("/{platform_id}/workflows", summary="列出指定应用的工作流")
|
||||
def route_list_workflows(
|
||||
platform_id: str,
|
||||
client: EasoClientDep,
|
||||
page: int = Query(1, ge=1, description="页码,从 1 开始"),
|
||||
page_size: int = Query(20, ge=1, le=100, description="每页数量"),
|
||||
):
|
||||
"""分页获取指定自建应用下的工作流列表"""
|
||||
result = list_workflows(client, platform_id, page=page, page_size=page_size)
|
||||
return result.model_dump()
|
||||
|
||||
|
||||
@router.get("/{platform_id}/workflows/stats", summary="工作流执行统计")
|
||||
def route_workflow_stats(platform_id: str, client: EasoClientDep):
|
||||
"""获取指定自建应用的工作流执行统计(总数/成功/失败等)"""
|
||||
return get_workflow_stats(client, platform_id).model_dump()
|
||||
|
||||
|
||||
@router.get("/workflows/charge", summary="企业工作流资源包配额")
|
||||
def route_workflow_charge(client: EasoClientDep):
|
||||
"""获取企业工作流资源包总量/已用/剩余"""
|
||||
return get_workflow_charge(client).model_dump()
|
||||
Reference in new issue
Block a user