Some checks failed
CI / build-check-test (push) Has been cancelled
Restructure local extensions into per-feature directories, split WebUI into backend modules with slash commands and systemd support, and track prompts/skills under .pi/agent for portable Gitea deployment. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
import type { WebUiContext } from "../types/context.ts";
|
|
import { json, readBody } from "../http/request.ts";
|
|
|
|
export function handleModelsRoute(
|
|
req: IncomingMessage,
|
|
res: ServerResponse,
|
|
ctx: WebUiContext,
|
|
pathname: string,
|
|
): boolean {
|
|
const { sendCmd } = ctx.rpc;
|
|
|
|
if (req.method === "GET" && pathname === "/api/models") {
|
|
void sendCmd({ type: "get_available_models" })
|
|
.then((r: any) => (r.success ? json(res, r.data) : json(res, { error: r.error }, 500)))
|
|
.catch((err) => json(res, { error: err.message }, 500));
|
|
return true;
|
|
}
|
|
|
|
if (req.method === "POST" && pathname === "/api/model") {
|
|
void readBody(req)
|
|
.then(({ provider, modelId }) =>
|
|
sendCmd({ type: "set_model", provider, modelId }).then((r: any) =>
|
|
r.success ? json(res, { model: r.data }) : json(res, { error: r.error }, 500),
|
|
),
|
|
)
|
|
.catch((err) => json(res, { error: err.message }, 500));
|
|
return true;
|
|
}
|
|
|
|
if (req.method === "POST" && pathname === "/api/thinking") {
|
|
void readBody(req)
|
|
.then(({ level }) =>
|
|
sendCmd({ type: "set_thinking_level", level }).then((r: any) =>
|
|
r.success ? json(res, { ok: true }) : json(res, { error: r.error }, 500),
|
|
),
|
|
)
|
|
.catch((err) => json(res, { error: err.message }, 500));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|