fix(models): stabilize proxy endpoint refresh behavior
* fix: support large proxy model endpoint refresh Large OpenAI-compatible proxy endpoints can expose hundreds of models and make /v1/models slow. Treating those endpoints like local model servers caused model picker opens and background probes to repeatedly hit /models, producing timeouts and making otherwise usable endpoints appear offline. Make model endpoint discovery cached-first for normal UI usage, add explicit proxy/API classification and refresh policy fields, exclude proxy/API endpoints from aggressive local probing, and preserve cached models when refresh fails. Manual Test/Add/Refresh actions still fetch the full model list with longer timeouts so users can intentionally import large proxy model lists without blocking normal model picker usage. * fix: preserve endpoint ping status semantics
This commit is contained in:
@@ -16,6 +16,7 @@ import { sortModelIds } from './modelSort.js';
|
||||
let API_BASE = '';
|
||||
let _cachedItems = []; // cached /api/models items for model-switch dropdown
|
||||
let _lastFetchTime = 0;
|
||||
let _fetchInflight = null;
|
||||
const _FETCH_CACHE_TTL = 30000; // 30s client-side cache for /api/models
|
||||
const COLLAPSE_KEY = 'odysseus-models-collapsed';
|
||||
const FAVORITES_KEY = 'odysseus-model-favorites';
|
||||
@@ -176,8 +177,15 @@ export async function refreshModels(force = false) {
|
||||
box.appendChild(_loadingSpinner.createElement());
|
||||
_loadingSpinner.start();
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/models`);
|
||||
const data = await res.json();
|
||||
if (!_fetchInflight) {
|
||||
_fetchInflight = fetch(`${API_BASE}/api/models`, { credentials: 'same-origin' })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
return res.json();
|
||||
})
|
||||
.finally(() => { _fetchInflight = null; });
|
||||
}
|
||||
const data = await _fetchInflight;
|
||||
_lastFetchTime = Date.now();
|
||||
_cachedItems = data.items || [];
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user