diff --git a/frontend/src/components/workspace/agents/agent-card.tsx b/frontend/src/components/workspace/agents/agent-card.tsx index ce1d8ce18..8cb7f6b7a 100644 --- a/frontend/src/components/workspace/agents/agent-card.tsx +++ b/frontend/src/components/workspace/agents/agent-card.tsx @@ -2,7 +2,7 @@ import { BotIcon, MessageSquareIcon, Trash2Icon } from "lucide-react"; import { useRouter } from "next/navigation"; -import { useState } from "react"; +import { type ComponentProps, type ReactElement, useState } from "react"; import { toast } from "sonner"; import { Badge } from "@/components/ui/badge"; @@ -23,14 +23,83 @@ import { DialogHeader, DialogTitle, } from "@/components/ui/dialog"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; import { useDeleteAgent } from "@/core/agents"; import type { Agent } from "@/core/agents"; import { useI18n } from "@/core/i18n/hooks"; +import { cn } from "@/lib/utils"; interface AgentCardProps { agent: Agent; } +/** + * Reveals the full text in a tooltip ONLY when its trigger is actually clipped. + * Clipping is measured on pointer enter against the trigger's own box, covering + * both single-line `truncate` (width) and multi-line `line-clamp` (height), so + * untruncated content never pops a redundant tooltip. + */ +function TruncatedTooltip({ + text, + children, +}: { + text: string; + children: ReactElement; +}) { + const [truncated, setTruncated] = useState(false); + return ( + + { + const el = e.currentTarget; + setTruncated( + el.scrollWidth > el.clientWidth || + el.scrollHeight > el.clientHeight, + ); + }} + > + {children} + + {truncated && ( + + {text} + + )} + + ); +} + +/** + * Long, user-controlled labels (agent model, skills, tool groups) that must + * never break the card layout: width is capped to the parent and the text is + * truncated with an ellipsis, with the full value revealed on hover. + */ +function TruncatedBadge({ + label, + variant, + className, +}: { + label: string; + variant: ComponentProps["variant"]; + className?: string; +}) { + return ( + + + {label} + + + ); +} + export function AgentCard({ agent }: AgentCardProps) { const { t } = useI18n(); const router = useRouter(); @@ -55,27 +124,33 @@ export function AgentCard({ agent }: AgentCardProps) { <> -
-
+
+
- - {agent.name} - + + + {agent.name} + + {agent.model && ( - - {agent.model} - + )}
{agent.description && ( - - {agent.description} - + + + {agent.description} + + )} @@ -83,22 +158,20 @@ export function AgentCard({ agent }: AgentCardProps) {
{agent.tool_groups?.map((group) => ( - - {group} - + /> ))} {agent.skills?.map((skill) => ( - - {skill} - + /> ))}