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:断言同步到新流程。
31 lines
701 B
Python
31 lines
701 B
Python
class MiddlewareError(Exception):
|
|
"""Never include plugin text, payloads or upstream exceptions in errors."""
|
|
|
|
|
|
class PluginFailure(MiddlewareError):
|
|
pass
|
|
|
|
|
|
class PolicyBlocked(MiddlewareError):
|
|
"""A plugin rejected the request.
|
|
|
|
``code`` is one of a closed set of tokens (see runtime.BLOCK_CODES). Plugin-supplied
|
|
text must never reach the response body, so anything outside that set is normalised.
|
|
"""
|
|
|
|
def __init__(self, code: str = "content_policy_violation") -> None:
|
|
super().__init__(code)
|
|
self.code = code
|
|
|
|
|
|
class Overloaded(MiddlewareError):
|
|
pass
|
|
|
|
|
|
class LimitExceeded(MiddlewareError):
|
|
pass
|
|
|
|
|
|
class NetworkDenied(MiddlewareError):
|
|
pass
|