coding-proxy 0.5.2a3__py3-none-any.whl → 0.5.2a5__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.
@@ -534,9 +534,9 @@ pricing:
534
534
  # ── 智谱 GLM ──
535
535
  - vendor: zhipu
536
536
  model: glm-5.2 # 待区分长短上下文定价
537
- input_cost_per_mtok: ¥6.00
538
- output_cost_per_mtok: ¥24.00
539
- cache_read_cost_per_mtok: ¥1.30
537
+ input_cost_per_mtok: ¥8.00
538
+ output_cost_per_mtok: ¥28.00
539
+ cache_read_cost_per_mtok: ¥2.00
540
540
  - vendor: zhipu
541
541
  model: glm-5.1 # 待区分长短上下文定价
542
542
  input_cost_per_mtok: ¥6.00
@@ -713,3 +713,4 @@ session_policies:
713
713
  # 写空列表即关闭豁免。加载时会自动 strip + 去空 + 去重。
714
714
  title_exempt_prefixes:
715
715
  - "Write the title in the language"
716
+ - "[Session]"
@@ -12,26 +12,36 @@ from fastapi.responses import HTMLResponse, Response
12
12
  from ..logging.db import TimePeriod
13
13
 
14
14
  # ── 品牌图标:Tabler terminal-2 核心笔划(> 与 _),不含外框 ──────────────
15
- # 外框由「蓝紫渐变圆角方块」容器承载(favicon SVG 的 <rect> 与页面 .logo 的 CSS
16
- # 渐变),保留 Tabler 原始外框笔划会双重描边、边缘发糊,故仅取 > 与 _ 两条。
17
- # 作为单一事实源,同时供 favicon SVG(f-string)与页面 logo({{TERMINAL2}} 模板替换)消费。
15
+ # 容器为「淡色磨砂卡片」(#f5f6fb 浅底 + 品牌紫描边环),> 与 _ 笔划改用品牌渐变
16
+ # (#667eea -> #764ba2)——色彩反转:品牌紫由背景迁移至图标笔划,轮廓成为视觉主角,
17
+ # 更简约、小尺寸下更清晰(Linear/Vercel 风)。保留 Tabler 原始外框笔划会双重描边、
18
+ # 边缘发糊,故仅取 > 与 _ 两条。
19
+ # 单一事实源:_TERMINAL2_PATHS 与 _LOGO_DEFS 同时供 favicon SVG(f-string)与页面
20
+ # logo({{TERMINAL2}} / {{LOGO_DEFS}} 模板替换)消费。
21
+ _BRAND_FROM, _BRAND_TO = "#667eea", "#764ba2"
22
+ _LOGO_DEFS = (
23
+ '<defs><linearGradient id="cpBrand" x1="0" y1="0" x2="1" y2="1">'
24
+ f'<stop offset="0" stop-color="{_BRAND_FROM}"/>'
25
+ f'<stop offset="1" stop-color="{_BRAND_TO}"/>'
26
+ "</linearGradient></defs>"
27
+ )
18
28
  _TERMINAL2_PATHS = '<path d="M8 9l3 3l-3 3" /><path d="M13 15l3 0" />'
19
29
 
20
30
 
21
31
  # ── Favicon (SVG, 现代浏览器主选) ──────────────────────────────────────────
22
32
  def _build_favicon_svg() -> str:
23
- """生成 24×24 SVG favicon:品牌渐变圆角方块 + 白色 terminal-2 笔划.
33
+ """生成 24×24 SVG favicon:淡色磨砂卡片 + 品牌渐变 terminal-2 笔划.
24
34
 
25
- 独立 SVG 文档无 CSS 上下文,``currentColor`` 不可靠,故笔划硬编码 ``#ffffff``。
35
+ 容器为 ``#f5f6fb`` 浅底圆角方块 + 品牌紫描边环;``>`` 与 ``_`` 笔划由白色改为品牌
36
+ 渐变(``url(#cpBrand)``),使图标轮廓成为主角。独立 SVG 文档无 CSS 上下文,
37
+ ``currentColor`` 不可靠,故颜色硬编码;``<defs>`` 复用 ``_LOGO_DEFS`` 单一事实源。
26
38
  """
27
39
  return (
28
40
  '<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" '
41
+ f"{_LOGO_DEFS}"
42
+ '<rect x="1" y="1" width="22" height="22" rx="6" fill="#f5f6fb" '
43
+ 'stroke="#667eea" stroke-opacity=".18" stroke-width="1"/>'
44
+ f'<g fill="none" stroke="url(#cpBrand)" stroke-width="2" '
35
45
  f'stroke-linecap="round" stroke-linejoin="round">{_TERMINAL2_PATHS}</g>'
36
46
  "</svg>"
37
47
  )
@@ -39,11 +49,12 @@ def _build_favicon_svg() -> str:
39
49
 
40
50
  # ── Favicon (ICO, 32×32 光栅回退) ─────────────────────────────────────────
41
51
  def _build_favicon() -> bytes:
42
- """程序化生成 32×32 ICO:品牌渐变圆角方块 + 白色 terminal-2 笔划(旧浏览器/Safari 回退).
52
+ """程序化生成 32×32 ICO:淡色磨砂卡片 + 品牌渐变 terminal-2 笔划(旧浏览器/Safari 回退).
43
53
 
44
- 项目无 Pillow/cairosvg 等图像库,故以纯 Python 按像素光栅化:渐变圆角方块背景
45
- + 白色 ``>`` 折线与 ``_`` 下划线。沿用原实现「全零 AND-mask + per-pixel alpha」
46
- 的圆角透明方案(现代渲染器按 alpha 通道处理透明)。
54
+ 项目无 Pillow/cairosvg 等图像库,故以纯 Python 按像素光栅化:``#f5f6fb`` 浅底圆角
55
+ 方块 + 品牌渐变(#667eea -> #764ba2)``>`` 折线与 ``_`` 下划线。沿用原实现「全零
56
+ AND-mask + per-pixel alpha」的圆角透明方案(现代渲染器按 alpha 通道处理透明)。
57
+ 32px 下细描边环易锯齿,故 ICO 仅保留浅底 + 渐变笔划,精修外观由 SVG 承载。
47
58
  """
48
59
  import math
49
60
  import struct
@@ -52,8 +63,11 @@ def _build_favicon() -> bytes:
52
63
  radius = 8
53
64
  scale = width / 24.0 # SVG 24 单位 -> 像素
54
65
 
55
- r0, g0, b0 = 0x66, 0x7E, 0xEA # #667eea
56
- r1, g1, b1 = 0x76, 0x4B, 0xA2 # #764ba2
66
+ # 图标笔划品牌渐变:#667eea -> #764ba2(与 _LOGO_DEFS 同源)
67
+ r0, g0, b0 = 0x66, 0x7E, 0xEA
68
+ r1, g1, b1 = 0x76, 0x4B, 0xA2
69
+ # 容器底色:#f5f6fb(近白、极浅冷蓝紫)
70
+ tile_r, tile_g, tile_b = 0xF5, 0xF6, 0xFB
57
71
 
58
72
  def inside(x: int, y: int) -> bool:
59
73
  """满铺圆角方块(四角半径 radius)包含判定."""
@@ -68,30 +82,34 @@ def _build_favicon() -> bytes:
68
82
  [[0, 0, 0, 0] for _ in range(width)] for _ in range(height)
69
83
  ]
70
84
 
71
- # 1) 对角渐变圆角背景(左上 #667eea -> 右下 #764ba2)
85
+ # 1) 浅底圆角背景(扁平 #f5f6fb)
72
86
  for y in range(height):
73
87
  for x in range(width):
74
88
  if not inside(x, y):
75
89
  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
- ]
90
+ buf[y][x] = [tile_b, tile_g, tile_r, 255]
91
+
92
+ def brand_at(px: float, py: float) -> tuple[int, int, int]:
93
+ """按对角参数 t 返回 (px,py) 处的品牌渐变 RGB(与 SVG url(#cpBrand) 同向)."""
94
+ t = (px + py) / (width + height - 2)
95
+ return (
96
+ int(r0 + (r1 - r0) * t),
97
+ int(g0 + (g1 - g0) * t),
98
+ int(b0 + (b1 - b0) * t),
99
+ )
83
100
 
84
101
  def stamp(px: float, py: float) -> None:
85
- """以 (px, py) 为中心盖 ~3px 白色方块(笔划加粗,保证小尺寸可辨识)."""
102
+ """以 (px, py) 为中心盖 ~3px 品牌渐变方块(笔划加粗,保证小尺寸可辨识)."""
86
103
  ix, iy = int(round(px)), int(round(py))
104
+ cr, cg, cb = brand_at(px, py)
87
105
  for oy in (-1, 0, 1):
88
106
  for ox in (-1, 0, 1):
89
107
  nx, ny = ix + ox, iy + oy
90
108
  if 0 <= nx < width and 0 <= ny < height:
91
- buf[ny][nx] = [255, 255, 255, 255]
109
+ buf[ny][nx] = [cb, cg, cr, 255]
92
110
 
93
111
  def line(x0: float, y0: float, x1: float, y1: float) -> None:
94
- """稠密采样 + stamp 形成白色粗线段."""
112
+ """稠密采样 + stamp 形成品牌渐变粗线段."""
95
113
  dist = math.hypot(x1 - x0, y1 - y0)
96
114
  steps = max(1, int(dist * 3))
97
115
  for i in range(steps + 1):
@@ -204,10 +222,11 @@ _DASHBOARD_HTML = """<!DOCTYPE html>
204
222
  .header-left { display: flex; align-items: center; gap: 12px; }
205
223
  .logo {
206
224
  width: 32px; height: 32px;
207
- background: var(--gradient-primary);
225
+ background: #f5f6fb;
226
+ border: 1px solid rgba(102,126,234,.18);
208
227
  border-radius: 10px;
209
228
  display: flex; align-items: center; justify-content: center;
210
- box-shadow: 0 4px 12px rgba(102,126,234,.25);
229
+ box-shadow: 0 4px 12px rgba(102,126,234,.18);
211
230
  }
212
231
  .logo svg { width: 20px; height: 20px; display: block; }
213
232
  h1 { font-size: 18px; font-weight: 600; color: var(--text-primary); letter-spacing: -.3px; }
@@ -411,6 +430,17 @@ _DASHBOARD_HTML = """<!DOCTYPE html>
411
430
  height: 100%; border-radius: 2px;
412
431
  transition: width .6s cubic-bezier(.4,0,.2,1);
413
432
  }
433
+ /* ── 供应商状态:拖拽排序(Pointer Events,手柄发起) ── */
434
+ .vendor-item.dragging { opacity: .4; }
435
+ .drag-handle {
436
+ display: flex; align-items: center; flex-shrink: 0;
437
+ color: var(--text-tertiary); font-size: 15px; line-height: 1;
438
+ cursor: grab; user-select: none; touch-action: none; padding: 0 2px;
439
+ opacity: 0; transition: opacity .2s ease;
440
+ }
441
+ .drag-handle:active { cursor: grabbing; }
442
+ .vendor-item:hover .drag-handle { opacity: .55; }
443
+ .drag-handle:hover { opacity: 1 !important; color: var(--text-secondary); }
414
444
  /* ── 故障转移表 ── */
415
445
  .ft-table-wrap { overflow-x: auto; }
416
446
  table { width: 100%; border-collapse: collapse; }
@@ -785,7 +815,7 @@ _DASHBOARD_HTML = """<!DOCTYPE html>
785
815
  <body>
786
816
  <header>
787
817
  <div class="header-left">
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>
818
+ <div class="logo"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="url(#cpBrand)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">{{LOGO_DEFS}}{{TERMINAL2}}</svg></div>
789
819
  <h1>Coding Proxy Dashboard</h1>
790
820
  <span class="badge" id="version-badge">v-.-.-</span>
791
821
  </div>
@@ -1332,12 +1362,15 @@ function renderQuotaBar(qg) {
1332
1362
  }
1333
1363
 
1334
1364
  function updateVendorStatus(status) {
1365
+ // 拖拽进行中 / 重排序 POST 未决时跳过重渲染,避免抢占正在操作的 DOM
1366
+ if (_tierDrag.active || _tierDrag.inFlight) return;
1335
1367
  const tiers = status.tiers || [];
1336
1368
  const list = document.getElementById('vendor-list');
1337
1369
  if (!tiers.length) {
1338
1370
  list.innerHTML = '<div class="empty"><div class="empty-icon">🔌</div>无供应商数据</div>';
1339
1371
  return;
1340
1372
  }
1373
+ const reorderable = tiers.length >= 2;
1341
1374
  list.innerHTML = tiers.map(tier => {
1342
1375
  const cb = tier.circuit_breaker || {};
1343
1376
  const cbClass = cbStateClass(cb.state);
@@ -1351,8 +1384,13 @@ function updateVendorStatus(status) {
1351
1384
  const rlInfo = tier.rate_limit || {};
1352
1385
  const rlHtml = rlInfo.limited ? `<span class="status-badge sb-warn">限速中</span>` : '';
1353
1386
 
1354
- return `<div class="vendor-item">
1387
+ // Pointer Events 重排:仅需 data-vendor 定位;手柄作为拖拽发起点(无原生 draggable)
1388
+ const dragAttrs = ` data-vendor="${tier.name}"`;
1389
+ const handle = reorderable ? `<div class="drag-handle" title="拖拽调整优先级">⠿</div>` : '';
1390
+
1391
+ return `<div class="vendor-item"${dragAttrs}>
1355
1392
  <div class="vendor-info">
1393
+ ${handle}
1356
1394
  <div class="vendor-avatar">${initial}</div>
1357
1395
  <span class="vendor-name">${tier.name}</span>
1358
1396
  </div>
@@ -1365,6 +1403,145 @@ function updateVendorStatus(status) {
1365
1403
  }).join('');
1366
1404
  }
1367
1405
 
1406
+ // ── 供应商状态:拖拽调整优先级(Pointer Events 重排,运行时生效,不重置配额) ────
1407
+ // 采用 Pointer Events 而非原生 HTML5 DnD:后者触屏不支持、跨浏览器易「拿不起来」,
1408
+ // 是业界公认脆弱的重排序方案(故 SortableJS / dnd-kit 等均改用指针事件)。
1409
+ const _tierDrag = {
1410
+ active: false, // 已越过阈值、进入拖拽
1411
+ srcName: null, // 被拖拽 vendor 名
1412
+ srcEl: null, // 被拖拽行
1413
+ pointerId: null, // 捕获的指针 ID
1414
+ startY: 0, // pointerdown 起点 Y
1415
+ origOrder: null, // 拖拽开始时的顺序快照(无变化则跳过 PUT)
1416
+ inFlight: false, // PUT 未决
1417
+ };
1418
+ const _TIER_DRAG_THRESHOLD = 4; // px,越过才判定为拖拽(否则视作点击)
1419
+
1420
+ function _tierCurrentOrder(listEl) {
1421
+ return Array.from(listEl.querySelectorAll('.vendor-item'))
1422
+ .map(function(el) { return el.dataset.vendor; })
1423
+ .filter(Boolean);
1424
+ }
1425
+
1426
+ // 依据指针 Y 与各兄弟行中点比较,即时(乐观)重排 DOM
1427
+ function _tierDragMoveTo(listEl, clientY) {
1428
+ const dragged = _tierDrag.srcEl;
1429
+ if (!dragged) return;
1430
+ const siblings = Array.from(listEl.querySelectorAll('.vendor-item'))
1431
+ .filter(function(el) { return el !== dragged; });
1432
+ for (var i = 0; i < siblings.length; i++) {
1433
+ const rect = siblings[i].getBoundingClientRect();
1434
+ if (clientY < rect.top + rect.height / 2) {
1435
+ if (dragged !== siblings[i] && dragged.nextElementSibling !== siblings[i]) {
1436
+ listEl.insertBefore(dragged, siblings[i]);
1437
+ }
1438
+ return;
1439
+ }
1440
+ }
1441
+ if (listEl.lastElementChild !== dragged) listEl.appendChild(dragged); // 落到末尾
1442
+ }
1443
+
1444
+ function _tierDragReset() {
1445
+ if (_tierDrag.srcEl) {
1446
+ if (_tierDrag.pointerId != null) {
1447
+ try { _tierDrag.srcEl.releasePointerCapture(_tierDrag.pointerId); } catch (_) {}
1448
+ }
1449
+ _tierDrag.srcEl.classList.remove('dragging');
1450
+ }
1451
+ _tierDrag.active = false;
1452
+ _tierDrag.srcName = null;
1453
+ _tierDrag.srcEl = null;
1454
+ _tierDrag.pointerId = null;
1455
+ _tierDrag.startY = 0;
1456
+ _tierDrag.origOrder = null;
1457
+ }
1458
+
1459
+ function initTierDrag() {
1460
+ // 指针事件委托绑定在静态容器 #vendor-list 上一次;子节点重渲染后仍生效
1461
+ const list = document.getElementById('vendor-list');
1462
+ if (!list || list.dataset.dndBound === '1') return;
1463
+ list.dataset.dndBound = '1';
1464
+
1465
+ list.addEventListener('pointerdown', function(e) {
1466
+ if (e.button != null && e.button !== 0) return; // 仅主指针/左键
1467
+ const handle = e.target && e.target.closest && e.target.closest('.drag-handle');
1468
+ if (!handle) return; // 仅从手柄发起,避免误触与文本选择
1469
+ const item = handle.closest('.vendor-item');
1470
+ if (!item || !item.dataset.vendor) return;
1471
+ if (list.querySelectorAll('.vendor-item').length < 2) return;
1472
+ _tierDrag.srcEl = item;
1473
+ _tierDrag.srcName = item.dataset.vendor;
1474
+ _tierDrag.pointerId = e.pointerId;
1475
+ _tierDrag.startY = e.clientY;
1476
+ try { item.setPointerCapture(e.pointerId); } catch (_) {} // 捕获后 DOM 重排不丢事件
1477
+ e.preventDefault(); // 阻止文本选择
1478
+ });
1479
+
1480
+ list.addEventListener('pointermove', function(e) {
1481
+ if (!_tierDrag.srcEl || e.pointerId !== _tierDrag.pointerId) return;
1482
+ if (!_tierDrag.active) {
1483
+ if (Math.abs(e.clientY - _tierDrag.startY) < _TIER_DRAG_THRESHOLD) return;
1484
+ _tierDrag.active = true; // 越阈值 → 正式进入拖拽
1485
+ _tierDrag.origOrder = _tierCurrentOrder(list);
1486
+ _tierDrag.srcEl.classList.add('dragging');
1487
+ }
1488
+ e.preventDefault();
1489
+ _tierDragMoveTo(list, e.clientY);
1490
+ });
1491
+
1492
+ function _tierDragFinish(commit) {
1493
+ if (!_tierDrag.srcEl) return;
1494
+ const wasActive = _tierDrag.active;
1495
+ const order = _tierCurrentOrder(list);
1496
+ const orig = _tierDrag.origOrder;
1497
+ _tierDragReset();
1498
+ if (!wasActive) return; // 仅点击手柄未拖动 → 空操作
1499
+ if (!commit) { _tierRevertToList(); return; } // 取消 → 回滚服务端真实顺序
1500
+ if (orig && order.join(',') === orig.join(',')) return; // 顺序未变 → 跳过 PUT
1501
+ persistTierOrder(order); // 提交新顺序(PUT + 失败回滚)
1502
+ }
1503
+
1504
+ list.addEventListener('pointerup', function(e) {
1505
+ if (!_tierDrag.srcEl || e.pointerId !== _tierDrag.pointerId) return;
1506
+ _tierDragFinish(true);
1507
+ });
1508
+ list.addEventListener('pointercancel', function(e) {
1509
+ if (!_tierDrag.srcEl || e.pointerId !== _tierDrag.pointerId) return;
1510
+ _tierDragFinish(false);
1511
+ });
1512
+ }
1513
+
1514
+ function persistTierOrder(names) {
1515
+ if (_tierDrag.inFlight) return; // 防并发:上一次未决则忽略
1516
+ if (!Array.isArray(names) || names.length < 2) return;
1517
+ _tierDrag.inFlight = true;
1518
+ fetch('/api/tier-order', {
1519
+ method: 'PUT',
1520
+ headers: { 'Content-Type': 'application/json' },
1521
+ body: JSON.stringify({ vendors: names })
1522
+ }).then(function(res) {
1523
+ _tierDrag.inFlight = false; // 先清守卫,允许随后的 refreshOverview 重渲染
1524
+ if (res.ok) {
1525
+ // 服务端已更新顺序;刷新以同步请求趋势图等的排序
1526
+ if (!_tierDrag.active) refreshOverview().catch(function() {});
1527
+ } else {
1528
+ console.error('tier-order rejected:', res.status);
1529
+ _tierRevertToList();
1530
+ }
1531
+ }).catch(function(e) {
1532
+ _tierDrag.inFlight = false;
1533
+ console.error('tier-order failed:', e);
1534
+ _tierRevertToList();
1535
+ });
1536
+ }
1537
+
1538
+ function _tierRevertToList() {
1539
+ // 回滚到服务端真实顺序(PUT 失败 → 服务端顺序未变)
1540
+ fetchJSON('/api/status').then(function(status) {
1541
+ updateVendorStatus(status);
1542
+ }).catch(function() {});
1543
+ }
1544
+
1368
1545
  // ── Model Calling 实时状态 ────────────────────────────────
1369
1546
  function updateModelCalling(status) {
1370
1547
  var wrap = document.getElementById('model-calling-wrap');
@@ -2200,6 +2377,7 @@ function switchTab(name) {
2200
2377
  fetchJSON('/api/dashboard/summary?days=7').then(function(s) {
2201
2378
  if (s && s.version) document.getElementById('version-badge').textContent = 'v' + s.version;
2202
2379
  }).catch(function(){});
2380
+ initTierDrag(); // 绑定供应商列表拖拽(事件委托,幂等)
2203
2381
  refresh(); // 仅加载初始页签的数据
2204
2382
  setInterval(refresh, 600000); // 每 10 分钟刷新当前页签
2205
2383
  if (initial === 'overview') startModelCallingPoll();
@@ -2207,7 +2385,7 @@ function switchTab(name) {
2207
2385
  </script>
2208
2386
  </body>
2209
2387
  </html>
2210
- """.replace("{{TERMINAL2}}", _TERMINAL2_PATHS)
2388
+ """.replace("{{TERMINAL2}}", _TERMINAL2_PATHS).replace("{{LOGO_DEFS}}", _LOGO_DEFS)
2211
2389
 
2212
2390
 
2213
2391
  # ── 数据计算工具 ──────────────────────────────────────────────────────────
@@ -2291,8 +2469,13 @@ def register_dashboard_routes(app: Any) -> None:
2291
2469
 
2292
2470
  @app.get("/dashboard", response_class=HTMLResponse, include_in_schema=False)
2293
2471
  async def dashboard() -> HTMLResponse:
2294
- """返回 Dashboard HTML 页面."""
2295
- return HTMLResponse(content=_DASHBOARD_HTML)
2472
+ """返回 Dashboard HTML 页面.
2473
+
2474
+ 内联 JS/CSS 随版本变化,禁用缓存以免浏览器留存旧内联脚本掩盖前端修复。
2475
+ """
2476
+ return HTMLResponse(
2477
+ content=_DASHBOARD_HTML, headers={"Cache-Control": "no-cache"}
2478
+ )
2296
2479
 
2297
2480
  @app.get("/api/dashboard/summary")
2298
2481
  async def dashboard_summary(request: Request, days: int = 7) -> Response:
@@ -386,6 +386,53 @@ def register_admin_routes(app: Any, router: Any) -> None:
386
386
  )
387
387
 
388
388
 
389
+ def register_tier_order_route(app: Any, router: Any) -> None:
390
+ """注册运行时 N-tier 链路顺序调整路由(纯重排序,不重置熔断器/配额守卫)."""
391
+
392
+ @app.put("/api/tier-order")
393
+ async def update_tier_order(request: Request) -> Response:
394
+ """替换整个 N-tier 链路顺序.
395
+
396
+ JSON body: ``{"vendors": ["v1", "v2", ...]}``(需覆盖所有当前启用的 vendor)。
397
+ 与 ``/api/reset`` 的重排序语义一致,但**不会**重置熔断器/配额守卫/rate limit,
398
+ 以保留当日用量统计(供 Web 拖拽调整优先级使用)。
399
+ """
400
+ try:
401
+ body = await request.json()
402
+ except Exception:
403
+ return json_error_response(
404
+ 400, error_type="invalid_request_error", message="body must be JSON"
405
+ )
406
+ if not isinstance(body, dict):
407
+ return json_error_response(
408
+ 400,
409
+ error_type="invalid_request_error",
410
+ message="body must be a JSON object",
411
+ )
412
+ raw = body.get("vendors")
413
+ if not isinstance(raw, list) or not raw:
414
+ return json_error_response(
415
+ 400,
416
+ error_type="invalid_request_error",
417
+ message="requires non-empty 'vendors' list",
418
+ )
419
+ vendor_names = [str(v) for v in raw]
420
+ try:
421
+ router.reorder_tiers(vendor_names)
422
+ except ValueError as exc:
423
+ return json_error_response(
424
+ 400, error_type="invalid_request_error", message=str(exc)
425
+ )
426
+ return Response(
427
+ content=json.dumps(
428
+ {"ok": True, "tier_order": router.get_vendor_names()},
429
+ ensure_ascii=False,
430
+ ).encode(),
431
+ status_code=200,
432
+ media_type="application/json",
433
+ )
434
+
435
+
389
436
  def register_session_vendor_routes(app: Any, router: Any) -> None:
390
437
  """注册 Session-Vendor 运行时绑定路由."""
391
438
 
@@ -518,6 +565,7 @@ def register_all_routes(
518
565
  register_concurrency_route(app, router)
519
566
  register_copilot_routes(app, router)
520
567
  register_admin_routes(app, router)
568
+ register_tier_order_route(app, router)
521
569
  register_session_vendor_routes(app, router)
522
570
  if reauth_coordinator:
523
571
  register_reauth_routes(app, reauth_coordinator)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: coding-proxy
3
- Version: 0.5.2a3
3
+ Version: 0.5.2a5
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,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=20cIVpZBfUvQeIFltXxQ7TlFSB2voZuYxha4iPX5tzk,23708
20
+ coding/proxy/config/config.default.yaml,sha256=P0QBPMGrGOlTVFncpC-u6oJ92nPWO_He95BF0ZgBW4g,23726
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
@@ -69,10 +69,10 @@ coding/proxy/routing/usage_parser.py,sha256=ZwPuMGtXAwdIOKrXLpdtA4nCmc83ViF6kw5J
69
69
  coding/proxy/routing/usage_recorder.py,sha256=PHUHotCt3VaKkdJizMpPGsUOAj-f5qz9JKeiLEnFNgA,8779
70
70
  coding/proxy/server/__init__.py,sha256=KeH7mEu36v9v27m3VgeSxSeFz9sLTJrxS_EVATJ7Vks,20
71
71
  coding/proxy/server/app.py,sha256=3MYE8-Vsxpt1SVqTKReMKNREBsh_LHKIFq1B4jhfeL8,7121
72
- coding/proxy/server/dashboard.py,sha256=DRfa4T4nbKGqVgryf44dGQewh8Umh8lkiRrEu1Emr_s,96638
72
+ coding/proxy/server/dashboard.py,sha256=Mm6Gh2WtHHdL7HPnDZwKWUHwY7mZBa0w3AG-R-NJsUE,104937
73
73
  coding/proxy/server/factory.py,sha256=L0d0AA0fpkV-gynM85u1l5dXY1OQ5A_p_-PV0XlFGQs,10272
74
74
  coding/proxy/server/responses.py,sha256=i0ugnLRNOdRYGHEWxkwsxR35ChmdMQsSaD8AjRluTn4,2167
75
- coding/proxy/server/routes.py,sha256=B8rsFFLyCnjyamnQhp_sUm9KRMfdXiY3DPrfacD5Nvs,20454
75
+ coding/proxy/server/routes.py,sha256=5f9ONVckM3LG2AftBW6YahelhjkP6XlgaYSH7MvXUp4,22362
76
76
  coding/proxy/streaming/__init__.py,sha256=0al5TC-zJt8Bz0CibTmd8WPza-Cs-qcuZWvT2fKPqHI,23
77
77
  coding/proxy/streaming/anthropic_compat.py,sha256=cycYiJ-glN88OmfLTR7FroHRethONlEcK0PT78KqGbA,21202
78
78
  coding/proxy/vendors/__init__.py,sha256=fehSpQ2-kUlZY6N8cNMGVJYMXspQmi3V4e0FgC4Ay4k,1011
@@ -93,8 +93,8 @@ coding/proxy/vendors/native_anthropic.py,sha256=SxtM71PDci0gqLqiwCrFnT410SnSoD7F
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
95
  coding/proxy/vendors/zhipu.py,sha256=GaLaWssa4c1lcukQL4nOtzji8jxEUJFrZtFgOkXTKaM,11127
96
- coding_proxy-0.5.2a3.dist-info/METADATA,sha256=AQWHMsoXar2_gP8DdsaNVnJNS31RpuK6TNtNxVNdXR4,11346
97
- coding_proxy-0.5.2a3.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
98
- coding_proxy-0.5.2a3.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
99
- coding_proxy-0.5.2a3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
100
- coding_proxy-0.5.2a3.dist-info/RECORD,,
96
+ coding_proxy-0.5.2a5.dist-info/METADATA,sha256=TKQ7eSzT2YftZSCzbcnPv5WV-oLcqkjQwwkZPtMLAd8,11346
97
+ coding_proxy-0.5.2a5.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
98
+ coding_proxy-0.5.2a5.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
99
+ coding_proxy-0.5.2a5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
100
+ coding_proxy-0.5.2a5.dist-info/RECORD,,