/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/shared-chat/components/SharedChatPanel.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 { useState, useEffect, useRef } from "react"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { MessageSquare, Loader2, Bot, User } from "lucide-react"; import { ChatMessage as ChatMessageType } from "@/services/sessionService"; import { ChatMessage } from "@/app/chat/components/ChatMessage"; import { FileData } from "@/lib/file-utils"; import { ChatInput } from "@/app/chat/components/ChatInput"; interface FunctionMessageContent { title: string; content: string; author?: string; } interface SharedChatPanelProps { messages: ChatMessageType[]; isLoading: boolean; isSending: boolean; agentName?: string; onSendMessage: (message: string, files?: FileData[]) => void; getMessageText: (message: ChatMessageType) => string | FunctionMessageContent; containsMarkdown: (text: string) => boolean; sessionId?: string; } export function SharedChatPanel({ messages, isLoading, isSending, agentName = "Shared Agent", onSendMessage, getMessageText, containsMarkdown, sessionId, }: SharedChatPanelProps) { const [expandedFunctions, setExpandedFunctions] = useState>({}); const messagesContainerRef = useRef(null); const scrollToBottom = () => { if (messagesContainerRef.current) { messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight; } }; useEffect(() => { if (messages.length > 0) { setTimeout(scrollToBottom, 100); } }, [messages]); const toggleFunctionExpansion = (messageId: string) => { setExpandedFunctions((prev) => ({ ...prev, [messageId]: !prev[messageId], })); }; return (
{isLoading ? (

Loading conversation...

) : messages.length === 0 ? (

{`Chat with ${agentName}`}

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

) : (
{messages.map((message) => { const messageContent = getMessageText(message); const agentColor = message.author === "user" ? "bg-emerald-500" : "bg-gradient-to-br from-neutral-800 to-neutral-900"; const isExpanded = expandedFunctions[message.id] || false; return ( ); })} {isSending && (
)}
)}
{isSending && !isLoading && (
Agent is thinking...
)}
); }