mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-23 16:16:34 +01:00
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Waiting to run
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
* chore: Remove unused setValueOnChange prop from MCPServerMenuItem component
* fix: Resolve agent provider endpoint type for file upload support
When using the agents endpoint with a custom provider (e.g., Moonshot),
the endpointType was resolving to "agents" instead of the provider's
actual type ("custom"), causing "Upload to Provider" to not appear in
the file attach menu.
Adds `resolveEndpointType` utility in data-provider that follows the
chain: endpoint (if not agents) → agent.provider → agents. Applied
consistently across AttachFileChat, DragDropContext, useDragHelpers,
and AgentPanel file components (FileContext, FileSearch, Code/Files).
* refactor: Extract useAgentFileConfig hook, restore deleted tests, fix review findings
- Extract shared provider resolution logic into useAgentFileConfig hook
(Finding #2: DRY violation across FileContext, FileSearch, Code/Files)
- Restore 18 deleted test cases in AttachFileMenu.spec.tsx covering
agent capabilities, SharePoint, edge cases, and button state
(Finding #1: accidental test deletion)
- Wrap fileConfigEndpoint in useMemo in AttachFileChat (Finding #3)
- Fix misleading test name in AgentFileConfig.spec.tsx (Finding #4)
- Fix import order in FileSearch.tsx, FileContext.tsx, Code/Files.tsx (Finding #5)
- Add comment about cache gap in useDragHelpers (Finding #6)
- Clarify resolveEndpointType JSDoc (Finding #7)
* refactor: Memoize Footer component for performance optimization
- Converted Footer component to a memoized version to prevent unnecessary re-renders.
- Improved import structure by adding memo to the React import statement for clarity.
* chore: Fix remaining review nits
- Widen useAgentFileConfig return type to EModelEndpoint | string
- Fix import order in FileContext.tsx and FileSearch.tsx
- Remove dead endpointType param from setupMocks in AttachFileMenu test
* fix: Pass resolved provider endpoint to file upload validation
AgentPanel file components (FileContext, FileSearch, Code/Files) were
hardcoding endpointOverride to "agents", causing both client-side
validation (file limits, MIME types) and server-side validation to
use the agents config instead of the provider-specific config.
Adds endpointTypeOverride to UseFileHandling params so endpoint and
endpointType can be set independently. Components now pass the
resolved provider name and type from useAgentFileConfig, so the full
fallback chain (provider → custom → agents → default) applies to
file upload validation on both client and server.
* test: Verify any custom endpoint is document-supported regardless of name
Adds parameterized tests with arbitrary endpoint names (spaces, hyphens,
colons, etc.) confirming that all custom endpoints resolve to
document-supported through resolveEndpointType, both as direct
endpoints and as agent providers.
* fix: Use || for provider fallback, test endpointOverride wiring
- Change providerValue ?? to providerValue || so empty string is
treated as "no provider" consistently with resolveEndpointType
- Add wiring tests to CodeFiles, FileContext, FileSearch verifying
endpointOverride and endpointTypeOverride are passed correctly
- Update endpointOverride JSDoc to document endpointType fallback
112 lines
3.9 KiB
TypeScript
112 lines
3.9 KiB
TypeScript
import * as Ariakit from '@ariakit/react';
|
|
import { Check } from 'lucide-react';
|
|
import { MCPIcon } from '@librechat/client';
|
|
import type { MCPServerDefinition } from '~/hooks/MCP/useMCPServerManager';
|
|
import type { MCPServerStatusIconProps } from './MCPServerStatusIcon';
|
|
import MCPServerStatusIcon from './MCPServerStatusIcon';
|
|
import {
|
|
getStatusColor,
|
|
getStatusTextKey,
|
|
shouldShowActionButton,
|
|
type ConnectionStatusMap,
|
|
} from './mcpServerUtils';
|
|
import { useLocalize } from '~/hooks';
|
|
import { cn } from '~/utils';
|
|
|
|
interface MCPServerMenuItemProps {
|
|
server: MCPServerDefinition;
|
|
isSelected: boolean;
|
|
connectionStatus?: ConnectionStatusMap;
|
|
isInitializing?: (serverName: string) => boolean;
|
|
statusIconProps?: MCPServerStatusIconProps | null;
|
|
onToggle: (serverName: string) => void;
|
|
}
|
|
|
|
export default function MCPServerMenuItem({
|
|
server,
|
|
isSelected,
|
|
connectionStatus,
|
|
isInitializing,
|
|
statusIconProps,
|
|
onToggle,
|
|
}: MCPServerMenuItemProps) {
|
|
const localize = useLocalize();
|
|
const displayName = server.config?.title || server.serverName;
|
|
const statusColor = getStatusColor(server.serverName, connectionStatus, isInitializing);
|
|
const statusTextKey = getStatusTextKey(server.serverName, connectionStatus, isInitializing);
|
|
const statusText = localize(statusTextKey as Parameters<typeof localize>[0]);
|
|
const showActionButton = shouldShowActionButton(statusIconProps);
|
|
|
|
// Include status in aria-label so screen readers announce it
|
|
const accessibleLabel = `${displayName}, ${statusText}`;
|
|
|
|
return (
|
|
<Ariakit.MenuItemCheckbox
|
|
hideOnClick={false}
|
|
name="mcp-servers"
|
|
value={server.serverName}
|
|
checked={isSelected}
|
|
onChange={() => onToggle(server.serverName)}
|
|
aria-label={accessibleLabel}
|
|
className={cn(
|
|
'group flex w-full cursor-pointer items-center gap-3 rounded-lg px-2.5 py-2',
|
|
'outline-none transition-all duration-150',
|
|
'hover:bg-surface-hover data-[active-item]:bg-surface-hover',
|
|
isSelected && 'bg-surface-active-alt',
|
|
)}
|
|
>
|
|
{/* Server Icon with Status Dot */}
|
|
<div className="relative flex-shrink-0">
|
|
{server.config?.iconPath ? (
|
|
<img
|
|
src={server.config.iconPath}
|
|
className="h-8 w-8 rounded-lg object-cover"
|
|
alt={displayName}
|
|
/>
|
|
) : (
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-surface-tertiary">
|
|
<MCPIcon className="h-5 w-5 text-text-secondary" />
|
|
</div>
|
|
)}
|
|
{/* Status dot - decorative, status is announced via aria-label on MenuItem */}
|
|
<div
|
|
aria-hidden="true"
|
|
className={cn(
|
|
'absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-surface-secondary',
|
|
statusColor,
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
{/* Server Info */}
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex items-center gap-1.5">
|
|
<span className="truncate text-sm font-medium text-text-primary">{displayName}</span>
|
|
</div>
|
|
{server.config?.description && (
|
|
<p className="truncate text-xs text-text-secondary">{server.config.description}</p>
|
|
)}
|
|
</div>
|
|
|
|
{/* Action Button - only show when actionable */}
|
|
{showActionButton && statusIconProps && (
|
|
<div className="flex-shrink-0" onClick={(e) => e.stopPropagation()}>
|
|
<MCPServerStatusIcon {...statusIconProps} />
|
|
</div>
|
|
)}
|
|
|
|
{/* Selection Indicator - purely visual, state conveyed by aria-checked on MenuItem */}
|
|
<span
|
|
aria-hidden="true"
|
|
className={cn(
|
|
'flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-sm border',
|
|
isSelected
|
|
? 'border-primary bg-primary text-primary-foreground'
|
|
: 'border-border-xheavy bg-transparent',
|
|
)}
|
|
>
|
|
{isSelected && <Check className="h-4 w-4" />}
|
|
</span>
|
|
</Ariakit.MenuItemCheckbox>
|
|
);
|
|
}
|