feat(settings): 增加供应商鉴权与模型拉取#122
Conversation
Provider setup needed an explicit way to validate OpenAI-compatible credentials and discover account models without forcing manual model IDs. Add minimal IPC commands for /models checks and a small Settings UI control that preserves manual entry when discovery fails. Constraint: Do not leak API keys in logs or user-visible provider error bodies. Rejected: Full provider-specific SDK integrations | OpenAI-compatible /models covers the configured providers with less scope. Confidence: medium Scope-risk: moderate Tested: cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml Tested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml commands::tests -- --nocapture Tested: npm run build Tested: git diff --check
There was a problem hiding this comment.
Sorry @H-Chris233, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da31f67b3f
ℹ️ 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".
| message: if models.is_empty() { | ||
| "鉴权成功,但账号未返回可用模型".to_string() | ||
| } else { | ||
| format!("鉴权成功,可用模型 {} 个", models.len()) | ||
| }, |
There was a problem hiding this comment.
Return locale-neutral validation messages
validate_provider_credentials hardcodes Chinese success text, and ProviderTools displays result.message directly, so users on the English locale see untranslated Chinese after a successful check despite the new i18n keys. This is a user-facing regression for non-Chinese locales; return structured data (e.g., ok + count) or a message key so the frontend can localize consistently.
Useful? React with 👍 / 👎.
The credential validation IPC returned Chinese success text that Settings rendered directly. Return a structured model count instead and let the frontend localize success or empty-list states through existing i18n resources. Constraint: Review comment requires locale-neutral validation output. Rejected: Returning message keys from Rust | model count is simpler and keeps presentation entirely in the frontend. Confidence: high Scope-risk: narrow Tested: cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml Tested: npm run build Tested: git diff --check
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fc4299f06
ℹ️ 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".
| setResult( | ||
| result.ok ? (result.modelCount === 0 ? 'empty' : 'success') : 'error', | ||
| result.modelCount === 0 | ||
| ? t('settings.providers.modelsEmpty') | ||
| : t('settings.providers.validateSuccess', { count: result.modelCount }), | ||
| ); |
There was a problem hiding this comment.
Clear stale model options after credential validation
When validate runs, it updates only status/message and leaves models untouched, so a previously fetched model list stays visible even if the current validation reports "no models" or fails. This creates contradictory UI state (modelsEmpty/error message with selectable old models) and lets users apply outdated models after changing endpoint/key. Reset models (and selection) on validation paths that don't guarantee the current list is valid.
Useful? React with 👍 / 👎.
| const applyModel = async (model: string) => { | ||
| setSelectedModel(model); | ||
| await setCredential(modelAccount, model); | ||
| onModelSelected(); |
There was a problem hiding this comment.
Handle model-save failures before updating selection
applyModel sets selectedModel before awaiting setCredential and doesn't catch errors. If credential persistence fails (e.g., keychain/storage error), the dropdown still shows the new model even though it wasn't saved, and the rejected promise is unhandled. This can mislead users about what model is actually configured; update UI state only after successful save (or revert on failure with an error message).
Useful? React with 👍 / 👎.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Validation could leave a previously fetched model list visible after credentials changed or validation failed, and model selection updated before persistence completed. Clear stale models before validation and only reflect selected models after the credential save succeeds. Constraint: Address review feedback without changing provider discovery scope. Confidence: high Scope-risk: narrow Tested: npm run build Tested: git diff --check
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
…mapping fix(settings): clarify Volcengine ASR credential mapping 火山 ASR credential 字段命名统一:App Key/Access Key/Resource ID → 用 volcengine* 前缀的 i18n key 标明对应 APP ID/Access Token/Resource ID, 加 mappingNote 一行说明 Secret Key 当前不需要、Resource ID 默认值。 Settings.tsx 冲突解决:保留 #124 的多行 JSX + volcengine* key 写法 (main 上 #122 加的 appIdLabel 等老 key 留着不删,避免影响其他引用)。
摘要
Fixes #114。
本 PR 在设置页补充供应商连接检查能力,让用户可以在正式听写前验证 API Key / Endpoint 是否可用,并从 OpenAI-compatible
/models接口拉取当前账号可用模型,减少手动填写模型 ID 的成本。当前实现提供两个入口:验证凭据和拉取模型。验证成功时给出明确成功状态;失败时展示可理解的错误信息;拉取模型成功后可以从列表中选择模型并写入现有模型字段。即使模型拉取失败,用户仍可以继续手动填写模型 ID,不阻断原有配置方式。
修复 / 新增 / 改进
新增后端 Tauri command:
validate_provider_credentialslist_provider_models新增 provider 检查结果类型:
ProviderCheckResultProviderModelsResult新增 OpenAI-compatible
/models请求逻辑:/models/chat/completionsendpoint 推导/modelsdata[].id设置页新增连接检查区域:
保留手动模型填写能力:
新增前端 IPC 封装:
validateProviderCredentialslistProviderModels补充中英文 i18n 文案:
错误处理避免泄露敏感信息:
兼容
不包含:
对现有用户 / 本地环境 / 构建流程的影响:
测试计划
命令:
cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml结果:通过
证据路径:本地检查输出
命令:
cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml commands::tests -- --nocapture结果:通过
证据路径:本地测试输出
命令:
npm run build结果:通过
证据路径:本地构建输出
命令:
git diff --check结果:通过
证据路径:本地命令输出
主要改动文件
openless-all/app/src-tauri/src/commands.rsopenless-all/app/src-tauri/src/lib.rsopenless-all/app/src/lib/ipc.tsopenless-all/app/src/pages/Settings.tsxopenless-all/app/src/i18n/en.tsopenless-all/app/src/i18n/zh-CN.ts备注
本 PR 选择最小实现路径:基于 OpenAI-compatible
/models接口完成鉴权与模型发现,没有扩大到各供应商专用 SDK 集成。模型发现失败时仍保留手动模型 ID 输入,避免影响现有配置方式。