fix(settings): 修复 WebUI 刷新模型列表按钮变灰及误报未填 Key - #463
Merged
Conversation
WebUI 已保存供应商的 apiKey 恒为打码空串(密钥不下发浏览器),旧 canFetchModels 守卫与 handleRefresh 前置校验要求密钥非空,导致按钮 变灰、点击误报「请先填写 Base URL 和 API Key」。 - ProviderModelsRequest 新增 provider_id 与 optional is_full_url; 空 api_key + provider_id 时桌面端从本地库复用已存密钥发起请求, 密钥不回传浏览器,且该分支忽略草稿 URL 只用已存配置(防外泄) - 前端 canReuseStoredApiKey 守卫:仅打码显示且草稿 baseUrl/ modelsUrl/useSystemProxy 与已存配置一致时允许空密钥刷新 - 刷新按钮仅在请求进行中禁用,canFetchModels 删除 - 补齐 WebUI 链路缺失的 isFullUrl 语义:完整端点模式的模型列表 地址推导下沉到 Rust normalize_provider_full_url(与前端 deriveModelsBaseUrlFromFullUrl 镜像),未带时沿用已存 isFullUrl - 提取 parse_http_url 合并 provider_models.rs 三处重复 URL 校验 Closes #462
StackCairn
marked this pull request as draft
August 13, 2026 15:00
Contributor
|
PR governance checks failed — this PR has been converted to draft.
Fix the items above, then click Ready for review to re-run the checks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #462
问题
WebUI 编辑已保存供应商时,「刷新模型列表」按钮变灰无法点击;部分路径下点击报「请先填写 Base URL 和 API Key」,但两者均已填写。
根因
WebUI 的密钥打码契约(
redact_provider_credentials)决定浏览器端已存供应商的apiKey恒为空串、只有apiKeyConfigured: true。而旧的canFetchModels按钮守卫与handleRefresh前置校验都要求密钥非空,在 WebUI 编辑已存供应商的形态下必然失败。方案
协议:
ProviderModelsRequest新增provider_id(6)、optional bool is_full_url(7)。桌面端(gateway_bridge.rs):请求
api_key为空且带provider_id时,resolve_stored_provider_models_config从本地库解出已存密钥/baseUrl/modelsUrl/useSystemProxy 发起请求——密钥全程不回传浏览器;且该分支忽略请求中的草稿 URL,只用已存配置,从根上杜绝"改个地址把已存密钥骗到任意服务器"的外泄面。前端(ProvidersSection.tsx):
canReuseStoredApiKey守卫:仅 WebUI + 密钥打码显示 + 草稿 baseUrl/modelsUrl/useSystemProxy 与已存配置完全一致时,允许空密钥点刷新(与桌面端兜底互为双层防线);用户改了任一字段则仍要求重新输入密钥canFetchModels顺带补齐:WebUI 链路此前一直不传
isFullUrl(完整端点模式),模型列表端点推导会出错。现在完整端点的推导下沉到 Rustnormalize_provider_full_url(与前端deriveModelsBaseUrlFromFullUrl逻辑镜像:优先截到 /v1/,否则去掉末段);请求未带该字段时沿用已存配置的isFullUrl。精简:提取
parse_http_url合并 provider_models.rs 三处逐字重复的 URL scheme/host/凭据校验。测试
cargo check通过go build ./...通过(pb.go 再生成)check:ui-boundaries通过;biome 对触及文件无新增告警安全考量
isFullUrl有意不参与前端一致性比对:它只影响同一 host 上的路径推导,不改变密钥去向(有守卫测试锁定该决策)