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
@@ -1,4 +1,6 @@
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import type { Dispatch, SetStateAction, ReactNode } from "react";
|
||||
import { SettingsAdvancedOptions } from "@/components/settings/shared/SettingsFeature";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ModelIdPicker, ProviderPicker, optionRowsWithCurrent } from "@/components/settings/shared/ModelControls";
|
||||
@@ -39,6 +41,9 @@ export function imageGenerationFormFromPayload(payload: SettingsPayload): ImageG
|
||||
}
|
||||
|
||||
export function ImageGenerationSettings({
|
||||
embedded = false,
|
||||
error,
|
||||
children,
|
||||
token,
|
||||
settings,
|
||||
form,
|
||||
@@ -52,6 +57,9 @@ export function ImageGenerationSettings({
|
||||
isRestarting,
|
||||
requiresRestartPending,
|
||||
}: {
|
||||
embedded?: boolean;
|
||||
error?: string;
|
||||
children?: ReactNode;
|
||||
token: string;
|
||||
settings: SettingsPayload;
|
||||
form: ImageGenerationSettingsUpdate;
|
||||
@@ -72,6 +80,7 @@ export function ImageGenerationSettings({
|
||||
settings.image_generation.providers[0];
|
||||
const providerConfigured = !!selectedProvider?.configured;
|
||||
const missingCredential = form.enabled && !providerConfigured;
|
||||
useAutoSave(form, dirty, saving, onSave, !embedded && !missingCredential);
|
||||
const aspectOptions = optionRowsWithCurrent(
|
||||
IMAGE_ASPECT_RATIO_OPTIONS.map((value) => ({ name: value, label: value })),
|
||||
form.defaultAspectRatio,
|
||||
@@ -90,10 +99,11 @@ export function ImageGenerationSettings({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-7">
|
||||
<div className="settings-stack">
|
||||
<section>
|
||||
<SettingsSectionTitle>{tx("settings.sections.imageGeneration", "Image generation")}</SettingsSectionTitle>
|
||||
{!embedded ? <SettingsSectionTitle>{tx("settings.sections.imageGeneration", "Image generation")}</SettingsSectionTitle> : null}
|
||||
<SettingsGroup>
|
||||
{!embedded ? (
|
||||
<SettingsRow title={tx("settings.rows.imageGeneration", "Image generation")}>
|
||||
<ToggleButton
|
||||
checked={form.enabled}
|
||||
@@ -102,6 +112,8 @@ export function ImageGenerationSettings({
|
||||
label={form.enabled ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
||||
/>
|
||||
</SettingsRow>
|
||||
) : null}
|
||||
{embedded || form.enabled ? <>
|
||||
<SettingsRow title={tx("settings.rows.imageProvider", "Image provider")}>
|
||||
<ProviderPicker
|
||||
providers={settings.image_generation.providers}
|
||||
@@ -128,17 +140,11 @@ export function ImageGenerationSettings({
|
||||
) : null}
|
||||
</div>
|
||||
</SettingsRow>
|
||||
<SettingsRow title={tx("settings.rows.imageProviderBase", "Provider base")}>
|
||||
<SettingsRow title={tx("settings.rows.imageProviderBase", "Provider URL")}>
|
||||
<span className="max-w-[320px] truncate text-right text-[13px] text-muted-foreground">
|
||||
{selectedProvider?.api_base || selectedProvider?.default_api_base || selectedProvider?.name || tx("settings.values.notAvailable", "Not available")}
|
||||
</span>
|
||||
</SettingsRow>
|
||||
</SettingsGroup>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<SettingsSectionTitle>{tx("settings.sections.imageDefaults", "Defaults")}</SettingsSectionTitle>
|
||||
<SettingsGroup>
|
||||
<SettingsRow title={tx("settings.rows.imageModel", "Image model")}>
|
||||
<ModelIdPicker
|
||||
token={token}
|
||||
@@ -159,7 +165,7 @@ export function ImageGenerationSettings({
|
||||
onChange={(model) => onChangeForm((prev) => ({ ...prev, model }))}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsRow title={tx("settings.rows.defaultAspectRatio", "Default aspect")}>
|
||||
<SettingsRow title={tx("settings.rows.defaultAspectRatio", "Default aspect ratio")}>
|
||||
<ProviderPicker
|
||||
providers={aspectOptions}
|
||||
value={form.defaultAspectRatio}
|
||||
@@ -179,7 +185,8 @@ export function ImageGenerationSettings({
|
||||
}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsRow title={tx("settings.rows.maxImagesPerTurn", "Max images per turn")}>
|
||||
<SettingsAdvancedOptions>
|
||||
<SettingsRow title={tx("settings.rows.maxImagesPerTurn", "Max images per request")}>
|
||||
<NumberInput
|
||||
value={form.maxImagesPerTurn}
|
||||
min={1}
|
||||
@@ -189,19 +196,26 @@ export function ImageGenerationSettings({
|
||||
}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<ReadOnlyRow title={tx("settings.rows.imageSaveDir", "Save directory")} value={settings.image_generation.save_dir} />
|
||||
{!settings.runtime_config ? (
|
||||
<ReadOnlyRow title={tx("settings.rows.imageSaveDir", "Save directory")} value={settings.image_generation.save_dir} />
|
||||
) : null}
|
||||
{children}
|
||||
</SettingsAdvancedOptions>
|
||||
</> : null}
|
||||
<RestartSettingsFooter
|
||||
error={missingCredential || Boolean(error)}
|
||||
autoSave
|
||||
dirty={dirty}
|
||||
saving={saving}
|
||||
pendingRestart={requiresRestartPending}
|
||||
pendingRestart={!embedded && requiresRestartPending}
|
||||
disabled={missingCredential}
|
||||
message={
|
||||
missingCredential
|
||||
? tx("settings.image.missingCredential", "Configure this provider before enabling image generation.")
|
||||
: undefined
|
||||
: error
|
||||
}
|
||||
dirtyMessage={tx("settings.status.restartAfterSaving", "Save changes, then restart when ready.")}
|
||||
pendingMessage={tx("settings.status.savedRestartApply", "Saved. Restart when ready.")}
|
||||
dirtyMessage={tx("settings.status.restartAfterSaving", "Save changes, then restart nanobot to apply them.")}
|
||||
pendingMessage={tx("settings.status.savedRestartApply", "Saved. Restart to apply changes.")}
|
||||
onSave={onSave}
|
||||
onRestart={onRestart}
|
||||
isRestarting={isRestarting}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -37,6 +38,7 @@ export function visibleWebuiDefaultAccessMode(mode: string | null | undefined):
|
||||
}
|
||||
|
||||
export function AdvancedSettings({
|
||||
error,
|
||||
form,
|
||||
dirty,
|
||||
saving,
|
||||
@@ -47,6 +49,7 @@ export function AdvancedSettings({
|
||||
onRestart,
|
||||
isRestarting,
|
||||
}: {
|
||||
error?: string;
|
||||
form: NetworkSafetySettingsUpdate;
|
||||
dirty: boolean;
|
||||
saving: boolean;
|
||||
@@ -58,9 +61,10 @@ export function AdvancedSettings({
|
||||
isRestarting?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
useAutoSave(form, dirty, saving, onSave);
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
return (
|
||||
<div className="space-y-7">
|
||||
<div className="settings-stack">
|
||||
<section>
|
||||
<SettingsSectionTitle>
|
||||
{isNativeHostSurface
|
||||
@@ -110,6 +114,9 @@ export function AdvancedSettings({
|
||||
/>
|
||||
</SettingsRow>
|
||||
<RestartSettingsFooter
|
||||
autoSave
|
||||
error={Boolean(error)}
|
||||
message={error}
|
||||
dirty={dirty}
|
||||
saving={saving}
|
||||
pendingRestart={requiresRestartPending}
|
||||
@@ -120,12 +127,6 @@ export function AdvancedSettings({
|
||||
</SettingsGroup>
|
||||
</section>
|
||||
|
||||
<p className="max-w-3xl px-1 text-sm leading-6 text-muted-foreground">
|
||||
{tx(
|
||||
"settings.help.securityManagedControls",
|
||||
"Web fetches always protect local, private, and metadata services. Core channel safety stays in config.json.",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import { SettingsAdvancedOptions } from "@/components/settings/shared/SettingsFeature";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -48,6 +50,8 @@ export function transcriptionFormFromPayload(payload: SettingsPayload): Transcri
|
||||
}
|
||||
|
||||
export function TranscriptionSettings({
|
||||
embedded = false,
|
||||
error,
|
||||
settings,
|
||||
form,
|
||||
dirty,
|
||||
@@ -60,6 +64,8 @@ export function TranscriptionSettings({
|
||||
isRestarting,
|
||||
requiresRestartPending,
|
||||
}: {
|
||||
embedded?: boolean;
|
||||
error?: string;
|
||||
settings: SettingsPayload;
|
||||
form: TranscriptionSettingsUpdate;
|
||||
dirty: boolean;
|
||||
@@ -73,6 +79,7 @@ export function TranscriptionSettings({
|
||||
requiresRestartPending: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
useAutoSave(form, dirty, saving, onSave, !embedded);
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const transcription = settings.transcription ?? DEFAULT_TRANSCRIPTION_SETTINGS;
|
||||
const selectedProvider =
|
||||
@@ -82,8 +89,9 @@ export function TranscriptionSettings({
|
||||
|
||||
return (
|
||||
<section>
|
||||
<SettingsSectionTitle>{tx("settings.sections.voiceInput", "Voice input")}</SettingsSectionTitle>
|
||||
{!embedded ? <SettingsSectionTitle>{tx("settings.sections.voiceInput", "Voice input")}</SettingsSectionTitle> : null}
|
||||
<SettingsGroup>
|
||||
{!embedded ? (
|
||||
<SettingsRow
|
||||
title={tx("settings.rows.transcription", "Transcription")}
|
||||
description={tx("settings.help.transcription", "Transcribe microphone input before sending it. Chat channel voice messages use the same settings.")}
|
||||
@@ -95,6 +103,8 @@ export function TranscriptionSettings({
|
||||
label={form.enabled ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
||||
/>
|
||||
</SettingsRow>
|
||||
) : null}
|
||||
{embedded || form.enabled ? <>
|
||||
<SettingsRow title={tx("settings.rows.transcriptionProvider", "Provider")}>
|
||||
<ProviderPicker
|
||||
providers={transcription.providers}
|
||||
@@ -123,27 +133,28 @@ export function TranscriptionSettings({
|
||||
</SettingsRow>
|
||||
<SettingsRow
|
||||
title={tx("settings.rows.transcriptionModel", "Model")}
|
||||
description={tx("settings.help.transcriptionModel", "Leave as the resolved default unless your provider needs a custom model id.")}
|
||||
description={tx("settings.help.transcriptionModel", "Keep the default model unless your provider requires a specific model ID.")}
|
||||
>
|
||||
<Input
|
||||
value={form.model}
|
||||
onChange={(event) => onChangeForm((prev) => ({ ...prev, model: event.target.value }))}
|
||||
className="h-8 w-[min(300px,70vw)] rounded-full text-[13px]"
|
||||
className="h-9 w-full rounded-full text-end text-[13px]"
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsRow
|
||||
title={tx("settings.rows.transcriptionLanguage", "Language")}
|
||||
description={tx("settings.help.transcriptionLanguage", "Optional ISO-639 hint such as en, zh, ja, or ko.")}
|
||||
description={tx("settings.help.transcriptionLanguage", "Optional language code, such as en for English, zh for Chinese, ja for Japanese, or ko for Korean.")}
|
||||
>
|
||||
<Input
|
||||
value={form.language}
|
||||
onChange={(event) => onChangeForm((prev) => ({ ...prev, language: event.target.value }))}
|
||||
placeholder={tx("settings.voice.languageAuto", "Auto")}
|
||||
className="h-8 w-[min(180px,60vw)] rounded-full text-[13px]"
|
||||
className="h-9 w-full rounded-full text-end text-[13px]"
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsAdvancedOptions>
|
||||
<SettingsRow title={tx("settings.rows.voiceLimits", "Limits")}>
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<div className="grid w-full gap-2">
|
||||
<NumberInput
|
||||
value={form.maxDurationSec}
|
||||
min={1}
|
||||
@@ -160,12 +171,17 @@ export function TranscriptionSettings({
|
||||
/>
|
||||
</div>
|
||||
</SettingsRow>
|
||||
</SettingsAdvancedOptions>
|
||||
</> : null}
|
||||
<RestartSettingsFooter
|
||||
error={Boolean(error)}
|
||||
message={error}
|
||||
autoSave
|
||||
dirty={dirty}
|
||||
saving={saving}
|
||||
pendingRestart={requiresRestartPending}
|
||||
dirtyMessage={tx("settings.status.restartAfterSaving", "Save changes, then restart when ready.")}
|
||||
pendingMessage={tx("settings.status.savedRestartApply", "Saved. Restart when ready.")}
|
||||
pendingRestart={!embedded && requiresRestartPending}
|
||||
dirtyMessage={tx("settings.status.restartAfterSaving", "Save changes, then restart nanobot to apply them.")}
|
||||
pendingMessage={tx("settings.status.savedRestartApply", "Saved. Restart to apply changes.")}
|
||||
onSave={onSave}
|
||||
onRestart={onRestart}
|
||||
isRestarting={isRestarting}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import { SettingsAdvancedOptions } from "@/components/settings/shared/SettingsFeature";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { Eye, EyeOff, Pencil } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -54,7 +56,28 @@ export function webSearchProviderRequiresApiKey(provider?: WebSearchProviderOpti
|
||||
return provider?.credential === "api_key";
|
||||
}
|
||||
|
||||
export function webSearchDraftState(settings: SettingsPayload, form: WebSearchSettingsUpdate) {
|
||||
const provider = settings.web_search.providers.find((row) => row.name === form.provider);
|
||||
const apiKey = form.apiKey?.trim() ?? "";
|
||||
const baseUrl = form.baseUrl?.trim() ?? "";
|
||||
const hasExistingSecret = webSearchProviderAcceptsApiKey(provider) &&
|
||||
form.provider === settings.web_search.provider && Boolean(settings.web_search.api_key_hint);
|
||||
const jinaReaderDirty = (form.useJinaReader ?? settings.web.fetch.use_jina_reader) !== settings.web.fetch.use_jina_reader;
|
||||
return {
|
||||
hasExistingSecret,
|
||||
jinaReaderDirty,
|
||||
dirty: form.provider !== settings.web_search.provider || apiKey.length > 0 ||
|
||||
baseUrl !== (settings.web_search.base_url ?? "") || form.maxResults !== settings.web_search.max_results ||
|
||||
form.timeout !== settings.web_search.timeout || jinaReaderDirty,
|
||||
missingCredential: webSearchProviderRequiresApiKey(provider) ? !apiKey && !hasExistingSecret
|
||||
: provider?.credential === "base_url" ? !baseUrl : false,
|
||||
};
|
||||
}
|
||||
|
||||
export function WebSettings({
|
||||
embedded = false,
|
||||
error,
|
||||
enabled = true,
|
||||
settings,
|
||||
form,
|
||||
keyVisible,
|
||||
@@ -74,6 +97,9 @@ export function WebSettings({
|
||||
olostepInstalling,
|
||||
capabilityError,
|
||||
}: {
|
||||
embedded?: boolean;
|
||||
error?: string;
|
||||
enabled?: boolean;
|
||||
settings: SettingsPayload;
|
||||
form: WebSearchSettingsUpdate;
|
||||
keyVisible: boolean;
|
||||
@@ -98,40 +124,24 @@ export function WebSettings({
|
||||
const selectedProvider =
|
||||
settings.web_search.providers.find((provider) => provider.name === form.provider) ??
|
||||
settings.web_search.providers[0];
|
||||
const hasExistingSecret =
|
||||
webSearchProviderAcceptsApiKey(selectedProvider) &&
|
||||
form.provider === settings.web_search.provider &&
|
||||
!!settings.web_search.api_key_hint;
|
||||
const showKeyInput = webSearchProviderAcceptsApiKey(selectedProvider) && (!hasExistingSecret || keyEditing);
|
||||
const apiKey = form.apiKey?.trim() ?? "";
|
||||
const baseUrl = form.baseUrl?.trim() ?? "";
|
||||
const { hasExistingSecret, dirty, jinaReaderDirty, missingCredential } = webSearchDraftState(settings, form);
|
||||
const effectiveJinaReader = form.useJinaReader ?? settings.web.fetch.use_jina_reader;
|
||||
const dirty =
|
||||
form.provider !== settings.web_search.provider ||
|
||||
apiKey.length > 0 ||
|
||||
baseUrl !== (settings.web_search.base_url ?? "") ||
|
||||
form.maxResults !== settings.web_search.max_results ||
|
||||
form.timeout !== settings.web_search.timeout ||
|
||||
effectiveJinaReader !== settings.web.fetch.use_jina_reader;
|
||||
const jinaReaderDirty = effectiveJinaReader !== settings.web.fetch.use_jina_reader;
|
||||
const missingCredential =
|
||||
webSearchProviderRequiresApiKey(selectedProvider)
|
||||
? !apiKey && !hasExistingSecret
|
||||
: selectedProvider?.credential === "base_url"
|
||||
? !baseUrl
|
||||
: false;
|
||||
const showKeyInput = webSearchProviderAcceptsApiKey(selectedProvider) && (!hasExistingSecret || keyEditing);
|
||||
|
||||
useAutoSave(form, dirty, saving, onSave, !embedded && !missingCredential && (form.provider !== "olostep" || olostepFeature?.installed === true));
|
||||
|
||||
return (
|
||||
<div className="space-y-7">
|
||||
<div className="settings-stack">
|
||||
<section>
|
||||
<SettingsSectionTitle>{tx("settings.sections.webSearch", "Web search")}</SettingsSectionTitle>
|
||||
{enabled && !embedded ? <SettingsSectionTitle>{tx("settings.sections.webSearch", "Web search")}</SettingsSectionTitle> : null}
|
||||
<div hidden={!embedded && !enabled}>
|
||||
{form.provider === "olostep" && olostepFeature && !olostepFeature.installed ? (
|
||||
<div className="mb-3">
|
||||
<CapabilityInstallNotice
|
||||
title={tx("settings.capabilities.searchSupport", "Search provider support")}
|
||||
title={tx("settings.capabilities.searchSupport", "Search dependencies")}
|
||||
description={tx(
|
||||
"settings.capabilities.searchInstallOnSave",
|
||||
"Olostep support will be installed automatically when you save.",
|
||||
"Required Olostep packages will be installed automatically when you save.",
|
||||
)}
|
||||
installing={olostepInstalling}
|
||||
/>
|
||||
@@ -140,7 +150,9 @@ export function WebSettings({
|
||||
{capabilityError ? (
|
||||
<p className="mb-3 text-[12px] text-destructive">{capabilityError}</p>
|
||||
) : null}
|
||||
</div>
|
||||
<SettingsGroup>
|
||||
<div hidden={!embedded && !enabled} className="space-y-1">
|
||||
<SettingsRow title={t("settings.byok.webSearch.provider")}>
|
||||
<ProviderPicker
|
||||
providers={settings.web_search.providers}
|
||||
@@ -162,7 +174,7 @@ export function WebSettings({
|
||||
title={t("settings.byok.apiKey")}
|
||||
description={t("settings.byok.webSearch.apiKeyHelp")}
|
||||
>
|
||||
<div className="relative w-[280px] max-w-full">
|
||||
<div className="relative w-full">
|
||||
{showKeyInput ? (
|
||||
<>
|
||||
<Input
|
||||
@@ -186,7 +198,7 @@ export function WebSettings({
|
||||
aria-label={
|
||||
keyVisible ? t("settings.byok.hideApiKey") : t("settings.byok.showApiKey")
|
||||
}
|
||||
className="absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
className="absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full text-muted-foreground settings-hover hover:text-foreground"
|
||||
>
|
||||
{keyVisible ? (
|
||||
<EyeOff className="h-3.5 w-3.5" aria-hidden />
|
||||
@@ -206,7 +218,7 @@ export function WebSettings({
|
||||
size="icon"
|
||||
onClick={onToggleKeyEditing}
|
||||
aria-label={t("settings.actions.edit")}
|
||||
className="absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
className="absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full text-muted-foreground settings-hover hover:text-foreground"
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" aria-hidden />
|
||||
</Button>
|
||||
@@ -227,16 +239,11 @@ export function WebSettings({
|
||||
onChangeForm((prev) => ({ ...prev, baseUrl: event.target.value }))
|
||||
}
|
||||
placeholder={t("settings.byok.webSearch.baseUrlPlaceholder")}
|
||||
className="h-9 w-[280px] rounded-full text-[13px]"
|
||||
className="h-9 w-full rounded-full text-[13px]"
|
||||
/>
|
||||
</SettingsRow>
|
||||
) : null}
|
||||
</SettingsGroup>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<SettingsSectionTitle>{tx("settings.sections.webBehavior", "Behavior")}</SettingsSectionTitle>
|
||||
<SettingsGroup>
|
||||
<SettingsAdvancedOptions>
|
||||
<SettingsRow title={tx("settings.rows.maxResults", "Max results")}>
|
||||
<NumberInput
|
||||
value={form.maxResults ?? settings.web_search.max_results}
|
||||
@@ -256,7 +263,7 @@ export function WebSettings({
|
||||
</SettingsRow>
|
||||
<SettingsRow
|
||||
title={tx("settings.rows.jinaReader", "Jina reader")}
|
||||
description={tx("settings.help.jinaReader", "Use Jina Reader for web_fetch when available.")}
|
||||
description={tx("settings.help.jinaReader", "Use Jina Reader to read web pages when available.")}
|
||||
>
|
||||
<ToggleButton
|
||||
checked={effectiveJinaReader}
|
||||
@@ -265,21 +272,26 @@ export function WebSettings({
|
||||
label={effectiveJinaReader ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
||||
/>
|
||||
</SettingsRow>
|
||||
</SettingsAdvancedOptions>
|
||||
</div>
|
||||
<RestartSettingsFooter
|
||||
error={missingCredential || Boolean(error)}
|
||||
autoSave={form.provider !== "olostep" || olostepFeature?.installed === true}
|
||||
saveLabel={t("settings.nanobotFeatures.installConfirmAction")}
|
||||
dirty={dirty}
|
||||
saving={saving}
|
||||
pendingRestart={requiresRestartPending}
|
||||
pendingRestart={!embedded && requiresRestartPending}
|
||||
disabled={missingCredential}
|
||||
message={
|
||||
missingCredential
|
||||
? t("settings.byok.webSearch.missingCredential")
|
||||
: requiresRestartPending && !dirty
|
||||
? tx("settings.status.savedRestartApply", "Saved. Restart when ready.")
|
||||
: error || (!embedded && requiresRestartPending && !dirty
|
||||
? tx("settings.status.savedRestartApply", "Saved. Restart to apply changes.")
|
||||
: jinaReaderDirty
|
||||
? tx("settings.status.restartAfterSaving", "Save changes, then restart when ready.")
|
||||
? tx("settings.status.restartAfterSaving", "Save changes, then restart nanobot to apply them.")
|
||||
: dirty
|
||||
? t("settings.byok.webSearch.saveHint")
|
||||
: undefined
|
||||
: undefined)
|
||||
}
|
||||
onSave={onSave}
|
||||
onRestart={onRestart}
|
||||
|
||||
@@ -19,6 +19,9 @@ import {
|
||||
} from "@/lib/api";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type { SettingsPayload, WebSearchSettingsUpdate } from "@/lib/types";
|
||||
import { imageGenerationFormFromPayload } from "@/components/settings/capabilities/ImageGenerationSettings";
|
||||
import { transcriptionFormFromPayload } from "@/components/settings/capabilities/TranscriptionSettings";
|
||||
import { networkSafetyFormFromPayload } from "@/components/settings/capabilities/SecuritySettings";
|
||||
|
||||
interface CapabilitySettingsActionsOptions {
|
||||
state: CapabilitySettingsState;
|
||||
@@ -28,7 +31,6 @@ interface CapabilitySettingsActionsOptions {
|
||||
applyPayload: ApplySettingsPayload;
|
||||
maybeRestartHostEngine: MaybeRestartHostEngine;
|
||||
setPendingRestartSections: Dispatch<SetStateAction<PendingRestartSections>>;
|
||||
setError: Dispatch<SetStateAction<string | null>>;
|
||||
installCapabilities: (names: string[]) => Promise<boolean>;
|
||||
imageGenerationDirty: boolean;
|
||||
transcriptionDirty: boolean;
|
||||
@@ -43,7 +45,6 @@ export function useCapabilitySettingsActions({
|
||||
applyPayload,
|
||||
maybeRestartHostEngine,
|
||||
setPendingRestartSections,
|
||||
setError,
|
||||
installCapabilities,
|
||||
imageGenerationDirty,
|
||||
transcriptionDirty,
|
||||
@@ -67,20 +68,29 @@ export function useCapabilitySettingsActions({
|
||||
webSearchKeyEditing,
|
||||
webSearchSaving,
|
||||
} = state;
|
||||
const setError = (section: "image" | "voice" | "web" | "safety", message?: string) =>
|
||||
state.setCapabilityErrors((prev) => ({ ...prev, [section]: message }));
|
||||
|
||||
const saveImageGenerationSettings = async () => {
|
||||
if (!settings || !imageGenerationDirty || imageGenerationSaving) return;
|
||||
if (imageGenerationForm.enabled && !settings.image_generation.providers.find(
|
||||
(provider) => provider.name === imageGenerationForm.provider,
|
||||
)?.configured) return;
|
||||
setError("image");
|
||||
setImageGenerationSaving(true);
|
||||
try {
|
||||
const payload = await updateImageGenerationSettings(client, imageGenerationForm);
|
||||
applyPayload(payload);
|
||||
if (payload.requires_restart) {
|
||||
applyPayload(payload, { preserveCapabilityForms: true });
|
||||
state.setImageGenerationForm(imageGenerationFormFromPayload(payload));
|
||||
if (!payload.restart_required_sections && payload.requires_restart) {
|
||||
setPendingRestartSections((prev) => ({ ...prev, image: true }));
|
||||
}
|
||||
await maybeRestartHostEngine(payload);
|
||||
setError(null);
|
||||
setError("image");
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
const message = (err as Error).message;
|
||||
setError("image", message === "image generation provider is not configured"
|
||||
? t("settings.image.missingCredential") : message);
|
||||
} finally {
|
||||
setImageGenerationSaving(false);
|
||||
}
|
||||
@@ -88,17 +98,19 @@ export function useCapabilitySettingsActions({
|
||||
|
||||
const saveTranscriptionSettings = async () => {
|
||||
if (!settings || !transcriptionDirty || transcriptionSaving) return;
|
||||
setError("voice");
|
||||
setTranscriptionSaving(true);
|
||||
try {
|
||||
const payload = await updateTranscriptionSettings(client, transcriptionForm);
|
||||
applyPayload(payload);
|
||||
if (payload.requires_restart) {
|
||||
applyPayload(payload, { preserveCapabilityForms: true });
|
||||
state.setTranscriptionForm(transcriptionFormFromPayload(payload));
|
||||
if (!payload.restart_required_sections && payload.requires_restart) {
|
||||
setPendingRestartSections((prev) => ({ ...prev, browser: true }));
|
||||
}
|
||||
await maybeRestartHostEngine(payload);
|
||||
setError(null);
|
||||
setError("voice");
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
setError("voice", (err as Error).message);
|
||||
} finally {
|
||||
setTranscriptionSaving(false);
|
||||
}
|
||||
@@ -106,17 +118,19 @@ export function useCapabilitySettingsActions({
|
||||
|
||||
const saveNetworkSafetySettings = async () => {
|
||||
if (!settings || !networkSafetyDirty || networkSafetySaving) return;
|
||||
setError("safety");
|
||||
setNetworkSafetySaving(true);
|
||||
try {
|
||||
const payload = await updateNetworkSafetySettings(client, networkSafetyForm);
|
||||
applyPayload(payload);
|
||||
if (payload.requires_restart) {
|
||||
applyPayload(payload, { preserveCapabilityForms: true });
|
||||
state.setNetworkSafetyForm(networkSafetyFormFromPayload(payload));
|
||||
if (!payload.restart_required_sections && payload.requires_restart) {
|
||||
setPendingRestartSections((prev) => ({ ...prev, runtime: true }));
|
||||
}
|
||||
await maybeRestartHostEngine(payload);
|
||||
setError(null);
|
||||
setError("safety");
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
setError("safety", (err as Error).message);
|
||||
} finally {
|
||||
setNetworkSafetySaving(false);
|
||||
}
|
||||
@@ -134,14 +148,13 @@ export function useCapabilitySettingsActions({
|
||||
!!settings.web_search.api_key_hint;
|
||||
|
||||
if (webSearchProviderRequiresApiKey(provider) && !apiKey && !hasExistingSecret) {
|
||||
setError(t("settings.byok.webSearch.apiKeyRequired"));
|
||||
return;
|
||||
}
|
||||
if (provider.credential === "base_url" && !baseUrl) {
|
||||
setError(t("settings.byok.webSearch.baseUrlRequired"));
|
||||
return;
|
||||
}
|
||||
|
||||
setError("web");
|
||||
setWebSearchSaving(true);
|
||||
try {
|
||||
if (provider.name === "olostep" && !(await installCapabilities(["olostep"]))) return;
|
||||
@@ -162,8 +175,8 @@ export function useCapabilitySettingsActions({
|
||||
}
|
||||
if (provider.credential === "base_url") update.baseUrl = baseUrl;
|
||||
const payload = await updateWebSearchSettings(client, update);
|
||||
applyPayload(payload);
|
||||
if (payload.requires_restart || webFetchRestartRequired) {
|
||||
applyPayload(payload, { preserveCapabilityForms: true });
|
||||
if (!payload.restart_required_sections && (payload.requires_restart || webFetchRestartRequired)) {
|
||||
setPendingRestartSections((prev) => ({ ...prev, browser: true }));
|
||||
}
|
||||
await maybeRestartHostEngine(payload);
|
||||
@@ -177,9 +190,9 @@ export function useCapabilitySettingsActions({
|
||||
}));
|
||||
setWebSearchKeyVisible(false);
|
||||
setWebSearchKeyEditing(false);
|
||||
setError(null);
|
||||
setError("web");
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
setError("web", (err as Error).message);
|
||||
} finally {
|
||||
setWebSearchSaving(false);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import type {
|
||||
} from "@/lib/types";
|
||||
|
||||
export function useCapabilitySettingsState(initialSettings: SettingsPayload | null) {
|
||||
const [capabilityErrors, setCapabilityErrors] = useState<Partial<Record<"image" | "voice" | "web" | "safety", string>>>({});
|
||||
const [webSearchSaving, setWebSearchSaving] = useState(false);
|
||||
const [imageGenerationSaving, setImageGenerationSaving] = useState(false);
|
||||
const [transcriptionSaving, setTranscriptionSaving] = useState(false);
|
||||
@@ -47,6 +48,8 @@ export function useCapabilitySettingsState(initialSettings: SettingsPayload | nu
|
||||
const [webSearchKeyEditing, setWebSearchKeyEditing] = useState(false);
|
||||
|
||||
return {
|
||||
capabilityErrors,
|
||||
setCapabilityErrors,
|
||||
imageGenerationForm,
|
||||
imageGenerationSaving,
|
||||
networkSafetyForm,
|
||||
|
||||
Reference in new issue
Block a user