peppa/apps/web/app/(app)/layout.tsx
peppa-bot 1ef3bd7c98
Some checks failed
peppa/lint lint: success за 2с
peppa/typecheck typecheck: success за 53с
peppa/build build: success за 40с
peppa/bundle bundle: success за 2с
peppa/test test: failure за 1869с
peppa-ci / ci (pull_request) Failing after 33m54s
PEP-217: слияние с main — конфликты решены, терминал на /sessions грузится по требованию, эталон веса JS обновлён
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 19:38:45 +00:00

53 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 { LazyCommandPalette as CommandPalette } from "@/components/Lazy";
import { WebVitals } from "@/components/WebVitals";
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 <Workspace>. */
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 (
<WordsProvider mode={mode}>
<div className="min-h-dvh md:grid md:grid-cols-[232px_minmax(0,1fr)]">
<AttentionBadge count={counts.questions + counts.waitingRunners} sound={sound} />
<Sidebar login={user.login} avatarUrl={user.avatarUrl} counts={{ ...counts, feedback }} superadmin={superadmin} engineer={engineer} />
<div className="flex min-w-0 flex-col pb-16 md:pb-0">
<VersionWatch boot={bootId()} />
{line ? <AgentsStrip line={line} offers={offers} /> : <UsageStrip accounts={accounts} admin={superadmin} />}
{children}
</div>
<CommandPalette />
{/* PEP-217: Web Vitals of real users. */}
<WebVitals mode={mode} />
{/* PEP-143: «Сообщить о проблеме» on every page. */}
<FeedbackButton />
</div>
</WordsProvider>
);
}