From fa0f878c975cee72ebcb612e0982b70210bd3f72 Mon Sep 17 00:00:00 2001 From: mptyl Date: Sun, 28 Jun 2026 16:19:51 +0200 Subject: [PATCH] feat(frontend): settings api, typed PiModel, question-only createSession Co-Authored-By: Claude Opus 4.8 --- frontend/src/api/models.ts | 9 ++++++++- frontend/src/api/sessions.test.ts | 14 +++++++++++--- frontend/src/api/sessions.ts | 10 ++-------- frontend/src/api/settings.ts | 13 +++++++++++++ 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 frontend/src/api/settings.ts diff --git a/frontend/src/api/models.ts b/frontend/src/api/models.ts index 13d9e041..3de134ca 100644 --- a/frontend/src/api/models.ts +++ b/frontend/src/api/models.ts @@ -1,3 +1,10 @@ import { apiFetch } from "./client"; -export const listModels = () => apiFetch<{ models: unknown[] }>("/models"); +export interface PiModel { + provider: string; + id: string; + name: string; + reasoning: boolean; +} + +export const listModels = () => apiFetch<{ models: PiModel[] }>("/models"); diff --git a/frontend/src/api/sessions.test.ts b/frontend/src/api/sessions.test.ts index a31bd177..4082a3df 100644 --- a/frontend/src/api/sessions.test.ts +++ b/frontend/src/api/sessions.test.ts @@ -2,10 +2,18 @@ import { http, HttpResponse } from "msw"; import { server } from "../test/msw"; import { createSession, listSessions } from "./sessions"; -test("createSession POSTs and returns the id", async () => { - server.use(http.post("http://localhost:8787/sessions", () => HttpResponse.json({ id: "s1" }))); - expect(await createSession({ workspace: "w", question: "q" })).toEqual({ id: "s1" }); +test("createSession POSTs only {question} and returns the id", async () => { + let body: unknown = null; + server.use( + http.post("http://localhost:8787/sessions", async ({ request }) => { + body = await request.json(); + return HttpResponse.json({ id: "s1" }); + }), + ); + expect(await createSession({ question: "q" })).toEqual({ id: "s1" }); + expect(body).toEqual({ question: "q" }); }); + test("listSessions GETs the array", async () => { server.use(http.get("http://localhost:8787/sessions", () => HttpResponse.json([{ id: "s1", status: "open", question: "q", summary: null, created_at: "t", updated_at: null, author: null }]))); const rows = await listSessions(); diff --git a/frontend/src/api/sessions.ts b/frontend/src/api/sessions.ts index 466ccc32..f84b4546 100644 --- a/frontend/src/api/sessions.ts +++ b/frontend/src/api/sessions.ts @@ -1,14 +1,8 @@ import { apiFetch } from "./client"; import type { SessionSummary, UiResponse } from "./types"; -export const createSession = (i: { - workspace: string; - question: string; - provider?: string; - model?: string; - thinking?: string; - name?: string; -}) => apiFetch<{ id: string }>("/sessions", { method: "POST", body: JSON.stringify(i) }); +export const createSession = (i: { question: string; name?: string }) => + apiFetch<{ id: string }>("/sessions", { method: "POST", body: JSON.stringify(i) }); export const listSessions = () => apiFetch("/sessions"); diff --git a/frontend/src/api/settings.ts b/frontend/src/api/settings.ts new file mode 100644 index 00000000..d89ea3d9 --- /dev/null +++ b/frontend/src/api/settings.ts @@ -0,0 +1,13 @@ +import { apiFetch } from "./client"; + +export interface Settings { + workspace?: string; + provider?: string; + model?: string; + thinking?: string; +} + +export const getSettings = () => apiFetch("/settings"); + +export const putSettings = (s: Settings) => + apiFetch("/settings", { method: "PUT", body: JSON.stringify(s) });