Skip to content

Commit 1967ba7

Browse files
committed
Prevent stale provider model selections
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
1 parent 0284ff7 commit 1967ba7

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

openless-all/app/src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export const en: typeof zhCN = {
255255
modelsEmpty: 'Credentials are valid, but no models were returned.',
256256
modelsLoaded: 'Fetched {{count}} models.',
257257
selectModel: 'Select a model to fill the field above',
258+
modelSaved: 'Saved model {{model}}.',
258259
validateSuccess: 'Credentials are valid. {{count}} models available.',
259260
providerHttpStatus: 'Provider returned HTTP {{status}}. Check the API key permissions or endpoint.',
260261
apiKeyMissing: 'API Key is empty.',

openless-all/app/src/i18n/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export const zhCN = {
253253
modelsEmpty: '鉴权成功,但没有返回可用模型。',
254254
modelsLoaded: '已拉取 {{count}} 个模型。',
255255
selectModel: '选择一个模型写入上方字段',
256+
modelSaved: '已保存模型 {{model}}。',
256257
validateSuccess: '鉴权成功,可用模型 {{count}} 个。',
257258
providerHttpStatus: '供应商接口返回 {{status}},请检查 API Key 权限或 Endpoint。',
258259
apiKeyMissing: 'API Key 为空。',

openless-all/app/src/pages/Settings.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ function ProviderTools({ kind, modelAccount, onModelSelected }: { kind: 'llm' |
404404
};
405405

406406
const validate = async () => {
407+
setModels([]);
408+
setSelectedModel('');
407409
setResult('loading', t('settings.providers.validating'));
408410
try {
409411
const result = await validateProviderCredentials(kind);
@@ -436,9 +438,15 @@ function ProviderTools({ kind, modelAccount, onModelSelected }: { kind: 'llm' |
436438
};
437439

438440
const applyModel = async (model: string) => {
439-
setSelectedModel(model);
440-
await setCredential(modelAccount, model);
441-
onModelSelected();
441+
setResult('loading', t('common.saving'));
442+
try {
443+
await setCredential(modelAccount, model);
444+
setSelectedModel(model);
445+
onModelSelected();
446+
setResult('success', t('settings.providers.modelSaved', { model }));
447+
} catch (error) {
448+
setResult('error', providerErrorMessage(error, t));
449+
}
442450
};
443451

444452
return (
@@ -451,6 +459,7 @@ function ProviderTools({ kind, modelAccount, onModelSelected }: { kind: 'llm' |
451459
<select
452460
value={selectedModel}
453461
onChange={e => applyModel(e.target.value)}
462+
disabled={status === 'loading'}
454463
style={{ ...inputStyle, maxWidth: 220 }}
455464
>
456465
<option value="" disabled>{t('settings.providers.selectModel')}</option>

0 commit comments

Comments
 (0)