peppa/apps/web/lib/live-server.ts
peppa-bot acb6e3fb81
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 46с
peppa/build build: success за 34с
peppa/test test: success за 1325с
peppa-ci / ci (pull_request) Successful in 24m11s
PEP-224: статус функций из мониторинга (сведено с main после PEP-225)
Функция → мониторинги (core/feature-status.ts), серая кнопка входа через eGov и статус MCP,
отказ startEgovFlow, журнал и сообщения в канал. После переезда живых обновлений на
WebSocket (PEP-225): область `features` в LIVE_PLAIN_SCOPES, открыта без входа (SSE и
WebSocket с `anonymous: true` — только открытые области), смотрится по таймеру вместе с
`observe`, смена сбрасывает кэш статусов.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 15:00:03 +00:00

32 lines
1.5 KiB
TypeScript

// PEP-225: the tab's WebSocket, set up inside the Next process (instrumentation.ts) where the
// web's modules live — the cookie check, navCounts, the boot id. apps/web/server.ts only hands
// `upgrade` requests of /api/ws to what is registered here (globalThis: the custom server and
// the Next bundle are different module graphs of one process).
import { getNotifyPrefs } from "@peppa/core";
import { setLiveChatView, setLiveProvider } from "@peppa/runner";
import { createLiveWs, readCookie, type LiveWs } from "@peppa/runner/live-ws";
import { bootId } from "./boot";
import { liveChatView } from "./chat-live";
import { db } from "./db";
import { navCounts } from "./queries";
import { SESSION_COOKIE, userFromSessionToken } from "./session-user";
const g = globalThis as { __peppaLiveWs?: LiveWs };
export function registerLiveWs(): void {
setLiveProvider("attention", async (_db, userId) => {
const [c, { sound }] = await Promise.all([navCounts(userId), getNotifyPrefs(db, userId)]);
return { count: c.questions + c.waitingRunners, questions: c.questions, waitingRunners: c.waitingRunners, chats: c.chats, sound };
});
setLiveProvider("version", () => ({ boot: bootId() }));
setLiveChatView(liveChatView);
g.__peppaLiveWs?.close();
g.__peppaLiveWs = createLiveWs({
db,
authenticate: (req) => userFromSessionToken(readCookie(req.headers.cookie, SESSION_COOKIE)),
boot: bootId,
// PEP-224: the login page and /mcp-guide watch `features` before a sign-in.
anonymous: true,
});
}