w-lab-app/src/app/[locale]/(chat)/chat/[assistantId]/layout.tsx
2025-07-26 20:22:00 +04:00

31 lines
750 B
TypeScript

import { createChat, getChatMessages } from "@/entities/chats/api";
import type { IChatMessage } from "@/entities/chats/types";
import { ChatProvider } from "@/providers/chat-provider";
export default async function ChatLayout({
children,
params,
}: Readonly<{
children: React.ReactNode;
params: Promise<{ assistantId: string }>;
}>) {
const { assistantId } = await params;
const { chatId } = await createChat(assistantId);
const { messages: initialMessages, totalCount } = await getChatMessages(
chatId,
{ limit: 50, page: 1 }
);
return (
<ChatProvider
chatId={chatId}
initialMessages={initialMessages as IChatMessage[]}
initialTotal={totalCount}
>
{children}
</ChatProvider>
);
}