feat(backend): POST /sessions applies global settings, body is question-only
workspace/provider/model/thinking now come from getSettings() injected into sessionRoutes; the request body supplies only question+name. Also teaches fake_pi_rpc to respond to set_model and set_thinking_level RPC commands so tests that pass real model settings don't hang. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,17 +2,32 @@ import type { FastifyInstance } from "fastify";
|
||||
import type { PiProcessManager } from "../pi/pi-process-manager.js";
|
||||
import type { ThtRunner } from "../tht/tht-runner.js";
|
||||
import type { SseHub } from "../sse/sse-hub.js";
|
||||
import type { Settings } from "../settings/settings-store.js";
|
||||
import { getUser } from "../auth/auth.js";
|
||||
|
||||
export function sessionRoutes(app: FastifyInstance, d: { mgr: PiProcessManager; tht: ThtRunner; hub: SseHub }) {
|
||||
export function sessionRoutes(
|
||||
app: FastifyInstance,
|
||||
d: { mgr: PiProcessManager; tht: ThtRunner; hub: SseHub; getSettings: () => Settings },
|
||||
) {
|
||||
app.post("/sessions", async (req, reply) => {
|
||||
const b = req.body as any;
|
||||
// NOTE (MVP): `workspace` selects the tht `-c <config>` for the backend's own
|
||||
// tht calls (session new/list/show). The gate/Pi side still uses the symlinked
|
||||
// `config/tht.yaml` (single-workspace). Full multi-workspace on the Pi side is
|
||||
// future work — the gate would need a THT_CONFIG/workspace env passed at spawn.
|
||||
const { id } = await d.tht.sessionNew({ question: b.question, provider: b.provider, model: b.model, thinking: b.thinking, name: b.name, workspace: b.workspace });
|
||||
const rt = await d.mgr.spawnFor(id, { provider: b.provider, model: b.model, thinking: b.thinking, author: getUser(req).id });
|
||||
const b = req.body as { question: string; name?: string };
|
||||
const s = d.getSettings();
|
||||
// Settings (global) supply workspace/provider/model/thinking. The new-question
|
||||
// form sends only the question text. `workspace` selects the tht `-c <config>`.
|
||||
const { id } = await d.tht.sessionNew({
|
||||
question: b.question,
|
||||
name: b.name,
|
||||
workspace: s.workspace,
|
||||
provider: s.provider,
|
||||
model: s.model,
|
||||
thinking: s.thinking,
|
||||
});
|
||||
const rt = await d.mgr.spawnFor(id, {
|
||||
provider: s.provider,
|
||||
model: s.model,
|
||||
thinking: s.thinking,
|
||||
author: getUser(req).id,
|
||||
});
|
||||
rt.bridge.onClientEvent((e) => d.hub.publish(id, e.type, e));
|
||||
return { id };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user