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,7 +1,8 @@
|
||||
import { ProviderIcon } from "@/components/settings/models/ProviderSettings";
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import { useEffect, useRef, useState, type Dispatch, type SetStateAction } from "react";
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
GripVertical,
|
||||
ListOrdered,
|
||||
Loader2,
|
||||
@@ -142,7 +143,7 @@ export function ModelPresetDeleteDialog({
|
||||
<DialogDescription className="leading-5">
|
||||
{tx(
|
||||
"settings.models.deletePresetHelp",
|
||||
"This removes the preset “{{name}}”. Provider credentials are not affected.",
|
||||
"Delete “{{name}}” and remove it from the fallback list. Provider credentials will be kept.",
|
||||
{ name: preset?.name ?? "" },
|
||||
)}
|
||||
</DialogDescription>
|
||||
@@ -227,15 +228,22 @@ export function ModelsSettings({
|
||||
onDeleteConfiguration: (preset: SettingsPayload["model_presets"][number]) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
useAutoSave(form, dirty, saving, onSave, !creating && !!form.model.trim());
|
||||
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
|
||||
t(key, { defaultValue: fallback, ...(values ?? {}) });
|
||||
const [editorOpen, setEditorOpen] = useState(false);
|
||||
const editorTriggerRef = useRef<HTMLElement | null>(null);
|
||||
const presetNameInputRef = useRef<HTMLInputElement>(null);
|
||||
const suggestedPresetNameRef = useRef<string | null>(null);
|
||||
const [editorRowKey, setEditorRowKey] = useState<string | null>(null);
|
||||
const [advancedOpen, setAdvancedOpen] = useState(false);
|
||||
const [draggedCallOrderIndex, setDraggedCallOrderIndex] = useState<number | null>(null);
|
||||
const [dragOverCallOrderIndex, setDragOverCallOrderIndex] = useState<number | null>(null);
|
||||
const [draggedRowHeight, setDraggedRowHeight] = useState(0);
|
||||
const dragStartY = useRef(0);
|
||||
const pendingDrag = useRef<number | null>(null);
|
||||
const suppressDragClick = useRef(false);
|
||||
const [draggedOffset, setDraggedOffset] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (presetNameError) presetNameInputRef.current?.focus();
|
||||
@@ -303,13 +311,14 @@ export function ModelsSettings({
|
||||
form.temperature < 0 ||
|
||||
form.temperature > 2;
|
||||
const selectedPresetReferenced = Boolean(
|
||||
selectedPreset && callOrder.includes(selectedPreset.name),
|
||||
selectedPreset && callOrder[0] === selectedPreset.name,
|
||||
);
|
||||
const callOrderBusy = orderSaving || saving;
|
||||
const selectPreset = (
|
||||
preset: SettingsPayload["model_presets"][number],
|
||||
rowKey: string,
|
||||
) => {
|
||||
editorTriggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
const toggleCurrentPreset =
|
||||
!creating && selectedPreset?.name === preset.name && activeEditorRowKey === rowKey;
|
||||
onSelectConfiguration(preset.name);
|
||||
@@ -372,18 +381,8 @@ export function ModelsSettings({
|
||||
<div
|
||||
id="model-preset-editor"
|
||||
data-testid="model-preset-editor"
|
||||
className={cn(
|
||||
"mx-3 mb-3 divide-y divide-border/45 overflow-hidden rounded-floating border border-border/45 bg-background/80 shadow-sm motion-reduce:animate-none animate-in fade-in-0 slide-in-from-top-1 duration-200 sm:mx-5 lg:mx-auto lg:w-[calc(100%-2.5rem)] lg:max-w-6xl",
|
||||
creating && "mt-3",
|
||||
)}
|
||||
className="space-y-1 pb-4"
|
||||
>
|
||||
{creating ? (
|
||||
<div className="flex min-h-[52px] items-center px-4 py-3 sm:px-5">
|
||||
<span className="text-[13px] font-semibold text-foreground/85">
|
||||
{tx("settings.models.newPreset", "New model preset")}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
<SettingsRow
|
||||
title={tx("settings.models.presetName", "Preset name")}
|
||||
description={tx(
|
||||
@@ -393,7 +392,7 @@ export function ModelsSettings({
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"w-[min(280px,70vw)] motion-reduce:animate-none",
|
||||
"w-full motion-reduce:animate-none",
|
||||
presetNameError && "animate-[preset-name-shake_180ms_ease-in-out]",
|
||||
)}
|
||||
>
|
||||
@@ -411,7 +410,7 @@ export function ModelsSettings({
|
||||
setForm((prev) => ({ ...prev, modelPreset: event.target.value }));
|
||||
}}
|
||||
className={cn(
|
||||
"h-8 rounded-full text-[13px]",
|
||||
"h-9 rounded-full text-[13px]",
|
||||
presetNameError &&
|
||||
"border-destructive/70 focus-visible:border-destructive focus-visible:ring-destructive/25",
|
||||
)}
|
||||
@@ -501,7 +500,7 @@ export function ModelsSettings({
|
||||
type="button"
|
||||
aria-expanded={advancedOpen}
|
||||
onClick={() => setAdvancedOpen((value) => !value)}
|
||||
className="flex min-h-[62px] w-full items-center justify-between gap-4 px-4 py-3.5 text-left transition-colors hover:bg-muted/30 sm:px-5"
|
||||
className="flex min-h-[62px] w-full items-center justify-between gap-4 px-4 py-3.5 text-left transition-colors settings-hover sm:px-5"
|
||||
>
|
||||
<span>
|
||||
<span className="block text-[14px] font-medium text-foreground">
|
||||
@@ -573,7 +572,7 @@ export function ModelsSettings({
|
||||
>
|
||||
{tx(
|
||||
"settings.models.removeBeforeDelete",
|
||||
"Remove this preset from the call order before deleting it.",
|
||||
"Choose another primary preset before deleting this one.",
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
@@ -603,7 +602,7 @@ export function ModelsSettings({
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-7">
|
||||
<div className="settings-stack">
|
||||
<section>
|
||||
<SettingsSectionTitle>
|
||||
{tx("settings.models.presets", "Model presets")}
|
||||
@@ -645,7 +644,7 @@ export function ModelsSettings({
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div role="list" className="divide-y divide-border/45">
|
||||
<div role="list">
|
||||
{presetRows.map(({ key, name, orderIndex, preset }) => {
|
||||
const ordered = orderIndex >= 0;
|
||||
const provider = preset
|
||||
@@ -658,14 +657,13 @@ export function ModelsSettings({
|
||||
preset.resolved_provider,
|
||||
)
|
||||
: true;
|
||||
const isDropTarget =
|
||||
ordered &&
|
||||
dragOverCallOrderIndex === orderIndex &&
|
||||
draggedCallOrderIndex !== orderIndex;
|
||||
const dropAfterTarget =
|
||||
isDropTarget &&
|
||||
draggedCallOrderIndex !== null &&
|
||||
draggedCallOrderIndex < orderIndex;
|
||||
let dragOffset = 0;
|
||||
const isDragging = ordered && draggedCallOrderIndex === orderIndex;
|
||||
if (ordered && draggedCallOrderIndex !== null && dragOverCallOrderIndex !== null) {
|
||||
if (isDragging) dragOffset = draggedOffset;
|
||||
if (orderIndex > draggedCallOrderIndex && orderIndex <= dragOverCallOrderIndex) dragOffset = -draggedRowHeight;
|
||||
if (orderIndex < draggedCallOrderIndex && orderIndex >= dragOverCallOrderIndex) dragOffset = draggedRowHeight;
|
||||
}
|
||||
const isSelected =
|
||||
editorOpen &&
|
||||
!creating &&
|
||||
@@ -674,7 +672,7 @@ export function ModelsSettings({
|
||||
const presetRow = (
|
||||
<div
|
||||
tabIndex={ordered ? 0 : -1}
|
||||
draggable={ordered && !callOrderBusy}
|
||||
onDragStart={(event) => event.preventDefault()}
|
||||
aria-label={
|
||||
ordered
|
||||
? `${name}. ${tx(
|
||||
@@ -684,36 +682,43 @@ export function ModelsSettings({
|
||||
: name
|
||||
}
|
||||
data-testid={`model-call-order-row-${name}`}
|
||||
onDragStart={(event) => {
|
||||
if (!ordered || callOrderBusy) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("text/plain", name);
|
||||
setDraggedCallOrderIndex(orderIndex);
|
||||
setDragOverCallOrderIndex(orderIndex);
|
||||
onPointerDown={(event) => {
|
||||
if (!ordered || callOrderBusy || event.button !== 0 || (event.target as HTMLElement).closest('[role="switch"]')) return;
|
||||
pendingDrag.current = orderIndex;
|
||||
suppressDragClick.current = false;
|
||||
dragStartY.current = event.clientY;
|
||||
setDraggedOffset(0);
|
||||
const wrapper = event.currentTarget.parentElement;
|
||||
setDraggedRowHeight(wrapper?.getBoundingClientRect().height || 60);
|
||||
}}
|
||||
onDragEnd={() => {
|
||||
onPointerMove={(event) => {
|
||||
if (!event.buttons) { pendingDrag.current = null; return; }
|
||||
if (pendingDrag.current !== orderIndex || callOrderBusy) return;
|
||||
const offset = event.clientY - dragStartY.current;
|
||||
if (draggedCallOrderIndex === null && Math.abs(offset) < 5) return;
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
suppressDragClick.current = true;
|
||||
setDraggedCallOrderIndex(orderIndex);
|
||||
const target = Math.max(0, Math.min(callOrder.length - 1, orderIndex + Math.round(offset / draggedRowHeight)));
|
||||
setDragOverCallOrderIndex(target);
|
||||
setDraggedOffset(Math.max(-orderIndex * draggedRowHeight, Math.min((callOrder.length - orderIndex - 1) * draggedRowHeight, offset)));
|
||||
}}
|
||||
onPointerUp={() => {
|
||||
pendingDrag.current = null;
|
||||
if (draggedCallOrderIndex !== null) dropCallOrderItem(dragOverCallOrderIndex ?? orderIndex);
|
||||
}}
|
||||
onPointerCancel={() => {
|
||||
pendingDrag.current = null;
|
||||
setDraggedCallOrderIndex(null);
|
||||
setDragOverCallOrderIndex(null);
|
||||
}}
|
||||
onDragEnter={(event) => {
|
||||
if (ordered && draggedCallOrderIndex !== null) {
|
||||
onClickCapture={(event) => {
|
||||
if (suppressDragClick.current) {
|
||||
event.preventDefault();
|
||||
setDragOverCallOrderIndex(orderIndex);
|
||||
event.stopPropagation();
|
||||
suppressDragClick.current = false;
|
||||
}
|
||||
}}
|
||||
onDragOver={(event) => {
|
||||
if (!ordered || draggedCallOrderIndex === null) return;
|
||||
event.preventDefault();
|
||||
event.dataTransfer.dropEffect = "move";
|
||||
}}
|
||||
onDrop={(event) => {
|
||||
if (!ordered) return;
|
||||
event.preventDefault();
|
||||
dropCallOrderItem(orderIndex);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.currentTarget !== event.target) return;
|
||||
if (ordered && event.key === "ArrowUp") {
|
||||
@@ -728,52 +733,32 @@ export function ModelsSettings({
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"group relative flex min-h-[76px] select-none items-center gap-3 px-4 py-3 outline-none transition-[background-color,opacity] duration-150 sm:px-5",
|
||||
"settings-list-row group relative flex select-none items-center gap-3 py-2 outline-none transition-colors duration-150",
|
||||
ordered &&
|
||||
(callOrderBusy
|
||||
? "cursor-wait"
|
||||
: "cursor-grab active:cursor-grabbing"),
|
||||
"hover:bg-muted/25",
|
||||
isDropTarget &&
|
||||
!dropAfterTarget &&
|
||||
"before:absolute before:inset-x-4 before:top-0 before:z-10 before:h-0.5 before:rounded-full before:bg-foreground sm:before:inset-x-5",
|
||||
isDropTarget &&
|
||||
dropAfterTarget &&
|
||||
"after:absolute after:inset-x-4 after:bottom-0 after:z-10 after:h-0.5 after:rounded-full after:bg-foreground sm:after:inset-x-5",
|
||||
ordered && draggedCallOrderIndex === orderIndex && "opacity-35",
|
||||
isSelected && "bg-muted/45 hover:bg-muted/45",
|
||||
!isDragging && "settings-hover",
|
||||
isDragging && "bg-settings-surface shadow-md",
|
||||
isSelected && "bg-muted/45 settings-hover",
|
||||
"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
{ordered ? (
|
||||
<GripVertical
|
||||
className="pointer-events-none h-4 w-4 shrink-0 text-muted-foreground/40 transition-colors group-hover:text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
) : (
|
||||
<span className="h-4 w-4 shrink-0" aria-hidden />
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={selectedPreset?.name === name}
|
||||
aria-expanded={isSelected}
|
||||
aria-controls={isSelected ? "model-preset-editor" : undefined}
|
||||
aria-haspopup="dialog"
|
||||
disabled={!preset}
|
||||
onClick={() => preset && selectPreset(preset, key)}
|
||||
className="flex min-w-0 flex-1 items-center gap-3 rounded-control text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
{ordered ? (
|
||||
<span className="grid h-7 w-7 shrink-0 place-items-center rounded-full bg-muted font-mono text-[11px] font-semibold tabular-nums text-muted-foreground">
|
||||
{orderIndex + 1}
|
||||
</span>
|
||||
{presetConfigured ? (
|
||||
<ProviderIcon provider={provider} showBrandLogos={showBrandLogos} />
|
||||
) : (
|
||||
<span className="h-7 w-7 shrink-0" aria-hidden />
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center">
|
||||
<ProviderPickerIcon provider={provider} showBrandLogos={showBrandLogos} unconfigured />
|
||||
</span>
|
||||
)}
|
||||
<ProviderPickerIcon
|
||||
provider={provider}
|
||||
showBrandLogos={showBrandLogos}
|
||||
unconfigured={!presetConfigured}
|
||||
/>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span className="truncate text-[14px] font-medium text-foreground">
|
||||
@@ -783,10 +768,6 @@ export function ModelsSettings({
|
||||
<StatusPill tone="success">
|
||||
{tx("settings.models.primary", "Primary")}
|
||||
</StatusPill>
|
||||
) : !ordered ? (
|
||||
<StatusPill tone="neutral">
|
||||
{tx("settings.models.disabled", "Disabled")}
|
||||
</StatusPill>
|
||||
) : null}
|
||||
{!presetConfigured ? (
|
||||
<span className="text-[11px] font-medium text-amber-700 dark:text-amber-300">
|
||||
@@ -797,18 +778,19 @@ export function ModelsSettings({
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="mt-0.5 block truncate text-[12px] text-muted-foreground">
|
||||
{preset?.model ?? name}
|
||||
</span>
|
||||
</span>
|
||||
<ChevronRight
|
||||
className={cn(
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform",
|
||||
isSelected && "rotate-90",
|
||||
)}
|
||||
<span className="shrink-0 px-2 py-1 text-[13px] font-normal leading-5 text-muted-foreground">
|
||||
{t("settings.configure")}
|
||||
</span>
|
||||
</button>
|
||||
{ordered ? (
|
||||
<GripVertical
|
||||
className="h-4 w-4 shrink-0 touch-none text-muted-foreground/40 transition-colors group-hover:text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
) : (
|
||||
<span className="h-4 w-4 shrink-0" aria-hidden />
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
@@ -842,9 +824,11 @@ export function ModelsSettings({
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div key={key} role="listitem">
|
||||
{presetRow}
|
||||
{isSelected ? renderPresetEditor() : null}
|
||||
<div key={key} role="listitem" data-call-order-index={orderIndex}>
|
||||
<div className={cn("relative", isDragging ? "z-10" : "transition-transform duration-150 ease-out motion-reduce:transition-none")}
|
||||
style={{ transform: `translateY(${dragOffset}px)` }}>
|
||||
{presetRow}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -852,16 +836,17 @@ export function ModelsSettings({
|
||||
{!creating ? (
|
||||
<button
|
||||
type="button"
|
||||
className="flex min-h-[58px] w-full items-center justify-between gap-3 px-4 py-3 text-left outline-none transition-colors hover:bg-muted/30 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 sm:px-5"
|
||||
className="flex min-h-[58px] w-full items-center justify-between gap-3 settings-list-inset py-3 text-left outline-none transition-colors settings-hover focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={callOrderBusy}
|
||||
onClick={() => {
|
||||
onClick={(event) => {
|
||||
editorTriggerRef.current = event.currentTarget;
|
||||
setEditorRowKey(null);
|
||||
setEditorOpen(true);
|
||||
onBeginCreate();
|
||||
}}
|
||||
>
|
||||
<span className="inline-flex items-center text-[13px] font-medium">
|
||||
<Plus className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
<span className="inline-flex items-center gap-3 text-[14px] font-medium">
|
||||
<span className="grid w-10 shrink-0 place-items-center"><Plus className="h-5 w-5" aria-hidden /></span>
|
||||
{tx("settings.models.newPreset", "New model preset")}
|
||||
</span>
|
||||
{orderSaving ? (
|
||||
@@ -874,11 +859,26 @@ export function ModelsSettings({
|
||||
) : null}
|
||||
</button>
|
||||
) : null}
|
||||
{creating && editorOpen ? renderPresetEditor() : null}
|
||||
</>
|
||||
)}
|
||||
</SettingsGroup>
|
||||
</section>
|
||||
<Dialog open={editorOpen && (creating || selectedPreset !== null)} onOpenChange={(open) => {
|
||||
setEditorOpen(open);
|
||||
if (!open && creating) onCancelCreate();
|
||||
}}>
|
||||
<DialogContent aria-describedby={undefined}
|
||||
className="relative max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none gap-0 overflow-y-auto p-0"
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
editorTriggerRef.current?.focus();
|
||||
}}>
|
||||
<DialogHeader className="px-6 pb-2 pt-5 pr-12">
|
||||
<DialogTitle>{creating ? tx("settings.models.newPreset", "New model preset") : selectedPreset?.name}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="settings-grid !px-0">{renderPresetEditor()}</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
Loader2,
|
||||
Pencil,
|
||||
Plus,
|
||||
RotateCcw,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -30,6 +29,7 @@ import {
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -381,17 +382,14 @@ function ProviderRequestOptions({
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-floating border border-border/45 bg-background/75">
|
||||
{options.map((option, index) => {
|
||||
{options.map((option) => {
|
||||
const title = tx(option.titleKey, option.title);
|
||||
const Icon = option.kind === "priority" ? Zap : Globe2;
|
||||
const checked = providerRequestOptionEnabled(option, extraBody);
|
||||
return (
|
||||
<div
|
||||
key={option.titleKey}
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-4 px-4 py-3",
|
||||
index > 0 && "border-t border-border/45",
|
||||
)}
|
||||
className="flex items-center justify-between gap-4 rounded-xl px-4 py-3 transition-colors settings-hover focus-within:bg-sidebar-accent/60"
|
||||
>
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
<span className="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted/70 text-muted-foreground">
|
||||
@@ -444,7 +442,7 @@ function ProviderAdvancedOptions({
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="border-y border-border/45">
|
||||
<div className="space-y-1">
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={open}
|
||||
@@ -463,7 +461,7 @@ function ProviderAdvancedOptions({
|
||||
/>
|
||||
</button>
|
||||
{open ? (
|
||||
<div className="border-t border-border/45 py-3">
|
||||
<div className="py-3">
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{enabled.has("api_type") ? (
|
||||
<label className="block space-y-1.5">
|
||||
@@ -504,7 +502,7 @@ function ProviderAdvancedOptions({
|
||||
{enabled.has("thinking_style") ? (
|
||||
<label className="block space-y-1.5">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.providers.thinkingStyle", "Thinking style")}
|
||||
{tx("settings.providers.thinkingStyle", "Reasoning parameter format")}
|
||||
</span>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -575,7 +573,7 @@ function ProviderAdvancedOptions({
|
||||
{enabled.has("profile") ? (
|
||||
<label className="block space-y-1.5">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.providers.profile", "Profile")}
|
||||
{tx("settings.providers.profile", "AWS profile")}
|
||||
</span>
|
||||
<Input
|
||||
value={form.profile}
|
||||
@@ -594,40 +592,31 @@ function ProviderAdvancedOptions({
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.providers.extraHeaders", "Extra headers")}
|
||||
</span>
|
||||
<Textarea
|
||||
value={form.extraHeaders}
|
||||
onChange={(event) => onChange({ extraHeaders: event.target.value })}
|
||||
<SettingsTextEditor title={tx("settings.providers.extraHeaders", "Extra headers")}
|
||||
value={form.extraHeaders} onSave={(value) => onChange({ extraHeaders: value })}
|
||||
placeholder={'{"X-Header":"value"}'}
|
||||
spellCheck={false}
|
||||
className="min-h-[88px] resize-y bg-background font-mono text-[12px]"
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
{enabled.has("extra_query") ? (
|
||||
<label className="block min-w-0 space-y-1.5">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.providers.extraQuery", "Extra query")}
|
||||
{tx("settings.providers.extraQuery", "Additional query parameters")}
|
||||
</span>
|
||||
<Textarea
|
||||
value={form.extraQuery}
|
||||
onChange={(event) => onChange({ extraQuery: event.target.value })}
|
||||
<SettingsTextEditor title={tx("settings.providers.extraQuery", "Additional query parameters")}
|
||||
value={form.extraQuery} onSave={(value) => onChange({ extraQuery: value })}
|
||||
placeholder={'{"api-version":"2024-02-01"}'}
|
||||
spellCheck={false}
|
||||
className="min-h-[88px] resize-y bg-background font-mono text-[12px]"
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
{enabled.has("extra_body") ? (
|
||||
<label className="block min-w-0 space-y-1.5 md:col-span-2">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.providers.extraBody", "Extra body")}
|
||||
{tx("settings.providers.extraBody", "Additional body parameters")}
|
||||
</span>
|
||||
<Textarea
|
||||
value={form.extraBody}
|
||||
onChange={(event) => onChange({ extraBody: event.target.value })}
|
||||
<SettingsTextEditor title={tx("settings.providers.extraBody", "Additional body parameters")}
|
||||
value={form.extraBody} onSave={(value) => onChange({ extraBody: value })}
|
||||
placeholder={'{"service_tier":"priority"}'}
|
||||
spellCheck={false}
|
||||
className="min-h-[96px] resize-y bg-background font-mono text-[12px]"
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
@@ -635,7 +624,7 @@ function ProviderAdvancedOptions({
|
||||
</div>
|
||||
) : null}
|
||||
{footer ? (
|
||||
<div className="flex items-center justify-end gap-2 border-t border-border/45 py-3">
|
||||
<div className="flex items-center justify-end gap-2 py-3">
|
||||
{footer}
|
||||
</div>
|
||||
) : null}
|
||||
@@ -663,9 +652,6 @@ export function ProvidersSettings({
|
||||
onCreateCustomProvider,
|
||||
onProviderOAuthLogin,
|
||||
onProviderOAuthLogout,
|
||||
imageProviderRestartPending,
|
||||
onRestart,
|
||||
isRestarting,
|
||||
}: {
|
||||
settings: SettingsPayload;
|
||||
nanobotFeatures: NanobotFeaturesPayload | null;
|
||||
@@ -686,9 +672,6 @@ export function ProvidersSettings({
|
||||
onCreateCustomProvider: (draft: CustomProviderDraft) => Promise<boolean>;
|
||||
onProviderOAuthLogin: (provider: string) => void;
|
||||
onProviderOAuthLogout: (provider: string) => void;
|
||||
imageProviderRestartPending: boolean;
|
||||
onRestart?: () => void;
|
||||
isRestarting?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
@@ -776,12 +759,14 @@ export function ProvidersSettings({
|
||||
? (nanobotFeatures?.features ?? []).find((feature) => feature.name === supportName)
|
||||
: null;
|
||||
return (
|
||||
<div key={provider.name} className="divide-y divide-border/45">
|
||||
<Dialog key={provider.name} open={expanded} onOpenChange={(open) => {
|
||||
if (open !== expanded) toggleProvider(provider.name);
|
||||
}}>
|
||||
<DialogTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
onClick={() => toggleProvider(provider.name)}
|
||||
className="flex min-h-[70px] w-full items-center justify-between gap-4 px-4 py-3 text-left transition-colors hover:bg-muted/35 sm:px-5"
|
||||
aria-label={provider.label}
|
||||
className="settings-list-row flex w-full items-center justify-between gap-4 py-2.5 text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<ProviderIcon
|
||||
@@ -789,33 +774,26 @@ export function ProvidersSettings({
|
||||
showBrandLogos={showBrandLogos}
|
||||
/>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate text-[15px] font-semibold leading-5 text-foreground">
|
||||
<span className="block truncate text-[14px] font-medium leading-5 text-foreground">
|
||||
{provider.label}
|
||||
</span>
|
||||
{provider.api_base ? (
|
||||
<span className="block truncate text-[12px] text-muted-foreground">
|
||||
{provider.api_base}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="shrink-0 px-2 py-1 text-[13px] font-normal leading-5 text-muted-foreground">
|
||||
{t("settings.configure")}
|
||||
</span>
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
|
||||
{expanded ? (
|
||||
<div className="space-y-3 bg-muted/18 px-4 py-4 sm:px-5">
|
||||
<DialogContent aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto">
|
||||
<DialogHeader><DialogTitle>{provider.label}</DialogTitle></DialogHeader>
|
||||
{supportFeature && !supportFeature.installed ? (
|
||||
<CapabilityInstallNotice
|
||||
title={tx("settings.capabilities.providerSupport", "Provider support")}
|
||||
title={tx("settings.capabilities.providerSupport", "Provider dependencies")}
|
||||
description={tx(
|
||||
"settings.capabilities.providerInstallOnSave",
|
||||
"Required support will be installed automatically when you save this provider.",
|
||||
"Required packages will be installed automatically when you save this provider.",
|
||||
)}
|
||||
installing={featureAction === `enable:${supportName}`}
|
||||
/>
|
||||
@@ -976,7 +954,7 @@ export function ProvidersSettings({
|
||||
? 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 />
|
||||
@@ -996,7 +974,7 @@ export function ProvidersSettings({
|
||||
size="icon"
|
||||
onClick={() => onToggleProviderKeyEditing(provider.name)}
|
||||
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>
|
||||
@@ -1055,31 +1033,16 @@ export function ProvidersSettings({
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
) : null}
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
const customProviderForm = creatingCustomProvider ? (
|
||||
<div className="divide-y divide-border/45">
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded
|
||||
onClick={cancelCustomProviderCreation}
|
||||
className="flex min-h-[70px] w-full items-center justify-between gap-4 px-4 py-3 text-left transition-colors hover:bg-muted/35 sm:px-5"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<ProviderIcon provider="custom" showBrandLogos={showBrandLogos} />
|
||||
<span className="truncate text-[15px] font-semibold text-foreground">
|
||||
{tx("settings.providers.customProvider", "Custom provider")}
|
||||
</span>
|
||||
</span>
|
||||
<ChevronDown
|
||||
className="h-4 w-4 shrink-0 rotate-180 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
<div className="space-y-3 bg-muted/18 px-4 py-4 sm:px-5">
|
||||
<Dialog open onOpenChange={(open) => { if (!open) cancelCustomProviderCreation(); }}>
|
||||
<DialogContent aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto">
|
||||
<DialogHeader><DialogTitle>{tx("settings.providers.customProvider", "Custom provider")}</DialogTitle></DialogHeader>
|
||||
<div className="space-y-3">
|
||||
<label className="block space-y-1.5">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.providers.customProviderName", "Provider name")}
|
||||
@@ -1151,7 +1114,7 @@ export function ProvidersSettings({
|
||||
? 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"
|
||||
>
|
||||
{customProviderKeyVisible ? (
|
||||
<EyeOff className="h-3.5 w-3.5" aria-hidden />
|
||||
@@ -1195,33 +1158,11 @@ export function ProvidersSettings({
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
) : null;
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{imageProviderRestartPending && onRestart ? (
|
||||
<div className="flex min-h-[48px] items-center justify-between gap-3 border-y border-border/55 py-3">
|
||||
<p className="text-[13px] leading-5 text-muted-foreground">
|
||||
{tx("settings.status.imageProviderRestart", "Provider support changed. Restart when ready.")}
|
||||
</p>
|
||||
<div className="shrink-0">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={onRestart}
|
||||
disabled={isRestarting}
|
||||
className="rounded-full"
|
||||
>
|
||||
{isRestarting ? (
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
) : (
|
||||
<RotateCcw className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
)}
|
||||
{isRestarting ? t("app.system.restarting") : t("app.system.restart")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<section>
|
||||
<SettingsSectionTitle>
|
||||
{tx("settings.providers.title", "Model providers")}
|
||||
@@ -1237,13 +1178,13 @@ export function ProvidersSettings({
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="group flex min-h-[70px] w-full items-center justify-between gap-4 px-4 py-3 text-left transition-colors hover:bg-muted/35 sm:px-5"
|
||||
className="group settings-list-row flex w-full items-center justify-between gap-4 py-2.5 text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<span className="grid h-10 w-10 shrink-0 place-items-center rounded-control bg-muted text-muted-foreground">
|
||||
<Plus className="h-5 w-5" aria-hidden />
|
||||
</span>
|
||||
<span className="truncate text-[15px] font-semibold text-foreground">
|
||||
<span className="truncate text-[14px] font-medium text-foreground">
|
||||
{tx(
|
||||
"settings.providers.addOwnProvider",
|
||||
"Add your own model provider",
|
||||
@@ -1319,7 +1260,7 @@ function providerVisibilityRank(provider: SettingsPayload["providers"][number]):
|
||||
return 200;
|
||||
}
|
||||
|
||||
function ProviderIcon({
|
||||
export function ProviderIcon({
|
||||
provider,
|
||||
showBrandLogos,
|
||||
}: {
|
||||
@@ -1334,7 +1275,7 @@ function ProviderIcon({
|
||||
return (
|
||||
<span
|
||||
data-testid={`provider-logo-${provider}`}
|
||||
className="grid h-10 w-10 shrink-0 place-items-center overflow-hidden rounded-control border border-border/45 bg-background"
|
||||
className="grid h-8 w-8 shrink-0 place-items-center overflow-hidden rounded-control border border-border/45 bg-background"
|
||||
>
|
||||
<img
|
||||
src={logoUrl}
|
||||
@@ -1352,7 +1293,7 @@ function ProviderIcon({
|
||||
return (
|
||||
<span
|
||||
data-testid={`provider-logo-fallback-${provider}`}
|
||||
className="grid h-10 w-10 shrink-0 place-items-center rounded-control text-[11px] font-semibold text-white"
|
||||
className="grid h-8 w-8 shrink-0 place-items-center rounded-control text-[11px] font-semibold text-white"
|
||||
style={{ backgroundColor: brand.color }}
|
||||
aria-hidden
|
||||
>
|
||||
@@ -1361,7 +1302,7 @@ function ProviderIcon({
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className="grid h-10 w-10 shrink-0 place-items-center rounded-2xl bg-muted text-foreground/82 dark:bg-muted/70">
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-control bg-muted text-foreground/82 dark:bg-muted/70">
|
||||
<Icon className="h-5 w-5" strokeWidth={2} aria-hidden />
|
||||
</span>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user