Agent Zero AI framework
Allow OAuth model slots to switch providers
Alessandro0202323ff5ee
diff --git a/plugins/_oauth/AGENTS.md b/plugins/_oauth/AGENTS.mdindex 246779b90..9aafa56f6 100644--- a/plugins/_oauth/AGENTS.md+++ b/plugins/_oauth/AGENTS.md@@ -25,6 +25,7 @@- Add OAuth model providers in `_oauth/conf/model_providers.yaml`, not `_model_config/provider_metadata.yaml`.- Provider cards and model slot actions must be driven by backend provider status. Do not reintroduce hardcoded frontend provider lists or fallback provider catalogs.- OAuth account surfaces in settings, discovery, and onboarding must use the provider registry/status summary rather than Codex-only frontend state.+- 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`.- `helpers/providers/registry.py` is the source of truth for connectable OAuth providers.- Usage-plan metadata belongs only to connectable providers. Do not add metadata-only subscription families for providers this plugin cannot connect.- API handlers should remain provider-aware. Missing or blank `provider_id` defaults to Codex only for existing backward compatibility; falsey non-string IDs must not silently default.diff --git a/plugins/_oauth/README.md b/plugins/_oauth/README.mdindex c25485d9c..b757274ec 100644--- a/plugins/_oauth/README.md+++ b/plugins/_oauth/README.md@@ -6,6 +6,8 @@ Tokens in `auth.json` are password-equivalent credentials. Keep this plugin on tThe settings UI groups providers as account-backed connections. More than one account provider can be connected at the same time, and the Main/Utility model slots can choose models from any connected OAuth provider.+Each model slot has its own provider selector. The selector lists connected OAuth accounts only, so Main and Utility can use different account-backed providers when more than one account is connected.+## Providers### Codex/ChatGPT (`codex_oauth`)diff --git a/plugins/_oauth/webui/config.html b/plugins/_oauth/webui/config.htmlindex 437de3116..e14270d8a 100644--- a/plugins/_oauth/webui/config.html+++ b/plugins/_oauth/webui/config.html@@ -221,7 +221,7 @@<span class="oauth-model-icon material-symbols-outlined" x-text="slot.icon"></span><div class="oauth-model-title"><strong x-text="slot.title"></strong>- <span x-text="$store.oauthConfig.slotStatusLabel(slot.key)"></span>+ <span x-show="$store.oauthConfig.slotStatusLabel(slot.key)" x-text="$store.oauthConfig.slotStatusLabel(slot.key)"></span></div><div class="oauth-model-actions"><button@@ -240,14 +240,28 @@<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+ :value="$store.oauthConfig.modelSlot(slot.key).provider"+ @change="$store.oauthConfig.useProviderForSlot(slot.key, $event.target.value)"+ :disabled="!$store.oauthConfig.connectedProviderCards().length"+ >+ <option value="" disabled>Choose connected provider</option>+ <template x-for="provider in $store.oauthConfig.slotProviderChoices(slot.key)" :key="`${slot.key}-${provider.provider_id}`">+ <option :value="provider.provider_id" x-text="$store.oauthConfig.modelProviderOptionLabel(provider)"></option>+ </template>+ </select>+ </label>+<div class="oauth-model-input-row"><inputtype="text"x-model="$store.oauthConfig.modelSlot(slot.key).name"@input="$store.oauthConfig.markModelDirty(slot.key)"@focus="$store.oauthConfig.openModelDropdown(slot.key)"- :disabled="!$store.oauthConfig.slotUsesOauth(slot.key)"- placeholder="Search or enter a provider model"+ :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"@@ -255,7 +269,7 @@title="Check models"aria-label="Check models"@click="$store.oauthConfig.loadModels({ providerId: $store.oauthConfig.modelSlot(slot.key).provider, openDropdown: slot.key })"- :disabled="!$store.oauthConfig.slotUsesOauth(slot.key) || !$store.oauthConfig.providerConnected($store.oauthConfig.modelSlot(slot.key).provider) || $store.oauthConfig.loadingModelsProvider === $store.oauthConfig.modelSlot(slot.key).provider"+ :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></button>@@ -285,15 +299,15 @@</template></section>- <section class="oauth-models-panel" x-show="$store.oauthConfig.models.length">+ <section class="oauth-models-panel" x-show="$store.oauthConfig.activeProviderModels().length"><div class="oauth-section-head"><div><h3>Available models</h3>- <p>Available models from selected provider</p>+ <p x-text="$store.oauthConfig.activeModelsDescription()"></p></div></div><div class="oauth-models">- <template x-for="model in $store.oauthConfig.models" :key="model">+ <template x-for="model in $store.oauthConfig.activeProviderModels()" :key="model"><span x-text="model"></span></template></div>@@ -932,7 +946,38 @@.oauth-model-picker {position: relative;+ display: grid;+ gap: 8px;+ min-width: 0;+ }++ .oauth-model-provider-field {+ display: grid;min-width: 0;+ gap: 6px;+ }++ .oauth-model-provider-field span {+ color: var(--color-text-secondary);+ font-size: 0.74rem;+ font-weight: 750;+ }++ .oauth-model-provider-field select {+ 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);+ color: var(--color-text);+ font: inherit;+ font-size: 0.82rem;+ }++ .oauth-model-provider-field select:disabled {+ opacity: .58;}.oauth-model-input-row {diff --git a/plugins/_oauth/webui/oauth-config-store.js b/plugins/_oauth/webui/oauth-config-store.jsindex 1e30ccb6b..5e2b45695 100644--- a/plugins/_oauth/webui/oauth-config-store.js+++ b/plugins/_oauth/webui/oauth-config-store.js@@ -504,19 +504,42 @@ export const store = createStore("oauthConfig", {return found?.label || this.providerLabel(provider);},+ slotProviderChoices() {+ return this.connectedProviderCards();+ },++ modelProviderOptionLabel(provider) {+ return provider?.display_name || provider?.short_name || provider?.provider_id || "Connected account";+ },+slotStatusLabel(key) {const slot = this.modelSlot(key);- if (this.slotUsesOauth(key)) return `Using ${this.providerLabel(slot.provider)}`;+ if (this.slotUsesOauth(key)) return "";return `Currently ${this.providerName(slot.provider)}`;},+ slotCanUseModels(key) {+ const providerId = this.modelSlot(key).provider;+ return this.isOauthProvider(providerId) && this.providerConnected(providerId);+ },++ activeProviderModels() {+ if (!this.providerConnected(this.activeModelProvider)) return [];+ return this.providerModels[this.activeModelProvider] || [];+ },++ activeModelsDescription() {+ if (!this.providerConnected(this.activeModelProvider)) return "";+ return `Available models from ${this.providerLabel(this.activeModelProvider)}`;+ },+markModelDirty(key) {this.modelConfigDirty = true;this.modelSlotDirty = { ...this.modelSlotDirty, [key]: true };},useProviderForSlot(key, providerId) {- if (!this.isOauthProvider(providerId)) return;+ if (!this.providerConnected(providerId)) return;const slot = this.modelSlot(key);const previousProvider = slot.provider;slot.provider = providerId;@@ -526,7 +549,7 @@ export const store = createStore("oauthConfig", {}if (!slot.kwargs || typeof slot.kwargs !== "object") slot.kwargs = {};this.activeModelProvider = providerId;- this.models = this.providerModels[providerId] || [];+ this.models = this.activeProviderModels();this.markModelDirty(key);if (this.models.length) {this.openModelDropdown(key);@@ -544,14 +567,15 @@ export const store = createStore("oauthConfig", {utility.api_base = main.api_base || "";utility.kwargs = clone(main.kwargs || {});this.activeModelProvider = utility.provider || this.activeModelProvider;+ this.models = this.activeProviderModels();this.markModelDirty("utility_model");},openModelDropdown(key) {- if (!this.slotUsesOauth(key)) return;+ if (!this.slotCanUseModels(key)) return;const providerId = this.modelSlot(key).provider;this.activeModelProvider = providerId;- this.models = this.providerModels[providerId] || [];+ this.models = this.activeProviderModels();this.modelDropdown[key] = { ...this.modelDropdown[key], open: true };if (!this.models.length && !this.loadingModelsProvider && this.providerConnected(providerId)) {void this.loadModels({ providerId, openDropdown: key, silent: true });@@ -565,7 +589,7 @@ export const store = createStore("oauthConfig", {filteredModels(key) {const slot = this.modelSlot(key);const query = String(slot.name || "").trim().toLowerCase();- const models = this.providerModels[slot.provider] || this.models || [];+ const models = this.providerModels[slot.provider] || [];const filtered = query? models.filter((model) => String(model).toLowerCase().includes(query)): models;@@ -574,13 +598,11 @@ export const store = createStore("oauthConfig", {selectModel(key, model) {const slot = this.modelSlot(key);- const providerId = this.isOauthProvider(this.activeModelProvider)- ? this.activeModelProvider- : slot.provider;- if (this.isOauthProvider(providerId)) {- slot.provider = providerId;- }+ const providerId = slot.provider;+ if (!this.providerConnected(providerId)) return;slot.name = model;+ this.activeModelProvider = providerId;+ this.models = this.activeProviderModels();this.markModelDirty(key);this.closeModelDropdown(key);},@@ -638,8 +660,11 @@ export const store = createStore("oauthConfig", {ui.quota_project_id = card.quota_project_id;}}- if (!this.isOauthProvider(this.activeModelProvider)) {- this.activeModelProvider = this.providerCards()[0]?.provider_id || CODEX_PROVIDER;+ if (!this.providerConnected(this.activeModelProvider)) {+ this.activeModelProvider = this.connectedProviderCards()[0]?.provider_id+ || this.providerCards()[0]?.provider_id+ || CODEX_PROVIDER;+ this.models = this.activeProviderModels();}if (!this.isOauthProvider(this.selectedProviderId)) {this.selectedProviderId = this.connectedProviderCards()[0]?.provider_iddiff --git a/tests/test_oauth_static.py b/tests/test_oauth_static.pyindex bbdc46a95..0cdc2d394 100644--- a/tests/test_oauth_static.py+++ b/tests/test_oauth_static.py@@ -19,7 +19,11 @@ def test_oauth_settings_exposes_provider_cards_and_model_slots():assert "provider_map" in store_jsassert "<h3>Accounts</h3>" not in config_htmlassert "oauth-plan-catalog" not in config_html- assert "oauth-model-provider-choice" not in config_html+ assert "oauth-model-provider-field" in config_html+ assert "slotProviderChoices(slot.key)" in config_html+ assert "connectedProviderCards().length" in config_html+ assert "useProviderForSlot(slot.key, $event.target.value)" in config_html+ assert "slotCanUseModels(slot.key)" in config_htmlassert "<span>Account</span>" not in config_htmlassert "oauth-connected-panel" not in config_htmlassert "oauth-provider-usage" in config_html@@ -53,7 +57,8 @@ def test_oauth_settings_exposes_provider_specific_controls_and_generic_copy():assert "oauth-auth-attempt" in config_htmlassert "oauth-detail-metrics" not in config_htmlassert "Codex/ChatGPT Account" not in config_html + store_js- assert "Available models from selected provider" in config_html+ assert "activeModelsDescription()" in config_html + store_js+ assert "activeProviderModels()" in config_html + store_jsassert "Available models from Codex account" not in config_htmlassert "disconnectProvider(card.provider_id)" in config_htmlassert "disconnectProvider($store.oauthConfig.selectedProviderId)" not in config_html@@ -78,7 +83,7 @@ def test_oauth_connect_buttons_disable_during_any_provider_connection():def test_oauth_available_models_list_sits_above_advanced_without_borders():config_html = (PROJECT_ROOT / "plugins/_oauth/webui/config.html").read_text(encoding="utf-8")- assert "Available models from selected provider" in config_html+ assert "activeModelsDescription()" in config_htmlassert config_html.index("<h3>Providers</h3>") < config_html.index("Choose your models")assert config_html.index("<h3>Providers</h3>") < config_html.index("<summary>Advanced</summary>")assert config_html.index("Available models") < config_html.index("<summary>Advanced</summary>")@@ -99,6 +104,12 @@ def test_oauth_model_slots_reuse_model_config_api():assert "isOauthProvider" in store_jsassert "providerCards()" in store_jsassert "saveModelConfigIfDirty" in store_js+ assert "slotProviderChoices()" in store_js+ assert "modelProviderOptionLabel(provider)" in store_js+ assert "return this.connectedProviderCards();" in store_js+ assert "if (!this.providerConnected(providerId)) return;" in store_js+ assert "const providerId = slot.provider;" in store_js+ assert "const providerId = this.isOauthProvider(this.activeModelProvider)" not in store_jsdef test_browser_callback_completion_is_observed_from_modal():