Skip to content

Commit 006ad8b

Browse files
committed
Refactor settings bindings for Svelte 5 compatibility
Replaces direct store mutations with functional bindings for settings fields in model and application settings pages, ensuring proper updates via store methods. Also updates ToolUpdate.svelte to use $derived.by for availableTools and initializes state variables with explicit undefined values.
1 parent e27d38f commit 006ad8b

File tree

3 files changed

+76
-12
lines changed

3 files changed

+76
-12
lines changed

src/lib/components/chat/ToolUpdate.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
let toolDone = $derived(tool.some(isMessageToolResultUpdate));
2424
let eta = $derived(tool.find((update) => update.subtype === MessageToolUpdateType.ETA)?.eta);
2525
26-
const toolsData = page.data as { tools?: ToolFront[] } | undefined;
27-
const availableTools: ToolFront[] = toolsData?.tools ?? [];
26+
const availableTools: ToolFront[] = $derived.by(
27+
() => (page.data as { tools?: ToolFront[] } | undefined)?.tools ?? []
28+
);
2829
29-
let loadingBarEl: HTMLDivElement | undefined = $state();
30-
let animation: Animation | undefined = $state();
30+
let loadingBarEl: HTMLDivElement | undefined = $state(undefined);
31+
let animation: Animation | undefined = $state(undefined);
3132
let showingLoadingBar = $state(false);
3233
3334
const formatValue = (value: unknown): string => {

src/routes/settings/(nav)/[...model]/+page.svelte

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,46 @@
1919
const publicConfig = usePublicConfig();
2020
const settings = useSettingsStore();
2121
22+
// Functional bindings for nested settings (Svelte 5):
23+
// Avoid binding directly to $settings.*[modelId]; write via store update
24+
function getToolsOverride() {
25+
return $settings.toolsOverrides?.[page.params.model] ?? false;
26+
}
27+
function setToolsOverride(v: boolean) {
28+
settings.update((s) => ({
29+
...s,
30+
toolsOverrides: { ...s.toolsOverrides, [page.params.model]: v },
31+
}));
32+
}
33+
function getMultimodalOverride() {
34+
return $settings.multimodalOverrides?.[page.params.model] ?? false;
35+
}
36+
function setMultimodalOverride(v: boolean) {
37+
settings.update((s) => ({
38+
...s,
39+
multimodalOverrides: { ...s.multimodalOverrides, [page.params.model]: v },
40+
}));
41+
}
42+
function getHidePromptExamples() {
43+
return $settings.hidePromptExamples?.[page.params.model] ?? false;
44+
}
45+
function setHidePromptExamples(v: boolean) {
46+
settings.update((s) => ({
47+
...s,
48+
hidePromptExamples: { ...s.hidePromptExamples, [page.params.model]: v },
49+
}));
50+
}
51+
52+
function getCustomPrompt() {
53+
return $settings.customPrompts?.[page.params.model] ?? "";
54+
}
55+
function setCustomPrompt(v: string) {
56+
settings.update((s) => ({
57+
...s,
58+
customPrompts: { ...s.customPrompts, [page.params.model]: v },
59+
}));
60+
}
61+
2262
type RouterProvider = { provider: string } & Record<string, unknown>;
2363
2464
$effect(() => {
@@ -172,7 +212,10 @@
172212
class="ml-auto text-xs underline decoration-gray-300 hover:decoration-gray-700 dark:decoration-gray-700 dark:hover:decoration-gray-400"
173213
onclick={(e) => {
174214
e.stopPropagation();
175-
$settings.customPrompts[page.params.model] = model.preprompt;
215+
settings.update((s) => ({
216+
...s,
217+
customPrompts: { ...s.customPrompts, [page.params.model]: model.preprompt },
218+
}));
176219
}}
177220
>
178221
Reset
@@ -184,7 +227,7 @@
184227
aria-label="Custom system prompt"
185228
rows="8"
186229
class="w-full resize-none rounded-md border border-gray-200 bg-gray-50 p-2 text-[13px] dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200"
187-
bind:value={$settings.customPrompts[page.params.model]}
230+
bind:value={getCustomPrompt, setCustomPrompt}
188231
></textarea>
189232
<!-- Capabilities -->
190233
<div
@@ -200,7 +243,7 @@
200243
Enable tools and allow the model to call them in chat.
201244
</p>
202245
</div>
203-
<Switch name="forceTools" bind:checked={$settings.toolsOverrides[page.params.model]} />
246+
<Switch name="forceTools" bind:checked={getToolsOverride, setToolsOverride} />
204247
</div>
205248

206249
<div class="flex items-start justify-between py-3">
@@ -214,7 +257,7 @@
214257
</div>
215258
<Switch
216259
name="forceMultimodal"
217-
bind:checked={$settings.multimodalOverrides[page.params.model]}
260+
bind:checked={getMultimodalOverride, setMultimodalOverride}
218261
/>
219262
</div>
220263

@@ -230,7 +273,7 @@
230273
</div>
231274
<Switch
232275
name="hidePromptExamples"
233-
bind:checked={$settings.hidePromptExamples[page.params.model]}
276+
bind:checked={getHidePromptExamples, setHidePromptExamples}
234277
/>
235278
</div>
236279
{/if}

src/routes/settings/(nav)/application/+page.svelte

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@
1919
const publicConfig = usePublicConfig();
2020
let settings = useSettingsStore();
2121
22+
// Functional bindings for store fields (Svelte 5): avoid mutating $settings directly
23+
function getShareWithAuthors() {
24+
return $settings.shareConversationsWithModelAuthors;
25+
}
26+
function setShareWithAuthors(v: boolean) {
27+
settings.update((s) => ({ ...s, shareConversationsWithModelAuthors: v }));
28+
}
29+
function getDisableStream() {
30+
return $settings.disableStream;
31+
}
32+
function setDisableStream(v: boolean) {
33+
settings.update((s) => ({ ...s, disableStream: v }));
34+
}
35+
function getDirectPaste() {
36+
return $settings.directPaste;
37+
}
38+
function setDirectPaste(v: boolean) {
39+
settings.update((s) => ({ ...s, directPaste: v }));
40+
}
41+
2242
const client = useAPIClient();
2343
2444
let OPENAI_BASE_URL: string | null = $state(null);
@@ -121,7 +141,7 @@
121141
</div>
122142
<Switch
123143
name="shareConversationsWithModelAuthors"
124-
bind:checked={$settings.shareConversationsWithModelAuthors}
144+
bind:checked={getShareWithAuthors, setShareWithAuthors}
125145
/>
126146
</div>
127147
{/if}
@@ -135,7 +155,7 @@
135155
Show responses only when complete.
136156
</p>
137157
</div>
138-
<Switch name="disableStream" bind:checked={$settings.disableStream} />
158+
<Switch name="disableStream" bind:checked={getDisableStream, setDisableStream} />
139159
</div>
140160

141161
<div class="flex items-start justify-between py-3">
@@ -147,7 +167,7 @@
147167
Paste long text directly into chat instead of a file.
148168
</p>
149169
</div>
150-
<Switch name="directPaste" bind:checked={$settings.directPaste} />
170+
<Switch name="directPaste" bind:checked={getDirectPaste, setDirectPaste} />
151171
</div>
152172

153173
<!-- Theme selector -->

0 commit comments

Comments
 (0)