🤖 refactor: Auto-validate IDs in Agent Query (#9555)

* 🤖 refactor: Auto-validate IDs in Agent Query

* chore: remove comments in useAgentToolPermissions
This commit is contained in:
Danny Avila 2025-09-10 18:38:33 -04:00 committed by GitHub
parent f3eca8c7a7
commit f125f5bd32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 21 additions and 33 deletions

View file

@ -1,5 +1,11 @@
import { useQuery, useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
import { QueryKeys, dataService, EModelEndpoint, PermissionBits } from 'librechat-data-provider';
import {
Constants,
QueryKeys,
dataService,
EModelEndpoint,
PermissionBits,
} from 'librechat-data-provider';
import type {
QueryObserverResult,
UseQueryOptions,
@ -64,20 +70,27 @@ export const useListAgentsQuery = <TData = t.AgentListResponse>(
* Hook for retrieving basic details about a single agent (VIEW permission)
*/
export const useGetAgentByIdQuery = (
agent_id: string,
agent_id: string | null | undefined,
config?: UseQueryOptions<t.Agent>,
): QueryObserverResult<t.Agent> => {
const isValidAgentId = !!(
agent_id &&
agent_id !== '' &&
agent_id !== Constants.EPHEMERAL_AGENT_ID
);
return useQuery<t.Agent>(
[QueryKeys.agent, agent_id],
() =>
dataService.getAgentById({
agent_id,
agent_id: agent_id as string,
}),
{
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchOnMount: false,
retry: false,
enabled: isValidAgentId && (config?.enabled ?? true),
...config,
},
);