mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-10 18:22:20 +02:00
* perf(frontend): share one cached fetch for settings and tools /api/auth/settings was fetched independently by eight modules and /api/tools by three on a single load — 4 and 3 requests measured — and any two of those callers could observe a different snapshot of the same object. chatRenderer.js is imported under three different ?v= query strings, so it is three separate module instances each issuing its own /api/tools request. appConfig.js holds one promise per endpoint, so concurrent and later callers share it. Every writer invalidates: the settings panel routes its 16 saves through a single helper, and the admin tools save drops both snapshots because that route persists disabled_tools into the same settings store. A rejected fetch clears its slot rather than being memoised, so one blip at boot cannot leave keybinds, TTS and the search provider on defaults for the session. The settings panel keeps reading directly: it is the writer and edits what it reads, so it must see authoritative state. Cold load, Resource Timing: /api/auth/settings 4 -> 1, /api/tools 3 -> 1, and 0 settings requests on the first load after a login, because the cache now consumes the sessionStorage prefetch that login.html writes. Fixes #5996 * fix(admin): refetch tool state when the Agent Tools panel opens The shared cache made Admin > Tools render the boot snapshot on every reopen. Its save posts the whole disabled list rebuilt from the checkboxes, so a tool disabled out of band (the manage_settings tool, another tab) came back enabled on the next unrelated toggle. Reproduced against the running app: with api_call disabled by a separate client, toggling app_api off posted ['app_api'] and silently re-enabled api_call. The panel now drops the shared entry before reading it, which restores what dev does today and keeps the startup read that chatRenderer.js shares. Cold load is still 1 request each for /api/auth/settings and /api/tools, and the panel costs the same 2 requests per open as dev. * fix(static): preserve concurrent tool setting changes --------- Co-authored-by: Alexandre Teixeira <alexandremagteixeira@gmail.com>
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
// static/js/search.js
|
|
|
|
/**
|
|
* Search settings management — reads active provider from admin settings.
|
|
*/
|
|
|
|
import { getSettings, invalidateSettings } from './appConfig.js';
|
|
|
|
let _provider = 'searxng';
|
|
let _loaded = false;
|
|
|
|
// No API base parameter any more: the settings request lives in appConfig.js and
|
|
// resolves against the document origin, which is exactly what API_BASE held.
|
|
export function init() {
|
|
// Fetch provider on init so it's ready when chat needs it
|
|
_fetchProvider();
|
|
}
|
|
|
|
async function _fetchProvider() {
|
|
try {
|
|
const s = await getSettings();
|
|
_provider = s.search_provider || 'searxng';
|
|
_loaded = true;
|
|
} catch (e) { /* keep default */ }
|
|
}
|
|
|
|
export function getCurrentProvider() {
|
|
return _provider;
|
|
}
|
|
|
|
const _labels = {
|
|
searxng: 'SearXNG', brave: 'Brave', duckduckgo: 'DuckDuckGo',
|
|
google_pse: 'Google', tavily: 'Tavily', serper: 'Serper',
|
|
disabled: 'search (disabled)',
|
|
};
|
|
|
|
export function getProviderLabel() {
|
|
return _labels[_provider] || _provider;
|
|
}
|
|
|
|
/** Re-fetch after admin saves new settings */
|
|
export function refresh() {
|
|
// Drop the shared snapshot first: the point of this call is to observe the
|
|
// settings that were just written, so it must not be served from cache.
|
|
invalidateSettings();
|
|
_fetchProvider();
|
|
}
|
|
|
|
const searchModule = {
|
|
init,
|
|
getCurrentProvider,
|
|
getProviderLabel,
|
|
refresh
|
|
};
|
|
|
|
export default searchModule;
|