Add message actions (#482)

This commit is contained in:
Jeremy 2024-11-05 17:15:51 +03:00 committed by GitHub
parent 94f563f179
commit 171914941e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 1011 additions and 150 deletions

View file

@ -5,25 +5,18 @@ import { notFound } from 'next/navigation';
import { DEFAULT_MODEL_NAME, models } from '@/ai/models';
import { auth } from '@/app/(auth)/auth';
import { Chat as PreviewChat } from '@/components/custom/chat';
import { getChatById } from '@/db/queries';
import { Chat } from '@/db/schema';
import { getChatById, getMessagesByChatId } from '@/db/queries';
import { convertToUIMessages } from '@/lib/utils';
export default async function Page(props: { params: Promise<any> }) {
const params = await props.params;
const { id } = params;
const chatFromDb = await getChatById({ id });
const chat = await getChatById({ id });
if (!chatFromDb) {
if (!chat) {
notFound();
}
// type casting
const chat: Chat = {
...chatFromDb,
messages: convertToUIMessages(chatFromDb.messages as Array<CoreMessage>),
};
const session = await auth();
if (!session || !session.user) {
@ -34,6 +27,10 @@ export default async function Page(props: { params: Promise<any> }) {
return notFound();
}
const messagesFromDb = await getMessagesByChatId({
id,
});
const cookieStore = await cookies();
const modelIdFromCookie = cookieStore.get('model-id')?.value;
const selectedModelId =
@ -43,7 +40,7 @@ export default async function Page(props: { params: Promise<any> }) {
return (
<PreviewChat
id={chat.id}
initialMessages={chat.messages}
initialMessages={convertToUIMessages(messagesFromDb)}
selectedModelId={selectedModelId}
/>
);