feat(compute): 算力中心 余额门控+充值+真实来源数值
- relay 匿名不再回落admin令牌(root无限额)→401或受限RELAY令牌(修无余额可用) - /admin/compute/user-balance(充值add/subtract/override)+审计; compute_client.adjust_user_quota - proxy follow_redirects(修gin尾斜杠301/307空数据); ping 返 version+quota_per_unit
This commit is contained in:
@@ -181,6 +181,22 @@ async def delete_token(token_id: int) -> dict:
|
||||
)
|
||||
|
||||
|
||||
async def adjust_user_quota(engine_user_id: int, value: int, mode: str = "add") -> dict:
|
||||
"""调整引擎用户余额/额度(充值/扣减/覆盖)。
|
||||
|
||||
对应引擎 ``POST /api/user/manage``,action="add_quota":
|
||||
- mode="add" 充值(增加余额)
|
||||
- mode="subtract" 扣减
|
||||
- mode="override" 直接设为该值
|
||||
``value`` 为配额单位(见 /api/status 的 quota_per_unit:500000 = $1)。
|
||||
被充值用户的其他 PAT/会话会实时扣除,额度耗尽时引擎返回 403。
|
||||
"""
|
||||
return await _request(
|
||||
method="POST", path="/api/user/manage", headers=_admin_headers(),
|
||||
json={"id": int(engine_user_id), "action": "add_quota", "value": int(value), "mode": mode},
|
||||
)
|
||||
|
||||
|
||||
async def sync_user_enabled(username: str, enabled: bool) -> dict:
|
||||
"""按 username 同步引擎用户启用/禁用(平台用户生命周期自动同步)。"""
|
||||
return await _request(
|
||||
@@ -207,7 +223,7 @@ async def proxy(method: str, path: str, *, json_body: dict | None = None, params
|
||||
return {"status": 503, "body": '{"success": false, "message": "算力引擎内部令牌未配置(PINEAGENTS_INTERNAL_TOKEN)"}'}
|
||||
url = f"{_base()}/api{path}"
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=config.COMPUTE_TIMEOUT) as client:
|
||||
async with httpx.AsyncClient(timeout=config.COMPUTE_TIMEOUT, follow_redirects=True) as client:
|
||||
resp = await client.request(
|
||||
method, url, json=json_body, params=params, headers=_admin_headers(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user