/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/agents/dialogs/AgentToolDialog.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 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 { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Label } from "@/components/ui/label"; import { Agent } from "@/types/agent"; import { useState, useEffect } from "react"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; import { listAgents } from "@/services/agentService"; import { Loader2 } from "lucide-react"; interface AgentToolDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSave: (tool: { id: string; envs: Record }) => void; currentAgentId?: string; folderId?: string | null; clientId: string; } export function AgentToolDialog({ open, onOpenChange, onSave, currentAgentId, folderId, clientId, }: AgentToolDialogProps) { const [selectedAgentId, setSelectedAgentId] = useState(""); const [search, setSearch] = useState(""); const [agents, setAgents] = useState([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { if (open) { setSelectedAgentId(""); setSearch(""); loadAgents(); } }, [open, folderId, clientId]); const loadAgents = async () => { if (!clientId) return; setIsLoading(true); try { const res = await listAgents( clientId, 0, 100, folderId || undefined ); // Filter out the current agent to avoid self-reference const filteredAgents = res.data.filter(agent => agent.id !== currentAgentId ); setAgents(filteredAgents); } catch (error) { console.error("Error loading agents:", error); } finally { setIsLoading(false); } }; const handleSave = () => { if (!selectedAgentId) return; onSave({ id: selectedAgentId, envs: {} }); onOpenChange(false); }; const filteredAgents = agents.filter((agent) => agent.name.toLowerCase().includes(search.toLowerCase()) ); return ( Add Agent Tool Select an agent to add as a tool.
setSearch(e.target.value)} className="mb-2 bg-[#222] border-[#444] text-white placeholder:text-neutral-400" />
{isLoading ? (
Loading agents...
) : filteredAgents.length === 0 ? (
{search ? `No agents found matching "${search}"` : "No agents found in this folder."}
) : ( filteredAgents.map((agent) => ( )) )}
); }