coding-proxy 0.1.2a1__tar.gz → 0.1.3a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of coding-proxy might be problematic. Click here for more details.
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/PKG-INFO +1 -1
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/pyproject.toml +1 -1
- coding_proxy-0.1.3a1/src/coding/proxy/vendors/anthropic.py +105 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_vendors.py +187 -1
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/uv.lock +1 -1
- coding_proxy-0.1.2a1/src/coding/proxy/vendors/anthropic.py +0 -48
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/.github/workflows/ci.yml +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/.github/workflows/coverage.yml +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/.github/workflows/promote.yml +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/.github/workflows/release.yml +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/.gitignore +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/AGENTS.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/CHANGELOG.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/CLAUDE.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/LICENSE +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/README.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/docs/ci-cd.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/docs/framework.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/docs/user-guide.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/docs/zh-CN/README.md +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/__main__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/providers/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/providers/base.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/providers/github.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/providers/google.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/runtime.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/auth/store.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/cli/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/cli/auth_commands.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/compat/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/compat/canonical.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/compat/session_store.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/auth_schema.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/config.default.yaml +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/loader.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/resiliency.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/routing.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/schema.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/server.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/config/vendors.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/anthropic_to_gemini.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/anthropic_to_openai.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/gemini_sse_adapter.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/gemini_to_anthropic.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/openai_to_anthropic.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/logging/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/logging/db.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/logging/stats.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/auth.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/compat.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/constants.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/pricing.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/token.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/model/vendor.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/pricing.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/circuit_breaker.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/error_classifier.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/executor.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/model_mapper.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/quota_guard.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/rate_limit.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/retry.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/router.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/session_manager.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/tier.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/usage_parser.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/routing/usage_recorder.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/server/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/server/app.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/server/factory.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/server/request_normalizer.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/server/responses.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/server/routes.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/streaming/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/streaming/anthropic_compat.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/antigravity.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/base.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/copilot.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/copilot_models.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/copilot_token_manager.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/copilot_urls.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/mixins.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/token_manager.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/zhipu.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/__init__.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_antigravity.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_app_routes.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_auto_login.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_circuit_breaker.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_cli_usage.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_compat.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_config_init.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_config_loader.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_convert_request.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_convert_response.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_convert_sse.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_copilot.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_copilot_convert_request.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_copilot_convert_response.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_copilot_models.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_copilot_urls.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_currency.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_error_classifier.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_mixins.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_auth.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_compat.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_constants.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_mapper.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_pricing.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_token.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_model_vendor.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_parse_usage.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_pricing.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_quota_guard.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_rate_limit.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_request_normalizer.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_router_chain.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_router_executor.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_runtime_reauth.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_schema.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_streaming_anthropic_compat.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_tier.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_tiers_config.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_token_logger.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_token_manager.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_types.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_vendor_streaming.py +0 -0
- {coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/tests/test_zhipu.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: coding-proxy
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3a1
|
|
4
4
|
Summary: A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM.
|
|
5
5
|
Project-URL: Source Code, https://github.com/ThreeFish-AI/coding-proxy
|
|
6
6
|
Project-URL: User Guide, https://github.com/ThreeFish-AI/coding-proxy/blob/master/docs/user-guide.md
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "coding-proxy"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.3a1"
|
|
4
4
|
description = "A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Anthropic 官方供应商 — 透传 OAuth token."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
import logging
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ..config.schema import AnthropicConfig, FailoverConfig
|
|
10
|
+
from .base import PROXY_SKIP_HEADERS, BaseVendor
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
# 需要从 assistant messages 中剥离的 thinking block 类型
|
|
15
|
+
_THINKING_BLOCK_TYPES = {"thinking", "redacted_thinking"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _strip_thinking_blocks(body: dict[str, Any]) -> int:
|
|
19
|
+
"""从 assistant messages 中移除 thinking / redacted_thinking blocks.
|
|
20
|
+
|
|
21
|
+
Anthropic API 要求 thinking blocks 的 ``signature`` 必须是其签发的有效签名。
|
|
22
|
+
跨供应商迁移(如 Zhipu → Anthropic)后,conversation history 中可能包含
|
|
23
|
+
非 Anthropic 签发的 signature,导致 400 ``invalid_request_error``。
|
|
24
|
+
根据 Anthropic 官方文档,thinking blocks 可以被安全省略,不影响模型行为。
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
被移除的 thinking block 数量。
|
|
28
|
+
"""
|
|
29
|
+
stripped = 0
|
|
30
|
+
for message in body.get("messages", []):
|
|
31
|
+
if not isinstance(message, dict) or message.get("role") != "assistant":
|
|
32
|
+
continue
|
|
33
|
+
content = message.get("content")
|
|
34
|
+
if not isinstance(content, list):
|
|
35
|
+
continue
|
|
36
|
+
original_len = len(content)
|
|
37
|
+
new_content = [
|
|
38
|
+
block
|
|
39
|
+
for block in content
|
|
40
|
+
if not (
|
|
41
|
+
isinstance(block, dict) and block.get("type") in _THINKING_BLOCK_TYPES
|
|
42
|
+
)
|
|
43
|
+
]
|
|
44
|
+
removed = original_len - len(new_content)
|
|
45
|
+
if removed and not new_content:
|
|
46
|
+
logger.warning(
|
|
47
|
+
"anthropic: assistant message content became empty after "
|
|
48
|
+
"stripping %d thinking block(s); this may cause API errors",
|
|
49
|
+
removed,
|
|
50
|
+
)
|
|
51
|
+
message["content"] = new_content
|
|
52
|
+
stripped += removed
|
|
53
|
+
return stripped
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class AnthropicVendor(BaseVendor):
|
|
57
|
+
"""Anthropic 官方 API 供应商.
|
|
58
|
+
|
|
59
|
+
透传 Claude Code 发来的 OAuth token 和请求体到 Anthropic API.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def __init__(
|
|
63
|
+
self, config: AnthropicConfig, failover_config: FailoverConfig
|
|
64
|
+
) -> None:
|
|
65
|
+
super().__init__(config.base_url, config.timeout_ms, failover_config)
|
|
66
|
+
|
|
67
|
+
def get_name(self) -> str:
|
|
68
|
+
return "anthropic"
|
|
69
|
+
|
|
70
|
+
async def check_health(self) -> bool:
|
|
71
|
+
"""Anthropic 健康检查 — 透明代理被动策略.
|
|
72
|
+
|
|
73
|
+
Anthropic 供应商作为透明代理,不管理凭证(auth 来自客户端请求头),
|
|
74
|
+
无法独立发起 API 探测。健康状态通过 VendorTier 的 Rate Limit
|
|
75
|
+
Deadline 门控判定:仅在服务端声明的 rate limit 重置时间到期后,
|
|
76
|
+
才允许使用下一个真实客户端请求作为探针。
|
|
77
|
+
"""
|
|
78
|
+
return True
|
|
79
|
+
|
|
80
|
+
async def _prepare_request(
|
|
81
|
+
self,
|
|
82
|
+
request_body: dict[str, Any],
|
|
83
|
+
headers: dict[str, str],
|
|
84
|
+
) -> tuple[dict[str, Any], dict[str, str]]:
|
|
85
|
+
"""深拷贝请求体、剥离历史 thinking blocks,过滤无关请求头.
|
|
86
|
+
|
|
87
|
+
深拷贝确保 Anthropic 的请求体修改不会污染后续 tier 的输入。
|
|
88
|
+
剥离 thinking blocks 防止跨供应商 signature 不兼容导致 400 错误。
|
|
89
|
+
"""
|
|
90
|
+
body = copy.deepcopy(request_body)
|
|
91
|
+
stripped = _strip_thinking_blocks(body)
|
|
92
|
+
if stripped:
|
|
93
|
+
logger.debug(
|
|
94
|
+
"anthropic: stripped %d thinking block(s) from conversation history",
|
|
95
|
+
stripped,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
filtered = {
|
|
99
|
+
k: v for k, v in headers.items() if k.lower() not in PROXY_SKIP_HEADERS
|
|
100
|
+
}
|
|
101
|
+
return body, filtered
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# 向后兼容别名
|
|
105
|
+
AnthropicBackend = AnthropicVendor
|
|
@@ -37,13 +37,199 @@ async def test_anthropic_prepare_request_filters_headers():
|
|
|
37
37
|
"anthropic-version": "2023-06-01",
|
|
38
38
|
}
|
|
39
39
|
prepared_body, prepared_headers = await vendor._prepare_request(body, headers)
|
|
40
|
-
assert prepared_body is body #
|
|
40
|
+
assert prepared_body is not body # deepcopy: 返回新对象
|
|
41
|
+
assert prepared_body == body # 内容等价
|
|
41
42
|
assert "host" not in prepared_headers
|
|
42
43
|
assert "content-length" not in prepared_headers
|
|
43
44
|
assert prepared_headers["authorization"] == "Bearer sk-test"
|
|
44
45
|
assert prepared_headers["anthropic-version"] == "2023-06-01"
|
|
45
46
|
|
|
46
47
|
|
|
48
|
+
@pytest.mark.asyncio
|
|
49
|
+
async def test_anthropic_prepare_request_strips_thinking_blocks():
|
|
50
|
+
"""Anthropic vendor 应剥离 assistant messages 中的 thinking blocks."""
|
|
51
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
52
|
+
body = {
|
|
53
|
+
"model": "claude-opus-4-6",
|
|
54
|
+
"messages": [
|
|
55
|
+
{
|
|
56
|
+
"role": "assistant",
|
|
57
|
+
"content": [
|
|
58
|
+
{
|
|
59
|
+
"type": "thinking",
|
|
60
|
+
"thinking": "Let me think about this...",
|
|
61
|
+
"signature": "zhipu-issued-signature",
|
|
62
|
+
},
|
|
63
|
+
{"type": "text", "text": "Here is my answer."},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
prepared_body, _ = await vendor._prepare_request(body, {})
|
|
69
|
+
|
|
70
|
+
# thinking block 被剥离,text block 保留
|
|
71
|
+
content = prepared_body["messages"][0]["content"]
|
|
72
|
+
assert len(content) == 1
|
|
73
|
+
assert content[0]["type"] == "text"
|
|
74
|
+
assert content[0]["text"] == "Here is my answer."
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.asyncio
|
|
78
|
+
async def test_anthropic_prepare_request_strips_redacted_thinking_blocks():
|
|
79
|
+
"""Anthropic vendor 应剥离 assistant messages 中的 redacted_thinking blocks."""
|
|
80
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
81
|
+
body = {
|
|
82
|
+
"model": "claude-opus-4-6",
|
|
83
|
+
"messages": [
|
|
84
|
+
{
|
|
85
|
+
"role": "assistant",
|
|
86
|
+
"content": [
|
|
87
|
+
{"type": "redacted_thinking", "data": "base64data"},
|
|
88
|
+
{"type": "text", "text": "response"},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
}
|
|
93
|
+
prepared_body, _ = await vendor._prepare_request(body, {})
|
|
94
|
+
|
|
95
|
+
content = prepared_body["messages"][0]["content"]
|
|
96
|
+
assert len(content) == 1
|
|
97
|
+
assert content[0]["type"] == "text"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@pytest.mark.asyncio
|
|
101
|
+
async def test_anthropic_prepare_request_preserves_thinking_param():
|
|
102
|
+
"""body 顶层的 thinking 参数(控制当前请求是否启用 thinking)不应被修改."""
|
|
103
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
104
|
+
body = {
|
|
105
|
+
"model": "claude-opus-4-6",
|
|
106
|
+
"thinking": {"type": "enabled", "budget_tokens": 10000},
|
|
107
|
+
"messages": [
|
|
108
|
+
{
|
|
109
|
+
"role": "assistant",
|
|
110
|
+
"content": [
|
|
111
|
+
{"type": "thinking", "thinking": "old thought", "signature": "sig"},
|
|
112
|
+
{"type": "text", "text": "old response"},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
{"role": "user", "content": "follow up"},
|
|
116
|
+
],
|
|
117
|
+
}
|
|
118
|
+
prepared_body, _ = await vendor._prepare_request(body, {})
|
|
119
|
+
|
|
120
|
+
# 顶层 thinking 参数保留
|
|
121
|
+
assert prepared_body["thinking"] == {"type": "enabled", "budget_tokens": 10000}
|
|
122
|
+
# assistant message 的 thinking block 被剥离
|
|
123
|
+
assert len(prepared_body["messages"][0]["content"]) == 1
|
|
124
|
+
assert prepared_body["messages"][0]["content"][0]["type"] == "text"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@pytest.mark.asyncio
|
|
128
|
+
async def test_anthropic_prepare_request_does_not_mutate_original_body():
|
|
129
|
+
"""deepcopy 验证:原始 body 不应被修改."""
|
|
130
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
131
|
+
body = {
|
|
132
|
+
"model": "claude-opus-4-6",
|
|
133
|
+
"messages": [
|
|
134
|
+
{
|
|
135
|
+
"role": "assistant",
|
|
136
|
+
"content": [
|
|
137
|
+
{"type": "thinking", "thinking": "thought", "signature": "sig"},
|
|
138
|
+
{"type": "text", "text": "response"},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
}
|
|
143
|
+
await vendor._prepare_request(body, {})
|
|
144
|
+
|
|
145
|
+
# 原始 body 的 thinking block 应仍然存在
|
|
146
|
+
assert len(body["messages"][0]["content"]) == 2
|
|
147
|
+
assert body["messages"][0]["content"][0]["type"] == "thinking"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@pytest.mark.asyncio
|
|
151
|
+
async def test_anthropic_prepare_request_preserves_user_messages():
|
|
152
|
+
"""user messages 不应被修改(thinking blocks 仅出现在 assistant messages 中)."""
|
|
153
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
154
|
+
body = {
|
|
155
|
+
"model": "claude-opus-4-6",
|
|
156
|
+
"messages": [
|
|
157
|
+
{
|
|
158
|
+
"role": "user",
|
|
159
|
+
"content": [
|
|
160
|
+
{"type": "text", "text": "hello"},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
}
|
|
165
|
+
prepared_body, _ = await vendor._prepare_request(body, {})
|
|
166
|
+
|
|
167
|
+
content = prepared_body["messages"][0]["content"]
|
|
168
|
+
assert len(content) == 1
|
|
169
|
+
assert content[0]["type"] == "text"
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@pytest.mark.asyncio
|
|
173
|
+
async def test_anthropic_prepare_request_handles_string_content():
|
|
174
|
+
"""assistant message content 为字符串时应原样保留(不触发剥离逻辑)."""
|
|
175
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
176
|
+
body = {
|
|
177
|
+
"model": "claude-opus-4-6",
|
|
178
|
+
"messages": [
|
|
179
|
+
{"role": "assistant", "content": "plain text response"},
|
|
180
|
+
],
|
|
181
|
+
}
|
|
182
|
+
prepared_body, _ = await vendor._prepare_request(body, {})
|
|
183
|
+
assert prepared_body["messages"][0]["content"] == "plain text response"
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@pytest.mark.asyncio
|
|
187
|
+
async def test_anthropic_prepare_request_multi_turn_strips_all_thinking():
|
|
188
|
+
"""多轮对话中所有 assistant thinking blocks 均应被剥离."""
|
|
189
|
+
vendor = AnthropicVendor(AnthropicConfig(), FailoverConfig())
|
|
190
|
+
body = {
|
|
191
|
+
"model": "claude-opus-4-6",
|
|
192
|
+
"messages": [
|
|
193
|
+
{
|
|
194
|
+
"role": "assistant",
|
|
195
|
+
"content": [
|
|
196
|
+
{"type": "thinking", "thinking": "thought 1", "signature": "s1"},
|
|
197
|
+
{"type": "text", "text": "response 1"},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
{"role": "user", "content": "follow up"},
|
|
201
|
+
{
|
|
202
|
+
"role": "assistant",
|
|
203
|
+
"content": [
|
|
204
|
+
{"type": "thinking", "thinking": "thought 2", "signature": "s2"},
|
|
205
|
+
{"type": "text", "text": "response 2"},
|
|
206
|
+
{
|
|
207
|
+
"type": "tool_use",
|
|
208
|
+
"id": "toolu_123",
|
|
209
|
+
"name": "bash",
|
|
210
|
+
"input": {"command": "pwd"},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
}
|
|
216
|
+
prepared_body, _ = await vendor._prepare_request(body, {})
|
|
217
|
+
|
|
218
|
+
# 第一条 assistant message: thinking 被剥离,text 保留
|
|
219
|
+
content_0 = prepared_body["messages"][0]["content"]
|
|
220
|
+
assert len(content_0) == 1
|
|
221
|
+
assert content_0[0]["type"] == "text"
|
|
222
|
+
|
|
223
|
+
# user message 不变
|
|
224
|
+
assert prepared_body["messages"][1]["content"] == "follow up"
|
|
225
|
+
|
|
226
|
+
# 第三条 assistant message: thinking 被剥离,text + tool_use 保留
|
|
227
|
+
content_2 = prepared_body["messages"][2]["content"]
|
|
228
|
+
assert len(content_2) == 2
|
|
229
|
+
assert content_2[0]["type"] == "text"
|
|
230
|
+
assert content_2[1]["type"] == "tool_use"
|
|
231
|
+
|
|
232
|
+
|
|
47
233
|
@pytest.mark.asyncio
|
|
48
234
|
async def test_zhipu_prepare_request_maps_model():
|
|
49
235
|
mapper = ModelMapper(
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"""Anthropic 官方供应商 — 透传 OAuth token."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from typing import Any
|
|
6
|
-
|
|
7
|
-
from ..config.schema import AnthropicConfig, FailoverConfig
|
|
8
|
-
from .base import PROXY_SKIP_HEADERS, BaseVendor
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AnthropicVendor(BaseVendor):
|
|
12
|
-
"""Anthropic 官方 API 供应商.
|
|
13
|
-
|
|
14
|
-
透传 Claude Code 发来的 OAuth token 和请求体到 Anthropic API.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(
|
|
18
|
-
self, config: AnthropicConfig, failover_config: FailoverConfig
|
|
19
|
-
) -> None:
|
|
20
|
-
super().__init__(config.base_url, config.timeout_ms, failover_config)
|
|
21
|
-
|
|
22
|
-
def get_name(self) -> str:
|
|
23
|
-
return "anthropic"
|
|
24
|
-
|
|
25
|
-
async def check_health(self) -> bool:
|
|
26
|
-
"""Anthropic 健康检查 — 透明代理被动策略.
|
|
27
|
-
|
|
28
|
-
Anthropic 供应商作为透明代理,不管理凭证(auth 来自客户端请求头),
|
|
29
|
-
无法独立发起 API 探测。健康状态通过 VendorTier 的 Rate Limit
|
|
30
|
-
Deadline 门控判定:仅在服务端声明的 rate limit 重置时间到期后,
|
|
31
|
-
才允许使用下一个真实客户端请求作为探针。
|
|
32
|
-
"""
|
|
33
|
-
return True
|
|
34
|
-
|
|
35
|
-
async def _prepare_request(
|
|
36
|
-
self,
|
|
37
|
-
request_body: dict[str, Any],
|
|
38
|
-
headers: dict[str, str],
|
|
39
|
-
) -> tuple[dict[str, Any], dict[str, str]]:
|
|
40
|
-
"""透传请求体,过滤无关请求头."""
|
|
41
|
-
filtered = {
|
|
42
|
-
k: v for k, v in headers.items() if k.lower() not in PROXY_SKIP_HEADERS
|
|
43
|
-
}
|
|
44
|
-
return request_body, filtered
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# 向后兼容别名
|
|
48
|
-
AnthropicBackend = AnthropicVendor
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/anthropic_to_gemini.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/anthropic_to_openai.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/gemini_sse_adapter.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/gemini_to_anthropic.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/convert/openai_to_anthropic.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/streaming/anthropic_compat.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coding_proxy-0.1.2a1 → coding_proxy-0.1.3a1}/src/coding/proxy/vendors/copilot_token_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|