|
5 | 5 | import Label from '$lib/components/ui/label/label.svelte'; |
6 | 6 | import * as Select from '$lib/components/ui/select'; |
7 | 7 | import { Textarea } from '$lib/components/ui/textarea'; |
8 | | - import { SETTING_CONFIG_DEFAULT, SETTING_CONFIG_INFO, SETTINGS_KEYS } from '$lib/constants'; |
| 8 | + import { SETTING_CONFIG_INFO, SETTINGS_KEYS } from '$lib/constants'; |
9 | 9 | import { SettingsFieldType } from '$lib/enums/settings'; |
10 | 10 | import { settingsStore } from '$lib/stores/settings.svelte'; |
| 11 | + import { serverStore } from '$lib/stores/server.svelte'; |
| 12 | + import { modelsStore, selectedModelName } from '$lib/stores/models.svelte'; |
| 13 | + import { normalizeFloatingPoint } from '$lib/utils/precision'; |
11 | 14 | import { ChatSettingsParameterSourceIndicator } from '$lib/components/app'; |
12 | 15 | import type { Component } from 'svelte'; |
13 | 16 |
|
|
20 | 23 |
|
21 | 24 | let { fields, localConfig, onConfigChange, onThemeChange }: Props = $props(); |
22 | 25 |
|
23 | | - // Helper function to get parameter source info for syncable parameters |
24 | | - function getParameterSourceInfo(key: string) { |
25 | | - if (!settingsStore.canSyncParameter(key)) { |
26 | | - return null; |
| 26 | + // server sampling defaults for placeholders |
| 27 | + let sp = $derived.by(() => { |
| 28 | + if (serverStore.isRouterMode) { |
| 29 | + const m = selectedModelName(); |
| 30 | + if (m) { |
| 31 | + const p = modelsStore.getModelProps(m); |
| 32 | + return (p?.default_generation_settings?.params ?? {}) as Record<string, unknown>; |
| 33 | + } |
27 | 34 | } |
28 | | -
|
29 | | - return settingsStore.getParameterInfo(key); |
30 | | - } |
| 35 | + return (serverStore.defaultParams ?? {}) as Record<string, unknown>; |
| 36 | + }); |
31 | 37 | </script> |
32 | 38 |
|
33 | 39 | {#each fields as field (field.key)} |
34 | 40 | <div class="space-y-2"> |
35 | 41 | {#if field.type === SettingsFieldType.INPUT} |
36 | | - {@const paramInfo = getParameterSourceInfo(field.key)} |
37 | 42 | {@const currentValue = String(localConfig[field.key] ?? '')} |
38 | | - {@const propsDefault = paramInfo?.serverDefault} |
| 43 | + {@const serverDefault = sp[field.key]} |
39 | 44 | {@const isCustomRealTime = (() => { |
40 | | - if (!paramInfo || propsDefault === undefined) return false; |
| 45 | + if (serverDefault == null) return false; |
| 46 | + if (currentValue === '') return false; |
41 | 47 |
|
42 | | - // Apply same rounding logic for real-time comparison |
43 | | - const inputValue = currentValue; |
44 | | - const numericInput = parseFloat(inputValue); |
| 48 | + const numericInput = parseFloat(currentValue); |
45 | 49 | const normalizedInput = !isNaN(numericInput) |
46 | 50 | ? Math.round(numericInput * 1000000) / 1000000 |
47 | | - : inputValue; |
| 51 | + : currentValue; |
48 | 52 | const normalizedDefault = |
49 | | - typeof propsDefault === 'number' |
50 | | - ? Math.round(propsDefault * 1000000) / 1000000 |
51 | | - : propsDefault; |
| 53 | + typeof serverDefault === 'number' |
| 54 | + ? Math.round(serverDefault * 1000000) / 1000000 |
| 55 | + : serverDefault; |
52 | 56 |
|
53 | 57 | return normalizedInput !== normalizedDefault; |
54 | 58 | })()} |
|
74 | 78 | // Update local config immediately for real-time badge feedback |
75 | 79 | onConfigChange(field.key, e.currentTarget.value); |
76 | 80 | }} |
77 | | - placeholder={`Default: ${SETTING_CONFIG_DEFAULT[field.key] ?? 'none'}`} |
| 81 | + placeholder={sp[field.key] != null |
| 82 | + ? `Default: ${normalizeFloatingPoint(sp[field.key])}` |
| 83 | + : ''} |
78 | 84 | class="w-full {isCustomRealTime ? 'pr-8' : ''}" |
79 | 85 | /> |
80 | 86 | {#if isCustomRealTime} |
81 | 87 | <button |
82 | 88 | type="button" |
83 | 89 | onclick={() => { |
84 | 90 | settingsStore.resetParameterToServerDefault(field.key); |
85 | | - // Trigger UI update by calling onConfigChange with the default value |
86 | | - const defaultValue = propsDefault ?? SETTING_CONFIG_DEFAULT[field.key]; |
87 | | - onConfigChange(field.key, String(defaultValue)); |
| 91 | + onConfigChange(field.key, ''); |
88 | 92 | }} |
89 | 93 | class="absolute top-1/2 right-2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded transition-colors hover:bg-muted" |
90 | 94 | aria-label="Reset to default" |
|
112 | 116 | id={field.key} |
113 | 117 | value={String(localConfig[field.key] ?? '')} |
114 | 118 | onchange={(e) => onConfigChange(field.key, e.currentTarget.value)} |
115 | | - placeholder={`Default: ${SETTING_CONFIG_DEFAULT[field.key] ?? 'none'}`} |
| 119 | + placeholder="" |
116 | 120 | class="min-h-[10rem] w-full md:max-w-2xl" |
117 | 121 | /> |
118 | 122 |
|
|
140 | 144 | (opt: { value: string; label: string; icon?: Component }) => |
141 | 145 | opt.value === localConfig[field.key] |
142 | 146 | )} |
143 | | - {@const paramInfo = getParameterSourceInfo(field.key)} |
144 | 147 | {@const currentValue = localConfig[field.key]} |
145 | | - {@const propsDefault = paramInfo?.serverDefault} |
| 148 | + {@const serverDefault = sp[field.key]} |
146 | 149 | {@const isCustomRealTime = (() => { |
147 | | - if (!paramInfo || propsDefault === undefined) return false; |
148 | | - |
149 | | - // For select fields, do direct comparison (no rounding needed) |
150 | | - return currentValue !== propsDefault; |
| 150 | + if (serverDefault == null) return false; |
| 151 | + if (currentValue === '' || currentValue === undefined) return false; |
| 152 | + return currentValue !== serverDefault; |
151 | 153 | })()} |
152 | 154 |
|
153 | 155 | <div class="flex items-center gap-2"> |
|
190 | 192 | type="button" |
191 | 193 | onclick={() => { |
192 | 194 | settingsStore.resetParameterToServerDefault(field.key); |
193 | | - // Trigger UI update by calling onConfigChange with the default value |
194 | | - const defaultValue = propsDefault ?? SETTING_CONFIG_DEFAULT[field.key]; |
195 | | - onConfigChange(field.key, String(defaultValue)); |
| 195 | + onConfigChange(field.key, ''); |
196 | 196 | }} |
197 | 197 | class="absolute top-1/2 right-8 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded transition-colors hover:bg-muted" |
198 | 198 | aria-label="Reset to default" |
|
0 commit comments