import { cookies } from "next/headers"; import { notFound, redirect } from "next/navigation"; import { Suspense } from "react"; import { Chat } from "@/components/chat"; import { DataStreamHandler } from "@/components/data-stream-handler"; import { DEFAULT_CHAT_MODEL } from "@/lib/ai/models"; import { getSession } from "@/lib/auth"; import { getChatById, getMessagesByChatId } from "@/lib/db/queries"; import { convertToUIMessages } from "@/lib/utils"; export default function Page(props: { params: Promise<{ id: string }> }) { return ( }> ); } async function ChatPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const chat = await getChatById({ id }); if (!chat) { redirect("/"); } const session = await getSession(); if (!session) { redirect("/login"); } if (chat.visibility === "private") { if (!session.user) { return notFound(); } if (session.user.id !== chat.userId) { return notFound(); } } const messagesFromDb = await getMessagesByChatId({ id, }); const uiMessages = convertToUIMessages(messagesFromDb); const cookieStore = await cookies(); const chatModelFromCookie = cookieStore.get("chat-model"); if (!chatModelFromCookie) { return ( <> ); } return ( <> ); }