mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +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,5 +1,9 @@
|
|||
import { useSetRecoilState } from 'recoil';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
import type { SetterOrUpdater } from 'recoil';
|
||||
import useHasAccess from '~/hooks/Roles/useHasAccess';
|
||||
import store from '~/store';
|
||||
|
||||
/** Event Keys that shouldn't trigger a command */
|
||||
const invalidKeys = {
|
||||
|
|
@ -36,14 +40,21 @@ const shouldTriggerCommand = (
|
|||
* Custom hook for handling key up events with command triggers.
|
||||
*/
|
||||
const useHandleKeyUp = ({
|
||||
index,
|
||||
textAreaRef,
|
||||
setShowPlusPopover,
|
||||
setShowMentionPopover,
|
||||
}: {
|
||||
index: number;
|
||||
textAreaRef: React.RefObject<HTMLTextAreaElement>;
|
||||
setShowPlusPopover: SetterOrUpdater<boolean>;
|
||||
setShowMentionPopover: SetterOrUpdater<boolean>;
|
||||
}) => {
|
||||
const hasAccess = useHasAccess({
|
||||
permissionType: PermissionTypes.PROMPTS,
|
||||
permission: Permissions.USE,
|
||||
});
|
||||
const setShowPromptsPopover = useSetRecoilState(store.showPromptsPopoverFamily(index));
|
||||
const handleAtCommand = useCallback(() => {
|
||||
if (shouldTriggerCommand(textAreaRef, '@')) {
|
||||
setShowMentionPopover(true);
|
||||
|
|
@ -56,12 +67,22 @@ const useHandleKeyUp = ({
|
|||
}
|
||||
}, [textAreaRef, setShowPlusPopover]);
|
||||
|
||||
const handlePromptsCommand = useCallback(() => {
|
||||
if (!hasAccess) {
|
||||
return;
|
||||
}
|
||||
if (shouldTriggerCommand(textAreaRef, '/')) {
|
||||
setShowPromptsPopover(true);
|
||||
}
|
||||
}, [textAreaRef, hasAccess, setShowPromptsPopover]);
|
||||
|
||||
const commandHandlers = useMemo(
|
||||
() => ({
|
||||
'@': handleAtCommand,
|
||||
'+': handlePlusCommand,
|
||||
'/': handlePromptsCommand,
|
||||
}),
|
||||
[handleAtCommand, handlePlusCommand],
|
||||
[handleAtCommand, handlePlusCommand, handlePromptsCommand],
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue