chatbot-template/app/(chat)/page.tsx

53 lines
1.2 KiB
TypeScript
Raw Normal View History

import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { Chat } from "@/components/chat";
import { DataStreamHandler } from "@/components/data-stream-handler";
import { DEFAULT_CHAT_MODEL } from "@/lib/ai/models";
import { generateUUID } from "@/lib/utils";
import { auth } from "../(auth)/auth";
2023-05-19 12:33:56 -04:00
2024-10-11 18:00:22 +05:30
export default async function Page() {
2025-04-25 23:40:15 -07:00
const session = await auth();
if (!session) {
redirect("/api/auth/guest");
2025-04-25 23:40:15 -07:00
}
2024-10-11 18:00:22 +05:30
const id = generateUUID();
const cookieStore = await cookies();
const modelIdFromCookie = cookieStore.get("chat-model");
2024-10-30 16:01:24 +05:30
if (!modelIdFromCookie) {
return (
<>
<Chat
autoResume={false}
id={id}
initialChatModel={DEFAULT_CHAT_MODEL}
initialMessages={[]}
initialVisibilityType="private"
isReadonly={false}
key={id}
/>
<DataStreamHandler />
</>
);
}
return (
<>
<Chat
autoResume={false}
id={id}
initialChatModel={modelIdFromCookie.value}
initialMessages={[]}
initialVisibilityType="private"
isReadonly={false}
key={id}
/>
<DataStreamHandler />
</>
);
2023-05-19 12:33:56 -04:00
}