请求侧改为直接拦截,宿主统一渲染 OpenAI 错误体
response_guard.lua:判定通过直接 pass,原始请求一字不改转发上游;不通过直接 block。删除 stub 替换逻辑,风险请求不再让上游白跑一次生成。
middleware/errors.py:PolicyBlocked 携带 code。middleware/runtime.py:block 的 reason 经白名单映射成 code,插件文本不进响应。middleware/proxy.py:PolicyBlocked 输出 OpenAI 错误体(400 content_policy_violation / 503 safety_review_unavailable),替换原来的 403 {error: PolicyBlocked}。
tools/verify_plugins.py:断言同步到新流程。
This commit is contained in:
1 parent
9218bdf1e8
commit
af7b2e28f3
5 files changed
+89
-96
No files matched your search
+10
-1
@@ -17,6 +17,15 @@ 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):
|
||||
@@ -233,7 +242,7 @@ class Session:
|
||||
raise PluginFailure()
|
||||
action = result.get("action")
|
||||
if action == "block":
|
||||
raise PolicyBlocked()
|
||||
raise PolicyBlocked(block_code(result.get("reason")))
|
||||
if action == "pass":
|
||||
if "value" in result or "events" in result:
|
||||
raise PluginFailure()
|
||||
|
||||
Reference in new issue
Block a user