Keep provider validation messages locale neutral

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
This commit is contained in:
H-Chris233 committed 2026-05-01 15:29:38 +08:00
1 parent da31f67b3f
commit 2fc4299f06
5 files changed
+13 -11

No files matched your search

+3 -6
View File
@@ -85,9 +85,10 @@ pub fn read_credential(account: String) -> Result<Option<String>, String> {
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProviderCheckResult {
ok: bool,
message: String,
model_count: usize,
}
#[derive(Serialize)]
@@ -102,11 +103,7 @@ pub async fn validate_provider_credentials(kind: String) -> Result<ProviderCheck
.await
.map(|models| ProviderCheckResult {
ok: true,
message: if models.is_empty() {
"鉴权成功,但账号未返回可用模型".to_string()
} else {
format!("鉴权成功,可用模型 {} 个", models.len())
},
model_count: models.len(),
})
}
+1 -1
View File
@@ -255,7 +255,7 @@ export const en: typeof zhCN = {
modelsEmpty: 'Credentials are valid, but no models were returned.',
modelsLoaded: 'Fetched {{count}} models.',
selectModel: 'Select a model to fill the field above',
validateSuccess: 'Credentials are valid.',
validateSuccess: 'Credentials are valid. {{count}} models available.',
providerHttpStatus: 'Provider returned HTTP {{status}}. Check the API key permissions or endpoint.',
apiKeyMissing: 'API Key is empty.',
endpointMissing: 'Endpoint is empty.',
+1 -1
View File
@@ -253,7 +253,7 @@ export const zhCN = {
modelsEmpty: '鉴权成功,但没有返回可用模型。',
modelsLoaded: '已拉取 {{count}} 个模型。',
selectModel: '选择一个模型写入上方字段',
validateSuccess: '鉴权成功。',
validateSuccess: '鉴权成功,可用模型 {{count}} 个。',
providerHttpStatus: '供应商接口返回 {{status}},请检查 API Key 权限或 Endpoint。',
apiKeyMissing: 'API Key 为空。',
endpointMissing: 'Endpoint 为空。',
+2 -2
View File
@@ -65,7 +65,7 @@ const mockCredentialsStatus: CredentialsStatus = {
export interface ProviderCheckResult {
ok: boolean;
message: string;
modelCount: number;
}
export interface ProviderModelsResult {
@@ -141,7 +141,7 @@ export function readCredential(account: string): Promise<string | null> {
}
export function validateProviderCredentials(kind: 'llm' | 'asr'): Promise<ProviderCheckResult> {
return invokeOrMock('validate_provider_credentials', { kind }, () => ({ ok: true, message: 'Mock credentials are valid.' }));
return invokeOrMock('validate_provider_credentials', { kind }, () => ({ ok: true, modelCount: 2 }));
}
export function listProviderModels(kind: 'llm' | 'asr'): Promise<ProviderModelsResult> {
+6 -1
View File
@@ -407,7 +407,12 @@ function ProviderTools({ kind, modelAccount, onModelSelected }: { kind: 'llm' |
setResult('loading', t('settings.providers.validating'));
try {
const result = await validateProviderCredentials(kind);
setResult(result.ok ? 'success' : 'error', result.message || t('settings.providers.validateSuccess'));
setResult(
result.ok ? (result.modelCount === 0 ? 'empty' : 'success') : 'error',
result.modelCount === 0
? t('settings.providers.modelsEmpty')
: t('settings.providers.validateSuccess', { count: result.modelCount }),
);
} catch (error) {
setResult('error', providerErrorMessage(error, t));
}