新增 SealAI CLI 命令层(whoami/billing)+ HTTP 路由 + 文档同步
This commit is contained in:
1 parent
9d517defe3
commit
54ca2ffc4b
8 files changed
+248
-19
No files matched your search
@@ -6,6 +6,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.help import cmd_commands
|
||||
from ekb_cli.commands.serve import cmd_serve
|
||||
|
||||
@@ -17,6 +18,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.command("commands")(cmd_commands)
|
||||
app.command("serve")(cmd_serve)
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ COMMAND_TREE = {
|
||||
"--port": "监听端口(默认 9528)",
|
||||
"--reload": "开发模式自动重载",
|
||||
},
|
||||
"sealai": {
|
||||
"_help": "SealAI 智能填单/审核平台管理",
|
||||
"whoami": "查看当前 SealAI 用户身份及租户信息",
|
||||
"billing": "查看当前企业 SealAI 订阅状态及功能配额",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
@@ -1,7 +1,7 @@
|
||||
"""FastAPI 应用工厂
|
||||
|
||||
create_app() 创建并返回完整配置的 FastAPI 实例:
|
||||
- 注册 auth / agent / rule 三个路由组
|
||||
- 注册 auth / agent / rule / sealai 四个路由组
|
||||
- 统一 EkbError 异常处理(转 HTTP 状态码 + JSON 响应)
|
||||
"""
|
||||
|
||||
@@ -28,10 +28,12 @@ def create_app() -> FastAPI:
|
||||
from ekb_cli.server.auth_router import router as auth_router
|
||||
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
|
||||
|
||||
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"])
|
||||
|
||||
# ── 统一异常处理:EkbError → HTTP JSON ──────────────────
|
||||
# code → HTTP status 的映射表
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Server:SealAI 路由
|
||||
|
||||
对应 CLI 命令:
|
||||
ekb sealai whoami → GET /sealai/me
|
||||
ekb sealai billing → GET /sealai/billing
|
||||
|
||||
注意:SealAI 接口使用独立的 SealAiClient(Bearer JWT),
|
||||
不使用快报主站的 EkbClient(三 Header 认证)。
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Query
|
||||
|
||||
from ekb_cli.services.sealai import (
|
||||
get_sealai_client,
|
||||
query_billing_status,
|
||||
)
|
||||
from ekb_cli.api.sealai import get_me
|
||||
from ekb_cli.api.sealai.schemas import MeData, BillingStatusData
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/me",
|
||||
response_model=MeData,
|
||||
summary="查看当前 SealAI 用户身份及租户信息",
|
||||
)
|
||||
def sealai_whoami(
|
||||
corp_id: str = Query(None, description="企业 corpId,不传则使用当前企业"),
|
||||
refresh: bool = Query(False, description="强制刷新 Bearer token"),
|
||||
):
|
||||
client = get_sealai_client(corp_id=corp_id, force_refresh=refresh)
|
||||
return get_me(client)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/billing",
|
||||
response_model=BillingStatusData,
|
||||
summary="查看 SealAI 订阅状态及功能配额",
|
||||
)
|
||||
def sealai_billing(
|
||||
corp_id: str = Query(None, description="企业 corpId,不传则使用当前企业"),
|
||||
):
|
||||
client = get_sealai_client(corp_id=corp_id)
|
||||
return query_billing_status(client)
|
||||
Reference in new issue
Block a user