"""Validation helpers for workflow file inputs.""" from __future__ import annotations from graphon.file import FileTransferMethod, FileType, FileUploadConfig def is_file_valid_with_config( *, input_file_type: str, file_extension: str, file_transfer_method: FileTransferMethod, config: FileUploadConfig, ) -> bool: # FIXME(QIN2DIM): Always allow tool files (files generated by the assistant/model) # These are internally generated and should bypass user upload restrictions if file_transfer_method == FileTransferMethod.TOOL_FILE: return True if ( config.allowed_file_types and input_file_type not in config.allowed_file_types and input_file_type != FileType.CUSTOM ): return False if ( input_file_type == FileType.CUSTOM and config.allowed_file_extensions is not None and file_extension not in config.allowed_file_extensions ): return False if input_file_type == FileType.IMAGE: if ( config.image_config and config.image_config.transfer_methods and file_transfer_method not in config.image_config.transfer_methods ): return False elif config.allowed_file_upload_methods and file_transfer_method not in config.allowed_file_upload_methods: return False return True