2023-05-19 12:33:56 -04:00
|
|
|
import { Sidebar } from "@/app/sidebar";
|
|
|
|
|
|
|
|
|
|
import { type Metadata } from "next";
|
2023-05-22 10:16:09 -04:00
|
|
|
import { auth } from "@/auth";
|
2023-06-02 11:57:44 -04:00
|
|
|
import { db, chats } from "@/lib/db/schema";
|
|
|
|
|
import { eq } from "drizzle-orm";
|
|
|
|
|
import { Chat } from "@/app/chat";
|
|
|
|
|
import { Message } from "ai-connector";
|
2023-05-19 12:33:56 -04:00
|
|
|
export interface ChatPageProps {
|
|
|
|
|
params: {
|
|
|
|
|
id: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function generateMetadata({
|
|
|
|
|
params,
|
|
|
|
|
}: ChatPageProps): Promise<Metadata> {
|
2023-06-02 11:57:44 -04:00
|
|
|
const chat = await db.query.chats.findFirst({
|
|
|
|
|
where: eq(chats.id, params.id),
|
2023-05-19 12:33:56 -04:00
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
title: chat?.title.slice(0, 50) ?? "Chat",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prisma does not support Edge without the Data Proxy currently
|
|
|
|
|
export const runtime = "nodejs"; // default
|
|
|
|
|
export const preferredRegion = "home";
|
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
export default async function ChatPage({ params }: ChatPageProps) {
|
2023-05-22 10:16:09 -04:00
|
|
|
const session = await auth();
|
2023-06-02 11:57:44 -04:00
|
|
|
const chat = await db.query.chats.findFirst({
|
|
|
|
|
where: eq(chats.id, params.id),
|
2023-05-19 12:33:56 -04:00
|
|
|
});
|
2023-06-02 11:57:44 -04:00
|
|
|
|
2023-05-19 12:33:56 -04:00
|
|
|
if (!chat) {
|
|
|
|
|
throw new Error("Chat not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="relative flex h-full w-full overflow-hidden">
|
|
|
|
|
<Sidebar session={session} />
|
|
|
|
|
<div className="flex h-full min-w-0 flex-1 flex-col">
|
2023-06-02 11:57:44 -04:00
|
|
|
<Chat id={chat.id} initialMessages={chat.messages as Message[]} />
|
2023-05-19 12:33:56 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChatPage.displayName = "ChatPage";
|