2025-09-21 11:02:31 -07:00
|
|
|
import { cookies } from "next/headers";
|
|
|
|
|
import { redirect } from "next/navigation";
|
2025-11-29 13:21:34 +00:00
|
|
|
import { Suspense } from "react";
|
2025-09-21 11:02:31 -07:00
|
|
|
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
|
|
|
|
2025-11-29 13:21:34 +00:00
|
|
|
export default function Page() {
|
|
|
|
|
return (
|
|
|
|
|
<Suspense fallback={<div className="flex h-dvh" />}>
|
|
|
|
|
<NewChatPage />
|
|
|
|
|
</Suspense>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function NewChatPage() {
|
2025-04-25 23:40:15 -07:00
|
|
|
const session = await auth();
|
|
|
|
|
|
|
|
|
|
if (!session) {
|
2025-09-21 11:02:31 -07:00
|
|
|
redirect("/api/auth/guest");
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 18:00:22 +05:30
|
|
|
const id = generateUUID();
|
2024-10-24 16:35:51 -04:00
|
|
|
|
|
|
|
|
const cookieStore = await cookies();
|
2025-09-21 11:02:31 -07:00
|
|
|
const modelIdFromCookie = cookieStore.get("chat-model");
|
2024-10-30 16:01:24 +05:30
|
|
|
|
2025-02-03 20:33:15 +05:30
|
|
|
if (!modelIdFromCookie) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Chat
|
2025-09-21 11:02:31 -07:00
|
|
|
autoResume={false}
|
2025-02-03 20:33:15 +05:30
|
|
|
id={id}
|
2025-09-21 12:03:29 +01:00
|
|
|
initialChatModel={DEFAULT_CHAT_MODEL}
|
2025-09-21 11:02:31 -07:00
|
|
|
initialMessages={[]}
|
2025-05-01 17:47:48 -07:00
|
|
|
initialVisibilityType="private"
|
2025-02-03 20:33:15 +05:30
|
|
|
isReadonly={false}
|
2025-09-21 11:02:31 -07:00
|
|
|
key={id}
|
2025-02-03 20:33:15 +05:30
|
|
|
/>
|
2025-07-03 02:26:34 -07:00
|
|
|
<DataStreamHandler />
|
2025-02-03 20:33:15 +05:30
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-10-24 16:35:51 -04:00
|
|
|
|
|
|
|
|
return (
|
2024-12-19 17:05:04 +05:30
|
|
|
<>
|
|
|
|
|
<Chat
|
2025-09-21 11:02:31 -07:00
|
|
|
autoResume={false}
|
2024-12-19 17:05:04 +05:30
|
|
|
id={id}
|
2025-09-21 12:03:29 +01:00
|
|
|
initialChatModel={modelIdFromCookie.value}
|
2025-09-21 11:02:31 -07:00
|
|
|
initialMessages={[]}
|
2025-05-01 17:47:48 -07:00
|
|
|
initialVisibilityType="private"
|
2024-12-19 17:05:04 +05:30
|
|
|
isReadonly={false}
|
2025-09-21 11:02:31 -07:00
|
|
|
key={id}
|
2024-12-19 17:05:04 +05:30
|
|
|
/>
|
2025-07-03 02:26:34 -07:00
|
|
|
<DataStreamHandler />
|
2024-12-19 17:05:04 +05:30
|
|
|
</>
|
2024-10-24 16:35:51 -04:00
|
|
|
);
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|