coding-proxy 0.2.0a1__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 +89 -72
- coding/proxy/config/routing.py +2 -0
- 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.0a1.dist-info → coding_proxy-0.2.1a1.dist-info}/METADATA +1 -1
- {coding_proxy-0.2.0a1.dist-info → coding_proxy-0.2.1a1.dist-info}/RECORD +11 -11
- {coding_proxy-0.2.0a1.dist-info → coding_proxy-0.2.1a1.dist-info}/WHEEL +0 -0
- {coding_proxy-0.2.0a1.dist-info → coding_proxy-0.2.1a1.dist-info}/entry_points.txt +0 -0
- {coding_proxy-0.2.0a1.dist-info → coding_proxy-0.2.1a1.dist-info}/licenses/LICENSE +0 -0
|
@@ -26,12 +26,12 @@ logging:
|
|
|
26
26
|
# 示例 3:将 zhipu 提升为首选,anthropic 作为后备
|
|
27
27
|
# tiers: ["zhipu", "anthropic"]
|
|
28
28
|
|
|
29
|
-
tiers: ["
|
|
29
|
+
tiers: ["zhipu", "anthropic", "copilot", "antigravity"]
|
|
30
30
|
|
|
31
31
|
# === 供应商定义(vendors 列表) ===
|
|
32
32
|
#
|
|
33
33
|
# 每个 vendor 通过 vendor 字段指定供应商类型:
|
|
34
|
-
# anthropic |
|
|
34
|
+
# anthropic | zhipu | minimax | alibaba | xiaomi | kimi | doubao | copilot | antigravity
|
|
35
35
|
#
|
|
36
36
|
# 优先级规则:
|
|
37
37
|
# - 若配置了 tiers,以其指定的顺序为准
|
|
@@ -101,6 +101,7 @@ vendors:
|
|
|
101
101
|
|
|
102
102
|
# Vendor 3: 智谱 GLM(终端兜底,无 circuit_breaker)
|
|
103
103
|
- vendor: zhipu
|
|
104
|
+
enabled: true
|
|
104
105
|
base_url: "https://open.bigmodel.cn/api/anthropic"
|
|
105
106
|
api_key: "${ZHIPU_API_KEY}"
|
|
106
107
|
timeout_ms: 3000000
|
|
@@ -127,75 +128,75 @@ vendors:
|
|
|
127
128
|
recovery_timeout_seconds: 300
|
|
128
129
|
success_threshold: 2
|
|
129
130
|
quota_guard:
|
|
130
|
-
enabled:
|
|
131
|
+
enabled: false
|
|
131
132
|
token_budget: 1000000000
|
|
132
133
|
window_hours: 24.0
|
|
133
134
|
threshold_percent: 95.0
|
|
134
135
|
probe_interval_seconds: 300
|
|
135
136
|
|
|
136
|
-
# Vendor 5:
|
|
137
|
-
- vendor:
|
|
137
|
+
# Vendor 5: 阿里 Qwen(默认禁用)
|
|
138
|
+
- vendor: alibaba
|
|
138
139
|
enabled: false
|
|
139
|
-
base_url: "https://
|
|
140
|
-
api_key: "${
|
|
140
|
+
base_url: "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic"
|
|
141
|
+
api_key: "${ALIBABA_API_KEY}"
|
|
141
142
|
timeout_ms: 3000000
|
|
142
143
|
circuit_breaker:
|
|
143
144
|
failure_threshold: 3
|
|
144
145
|
recovery_timeout_seconds: 300
|
|
145
146
|
success_threshold: 2
|
|
146
147
|
quota_guard:
|
|
147
|
-
enabled:
|
|
148
|
+
enabled: false
|
|
148
149
|
token_budget: 1000000000
|
|
149
150
|
window_hours: 24.0
|
|
150
151
|
threshold_percent: 95.0
|
|
151
152
|
probe_interval_seconds: 300
|
|
152
153
|
|
|
153
|
-
# Vendor 6:
|
|
154
|
-
- vendor:
|
|
154
|
+
# Vendor 6: 小米 MiMo(默认禁用)
|
|
155
|
+
- vendor: xiaomi
|
|
155
156
|
enabled: false
|
|
156
|
-
base_url: "https://
|
|
157
|
-
api_key: "${
|
|
157
|
+
base_url: "https://token-plan-cn.xiaomimimo.com/anthropic"
|
|
158
|
+
api_key: "${XIAOMI_API_KEY}"
|
|
158
159
|
timeout_ms: 3000000
|
|
159
160
|
circuit_breaker:
|
|
160
161
|
failure_threshold: 3
|
|
161
162
|
recovery_timeout_seconds: 300
|
|
162
163
|
success_threshold: 2
|
|
163
164
|
quota_guard:
|
|
164
|
-
enabled:
|
|
165
|
+
enabled: false
|
|
165
166
|
token_budget: 1000000000
|
|
166
167
|
window_hours: 24.0
|
|
167
168
|
threshold_percent: 95.0
|
|
168
169
|
probe_interval_seconds: 300
|
|
169
170
|
|
|
170
|
-
# Vendor 7:
|
|
171
|
-
- vendor:
|
|
171
|
+
# Vendor 7: Kimi(默认禁用)
|
|
172
|
+
- vendor: kimi
|
|
172
173
|
enabled: false
|
|
173
|
-
base_url: "https://
|
|
174
|
-
api_key: "${
|
|
174
|
+
base_url: "https://api.kimi.com/coding/"
|
|
175
|
+
api_key: "${KIMI_API_KEY}"
|
|
175
176
|
timeout_ms: 3000000
|
|
176
177
|
circuit_breaker:
|
|
177
178
|
failure_threshold: 3
|
|
178
179
|
recovery_timeout_seconds: 300
|
|
179
180
|
success_threshold: 2
|
|
180
181
|
quota_guard:
|
|
181
|
-
enabled:
|
|
182
|
+
enabled: false
|
|
182
183
|
token_budget: 1000000000
|
|
183
184
|
window_hours: 24.0
|
|
184
185
|
threshold_percent: 95.0
|
|
185
186
|
probe_interval_seconds: 300
|
|
186
187
|
|
|
187
|
-
# Vendor 8:
|
|
188
|
-
- vendor:
|
|
188
|
+
# Vendor 8: 豆包 Doubao(默认禁用)
|
|
189
|
+
- vendor: doubao
|
|
189
190
|
enabled: false
|
|
190
|
-
base_url: "https://
|
|
191
|
-
api_key: "${
|
|
191
|
+
base_url: "https://ark.cn-beijing.volces.com/api/coding"
|
|
192
|
+
api_key: "${ARK_API_KEY}"
|
|
192
193
|
timeout_ms: 3000000
|
|
193
194
|
circuit_breaker:
|
|
194
195
|
failure_threshold: 3
|
|
195
196
|
recovery_timeout_seconds: 300
|
|
196
197
|
success_threshold: 2
|
|
197
198
|
quota_guard:
|
|
198
|
-
enabled:
|
|
199
|
+
enabled: false
|
|
199
200
|
token_budget: 1000000000
|
|
200
201
|
window_hours: 24.0
|
|
201
202
|
threshold_percent: 95.0
|
|
@@ -231,11 +232,15 @@ model_mapping:
|
|
|
231
232
|
# Google Antigravity 模型映射
|
|
232
233
|
- pattern: "claude-sonnet-.*"
|
|
233
234
|
vendors: ["antigravity"]
|
|
234
|
-
target: "
|
|
235
|
+
target: "Claude Sonnet 4.6"
|
|
235
236
|
is_regex: true
|
|
236
237
|
- pattern: "claude-opus-.*"
|
|
237
238
|
vendors: ["antigravity"]
|
|
238
|
-
target: "
|
|
239
|
+
target: "Claude Opus 4.6 Thinking"
|
|
240
|
+
is_regex: true
|
|
241
|
+
- pattern: "claude-haiku-.*"
|
|
242
|
+
vendors: ["antigravity"]
|
|
243
|
+
target: "Gemini 3 Flash"
|
|
239
244
|
is_regex: true
|
|
240
245
|
# 智谱 GLM 映射(官方原生 Anthropic 兼容端点)
|
|
241
246
|
# glm-5v-turbo 完整承载 Claude Code 满血能力(tool calling / thinking / 多模态)
|
|
@@ -264,6 +269,32 @@ model_mapping:
|
|
|
264
269
|
vendors: ["minimax"]
|
|
265
270
|
target: "minimax-m2.7"
|
|
266
271
|
is_regex: true
|
|
272
|
+
# 阿里 Qwen 模型映射(原生 Anthropic 兼容端点)
|
|
273
|
+
- pattern: "claude-sonnet-.*"
|
|
274
|
+
vendors: ["alibaba"]
|
|
275
|
+
target: "qwen3.6-plus"
|
|
276
|
+
is_regex: true
|
|
277
|
+
- pattern: "claude-opus-.*"
|
|
278
|
+
vendors: ["alibaba"]
|
|
279
|
+
target: "qwen3.6-plus"
|
|
280
|
+
is_regex: true
|
|
281
|
+
- pattern: "claude-haiku-.*"
|
|
282
|
+
vendors: ["alibaba"]
|
|
283
|
+
target: "qwen3.6-plus"
|
|
284
|
+
is_regex: true
|
|
285
|
+
# 小米 MiMo 模型映射(原生 Anthropic 兼容端点)
|
|
286
|
+
- pattern: "claude-sonnet-.*"
|
|
287
|
+
vendors: ["xiaomi"]
|
|
288
|
+
target: "mimo-v2-pro"
|
|
289
|
+
is_regex: true
|
|
290
|
+
- pattern: "claude-opus-.*"
|
|
291
|
+
vendors: ["xiaomi"]
|
|
292
|
+
target: "mimo-v2-pro"
|
|
293
|
+
is_regex: true
|
|
294
|
+
- pattern: "claude-haiku-.*"
|
|
295
|
+
vendors: ["xiaomi"]
|
|
296
|
+
target: "mimo-v2-pro"
|
|
297
|
+
is_regex: true
|
|
267
298
|
# Kimi 模型映射(原生 Anthropic 兼容端点)
|
|
268
299
|
- pattern: "claude-sonnet-.*"
|
|
269
300
|
vendors: ["kimi"]
|
|
@@ -290,32 +321,6 @@ model_mapping:
|
|
|
290
321
|
vendors: ["doubao"]
|
|
291
322
|
target: "doubao-seed-2.0-lite"
|
|
292
323
|
is_regex: true
|
|
293
|
-
# 小米 MiMo 模型映射(原生 Anthropic 兼容端点)
|
|
294
|
-
- pattern: "claude-sonnet-.*"
|
|
295
|
-
vendors: ["xiaomi"]
|
|
296
|
-
target: "mimo-v2-pro"
|
|
297
|
-
is_regex: true
|
|
298
|
-
- pattern: "claude-opus-.*"
|
|
299
|
-
vendors: ["xiaomi"]
|
|
300
|
-
target: "mimo-v2-pro"
|
|
301
|
-
is_regex: true
|
|
302
|
-
- pattern: "claude-haiku-.*"
|
|
303
|
-
vendors: ["xiaomi"]
|
|
304
|
-
target: "mimo-v2-pro"
|
|
305
|
-
is_regex: true
|
|
306
|
-
# 阿里 Qwen 模型映射(原生 Anthropic 兼容端点)
|
|
307
|
-
- pattern: "claude-sonnet-.*"
|
|
308
|
-
vendors: ["alibaba"]
|
|
309
|
-
target: "qwen3.6-plus"
|
|
310
|
-
is_regex: true
|
|
311
|
-
- pattern: "claude-opus-.*"
|
|
312
|
-
vendors: ["alibaba"]
|
|
313
|
-
target: "qwen3.6-plus"
|
|
314
|
-
is_regex: true
|
|
315
|
-
- pattern: "claude-haiku-.*"
|
|
316
|
-
vendors: ["alibaba"]
|
|
317
|
-
target: "qwen3.6-plus"
|
|
318
|
-
is_regex: true
|
|
319
324
|
|
|
320
325
|
# === 模型定价(USD / 1M tokens) ===
|
|
321
326
|
# vendor: 供应商名称(对应 `usage` 统计表中的"供应商"列)
|
|
@@ -329,6 +334,12 @@ pricing:
|
|
|
329
334
|
output_cost_per_mtok: $25.0
|
|
330
335
|
cache_write_cost_per_mtok: $6.25
|
|
331
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
|
|
332
343
|
- vendor: anthropic
|
|
333
344
|
model: claude-sonnet-4-6
|
|
334
345
|
input_cost_per_mtok: $3.0
|
|
@@ -341,6 +352,12 @@ pricing:
|
|
|
341
352
|
output_cost_per_mtok: $5
|
|
342
353
|
cache_write_cost_per_mtok: $1.25
|
|
343
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
|
|
344
361
|
# ── GitHub Copilot(透传 Claude,参照 Anthropic 定价估算) ──
|
|
345
362
|
- vendor: copilot
|
|
346
363
|
model: claude-opus-4.6
|
|
@@ -434,6 +451,27 @@ pricing:
|
|
|
434
451
|
output_cost_per_mtok: ¥8.40
|
|
435
452
|
cache_write_cost_per_mtok: ¥2.625
|
|
436
453
|
cache_read_cost_per_mtok: ¥0.21
|
|
454
|
+
# ── 阿里 Qwen ──
|
|
455
|
+
- vendor: alibaba
|
|
456
|
+
model: qwen3.6-plus
|
|
457
|
+
input_cost_per_mtok: $0.276
|
|
458
|
+
output_cost_per_mtok: $1.651
|
|
459
|
+
# ── 小米 MiMo ──
|
|
460
|
+
- vendor: xiaomi
|
|
461
|
+
model: mimo-v2-pro
|
|
462
|
+
input_cost_per_mtok: ¥7.00
|
|
463
|
+
output_cost_per_mtok: ¥21.00
|
|
464
|
+
cache_read_cost_per_mtok: ¥1.40
|
|
465
|
+
- vendor: xiaomi
|
|
466
|
+
model: mimo-v2-omni
|
|
467
|
+
input_cost_per_mtok: ¥2.80
|
|
468
|
+
output_cost_per_mtok: ¥14.00
|
|
469
|
+
cache_read_cost_per_mtok: ¥0.56
|
|
470
|
+
- vendor: xiaomi
|
|
471
|
+
model: mimo-v2-flash
|
|
472
|
+
input_cost_per_mtok: ¥0.70
|
|
473
|
+
output_cost_per_mtok: ¥2.10
|
|
474
|
+
cache_read_cost_per_mtok: ¥0.07
|
|
437
475
|
# ── Kimi ──
|
|
438
476
|
- vendor: kimi
|
|
439
477
|
model: kimi-k2.5
|
|
@@ -458,27 +496,6 @@ pricing:
|
|
|
458
496
|
output_cost_per_mtok: ¥3.60
|
|
459
497
|
cache_write_cost_per_mtok: ¥0.12
|
|
460
498
|
cache_read_cost_per_mtok: ¥0.017
|
|
461
|
-
# ── 小米 MiMo ──
|
|
462
|
-
- vendor: xiaomi
|
|
463
|
-
model: mimo-v2-pro
|
|
464
|
-
input_cost_per_mtok: ¥7.00
|
|
465
|
-
output_cost_per_mtok: ¥21.00
|
|
466
|
-
cache_read_cost_per_mtok: ¥1.40
|
|
467
|
-
- vendor: xiaomi
|
|
468
|
-
model: mimo-v2-omni
|
|
469
|
-
input_cost_per_mtok: ¥2.80
|
|
470
|
-
output_cost_per_mtok: ¥14.00
|
|
471
|
-
cache_read_cost_per_mtok: ¥0.56
|
|
472
|
-
- vendor: xiaomi
|
|
473
|
-
model: mimo-v2-flash
|
|
474
|
-
input_cost_per_mtok: ¥0.70
|
|
475
|
-
output_cost_per_mtok: ¥2.10
|
|
476
|
-
cache_read_cost_per_mtok: ¥0.07
|
|
477
|
-
# ── 阿里 Qwen ──
|
|
478
|
-
- vendor: alibaba
|
|
479
|
-
model: qwen3.6-plus
|
|
480
|
-
input_cost_per_mtok: $0.276
|
|
481
|
-
output_cost_per_mtok: $1.651
|
|
482
499
|
|
|
483
500
|
database:
|
|
484
501
|
path: "~/.coding-proxy/usage.db"
|
coding/proxy/config/routing.py
CHANGED
|
@@ -295,6 +295,8 @@ class VendorConfig(BaseModel):
|
|
|
295
295
|
if vendor_type == self.vendor:
|
|
296
296
|
continue
|
|
297
297
|
for field_name in fields:
|
|
298
|
+
if field_name in exclusive:
|
|
299
|
+
continue
|
|
298
300
|
value = getattr(self, field_name, None)
|
|
299
301
|
if value and value != getattr(
|
|
300
302
|
VendorConfig.model_fields[field_name], "default", None
|
|
@@ -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,10 +17,10 @@ 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
|
-
coding/proxy/config/routing.py,sha256=
|
|
23
|
+
coding/proxy/config/routing.py,sha256=aJMhfCRyoZIvemM3Q2_KV9rpWxUsFnoY0ZdCr4TwSs8,11765
|
|
24
24
|
coding/proxy/config/schema.py,sha256=yDPQfxUzJToAfXH-fJxoujXoYAb6WMeq7VyySbvMYC8,12205
|
|
25
25
|
coding/proxy/config/server.py,sha256=um6SJHat9Z_DPjE0AzpdbmbA0fTB0KovUlkNl_eJX-k,509
|
|
26
26
|
coding/proxy/config/vendors.py,sha256=Kw4IctoZBgB4yd7GlnoubWHRrKqmqSC6zY87oH3EPTQ,2796
|
|
@@ -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
|