feat: Antigravity 和 Codex 服务支持

- 新增 Antigravity 服务:签名缓存、URL 可用性检测、信封处理
- 新增 Codex 服务:信封处理、元数据收集器
- 重构 provider transport 支持新的服务架构
- 新增 stream_bridge 和 upstream_stream_bridge 处理流式响应
- 优化 OAuth 工具函数
- 添加相关测试用例
This commit is contained in:
fawney19
2026-02-05 15:57:52 +08:00
parent ed2ff5c1d7
commit 440721368f
44 changed files with 3498 additions and 134 deletions

View File

@@ -0,0 +1,63 @@
from __future__ import annotations
from dataclasses import dataclass
from types import SimpleNamespace
from src.services.provider.stream_policy import (
UpstreamStreamPolicy,
enforce_stream_mode_for_upstream,
get_upstream_stream_policy,
)
@dataclass
class _DummyEndpoint:
api_format: str
config: dict | None = None
provider: object | None = None
def test_get_upstream_stream_policy_defaults_to_auto() -> None:
ep = _DummyEndpoint(api_format="openai:chat", config=None, provider=SimpleNamespace(provider_type="custom"))
assert get_upstream_stream_policy(ep) == UpstreamStreamPolicy.AUTO
def test_get_upstream_stream_policy_codex_openai_cli_forces_stream() -> None:
ep = _DummyEndpoint(
api_format="openai:cli",
config=None,
provider=SimpleNamespace(provider_type="codex"),
)
assert get_upstream_stream_policy(ep) == UpstreamStreamPolicy.FORCE_STREAM
def test_get_upstream_stream_policy_codex_ignores_force_non_stream_config() -> None:
ep = _DummyEndpoint(
api_format="openai:cli",
config={"upstream_stream_policy": "force_non_stream"},
provider=SimpleNamespace(provider_type="codex"),
)
assert get_upstream_stream_policy(ep) == UpstreamStreamPolicy.FORCE_STREAM
def test_enforce_stream_mode_for_upstream_openai_chat_sets_stream_options_usage() -> None:
body = {"stream": False}
out = enforce_stream_mode_for_upstream(
body,
provider_api_format="openai:chat",
upstream_is_stream=True,
)
assert out["stream"] is True
assert out["stream_options"]["include_usage"] is True
def test_enforce_stream_mode_for_upstream_gemini_drops_stream_field() -> None:
body = {"stream": True, "foo": "bar"}
out = enforce_stream_mode_for_upstream(
body,
provider_api_format="gemini:chat",
upstream_is_stream=False,
)
assert "stream" not in out
assert out["foo"] == "bar"