mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
25 lines
718 B
TypeScript
25 lines
718 B
TypeScript
import { useMemo } from 'react';
|
|
import { PermissionBits } from 'librechat-data-provider';
|
|
import type { TAgentsMap } from 'librechat-data-provider';
|
|
import { useListAgentsQuery } from '~/data-provider';
|
|
import { mapAgents } from '~/utils';
|
|
|
|
export default function useAgentsMap({
|
|
isAuthenticated,
|
|
}: {
|
|
isAuthenticated: boolean;
|
|
}): TAgentsMap | undefined {
|
|
const { data: agentsList = null } = useListAgentsQuery(
|
|
{ requiredPermission: PermissionBits.VIEW },
|
|
{
|
|
select: (res) => mapAgents(res.data),
|
|
enabled: isAuthenticated,
|
|
},
|
|
);
|
|
|
|
const agents = useMemo<TAgentsMap | undefined>(() => {
|
|
return agentsList !== null ? agentsList : undefined;
|
|
}, [agentsList]);
|
|
|
|
return agents;
|
|
}
|