Agent Zero AI framework
Polish OAuth model selection
Alessandro877d063d3c5f
diff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.mdindex c0101d740..c0efd47cc 100644--- a/plugins/_model_config/AGENTS.md+++ b/plugins/_model_config/AGENTS.md@@ -21,6 +21,7 @@- Applying a model preset may inherit durable tuning such as context windows and rate limits, but must replace or clear per-slot `kwargs` so provider-specific extra params never leak across model providers.- Repair provider-specific model-config aliases at the model-config read/build boundary; keep provider-specific repairs out of provider-agnostic core wrappers such as `models.py`.- `modelConfig.createPresetEditor()` owns local preset drafts, row actions, and stable UI-only row keys so deletion or renaming cannot rebind nested model fields.+- Model-name catalogs open below the input from either a field click or the embedded magnifier.## Work Guidancediff --git a/plugins/_model_config/webui/model-field.html b/plugins/_model_config/webui/model-field.htmlindex 7a9ad3ae7..ac0057985 100644--- a/plugins/_model_config/webui/model-field.html+++ b/plugins/_model_config/webui/model-field.html@@ -41,22 +41,27 @@<div class="field"><div class="field-label"><div class="field-title">Model name</div>- <div class="field-description">Model identifier. Click the search icon to browse available models.</div>+ <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() { this.searching = true; $store.modelConfig.searchModels(_prov, model.name, searchType, _apiBase).then(r => { this.results = r; this.open = true; }).finally(() => this.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); },+ openSearch(trigger) { trigger?.scrollIntoView({ block: 'center' }); this.doSearch(); },grouped() { return $store.modelConfig.groupResults(this.results, model.name); }}"@click.outside="open = false"><input type="text" x-model="model.name" style="padding-right:32px;"+ @click="openSearch($el)"@keydown.enter.prevent="doSearch()" />- <span class="model-search-btn"- @click="if (!searching) doSearch()"- title="Search available models">+ <button class="model-search-btn"+ type="button"+ @click="openSearch($el)"+ :disabled="searching"+ title="Search available models"+ aria-label="Search available models"><span class="material-symbols-outlined" :style="searching && 'opacity:0'">search</span><span class="material-symbols-outlined model-search-spinner" :style="!searching && 'opacity:0'">progress_activity</span>- </span>+ </button><div class="model-search-results" x-show="open && results.length > 0" x-transition.opacity><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>@@ -289,8 +294,12 @@transform: translateY(-50%);width: 20px;height: 20px;+ padding: 0;display: grid;place-items: center;+ border: 0;+ background: transparent;+ color: var(--color-text);cursor: pointer;user-select: none;opacity: 0.6;@@ -299,6 +308,9 @@.model-search-btn:hover {opacity: 1;}+ .model-search-btn:disabled {+ cursor: default;+ }.model-search-btn > span {grid-area: 1 / 1;font-size: 18px;diff --git a/plugins/_oauth/AGENTS.md b/plugins/_oauth/AGENTS.mdindex ebcf18c36..9c6406a20 100644--- a/plugins/_oauth/AGENTS.md+++ b/plugins/_oauth/AGENTS.md@@ -28,7 +28,10 @@- OAuth settings pending-auth controls such as device codes, manual callback input, and provider setup fields must render inline under the relevant provider row, not as a detached section below all providers.- OAuth device-code polling must honor provider `interval`, `expires_at`, and `slow_down` updates; do not poll immediately or keep a stale fixed interval after a provider asks the client to slow down.- OAuth settings model slots must keep provider choice editable per slot, list only connected OAuth account providers, and persist the selected provider IDs into `chat_model.provider` and `utility_model.provider`.-- OAuth settings must dispatch `model-setup-changed` when a provider connection completes, but model selection remains explicit and must not be filled automatically.+- When exactly one OAuth provider is connected, use it as an unsaved default only for empty slots or slots already using that provider. A different saved provider must keep the explicit `Choose connected provider` prompt until the user opts into the switch.+- OAuth provider rows show a status pill only for connected accounts; model catalogs open from the model-slot field or its embedded magnifier, not from provider-row model-check actions.+- OAuth model-slot fields must match `_model_config` input and below-field dropdown geometry while opening the catalog when the field is clicked.+- OAuth settings must dispatch `model-setup-changed` when a provider connection completes; provider defaults may be inferred from one connected account, but model-name selection remains explicit.- `helpers/providers/registry.py` is the source of truth for connectable OAuth providers.- The models API must preserve the legacy plain `models` slug list and may add `model_metadata` entries for richer provider catalogs.- OAuth provider config must not expose the dummy `oauth` API key in `conf/model_providers.yaml`; the dummy key is a runtime-only shim supplied by the `get_api_key` extension after the account provider reports connected.diff --git a/plugins/_oauth/webui/config.html b/plugins/_oauth/webui/config.htmlindex 2e04cd876..124af270a 100644--- a/plugins/_oauth/webui/config.html+++ b/plugins/_oauth/webui/config.html@@ -40,7 +40,7 @@<strong x-text="card.display_name"></strong><span x-text="$store.oauthConfig.providerReadinessLabel(card.provider_id)"></span></div>- <span class="oauth-account-state" :class="{ connected: card.connected }" x-text="card.connected ? 'Connected' : 'Available'"></span>+ <span class="oauth-account-state connected" x-show="card.connected">Connected</span><div class="oauth-row-actions"><buttonclass="oauth-connect compact"@@ -52,15 +52,6 @@<span class="material-symbols-outlined" x-text="$store.oauthConfig.connectingProvider === card.provider_id ? 'progress_activity' : ($store.oauthConfig.providerSetupReady(card.provider_id) ? 'login' : 'tune')"></span><span x-text="$store.oauthConfig.providerPrimaryLabel(card.provider_id)"></span></button>- <button- class="oauth-connect secondary compact"- type="button"- @click.stop="$store.oauthConfig.loadModels({ providerId: card.provider_id })"- :disabled="!card.connected || $store.oauthConfig.loadingModelsProvider === card.provider_id"- >- <span class="material-symbols-outlined" x-text="$store.oauthConfig.loadingModelsProvider === card.provider_id ? 'progress_activity' : 'search'"></span>- <span>Check models</span>- </button><buttonclass="oauth-connect danger compact"type="button"@@ -178,7 +169,6 @@<div class="oauth-section-head"><div><h3>Choose your models</h3>- <p>Select account-backed models used by the Main model and Utility model slots.</p></div><span class="oauth-save-chip" x-show="$store.oauthConfig.modelConfigDirty">Pending changes</span></div>@@ -211,12 +201,10 @@</div></div>- <p class="oauth-model-description" x-text="slot.description"></p>-<div class="oauth-model-picker" @click.outside="$store.oauthConfig.closeModelDropdown(slot.key)"><label class="oauth-model-provider-field">- <span>Provider</span><select+ :aria-label="`${slot.title} provider`":value="$store.oauthConfig.slotCanUseModels(slot.key) ? $store.oauthConfig.modelSlot(slot.key).provider : ''"@change="$store.oauthConfig.useProviderForSlot(slot.key, $event.target.value)":disabled="!$store.oauthConfig.connectedProviderCards().length"@@ -233,16 +221,16 @@type="text"x-model="$store.oauthConfig.modelSlot(slot.key).name"@input="$store.oauthConfig.markModelDirty(slot.key)"- @focus="$store.oauthConfig.openModelDropdown(slot.key)"+ @click="$store.oauthConfig.openModelDropdown(slot.key, $el)":disabled="!$store.oauthConfig.slotCanUseModels(slot.key)":placeholder="$store.oauthConfig.slotCanUseModels(slot.key) ? 'Search or enter a provider model' : 'Choose a connected provider first'"/><buttonclass="oauth-model-search"type="button"- title="Check models"- aria-label="Check models"- @click="$store.oauthConfig.loadModels({ providerId: $store.oauthConfig.modelSlot(slot.key).provider, openDropdown: slot.key })"+ title="Browse available models"+ aria-label="Browse available models"+ @click="$store.oauthConfig.openModelDropdown(slot.key, $el)":disabled="!$store.oauthConfig.slotCanUseModels(slot.key) || $store.oauthConfig.loadingModelsProvider === $store.oauthConfig.modelSlot(slot.key).provider"><span class="material-symbols-outlined" x-text="$store.oauthConfig.loadingModelsProvider === $store.oauthConfig.modelSlot(slot.key).provider ? 'progress_activity' : 'search'"></span>@@ -808,7 +796,6 @@}.oauth-section-head p,- .oauth-model-description,.oauth-model-loading {margin: 0;color: var(--color-text-secondary);@@ -889,41 +876,34 @@gap: 6px;}- .oauth-model-action,- .oauth-model-search {+ .oauth-model-action {display: inline-flex;align-items: center;justify-content: center;+ gap: 5px;+ min-height: 32px;+ padding: 0 9px;border: 1px solid color-mix(in srgb, var(--color-border) 76%, transparent);border-radius: 8px;background: transparent;color: var(--color-text);- cursor: pointer;- }-- .oauth-model-action {- gap: 5px;- min-height: 32px;- padding: 0 9px;font-size: 0.76rem;font-weight: 750;white-space: nowrap;+ cursor: pointer;}- .oauth-model-action.icon,- .oauth-model-search {+ .oauth-model-action.icon {width: 34px;height: 34px;padding: 0;}- .oauth-model-action .material-symbols-outlined,- .oauth-model-search .material-symbols-outlined {+ .oauth-model-action .material-symbols-outlined {font-size: 18px;}- .oauth-model-action:disabled,- .oauth-model-search:disabled {+ .oauth-model-action:disabled {cursor: default;opacity: .45;}@@ -965,40 +945,68 @@}.oauth-model-input-row {- display: grid;- grid-template-columns: minmax(0, 1fr) auto;- gap: 8px;+ position: relative;}.oauth-model-input-row input {width: 100%;min-width: 0;- min-height: 36px;- padding: 7px 10px;- border: 1px solid color-mix(in srgb, var(--color-border) 74%, transparent);- border-radius: 8px;- background: var(--color-input);+ padding: .5rem 32px .5rem .5rem;+ border: 1px solid var(--color-border);+ border-radius: .25rem;+ background: var(--color-background);color: var(--color-text);- font: inherit;- font-size: 0.82rem;+ font-family: "Rubik", Arial, Helvetica, sans-serif;}.oauth-model-input-row input:disabled {opacity: .58;}+ .oauth-model-search {+ position: absolute;+ z-index: 1;+ top: 50%;+ right: 8px;+ display: grid;+ width: 20px;+ height: 20px;+ padding: 0;+ transform: translateY(-50%);+ place-items: center;+ border: 0;+ background: transparent;+ color: var(--color-text);+ cursor: pointer;+ opacity: .6;+ }++ .oauth-model-search:hover {+ opacity: 1;+ }++ .oauth-model-search:disabled {+ cursor: default;+ opacity: .45;+ }++ .oauth-model-search .material-symbols-outlined {+ font-size: 18px;+ }+.oauth-model-dropdown {position: absolute;- z-index: 20;- right: 42px;+ z-index: 50;+ top: calc(100% + 4px);+ right: 0;left: 0;overflow: auto;- max-height: 220px;- margin-top: 6px;+ max-height: 200px;+ padding: 4px;border: 1px solid var(--color-border);- border-radius: 8px;- background: var(--color-panel);- box-shadow: 0 12px 28px rgba(0, 0, 0, .24);+ border-radius: 6px;+ background: var(--color-input);+ box-shadow: 0 4px 12px rgba(0, 0, 0, .3);}.oauth-model-item {@@ -1006,9 +1014,10 @@flex-direction: column;gap: 3px;width: 100%;- min-height: 34px;- padding: 8px 10px;+ min-height: 30px;+ padding: 5px 8px;border: 0;+ border-radius: 4px;background: transparent;color: var(--color-text);font: inherit;diff --git a/plugins/_oauth/webui/oauth-config-store.js b/plugins/_oauth/webui/oauth-config-store.jsindex 004093662..bf8349570 100644--- a/plugins/_oauth/webui/oauth-config-store.js+++ b/plugins/_oauth/webui/oauth-config-store.js@@ -26,13 +26,11 @@ const MODEL_SLOTS = [{key: "chat_model",title: "Main model",- description: "Primary model for chat, reasoning, and browser tasks.",icon: "forum",},{key: "utility_model",title: "Utility model",- description: "Background model for summaries, memory, and prompt preparation.",icon: "manufacturing",},];@@ -120,6 +118,7 @@ export const store = createStore("oauthConfig", {modelConfigLoading: false,modelConfigSaving: false,modelConfigDirty: false,+ modelSlotCurrentProviders: {},modelSlotDirty: {chat_model: false,utility_model: false,@@ -140,6 +139,7 @@ export const store = createStore("oauthConfig", {this.bindConfig(config);this.installSettingsHooks(context);await Promise.all([this.loadStatus(), this.loadModelConfig()]);+ this.applySoleConnectedProviderDefaults();},cleanup() {@@ -163,6 +163,7 @@ export const store = createStore("oauthConfig", {this.modelConfigLoading = false;this.modelConfigSaving = false;this.modelConfigDirty = false;+ this.modelSlotCurrentProviders = {};this.modelSlotDirty = { chat_model: false, utility_model: false };this.modelDropdown = {chat_model: { open: false },@@ -504,6 +505,9 @@ export const store = createStore("oauthConfig", {ensureModelSlot(modelConfig, "chat_model");ensureModelSlot(modelConfig, "utility_model");this.modelConfig = modelConfig;+ this.modelSlotCurrentProviders = Object.fromEntries(+ MODEL_SLOTS.map((slot) => [slot.key, modelConfig[slot.key].provider || ""]),+ );this.modelConfigDirty = false;this.modelSlotDirty = { chat_model: false, utility_model: false };} catch (error) {@@ -542,10 +546,28 @@ export const store = createStore("oauthConfig", {return provider?.display_name || provider?.short_name || provider?.provider_id || "Connected account";},+ applySoleConnectedProviderDefaults() {+ const providers = this.connectedProviderCards();+ if (providers.length !== 1 || !this.modelConfig) return;+ const providerId = providers[0].provider_id;+ for (const slot of MODEL_SLOTS) {+ const model = this.modelSlot(slot.key);+ if (model.provider && model.provider !== providerId) continue;+ if (this.providerConnected(model.provider)) continue;+ model.provider = providerId;+ model.name = "";+ model.api_base = "";+ model.kwargs = {};+ }+ this.activeModelProvider = providerId;+ this.models = this.activeProviderModels();+ },+slotStatusLabel(key) {const slot = this.modelSlot(key);- if (this.slotUsesOauth(key)) return "";- return `Currently ${this.providerName(slot.provider)}`;+ const currentProvider = this.modelSlotCurrentProviders[key] ?? slot.provider;+ if (this.isOauthProvider(currentProvider)) return "";+ return `Currently ${this.providerName(currentProvider)}`;},slotCanUseModels(key) {@@ -609,8 +631,9 @@ export const store = createStore("oauthConfig", {this.markModelDirty("utility_model");},- openModelDropdown(key) {+ openModelDropdown(key, trigger = null) {if (!this.slotCanUseModels(key)) return;+ trigger?.scrollIntoView({ block: "center" });const providerId = this.modelSlot(key).provider;this.activeModelProvider = providerId;this.models = this.activeProviderModels();@@ -721,6 +744,7 @@ export const store = createStore("oauthConfig", {|| this.providerCards()[0]?.provider_id|| "";}+ this.applySoleConnectedProviderDefaults();} catch (error) {void toastFrontendError(messageOf(error), "OAuth Connections");} finally {diff --git a/tests/test_model_config_api_keys.py b/tests/test_model_config_api_keys.pyindex 43af66f56..a130d4944 100644--- a/tests/test_model_config_api_keys.py+++ b/tests/test_model_config_api_keys.py@@ -242,6 +242,15 @@ def test_model_config_provider_switch_resets_custom_api_base():assert '@change="model.api_base = \'\'"' in provider_select+def test_model_config_model_field_opens_search_on_click():+ model_field_path = PROJECT_ROOT / "plugins" / "_model_config" / "webui" / "model-field.html"+ content = model_field_path.read_text(encoding="utf-8")++ assert '@click="openSearch($el)"' in content+ assert '<button class="model-search-btn"' in content+ assert 'aria-label="Search available models"' in content++def test_model_config_primary_context_controls_are_outside_advanced_settings():model_field_path = PROJECT_ROOT / "plugins" / "_model_config" / "webui" / "model-field.html"content = model_field_path.read_text(encoding="utf-8")diff --git a/tests/test_oauth_static.py b/tests/test_oauth_static.pyindex 4dac3b18f..50a01ec91 100644--- a/tests/test_oauth_static.py+++ b/tests/test_oauth_static.py@@ -21,6 +21,8 @@ def test_oauth_settings_exposes_provider_cards_and_model_slots():assert "oauth-plan-catalog" not in config_htmlassert "oauth-model-provider-field" in config_htmlassert "slotProviderChoices(slot.key)" in config_html+ assert "<span>Provider</span>" not in config_html+ assert ':aria-label="`${slot.title} provider`"' in config_htmlassert "connectedProviderCards().length" in config_htmlassert "useProviderForSlot(slot.key, $event.target.value)" in config_htmlassert ":value=\"$store.oauthConfig.slotCanUseModels(slot.key) ? $store.oauthConfig.modelSlot(slot.key).provider : ''\"" in config_html@@ -42,8 +44,14 @@ def test_oauth_settings_exposes_provider_specific_controls_and_generic_copy():config_html = (PROJECT_ROOT / "plugins/_oauth/webui/config.html").read_text(encoding="utf-8")store_js = (PROJECT_ROOT / "plugins/_oauth/webui/oauth-config-store.js").read_text(encoding="utf-8")- assert "Check Models" not in config_html- assert "Check models" in config_html+ assert "Check models" not in config_html+ assert "card.connected ? 'Connected' : 'Available'" not in config_html+ assert '<span class="oauth-account-state connected" x-show="card.connected">Connected</span>' in config_html+ assert "Select account-backed models used by the Main model and Utility model slots." not in config_html+ assert "Primary model for chat, reasoning, and browser tasks." not in config_html + store_js+ assert "Background model for summaries, memory, and prompt preparation." not in config_html + store_js+ assert '@click="$store.oauthConfig.openModelDropdown(slot.key, $el)"' in config_html+ assert "top: calc(100% + 4px);" in config_htmlassert "enterprise_domain" in config_html + store_jsassert "manualCallback" in config_html + store_jsassert "Paste callback URL, query string, or code" in config_html + store_js@@ -117,7 +125,12 @@ def test_oauth_model_slots_reuse_model_config_api():assert "if (!this.providerConnected(providerId)) return;" in store_jsassert "const providerId = slot.provider;" in store_jsassert "const providerId = this.isOauthProvider(this.activeModelProvider)" not in store_js- assert "autoApplyConnectedProviderIfNeeded" not in store_js+ assert "applySoleConnectedProviderDefaults" in store_js+ assert "this.applySoleConnectedProviderDefaults();" in store_js+ assert "if (providers.length !== 1 || !this.modelConfig) return;" in store_js+ assert "if (model.provider && model.provider !== providerId) continue;" in store_js+ assert "model.name = \"\";" in store_js+ assert "this.modelSlotCurrentProviders[key] ?? slot.provider" in store_jsassert "currentChatModelConfigured" not in store_jsassert "providerDefaultModel" not in store_jsassert 'new CustomEvent("model-setup-changed"' in store_js