🧩 refactor: File Upload Options based on Ephemeral Agent (#9693)

* refactor: agent tool permissions to support ephemeral agent settings

* ci: rename render tests and correct typing for `useAgentToolPermissions` hook

* refactor: implement `DragDropContext` to minimize effect of `useChatContext` in `DragDropModal`
This commit is contained in:
Danny Avila 2025-09-18 14:44:55 -04:00 committed by GitHub
parent 208be7c06c
commit 48ca1bfd88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 300 additions and 59 deletions

View file

@ -1,5 +1,6 @@
import { useMemo } from 'react';
import { Tools, Constants } from 'librechat-data-provider';
import { Tools, Constants, EToolResources } from 'librechat-data-provider';
import type { TEphemeralAgent } from 'librechat-data-provider';
import { useGetAgentByIdQuery } from '~/data-provider';
import { useAgentsMapContext } from '~/Providers';
@ -16,11 +17,13 @@ function isEphemeralAgent(agentId: string | null | undefined): boolean {
/**
* Hook to determine whether specific tools are allowed for a given agent.
*
* @param agentId - The ID of the agent. If null/undefined/empty, returns true for all tools (ephemeral agent behavior)
* @param agentId - The ID of the agent. If null/undefined/empty, checks ephemeralAgent settings
* @param ephemeralAgent - Optional ephemeral agent settings for tool permissions
* @returns Object with boolean flags for file_search and execute_code permissions, plus the tools array
*/
export default function useAgentToolPermissions(
agentId: string | null | undefined,
ephemeralAgent?: TEphemeralAgent | null,
): AgentToolPermissionsResult {
const agentsMap = useAgentsMapContext();
@ -37,22 +40,26 @@ export default function useAgentToolPermissions(
);
const fileSearchAllowedByAgent = useMemo(() => {
// Allow for ephemeral agents
if (isEphemeralAgent(agentId)) return true;
// Check ephemeral agent settings
if (isEphemeralAgent(agentId)) {
return ephemeralAgent?.[EToolResources.file_search] ?? false;
}
// If agentId exists but agent not found, disallow
if (!selectedAgent) return false;
// Check if the agent has the file_search tool
return tools?.includes(Tools.file_search) ?? false;
}, [agentId, selectedAgent, tools]);
}, [agentId, selectedAgent, tools, ephemeralAgent]);
const codeAllowedByAgent = useMemo(() => {
// Allow for ephemeral agents
if (isEphemeralAgent(agentId)) return true;
// Check ephemeral agent settings
if (isEphemeralAgent(agentId)) {
return ephemeralAgent?.[EToolResources.execute_code] ?? false;
}
// If agentId exists but agent not found, disallow
if (!selectedAgent) return false;
// Check if the agent has the execute_code tool
return tools?.includes(Tools.execute_code) ?? false;
}, [agentId, selectedAgent, tools]);
}, [agentId, selectedAgent, tools, ephemeralAgent]);
return {
fileSearchAllowedByAgent,