// BENCH-HIDDEN — эталонное решение задачи 8. import { html, json, page } from "./lib/http.mjs"; import { answer, demoMode } from "./assistant.mjs"; const chat = () => `
Сервис пока работает в демо-режиме: отвечает только на частые вопросы.
" : ""} `; export const routes = [ { method: "GET", path: "/healthz", handler: ({ res }) => res.writeHead(200).end("ok") }, { method: "GET", path: "/", handler: ({ res }) => html(res, page("Медеу", 'Задать вопрос')) }, { method: "GET", path: "/chat", handler: ({ res }) => html(res, page("Помощник", chat())) }, { method: "POST", path: "/api/chat", async handler({ res, body }) { const message = String((await body()).message ?? "").trim(); if (!message) return json(res, 400, { errors: { message: "Напишите вопрос." } }); json(res, 200, { reply: await answer(message) }); }, }, ];