Agent Zero AI framework
Improve Codex OAuth model setup UI
Alessandrobb48fad754fd
diff --git a/plugins/_discovery/extensions/python/banners/10_discovery_cards.py b/plugins/_discovery/extensions/python/banners/10_discovery_cards.pyindex 3b51f1c44..b9e581899 100644--- a/plugins/_discovery/extensions/python/banners/10_discovery_cards.py+++ b/plugins/_discovery/extensions/python/banners/10_discovery_cards.py@@ -5,13 +5,42 @@ from helpers import pluginsclass DiscoveryCardsExtension(Extension):"""Injects discovery cards into the banners list."""- def _codex_oauth_connected(self) -> bool:+ def _codex_oauth_status(self) -> dict:try:from plugins._oauth.helpers import codex- return bool(codex.status().get("connected"))+ status = codex.status()+ return status if isinstance(status, dict) else {}except Exception:- return False+ return {}++ def _codex_oauth_usage_windows(self, status: dict) -> list[dict]:+ usage = status.get("usage") if isinstance(status, dict) else {}+ if not isinstance(usage, dict) or not usage.get("available"):+ return []++ windows: list[dict] = []+ for key, title in (("primary", "Session"), ("secondary", "Week")):+ window = usage.get(key)+ if not isinstance(window, dict):+ continue+ remaining = window.get("remaining_percent")+ used = window.get("used_percent")+ if remaining is None and used is not None:+ try:+ remaining = max(0, min(100, 100 - float(used)))+ except (TypeError, ValueError):+ remaining = None+ if remaining is None:+ continue+ windows.append({+ "key": key,+ "title": title,+ "label": window.get("label") or "",+ "remaining_percent": remaining,+ "reset_at": window.get("reset_at") or 0,+ })+ return windowsasync def execute(self, banners: list = [], frontend_context: dict = {}, **kwargs):# Optional logic: only show specific cards if plugins aren't already configured.@@ -20,7 +49,8 @@ class DiscoveryCardsExtension(Extension):telegram_config = plugins.get_plugin_config("_telegram_integration") or {}email_config = plugins.get_plugin_config("_email_integration") or {}whatsapp_config = plugins.get_plugin_config("_whatsapp_integration") or {}- codex_oauth_connected = self._codex_oauth_connected()+ codex_oauth_status = self._codex_oauth_status()+ codex_oauth_connected = bool(codex_oauth_status.get("connected"))# 1. Plugin Hub Herobanners.append({@@ -88,7 +118,7 @@ class DiscoveryCardsExtension(Extension):})# 5. Codex/ChatGPT OAuth- banners.append({+ codex_oauth_card = {"id": "discovery-codex-oauth","type": "hero","placement": "after-features",@@ -103,4 +133,9 @@ class DiscoveryCardsExtension(Extension):"dismissible": True,"priority": 40,"show_in_onboarding": True- })+ }+ if codex_oauth_connected:+ usage_windows = self._codex_oauth_usage_windows(codex_oauth_status)+ if usage_windows:+ codex_oauth_card["usage_windows"] = usage_windows+ banners.append(codex_oauth_card)diff --git a/plugins/_discovery/extensions/webui/welcome-actions-end/discovery-cards.html b/plugins/_discovery/extensions/webui/welcome-actions-end/discovery-cards.htmlindex e5a7643c5..72c982bf7 100644--- a/plugins/_discovery/extensions/webui/welcome-actions-end/discovery-cards.html+++ b/plugins/_discovery/extensions/webui/welcome-actions-end/discovery-cards.html@@ -29,6 +29,23 @@<div class="discovery-hero-content"><h3 class="discovery-hero-title" x-text="card.title"></h3><p class="discovery-hero-desc" x-text="card.description"></p>+ <div class="discovery-usage" x-show="(card.usage_windows || []).length">+ <template x-for="window in card.usage_windows" :key="`${card.id}-${window.key}`">+ <div class="discovery-usage-window">+ <div class="discovery-usage-head">+ <span>+ <span x-text="window.title"></span>+ <small x-show="window.label" x-text="window.label"></small>+ </span>+ <strong x-text="$store.discoveryStore.formatRemainingPercent(window)"></strong>+ </div>+ <div class="discovery-usage-bar" aria-hidden="true">+ <i :style="{ width: $store.discoveryStore.usageWidth(window) }"></i>+ </div>+ <p x-show="$store.discoveryStore.formatReset(window)" x-text="`Resets in ${$store.discoveryStore.formatReset(window)}`"></p>+ </div>+ </template>+ </div><button class="btn btn-ok"type="button"@click.stop="$store.discoveryStore.executeCta(card.cta_action)">@@ -108,6 +125,23 @@<div class="discovery-hero-content"><h3 class="discovery-hero-title" x-text="card.title"></h3><p class="discovery-hero-desc" x-text="card.description"></p>+ <div class="discovery-usage" x-show="(card.usage_windows || []).length">+ <template x-for="window in card.usage_windows" :key="`${card.id}-${window.key}`">+ <div class="discovery-usage-window">+ <div class="discovery-usage-head">+ <span>+ <span x-text="window.title"></span>+ <small x-show="window.label" x-text="window.label"></small>+ </span>+ <strong x-text="$store.discoveryStore.formatRemainingPercent(window)"></strong>+ </div>+ <div class="discovery-usage-bar" aria-hidden="true">+ <i :style="{ width: $store.discoveryStore.usageWidth(window) }"></i>+ </div>+ <p x-show="$store.discoveryStore.formatReset(window)" x-text="`Resets in ${$store.discoveryStore.formatReset(window)}`"></p>+ </div>+ </template>+ </div><button class="btn btn-ok"type="button"@click.stop="$store.discoveryStore.executeCta(card.cta_action)">@@ -224,6 +258,74 @@max-width: 38ch;}+ .discovery-usage {+ display: grid;+ grid-template-columns: repeat(2, minmax(0, 1fr));+ gap: 0.6rem;+ max-width: 520px;+ margin: -0.15rem 0 1rem;+ }++ .discovery-usage-window {+ display: grid;+ min-width: 0;+ gap: 0.42rem;+ }++ .discovery-usage-head {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 0.65rem;+ }++ .discovery-usage-head span {+ display: inline-flex;+ min-width: 0;+ align-items: center;+ gap: 0.35rem;+ color: var(--color-secondary);+ font-size: 0.75rem;+ font-weight: 700;+ }++ .discovery-usage-head small {+ padding: 0.12rem 0.34rem;+ border-radius: 999px;+ background: color-mix(in srgb, var(--color-border) 56%, transparent);+ color: var(--color-secondary);+ font-size: 0.68rem;+ line-height: 1;+ }++ .discovery-usage-head strong {+ color: var(--color-text);+ font-size: 0.78rem;+ white-space: nowrap;+ }++ .discovery-usage-bar {+ overflow: hidden;+ height: 0.48rem;+ border-radius: 999px;+ background: color-mix(in srgb, var(--color-border) 54%, transparent);+ }++ .discovery-usage-bar i {+ display: block;+ width: 0;+ height: 100%;+ border-radius: inherit;+ background: #35d07f;+ transition: width 0.22s ease;+ }++ .discovery-usage-window p {+ margin: 0;+ color: var(--color-secondary);+ font-size: 0.7rem;+ }+.discovery-cta-link,.discovery-undismiss-btn {display: inline-flex;@@ -506,6 +608,10 @@font-size: 1rem;}+ .discovery-usage {+ grid-template-columns: 1fr;+ }+.discovery-feature-card {grid-template-columns: minmax(0, 1fr) auto;padding-right: 3rem;diff --git a/plugins/_discovery/webui/discovery-store.js b/plugins/_discovery/webui/discovery-store.jsindex 2fdd1ed03..520ba3ec4 100644--- a/plugins/_discovery/webui/discovery-store.js+++ b/plugins/_discovery/webui/discovery-store.js@@ -98,6 +98,36 @@ const model = {}},+ usageWidth(window) {+ const value = Math.max(0, Math.min(100, this.remainingPercent(window)));+ return `${value}%`;+ },++ remainingPercent(window) {+ const remaining = Number(window?.remaining_percent);+ if (Number.isFinite(remaining)) return remaining;+ const used = Number(window?.used_percent);+ if (Number.isFinite(used)) return 100 - used;+ return Number.NaN;+ },++ formatRemainingPercent(window) {+ const number = this.remainingPercent(window);+ if (!Number.isFinite(number)) return "0%";+ return `${Math.round(number * 10) / 10}% left`;+ },++ formatReset(window) {+ const seconds = Number(window?.reset_at || 0);+ if (!Number.isFinite(seconds) || seconds <= 0) return "";+ const remainingMs = Math.max(0, seconds * 1000 - Date.now());+ const minutes = Math.round(remainingMs / 60000);+ if (minutes < 60) return `${minutes}m`;+ const hours = Math.round(minutes / 60);+ if (hours < 48) return `${hours}h`;+ return `${Math.round(hours / 24)}d`;+ },+// --- Helpers (Private-ish) ---_getDismissedIds() {diff --git a/plugins/_oauth/webui/config.html b/plugins/_oauth/webui/config.htmlindex ff7494980..4bbeb131d 100644--- a/plugins/_oauth/webui/config.html+++ b/plugins/_oauth/webui/config.html@@ -11,7 +11,7 @@<template x-if="$store.oauthConfig && config"><divclass="oauth"- x-init="$store.oauthConfig.init(config)"+ x-init="$store.oauthConfig.init(config, context)"x-effect="$store.oauthConfig.bindConfig(config)"x-destroy="$store.oauthConfig.cleanup()">@@ -44,16 +44,6 @@<span class="material-symbols-outlined" x-text="$store.oauthConfig.connecting ? 'progress_activity' : 'login'"></span><span x-text="$store.oauthConfig.connecting ? 'Waiting' : 'Connect'"></span></button>- <button- class="oauth-connect secondary"- type="button"- @click="$store.oauthConfig.loadModels()"- :disabled="$store.oauthConfig.loadingModels"- x-show="$store.oauthConfig.connected()"- >- <span class="material-symbols-outlined" x-text="$store.oauthConfig.loadingModels ? 'progress_activity' : 'view_list'"></span>- <span>Check Models</span>- </button><buttonclass="oauth-connect danger"type="button"@@ -108,6 +98,117 @@</button></section>+ <section class="oauth-model-config">+ <div class="oauth-section-head">+ <div>+ <h3>Agent Zero models</h3>+ <p>Select the Codex/ChatGPT models used by the Main and Utility model slots.</p>+ </div>+ <span class="oauth-save-chip" x-show="$store.oauthConfig.modelConfigDirty">Pending changes</span>+ </div>++ <div class="oauth-model-loading" x-show="$store.oauthConfig.modelConfigLoading">+ Loading model configuration...+ </div>++ <template x-if="$store.oauthConfig.modelConfig">+ <div class="oauth-model-grid">+ <template x-for="slot in $store.oauthConfig.modelSlots" :key="slot.key">+ <div class="oauth-model-card">+ <div class="oauth-model-head">+ <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-show="!$store.oauthConfig.slotUsesCodex(slot.key)"+ x-text="$store.oauthConfig.slotStatusLabel(slot.key)"+ ></span>+ </div>+ <div class="oauth-model-actions">+ <button+ class="oauth-model-action"+ type="button"+ x-show="!$store.oauthConfig.slotUsesCodex(slot.key)"+ @click="$store.oauthConfig.useCodexForSlot(slot.key)"+ >+ <span class="material-symbols-outlined">swap_horiz</span>+ <span>Use Codex</span>+ </button>+ <button+ class="oauth-model-action icon"+ type="button"+ title="Copy Main model"+ aria-label="Copy Main model"+ x-show="slot.key === 'utility_model' && $store.oauthConfig.slotUsesCodex('chat_model')"+ @click="$store.oauthConfig.copyMainToUtility()"+ >+ <span class="material-symbols-outlined">content_copy</span>+ </button>+ </div>+ </div>++ <p class="oauth-model-description" x-text="slot.description"></p>++ <div class="oauth-model-picker" @click.outside="$store.oauthConfig.closeModelDropdown(slot.key)">+ <div class="oauth-model-input-row">+ <input+ type="text"+ x-model="$store.oauthConfig.modelSlot(slot.key).name"+ @input="$store.oauthConfig.markModelDirty(slot.key)"+ @focus="$store.oauthConfig.openModelDropdown(slot.key)"+ :disabled="!$store.oauthConfig.slotUsesCodex(slot.key)"+ placeholder="Search or enter a Codex model"+ />+ <button+ class="oauth-model-search"+ type="button"+ title="Search available Codex models"+ aria-label="Search available Codex models"+ @click="$store.oauthConfig.loadModels({ openDropdown: slot.key })"+ :disabled="!$store.oauthConfig.slotUsesCodex(slot.key) || !$store.oauthConfig.connected() || $store.oauthConfig.loadingModels"+ >+ <span class="material-symbols-outlined" x-text="$store.oauthConfig.loadingModels ? 'progress_activity' : 'search'"></span>+ </button>+ </div>++ <div+ class="oauth-model-dropdown"+ x-show="$store.oauthConfig.modelDropdown[slot.key]?.open && !$store.oauthConfig.loadingModels"+ x-transition.opacity+ >+ <template x-for="model in $store.oauthConfig.filteredModels(slot.key)" :key="slot.key + model">+ <button+ type="button"+ class="oauth-model-item"+ @click="$store.oauthConfig.selectModel(slot.key, model)"+ x-text="model"+ ></button>+ </template>+ <div class="oauth-model-item muted" x-show="$store.oauthConfig.filteredModels(slot.key).length === 0">+ No models found. You can still type the model name manually.+ </div>+ </div>+ </div>+ </div>+ </template>+ </div>+ </template>+ </section>++ <section class="oauth-models-panel" x-show="$store.oauthConfig.models.length">+ <div class="oauth-section-head">+ <div>+ <h3>Available models</h3>+ <p>Available models from Codex account</p>+ </div>+ </div>+ <div class="oauth-models">+ <template x-for="model in $store.oauthConfig.models" :key="model">+ <span x-text="model"></span>+ </template>+ </div>+ </section>+<details class="oauth-advanced"><summary>Advanced</summary>@@ -157,12 +258,6 @@</label></div></details>-- <div class="oauth-models" x-show="$store.oauthConfig.models.length">- <template x-for="model in $store.oauthConfig.models" :key="model">- <span x-text="model"></span>- </template>- </div></div></template></div>@@ -393,6 +488,219 @@cursor: pointer;}+ .oauth-model-config {+ display: grid;+ gap: 12px;+ padding: 0;+ border: 0;+ }++ .oauth-models-panel {+ display: grid;+ gap: 10px;+ padding: 0;+ border: 0;+ }++ .oauth-section-head {+ display: flex;+ align-items: flex-start;+ justify-content: space-between;+ gap: 12px;+ }++ .oauth-section-head h3 {+ margin: 0 0 4px;+ font-size: 1rem;+ letter-spacing: 0;+ }++ .oauth-section-head p,+ .oauth-model-description,+ .oauth-model-loading {+ margin: 0;+ color: var(--color-text-secondary);+ font-size: 0.8rem;+ line-height: 1.35;+ }++ .oauth-save-chip {+ flex: 0 0 auto;+ padding: 3px 8px;+ border: 1px solid color-mix(in srgb, #d9ad68 46%, var(--color-border));+ border-radius: 999px;+ color: #d9ad68;+ font-size: 0.72rem;+ font-weight: 750;+ }++ .oauth-model-grid {+ display: grid;+ grid-template-columns: repeat(2, minmax(0, 1fr));+ gap: 12px;+ }++ .oauth-model-card {+ display: grid;+ min-width: 0;+ gap: 10px;+ padding: 0;+ border: 0;+ background: transparent;+ }++ .oauth-model-head {+ display: grid;+ grid-template-columns: auto minmax(0, 1fr) auto;+ align-items: center;+ gap: 10px;+ }++ .oauth-model-icon {+ display: grid;+ width: 34px;+ height: 34px;+ place-items: center;+ border-radius: 8px;+ background: color-mix(in srgb, var(--color-border) 52%, transparent);+ color: var(--color-text);+ font-size: 19px;+ }++ .oauth-model-title {+ display: grid;+ min-width: 0;+ gap: 2px;+ }++ .oauth-model-title strong {+ overflow: hidden;+ font-size: 0.88rem;+ text-overflow: ellipsis;+ white-space: nowrap;+ }++ .oauth-model-title span {+ overflow: hidden;+ color: var(--color-text-secondary);+ font-size: 0.74rem;+ font-weight: 700;+ text-overflow: ellipsis;+ white-space: nowrap;+ }++ .oauth-model-actions {+ display: flex;+ align-items: center;+ gap: 6px;+ }++ .oauth-model-action,+ .oauth-model-search {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ 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;+ }++ .oauth-model-action.icon,+ .oauth-model-search {+ width: 34px;+ height: 34px;+ padding: 0;+ }++ .oauth-model-action .material-symbols-outlined,+ .oauth-model-search .material-symbols-outlined {+ font-size: 18px;+ }++ .oauth-model-action:disabled,+ .oauth-model-search:disabled {+ cursor: default;+ opacity: .45;+ }++ .oauth-model-picker {+ position: relative;+ min-width: 0;+ }++ .oauth-model-input-row {+ display: grid;+ grid-template-columns: minmax(0, 1fr) auto;+ gap: 8px;+ }++ .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);+ color: var(--color-text);+ font: inherit;+ font-size: 0.82rem;+ }++ .oauth-model-input-row input:disabled {+ opacity: .58;+ }++ .oauth-model-dropdown {+ position: absolute;+ z-index: 20;+ right: 42px;+ left: 0;+ overflow: auto;+ max-height: 220px;+ margin-top: 6px;+ border: 1px solid var(--color-border);+ border-radius: 8px;+ background: var(--color-panel);+ box-shadow: 0 12px 28px rgba(0, 0, 0, .24);+ }++ .oauth-model-item {+ display: block;+ width: 100%;+ min-height: 34px;+ padding: 8px 10px;+ border: 0;+ background: transparent;+ color: var(--color-text);+ font: inherit;+ font-size: 0.8rem;+ text-align: left;+ cursor: pointer;+ }++ .oauth-model-item:hover,+ .oauth-model-item:focus-visible {+ background: color-mix(in srgb, var(--color-border) 42%, transparent);+ outline: none;+ }++ .oauth-model-item.muted {+ color: var(--color-text-secondary);+ cursor: default;+ }+.oauth-advanced {border: 1px solid var(--color-border);border-radius: 8px;@@ -472,8 +780,8 @@.oauth-models span {padding: 5px 8px;- border: 1px solid color-mix(in srgb, var(--color-border) 70%, transparent);border-radius: 999px;+ background: color-mix(in srgb, var(--color-border) 34%, transparent);color: var(--color-text-secondary);font-size: 0.76rem;}@@ -483,15 +791,25 @@.oauth-device,.oauth-usage,.oauth-status-row,+ .oauth-model-grid,+ .oauth-model-head,.oauth-grid,.oauth-details div {grid-template-columns: 1fr;}+ .oauth-section-head {+ flex-direction: column;+ }+.oauth-primary {width: 100%;}+ .oauth-model-actions {+ justify-content: flex-start;+ }+.oauth-connect {width: 100%;}diff --git a/plugins/_oauth/webui/oauth-config-store.js b/plugins/_oauth/webui/oauth-config-store.jsindex 2e5fb0fc5..6aa2c3a8c 100644--- a/plugins/_oauth/webui/oauth-config-store.js+++ b/plugins/_oauth/webui/oauth-config-store.js@@ -1,17 +1,34 @@import { createStore } from "/js/AlpineStore.js";-import { callJsonApi } from "/js/api.js";+import { callJsonApi, fetchApi } from "/js/api.js";+import { store as modelConfigStore } from "/plugins/_model_config/webui/model-config-store.js";import {toastFrontendError,toastFrontendInfo,toastFrontendSuccess,} from "/components/notifications/notification-store.js";+const MODEL_CONFIG_API = "/plugins/_model_config";const STATUS_API = "/plugins/_oauth/status";const START_DEVICE_LOGIN_API = "/plugins/_oauth/start_device_login";const POLL_DEVICE_LOGIN_API = "/plugins/_oauth/poll_device_login";const MODELS_API = "/plugins/_oauth/models";const DISCONNECT_API = "/plugins/_oauth/disconnect";const MAX_POLL_MS = 120000;+const CODEX_PROVIDER = "codex_oauth";+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",+ },+];function ensureConfig(config) {if (!config || typeof config !== "object") return null;@@ -32,6 +49,30 @@ function ensureConfig(config) {return config;}+function clone(value) {+ return JSON.parse(JSON.stringify(value || {}));+}++function ensureModelSlot(config, key) {+ if (!config[key] || typeof config[key] !== "object") config[key] = {};+ config[key] = {+ provider: "",+ name: "",+ api_base: "",+ ctx_length: key === "utility_model" ? 128000 : 200000,+ ctx_history: key === "chat_model" ? 0.7 : undefined,+ ctx_input: key === "utility_model" ? 0.7 : undefined,+ vision: key === "chat_model" ? true : undefined,+ max_embeds: key === "chat_model" ? 10 : undefined,+ rl_requests: 0,+ rl_input: 0,+ rl_output: 0,+ kwargs: {},+ ...config[key],+ };+ if (!config[key].kwargs || typeof config[key].kwargs !== "object") config[key].kwargs = {};+}+function messageOf(error) {return error instanceof Error ? error.message : String(error);}@@ -44,13 +85,27 @@ export const store = createStore("oauthConfig", {disconnecting: false,loadingModels: false,models: [],+ modelSlots: MODEL_SLOTS,+ modelConfig: null,+ modelConfigLoading: false,+ modelConfigSaving: false,+ modelConfigDirty: false,+ modelSlotDirty: {+ chat_model: false,+ utility_model: false,+ },+ modelDropdown: {+ chat_model: { open: false },+ utility_model: { open: false },+ },device: null,pollTimer: null,pollStartedAt: 0,- async init(config) {+ async init(config, context = null) {this.bindConfig(config);- await this.loadStatus();+ this.installSettingsHooks(context);+ await Promise.all([this.loadStatus(), this.loadModelConfig()]);},cleanup() {@@ -58,6 +113,15 @@ export const store = createStore("oauthConfig", {this.config = null;this.status = null;this.models = [];+ this.modelConfig = null;+ this.modelConfigLoading = false;+ this.modelConfigSaving = false;+ this.modelConfigDirty = false;+ this.modelSlotDirty = { chat_model: false, utility_model: false };+ this.modelDropdown = {+ chat_model: { open: false },+ utility_model: { open: false },+ };this.device = null;},@@ -138,6 +202,168 @@ export const store = createStore("oauthConfig", {return `${window.location.origin}${path}`;},+ installSettingsHooks(context) {+ if (!context || context.__oauthConfigHooksInstalled) return;++ const originalSave = context.save.bind(context);+ context.save = async () => {+ context.error = null;+ try {+ await this.saveModelConfigIfDirty();+ } catch (error) {+ context.error = messageOf(error) || "Failed to save model selection.";+ return;+ }+ await originalSave();+ };++ context.__oauthConfigHooksInstalled = true;+ },++ async loadModelConfig() {+ if (this.modelConfigLoading) return;+ this.modelConfigLoading = true;+ try {+ await modelConfigStore.ensureLoaded();+ const response = await fetchApi(`${MODEL_CONFIG_API}/model_config_get`, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({}),+ });+ const data = await response.json().catch(() => ({}));+ const modelConfig = data.config && typeof data.config === "object" ? data.config : {};+ ensureModelSlot(modelConfig, "chat_model");+ ensureModelSlot(modelConfig, "utility_model");+ this.modelConfig = modelConfig;+ this.modelConfigDirty = false;+ this.modelSlotDirty = { chat_model: false, utility_model: false };+ } catch (error) {+ this.modelConfig = null;+ void toastFrontendError(messageOf(error), "OAuth Connections");+ } finally {+ this.modelConfigLoading = false;+ }+ },++ modelSlot(key) {+ if (!this.modelConfig) return {};+ ensureModelSlot(this.modelConfig, key);+ return this.modelConfig[key];+ },++ slotUsesCodex(key) {+ return this.modelSlot(key).provider === CODEX_PROVIDER;+ },++ providerName(provider) {+ if (!provider) return "Not configured";+ const found = (modelConfigStore.chatProviders || []).find((item) => item.value === provider);+ return found?.label || provider;+ },++ slotStatusLabel(key) {+ const slot = this.modelSlot(key);+ if (slot.provider === CODEX_PROVIDER) return "";+ return `Currently ${this.providerName(slot.provider)}`;+ },++ markModelDirty(key) {+ this.modelConfigDirty = true;+ this.modelSlotDirty = { ...this.modelSlotDirty, [key]: true };+ },++ useCodexForSlot(key) {+ const slot = this.modelSlot(key);+ const previousProvider = slot.provider;+ slot.provider = CODEX_PROVIDER;+ slot.api_base = "";+ if (previousProvider && previousProvider !== CODEX_PROVIDER) {+ slot.name = "";+ }+ if (!slot.kwargs || typeof slot.kwargs !== "object") slot.kwargs = {};+ this.markModelDirty(key);+ if (this.models.length) {+ this.openModelDropdown(key);+ } else {+ void this.loadModels({ openDropdown: key, silent: true });+ }+ },++ copyMainToUtility() {+ if (!this.modelConfig) return;+ const main = this.modelSlot("chat_model");+ const utility = this.modelSlot("utility_model");+ utility.provider = CODEX_PROVIDER;+ utility.name = main.name || "";+ utility.api_base = main.api_base || "";+ utility.kwargs = clone(main.kwargs || {});+ this.markModelDirty("utility_model");+ },++ openModelDropdown(key) {+ if (!this.slotUsesCodex(key)) return;+ this.modelDropdown[key] = { ...this.modelDropdown[key], open: true };+ if (!this.models.length && !this.loadingModels) {+ void this.loadModels({ openDropdown: key, silent: true });+ }+ },++ closeModelDropdown(key) {+ this.modelDropdown[key] = { ...this.modelDropdown[key], open: false };+ },++ filteredModels(key) {+ const query = String(this.modelSlot(key).name || "").trim().toLowerCase();+ const models = this.models || [];+ const filtered = query+ ? models.filter((model) => String(model).toLowerCase().includes(query))+ : models;+ return filtered.slice(0, 80);+ },++ selectModel(key, model) {+ const slot = this.modelSlot(key);+ slot.provider = CODEX_PROVIDER;+ slot.name = model;+ this.markModelDirty(key);+ this.closeModelDropdown(key);+ },++ validateModelConfig() {+ if (!this.modelConfigDirty) return;+ for (const slot of MODEL_SLOTS) {+ if (!this.modelSlotDirty[slot.key]) continue;+ const model = this.modelSlot(slot.key);+ if (model.provider === CODEX_PROVIDER && !String(model.name || "").trim()) {+ throw new Error(`Choose a ${slot.title} before saving.`);+ }+ }+ },++ async saveModelConfigIfDirty() {+ if (!this.modelConfigDirty || !this.modelConfig) return;+ this.validateModelConfig();+ this.modelConfigSaving = true;+ try {+ const response = await fetchApi(`${MODEL_CONFIG_API}/model_config_set`, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ project_name: "",+ agent_profile: "",+ config: this.modelConfig,+ }),+ });+ const data = await response.json().catch(() => ({}));+ if (!data?.ok) throw new Error(data?.error || "Could not save model selection.");+ this.modelConfigDirty = false;+ this.modelSlotDirty = { chat_model: false, utility_model: false };+ await modelConfigStore.refreshModelsSummary?.();+ } finally {+ this.modelConfigSaving = false;+ }+ },+async loadStatus() {if (this.loadingStatus) return;this.loadingStatus = true;@@ -217,17 +443,18 @@ export const store = createStore("oauthConfig", {this.pollTimer = null;},- async loadModels() {+ async loadModels({ openDropdown = "", silent = false } = {}) {if (this.loadingModels) return;this.loadingModels = true;try {const response = await callJsonApi(MODELS_API, {});if (!response?.ok) throw new Error(response?.error || "Could not load Codex models.");this.models = Array.isArray(response.models) ? response.models : [];- void toastFrontendSuccess("Codex models loaded.", "OAuth Connections");+ if (openDropdown) this.openModelDropdown(openDropdown);+ if (!silent) void toastFrontendSuccess("Codex models loaded.", "OAuth Connections");} catch (error) {this.models = [];- void toastFrontendError(messageOf(error), "OAuth Connections");+ if (!silent) void toastFrontendError(messageOf(error), "OAuth Connections");} finally {this.loadingModels = false;}diff --git a/tests/test_oauth_static.py b/tests/test_oauth_static.pynew file mode 100644index 000000000..723112ec1--- /dev/null+++ b/tests/test_oauth_static.py@@ -0,0 +1,74 @@+from pathlib import Path+++PROJECT_ROOT = Path(__file__).resolve().parents[1]+++def test_oauth_settings_exposes_codex_model_slots():+ 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 "Agent Zero models" in config_html+ assert "Main model" in store_js+ assert "Utility model" in store_js+ assert "Use Codex" in config_html+ assert "Search available Codex models" in config_html+ assert "copyMainToUtility" in config_html + store_js+++def test_oauth_settings_remove_redundant_model_action_and_account_label():+ 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 "Codex/ChatGPT Account" not in config_html + store_js+++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 Codex account" in config_html+ assert config_html.index("Available models") < config_html.index("<summary>Advanced</summary>")+ assert ".oauth-models-panel {\n display: grid;\n gap: 10px;\n padding: 0;\n border: 0;\n }" in config_html+ model_chip_rule = config_html.split(".oauth-models span {", 1)[1].split("}", 1)[0]+ assert "border:" not in model_chip_rule+++def test_oauth_model_slots_reuse_model_config_api():+ store_js = (PROJECT_ROOT / "plugins/_oauth/webui/oauth-config-store.js").read_text(encoding="utf-8")++ assert 'import { store as modelConfigStore } from "/plugins/_model_config/webui/model-config-store.js";' in store_js+ assert 'const MODEL_CONFIG_API = "/plugins/_model_config";' in store_js+ assert "model_config_get" in store_js+ assert "model_config_set" in store_js+ assert 'const CODEX_PROVIDER = "codex_oauth";' in store_js+ assert "saveModelConfigIfDirty" in store_js+++def test_oauth_model_wrappers_do_not_add_box_borders_or_lateral_padding():+ config_html = (PROJECT_ROOT / "plugins/_oauth/webui/config.html").read_text(encoding="utf-8")++ assert ".oauth-model-config {\n display: grid;\n gap: 12px;\n padding: 0;\n border: 0;\n }" in config_html+ assert ".oauth-model-card {\n display: grid;" in config_html+ assert " padding: 0;\n border: 0;\n background: transparent;" in config_html+ assert "oauth-model-card.is-codex" not in config_html+ assert "'is-codex'" not in config_html+++def test_connected_codex_welcome_card_renders_usage_limit_bars():+ discovery_cards = (+ PROJECT_ROOT+ / "plugins/_discovery/extensions/python/banners/10_discovery_cards.py"+ ).read_text(encoding="utf-8")+ welcome_cards = (+ PROJECT_ROOT+ / "plugins/_discovery/extensions/webui/welcome-actions-end/discovery-cards.html"+ ).read_text(encoding="utf-8")+ discovery_store = (PROJECT_ROOT / "plugins/_discovery/webui/discovery-store.js").read_text(encoding="utf-8")++ assert "ChatGPT/Codex Connected" in discovery_cards+ assert "5h and weekly limits are ready." not in discovery_cards+ assert "usage_windows" in discovery_cards+ assert "discovery-usage" in welcome_cards+ assert "discovery-usage-bar" in welcome_cards+ assert "formatRemainingPercent(window)" in welcome_cards + discovery_store