Agent Zero AI framework
Keep OAuth model discovery tied to account availability
Alessandro0487b60ae43d
diff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.mdindex 8ea553924..05fbc623a 100644--- a/plugins/_model_config/AGENTS.md+++ b/plugins/_model_config/AGENTS.md@@ -21,6 +21,7 @@- Keep provider metadata and API-key checks safe around secrets.- Check API-key readiness only for the effective model configuration; unused global presets must not produce Welcome-screen warnings.- Coordinate OAuth-backed providers with `_oauth` instead of hardcoding provider-specific auth here.+- Model discovery never substitutes the generic LiteLLM registry for an OAuth account catalog (`api_key_mode: oauth`). Preserve source/error details; label API-key-provider registry suggestions as unverified and report failed discovery through standard notifications without exposing raw endpoint URLs.- `model_config_get` exposes `model_configured` as a derived chat-model readiness flag from provider, model name, and API-key availability.- Non-default presets may inherit omitted main, utility, or embedding slots and durable tuning from `Default`, but must replace or clear per-slot `kwargs` so provider-specific extra params never leak across model providers.- The optional `vision` slot is strictly per preset and never inherited from `Default`; an empty slot disables the separate Vision Model for that preset.diff --git a/plugins/_model_config/api/model_search.py b/plugins/_model_config/api/model_search.pyindex a83ff68f5..17d6b52e8 100644--- a/plugins/_model_config/api/model_search.py+++ b/plugins/_model_config/api/model_search.py@@ -198,6 +198,8 @@ class ModelSearch(ApiHandler):return headersdef _litellm_fallback(self, provider: str, cfg: dict | None) -> list[str]:+ if (cfg or {}).get("api_key_mode") == "oauth":+ return []try:import litellmdiff --git a/plugins/_model_config/webui/model-field.html b/plugins/_model_config/webui/model-field.htmlindex c54f528fa..a5b3ac92b 100644--- a/plugins/_model_config/webui/model-field.html+++ b/plugins/_model_config/webui/model-field.html@@ -45,8 +45,19 @@<div class="field-description">Model identifier. Click the field or search icon to browse available models.</div></div><div class="field-control" style="position:relative;"- x-data="{ results: [], open: false, searching: false,- doSearch() { if (this.searching) return; this.searching = true; $store.modelConfig.searchModels(_prov, model.name, searchType, _apiBase).then(r => { this.results = r; this.open = true; }).finally(() => this.searching = false); },+ x-data="{ results: [], source: '', open: false, searching: false,+ doSearch() {+ if (this.searching) return;+ this.searching = true;+ const provider = _prov, apiBase = _apiBase;+ $store.modelConfig.searchModelsDetailed(provider, model.name, searchType, apiBase).then(r => {+ if (provider !== _prov || apiBase !== _apiBase) return;+ this.results = r.models;+ this.source = r.source;+ this.open = true;+ if (r.error) globalThis.toastFrontendError?.('Could not load models from the provider. Check its connection and endpoint settings.', 'Model search');+ }).finally(() => this.searching = false);+ },openSearch(trigger) { trigger?.scrollIntoView({ block: 'center' }); this.doSearch(); },grouped() { return $store.modelConfig.groupResults(this.results, model.name); }}"@@ -64,6 +75,7 @@<x-icon class="model-search-spinner" :style="!searching && 'opacity:0'" name="progress_activity"></x-icon></button><div class="model-search-results" x-show="open && results.length > 0" x-transition.opacity>+ <div class="model-search-item disabled" x-show="source === 'litellm_registry'">Catalog suggestions — availability not verified</div><template x-for="m in grouped().matched" :key="'m_'+m"><div class="model-search-item matched" @click="model.name = m; open = false;" x-text="m"></div></template>diff --git a/tests/test_model_search.py b/tests/test_model_search.pyindex 2e97780c5..4bdfb84e4 100644--- a/tests/test_model_search.py+++ b/tests/test_model_search.py@@ -1,3 +1,5 @@+import asyncio+import pytestimport sysimport threadingimport types@@ -96,3 +98,26 @@ def test_model_search_falls_back_to_litellm_registry(monkeypatch):monkeypatch.setitem(sys.modules, "litellm", fake_litellm)assert set(handler._litellm_fallback("openai", {"litellm_provider": "openai"})) == {"gpt-4.1"}++[email protected]("discovered,error", [([], "HTTP 503"), ([], ""), (["account-model"], "")])+def test_oauth_discovery_never_substitutes_generic_registry(monkeypatch, discovered, error):+ handler = _handler()+ config = {"api_key_mode": "oauth", "litellm_provider": "openai"}+ monkeypatch.setattr(handler, "_get_provider_cfg", lambda *_: config)+ monkeypatch.setitem(sys.modules, "litellm", types.SimpleNamespace(+ models_by_provider={"openai": {"unrelated-api-model"}},+ ))++ async def fetch(*args):+ return discovered, "provider_endpoint", error++ monkeypatch.setattr(handler, "_fetch_models", fetch)+ result = asyncio.run(handler.process({"provider": "account-provider"}, None))+ assert result == {+ "models": discovered, "provider": "account-provider",+ "source": "provider_endpoint", "error": error,+ }+ assert handler._litellm_fallback("account-provider", config) == []+ assert handler._litellm_fallback("unknown-provider", {}) == []+ assert handler._litellm_fallback("custom", {"litellm_provider": "openai"}) == ["unrelated-api-model"]