mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-11 12:27:13 +00:00
Checkpoint Odysseus local update
This commit is contained in:
+20
-25
@@ -121,7 +121,7 @@ async function _ensureDefaultPendingChat() {
|
||||
if (!_deps || _defaultChatPickInFlight) return;
|
||||
if (_deps.getCurrentSessionId && _deps.getCurrentSessionId()) return;
|
||||
const pending = _deps.getPendingChat && _deps.getPendingChat();
|
||||
if (pending && pending.modelId) return;
|
||||
if (pending && pending.modelId && pending.source === 'manual') return;
|
||||
_defaultChatPickInFlight = true;
|
||||
try {
|
||||
await _ensureModelCacheForFallback();
|
||||
@@ -131,20 +131,26 @@ async function _ensureDefaultPendingChat() {
|
||||
if (res.ok) dc = await res.json();
|
||||
} catch (_) {}
|
||||
if (dc && dc.endpoint_url && dc.model && _modelExists(dc.model, dc.endpoint_url)) {
|
||||
const pendingUrl = String((pending && pending.url) || '').replace(/\/+$/, '');
|
||||
const defaultUrl = String(dc.endpoint_url || '').replace(/\/+$/, '');
|
||||
_deps.setPendingChat({
|
||||
url: dc.endpoint_url,
|
||||
modelId: dc.model,
|
||||
endpointId: dc.endpoint_id || '',
|
||||
source: 'default',
|
||||
});
|
||||
try { window.__odysseusDefaultChat = dc; } catch (_) {}
|
||||
updateModelPicker();
|
||||
if (!pending || pending.modelId !== dc.model || pendingUrl !== defaultUrl || pending.source !== 'default') {
|
||||
updateModelPicker();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (pending && pending.modelId) return;
|
||||
// No configured default, or the configured default is gone/offline:
|
||||
// preserve the convenience fallback and keep the picker usable.
|
||||
const fallback = _firstAvailableModel();
|
||||
if (fallback) {
|
||||
_deps.setPendingChat(fallback);
|
||||
_deps.setPendingChat({ ...fallback, source: 'fallback' });
|
||||
updateModelPicker();
|
||||
}
|
||||
} finally {
|
||||
@@ -564,7 +570,7 @@ function _initModelPickerDropdown() {
|
||||
}
|
||||
if (!currentSessionId && _pendingChat) {
|
||||
// Already have a deferred session — just update the model
|
||||
_deps.setPendingChat({ url: m.url, modelId: m.mid, endpointId: m.endpointId });
|
||||
_deps.setPendingChat({ url: m.url, modelId: m.mid, endpointId: m.endpointId, source: 'manual' });
|
||||
// Header stays as session name — model switch only updates picker
|
||||
updateModelPicker();
|
||||
uiModule.showToast(`Using ${m.display}`);
|
||||
@@ -607,7 +613,7 @@ function _initModelPickerDropdown() {
|
||||
if ((current && current.model) || (pending && pending.modelId)) return;
|
||||
|
||||
if (window.modelsModule && window.modelsModule.refreshModels) {
|
||||
try { await window.modelsModule.refreshModels(true); } catch (_) {}
|
||||
try { await window.modelsModule.refreshModels(false); } catch (_) {}
|
||||
}
|
||||
const items = window.modelsModule && window.modelsModule.getCachedItems ? window.modelsModule.getCachedItems() : [];
|
||||
const targetEndpointId = detail.endpointId ? String(detail.endpointId) : '';
|
||||
@@ -656,12 +662,6 @@ function _initModelPickerDropdown() {
|
||||
updateModelPicker();
|
||||
}).catch(() => {});
|
||||
}
|
||||
// Kick off a local-endpoint probe — when it returns, re-render
|
||||
// the list so stale local servers get dimmed. Cloud entries
|
||||
// aren't probed; they stay visible.
|
||||
_refreshLocalProbe().then(() => {
|
||||
if (!menu.classList.contains('hidden')) _populate(search.value || '');
|
||||
});
|
||||
if (window.innerWidth >= 768) search.focus();
|
||||
// Hide scroll button so it doesn't overlap
|
||||
const _scrollBtn = document.getElementById('scroll-bottom-btn');
|
||||
@@ -755,18 +755,6 @@ export function updateModelPicker() {
|
||||
// we have no session model and no pending-chat pick, fall through to
|
||||
// the "Select model" placeholder below.
|
||||
//
|
||||
// But if the server model cache already has an online endpoint, make the
|
||||
// same safe fallback visible in the picker immediately. The send path can
|
||||
// already resolve a usable model; the UI should not sit on "Select model"
|
||||
// and make it look broken.
|
||||
if (!modelId && !currentSessionId && window.modelsModule && window.modelsModule.getCachedItems) {
|
||||
const fallback = _firstAvailableModel();
|
||||
if (fallback) {
|
||||
_deps.setPendingChat(fallback);
|
||||
modelId = fallback.modelId;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if selected model is still available — fall back ONLY for pending chats with no user selection
|
||||
// Never override an existing session's model — the user explicitly chose it
|
||||
if (modelId && !currentSessionId && _pendingChat && window.modelsModule && window.modelsModule.getCachedItems) {
|
||||
@@ -781,11 +769,18 @@ export function updateModelPicker() {
|
||||
const fallback = items.find(item => !item.offline && (item.models || []).length > 0);
|
||||
if (fallback) {
|
||||
modelId = fallback.models[0];
|
||||
_deps.setPendingChat({ url: fallback.url, modelId, endpointId: fallback.endpoint_id });
|
||||
_deps.setPendingChat({ url: fallback.url, modelId, endpointId: fallback.endpoint_id, source: 'fallback' });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!modelId && !_autoSelectingDefault && window.modelsModule && window.modelsModule.getCachedItems) {
|
||||
const latestPending = _deps.getPendingChat && _deps.getPendingChat();
|
||||
if (
|
||||
!currentSessionId &&
|
||||
!_autoSelectingDefault &&
|
||||
window.modelsModule &&
|
||||
window.modelsModule.getCachedItems &&
|
||||
(!modelId || (latestPending && latestPending.source === 'fallback'))
|
||||
) {
|
||||
_ensureDefaultPendingChat();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user