mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-06 10:38:50 +01:00
🤖 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:
parent
f3eca8c7a7
commit
f125f5bd32
6 changed files with 21 additions and 33 deletions
|
|
@ -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,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue