mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 02:40:14 +01:00
refactor(client): Refactors recent typescript changes for best practices (#763)
* create common types in client * remove unnecessary rules from eslint config * cleanup types * put back eslintrc rules
This commit is contained in:
parent
5828200197
commit
96d29f7390
32 changed files with 233 additions and 245 deletions
|
|
@ -1,16 +1,20 @@
|
|||
import { UsePresetOptions, TPreset, SetOption, SetExample } from 'librechat-data-provider';
|
||||
import { TPreset } from 'librechat-data-provider';
|
||||
import type { TSetOptionsPayload, TSetExample, TSetOption } from '~/common';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { cleanupPreset } from '~/utils';
|
||||
import store from '~/store';
|
||||
|
||||
const usePresetOptions: UsePresetOptions = (_preset) => {
|
||||
type TUsePresetOptions = (preset?: TPreset | boolean | null) => TSetOptionsPayload | boolean;
|
||||
|
||||
const usePresetOptions: TUsePresetOptions = (_preset) => {
|
||||
const [preset, setPreset] = useRecoilState(store.preset);
|
||||
const endpointsConfig = useRecoilValue(store.endpointsConfig);
|
||||
if (!_preset) {
|
||||
return false;
|
||||
}
|
||||
const getConversation: () => TPreset | null = () => preset;
|
||||
const setOption: SetOption = (param) => (newValue) => {
|
||||
|
||||
const setOption: TSetOption = (param) => (newValue) => {
|
||||
const update = {};
|
||||
update[param] = newValue;
|
||||
setPreset((prevState) =>
|
||||
|
|
@ -24,7 +28,7 @@ const usePresetOptions: UsePresetOptions = (_preset) => {
|
|||
);
|
||||
};
|
||||
|
||||
const setExample: SetExample = (i, type, newValue = null) => {
|
||||
const setExample: TSetExample = (i, type, newValue = null) => {
|
||||
const update = {};
|
||||
const current = preset?.examples?.slice() || [];
|
||||
const currentExample = { ...current[i] } || {};
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
import {
|
||||
UseSetOptions,
|
||||
TConversation,
|
||||
SetOption,
|
||||
SetExample,
|
||||
TPlugin,
|
||||
tConversationSchema,
|
||||
} from 'librechat-data-provider';
|
||||
import { TConversation, TPreset, TPlugin, tConversationSchema } from 'librechat-data-provider';
|
||||
import type { TSetExample, TSetOption, TSetOptionsPayload } from '~/common';
|
||||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import usePresetOptions from './usePresetOptions';
|
||||
import store from '~/store';
|
||||
|
||||
const useSetOptions: UseSetOptions = (preset = false) => {
|
||||
type TUseSetOptions = (preset?: TPreset | boolean | null) => TSetOptionsPayload;
|
||||
|
||||
const useSetOptions: TUseSetOptions = (preset = false) => {
|
||||
const setShowPluginStoreDialog = useSetRecoilState(store.showPluginStoreDialog);
|
||||
const [conversation, setConversation] = useRecoilState(store.conversation);
|
||||
const availableTools = useRecoilValue(store.availableTools);
|
||||
|
|
@ -21,7 +17,7 @@ const useSetOptions: UseSetOptions = (preset = false) => {
|
|||
return result;
|
||||
}
|
||||
|
||||
const setOption: SetOption = (param) => (newValue) => {
|
||||
const setOption: TSetOption = (param) => (newValue) => {
|
||||
const update = {};
|
||||
update[param] = newValue;
|
||||
setConversation((prevState) =>
|
||||
|
|
@ -32,7 +28,7 @@ const useSetOptions: UseSetOptions = (preset = false) => {
|
|||
);
|
||||
};
|
||||
|
||||
const setExample: SetExample = (i, type, newValue = null) => {
|
||||
const setExample: TSetExample = (i, type, newValue = null) => {
|
||||
const update = {};
|
||||
const current = conversation?.examples?.slice() || [];
|
||||
const currentExample = { ...current[i] } || {};
|
||||
|
|
@ -92,7 +88,7 @@ const useSetOptions: UseSetOptions = (preset = false) => {
|
|||
return conversation.tools.find((el) => el.pluginKey === value) ? true : false;
|
||||
}
|
||||
|
||||
const setAgentOption: SetOption = (param) => (newValue) => {
|
||||
const setAgentOption: TSetOption = (param) => (newValue) => {
|
||||
const editableConvo = JSON.stringify(conversation);
|
||||
const convo = JSON.parse(editableConvo);
|
||||
const { agentOptions } = convo;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue