coding-proxy 0.2.0a2__py3-none-any.whl → 0.2.1a1__py3-none-any.whl
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/config/config.default.yaml +18 -2
- coding/proxy/routing/quota_guard.py +9 -2
- coding/proxy/server/app.py +2 -5
- coding/proxy/server/request_normalizer.py +2 -117
- coding/proxy/vendors/antigravity.py +4 -4
- {coding_proxy-0.2.0a2.dist-info → coding_proxy-0.2.1a1.dist-info}/METADATA +1 -1
- {coding_proxy-0.2.0a2.dist-info → coding_proxy-0.2.1a1.dist-info}/RECORD +10 -10
- {coding_proxy-0.2.0a2.dist-info → coding_proxy-0.2.1a1.dist-info}/WHEEL +0 -0
- {coding_proxy-0.2.0a2.dist-info → coding_proxy-0.2.1a1.dist-info}/entry_points.txt +0 -0
- {coding_proxy-0.2.0a2.dist-info → coding_proxy-0.2.1a1.dist-info}/licenses/LICENSE +0 -0
|
@@ -232,11 +232,15 @@ model_mapping:
|
|
|
232
232
|
# Google Antigravity 模型映射
|
|
233
233
|
- pattern: "claude-sonnet-.*"
|
|
234
234
|
vendors: ["antigravity"]
|
|
235
|
-
target: "
|
|
235
|
+
target: "Claude Sonnet 4.6"
|
|
236
236
|
is_regex: true
|
|
237
237
|
- pattern: "claude-opus-.*"
|
|
238
238
|
vendors: ["antigravity"]
|
|
239
|
-
target: "
|
|
239
|
+
target: "Claude Opus 4.6 Thinking"
|
|
240
|
+
is_regex: true
|
|
241
|
+
- pattern: "claude-haiku-.*"
|
|
242
|
+
vendors: ["antigravity"]
|
|
243
|
+
target: "Gemini 3 Flash"
|
|
240
244
|
is_regex: true
|
|
241
245
|
# 智谱 GLM 映射(官方原生 Anthropic 兼容端点)
|
|
242
246
|
# glm-5v-turbo 完整承载 Claude Code 满血能力(tool calling / thinking / 多模态)
|
|
@@ -330,6 +334,12 @@ pricing:
|
|
|
330
334
|
output_cost_per_mtok: $25.0
|
|
331
335
|
cache_write_cost_per_mtok: $6.25
|
|
332
336
|
cache_read_cost_per_mtok: $0.50
|
|
337
|
+
- vendor: anthropic
|
|
338
|
+
model: Claude Opus 4.6
|
|
339
|
+
input_cost_per_mtok: $5.0
|
|
340
|
+
output_cost_per_mtok: $25.0
|
|
341
|
+
cache_write_cost_per_mtok: $6.25
|
|
342
|
+
cache_read_cost_per_mtok: $0.50
|
|
333
343
|
- vendor: anthropic
|
|
334
344
|
model: claude-sonnet-4-6
|
|
335
345
|
input_cost_per_mtok: $3.0
|
|
@@ -342,6 +352,12 @@ pricing:
|
|
|
342
352
|
output_cost_per_mtok: $5
|
|
343
353
|
cache_write_cost_per_mtok: $1.25
|
|
344
354
|
cache_read_cost_per_mtok: $0.10
|
|
355
|
+
- vendor: anthropic
|
|
356
|
+
model: Claude Haiku 4.5
|
|
357
|
+
input_cost_per_mtok: $1
|
|
358
|
+
output_cost_per_mtok: $5
|
|
359
|
+
cache_write_cost_per_mtok: $1.25
|
|
360
|
+
cache_read_cost_per_mtok: $0.10
|
|
345
361
|
# ── GitHub Copilot(透传 Claude,参照 Anthropic 定价估算) ──
|
|
346
362
|
- vendor: copilot
|
|
347
363
|
model: claude-opus-4.6
|
|
@@ -129,7 +129,7 @@ class QuotaGuard:
|
|
|
129
129
|
int(self._effective_probe_interval),
|
|
130
130
|
)
|
|
131
131
|
|
|
132
|
-
def load_baseline(self, total_tokens: int) -> None:
|
|
132
|
+
def load_baseline(self, total_tokens: int, vendor: str | None = None) -> None:
|
|
133
133
|
"""从数据库加载窗口历史用量基线."""
|
|
134
134
|
if not self._enabled or total_tokens <= 0:
|
|
135
135
|
return
|
|
@@ -137,7 +137,14 @@ class QuotaGuard:
|
|
|
137
137
|
midpoint = time.monotonic() - self._window / 2
|
|
138
138
|
self._entries.append((midpoint, total_tokens))
|
|
139
139
|
self._total += total_tokens
|
|
140
|
-
|
|
140
|
+
if vendor:
|
|
141
|
+
logger.info(
|
|
142
|
+
"Quota guard [%s]: loaded baseline %d tokens",
|
|
143
|
+
vendor,
|
|
144
|
+
total_tokens,
|
|
145
|
+
)
|
|
146
|
+
else:
|
|
147
|
+
logger.info("Quota guard: loaded baseline %d tokens", total_tokens)
|
|
141
148
|
|
|
142
149
|
def reset(self) -> None:
|
|
143
150
|
"""手动重置为 WITHIN_QUOTA 状态."""
|
coding/proxy/server/app.py
CHANGED
|
@@ -60,17 +60,14 @@ async def lifespan(app: FastAPI):
|
|
|
60
60
|
tier.quota_guard.window_hours,
|
|
61
61
|
vendor=tier.name,
|
|
62
62
|
)
|
|
63
|
-
tier.quota_guard.load_baseline(total)
|
|
63
|
+
tier.quota_guard.load_baseline(total, vendor=tier.name)
|
|
64
64
|
if tier.weekly_quota_guard and tier.weekly_quota_guard.enabled:
|
|
65
65
|
total = await token_logger.query_window_total(
|
|
66
66
|
tier.weekly_quota_guard.window_hours,
|
|
67
67
|
vendor=tier.name,
|
|
68
68
|
)
|
|
69
|
-
tier.weekly_quota_guard.load_baseline(total)
|
|
69
|
+
tier.weekly_quota_guard.load_baseline(total, vendor=tier.name)
|
|
70
70
|
|
|
71
|
-
logger.info(
|
|
72
|
-
"coding-proxy started: host=%s port=%d", config.server.host, config.server.port
|
|
73
|
-
)
|
|
74
71
|
yield
|
|
75
72
|
await router.close()
|
|
76
73
|
await compat_session_store.close()
|
|
@@ -42,10 +42,9 @@ def normalize_anthropic_request(body: dict[str, Any]) -> NormalizationResult:
|
|
|
42
42
|
处理策略:
|
|
43
43
|
1. 移除供应商私有块(如 server_tool_use_delta)
|
|
44
44
|
2. 重写无效/非标准的 tool_use / tool_result ID
|
|
45
|
-
3.
|
|
45
|
+
3. **剥离错位的 tool_result 块**:Anthropic API 要求 ``tool_result`` 只能出现在
|
|
46
46
|
``user`` 消息中。当检测到非 user 消息中存在 ``tool_result`` 时,
|
|
47
|
-
|
|
48
|
-
防止上游返回 ``400 invalid_request_error`` 导致全链路降级失败。
|
|
47
|
+
直接剥离以防止上游返回 ``400 invalid_request_error`` 导致全链路降级失败。
|
|
49
48
|
"""
|
|
50
49
|
normalized = copy.deepcopy(body)
|
|
51
50
|
adaptations: list[str] = []
|
|
@@ -182,15 +181,6 @@ def normalize_anthropic_request(body: dict[str, Any]) -> NormalizationResult:
|
|
|
182
181
|
if stripped_misplaced:
|
|
183
182
|
_emit_misplaced_tool_result_summary(stripped_misplaced)
|
|
184
183
|
|
|
185
|
-
# ── 后处理:迁移错位的 tool_result 块 ──────────────────────
|
|
186
|
-
# Anthropic API 强制要求 tool_result 仅存在于 user 消息中。
|
|
187
|
-
# 多 vendor 场景下(尤其是降级恢复后的对话历史),可能出现
|
|
188
|
-
# tool_result 残留在 assistant / system 等非 user 消息中的情况,
|
|
189
|
-
# 导致 Anthropic 返回 400 invalid_request_error 并触发全链路降级。
|
|
190
|
-
relocated = _relocate_misplaced_tool_results(normalized, adaptations)
|
|
191
|
-
if relocated > 0:
|
|
192
|
-
adaptations.append(f"tool_result_relocated_from_non_user_messages({relocated})")
|
|
193
|
-
|
|
194
184
|
return NormalizationResult(
|
|
195
185
|
body=normalized,
|
|
196
186
|
adaptations=sorted(set(adaptations)),
|
|
@@ -258,108 +248,3 @@ def _emit_misplaced_tool_result_summary(
|
|
|
258
248
|
known_count,
|
|
259
249
|
", ".join(sorted(known_id_set)),
|
|
260
250
|
)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
def _relocate_misplaced_tool_results(
|
|
264
|
-
body: dict[str, Any],
|
|
265
|
-
adaptations: list[str],
|
|
266
|
-
) -> int:
|
|
267
|
-
"""检测并将非 user 消息中的 tool_result 块迁移到合法位置.
|
|
268
|
-
|
|
269
|
-
策略:
|
|
270
|
-
1. 扫描所有消息,识别非 user 消息中的 tool_result 块
|
|
271
|
-
2. 将这些块从原消息中移除
|
|
272
|
-
3. 将它们挂载到最近的前置 user 消息末尾(或创建新 user 消息)
|
|
273
|
-
|
|
274
|
-
Returns:
|
|
275
|
-
被迁移的 tool_result 块数量。
|
|
276
|
-
"""
|
|
277
|
-
messages = body.get("messages", [])
|
|
278
|
-
if not messages:
|
|
279
|
-
return 0
|
|
280
|
-
|
|
281
|
-
displaced_results: list[tuple[int, dict[str, Any]]] = [] # (msg_idx, block)
|
|
282
|
-
|
|
283
|
-
for msg_idx, message in enumerate(messages):
|
|
284
|
-
if not isinstance(message, dict):
|
|
285
|
-
continue
|
|
286
|
-
role = message.get("role")
|
|
287
|
-
if role == "user":
|
|
288
|
-
continue
|
|
289
|
-
content = message.get("content")
|
|
290
|
-
if not isinstance(content, list):
|
|
291
|
-
continue
|
|
292
|
-
|
|
293
|
-
cleaned_content: list[Any] = []
|
|
294
|
-
for block in content:
|
|
295
|
-
if (
|
|
296
|
-
isinstance(block, dict)
|
|
297
|
-
and block.get("type") == "tool_result"
|
|
298
|
-
and block.get("tool_use_id")
|
|
299
|
-
):
|
|
300
|
-
displaced_results.append((msg_idx, dict(block)))
|
|
301
|
-
logger.debug(
|
|
302
|
-
"发现错位 tool_result: messages[%d], tool_use_id=%s, "
|
|
303
|
-
"将迁移至最近的 user 消息",
|
|
304
|
-
msg_idx,
|
|
305
|
-
block.get("tool_use_id", ""),
|
|
306
|
-
)
|
|
307
|
-
else:
|
|
308
|
-
cleaned_content.append(block)
|
|
309
|
-
message["content"] = cleaned_content
|
|
310
|
-
|
|
311
|
-
if not displaced_results:
|
|
312
|
-
return 0
|
|
313
|
-
|
|
314
|
-
# 查找或创建目标 user 消息:优先选择离错位块最近的前置 user 消息
|
|
315
|
-
first_displaced_idx = displaced_results[0][0]
|
|
316
|
-
target_msg_idx = _find_nearest_user_message(messages, first_displaced_idx)
|
|
317
|
-
|
|
318
|
-
if target_msg_idx is None:
|
|
319
|
-
# 无前置 user 消息:在消息列表头部插入一个新的 user 消息
|
|
320
|
-
messages.insert(
|
|
321
|
-
0,
|
|
322
|
-
{
|
|
323
|
-
"role": "user",
|
|
324
|
-
"content": [block for _, block in displaced_results],
|
|
325
|
-
},
|
|
326
|
-
)
|
|
327
|
-
logger.info(
|
|
328
|
-
"已创建新 user 消息(索引 0)以容纳 %d 个错位 tool_result 块",
|
|
329
|
-
len(displaced_results),
|
|
330
|
-
)
|
|
331
|
-
else:
|
|
332
|
-
target_msg = messages[target_msg_idx]
|
|
333
|
-
target_content = target_msg.get("content")
|
|
334
|
-
if not isinstance(target_content, list):
|
|
335
|
-
target_content = []
|
|
336
|
-
target_msg["content"] = target_content
|
|
337
|
-
for _, block in displaced_results:
|
|
338
|
-
target_content.append(block)
|
|
339
|
-
logger.info(
|
|
340
|
-
"已将 %d 个错位 tool_result 块迁移至 messages[%d] (role=user)",
|
|
341
|
-
len(displaced_results),
|
|
342
|
-
target_msg_idx,
|
|
343
|
-
)
|
|
344
|
-
|
|
345
|
-
return len(displaced_results)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
def _find_nearest_user_message(
|
|
349
|
-
messages: list[dict[str, Any]],
|
|
350
|
-
from_index: int,
|
|
351
|
-
) -> int | None:
|
|
352
|
-
"""查找离指定索引最近的前置 user 消息.
|
|
353
|
-
|
|
354
|
-
Args:
|
|
355
|
-
messages: 消息列表
|
|
356
|
-
from_index: 起始搜索位置(不包含此位置)
|
|
357
|
-
|
|
358
|
-
Returns:
|
|
359
|
-
最近的前置 user 消息索引,若无则返回 None。
|
|
360
|
-
"""
|
|
361
|
-
for idx in range(from_index - 1, -1, -1):
|
|
362
|
-
msg = messages[idx]
|
|
363
|
-
if isinstance(msg, dict) and msg.get("role") == "user":
|
|
364
|
-
return idx
|
|
365
|
-
return None
|
|
@@ -97,10 +97,10 @@ class GoogleOAuthTokenManager(BaseTokenManager):
|
|
|
97
97
|
from ..auth.providers.google import GoogleOAuthProvider
|
|
98
98
|
|
|
99
99
|
if not GoogleOAuthProvider.has_required_scopes(scope):
|
|
100
|
-
|
|
101
|
-
"Google access_token
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
logger.warning(
|
|
101
|
+
"Google access_token scope 不完整(%s),"
|
|
102
|
+
"可能影响 Generative Language API 调用",
|
|
103
|
+
scope,
|
|
104
104
|
)
|
|
105
105
|
expires_in = data.get("expires_in", 3600)
|
|
106
106
|
logger.info("Google OAuth token refreshed, expires_in=%ds", expires_in)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: coding-proxy
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1a1
|
|
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
|
|
@@ -17,7 +17,7 @@ coding/proxy/compat/canonical.py,sha256=-zcuEwZ402xeH3C545RmuYRkT2HDuvFloyFydDv8
|
|
|
17
17
|
coding/proxy/compat/session_store.py,sha256=B9IFjjQJnHMg1244m__jG9gnqGWi26-JyEtwopEri6Q,5244
|
|
18
18
|
coding/proxy/config/__init__.py,sha256=hzgU5noJGecjj13UY38cC_p6jpWO3GO7okSW-A2XkJ0,127
|
|
19
19
|
coding/proxy/config/auth_schema.py,sha256=LYrJQU_fgW-6AoQdjXt4-MgPJjXjv9HrghlCcZwotnA,696
|
|
20
|
-
coding/proxy/config/config.default.yaml,sha256=
|
|
20
|
+
coding/proxy/config/config.default.yaml,sha256=kO64Dw9rvBx637SfL6nn1qBWANl1JwOHcboV6NLxVww,16158
|
|
21
21
|
coding/proxy/config/loader.py,sha256=1J_RBJgjuC8RwB2mwewLMS7vy9WEhUqttZG2igeDm-w,8984
|
|
22
22
|
coding/proxy/config/resiliency.py,sha256=GnzY-LoyfFqXFM1l6xEru418v-cKlv97-HM0noGPdks,1308
|
|
23
23
|
coding/proxy/config/routing.py,sha256=aJMhfCRyoZIvemM3Q2_KV9rpWxUsFnoY0ZdCr4TwSs8,11765
|
|
@@ -45,7 +45,7 @@ coding/proxy/routing/circuit_breaker.py,sha256=fKodIYxJ-3hhil2rEjsGqvyHTspliN_eS
|
|
|
45
45
|
coding/proxy/routing/error_classifier.py,sha256=oDxp69sCb-pdfe1hWce29A9tsN3jAbhqfl2fRECBtCo,3747
|
|
46
46
|
coding/proxy/routing/executor.py,sha256=xQw3rtHd00n3BBgUHzqAli1GUoFNOxc0odKEaq-Dw7A,28206
|
|
47
47
|
coding/proxy/routing/model_mapper.py,sha256=b72CGRdusLAwoq7p8-8TWAv9-Zv8BozssiZC8XnNTx4,3574
|
|
48
|
-
coding/proxy/routing/quota_guard.py,sha256=
|
|
48
|
+
coding/proxy/routing/quota_guard.py,sha256=TRJs3mjdRMc_u0HCw-hZn--osha_m11dEtAUxOO2P5A,6806
|
|
49
49
|
coding/proxy/routing/rate_limit.py,sha256=i2cCqtbmXrP6wjRUTWXLP4DdYwVj0C4o59QdYGkPQj0,5122
|
|
50
50
|
coding/proxy/routing/retry.py,sha256=KEYVToBkBOtXdqY7He70RrtVWFqIpnOQf2VVksdLrlk,2386
|
|
51
51
|
coding/proxy/routing/router.py,sha256=bXaglxuT-5qYzrSMk7ZE4mpQynP4Z6F2pm9hnCbdG90,3440
|
|
@@ -54,9 +54,9 @@ coding/proxy/routing/tier.py,sha256=U12Mw0eTE1AO5RuHNpoOuXDdujz_Hkx_iyIrqkZbtyA,
|
|
|
54
54
|
coding/proxy/routing/usage_parser.py,sha256=j4G0ArFduQ2D4Yeuad94DVlwdc-JvSh7SJLVzc-hLcs,8480
|
|
55
55
|
coding/proxy/routing/usage_recorder.py,sha256=pSs2r79fOrrq2cWJP-P5KKFnnXf62-3gYLaxAwndFi0,6272
|
|
56
56
|
coding/proxy/server/__init__.py,sha256=KeH7mEu36v9v27m3VgeSxSeFz9sLTJrxS_EVATJ7Vks,20
|
|
57
|
-
coding/proxy/server/app.py,sha256=
|
|
57
|
+
coding/proxy/server/app.py,sha256=ITCbtDrweNMp-l4_uNN-8wQ33BXpjvCk6p2dn8E0424,5538
|
|
58
58
|
coding/proxy/server/factory.py,sha256=I4asjFw_1ET49DC-xkCpfV7oyfSv4G6xUB_Z5N_SHY8,9920
|
|
59
|
-
coding/proxy/server/request_normalizer.py,sha256=
|
|
59
|
+
coding/proxy/server/request_normalizer.py,sha256=F_mgxxuA3i7cN1CEWlto7Mm9VT_QG2QNspiUWeYVBpM,10511
|
|
60
60
|
coding/proxy/server/responses.py,sha256=i0ugnLRNOdRYGHEWxkwsxR35ChmdMQsSaD8AjRluTn4,2167
|
|
61
61
|
coding/proxy/server/routes.py,sha256=QeEsYczjvPfVhOrED2qe1V6CpwVBZbQHs8dP0OGdGXQ,11734
|
|
62
62
|
coding/proxy/streaming/__init__.py,sha256=0al5TC-zJt8Bz0CibTmd8WPza-Cs-qcuZWvT2fKPqHI,23
|
|
@@ -64,7 +64,7 @@ coding/proxy/streaming/anthropic_compat.py,sha256=cycYiJ-glN88OmfLTR7FroHRethONl
|
|
|
64
64
|
coding/proxy/vendors/__init__.py,sha256=fehSpQ2-kUlZY6N8cNMGVJYMXspQmi3V4e0FgC4Ay4k,1011
|
|
65
65
|
coding/proxy/vendors/alibaba.py,sha256=vYhvk8hZEeOpqUrtGT-uaK89y6uolrDUAT2BvTD_IQY,876
|
|
66
66
|
coding/proxy/vendors/anthropic.py,sha256=KA_fvOxagGBggH2pc3l9Zoyl_XYUyRdfR8bI-eVj_e4,6328
|
|
67
|
-
coding/proxy/vendors/antigravity.py,sha256=
|
|
67
|
+
coding/proxy/vendors/antigravity.py,sha256=OmVXR6K_CHAZkhaAt_KIe3Q5NckNp0Mu3-PlEPeSrRQ,13270
|
|
68
68
|
coding/proxy/vendors/base.py,sha256=vrAaI_4uLtzaFcPWtBStVMHU5AgkCWTNLEgVeoHHgLE,14781
|
|
69
69
|
coding/proxy/vendors/copilot.py,sha256=qAFTO2xMqnawaFlvZS2a9-7f_UEkfODIFfDlgOBiQl4,29590
|
|
70
70
|
coding/proxy/vendors/copilot_models.py,sha256=UckIQYA4qLyNwEA09koQGBOZ65Nxhuo3ytUuDNqtzRU,15514
|
|
@@ -78,8 +78,8 @@ coding/proxy/vendors/native_anthropic.py,sha256=SxtM71PDci0gqLqiwCrFnT410SnSoD7F
|
|
|
78
78
|
coding/proxy/vendors/token_manager.py,sha256=s10t4Com0jNnKGkPyJ_HpG5SjHrCEJvfArEOAaPKA_k,4189
|
|
79
79
|
coding/proxy/vendors/xiaomi.py,sha256=E-GcmJBZh7GOtDFonxZmlf0hKRhrlrXzL0IxHFRYcRo,860
|
|
80
80
|
coding/proxy/vendors/zhipu.py,sha256=3j_rqNFu1CX-B5ugtrL6Y1OeWSy9yiqsVa9Bi1ssaAA,1062
|
|
81
|
-
coding_proxy-0.2.
|
|
82
|
-
coding_proxy-0.2.
|
|
83
|
-
coding_proxy-0.2.
|
|
84
|
-
coding_proxy-0.2.
|
|
85
|
-
coding_proxy-0.2.
|
|
81
|
+
coding_proxy-0.2.1a1.dist-info/METADATA,sha256=jjfyxndLfJqfFAa-wL9vy4e7rXi82BCC3sDkzl1xhpM,10782
|
|
82
|
+
coding_proxy-0.2.1a1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
83
|
+
coding_proxy-0.2.1a1.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
|
|
84
|
+
coding_proxy-0.2.1a1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
85
|
+
coding_proxy-0.2.1a1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|