-
Notifications
You must be signed in to change notification settings - Fork 16
Onboarding
Python 3.11+ is required. Poetry is used to manage dependencies and tasks.
install pre-reqs
pip install poetryOllama is required to run AI tools. See Ollama installation guide. Some of the plugns have pre-reqs like UFDR-Mounter needs Winfsp installed.
Clone the repo:
git clone https://github.com/UMass-Rescue/RescueBox.gitInstall setup dependencies:
# cd RescueBox/
poetry installthis src is tested on windows. pyproject.toml may need updates on mac/linux
Run RescueBox API for use with Desktop UI:
# cd RescueBox/
./run_serverRun rescuebox-Autoui: by browing http://localhost:8000/ , this UI is useful in dev mode only.
Run rescuebox-UI for customer experience :
Install RescueBox Desktop desktop and follow the readme to start the Desktop. refer these docs/screenshots
RescueBox is an application with a plugin-based architecture. It is designed to be extensible, allowing for the addition of new functionalities through plugins. The backend of the application is built with Python, utilizing the typer library to create a user-friendly and powerful command-line experience and fastapi for rest-api programmatic experience as well. There is developer UI "autoui" for quick tests and a production use UI frontend based on electron react framework.
- Programming Language: Python
-
Framework:
fastapi, typer, elecrtron -
Package Management:
poetry npm -
Main Backend Entry Point:
rescuebox.main:app
The project is organized into several directories, with the main application logic located in the rescuebox directory. Plugins are located in the src directory, with each plugin in its own subdirectory.
-
pyproject.toml: Defines the project's metadata, dependencies, and scripts. -
rescuebox/main.py: The main entry point for the CLI application. This file is responsible for loading the plugins and setting up thetyperapplication. -
CONTRIBUTING.md: Provides guidelines for contributing to the project.
The RescueBox plugin architecture is designed to be modular and extensible, allowing for the seamless integration of new functionalities. Here's a detailed breakdown of how plugins work, how they are exposed, and how their inputs and outputs are validated.
Plugins are discovered and loaded into the main application through a straightforward mechanism:
-
Plugin Aggregation: The
rescuebox/plugins/__init__.pyfile is responsible for collecting all available plugins. It imports thetyperapp from each plugin'smain.pyfile and wraps it in aRescueBoxPlugindataclass, which stores the plugin'styperapplication, its CLI name, and its full name. -
Dynamic Loading: The main application entry point,
rescuebox/main.py, imports the list ofRescueBoxPlugininstances fromrescuebox/plugins/__init__.py. It then iterates through this list and adds each plugin'styperapp to the maintyperapplication usingapp.add_typer(). This makes the plugin's commands available as subcommands of the mainrescueboxcommand.
In addition to being accessible via the CLI, plugin functionalities are also exposed through a FastAPI-based RESTful API. This is achieved as follows:
-
Dynamic Route Generation: The
src/rb-api/rb/api/routes/cli.pyfile is the core of the API exposure mechanism. It inspects thetypercommands registered in the mainrescueboxapplication and dynamically generates corresponding FastAPI endpoints for each command. -
Command Handling: The
command_callbackfunction incli.pywraps the originaltypercommand's callback function. This wrapper handles both synchronous and streaming responses, allowing for flexible data handling. For streaming responses, the output is sent as a series of server-sent events (SSE). -
API Router: The generated routes are added to the
cli_to_api_router, which is then included in the main FastAPI application insrc/rb-api/rb/api/main.py. This makes the plugin's functionality accessible via HTTP requests.
To simplify the development of machine learning-based plugins, the project provides a helper class called MLService in src/rb-lib/rb/lib/ml_service.py. This class offers a structured way to define and manage ML services:
-
Decorator-Based Approach: The
add_ml_servicedecorator simplifies the creation oftypercommands and their corresponding API endpoints. It handles the boilerplate code for defining routes, generating task schemas, and managing request/response models. -
Metadata and Schema: The
MLServiceclass also provides methods for adding metadata to the plugin and definingTaskSchemafor each ML task. TheTaskSchemadefines the expected inputs and parameters for a given task, which is crucial for validation and for the frontend to dynamically generate user interfaces.
The RescueBox plugin architecture places a strong emphasis on data validation to ensure the stability and reliability of the system. This is achieved through a combination of Pydantic models and custom validation logic:
-
Pydantic Models: The
src/rb-api/rb/api/models.pyfile defines a comprehensive set of Pydantic models for API requests and responses. These models define the data structures for inputs, outputs, and task schemas, ensuring that all data exchanged between the frontend, API, and backend plugins is well-structured and validated. -
Type Hint Validation: The
src/rb-lib/rb/lib/utils.pymodule provides functions that enforce consistency between the type hints in a plugin's ML function and theTaskSchemadefined for that function. Theensure_ml_func_hinting_and_task_schemas_are_validfunction is particularly important, as it checks that the data types of the function's arguments match the types specified in the schema. This prevents data type mismatches and ensures that the backend functions receive the data in the expected format. -
Exception Handling: The FastAPI application includes a global exception handler in
src/rb-api/rb/api/main.pythat catches and formats validation errors from the backend plugins. This ensures that the API provides consistent and informative error responses.
Plugins can be run two ways:
-
CLI: From the command line, plugins are invoked as subcommands of the main
rescueboxcommand. For example, a command in thefile-utilsplugin would be invoked asrescuebox fs <command>. -
API: Plugins are invoked via HTTP requests to the dynamically generated API endpoints. The specific endpoint for a given command can be discovered by querying the
/api/routesendpoint of the plugin.
The src/rb-lib/rb/lib/common_tests.py file provides a base class, RBAppTest, which simplifies the process of writing tests for plugins. This class includes helper methods for testing the CLI commands, API endpoints, metadata, and task schemas, ensuring that plugins are working correctly and are well-integrated into the RescueBox ecosystem.
The backend of the RescueBox project is contained within the rescuebox and src directories. The rescuebox directory contains the core CLI application, while the src directory holds all the plugins. The file RescueBox/rescuebox/plugins/__init__.py is responsible for importing and collecting all the backend plugins from the src directory.
The RescueBox project also includes a FastAPI application that exposes the functionality of the plugins through a RESTful API. The main entry point for this application is RescueBox/src/rb-api/rb/api/main.py. This file is responsible for creating the FastAPI application and including the API routers from rb.api.routes.
The file RescueBox/src/rb-api/rb/api/routes/cli.py is responsible for dynamically generating API routes from the CLI commands defined in the plugins. It inspects the typer commands and creates corresponding FastAPI endpoints, effectively exposing the CLI functionality through the API. This includes both static and streaming endpoints, with the command_callback function creating the appropriate handler for each command.
Additionally, the file RescueBox/src/rb-api/rb/api/routes/ui.py provides the backend with a simple web-based user interface for developers. This "dev UI" or "react autoui" renders a tree of all available backend commands. The frontend for this interface is a React application located in RescueBox/web/rescuebox-autoui, which consumes the data from the API and provides an interactive way to execute commands and view their output. The endpoint URLs are constructed in the typer_app_to_tree function, which is responsible for generating the data structure used by the frontend.
The validation_exception_handler function in this file is a global exception handler that catches and formats validation errors from any of the backend plugins, ensuring a consistent error response format across the API.
The RescueBox project also includes a desktop application, RescueBox-Desktop. This is an Electron application built with the following technologies:
- Framework: React
- Language: TypeScript
- Bundler: Webpack
- UI Components: Radix UI, shadcn/ui
- Styling: Tailwind CSS
This application provides a graphical user interface for interacting with the RescueBox plugins and viewing the results of their analyses.
The CONTRIBUTING.md file contains detailed instructions for developers who wish to contribute to the project. It covers topics such as reporting bugs, suggesting enhancements, and submitting code changes.