diff --git a/tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettings.svelte b/tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettings.svelte index e87a94f8ca..7b52a992f3 100644 --- a/tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettings.svelte +++ b/tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettings.svelte @@ -22,6 +22,7 @@ import { setMode } from 'mode-watcher'; import { ColorMode } from '$lib/enums/ui'; import type { Component } from 'svelte'; + import { NUMERIC_FIELDS, POSITIVE_INTEGER_FIELDS } from '$lib/constants/settings-fields'; interface Props { onSave?: () => void; @@ -342,44 +343,18 @@ // Convert numeric strings to numbers for numeric fields const processedConfig = { ...localConfig }; - const numericFields = [ - 'temperature', - 'top_k', - 'top_p', - 'min_p', - 'max_tokens', - 'pasteLongTextToFileLen', - 'dynatemp_range', - 'dynatemp_exponent', - 'typ_p', - 'xtc_probability', - 'xtc_threshold', - 'repeat_last_n', - 'repeat_penalty', - 'presence_penalty', - 'frequency_penalty', - 'dry_multiplier', - 'dry_base', - 'dry_allowed_length', - 'dry_penalty_last_n', - 'agenticMaxTurns', - 'agenticMaxToolPreviewLines' - ]; - const positiveIntegerFields = ['agenticMaxTurns', 'agenticMaxToolPreviewLines']; - - for (const field of numericFields) { + for (const field of NUMERIC_FIELDS) { if (processedConfig[field] !== undefined && processedConfig[field] !== '') { const numValue = Number(processedConfig[field]); if (!isNaN(numValue)) { - if (positiveIntegerFields.includes(field)) { + if ((POSITIVE_INTEGER_FIELDS as readonly string[]).includes(field)) { processedConfig[field] = Math.max(1, Math.round(numValue)); } else { processedConfig[field] = numValue; } } else { alert(`Invalid numeric value for ${field}. Please enter a valid number.`); - return; } } diff --git a/tools/server/webui/src/lib/constants/settings-fields.ts b/tools/server/webui/src/lib/constants/settings-fields.ts new file mode 100644 index 0000000000..79a6e92870 --- /dev/null +++ b/tools/server/webui/src/lib/constants/settings-fields.ts @@ -0,0 +1,33 @@ +/** + * List of all numeric fields in settings configuration. + * These fields will be converted from strings to numbers during save. + */ +export const NUMERIC_FIELDS = [ + 'temperature', + 'top_k', + 'top_p', + 'min_p', + 'max_tokens', + 'pasteLongTextToFileLen', + 'dynatemp_range', + 'dynatemp_exponent', + 'typ_p', + 'xtc_probability', + 'xtc_threshold', + 'repeat_last_n', + 'repeat_penalty', + 'presence_penalty', + 'frequency_penalty', + 'dry_multiplier', + 'dry_base', + 'dry_allowed_length', + 'dry_penalty_last_n', + 'agenticMaxTurns', + 'agenticMaxToolPreviewLines' +] as const; + +/** + * Fields that must be positive integers (>= 1). + * These will be clamped to minimum 1 and rounded during save. + */ +export const POSITIVE_INTEGER_FIELDS = ['agenticMaxTurns', 'agenticMaxToolPreviewLines'] as const;