新增 SealAI CLI 命令层(whoami/billing)+ HTTP 路由 + 文档同步

This commit is contained in:
gitea committed 2026-04-14 16:47:20 +08:00
1 parent 9d517defe3
commit 54ca2ffc4b
8 files changed
+248 -19

No files matched your search

+5
View File
@@ -36,6 +36,11 @@ COMMAND_TREE = {
"--port": "监听端口(默认 9528)",
"--reload": "开发模式自动重载",
},
"sealai": {
"_help": "SealAI 智能填单/审核平台管理",
"whoami": "查看当前 SealAI 用户身份及租户信息",
"billing": "查看当前企业 SealAI 订阅状态及功能配额",
},
}
+15
View File
@@ -0,0 +1,15 @@
"""sealai 子命令组
对应 CLI 命令:
ekb sealai whoami → 查看当前 SealAI 用户身份及租户信息
ekb sealai billing → 查看当前企业 SealAI 订阅状态及功能配额
"""
import typer
from ekb_cli.commands.sealai.whoami import cmd_whoami
from ekb_cli.commands.sealai.billing import cmd_billing
app = typer.Typer(help="SealAI 智能填单/审核平台管理")
app.command("whoami")(cmd_whoami)
app.command("billing")(cmd_billing)
+63
View File
@@ -0,0 +1,63 @@
"""sealai billing:查看 SealAI 订阅状态及功能配额
表现层:只负责 rich 格式化输出。
业务逻辑委托给 services.sealai.billing_service。
"""
import typer
from rich.console import Console
from rich.table import Table
from rich import print as rprint
from ekb_cli.services.sealai import get_sealai_client, query_billing_status
console = Console()
def cmd_billing(
corp_id: str = typer.Option(None, "--corp", "-c", help="指定企业 corpId,默认使用当前企业"),
):
"""查看当前企业 SealAI 订阅状态及各功能配额"""
client = get_sealai_client(corp_id=corp_id)
status = query_billing_status(client)
# 订阅信息
if status.subscriptions:
sub = status.subscriptions[0]
console.print(f"\n[bold]订阅信息[/bold]")
table = Table(show_header=False, box=None, padding=(0, 2))
table.add_column("字段", style="dim")
table.add_column("值")
table.add_row("订阅 ID", sub.id)
table.add_row("状态", "[green]生效中[/green]" if sub.status == "active" else sub.status)
table.add_row("开始日期", sub.startDate)
console.print(table)
else:
rprint("[yellow]当前企业无有效订阅[/yellow]")
# 功能配额表
if not status.features:
return
console.print(f"\n[bold]功能配额[/bold]")
feat_table = Table(show_header=True, header_style="bold")
feat_table.add_column("功能名称")
feat_table.add_column("code", style="dim")
feat_table.add_column("状态/用量", justify="right")
for f in status.features:
if f.enabled is not None:
# 开关型
usage = "[green]已开启[/green]" if f.enabled else "[red]未开启[/red]"
elif f.balance is not None:
# 余额型
usage = f"余额 {f.balance}/{f.totalQuota}"
elif f.quota is not None:
# 配额型
usage = f"已用 {f.used}/{f.quota}"
else:
usage = "-"
feat_table.add_row(f.name, f.code, usage)
console.print(feat_table)
console.print()
+49
View File
@@ -0,0 +1,49 @@
"""sealai whoami:查看当前 SealAI 用户身份
表现层:只负责 rich 格式化输出。
业务逻辑委托给 services.sealai.auth_service。
"""
import typer
from rich.console import Console
from rich.table import Table
from rich import print as rprint
from ekb_cli.services.sealai import get_sealai_client, get_bearer_token
from ekb_cli.api.sealai import get_me
console = Console()
def cmd_whoami(
corp_id: str = typer.Option(None, "--corp", "-c", help="指定企业 corpId,默认使用当前企业"),
refresh: bool = typer.Option(False, "--refresh", help="强制刷新 SealAI Bearer token"),
):
"""查看当前 SealAI 用户身份及租户信息"""
client = get_sealai_client(corp_id=corp_id, force_refresh=refresh)
me = get_me(client)
user = me.user
tenant = me.tenant
# 用户信息
console.print(f"\n[bold]SealAI 用户[/bold]")
table = Table(show_header=False, box=None, padding=(0, 2))
table.add_column("字段", style="dim")
table.add_column("值")
table.add_row("姓名", user.name)
table.add_row("用户 ID", user.id)
table.add_row("是否管理员", "[green]是[/green]" if user.isAdmin else "否")
table.add_row("快报 staffId", user.providerUserId)
console.print(table)
# 租户信息
console.print(f"\n[bold]租户(企业)[/bold]")
table2 = Table(show_header=False, box=None, padding=(0, 2))
table2.add_column("字段", style="dim")
table2.add_column("值")
table2.add_row("企业名称", tenant.name)
table2.add_row("租户 Slug", tenant.tenantSlug)
table2.add_row("企业 ID(快报)", tenant.hoseCorpConfig.corporationId)
console.print(table2)
console.print()