suggestedActions component in vercel/ai-chatbot source code.
In this article, we will review what happens when you click on “What is the weather” widget on chat.vercel.ai. Let’s find out.
Let’s start from this UI element “What is the weather”. I searched across the codebase for this string and I found this in components/suggested-actions.
function PureSuggestedActions({ chatId, append }: SuggestedActionsProps) { const suggestedActions = [ { title: 'What are the advantages', label: 'of using Next.js?', action: 'What are the advantages of using Next.js?', }, { title: 'Write code to', label: `demonstrate djikstra's algorithm`, action: `Write code to demonstrate djikstra's algorithm`, }, { title: 'Help me write an essay', label: `about silicon valley`, action: `Help me write an essay about silicon valley`, }, { title: 'What is the weather', label: 'in San Francisco?', action: 'What is the weather in San Francisco?', }, ]; return ( <div data-testid="suggested-actions" className="grid sm:grid-cols-2 gap-2 w-full" > {suggestedActions.map((suggestedAction, index) => ( <motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 20 }} transition={{ delay: 0.05 * index }} key={`suggested-action-${suggestedAction.title}-${index}`} className={index > 1 ? 'hidden sm:block' : 'block'} > <Button variant="ghost" onClick={async () => { window.history.replaceState({}, '', `/chat/${chatId}`); append({ role: 'user', content: suggestedAction.action, }); }} className="text-left border rounded-xl px-4 py-3.5 text-sm flex-1 gap-1 sm:flex-col w-full h-auto justify-start items-start" > <span className="font-medium">{suggestedAction.title}</span> <span className="text-muted-foreground"> {suggestedAction.label} </span> </Button> </motion.div> ))} </div> );}
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.