66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { context } from "@bureaudouble/rsc/server/context";
|
|
import type { Context as RouteurContext } from "@bureaudouble/routeur";
|
|
import { NarrativeProvider } from "@/app/game-engine/narrative-provider.tsx";
|
|
import ChatInterface from "@/app/components/chat/chat-interface.tsx";
|
|
import { Suspense } from "react";
|
|
import Layout from "./layout.tsx";
|
|
import { useServerI18n } from "../actions/locale.ts";
|
|
import { StatusBar } from "@/app/components/chat/status-bar.tsx";
|
|
import { AVAILABLE_MODELS } from "../game-engine/models-server.ts";
|
|
import { getInitialMessages } from "../game-engine/prompt-constructor.ts";
|
|
import GlobalBackgroundImageDisplay from "../components/global-background-image.tsx";
|
|
import ChatMetrics from "../components/chat/chat-metrics.tsx";
|
|
|
|
async function GamePageContent() {
|
|
const rscContext = context<RouteurContext>();
|
|
const searchParams = rscContext.url.searchParams as URLSearchParams;
|
|
const defaultSessionId = Date.now().toString().slice(5).toString();
|
|
const sessionId = searchParams.get("session-id") || defaultSessionId;
|
|
const personaId = searchParams.get("persona-id");
|
|
const modelId = searchParams.get("model-id") ?? AVAILABLE_MODELS.at(0)?.id;
|
|
|
|
const { locale } = await useServerI18n();
|
|
|
|
const initialMessages = getInitialMessages({ locale, personaId });
|
|
|
|
return (
|
|
<NarrativeProvider
|
|
apiEndpoint="/api/chat"
|
|
locale={locale}
|
|
initialMessages={initialMessages}
|
|
sessionId={sessionId}
|
|
modelId={modelId}
|
|
key={sessionId + modelId}
|
|
>
|
|
<Layout className="contents" variant="terminal">
|
|
<StatusBar
|
|
models={AVAILABLE_MODELS.map(({ id, name }) => ({ id, name }))}
|
|
modelId={modelId}
|
|
/>
|
|
<ChatMetrics />
|
|
<GlobalBackgroundImageDisplay />
|
|
<ChatInterface locale={locale} />
|
|
</Layout>
|
|
</NarrativeProvider>
|
|
);
|
|
}
|
|
|
|
async function FallbackComponent() {
|
|
const { t } = await useServerI18n();
|
|
return (
|
|
<Layout
|
|
variant="terminal"
|
|
className="text-xs px-2 text-muted-foreground flex flex-col gap-0.5 py-1"
|
|
>
|
|
{t("systemLoading")}
|
|
</Layout>
|
|
);
|
|
}
|
|
|
|
export default () => {
|
|
return (
|
|
<Suspense fallback={<FallbackComponent />}>
|
|
<GamePageContent />
|
|
</Suspense>
|
|
);
|
|
};
|