拦截逻辑收回 Lua 层,宿主代码恢复原样

还原 middleware/errors.py、runtime.py、proxy.py:不再依赖宿主渲染错误体,宿主按原样返回 403。网关代码零改动。

response_guard.lua:请求侧判定不通过时,把发往上游的请求体换成最小 stub(原文不出网关),在响应侧用 replace 输出 OpenAI 错误体 400 content_policy_violation;审核不可用时 503 safety_review_unavailable。拦截响应形态完全由插件自己控制。

tools/verify_plugins.py:断言同步回 stub 流程,57 项。
This commit is contained in:
Автомата Калашникова committed 2026-11-27 17:56:03 +08:00
1 parent 554a36cf05
commit c76972c623
6 files changed
+97 -90

No files matched your search

+2 -34
View File
@@ -28,37 +28,6 @@ async def bounded_body(chunks, maximum):
return bytes(data)
# OpenAI-shaped rejection bodies. The set is closed: an unknown code falls back to the
# content-policy message, so no plugin-supplied text can reach the client.
POLICY_ERRORS = {
"content_policy_violation": (
400,
"Your request was rejected by the content safety policy.",
"invalid_request_error",
),
"safety_review_unavailable": (
503,
"Content safety review is temporarily unavailable. Please retry later.",
"server_error",
),
}
def policy_error(code):
status_code, message, kind = POLICY_ERRORS.get(code, POLICY_ERRORS["content_policy_violation"])
return (
{
"error": {
"message": message,
"type": kind,
"param": None,
"code": code if code in POLICY_ERRORS else "content_policy_violation",
}
},
status_code,
)
async def disconnected(receive):
while True:
message = await receive()
@@ -372,9 +341,8 @@ def create_app(settings: Settings | str = "config.yaml") -> FastAPI:
)
except Overloaded:
return JSONResponse({"error": "Overloaded"}, status_code=503)
except PolicyBlocked as exc:
payload, status_code = policy_error(exc.code)
return JSONResponse(payload, status_code=status_code)
except PolicyBlocked:
return JSONResponse({"error": "PolicyBlocked"}, status_code=403)
except InvalidMultipart:
return JSONResponse({"error": "InvalidMultipart"}, status_code=400)
except (MiddlewareError, aiohttp.ClientError, TimeoutError, UnicodeError, ValueError):