# actions/file_actions.py from environment.file_system import FileSystem def create_folder(fs: FileSystem, name: str) -> dict: """Action: Create a new folder.""" return fs.create_folder(name) def move_file(fs: FileSystem, filename: str, destination: str) -> dict: """Action: Move a file to a destination folder.""" return fs.move_file(filename, destination) def rename_file(fs: FileSystem, old_name: str, new_name: str) -> dict: """Action: Rename a file.""" return fs.rename_file(old_name, new_name) def delete_file(fs: FileSystem, filename: str) -> dict: """Action: Delete a file.""" return fs.delete_file(filename) def zip_folder(fs: FileSystem, folder_name: str) -> dict: """Action: Zip a folder to compress it.""" return fs.zip_folder(folder_name) def inspect_file(fs: FileSystem, filename: str) -> dict: """Action: Inspect a file's metadata.""" info = fs.get_file_info(filename) if info: return {"success": True, "file_info": info} return {"success": False, "message": f"File '{filename}' not found."} def list_all_files(fs: FileSystem) -> dict: """Action: List all files in the filesystem.""" files = fs.list_files() return {"success": True, "files": files, "total": len(files)} # Registry mapping action name → callable ACTION_REGISTRY = { "create_folder": create_folder, "move_file": move_file, "rename_file": rename_file, "delete_file": delete_file, "zip_folder": zip_folder, "inspect_file": inspect_file, "list_all_files": list_all_files, } def execute_action(fs, action_type, params): """ Dispatch action using registry. """ if action_type not in ACTION_REGISTRY: raise ValueError( f"Unknown action: {action_type}" ) handler = ACTION_REGISTRY[action_type] # Call handler with parameters return handler( fs, **params )