Files
learnharness/components/default-settings.ts
T
amosblomqvist bd3086194f feat: no baked-in default model — the new-session controls ARE the default settings page
Owner reframe (2026-09-18): the model + thinking + context controls on
the home graph view and /chat/new are not a draft overlay on a baked-in
default — they ARE the settings page for the default model, and the
user's last choice IS the default. BYOK first boot has no keys and
possibly no OpenRouter, so there is NO default to show: the controls
render 'no model' ('—') until the first pick.

The flash was the deeper symptom: the surfaces rendered from client
state that started empty and fetched truth afterward, so every visit
flashed the config pin (GLM/low — a dev artifact) for a few frames.
Fix at the root: both pages are now force-dynamic server components
that read the record (readDefaultSettings → initialSettings) and hand
it to the client — the first frame shows truth. Dynamic routes aren't
cached client-side (staleTimes.dynamic = 0), so every navigation
re-reads the record; the useDefaultSettings hook keeps only save-side
state (optimistic set + PUT). The GET-on-mount and its touch-guard are
gone.

ModelControl gains noDefaultModel (the default surfaces only): unset
settings render no model/level, never the catalog pin; the thinking
menu no-ops until a model exists. Chat surfaces keep the catalog
fallback — the engine runs the config pin when a session record has no
override, so the control keeps showing what will actually run.

Renamed draft→default throughout: data/default-settings.json,
GET/PUT /api/settings/defaults, useDefaultSettings. New sessions
still inherit the default on creation exactly as before.

Live-verified: first-boot 'no model' with zero flash, picker +
Shift+Tab cycle, values held across session→/chat/new→home roundtrips
and a reload (10×100ms samples, never the old default), zero console
errors.
2026-09-18 09:37:20 +03:00

45 lines
1.8 KiB
TypeScript

"use client";
/**
* THE default settings (owner, 2026-09-18): the new-session surfaces'
* model + thinking + knowledge-context controls are the settings page for
* the default model. There is NO baked-in default — BYOK first boot shows
* "no model" until the user picks one, and their last choice IS the
* default from then on. Both surfaces (the home graph view's topic dock
* and /chat/new) share ONE server-side record (GET/PUT
* /api/settings/defaults → data/default-settings.json).
*
* No loading state, no flash: the PAGES server-render the record
* (readDefaultSettings → initialSettings), so the controls show truth on
* the first frame — dynamic routes aren't cached client-side (staleTimes
* .dynamic = 0), so every navigation gets fresh server truth. This hook
* only holds the state between saves: initialSettings seeds it, and every
* change applies locally (optimistic — the controls only send valid
* values: the picker offers catalog models, the slider sends its stops)
* and persists fire-and-forget; a failed write logs, and the next
* navigation re-reads the persisted truth.
*/
import { useCallback, useState } from "react";
import type { ChatSettings } from "@/src/core";
export function useDefaultSettings(initialSettings: ChatSettings | null): {
settings: ChatSettings | undefined;
save: (settings: ChatSettings) => void;
} {
const [settings, setSettings] = useState<ChatSettings | undefined>(initialSettings ?? undefined);
const save = useCallback((next: ChatSettings) => {
setSettings(next);
void fetch("/api/settings/defaults", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(next),
}).catch((err: unknown) => {
console.error("default settings write failed:", err);
});
}, []);
return { settings, save };
}