mirror of
https://github.com/zooai/ai.git
synced 2026-10-30 14:52:08 +00:00
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import { type UseChatHelpers } from 'ai/react'
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
import { PromptForm } from '@/components/prompt-form'
|
|
import { ButtonScrollToBottom } from '@/components/button-scroll-to-bottom'
|
|
import { IconRefresh, IconStop } from '@/components/ui/icons'
|
|
import { FooterText } from '@/components/footer'
|
|
|
|
export interface ChatPanelProps
|
|
extends Pick<
|
|
UseChatHelpers,
|
|
| 'append'
|
|
| 'isLoading'
|
|
| 'reload'
|
|
| 'messages'
|
|
| 'stop'
|
|
| 'input'
|
|
| 'setInput'
|
|
> {
|
|
id?: string
|
|
}
|
|
|
|
export function ChatPanel({
|
|
id,
|
|
isLoading,
|
|
stop,
|
|
append,
|
|
reload,
|
|
input,
|
|
setInput,
|
|
messages
|
|
}: ChatPanelProps) {
|
|
return (
|
|
<div className="fixed inset-x-0 bottom-0">
|
|
<ButtonScrollToBottom />
|
|
<div className="mx-auto sm:max-w-2xl sm:px-4">
|
|
<div className="flex h-10 items-center justify-center">
|
|
{isLoading ? (
|
|
<Button
|
|
variant="outline"
|
|
onClick={() => stop()}
|
|
className="bg-background"
|
|
>
|
|
<IconStop className="mr-2" />
|
|
Stop generating
|
|
</Button>
|
|
) : (
|
|
messages?.length > 0 && (
|
|
<Button
|
|
variant="outline"
|
|
onClick={() => reload()}
|
|
className="bg-background"
|
|
>
|
|
<IconRefresh className="mr-2" />
|
|
Regenerate response
|
|
</Button>
|
|
)
|
|
)}
|
|
</div>
|
|
<div className="space-y-4 max-sm:border-t bg-transparent px-4 py-2 md:py-4">
|
|
<PromptForm
|
|
onSubmit={async value => {
|
|
await append({
|
|
id: id,
|
|
content: value,
|
|
role: 'user'
|
|
})
|
|
}
|
|
}
|
|
input={input}
|
|
setInput={setInput}
|
|
isLoading={isLoading}
|
|
/>
|
|
<FooterText className="hidden sm:block" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|