feat(webui): configure idle compaction timeout (NAN-305) (#6383)

* feat(webui): configure idle compaction timeout (NAN-305)

* fix(webui): clarify idle compaction timeout and tradeoff

* refactor(webui): remove unused idle compaction minimum

* fix(webui): match idle compaction loading skeleton
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 13:41:05 +08:00
1 parent c6babb20e8
commit f11ea5f9e0
25 files changed
+523 -15

No files matched your search

@@ -324,6 +324,7 @@ export function RestartSettingsFooter({
size="sm"
variant="ghost"
onClick={onReset}
data-settings-reset=""
disabled={!dirty || saving}
className="rounded-full"
>
@@ -8,7 +8,7 @@ import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus";
import { RUNTIME_CONFIG_FIELDS, RUNTIME_CONFIG_GROUPS, type RuntimeConfigPage } from "@/components/settings/system/runtime-config-fields";
import { cn } from "@/lib/utils";
type Control = "switch" | "input" | "duration" | "segments" | "reading" | "theme" | "edit" | "text" | "feature";
type Control = "switch" | "input" | "duration" | "idle-timeout" | "segments" | "reading" | "theme" | "edit" | "text" | "feature";
const block = "rounded bg-muted-foreground/20";
function Title({ heading = false }: { heading?: boolean }) {
@@ -23,7 +23,9 @@ function Row({ control }: { control: Control }) {
<div className="flex h-5 items-center"><div className={cn(block, "h-3.5 w-32 max-w-full")} /></div>
<div className="settings-control">
{control === "feature" ? <div className={cn(block, "mr-3 h-3 w-14")} /> : null}
{control === "duration" ? <div className="w-full"><div className={cn(block, "h-9 w-full rounded-full")} /><div className="mt-1.5 flex h-4 items-center"><div className={cn(block, "h-2.5 w-4/5 opacity-60")} /></div></div> : <div data-skeleton-switch={toggle ? "" : undefined} data-skeleton-reading-size={control === "reading" ? "" : undefined} className={cn(block,
{control === "idle-timeout" ? <div className="flex items-center gap-2">
<div className={cn(block, "h-9 w-28 rounded-full")} /><div className={cn(block, "h-3 w-10")} />
</div> : control === "duration" ? <div className="w-full"><div className={cn(block, "h-9 w-full rounded-full")} /><div className="mt-1.5 flex h-4 items-center"><div className={cn(block, "h-2.5 w-4/5 opacity-60")} /></div></div> : <div data-skeleton-switch={toggle ? "" : undefined} data-skeleton-reading-size={control === "reading" ? "" : undefined} className={cn(block,
toggle ? "h-5 w-9 shrink-0 rounded-full" : control === "input" ? "h-9 w-full rounded-full"
: control === "segments" || control === "reading" || control === "theme" ? "segmented-control w-44 rounded-full" : control === "edit" ? "ml-auto h-9 w-9 rounded-full" : "h-[1lh] w-24 text-ui",
(control === "segments" || control === "reading") && "h-[34px]", control === "theme" && "h-8",
@@ -40,8 +42,10 @@ function Group({ controls }: { controls: Control[] }) {
function RuntimeGroups({ page }: { page: RuntimeConfigPage }) {
return <>{RUNTIME_CONFIG_GROUPS.filter((group) => group.page === page).map((group) => group.id === "chat"
? <Group key={group.id} controls={["switch", "segments"]} />
: <Group key={group.id} controls={RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group.id && (!field.when || field.when.value === true)).map((field) =>
field.kind === "boolean" || field.kind === "toggle" ? "switch" : field.kind === "list" ? "edit" : field.kind === "duration" ? "duration" : "input",
: <Group key={group.id} controls={RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group.id && (!field.when || field.when.value === true)).flatMap<Control>((field) =>
field.kind === "idle-compaction" ? ["switch", "idle-timeout"] : [
field.kind === "boolean" || field.kind === "toggle" ? "switch" : field.kind === "list" ? "edit" : field.kind === "duration" ? "duration" : "input",
],
)} />)}</>;
}
@@ -0,0 +1,63 @@
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { SettingsRow } from "@/components/settings/shared/SettingsControls";
import { Input } from "@/components/ui/input";
import { ToggleButton } from "@/components/ui/toggle-button";
export function IdleCompactionControl({
id, value, savedMinutes, disabled, errorId, onChange, onCommit,
}: {
id: string;
value: string;
savedMinutes: number;
disabled: boolean;
errorId?: string;
onChange: (next: string) => void;
onCommit: (next: string) => void;
}) {
const { t } = useTranslation();
const tr = (key: string) => t(`settings.runtimeConfig.idleCompaction.${key}`);
const [editing, setEditing] = useState(false);
const enabled = editing || value !== "0";
const lastMinutes = useRef(savedMinutes > 0 ? String(savedMinutes) : "15");
useEffect(() => {
if (savedMinutes > 0) lastMinutes.current = String(savedMinutes);
}, [savedMinutes]);
const toggleId = `${id}-enabled`;
return <>
<SettingsRow title={tr("label")} description={tr("help")}>
<ToggleButton id={toggleId} checked={enabled} disabled={disabled} label={tr("label")}
onChange={(next) => {
if (/^\d+$/.test(value) && Number.isSafeInteger(Number(value)) && Number(value) > 0) {
lastMinutes.current = value;
}
setEditing(false);
onCommit(next ? lastMinutes.current : "0");
}} />
</SettingsRow>
{enabled ? <SettingsRow title={tr("wait")}>
<div className="flex items-center gap-2">
<Input id={id} type="text" inputMode="numeric" value={value} disabled={disabled}
aria-label={tr("wait")} aria-describedby={`${id}-unit${errorId ? ` ${errorId}` : ""}`}
aria-invalid={Boolean(errorId) || undefined}
className="h-9 w-28 rounded-full text-[13px]" autoComplete="off"
onChange={(event) => onChange(event.target.value)}
onFocus={() => setEditing(true)}
onKeyDown={(event) => {
if (event.key === "Enter") {
event.preventDefault();
setEditing(false);
onCommit(value);
}
}}
onBlur={(event) => {
if (event.relatedTarget?.id === toggleId
|| (event.relatedTarget instanceof Element && event.relatedTarget.closest("[data-settings-reset]"))) return;
setEditing(false);
}} />
<span id={`${id}-unit`} className="text-[13px] text-muted-foreground">{tr("minutes")}</span>
</div>
</SettingsRow> : null}
</>;
}
@@ -7,6 +7,7 @@ import { ProviderPicker } from "@/components/settings/shared/ModelControls";
import { TimezonePicker } from "@/components/settings/shared/TimezonePicker";
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
import { ShellRuntimeControl } from "@/components/settings/system/ShellRuntimeControl";
import { IdleCompactionControl } from "@/components/settings/system/IdleCompactionControl";
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";
@@ -65,18 +66,26 @@ export function useRuntimeConfigSettings(
setErrors((prev) => ({ ...prev, [field.group]: message }));
setInvalidField(field.path);
};
const save = async (group: string) => {
const save = async (group: string, edits: Record<string, Draft> = {}) => {
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));
const editedValue = (field: RuntimeConfigField) => edits[field.path] ?? value(field.path);
const changed = RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group && visible(field)
&& editedValue(field) !== displayValue(settings.runtime_config?.[field.path]));
if (!changed.length) return;
const values: Record<string, RuntimeConfigValue> = {};
for (const field of changed) {
const raw = value(field.path);
if (field.kind === "number" || field.kind === "duration") {
const raw = editedValue(field);
if (field.kind === "idle-compaction") {
if (!/^\d+$/.test(String(raw)) || !Number.isSafeInteger(Number(raw))) {
reject(field, t("settings.runtimeConfig.idleCompaction.numberError"));
return;
}
values[field.path] = Number(raw);
} else if (field.kind === "number" || field.kind === "duration") {
const maximum = field.kind === "duration" ? settings.advanced.exec_max_runtime_limit : field.max;
const parsed = Number(raw);
if (String(raw).trim() === "" || !Number.isFinite(parsed)
@@ -131,7 +140,12 @@ export function useRuntimeConfigSettings(
applyPayload(payload, { preserveAgentForm: true, preserveCapabilityForms: true });
setSaved((prev) => ({ ...prev, [field.group]: true }));
};
return { value, visible, dirty, discard, change, reject, save, saveList, saving, errors, invalidField, saved };
const commit = (field: RuntimeConfigField, next: Draft) => {
if (next === value(field.path) && !dirty(field)) return;
change(field, next);
void save(field.group, { [field.path]: next });
};
return { value, visible, dirty, discard, change, commit, reject, save, saveList, saving, errors, invalidField, saved };
}
export type RuntimeConfigController = ReturnType<typeof useRuntimeConfigSettings>;
@@ -171,17 +185,31 @@ export function RuntimeConfigSettings({
const section = (
<section key={group.id} aria-label={title}>
<SettingsSectionTitle>{title}</SettingsSectionTitle>
<form noValidate onSubmit={(event) => { event.preventDefault(); void state.save(group.id); }}>
<form noValidate onSubmit={(event) => { event.preventDefault(); void state.save(group.id); }}
onBlur={(event) => {
if (event.relatedTarget && event.currentTarget.contains(event.relatedTarget)) return;
if (fields.some((field) => field.kind === "idle-compaction" && state.dirty(field))) {
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 current = state.value(field.path);
if (field.kind === "idle-compaction") return (
<IdleCompactionControl key={field.path} id={id} value={String(current)}
savedMinutes={Number(settings.runtime_config?.[field.path])}
disabled={state.saving === group.id || isRestarting}
errorId={state.invalidField === field.path ? errorId : undefined}
onChange={(next) => state.change(field, next)}
onCommit={(next) => state.commit(field, next)} />
);
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 = {
@@ -1,7 +1,7 @@
export interface RuntimeConfigField {
group: string;
path: string;
kind: "toggle" | "text" | "nullable" | "number" | "duration" | "boolean" | "select" | "list" | "preset";
kind: "toggle" | "text" | "nullable" | "number" | "duration" | "boolean" | "select" | "list" | "preset" | "idle-compaction";
options?: string[];
when?: { path: string; value: string | boolean | string[] };
manual?: boolean;
@@ -39,6 +39,7 @@ export const RUNTIME_CONFIG_FIELDS: RuntimeConfigField[] = [
{ group: "execution", path: "agents.defaults.tool_hint_max_length", kind: "number", min: 20, max: 500 },
{ group: "execution", path: "tools.max_session_messages_per_minute", kind: "number", min: 1 },
{ group: "sessions", path: "agents.defaults.unified_session", kind: "boolean" },
{ group: "sessions", path: "agents.defaults.session_ttl_minutes", kind: "idle-compaction", manual: true },
{ group: "tools", path: "tools.exec.enable", kind: "boolean" },
{ group: "tools", path: "tools.file.enable", kind: "boolean" },
{ group: "web", path: "tools.web.enable", kind: "boolean" },