'use client'; import React, { useState } from 'react'; import { useChat } from '@ai-sdk/react'; import { DefaultChatTransport } from 'ai'; import { Conversation, ConversationContent, ConversationEmptyState, ConversationScrollButton, } from '@/components/ai-elements/conversation'; import { Message, MessageContent, MessageResponse, } from '@/components/ai-elements/message'; import { PromptInput, PromptInputBody, PromptInputTextarea, PromptInputFooter, PromptInputSubmit, } from '@/components/ai-elements/prompt-input'; import { Tool, ToolHeader, ToolContent, ToolInput, ToolOutput, } from '@/components/ai-elements/tool'; import { Shimmer } from '@/components/ai-elements/shimmer'; import { Button } from '@/components/ui/button'; import { RiSparkling2Line, RiCloseLine, RiExpandLeftRightLine, } from '@remixicon/react'; const SUGGESTIONS = [ 'What do you sell?', 'Show me hoodies under $100', 'What collections are there?', ]; // Human-readable labels for the tool names exposed by /api/chat. const TOOL_LABELS: Record = { searchCatalogue: 'Searching the catalogue', getProductDetails: 'Reading product details', listCollections: 'Listing collections', getCollectionProducts: 'Browsing a collection', browseProducts: 'Browsing new arrivals', }; const toolLabel = (type: string) => { const name = type.startsWith('tool-') ? type.slice(5) : type; return TOOL_LABELS[name] ?? name; }; const StoreAssistant: React.FC = () => { const [open, setOpen] = useState(false); const [expanded, setExpanded] = useState(false); const [input, setInput] = useState(''); const { messages, sendMessage, status, error } = useChat({ transport: new DefaultChatTransport({ api: '/api/chat' }), }); const isBusy = status === 'submitted' || status === 'streaming'; const send = (text: string) => { const trimmed = text.trim(); if (!trimmed || isBusy) return; sendMessage({ text: trimmed }); setInput(''); }; return ( <> {/* Launcher */} {!open && ( )} {/* Sidebar */} ); }; export default StoreAssistant;