peppa/apps/web/lib/live-server.ts
peppa-bot 10363f8592 PEP-270: задачи агентов — предложения, не больше 5 в сутки на проект
- MCP create_task агента: origin agent + «Предложено» (раньше — задача человека, диспетчер брал её сам)
- AgentLimits.perDay (5, скользящие 24 ч), proposalRoom/proposalsToday; сверх — отказ агенту,
  находки приёмки — в недельную сводку; событие proposal_limited
- CLI agent-limits perDay=N, правило агентам в template/RULES.md, тест proposal-daily-limit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 17:02:04 +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,
});
}