2025-08-25 13:54:13 -04:00
|
|
|
import React, { useMemo } from 'react';
|
2025-08-04 18:50:54 +02:00
|
|
|
import { Label } from '@librechat/client';
|
2025-06-23 10:22:27 -04:00
|
|
|
import type t from 'librechat-data-provider';
|
2025-08-25 13:54:13 -04:00
|
|
|
import { useLocalize, TranslationKeys, useAgentCategories } from '~/hooks';
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
import { cn, renderAgentAvatar, getContactDisplayName } from '~/utils';
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
interface AgentCardProps {
|
|
|
|
|
agent: t.Agent; // The agent data to display
|
|
|
|
|
onClick: () => void; // Callback when card is clicked
|
|
|
|
|
className?: string; // Additional CSS classes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Card component to display agent information
|
|
|
|
|
*/
|
|
|
|
|
const AgentCard: React.FC<AgentCardProps> = ({ agent, onClick, className = '' }) => {
|
|
|
|
|
const localize = useLocalize();
|
2025-08-25 13:54:13 -04:00
|
|
|
const { categories } = useAgentCategories();
|
|
|
|
|
|
|
|
|
|
const categoryLabel = useMemo(() => {
|
|
|
|
|
if (!agent.category) return '';
|
|
|
|
|
|
|
|
|
|
const category = categories.find((cat) => cat.value === agent.category);
|
|
|
|
|
if (category) {
|
|
|
|
|
if (category.label && category.label.startsWith('com_')) {
|
|
|
|
|
return localize(category.label as TranslationKeys);
|
|
|
|
|
}
|
|
|
|
|
return category.label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return agent.category.charAt(0).toUpperCase() + agent.category.slice(1);
|
|
|
|
|
}, [agent.category, categories, localize]);
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
2025-08-04 18:50:54 +02:00
|
|
|
'group relative h-40 overflow-hidden rounded-xl border border-border-light',
|
|
|
|
|
'cursor-pointer shadow-sm transition-all duration-200 hover:border-border-medium hover:shadow-lg',
|
|
|
|
|
'bg-surface-tertiary hover:bg-surface-hover',
|
|
|
|
|
'space-y-3 p-4',
|
2025-06-23 10:22:27 -04:00
|
|
|
className,
|
|
|
|
|
)}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
aria-label={localize('com_agents_agent_card_label', {
|
|
|
|
|
name: agent.name,
|
2025-08-15 20:59:10 +02:00
|
|
|
description: agent.description ?? '',
|
2025-06-23 10:22:27 -04:00
|
|
|
})}
|
|
|
|
|
aria-describedby={`agent-${agent.id}-description`}
|
|
|
|
|
tabIndex={0}
|
|
|
|
|
role="button"
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onClick();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-08-04 18:50:54 +02:00
|
|
|
{/* Two column layout */}
|
|
|
|
|
<div className="flex h-full items-start gap-3">
|
|
|
|
|
{/* Left column: Avatar and Category */}
|
|
|
|
|
<div className="flex h-full flex-shrink-0 flex-col justify-between space-y-4">
|
|
|
|
|
<div className="flex-shrink-0">{renderAgentAvatar(agent, { size: 'sm' })}</div>
|
|
|
|
|
|
|
|
|
|
{/* Category tag */}
|
2025-08-15 20:59:10 +02:00
|
|
|
{agent.category && (
|
|
|
|
|
<div className="inline-flex items-center rounded-md border-border-xheavy bg-surface-active-alt px-2 py-1 text-xs font-medium">
|
2025-08-25 13:54:13 -04:00
|
|
|
<Label className="line-clamp-1 font-normal">{categoryLabel}</Label>
|
2025-08-15 20:59:10 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-06-23 10:22:27 -04:00
|
|
|
</div>
|
|
|
|
|
|
2025-08-04 18:50:54 +02:00
|
|
|
{/* Right column: Name, description, and other content */}
|
2025-08-15 20:59:10 +02:00
|
|
|
<div className="flex h-full min-w-0 flex-1 flex-col justify-between space-y-1">
|
|
|
|
|
<div className="space-y-1">
|
2025-08-04 18:50:54 +02:00
|
|
|
{/* Agent name */}
|
|
|
|
|
<Label className="mb-1 line-clamp-1 text-xl font-semibold text-text-primary">
|
|
|
|
|
{agent.name}
|
|
|
|
|
</Label>
|
2025-06-23 10:22:27 -04:00
|
|
|
|
2025-08-15 20:59:10 +02:00
|
|
|
{/* Agent description */}
|
|
|
|
|
<p
|
|
|
|
|
id={`agent-${agent.id}-description`}
|
|
|
|
|
className="line-clamp-3 text-sm leading-relaxed text-text-primary"
|
|
|
|
|
{...(agent.description ? { 'aria-label': `Description: ${agent.description}` } : {})}
|
|
|
|
|
>
|
|
|
|
|
{agent.description ?? ''}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Owner info - moved to bottom right */}
|
|
|
|
|
{(() => {
|
|
|
|
|
const displayName = getContactDisplayName(agent);
|
|
|
|
|
if (displayName) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex justify-end">
|
2025-08-04 18:50:54 +02:00
|
|
|
<div className="flex items-center text-sm text-text-secondary">
|
|
|
|
|
<Label>{displayName}</Label>
|
|
|
|
|
</div>
|
2025-08-15 20:59:10 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
})()}
|
2025-06-23 10:22:27 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AgentCard;
|