diff --git a/static/ui.js b/static/ui.js index 9a3c80d7c..f6ee9c915 100644 --- a/static/ui.js +++ b/static/ui.js @@ -2570,8 +2570,17 @@ function _modelStateForSelect(sel, modelId){ if(!value) return {model:'',model_provider:null}; const explicitProvider=_providerFromModelValue(value); if(explicitProvider) return {model:value,model_provider:explicitProvider}; - const opt=sel&&sel.selectedOptions&&sel.selectedOptions[0]; - const provider=String(_getOptionProviderId(opt)||'').trim(); + let opt=null; + if(sel&&sel.options){ + opt=Array.from(sel.options).find(o=>o.value===value); + } + if(!opt){ + const currentOpt=sel&&sel.selectedOptions&&sel.selectedOptions[0]; + if(currentOpt&¤tOpt.value===value){ + opt=currentOpt; + } + } + const provider=String((opt&&_getOptionProviderId(opt))||'').trim(); return {model:value,model_provider:(provider&&provider!=='default')?provider:null}; } function _captureModelDropdownSelection(sel){ diff --git a/tests/test_chat_start_provider_fallback.py b/tests/test_chat_start_provider_fallback.py index d3c6b2026..181627bae 100644 --- a/tests/test_chat_start_provider_fallback.py +++ b/tests/test_chat_start_provider_fallback.py @@ -215,6 +215,24 @@ def test_model_state_reads_live_custom_provider_from_option_metadata(driver_path assert state == {"model": "llama-3.3-custom", "model_provider": "custom:lab"} +@node_test +def test_model_state_does_not_use_unrelated_selected_option_provider(driver_path): + # If the requested model is not in the options and differs from the currently + # selected option, it should return model_provider = null instead of the selected option's provider. + state = _run_model_state_helper(driver_path, { + "model": "kilo/minimax/minimax-m3", + "initialValue": "qwen3.6:27b-mlx", + "options": [{ + "provider": "ollama", + "optionProvider": "ollama", + "value": "qwen3.6:27b-mlx", + }], + }) + + assert state == {"model": "kilo/minimax/minimax-m3", "model_provider": None} + + + def test_live_custom_models_are_tagged_with_provider_metadata(): ui_src = UI_JS_PATH.read_text(encoding="utf-8") start = ui_src.index("function _addLiveModelsToSelect")