Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🎚️ feat: Group Model Parameters Into Sections (#16247)
Marco Berettadd1cb0e5ba42
diff --git a/client/src/components/SidePanel/Parameters/DynamicCheckbox.tsx b/client/src/components/SidePanel/Parameters/DynamicCheckbox.tsxindex 4e04dec854..4af94f8e16 100644--- a/client/src/components/SidePanel/Parameters/DynamicCheckbox.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicCheckbox.tsx@@ -64,7 +64,7 @@ function DynamicCheckbox({>{labelCode ? (localize(label as TranslationKeys) ?? label) : label || settingKey}{' '}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({localize('com_endpoint_default')}:{' '}{defaultValue != null ? localize('com_ui_yes') : localize('com_ui_no')})</small>diff --git a/client/src/components/SidePanel/Parameters/DynamicCombobox.tsx b/client/src/components/SidePanel/Parameters/DynamicCombobox.tsxindex f708b44d18..80d3d1833a 100644--- a/client/src/components/SidePanel/Parameters/DynamicCombobox.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicCombobox.tsx@@ -77,7 +77,7 @@ function DynamicCombobox({)}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2">{showLabel === true && (<div className="flex w-full justify-between"><Label@@ -86,7 +86,7 @@ function DynamicCombobox({>{labelCode ? (localize(label as TranslationKeys) ?? label) : label || settingKey}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({localize('com_endpoint_default')}: {defaultValue})</small>)}diff --git a/client/src/components/SidePanel/Parameters/DynamicDropdown.tsx b/client/src/components/SidePanel/Parameters/DynamicDropdown.tsxindex 95325924f9..c42108be52 100644--- a/client/src/components/SidePanel/Parameters/DynamicDropdown.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicDropdown.tsx@@ -71,7 +71,7 @@ function DynamicDropdown({)}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2">{showLabel === true && (<div className="flex w-full justify-between"><Label@@ -80,7 +80,7 @@ function DynamicDropdown({>{labelCode ? (localize(label as TranslationKeys) ?? label) : label || settingKey}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({localize('com_endpoint_default')}: {defaultValue})</small>)}diff --git a/client/src/components/SidePanel/Parameters/DynamicInput.tsx b/client/src/components/SidePanel/Parameters/DynamicInput.tsxindex 096c8a0313..88f4745f52 100644--- a/client/src/components/SidePanel/Parameters/DynamicInput.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicInput.tsx@@ -170,7 +170,7 @@ function DynamicInput({}`}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2"><div className="flex w-full justify-between"><LabelhtmlFor={`${settingKey}-dynamic-input`}@@ -178,7 +178,7 @@ function DynamicInput({>{labelCode ? localize(label as TranslationKeys) || label : label || settingKey}{' '}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({typeof defaultValue === 'undefined' || !(defaultValue as string).length? localize('com_endpoint_default_blank')@@ -197,7 +197,7 @@ function DynamicInput({onBlur={handleInputBlur}placeholder={placeholderText}className={cn(- 'flex h-9 max-h-9 w-full resize-none rounded-lg border border-border-light bg-surface-secondary px-3 py-2',+ 'border-border-light bg-surface-secondary flex h-9 max-h-9 w-full resize-none rounded-lg border px-3 py-2',)}/></HoverCardTrigger>diff --git a/client/src/components/SidePanel/Parameters/DynamicSlider.tsx b/client/src/components/SidePanel/Parameters/DynamicSlider.tsxindex d4979e04b4..262811ab6c 100644--- a/client/src/components/SidePanel/Parameters/DynamicSlider.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicSlider.tsx@@ -171,15 +171,15 @@ function DynamicSlider({)}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2"><div className="flex w-full items-center justify-between"><LabelhtmlFor={`${settingKey}-dynamic-setting`}- className="break-words text-left text-xs font-medium"+ className="text-left text-xs font-medium break-words">{labelCode ? (localize(label as TranslationKeys) ?? label) : label || settingKey}{' '}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({localize('com_endpoint_default')}: {getDefaultDisplayValue()})</small>)}@@ -202,7 +202,7 @@ function DynamicSlider({defaultTextProps,cn(optionText,- 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 py-1 text-xs group-hover/temp:border-border-light',+ 'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0 py-1 text-xs',),)}/>@@ -217,7 +217,7 @@ function DynamicSlider({defaultTextProps,cn(optionText,- 'reset-rc-number-input h-auto w-14 border-0 py-1 pl-1 text-center text-xs group-hover/temp:border-border-light',+ 'reset-rc-number-input group-hover/temp:border-border-light h-auto w-14 border-0 py-1 pl-1 text-center text-xs',),)}/>diff --git a/client/src/components/SidePanel/Parameters/DynamicSwitch.tsx b/client/src/components/SidePanel/Parameters/DynamicSwitch.tsxindex c9772dc20a..be29309400 100644--- a/client/src/components/SidePanel/Parameters/DynamicSwitch.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicSwitch.tsx@@ -51,15 +51,15 @@ function DynamicSwitch({}`}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2"><div className="flex justify-between"><LabelhtmlFor={`${settingKey}-dynamic-switch`}- className="break-words text-left text-xs font-medium"+ className="text-left text-xs font-medium break-words">{labelCode ? (localize(label as TranslationKeys) ?? label) : label || settingKey}{' '}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({localize('com_endpoint_default')}:{' '}{defaultValue != null ? localize('com_ui_on') : localize('com_ui_off')})</small>diff --git a/client/src/components/SidePanel/Parameters/DynamicTags.tsx b/client/src/components/SidePanel/Parameters/DynamicTags.tsxindex d61ec18ee6..767483e620 100644--- a/client/src/components/SidePanel/Parameters/DynamicTags.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicTags.tsx@@ -106,7 +106,7 @@ function DynamicTags({}`}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2"><div className="flex w-full justify-between"><LabelhtmlFor={`${settingKey}-dynamic-input`}@@ -114,7 +114,7 @@ function DynamicTags({>{labelCode ? (localize(label as TranslationKeys) ?? label) : label || settingKey}{' '}{showDefault && (- <small className="opacity-40 high-contrast:opacity-100">+ <small className="high-contrast:opacity-100 opacity-40">({typeof defaultValue === 'undefined' || !(defaultValue as string).length? localize('com_endpoint_default_blank')@@ -125,7 +125,7 @@ function DynamicTags({</Label></div><div>- <div className="mb-2 flex flex-wrap break-all rounded-lg border border-border-light bg-surface-secondary">+ <div className="border-border-light bg-surface-secondary flex flex-wrap rounded-lg border break-all">{currentTags && currentTags.length > 0 && (<div className="flex w-full gap-1 p-1">{currentTags.map((tag: string, index: number) => (@@ -166,7 +166,7 @@ function DynamicTags({? (localize(placeholder as TranslationKeys) ?? placeholder): placeholder}- className={cn('flex h-9 max-h-9 border-none bg-surface-secondary px-3 py-2')}+ className={cn('bg-surface-secondary flex h-9 max-h-9 border-none px-3 py-2')}/></div></div>diff --git a/client/src/components/SidePanel/Parameters/DynamicTextarea.tsx b/client/src/components/SidePanel/Parameters/DynamicTextarea.tsxindex df54972adf..a673c9a0e0 100644--- a/client/src/components/SidePanel/Parameters/DynamicTextarea.tsx+++ b/client/src/components/SidePanel/Parameters/DynamicTextarea.tsx@@ -54,7 +54,7 @@ function DynamicTextarea({}`}><HoverCard openDelay={300}>- <HoverCardTrigger className="grid w-full items-center gap-2">+ <HoverCardTrigger className="grid h-full w-full content-between items-center gap-2"><div className="flex w-full justify-between"><LabelhtmlFor={`${settingKey}-dynamic-textarea`}@@ -75,6 +75,12 @@ function DynamicTextarea({<TextareaAutosizefocusOutline="hidden"id={`${settingKey}-dynamic-textarea`}+ /** The field is measured by a shadow copy of itself, and the panel mounts+ * before the sidebar has settled on a width, so that measurement can come+ * back as one word per line. Capping the rows lets the library clamp its+ * own answer instead of leaving a CSS max-height to hide a wrong one. */+ minRows={3}+ maxRows={8}disabled={readonly}value={inputValue ?? ''}onChange={setInputValue}@@ -88,7 +94,7 @@ function DynamicTextarea({: placeholder}className={cn(- 'border-border-light bg-surface-secondary flex max-h-[138px] min-h-[100px] w-full resize-none rounded-lg border px-3 py-2 text-sm',+ 'border-border-light bg-surface-secondary flex max-h-[220px] min-h-[76px] w-full resize-none rounded-lg border px-3 py-2 text-sm',)}/></HoverCardTrigger>diff --git a/client/src/components/SidePanel/Parameters/OptionHover.tsx b/client/src/components/SidePanel/Parameters/OptionHover.tsxindex be23d66297..d995ce6c88 100644--- a/client/src/components/SidePanel/Parameters/OptionHover.tsx+++ b/client/src/components/SidePanel/Parameters/OptionHover.tsx@@ -29,7 +29,7 @@ function OptionHover({<HoverCardPortal><HoverCardContent side={side} className={`z-[999] w-80 ${className}`} sideOffset={sideOffset}><div className="space-y-2">- <p className="whitespace-pre-wrap text-sm text-text-secondary">{text}</p>+ <p className="text-text-secondary text-sm whitespace-pre-wrap">{text}</p></div></HoverCardContent></HoverCardPortal>diff --git a/client/src/components/SidePanel/Parameters/Panel.tsx b/client/src/components/SidePanel/Parameters/Panel.tsxindex a9b7b0cf6b..2a0e98b27c 100644--- a/client/src/components/SidePanel/Parameters/Panel.tsx+++ b/client/src/components/SidePanel/Parameters/Panel.tsx@@ -1,4 +1,4 @@-import React, { useMemo, useState, useEffect, useCallback } from 'react';+import React, { useId, useMemo, useState, useEffect, useCallback } from 'react';import keyBy from 'lodash/keyBy';import { RotateCcw } from 'lucide-react';import { Button } from '@librechat/client';@@ -14,6 +14,7 @@ import {resolveDropParamsUIKeys,} from 'librechat-data-provider';import type { TPreset } from 'librechat-data-provider';+import { groupParameters, countModified, hasControl, isWideParameter } from './groups';import { useGetEndpointsQuery, useGetStartupConfig } from '~/data-provider';import { useChatContext, useLiveAnnouncer } from '~/Providers';import { SaveAsPresetDialog } from '~/components/Endpoints';@@ -22,6 +23,7 @@ import { componentMapping } from './components';import { logger, cn } from '~/utils';export default function Parameters() {+ const panelId = useId();const localize = useLocalize();const { data: startupConfig } = useGetStartupConfig();const { conversation, setConversation } = useChatContext();@@ -164,6 +166,23 @@ export default function Parameters() {setResetCount((count) => count + 1);}, [setConversation, announcePolite, localize]);+ /** Region choices come from the deployment, so they are filled in before grouping,+ * and a control left with nothing to render is dropped there too: a section is+ * built only from controls that show something. */+ const sections = useMemo(+ () =>+ groupParameters(+ visibleParameters+ .map((setting) =>+ setting.key === 'region' && bedrockRegions.length > 0+ ? { ...setting, options: bedrockRegions }+ : setting,+ )+ .filter((setting) => componentMapping[setting.component] != null && hasControl(setting)),+ ),+ [visibleParameters, bedrockRegions],+ );+const openDialog = useCallback(() => {const newPreset = tConvoUpdateSchema.parse({...conversation,@@ -177,57 +196,103 @@ export default function Parameters() {}return (- <div className="h-auto max-w-full px-3 pb-3 pt-2">- <div className="grid grid-cols-2 gap-4">- {' '}- {/* This is the parent element containing all settings */}- {/* Below is an example of an applied dynamic setting, each be contained by a div with the column span specified */}- {visibleParameters.map((setting) => {- const Component = componentMapping[setting.component];- if (!Component) {- return null;- }- const { key, default: defaultValue, ...rest } = setting;-- if (key === 'region' && bedrockRegions.length) {- rest.options = bedrockRegions;- }-- return (- <Component- key={key}- settingKey={key}- defaultValue={defaultValue}- {...rest}- setOption={setOption}- conversation={conversation}- />- );- })}- </div>- <div className="mt-4 flex justify-center">+ <div className="h-auto max-w-full px-3 pt-1 pb-3">+ {/* Every parameter this model can act on is on screen. A disclosure would+ trade the one thing a settings panel is for, seeing the current state at a+ glance, for vertical space that pairing and quieter headings give back+ anyway. */}+ {sections.map((section) => {+ const changed = countModified(section.settings, conversation);+ const headingId = `${panelId}-${section.id}`;++ return (+ <section key={section.id} aria-labelledby={headingId} className="pt-4 first:pt-0">+ <h3+ id={headingId}+ className="text-text-secondary mb-2 flex items-center gap-1.5 text-xs font-semibold tracking-wide uppercase"+ >+ <span className="truncate">{localize(section.label)}</span>+ {/* Where this conversation's own answers are, which is what the owner+ scans for before reaching for Reset. */}+ {changed > 0 && (+ <>+ <span+ aria-hidden="true"+ className="bg-surface-tertiary text-text-primary shrink-0 rounded-full px-1.5 text-xs font-normal tracking-normal normal-case tabular-nums"+ >+ {changed}+ </span>+ <span className="sr-only">+ {localize(+ changed === 1+ ? 'com_ui_params_changed_count_one'+ : 'com_ui_params_changed_count',+ { count: changed },+ )}+ </span>+ </>+ )}+ </h3>+ <div className="grid grid-cols-2 gap-x-3 gap-y-2.5">+ {section.settings.map((setting) => {+ const Component = componentMapping[setting.component];+ if (!Component) {+ return null;+ }+ const { key, default: defaultValue, ...rest } = setting;++ /** The cell owns the span, not the control. The definitions carry a+ * columnSpan written for the four-column preset dialog, which says+ * nothing about a panel this narrow. */+ /** The cell stretches its control to the row, so a pair whose labels+ * wrap differently still lines their inputs up. Applied here rather+ * than in the shared controls, which the preset editors reuse. */+ return (+ <div+ key={key}+ className={cn(+ '*:h-full',+ isWideParameter(setting) ? 'col-span-2' : 'col-span-1',+ )}+ >+ <Component+ settingKey={key}+ defaultValue={defaultValue}+ {...rest}+ setOption={setOption}+ conversation={conversation}+ />+ </div>+ );+ })}+ </div>+ </section>+ );+ })}+ {/* The two share a row while their labels fit, stack when a translation is too+ long for the panel, and a label longer than the panel itself wraps. */}+ <div className="mt-5 flex flex-wrap gap-2"><Buttonvariant="outline"type="button"onClick={resetParameters}- className="flex w-full items-center justify-center gap-2 px-4 py-2 text-sm active:scale-[0.98] motion-reduce:transform-none"+ aria-label={localize('com_ui_reset_var', { 0: localize('com_ui_model_parameters') })}+ className="flex h-auto min-h-9 flex-auto items-center justify-center gap-2 px-4 py-2 text-sm whitespace-normal active:scale-[0.98] motion-reduce:transform-none"><RotateCcwkey={resetCount}className={cn(- 'h-4 w-4 motion-reduce:animate-none',+ 'h-4 w-4 shrink-0 motion-reduce:animate-none',resetCount > 0 && 'animate-reset-spin',)}aria-hidden="true"/>- {localize('com_ui_reset_var', { 0: localize('com_ui_model_parameters') })}+ {localize('com_ui_reset')}</Button>- </div>- <div className="mt-2 flex justify-center"><Buttonvariant="default"onClick={openDialog}- className="flex w-full items-center justify-center px-4 py-2 font-semibold"+ className="flex h-auto min-h-9 flex-auto items-center justify-center px-4 py-2 font-semibold whitespace-normal"type="button">{localize('com_endpoint_save_as_preset')}diff --git a/client/src/components/SidePanel/Parameters/__tests__/groups.spec.ts b/client/src/components/SidePanel/Parameters/__tests__/groups.spec.tsnew file mode 100644index 0000000000..80ff81542a--- /dev/null+++ b/client/src/components/SidePanel/Parameters/__tests__/groups.spec.ts@@ -0,0 +1,203 @@+import { ComponentTypes } from 'librechat-data-provider';+import type { SettingDefinition } from 'librechat-data-provider';+import { countModified, groupParameters, hasControl, isModified, isWideParameter } from '../groups';++const setting = (key: string, over: Partial<SettingDefinition> = {}): SettingDefinition =>+ ({ key, type: 'number', component: 'slider', ...over }) as SettingDefinition;++describe('groupParameters', () => {+ it('files each parameter under the question it answers', () => {+ const sections = groupParameters([+ setting('temperature'),+ setting('promptPrefix'),+ setting('web_search'),+ setting('maxContextTokens'),+ ]);++ expect(sections.map((section) => section.id)).toEqual([+ 'identity',+ 'sampling',+ 'limits',+ 'context',+ ]);+ });++ /** The panel is narrow and endpoints differ wildly: a heading for a section this+ * model has nothing in is a row of nothing. */+ it('leaves out the sections this endpoint has no parameters for', () => {+ const sections = groupParameters([setting('temperature')]);++ expect(sections).toHaveLength(1);+ expect(sections[0].settings.map((s) => s.key)).toEqual(['temperature']);+ });++ /** A deployment can define its own parameters through `customParams`. Filing them+ * under a guessed heading would misdescribe them; dropping them would hide a+ * control the operator deliberately added. */+ it('keeps a parameter it has never heard of, in the last section', () => {+ const sections = groupParameters([setting('temperature'), setting('house_style')]);++ expect(sections.at(-1)).toMatchObject({ id: 'other' });+ expect(sections.at(-1)?.settings.map((s) => s.key)).toEqual(['house_style']);+ });++ /** Two narrow controls share a row, so a full-width one in the middle would break+ * the pair on either side of it. */+ it('packs the narrow parameters before the wide ones', () => {+ const [limits] = groupParameters([+ setting('maxContextTokens', { type: 'number', component: 'input' }),+ setting('stop', { type: 'array', component: 'tags' }),+ setting('fileTokenLimit', { type: 'number', component: 'input' }),+ ]);++ expect(limits.settings.map((s) => s.key)).toEqual([+ 'maxContextTokens',+ 'fileTokenLimit',+ 'stop',+ ]);+ });++ it("keeps the provider's own order inside a section", () => {+ const [sampling] = groupParameters([+ setting('presence_penalty'),+ setting('temperature'),+ setting('top_p'),+ ]);++ expect(sampling.settings.map((s) => s.key)).toEqual([+ 'presence_penalty',+ 'temperature',+ 'top_p',+ ]);+ });++ it('survives a null in the definitions', () => {+ const sections = groupParameters([+ setting('temperature'),+ null as unknown as SettingDefinition,+ ]);++ expect(sections).toHaveLength(1);+ });+});++describe('isModified', () => {+ const temperature = setting('temperature', { default: 1 });++ it('reads an absent value as untouched', () => {+ expect(isModified(temperature, {})).toBe(false);+ expect(isModified(temperature, null)).toBe(false);+ });++ /** The count tells the owner where their changes are, so a value that merely+ * restates the default is not one. */+ it('reads a value equal to the default as untouched', () => {+ expect(isModified(temperature, { temperature: 1 })).toBe(false);+ });++ it('counts a value that differs', () => {+ expect(isModified(temperature, { temperature: 0.2 })).toBe(true);+ });++ it('treats an empty string and an empty list as nothing said', () => {+ expect(isModified(setting('promptPrefix', { type: 'string' }), { promptPrefix: '' })).toBe(+ false,+ );+ expect(isModified(setting('stop', { type: 'array', default: [] }), { stop: [] })).toBe(false);+ });++ it('compares a list by its contents', () => {+ const stop = setting('stop', { type: 'array', default: [] });++ expect(isModified(stop, { stop: ['###'] })).toBe(true);+ });++ it('counts only what changed', () => {+ const settings = [temperature, setting('top_p', { default: 1 })];++ expect(countModified(settings, { temperature: 0.2, top_p: 1 })).toBe(1);+ expect(countModified(settings, {})).toBe(0);+ });+});++describe('isModified with an operator default', () => {+ /** A deployment can give a text or tags parameter its own default, and clearing it is+ * a change this conversation made. */+ it('counts clearing a nonempty default as a change', () => {+ expect(isModified(setting('promptPrefix', { default: 'Be brief' }), { promptPrefix: '' })).toBe(+ true,+ );+ expect(isModified(setting('stop', { default: ['END'] }), { stop: [] })).toBe(true);+ });++ it('leaves an empty value untouched when the default is empty too', () => {+ expect(isModified(setting('promptPrefix'), { promptPrefix: '' })).toBe(false);+ expect(isModified(setting('stop', { default: [] }), { stop: [] })).toBe(false);+ expect(isModified(setting('promptPrefix', { default: 'Be brief' }), {})).toBe(false);+ });+});++describe('hasControl', () => {+ it('keeps a choice with options to pick from', () => {+ expect(+ hasControl(setting('region', { component: ComponentTypes.Combobox, options: ['us-east-1'] })),+ ).toBe(true);+ expect(+ hasControl(+ setting('imageDetail', { component: ComponentTypes.Dropdown, options: ['auto', 'low'] }),+ ),+ ).toBe(true);+ });++ /** Bedrock's region lists nothing of its own and takes the deployment's regions, so+ * with none configured its combobox renders nothing. */+ it('drops a choice with nothing to choose', () => {+ expect(hasControl(setting('region', { component: ComponentTypes.Combobox }))).toBe(false);+ expect(+ hasControl(setting('imageDetail', { component: ComponentTypes.Dropdown, options: [] })),+ ).toBe(false);+ });++ it('keeps every other kind of control', () => {+ expect(hasControl(setting('temperature', { component: ComponentTypes.Slider }))).toBe(true);+ });++ it('leaves no section standing around a dropped control', () => {+ const settings = [+ setting('temperature'),+ setting('region', { component: ComponentTypes.Combobox }),+ ].filter(hasControl);++ expect(groupParameters(settings).map((section) => section.id)).toEqual(['sampling']);+ });+});++describe('isWideParameter', () => {+ /** A system prompt, a name and a stop list are read back as text, and half of a+ * 300px panel is a peephole for any of them. */+ it('gives the whole row to free text', () => {+ expect(+ isWideParameter(setting('promptPrefix', { type: 'string', component: 'textarea' })),+ ).toBe(true);+ expect(isWideParameter(setting('modelLabel', { type: 'string', component: 'input' }))).toBe(+ true,+ );+ expect(isWideParameter(setting('stop', { type: 'array', component: 'tags' }))).toBe(true);+ });++ /** Pairing these is the whole reason the panel fits with nothing collapsed. */+ it('keeps a number, a toggle and a choice in one column', () => {+ expect(+ isWideParameter(setting('maxContextTokens', { type: 'number', component: 'input' })),+ ).toBe(false);+ expect(isWideParameter(setting('resendFiles', { type: 'boolean', component: 'switch' }))).toBe(+ false,+ );+ expect(isWideParameter(setting('temperature', { type: 'number', component: 'slider' }))).toBe(+ false,+ );+ expect(+ isWideParameter(setting('promptCacheTtl', { type: 'string', component: 'combobox' })),+ ).toBe(false);+ });+});diff --git a/client/src/components/SidePanel/Parameters/groups.ts b/client/src/components/SidePanel/Parameters/groups.tsnew file mode 100644index 0000000000..71b8abf101--- /dev/null+++ b/client/src/components/SidePanel/Parameters/groups.ts@@ -0,0 +1,197 @@+import { ComponentTypes, SettingTypes } from 'librechat-data-provider';+import type { SettingDefinition, TConversation, TPreset } from 'librechat-data-provider';+import type { TranslationKeys } from '~/hooks';++export interface ParameterSection {+ id: string;+ label: TranslationKeys;+ settings: SettingDefinition[];+}++/**+ * The panel's order of questions, rather than the order the definitions happen to+ * arrive in.+ *+ * A provider hands over a flat list built for its API, so a panel that renders it+ * as-is asks about temperature, then reasoning, then whether to resend files, with+ * nothing to say which of those belong together. Grouping is the client's job+ * because it is a reading order, not part of the contract: the same key means the+ * same thing wherever it appears, so one map serves every endpoint.+ *+ * Keys are listed per section rather than matched by prefix. A provider is free to+ * name a parameter anything, and a wrong guess would file it under a heading that+ * misdescribes it; an unknown key falls to the last section instead, where it is+ * still visible and still editable.+ */+const SECTIONS: ReadonlyArray<{ id: string; label: TranslationKeys; keys: readonly string[] }> = [+ {+ id: 'identity',+ label: 'com_ui_params_identity',+ keys: ['chatGptLabel', 'modelLabel', 'promptPrefix', 'system'],+ },+ {+ id: 'sampling',+ label: 'com_ui_params_sampling',+ keys: ['temperature', 'topP', 'top_p', 'topK', 'frequency_penalty', 'presence_penalty'],+ },+ {+ id: 'limits',+ label: 'com_ui_params_limits',+ keys: [+ 'maxContextTokens',+ 'max_tokens',+ 'maxOutputTokens',+ 'maxTokens',+ 'fileTokenLimit',+ 'stop',+ ],+ },+ {+ id: 'reasoning',+ label: 'com_ui_params_reasoning',+ keys: [+ 'effort',+ 'reasoning_effort',+ 'reasoning_mode',+ 'reasoning_summary',+ 'reasoning_context',+ 'thinking',+ 'thinkingBudget',+ 'thinkingDisplay',+ 'thinkingLevel',+ 'verbosity',+ ],+ },+ {+ id: 'context',+ label: 'com_ui_context',+ keys: [+ 'resendFiles',+ 'imageDetail',+ 'promptCache',+ 'promptCacheTtl',+ 'web_search',+ 'url_context',+ ],+ },+ {+ id: 'advanced',+ label: 'com_ui_advanced',+ keys: ['useResponsesApi', 'disableStreaming', 'region', 'model'],+ },+ /** Everything a deployment added that this map has never heard of. */+ { id: 'other', label: 'com_ui_misc', keys: [] },+];++const SECTION_BY_KEY = new Map<string, string>(+ SECTIONS.flatMap((section) => section.keys.map((key) => [key, section.id] as const)),+);++/**+ * Whether a parameter needs the whole row rather than one of the two columns.+ *+ * Free text is the only thing in the panel that is read back as text: a system+ * prompt, a custom name, a list of stop sequences. Half of a 300px panel turns+ * those into a peephole. A number, a toggle or a choice says the same thing in a+ * narrow column as in a wide one, so two of them cost one row instead of two,+ * which is the whole reason the panel fits without hiding anything.+ */+export function isWideParameter(setting: SettingDefinition): boolean {+ if (setting.component === ComponentTypes.Textarea || setting.component === ComponentTypes.Tags) {+ return true;+ }+ return setting.component === ComponentTypes.Input && setting.type !== SettingTypes.Number;+}++/**+ * Files the parameters under their headings, keeping each provider's own order+ * inside a section and dropping the sections this endpoint has nothing for.+ *+ * Within a section the narrow parameters come first. They sit two to a row, so a+ * full-width one landing between them breaks the pairs on either side and leaves a+ * gap beside whatever follows it. Sending the wide ones to the end of their own+ * section packs the columns and leaves a single ragged edge at the bottom.+ */+export function groupParameters(parameters: SettingDefinition[]): ParameterSection[] {+ const bySection = new Map<string, SettingDefinition[]>();+ for (const setting of parameters) {+ if (setting == null) {+ continue;+ }+ const id = SECTION_BY_KEY.get(setting.key) ?? 'other';+ const existing = bySection.get(id);+ if (existing) {+ existing.push(setting);+ continue;+ }+ bySection.set(id, [setting]);+ }++ const sections: ParameterSection[] = [];+ for (const section of SECTIONS) {+ const settings = bySection.get(section.id);+ if (settings != null && settings.length > 0) {+ sections.push({+ id: section.id,+ label: section.label,+ settings: [+ ...settings.filter((setting) => !isWideParameter(setting)),+ ...settings.filter(isWideParameter),+ ],+ });+ }+ }+ return sections;+}++/**+ * Whether a parameter's control has anything to show. A combobox or dropdown with no+ * choices renders nothing, which Bedrock's region does when the deployment lists no+ * regions; dropping it before grouping keeps a section from standing empty around it.+ */+export function hasControl(setting: SettingDefinition): boolean {+ if (+ setting.component !== ComponentTypes.Combobox &&+ setting.component !== ComponentTypes.Dropdown+ ) {+ return true;+ }+ return (setting.items?.length ?? 0) > 0 || (setting.options?.length ?? 0) > 0;+}++/**+ * Whether this conversation says something about a parameter that its default does+ * not already say. It is what the panel counts to tell the owner where their changes+ * are, so an absent value and a value equal to the default both read as untouched.+ */+export function isModified(+ setting: SettingDefinition,+ conversation: Partial<TConversation> | Partial<TPreset> | null,+): boolean {+ const value = conversation?.[setting.key as keyof typeof conversation];+ if (value == null) {+ return false;+ }+ const fallback = setting.default;+ /** Clearing a field reads as untouched only when there was nothing to clear. */+ if (value === '') {+ return fallback != null && fallback !== '';+ }+ if (Array.isArray(value)) {+ if (value.length === 0) {+ return Array.isArray(fallback) && fallback.length > 0;+ }+ return JSON.stringify(value) !== JSON.stringify(fallback);+ }+ return value !== fallback;+}++export function countModified(+ settings: SettingDefinition[],+ conversation: Partial<TConversation> | Partial<TPreset> | null,+): number {+ return settings.reduce(+ (count, setting) => (isModified(setting, conversation) ? count + 1 : count),+ 0,+ );+}diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.jsonindex a40384abdc..eb0d4d67fe 100644--- a/client/src/locales/en/translation.json+++ b/client/src/locales/en/translation.json@@ -2033,6 +2033,12 @@"com_ui_output": "Output","com_ui_page": "Page","com_ui_parameters": "Parameters",+ "com_ui_params_changed_count": "{{count}} changed settings",+ "com_ui_params_changed_count_one": "{{count}} changed setting",+ "com_ui_params_identity": "Identity",+ "com_ui_params_limits": "Limits",+ "com_ui_params_reasoning": "Reasoning",+ "com_ui_params_sampling": "Sampling","com_ui_passkey_add": "Add passkey","com_ui_passkey_added": "Passkey added","com_ui_passkey_added_on": "Added {{date}}",diff --git a/e2e/specs/mock/scenarios/grouped-model-params.spec.ts b/e2e/specs/mock/scenarios/grouped-model-params.spec.tsnew file mode 100644index 0000000000..6a5e472f48--- /dev/null+++ b/e2e/specs/mock/scenarios/grouped-model-params.spec.ts@@ -0,0 +1,167 @@+import { randomUUID } from 'node:crypto';+import { expect, test } from '@playwright/test';+import type { Page } from '@playwright/test';+import { MOCK_ENDPOINTS, NEW_CHAT_PATH, selectMockEndpoint } from '../helpers';+import type { MockEndpoint } from '../helpers';+import { openPanel } from './panels';+import { withMongo } from '../db';++/** Mock Provider A takes Anthropic's parameter set, which carries the thinking and+ * prompt cache controls this panel groups. */+async function openParameters(+ page: Page,+ endpoint: MockEndpoint = MOCK_ENDPOINTS[0],+): Promise<void> {+ await page.goto(NEW_CHAT_PATH, { timeout: 10000 });+ await selectMockEndpoint(page, endpoint);+ await openPanel(page, 'parameters', 'Parameters');+ await expect(page.getByRole('region', { name: 'Sampling' })).toBeVisible();+}++test.describe('grouped model parameters', () => {+ test('the parameters are filed under headings that count what this chat changed @scenario:params-grouped-with-change-count', async ({+ page,+ }) => {+ await openParameters(page);++ const reasoning = page.getByRole('region', { name: 'Reasoning' });+ await expect(reasoning).toBeVisible();+ await expect(page.getByRole('region', { name: 'Context' })).toBeVisible();+ await expect(reasoning.getByRole('switch', { name: /Thinking/ }).first()).toBeVisible();+ await expect(reasoning.getByText(/^\d+$/)).toHaveCount(0);++ await reasoning+ .getByRole('switch', { name: /^Thinking/ })+ .first()+ .click();+ await expect(reasoning.getByText(/^1$/)).toBeVisible();+ /* The numeral is decoration; the heading says what it counts. */+ await expect(page.getByRole('region', { name: 'Reasoning 1 changed setting' })).toBeVisible();+ });++ test('a parameter stays on screen when the toggle it works with is off @scenario:params-stay-visible-when-companion-off', async ({+ page,+ }) => {+ await openParameters(page);++ const reasoning = page.getByRole('region', { name: 'Reasoning' });+ const thinking = reasoning.getByRole('switch', { name: /^Thinking/ }).first();+ await expect(thinking).toHaveAttribute('aria-checked', 'true');+ await thinking.click();+ await expect(thinking).toHaveAttribute('aria-checked', 'false');++ await expect(reasoning.getByText('Thinking Budget')).toBeVisible();+ });++ test('the preset editor keeps each label beside its control @scenario:preset-dialog-controls-keep-labels-close', async ({+ page,+ }) => {+ /* The harness defines model specs, which turn the presets menu off; the editor that+ * reuses these controls sits behind it. */+ await page.route(+ (url) => url.pathname === '/api/config',+ async (route) => {+ const response = await route.fetch();+ const body = await response.json();+ await route.fulfill({+ response,+ json: { ...body, interface: { ...body.interface, presets: true, modelSelect: true } },+ });+ },+ );+ const title = `Params preset ${randomUUID().slice(0, 8)}`;+ try {+ /* Mock Provider B is a plain custom endpoint, so its preset editor is the OpenAI+ * one, whose left column holds far fewer controls than its right. */+ await openParameters(page, MOCK_ENDPOINTS[1]);+ await page.getByRole('button', { name: 'Save As Preset' }).click();+ const saveDialog = page.getByRole('dialog');+ await saveDialog.getByRole('textbox').first().fill(title);+ await saveDialog.getByRole('button', { name: 'Save' }).click();+ await expect(saveDialog).toBeHidden();++ /* On a phone the drawer holding the panel covers the header's presets button. */+ if ((page.viewportSize()?.width ?? 1280) < 768) {+ await page.getByTestId('close-sidebar-button').click();+ }+ await page.getByTestId('presets-button').first().click();+ const presets = page.getByRole('dialog', { name: 'Presets' });+ const item = presets.getByRole('button', { name: new RegExp(`^${title}`) });+ /* Each run has its own database, so this preset is the only one listed. */+ await item.hover();+ await presets.getByRole('button', { name: 'Edit' }).first().click();+ const editor = page.getByRole('dialog').filter({ has: page.getByRole('slider') });+ await expect(editor.getByRole('slider').first()).toBeVisible();++ /* A control stretched to its column's height would push its field far below its+ * label. */+ /* Each control's label and field share one hover card trigger; the field is its+ * last child, whatever kind of control it is. */+ const gaps = await editor.evaluate((element) =>+ Array.from(element.querySelectorAll('label'))+ .map((label) => {+ const trigger = label.closest('[data-state]');+ const field = trigger?.lastElementChild;+ if (trigger == null || field == null || field.contains(label)) {+ return null;+ }+ return {+ label: label.textContent,+ gap: field.getBoundingClientRect().top - label.getBoundingClientRect().bottom,+ };+ })+ .filter((entry) => entry != null),+ );+ expect(gaps.length, JSON.stringify(gaps)).toBeGreaterThan(3);+ for (const entry of gaps) {+ expect(entry?.gap, JSON.stringify(entry)).toBeLessThan(48);+ }+ } finally {+ await withMongo((db) => db.collection('presets').deleteMany({ title }));+ }+ });++ test('Reset and Save As Preset stay inside the panel in a language with long labels @scenario:params-actions-fit-long-labels', async ({+ page,+ }) => {+ /* The endpoint is chosen in English, where the model selector's label is known,+ * and the chat keeps it across the reload into Spanish. */+ await openParameters(page);+ await page.evaluate(() => window.localStorage.setItem('lang', 'es-ES'));+ await page.reload();+ /* The shared sidebar helpers read English labels, so the Spanish shell is driven+ * by its own. */+ if ((page.viewportSize()?.width ?? 1280) < 768) {+ await page.getByRole('button', { name: 'Abrir barra lateral' }).first().click();+ await page.getByTestId('panel-switcher-button').click();+ await page.getByRole('menuitemcheckbox', { name: 'Parámetros', exact: true }).click();+ } else {+ const trigger = page.getByTestId('nav-panel-parameters');+ if ((await trigger.getAttribute('aria-pressed')) !== 'true') {+ await trigger.click();+ }+ }+ const save = page.getByRole('button', { name: 'Guardar como configuración preestablecida' });+ await expect(save).toBeVisible();++ /* The finding is the action row running past the panel, so the row and the+ * button's own label are what is measured. */+ const row = save.locator('xpath=..');+ const measured = await row.evaluate((element) => {+ const button = element.lastElementChild as HTMLElement;+ const panel = element.parentElement as HTMLElement;+ const rowBox = element.getBoundingClientRect();+ const panelBox = panel.getBoundingClientRect();+ return {+ rowScroll: element.scrollWidth,+ rowClient: element.clientWidth,+ buttonScroll: button.scrollWidth,+ buttonClient: button.clientWidth,+ rowRight: rowBox.right,+ panelRight: panelBox.right,+ };+ });+ expect(measured.rowScroll, JSON.stringify(measured)).toBeLessThanOrEqual(measured.rowClient);+ expect(measured.rowRight, JSON.stringify(measured)).toBeLessThanOrEqual(measured.panelRight);+ });+});