import type { ReactNode } from "react"; import { accountUsageForUser, agentsLine, getNotifyPrefs, isSuperadmin, pendingFeedbackCount } from "@peppa/core"; import { db } from "@/lib/db"; import { subscriptionRequestOffers } from "@peppa/runner"; import { requireUser, uiMode } from "@/lib/auth"; import { navCounts } from "@/lib/queries"; import { WordsProvider } from "@/components/Words"; import { Sidebar } from "@/components/Sidebar"; import { AttentionBadge } from "@/components/AttentionBadge"; import { CommandPalette } from "@/components/CommandPalette"; import { AgentsStrip, UsageStrip } from "@/components/Accounting"; import { VersionWatch } from "@/components/VersionWatch"; import { bootId } from "@/lib/boot"; import { FeedbackButton } from "@/components/FeedbackButton"; export const dynamic = "force-dynamic"; /** Console layout (PEP-38): navigation on the left, each page renders centre + right panel via . */ export default async function AppLayout({ children }: { children: ReactNode }) { const user = await requireUser(); // PEP-216: independent reads together, not one after another on every page. const [counts, { sound }, superadmin, mode] = await Promise.all([navCounts(user.id), getNotifyPrefs(db, user.id), isSuperadmin(db, user), uiMode()]); const engineer = mode === "engineer"; // PEP-5: subscription limit windows over every page — for «Инженер»; PEP-121: «Продакт» // reads one line: agents work, or when they go on. const [accounts, line, feedback] = await Promise.all([ engineer ? accountUsageForUser(db, user).catch(() => []) : [], engineer ? null : agentsLine(db, user).catch(() => ({ state: "working" as const })), superadmin ? pendingFeedbackCount(db) : 0, ]); // PEP-186: agents stand — the owner may ask the superadmin for a subscription right from the strip. const offers = line?.state === "paused" ? await subscriptionRequestOffers(db, user).catch(() => []) : []; return (
{line ? : } {children}
{/* PEP-143: «Сообщить о проблеме» on every page. */}
); }