feat: pin sessions to workspace revisions
This commit is contained in:
@@ -1,10 +1,34 @@
|
||||
import { apiFetch } from "./client";
|
||||
import { getSettings } from "./settings";
|
||||
import { workspacePreferences, type WorkspacePreference } from "../workspaces/preferences";
|
||||
import type {
|
||||
Principal, ResumeSessionResult, SessionScope, SessionSummary, SessionDocument, UiResponse,
|
||||
} from "./types";
|
||||
|
||||
export const createSession = (i: { question: string; name?: string }) =>
|
||||
apiFetch<{ id: string }>("/sessions", { method: "POST", body: JSON.stringify(i) });
|
||||
type NewSessionInput = { question: string; name?: string } & Partial<WorkspacePreference>;
|
||||
|
||||
async function selectedPreferences(): Promise<WorkspacePreference> {
|
||||
const saved = workspacePreferences.load();
|
||||
if (saved.workspaceId && saved.provider && saved.model && saved.thinking) return saved;
|
||||
|
||||
// A direct new-session entry point can run before the composer has mounted. Seed its
|
||||
// browser-local preferences from the legacy read-only defaults once, then keep them local.
|
||||
const legacy = await getSettings();
|
||||
return workspacePreferences.save({
|
||||
workspaceId: saved.workspaceId ?? legacy.workspace,
|
||||
provider: saved.provider ?? legacy.provider,
|
||||
model: saved.model ?? legacy.model,
|
||||
thinking: saved.thinking ?? legacy.thinking,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createSession(i: NewSessionInput) {
|
||||
const preferences = await selectedPreferences();
|
||||
return apiFetch<{ id: string }>("/sessions", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ ...preferences, ...i }),
|
||||
});
|
||||
}
|
||||
|
||||
/** Best-effort warm-up; callers must not await it before showing the composer. */
|
||||
export const prewarmRuntime = () =>
|
||||
|
||||
Reference in New Issue
Block a user