mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-03 22:37:20 +02:00
* refactor(OpenSidebar): removed useless classNames
* style(Header): update hover styles across various components for improved UI consistency
* style(Nav): update hover styles in AccountSettings and SearchBar for improved UI consistency
* style: update button classes for consistent hover effects and improved UI responsiveness
* style(Nav, OpenSidebar, Header, Convo): improve UI responsiveness and animation transitions
* style(PresetsMenu, NewChat): update icon sizes and improve component styling for better UI consistency
* style(Nav, Root): enhance sidebar mobile animations and responsiveness for better UI experience
* style(ExportAndShareMenu, BookmarkMenu): update icon sizes for improved UI consistency
* style: remove transition duration from button classes for improved UI responsiveness
* style(CustomMenu, ModelSelector): update background colors for improved UI consistency and responsiveness
* style(ExportAndShareMenu): update icon color for improved UI consistency
* style(TemporaryChat): refine button styles for improved UI consistency and responsiveness
* style(BookmarkNav): refactor to use DropdownPopup and remove BookmarkNavItems for improved UI consistency and functionality
* style(CustomMenu, EndpointItem): enhance UI elements for improved consistency and accessibility
* style(EndpointItem): adjust gap in icon container for improved layout consistency
* style(CustomMenu, EndpointItem): update focus ring color for improved UI consistency
* style(EndpointItem): update icon color for improved UI consistency in dark theme
* style: update focus styles for improved accessibility and consistency across components
* refactor(Nav): extract sidebar width to NAV_WIDTH constant
Centralize mobile (320px) and desktop (260px) sidebar widths in a single
exported constant to avoid magic numbers and ensure consistency.
* fix(BookmarkNav): memoize handlers used in useMemo
Wrap handleTagClick and handleClear in useCallback and add them to the
dropdownItems useMemo dependency array to prevent stale closures.
* feat: introduce FilterInput component and replace existing inputs with it across multiple components
* feat(DataTable): replace custom input with FilterInput component for improved filtering
* fix: Nested dialog overlay stacking issue
Fixes overlay appearing behind content when opening nested dialogs.
Introduced dynamic z-index calculation based on dialog depth using React context.
- First dialog: overlay z-50, content z-100
- Nested dialogs increment by 60: overlay z-110/content z-160, etc.
Preserves a11y escape key handling from #10975 and #10851.
Regression from #11008 (afb67fcf1) which increased content z-index
without adjusting overlay z-index for nested dialog scenarios.
* Refactor admin settings components to use a unified AdminSettingsDialog
- Removed redundant code from AdminSettings, MCPAdminSettings, and Memories AdminSettings components.
- Introduced AdminSettingsDialog component to handle permission management for different sections.
- Updated permission handling logic to use a consistent structure across components.
- Enhanced role selection and permission confirmation features in the new dialog.
- Improved UI consistency and maintainability by centralizing dialog functionality.
* refactor(Memory): memory management UI components and replace MemoryViewer with MemoryPanel
* refactor(Memory): enhance UI components for Memory dialogs and improve input styling
* refactor(Bookmarks): improve bookmark management UI with enhanced styling
* refactor(translations): remove redundant filter input and bookmark count entries
* refactor(Convo): integrate useShiftKey hook for enhanced keyboard interaction and improve UI responsiveness
344 lines
11 KiB
TypeScript
344 lines
11 KiB
TypeScript
import React, { useState, useMemo, useCallback } from 'react';
|
|
import * as Ariakit from '@ariakit/react';
|
|
import { Globe, Settings, Settings2, TerminalSquareIcon } from 'lucide-react';
|
|
import { TooltipAnchor, DropdownPopup, PinIcon, VectorIcon } from '@librechat/client';
|
|
import type { MenuItemProps } from '~/common';
|
|
import {
|
|
AuthType,
|
|
Permissions,
|
|
ArtifactModes,
|
|
PermissionTypes,
|
|
defaultAgentCapabilities,
|
|
} from 'librechat-data-provider';
|
|
import { useLocalize, useHasAccess, useAgentCapabilities } from '~/hooks';
|
|
import ArtifactsSubMenu from '~/components/Chat/Input/ArtifactsSubMenu';
|
|
import MCPSubMenu from '~/components/Chat/Input/MCPSubMenu';
|
|
import { useGetStartupConfig } from '~/data-provider';
|
|
import { useBadgeRowContext } from '~/Providers';
|
|
import { cn } from '~/utils';
|
|
|
|
interface ToolsDropdownProps {
|
|
disabled?: boolean;
|
|
}
|
|
|
|
const ToolsDropdown = ({ disabled }: ToolsDropdownProps) => {
|
|
const localize = useLocalize();
|
|
const isDisabled = disabled ?? false;
|
|
const [isPopoverActive, setIsPopoverActive] = useState(false);
|
|
const {
|
|
webSearch,
|
|
artifacts,
|
|
fileSearch,
|
|
agentsConfig,
|
|
mcpServerManager,
|
|
codeApiKeyForm,
|
|
codeInterpreter,
|
|
searchApiKeyForm,
|
|
} = useBadgeRowContext();
|
|
const { data: startupConfig } = useGetStartupConfig();
|
|
|
|
const { codeEnabled, webSearchEnabled, artifactsEnabled, fileSearchEnabled } =
|
|
useAgentCapabilities(agentsConfig?.capabilities ?? defaultAgentCapabilities);
|
|
|
|
const { setIsDialogOpen: setIsCodeDialogOpen, menuTriggerRef: codeMenuTriggerRef } =
|
|
codeApiKeyForm;
|
|
const { setIsDialogOpen: setIsSearchDialogOpen, menuTriggerRef: searchMenuTriggerRef } =
|
|
searchApiKeyForm;
|
|
const {
|
|
isPinned: isSearchPinned,
|
|
setIsPinned: setIsSearchPinned,
|
|
authData: webSearchAuthData,
|
|
} = webSearch;
|
|
const {
|
|
isPinned: isCodePinned,
|
|
setIsPinned: setIsCodePinned,
|
|
authData: codeAuthData,
|
|
} = codeInterpreter;
|
|
const { isPinned: isFileSearchPinned, setIsPinned: setIsFileSearchPinned } = fileSearch;
|
|
const { isPinned: isArtifactsPinned, setIsPinned: setIsArtifactsPinned } = artifacts;
|
|
|
|
const canUseWebSearch = useHasAccess({
|
|
permissionType: PermissionTypes.WEB_SEARCH,
|
|
permission: Permissions.USE,
|
|
});
|
|
|
|
const canRunCode = useHasAccess({
|
|
permissionType: PermissionTypes.RUN_CODE,
|
|
permission: Permissions.USE,
|
|
});
|
|
|
|
const canUseFileSearch = useHasAccess({
|
|
permissionType: PermissionTypes.FILE_SEARCH,
|
|
permission: Permissions.USE,
|
|
});
|
|
|
|
const canUseMcp = useHasAccess({
|
|
permissionType: PermissionTypes.MCP_SERVERS,
|
|
permission: Permissions.USE,
|
|
});
|
|
|
|
const showWebSearchSettings = useMemo(() => {
|
|
const authTypes = webSearchAuthData?.authTypes ?? [];
|
|
if (authTypes.length === 0) return true;
|
|
return !authTypes.every(([, authType]) => authType === AuthType.SYSTEM_DEFINED);
|
|
}, [webSearchAuthData?.authTypes]);
|
|
|
|
const showCodeSettings = useMemo(
|
|
() => codeAuthData?.message !== AuthType.SYSTEM_DEFINED,
|
|
[codeAuthData?.message],
|
|
);
|
|
|
|
const handleWebSearchToggle = useCallback(() => {
|
|
const newValue = !webSearch.toggleState;
|
|
webSearch.debouncedChange({ value: newValue });
|
|
}, [webSearch]);
|
|
|
|
const handleCodeInterpreterToggle = useCallback(() => {
|
|
const newValue = !codeInterpreter.toggleState;
|
|
codeInterpreter.debouncedChange({ value: newValue });
|
|
}, [codeInterpreter]);
|
|
|
|
const handleFileSearchToggle = useCallback(() => {
|
|
const newValue = !fileSearch.toggleState;
|
|
fileSearch.debouncedChange({ value: newValue });
|
|
}, [fileSearch]);
|
|
|
|
const handleArtifactsToggle = useCallback(() => {
|
|
const currentState = artifacts.toggleState;
|
|
if (!currentState || currentState === '') {
|
|
artifacts.debouncedChange({ value: ArtifactModes.DEFAULT });
|
|
} else {
|
|
artifacts.debouncedChange({ value: '' });
|
|
}
|
|
}, [artifacts]);
|
|
|
|
const handleShadcnToggle = useCallback(() => {
|
|
const currentState = artifacts.toggleState;
|
|
if (currentState === ArtifactModes.SHADCNUI) {
|
|
artifacts.debouncedChange({ value: ArtifactModes.DEFAULT });
|
|
} else {
|
|
artifacts.debouncedChange({ value: ArtifactModes.SHADCNUI });
|
|
}
|
|
}, [artifacts]);
|
|
|
|
const handleCustomToggle = useCallback(() => {
|
|
const currentState = artifacts.toggleState;
|
|
if (currentState === ArtifactModes.CUSTOM) {
|
|
artifacts.debouncedChange({ value: ArtifactModes.DEFAULT });
|
|
} else {
|
|
artifacts.debouncedChange({ value: ArtifactModes.CUSTOM });
|
|
}
|
|
}, [artifacts]);
|
|
|
|
const mcpPlaceholder = startupConfig?.interface?.mcpServers?.placeholder;
|
|
|
|
const dropdownItems: MenuItemProps[] = [];
|
|
|
|
if (fileSearchEnabled && canUseFileSearch) {
|
|
dropdownItems.push({
|
|
onClick: handleFileSearchToggle,
|
|
hideOnClick: false,
|
|
render: (props) => (
|
|
<div {...props}>
|
|
<div className="flex items-center gap-2">
|
|
<VectorIcon className="icon-md" />
|
|
<span>{localize('com_assistants_file_search')}</span>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
setIsFileSearchPinned(!isFileSearchPinned);
|
|
}}
|
|
className={cn(
|
|
'rounded p-1 transition-all duration-200',
|
|
'hover:bg-surface-secondary hover:shadow-sm',
|
|
!isFileSearchPinned && 'text-text-secondary hover:text-text-primary',
|
|
)}
|
|
aria-label={isFileSearchPinned ? 'Unpin' : 'Pin'}
|
|
>
|
|
<div className="h-4 w-4">
|
|
<PinIcon unpin={isFileSearchPinned} />
|
|
</div>
|
|
</button>
|
|
</div>
|
|
),
|
|
});
|
|
}
|
|
|
|
if (canUseWebSearch && webSearchEnabled) {
|
|
dropdownItems.push({
|
|
onClick: handleWebSearchToggle,
|
|
hideOnClick: false,
|
|
render: (props) => (
|
|
<div {...props}>
|
|
<div className="flex items-center gap-2">
|
|
<Globe className="icon-md" aria-hidden="true" />
|
|
<span>{localize('com_ui_web_search')}</span>
|
|
</div>
|
|
<div className="flex items-center gap-1">
|
|
{showWebSearchSettings && (
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
setIsSearchDialogOpen(true);
|
|
}}
|
|
className={cn(
|
|
'rounded p-1 transition-all duration-200',
|
|
'hover:bg-surface-secondary hover:shadow-sm',
|
|
'text-text-secondary hover:text-text-primary',
|
|
)}
|
|
aria-label="Configure web search"
|
|
ref={searchMenuTriggerRef}
|
|
>
|
|
<div className="h-4 w-4">
|
|
<Settings className="h-4 w-4" aria-hidden="true" />
|
|
</div>
|
|
</button>
|
|
)}
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
setIsSearchPinned(!isSearchPinned);
|
|
}}
|
|
className={cn(
|
|
'rounded p-1 transition-all duration-200',
|
|
'hover:bg-surface-secondary hover:shadow-sm',
|
|
!isSearchPinned && 'text-text-secondary hover:text-text-primary',
|
|
)}
|
|
aria-label={isSearchPinned ? 'Unpin' : 'Pin'}
|
|
>
|
|
<div className="h-4 w-4">
|
|
<PinIcon unpin={isSearchPinned} />
|
|
</div>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
),
|
|
});
|
|
}
|
|
|
|
if (canRunCode && codeEnabled) {
|
|
dropdownItems.push({
|
|
onClick: handleCodeInterpreterToggle,
|
|
hideOnClick: false,
|
|
render: (props) => (
|
|
<div {...props}>
|
|
<div className="flex items-center gap-2">
|
|
<TerminalSquareIcon className="icon-md" aria-hidden="true" />
|
|
<span>{localize('com_assistants_code_interpreter')}</span>
|
|
</div>
|
|
<div className="flex items-center gap-1">
|
|
{showCodeSettings && (
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
setIsCodeDialogOpen(true);
|
|
}}
|
|
ref={codeMenuTriggerRef}
|
|
className={cn(
|
|
'rounded p-1 transition-all duration-200',
|
|
'hover:bg-surface-secondary hover:shadow-sm',
|
|
'text-text-secondary hover:text-text-primary',
|
|
)}
|
|
aria-label="Configure code interpreter"
|
|
>
|
|
<div className="h-4 w-4">
|
|
<Settings className="h-4 w-4" aria-hidden="true" />
|
|
</div>
|
|
</button>
|
|
)}
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
setIsCodePinned(!isCodePinned);
|
|
}}
|
|
className={cn(
|
|
'rounded p-1 transition-all duration-200',
|
|
'hover:bg-surface-secondary hover:shadow-sm',
|
|
!isCodePinned && 'text-text-primary hover:text-text-primary',
|
|
)}
|
|
aria-label={isCodePinned ? 'Unpin' : 'Pin'}
|
|
>
|
|
<div className="h-4 w-4">
|
|
<PinIcon unpin={isCodePinned} />
|
|
</div>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
),
|
|
});
|
|
}
|
|
|
|
if (artifactsEnabled) {
|
|
dropdownItems.push({
|
|
hideOnClick: false,
|
|
render: (props) => (
|
|
<ArtifactsSubMenu
|
|
{...props}
|
|
isArtifactsPinned={isArtifactsPinned}
|
|
setIsArtifactsPinned={setIsArtifactsPinned}
|
|
artifactsMode={artifacts.toggleState as string}
|
|
handleArtifactsToggle={handleArtifactsToggle}
|
|
handleShadcnToggle={handleShadcnToggle}
|
|
handleCustomToggle={handleCustomToggle}
|
|
/>
|
|
),
|
|
});
|
|
}
|
|
|
|
const { availableMCPServers } = mcpServerManager;
|
|
if (canUseMcp && availableMCPServers && availableMCPServers.length > 0) {
|
|
dropdownItems.push({
|
|
hideOnClick: false,
|
|
render: (props) => <MCPSubMenu {...props} placeholder={mcpPlaceholder} />,
|
|
});
|
|
}
|
|
|
|
if (dropdownItems.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const menuTrigger = (
|
|
<TooltipAnchor
|
|
render={
|
|
<Ariakit.MenuButton
|
|
disabled={isDisabled}
|
|
id="tools-dropdown-button"
|
|
aria-label="Tools Options"
|
|
className={cn(
|
|
'flex size-9 items-center justify-center rounded-full p-1 hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-opacity-50',
|
|
isPopoverActive && 'bg-surface-hover',
|
|
)}
|
|
>
|
|
<div className="flex w-full items-center justify-center gap-2">
|
|
<Settings2 className="size-5" aria-hidden="true" />
|
|
</div>
|
|
</Ariakit.MenuButton>
|
|
}
|
|
id="tools-dropdown-button"
|
|
description={localize('com_ui_tools')}
|
|
disabled={isDisabled}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<DropdownPopup
|
|
itemClassName="flex w-full cursor-pointer rounded-lg items-center justify-between hover:bg-surface-hover gap-5"
|
|
menuId="tools-dropdown-menu"
|
|
isOpen={isPopoverActive}
|
|
setIsOpen={setIsPopoverActive}
|
|
modal={true}
|
|
unmountOnHide={true}
|
|
trigger={menuTrigger}
|
|
items={dropdownItems}
|
|
iconClassName="mr-0"
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default React.memo(ToolsDropdown);
|