mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
feat: Implement Default Preset Selection for Conversations 📌 (#1275)
* fix: type issues with icons * refactor: use react query for presets, show toasts on preset crud, refactor mutations, remove presetsQuery from Root (breaking change) * refactor: change preset titling * refactor: update preset schemas and methods for necessary new properties `order` and `defaultPreset` * feat: add `defaultPreset` Recoil value * refactor(getPresetTitle): make logic cleaner and more concise * feat: complete UI portion of defaultPreset feature, with animations added to preset items * chore: remove console.logs() * feat: complete default preset handling * refactor: remove user sensitive values on logout * fix: allow endpoint selection without default preset overwriting
This commit is contained in:
parent
fdb65366d7
commit
ca64efec1b
32 changed files with 681 additions and 270 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import * as f from './types/files';
|
||||
import * as p from './types/presets';
|
||||
import * as a from './types/assistants';
|
||||
import * as t from './types';
|
||||
import * as s from './schemas';
|
||||
|
|
@ -73,15 +74,15 @@ export function getPresets(): Promise<s.TPreset[]> {
|
|||
return request.get(endpoints.presets());
|
||||
}
|
||||
|
||||
export function createPreset(payload: s.TPreset): Promise<s.TPreset[]> {
|
||||
export function createPreset(payload: s.TPreset): Promise<s.TPreset> {
|
||||
return request.post(endpoints.presets(), payload);
|
||||
}
|
||||
|
||||
export function updatePreset(payload: s.TPreset): Promise<s.TPreset[]> {
|
||||
export function updatePreset(payload: s.TPreset): Promise<s.TPreset> {
|
||||
return request.post(endpoints.presets(), payload);
|
||||
}
|
||||
|
||||
export function deletePreset(arg: s.TPreset | object): Promise<s.TPreset[]> {
|
||||
export function deletePreset(arg: s.TPreset | undefined): Promise<p.PresetDeleteResponse> {
|
||||
return request.post(endpoints.deletePreset(), arg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
export * from './types';
|
||||
export * from './types/assistants';
|
||||
export * from './types/files';
|
||||
export * from './types/presets';
|
||||
/*
|
||||
* react query
|
||||
* TODO: move to client, or move schemas/types to their own package
|
||||
|
|
|
|||
|
|
@ -20,4 +20,6 @@ export enum QueryKeys {
|
|||
export enum MutationKeys {
|
||||
imageUpload = 'imageUpload',
|
||||
fileDelete = 'fileDelete',
|
||||
updatePreset = 'updatePreset',
|
||||
deletePreset = 'deletePreset',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from '@tanstack/react-query';
|
||||
import * as t from './types';
|
||||
import * as s from './schemas';
|
||||
import * as p from './types/presets';
|
||||
import * as dataService from './data-service';
|
||||
import request from './request';
|
||||
import { QueryKeys } from './keys';
|
||||
|
|
@ -276,7 +277,7 @@ export const useGetModelsQuery = (
|
|||
};
|
||||
|
||||
export const useCreatePresetMutation = (): UseMutationResult<
|
||||
s.TPreset[],
|
||||
s.TPreset,
|
||||
unknown,
|
||||
s.TPreset,
|
||||
unknown
|
||||
|
|
@ -290,7 +291,7 @@ export const useCreatePresetMutation = (): UseMutationResult<
|
|||
};
|
||||
|
||||
export const useUpdatePresetMutation = (): UseMutationResult<
|
||||
s.TPreset[],
|
||||
s.TPreset,
|
||||
unknown,
|
||||
s.TPreset,
|
||||
unknown
|
||||
|
|
@ -315,13 +316,13 @@ export const useGetPresetsQuery = (
|
|||
};
|
||||
|
||||
export const useDeletePresetMutation = (): UseMutationResult<
|
||||
s.TPreset[],
|
||||
p.PresetDeleteResponse,
|
||||
unknown,
|
||||
s.TPreset | object,
|
||||
s.TPreset | undefined,
|
||||
unknown
|
||||
> => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation((payload: s.TPreset | object) => dataService.deletePreset(payload), {
|
||||
return useMutation((payload: s.TPreset | undefined) => dataService.deletePreset(payload), {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries([QueryKeys.presets]);
|
||||
},
|
||||
|
|
@ -369,6 +370,9 @@ export const useLoginUserMutation = (): UseMutationResult<
|
|||
return useMutation((payload: t.TLoginUser) => dataService.login(payload), {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries([QueryKeys.user]);
|
||||
queryClient.invalidateQueries([QueryKeys.presets]);
|
||||
queryClient.invalidateQueries([QueryKeys.conversation]);
|
||||
queryClient.invalidateQueries([QueryKeys.allConversations]);
|
||||
},
|
||||
onMutate: () => {
|
||||
queryClient.invalidateQueries([QueryKeys.models]);
|
||||
|
|
|
|||
|
|
@ -225,6 +225,8 @@ export const tPresetSchema = tConversationSchema
|
|||
conversationId: z.string().optional(),
|
||||
presetId: z.string().nullable().optional(),
|
||||
title: z.string().nullable().optional(),
|
||||
defaultPreset: z.boolean().optional(),
|
||||
order: z.number().optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
22
packages/data-provider/src/types/presets.ts
Normal file
22
packages/data-provider/src/types/presets.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { TPreset } from '../types';
|
||||
|
||||
export type PresetDeleteResponse = {
|
||||
acknowledged: boolean;
|
||||
deletedCount: number;
|
||||
};
|
||||
|
||||
export type UpdatePresetOptions = {
|
||||
onSuccess?: (data: TPreset, variables: TPreset, context?: unknown) => void;
|
||||
onMutate?: (variables: TPreset) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: TPreset, context?: unknown) => void;
|
||||
};
|
||||
|
||||
export type DeletePresetOptions = {
|
||||
onSuccess?: (
|
||||
data: PresetDeleteResponse,
|
||||
variables: TPreset | undefined,
|
||||
context?: unknown,
|
||||
) => void;
|
||||
onMutate?: (variables: TPreset | undefined) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: TPreset | undefined, context?: unknown) => void;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue