feat(webui): expand and organize settings with autosave (#5704)
* feat(webui): expand settings with autosave and live configuration * feat(memory): add long-term memory and idle compaction switches * refactor(webui): clarify settings hierarchy and align compact controls * refactor(webui): keep only memory consolidation in memory settings * refactor(webui): defer runtime changes until explicit restart * refactor(webui): remove default workspace setting * fix(webui): align model lists and remove preset counters * fix(i18n): use natural Chinese labels for chat platforms * fix(i18n): shorten chat settings navigation label * fix(webui): match settings navigation icons to text size * refactor(webui): remove redundant settings sidebar heading * refactor(webui): use icon-only back navigation in settings * fix(webui): remove back arrow hover hint * refactor(webui): remove redundant overview details * refactor(webui): hide secondary descriptions in settings rows * style(webui): replace settings dividers with rounded highlights * refactor(webui): remove redundant model list subtitles and badges * fix(i18n): restore chat translation namespace boundaries * fix(i18n): complete settings translations for all locales * fix(webui): reveal settings only for enabled capabilities * fix(webui): consolidate capabilities and isolate settings feedback * fix(webui): clear restart notices when settings are reverted * fix(webui): anchor restart controls in settings sidebar * fix(webui): shorten sidebar restart label * fix(webui): align settings spacing and control sizes * refactor(webui): unify settings dialogs and interaction feedback * fix(webui): keep settings option groups on one line without scrolling * refactor(webui): align settings spacing and sidebar icon proportions * style(webui): match main sidebar typography to settings * style(webui): use monospace for sidebar session handles * refactor(webui): remove heartbeat configuration from automations * feat(webui): expose configuration actions beside capability toggles * style(webui): remove ellipsis from configuration actions * refactor(webui): remove redundant app configuration controls * feat(webui): add compact sidebar navigation and shortcut hints * fix(webui): synchronize npm dependency lockfile * test(webui): align input radius expectation with pill styling * feat(webui): show daily token usage and cache breakdown * feat(webui): add model usage details and cache hit rates * feat(webui): chart daily token usage by model * refactor(webui): simplify usage details and model labels * fix(webui): hide usage dialog date range * refactor(webui): consolidate model usage into chart legends * fix(webui): enforce restart choices and correct settings test route * fix(webui): polish settings localization and controls * fix(webui): avoid repeated usage legend labels * fix(webui): skip empty usage columns in keyboard navigation * test(webui): assert settings behavior positively * feat(webui): refine sidebar navigation and add drag resizing * style(webui): soften sidebar scroll edges * style(webui): harmonize sidebar typography and text colors * feat(webui): move channels to the main sidebar * style(webui): remove dotted underlines from settings hints * fix(webui): unify tooltip hover delay * fix(webui): support Seatbelt sandbox settings * fix(webui): remove unused appearance density preference * fix(webui): align settings input values consistently * style(webui): group compact settings controls before inputs * feat(webui): edit multiline settings in compact dialogs * feat(webui): add continuous settings scrolling with gentle snapping * Revert "feat(webui): add continuous settings scrolling with gentle snapping" This reverts commit f0978c261a53c844185eeab4d0c3190fbd196fe6.
This commit is contained in:
1 parent
20f115bf46
commit
8ea683679d
244 files changed
+6929
-3900
No files matched your search
@@ -0,0 +1,238 @@
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
import { SettingsGroup, SettingsRow, SettingsSectionTitle, RestartRequiredNotice, RestartSettingsFooter } from "@/components/settings/shared/SettingsControls";
|
||||
import { ProviderPicker } from "@/components/settings/shared/ModelControls";
|
||||
import { TimezonePicker } from "@/components/settings/shared/TimezonePicker";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { RUNTIME_CONFIG_FIELDS, RUNTIME_CONFIG_GROUPS, type RuntimeConfigField, type RuntimeConfigPage } from "@/components/settings/system/runtime-config-fields";
|
||||
import { updateRuntimeConfigSettings } from "@/lib/api";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type { RuntimeConfigValue, SettingsPayload } from "@/lib/types";
|
||||
import type { ApplySettingsPayload } from "@/components/settings/contracts";
|
||||
|
||||
type Draft = string | boolean;
|
||||
|
||||
function displayValue(value: RuntimeConfigValue | undefined): Draft {
|
||||
if (typeof value === "boolean") return value;
|
||||
if (Array.isArray(value)) return value.join("\n");
|
||||
return value == null ? "" : String(value);
|
||||
}
|
||||
|
||||
export function useRuntimeConfigSettings(
|
||||
settings: SettingsPayload | null,
|
||||
client: NanobotClient,
|
||||
applyPayload: ApplySettingsPayload,
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
const [drafts, setDrafts] = useState<Record<string, Draft>>({});
|
||||
const [saving, setSaving] = useState<string | null>(null);
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [invalidField, setInvalidField] = useState<string | null>(null);
|
||||
const delay = useRef(600);
|
||||
const saveLatest = useRef<(group: string) => Promise<void>>(async () => {});
|
||||
const pendingGroups = useRef<string[]>([]);
|
||||
const queuedSaves = useRef<string[]>([]);
|
||||
const [saved, setSaved] = useState<Record<string, boolean>>({});
|
||||
useEffect(() => {
|
||||
if (invalidField && saving === null) document.getElementById(`runtime-${invalidField}`)?.focus();
|
||||
}, [invalidField, saving]);
|
||||
const value = (path: string): Draft => drafts[path] ?? displayValue(settings?.runtime_config?.[path]);
|
||||
const visible = (field: RuntimeConfigField) => !field.when || (Array.isArray(field.when.value)
|
||||
? field.when.value.includes(String(value(field.when.path)))
|
||||
: value(field.when.path) === field.when.value);
|
||||
const dirty = (field: RuntimeConfigField) =>
|
||||
drafts[field.path] !== undefined && drafts[field.path] !== displayValue(settings?.runtime_config?.[field.path]);
|
||||
const discard = (group: string) => {
|
||||
setDrafts((prev) => Object.fromEntries(Object.entries(prev).filter(([path]) =>
|
||||
!RUNTIME_CONFIG_FIELDS.some((field) => field.group === group && field.path === path),
|
||||
)));
|
||||
setErrors((prev) => ({ ...prev, [group]: "" }));
|
||||
setInvalidField(null);
|
||||
};
|
||||
const change = (field: RuntimeConfigField, next: Draft) => {
|
||||
delay.current = ["boolean", "toggle", "select", "preset"].includes(field.kind) ? 0 : 600;
|
||||
setDrafts((prev) => ({ ...prev, [field.path]: next }));
|
||||
setSaved((prev) => ({ ...prev, [field.group]: false }));
|
||||
setErrors((prev) => ({ ...prev, [field.group]: "" }));
|
||||
setInvalidField(null);
|
||||
};
|
||||
const save = async (group: string) => {
|
||||
if (!settings?.runtime_config) return;
|
||||
if (saving) {
|
||||
if (!queuedSaves.current.includes(group)) queuedSaves.current.push(group);
|
||||
return;
|
||||
}
|
||||
const changed = RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group && visible(field) && dirty(field));
|
||||
if (!changed.length) return;
|
||||
const values: Record<string, RuntimeConfigValue> = {};
|
||||
for (const field of changed) {
|
||||
const raw = value(field.path);
|
||||
if (field.kind === "number") {
|
||||
const parsed = Number(raw);
|
||||
if (String(raw).trim() === "" || !Number.isFinite(parsed)
|
||||
|| (field.path !== "api.timeout" && !Number.isInteger(parsed))
|
||||
|| (field.min !== undefined && parsed < field.min)
|
||||
|| (field.max !== undefined && parsed > field.max)) {
|
||||
setErrors((prev) => ({ ...prev, [group]: t("settings.runtimeConfig.numberError") }));
|
||||
setInvalidField(field.path);
|
||||
return;
|
||||
}
|
||||
values[field.path] = parsed;
|
||||
} else if (field.kind === "list") {
|
||||
values[field.path] = String(raw).split("\n").map((line) => line.trim()).filter(Boolean);
|
||||
} else if (field.kind === "nullable" || field.kind === "preset") {
|
||||
values[field.path] = String(raw).trim() || null;
|
||||
} else {
|
||||
values[field.path] = raw;
|
||||
}
|
||||
}
|
||||
setSaving(group);
|
||||
setErrors((prev) => ({ ...prev, [group]: "" }));
|
||||
try {
|
||||
const payload = await updateRuntimeConfigSettings(client, values);
|
||||
applyPayload(payload, { preserveAgentForm: true, preserveCapabilityForms: true });
|
||||
discard(group);
|
||||
setSaved((prev) => ({ ...prev, [group]: true }));
|
||||
} catch (error) {
|
||||
const message = (error as Error).message;
|
||||
setErrors((prev) => ({ ...prev, [group]: message }));
|
||||
setInvalidField(changed.find((field) => message.startsWith(field.path))?.path ?? null);
|
||||
} finally {
|
||||
setSaving(null);
|
||||
}
|
||||
};
|
||||
saveLatest.current = save;
|
||||
pendingGroups.current = [...new Set(RUNTIME_CONFIG_FIELDS.filter((field) =>
|
||||
visible(field) && dirty(field) && !errors[field.group]
|
||||
&& !RUNTIME_CONFIG_FIELDS.some((other) => other.group === field.group && other.manual && dirty(other)),
|
||||
).map((field) => field.group))];
|
||||
useEffect(() => {
|
||||
if (saving) return;
|
||||
const timer = window.setTimeout(() => {
|
||||
const group = queuedSaves.current.shift() ?? pendingGroups.current[0];
|
||||
if (group) void saveLatest.current(group);
|
||||
}, delay.current);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [drafts, saving]);
|
||||
const saveList = async (field: RuntimeConfigField, next: string) => {
|
||||
const payload = await updateRuntimeConfigSettings(client, {
|
||||
[field.path]: next.split("\n").map((line) => line.trim()).filter(Boolean),
|
||||
});
|
||||
applyPayload(payload, { preserveAgentForm: true, preserveCapabilityForms: true });
|
||||
setSaved((prev) => ({ ...prev, [field.group]: true }));
|
||||
};
|
||||
return { value, visible, dirty, discard, change, save, saveList, saving, errors, invalidField, saved };
|
||||
}
|
||||
|
||||
export type RuntimeConfigController = ReturnType<typeof useRuntimeConfigSettings>;
|
||||
|
||||
export function RuntimeConfigSettings({
|
||||
page, settings, state, onRestart, isRestarting, remoteBrowserAccess, children,
|
||||
}: {
|
||||
page: RuntimeConfigPage;
|
||||
settings: SettingsPayload;
|
||||
state: RuntimeConfigController;
|
||||
onRestart?: () => void;
|
||||
isRestarting: boolean;
|
||||
remoteBrowserAccess: boolean;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tr = (key: string) => t(`settings.runtimeConfig.${key}`);
|
||||
if (!settings.runtime_config) return <div className="settings-stack">
|
||||
<p className="settings-editor text-[13px] leading-5 text-muted-foreground">{tr("unavailable")}</p>
|
||||
{children}
|
||||
</div>;
|
||||
const groups = RUNTIME_CONFIG_GROUPS.filter((group) => group.page === page);
|
||||
const restartPending = settings.restart_required_sections?.includes("runtime")
|
||||
|| (settings.requires_restart && Object.values(state.saved).some(Boolean));
|
||||
return (
|
||||
<div className="settings-stack">
|
||||
{restartPending && onRestart ? <RestartRequiredNotice message={t("settings.status.savedRestartApply")}
|
||||
onRestart={onRestart} isRestarting={isRestarting} /> : null}
|
||||
{groups.map((group) => {
|
||||
if (group.enabledBy && state.value(group.enabledBy) === false) return null;
|
||||
if (group.id === "chat") return <div key={group.id}>{children}</div>;
|
||||
const fields = RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group.id);
|
||||
const dirty = fields.filter(state.visible).some(state.dirty);
|
||||
const title = tr(`groups.${group.id}.title`);
|
||||
const errorId = `runtime-error-${group.id}`;
|
||||
const section = (
|
||||
<section key={group.id} aria-label={title}>
|
||||
<SettingsSectionTitle>{title}</SettingsSectionTitle>
|
||||
<form noValidate onSubmit={(event) => { event.preventDefault(); void state.save(group.id); }}>
|
||||
<fieldset disabled={state.saving === group.id || isRestarting} className="min-w-0">
|
||||
<legend className="sr-only">{title}</legend>
|
||||
<button type="submit" hidden />
|
||||
<SettingsGroup>
|
||||
{fields.filter(state.visible).map((field) => {
|
||||
const id = `runtime-${field.path}`;
|
||||
const key = field.path.replaceAll(".", "_");
|
||||
const text = tr(`fields.${key}.label`);
|
||||
const help = tr(`fields.${key}.help`);
|
||||
const current = state.value(field.path);
|
||||
const disabled = (field.path === "agents.defaults.timezone" && state.value("agents.defaults.timezone_mode") === "auto")
|
||||
|| (field.path === "tools.webui_allow_remote_package_install" && remoteBrowserAccess);
|
||||
const common = {
|
||||
id, disabled, "aria-label": text, "aria-describedby": `${id}-help${state.invalidField === field.path ? ` ${errorId}` : ""}`,
|
||||
"aria-invalid": state.invalidField === field.path || undefined,
|
||||
};
|
||||
const options = field.kind === "preset"
|
||||
? ["", ...new Set(["default", ...settings.model_presets.map((preset) => preset.name)])]
|
||||
: [...field.options ?? []];
|
||||
// Keep a configured preset visible if it is no longer available.
|
||||
if (field.kind === "preset" && current && !options.includes(String(current))) options.push(String(current));
|
||||
return (
|
||||
<SettingsRow key={field.path} title={text} description={help}>
|
||||
<span id={`${id}-help`} className="sr-only">{help}</span>
|
||||
{field.kind === "boolean" || field.kind === "toggle" ? (
|
||||
<ToggleButton {...common} checked={field.kind === "toggle" ? current === field.options?.[1] : current === true} label={text}
|
||||
onChange={(next) => state.change(field, field.kind === "toggle" ? field.options![next ? 1 : 0] : next)} />
|
||||
) : (
|
||||
<div className="w-full">
|
||||
{field.path === "agents.defaults.timezone" ? (
|
||||
<TimezonePicker {...common} value={String(current)} onChange={(next) => state.change(field, next)} />
|
||||
) : field.kind === "list" ? (
|
||||
<SettingsTextEditor id={id} title={text} description={help} value={String(current)}
|
||||
disabled={disabled || state.saving !== null || isRestarting}
|
||||
onSave={(next) => state.saveList(field, next)} />
|
||||
) : field.kind === "select" || field.kind === "preset" ? (
|
||||
<ProviderPicker triggerProps={{ ...common, disabled: disabled || state.saving === group.id || isRestarting }}
|
||||
value={String(current) || "__none__"} emptyLabel={tr("none")}
|
||||
providers={options.map((option) => ({ name: option || "__none__", label:
|
||||
!option ? tr(field.kind === "preset" ? "activeModel" : "none")
|
||||
: ["auto", "manual", "standard", "persistent"].includes(option) ? tr(option) : option,
|
||||
}))}
|
||||
onChange={(next) => state.change(field, next === "__none__" ? "" : next)} />
|
||||
) : (
|
||||
<Input {...common} type={field.kind === "number" ? "number" : "text"}
|
||||
min={field.min} max={field.max} step={field.path === "api.timeout" ? "any" : 1}
|
||||
value={String(current)} className="h-9 rounded-full text-[13px]" autoComplete="off"
|
||||
onChange={(event) => state.change(field, event.target.value)} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</SettingsRow>
|
||||
);
|
||||
})}
|
||||
<RestartSettingsFooter autoSave={!fields.some((field) => field.manual && state.dirty(field))} dirty={dirty} saving={state.saving === group.id}
|
||||
error={Boolean(state.errors[group.id])}
|
||||
disabled={state.saving === group.id || isRestarting}
|
||||
pendingRestart={false}
|
||||
message={state.saved[group.id] && !dirty ? tr("saved") : undefined}
|
||||
onSave={() => void state.save(group.id)} onReset={() => state.discard(group.id)}
|
||||
onRestart={onRestart} isRestarting={isRestarting} />
|
||||
</SettingsGroup>
|
||||
</fieldset>
|
||||
{state.errors[group.id] ? <p id={errorId} role="alert" className="mt-2 break-words px-1 text-[12px] text-destructive">{state.errors[group.id]}</p> : null}
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
return section;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user