mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-27 12:46:13 +01:00
🗨️ feat: Prompt Slash Commands (#3219)
* chore: Update prompt description placeholder text * fix: promptsPathPattern to not include new * feat: command input and styling change for prompt views * fix: intended validation * feat: prompts slash command * chore: localizations and fix add command during creation * refactor(PromptsCommand): better label * feat: update `allPrompGroups` cache on all promptGroups mutations * refactor: ensure assistants builder is first within sidepanel * refactor: allow defining emailVerified via create-user script
This commit is contained in:
parent
b8f2bee3fc
commit
83619de158
33 changed files with 764 additions and 80 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { InfiniteData } from '@tanstack/react-query';
|
||||
import { InfiniteData, QueryClient } from '@tanstack/react-query';
|
||||
|
||||
export const addData = <TCollection, TData>(
|
||||
data: InfiniteData<TCollection>,
|
||||
|
|
@ -165,3 +165,56 @@ export const updateFields = <TCollection, TData>(
|
|||
|
||||
return newData;
|
||||
};
|
||||
|
||||
type UpdateCacheListOptions<TData> = {
|
||||
queryClient: QueryClient;
|
||||
queryKey: unknown[];
|
||||
searchProperty: keyof TData;
|
||||
updateData: Partial<TData>;
|
||||
searchValue: unknown;
|
||||
};
|
||||
|
||||
export function updateCacheList<TData>({
|
||||
queryClient,
|
||||
queryKey,
|
||||
searchProperty,
|
||||
updateData,
|
||||
searchValue,
|
||||
}: UpdateCacheListOptions<TData>) {
|
||||
queryClient.setQueryData<TData[]>(queryKey, (oldData) => {
|
||||
if (!oldData) {
|
||||
return oldData;
|
||||
}
|
||||
|
||||
return oldData.map((item) =>
|
||||
item[searchProperty] === searchValue ? { ...item, ...updateData } : item,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function addToCacheList<TData>(
|
||||
queryClient: QueryClient,
|
||||
queryKey: unknown[],
|
||||
newItem: TData,
|
||||
) {
|
||||
queryClient.setQueryData<TData[]>(queryKey, (oldData) => {
|
||||
if (!oldData) {
|
||||
return [newItem];
|
||||
}
|
||||
return [...oldData, newItem];
|
||||
});
|
||||
}
|
||||
|
||||
export function removeFromCacheList<TData>(
|
||||
queryClient: QueryClient,
|
||||
queryKey: unknown[],
|
||||
searchProperty: keyof TData,
|
||||
searchValue: unknown,
|
||||
) {
|
||||
queryClient.setQueryData<TData[]>(queryKey, (oldData) => {
|
||||
if (!oldData) {
|
||||
return oldData;
|
||||
}
|
||||
return oldData.filter((item) => item[searchProperty] !== searchValue);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
import { InfiniteCollections } from 'librechat-data-provider';
|
||||
import { InfiniteCollections, QueryKeys } from 'librechat-data-provider';
|
||||
import type { InfiniteData, QueryClient } from '@tanstack/react-query';
|
||||
import type {
|
||||
PromptGroupListResponse,
|
||||
PromptGroupListData,
|
||||
TPromptGroup,
|
||||
} from 'librechat-data-provider';
|
||||
import { addData, deleteData, updateData, updateFields, getRecordByProperty } from './collection';
|
||||
import { InfiniteData } from '@tanstack/react-query';
|
||||
import {
|
||||
addData,
|
||||
deleteData,
|
||||
updateData,
|
||||
updateFields,
|
||||
addToCacheList,
|
||||
updateCacheList,
|
||||
removeFromCacheList,
|
||||
getRecordByProperty,
|
||||
} from './collection';
|
||||
|
||||
export const addPromptGroup = (
|
||||
data: InfiniteData<PromptGroupListResponse>,
|
||||
|
|
@ -70,3 +79,24 @@ export const findPromptGroup = (
|
|||
findProperty,
|
||||
);
|
||||
};
|
||||
|
||||
export const addGroupToAll = (queryClient: QueryClient, newGroup: TPromptGroup) => {
|
||||
addToCacheList<TPromptGroup>(queryClient, [QueryKeys.allPromptGroups], newGroup);
|
||||
};
|
||||
|
||||
export const updateGroupInAll = (
|
||||
queryClient: QueryClient,
|
||||
updatedGroup: Partial<TPromptGroup> & { _id: string },
|
||||
) => {
|
||||
updateCacheList<TPromptGroup>({
|
||||
queryClient,
|
||||
queryKey: [QueryKeys.allPromptGroups],
|
||||
searchProperty: '_id',
|
||||
updateData: updatedGroup,
|
||||
searchValue: updatedGroup._id,
|
||||
});
|
||||
};
|
||||
|
||||
export const removeGroupFromAll = (queryClient: QueryClient, groupId: string) => {
|
||||
removeFromCacheList<TPromptGroup>(queryClient, [QueryKeys.allPromptGroups], '_id', groupId);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { format } from 'date-fns';
|
||||
import type { TUser } from 'librechat-data-provider';
|
||||
import type { TUser, TPromptGroup } from 'librechat-data-provider';
|
||||
|
||||
export function replaceSpecialVars({ text, user }: { text: string; user?: TUser }) {
|
||||
if (!text) {
|
||||
|
|
@ -92,3 +92,13 @@ export function formatDateTime(dateTimeString: string) {
|
|||
|
||||
return `${formattedDate}, ${formattedTime}`;
|
||||
}
|
||||
|
||||
export const mapPromptGroups = (groups: TPromptGroup[]): Record<string, TPromptGroup> => {
|
||||
return groups.reduce((acc, group) => {
|
||||
if (!group._id) {
|
||||
return acc;
|
||||
}
|
||||
acc[group._id] = group;
|
||||
return acc;
|
||||
}, {} as Record<string, TPromptGroup>);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue