2023-06-02 15:33:48 -04:00
|
|
|
'use client'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-02 15:33:48 -04:00
|
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
|
import { Prompt } from './prompt'
|
|
|
|
|
import { useChat, type Message } from 'ai-connector'
|
|
|
|
|
import { ChatList } from './chat-list'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
|
|
|
|
export interface ChatProps {
|
|
|
|
|
// create?: (input: string) => Chat | undefined;
|
2023-06-02 15:33:48 -04:00
|
|
|
initialMessages?: Message[]
|
|
|
|
|
id?: string
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Chat({
|
2023-05-22 13:10:52 +02:00
|
|
|
id,
|
2023-05-19 12:33:56 -04:00
|
|
|
// create,
|
2023-06-02 15:33:48 -04:00
|
|
|
initialMessages
|
2023-05-19 12:33:56 -04:00
|
|
|
}: ChatProps) {
|
2023-06-02 15:33:48 -04:00
|
|
|
const router = useRouter()
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-02 11:15:04 -04:00
|
|
|
const { isLoading, messages, reload, append } = useChat({
|
|
|
|
|
initialMessages: initialMessages as any[],
|
2023-06-02 15:33:48 -04:00
|
|
|
id
|
2023-06-02 11:15:04 -04:00
|
|
|
// onCreate: (id: string) => {
|
|
|
|
|
// router.push(`/chat/${id}`);
|
|
|
|
|
// },
|
2023-06-02 15:33:48 -04:00
|
|
|
})
|
2023-05-19 12:33:56 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<main className="transition-width relative min-h-full w-full flex-1 overflow-y-auto flex flex-col">
|
|
|
|
|
<div className="flex-1">
|
2023-06-02 11:15:04 -04:00
|
|
|
<ChatList messages={messages} />
|
2023-05-19 12:33:56 -04:00
|
|
|
</div>
|
|
|
|
|
<div className="sticky light-gradient dark:bg-gradient-to-b dark:from-zinc-900 dark:to-zinc-950 bottom-0 left-0 w-full border-t bg-white dark:bg-black md:border-t-0 py-4 md:border-transparent md:!bg-transparent md:dark:border-transparent pr-0 lg:pr-[260px] flex dark:border-transparent items-center justify-center">
|
|
|
|
|
<Prompt
|
2023-06-02 15:33:48 -04:00
|
|
|
onSubmit={value => {
|
2023-06-02 11:15:04 -04:00
|
|
|
append({
|
|
|
|
|
content: value,
|
2023-06-02 15:33:48 -04:00
|
|
|
role: 'user'
|
|
|
|
|
})
|
2023-06-02 11:15:04 -04:00
|
|
|
}}
|
|
|
|
|
onRefresh={messages.length ? reload : undefined}
|
2023-05-19 12:33:56 -04:00
|
|
|
isLoading={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2023-06-02 15:33:48 -04:00
|
|
|
)
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-02 15:33:48 -04:00
|
|
|
Chat.displayName = 'Chat'
|