/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/chat/components/ChatContainer.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 14, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ "use client"; import React, { useRef, useEffect, useState } from "react"; import { ScrollArea } from "@/components/ui/scroll-area"; import { MessageSquare, Loader2, Bot, Zap } from "lucide-react"; import { ChatMessage } from "./ChatMessage"; import { ChatInput } from "./ChatInput"; import { ChatMessage as ChatMessageType } from "@/services/sessionService"; import { cn } from "@/lib/utils"; interface FunctionMessageContent { title: string; content: string; author?: string; } interface ChatContainerProps { messages: ChatMessageType[]; isLoading: boolean; onSendMessage: (message: string) => void; agentColor: string; expandedFunctions: Record; toggleFunctionExpansion: (messageId: string) => void; containsMarkdown: (text: string) => boolean; getMessageText: (message: ChatMessageType) => string | FunctionMessageContent; agentName?: string; containerClassName?: string; messagesContainerClassName?: string; inputContainerClassName?: string; sessionId?: string; } export function ChatContainer({ messages, isLoading, onSendMessage, agentColor, expandedFunctions, toggleFunctionExpansion, containsMarkdown, getMessageText, agentName = "Agent", containerClassName = "", messagesContainerClassName = "", inputContainerClassName = "", sessionId, }: ChatContainerProps) { const messagesContainerRef = useRef(null); const [isInitializing, setIsInitializing] = useState(false); const scrollToBottom = () => { if (messagesContainerRef.current) { messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight; } }; useEffect(() => { if (messages.length > 0) { setTimeout(scrollToBottom, 100); } }, [messages]); // Simulate initial loading for smoother UX useEffect(() => { if (sessionId) { setIsInitializing(true); const timer = setTimeout(() => { setIsInitializing(false); }, 1000); return () => clearTimeout(timer); } }, [sessionId]); const isEmpty = messages.length === 0; return (
{isInitializing ? (

Loading conversation...

) : isEmpty ? (

{`Chat with ${agentName}`}

Type your message below to start the conversation. This chat will help you interact with the agent and explore its capabilities.

) : (
{messages.map((message) => { const messageContent = getMessageText(message); const isExpanded = expandedFunctions[message.id] || false; return ( ); })}
)}
{isLoading && !isInitializing && (
Agent is thinking...
)}
); }