/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/chat/components/AgentInfoDialog.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 } from "react"; import { Agent } from "@/types/agent"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Bot, Code, WrenchIcon, Layers, Server, TagIcon, Share, Edit, Loader2, Download, } from "lucide-react"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { ScrollArea } from "@/components/ui/scroll-area"; import { listApiKeys, ApiKey } from "@/services/agentService"; import { listMCPServers } from "@/services/mcpServerService"; import { availableModels } from "@/types/aiModels"; import { MCPServer } from "@/types/mcpServer"; import { AgentForm } from "@/app/agents/forms/AgentForm"; import { exportAsJson } from "@/lib/utils"; interface AgentInfoDialogProps { agent: Agent | null; open: boolean; onOpenChange: (open: boolean) => void; onAgentUpdated?: (updatedAgent: Agent) => void; } export function AgentInfoDialog({ agent, open, onOpenChange, onAgentUpdated, }: AgentInfoDialogProps) { const [activeTab, setActiveTab] = useState("info"); const [isAgentFormOpen, setIsAgentFormOpen] = useState(false); const [apiKeys, setApiKeys] = useState([]); const [availableMCPs, setAvailableMCPs] = useState([]); const [agents, setAgents] = useState([]); const [isLoading, setIsLoading] = useState(false); const user = typeof window !== "undefined" ? JSON.parse(localStorage.getItem("user") || "{}") : {}; const clientId = user?.client_id || ""; useEffect(() => { if (!clientId || !open) return; const loadData = async () => { try { const [apiKeysResponse, mcpServersResponse] = await Promise.all([ listApiKeys(clientId), listMCPServers(), ]); setApiKeys(apiKeysResponse.data); setAvailableMCPs(mcpServersResponse.data); } catch (error) { console.error("Error loading data for agent form:", error); } }; loadData(); }, [clientId, open]); const getAgentTypeName = (type: string) => { const agentTypes: Record = { llm: "LLM Agent", a2a: "A2A Agent", sequential: "Sequential Agent", parallel: "Parallel Agent", loop: "Loop Agent", workflow: "Workflow Agent", task: "Task Agent", }; return agentTypes[type] || type; }; const handleSaveAgent = async (agentData: Partial) => { if (!agent?.id) return; setIsLoading(true); try { const { updateAgent } = await import("@/services/agentService"); const updated = await updateAgent(agent.id, agentData as any); if (updated.data && onAgentUpdated) { onAgentUpdated(updated.data); } setIsAgentFormOpen(false); } catch (error) { console.error("Error updating agent:", error); } finally { setIsLoading(false); } }; // Function to export the agent as JSON const handleExportAgent = async () => { if (!agent) return; try { // First fetch all agents to properly resolve agent_tools references const { listAgents } = await import("@/services/agentService"); const allAgentsResponse = await listAgents(clientId, 0, 1000); const allAgents = allAgentsResponse.data || []; exportAsJson( agent, `agent-${agent.name.replace(/\s+/g, "-").toLowerCase()}-${agent.id.substring(0, 8)}`, true, allAgents ); } catch (error) { console.error("Error exporting agent:", error); } }; if (!agent) return null; const getToolsCount = () => { let count = 0; if (agent.config?.tools) count += agent.config.tools.length; if (agent.config?.custom_tools?.http_tools) count += agent.config.custom_tools.http_tools.length; if (agent.config?.agent_tools) count += agent.config.agent_tools.length; return count; }; const getSubAgentsCount = () => { return agent.config?.sub_agents?.length || 0; }; const getMCPServersCount = () => { let count = 0; if (agent.config?.mcp_servers) count += agent.config.mcp_servers.length; if (agent.config?.custom_mcp_servers) count += agent.config.custom_mcp_servers.length; return count; }; return ( <>
{agent.name} {agent.description || "No description available"}
{getAgentTypeName(agent.type)}
Information Tools Configuration
Model {agent.model || "Not specified"}
Tools {getToolsCount()}
Sub-agents {getSubAgentsCount()}

Agent Role

{agent.role || "Not specified"}

Agent Goal

{agent.goal || "Not specified"}

{/* agent instructions: agent.instruction */}

Agent Instructions

                        {agent.instruction || "No instructions provided"}
                      
{getToolsCount() > 0 ? (
{/* Built-in tools */} {agent.config?.tools && agent.config.tools.length > 0 && (

Built-in Tools

{agent.config.tools.map((tool, index) => ( {typeof tool === 'string' ? tool : 'Custom Tool'} ))}
)} {/* Agent Tools */} {agent.config?.agent_tools && agent.config.agent_tools.length > 0 && (

Agent Tools

{agent.config.agent_tools.map((agentId, index) => (
{agents.find(a => a.id === agentId)?.name || agentId}
))}
)} {/* Custom HTTP tools */} {agent.config?.custom_tools?.http_tools && agent.config.custom_tools.http_tools.length > 0 && (

Custom HTTP Tools

{agent.config.custom_tools.http_tools.map( (tool, index) => (
{tool.name}
{tool.method}
) )}
)}
) : (

This agent has no tools configured

)}
{/* MCP Servers */}

MCP Servers

{getMCPServersCount() > 0 ? (
{agent.config?.mcp_servers && agent.config.mcp_servers.map((mcp, index) => (
{mcp.id}
))} {agent.config?.custom_mcp_servers && agent.config.custom_mcp_servers.map((mcp, index) => (
{mcp.url}
))}
) : (

No MCP servers configured

)}
{/* API Key */}

API Key

{agent.api_key_id ? `Key ID: ${agent.api_key_id}` : "No API key configured"}

{/* Agent Edit Form Dialog */} {isAgentFormOpen && agent && ( {}} onOpenMCPDialog={() => {}} onOpenCustomMCPDialog={() => {}} onSave={handleSaveAgent} isLoading={isLoading} getAgentNameById={(id) => id} clientId={clientId} /> )} ); }