refactor: Use librechat-data-provider app-wide 🔄 (#1326)

* chore: bump vite, vitejs/plugin-react, mark client package as esm, move react-query as a peer dep in data-provider

* chore: import changes due to new data-provider export strategy, also fix type imports where applicable

* chore: export react-query services as separate to avoid react dependencies in /api/

* chore: suppress sourcemap warnings and polyfill node:path which is used by filenamify
TODO: replace filenamify with an alternative and REMOVE polyfill

* chore: /api/ changes to support `librechat-data-provider`

* refactor: rewrite Dockerfile.multi in light of /api/ changes to support `librechat-data-provider`

* chore: remove volume mapping to node_modules directories in default compose file

* chore: remove schemas from /api/ as is no longer needed with use of `librechat-data-provider`

* fix(ci): jest `librechat-data-provider/react-query` module resolution
This commit is contained in:
Danny Avila 2023-12-11 14:48:40 -05:00 committed by GitHub
parent d4c846b543
commit df1dfa7d46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
97 changed files with 1831 additions and 1343 deletions

View file

@ -1,11 +1,11 @@
import React, { useEffect } from 'react';
import LoginForm from './LoginForm';
import { useAuthContext } from '~/hooks/AuthContext';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLocalize } from '~/hooks';
import { useGetStartupConfig } from 'librechat-data-provider';
import { useGetStartupConfig } from 'librechat-data-provider/react-query';
import { GoogleIcon, FacebookIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
import { useAuthContext } from '~/hooks/AuthContext';
import { getLoginError } from '~/utils';
import { useLocalize } from '~/hooks';
import LoginForm from './LoginForm';
function Login() {
const { login, error, isAuthenticated } = useAuthContext();

View file

@ -1,13 +1,10 @@
import { useForm } from 'react-hook-form';
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useForm } from 'react-hook-form';
import { useLocalize } from '~/hooks';
import {
useRegisterUserMutation,
TRegisterUser,
useGetStartupConfig,
} from 'librechat-data-provider';
import { useRegisterUserMutation, useGetStartupConfig } from 'librechat-data-provider/react-query';
import type { TRegisterUser } from 'librechat-data-provider';
import { GoogleIcon, FacebookIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
import { useLocalize } from '~/hooks';
function Registration() {
const navigate = useNavigate();
@ -281,7 +278,8 @@ function Registration() {
<a
href="/login"
aria-label="Login"
className="p-1 font-medium text-green-500 hover:underline">
className="p-1 font-medium text-green-500 hover:underline"
>
{localize('com_auth_login')}
</a>
</p>

View file

@ -1,12 +1,11 @@
import React, { useState, useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { useLocalize } from '~/hooks';
import { useState, useEffect } from 'react';
import {
useRequestPasswordResetMutation,
useGetStartupConfig,
TRequestPasswordReset,
TRequestPasswordResetResponse,
} from 'librechat-data-provider';
useRequestPasswordResetMutation,
} from 'librechat-data-provider/react-query';
import type { TRequestPasswordReset, TRequestPasswordResetResponse } from 'librechat-data-provider';
import { useLocalize } from '~/hooks';
function RequestPasswordReset() {
const localize = useLocalize();
@ -116,7 +115,8 @@ function RequestPasswordReset() {
></input>
<label
htmlFor="email"
className="pointer-events-none absolute left-2.5 top-4 z-10 origin-[0] -translate-y-4 scale-75 transform text-sm text-gray-500 duration-100 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:text-green-500">
className="pointer-events-none absolute left-2.5 top-4 z-10 origin-[0] -translate-y-4 scale-75 transform text-sm text-gray-500 duration-100 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:text-green-500"
>
{localize('com_auth_email_address')}
</label>
</div>
@ -131,7 +131,8 @@ function RequestPasswordReset() {
<button
type="submit"
disabled={!!errors.email}
className="w-full transform rounded-md bg-green-500 px-4 py-3 tracking-wide text-white transition-colors duration-200 hover:bg-green-600 focus:bg-green-600 focus:outline-none">
className="w-full transform rounded-md bg-green-500 px-4 py-3 tracking-wide text-white transition-colors duration-200 hover:bg-green-600 focus:bg-green-600 focus:outline-none"
>
{localize('com_auth_continue')}
</button>
</div>

View file

@ -1,9 +1,8 @@
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { useResetPasswordMutation, TResetPassword } from 'librechat-data-provider';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import store from '~/store';
import { useResetPasswordMutation } from 'librechat-data-provider/react-query';
import type { TResetPassword } from 'librechat-data-provider';
import { useLocalize } from '~/hooks';
function ResetPassword() {
@ -177,7 +176,8 @@ function ResetPassword() {
disabled={!!errors.password || !!errors.confirm_password}
type="submit"
aria-label={localize('com_auth_submit_registration')}
className="w-full transform rounded-md bg-green-500 px-4 py-3 tracking-wide text-white transition-colors duration-200 hover:bg-green-600 focus:bg-green-600 focus:outline-none">
className="w-full transform rounded-md bg-green-500 px-4 py-3 tracking-wide text-white transition-colors duration-200 hover:bg-green-600 focus:bg-green-600 focus:outline-none"
>
{localize('com_auth_continue')}
</button>
</div>

View file

@ -1,9 +1,9 @@
import { render, waitFor } from 'test/layout-test-utils';
import userEvent from '@testing-library/user-event';
import Login from '../Login';
import * as mockDataProvider from 'librechat-data-provider';
import * as mockDataProvider from 'librechat-data-provider/react-query';
jest.mock('librechat-data-provider');
jest.mock('librechat-data-provider/react-query');
const setup = ({
useGetUserQueryReturnValue = {

View file

@ -1,9 +1,9 @@
import { render, waitFor, screen } from 'test/layout-test-utils';
import userEvent from '@testing-library/user-event';
import Registration from '../Registration';
import * as mockDataProvider from 'librechat-data-provider';
import * as mockDataProvider from 'librechat-data-provider/react-query';
jest.mock('librechat-data-provider');
jest.mock('librechat-data-provider/react-query');
const setup = ({
useGetUserQueryReturnValue = {

View file

@ -1,7 +1,7 @@
import { memo } from 'react';
import { useRecoilValue } from 'recoil';
import { useParams } from 'react-router-dom';
import { useGetMessagesByConvoId } from 'librechat-data-provider';
import { useGetMessagesByConvoId } from 'librechat-data-provider/react-query';
import { useChatHelpers, useSSE } from '~/hooks';
// import GenerationButtons from './Input/GenerationButtons';
import MessagesView from './Messages/MessagesView';

View file

@ -1,6 +1,6 @@
// import { useState } from 'react';
import { Plus } from 'lucide-react';
import { useListAssistantsQuery } from 'librechat-data-provider';
import { useListAssistantsQuery } from 'librechat-data-provider/react-query';
import type { Assistant } from 'librechat-data-provider';
import type { UseFormReset, UseFormSetValue } from 'react-hook-form';
import type { CreationForm, Actions, Option } from '~/common';

View file

@ -1,7 +1,8 @@
import { Controller, useWatch } from 'react-hook-form';
import type { Tool } from 'librechat-data-provider';
import { Tools, EModelEndpoint } from 'librechat-data-provider';
import { useCreateAssistantMutation } from 'librechat-data-provider/react-query';
import type { CreationForm, Actions } from '~/common';
import { useCreateAssistantMutation, Tools, EModelEndpoint } from 'librechat-data-provider';
import type { Tool } from 'librechat-data-provider';
import { Separator } from '~/components/ui/Separator';
import { useAssistantsContext } from '~/Providers';
import { Switch } from '~/components/ui/Switch';

View file

@ -1,4 +1,4 @@
import { useGetStartupConfig } from 'librechat-data-provider';
import { useGetStartupConfig } from 'librechat-data-provider/react-query';
import { useLocalize } from '~/hooks';
export default function Footer() {

View file

@ -1,6 +1,7 @@
import type { FC } from 'react';
import { Close } from '@radix-ui/react-popover';
import { EModelEndpoint, useGetEndpointsQuery, alternateName } from 'librechat-data-provider';
import { EModelEndpoint, alternateName } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import MenuSeparator from '../UI/MenuSeparator';
import MenuItem from './MenuItem';

View file

@ -1,5 +1,6 @@
import { Content, Portal, Root } from '@radix-ui/react-popover';
import { useGetEndpointsQuery, alternateName } from 'librechat-data-provider';
import { alternateName } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import type { FC } from 'react';
import EndpointItems from './Endpoints/MenuItems';
import { useChatContext } from '~/Providers';

View file

@ -1,5 +1,5 @@
import { useRecoilState } from 'recoil';
import { useGetEndpointsQuery } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import { cn, defaultTextProps, removeFocusOutlines, mapEndpoints } from '~/utils';
import { Input, Label, Dropdown, Dialog, DialogClose, DialogButton } from '~/components/';
import PopoverButtons from '~/components/Chat/Input/PopoverButtons';

View file

@ -1,5 +1,6 @@
import { useRef } from 'react';
import { useUpdateMessageMutation, EModelEndpoint } from 'librechat-data-provider';
import { EModelEndpoint } from 'librechat-data-provider';
import { useUpdateMessageMutation } from 'librechat-data-provider/react-query';
import Container from '~/components/Messages/Content/Container';
import { useChatContext } from '~/Providers';
import type { TEditProps } from '~/common';

View file

@ -1,6 +1,6 @@
import { useState, useRef } from 'react';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { useUpdateConversationMutation } from 'librechat-data-provider';
import { useUpdateConversationMutation } from 'librechat-data-provider/react-query';
import { useConversations, useConversation } from '~/hooks';
import { MinimalIcon } from '~/components/Endpoints';
import { NotificationSeverity } from '~/common';

View file

@ -1,7 +1,7 @@
import { useRecoilValue } from 'recoil';
import { useState, useRef } from 'react';
import { useParams } from 'react-router-dom';
import { useUpdateConversationMutation } from 'librechat-data-provider';
import { useUpdateConversationMutation } from 'librechat-data-provider/react-query';
import type { MouseEvent, FocusEvent, KeyboardEvent } from 'react';
import { useConversations, useNavigateToConvo } from '~/hooks';
import { MinimalIcon } from '~/components/Endpoints';

View file

@ -1,5 +1,5 @@
import { useParams } from 'react-router-dom';
import { useDeleteConversationMutation } from 'librechat-data-provider';
import { useDeleteConversationMutation } from 'librechat-data-provider/react-query';
import { useLocalize, useConversations, useConversation } from '~/hooks';
import { Dialog, DialogTrigger, Label } from '~/components/ui';
import DialogTemplate from '~/components/ui/DialogTemplate';

View file

@ -1,5 +1,5 @@
import { useParams } from 'react-router-dom';
import { useDeleteConversationMutation } from 'librechat-data-provider';
import { useDeleteConversationMutation } from 'librechat-data-provider/react-query';
import { useLocalize, useConversations, useNewConvo } from '~/hooks';
import { Dialog, DialogTrigger, Label } from '~/components/ui';
import DialogTemplate from '~/components/ui/DialogTemplate';

View file

@ -3,7 +3,7 @@ import { useEffect } from 'react';
import filenamify from 'filenamify';
import exportFromJSON from 'export-from-json';
import { useSetRecoilState, useRecoilState } from 'recoil';
import { useGetEndpointsQuery } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import type { TEditPresetProps } from '~/common';
import { useSetOptions, useLocalize } from '~/hooks';
import { Input, Label, Dropdown, Dialog, DialogClose, DialogButton } from '~/components/';

View file

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { useCreatePresetMutation } from 'librechat-data-provider';
import { useCreatePresetMutation } from 'librechat-data-provider/react-query';
import type { TEditPresetProps } from '~/common';
import { cn, defaultTextPropsLabel, removeFocusOutlines, cleanupPreset } from '~/utils/';
import DialogTemplate from '~/components/ui/DialogTemplate';

View file

@ -1,10 +1,11 @@
import { useEffect, useState } from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { useUpdateTokenCountMutation, TUpdateTokenCountResponse } from 'librechat-data-provider';
import type { TSettingsProps } from '~/common';
import { Label, Checkbox, SelectDropDown } from '~/components/ui';
import { useUpdateTokenCountMutation } from 'librechat-data-provider/react-query';
import type { TUpdateTokenCountResponse } from 'librechat-data-provider';
import { cn, defaultTextProps, removeFocusOutlines } from '~/utils/';
import { Label, Checkbox, SelectDropDown } from '~/components/ui';
import { useLocalize, useDebounce } from '~/hooks';
import type { TSettingsProps } from '~/common';
export default function Settings({ conversation, setOption, readonly }: TSettingsProps) {
const localize = useLocalize();

View file

@ -1,9 +1,10 @@
import { useState } from 'react';
import { useGetEndpointsQuery, alternateName } from 'librechat-data-provider';
import { Settings } from 'lucide-react';
import { alternateName } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import { DropdownMenuRadioItem } from '~/components';
import { Icon } from '~/components/Endpoints';
import { SetKeyDialog } from '../SetKeyDialog';
import { Icon } from '~/components/Endpoints';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';

View file

@ -1,12 +1,12 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { Trash2 } from 'lucide-react';
import { useState, useEffect } from 'react';
import { useRecoilState } from 'recoil';
import { useState, useEffect } from 'react';
import {
useDeletePresetMutation,
useCreatePresetMutation,
useGetEndpointsQuery,
} from 'librechat-data-provider';
} from 'librechat-data-provider/react-query';
import { Icon, EditPresetDialog } from '~/components/Endpoints';
import EndpointItems from './EndpointItems';
import PresetItems from './PresetItems';

View file

@ -1,5 +1,4 @@
import React from 'react';
import { useGetStartupConfig } from 'librechat-data-provider';
import { useGetStartupConfig } from 'librechat-data-provider/react-query';
import { useLocalize } from '~/hooks';
export default function Footer() {

View file

@ -1,7 +1,8 @@
import { useRecoilState } from 'recoil';
import { useState, useEffect } from 'react';
import { ChevronDownIcon } from 'lucide-react';
import { useAvailablePluginsQuery, TPlugin } from 'librechat-data-provider';
import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
import type { TPlugin } from 'librechat-data-provider';
import type { TModelSelectProps } from '~/common';
import { SelectDropDown, MultiSelectDropDown, SelectDropDownPop, Button } from '~/components/ui';
import { useSetOptions, useAuthContext, useMediaQuery } from '~/hooks';

View file

@ -1,7 +1,8 @@
import { useRecoilState } from 'recoil';
import { useState, useEffect } from 'react';
import { ChevronDownIcon } from 'lucide-react';
import { useAvailablePluginsQuery, TPlugin } from 'librechat-data-provider';
import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
import type { TPlugin } from 'librechat-data-provider';
import type { TModelSelectProps } from '~/common';
import {
SelectDropDown,

View file

@ -1,6 +1,6 @@
import { useRef } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useUpdateMessageMutation } from 'librechat-data-provider';
import { useUpdateMessageMutation } from 'librechat-data-provider/react-query';
import type { TEditProps } from '~/common';
import store from '~/store';
import Container from './Container';

View file

@ -1,6 +1,6 @@
import { Disclosure } from '@headlessui/react';
import { useCallback, memo, ReactNode } from 'react';
import { useGetEndpointsQuery } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import type { TResPlugin, TInput } from 'librechat-data-provider';
import { ChevronDownIcon, LucideProps } from 'lucide-react';
import { cn, formatJSON } from '~/utils';

View file

@ -1,5 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useGetConversationByIdQuery } from 'librechat-data-provider';
import { useGetConversationByIdQuery } from 'librechat-data-provider/react-query';
import { useEffect } from 'react';
import { useSetRecoilState, useRecoilState, useRecoilValue } from 'recoil';
import copy from 'copy-to-clipboard';

View file

@ -2,7 +2,7 @@ import { useState } from 'react';
import { Dialog } from '~/components/ui/';
import DialogTemplate from '~/components/ui/DialogTemplate';
import { ClearChatsButton } from './SettingsTabs/';
import { useClearConversationsMutation } from 'librechat-data-provider';
import { useClearConversationsMutation } from 'librechat-data-provider/react-query';
import { useLocalize, useConversation, useConversations } from '~/hooks';
const ClearConvos = ({ open, onOpenChange }) => {

View file

@ -4,7 +4,7 @@ import { useRecoilCallback } from 'recoil';
import { useEffect, useState } from 'react';
import exportFromJSON from 'export-from-json';
import DialogTemplate from '~/components/ui/DialogTemplate';
import { useGetMessagesByConvoId } from 'librechat-data-provider';
import { useGetMessagesByConvoId } from 'librechat-data-provider/react-query';
import { Dialog, DialogButton, Input, Label, Checkbox, Dropdown } from '~/components/ui/';
import { cn, defaultTextProps, removeFocusOutlines, cleanupPreset } from '~/utils/';
import { useScreenshot, useLocalize } from '~/hooks';

View file

@ -1,11 +1,7 @@
import {
TConversation,
useGetConversationsQuery,
useSearchQuery,
TSearchResults,
} from 'librechat-data-provider';
import { useSearchQuery, useGetConversationsQuery } from 'librechat-data-provider/react-query';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useCallback, useEffect, useRef, useState } from 'react';
import type { TConversation, TSearchResults } from 'librechat-data-provider';
import {
useAuthContext,
useMediaQuery,

View file

@ -3,7 +3,7 @@ import { useRecoilValue } from 'recoil';
import { Fragment, useState, memo } from 'react';
import { useLocation } from 'react-router-dom';
import { Menu, Transition } from '@headlessui/react';
import { useGetUserBalance, useGetStartupConfig } from 'librechat-data-provider';
import { useGetUserBalance, useGetStartupConfig } from 'librechat-data-provider/react-query';
import type { TConversation } from 'librechat-data-provider';
import { ExportModal } from './ExportConversation';
import { LinkIcon, GearIcon } from '~/components';

View file

@ -1,5 +1,8 @@
import * as Tabs from '@radix-ui/react-tabs';
import { useRevokeAllUserKeysMutation, useRevokeUserKeyMutation } from 'librechat-data-provider';
import {
useRevokeAllUserKeysMutation,
useRevokeUserKeyMutation,
} from 'librechat-data-provider/react-query';
import React, { useState, useCallback, useRef } from 'react';
import { useOnClickOutside } from '~/hooks';
import DangerButton from './DangerButton';

View file

@ -1,7 +1,7 @@
import { useRecoilState } from 'recoil';
import * as Tabs from '@radix-ui/react-tabs';
import React, { useState, useContext, useCallback, useRef } from 'react';
import { useClearConversationsMutation } from 'librechat-data-provider';
import { useClearConversationsMutation } from 'librechat-data-provider/react-query';
import {
ThemeContext,
useLocalize,

View file

@ -1,21 +1,19 @@
import { useState, useEffect, useCallback } from 'react';
import { Dialog } from '@headlessui/react';
import { useRecoilState } from 'recoil';
import { Search, X } from 'lucide-react';
import store from '~/store';
import PluginStoreItem from './PluginStoreItem';
import PluginPagination from './PluginPagination';
import PluginAuthForm from './PluginAuthForm';
import { Dialog } from '@headlessui/react';
import { useState, useEffect, useCallback } from 'react';
import { tConversationSchema } from 'librechat-data-provider';
import {
useAvailablePluginsQuery,
useUpdateUserPluginsMutation,
TPlugin,
TPluginAction,
tConversationSchema,
TError,
} from 'librechat-data-provider';
} from 'librechat-data-provider/react-query';
import type { TError, TPlugin, TPluginAction } from 'librechat-data-provider';
import { useAuthContext } from '~/hooks/AuthContext';
import PluginPagination from './PluginPagination';
import PluginStoreItem from './PluginStoreItem';
import PluginAuthForm from './PluginAuthForm';
import { useLocalize } from '~/hooks';
import store from '~/store';
type TPluginStoreDialogProps = {
isOpen: boolean;

View file

@ -1,9 +1,9 @@
import { render, screen, fireEvent } from 'test/layout-test-utils';
import PluginStoreDialog from '../PluginStoreDialog';
import userEvent from '@testing-library/user-event';
import * as mockDataProvider from 'librechat-data-provider';
import * as mockDataProvider from 'librechat-data-provider/react-query';
jest.mock('librechat-data-provider');
jest.mock('librechat-data-provider/react-query');
class ResizeObserver {
observe() {

View file

@ -1,12 +1,12 @@
import React from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useGetStartupConfig } from 'librechat-data-provider/react-query';
import LightningIcon from '~/components/svg/LightningIcon';
import useDocumentTitle from '~/hooks/useDocumentTitle';
import SunIcon from '../svg/SunIcon';
import LightningIcon from '../svg/LightningIcon';
import CautionIcon from '../svg/CautionIcon';
import store from '~/store';
import CautionIcon from '~/components/svg/CautionIcon';
import SunIcon from '~/components/svg/SunIcon';
import { useLocalize } from '~/hooks';
import { useGetStartupConfig } from 'librechat-data-provider';
import store from '~/store';
export default function Landing() {
const { data: config } = useGetStartupConfig();