LibreChat/client/src/hooks/Agents/useAgentCategories.tsx
Danny Avila 76d75030b9
🔐 feat: Granular Role-based Permissions + Entra ID Group Discovery (#7804)
WIP: pre-granular-permissions commit

feat: Add category and support contact fields to Agent schema and UI components

Revert "feat: Add category and support contact fields to Agent schema and UI components"

This reverts commit c43a52b4c9.

Fix: Update import for renderHook in useAgentCategories.spec.tsx

fix: Update icon rendering in AgentCategoryDisplay tests to use empty spans

refactor: Improve category synchronization logic and clean up AgentConfig component

refactor: Remove unused UI flow translations from translation.json

feat: agent marketplace features

🔐 feat: Granular Role-based Permissions + Entra ID Group Discovery (#7804)
2025-08-11 19:00:47 -04:00

57 lines
1.6 KiB
TypeScript

import { useMemo } from 'react';
import useLocalize from '~/hooks/useLocalize';
import { useGetAgentCategoriesQuery } from '~/data-provider';
import { EMPTY_AGENT_CATEGORY } from '~/constants/agentCategories';
// This interface matches the structure used by the ControlCombobox component
export interface ProcessedAgentCategory {
label: string; // Translated label
value: string; // Category value
className?: string;
}
/**
* Custom hook that provides processed and translated agent categories from API
*
* @returns Object containing categories, emptyCategory, and loading state
*/
const useAgentCategories = () => {
const localize = useLocalize();
// Fetch categories from API
const categoriesQuery = useGetAgentCategoriesQuery({
staleTime: 1000 * 60 * 15, // 15 minutes
});
const categories = useMemo((): ProcessedAgentCategory[] => {
if (!categoriesQuery.data) return [];
// Filter out special categories (promoted, all) and convert to form format
return categoriesQuery.data
.filter((category) => category.value !== 'promoted' && category.value !== 'all')
.map((category) => ({
label: category.label || category.value,
value: category.value,
className: 'w-full',
}));
}, [categoriesQuery.data]);
const emptyCategory = useMemo(
(): ProcessedAgentCategory => ({
label: localize(EMPTY_AGENT_CATEGORY.label),
value: EMPTY_AGENT_CATEGORY.value,
className: 'w-full',
}),
[localize],
);
return {
categories,
emptyCategory,
isLoading: categoriesQuery.isLoading,
error: categoriesQuery.error,
};
};
export default useAgentCategories;