mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-07 19:18:52 +01:00
* feat: init @librechat/client * feat: Add common types and interfaces for accessibility, agents, artifacts, assistants, and tools * feat: Add jotai as a peer dependency * fix build client package * feat: cleanup unused types from common/index.ts - Remove 104 unused type exports from packages/client/src/common/index.ts - Keep only 7 actually used exports (93% reduction) - Add cleanup script with enhanced import pattern detection - Support both named imports and namespace imports (* as t) - Create automatic backups and comprehensive documentation - Maintain type safety with build verification - No breaking changes to existing code Kept exports: - TShowToast, Option, OptionWithIcon, DropdownValueSetter - MentionOption, NotificationSeverity, MenuItemProps Scripts: cleanup-common-types-safe.js, README-CLEANUP.md * fix: cleanup * fix: package; refactor: tsconfig * feat: add back `recoil` * fix: move dependencies to peerDependencies in client package * feat: add @librechat/client as a dependency in package.json and package-lock.json * feat: update client package configuration and dependencies - Added new dependencies for Rollup plugins and updated existing ones in package.json and package-lock.json. - Introduced a new Rollup configuration file for building the client package. - Refactored build scripts to include a dedicated build command for the client. - Updated TypeScript configuration for improved module resolution and type declaration output. - Integrated a Toast component from the client package into the main App component. * feat: enhance Rollup configuration for client package - Updated terser plugin settings to preserve directives like 'use client'. - Added custom warning handler to ignore "use client" directive warnings during the build process. * chore: rename package/client build script command * feat: update client package dependencies and Rollup configuration - Added rollup-plugin-postcss to package.json and updated package-lock.json. - Enhanced Rollup configuration to include postcss plugin for CSS handling. - Updated index.ts to export all components from the components directory for better modularity. * feat: add client package directory to update configuration - Included the 'client' package directory in the update.js configuration to ensure it is recognized during updates. * feat: export Toast component in client package - Added export for the Toast component in index.ts to enhance modularity and accessibility of components. * feat: /client transition to @librechat/client * chore: fixed formatting issues * fix: update peer dependencies in @librechat/client to prevent bundling them * fix: correct useSprings implementation in SplitText component * fix: circular dependencies in DataTable * fix: add remaining peer dependencies and match actual versions previously used in `client/package.json` * fix: correct frontend:ci script to include client package build * chore: enhance unused package detection for @librechat/client and improve dependency extraction * fix: add missing peer dependency for @radix-ui/react-collapsible * chore: include "packages/client" in unused i18next keys detection * test: update AgentFooter tests to use document.querySelector for spinner checks test: mock window.matchMedia in setupTests.js for consistent test environment * feat: add react-hook-form dependency and update FormInput component to use its types * chore: linting * refactor: remove unused defaultSelectedValues prop from MCPSelect and MultiSelect components * chore: linting * feat: update GitHub Actions workflow to publish @librechat/client * chore: update GitHub Actions workflow to install and build data-provider and client dependencies * chore: add missing @testing-library/react dependency to client package * chore: update tsconfig.json to exclude additional test files * chore: fix build issues, resolve latest LC changes * chore: move MCP components outside of `~/components/ui` * feat: implement dynamic theme system with environment variable support and Tailwind CSS integration * chore: remove unnecessary logging of sttExternal and ttsExternal in Speech component * chore: squashed cleanup commits chore: move @tanstack/react-virtual to dependencies and remove recoil from package.json chore: move dependencies to peerDependencies in package.json feat: update package.json and rollup.config.js to include jotai and enhance bundling configuration feat: update package.json and rollup.config.js to include jotai and enhance bundling configuration refactor: reorganize exports in index.ts for improved clarity refactor: remove unused types and interfaces from common files refactor: update peer dependencies and improve component typings - Removed duplicate peer dependencies from package.json and organized them. - Updated rollup.config.js to disable TypeScript checking during the build process. - Modified AnimatedTabs component to use React.ReactNode for label and content types, and added TypeScript workarounds for compatibility. - Enhanced Label and Separator components to accept an optional className prop and improved prop spreading. - Updated Slider component to include an optional className prop and refined prop handling for better type safety. refactor: clean up client workflow and update package dependencies refactor: update package dependencies and improve PostCSS and Rollup configurations chore: bump version to 0.1.2 in package.json chore: bump client version to 0.1.2 in package-lock.json chore: bump client version to 0.1.3 and update dependencies chore: bump client version to 0.1.4 and update @react-spring dependencies chore: update package version to 0.1.5 and adjust peer dependencies - Bump version in package.json from 0.1.4 to 0.1.5. - Update peer dependency for @tanstack/react-query to allow version 5.0.0. - Add @tanstack/react-table and @tanstack/react-virtual as dependencies. - Update various dependencies to their latest compatible versions. - Simplify postcss.config.js by removing unnecessary options. - Clean up rollup.config.js by removing ignored PostCSS warnings. - Update CheckboxButton component to cast icon as React JSX element. - Adjust Combobox component's class names for better styling. - Change DropdownPopup component to use React's namespace import. - Modify InputOTP component to use 'any' type for OTPInputContext. - Ensure displayLabel and value in ModelParameters are converted to strings. - Update MultiSearch component's placeholder to ensure it's a string. - Cast selectIcon in MultiSelect as React JSX element for consistency. - Update OGDialogTemplate to cast selectText as React JSX element. - Initialize animationRef in PixelCard with undefined for clarity. - Add TypeScript ignore comments in Select and SelectDropDown components for Radix UI type conflicts. - Ensure title in SelectDropDown is a string and adjust rendering of options. - Update useLocalize hook to cast options as any for compatibility. refactor: code structure; chore: translations cleanup chore: remove unused imports and clean up code in NewChat component refactor: enhance Menu component to support custom render functions for menu items style: update itemClassName in ToolsDropdown for improved UI consistency fix: merge conflicts chore: update @radix-ui/react-accordion to version 1.2.11 * refactor: remove unnecessary TypeScript type assertions in AnimatedTabs, Label, Separator, and Slider components * feat: enhance theme system with localStorage persistence and new theme atoms * chore: bump version of @librechat/client to 0.1.7 * chore: fix ci/cd warnings/errors related to linting and unused localization keys * chore: update dependencies for class-variance-authority, clsx, and match-sorter * chore: bump @librechat/client to v0.1.8 * feat: add utility colors for theme customization and remove unused tailwindConfig * v0.1.9 --------- Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
332 lines
11 KiB
TypeScript
332 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 { 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,
|
|
mcpSelect,
|
|
artifacts,
|
|
fileSearch,
|
|
agentsConfig,
|
|
startupConfig,
|
|
codeApiKeyForm,
|
|
codeInterpreter,
|
|
searchApiKeyForm,
|
|
} = useBadgeRowContext();
|
|
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 { mcpServerNames } = mcpSelect;
|
|
|
|
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 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" />
|
|
<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" />
|
|
</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" />
|
|
<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" />
|
|
</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}
|
|
/>
|
|
),
|
|
});
|
|
}
|
|
|
|
if (mcpServerNames && mcpServerNames.length > 0) {
|
|
dropdownItems.push({
|
|
hideOnClick: false,
|
|
render: (props) => <MCPSubMenu {...props} placeholder={mcpPlaceholder} />,
|
|
});
|
|
}
|
|
|
|
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 transition-colors hover:bg-surface-hover focus:outline-none focus:ring-2 focus:ring-primary focus:ring-opacity-50',
|
|
)}
|
|
>
|
|
<div className="flex w-full items-center justify-center gap-2">
|
|
<Settings2 className="icon-md" />
|
|
</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);
|