Skip to content

feat(settings): 增加供应商鉴权与模型拉取#122

Merged
H-Chris233 merged 5 commits into
Open-Less:mainfrom
H-Chris233:main
May 1, 2026
Merged

feat(settings): 增加供应商鉴权与模型拉取#122
H-Chris233 merged 5 commits into
Open-Less:mainfrom
H-Chris233:main

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

摘要

Fixes #114

本 PR 在设置页补充供应商连接检查能力,让用户可以在正式听写前验证 API Key / Endpoint 是否可用,并从 OpenAI-compatible /models 接口拉取当前账号可用模型,减少手动填写模型 ID 的成本。

当前实现提供两个入口:验证凭据和拉取模型。验证成功时给出明确成功状态;失败时展示可理解的错误信息;拉取模型成功后可以从列表中选择模型并写入现有模型字段。即使模型拉取失败,用户仍可以继续手动填写模型 ID,不阻断原有配置方式。

修复 / 新增 / 改进

  • 新增后端 Tauri command:

    • validate_provider_credentials
    • list_provider_models
  • 新增 provider 检查结果类型:

    • ProviderCheckResult
    • ProviderModelsResult
  • 新增 OpenAI-compatible /models 请求逻辑:

    • 根据当前保存的 API Key / Endpoint 发起模型列表请求
    • 支持 base URL 自动拼接 /models
    • 支持从 /chat/completions endpoint 推导 /models
    • 解析返回的 data[].id
    • 对模型 ID 排序并去重
  • 设置页新增连接检查区域:

    • 验证 API Key / Endpoint
    • 拉取可用模型
    • 显示加载中、成功、失败、空列表状态
    • 拉取成功后可选择模型写入上方模型字段
  • 保留手动模型填写能力:

    • 拉取失败时不覆盖用户手动输入
    • 用户仍可直接填写模型 ID
  • 新增前端 IPC 封装:

    • validateProviderCredentials
    • listProviderModels
  • 补充中英文 i18n 文案:

    • 连接检查
    • 验证 / 验证中
    • 拉取模型 / 拉取模型中
    • 模型为空
    • 模型拉取成功
    • 选择模型
    • API Key 为空
    • Endpoint 为空
    • 请求超时
    • provider HTTP 状态错误
  • 错误处理避免泄露敏感信息:

    • 不在用户可见错误中回显 provider 原始响应 body
    • 不打印明文 API Key

兼容

  • 不包含:

    • 不引入 provider-specific SDK。
    • 不改变现有 provider 配置结构。
    • 不移除手动填写模型 ID 的方式。
    • 不改变听写、ASR、LLM 的调用路径。
    • 不改变凭据存储格式。
    • 不在日志或 UI 中暴露明文 API Key。
  • 对现有用户 / 本地环境 / 构建流程的影响:

    • 用户可以在设置页提前验证供应商凭据,减少开始听写后才发现配置不可用的情况。
    • 用户可以自动拉取模型列表,也可以继续手动填写模型 ID。
    • 已有手动配置方式保持可用。
    • 对不使用该功能的用户无行为影响。
    • 构建流程无变化。

测试计划

  • 命令: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.rs
  • openless-all/app/src-tauri/src/lib.rs
  • openless-all/app/src/lib/ipc.ts
  • openless-all/app/src/pages/Settings.tsx
  • openless-all/app/src/i18n/en.ts
  • openless-all/app/src/i18n/zh-CN.ts

备注

本 PR 选择最小实现路径:基于 OpenAI-compatible /models 接口完成鉴权与模型发现,没有扩大到各供应商专用 SDK 集成。模型发现失败时仍保留手动模型 ID 输入,避免影响现有配置方式。

H-Chris233 added 2 commits May 1, 2026 11:14
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
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @H-Chris233, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@H-Chris233
Copy link
Copy Markdown
Collaborator Author

@codex review

@H-Chris233 H-Chris233 self-assigned this May 1, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +105 to +109
message: if models.is_empty() {
"鉴权成功,但账号未返回可用模型".to_string()
} else {
format!("鉴权成功,可用模型 {} 个", models.len())
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +410 to +415
setResult(
result.ok ? (result.modelCount === 0 ? 'empty' : 'success') : 'error',
result.modelCount === 0
? t('settings.providers.modelsEmpty')
: t('settings.providers.validateSuccess', { count: result.modelCount }),
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread openless-all/app/src/pages/Settings.tsx Outdated
Comment on lines +438 to +441
const applyModel = async (model: string) => {
setSelectedModel(model);
await setCredential(modelAccount, model);
onModelSelected();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

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
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@H-Chris233 H-Chris233 merged commit 6ef2374 into Open-Less:main May 1, 2026
2 checks passed
appergb pushed a commit that referenced this pull request May 1, 2026
…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 留着不删,避免影响其他引用)。
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.

增加 API Key 鉴权按钮并自动拉取可用模型

1 participant