feat: store workspace preferences and drafts locally

This commit is contained in:
2026-08-04 05:28:13 +02:00
parent 6c09adc05e
commit cee4cfa63d
8 changed files with 537 additions and 21 deletions
+20 -7
View File
@@ -5,10 +5,10 @@ import { useQuery } from "@tanstack/react-query";
import { postSteer, createSession } from "../api/sessions";
import { ApiError } from "../api/client";
import { getSettings } from "../api/settings";
import { listWorkspaces } from "../api/workspaces";
import { getWorkspace, listWorkspaces } from "../api/workspaces";
import { listModels } from "../api/models";
import { useSessionStore } from "../store/sessionStore";
import { workspacePreferences, type WorkspacePreference } from "../workspaces/preferences";
import { workspacePreferences, type WorkspacePreference } from "../workspaces/drafts";
const THINKING_LEVELS = ["low", "medium", "high"] as const;
@@ -84,7 +84,7 @@ export function SteerInput({
setLastUserEntry({ kind: "input", text: trimmed });
onSessionCreating?.(trimmed);
try {
const { id } = await createSession({ question: trimmed });
const { id } = await createSession({ question: trimmed, ...workspacePreferences.load() });
onSessionCreated?.(id);
setText("");
} catch (error) {
@@ -173,20 +173,33 @@ export function ComposerFooter() {
}, [settings]);
const workspace = preferences.workspaceId ?? settings?.workspace ?? "";
const selectedWorkspace = workspaces.find((candidate) => candidate.id === workspace);
const { data: workspaceRecord } = useQuery({
queryKey: ["workspace", workspace],
queryFn: () => getWorkspace(workspace),
// Legacy metadata responses do not carry a registry revision, so retain the
// existing selector behavior without issuing an incompatible detail request.
enabled: Boolean(selectedWorkspace?.revision),
});
const model = preferences.model ?? settings?.model ?? "";
const thinking = preferences.thinking ?? settings?.thinking ?? "medium";
const allowedModels = workspaceRecord?.workspace.llm_policy.allowed;
const policyModels = allowedModels
? models.filter((candidate) => allowedModels.includes(`${candidate.provider}/${candidate.id}`))
: models;
function update(patch: WorkspacePreference) {
const next = workspacePreferences.save({ ...preferences, ...patch });
setPreferences(next);
}
function onModelChange(id: string) {
const m = models.find((x) => x.id === id);
const m = policyModels.find((x) => x.id === id);
update({ model: id, provider: m?.provider });
}
const knownModel = models.some((m) => m.id === model);
const knownModel = policyModels.some((m) => m.id === model);
const contextPct = tokenUsage && tokenUsage.contextWindow > 0
? tokenUsage.totalTokens / tokenUsage.contextWindow
: 0;
@@ -215,12 +228,12 @@ export function ComposerFooter() {
<div className="flex items-center gap-2">
<FooterSelect aria-label="Model" value={model} onChange={onModelChange}>
{models.length === 0 ? (
{policyModels.length === 0 ? (
<option value={model}>{model || "— model —"}</option>
) : (
<>
{!knownModel && <option value={model}>{model || "— model —"}</option>}
{models.map((m) => (
{policyModels.map((m) => (
<option key={`${m.provider}/${m.id}`} value={m.id}>
{m.name}
</option>