coding-proxy 0.5.1a9__py3-none-any.whl → 0.5.2a2__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.
- coding/proxy/config/config.default.yaml +7 -0
- coding/proxy/config/session_policy.py +32 -1
- coding/proxy/routing/executor.py +54 -10
- coding/proxy/routing/retry.py +13 -4
- coding/proxy/routing/router.py +2 -0
- coding/proxy/server/app.py +1 -0
- coding/proxy/server/dashboard.py +102 -17
- coding/proxy/vendors/zhipu.py +2 -2
- {coding_proxy-0.5.1a9.dist-info → coding_proxy-0.5.2a2.dist-info}/METADATA +1 -1
- {coding_proxy-0.5.1a9.dist-info → coding_proxy-0.5.2a2.dist-info}/RECORD +13 -13
- {coding_proxy-0.5.1a9.dist-info → coding_proxy-0.5.2a2.dist-info}/WHEEL +0 -0
- {coding_proxy-0.5.1a9.dist-info → coding_proxy-0.5.2a2.dist-info}/entry_points.txt +0 -0
- {coding_proxy-0.5.1a9.dist-info → coding_proxy-0.5.2a2.dist-info}/licenses/LICENSE +0 -0
|
@@ -704,3 +704,10 @@ session_policies:
|
|
|
704
704
|
title_vendor_bindings:
|
|
705
705
|
- prefix: "# 目标"
|
|
706
706
|
vendor: "zhipu"
|
|
707
|
+
# Session 标题豁免前缀:user 输入(经噪声剥离清洗后)以任一前缀开头则跳过,
|
|
708
|
+
# 继续向后查找 title 候选。用于过滤注入式 Prompt(如示例语言指令),
|
|
709
|
+
# 避免其被误用作 Session 标题。大小写敏感 startswith。
|
|
710
|
+
# ⚠️ 自定义 yaml 中该字段为整体替换(loader 的 list 合并约定,非追加合并);
|
|
711
|
+
# 写空列表即关闭豁免。加载时会自动 strip + 去空 + 去重。
|
|
712
|
+
title_exempt_prefixes:
|
|
713
|
+
- "Write the title in the language"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from pydantic import BaseModel, Field
|
|
5
|
+
from pydantic import BaseModel, Field, field_validator
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class SessionPolicyMatch(BaseModel):
|
|
@@ -81,3 +81,34 @@ class SessionPoliciesConfig(BaseModel):
|
|
|
81
81
|
"匹配规则按列表顺序求值,首次匹配生效。"
|
|
82
82
|
),
|
|
83
83
|
)
|
|
84
|
+
title_exempt_prefixes: list[str] = Field(
|
|
85
|
+
default_factory=list,
|
|
86
|
+
description=(
|
|
87
|
+
"Session 标题豁免前缀名单。当首条 user TEXT 输入(经噪声剥离清洗后)"
|
|
88
|
+
"以任一前缀开头时,跳过该输入、继续向后查找合适的 title 候选。"
|
|
89
|
+
"用于过滤注入式 Prompt(如示例语言指令),避免其被误用作 Session 标题。"
|
|
90
|
+
"大小写敏感的 startswith 匹配,与 title_vendor_bindings 语义一致。"
|
|
91
|
+
"加载时会自动 strip + 去空 + 去重;空字符串前缀会被丢弃"
|
|
92
|
+
"(防空串 startswith 恒真导致全量误豁免)。"
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
@field_validator("title_exempt_prefixes", mode="after")
|
|
97
|
+
@classmethod
|
|
98
|
+
def _normalize_exempt_prefixes(cls, value: list[str]) -> list[str]:
|
|
99
|
+
"""归一化豁免前缀:strip + 去空 + 去重保序.
|
|
100
|
+
|
|
101
|
+
空字符串前缀必须丢弃——``"".startswith`` 恒真会豁免一切用户输入,
|
|
102
|
+
导致 Level 1 标题提取永久失效。
|
|
103
|
+
"""
|
|
104
|
+
seen: set[str] = set()
|
|
105
|
+
result: list[str] = []
|
|
106
|
+
for item in value:
|
|
107
|
+
if not isinstance(item, str):
|
|
108
|
+
continue
|
|
109
|
+
cleaned = item.strip()
|
|
110
|
+
if not cleaned or cleaned in seen:
|
|
111
|
+
continue
|
|
112
|
+
seen.add(cleaned)
|
|
113
|
+
result.append(cleaned)
|
|
114
|
+
return result
|
coding/proxy/routing/executor.py
CHANGED
|
@@ -148,14 +148,30 @@ def _sanitize_user_text(raw: str) -> str:
|
|
|
148
148
|
# ─────────────────────────────────────────────────────────────────
|
|
149
149
|
|
|
150
150
|
|
|
151
|
-
def _extract_title_from_user_text(
|
|
152
|
-
|
|
151
|
+
def _extract_title_from_user_text(
|
|
152
|
+
messages: list[CanonicalMessagePart],
|
|
153
|
+
exempt_prefixes: list[str] | None = None,
|
|
154
|
+
) -> str:
|
|
155
|
+
"""Level 1: 从 user TEXT 部分提取经噪声剥离后的首条非空文本.
|
|
156
|
+
|
|
157
|
+
``exempt_prefixes`` 非空时,清洗后文本以任一前缀开头则跳过该输入、继续向后
|
|
158
|
+
查找——用于过滤注入式 Prompt,避免其被误用作 Session 标题。匹配作用于
|
|
159
|
+
``_sanitize_user_text`` 清洗后的纯文本(而非带 XML 标签的原始 raw)。
|
|
160
|
+
"""
|
|
153
161
|
for part in messages:
|
|
154
162
|
if part.role != "user" or part.type != CanonicalPartType.TEXT:
|
|
155
163
|
continue
|
|
156
164
|
cleaned = _sanitize_user_text(part.text)
|
|
157
|
-
if cleaned:
|
|
158
|
-
|
|
165
|
+
if not cleaned:
|
|
166
|
+
continue
|
|
167
|
+
if exempt_prefixes and any(cleaned.startswith(p) for p in exempt_prefixes):
|
|
168
|
+
logger.debug(
|
|
169
|
+
"Title candidate skipped by exempt prefix %r (snippet=%r)",
|
|
170
|
+
next(p for p in exempt_prefixes if cleaned.startswith(p)),
|
|
171
|
+
cleaned[:60],
|
|
172
|
+
)
|
|
173
|
+
continue
|
|
174
|
+
return cleaned[:_SESSION_TITLE_MAX_LEN]
|
|
159
175
|
return ""
|
|
160
176
|
|
|
161
177
|
|
|
@@ -193,15 +209,24 @@ def _extract_title_from_metadata(request: CanonicalRequest) -> str:
|
|
|
193
209
|
return ""
|
|
194
210
|
|
|
195
211
|
|
|
196
|
-
def _extract_session_title(
|
|
212
|
+
def _extract_session_title(
|
|
213
|
+
request: CanonicalRequest,
|
|
214
|
+
exempt_prefixes: list[str] | None = None,
|
|
215
|
+
) -> str:
|
|
197
216
|
"""从规范化请求中提取 session 标题 — 多层级回退策略。
|
|
198
217
|
|
|
199
218
|
依次尝试: user TEXT 噪声剥离 → TOOL_RESULT 摘要 → IMAGE 计数 → 元数据兜底。
|
|
200
219
|
任意级别命中即返回,确保 Dashboard 尽可能展示有辨识度的标题。
|
|
220
|
+
|
|
221
|
+
``exempt_prefixes`` 仅作用于 Level 1(用户直接输入的 TEXT);Level 2/3/4
|
|
222
|
+
为非用户直接输入的回退来源,不参与豁免。默认 ``None`` 时行为与历史一致。
|
|
201
223
|
"""
|
|
202
224
|
messages = request.messages
|
|
225
|
+
# Level 1 需要豁免前缀;单独调用以传入参数,避免污染 L2/L3 的统一签名。
|
|
226
|
+
title = _extract_title_from_user_text(messages, exempt_prefixes)
|
|
227
|
+
if title:
|
|
228
|
+
return title[:_SESSION_TITLE_MAX_LEN]
|
|
203
229
|
for extractor in (
|
|
204
|
-
_extract_title_from_user_text,
|
|
205
230
|
_extract_title_from_tool_results,
|
|
206
231
|
_extract_title_from_images,
|
|
207
232
|
):
|
|
@@ -614,6 +639,7 @@ class _RouteExecutor:
|
|
|
614
639
|
reauth_coordinator: Any | None = None,
|
|
615
640
|
session_policy_resolver: SessionPolicyResolver | None = None,
|
|
616
641
|
title_vendor_bindings: list[TitleVendorBinding] | None = None,
|
|
642
|
+
title_exempt_prefixes: list[str] | None = None,
|
|
617
643
|
) -> None:
|
|
618
644
|
self._router = router
|
|
619
645
|
self._tiers = tiers
|
|
@@ -622,6 +648,13 @@ class _RouteExecutor:
|
|
|
622
648
|
self._reauth_coordinator = reauth_coordinator
|
|
623
649
|
self._policy_resolver = session_policy_resolver or SessionPolicyResolver()
|
|
624
650
|
self._title_vendor_bindings = title_vendor_bindings or []
|
|
651
|
+
# 豁免前缀名单:构造期二次归一化(strip + 去空),双重防御配置层 field_validator。
|
|
652
|
+
# 即便绕过配置层直接构造 executor,也能避免空串 startswith 恒真与纯空白失配。
|
|
653
|
+
self._title_exempt_prefixes: list[str] = [
|
|
654
|
+
stripped
|
|
655
|
+
for p in (title_exempt_prefixes or [])
|
|
656
|
+
if isinstance(p, str) and (stripped := p.strip())
|
|
657
|
+
]
|
|
625
658
|
self._validate_title_vendor_bindings()
|
|
626
659
|
|
|
627
660
|
# Tier 名称 → OAuth provider 名称的映射
|
|
@@ -676,6 +709,17 @@ class _RouteExecutor:
|
|
|
676
709
|
seen.add(tier.name)
|
|
677
710
|
return ordered
|
|
678
711
|
|
|
712
|
+
def _extract_session_title(self, request: CanonicalRequest) -> str:
|
|
713
|
+
"""封装模块级标题提取,注入实例持有的豁免前缀名单.
|
|
714
|
+
|
|
715
|
+
将 ``self._title_exempt_prefixes`` 透传给模块级 ``_extract_session_title``,
|
|
716
|
+
使 Level 1 能跳过以豁免前缀开头的注入式 Prompt。4 处标题提取调用点统一
|
|
717
|
+
经此方法,避免重复透传(零透传污染)。
|
|
718
|
+
"""
|
|
719
|
+
return _extract_session_title(
|
|
720
|
+
request, exempt_prefixes=self._title_exempt_prefixes
|
|
721
|
+
)
|
|
722
|
+
|
|
679
723
|
def _apply_title_based_policy(self, session_key: str, title: str) -> None:
|
|
680
724
|
"""根据 Session 标题前缀自动绑定供应商.
|
|
681
725
|
|
|
@@ -790,7 +834,7 @@ class _RouteExecutor:
|
|
|
790
834
|
canonical_request.trace_id,
|
|
791
835
|
)
|
|
792
836
|
if is_new_session:
|
|
793
|
-
title = _extract_session_title(canonical_request)
|
|
837
|
+
title = self._extract_session_title(canonical_request)
|
|
794
838
|
if title:
|
|
795
839
|
await self._recorder.set_session_title(
|
|
796
840
|
canonical_request.session_key, title
|
|
@@ -798,7 +842,7 @@ class _RouteExecutor:
|
|
|
798
842
|
self._apply_title_based_policy(canonical_request.session_key, title)
|
|
799
843
|
else:
|
|
800
844
|
# 延迟标题补写: 若 session 尚无标题,尝试从当前请求中提取并回写。
|
|
801
|
-
title = _extract_session_title(canonical_request)
|
|
845
|
+
title = self._extract_session_title(canonical_request)
|
|
802
846
|
if title:
|
|
803
847
|
await self._recorder.update_empty_session_title(
|
|
804
848
|
canonical_request.session_key, title
|
|
@@ -977,7 +1021,7 @@ class _RouteExecutor:
|
|
|
977
1021
|
canonical_request.trace_id,
|
|
978
1022
|
)
|
|
979
1023
|
if is_new_session:
|
|
980
|
-
title = _extract_session_title(canonical_request)
|
|
1024
|
+
title = self._extract_session_title(canonical_request)
|
|
981
1025
|
if title:
|
|
982
1026
|
await self._recorder.set_session_title(
|
|
983
1027
|
canonical_request.session_key, title
|
|
@@ -985,7 +1029,7 @@ class _RouteExecutor:
|
|
|
985
1029
|
self._apply_title_based_policy(canonical_request.session_key, title)
|
|
986
1030
|
else:
|
|
987
1031
|
# 延迟标题补写: 若 session 尚无标题,尝试从当前请求中提取并回写。
|
|
988
|
-
title = _extract_session_title(canonical_request)
|
|
1032
|
+
title = self._extract_session_title(canonical_request)
|
|
989
1033
|
if title:
|
|
990
1034
|
await self._recorder.update_empty_session_title(
|
|
991
1035
|
canonical_request.session_key, title
|
coding/proxy/routing/retry.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""传输层重试策略 — 指数退避与
|
|
1
|
+
"""传输层重试策略 — 指数退避与 Equal Jitter.
|
|
2
2
|
|
|
3
3
|
与 Circuit Breaker 正交互:
|
|
4
4
|
- Retry 处理瞬态网络抖动(秒级恢复)
|
|
@@ -68,15 +68,24 @@ def is_retryable_status(status_code: int) -> bool:
|
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
def calculate_delay(attempt: int, cfg: RetryConfig) -> float:
|
|
71
|
-
"""计算第 N 次重试的延迟(毫秒),含指数退避和
|
|
71
|
+
"""计算第 N 次重试的延迟(毫秒),含指数退避和 Equal Jitter.
|
|
72
|
+
|
|
73
|
+
Equal Jitter 策略: temp = min(initial * backoff^attempt, max);
|
|
74
|
+
delay = temp/2 + random(0, temp/2),落在 [temp/2, temp]。
|
|
75
|
+
相较 Full Jitter (random(0, temp)),Equal Jitter 保留一半固定基线,
|
|
76
|
+
使相邻重试的延迟区间仅边界相切,呈现单调非递减的指数形态,
|
|
77
|
+
同时保留抖动以防惊群。
|
|
78
|
+
|
|
79
|
+
契约边界:单调非递减依赖 ``backoff_multiplier >= 2.0`` 且未触及
|
|
80
|
+
``max_delay_ms`` 封顶;封顶后各 attempt 区间退化为同一 [max/2, max]
|
|
81
|
+
(当前 Zhipu ``max_retries=4`` 触及不到该边界)。
|
|
72
82
|
|
|
73
|
-
Full Jitter 策略: delay = random(0, min(initial * backoff^attempt, max))
|
|
74
83
|
参考: AWS "Exponential Backoff And Jitter" (Marc Brooker, 2015)
|
|
75
84
|
"""
|
|
76
85
|
delay = cfg.initial_delay_ms * (cfg.backoff_multiplier**attempt)
|
|
77
86
|
delay = min(delay, cfg.max_delay_ms)
|
|
78
87
|
|
|
79
88
|
if cfg.jitter:
|
|
80
|
-
delay = random.uniform(0, delay)
|
|
89
|
+
delay = delay / 2 + random.uniform(0, delay / 2)
|
|
81
90
|
|
|
82
91
|
return delay
|
coding/proxy/routing/router.py
CHANGED
|
@@ -40,6 +40,7 @@ class RequestRouter:
|
|
|
40
40
|
compat_session_store: CompatSessionStore | None = None,
|
|
41
41
|
session_policy_resolver: SessionPolicyResolver | None = None,
|
|
42
42
|
title_vendor_bindings: list[TitleVendorBinding] | None = None,
|
|
43
|
+
title_exempt_prefixes: list[str] | None = None,
|
|
43
44
|
) -> None:
|
|
44
45
|
if not tiers:
|
|
45
46
|
raise ValueError("至少需要一个供应商层级")
|
|
@@ -59,6 +60,7 @@ class RequestRouter:
|
|
|
59
60
|
reauth_coordinator=reauth_coordinator,
|
|
60
61
|
session_policy_resolver=session_policy_resolver,
|
|
61
62
|
title_vendor_bindings=title_vendor_bindings,
|
|
63
|
+
title_exempt_prefixes=title_exempt_prefixes,
|
|
62
64
|
)
|
|
63
65
|
|
|
64
66
|
def set_pricing_table(self, table: PricingTable) -> None:
|
coding/proxy/server/app.py
CHANGED
|
@@ -162,6 +162,7 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
|
|
|
162
162
|
compat_session_store,
|
|
163
163
|
session_policy_resolver=SessionPolicyResolver(config.session_policies.policies),
|
|
164
164
|
title_vendor_bindings=config.session_policies.title_vendor_bindings,
|
|
165
|
+
title_exempt_prefixes=config.session_policies.title_exempt_prefixes,
|
|
165
166
|
)
|
|
166
167
|
|
|
167
168
|
app = FastAPI(title="coding-proxy", version=__version__, lifespan=lifespan)
|
coding/proxy/server/dashboard.py
CHANGED
|
@@ -11,28 +11,106 @@ from fastapi.responses import HTMLResponse, Response
|
|
|
11
11
|
|
|
12
12
|
from ..logging.db import TimePeriod
|
|
13
13
|
|
|
14
|
+
# ── 品牌图标:Tabler terminal-2 核心笔划(> 与 _),不含外框 ──────────────
|
|
15
|
+
# 外框由「蓝紫渐变圆角方块」容器承载(favicon SVG 的 <rect> 与页面 .logo 的 CSS
|
|
16
|
+
# 渐变),保留 Tabler 原始外框笔划会双重描边、边缘发糊,故仅取 > 与 _ 两条。
|
|
17
|
+
# 作为单一事实源,同时供 favicon SVG(f-string)与页面 logo({{TERMINAL2}} 模板替换)消费。
|
|
18
|
+
_TERMINAL2_PATHS = '<path d="M8 9l3 3l-3 3" /><path d="M13 15l3 0" />'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# ── Favicon (SVG, 现代浏览器主选) ──────────────────────────────────────────
|
|
22
|
+
def _build_favicon_svg() -> str:
|
|
23
|
+
"""生成 24×24 SVG favicon:品牌渐变圆角方块 + 白色 terminal-2 笔划.
|
|
24
|
+
|
|
25
|
+
独立 SVG 文档无 CSS 上下文,``currentColor`` 不可靠,故笔划硬编码 ``#ffffff``。
|
|
26
|
+
"""
|
|
27
|
+
return (
|
|
28
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">'
|
|
29
|
+
'<defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1">'
|
|
30
|
+
'<stop offset="0" stop-color="#667eea"/>'
|
|
31
|
+
'<stop offset="1" stop-color="#764ba2"/>'
|
|
32
|
+
"</linearGradient></defs>"
|
|
33
|
+
'<rect x="1" y="1" width="22" height="22" rx="6" fill="url(#g)"/>'
|
|
34
|
+
f'<g fill="none" stroke="#ffffff" stroke-width="2" '
|
|
35
|
+
f'stroke-linecap="round" stroke-linejoin="round">{_TERMINAL2_PATHS}</g>'
|
|
36
|
+
"</svg>"
|
|
37
|
+
)
|
|
38
|
+
|
|
14
39
|
|
|
15
|
-
# ── Favicon (
|
|
40
|
+
# ── Favicon (ICO, 32×32 光栅回退) ─────────────────────────────────────────
|
|
16
41
|
def _build_favicon() -> bytes:
|
|
17
|
-
"""程序化生成
|
|
42
|
+
"""程序化生成 32×32 ICO:品牌渐变圆角方块 + 白色 terminal-2 笔划(旧浏览器/Safari 回退).
|
|
43
|
+
|
|
44
|
+
项目无 Pillow/cairosvg 等图像库,故以纯 Python 按像素光栅化:渐变圆角方块背景
|
|
45
|
+
+ 白色 ``>`` 折线与 ``_`` 下划线。沿用原实现「全零 AND-mask + per-pixel alpha」
|
|
46
|
+
的圆角透明方案(现代渲染器按 alpha 通道处理透明)。
|
|
47
|
+
"""
|
|
48
|
+
import math
|
|
18
49
|
import struct
|
|
19
50
|
|
|
20
|
-
width
|
|
51
|
+
width = height = 32
|
|
52
|
+
radius = 8
|
|
53
|
+
scale = width / 24.0 # SVG 24 单位 -> 像素
|
|
54
|
+
|
|
55
|
+
r0, g0, b0 = 0x66, 0x7E, 0xEA # #667eea
|
|
56
|
+
r1, g1, b1 = 0x76, 0x4B, 0xA2 # #764ba2
|
|
57
|
+
|
|
58
|
+
def inside(x: int, y: int) -> bool:
|
|
59
|
+
"""满铺圆角方块(四角半径 radius)包含判定."""
|
|
60
|
+
cx = min(x, width - 1 - x)
|
|
61
|
+
cy = min(y, height - 1 - y)
|
|
62
|
+
if cx >= radius or cy >= radius:
|
|
63
|
+
return True
|
|
64
|
+
return (radius - cx) ** 2 + (radius - cy) ** 2 <= radius * radius
|
|
65
|
+
|
|
66
|
+
# 像素缓冲:[B, G, R, A],默认全透明
|
|
67
|
+
buf: list[list[list[int]]] = [
|
|
68
|
+
[[0, 0, 0, 0] for _ in range(width)] for _ in range(height)
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
# 1) 对角渐变圆角背景(左上 #667eea -> 右下 #764ba2)
|
|
72
|
+
for y in range(height):
|
|
73
|
+
for x in range(width):
|
|
74
|
+
if not inside(x, y):
|
|
75
|
+
continue
|
|
76
|
+
t = (x + y) / (width + height - 2)
|
|
77
|
+
buf[y][x] = [
|
|
78
|
+
int(b0 + (b1 - b0) * t),
|
|
79
|
+
int(g0 + (g1 - g0) * t),
|
|
80
|
+
int(r0 + (r1 - r0) * t),
|
|
81
|
+
255,
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
def stamp(px: float, py: float) -> None:
|
|
85
|
+
"""以 (px, py) 为中心盖 ~3px 白色方块(笔划加粗,保证小尺寸可辨识)."""
|
|
86
|
+
ix, iy = int(round(px)), int(round(py))
|
|
87
|
+
for oy in (-1, 0, 1):
|
|
88
|
+
for ox in (-1, 0, 1):
|
|
89
|
+
nx, ny = ix + ox, iy + oy
|
|
90
|
+
if 0 <= nx < width and 0 <= ny < height:
|
|
91
|
+
buf[ny][nx] = [255, 255, 255, 255]
|
|
92
|
+
|
|
93
|
+
def line(x0: float, y0: float, x1: float, y1: float) -> None:
|
|
94
|
+
"""稠密采样 + stamp 形成白色粗线段."""
|
|
95
|
+
dist = math.hypot(x1 - x0, y1 - y0)
|
|
96
|
+
steps = max(1, int(dist * 3))
|
|
97
|
+
for i in range(steps + 1):
|
|
98
|
+
s = i / steps
|
|
99
|
+
stamp(x0 + (x1 - x0) * s, y0 + (y1 - y0) * s)
|
|
100
|
+
|
|
101
|
+
# 2) terminal-2 笔划(SVG 24 单位 -> 像素)
|
|
102
|
+
# > 折线 (8,9)->(11,12)->(8,15);_ 下划线 (13,15)->(16,15)
|
|
103
|
+
line(8 * scale, 9 * scale, 11 * scale, 12 * scale)
|
|
104
|
+
line(11 * scale, 12 * scale, 8 * scale, 15 * scale)
|
|
105
|
+
line(13 * scale, 15 * scale, 16 * scale, 15 * scale)
|
|
106
|
+
|
|
107
|
+
# 3) 打包 ICO(BMP bottom-up;全零 AND-mask,信任 per-pixel alpha 实现圆角透明)
|
|
21
108
|
pixel_rows: list[bytes] = []
|
|
22
|
-
cx, cy = width / 2.0, height / 2.0
|
|
23
109
|
for y in range(height - 1, -1, -1): # BMP bottom-up
|
|
24
110
|
row = bytearray()
|
|
25
111
|
for x in range(width):
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if dx * dx + dy * dy > (width / 2.0) ** 2:
|
|
29
|
-
row.extend([0, 0, 0, 0]) # 圆外透明
|
|
30
|
-
else:
|
|
31
|
-
t = (x + (height - 1 - y)) / (width + height - 2)
|
|
32
|
-
r = int(88 + (188 - 88) * t)
|
|
33
|
-
g = int(166 + (140 - 166) * t)
|
|
34
|
-
b = 255
|
|
35
|
-
row.extend([b, g, r, 255]) # BGRA
|
|
112
|
+
b, g, r, a = buf[y][x]
|
|
113
|
+
row.extend([b, g, r, a]) # BGRA
|
|
36
114
|
pixel_rows.append(bytes(row))
|
|
37
115
|
|
|
38
116
|
bmp_hdr = struct.pack(
|
|
@@ -50,6 +128,7 @@ def _build_favicon() -> bytes:
|
|
|
50
128
|
|
|
51
129
|
|
|
52
130
|
_FAVICON_ICO: bytes = _build_favicon()
|
|
131
|
+
_FAVICON_SVG: str = _build_favicon_svg()
|
|
53
132
|
|
|
54
133
|
logger = logging.getLogger(__name__)
|
|
55
134
|
|
|
@@ -61,6 +140,7 @@ _DASHBOARD_HTML = """<!DOCTYPE html>
|
|
|
61
140
|
<meta charset="UTF-8" />
|
|
62
141
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
63
142
|
<title>Coding Proxy Dashboard</title>
|
|
143
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
64
144
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
|
65
145
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
66
146
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
@@ -127,9 +207,9 @@ _DASHBOARD_HTML = """<!DOCTYPE html>
|
|
|
127
207
|
background: var(--gradient-primary);
|
|
128
208
|
border-radius: 10px;
|
|
129
209
|
display: flex; align-items: center; justify-content: center;
|
|
130
|
-
font-size: 15px; font-weight: 700; color: #fff;
|
|
131
210
|
box-shadow: 0 4px 12px rgba(102,126,234,.25);
|
|
132
211
|
}
|
|
212
|
+
.logo svg { width: 20px; height: 20px; display: block; }
|
|
133
213
|
h1 { font-size: 18px; font-weight: 600; color: var(--text-primary); letter-spacing: -.3px; }
|
|
134
214
|
.header-right { display: flex; align-items: center; gap: 12px; }
|
|
135
215
|
.badge {
|
|
@@ -705,7 +785,7 @@ _DASHBOARD_HTML = """<!DOCTYPE html>
|
|
|
705
785
|
<body>
|
|
706
786
|
<header>
|
|
707
787
|
<div class="header-left">
|
|
708
|
-
<div class="logo">
|
|
788
|
+
<div class="logo"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">{{TERMINAL2}}</svg></div>
|
|
709
789
|
<h1>Coding Proxy Dashboard</h1>
|
|
710
790
|
<span class="badge" id="version-badge">v-.-.-</span>
|
|
711
791
|
</div>
|
|
@@ -2127,7 +2207,7 @@ function switchTab(name) {
|
|
|
2127
2207
|
</script>
|
|
2128
2208
|
</body>
|
|
2129
2209
|
</html>
|
|
2130
|
-
"""
|
|
2210
|
+
""".replace("{{TERMINAL2}}", _TERMINAL2_PATHS)
|
|
2131
2211
|
|
|
2132
2212
|
|
|
2133
2213
|
# ── 数据计算工具 ──────────────────────────────────────────────────────────
|
|
@@ -2204,6 +2284,11 @@ def register_dashboard_routes(app: Any) -> None:
|
|
|
2204
2284
|
"""返回内嵌 favicon."""
|
|
2205
2285
|
return Response(content=_FAVICON_ICO, media_type="image/x-icon")
|
|
2206
2286
|
|
|
2287
|
+
@app.get("/favicon.svg", include_in_schema=False)
|
|
2288
|
+
async def favicon_svg() -> Response:
|
|
2289
|
+
"""返回 SVG favicon(现代浏览器优先)."""
|
|
2290
|
+
return Response(content=_FAVICON_SVG, media_type="image/svg+xml")
|
|
2291
|
+
|
|
2207
2292
|
@app.get("/dashboard", response_class=HTMLResponse, include_in_schema=False)
|
|
2208
2293
|
async def dashboard() -> HTMLResponse:
|
|
2209
2294
|
"""返回 Dashboard HTML 页面."""
|
coding/proxy/vendors/zhipu.py
CHANGED
|
@@ -16,7 +16,7 @@ Anthropic Messages API 协议,本模块做以下适配:
|
|
|
16
16
|
额外提供 429/529 专用重试挽回机制:
|
|
17
17
|
- 429 Rate Limit(限流)与 529 Overloaded(并发过载)共用同一退避策略
|
|
18
18
|
- max_attempt = 5(1 初始 + 4 重试)
|
|
19
|
-
- 指数退避 +
|
|
19
|
+
- 指数退避 + Equal Jitter(区间 0.5–1s → 1–2s → 2–4s → 4–8s)
|
|
20
20
|
- 优先尊重 server retry-after header
|
|
21
21
|
|
|
22
22
|
并发限流由 BaseVendor._concurrency_controller 统一管控
|
|
@@ -238,7 +238,7 @@ class ZhipuVendor(NativeAnthropicVendor):
|
|
|
238
238
|
以"限流退避"语义(429)解析 header:``parse_rate_limit_headers``
|
|
239
239
|
仅对 429/403 解析 retry-after,故此处固定传 429,
|
|
240
240
|
使 529 也能尊重 server retry-after,与 429 行为一致。
|
|
241
|
-
无 server 信号时回退到指数退避 +
|
|
241
|
+
无 server 信号时回退到指数退避 + Equal Jitter。
|
|
242
242
|
"""
|
|
243
243
|
rl_info = parse_rate_limit_headers(headers, 429, None)
|
|
244
244
|
server_delay_s = compute_effective_retry_seconds(rl_info)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: coding-proxy
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2a2
|
|
4
4
|
Summary: A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM, MiniMax, Qwen, Xiaomi, Kimi, Doubao...
|
|
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,13 +17,13 @@ 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=HVfHHvqJqBQ89Oq582ScT-VYz6QzwYhLyfQFt24xwU4,23481
|
|
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=MWTUq6QaYDmoXEARN9EBAptC6TSGK2yezNiaVk3kaXY,12196
|
|
24
24
|
coding/proxy/config/schema.py,sha256=q1mlpnSMoVneDqzCSBR88xCgKG6aVu11ikdbMzWM27I,13542
|
|
25
25
|
coding/proxy/config/server.py,sha256=4yY7i3WYOjtyZtZqHMtkjqHZ2W6D_ffEwVIfzxRar90,1002
|
|
26
|
-
coding/proxy/config/session_policy.py,sha256=
|
|
26
|
+
coding/proxy/config/session_policy.py,sha256=bjJqszszWirnrKiiA46lckzsY-nqbFIh1xnrju0S0j0,4073
|
|
27
27
|
coding/proxy/config/vendors.py,sha256=9_Pgj9U6zOZVUV3UlA9P8BlKSDlj34g4p0lCy_bdimE,3472
|
|
28
28
|
coding/proxy/convert/__init__.py,sha256=0D3Q9TdY_AWCaMMf9f_i3jn0RIiWmqlcIAA79Ki8uJc,458
|
|
29
29
|
coding/proxy/convert/anthropic_to_gemini.py,sha256=9mRQ0CRAGJyWQADNlfMqoCJ_vY8ZZBGWaS_R8Vbe_l0,13201
|
|
@@ -56,20 +56,20 @@ coding/proxy/native_api/extractors/openai.py,sha256=bPdkcR_2g7zb-F8P7CGumVqv_chR
|
|
|
56
56
|
coding/proxy/routing/__init__.py,sha256=2Tpc6MQ5Oy_w-YlEWQVDSgcSgiHp3OwKOABIjj5kfHA,1595
|
|
57
57
|
coding/proxy/routing/circuit_breaker.py,sha256=hOyoY_RWB5dTVbipyuiWfAelnva3cZRLbXrSmSn8KTs,8096
|
|
58
58
|
coding/proxy/routing/error_classifier.py,sha256=SoJsExbfzduBOC04tKv9RdQqkzA-tQxbPapU5duNJqA,4204
|
|
59
|
-
coding/proxy/routing/executor.py,sha256=
|
|
59
|
+
coding/proxy/routing/executor.py,sha256=Nexuq1xJ3MKYeJHDTXGD731bu4-vnOcPMUyH2Ah1ZUA,58929
|
|
60
60
|
coding/proxy/routing/model_mapper.py,sha256=yc5PW7c9x6wfs7wGdbm-G5pFwg-kPTim6A2mKZ3sQgc,2803
|
|
61
61
|
coding/proxy/routing/quota_guard.py,sha256=uoQSr2siv6aIBVylvXG_PsfdpY_i4QJxc-WHz4MGDa4,7791
|
|
62
62
|
coding/proxy/routing/rate_limit.py,sha256=i2cCqtbmXrP6wjRUTWXLP4DdYwVj0C4o59QdYGkPQj0,5122
|
|
63
|
-
coding/proxy/routing/retry.py,sha256=
|
|
64
|
-
coding/proxy/routing/router.py,sha256=
|
|
63
|
+
coding/proxy/routing/retry.py,sha256=iRtuMSwXgGi_FPRi5mopTicdbEs_xrrKCXs83QjCz1c,2912
|
|
64
|
+
coding/proxy/routing/router.py,sha256=qqI3-cqdwArnBr0d8L0rLlkisu4HRsxhs-PwZAY8TiA,6311
|
|
65
65
|
coding/proxy/routing/session_manager.py,sha256=GXeqLmHBlbcK49vNV_fDZnW8pVumeTJkiDB3ijKIsow,3145
|
|
66
66
|
coding/proxy/routing/session_policy.py,sha256=U46jidS3y7MgfcIQtOa8k0SBnkdRO0Jybe3ph4q-br4,4725
|
|
67
67
|
coding/proxy/routing/tier.py,sha256=OBrJiMxfLCxXvZfARD5oNmuhpYASKnyrW9sOCHLdQ1g,7777
|
|
68
68
|
coding/proxy/routing/usage_parser.py,sha256=ZwPuMGtXAwdIOKrXLpdtA4nCmc83ViF6kw5JnivRC6s,10426
|
|
69
69
|
coding/proxy/routing/usage_recorder.py,sha256=PHUHotCt3VaKkdJizMpPGsUOAj-f5qz9JKeiLEnFNgA,8779
|
|
70
70
|
coding/proxy/server/__init__.py,sha256=KeH7mEu36v9v27m3VgeSxSeFz9sLTJrxS_EVATJ7Vks,20
|
|
71
|
-
coding/proxy/server/app.py,sha256=
|
|
72
|
-
coding/proxy/server/dashboard.py,sha256=
|
|
71
|
+
coding/proxy/server/app.py,sha256=3MYE8-Vsxpt1SVqTKReMKNREBsh_LHKIFq1B4jhfeL8,7121
|
|
72
|
+
coding/proxy/server/dashboard.py,sha256=DRfa4T4nbKGqVgryf44dGQewh8Umh8lkiRrEu1Emr_s,96638
|
|
73
73
|
coding/proxy/server/factory.py,sha256=L0d0AA0fpkV-gynM85u1l5dXY1OQ5A_p_-PV0XlFGQs,10272
|
|
74
74
|
coding/proxy/server/responses.py,sha256=i0ugnLRNOdRYGHEWxkwsxR35ChmdMQsSaD8AjRluTn4,2167
|
|
75
75
|
coding/proxy/server/routes.py,sha256=B8rsFFLyCnjyamnQhp_sUm9KRMfdXiY3DPrfacD5Nvs,20454
|
|
@@ -92,9 +92,9 @@ coding/proxy/vendors/mixins.py,sha256=eZd_vlsPCKUNOEWSxWTDDb5i24GUIE3_JZDsj5LMr0
|
|
|
92
92
|
coding/proxy/vendors/native_anthropic.py,sha256=SxtM71PDci0gqLqiwCrFnT410SnSoD7FhLwcZuGB8tU,10074
|
|
93
93
|
coding/proxy/vendors/token_manager.py,sha256=s10t4Com0jNnKGkPyJ_HpG5SjHrCEJvfArEOAaPKA_k,4189
|
|
94
94
|
coding/proxy/vendors/xiaomi.py,sha256=E-GcmJBZh7GOtDFonxZmlf0hKRhrlrXzL0IxHFRYcRo,860
|
|
95
|
-
coding/proxy/vendors/zhipu.py,sha256=
|
|
96
|
-
coding_proxy-0.5.
|
|
97
|
-
coding_proxy-0.5.
|
|
98
|
-
coding_proxy-0.5.
|
|
99
|
-
coding_proxy-0.5.
|
|
100
|
-
coding_proxy-0.5.
|
|
95
|
+
coding/proxy/vendors/zhipu.py,sha256=GaLaWssa4c1lcukQL4nOtzji8jxEUJFrZtFgOkXTKaM,11127
|
|
96
|
+
coding_proxy-0.5.2a2.dist-info/METADATA,sha256=EVtjI9q0EXp90rCMWE5HRHaC4jlW0Q56Xwnu0R0sJ3w,11346
|
|
97
|
+
coding_proxy-0.5.2a2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
98
|
+
coding_proxy-0.5.2a2.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
|
|
99
|
+
coding_proxy-0.5.2a2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
100
|
+
coding_proxy-0.5.2a2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|