'use client'; import { Attachment, ToolInvocation } from 'ai'; import cx from 'classnames'; import { motion } from 'framer-motion'; import { Sparkles } from 'lucide-react'; import { Dispatch, ReactNode, SetStateAction } from 'react'; import { UICanvas } from './canvas'; import { DocumentToolCall, DocumentToolResult } from './document'; import { Markdown } from './markdown'; import { PreviewAttachment } from './preview-attachment'; import { Weather } from './weather'; export const Message = ({ role, content, toolInvocations, attachments, canvas, setCanvas, }: { role: string; content: string | ReactNode; toolInvocations: Array | undefined; attachments?: Array; canvas: UICanvas | null; setCanvas: Dispatch>; }) => { return (
{role === 'assistant' && (
)}
{content && (
{content as string}
)} {toolInvocations && toolInvocations.length > 0 && (
{toolInvocations.map((toolInvocation) => { const { toolName, toolCallId, state, args } = toolInvocation; if (state === 'result') { const { result } = toolInvocation; return (
{toolName === 'getWeather' ? ( ) : toolName === 'createDocument' ? ( ) : toolName === 'updateDocument' ? ( ) : toolName === 'requestSuggestions' ? ( ) : (
{JSON.stringify(result, null, 2)}
)}
); } else { return (
{toolName === 'getWeather' ? ( ) : toolName === 'createDocument' ? ( ) : toolName === 'updateDocument' ? ( ) : toolName === 'requestSuggestions' ? ( ) : null}
); } })}
)} {attachments && (
{attachments.map((attachment) => ( ))}
)}
); };