mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-08 03:28:51 +01:00
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids chore: move sharing related components to dedicated "Sharing" directory chore: remove PublicSharingToggle component and update index exports chore: move non-sidepanel agent components to `~/components/Agents` chore: move AgentCategoryDisplay component with tests chore: remove commented out code refactor: change PERMISSION_BITS from const to enum for better type safety refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety refactor: remove unused canAccessPromptResource middleware and related code refactor: remove unused prompt access roles from createAccessRoleMethods refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions chore: move SearchPicker to PeoplePicker dir refactor: implement debouncing for query changes in SearchPicker for improved performance chore: fix typing, import order for agent admin settings fix: agent admin settings, prevent agent form submission refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds` refactor: replace PermissionBits with PERMISSION_BITS refactor: replace PERMISSION_BITS with PermissionBits
104 lines
3.7 KiB
TypeScript
104 lines
3.7 KiB
TypeScript
import { Spinner } from '@librechat/client';
|
|
import { useWatch, useFormContext } from 'react-hook-form';
|
|
import {
|
|
SystemRoles,
|
|
Permissions,
|
|
ResourceType,
|
|
PermissionTypes,
|
|
PermissionBits,
|
|
} from 'librechat-data-provider';
|
|
import type { AgentForm, AgentPanelProps } from '~/common';
|
|
import { useLocalize, useAuthContext, useHasAccess, useResourcePermissions } from '~/hooks';
|
|
import { GenericGrantAccessDialog } from '~/components/Sharing';
|
|
import { useUpdateAgentMutation } from '~/data-provider';
|
|
import AdvancedButton from './Advanced/AdvancedButton';
|
|
import VersionButton from './Version/VersionButton';
|
|
import DuplicateAgent from './DuplicateAgent';
|
|
import AdminSettings from './AdminSettings';
|
|
import DeleteButton from './DeleteButton';
|
|
import { Panel } from '~/common';
|
|
|
|
export default function AgentFooter({
|
|
activePanel,
|
|
createMutation,
|
|
updateMutation,
|
|
setActivePanel,
|
|
setCurrentAgentId,
|
|
}: Pick<
|
|
AgentPanelProps,
|
|
'setCurrentAgentId' | 'createMutation' | 'activePanel' | 'setActivePanel'
|
|
> & {
|
|
updateMutation: ReturnType<typeof useUpdateAgentMutation>;
|
|
}) {
|
|
const localize = useLocalize();
|
|
const { user } = useAuthContext();
|
|
|
|
const methods = useFormContext<AgentForm>();
|
|
|
|
const { control } = methods;
|
|
const agent = useWatch({ control, name: 'agent' });
|
|
const agent_id = useWatch({ control, name: 'id' });
|
|
const hasAccessToShareAgents = useHasAccess({
|
|
permissionType: PermissionTypes.AGENTS,
|
|
permission: Permissions.SHARED_GLOBAL,
|
|
});
|
|
const { hasPermission, isLoading: permissionsLoading } = useResourcePermissions(
|
|
'agent',
|
|
agent?._id || '',
|
|
);
|
|
|
|
const canShareThisAgent = hasPermission(PermissionBits.SHARE);
|
|
const canDeleteThisAgent = hasPermission(PermissionBits.DELETE);
|
|
const renderSaveButton = () => {
|
|
if (createMutation.isLoading || updateMutation.isLoading) {
|
|
return <Spinner className="icon-md" aria-hidden="true" />;
|
|
}
|
|
|
|
if (agent_id) {
|
|
return localize('com_ui_save');
|
|
}
|
|
|
|
return localize('com_ui_create');
|
|
};
|
|
|
|
const showButtons = activePanel === Panel.builder;
|
|
|
|
return (
|
|
<div className="mb-1 flex w-full flex-col gap-2">
|
|
{showButtons && <AdvancedButton setActivePanel={setActivePanel} />}
|
|
{showButtons && agent_id && <VersionButton setActivePanel={setActivePanel} />}
|
|
{user?.role === SystemRoles.ADMIN && showButtons && <AdminSettings />}
|
|
{/* Context Button */}
|
|
<div className="flex items-center justify-end gap-2">
|
|
{(agent?.author === user?.id || user?.role === SystemRoles.ADMIN || canDeleteThisAgent) &&
|
|
!permissionsLoading && (
|
|
<DeleteButton
|
|
agent_id={agent_id}
|
|
setCurrentAgentId={setCurrentAgentId}
|
|
createMutation={createMutation}
|
|
/>
|
|
)}
|
|
{(agent?.author === user?.id || user?.role === SystemRoles.ADMIN || canShareThisAgent) &&
|
|
hasAccessToShareAgents &&
|
|
!permissionsLoading && (
|
|
<GenericGrantAccessDialog
|
|
resourceDbId={agent?._id}
|
|
resourceId={agent_id}
|
|
resourceName={agent?.name ?? ''}
|
|
resourceType={ResourceType.AGENT}
|
|
/>
|
|
)}
|
|
{agent && agent.author === user?.id && <DuplicateAgent agent_id={agent_id} />}
|
|
{/* Submit Button */}
|
|
<button
|
|
className="btn btn-primary focus:shadow-outline flex h-9 w-full items-center justify-center px-4 py-2 font-semibold text-white hover:bg-green-600 focus:border-green-500"
|
|
type="submit"
|
|
disabled={createMutation.isLoading || updateMutation.isLoading}
|
|
aria-busy={createMutation.isLoading || updateMutation.isLoading}
|
|
>
|
|
{renderSaveButton()}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|