feat: expose weighted routing configuration#325
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for a new weighted-round-robin routing strategy, allowing users to configure and display a selection_weight for provider credentials, API key entries, and quota cards. The changes span configuration editors, hooks, API transformers, and translation files across multiple locales. A critical issue was identified in QuotaCard.tsx, where the newly added styles.scheduleMeta class is accessed but its CSS definition resides in QuotaPage.module.scss instead of the component's scoped stylesheet, which will prevent the styles from being applied at runtime.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| <div className={styles.scheduleMeta}> | ||
| <span> | ||
| {t('auth_files.priority_display')}: {priority} | ||
| </span> | ||
| <span> | ||
| {t('auth_files.selection_weight_display')}: {selectionWeight} | ||
| </span> | ||
| </div> |
There was a problem hiding this comment.
The CSS class scheduleMeta is defined in src/pages/QuotaPage.module.scss, but it is being accessed here via styles.scheduleMeta. Since QuotaCard.tsx is a reusable component located in src/components/quota/, it likely imports its own scoped stylesheet (e.g., QuotaCard.module.scss). Accessing styles.scheduleMeta will result in undefined at runtime, and the styles won't be applied due to CSS Modules scoping.
Please verify where QuotaCard.tsx imports styles from, and move the .scheduleMeta class definition from QuotaPage.module.scss to the appropriate stylesheet imported by QuotaCard.tsx (such as QuotaCard.module.scss).
There was a problem hiding this comment.
Verified this path: QuotaCard.tsx imports styles from @/pages/QuotaPage.module.scss, and .scheduleMeta is declared in that same module. The class is therefore present in the imported CSS module at runtime; no code move is needed for this comment.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1aa6a48a59
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const serializeVertexKey = (config: ProviderKeyConfig) => { | ||
| const payload: Record<string, unknown> = { 'api-key': config.apiKey }; | ||
| if (config.priority !== undefined) payload.priority = config.priority; | ||
| if (config.selectionWeight !== undefined) payload['selection-weight'] = config.selectionWeight; |
There was a problem hiding this comment.
Allow clearing Vertex selection weights
When a Vertex key already has selection-weight and the operator clears the new selection-weight input, buildProviderKeyConfig sets selectionWeight to undefined and this serializer omits the field. However saveVertexConfigs merges that payload back over the raw config using VERTEX_KEY_FIELDS, which still does not include selection-weight, so mergeKnownFields preserves the old raw value; the UI appears cleared until the next refetch/reload brings the stale Vertex weight back. Add selection-weight to VERTEX_KEY_FIELDS so an omitted payload removes it like the other provider types.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 0ef464d: selection-weight is now included in VERTEX_KEY_FIELDS, so clearing the Vertex selection weight removes the preserved raw field during merge just like the other provider types.
1aa6a48 to
0ef464d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0ef464d636
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else if (nextSelectionWeight === undefined) { | ||
| patch.selection_weight = -1; |
There was a problem hiding this comment.
Reject invalid selection weights instead of saving -1
When the auth-file editor's new selection weight field contains any non-empty invalid value (for example abc or 1.5), parseSelectionWeightValue returns undefined and this branch sends selection_weight: -1 in both the preview and PATCH payload. Selection weights are otherwise constrained to non-negative integers (and the hint says empty means default 1), so a typo can attempt to persist an invalid negative routing weight instead of being ignored or blocked like the other validation errors.
Useful? React with 👍 / 👎.
Summary
Exposes weighted routing controls in the management UI so operators can configure and inspect
weighted-round-robinwithout editing YAML or auth JSON by hand.The UI now supports selecting
weighted-round-robinglobally, editing provider-level and OpenAI-compatible per-keyselection-weight, editing auth-fileselection_weight, and seeing priority/weight metadata where quota and credential decisions are reviewed.Backend Compatibility
Requires CLIProxyAPI with weighted routing support from router-for-me/CLIProxyAPI#3935, or a later backend release containing equivalent support, for full functionality. Against older backend builds, the panel can still load, but
weighted-round-robinandselection-weightmay be ignored, rejected, or absent from quota/auth-file responses.Details
weighted-round-robinto visual config editing, dashboard badges, search metadata, and i18n strings.selection-weightparsing and serialization for provider lists and OpenAI-compatible API key entries.Related
Validation
bun run type-checkbun run lintbun run buildgit diff --check