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:
gitea committed 2026-04-17 09:50:44 +08:00
1 parent 474349e7e4
commit 6912c51e43
11 files changed
+265 -4

No files matched your search

+7
View File
@@ -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>` | 页面设计器列表 |
+15
View File
@@ -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)
+36
View File
@@ -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)