refactor: Migrate system preferences to field-based endpoint and remove deprecated endpoint (#4958)

* Migrate all existing deprecated system preferences endpoint services to new service by field | delete old endpoint and service

* format

* destructure settings from response

* nitpick

---------

Co-authored-by: shatfield4 <seanhatfield5@gmail.com>
Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
Marcello Fitton 2026-02-09 12:48:48 -08:00 committed by GitHub
parent bb77326659
commit 0da728fc50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 26 additions and 85 deletions

View File

@ -156,20 +156,6 @@ const Admin = {
},
// System Preferences
// TODO: remove this in favor of systemPreferencesByFields
// DEPRECATED: use systemPreferencesByFields instead
systemPreferences: async () => {
return await fetch(`${API_BASE}/admin/system-preferences`, {
method: "GET",
headers: baseHeaders(),
})
.then((res) => res.json())
.catch((e) => {
console.error(e);
return null;
});
},
/**
* Fetches system preferences by fields
* @param {string[]} labels - Array of labels for settings

View File

@ -19,7 +19,9 @@ export default function ExperimentalFeatures() {
useEffect(() => {
async function fetchSettings() {
setLoading(true);
const { settings } = await Admin.systemPreferences();
const { settings } = await Admin.systemPreferencesByFields([
"feature_flags",
]);
setFeatureFlags(settings?.feature_flags ?? {});
setLoading(false);
}
@ -27,7 +29,9 @@ export default function ExperimentalFeatures() {
}, []);
const refresh = async () => {
const { settings } = await Admin.systemPreferences();
const { settings } = await Admin.systemPreferencesByFields([
"feature_flags",
]);
setFeatureFlags(settings?.feature_flags ?? {});
};

View File

@ -72,7 +72,13 @@ export default function EmbeddingTextSplitterPreference() {
useEffect(() => {
async function fetchSettings() {
const _settings = (await Admin.systemPreferences())?.settings;
const _settings = (
await Admin.systemPreferencesByFields([
"text_splitter_chunk_size",
"text_splitter_chunk_overlap",
"max_embed_chunk_size",
])
)?.settings;
setSettings(_settings ?? {});
setLoading(false);
}

View File

@ -12,7 +12,10 @@ export default function CustomSiteSettings() {
});
useEffect(() => {
Admin.systemPreferences().then(({ settings }) => {
Admin.systemPreferencesByFields([
"meta_page_title",
"meta_page_favicon",
]).then(({ settings }) => {
setSettings({
title: settings?.meta_page_title,
faviconUrl: settings?.meta_page_favicon,

View File

@ -9,11 +9,16 @@ import { useTranslation } from "react-i18next";
export default function FooterCustomization() {
const [footerIcons, setFooterIcons] = useState(Array(3).fill(null));
const { t } = useTranslation();
useEffect(() => {
async function fetchFooterIcons() {
const settings = (await Admin.systemPreferences())?.settings;
if (settings && settings.footer_data) {
const parsedIcons = safeJsonParse(settings.footer_data, []);
const { settings } = await Admin.systemPreferencesByFields([
"footer_data",
]);
const footerData = settings?.footer_data;
if (footerData) {
const parsedIcons = safeJsonParse(footerData, []);
setFooterIcons((prevIcons) => {
const updatedIcons = [...prevIcons];
parsedIcons.forEach((icon, index) => {

View File

@ -21,8 +21,7 @@ export default function WorkspaceAgentConfiguration({ workspace }) {
useEffect(() => {
async function fetchSettings() {
const _settings = await System.keys();
const _preferences = await Admin.systemPreferences();
setSettings({ ..._settings, preferences: _preferences.settings } ?? {});
setSettings(_settings ?? {});
setLoading(false);
}
fetchSettings();

View File

@ -415,68 +415,6 @@ function adminEndpoints(app) {
}
);
// TODO: Delete this endpoint
// DEPRECATED - use /admin/system-preferences-for instead with ?labels=... comma separated string of labels
app.get(
"/admin/system-preferences",
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
async (_, response) => {
try {
const embedder = getEmbeddingEngineSelection();
const settings = {
footer_data:
(await SystemSettings.get({ label: "footer_data" }))?.value ||
JSON.stringify([]),
support_email:
(await SystemSettings.get({ label: "support_email" }))?.value ||
null,
text_splitter_chunk_size:
(await SystemSettings.get({ label: "text_splitter_chunk_size" }))
?.value ||
embedder?.embeddingMaxChunkLength ||
null,
text_splitter_chunk_overlap:
(await SystemSettings.get({ label: "text_splitter_chunk_overlap" }))
?.value || null,
max_embed_chunk_size: embedder?.embeddingMaxChunkLength || 1000,
agent_search_provider:
(await SystemSettings.get({ label: "agent_search_provider" }))
?.value || null,
agent_sql_connections: await SystemSettings.agent_sql_connections(),
default_agent_skills:
safeJsonParse(
(await SystemSettings.get({ label: "default_agent_skills" }))
?.value,
[]
) || [],
disabled_agent_skills:
safeJsonParse(
(await SystemSettings.get({ label: "disabled_agent_skills" }))
?.value,
[]
) || [],
imported_agent_skills: ImportedPlugin.listImportedPlugins(),
custom_app_name:
(await SystemSettings.get({ label: "custom_app_name" }))?.value ||
null,
feature_flags: (await SystemSettings.getFeatureFlags()) || {},
meta_page_title: await SystemSettings.getValueOrFallback(
{ label: "meta_page_title" },
null
),
meta_page_favicon: await SystemSettings.getValueOrFallback(
{ label: "meta_page_favicon" },
null
),
};
response.status(200).json({ settings });
} catch (e) {
console.error(e);
response.sendStatus(500).end();
}
}
);
app.post(
"/admin/system-preferences",
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],