拦截逻辑收回 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

+1 -10
View File
@@ -17,15 +17,6 @@ from .worker import json_bytes, worker_main
logger = logging.getLogger("middleware.audit")
ADAPTER_ID = "__protocol_adapter__"
# A plugin may only name a rejection from this closed set; anything else falls back to the
# default. This keeps plugin-supplied text out of the response body (see errors.PolicyBlocked).
BLOCK_CODES = frozenset({"content_policy_violation", "safety_review_unavailable"})
DEFAULT_BLOCK_CODE = "content_policy_violation"
def block_code(reason):
return reason if reason in BLOCK_CODES else DEFAULT_BLOCK_CODE
class Session:
def __init__(self, manager, request_id=None, plugins=None, attachments=None):
@@ -242,7 +233,7 @@ class Session:
raise PluginFailure()
action = result.get("action")
if action == "block":
raise PolicyBlocked(block_code(result.get("reason")))
raise PolicyBlocked()
if action == "pass":
if "value" in result or "events" in result:
raise PluginFailure()