diff --git a/.env b/.env new file mode 100644 index 00000000..b454ca74 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DATABASE_URL="postgresql://user:password@host:port/db" diff --git a/app/actions.tsx b/app/actions.tsx index 6617ab64..3799edc0 100644 --- a/app/actions.tsx +++ b/app/actions.tsx @@ -248,6 +248,17 @@ async function submit(formData?: FormData, skip?: boolean) { }; } +async function clearChat() { + 'use server' + + const aiState = getMutableAIState() + + aiState.done({ + chatId: nanoid(), + messages: [] + }) +} + export type AIState = { messages: AIMessage[]; chatId: string; @@ -272,6 +283,7 @@ const initialUIState: UIState = []; export const AI = createAI({ actions: { submit, + clearChat, }, initialUIState, initialAIState, diff --git a/bun.lockb b/bun.lockb index d24d91ca..6ce99d8c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index 2e9fb1b0..c5268ead 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -1,7 +1,6 @@ 'use client' import { useEffect, useState, useRef } from 'react' -import { useRouter } from 'next/navigation' import type { AI, UIState } from '@/app/actions' import { useUIState, useActions } from 'ai/rsc' // Removed import of useGeospatialToolMcp as it's no longer used/available @@ -20,13 +19,11 @@ interface ChatPanelProps { export function ChatPanel({ messages, input, setInput }: ChatPanelProps) { const [, setMessages] = useUIState() - const { submit } = useActions() + const { submit, clearChat } = useActions() // Removed mcp instance as it's no longer passed to submit - const [isButtonPressed, setIsButtonPressed] = useState(false) const [isMobile, setIsMobile] = useState(false) const inputRef = useRef(null) const formRef = useRef(null) - const router = useRouter() // Detect mobile layout useEffect(() => { @@ -38,19 +35,8 @@ export function ChatPanel({ messages, input, setInput }: ChatPanelProps) { return () => window.removeEventListener('resize', checkMobile) }, []) - useEffect(() => { - if (isButtonPressed) { - inputRef.current?.focus() - setIsButtonPressed(false) - } - }, [isButtonPressed]) - const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() - if (isButtonPressed) { - handleClear() - setIsButtonPressed(false) - } setMessages(currentMessages => [ ...currentMessages, { @@ -64,8 +50,9 @@ export function ChatPanel({ messages, input, setInput }: ChatPanelProps) { setMessages(currentMessages => [...currentMessages, responseMessage as any]) } - const handleClear = () => { - router.push('/') + const handleClear = async () => { + setMessages([]) + await clearChat() } useEffect(() => { @@ -73,7 +60,7 @@ export function ChatPanel({ messages, input, setInput }: ChatPanelProps) { }, []) // New chat button (appears when there are messages) - if (messages.length > 0 && !isButtonPressed && !isMobile) { + if (messages.length > 0 && !isMobile) { return (
{ - const router = useRouter() + const [, setMessages] = useUIState() + const { clearChat } = useActions() - const handleNewChat = () => { - router.push('/') + const handleNewChat = async () => { + setMessages([]) + await clearChat() } return (