2024-08-06 22:18:07 -04:00
|
|
|
import { memo } from 'react';
|
2025-08-04 18:50:54 +02:00
|
|
|
import { InfoHoverCard, ESide } from '@librechat/client';
|
2024-09-10 10:11:39 -09:00
|
|
|
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
2025-08-04 18:50:54 +02:00
|
|
|
import { useLocalize, useHasAccess } from '~/hooks';
|
2025-10-07 20:12:49 +02:00
|
|
|
import ToggleSwitch from '../ToggleSwitch';
|
|
|
|
|
import store from '~/store';
|
|
|
|
|
|
|
|
|
|
const commandSwitchConfigs = [
|
|
|
|
|
{
|
|
|
|
|
stateAtom: store.atCommand,
|
|
|
|
|
localizationKey: 'com_nav_at_command_description' as const,
|
|
|
|
|
switchId: 'atCommand',
|
|
|
|
|
key: 'atCommand',
|
|
|
|
|
permissionType: undefined,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
stateAtom: store.plusCommand,
|
|
|
|
|
localizationKey: 'com_nav_plus_command_description' as const,
|
|
|
|
|
switchId: 'plusCommand',
|
|
|
|
|
key: 'plusCommand',
|
|
|
|
|
permissionType: PermissionTypes.MULTI_CONVO,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
stateAtom: store.slashCommand,
|
|
|
|
|
localizationKey: 'com_nav_slash_command_description' as const,
|
|
|
|
|
switchId: 'slashCommand',
|
|
|
|
|
key: 'slashCommand',
|
|
|
|
|
permissionType: PermissionTypes.PROMPTS,
|
|
|
|
|
},
|
|
|
|
|
] as const;
|
2024-08-06 22:18:07 -04:00
|
|
|
|
|
|
|
|
function Commands() {
|
2024-09-09 16:29:24 -04:00
|
|
|
const localize = useLocalize();
|
|
|
|
|
|
|
|
|
|
const hasAccessToPrompts = useHasAccess({
|
|
|
|
|
permissionType: PermissionTypes.PROMPTS,
|
|
|
|
|
permission: Permissions.USE,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const hasAccessToMultiConvo = useHasAccess({
|
|
|
|
|
permissionType: PermissionTypes.MULTI_CONVO,
|
|
|
|
|
permission: Permissions.USE,
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-07 20:12:49 +02:00
|
|
|
const getShowSwitch = (permissionType?: PermissionTypes) => {
|
|
|
|
|
if (!permissionType) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (permissionType === PermissionTypes.MULTI_CONVO) {
|
|
|
|
|
return hasAccessToMultiConvo === true;
|
|
|
|
|
}
|
|
|
|
|
if (permissionType === PermissionTypes.PROMPTS) {
|
|
|
|
|
return hasAccessToPrompts === true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-06 22:18:07 -04:00
|
|
|
return (
|
2024-09-10 10:11:39 -09:00
|
|
|
<div className="space-y-4 p-1">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<h3 className="text-lg font-medium text-text-primary">
|
|
|
|
|
{localize('com_nav_chat_commands')}
|
|
|
|
|
</h3>
|
2025-08-04 18:50:54 +02:00
|
|
|
<InfoHoverCard side={ESide.Bottom} text={localize('com_nav_chat_commands_info')} />
|
2024-09-10 10:11:39 -09:00
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-3 text-sm text-text-primary">
|
2025-10-07 20:12:49 +02:00
|
|
|
{commandSwitchConfigs.map((config) => (
|
|
|
|
|
<div key={config.key} className="pb-3">
|
|
|
|
|
<ToggleSwitch
|
|
|
|
|
stateAtom={config.stateAtom}
|
|
|
|
|
localizationKey={config.localizationKey}
|
|
|
|
|
switchId={config.switchId}
|
|
|
|
|
showSwitch={getShowSwitch(config.permissionType)}
|
|
|
|
|
/>
|
2024-09-10 10:11:39 -09:00
|
|
|
</div>
|
2025-10-07 20:12:49 +02:00
|
|
|
))}
|
2024-08-06 22:18:07 -04:00
|
|
|
</div>
|
2024-09-10 10:11:39 -09:00
|
|
|
</div>
|
2024-08-06 22:18:07 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default memo(Commands);
|