Skip to content

feat(api-access): sync drag order into credential priority behind a toggle - #214

Open
jiaxuan1101 wants to merge 1 commit into
router-for-me:mainfrom
jiaxuan1101:feat/drag-order-priority-scheduling
Open

jiaxuan1101 wants to merge 1 commit into
router-for-me:mainfrom
jiaxuan1101:feat/drag-order-priority-scheduling

Conversation

@jiaxuan1101

@jiaxuan1101 jiaxuan1101 commented Sep 6, 2026

Copy link
Copy Markdown

中文

背景

GUI 中拖动接入(Provider)排序目前只改变 config.yaml 里的数组顺序,而 CPA Core 调度时完全不使用这个顺序:选择器按 priority 分桶、只取最高可用档,档内按凭据的内容哈希 ID 排序(见 sdk/cliproxy/auth/selector.go)。因此拖拽排序对实际故障转移顺序没有影响。

改动

本 PR 通过核心已支持的 priority 字段让拖拽顺序生效:

  • 在 API 接入页头部新增可选开关 "按列表顺序调度"(默认关闭)
  • 开启后,拖动接入会将其列表位置写入该分类下各接入的 priority 字段(第一行优先级最高;末行 priority: 0 省略,因为 0 即核心默认值),核心在该分类内严格按从上到下的顺序故障转移
  • 开启开关时立即按当前分类顺序同步一次优先级(同步时忽略搜索过滤,避免误伤未显示的接入)
  • 关闭开关后行为与现状完全一致(拖动仅改写数组顺序),已写入的优先级保持不变
  • 开关持久化到 GUI 配置的 ^Gpi-access-order-scheduling 字段(默认关闭);#[serde(default)] 保证旧配置文件兼容

验证

  • cargo check 与全量 cargo test:343/344 通过;唯一失败的 ^Ggent_command_path_prioritizes_the_executable_and_preserves_discovered_paths 在未修改的上游 main 上同样失败(该测试依赖本机 PATH 组成,与本改动无关)
  • 前端 sc --noEmit 通过
  • 已在 Windows 便携版实测:开启开关后拖动接入,优先级按位置写入并显示在列表行上;关闭后恢复原行为

说明

  • 开启开关后,下次拖动或开启同步会覆盖该分类内手工设置的优先级;开关关闭时编辑对话框的手工 priority 字段照常生效
  • 新增 en、zh-CN 与 ja 文案(项目现有三个语言包)

English

Background

Drag-to-reorder on the API Access page currently only rewrites the array order in config.yaml, which the CPA core scheduler ignores entirely: selection groups credentials into priority buckets and picks from the highest available tier, ordering within a tier by the stable content-hash auth ID (see sdk/cliproxy/auth/selector.go).

Changes

This PR makes the drag order meaningful through the mechanism the core already supports: the per-credential priority field.

  • Adds an opt-in Schedule by list order switch on the API Access page header (off by default)
  • When enabled, dragging a connection writes its list position into the priority field of that category's connections (first row gets the highest value; the last row's priority: 0 is omitted since 0 is the core default). The core then fails over strictly from top to bottom within the category
  • Enabling the switch immediately syncs priorities from the current category order (the search filter is ignored for this sync)
  • When disabled, behavior is unchanged (drag only rewrites the config array order), and already-written priorities are left untouched
  • The toggle persists in the GUI config as ^Gpi-access-order-scheduling (default off); #[serde(default)] keeps older config files compatible

Validation

  • cargo check and the full cargo test suite: 343/344 pass; the single failure (^Ggent_command_path_prioritizes_the_executable_and_preserves_discovered_paths) also fails on unmodified upstream/main on this machine (PATH-composition-dependent, unrelated to this change)
  • Frontend sc --noEmit passes
  • Tested manually on Windows with a portable build: toggling the switch and dragging connections writes priorities per position and displays them on the rows; disabling restores the previous behavior

Notes

  • Once enabled, the next drag or toggle-on sync overwrites manually set priorities of that category; the edit dialog's manual priority field still works when the switch is off
  • Labels added for en, zh-CN, and ja (the three locales the project now ships)

@jiaxuan1101

Copy link
Copy Markdown
Author

顺便借这个 PR 提一个后续优化的想法(与本 PR 互不影响):

当前的模型别名功能是把别名绑定到来源渠道,故障转移仍然只发生在同一 Provider 的多个凭据之间。如果能让每个模型单独配置一个故障转移列表(例如 claude-opus-4-5 → [凭据A, 凭据B, 凭据C]),没有显式配置的模型则默认沿用 Provider 级的故障转移顺序(比如本 PR 的"按列表顺序调度"),调度灵活性会再上一级——不同模型可以拥有各自独立的凭据优先链。


One related idea for a follow-up (independent of this PR): the current model-alias feature binds an alias to a source channel, and failover still happens only among credentials of the same provider. It would be nice if each model could have its own failover list (e.g. claude-opus-4-5 → [credential A, credential B, credential C]), while models without an explicit list keep the provider-level failover order (e.g. the schedule-by-list-order switch from this PR) as the default. That way different models can have their own independent credential chains.

…oggle

- Add an opt-in Schedule-by-list-order switch on the API Access page
- Dragging a connection writes its list position into the priority field (first row highest), so the core fails over strictly from top to bottom within the category
- Enabling the switch syncs priorities from the current category order immediately
- Persist the toggle as api-access-order-scheduling in the GUI config (default off, backward compatible)
- Add en/zh-CN labels and GUI config regression tests
@jiaxuan1101
jiaxuan1101 force-pushed the feat/drag-order-priority-scheduling branch from 7c4ad45 to d316a9f Compare September 7, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant