An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: implement auto-scroll for chat messages and update example messages
Yoshiki Miuraa7d076e2cce6
diff --git a/components/chat-messages.tsx b/components/chat-messages.tsxindex 5f21a1dc..be999337 100644--- a/components/chat-messages.tsx+++ b/components/chat-messages.tsx@@ -1,5 +1,5 @@import { JSONValue, Message } from 'ai'-import { useEffect, useMemo, useState } from 'react'+import { useEffect, useMemo, useRef, useState } from 'react'import { RenderMessage } from './render-message'import { ToolSection } from './tool-section'import { Spinner } from './ui/spinner'@@ -22,6 +22,19 @@ export function ChatMessages({const [openStates, setOpenStates] = useState<Record<string, boolean>>({})const manualToolCallId = 'manual-tool-call'+ // Add ref for the messages container+ const messagesEndRef = useRef<HTMLDivElement>(null)++ // Scroll to bottom function+ const scrollToBottom = () => {+ messagesEndRef.current?.scrollIntoView({ behavior: 'instant' })+ }++ // Scroll to bottom on mount and when messages change+ useEffect(() => {+ scrollToBottom()+ }, [])+useEffect(() => {const lastMessage = messages[messages.length - 1]if (lastMessage?.role === 'user') {@@ -101,6 +114,7 @@ export function ChatMessages({) : (<Spinner />))}+ <div ref={messagesEndRef} /> {/* Add empty div as scroll anchor */}</div>)}diff --git a/components/empty-screen.tsx b/components/empty-screen.tsxindex 246d2a8c..84911417 100644--- a/components/empty-screen.tsx+++ b/components/empty-screen.tsx@@ -3,8 +3,8 @@ import { ArrowRight } from 'lucide-react'const exampleMessages = [{- heading: 'What is OpenAI o1?',- message: 'What is OpenAI o1?'+ heading: 'What is DeepSeek R1?',+ message: 'What is DeepSeek R1?'},{heading: 'Why is Nvidia growing rapidly?',@@ -15,8 +15,8 @@ const exampleMessages = [message: 'Tesla vs Rivian'},{- heading: 'Summary: https://arxiv.org/pdf/2407.16833',- message: 'Summary: https://arxiv.org/pdf/2407.16833'+ heading: 'Summary: https://arxiv.org/pdf/2501.05707',+ message: 'Summary: https://arxiv.org/pdf/2501.05707'}]export function EmptyScreen({diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex bc7ec21c..e88edd2b 100644--- a/lib/agents/researcher.ts+++ b/lib/agents/researcher.ts@@ -17,14 +17,10 @@ When asked a question, you should:6. If results are not relevant or helpful, rely on your general knowledge7. Provide comprehensive and detailed responses based on search results, ensuring thorough coverage of the user's question8. Use markdown to structure your responses. Use headings to break up the content into sections.-9. Include relevant images that support your explanations, but avoid using images frequently. Use images only when they actively aid the user's understanding.-10. **Use the retrieve tool only with user-provided URLs.**+9. **Use the retrieve tool only with user-provided URLs.**Citation Format:[number](url)--Image Format:-`type ResearcherReturn = Parameters<typeof streamText>[0]diff --git a/lib/streaming/tool-execution.ts b/lib/streaming/tool-execution.tsindex a11cf229..bc0ed6d0 100644--- a/lib/streaming/tool-execution.ts+++ b/lib/streaming/tool-execution.ts@@ -45,7 +45,7 @@ export async function executeToolCall(<tool>tool_name</tool><parameters><query>search query text</query>- <max_results>number - 5 by default</max_results>+ <max_results>number - 20 by default</max_results><search_depth>basic or advanced</search_depth><include_domains>domain1,domain2</include_domains><exclude_domains>domain1,domain2</exclude_domains>