diff --git a/app/api/routers/rbac_opc.py b/app/api/routers/rbac_opc.py index d8fc49e..fa005d5 100644 --- a/app/api/routers/rbac_opc.py +++ b/app/api/routers/rbac_opc.py @@ -18,6 +18,9 @@ from ... import config from ...services import compute_client, compute_catalog router = APIRouter(prefix="/opc", tags=["opc"]) +PLATFORM_RELAY_TOKEN_NAME = "平台中继令牌" +# 平台中继令牌:系统自动创建,桌面端智能体调用模型时使用,不对外展示、不允许删除 + @router.get("/dashboard", summary="OPC 工作台总览") @@ -530,6 +533,9 @@ async def opc_compute_tokens(user: dict = Depends(require_roles("opc_member"))): out = [] for it in items or []: it = dict(it) + # 平台中继令牌由系统自动创建,桌面端智能体调用模型时使用,不对外展示、不允许删除 + if str(it.get("name") or "") == PLATFORM_RELAY_TOKEN_NAME: + continue key = str(it.get("key") or it.get("token") or "") if key and not key.startswith("sk-"): it["key"] = f"sk-{key}" @@ -563,6 +569,17 @@ async def opc_compute_tokens_create( @router.delete("/compute/tokens/{token_id}", summary="删除算力令牌") async def opc_compute_tokens_delete(token_id: int, user: dict = Depends(require_roles("opc_member"))): + # 平台中继令牌不允许删除(桌面端智能体依赖此令牌调用模型) + try: + existing = await compute_client.list_user_tokens(user.get("username")) + except compute_client.ComputeError as exc: + raise HTTPException(status_code=502, detail=f"算力引擎对接失败: {exc}") from exc + existing_items = existing if isinstance(existing, list) else existing.get("items", []) + for it in existing_items or []: + if int(dict(it).get("id") or 0) == token_id: + if str(dict(it).get("name") or "") == PLATFORM_RELAY_TOKEN_NAME: + raise HTTPException(status_code=403, detail="平台中继令牌由系统管理,不允许删除") + break try: await compute_client.delete_token(token_id) except compute_client.ComputeError as exc: