'use client'; import ChatInput from '@/component/chat-input'; import { useChat } from '@ai-sdk/react'; import { DefaultChatTransport } from 'ai'; import { ToolsMessage } from '../api/dynamic-tools/route'; export default function Chat() { const { messages, sendMessage, status } = useChat({ transport: new DefaultChatTransport({ api: '/api/dynamic-tools' }), }); return (
{messages?.map(message => (
{`${message.role}: `} {message.parts.map((part, index) => { switch (part.type) { case 'text': return
{part.text}
; case 'step-start': return index > 0 ? (

) : null; case 'dynamic-tool': { switch (part.state) { case 'input-streaming': case 'input-available': case 'output-available': return (
{JSON.stringify(part, null, 2)}
); case 'output-error': return (
Error: {part.errorText}
); } } case 'tool-getWeatherInformation': { switch (part.state) { // example of pre-rendering streaming tool calls: case 'input-streaming': return (
                        {JSON.stringify(part.input, null, 2)}
                      
); case 'input-available': return (
Getting weather information for {part.input.city}...
); case 'output-available': return (
Weather in {part.input.city}: {part.output}
); case 'output-error': return (
Error: {part.errorText}
); } } } })}
))} sendMessage({ text })} />
); }