📋 refactor: Agent Tool Permissions for File Upload Options (#9647)

- Added isEphemeralAgent function to streamline checks for ephemeral agents.
- Updated logic in useAgentToolPermissions to utilize the new function for determining tool access.
- Introduced comprehensive tests for useAgentToolPermissions covering various scenarios including ephemeral agents, regular agents with tools, and edge cases.
This commit is contained in:
Danny Avila 2025-09-15 12:57:40 -04:00 committed by GitHub
parent 52b65492d5
commit 6738360051
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 449 additions and 5 deletions

View file

@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { Tools } from 'librechat-data-provider';
import { Tools, Constants } from 'librechat-data-provider';
import { useGetAgentByIdQuery } from '~/data-provider';
import { useAgentsMapContext } from '~/Providers';
@ -9,6 +9,10 @@ interface AgentToolPermissionsResult {
tools: string[] | undefined;
}
function isEphemeralAgent(agentId: string | null | undefined): boolean {
return agentId == null || agentId === '' || agentId === Constants.EPHEMERAL_AGENT_ID;
}
/**
* Hook to determine whether specific tools are allowed for a given agent.
*
@ -33,8 +37,8 @@ export default function useAgentToolPermissions(
);
const fileSearchAllowedByAgent = useMemo(() => {
// If no agentId, allow for ephemeral agents
if (!agentId) return true;
// Allow for ephemeral agents
if (isEphemeralAgent(agentId)) return true;
// If agentId exists but agent not found, disallow
if (!selectedAgent) return false;
// Check if the agent has the file_search tool
@ -42,8 +46,8 @@ export default function useAgentToolPermissions(
}, [agentId, selectedAgent, tools]);
const codeAllowedByAgent = useMemo(() => {
// If no agentId, allow for ephemeral agents
if (!agentId) return true;
// Allow for ephemeral agents
if (isEphemeralAgent(agentId)) return true;
// If agentId exists but agent not found, disallow
if (!selectedAgent) return false;
// Check if the agent has the execute_code tool