mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
feat(body-rules): 支持按 provider_type 覆盖 cache-sensitive 保护字段集合
Codex 通过 OpenAI CLI/Compact 格式转发时,endpoint body_rules 需要能 修改 instructions/input/tools 等 prompt 字段。新增 provider_type 维度的 保护集合映射,Codex 场景仅保护 prompt_cache_key,其余 prompt 字段交由 body_rules 自由调整。
This commit is contained in:
@@ -279,6 +279,37 @@ def test_codex_passthrough_builder_preserves_real_codex_headers() -> None:
|
||||
assert "x-forwarded-scheme" not in headers
|
||||
|
||||
|
||||
def test_codex_passthrough_builder_applies_prompt_body_rules() -> None:
|
||||
from src.api.handlers.base.request_builder import get_cache_sensitive_protected_body_keys
|
||||
from src.core.api_format.metadata import CODEX_DEFAULT_BODY_RULES
|
||||
|
||||
builder = PassthroughRequestBuilder()
|
||||
endpoint = SimpleNamespace(
|
||||
api_family="openai",
|
||||
endpoint_kind="cli",
|
||||
header_rules=None,
|
||||
body_rules=list(CODEX_DEFAULT_BODY_RULES),
|
||||
)
|
||||
key = SimpleNamespace(api_key="unused")
|
||||
|
||||
payload, _headers = builder.build(
|
||||
{"model": "gpt-test", "input": []},
|
||||
{"content-type": "application/json"},
|
||||
endpoint,
|
||||
key,
|
||||
pre_computed_auth=("Authorization", "Bearer upstream-token"),
|
||||
protected_body_keys=get_cache_sensitive_protected_body_keys(
|
||||
"openai:cli",
|
||||
provider_type="codex",
|
||||
),
|
||||
provider_api_format="openai:cli",
|
||||
)
|
||||
|
||||
assert payload["instructions"] == "You are GPT-5."
|
||||
assert payload["store"] is False
|
||||
assert "max_output_tokens" not in payload
|
||||
|
||||
|
||||
def _encode_unsigned_jwt(payload: dict[str, object]) -> str:
|
||||
token = jwt.encode(payload, key="", algorithm="none")
|
||||
return token.decode("utf-8") if isinstance(token, bytes) else token
|
||||
|
||||
Reference in New Issue
Block a user