⬆️ feat: Cancel chat file uploads; fix: Assistant uploads (#4433)

* refactor: move file mutations to dedicated file, improve typing

* refactor(ChatForm): utilize FileFormWrapper to consolidate file upload logic/rendering to single parent

* refactor: better TSX heirarchies between AttachFile and FileFormWrapper

* refactor: `abortUpload` WIP

* fix: file debugging and file upload issues

* refactor: reject promise outright if axios intercepted error does not include response property

* chore: bump data-provider version to 0.7.428

* refactor: Add return type to localize function in Translation.ts

* refactor: allow message file attachment upload request cancellations, and add localizations for file upload errors

* refactor: include Azure OpenAI in paramEndpoints set

* fix: assistant form uploads and better typing

* refactor: consolidate logic
This commit is contained in:
Danny Avila 2024-10-16 11:24:40 -04:00 committed by GitHub
parent 0870acd086
commit 65888c274a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 419 additions and 311 deletions

View file

@ -4,11 +4,13 @@ import type { ExtendedFile } from '~/common';
import { useDeleteFilesMutation } from '~/data-provider';
import { useFileDeletion } from '~/hooks/Files';
import FileContainer from './FileContainer';
import { logger } from '~/utils';
import Image from './Image';
export default function FileRow({
files: _files,
setFiles,
abortUpload,
setFilesLoading,
assistant_id,
agent_id,
@ -18,6 +20,7 @@ export default function FileRow({
Wrapper,
}: {
files: Map<string, ExtendedFile> | undefined;
abortUpload?: () => void;
setFiles: React.Dispatch<React.SetStateAction<Map<string, ExtendedFile>>>;
setFilesLoading: React.Dispatch<React.SetStateAction<boolean>>;
fileFilter?: (file: ExtendedFile) => boolean;
@ -33,7 +36,8 @@ export default function FileRow({
const { mutateAsync } = useDeleteFilesMutation({
onMutate: async () =>
console.log(
logger.log(
'agents',
'Deleting files: agent_id, assistant_id, tool_resource',
agent_id,
assistant_id,
@ -86,7 +90,12 @@ export default function FileRow({
{ map: new Map(), uniqueFiles: [] as ExtendedFile[] },
)
.uniqueFiles.map((file: ExtendedFile, index: number) => {
const handleDelete = () => deleteFile({ file, setFiles });
const handleDelete = () => {
if (abortUpload && file.progress < 1) {
abortUpload();
}
deleteFile({ file, setFiles });
};
const isImage = file.type?.startsWith('image') ?? false;
if (isImage) {
return (