LibreChat/client/src/hooks/Files/useSharePointFileHandling.ts
Danny Avila cde5079886
🎯 fix: Use Agents Endpoint Config for Agent Panel File Upload Validation (#11992)
* fix: Use correct endpoint for file validation in agent panel uploads

  Agent panel file uploads (FileSearch, FileContext, Code/Files) were validating against the active conversation's endpoint config instead of the agents endpoint config. This caused incorrect file size limits when the active chat used a different endpoint.

  Add endpointOverride option to useFileHandling so callers can specify the correct endpoint for validation independent of the active conversation.

* fix: Use agents endpoint config for agent panel file upload validation

Agent panel file uploads (FileSearch, FileContext, Code/Files) validated
against the active conversation's endpoint config instead of the agents
endpoint config. This caused wrong file size limits when the active chat
used a different endpoint.

Adds endpointOverride to useFileHandling so callers can specify the
correct endpoint for both validation and upload routing, independent of
the active conversation.

* test: Add unit tests for useFileHandling hook to validate endpoint overrides

Introduced comprehensive tests for the useFileHandling hook, ensuring correct behavior when using endpoint overrides for file validation and upload routing. The tests cover various scenarios, including fallback to conversation endpoints and proper handling of agent-specific configurations, enhancing the reliability of file handling in the application.
2026-02-28 15:01:51 -05:00

57 lines
1.7 KiB
TypeScript

import { useCallback } from 'react';
import useFileHandling from './useFileHandling';
import useSharePointDownload from './useSharePointDownload';
import type { EModelEndpoint } from 'librechat-data-provider';
import type { SharePointFile } from '~/data-provider/Files/sharepoint';
interface UseSharePointFileHandlingProps {
fileSetter?: any;
toolResource?: string;
fileFilter?: (file: File) => boolean;
additionalMetadata?: Record<string, string | undefined>;
endpointOverride?: EModelEndpoint;
}
interface UseSharePointFileHandlingReturn {
handleSharePointFiles: (files: SharePointFile[]) => Promise<void>;
isProcessing: boolean;
downloadProgress: any;
error: string | null;
}
export default function useSharePointFileHandling(
props?: UseSharePointFileHandlingProps,
): UseSharePointFileHandlingReturn {
const { handleFiles } = useFileHandling(props);
const { downloadSharePointFiles, isDownloading, downloadProgress, error } = useSharePointDownload(
{
onFilesDownloaded: async (downloadedFiles: File[]) => {
const fileArray = Array.from(downloadedFiles);
await handleFiles(fileArray, props?.toolResource);
},
onError: (error) => {
console.error('SharePoint download failed:', error);
},
},
);
const handleSharePointFiles = useCallback(
async (sharePointFiles: SharePointFile[]) => {
try {
await downloadSharePointFiles(sharePointFiles);
} catch (error) {
console.error('SharePoint file handling error:', error);
throw error;
}
},
[downloadSharePointFiles],
);
return {
handleSharePointFiles,
isProcessing: isDownloading,
downloadProgress,
error,
};
}