Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-2470 [FEAT] Remove Django dependency from Celery workers with internal APIs (#1494)

ali0c5997f9a9da
diff --git a/.gitignore b/.gitignore
index e912bde5c..8cb0de037 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,14 @@
# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,linux,pycharm,pycharm+all,pycharm+iml,python,visualstudiocode,react,django
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,linux,pycharm,pycharm+all,pycharm+iml,python,visualstudiocode,react,django
+# Development helper scripts
+*.sh
+# list Exceptional files with ! like !fix-and-test.sh
+!run-platform.sh
+!workers/run-worker.sh
+!workers/run-worker-docker.sh
+!workers/log_consumer/scheduler.sh
+
### Django ###
*.log
*.pot
@@ -622,6 +630,7 @@ backend/plugins/processor/*
# Subscription Plugins
backend/plugins/subscription/*
+
# API Deployment Plugins
backend/plugins/api/**
@@ -685,6 +694,7 @@ backend/requirements.txt
backend/backend/*_urls.py
!backend/backend/base_urls.py
!backend/backend/public_urls.py
+!backend/backend/internal_base_urls.py
# TODO: Remove after v2 migration is completed
backend/backend/*_urls_v2.py
!backend/backend/public_urls_v2.py
diff --git a/backend/account_v2/custom_auth_middleware.py b/backend/account_v2/custom_auth_middleware.py
index 3fc902bdb..d55bbca39 100644
--- a/backend/account_v2/custom_auth_middleware.py
+++ b/backend/account_v2/custom_auth_middleware.py
@@ -8,6 +8,7 @@ from account_v2.authentication_plugin_registry import AuthenticationPluginRegist
from account_v2.authentication_service import AuthenticationService
from account_v2.constants import Common
from backend.constants import RequestHeader
+from backend.internal_api_constants import INTERNAL_API_PREFIX
class CustomAuthMiddleware:
@@ -22,6 +23,10 @@ class CustomAuthMiddleware:
if any(request.path.startswith(path) for path in settings.WHITELISTED_PATHS):
return self.get_response(request)
+ # Skip internal API paths - they are handled by InternalAPIAuthMiddleware
+ if request.path.startswith(f"{INTERNAL_API_PREFIX}/"):
+ return self.get_response(request)
+
# Authenticating With API_KEY
x_api_key = request.headers.get(RequestHeader.X_API_KEY)
if (
diff --git a/backend/account_v2/internal_serializers.py b/backend/account_v2/internal_serializers.py
new file mode 100644
index 000000000..6a076313c
--- /dev/null
+++ b/backend/account_v2/internal_serializers.py
@@ -0,0 +1,15 @@
+"""Account Internal API Serializers
+Handles serialization for organization context related endpoints.
+"""
+
+from rest_framework import serializers
+
+
+class OrganizationContextSerializer(serializers.Serializer):
+ """Serializer for organization context information."""
+
+ organization_id = serializers.CharField()
+ organization_name = serializers.CharField()
+ organization_slug = serializers.CharField(required=False, allow_blank=True)
+ created_at = serializers.CharField(required=False, allow_blank=True)
+ settings = serializers.DictField(required=False)
diff --git a/backend/account_v2/internal_urls.py b/backend/account_v2/internal_urls.py
new file mode 100644
index 000000000..00dcb787e
--- /dev/null
+++ b/backend/account_v2/internal_urls.py
@@ -0,0 +1,20 @@
+"""Internal API URLs for Organization Context
+URL patterns for organization-related internal APIs.
+"""
+
+from django.urls import path
+
+from .internal_views import OrganizationContextAPIView
+
+urlpatterns = [
+ # Organization context endpoint (backward compatibility)
+ path(
+ "<str:org_id>/", OrganizationContextAPIView.as_view(), name="organization-context"
+ ),
+ # Organization context endpoint (explicit path)
+ path(
+ "<str:org_id>/context/",
+ OrganizationContextAPIView.as_view(),
+ name="organization-context-explicit",
+ ),
+]
diff --git a/backend/account_v2/internal_views.py b/backend/account_v2/internal_views.py
new file mode 100644
index 000000000..10161a4e6
--- /dev/null
+++ b/backend/account_v2/internal_views.py
@@ -0,0 +1,40 @@
+"""Account Internal API Views
+Handles organization context related endpoints for internal services.
+"""
+
+import logging
+
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from utils.organization_utils import get_organization_context, resolve_organization
+
+from .internal_serializers import OrganizationContextSerializer
+
+logger = logging.getLogger(__name__)
+
+
+class OrganizationContextAPIView(APIView):
+ """Internal API endpoint for getting organization context."""
+
+ def get(self, request, org_id):
+ """Get organization context information."""
+ try:
+ # Use shared utility to resolve organization
+ organization = resolve_organization(org_id, raise_on_not_found=True)
+
+ # Use shared utility to get context data
+ context_data = get_organization_context(organization)
+
+ serializer = OrganizationContextSerializer(context_data)
+
+ logger.info(f"Retrieved organization context for {org_id}")
+
+ return Response(serializer.data)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization context for {org_id}: {str(e)}")
+ return Response(
+ {"error": "Failed to get organization context", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/account_v2/organization_internal_urls.py b/backend/account_v2/organization_internal_urls.py
new file mode 100644
index 000000000..6d247d43c
--- /dev/null
+++ b/backend/account_v2/organization_internal_urls.py
@@ -0,0 +1,16 @@
+"""Account Internal API URLs
+Defines internal API endpoints for organization operations.
+"""
+
+from django.urls import path
+
+from .internal_views import OrganizationContextAPIView
+
+urlpatterns = [
+ # Organization context API
+ path(
+ "<str:org_id>/context/",
+ OrganizationContextAPIView.as_view(),
+ name="organization-context",
+ ),
+]
diff --git a/backend/account_v2/subscription_loader.py b/backend/account_v2/subscription_loader.py
index 13fe05a6c..8f323c29b 100644
--- a/backend/account_v2/subscription_loader.py
+++ b/backend/account_v2/subscription_loader.py
@@ -21,8 +21,19 @@ class SubscriptionConfig:
METADATA_IS_ACTIVE = "is_active"
+# Cache for loaded plugins to avoid repeated loading
+_subscription_plugins_cache: list[Any] = []
+_plugins_loaded = False
+
+
def load_plugins() -> list[Any]:
"""Iterate through the subscription plugins and register them."""
+ global _subscription_plugins_cache, _plugins_loaded
+
+ # Return cached plugins if already loaded
+ if _plugins_loaded:
+ return _subscription_plugins_cache
+
plugins_app = apps.get_app_config(SubscriptionConfig.PLUGINS_APP)
package_path = plugins_app.module.__package__
subscription_dir = os.path.join(plugins_app.path, SubscriptionConfig.PLUGIN_DIR)
@@ -30,6 +41,8 @@ def load_plugins() -> list[Any]:
subscription_plugins: list[Any] = []
if not os.path.exists(subscription_dir):
+ _subscription_plugins_cache = subscription_plugins
+ _plugins_loaded = True
return subscription_plugins
for item in os.listdir(subscription_dir):
@@ -56,10 +69,13 @@ def load_plugins() -> list[Any]:
SubscriptionConfig.METADATA: module.metadata,
}
)
+ name = metadata.get(
+ SubscriptionConfig.METADATA_NAME,
+ getattr(module, "__name__", "unknown"),
+ )
+ is_active = metadata.get(SubscriptionConfig.METADATA_IS_ACTIVE, False)
logger.info(
- "Loaded subscription plugin: %s, is_active: %s",
- module.metadata[SubscriptionConfig.METADATA_NAME],
- module.metadata[SubscriptionConfig.METADATA_IS_ACTIVE],
+ "Loaded subscription plugin: %s, is_active: %s", name, is_active
)
else:
logger.info(
@@ -75,6 +91,10 @@ def load_plugins() -> list[Any]:
if len(subscription_plugins) == 0:
logger.info("No subscription plugins found.")
+ # Cache the results for future requests
+ _subscription_plugins_cache = subscription_plugins
+ _plugins_loaded = True
+
return subscription_plugins
diff --git a/backend/api_v2/internal_api_views.py b/backend/api_v2/internal_api_views.py
new file mode 100644
index 000000000..9c2c0b441
--- /dev/null
+++ b/backend/api_v2/internal_api_views.py
@@ -0,0 +1,74 @@
+"""Internal API Views for API v2
+
+This module provides internal API endpoints for worker communication,
+specifically optimized for type-aware pipeline data fetching.
+
+Since we know the context from worker function calls:
+- process_batch_callback_api -> APIDeployment model
+- process_batch_callback -> Pipeline model (handled in workflow_manager)
+
+This provides direct access to APIDeployment model data without
+the overhead of checking both Pipeline and APIDeployment models.
+"""
+
+import logging
+
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from api_v2.models import APIDeployment
+from api_v2.serializers import APIDeploymentSerializer
+
+logger = logging.getLogger(__name__)
+
+
+class APIDeploymentDataView(APIView):
+ """Internal API endpoint for fetching APIDeployment data.
+
+ This endpoint is optimized for callback workers that know they're dealing
+ with API deployments. It directly queries the APIDeployment model without
+ checking the Pipeline model, improving performance.
+
+ Endpoint: GET /v2/api-deployments/{api_id}/data/
+ """
+
+ def get(self, request, api_id):
+ """Get APIDeployment model data by API ID.
+
+ Args:
+ request: HTTP request object
+ api_id: APIDeployment UUID
+
+ Returns:
+ Response with APIDeployment model data
+ """
+ try:
+ logger.debug(f"Fetching APIDeployment data for ID: {api_id}")
+
+ # Query APIDeployment model directly (organization-scoped via DefaultOrganizationMixin)
+ api_deployment = APIDeployment.objects.get(id=api_id)
+
+ # Serialize the APIDeployment model
+ serializer = APIDeploymentSerializer(api_deployment)
+
+ # Use consistent response format with pipeline endpoint
+ response_data = {"status": "success", "pipeline": serializer.data}
+
+ logger.info(
+ f"Found APIDeployment {api_id}: name='{api_deployment.api_name}', display_name='{api_deployment.display_name}'"
+ )
+ return Response(response_data, status=status.HTTP_200_OK)
+
+ except APIDeployment.DoesNotExist:
+ logger.warning(f"APIDeployment not found for ID: {api_id}")
+ return Response(
+ {"error": f"APIDeployment with ID {api_id} not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Exception as e:
+ logger.error(f"Error fetching APIDeployment data for {api_id}: {str(e)}")
+ return Response(
+ {"error": f"Failed to fetch APIDeployment data: {str(e)}"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/api_v2/internal_urls.py b/backend/api_v2/internal_urls.py
new file mode 100644
index 000000000..c4619221c
--- /dev/null
+++ b/backend/api_v2/internal_urls.py
@@ -0,0 +1,20 @@
+"""Internal API URLs for API v2
+
+Internal endpoints for worker communication, specifically optimized
+for type-aware pipeline data fetching.
+"""
+
+from django.urls import path
+from rest_framework.urlpatterns import format_suffix_patterns
+
+from api_v2.internal_api_views import APIDeploymentDataView
+
+urlpatterns = format_suffix_patterns(
+ [
+ path(
+ "<uuid:api_id>/",
+ APIDeploymentDataView.as_view(),
+ name="api_deployment_data_internal",
+ ),
+ ]
+)
diff --git a/backend/backend/base_urls.py b/backend/backend/base_urls.py
index 3a37717ab..8450add04 100644
--- a/backend/backend/base_urls.py
+++ b/backend/backend/base_urls.py
@@ -23,4 +23,6 @@ urlpatterns = [
include("pipeline_v2.public_api_urls"),
),
path("", include("health.urls")),
+ # Internal API for worker communication
+ path("internal/", include("backend.internal_base_urls")),
]
diff --git a/backend/backend/internal_api_constants.py b/backend/backend/internal_api_constants.py
new file mode 100644
index 000000000..52c0838db
--- /dev/null
+++ b/backend/backend/internal_api_constants.py
@@ -0,0 +1,100 @@
+"""Internal API Constants
+
+Centralized constants for internal API paths, versions, and configuration.
+These constants can be overridden via environment variables for flexibility.
+"""
+
+import os
+
+# Default constant for SonarCloud compliance
+DEFAULT_INTERNAL_PREFIX = "/internal"
+
+# Internal API Configuration
+INTERNAL_API_PREFIX = os.getenv("INTERNAL_API_PREFIX", DEFAULT_INTERNAL_PREFIX)
+INTERNAL_API_VERSION = os.getenv("INTERNAL_API_VERSION", "v1")
+
+# Computed full prefix
+INTERNAL_API_BASE_PATH = f"{INTERNAL_API_PREFIX}/{INTERNAL_API_VERSION}"
+
+
+def build_internal_endpoint(path: str) -> str:
+ """Build a complete internal API endpoint path.
+
+ Args:
+ path: The endpoint path without the internal prefix (e.g., "health/")
+
+ Returns:
+ Complete internal API path (e.g., "/internal/v1/health/")
+ """
+ # Ensure path starts and ends with /
+ if not path.startswith("/"):
+ path = f"/{path}"
+ if not path.endswith("/"):
+ path = f"{path}/"
+
+ return f"{INTERNAL_API_BASE_PATH}{path}"
+
+
+# Common endpoint builder shortcuts
+class InternalEndpoints:
+ """Convenience class for building internal API endpoints."""
+
+ @staticmethod
+ def health() -> str:
+ """Health check endpoint."""
+ return build_internal_endpoint("health")
+
+ @staticmethod
+ def workflow(workflow_id: str = "{id}") -> str:
+ """Workflow endpoint."""
+ return build_internal_endpoint(f"workflow/{workflow_id}")
+
+ @staticmethod
+ def workflow_status(workflow_id: str = "{id}") -> str:
+ """Workflow status endpoint."""
+ return build_internal_endpoint(f"workflow/{workflow_id}/status")
+
+ @staticmethod
+ def file_execution(file_execution_id: str = "{id}") -> str:
+ """File execution endpoint."""
+ return build_internal_endpoint(f"file-execution/{file_execution_id}")
+
+ @staticmethod
+ def file_execution_status(file_execution_id: str = "{id}") -> str:
+ """File execution status endpoint."""
+ return build_internal_endpoint(f"file-execution/{file_execution_id}/status")
+
+ @staticmethod
+ def webhook_send() -> str:
+ """Webhook send endpoint."""
+ return build_internal_endpoint("webhook/send")
+
+ @staticmethod
+ def organization(org_id: str = "{org_id}") -> str:
+ """Organization endpoint."""
+ return build_internal_endpoint(f"organization/{org_id}")
+
+
+# Environment variable documentation
+ENVIRONMENT_VARIABLES = {
+ "INTERNAL_API_PREFIX": {
+ "description": "Base prefix for internal API endpoints",
+ "default": DEFAULT_INTERNAL_PREFIX,
+ "example": DEFAULT_INTERNAL_PREFIX,
+ },
+ "INTERNAL_API_VERSION": {
+ "description": "API version for internal endpoints",
+ "default": "v1",
+ "example": "v1",
+ },
+}
+
+
+def get_api_info() -> dict:
+ """Get current internal API configuration info."""
+ return {
+ "prefix": INTERNAL_API_PREFIX,
+ "version": INTERNAL_API_VERSION,
+ "base_path": INTERNAL_API_BASE_PATH,
+ "environment_variables": ENVIRONMENT_VARIABLES,
+ }
diff --git a/backend/backend/internal_base_urls.py b/backend/backend/internal_base_urls.py
new file mode 100644
index 000000000..065a63591
--- /dev/null
+++ b/backend/backend/internal_base_urls.py
@@ -0,0 +1,266 @@
+"""Internal API URL Configuration - OSS Base.
+
+Base internal URL patterns for OSS deployment. This file contains
+the foundational internal APIs available in all deployments.
+
+Cloud deployments extend this via cloud_internal_urls.py following
+the same pattern as base_urls.py / cloud_base_urls.py.
+"""
+
+import logging
+import secrets
+
+from django.conf import settings
+from django.http import Http404, JsonResponse
+from django.urls import include, path
+from django.views.decorators.http import require_http_methods
+from utils.websocket_views import emit_websocket
+
+logger = logging.getLogger(__name__)
+
+
+@require_http_methods(["GET"])
+def internal_api_root(request):
+ """Internal API root endpoint with comprehensive documentation."""
+ return JsonResponse(
+ {
+ "message": "Unstract Internal API",
+ "version": "1.0.0",
+ "description": "Internal service-to-service API for Celery workers",
+ "documentation": "https://docs.unstract.com/internal-api",
+ "endpoints": {
+ "description": "Various v1 endpoints for workflow execution, pipeline, organization, and other services",
+ "base_path": "/internal/v1/",
+ },
+ "authentication": {
+ "type": "Bearer Token",
+ "header": "Authorization: Bearer <internal_service_api_key>",
+ "organization": "X-Organization-ID header (optional for scoped requests)",
+ "requirements": [
+ "All requests must include Authorization header",
+ "API key must match INTERNAL_SERVICE_API_KEY setting",
+ "Organization ID header required for org-scoped operations",
+ ],
+ },
+ "response_format": {
+ "success": {"status": "success", "data": "..."},
+ "error": {"error": "Error message", "detail": "Additional details"},
+ },
+ "rate_limits": {
+ "default": "No rate limits for internal services",
+ "note": "Monitor usage through application logs",
+ },
+ }
+ )
+
+
+@require_http_methods(["GET"])
+def internal_health_check(request):
+ """Health check endpoint for internal API."""
+ try:
+ # Debug information (sanitized for security)
+ debug_info = {
+ "has_internal_service": hasattr(request, "internal_service"),
+ "internal_service_value": getattr(request, "internal_service", None),
+ "auth_header_present": bool(request.META.get("HTTP_AUTHORIZATION")),
+ "auth_scheme": (
+ request.META.get("HTTP_AUTHORIZATION", "").split()[0]
+ if request.META.get("HTTP_AUTHORIZATION", "").strip()
+ else "None"
+ ),
+ "path": request.path,
+ "method": request.method,
+ }
+
+ # Check authentication - first check middleware, then fallback to direct key check
+ authenticated = False
+
+ if hasattr(request, "internal_service") and request.internal_service:
+ authenticated = True
+ else:
+ # Fallback: check API key directly if middleware didn't run
+ auth_header = request.META.get("HTTP_AUTHORIZATION", "")
+ if auth_header.startswith("Bearer "):
+ api_key = auth_header[7:] # Remove 'Bearer ' prefix
+ internal_api_key = getattr(settings, "INTERNAL_SERVICE_API_KEY", None)
+ if internal_api_key and secrets.compare_digest(api_key, internal_api_key):
+ authenticated = True
+ # Set the flag manually since middleware didn't run
+ request.internal_service = True
+ elif internal_api_key:
+ # Log authentication failure (without exposing the key)
+ logger.warning(
+ "Internal API authentication failed",
+ extra={
+ "path": request.path,
+ "method": request.method,
+ "remote_addr": request.META.get("REMOTE_ADDR"),
+ },
+ )
+
+ if not authenticated:
+ return JsonResponse(
+ {
+ "status": "error",
+ "message": "Not authenticated as internal service",
+ "debug": debug_info,
+ },
+ status=401,
+ )
+
+ # Basic health checks
+ health_data = {
+ "status": "healthy",
+ "service": "internal_api",
+ "version": "1.0.0",
+ "timestamp": request.META.get("HTTP_DATE"),
+ "authenticated": True,
+ "organization_id": getattr(request, "organization_id", None),
+ "debug": debug_info,
+ }
+
+ return JsonResponse(health_data)
+
+ except Exception as e:
+ logger.exception("internal_health_check failed")
+ return JsonResponse(
+ {
+ "status": "error",
+ "message": "Health check failed",
+ "error": str(e),
+ "debug": {
+ "has_internal_service": hasattr(request, "internal_service"),
+ "auth_header_present": bool(request.META.get("HTTP_AUTHORIZATION")),
+ "auth_scheme": (
+ request.META.get("HTTP_AUTHORIZATION", "").split()[0]
+ if request.META.get("HTTP_AUTHORIZATION", "").strip()
+ else "None"
+ ),
+ "path": request.path,
+ },
+ },
+ status=500,
+ )
+
+
+# Test endpoint to debug middleware (only available in DEBUG mode)
+@require_http_methods(["GET"])
+def test_middleware_debug(request):
+ """Debug endpoint to check middleware execution - only in DEBUG mode."""
+ # Only available in DEBUG mode or with explicit flag
+ if not (settings.DEBUG or getattr(settings, "INTERNAL_API_DEBUG", False)):
+ raise Http404("Debug endpoint not available")
+
+ return JsonResponse(
+ {
+ "middleware_debug": {
+ "path": request.path,
+ "method": request.method,
+ "auth_header_present": bool(request.META.get("HTTP_AUTHORIZATION")),
+ "auth_scheme": (
+ request.META.get("HTTP_AUTHORIZATION", "").split()[0]
+ if request.META.get("HTTP_AUTHORIZATION", "").strip()
+ else "None"
+ ),
+ "has_internal_service": hasattr(request, "internal_service"),
+ "internal_service_value": getattr(request, "internal_service", None),
+ "authenticated_via": getattr(request, "authenticated_via", None),
+ "organization_id": getattr(request, "organization_id", None),
+ "internal_api_key_configured": bool(
+ getattr(settings, "INTERNAL_SERVICE_API_KEY", None)
+ ),
+ }
+ }
+ )
+
+
+# Internal API URL patterns - OSS Base
+urlpatterns = [
+ # Internal API root and utilities
+ path("", internal_api_root, name="internal_api_root"),
+ path("debug/", test_middleware_debug, name="test_middleware_debug"),
+ path("v1/health/", internal_health_check, name="internal_health"),
+ # WebSocket emission endpoint for workers
+ path("emit-websocket/", emit_websocket, name="emit_websocket"),
+ # ========================================
+ # CORE OSS INTERNAL API MODULES
+ # ========================================
+ # Workflow execution management APIs
+ path(
+ "v1/workflow-execution/",
+ include("workflow_manager.workflow_execution_internal_urls"),
+ name="workflow_execution_internal",
+ ),
+ # Workflow management and pipeline APIs
+ path(
+ "v1/workflow-manager/",
+ include("workflow_manager.internal_urls"),
+ name="workflow_manager_internal",
+ ),
+ # Pipeline APIs
+ path(
+ "v1/pipeline/",
+ include("pipeline_v2.internal_urls"),
+ name="pipeline_internal",
+ ),
+ # Organization context and management APIs
+ path(
+ "v1/organization/",
+ include("account_v2.organization_internal_urls"),
+ name="organization_internal",
+ ),
+ # File execution and batch processing APIs
+ path(
+ "v1/file-execution/",
+ include("workflow_manager.file_execution.internal_urls"),
+ name="file_execution_internal",
+ ),
+ # Tool instance execution APIs
+ path(
+ "v1/tool-execution/",
+ include("tool_instance_v2.internal_urls"),
+ name="tool_execution_internal",
+ ),
+ # File processing history and caching APIs
+ path(
+ "v1/file-history/",
+ include("workflow_manager.workflow_v2.file_history_internal_urls"),
+ name="file_history_internal",
+ ),
+ # Webhook notification APIs
+ path(
+ "v1/webhook/",
+ include("notification_v2.internal_urls"),
+ name="webhook_internal",
+ ),
+ # API deployment data APIs for type-aware worker optimization
+ path(
+ "v1/api-deployments/",
+ include("api_v2.internal_urls"),
+ name="api_deployments_internal",
+ ),
+ # Platform configuration and settings APIs
+ path(
+ "v1/platform-settings/",
+ include("platform_settings_v2.internal_urls"),
+ name="platform_settings_internal",
+ ),
+ # Execution log management and cache operations APIs
+ path(
+ "v1/execution-logs/",
+ include("workflow_manager.workflow_v2.execution_log_internal_urls"),
+ name="execution_logs_internal",
+ ),
+ # Organization configuration management APIs
+ path(
+ "v1/configuration/",
+ include("configuration.internal_urls"),
+ name="configuration_internal",
+ ),
+ # Usage data and token count APIs
+ path(
+ "v1/usage/",
+ include("usage_v2.internal_urls"),
+ name="usage_internal",
+ ),
+]
diff --git a/backend/backend/settings/base.py b/backend/backend/settings/base.py
index cb18de0ca..307c61ee1 100644
--- a/backend/backend/settings/base.py
+++ b/backend/backend/settings/base.py
@@ -562,7 +562,6 @@ SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = {
}
SOCIAL_AUTH_GOOGLE_OAUTH2_USE_UNIQUE_USER_ID = True
-
# Always keep this line at the bottom of the file.
if missing_settings:
ERROR_MESSAGE = "Below required settings are missing.\n" + ",\n".join(
diff --git a/backend/backend/urls.py b/backend/backend/urls.py
index 5241649ec..1dd4a6a69 100644
--- a/backend/backend/urls.py
+++ b/backend/backend/urls.py
@@ -61,4 +61,5 @@ urlpatterns = [
include("prompt_studio.prompt_studio_index_manager.urls"),
),
path("notifications/", include("notification.urls")),
+ path("internal/", include("backend.internal_base_urls")),
]
diff --git a/backend/configuration/internal_urls.py b/backend/configuration/internal_urls.py
new file mode 100644
index 000000000..273705c66
--- /dev/null
+++ b/backend/configuration/internal_urls.py
@@ -0,0 +1,15 @@
+"""Internal API URLs for Configuration access by workers."""
+
+from django.urls import path
+
+from . import internal_views
+
+app_name = "configuration_internal"
+
+urlpatterns = [
+ path(
+ "<str:config_key>/",
+ internal_views.ConfigurationInternalView.as_view(),
+ name="configuration-detail",
+ ),
+]
diff --git a/backend/configuration/internal_views.py b/backend/configuration/internal_views.py
new file mode 100644
index 000000000..55dfa2be3
--- /dev/null
+++ b/backend/configuration/internal_views.py
@@ -0,0 +1,122 @@
+"""Internal API views for Configuration access by workers."""
+
+import logging
+
+from account_v2.models import Organization
+from django.http import JsonResponse
+from rest_framework import status
+from rest_framework.request import Request
+from rest_framework.views import APIView
+
+from .models import Configuration
+
+logger = logging.getLogger(__name__)
+
+
+class ConfigurationInternalView(APIView):
+ """Internal API view for workers to access organization configurations.
+
+ This endpoint allows workers to get organization-specific configuration
+ values without direct database access, maintaining the same logic as
+ Configuration.get_value_by_organization() but over HTTP.
+
+ Workers can call this to get configs like MAX_PARALLEL_FILE_BATCHES
+ with proper organization-specific overrides and fallbacks.
+ """
+
+ def get(self, request: Request, config_key: str) -> JsonResponse:
+ """Get configuration value for an organization.
+
+ Args:
+ request: HTTP request with organization_id parameter
+ config_key: Configuration key name (e.g., "MAX_PARALLEL_FILE_BATCHES")
+
+ Returns:
+ JSON response with configuration value and metadata
+ """
+ try:
+ organization_id = request.query_params.get("organization_id")
+
+ if not organization_id:
+ return JsonResponse(
+ {
+ "success": False,
+ "error": "organization_id parameter is required",
+ "config_key": config_key,
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get the organization - handle both ID (int) and organization_id (string)
+ try:
+ # Try to get organization by primary key ID first (for backward compatibility)
+ if organization_id.isdigit():
+ organization = Organization.objects.get(id=int(organization_id))
+ else:
+ # Otherwise, lookup by organization_id field (string identifier)
+ organization = Organization.objects.get(
+ organization_id=organization_id
+ )
+ except (Organization.DoesNotExist, ValueError):
+ return JsonResponse(
+ {
+ "success": False,
+ "error": f"Organization {organization_id} not found",
+ "config_key": config_key,
+ },
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get the configuration value using the same logic as the backend
+ try:
+ config_value = Configuration.get_value_by_organization(
+ config_key=config_key, organization=organization
+ )
+
+ # Check if we found an organization-specific override
+ has_override = False
+ try:
+ Configuration.objects.get(
+ organization=organization, key=config_key, enabled=True
+ )
+ has_override = True
+ except Configuration.DoesNotExist:
+ has_override = False
+
+ return JsonResponse(
+ {
+ "success": True,
+ "data": {
+ "config_key": config_key,
+ "value": config_value,
+ "organization_id": organization_id,
+ "has_organization_override": has_override,
+ },
+ }
+ )
+
+ except ValueError as e:
+ # Configuration key not found in registry
+ return JsonResponse(
+ {
+ "success": False,
+ "error": str(e),
+ "config_key": config_key,
+ "organization_id": organization_id,
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Error getting configuration {config_key} for organization {organization_id}: {e}",
+ exc_info=True,
+ )
+ return JsonResponse(
+ {
+ "success": False,
+ "error": "Internal server error",
+ "config_key": config_key,
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/connector_v2/migrations/0003_migrate_to_centralized_connectors.py b/backend/connector_v2/migrations/0003_migrate_to_centralized_connectors.py
index af11c120d..73dd12f04 100644
--- a/backend/connector_v2/migrations/0003_migrate_to_centralized_connectors.py
+++ b/backend/connector_v2/migrations/0003_migrate_to_centralized_connectors.py
@@ -42,10 +42,22 @@ def _group_connectors(
) -> dict[tuple[Any, str, str | None], list[Any]]:
"""Group connectors by organization, connector type, and metadata hash."""
connector_groups = {}
+ skipped_connectors = 0
for connector in connector_instances:
try:
- metadata_hash = _compute_metadata_hash(connector.connector_metadata)
+ # Try to access connector_metadata - this may fail due to encryption key mismatch
+ try:
+ metadata_hash = _compute_metadata_hash(connector.connector_metadata)
+ except Exception as decrypt_error:
+ # Log the encryption error and skip this connector
+ logger.warning(
+ f"Skipping connector {connector.id} due to encryption error: {str(decrypt_error)}. "
+ f"This is likely due to a changed ENCRYPTION_KEY."
+ )
+ skipped_connectors += 1
+ continue
+
connector_sys_name = _extract_connector_sys_name(connector.connector_id)
group_key = (
@@ -62,6 +74,11 @@ def _group_connectors(
logger.error(f"Error processing connector {connector.id}: {str(e)}")
raise
+ if skipped_connectors > 0:
+ logger.warning(
+ f"Skipped {skipped_connectors} connectors due to encryption key issues"
+ )
+
return connector_groups
@@ -70,9 +87,16 @@ def _process_single_connector(
processed_groups: int,
total_groups: int,
short_group_key: tuple[Any, str, str],
+ connector_instance_model: Any,
) -> None:
"""Process a group with only one connector."""
- connector.connector_name = f"{connector.connector_name}-{uuid.uuid4().hex[:8]}"
+ base_name = connector.connector_name
+ new_name = f"{base_name}-{uuid.uuid4().hex[:8]}"
+
+ # For performance with large datasets, UUID collisions are extremely rare
+ # If uniqueness becomes critical, we can add collision detection later
+
+ connector.connector_name = new_name
logger.info(
f"[Group {processed_groups}/{total_groups}] {short_group_key}: "
f"Only 1 connector present, renaming to '{connector.connector_name}'"
@@ -85,6 +109,7 @@ def _centralize_connector_group(
processed_groups: int,
total_groups: int,
short_group_key: tuple[Any, str, str],
+ connector_instance_model: Any,
) -> tuple[Any, dict[Any, Any], set[Any]]:
"""Centralize a group of multiple connectors."""
logger.info(
@@ -95,7 +120,12 @@ def _centralize_connector_group(
# First connector becomes the centralized one
centralized_connector = connectors[0]
original_name = centralized_connector.connector_name
- centralized_connector.connector_name = f"{original_name}-{uuid.uuid4().hex[:8]}"
+ new_name = f"{original_name}-{uuid.uuid4().hex[:8]}"
+
+ # For performance with large datasets, UUID collisions are extremely rare
+ # If uniqueness becomes critical, we can add collision detection later
+
+ centralized_connector.connector_name = new_name
logger.info(
f"[Group {processed_groups}/{total_groups}] {short_group_key}: "
@@ -164,6 +194,88 @@ def _delete_redundant_connectors(
raise
+def _fix_remaining_duplicate_names(connector_instance_model: Any) -> int:
+ """Fix any remaining duplicate connector names within organizations."""
+ from django.db.models import Count
+
+ # Find all organizations with duplicate connector names (optimized query)
+ duplicates = list(
+ connector_instance_model.objects.values("connector_name", "organization_id")
+ .annotate(count=Count("id"))
+ .filter(count__gt=1)
+ .order_by("organization_id", "connector_name")
+ )
+
+ total_duplicates = len(duplicates)
+ if total_duplicates == 0:
+ logger.info("No duplicate connector names found after migration")
+ return 0
+
+ logger.info(
+ f"Found {total_duplicates} groups with duplicate connector names - fixing"
+ )
+ fixed_count = 0
+
+ # Process in batches to avoid memory issues
+ batch_size = 20
+ for i in range(0, len(duplicates), batch_size):
+ batch = duplicates[i : i + batch_size]
+ logger.info(
+ f"Processing batch {i//batch_size + 1}/{(len(duplicates)-1)//batch_size + 1}"
+ )
+
+ for dup_info in batch:
+ connector_name = dup_info["connector_name"]
+ org_id = dup_info["organization_id"]
+
+ # Get all connectors with this name in this organization (select only needed fields)
+ duplicate_connectors = list(
+ connector_instance_model.objects.filter(
+ connector_name=connector_name, organization_id=org_id
+ )
+ .only("id", "connector_name", "organization_id")
+ .order_by("id")
+ )
+
+ if len(duplicate_connectors) <= 1:
+ continue # Skip if no longer duplicates
+
+ # Prepare batch updates (keep first, rename others)
+ updates = []
+ existing_names_in_org = set(
+ connector_instance_model.objects.filter(
+ organization_id=org_id
+ ).values_list("connector_name", flat=True)
+ )
+
+ for j, connector in enumerate(duplicate_connectors[1:], 1): # Skip first
+ base_name = connector_name
+ new_name = f"{base_name}-{uuid.uuid4().hex[:8]}"
+
+ # Simple collision check against existing names in this org
+ attempt = 0
+ while new_name in existing_names_in_org and attempt < 5:
+ new_name = f"{base_name}-{uuid.uuid4().hex[:8]}"
+ attempt += 1
+
+ existing_names_in_org.add(new_name) # Track new names
+ connector.connector_name = new_name
+ updates.append(connector)
+ fixed_count += 1
+
+ # Bulk update for better performance
+ if updates:
+ connector_instance_model.objects.bulk_update(
+ updates, ["connector_name"], batch_size=100
+ )
+ logger.info(
+ f" Fixed {len(updates)} duplicates of '{connector_name}' in org {org_id}"
+ )
+
+ logger.info(f"Fixed {fixed_count} duplicate connector names")
+ return fixed_count
+
+
def migrate_to_centralized_connectors(apps, schema_editor): # noqa: ARG001
"""Migrate existing workflow-specific connectors to centralized connectors.
@@ -176,10 +288,15 @@ def migrate_to_centralized_connectors(apps, schema_editor): # noqa: ARG001
ConnectorInstance = apps.get_model("connector_v2", "ConnectorInstance") # NOSONAR
WorkflowEndpoint = apps.get_model("endpoint_v2", "WorkflowEndpoint") # NOSONAR
- # Get all connector instances with select_related for performance
- connector_instances = ConnectorInstance.objects.select_related(
- "organization", "created_by", "modified_by"
- ).all()
+ # Get all connector instances, but defer the encrypted metadata field to avoid
+ # automatic decryption failures when the encryption key has changed
+ connector_instances = (
+ ConnectorInstance.objects.select_related(
+ "organization", "created_by", "modified_by"
+ )
+ .defer("connector_metadata")
+ .all()
+ )
total_connectors = connector_instances.count()
logger.info(f"Processing {total_connectors} connector instances for centralization")
@@ -187,6 +304,17 @@ def migrate_to_centralized_connectors(apps, schema_editor): # noqa: ARG001
# Group connectors by organization and unique credential fingerprint
connector_groups = _group_connectors(connector_instances)
+ # Safety check: If we have connectors but all were skipped, this indicates a serious issue
+ if total_connectors > 0 and len(connector_groups) == 0:
+ error_msg = (
+ f"CRITICAL: All {total_connectors} connectors were skipped due to encryption errors. "
+ f"This likely means the ENCRYPTION_KEY has changed. Please restore the correct "
+ f"ENCRYPTION_KEY and retry the migration. The migration has been aborted to prevent "
+ f"data loss."
+ )
+ logger.error(error_msg)
+ raise RuntimeError(error_msg)
+
# Process each group and centralize connectors
processed_groups = 0
centralized_count = 0
@@ -202,13 +330,21 @@ def migrate_to_centralized_connectors(apps, schema_editor): # noqa: ARG001
# Process single connector groups differently
if len(connectors) == 1:
_process_single_connector(
- connectors[0], processed_groups, total_groups, short_group_key
+ connectors[0],
+ processed_groups,
+ total_groups,
+ short_group_key,
+ ConnectorInstance,
)
continue
# Centralize multiple connectors
_, connector_mapping, connectors_to_delete = _centralize_connector_group(
- connectors, processed_groups, total_groups, short_group_key
+ connectors,
+ processed_groups,
+ total_groups,
+ short_group_key,
+ ConnectorInstance,
)
centralized_count += 1
@@ -232,6 +368,9 @@ def migrate_to_centralized_connectors(apps, schema_editor): # noqa: ARG001
# Delete redundant connectors
_delete_redundant_connectors(all_connectors_to_delete, ConnectorInstance)
+ # Final cleanup: Fix any remaining duplicate names within organizations
+ _fix_remaining_duplicate_names(ConnectorInstance)
+
logger.info(
f"Migration completed: {centralized_count} centralized connectors created"
)
@@ -273,19 +412,28 @@ def _create_workflow_specific_connector(
connector_instance_model: Any,
) -> Any:
"""Create a new workflow-specific connector from a centralized one."""
- return connector_instance_model.objects.create(
- connector_name=centralized_connector.connector_name,
- connector_id=centralized_connector.connector_id,
- connector_metadata=centralized_connector.connector_metadata,
- connector_version=centralized_connector.connector_version,
- connector_type=connector_type,
- connector_auth=centralized_connector.connector_auth,
- connector_mode=centralized_connector.connector_mode,
- workflow=workflow,
- organization=centralized_connector.organization,
- created_by=centralized_connector.created_by,
- modified_by=centralized_connector.modified_by,
- )
+ try:
+ # Try to access connector_metadata to ensure it's readable
+ metadata = centralized_connector.connector_metadata
+ return connector_instance_model.objects.create(
+ connector_name=centralized_connector.connector_name,
+ connector_id=centralized_connector.connector_id,
+ connector_metadata=metadata,
+ connector_version=centralized_connector.connector_version,
+ connector_type=connector_type,
+ connector_auth=centralized_connector.connector_auth,
+ connector_mode=centralized_connector.connector_mode,
+ workflow=workflow,
+ organization=centralized_connector.organization,
+ created_by=centralized_connector.created_by,
+ modified_by=centralized_connector.modified_by,
+ )
+ except Exception as e:
+ logger.warning(
+ f"Skipping creation of workflow-specific connector from {centralized_connector.id} "
+ f"due to encryption error: {str(e)}"
+ )
+ raise
def _process_connector_endpoints(
@@ -359,10 +507,13 @@ def reverse_centralized_connectors(apps, schema_editor): # noqa: ARG001
ConnectorInstance = apps.get_model("connector_v2", "ConnectorInstance") # NOSONAR
WorkflowEndpoint = apps.get_model("endpoint_v2", "WorkflowEndpoint") # NOSONAR
- # Get all centralized connectors with prefetch for better performance
- centralized_connectors = ConnectorInstance.objects.prefetch_related(
- "workflow_endpoints"
- ).all()
+ # Get all centralized connectors, but defer the encrypted metadata field to avoid
+ # automatic decryption failures when the encryption key has changed
+ centralized_connectors = (
+ ConnectorInstance.objects.prefetch_related("workflow_endpoints")
+ .defer("connector_metadata")
+ .all()
+ )
total_connectors = centralized_connectors.count()
logger.info(f"Processing {total_connectors} centralized connectors for reversal")
@@ -375,6 +526,7 @@ def reverse_centralized_connectors(apps, schema_editor): # noqa: ARG001
# Process connectors with endpoints to create workflow-specific copies
added_connector_count = 0
processed_connectors = 0
+ skipped_reverse_connectors = 0
for centralized_connector in centralized_connectors:
processed_connectors += 1
@@ -384,6 +536,17 @@ def reverse_centralized_connectors(apps, schema_editor): # noqa: ARG001
continue
try:
+ # Test if we can access encrypted fields before processing
+ try:
+ _ = centralized_connector.connector_metadata
+ except Exception as decrypt_error:
+ logger.warning(
+ f"Skipping reverse migration for connector {centralized_connector.id} "
+ f"due to encryption error: {str(decrypt_error)}"
+ )
+ skipped_reverse_connectors += 1
+ continue
+
endpoints = WorkflowEndpoint.objects.filter(
connector_instance=centralized_connector
)
@@ -404,6 +567,22 @@ def reverse_centralized_connectors(apps, schema_editor): # noqa: ARG001
)
raise
+ if skipped_reverse_connectors > 0:
+ logger.warning(
+ f"Skipped {skipped_reverse_connectors} connectors during reverse migration due to encryption issues"
+ )
+
+ # Safety check for reverse migration: if we skipped everything, abort
+ if skipped_reverse_connectors == total_connectors and total_connectors > 0:
+ error_msg = (
+ f"CRITICAL: All {total_connectors} connectors were skipped during reverse migration "
+ f"due to encryption errors. This likely means the ENCRYPTION_KEY has changed. "
+ f"Please restore the correct ENCRYPTION_KEY and retry the reverse migration. "
+ f"The reverse migration has been aborted to prevent data loss."
+ )
+ logger.error(error_msg)
+ raise RuntimeError(error_msg)
+
# Delete unused centralized connectors
_delete_unused_centralized_connectors(unused_connectors, ConnectorInstance)
diff --git a/backend/middleware/internal_api_auth.py b/backend/middleware/internal_api_auth.py
new file mode 100644
index 000000000..a34b62a47
--- /dev/null
+++ b/backend/middleware/internal_api_auth.py
@@ -0,0 +1,241 @@
+"""Internal API Service Authentication Middleware
+Handles service-to-service authentication for internal APIs.
+"""
+
+import logging
+from typing import Any
+
+from django.conf import settings
+from django.http import HttpRequest, HttpResponse, JsonResponse
+from django.utils.deprecation import MiddlewareMixin
+from utils.constants import Account
+from utils.local_context import StateStore
+
+logger = logging.getLogger(__name__)
+
+
+class InternalAPIAuthMiddleware(MiddlewareMixin):
+ """Middleware for authenticating internal service API requests.
+
+ This middleware:
+ 1. Checks for internal service API key in Authorization header
+ 2. Validates the key against INTERNAL_SERVICE_API_KEY setting
+ 3. Sets up organization context for requests
+ 4. Bypasses normal user authentication for internal services
+ """
+
+ def process_request(self, request: HttpRequest) -> HttpResponse | None:
+ """Enhanced request processing with improved debugging and organization context handling."""
+ # Enhanced request logging with more context
+ request_info = {
+ "path": request.path,
+ "method": request.method,
+ "content_type": request.META.get("CONTENT_TYPE", "unknown"),
+ "user_agent": request.META.get("HTTP_USER_AGENT", "unknown")[:100],
+ "remote_addr": request.META.get("REMOTE_ADDR", "unknown"),
+ "auth_header_present": bool(request.META.get("HTTP_AUTHORIZATION")),
+ "org_header_present": bool(request.headers.get("X-Organization-ID")),
+ }
+
+ logger.debug(f"InternalAPIAuthMiddleware processing request: {request_info}")
+
+ # Only apply to internal API endpoints
+ if not request.path.startswith("/internal/"):
+ logger.debug(f"Skipping middleware for non-internal path: {request.path}")
+ return None
+
+ logger.info(f"Processing internal API request: {request.method} {request.path}")
+
+ # Enhanced authentication handling
+ auth_result = self._authenticate_request(request)
+ if auth_result["error"]:
+ logger.warning(
+ f"Authentication failed for {request.path}: {auth_result['message']}"
+ )
+ return JsonResponse(
+ {
+ "error": auth_result["message"],
+ "detail": auth_result["detail"],
+ "debug_info": auth_result.get("debug_info", {})
+ if settings.DEBUG
+ else {},
+ },
+ status=auth_result["status"],
+ )
+
+ # Enhanced organization context handling
+ org_result = self._setup_organization_context(request)
+ if org_result["warning"]:
+ logger.warning(
+ f"Organization context issue for {request.path}: {org_result['warning']}"
+ )
+
+ # Mark request as authenticated
+ request.internal_service = True
+ request.authenticated_via = "internal_service_api_key"
+
+ # Enhanced organization context logging
+ final_context = {
+ "path": request.path,
+ "request_org_id": getattr(request, "organization_id", "None"),
+ "statestore_org_id": StateStore.get(Account.ORGANIZATION_ID),
+ "org_context_set": org_result["context_set"],
+ "org_validated": org_result.get("organization_validated", False),
+ }
+ logger.info(f"Internal API request authenticated successfully: {final_context}")
+ return None # Continue with request processing
+
+ def _authenticate_request(self, request: HttpRequest) -> dict[str, Any]:
+ """Enhanced authentication with detailed error reporting."""
+ auth_header = request.META.get("HTTP_AUTHORIZATION", "")
+
+ if not auth_header:
+ return {
+ "error": True,
+ "status": 401,
+ "message": "Authorization header required for internal APIs",
+ "detail": "Missing Authorization header",
+ "debug_info": {
+ "headers_present": list(request.META.keys()),
+ "expected_format": "Authorization: Bearer <api_key>",
+ },
+ }
+
+ if not auth_header.startswith("Bearer "):
+ return {
+ "error": True,
+ "status": 401,
+ "message": "Bearer token required for internal APIs",
+ "detail": f"Invalid authorization format: {auth_header[:20]}...",
+ "debug_info": {
+ "provided_format": auth_header.split(" ")[0]
+ if " " in auth_header
+ else auth_header[:10],
+ "expected_format": "Bearer <api_key>",
+ },
+ }
+
+ # Extract and validate API key
+ api_key = auth_header[7:] # Remove 'Bearer ' prefix
+ internal_api_key = getattr(settings, "INTERNAL_SERVICE_API_KEY", None)
+
+ if not internal_api_key:
+ logger.error("INTERNAL_SERVICE_API_KEY not configured in Django settings")
+ return {
+ "error": True,
+ "status": 500,
+ "message": "Internal API authentication not configured",
+ "detail": "INTERNAL_SERVICE_API_KEY setting missing",
+ }
+
+ if api_key != internal_api_key:
+ # Enhanced logging for key mismatch debugging
+ key_comparison = {
+ "provided_key_length": len(api_key),
+ "expected_key_length": len(internal_api_key),
+ "keys_match": api_key == internal_api_key,
+ "provided_key_prefix": api_key[:8] + "..."
+ if len(api_key) > 8
+ else api_key,
+ "expected_key_prefix": internal_api_key[:8] + "..."
+ if len(internal_api_key) > 8
+ else internal_api_key,
+ }
+ logger.warning(f"API key validation failed: {key_comparison}")
+
+ return {
+ "error": True,
+ "status": 401,
+ "message": "Invalid internal service API key",
+ "detail": "API key does not match configured value",
+ "debug_info": key_comparison if settings.DEBUG else {},
+ }
+
+ return {"error": False, "message": "Authentication successful"}
+
+ def _setup_organization_context(self, request: HttpRequest) -> dict[str, Any]:
+ """Enhanced organization context setup with validation."""
+ org_id = request.headers.get("X-Organization-ID")
+
+ if not org_id:
+ return {
+ "warning": "No organization ID provided in X-Organization-ID header",
+ "context_set": False,
+ }
+
+ try:
+ # Validate organization ID format
+ if not org_id.strip():
+ return {"warning": "Empty organization ID provided", "context_set": False}
+
+ # Enhanced organization context validation
+ from utils.organization_utils import resolve_organization
+
+ try:
+ organization = resolve_organization(org_id, raise_on_not_found=False)
+ if organization:
+ # Use organization.organization_id (string field) for StateStore consistency
+ # This ensures UserContext.get_organization() can properly retrieve the organization
+ request.organization_id = organization.organization_id
+ request.organization_context = {
+ "id": str(organization.id),
+ "organization_id": organization.organization_id,
+ "name": organization.display_name,
+ "validated": True,
+ }
+ # Store the organization_id string field in StateStore for UserContext compatibility
+ StateStore.set(Account.ORGANIZATION_ID, organization.organization_id)
+
+ logger.debug(
+ f"Organization context validated and set: {organization.display_name} (org_id: {organization.organization_id}, pk: {organization.id})"
+ )
+ return {
+ "warning": None,
+ "context_set": True,
+ "organization_validated": True,
+ }
+ else:
+ logger.warning(f"Organization {org_id} not found in database")
+ # Still set the context for backward compatibility
+ request.organization_id = org_id
+ StateStore.set(Account.ORGANIZATION_ID, org_id)
+ return {
+ "warning": f"Organization {org_id} not found in database, using raw value",
+ "context_set": True,
+ "organization_validated": False,
+ }
+
+ except Exception as e:
+ logger.warning(f"Failed to validate organization {org_id}: {str(e)}")
+ # Fallback to raw organization ID
+ request.organization_id = org_id
+ StateStore.set(Account.ORGANIZATION_ID, org_id)
+ return {
+ "warning": f"Organization validation failed: {str(e)}, using raw value",
+ "context_set": True,
+ "organization_validated": False,
+ }
+
+ except Exception as e:
+ logger.error(f"Unexpected error setting organization context: {str(e)}")
+ return {
+ "warning": f"Failed to set organization context: {str(e)}",
+ "context_set": False,
+ }
+
+ def process_response(
+ self, request: HttpRequest, response: HttpResponse
+ ) -> HttpResponse:
+ # Clean up organization context if we set it
+ if hasattr(request, "internal_service") and request.internal_service:
+ try:
+ org_id_before_clear = StateStore.get(Account.ORGANIZATION_ID)
+ if org_id_before_clear is not None:
+ StateStore.clear(Account.ORGANIZATION_ID)
+ logger.debug(
+ f"Cleaned up organization context for {request.path}: {org_id_before_clear}"
+ )
+ except AttributeError:
+ # StateStore key doesn't exist, which is fine
+ logger.debug(f"No organization context to clean up for {request.path}")
+ return response
diff --git a/backend/notification_v2/internal_api_views.py b/backend/notification_v2/internal_api_views.py
new file mode 100644
index 000000000..6843d5a50
--- /dev/null
+++ b/backend/notification_v2/internal_api_views.py
@@ -0,0 +1,252 @@
+"""Internal API views for notification data access by workers.
+
+These endpoints provide notification configuration data to workers
+without exposing full Django models or requiring Django dependencies.
+
+Security Note:
+- CSRF protection is disabled for internal service-to-service communication
+- Authentication is handled by InternalAPIAuthMiddleware using Bearer tokens
+- These endpoints are not accessible from browsers and don't use session cookies
+"""
+
+import logging
+
+from api_v2.models import APIDeployment
+from django.http import JsonResponse
+from django.shortcuts import get_object_or_404
+from django.views.decorators.csrf import csrf_exempt
+from django.views.decorators.http import require_http_methods
+from pipeline_v2.models import Pipeline
+from utils.organization_utils import filter_queryset_by_organization
+
+from notification_v2.models import Notification
+
+logger = logging.getLogger(__name__)
+
+# Constants for error messages
+INTERNAL_SERVER_ERROR_MSG = "Internal server error"
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, service-to-service only
+@require_http_methods(["GET"])
+def get_pipeline_notifications(request, pipeline_id):
+ """Get active notifications for a pipeline or API deployment.
+
+ Used by callback worker to fetch notification configuration.
+ """
+ try:
+ # Try to find the pipeline ID in Pipeline model first
+ pipeline_queryset = Pipeline.objects.filter(id=pipeline_id)
+ pipeline_queryset = filter_queryset_by_organization(
+ pipeline_queryset, request, "organization"
+ )
+
+ if pipeline_queryset.exists():
+ pipeline = pipeline_queryset.first()
+
+ # Get active notifications for this pipeline
+ notifications = Notification.objects.filter(pipeline=pipeline, is_active=True)
+
+ notifications_data = []
+ for notification in notifications:
+ notifications_data.append(
+ {
+ "id": str(notification.id),
+ "notification_type": notification.notification_type,
+ "platform": notification.platform,
+ "url": notification.url,
+ "authorization_type": notification.authorization_type,
+ "authorization_key": notification.authorization_key,
+ "authorization_header": notification.authorization_header,
+ "max_retries": notification.max_retries,
+ "is_active": notification.is_active,
+ }
+ )
+
+ return JsonResponse(
+ {
+ "status": "success",
+ "pipeline_id": str(pipeline.id),
+ "pipeline_name": pipeline.pipeline_name,
+ "pipeline_type": pipeline.pipeline_type,
+ "notifications": notifications_data,
+ }
+ )
+ else:
+ # If not found in Pipeline, try APIDeployment model
+ api_queryset = APIDeployment.objects.filter(id=pipeline_id)
+ api_queryset = filter_queryset_by_organization(
+ api_queryset, request, "organization"
+ )
+
+ if api_queryset.exists():
+ api = api_queryset.first()
+
+ # Get active notifications for this API deployment
+ notifications = Notification.objects.filter(api=api, is_active=True)
+
+ notifications_data = []
+ for notification in notifications:
+ notifications_data.append(
+ {
+ "id": str(notification.id),
+ "notification_type": notification.notification_type,
+ "platform": notification.platform,
+ "url": notification.url,
+ "authorization_type": notification.authorization_type,
+ "authorization_key": notification.authorization_key,
+ "authorization_header": notification.authorization_header,
+ "max_retries": notification.max_retries,
+ "is_active": notification.is_active,
+ }
+ )
+
+ return JsonResponse(
+ {
+ "status": "success",
+ "pipeline_id": str(api.id),
+ "pipeline_name": api.api_name,
+ "pipeline_type": "API",
+ "notifications": notifications_data,
+ }
+ )
+ else:
+ return JsonResponse(
+ {
+ "status": "error",
+ "message": "Pipeline or API deployment not found",
+ },
+ status=404,
+ )
+ except Exception as e:
+ logger.error(f"Error getting pipeline notifications for {pipeline_id}: {e}")
+ return JsonResponse(
+ {"status": "error", "message": INTERNAL_SERVER_ERROR_MSG}, status=500
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, service-to-service only
+@require_http_methods(["GET"])
+def get_api_notifications(request, api_id):
+ """Get active notifications for an API deployment.
+
+ Used by callback worker to fetch notification configuration.
+ """
+ try:
+ # Get API deployment with organization filtering
+ api_queryset = APIDeployment.objects.filter(id=api_id)
+ api_queryset = filter_queryset_by_organization(
+ api_queryset, request, "organization"
+ )
+ api = get_object_or_404(api_queryset)
+
+ # Get active notifications for this API
+ notifications = Notification.objects.filter(api=api, is_active=True)
+
+ notifications_data = []
+ for notification in notifications:
+ notifications_data.append(
+ {
+ "id": str(notification.id),
+ "notification_type": notification.notification_type,
+ "platform": notification.platform,
+ "url": notification.url,
+ "authorization_type": notification.authorization_type,
+ "authorization_key": notification.authorization_key,
+ "authorization_header": notification.authorization_header,
+ "max_retries": notification.max_retries,
+ "is_active": notification.is_active,
+ }
+ )
+
+ return JsonResponse(
+ {
+ "status": "success",
+ "api_id": str(api.id),
+ "api_name": api.api_name,
+ "display_name": api.display_name,
+ "notifications": notifications_data,
+ }
+ )
+
+ except APIDeployment.DoesNotExist:
+ return JsonResponse(
+ {"status": "error", "message": "API deployment not found"}, status=404
+ )
+ except Exception as e:
+ logger.error(f"Error getting API notifications for {api_id}: {e}")
+ return JsonResponse(
+ {"status": "error", "message": INTERNAL_SERVER_ERROR_MSG}, status=500
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, service-to-service only
+@require_http_methods(["GET"])
+def get_pipeline_data(request, pipeline_id):
+ """Get basic pipeline data for notification purposes.
+
+ Used by callback worker to determine pipeline type and name.
+ """
+ try:
+ # Get pipeline with organization filtering
+ pipeline_queryset = Pipeline.objects.filter(id=pipeline_id)
+ pipeline_queryset = filter_queryset_by_organization(
+ pipeline_queryset, request, "organization"
+ )
+ pipeline = get_object_or_404(pipeline_queryset)
+
+ return JsonResponse(
+ {
+ "status": "success",
+ "pipeline_id": str(pipeline.id),
+ "pipeline_name": pipeline.pipeline_name,
+ "pipeline_type": pipeline.pipeline_type,
+ "last_run_status": pipeline.last_run_status,
+ }
+ )
+
+ except Pipeline.DoesNotExist:
+ return JsonResponse(
+ {"status": "error", "message": "Pipeline not found"}, status=404
+ )
+ except Exception as e:
+ logger.error(f"Error getting pipeline data for {pipeline_id}: {e}")
+ return JsonResponse(
+ {"status": "error", "message": INTERNAL_SERVER_ERROR_MSG}, status=500
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, service-to-service only
+@require_http_methods(["GET"])
+def get_api_data(request, api_id):
+ """Get basic API deployment data for notification purposes.
+
+ Used by callback worker to determine API name and details.
+ """
+ try:
+ # Get API deployment with organization filtering
+ api_queryset = APIDeployment.objects.filter(id=api_id)
+ api_queryset = filter_queryset_by_organization(
+ api_queryset, request, "organization"
+ )
+ api = get_object_or_404(api_queryset)
+
+ return JsonResponse(
+ {
+ "status": "success",
+ "api_id": str(api.id),
+ "api_name": api.api_name,
+ "display_name": api.display_name,
+ "is_active": api.is_active,
+ }
+ )
+
+ except APIDeployment.DoesNotExist:
+ return JsonResponse(
+ {"status": "error", "message": "API deployment not found"}, status=404
+ )
+ except Exception as e:
+ logger.error(f"Error getting API data for {api_id}: {e}")
+ return JsonResponse(
+ {"status": "error", "message": INTERNAL_SERVER_ERROR_MSG}, status=500
+ )
diff --git a/backend/notification_v2/internal_serializers.py b/backend/notification_v2/internal_serializers.py
new file mode 100644
index 000000000..94669d64a
--- /dev/null
+++ b/backend/notification_v2/internal_serializers.py
@@ -0,0 +1,128 @@
+"""Internal API Serializers for Notification/Webhook Operations
+Used by Celery workers for service-to-service communication.
+"""
+
+from rest_framework import serializers
+
+from notification_v2.enums import AuthorizationType, NotificationType, PlatformType
+from notification_v2.models import Notification
+
+
+class NotificationSerializer(serializers.ModelSerializer):
+ """Serializer for Notification model."""
+
+ class Meta:
+ model = Notification
+ fields = [
+ "id",
+ "url",
+ "authorization_type",
+ "authorization_key",
+ "authorization_header",
+ "notification_type",
+ "platform",
+ "max_retries",
+ "is_active",
+ "created_at",
+ "modified_at",
+ "pipeline",
+ "api",
+ ]
+
+
+class WebhookNotificationRequestSerializer(serializers.Serializer):
+ """Serializer for webhook notification requests."""
+
+ notification_id = serializers.UUIDField(required=False)
+ url = serializers.URLField(required=True)
+ payload = serializers.JSONField(required=True)
+ authorization_type = serializers.ChoiceField(
+ choices=AuthorizationType.choices(), default=AuthorizationType.NONE.value
+ )
+ authorization_key = serializers.CharField(required=False, allow_blank=True)
+ authorization_header = serializers.CharField(required=False, allow_blank=True)
+ headers = serializers.DictField(required=False, default=dict)
+ timeout = serializers.IntegerField(default=30, min_value=1, max_value=300)
+ max_retries = serializers.IntegerField(default=3, min_value=0, max_value=10)
+ retry_delay = serializers.IntegerField(default=60, min_value=1, max_value=3600)
+
+
+class WebhookNotificationResponseSerializer(serializers.Serializer):
+ """Serializer for webhook notification responses."""
+
+ task_id = serializers.CharField()
+ notification_id = serializers.UUIDField(required=False)
+ url = serializers.URLField()
+ status = serializers.CharField()
+ queued_at = serializers.DateTimeField()
+
+
+class WebhookStatusSerializer(serializers.Serializer):
+ """Serializer for webhook delivery status."""
+
+ task_id = serializers.CharField()
+ status = serializers.CharField()
+ url = serializers.CharField()
+ attempts = serializers.IntegerField()
+ success = serializers.BooleanField()
+ error_message = serializers.CharField(required=False, allow_null=True)
+
+
+class WebhookBatchRequestSerializer(serializers.Serializer):
+ """Serializer for batch webhook requests."""
+
+ batch_name = serializers.CharField(required=False, max_length=255)
+ webhooks = serializers.ListField(
+ child=WebhookNotificationRequestSerializer(), min_length=1, max_length=100
+ )
+ delay_between_requests = serializers.IntegerField(
+ default=0, min_value=0, max_value=60
+ )
+
+
+class WebhookBatchResponseSerializer(serializers.Serializer):
+ """Serializer for batch webhook responses."""
+
+ batch_id = serializers.CharField()
+ batch_name = serializers.CharField()
+ total_webhooks = serializers.IntegerField()
+ queued_webhooks = serializers.ListField(child=WebhookNotificationResponseSerializer())
+ failed_webhooks = serializers.ListField(child=serializers.DictField())
+
+
+class WebhookConfigurationSerializer(serializers.Serializer):
+ """Serializer for webhook configuration."""
+
+ notification_id = serializers.UUIDField()
+ url = serializers.URLField()
+ authorization_type = serializers.ChoiceField(choices=AuthorizationType.choices())
+ authorization_key = serializers.CharField(required=False, allow_blank=True)
+ authorization_header = serializers.CharField(required=False, allow_blank=True)
+ max_retries = serializers.IntegerField()
+ is_active = serializers.BooleanField()
+
+
+class NotificationListSerializer(serializers.Serializer):
+ """Serializer for notification list filters."""
+
+ pipeline_id = serializers.UUIDField(required=False)
+ api_deployment_id = serializers.UUIDField(required=False)
+ notification_type = serializers.ChoiceField(
+ choices=NotificationType.choices(), required=False
+ )
+ platform = serializers.ChoiceField(choices=PlatformType.choices(), required=False)
+ is_active = serializers.BooleanField(required=False)
+
+
+class WebhookTestSerializer(serializers.Serializer):
+ """Serializer for webhook testing."""
+
+ url = serializers.URLField(required=True)
+ payload = serializers.JSONField(required=True)
+ authorization_type = serializers.ChoiceField(
+ choices=AuthorizationType.choices(), default=AuthorizationType.NONE.value
+ )
+ authorization_key = serializers.CharField(required=False, allow_blank=True)
+ authorization_header = serializers.CharField(required=False, allow_blank=True)
+ headers = serializers.DictField(required=False, default=dict)
+ timeout = serializers.IntegerField(default=30, min_value=1, max_value=300)
diff --git a/backend/notification_v2/internal_urls.py b/backend/notification_v2/internal_urls.py
new file mode 100644
index 000000000..041476108
--- /dev/null
+++ b/backend/notification_v2/internal_urls.py
@@ -0,0 +1,56 @@
+"""Internal API URLs for Notification/Webhook Operations
+URL patterns for webhook notification internal APIs.
+"""
+
+from django.urls import include, path
+from rest_framework.routers import DefaultRouter
+
+from . import internal_api_views
+from .internal_views import (
+ WebhookBatchAPIView,
+ WebhookBatchStatusAPIView,
+ WebhookInternalViewSet,
+ WebhookMetricsAPIView,
+ WebhookSendAPIView,
+ WebhookStatusAPIView,
+ WebhookTestAPIView,
+)
+
+# Create router for webhook viewsets
+router = DefaultRouter()
+router.register(r"", WebhookInternalViewSet, basename="webhook-internal")
+
+urlpatterns = [
+ # Notification data endpoints for workers
+ path(
+ "pipeline/<str:pipeline_id>/notifications/",
+ internal_api_views.get_pipeline_notifications,
+ name="get_pipeline_notifications",
+ ),
+ path(
+ "pipeline/<str:pipeline_id>/",
+ internal_api_views.get_pipeline_data,
+ name="get_pipeline_data",
+ ),
+ path(
+ "api/<str:api_id>/notifications/",
+ internal_api_views.get_api_notifications,
+ name="get_api_notifications",
+ ),
+ path(
+ "api/<str:api_id>/",
+ internal_api_views.get_api_data,
+ name="get_api_data",
+ ),
+ # Webhook operation endpoints
+ path("send/", WebhookSendAPIView.as_view(), name="webhook-send"),
+ path("batch/", WebhookBatchAPIView.as_view(), name="webhook-batch"),
+ path("test/", WebhookTestAPIView.as_view(), name="webhook-test"),
+ path("status/<str:task_id>/", WebhookStatusAPIView.as_view(), name="webhook-status"),
+ path(
+ "batch-status/", WebhookBatchStatusAPIView.as_view(), name="webhook-batch-status"
+ ),
+ path("metrics/", WebhookMetricsAPIView.as_view(), name="webhook-metrics"),
+ # Webhook configuration CRUD (via router)
+ path("", include(router.urls)),
+]
diff --git a/backend/notification_v2/internal_views.py b/backend/notification_v2/internal_views.py
new file mode 100644
index 000000000..60b994492
--- /dev/null
+++ b/backend/notification_v2/internal_views.py
@@ -0,0 +1,559 @@
+"""Internal API Views for Webhook Operations
+Handles webhook notification related endpoints for internal services.
+"""
+
+import logging
+import uuid
+from typing import Any
+
+from celery import current_app as celery_app
+from celery.result import AsyncResult
+from django.utils import timezone
+from rest_framework import status, viewsets
+from rest_framework.decorators import action
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from utils.organization_utils import filter_queryset_by_organization
+
+from notification_v2.enums import AuthorizationType, NotificationType, PlatformType
+
+# Import serializers from notification_v2 internal API
+from notification_v2.internal_serializers import (
+ NotificationListSerializer,
+ NotificationSerializer,
+ WebhookBatchRequestSerializer,
+ WebhookBatchResponseSerializer,
+ WebhookConfigurationSerializer,
+ WebhookNotificationRequestSerializer,
+ WebhookNotificationResponseSerializer,
+ WebhookStatusSerializer,
+ WebhookTestSerializer,
+)
+from notification_v2.models import Notification
+from notification_v2.provider.webhook.webhook import send_webhook_notification
+
+logger = logging.getLogger(__name__)
+
+# Constants
+APPLICATION_JSON = "application/json"
+
+
+class WebhookInternalViewSet(viewsets.ReadOnlyModelViewSet):
+ """Internal API ViewSet for Webhook/Notification operations."""
+
+ serializer_class = NotificationSerializer
+ lookup_field = "id"
+
+ def get_queryset(self):
+ """Get notifications filtered by organization context."""
+ queryset = Notification.objects.all()
+ return filter_queryset_by_organization(queryset, self.request)
+
+ def list(self, request, *args, **kwargs):
+ """List notifications with filtering options."""
+ try:
+ serializer = NotificationListSerializer(data=request.query_params)
+ if not serializer.is_valid():
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ filters = serializer.validated_data
+ queryset = self.get_queryset()
+
+ # Apply filters
+ if filters.get("pipeline_id"):
+ queryset = queryset.filter(pipeline_id=filters["pipeline_id"])
+ if filters.get("api_deployment_id"):
+ queryset = queryset.filter(api_id=filters["api_deployment_id"])
+ if filters.get("notification_type"):
+ queryset = queryset.filter(notification_type=filters["notification_type"])
+ if filters.get("platform"):
+ queryset = queryset.filter(platform=filters["platform"])
+ if filters.get("is_active") is not None:
+ queryset = queryset.filter(is_active=filters["is_active"])
+
+ notifications = NotificationSerializer(queryset, many=True).data
+
+ return Response({"count": len(notifications), "notifications": notifications})
+
+ except Exception as e:
+ logger.error(f"Failed to list notifications: {str(e)}")
+ return Response(
+ {"error": "Failed to list notifications", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ @action(detail=True, methods=["get"])
+ def configuration(self, request, id=None):
+ """Get webhook configuration for a notification."""
+ try:
+ notification = self.get_object()
+
+ config_data = {
+ "notification_id": notification.id,
+ "url": notification.url,
+ "authorization_type": notification.authorization_type,
+ "authorization_key": notification.authorization_key,
+ "authorization_header": notification.authorization_header,
+ "max_retries": notification.max_retries,
+ "is_active": notification.is_active,
+ }
+
+ serializer = WebhookConfigurationSerializer(config_data)
+ return Response(serializer.data)
+
+ except Exception as e:
+ logger.error(f"Failed to get webhook configuration {id}: {str(e)}")
+ return Response(
+ {"error": "Failed to get webhook configuration", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WebhookSendAPIView(APIView):
+ """Internal API endpoint for sending webhook notifications."""
+
+ def post(self, request):
+ """Send a webhook notification."""
+ try:
+ serializer = WebhookNotificationRequestSerializer(data=request.data)
+
+ if not serializer.is_valid():
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ validated_data = serializer.validated_data
+
+ # Build headers based on authorization type
+ headers = self._build_headers(validated_data)
+
+ # Send webhook notification task
+ task = send_webhook_notification.delay(
+ url=validated_data["url"],
+ payload=validated_data["payload"],
+ headers=headers,
+ timeout=validated_data["timeout"],
+ max_retries=validated_data["max_retries"],
+ retry_delay=validated_data["retry_delay"],
+ )
+
+ # Prepare response
+ response_data = {
+ "task_id": task.id,
+ "notification_id": validated_data.get("notification_id"),
+ "url": validated_data["url"],
+ "status": "queued",
+ "queued_at": timezone.now(),
+ }
+
+ response_serializer = WebhookNotificationResponseSerializer(response_data)
+
+ logger.info(
+ f"Queued webhook notification task {task.id} for URL {validated_data['url']}"
+ )
+
+ return Response(response_serializer.data, status=status.HTTP_202_ACCEPTED)
+
+ except Exception as e:
+ logger.error(f"Failed to send webhook notification: {str(e)}")
+ return Response(
+ {"error": "Failed to send webhook notification", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _build_headers(self, validated_data: dict[str, Any]) -> dict[str, str]:
+ """Build headers based on authorization configuration."""
+ headers = {"Content-Type": APPLICATION_JSON}
+
+ auth_type = validated_data.get("authorization_type", AuthorizationType.NONE.value)
+ auth_key = validated_data.get("authorization_key")
+ auth_header = validated_data.get("authorization_header")
+
+ if validated_data.get("headers"):
+ headers.update(validated_data["headers"])
+
+ if auth_type == AuthorizationType.BEARER.value and auth_key:
+ headers["Authorization"] = f"Bearer {auth_key}"
+ elif auth_type == AuthorizationType.API_KEY.value and auth_key:
+ headers["Authorization"] = auth_key
+ elif (
+ auth_type == AuthorizationType.CUSTOM_HEADER.value
+ and auth_header
+ and auth_key
+ ):
+ headers[auth_header] = auth_key
+
+ return headers
+
+
+class WebhookStatusAPIView(APIView):
+ """Internal API endpoint for checking webhook delivery status."""
+
+ def get(self, request, task_id):
+ """Get webhook delivery status by task ID."""
+ try:
+ task_result = AsyncResult(task_id, app=celery_app)
+
+ status_data = {
+ "task_id": task_id,
+ "status": task_result.status,
+ "url": "unknown",
+ "attempts": 0,
+ "success": task_result.successful(),
+ "error_message": None,
+ }
+
+ if task_result.failed():
+ status_data["error_message"] = str(task_result.result)
+ elif task_result.successful():
+ status_data["attempts"] = getattr(task_result.result, "attempts", 1)
+
+ serializer = WebhookStatusSerializer(status_data)
+ return Response(serializer.data)
+
+ except Exception as e:
+ logger.error(f"Failed to get webhook status for task {task_id}: {str(e)}")
+ return Response(
+ {"error": "Failed to get webhook status", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WebhookBatchAPIView(APIView):
+ """Internal API endpoint for sending batch webhook notifications."""
+
+ def post(self, request):
+ """Send multiple webhook notifications in batch."""
+ try:
+ serializer = WebhookBatchRequestSerializer(data=request.data)
+
+ if not serializer.is_valid():
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ validated_data = serializer.validated_data
+ webhooks = validated_data["webhooks"]
+ delay_between = validated_data.get("delay_between_requests", 0)
+
+ batch_id = str(uuid.uuid4())
+ queued_webhooks = []
+ failed_webhooks = []
+
+ for i, webhook_data in enumerate(webhooks):
+ try:
+ headers = self._build_headers(webhook_data)
+ countdown = i * delay_between if delay_between > 0 else 0
+
+ task = send_webhook_notification.apply_async(
+ args=[
+ webhook_data["url"],
+ webhook_data["payload"],
+ headers,
+ webhook_data["timeout"],
+ ],
+ kwargs={
+ "max_retries": webhook_data["max_retries"],
+ "retry_delay": webhook_data["retry_delay"],
+ },
+ countdown=countdown,
+ )
+
+ queued_webhooks.append(
+ {
+ "task_id": task.id,
+ "notification_id": webhook_data.get("notification_id"),
+ "url": webhook_data["url"],
+ "status": "queued",
+ "queued_at": timezone.now(),
+ }
+ )
+
+ except Exception as e:
+ failed_webhooks.append({"url": webhook_data["url"], "error": str(e)})
+
+ response_data = {
+ "batch_id": batch_id,
+ "batch_name": validated_data.get("batch_name", f"Batch-{batch_id[:8]}"),
+ "total_webhooks": len(webhooks),
+ "queued_webhooks": queued_webhooks,
+ "failed_webhooks": failed_webhooks,
+ }
+
+ response_serializer = WebhookBatchResponseSerializer(response_data)
+
+ logger.info(
+ f"Queued batch {batch_id} with {len(queued_webhooks)} webhooks, {len(failed_webhooks)} failed"
+ )
+
+ return Response(response_serializer.data, status=status.HTTP_202_ACCEPTED)
+
+ except Exception as e:
+ logger.error(f"Failed to send webhook batch: {str(e)}")
+ return Response(
+ {"error": "Failed to send webhook batch", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _build_headers(self, webhook_data: dict[str, Any]) -> dict[str, str]:
+ """Build headers for webhook request."""
+ headers = {"Content-Type": APPLICATION_JSON}
+
+ auth_type = webhook_data.get("authorization_type", AuthorizationType.NONE.value)
+ auth_key = webhook_data.get("authorization_key")
+ auth_header = webhook_data.get("authorization_header")
+
+ if webhook_data.get("headers"):
+ headers.update(webhook_data["headers"])
+
+ if auth_type == AuthorizationType.BEARER.value and auth_key:
+ headers["Authorization"] = f"Bearer {auth_key}"
+ elif auth_type == AuthorizationType.API_KEY.value and auth_key:
+ headers["Authorization"] = auth_key
+ elif (
+ auth_type == AuthorizationType.CUSTOM_HEADER.value
+ and auth_header
+ and auth_key
+ ):
+ headers[auth_header] = auth_key
+
+ return headers
+
+
+class WebhookTestAPIView(APIView):
+ """Internal API endpoint for testing webhook configurations."""
+
+ def post(self, request):
+ """Test a webhook configuration without queuing."""
+ try:
+ serializer = WebhookTestSerializer(data=request.data)
+
+ if not serializer.is_valid():
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ validated_data = serializer.validated_data
+ headers = self._build_headers(validated_data)
+
+ import requests
+
+ try:
+ response = requests.post(
+ url=validated_data["url"],
+ json=validated_data["payload"],
+ headers=headers,
+ timeout=validated_data["timeout"],
+ )
+
+ test_result = {
+ "success": response.status_code < 400,
+ "status_code": response.status_code,
+ "response_headers": dict(response.headers),
+ "response_body": response.text[:1000],
+ "url": validated_data["url"],
+ "request_headers": headers,
+ "request_payload": validated_data["payload"],
+ }
+
+ logger.info(
+ f"Webhook test to {validated_data['url']} completed with status {response.status_code}"
+ )
+
+ return Response(test_result)
+
+ except requests.exceptions.RequestException as e:
+ test_result = {
+ "success": False,
+ "error": str(e),
+ "url": validated_data["url"],
+ "request_headers": headers,
+ "request_payload": validated_data["payload"],
+ }
+
+ return Response(test_result, status=status.HTTP_400_BAD_REQUEST)
+
+ except Exception as e:
+ logger.error(f"Failed to test webhook: {str(e)}")
+ return Response(
+ {"error": "Failed to test webhook", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _build_headers(self, validated_data: dict[str, Any]) -> dict[str, str]:
+ """Build headers for webhook test."""
+ headers = {"Content-Type": APPLICATION_JSON}
+
+ auth_type = validated_data.get("authorization_type", AuthorizationType.NONE.value)
+ auth_key = validated_data.get("authorization_key")
+ auth_header = validated_data.get("authorization_header")
+
+ if validated_data.get("headers"):
+ headers.update(validated_data["headers"])
+
+ if auth_type == AuthorizationType.BEARER.value and auth_key:
+ headers["Authorization"] = f"Bearer {auth_key}"
+ elif auth_type == AuthorizationType.API_KEY.value and auth_key:
+ headers["Authorization"] = auth_key
+ elif (
+ auth_type == AuthorizationType.CUSTOM_HEADER.value
+ and auth_header
+ and auth_key
+ ):
+ headers[auth_header] = auth_key
+
+ return headers
+
+
+class WebhookBatchStatusAPIView(APIView):
+ """Internal API endpoint for checking batch webhook delivery status."""
+
+ def get(self, request):
+ """Get batch webhook delivery status."""
+ try:
+ batch_id = request.query_params.get("batch_id")
+ task_ids = request.query_params.get("task_ids", "").split(",")
+
+ if not batch_id and not task_ids:
+ return Response(
+ {"error": "Either batch_id or task_ids parameter is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ batch_results = []
+
+ if task_ids and task_ids[0]: # task_ids is not empty
+ for task_id in task_ids:
+ if task_id.strip():
+ try:
+ task_result = AsyncResult(task_id.strip(), app=celery_app)
+
+ batch_results.append(
+ {
+ "task_id": task_id.strip(),
+ "status": task_result.status,
+ "success": task_result.successful(),
+ "error_message": str(task_result.result)
+ if task_result.failed()
+ else None,
+ }
+ )
+ except Exception as e:
+ batch_results.append(
+ {
+ "task_id": task_id.strip(),
+ "status": "ERROR",
+ "success": False,
+ "error_message": f"Failed to get task status: {str(e)}",
+ }
+ )
+
+ response_data = {
+ "batch_id": batch_id,
+ "total_tasks": len(batch_results),
+ "results": batch_results,
+ "summary": {
+ "completed": sum(
+ 1 for r in batch_results if r["status"] == "SUCCESS"
+ ),
+ "failed": sum(1 for r in batch_results if r["status"] == "FAILURE"),
+ "pending": sum(1 for r in batch_results if r["status"] == "PENDING"),
+ "running": sum(1 for r in batch_results if r["status"] == "STARTED"),
+ },
+ }
+
+ return Response(response_data)
+
+ except Exception as e:
+ logger.error(f"Failed to get batch webhook status: {str(e)}")
+ return Response(
+ {"error": "Failed to get batch webhook status", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WebhookMetricsAPIView(APIView):
+ """Internal API endpoint for webhook delivery metrics."""
+
+ def get(self, request):
+ """Get webhook delivery metrics."""
+ try:
+ # Get query parameters
+ organization_id = request.query_params.get("organization_id")
+ start_date = request.query_params.get("start_date")
+ end_date = request.query_params.get("end_date")
+
+ # Get base queryset
+ queryset = Notification.objects.all()
+ queryset = filter_queryset_by_organization(queryset, request)
+
+ # Apply filters
+ if organization_id:
+ queryset = queryset.filter(organization_id=organization_id)
+
+ if start_date:
+ from datetime import datetime
+
+ try:
+ start_dt = datetime.fromisoformat(start_date.replace("Z", "+00:00"))
+ queryset = queryset.filter(created_at__gte=start_dt)
+ except ValueError:
+ return Response(
+ {"error": "Invalid start_date format. Use ISO format."},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ if end_date:
+ from datetime import datetime
+
+ try:
+ end_dt = datetime.fromisoformat(end_date.replace("Z", "+00:00"))
+ queryset = queryset.filter(created_at__lte=end_dt)
+ except ValueError:
+ return Response(
+ {"error": "Invalid end_date format. Use ISO format."},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Calculate metrics
+ total_webhooks = queryset.count()
+ active_webhooks = queryset.filter(is_active=True).count()
+ inactive_webhooks = queryset.filter(is_active=False).count()
+
+ # Group by notification type
+ type_breakdown = {}
+ for notification_type in NotificationType:
+ count = queryset.filter(notification_type=notification_type.value).count()
+ if count > 0:
+ type_breakdown[notification_type.value] = count
+
+ # Group by platform
+ platform_breakdown = {}
+ for platform_type in PlatformType:
+ count = queryset.filter(platform=platform_type.value).count()
+ if count > 0:
+ platform_breakdown[platform_type.value] = count
+
+ # Group by authorization type
+ auth_breakdown = {}
+ for auth_type in AuthorizationType:
+ count = queryset.filter(authorization_type=auth_type.value).count()
+ if count > 0:
+ auth_breakdown[auth_type.value] = count
+
+ metrics = {
+ "total_webhooks": total_webhooks,
+ "active_webhooks": active_webhooks,
+ "inactive_webhooks": inactive_webhooks,
+ "type_breakdown": type_breakdown,
+ "platform_breakdown": platform_breakdown,
+ "authorization_breakdown": auth_breakdown,
+ "filters_applied": {
+ "organization_id": organization_id,
+ "start_date": start_date,
+ "end_date": end_date,
+ },
+ }
+
+ return Response(metrics)
+
+ except Exception as e:
+ logger.error(f"Failed to get webhook metrics: {str(e)}")
+ return Response(
+ {"error": "Failed to get webhook metrics", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/pipeline_v2/internal_api_views.py b/backend/pipeline_v2/internal_api_views.py
new file mode 100644
index 000000000..69375a30a
--- /dev/null
+++ b/backend/pipeline_v2/internal_api_views.py
@@ -0,0 +1,167 @@
+import logging
+
+from api_v2.models import APIDeployment
+from rest_framework.response import Response
+from rest_framework.viewsets import ViewSet
+from utils.organization_utils import filter_queryset_by_organization
+
+from pipeline_v2.models import Pipeline
+
+from .serializers.internal import APIDeploymentSerializer, PipelineSerializer
+
+logger = logging.getLogger(__name__)
+
+
+class PipelineInternalViewSet(ViewSet):
+ def retrieve(self, request, pk=None):
+ logger.info(f"[PipelineInternalViewSet] Retrieving data for ID: {pk}")
+
+ try:
+ # 1️⃣ Try in Pipeline
+ pipeline_data = self._fetch_single_record(
+ pk,
+ request,
+ Pipeline.objects.filter(id=pk),
+ PipelineSerializer,
+ "Pipeline",
+ )
+ if isinstance(pipeline_data, dict): # Found successfully
+ return Response({"status": "success", "pipeline": pipeline_data})
+ elif isinstance(pipeline_data, Response): # Integrity error
+ return pipeline_data
+
+ # 2️⃣ Try in APIDeployment
+ api_data = self._fetch_single_record(
+ pk,
+ request,
+ APIDeployment.objects.filter(id=pk),
+ APIDeploymentSerializer,
+ "APIDeployment",
+ )
+ if isinstance(api_data, dict):
+ return Response({"status": "success", "pipeline": api_data})
+ elif isinstance(api_data, Response):
+ return api_data
+
+ # 3️⃣ Not found anywhere
+ logger.warning(f"⚠️ No Pipeline or APIDeployment found for {pk}")
+ return Response(
+ {"status": "error", "message": "Pipeline not found"}, status=404
+ )
+
+ except Exception:
+ logger.exception(f"💥 Error retrieving pipeline or deployment for {pk}")
+ return Response(
+ {"status": "error", "message": "Internal server error"}, status=500
+ )
+
+ # Helper function for DRY logic
+ def _fetch_single_record(self, pk, request, qs, serializer_cls, model_name):
+ qs = filter_queryset_by_organization(qs, request, "organization")
+ count = qs.count()
+
+ if count == 1:
+ obj = qs.first()
+ logger.info(f"✅ Found {model_name} entry: {obj}")
+ return serializer_cls(obj).data
+ elif count > 1:
+ logger.error(f"❌ Multiple {model_name} entries found for {pk}")
+ return Response(
+ {
+ "status": "error",
+ "message": f"Data integrity error: multiple {model_name} entries found",
+ },
+ status=500,
+ )
+
+ return None # Not found in this model
+
+ def update(self, request, pk=None):
+ """Update pipeline status with support for completion states."""
+ try:
+ new_status = request.data.get("status")
+ if not new_status:
+ return Response(
+ {"status": "error", "message": "Status is required"}, status=400
+ )
+
+ # Extract additional parameters for completion states
+ is_end = request.data.get("is_end", False)
+
+ # Import here to avoid circular imports
+ from pipeline_v2.pipeline_processor import PipelineProcessor
+
+ # Try to update pipeline first
+ try:
+ pipeline_qs = Pipeline.objects.filter(id=pk)
+ pipeline_qs = filter_queryset_by_organization(
+ pipeline_qs, request, "organization"
+ )
+ pipeline = pipeline_qs.first()
+
+ if pipeline:
+ # Use PipelineProcessor.update_pipeline() without execution_id and error_message
+ # This will update status but skip notifications (since execution_id=None)
+ PipelineProcessor.update_pipeline(
+ pipeline_guid=pk,
+ status=new_status,
+ is_end=is_end,
+ )
+
+ return Response(
+ {
+ "status": "success",
+ "pipeline_id": pk,
+ "new_status": new_status,
+ "is_end": is_end,
+ "message": "Pipeline status updated successfully",
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error updating pipeline status: {e}")
+ return Response(
+ {"status": "error", "message": f"Failed to update pipeline: {e}"},
+ status=500,
+ )
+
+ # Try API deployment if pipeline not found
+ try:
+ api_qs = APIDeployment.objects.filter(id=pk)
+ api_qs = filter_queryset_by_organization(api_qs, request, "organization")
+ api_deployment = api_qs.first()
+
+ if api_deployment:
+ # For API deployments, log the status update
+ logger.info(f"Updated API deployment {pk} status to {new_status}")
+
+ return Response(
+ {
+ "status": "success",
+ "pipeline_id": pk,
+ "new_status": new_status,
+ "message": "API deployment status updated successfully",
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error updating API deployment status: {e}")
+ return Response(
+ {
+ "status": "error",
+ "message": f"Failed to update API deployment: {e}",
+ },
+ status=500,
+ )
+
+ # Not found in either model
+ return Response(
+ {"status": "error", "message": "Pipeline or API deployment not found"},
+ status=404,
+ )
+
+ except Exception as e:
+ logger.error(f"Error updating pipeline/API deployment status for {pk}: {e}")
+ return Response(
+ {"status": "error", "message": "Internal server error"}, status=500
+ )
diff --git a/backend/pipeline_v2/internal_urls.py b/backend/pipeline_v2/internal_urls.py
new file mode 100644
index 000000000..2881c71ff
--- /dev/null
+++ b/backend/pipeline_v2/internal_urls.py
@@ -0,0 +1,17 @@
+"""Internal API URLs for Pipeline Operations"""
+
+from django.urls import include, path
+from rest_framework.routers import DefaultRouter
+
+from .internal_api_views import (
+ PipelineInternalViewSet,
+)
+
+# Create router for pipeline viewsets
+router = DefaultRouter()
+router.register(r"", PipelineInternalViewSet, basename="pipeline-internal")
+
+urlpatterns = [
+ # Pipeline internal APIs
+ path("", include(router.urls)),
+]
diff --git a/backend/pipeline_v2/pipeline_processor.py b/backend/pipeline_v2/pipeline_processor.py
index fc7be7d1d..b2967f1aa 100644
--- a/backend/pipeline_v2/pipeline_processor.py
+++ b/backend/pipeline_v2/pipeline_processor.py
@@ -113,7 +113,12 @@ class PipelineProcessor:
pipeline = PipelineProcessor._update_pipeline_status(
pipeline=pipeline, is_end=is_end, status=status, is_active=is_active
)
- PipelineProcessor._send_notification(
- pipeline=pipeline, execution_id=execution_id, error_message=error_message
- )
+
+ # Only send notifications if execution_id is provided
+ # This avoids duplicate notifications when called from workers (who handle notifications separately)
+ if execution_id:
+ PipelineProcessor._send_notification(
+ pipeline=pipeline, execution_id=execution_id, error_message=error_message
+ )
+
logger.info(f"Updated pipeline {pipeline_guid} status: {status}")
diff --git a/backend/pipeline_v2/serializers/internal.py b/backend/pipeline_v2/serializers/internal.py
new file mode 100644
index 000000000..d22cc5e49
--- /dev/null
+++ b/backend/pipeline_v2/serializers/internal.py
@@ -0,0 +1,59 @@
+from api_v2.models import APIDeployment
+from pipeline_v2.models import Pipeline
+from rest_framework import serializers
+
+
+class PipelineSerializer(serializers.ModelSerializer):
+ # Add computed fields for callback worker
+ is_api = serializers.SerializerMethodField()
+ resolved_pipeline_type = serializers.SerializerMethodField()
+ resolved_pipeline_name = serializers.SerializerMethodField()
+ pipeline_name = serializers.SerializerMethodField()
+
+ class Meta:
+ model = Pipeline
+ fields = "__all__"
+
+ def get_is_api(self, obj):
+ """Returns False for Pipeline model entries."""
+ return False
+
+ def get_resolved_pipeline_type(self, obj):
+ """Returns the pipeline type from the Pipeline model."""
+ return obj.pipeline_type
+
+ def get_resolved_pipeline_name(self, obj):
+ """Returns the pipeline name from the Pipeline model."""
+ return obj.pipeline_name
+
+ def get_pipeline_name(self, obj):
+ """Returns the pipeline name for callback worker compatibility."""
+ return obj.pipeline_name
+
+
+class APIDeploymentSerializer(serializers.ModelSerializer):
+ # Add computed fields for callback worker
+ is_api = serializers.SerializerMethodField()
+ resolved_pipeline_type = serializers.SerializerMethodField()
+ resolved_pipeline_name = serializers.SerializerMethodField()
+ pipeline_name = serializers.SerializerMethodField()
+
+ class Meta:
+ model = APIDeployment
+ fields = "__all__"
+
+ def get_is_api(self, obj):
+ """Returns True for APIDeployment model entries."""
+ return True
+
+ def get_resolved_pipeline_type(self, obj):
+ """Returns 'API' for APIDeployment model entries."""
+ return "API"
+
+ def get_resolved_pipeline_name(self, obj):
+ """Returns the api_name from the APIDeployment model."""
+ return obj.api_name
+
+ def get_pipeline_name(self, obj):
+ """Returns the api_name for callback worker compatibility."""
+ return obj.api_name
diff --git a/backend/platform_settings_v2/internal_urls.py b/backend/platform_settings_v2/internal_urls.py
new file mode 100644
index 000000000..a08dd0fec
--- /dev/null
+++ b/backend/platform_settings_v2/internal_urls.py
@@ -0,0 +1,18 @@
+"""Internal URLs for platform settings
+
+Routes for internal API endpoints used by workers.
+"""
+
+from django.urls import path
+
+from .internal_views import InternalPlatformKeyView
+
+app_name = "platform_settings_internal"
+
+urlpatterns = [
+ path(
+ "platform-key/",
+ InternalPlatformKeyView.as_view(),
+ name="platform_key",
+ ),
+]
diff --git a/backend/platform_settings_v2/internal_views.py b/backend/platform_settings_v2/internal_views.py
new file mode 100644
index 000000000..3850f4c54
--- /dev/null
+++ b/backend/platform_settings_v2/internal_views.py
@@ -0,0 +1,76 @@
+"""Internal API views for platform settings
+
+Provides internal endpoints for workers to access platform settings
+without direct database access.
+"""
+
+import logging
+
+from account_v2.models import PlatformKey
+from account_v2.organization import OrganizationService
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from platform_settings_v2.platform_auth_service import PlatformAuthenticationService
+
+logger = logging.getLogger(__name__)
+
+
+class InternalPlatformKeyView(APIView):
+ """Internal API to get active platform key for an organization."""
+
+ def get(self, request):
+ """Get active platform key for organization.
+
+ Uses X-Organization-ID header to identify the organization.
+
+ Args:
+ request: HTTP request with X-Organization-ID header
+
+ Returns:
+ Response with platform key
+ """
+ try:
+ # Get organization ID from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get organization
+ organization = OrganizationService.get_organization_by_org_id(org_id=org_id)
+
+ if not organization:
+ return Response(
+ {"error": f"Organization {org_id} not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get active platform key
+ platform_key = PlatformAuthenticationService.get_active_platform_key(
+ organization_id=org_id
+ )
+
+ return Response(
+ {
+ "platform_key": str(platform_key.key),
+ "key_name": platform_key.key_name,
+ "organization_id": org_id,
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except PlatformKey.DoesNotExist:
+ return Response(
+ {"error": f"No active platform key found for organization {org_id}"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Exception as e:
+ logger.error(f"Error getting platform key for org {org_id}: {str(e)}")
+ return Response(
+ {"error": "Internal server error"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/prompt_studio/modifier_loader.py b/backend/prompt_studio/modifier_loader.py
index ca1cd1eb9..e78d18113 100644
--- a/backend/prompt_studio/modifier_loader.py
+++ b/backend/prompt_studio/modifier_loader.py
@@ -20,8 +20,19 @@ class ModifierConfig:
METADATA_IS_ACTIVE = "is_active"
+# Cache for loaded plugins to avoid repeated loading
+_modifier_plugins_cache: list[Any] = []
+_plugins_loaded = False
+
+
def load_plugins() -> list[Any]:
"""Iterate through the extraction plugins and register them."""
+ global _modifier_plugins_cache, _plugins_loaded
+
+ # Return cached plugins if already loaded
+ if _plugins_loaded:
+ return _modifier_plugins_cache
+
plugins_app = apps.get_app_config(ModifierConfig.PLUGINS_APP)
package_path = plugins_app.module.__package__
modifier_dir = os.path.join(plugins_app.path, ModifierConfig.PLUGIN_DIR)
@@ -29,6 +40,8 @@ def load_plugins() -> list[Any]:
modifier_plugins: list[Any] = []
if not os.path.exists(modifier_dir):
+ _modifier_plugins_cache = modifier_plugins
+ _plugins_loaded = True
return modifier_plugins
for item in os.listdir(modifier_dir):
@@ -69,4 +82,8 @@ def load_plugins() -> list[Any]:
if len(modifier_plugins) == 0:
logger.info("No modifier plugins found.")
+ # Cache the results for future requests
+ _modifier_plugins_cache = modifier_plugins
+ _plugins_loaded = True
+
return modifier_plugins
diff --git a/backend/prompt_studio/processor_loader.py b/backend/prompt_studio/processor_loader.py
index 0bd8a7ddd..8c22dd82e 100644
--- a/backend/prompt_studio/processor_loader.py
+++ b/backend/prompt_studio/processor_loader.py
@@ -20,14 +20,29 @@ class ProcessorConfig:
METADATA_IS_ACTIVE = "is_active"
+# Cache for loaded plugins to avoid repeated loading
+_processor_plugins_cache: list[Any] = []
+_plugins_loaded = False
+
+
def load_plugins() -> list[Any]:
"""Iterate through the processor plugins and register them."""
+ global _processor_plugins_cache, _plugins_loaded
+
+ # Return cached plugins if already loaded
+ if _plugins_loaded:
+ return _processor_plugins_cache
+
plugins_app = apps.get_app_config(ProcessorConfig.PLUGINS_APP)
package_path = plugins_app.module.__package__
processor_dir = os.path.join(plugins_app.path, ProcessorConfig.PLUGIN_DIR)
processor_package_path = f"{package_path}.{ProcessorConfig.PLUGIN_DIR}"
processor_plugins: list[Any] = []
+ if not os.path.exists(processor_dir):
+ logger.info("No processor directory found at %s.", processor_dir)
+ return []
+
for item in os.listdir(processor_dir):
# Loads a plugin if it is in a directory.
if os.path.isdir(os.path.join(processor_dir, item)):
@@ -71,6 +86,10 @@ def load_plugins() -> list[Any]:
if len(processor_plugins) == 0:
logger.info("No processor plugins found.")
+ # Cache the results for future requests
+ _processor_plugins_cache = processor_plugins
+ _plugins_loaded = True
+
return processor_plugins
diff --git a/backend/pyproject.toml b/backend/pyproject.toml
index b74e64e1c..e1741a277 100644
--- a/backend/pyproject.toml
+++ b/backend/pyproject.toml
@@ -72,7 +72,10 @@ dev = [
# For file watching
"inotify>=0.2.10",
"poethepoet>=0.33.1",
- "debugpy>=1.8.14"
+ "debugpy>=1.8.14",
+ "pytest>=8.3.5",
+ "responses>=0.25.7",
+ "psutil>=7.0.0",
]
test = ["pytest>=8.0.1", "pytest-dotenv==0.5.2"]
deploy = [
diff --git a/backend/sample.env b/backend/sample.env
index b1347ef15..eaabb0c1b 100644
--- a/backend/sample.env
+++ b/backend/sample.env
@@ -65,7 +65,7 @@ PLATFORM_SERVICE_PORT=3001
# Tool Runner
UNSTRACT_RUNNER_HOST=http://unstract-runner
UNSTRACT_RUNNER_PORT=5002
-UNSTRACT_RUNNER_API_TIMEOUT=120 # (in seconds) 2 mins
+UNSTRACT_RUNNER_API_TIMEOUT=240 # (in seconds) 2 mins
UNSTRACT_RUNNER_API_RETRY_COUNT=5 # Number of retries for failed requests
UNSTRACT_RUNNER_API_BACKOFF_FACTOR=3 # Exponential backoff factor for retries
diff --git a/backend/tool_instance_v2/internal_urls.py b/backend/tool_instance_v2/internal_urls.py
new file mode 100644
index 000000000..78784a62f
--- /dev/null
+++ b/backend/tool_instance_v2/internal_urls.py
@@ -0,0 +1,16 @@
+"""Internal API URLs for tool instance operations."""
+
+from django.urls import path
+
+from .internal_views import tool_by_id_internal, validate_tool_instances_internal
+
+urlpatterns = [
+ # Tool by ID endpoint - critical for worker functionality
+ path("tool/<str:tool_id>/", tool_by_id_internal, name="tool-by-id-internal"),
+ # Tool instance validation endpoint - used by workers before execution
+ path(
+ "validate/",
+ validate_tool_instances_internal,
+ name="validate-tool-instances-internal",
+ ),
+]
diff --git a/backend/tool_instance_v2/internal_views.py b/backend/tool_instance_v2/internal_views.py
new file mode 100644
index 000000000..66f00feee
--- /dev/null
+++ b/backend/tool_instance_v2/internal_views.py
@@ -0,0 +1,403 @@
+"""Internal API Views for Tool Instance Operations
+
+This module contains internal API endpoints used by workers for tool execution.
+"""
+
+import logging
+
+from django.views.decorators.csrf import csrf_exempt
+from rest_framework import status, viewsets
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from utils.organization_utils import filter_queryset_by_organization
+
+from tool_instance_v2.models import ToolInstance
+from tool_instance_v2.serializers import ToolInstanceSerializer
+from tool_instance_v2.tool_instance_helper import ToolInstanceHelper
+from tool_instance_v2.tool_processor import ToolProcessor
+
+logger = logging.getLogger(__name__)
+
+
+class ToolExecutionInternalViewSet(viewsets.ModelViewSet):
+ """Internal API for tool execution operations used by lightweight workers."""
+
+ serializer_class = ToolInstanceSerializer
+
+ def get_queryset(self):
+ # Filter by organization context set by internal API middleware
+ # Use relationship path: ToolInstance -> Workflow -> Organization
+ queryset = ToolInstance.objects.all()
+ return filter_queryset_by_organization(
+ queryset, self.request, "workflow__organization"
+ )
+
+ def execute_tool(self, request, pk=None):
+ """Execute a specific tool with provided input data.
+
+ This replaces the direct tool execution that was previously done
+ in the heavy Django workers.
+ """
+ try:
+ tool_instance = self.get_object()
+
+ # Extract execution parameters from request
+ input_data = request.data.get("input_data", {})
+ file_data = request.data.get("file_data", {})
+ execution_context = request.data.get("execution_context", {})
+
+ # Execute tool using existing tool processor
+ execution_result = ToolProcessor.execute_tool(
+ tool_instance=tool_instance,
+ input_data=input_data,
+ file_data=file_data,
+ context=execution_context,
+ user=request.user,
+ )
+
+ return Response(
+ {
+ "status": "success",
+ "tool_instance_id": str(tool_instance.id),
+ "execution_result": execution_result,
+ "tool_function": tool_instance.tool_function,
+ "step": tool_instance.step,
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.error(f"Tool execution failed for tool {pk}: {e}")
+ return Response(
+ {
+ "status": "error",
+ "error_message": str(e),
+ "tool_instance_id": str(pk) if pk else None,
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET"])
+def tool_execution_status_internal(request, execution_id):
+ """Get tool execution status for internal API calls."""
+ try:
+ # This would track tool execution status
+ # For now, return a basic status structure
+ return Response(
+ {
+ "execution_id": execution_id,
+ "status": "completed", # Could be: pending, running, completed, failed
+ "progress": 100,
+ "results": [],
+ "error_message": None,
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get tool execution status for {execution_id}: {e}")
+ return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET"])
+def tool_by_id_internal(request, tool_id):
+ """Get tool information by tool ID for internal API calls."""
+ try:
+ logger.info(f"Getting tool information for tool ID: {tool_id}")
+
+ # Get tool from registry using ToolProcessor
+ try:
+ tool = ToolProcessor.get_tool_by_uid(tool_id)
+ logger.info(f"Successfully retrieved tool from ToolProcessor: {tool_id}")
+ except Exception as tool_fetch_error:
+ logger.error(
+ f"Failed to fetch tool {tool_id} from ToolProcessor: {tool_fetch_error}"
+ )
+ # Return fallback using Structure Tool image (which actually exists)
+ from django.conf import settings
+
+ return Response(
+ {
+ "tool": {
+ "tool_id": tool_id,
+ "properties": {
+ "displayName": f"Missing Tool ({tool_id[:8]}...)",
+ "functionName": tool_id,
+ "description": "Tool not found in registry or Prompt Studio",
+ "toolVersion": "unknown",
+ },
+ "image_name": settings.STRUCTURE_TOOL_IMAGE_NAME,
+ "image_tag": settings.STRUCTURE_TOOL_IMAGE_TAG,
+ "name": f"Missing Tool ({tool_id[:8]}...)",
+ "description": "Tool not found in registry or Prompt Studio",
+ "version": "unknown",
+ "note": "Fallback data for missing tool",
+ }
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ # Convert Properties object to dict for JSON serialization
+ properties_dict = {}
+ try:
+ if hasattr(tool.properties, "to_dict"):
+ # Use the to_dict method if available (which handles Adapter serialization)
+ properties_dict = tool.properties.to_dict()
+ logger.info(f"Properties serialized using to_dict() for tool {tool_id}")
+ elif hasattr(tool.properties, "dict"):
+ properties_dict = tool.properties.dict()
+ logger.info(f"Properties serialized using dict() for tool {tool_id}")
+ elif hasattr(tool.properties, "__dict__"):
+ properties_dict = tool.properties.__dict__
+ logger.info(f"Properties serialized using __dict__ for tool {tool_id}")
+ else:
+ # Try to convert to dict if it's iterable
+ try:
+ properties_dict = dict(tool.properties)
+ logger.info(
+ f"Properties serialized using dict conversion for tool {tool_id}"
+ )
+ except (TypeError, ValueError):
+ properties_dict = {"default": "true"} # Fallback
+ logger.warning(f"Using fallback properties for tool {tool_id}")
+ except Exception as props_error:
+ logger.error(
+ f"Failed to serialize properties for tool {tool_id}: {props_error}"
+ )
+ properties_dict = {"error": "serialization_failed"}
+
+ # Handle spec serialization if needed
+ if hasattr(tool, "spec") and tool.spec:
+ if hasattr(tool.spec, "to_dict"):
+ tool.spec.to_dict()
+ elif hasattr(tool.spec, "__dict__"):
+ pass
+
+ # Return tool information with essential fields only to avoid serialization issues
+ return Response(
+ {
+ "tool": {
+ "tool_id": tool_id,
+ "properties": properties_dict,
+ "image_name": str(tool.image_name)
+ if tool.image_name
+ else "default-tool",
+ "image_tag": str(tool.image_tag) if tool.image_tag else "latest",
+ "name": getattr(tool, "name", tool_id),
+ "description": getattr(tool, "description", ""),
+ "version": getattr(tool, "version", "latest"),
+ }
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get tool information for {tool_id}: {e}")
+ import traceback
+
+ logger.error(f"Full traceback: {traceback.format_exc()}")
+
+ # Always return fallback data instead of error to allow workflow to continue
+ from django.conf import settings
+
+ return Response(
+ {
+ "tool": {
+ "tool_id": tool_id,
+ "properties": {
+ "displayName": f"Error Tool ({tool_id[:8]}...)",
+ "functionName": tool_id,
+ "description": f"Error processing tool: {str(e)[:100]}",
+ "toolVersion": "error",
+ },
+ "image_name": settings.STRUCTURE_TOOL_IMAGE_NAME,
+ "image_tag": settings.STRUCTURE_TOOL_IMAGE_TAG,
+ "name": f"Error Tool ({tool_id[:8]}...)",
+ "description": f"Error: {str(e)[:100]}",
+ "version": "error",
+ "error": str(e),
+ "note": "Fallback data for tool processing error",
+ }
+ },
+ status=status.HTTP_200_OK, # Return 200 to allow workflow to continue
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET"])
+def tool_instances_by_workflow_internal(request, workflow_id):
+ """Get tool instances for a workflow for internal API calls."""
+ try:
+ from workflow_manager.workflow_v2.models.workflow import Workflow
+
+ logger.info(f"Getting tool instances for workflow: {workflow_id}")
+
+ # Get workflow with organization filtering first (via DefaultOrganizationManagerMixin)
+ try:
+ workflow = Workflow.objects.get(id=workflow_id)
+ logger.info(f"Found workflow: {workflow.id}")
+ except Workflow.DoesNotExist:
+ logger.error(f"Workflow not found: {workflow_id}")
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get tool instances for the workflow with organization filtering
+ # Filter through the relationship: ToolInstance -> Workflow -> Organization
+ tool_instances_queryset = ToolInstance.objects.filter(workflow=workflow)
+ tool_instances_queryset = filter_queryset_by_organization(
+ tool_instances_queryset, request, "workflow__organization"
+ )
+ tool_instances = tool_instances_queryset.order_by("step")
+ logger.info(f"Found {len(tool_instances)} tool instances")
+
+ # Serialize the tool instances
+ try:
+ logger.info("Starting serialization of tool instances")
+ serializer = ToolInstanceSerializer(tool_instances, many=True)
+ logger.info("Accessing serializer.data")
+ serializer_data = serializer.data
+ logger.info(f"Serialization completed, got {len(serializer_data)} items")
+ except Exception as serializer_error:
+ logger.error(f"Serialization error: {serializer_error}")
+ # Try to return basic data without enhanced tool information
+ basic_data = []
+ for instance in tool_instances:
+ basic_data.append(
+ {
+ "id": str(instance.id),
+ "tool_id": instance.tool_id,
+ "step": instance.step,
+ "metadata": instance.metadata,
+ }
+ )
+ logger.info(f"Returning {len(basic_data)} basic tool instances")
+ return Response(
+ {
+ "workflow_id": workflow_id,
+ "tool_instances": basic_data,
+ "total_count": len(tool_instances),
+ "note": "Basic data returned due to serialization error",
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ return Response(
+ {
+ "workflow_id": workflow_id,
+ "tool_instances": serializer_data,
+ "total_count": len(tool_instances),
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.exception(f"Failed to get tool instances for workflow {workflow_id}: {e}")
+ return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def validate_tool_instances_internal(request):
+ """Validate tool instances and ensure adapter IDs are migrated.
+
+ This internal endpoint validates tool instances for a workflow, ensuring:
+ 1. Adapter names are migrated to IDs
+ 2. User has permissions to access tools and adapters
+ 3. Tool settings match JSON schema requirements
+
+ Used by workers to validate tools before execution.
+
+ Args:
+ request: Request containing:
+ - workflow_id: ID of the workflow
+ - tool_instances: List of tool instance IDs
+
+ Returns:
+ Response with validation results and migrated metadata
+ """
+ workflow_id = request.data.get("workflow_id")
+ tool_instance_ids = request.data.get("tool_instances", [])
+
+ if not workflow_id:
+ return Response(
+ {"error": "workflow_id is required"}, status=status.HTTP_400_BAD_REQUEST
+ )
+
+ validated_instances = []
+ validation_errors = []
+
+ try:
+ # Get tool instances from database with organization filtering
+ tool_instances_queryset = ToolInstance.objects.filter(
+ workflow_id=workflow_id, id__in=tool_instance_ids
+ ).select_related("workflow", "workflow__created_by")
+
+ # Apply organization filtering
+ tool_instances_queryset = filter_queryset_by_organization(
+ tool_instances_queryset, request, "workflow__organization"
+ )
+ tool_instances = list(tool_instances_queryset)
+
+ # Validate each tool instance
+ for tool in tool_instances:
+ try:
+ # Get the user who created the workflow
+ user = tool.workflow.created_by
+
+ # Ensure adapter IDs are migrated from names to IDs
+ migrated_metadata = ToolInstanceHelper.ensure_adapter_ids_in_metadata(
+ tool, user=user
+ )
+
+ # Validate tool settings
+ ToolInstanceHelper.validate_tool_settings(
+ user=user,
+ tool_uid=tool.tool_id,
+ tool_meta=migrated_metadata,
+ )
+
+ # Add to validated list with migrated metadata
+ validated_instances.append(
+ {
+ "id": str(tool.id),
+ "tool_id": tool.tool_id,
+ "metadata": migrated_metadata,
+ "step": tool.step,
+ "status": "valid",
+ }
+ )
+
+ except Exception as e:
+ validation_errors.append(
+ {
+ "tool_id": tool.tool_id,
+ "tool_instance_id": str(tool.id),
+ "error": str(e),
+ }
+ )
+ logger.error(f"Tool validation failed for {tool.tool_id}: {e}")
+
+ # Return validation results
+ response_data = {
+ "success": len(validation_errors) == 0,
+ "validated_instances": validated_instances,
+ "errors": validation_errors,
+ "workflow_id": workflow_id,
+ }
+
+ if validation_errors:
+ return Response(response_data, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
+
+ return Response(response_data, status=status.HTTP_200_OK)
+
+ except Exception as e:
+ logger.error(f"Tool validation failed: {e}", exc_info=True)
+ return Response(
+ {"error": f"Tool validation failed: {str(e)}"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/tool_instance_v2/serializers.py b/backend/tool_instance_v2/serializers.py
index e51b64010..52a100bd5 100644
--- a/backend/tool_instance_v2/serializers.py
+++ b/backend/tool_instance_v2/serializers.py
@@ -63,7 +63,6 @@ class ToolInstanceSerializer(AuditSerializer):
rep[TIKey.METADATA] = self._transform_adapter_ids_to_names_for_display(
metadata, tool_function
)
-
return rep
def _transform_adapter_ids_to_names_for_display(
diff --git a/backend/usage_v2/internal_urls.py b/backend/usage_v2/internal_urls.py
new file mode 100644
index 000000000..a3a02ba7a
--- /dev/null
+++ b/backend/usage_v2/internal_urls.py
@@ -0,0 +1,15 @@
+"""Internal API URLs for Usage access by workers."""
+
+from django.urls import path
+
+from . import internal_views
+
+app_name = "usage_internal"
+
+urlpatterns = [
+ path(
+ "aggregated-token-count/<str:file_execution_id>/",
+ internal_views.UsageInternalView.as_view(),
+ name="aggregated-token-count",
+ ),
+]
diff --git a/backend/usage_v2/internal_views.py b/backend/usage_v2/internal_views.py
new file mode 100644
index 000000000..864ae6ae9
--- /dev/null
+++ b/backend/usage_v2/internal_views.py
@@ -0,0 +1,79 @@
+"""Internal API views for Usage access by workers."""
+
+import logging
+
+from django.http import JsonResponse
+from rest_framework import status
+from rest_framework.request import Request
+from rest_framework.views import APIView
+
+from unstract.core.data_models import UsageResponseData
+
+from .helper import UsageHelper
+
+logger = logging.getLogger(__name__)
+
+
+class UsageInternalView(APIView):
+ """Internal API view for workers to access usage data.
+
+ This endpoint allows workers to get aggregated token usage data
+ for a specific file execution without direct database access.
+ """
+
+ def get(self, request: Request, file_execution_id: str) -> JsonResponse:
+ """Get aggregated token usage for a file execution.
+
+ Args:
+ request: HTTP request (no additional parameters needed)
+ file_execution_id: File execution ID to get usage data for
+
+ Returns:
+ JSON response with aggregated usage data using core data models
+ """
+ try:
+ if not file_execution_id:
+ return JsonResponse(
+ {
+ "success": False,
+ "error": "file_execution_id parameter is required",
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get aggregated token count using the existing helper
+ result = UsageHelper.get_aggregated_token_count(run_id=file_execution_id)
+
+ # Create UsageResponseData for type safety and consistency
+ usage_data = UsageResponseData(
+ file_execution_id=file_execution_id,
+ embedding_tokens=result.get("embedding_tokens"),
+ prompt_tokens=result.get("prompt_tokens"),
+ completion_tokens=result.get("completion_tokens"),
+ total_tokens=result.get("total_tokens"),
+ cost_in_dollars=result.get("cost_in_dollars"),
+ )
+
+ return JsonResponse(
+ {
+ "success": True,
+ "data": {
+ "file_execution_id": file_execution_id,
+ "usage": usage_data.to_dict(),
+ },
+ }
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Error getting usage data for file_execution_id {file_execution_id}: {e}",
+ exc_info=True,
+ )
+ return JsonResponse(
+ {
+ "success": False,
+ "error": "Internal server error",
+ "file_execution_id": file_execution_id,
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/utils/cache_service.py b/backend/utils/cache_service.py
index 8633de58c..55cbb758d 100644
--- a/backend/utils/cache_service.py
+++ b/backend/utils/cache_service.py
@@ -1,4 +1,6 @@
import json
+import logging
+import time
from typing import Any
from django.conf import settings
@@ -7,6 +9,8 @@ from django_redis import get_redis_connection
redis_cache = get_redis_connection("default")
+logger = logging.getLogger(__name__)
+
class CacheService:
@staticmethod
@@ -38,6 +42,72 @@ class CacheService:
"""Delete keys in bulk based on the key pattern."""
cache.delete_pattern(key_pattern)
+ @staticmethod
+ def clear_cache_optimized(key_pattern: str) -> Any:
+ """Delete keys in bulk using optimized SCAN approach for large datasets.
+
+ Uses Redis SCAN instead of KEYS to avoid blocking Redis during deletion.
+ Safe for production with large key sets. Use this for heavy operations
+ like workflow history clearing.
+ """
+ TIMEOUT_SECONDS = 90 # Generous but bounded timeout
+ BATCH_SIZE = 1000
+
+ start_time = time.time()
+ deleted_count = 0
+ cursor = 0
+ completed_naturally = False
+
+ try:
+ while True:
+ # Check timeout first
+ if time.time() - start_time > TIMEOUT_SECONDS:
+ logger.warning(
+ f"Cache clearing timed out after {TIMEOUT_SECONDS}s, "
+ f"deleted {deleted_count} keys matching '{key_pattern}'"
+ )
+ break
+
+ # SCAN returns (next_cursor, keys_list)
+ cursor, keys = redis_cache.scan(
+ cursor=cursor, match=key_pattern, count=BATCH_SIZE
+ )
+
+ if keys:
+ # Delete keys in pipeline for efficiency
+ pipe = redis_cache.pipeline()
+ for key in keys:
+ pipe.delete(key)
+ pipe.execute()
+ deleted_count += len(keys)
+
+ # SCAN is complete when cursor returns to 0
+ if cursor == 0:
+ completed_naturally = True
+ break
+
+ # Log completion status
+ if completed_naturally:
+ logger.info(
+ f"Cache clearing completed: deleted {deleted_count} keys matching '{key_pattern}'"
+ )
+ else:
+ logger.warning(
+ f"Cache clearing incomplete: deleted {deleted_count} keys before timeout"
+ )
+
+ except (ConnectionError, TimeoutError, OSError) as e:
+ logger.error(f"Failed to clear cache pattern '{key_pattern}': {str(e)}")
+ # Fallback to old method for backward compatibility
+ try:
+ cache.delete_pattern(key_pattern)
+ logger.warning(f"Used fallback delete_pattern for '{key_pattern}'")
+ except (ConnectionError, TimeoutError, OSError) as fallback_error:
+ logger.error(
+ f"Fallback cache clearing also failed: {str(fallback_error)}"
+ )
+ raise e
+
@staticmethod
def check_a_key_exist(key: str, version: Any = None) -> bool:
data: bool = cache.has_key(key, version)
@@ -70,6 +140,10 @@ class CacheService:
def lpop(key: str) -> Any:
return redis_cache.lpop(key)
+ @staticmethod
+ def llen(key: str) -> int:
+ return redis_cache.llen(key)
+
@staticmethod
def lrem(key: str, value: str) -> None:
redis_cache.lrem(key, value)
diff --git a/backend/utils/log_events.py b/backend/utils/log_events.py
index 2cb79254e..3e11c8fcf 100644
--- a/backend/utils/log_events.py
+++ b/backend/utils/log_events.py
@@ -1,5 +1,4 @@
import http
-import json
import logging
import os
from typing import Any
@@ -9,10 +8,9 @@ import socketio
from django.conf import settings
from django.core.wsgi import WSGIHandler
-from unstract.core.constants import LogFieldName
-from unstract.workflow_execution.enums import LogType
+from unstract.core.data_models import LogDataDTO
+from unstract.core.log_utils import get_validated_log_data, store_execution_log
from utils.constants import ExecutionLogConstants
-from utils.dto import LogDataDTO
logger = logging.getLogger(__name__)
@@ -79,71 +77,23 @@ def _get_user_session_id_from_cookies(sid: str, environ: Any) -> str | None:
return session_id.value
-def _get_validated_log_data(json_data: Any) -> LogDataDTO | None:
- """Validate log data to persist history. This function takes log data in
- JSON format, validates it, and returns a `LogDataDTO` object if the data is
- valid. The validation process includes decoding bytes to string, parsing
- the string as JSON, and checking for required fields and log type.
-
- Args:
- json_data (Any): Log data in JSON format
- Returns:
- Optional[LogDataDTO]: Log data DTO object
- """
- if isinstance(json_data, bytes):
- json_data = json_data.decode("utf-8")
-
- if isinstance(json_data, str):
- try:
- # Parse the string as JSON
- json_data = json.loads(json_data)
- except json.JSONDecodeError:
- logger.error(f"Error decoding JSON data while validating {json_data}")
- return
-
- if not isinstance(json_data, dict):
- logger.warning(f"Getting invalid data type while validating {json_data}")
- return
-
- # Extract required fields from the JSON data
- execution_id = json_data.get(LogFieldName.EXECUTION_ID)
- organization_id = json_data.get(LogFieldName.ORGANIZATION_ID)
- timestamp = json_data.get(LogFieldName.TIMESTAMP)
- log_type = json_data.get(LogFieldName.TYPE)
- file_execution_id = json_data.get(LogFieldName.FILE_EXECUTION_ID)
-
- # Ensure the log type is LogType.LOG
- if log_type != LogType.LOG.value:
- return
+# Functions moved to unstract.core.log_utils for sharing with workers
+# Keep these as wrapper functions for backward compatibility
- # Check if all required fields are present
- if not all((execution_id, organization_id, timestamp)):
- logger.debug(f"Missing required fields while validating {json_data}")
- return
- return LogDataDTO(
- execution_id=execution_id,
- file_execution_id=file_execution_id,
- organization_id=organization_id,
- timestamp=timestamp,
- log_type=log_type,
- data=json_data,
- )
+def _get_validated_log_data(json_data: Any) -> LogDataDTO | None:
+ """Validate log data to persist history (backward compatibility wrapper)."""
+ return get_validated_log_data(json_data)
def _store_execution_log(data: dict[str, Any]) -> None:
- """Store execution log in database
- Args:
- data (dict[str, Any]): Execution log data
- """
- if not ExecutionLogConstants.IS_ENABLED:
- return
- try:
- log_data = _get_validated_log_data(json_data=data)
- if log_data:
- redis_conn.rpush(ExecutionLogConstants.LOG_QUEUE_NAME, log_data.to_json())
- except Exception as e:
- logger.error(f"Error storing execution log: {e}")
+ """Store execution log in database (backward compatibility wrapper)."""
+ store_execution_log(
+ data=data,
+ redis_client=redis_conn,
+ log_queue_name=ExecutionLogConstants.LOG_QUEUE_NAME,
+ is_enabled=ExecutionLogConstants.IS_ENABLED,
+ )
def _emit_websocket_event(room: str, event: str, data: dict[str, Any]) -> None:
diff --git a/backend/utils/organization_utils.py b/backend/utils/organization_utils.py
new file mode 100644
index 000000000..15053684b
--- /dev/null
+++ b/backend/utils/organization_utils.py
@@ -0,0 +1,95 @@
+"""Organization utilities for internal APIs.
+Provides shared functions for organization context resolution.
+"""
+
+import logging
+from typing import Any
+
+from account_v2.models import Organization
+from django.shortcuts import get_object_or_404
+
+logger = logging.getLogger(__name__)
+
+
+def resolve_organization(
+ org_id: str, raise_on_not_found: bool = False
+) -> Organization | None:
+ """Resolve organization by either organization.id (int) or organization.organization_id (string).
+
+ Args:
+ org_id: Organization identifier - can be either the primary key (numeric string)
+ or the organization_id field (string)
+ raise_on_not_found: If True, raises Http404 on not found. If False, returns None.
+
+ Returns:
+ Organization instance if found, None if not found and raise_on_not_found=False
+
+ Raises:
+ Http404: If organization not found and raise_on_not_found=True
+ """
+ try:
+ if org_id.isdigit():
+ # If it's numeric, treat as primary key
+ if raise_on_not_found:
+ return get_object_or_404(Organization, id=org_id)
+ else:
+ return Organization.objects.get(id=org_id)
+ else:
+ # If it's string, treat as organization_id field
+ if raise_on_not_found:
+ return get_object_or_404(Organization, organization_id=org_id)
+ else:
+ return Organization.objects.get(organization_id=org_id)
+ except Organization.DoesNotExist:
+ if raise_on_not_found:
+ raise
+ logger.warning(f"Organization {org_id} not found")
+ return None
+
+
+def get_organization_context(organization: Organization) -> dict[str, Any]:
+ """Get standardized organization context data.
+
+ Args:
+ organization: Organization instance
+
+ Returns:
+ Dictionary with organization context information
+ """
+ return {
+ "organization_id": str(organization.id),
+ "organization_name": organization.display_name,
+ "organization_slug": getattr(organization, "slug", ""),
+ "created_at": organization.created_at.isoformat()
+ if hasattr(organization, "created_at")
+ else None,
+ "settings": {
+ # Add organization-specific settings here
+ "subscription_active": True, # This would come from subscription model
+ "features_enabled": [], # This would come from feature flags
+ },
+ }
+
+
+def filter_queryset_by_organization(queryset, request, organization_field="organization"):
+ """Filter a Django queryset by organization context from request.
+
+ Args:
+ queryset: Django QuerySet to filter
+ request: HTTP request object with organization_id attribute
+ organization_field: Field name for organization relationship (default: 'organization')
+
+ Returns:
+ Filtered queryset or empty queryset if organization not found
+ """
+ org_id = getattr(request, "organization_id", None)
+ if org_id:
+ organization = resolve_organization(org_id, raise_on_not_found=False)
+ if organization:
+ # Use dynamic field lookup
+ filter_kwargs = {organization_field: organization}
+ return queryset.filter(**filter_kwargs)
+ else:
+ # Return empty queryset if organization not found
+ return queryset.none()
+ return queryset
diff --git a/backend/utils/websocket_views.py b/backend/utils/websocket_views.py
new file mode 100644
index 000000000..a57521ca4
--- /dev/null
+++ b/backend/utils/websocket_views.py
@@ -0,0 +1,87 @@
+"""WebSocket emission views for internal API.
+
+This module provides endpoints for workers to trigger WebSocket events
+through the backend's SocketIO server.
+
+Security Note:
+- CSRF protection is disabled for internal service-to-service communication
+- Authentication is handled by InternalAPIAuthMiddleware using Bearer tokens
+- This endpoint is for worker → backend WebSocket event triggering only
+"""
+
+import json
+import logging
+
+from django.http import JsonResponse
+from django.views.decorators.csrf import csrf_exempt
+from django.views.decorators.http import require_http_methods
+
+from utils.log_events import _emit_websocket_event
+
+logger = logging.getLogger(__name__)
+
+
+# CSRF exemption is safe here because:
+# 1. Internal service-to-service communication (workers → backend)
+# 2. Protected by InternalAPIAuthMiddleware Bearer token authentication
+# 3. No browser sessions or cookies involved
+# 4. Used for WebSocket event triggering, not state modification
+@csrf_exempt
+@require_http_methods(["POST"])
+def emit_websocket(request):
+ """Internal API endpoint for workers to emit WebSocket events.
+
+ Expected payload:
+ {
+ "room": "session_id",
+ "event": "logs:session_id",
+ "data": {...}
+ }
+
+ Returns:
+ JSON response with success/error status
+ """
+ try:
+ # Parse request data (standard Django view)
+ data = json.loads(request.body.decode("utf-8"))
+
+ # Extract required fields
+ room = data.get("room")
+ event = data.get("event")
+ message_data = data.get("data", {})
+
+ # Validate required fields
+ if not room or not event:
+ return JsonResponse(
+ {
+ "status": "error",
+ "message": "Missing required fields: room and event are required",
+ },
+ status=400,
+ )
+
+ # Emit the WebSocket event
+ _emit_websocket_event(room=room, event=event, data=message_data)
+
+ logger.debug(f"WebSocket event emitted: room={room}, event={event}")
+
+ return JsonResponse(
+ {
+ "status": "success",
+ "message": "WebSocket event emitted successfully",
+ "room": room,
+ "event": event,
+ }
+ )
+
+ except json.JSONDecodeError as e:
+ logger.error(f"Invalid JSON in WebSocket emission request: {e}")
+ return JsonResponse(
+ {"status": "error", "message": "Invalid JSON payload"}, status=400
+ )
+ except Exception as e:
+ logger.error(f"Error emitting WebSocket event: {e}")
+ return JsonResponse(
+ {"status": "error", "message": f"Failed to emit WebSocket event: {str(e)}"},
+ status=500,
+ )
diff --git a/backend/uv.lock b/backend/uv.lock
index 6a3752257..cbf757ce3 100644
--- a/backend/uv.lock
+++ b/backend/uv.lock
@@ -2975,6 +2975,21 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/0c/c1/6aece0ab5209981a70cd186f164c133fdba2f51e124ff92b73de7fd24d78/protobuf-4.25.8-py3-none-any.whl", hash = "sha256:15a0af558aa3b13efef102ae6e4f3efac06f1eea11afb3a57db2901447d9fb59", size = 156757, upload-time = "2025-05-28T14:22:24.135Z" },
]
+[[package]]
+name = "psutil"
+version = "7.0.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/2a/80/336820c1ad9286a4ded7e845b2eccfcb27851ab8ac6abece774a6ff4d3de/psutil-7.0.0.tar.gz", hash = "sha256:7be9c3eba38beccb6495ea33afd982a44074b78f28c434a1f51cc07fd315c456", size = 497003 }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ed/e6/2d26234410f8b8abdbf891c9da62bee396583f713fb9f3325a4760875d22/psutil-7.0.0-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:101d71dc322e3cffd7cea0650b09b3d08b8e7c4109dd6809fe452dfd00e58b25", size = 238051 },
+ { url = "https://files.pythonhosted.org/packages/04/8b/30f930733afe425e3cbfc0e1468a30a18942350c1a8816acfade80c005c4/psutil-7.0.0-cp36-abi3-macosx_11_0_arm64.whl", hash = "sha256:39db632f6bb862eeccf56660871433e111b6ea58f2caea825571951d4b6aa3da", size = 239535 },
+ { url = "https://files.pythonhosted.org/packages/2a/ed/d362e84620dd22876b55389248e522338ed1bf134a5edd3b8231d7207f6d/psutil-7.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1fcee592b4c6f146991ca55919ea3d1f8926497a713ed7faaf8225e174581e91", size = 275004 },
+ { url = "https://files.pythonhosted.org/packages/bf/b9/b0eb3f3cbcb734d930fdf839431606844a825b23eaf9a6ab371edac8162c/psutil-7.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4b1388a4f6875d7e2aff5c4ca1cc16c545ed41dd8bb596cefea80111db353a34", size = 277986 },
+ { url = "https://files.pythonhosted.org/packages/eb/a2/709e0fe2f093556c17fbafda93ac032257242cabcc7ff3369e2cb76a97aa/psutil-7.0.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5f098451abc2828f7dc6b58d44b532b22f2088f4999a937557b603ce72b1993", size = 279544 },
+ { url = "https://files.pythonhosted.org/packages/50/e6/eecf58810b9d12e6427369784efe814a1eec0f492084ce8eb8f4d89d6d61/psutil-7.0.0-cp37-abi3-win32.whl", hash = "sha256:ba3fcef7523064a6c9da440fc4d6bd07da93ac726b5733c29027d7dc95b39d99", size = 241053 },
+ { url = "https://files.pythonhosted.org/packages/50/1b/6921afe68c74868b4c9fa424dad3be35b095e16687989ebbb50ce4fceb7c/psutil-7.0.0-cp37-abi3-win_amd64.whl", hash = "sha256:4cf3d4eb1aa9b348dec30105c55cd9b7d4629285735a102beb4441e38db90553", size = 244885 },
+]
+
[[package]]
name = "psycopg2-binary"
version = "2.9.9"
@@ -3502,6 +3517,20 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/3f/51/d4db610ef29373b879047326cbf6fa98b6c1969d6f6dc423279de2b1be2c/requests_toolbelt-1.0.0-py2.py3-none-any.whl", hash = "sha256:cccfdd665f0a24fcf4726e690f65639d272bb0637b9b92dfd91a5568ccf6bd06", size = 54481, upload-time = "2023-05-01T04:11:28.427Z" },
]
+[[package]]
+name = "responses"
+version = "0.25.7"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pyyaml" },
+ { name = "requests" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/81/7e/2345ac3299bd62bd7163216702bbc88976c099cfceba5b889f2a457727a1/responses-0.25.7.tar.gz", hash = "sha256:8ebae11405d7a5df79ab6fd54277f6f2bc29b2d002d0dd2d5c632594d1ddcedb", size = 79203 }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e4/fc/1d20b64fa90e81e4fa0a34c9b0240a6cfb1326b7e06d18a5432a9917c316/responses-0.25.7-py3-none-any.whl", hash = "sha256:92ca17416c90fe6b35921f52179bff29332076bb32694c0df02dcac2c6bc043c", size = 34732 },
+]
+
[[package]]
name = "rpds-py"
version = "0.27.1"
@@ -4042,6 +4071,9 @@ dev = [
{ name = "debugpy" },
{ name = "inotify" },
{ name = "poethepoet" },
+ { name = "psutil" },
+ { name = "pytest" },
+ { name = "responses" },
{ name = "unstract-connectors" },
{ name = "unstract-core" },
{ name = "unstract-filesystem" },
@@ -4109,6 +4141,9 @@ dev = [
{ name = "debugpy", specifier = ">=1.8.14" },
{ name = "inotify", specifier = ">=0.2.10" },
{ name = "poethepoet", specifier = ">=0.33.1" },
+ { name = "psutil", specifier = ">=7.0.0" },
+ { name = "pytest", specifier = ">=8.3.5" },
+ { name = "responses", specifier = ">=0.25.7" },
{ name = "unstract-connectors", editable = "../unstract/connectors" },
{ name = "unstract-core", editable = "../unstract/core" },
{ name = "unstract-filesystem", editable = "../unstract/filesystem" },
diff --git a/backend/workflow_manager/endpoint_v2/destination.py b/backend/workflow_manager/endpoint_v2/destination.py
index b7bf2ca1b..83917a08f 100644
--- a/backend/workflow_manager/endpoint_v2/destination.py
+++ b/backend/workflow_manager/endpoint_v2/destination.py
@@ -871,7 +871,6 @@ class DestinationConnector(BaseConnector):
).to_dict()
queue_result_json = json.dumps(queue_result)
-
conn = QueueUtils.get_queue_inst()
conn.enqueue(queue_name=q_name, message=queue_result_json)
logger.info(f"Pushed {file_name} to queue {q_name} with file content")
@@ -891,11 +890,13 @@ class DestinationConnector(BaseConnector):
q_name = self._get_review_queue_name()
if meta_data:
whisper_hash = meta_data.get("whisper-hash")
+ extracted_text = meta_data.get("extracted_text")
else:
whisper_hash = None
+ extracted_text = None
- # Get extracted text from metadata (added by structure tool)
- extracted_text = meta_data.get("extracted_text") if meta_data else None
+ # Get TTL from workflow settings
+ ttl_seconds = WorkflowUtil.get_hitl_ttl_seconds(workflow)
# Create QueueResult with TTL metadata
queue_result_obj = QueueResult(
@@ -907,8 +908,8 @@ class DestinationConnector(BaseConnector):
whisper_hash=whisper_hash,
file_execution_id=file_execution_id,
extracted_text=extracted_text,
+ ttl_seconds=ttl_seconds,
)
-
# Add TTL metadata based on HITLSettings
queue_result_obj.ttl_seconds = WorkflowUtil.get_hitl_ttl_seconds(workflow)
diff --git a/backend/workflow_manager/endpoint_v2/endpoint_utils.py b/backend/workflow_manager/endpoint_v2/endpoint_utils.py
index 70207b3a9..4eeeee7ca 100644
--- a/backend/workflow_manager/endpoint_v2/endpoint_utils.py
+++ b/backend/workflow_manager/endpoint_v2/endpoint_utils.py
@@ -28,3 +28,27 @@ class WorkflowEndpointUtils:
workflow=workflow
)
return endpoints
+
+ @staticmethod
+ def get_endpoint_for_workflow_by_type(
+ workflow_id: str, endpoint_type: WorkflowEndpoint.EndpointType
+ ) -> WorkflowEndpoint:
+ """Get endpoint for a given workflow by type.
+
+ Args:
+ workflow_id (str): The ID of the workflow.
+ endpoint_type (WorkflowEndpoint.EndpointType): The type of the endpoint.
+
+ Returns:
+ WorkflowEndpoint: The endpoint for the given workflow and type.
+ """
+ workflow = WorkflowHelper.get_workflow_by_id(workflow_id)
+ endpoint: WorkflowEndpoint = WorkflowEndpoint.objects.get(
+ workflow=workflow,
+ endpoint_type=endpoint_type,
+ )
+ if endpoint.connector_instance:
+ endpoint.connector_instance.connector_metadata = (
+ endpoint.connector_instance.metadata
+ )
+ return endpoint
diff --git a/backend/workflow_manager/endpoint_v2/source.py b/backend/workflow_manager/endpoint_v2/source.py
index b0d223368..be43e1cf1 100644
--- a/backend/workflow_manager/endpoint_v2/source.py
+++ b/backend/workflow_manager/endpoint_v2/source.py
@@ -578,7 +578,7 @@ class SourceConnector(BaseConnector):
return WorkflowExecution.objects.filter(
workflow=self.workflow,
workflow__organization_id=organization.id, # Security: Organization isolation
- status__in=[ExecutionStatus.EXECUTING, ExecutionStatus.PENDING],
+ status__in=[ExecutionStatus.EXECUTING.value, ExecutionStatus.PENDING.value],
)
def _has_blocking_file_execution(self, execution, file_hash: FileHash) -> bool:
@@ -616,7 +616,10 @@ class SourceConnector(BaseConnector):
workflow_execution=execution,
file_hash=file_hash.file_hash,
file_path=file_hash.file_path,
- status__in=ExecutionStatus.get_skip_processing_statuses(),
+ status__in=[
+ status.value
+ for status in ExecutionStatus.get_skip_processing_statuses()
+ ],
)
except WorkflowFileExecution.DoesNotExist:
return None
@@ -633,7 +636,10 @@ class SourceConnector(BaseConnector):
workflow_execution=execution,
provider_file_uuid=file_hash.provider_file_uuid,
file_path=file_hash.file_path,
- status__in=ExecutionStatus.get_skip_processing_statuses(),
+ status__in=[
+ status.value
+ for status in ExecutionStatus.get_skip_processing_statuses()
+ ],
)
except WorkflowFileExecution.DoesNotExist:
return None
diff --git a/backend/workflow_manager/execution/serializer/execution.py b/backend/workflow_manager/execution/serializer/execution.py
index 1993e7037..04065cdcc 100644
--- a/backend/workflow_manager/execution/serializer/execution.py
+++ b/backend/workflow_manager/execution/serializer/execution.py
@@ -26,8 +26,8 @@ class ExecutionSerializer(serializers.ModelSerializer):
def get_successful_files(self, obj: WorkflowExecution) -> int:
"""Return the count of successfully executed files"""
- return obj.file_executions.filter(status=ExecutionStatus.COMPLETED).count()
+ return obj.file_executions.filter(status=ExecutionStatus.COMPLETED.value).count()
def get_failed_files(self, obj: WorkflowExecution) -> int:
"""Return the count of failed executed files"""
- return obj.file_executions.filter(status=ExecutionStatus.ERROR).count()
+ return obj.file_executions.filter(status=ExecutionStatus.ERROR.value).count()
diff --git a/backend/workflow_manager/file_execution/internal_urls.py b/backend/workflow_manager/file_execution/internal_urls.py
new file mode 100644
index 000000000..a7667d95d
--- /dev/null
+++ b/backend/workflow_manager/file_execution/internal_urls.py
@@ -0,0 +1,42 @@
+"""Internal API URLs for File Execution
+URL patterns for file execution internal APIs.
+"""
+
+from django.urls import include, path
+from rest_framework.routers import DefaultRouter
+
+from .internal_views import (
+ FileExecutionBatchCreateAPIView,
+ FileExecutionBatchHashUpdateAPIView,
+ FileExecutionBatchStatusUpdateAPIView,
+ FileExecutionInternalViewSet,
+ FileExecutionMetricsAPIView,
+)
+
+# Create router for file execution viewsets
+router = DefaultRouter()
+router.register(r"", FileExecutionInternalViewSet, basename="file-execution-internal")
+
+urlpatterns = [
+ # Batch operations
+ path(
+ "batch-create/",
+ FileExecutionBatchCreateAPIView.as_view(),
+ name="file-execution-batch-create",
+ ),
+ path(
+ "batch-status-update/",
+ FileExecutionBatchStatusUpdateAPIView.as_view(),
+ name="file-execution-batch-status-update",
+ ),
+ path(
+ "batch-hash-update/",
+ FileExecutionBatchHashUpdateAPIView.as_view(),
+ name="file-execution-batch-hash-update",
+ ),
+ path(
+ "metrics/", FileExecutionMetricsAPIView.as_view(), name="file-execution-metrics"
+ ),
+ # File execution CRUD (via router)
+ path("", include(router.urls)),
+]
diff --git a/backend/workflow_manager/file_execution/internal_views.py b/backend/workflow_manager/file_execution/internal_views.py
new file mode 100644
index 000000000..fbd5c65e7
--- /dev/null
+++ b/backend/workflow_manager/file_execution/internal_views.py
@@ -0,0 +1,777 @@
+"""Internal API Views for File Execution
+Handles file execution related endpoints for internal services.
+"""
+
+import logging
+
+from django.db import transaction
+from rest_framework import status, viewsets
+from rest_framework.decorators import action
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from utils.organization_utils import filter_queryset_by_organization
+
+from workflow_manager.endpoint_v2.dto import FileHash
+from workflow_manager.file_execution.models import WorkflowFileExecution
+
+# Import serializers from workflow_manager internal API
+from workflow_manager.internal_serializers import (
+ FileExecutionStatusUpdateSerializer,
+ WorkflowFileExecutionSerializer,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class FileExecutionInternalViewSet(viewsets.ModelViewSet):
+ """Internal API ViewSet for File Execution operations."""
+
+ serializer_class = WorkflowFileExecutionSerializer
+ lookup_field = "id"
+
+ def get_queryset(self):
+ """Get file executions filtered by organization context and query parameters."""
+ queryset = WorkflowFileExecution.objects.all()
+
+ # Filter through the relationship: WorkflowFileExecution -> WorkflowExecution -> Workflow -> Organization
+ queryset = filter_queryset_by_organization(
+ queryset, self.request, "workflow_execution__workflow__organization"
+ )
+
+ # Debug: Log initial queryset count after organization filtering
+ org_filtered_count = queryset.count()
+ logger.debug(
+ f"After organization filtering: {org_filtered_count} file executions"
+ )
+
+ # Support filtering by query parameters for get-or-create operations
+ execution_id = self.request.query_params.get("execution_id")
+ file_hash = self.request.query_params.get("file_hash")
+ provider_file_uuid = self.request.query_params.get("provider_file_uuid")
+ workflow_id = self.request.query_params.get("workflow_id")
+ file_path = self.request.query_params.get(
+ "file_path"
+ ) # CRITICAL: Add file_path parameter
+
+ logger.debug(
+ f"Query parameters: execution_id={execution_id}, file_hash={file_hash}, provider_file_uuid={provider_file_uuid}, workflow_id={workflow_id}, file_path={file_path}"
+ )
+
+ # Apply filters step by step with debugging
+ if execution_id:
+ queryset = queryset.filter(workflow_execution_id=execution_id)
+ logger.info(
+ f"DEBUG: After execution_id filter: {queryset.count()} file executions"
+ )
+
+ # CRITICAL FIX: Include file_path filter to match unique constraints
+ if file_path:
+ queryset = queryset.filter(file_path=file_path)
+ logger.debug(f"After file_path filter: {queryset.count()} file executions")
+
+ # CRITICAL FIX: Match backend manager logic - use file_hash OR provider_file_uuid (not both)
+ if file_hash:
+ queryset = queryset.filter(file_hash=file_hash)
+ logger.info(
+ f"DEBUG: After file_hash filter: {queryset.count()} file executions"
+ )
+ elif provider_file_uuid:
+ queryset = queryset.filter(provider_file_uuid=provider_file_uuid)
+ logger.info(
+ f"DEBUG: After provider_file_uuid filter: {queryset.count()} file executions"
+ )
+
+ if workflow_id:
+ queryset = queryset.filter(workflow_execution__workflow_id=workflow_id)
+ logger.info(
+ f"DEBUG: After workflow_id filter: {queryset.count()} file executions"
+ )
+
+ final_count = queryset.count()
+ logger.info(
+ f"Final queryset count: {final_count} file executions for params: execution_id={execution_id}, file_hash={file_hash}, provider_file_uuid={provider_file_uuid}, workflow_id={workflow_id}, file_path={file_path}"
+ )
+
+ # If we still have too many results, something is wrong with the filtering
+ if final_count > 10: # Reasonable threshold
+ logger.warning(
+ f"Query returned {final_count} file executions - filtering may not be working correctly"
+ )
+ logger.warning(
+ f"Query params: execution_id={execution_id}, file_hash={file_hash}, workflow_id={workflow_id}"
+ )
+
+ return queryset
+
+ def list(self, request, *args, **kwargs):
+ """List file executions with enhanced filtering validation."""
+ queryset = self.get_queryset()
+ count = queryset.count()
+
+ # If we get too many results, it means the filtering failed
+ if count > 50: # Conservative threshold
+ logger.error(
+ f"GET request returned {count} file executions - this suggests broken query parameter filtering"
+ )
+ logger.error(f"Request query params: {dict(request.query_params)}")
+
+ # For debugging, show a sample of what we're returning
+ sample_ids = list(queryset.values_list("id", flat=True)[:5])
+ logger.error(f"Sample file execution IDs: {sample_ids}")
+
+ # Return error response instead of broken list
+ return Response(
+ {
+ "error": "Query returned too many results",
+ "detail": f"Expected 0-1 file executions but got {count}. Check query parameters.",
+ "count": count,
+ "query_params": dict(request.query_params),
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Continue with normal list behavior for reasonable result counts
+ logger.info(f"GET request successfully filtered to {count} file executions")
+ return super().list(request, *args, **kwargs)
+
+ @action(detail=True, methods=["post"])
+ def status(self, request, id=None):
+ """Update file execution status."""
+ try:
+ # Get file execution by ID with organization filtering
+ # Don't use self.get_object() as it applies query parameter filtering
+ base_queryset = WorkflowFileExecution.objects.all()
+ base_queryset = filter_queryset_by_organization(
+ base_queryset, request, "workflow_execution__workflow__organization"
+ )
+
+ try:
+ file_execution = base_queryset.get(id=id)
+ except WorkflowFileExecution.DoesNotExist:
+ logger.warning(f"WorkflowFileExecution {id} not found for status update")
+ return Response(
+ {
+ "error": "WorkflowFileExecution not found",
+ "detail": f"No file execution record found with ID {id}",
+ },
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ serializer = FileExecutionStatusUpdateSerializer(data=request.data)
+
+ if serializer.is_valid():
+ validated_data = serializer.validated_data
+
+ # Update file execution using the model's update_status method
+ file_execution.update_status(
+ status=validated_data["status"],
+ execution_error=validated_data.get("error_message"),
+ execution_time=validated_data.get("execution_time"),
+ )
+
+ logger.info(
+ f"Updated file execution {id} status to {validated_data['status']}"
+ )
+
+ # Return consistent dataclass response
+ from unstract.core.data_models import FileExecutionStatusUpdateRequest
+
+ response_data = FileExecutionStatusUpdateRequest(
+ status=file_execution.status,
+ error_message=file_execution.execution_error,
+ result=getattr(file_execution, "result", None),
+ )
+
+ return Response(
+ {
+ "status": "updated",
+ "file_execution_id": str(file_execution.id),
+ "data": response_data.to_dict(),
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ except Exception as e:
+ logger.error(f"Failed to update file execution status {id}: {str(e)}")
+ return Response(
+ {"error": "Failed to update file execution status", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def create(self, request, *args, **kwargs):
+ """Create or get existing workflow file execution using existing manager method."""
+ try:
+ from workflow_manager.workflow_v2.models.execution import WorkflowExecution
+
+ data = request.data
+ execution_id = data.get("execution_id")
+ file_hash_data = data.get("file_hash", {})
+ workflow_id = data.get("workflow_id")
+
+ if not execution_id:
+ return Response(
+ {"error": "execution_id is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get workflow execution with organization filtering
+ try:
+ workflow_execution = WorkflowExecution.objects.get(id=execution_id)
+ # Verify organization access
+ filter_queryset_by_organization(
+ WorkflowExecution.objects.filter(id=execution_id),
+ request,
+ "workflow__organization",
+ ).get()
+ except WorkflowExecution.DoesNotExist:
+ return Response(
+ {"error": "WorkflowExecution not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Convert request data to FileHash object that the manager expects
+ file_hash = FileHash(
+ file_path=file_hash_data.get("file_path", ""),
+ file_name=file_hash_data.get("file_name", ""),
+ source_connection_type=file_hash_data.get("source_connection_type", ""),
+ file_hash=file_hash_data.get("file_hash"),
+ file_size=file_hash_data.get("file_size"),
+ provider_file_uuid=file_hash_data.get("provider_file_uuid"),
+ mime_type=file_hash_data.get("mime_type"),
+ fs_metadata=file_hash_data.get("fs_metadata"),
+ file_destination=file_hash_data.get("file_destination"),
+ is_executed=file_hash_data.get("is_executed", False),
+ file_number=file_hash_data.get("file_number"),
+ )
+
+ # Determine if this is an API request (affects file_path handling in manager)
+ is_api = file_hash_data.get("source_connection_type", "") == "API"
+
+ # Use existing manager method - this handles get_or_create logic properly
+ file_execution = WorkflowFileExecution.objects.get_or_create_file_execution(
+ workflow_execution=workflow_execution, file_hash=file_hash, is_api=is_api
+ )
+
+ # Return single object (not list!) using serializer
+ serializer = self.get_serializer(file_execution)
+ response_data = serializer.data
+
+ # ROOT CAUSE FIX: Ensure file_path is always present in API response
+ # The backend model sets file_path to None for API files, but workers require it
+ if not response_data.get("file_path") and file_hash.file_path:
+ logger.info(
+ f"Backend stored null file_path for API file, including original: {file_hash.file_path}"
+ )
+ response_data["file_path"] = file_hash.file_path
+
+ logger.info(
+ f"Retrieved/created file execution {file_execution.id} for workflow {workflow_id}"
+ )
+ logger.debug(f"Response data: {response_data}")
+
+ # Determine status code based on whether it was created or retrieved
+ # Note: We can't easily tell if it was created or retrieved from the manager,
+ # but 201 is fine for both cases in this context
+ return Response(response_data, status=status.HTTP_201_CREATED)
+
+ except Exception as e:
+ logger.error(f"Failed to get/create file execution: {str(e)}")
+ return Response(
+ {"error": "Failed to get/create file execution", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ @action(detail=True, methods=["patch"])
+ def update_hash(self, request, id=None):
+ """Update file execution with computed file hash."""
+ try:
+ # Get file execution by ID with organization filtering
+ base_queryset = WorkflowFileExecution.objects.all()
+ base_queryset = filter_queryset_by_organization(
+ base_queryset, request, "workflow_execution__workflow__organization"
+ )
+
+ try:
+ file_execution = base_queryset.get(id=id)
+ except WorkflowFileExecution.DoesNotExist:
+ logger.warning(f"WorkflowFileExecution {id} not found for hash update")
+ return Response(
+ {
+ "error": "WorkflowFileExecution not found",
+ "detail": f"No file execution record found with ID {id}",
+ },
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Extract update data
+ file_hash = request.data.get("file_hash")
+ fs_metadata = request.data.get("fs_metadata")
+ mime_type = request.data.get("mime_type")
+
+ if not file_hash and not fs_metadata and not mime_type:
+ return Response(
+ {"error": "file_hash, fs_metadata, or mime_type is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Use the model's update method for efficient field-specific updates
+ file_execution.update(
+ file_hash=file_hash, fs_metadata=fs_metadata, mime_type=mime_type
+ )
+
+ logger.info(
+ f"Updated file execution {id} with file_hash: {file_hash[:16] if file_hash else 'none'}..."
+ )
+
+ # Return updated record
+ serializer = self.get_serializer(file_execution)
+ return Response(
+ {
+ "status": "updated",
+ "file_execution_id": str(file_execution.id),
+ "data": serializer.data,
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to update file execution hash {id}: {str(e)}")
+ return Response(
+ {"error": "Failed to update file execution hash", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileExecutionBatchCreateAPIView(APIView):
+ """Internal API endpoint for creating multiple file executions in a single batch."""
+
+ def post(self, request):
+ """Create multiple file executions in a single batch request."""
+ try:
+ file_executions = request.data.get("file_executions", [])
+
+ if not file_executions:
+ return Response(
+ {"error": "file_executions list is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ successful_creations = []
+ failed_creations = []
+
+ with transaction.atomic():
+ for file_execution_data in file_executions:
+ try:
+ from workflow_manager.workflow_v2.models.execution import (
+ WorkflowExecution,
+ )
+
+ execution_id = file_execution_data.get("execution_id")
+ file_hash_data = file_execution_data.get("file_hash", {})
+
+ if not execution_id:
+ failed_creations.append(
+ {
+ "file_name": file_hash_data.get(
+ "file_name", "unknown"
+ ),
+ "error": "execution_id is required",
+ }
+ )
+ continue
+
+ # Get workflow execution with organization filtering
+ try:
+ workflow_execution = WorkflowExecution.objects.get(
+ id=execution_id
+ )
+ # Verify organization access
+ filter_queryset_by_organization(
+ WorkflowExecution.objects.filter(id=execution_id),
+ request,
+ "workflow__organization",
+ ).get()
+ except WorkflowExecution.DoesNotExist:
+ failed_creations.append(
+ {
+ "file_name": file_hash_data.get(
+ "file_name", "unknown"
+ ),
+ "error": "WorkflowExecution not found or access denied",
+ }
+ )
+ continue
+
+ # Convert request data to FileHash object
+ file_hash = FileHash(
+ file_path=file_hash_data.get("file_path", ""),
+ file_name=file_hash_data.get("file_name", ""),
+ source_connection_type=file_hash_data.get(
+ "source_connection_type", ""
+ ),
+ file_hash=file_hash_data.get("file_hash"),
+ file_size=file_hash_data.get("file_size"),
+ provider_file_uuid=file_hash_data.get("provider_file_uuid"),
+ mime_type=file_hash_data.get("mime_type"),
+ fs_metadata=file_hash_data.get("fs_metadata"),
+ file_destination=file_hash_data.get("file_destination"),
+ is_executed=file_hash_data.get("is_executed", False),
+ file_number=file_hash_data.get("file_number"),
+ )
+
+ # Determine if this is an API request
+ is_api = file_hash_data.get("source_connection_type", "") == "API"
+
+ # Use existing manager method
+ file_execution = (
+ WorkflowFileExecution.objects.get_or_create_file_execution(
+ workflow_execution=workflow_execution,
+ file_hash=file_hash,
+ is_api=is_api,
+ )
+ )
+
+ # ROOT CAUSE FIX: Ensure file_path is always present in batch response
+ # The backend model sets file_path to None for API files, but workers require it
+ response_file_path = file_execution.file_path
+ if not response_file_path and file_hash.file_path:
+ response_file_path = file_hash.file_path
+
+ successful_creations.append(
+ {
+ "id": str(file_execution.id),
+ "file_name": file_execution.file_name,
+ "file_path": response_file_path,
+ "status": file_execution.status,
+ }
+ )
+
+ except Exception as e:
+ failed_creations.append(
+ {
+ "file_name": file_execution_data.get("file_hash", {}).get(
+ "file_name", "unknown"
+ ),
+ "error": str(e),
+ }
+ )
+
+ logger.info(
+ f"Batch file execution creation: {len(successful_creations)} successful, {len(failed_creations)} failed"
+ )
+
+ return Response(
+ {
+ "successful_creations": successful_creations,
+ "failed_creations": failed_creations,
+ "total_processed": len(file_executions),
+ },
+ status=status.HTTP_201_CREATED,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to process batch file execution creation: {str(e)}")
+ return Response(
+ {
+ "error": "Failed to process batch file execution creation",
+ "detail": str(e),
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileExecutionBatchStatusUpdateAPIView(APIView):
+ """Internal API endpoint for updating multiple file execution statuses in a single batch."""
+
+ def post(self, request):
+ """Update multiple file execution statuses in a single batch request."""
+ try:
+ status_updates = request.data.get("status_updates", [])
+
+ if not status_updates:
+ return Response(
+ {"error": "status_updates list is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ successful_updates = []
+ failed_updates = []
+
+ with transaction.atomic():
+ for update_data in status_updates:
+ try:
+ file_execution_id = update_data.get("file_execution_id")
+ status_value = update_data.get("status")
+
+ if not file_execution_id or not status_value:
+ failed_updates.append(
+ {
+ "file_execution_id": file_execution_id,
+ "error": "file_execution_id and status are required",
+ }
+ )
+ continue
+
+ # Get file execution with organization filtering
+ base_queryset = WorkflowFileExecution.objects.all()
+ base_queryset = filter_queryset_by_organization(
+ base_queryset,
+ request,
+ "workflow_execution__workflow__organization",
+ )
+
+ try:
+ file_execution = base_queryset.get(id=file_execution_id)
+ except WorkflowFileExecution.DoesNotExist:
+ failed_updates.append(
+ {
+ "file_execution_id": file_execution_id,
+ "error": "WorkflowFileExecution not found",
+ }
+ )
+ continue
+
+ # Update file execution using the model's update_status method
+ file_execution.update_status(
+ status=status_value,
+ execution_error=update_data.get("error_message"),
+ execution_time=update_data.get("execution_time"),
+ )
+
+ successful_updates.append(
+ {
+ "file_execution_id": str(file_execution.id),
+ "status": file_execution.status,
+ "file_name": file_execution.file_name,
+ }
+ )
+
+ except Exception as e:
+ failed_updates.append(
+ {"file_execution_id": file_execution_id, "error": str(e)}
+ )
+
+ logger.info(
+ f"Batch file execution status update: {len(successful_updates)} successful, {len(failed_updates)} failed"
+ )
+
+ return Response(
+ {
+ "successful_updates": successful_updates,
+ "failed_updates": failed_updates,
+ "total_processed": len(status_updates),
+ }
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to process batch file execution status update: {str(e)}"
+ )
+ return Response(
+ {
+ "error": "Failed to process batch file execution status update",
+ "detail": str(e),
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileExecutionBatchHashUpdateAPIView(APIView):
+ """Internal API endpoint for updating multiple file execution hashes in a single batch."""
+
+ def post(self, request):
+ """Update multiple file execution hashes in a single batch request."""
+ try:
+ hash_updates = request.data.get("hash_updates", [])
+
+ if not hash_updates:
+ return Response(
+ {"error": "hash_updates list is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ successful_updates = []
+ failed_updates = []
+
+ with transaction.atomic():
+ for update_data in hash_updates:
+ try:
+ file_execution_id = update_data.get("file_execution_id")
+ file_hash = update_data.get("file_hash")
+
+ if not file_execution_id or not file_hash:
+ failed_updates.append(
+ {
+ "file_execution_id": file_execution_id,
+ "error": "file_execution_id and file_hash are required",
+ }
+ )
+ continue
+
+ # Get file execution with organization filtering
+ base_queryset = WorkflowFileExecution.objects.all()
+ base_queryset = filter_queryset_by_organization(
+ base_queryset,
+ request,
+ "workflow_execution__workflow__organization",
+ )
+
+ try:
+ file_execution = base_queryset.get(id=file_execution_id)
+ except WorkflowFileExecution.DoesNotExist:
+ failed_updates.append(
+ {
+ "file_execution_id": file_execution_id,
+ "error": "WorkflowFileExecution not found",
+ }
+ )
+ continue
+
+ # Update file execution hash using the model's update method
+ file_execution.update(
+ file_hash=file_hash,
+ fs_metadata=update_data.get("fs_metadata"),
+ )
+
+ successful_updates.append(
+ {
+ "file_execution_id": str(file_execution.id),
+ "file_hash": file_hash[:16] + "..."
+ if file_hash
+ else None,
+ "file_name": file_execution.file_name,
+ }
+ )
+
+ except Exception as e:
+ failed_updates.append(
+ {"file_execution_id": file_execution_id, "error": str(e)}
+ )
+
+ logger.info(
+ f"Batch file execution hash update: {len(successful_updates)} successful, {len(failed_updates)} failed"
+ )
+
+ return Response(
+ {
+ "successful_updates": successful_updates,
+ "failed_updates": failed_updates,
+ "total_processed": len(hash_updates),
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to process batch file execution hash update: {str(e)}")
+ return Response(
+ {
+ "error": "Failed to process batch file execution hash update",
+ "detail": str(e),
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileExecutionMetricsAPIView(APIView):
+ """Internal API endpoint for getting file execution metrics."""
+
+ def get(self, request):
+ """Get file execution metrics with optional filtering."""
+ try:
+ # Get query parameters
+ start_date = request.query_params.get("start_date")
+ end_date = request.query_params.get("end_date")
+ workflow_id = request.query_params.get("workflow_id")
+ execution_id = request.query_params.get("execution_id")
+ status = request.query_params.get("status")
+
+ # Build base queryset with organization filtering
+ file_executions = WorkflowFileExecution.objects.all()
+ file_executions = filter_queryset_by_organization(
+ file_executions, request, "workflow_execution__workflow__organization"
+ )
+
+ # Apply filters
+ if start_date:
+ from datetime import datetime
+
+ file_executions = file_executions.filter(
+ created_at__gte=datetime.fromisoformat(start_date)
+ )
+ if end_date:
+ from datetime import datetime
+
+ file_executions = file_executions.filter(
+ created_at__lte=datetime.fromisoformat(end_date)
+ )
+ if workflow_id:
+ file_executions = file_executions.filter(
+ workflow_execution__workflow_id=workflow_id
+ )
+ if execution_id:
+ file_executions = file_executions.filter(
+ workflow_execution_id=execution_id
+ )
+ if status:
+ file_executions = file_executions.filter(status=status)
+
+ # Calculate metrics
+ from django.db.models import Avg, Count, Sum
+
+ total_file_executions = file_executions.count()
+
+ # Status breakdown
+ status_counts = file_executions.values("status").annotate(count=Count("id"))
+ status_breakdown = {item["status"]: item["count"] for item in status_counts}
+
+ # Success rate
+ completed_count = status_breakdown.get("COMPLETED", 0)
+ success_rate = (
+ (completed_count / total_file_executions)
+ if total_file_executions > 0
+ else 0
+ )
+
+ # Average execution time
+ avg_execution_time = (
+ file_executions.aggregate(avg_time=Avg("execution_time"))["avg_time"] or 0
+ )
+
+ # File size statistics
+ total_file_size = (
+ file_executions.aggregate(total_size=Sum("file_size"))["total_size"] or 0
+ )
+
+ avg_file_size = (
+ file_executions.aggregate(avg_size=Avg("file_size"))["avg_size"] or 0
+ )
+
+ metrics = {
+ "total_file_executions": total_file_executions,
+ "status_breakdown": status_breakdown,
+ "success_rate": success_rate,
+ "average_execution_time": avg_execution_time,
+ "total_file_size": total_file_size,
+ "average_file_size": avg_file_size,
+ "filters_applied": {
+ "start_date": start_date,
+ "end_date": end_date,
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "status": status,
+ },
+ }
+
+ logger.info(
+ f"Generated file execution metrics: {total_file_executions} executions, {success_rate:.2%} success rate"
+ )
+
+ return Response(metrics)
+
+ except Exception as e:
+ logger.error(f"Failed to get file execution metrics: {str(e)}")
+ return Response(
+ {"error": "Failed to get file execution metrics", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/workflow_manager/file_execution/models.py b/backend/workflow_manager/file_execution/models.py
index fd75b163f..9a1508cb3 100644
--- a/backend/workflow_manager/file_execution/models.py
+++ b/backend/workflow_manager/file_execution/models.py
@@ -120,32 +120,30 @@ class WorkflowFileExecution(BaseModel):
def update_status(
self,
- status: ExecutionStatus,
+ status: ExecutionStatus | str,
execution_error: str = None,
+ execution_time: float = None,
) -> None:
"""Updates the status and execution details of an input file.
Args:
execution_file: The `WorkflowExecutionFile` object to update
- status: The new status of the file
- execution_time: The execution time for processing the file
+ status: The new status of the file (ExecutionStatus enum or string)
+ execution_time: The execution time for processing the file (optional)
execution_error: (Optional) Error message if processing failed
Return:
The updated `WorkflowExecutionInputFile` object
"""
- self.status = status
-
- if (
- status
- in [
- ExecutionStatus.COMPLETED,
- ExecutionStatus.ERROR,
- ExecutionStatus.STOPPED,
- ]
- and not self.execution_time
- ):
- self.execution_time = CommonUtils.time_since(self.created_at)
+ # Set execution_time if provided, otherwise calculate it for final states
+ status = ExecutionStatus(status)
+ self.status = status.value
+ if status in [
+ ExecutionStatus.COMPLETED,
+ ExecutionStatus.ERROR,
+ ExecutionStatus.STOPPED,
+ ]:
+ self.execution_time = CommonUtils.time_since(self.created_at, 3)
self.execution_error = execution_error
self.save()
@@ -210,6 +208,13 @@ class WorkflowFileExecution(BaseModel):
fields=["workflow_execution", "provider_file_uuid", "file_path"],
name="unique_workflow_provider_uuid_path",
),
+ # CRITICAL FIX: Add constraint for API files where file_path is None
+ # This prevents duplicate entries for same file_hash
+ models.UniqueConstraint(
+ fields=["workflow_execution", "file_hash"],
+ condition=models.Q(file_path__isnull=True),
+ name="unique_workflow_api_file_hash",
+ ),
]
@property
@@ -219,17 +224,20 @@ class WorkflowFileExecution(BaseModel):
Returns:
bool: True if the execution status is completed, False otherwise.
"""
- return self.status is not None and self.status == ExecutionStatus.COMPLETED
+ return self.status is not None and self.status == ExecutionStatus.COMPLETED.value
def update(
self,
file_hash: str = None,
fs_metadata: dict[str, Any] = None,
+ mime_type: str = None,
) -> None:
"""Updates the file execution details.
Args:
file_hash: (Optional) Hash of the file content
+ fs_metadata: (Optional) File system metadata
+ mime_type: (Optional) MIME type of the file
Returns:
None
@@ -242,5 +250,8 @@ class WorkflowFileExecution(BaseModel):
if fs_metadata is not None:
self.fs_metadata = fs_metadata
update_fields.append("fs_metadata")
+ if mime_type is not None:
+ self.mime_type = mime_type
+ update_fields.append("mime_type")
if update_fields: # Save only if there's an actual update
self.save(update_fields=update_fields)
diff --git a/backend/workflow_manager/file_execution/serializers.py b/backend/workflow_manager/file_execution/serializers.py
index 9151d4ddf..38d44b961 100644
--- a/backend/workflow_manager/file_execution/serializers.py
+++ b/backend/workflow_manager/file_execution/serializers.py
@@ -30,9 +30,9 @@ class FileCentricExecutionSerializer(serializers.ModelSerializer):
exclude = ["file_hash"]
def get_status_msg(self, obj: FileExecution) -> dict[str, any] | None:
- if obj.status in [ExecutionStatus.PENDING]:
+ if obj.status in [ExecutionStatus.PENDING.value]:
return self.INIT_STATUS_MSG
- elif obj.status == ExecutionStatus.ERROR:
+ elif obj.status == ExecutionStatus.ERROR.value:
return obj.execution_error
latest_log = (
diff --git a/backend/workflow_manager/internal_api_views.py b/backend/workflow_manager/internal_api_views.py
new file mode 100644
index 000000000..931ba9413
--- /dev/null
+++ b/backend/workflow_manager/internal_api_views.py
@@ -0,0 +1,447 @@
+"""Internal API Views for Worker Communication
+
+This module provides internal API endpoints that workers use to communicate
+with Django backend for database operations only. All business logic has been
+moved to workers.
+
+NOTE: Many sophisticated endpoints are now implemented in internal_views.py
+using class-based views. This file contains simpler function-based views
+for basic operations.
+"""
+
+import logging
+
+from account_v2.models import Organization
+from django.views.decorators.csrf import csrf_exempt
+from rest_framework import status
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from tool_instance_v2.models import ToolInstance
+
+from workflow_manager.workflow_v2.enums import ExecutionStatus
+from workflow_manager.workflow_v2.models import Workflow, WorkflowExecution
+
+logger = logging.getLogger(__name__)
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET"])
+def get_workflow_execution_data(request, execution_id: str):
+ """Get workflow execution data for workers.
+
+ Args:
+ execution_id: Workflow execution ID
+
+ Returns:
+ JSON response with workflow and execution data
+ """
+ try:
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get execution with organization filtering
+ execution = WorkflowExecution.objects.select_related("workflow").get(
+ id=execution_id, workflow__organization_id=org_id
+ )
+
+ workflow = execution.workflow
+
+ # Prepare workflow data
+ workflow_data = {
+ "id": str(workflow.id),
+ "workflow_name": workflow.workflow_name,
+ "execution_details": workflow.execution_details,
+ "organization_id": workflow.organization_id,
+ }
+
+ # Prepare execution data
+ execution_data = {
+ "id": str(execution.id),
+ "status": execution.status,
+ "execution_mode": execution.execution_mode,
+ "execution_method": execution.execution_method,
+ "execution_type": execution.execution_type,
+ "pipeline_id": execution.pipeline_id,
+ "total_files": execution.total_files,
+ "completed_files": execution.completed_files,
+ "failed_files": execution.failed_files,
+ "execution_log_id": execution.execution_log_id, # Include for WebSocket messaging
+ }
+
+ return Response(
+ {
+ "workflow": workflow_data,
+ "execution": execution_data,
+ }
+ )
+
+ except WorkflowExecution.DoesNotExist:
+ return Response(
+ {"error": f"Workflow execution {execution_id} not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Exception as e:
+ logger.error(f"Error getting workflow execution data: {e}")
+ return Response(
+ {"error": "Internal server error"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET"])
+def get_tool_instances_by_workflow(request, workflow_id: str):
+ """Get tool instances for a workflow.
+
+ Args:
+ workflow_id: Workflow ID
+
+ Returns:
+ JSON response with tool instances data
+ """
+ try:
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ logger.error(f"Missing X-Organization-ID header for workflow {workflow_id}")
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ logger.info(f"Getting tool instances for workflow {workflow_id}, org {org_id}")
+
+ # Get tool instances with organization filtering
+ # First check if workflow exists and belongs to organization
+ try:
+ # Get organization object first (org_id is the organization_id string field)
+ logger.info(f"Looking up organization with organization_id: {org_id}")
+ organization = Organization.objects.get(organization_id=org_id)
+ logger.info(
+ f"Found organization: {organization.id} - {organization.display_name}"
+ )
+
+ logger.info(
+ f"Looking up workflow {workflow_id} for organization {organization.id}"
+ )
+ workflow = Workflow.objects.get(id=workflow_id, organization=organization)
+ logger.info(f"Found workflow: {workflow.workflow_name}")
+
+ except Organization.DoesNotExist:
+ logger.error(f"Organization not found: {org_id}")
+ return Response(
+ {"error": f"Organization {org_id} not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Workflow.DoesNotExist:
+ logger.error(f"Workflow {workflow_id} not found for organization {org_id}")
+ return Response(
+ {"error": f"Workflow {workflow_id} not found for organization {org_id}"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Exception as e:
+ logger.error(
+ f"Unexpected error during organization/workflow lookup: {e}",
+ exc_info=True,
+ )
+ return Response(
+ {"error": "Database lookup error", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ # Get tool instances for the workflow
+ tool_instances = ToolInstance.objects.filter(workflow=workflow).order_by("step")
+
+ # Prepare tool instances data
+ instances_data = []
+ for instance in tool_instances:
+ instance_data = {
+ "id": str(instance.id),
+ "tool_id": instance.tool_id,
+ "step": instance.step,
+ "status": instance.status,
+ "version": instance.version,
+ "metadata": instance.metadata,
+ "input": instance.input,
+ "output": instance.output,
+ }
+ instances_data.append(instance_data)
+
+ return Response(
+ {
+ "tool_instances": instances_data,
+ }
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Error getting tool instances for workflow {workflow_id}: {e}", exc_info=True
+ )
+ return Response(
+ {"error": "Internal server error", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def create_file_execution_batch(request):
+ """Create a batch of file executions for workers.
+
+ Returns:
+ JSON response with batch creation result
+ """
+ try:
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ logger.error(
+ "Missing X-Organization-ID header for file execution batch creation"
+ )
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # For now, return a simple response indicating batch creation
+ # This would be expanded based on actual requirements
+ return Response(
+ {
+ "batch_id": "temp-batch-id",
+ "status": "created",
+ "organization_id": org_id,
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error creating file execution batch: {e}", exc_info=True)
+ return Response(
+ {"error": "Internal server error", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def update_file_execution_batch_status(request):
+ """Update file execution batch status for workers.
+
+ Returns:
+ JSON response with batch status update result
+ """
+ try:
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ logger.error(
+ "Missing X-Organization-ID header for file execution batch status update"
+ )
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # For now, return a simple response indicating status update
+ # This would be expanded based on actual requirements
+ return Response(
+ {
+ "status": "updated",
+ "organization_id": org_id,
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error updating file execution batch status: {e}", exc_info=True)
+ return Response(
+ {"error": "Internal server error", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def create_workflow_execution(request):
+ """Create a new workflow execution.
+
+ Returns:
+ JSON response with execution ID
+ """
+ try:
+ data = request.data
+
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get workflow with organization filtering
+ # First get organization object, then lookup workflow
+ try:
+ organization = Organization.objects.get(organization_id=org_id)
+ workflow = Workflow.objects.get(
+ id=data["workflow_id"], organization=organization
+ )
+ except Organization.DoesNotExist:
+ return Response(
+ {"error": f"Organization {org_id} not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Create execution with log_events_id for WebSocket messaging
+ log_events_id = data.get("log_events_id")
+ # If log_events_id not provided, fall back to pipeline_id for backward compatibility
+ execution_log_id = log_events_id if log_events_id else data.get("pipeline_id")
+
+ execution = WorkflowExecution.objects.create(
+ workflow=workflow,
+ pipeline_id=data.get("pipeline_id"),
+ execution_mode=data.get("mode", WorkflowExecution.Mode.INSTANT),
+ execution_method=WorkflowExecution.Method.SCHEDULED
+ if data.get("scheduled")
+ else WorkflowExecution.Method.DIRECT,
+ execution_type=WorkflowExecution.Type.STEP
+ if data.get("single_step")
+ else WorkflowExecution.Type.COMPLETE,
+ status=ExecutionStatus.PENDING.value,
+ total_files=data.get("total_files", 0),
+ execution_log_id=execution_log_id, # Set execution_log_id for WebSocket messaging
+ )
+
+ # Set tags if provided
+ if data.get("tags"):
+ # Handle tags logic if needed
+ pass
+
+ return Response(
+ {
+ "execution_id": str(execution.id),
+ "status": execution.status,
+ "execution_log_id": execution.execution_log_id, # Return for workers to use
+ }
+ )
+
+ except Workflow.DoesNotExist:
+ return Response({"error": "Workflow not found"}, status=status.HTTP_404_NOT_FOUND)
+ except Exception as e:
+ logger.error(f"Error creating workflow execution: {e}")
+ return Response(
+ {"error": "Internal server error"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def compile_workflow(request):
+ """Compile workflow for workers.
+
+ This is a database-only operation that workers need.
+
+ Returns:
+ JSON response with compilation result
+ """
+ try:
+ data = request.data
+ workflow_id = data.get("workflow_id")
+
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # For now, return success since compilation logic needs to be migrated
+ # TODO: Implement actual compilation logic in workers
+
+ return Response(
+ {
+ "success": True,
+ "workflow_id": workflow_id,
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error compiling workflow: {e}")
+ return Response(
+ {"error": "Internal server error"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def submit_file_batch_for_processing(request):
+ """Submit file batch for processing by workers.
+
+ This endpoint receives batch data and returns immediately,
+ as actual processing is handled by Celery workers.
+
+ Returns:
+ JSON response with batch submission status
+ """
+ try:
+ batch_data = request.data
+
+ # Get organization from header
+ org_id = request.headers.get("X-Organization-ID")
+ if not org_id:
+ return Response(
+ {"error": "X-Organization-ID header is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Add organization ID to file_data where WorkerFileData expects it
+ if "file_data" in batch_data:
+ batch_data["file_data"]["organization_id"] = org_id
+ else:
+ # Fallback: add at top level for backward compatibility
+ batch_data["organization_id"] = org_id
+
+ # Submit to file processing worker queue using Celery
+ try:
+ from backend.celery_service import app as celery_app
+
+ # Submit the batch data to the file processing worker using send_task
+ # This calls the task by name without needing to import it
+ task_result = celery_app.send_task(
+ "process_file_batch", # Task name as defined in workers/file_processing/tasks.py
+ args=[batch_data], # Pass batch_data as first argument
+ queue="file_processing", # Send to file processing queue
+ )
+
+ logger.info(
+ f"Successfully submitted file batch {batch_data.get('batch_id')} to worker queue (task: {task_result.id})"
+ )
+
+ return Response(
+ {
+ "success": True,
+ "batch_id": batch_data.get("batch_id"),
+ "celery_task_id": task_result.id,
+ "message": "Batch submitted for processing",
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to submit batch to worker queue: {e}")
+ return Response(
+ {"error": f"Failed to submit batch for processing: {str(e)}"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ except Exception as e:
+ logger.error(f"Error submitting file batch: {e}")
+ return Response(
+ {"error": "Internal server error"},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/workflow_manager/internal_serializers.py b/backend/workflow_manager/internal_serializers.py
new file mode 100644
index 000000000..bed98c685
--- /dev/null
+++ b/backend/workflow_manager/internal_serializers.py
@@ -0,0 +1,220 @@
+"""Workflow Manager Internal API Serializers
+Handles serialization for workflow execution related internal endpoints.
+"""
+
+import logging
+
+from pipeline_v2.models import Pipeline
+from rest_framework import serializers
+
+# Import shared dataclasses for type safety and consistency
+from unstract.core.data_models import (
+ FileExecutionStatusUpdateRequest,
+ WorkflowFileExecutionData,
+)
+from workflow_manager.file_execution.models import WorkflowFileExecution
+from workflow_manager.workflow_v2.enums import ExecutionStatus
+from workflow_manager.workflow_v2.models.execution import WorkflowExecution
+
+logger = logging.getLogger(__name__)
+
+
+class WorkflowExecutionSerializer(serializers.ModelSerializer):
+ """Serializer for WorkflowExecution model for internal API."""
+
+ workflow_id = serializers.CharField(source="workflow.id", read_only=True)
+ workflow_name = serializers.CharField(source="workflow.workflow_name", read_only=True)
+ pipeline_id = serializers.SerializerMethodField()
+ tags = serializers.SerializerMethodField()
+
+ def get_pipeline_id(self, obj):
+ """ROOT CAUSE FIX: Return None for pipeline_id if the referenced pipeline doesn't exist.
+ This prevents callback workers from attempting to update deleted pipelines.
+ PERFORMANCE: Cache pipeline existence to avoid repeated DB queries.
+ """
+ if not obj.pipeline_id:
+ return None
+
+ # Use instance-level cache to avoid repeated DB queries within same request
+ cache_key = f"_pipeline_exists_{obj.pipeline_id}"
+ if hasattr(self, cache_key):
+ return getattr(self, cache_key)
+
+ # Import here to avoid circular imports
+ from api_v2.models import APIDeployment
+
+ try:
+ # First check if it's a Pipeline
+ Pipeline.objects.get(id=obj.pipeline_id)
+ result = str(obj.pipeline_id)
+ setattr(self, cache_key, result)
+ return result
+ except Pipeline.DoesNotExist:
+ # Not a Pipeline, check if it's an APIDeployment
+ try:
+ APIDeployment.objects.get(id=obj.pipeline_id)
+ result = str(obj.pipeline_id)
+ setattr(self, cache_key, result)
+ return result
+ except APIDeployment.DoesNotExist:
+ # Neither Pipeline nor APIDeployment exists - return None to prevent stale reference usage
+ setattr(self, cache_key, None)
+ return None
+
+ def get_tags(self, obj):
+ """Serialize tags as full objects with id, name, and description.
+
+ This method ensures tags are serialized as:
+ [{"id": "uuid", "name": "tag_name", "description": "..."}, ...]
+ instead of just ["uuid1", "uuid2", ...]
+ """
+ try:
+ return [
+ {
+ "id": str(tag.id),
+ "name": tag.name,
+ "description": tag.description or "",
+ }
+ for tag in obj.tags.all()
+ ]
+ except Exception as e:
+ logger.warning(f"Failed to serialize tags for execution {obj.id}: {str(e)}")
+ return []
+
+ class Meta:
+ model = WorkflowExecution
+ fields = [
+ "id",
+ "workflow_id",
+ "workflow_name",
+ "pipeline_id",
+ "task_id",
+ "execution_mode",
+ "execution_method",
+ "execution_type",
+ "execution_log_id",
+ "status",
+ "result_acknowledged",
+ "total_files",
+ "error_message",
+ "attempts",
+ "execution_time",
+ "created_at",
+ "modified_at",
+ "tags",
+ ]
+ read_only_fields = ["id", "created_at", "modified_at"]
+
+
+class WorkflowFileExecutionSerializer(serializers.ModelSerializer):
+ """Serializer for WorkflowFileExecution model for internal API.
+ Enhanced with shared dataclass integration for type safety.
+ """
+
+ workflow_execution_id = serializers.CharField(
+ source="workflow_execution.id", read_only=True
+ )
+
+ class Meta:
+ model = WorkflowFileExecution
+ fields = [
+ "id",
+ "workflow_execution_id",
+ "file_name",
+ "file_path",
+ "file_size",
+ "file_hash",
+ "provider_file_uuid",
+ "mime_type",
+ "fs_metadata",
+ "status",
+ "execution_error",
+ "created_at",
+ "modified_at",
+ ]
+ read_only_fields = ["id", "created_at", "modified_at"]
+
+ def to_dataclass(self, instance=None) -> WorkflowFileExecutionData:
+ """Convert serialized data to shared dataclass."""
+ if instance is None:
+ instance = self.instance
+ return WorkflowFileExecutionData.from_dict(self.to_representation(instance))
+
+ @classmethod
+ def from_dataclass(cls, data: WorkflowFileExecutionData) -> dict:
+ """Convert shared dataclass to serializer-compatible dict."""
+ return data.to_dict()
+
+
+class FileExecutionStatusUpdateSerializer(serializers.Serializer):
+ """Serializer for updating file execution status.
+ Enhanced with shared dataclass integration for type safety.
+ """
+
+ status = serializers.ChoiceField(choices=ExecutionStatus.choices)
+ error_message = serializers.CharField(required=False, allow_blank=True)
+ result = serializers.CharField(required=False, allow_blank=True)
+ execution_time = serializers.FloatField(required=False, min_value=0)
+
+ def to_dataclass(self) -> FileExecutionStatusUpdateRequest:
+ """Convert validated data to shared dataclass."""
+ return FileExecutionStatusUpdateRequest(
+ status=self.validated_data["status"],
+ error_message=self.validated_data.get("error_message"),
+ result=self.validated_data.get("result"),
+ )
+
+ @classmethod
+ def from_dataclass(cls, data: FileExecutionStatusUpdateRequest):
+ """Create serializer from shared dataclass."""
+ return cls(data=data.to_dict())
+
+
+class WorkflowExecutionStatusUpdateSerializer(serializers.Serializer):
+ """Serializer for updating workflow execution status."""
+
+ status = serializers.ChoiceField(choices=ExecutionStatus.choices)
+ error_message = serializers.CharField(required=False, allow_blank=True)
+ total_files = serializers.IntegerField(
+ required=False, min_value=0
+ ) # Allow 0 but backend will only update if > 0
+ attempts = serializers.IntegerField(required=False, min_value=0)
+ execution_time = serializers.FloatField(required=False, min_value=0)
+
+
+class OrganizationContextSerializer(serializers.Serializer):
+ """Serializer for organization context information."""
+
+ organization_id = serializers.CharField(allow_null=True, required=False)
+ organization_name = serializers.CharField(required=False, allow_blank=True)
+ settings = serializers.DictField(required=False)
+
+
+class WorkflowExecutionContextSerializer(serializers.Serializer):
+ """Serializer for complete workflow execution context."""
+
+ execution = WorkflowExecutionSerializer()
+ workflow_definition = serializers.DictField()
+ source_config = serializers.DictField()
+ destination_config = serializers.DictField(required=False)
+ organization_context = OrganizationContextSerializer()
+ file_executions = serializers.ListField(required=False)
+ aggregated_usage_cost = serializers.FloatField(required=False, allow_null=True)
+
+
+class FileBatchCreateSerializer(serializers.Serializer):
+ """Serializer for creating file execution batches."""
+
+ workflow_execution_id = serializers.UUIDField()
+ files = serializers.ListField(child=serializers.DictField(), allow_empty=False)
+ is_api = serializers.BooleanField(default=False)
+
+
+class FileBatchResponseSerializer(serializers.Serializer):
+ """Serializer for file batch creation response."""
+
+ batch_id = serializers.CharField()
+ workflow_execution_id = serializers.CharField()
+ total_files = serializers.IntegerField()
+ created_file_executions = serializers.ListField()
+ skipped_files = serializers.ListField(required=False)
diff --git a/backend/workflow_manager/internal_urls.py b/backend/workflow_manager/internal_urls.py
new file mode 100644
index 000000000..6fac0be62
--- /dev/null
+++ b/backend/workflow_manager/internal_urls.py
@@ -0,0 +1,139 @@
+"""Internal API URLs for Workflow Manager
+
+URLs for internal APIs that workers use to communicate with Django backend.
+These handle only database operations while business logic remains in workers.
+"""
+
+from django.urls import path
+
+from . import internal_api_views, internal_views
+
+app_name = "workflow_manager_internal"
+
+urlpatterns = [
+ # Workflow execution endpoints - specific paths first
+ path(
+ "execution/create/",
+ internal_api_views.create_workflow_execution,
+ name="create_workflow_execution",
+ ),
+ path(
+ "execution/<str:execution_id>/",
+ internal_api_views.get_workflow_execution_data,
+ name="get_workflow_execution_data",
+ ),
+ # Tool instance endpoints
+ path(
+ "workflow/<str:workflow_id>/tool-instances/",
+ internal_api_views.get_tool_instances_by_workflow,
+ name="get_tool_instances_by_workflow",
+ ),
+ # Workflow compilation
+ path(
+ "workflow/compile/",
+ internal_api_views.compile_workflow,
+ name="compile_workflow",
+ ),
+ # File batch processing
+ path(
+ "file-batch/submit/",
+ internal_api_views.submit_file_batch_for_processing,
+ name="submit_file_batch_for_processing",
+ ),
+ # Workflow definition and type detection (using sophisticated class-based views)
+ path(
+ "workflow/<str:workflow_id>/",
+ internal_views.WorkflowDefinitionAPIView.as_view(),
+ name="get_workflow_definition",
+ ),
+ path(
+ "<str:workflow_id>/endpoint/",
+ internal_views.WorkflowEndpointAPIView.as_view(),
+ name="get_workflow_endpoints",
+ ),
+ path(
+ "pipeline-type/<str:pipeline_id>/",
+ internal_views.PipelineTypeAPIView.as_view(),
+ name="get_pipeline_type",
+ ),
+ path(
+ "pipeline-name/<str:pipeline_id>/",
+ internal_views.PipelineNameAPIView.as_view(),
+ name="get_pipeline_name",
+ ),
+ # Batch operations (using sophisticated class-based views)
+ path(
+ "batch-status-update/",
+ internal_views.BatchStatusUpdateAPIView.as_view(),
+ name="batch_update_execution_status",
+ ),
+ path(
+ "file-batch/",
+ internal_views.FileBatchCreateAPIView.as_view(),
+ name="create_file_batch",
+ ),
+ # File management (using sophisticated class-based views)
+ path(
+ "increment-files/",
+ internal_views.FileCountIncrementAPIView.as_view(),
+ name="increment_files",
+ ),
+ path(
+ "file-history/create/",
+ internal_views.FileHistoryCreateView.as_view(),
+ name="create_file_history_entry",
+ ),
+ path(
+ "file-history/check-batch/",
+ internal_views.FileHistoryBatchCheckView.as_view(),
+ name="check_file_history_batch",
+ ),
+ # Additional endpoints available in internal_views.py
+ path(
+ "source-files/<str:workflow_id>/",
+ internal_views.WorkflowSourceFilesAPIView.as_view(),
+ name="get_workflow_source_files",
+ ),
+ # path("execution/finalize/<str:execution_id>/", removed - ExecutionFinalizationAPIView was unused dead code
+ path(
+ "execution/cleanup/",
+ internal_views.WorkflowExecutionCleanupAPIView.as_view(),
+ name="cleanup_executions",
+ ),
+ path(
+ "execution/metrics/",
+ internal_views.WorkflowExecutionMetricsAPIView.as_view(),
+ name="get_execution_metrics",
+ ),
+ path(
+ "file-execution/",
+ internal_views.WorkflowFileExecutionAPIView.as_view(),
+ name="workflow_file_execution",
+ ),
+ path(
+ "file-execution/check-active",
+ internal_views.WorkflowFileExecutionCheckActiveAPIView.as_view(),
+ name="workflow_file_execution_check_active",
+ ),
+ path(
+ "execute-file/",
+ internal_views.WorkflowExecuteFileAPIView.as_view(),
+ name="execute_workflow_file",
+ ),
+ path(
+ "pipeline/<str:pipeline_id>/status/",
+ internal_views.PipelineStatusUpdateAPIView.as_view(),
+ name="update_pipeline_status",
+ ),
+ # File execution batch operations (using simple function views for now)
+ path(
+ "file-execution/batch-create/",
+ internal_api_views.create_file_execution_batch,
+ name="file_execution_batch_create",
+ ),
+ path(
+ "file-execution/batch-status-update/",
+ internal_api_views.update_file_execution_batch_status,
+ name="file_execution_batch_status_update",
+ ),
+]
diff --git a/backend/workflow_manager/internal_views.py b/backend/workflow_manager/internal_views.py
new file mode 100644
index 000000000..4923e7100
--- /dev/null
+++ b/backend/workflow_manager/internal_views.py
@@ -0,0 +1,2633 @@
+"""Workflow Manager Internal API Views
+Handles workflow execution related endpoints for internal services.
+"""
+
+import logging
+import uuid
+
+from django.core.cache import cache
+from django.db import transaction
+from django.shortcuts import get_object_or_404
+from django.utils import timezone
+from rest_framework import status, viewsets
+from rest_framework.decorators import action
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from tool_instance_v2.models import ToolInstance
+from utils.constants import Account
+from utils.local_context import StateStore
+from utils.organization_utils import filter_queryset_by_organization
+
+# Import new dataclasses for WorkflowDefinitionAPIView
+from unstract.core.data_models import (
+ ConnectionType,
+ ConnectorInstanceData,
+ WorkflowDefinitionResponseData,
+ WorkflowEndpointConfigData,
+ WorkflowEndpointConfigResponseData,
+)
+from workflow_manager.endpoint_v2.endpoint_utils import WorkflowEndpointUtils
+from workflow_manager.endpoint_v2.models import WorkflowEndpoint
+from workflow_manager.file_execution.models import WorkflowFileExecution
+from workflow_manager.workflow_v2.models.execution import WorkflowExecution
+from workflow_manager.workflow_v2.models.workflow import Workflow
+
+from .internal_serializers import (
+ FileBatchCreateSerializer,
+ FileBatchResponseSerializer,
+ WorkflowExecutionContextSerializer,
+ WorkflowExecutionSerializer,
+ WorkflowExecutionStatusUpdateSerializer,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class WorkflowExecutionInternalViewSet(viewsets.ReadOnlyModelViewSet):
+ """Internal API ViewSet for Workflow Execution operations.
+ Provides workflow execution CRUD operations for internal services.
+ """
+
+ serializer_class = WorkflowExecutionSerializer
+ lookup_field = "id"
+
+ def get_queryset(self):
+ """Get workflow executions filtered by organization context."""
+ queryset = WorkflowExecution.objects.select_related("workflow").prefetch_related(
+ "tags"
+ )
+ return filter_queryset_by_organization(
+ queryset, self.request, "workflow__organization"
+ )
+
+ def list(self, request, *args, **kwargs):
+ """List workflow executions with proper query parameter filtering."""
+ try:
+ # Start with organization-filtered queryset
+ queryset = self.get_queryset()
+
+ # Apply query parameter filters
+ workflow_id = request.query_params.get("workflow_id")
+ if workflow_id:
+ queryset = queryset.filter(workflow_id=workflow_id)
+
+ status_filter = request.query_params.get("status__in")
+ if status_filter:
+ # Handle comma-separated status values
+ statuses = [s.strip() for s in status_filter.split(",")]
+ queryset = queryset.filter(status__in=statuses)
+
+ # Apply any other filters
+ status = request.query_params.get("status")
+ if status:
+ queryset = queryset.filter(status=status)
+
+ # Order by creation time (newest first) for consistent results
+ queryset = queryset.order_by("-created_at")
+
+ # Serialize the filtered queryset
+ serializer = self.get_serializer(queryset, many=True)
+
+ logger.info(
+ f"WorkflowExecution list: returned {len(serializer.data)} executions"
+ )
+ logger.debug(
+ f"Applied filters - workflow_id: {workflow_id}, status__in: {status_filter}, status: {status}"
+ )
+
+ return Response(serializer.data)
+
+ except Exception as e:
+ logger.error(f"Error in WorkflowExecution list: {str(e)}")
+ return Response(
+ {"error": "Failed to list workflow executions", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def retrieve(self, request, *args, **kwargs):
+ """Get specific workflow execution with context."""
+ try:
+ execution = self.get_object()
+
+ # Check if cost data is requested (expensive operation)
+ include_cost = request.GET.get("include_cost", "false").lower() == "true"
+ file_execution = request.GET.get("file_execution", "true").lower() == "true"
+
+ # Build comprehensive context
+ workflow_definition = {}
+ if execution.workflow:
+ workflow_definition = {
+ "workflow_id": str(execution.workflow.id),
+ "workflow_name": execution.workflow.workflow_name,
+ "workflow_type": execution.workflow.deployment_type,
+ "description": execution.workflow.description,
+ "source_settings": execution.workflow.source_settings or {},
+ "destination_settings": execution.workflow.destination_settings or {},
+ "is_active": execution.workflow.is_active,
+ "status": execution.workflow.status,
+ }
+
+ context_data = {
+ "execution": execution, # Pass model instance, not serialized data
+ "workflow_definition": workflow_definition,
+ "source_config": self._get_source_config(execution),
+ "destination_config": self._get_destination_config(execution),
+ "organization_context": self._get_organization_context(execution),
+ "file_executions": list(execution.file_executions.values())
+ if file_execution
+ else [],
+ }
+
+ # Only calculate cost if explicitly requested (expensive database operation)
+ if include_cost:
+ context_data["aggregated_usage_cost"] = execution.aggregated_usage_cost
+
+ serializer = WorkflowExecutionContextSerializer(context_data)
+ return Response(serializer.data)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to retrieve workflow execution {kwargs.get('id')}: {str(e)}"
+ )
+ return Response(
+ {"error": "Failed to retrieve workflow execution", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _get_source_config(self, execution: WorkflowExecution) -> dict:
+ """Get source configuration for execution with connector instance details."""
+ try:
+ workflow = execution.workflow
+ if not workflow:
+ logger.warning(f"No workflow found for execution {execution.id}")
+ return {}
+
+ # Get workflow-level source settings
+ source_settings = {}
+ workflow_type = "general_workflow"
+ is_api = False
+
+ if execution.pipeline_id:
+ # Check if pipeline_id references a Pipeline or APIDeployment (like serializer)
+ from api_v2.models import APIDeployment
+ from pipeline_v2.models import Pipeline
+
+ try:
+ # First check if it's a Pipeline
+ pipeline = Pipeline.objects.get(id=execution.pipeline_id)
+ source_settings = pipeline.workflow.source_settings or {}
+ workflow_type = "pipeline"
+ is_api = False
+ logger.debug(
+ f"Pipeline {execution.pipeline_id} source settings: {bool(source_settings)}"
+ )
+ except Pipeline.DoesNotExist:
+ # Check if it's an APIDeployment (like serializer does)
+ try:
+ api_deployment = APIDeployment.objects.get(
+ id=execution.pipeline_id
+ )
+ source_settings = workflow.source_settings or {}
+ workflow_type = "api_deployment"
+ is_api = True
+ logger.debug(
+ f"APIDeployment {execution.pipeline_id} found for execution {execution.id}"
+ )
+ except APIDeployment.DoesNotExist:
+ # Neither Pipeline nor APIDeployment exists
+ logger.warning(
+ f"Neither Pipeline nor APIDeployment found for ID {execution.pipeline_id} in execution {execution.id}"
+ )
+ source_settings = workflow.source_settings or {}
+ workflow_type = "pipeline_not_found"
+ else:
+ # API deployment or general workflow execution
+ source_settings = workflow.source_settings or {}
+ if (
+ workflow
+ and hasattr(workflow, "api_deployments")
+ and workflow.api_deployments.filter(is_active=True).exists()
+ ):
+ workflow_type = "api_deployment"
+ is_api = True
+ logger.debug(
+ f"Workflow {workflow.id} source settings: {bool(source_settings)}"
+ )
+
+ # Get source connector instance from workflow endpoints
+ from workflow_manager.endpoint_v2.models import WorkflowEndpoint
+
+ source_connector_data = None
+ try:
+ # Look for source endpoint with connector instance
+ source_endpoint = (
+ WorkflowEndpoint.objects.select_related("connector_instance")
+ .filter(
+ workflow=workflow,
+ endpoint_type=WorkflowEndpoint.EndpointType.SOURCE,
+ )
+ .first()
+ )
+
+ if source_endpoint and source_endpoint.connector_instance:
+ source_connector_instance = source_endpoint.connector_instance
+ source_connector_data = {
+ "connector_id": source_connector_instance.connector_id,
+ "connector_settings": source_connector_instance.metadata or {},
+ "connector_name": getattr(
+ source_connector_instance, "connector_name", ""
+ ),
+ }
+ logger.debug(
+ f"Found source connector instance: {source_connector_instance.connector_id}"
+ )
+
+ # Include endpoint configuration in source settings
+ if source_endpoint.configuration:
+ source_settings.update(source_endpoint.configuration)
+ else:
+ logger.debug("No source connector instance found for workflow")
+
+ except Exception as source_error:
+ logger.warning(
+ f"Failed to get source connector info for workflow {workflow.id}: {str(source_error)}"
+ )
+
+ # Build comprehensive source config
+ source_config = {
+ "type": workflow_type,
+ "source_settings": source_settings,
+ "is_api": is_api,
+ }
+
+ # Add pipeline/deployment specific info
+ if execution.pipeline_id and workflow_type != "pipeline_not_found":
+ source_config["pipeline_id"] = str(execution.pipeline_id)
+ elif workflow_type == "api_deployment":
+ api_deployment = workflow.api_deployments.first()
+ if api_deployment:
+ source_config["deployment_id"] = str(api_deployment.id)
+
+ # Add source connector instance data if available
+ if source_connector_data:
+ source_config.update(source_connector_data)
+ logger.debug("Added source connector instance data to source config")
+
+ return source_config
+
+ except Exception as e:
+ logger.warning(
+ f"Failed to get source config for execution {execution.id}: {str(e)}"
+ )
+ return {}
+
+ def _get_destination_config(self, execution: WorkflowExecution) -> dict:
+ """Get destination configuration for execution with connector instance details."""
+ try:
+ workflow = execution.workflow
+ if not workflow:
+ logger.warning(f"No workflow found for execution {execution.id}")
+ return {}
+
+ # Get destination settings from workflow
+ destination_settings = {}
+ if execution.pipeline_id:
+ # ETL/Task pipeline execution - get settings from pipeline's workflow
+ from pipeline_v2.models import Pipeline
+
+ try:
+ pipeline = Pipeline.objects.get(id=execution.pipeline_id)
+ destination_settings = pipeline.workflow.destination_settings or {}
+ logger.debug(
+ f"Pipeline {execution.pipeline_id} destination settings: {bool(destination_settings)}"
+ )
+ except Pipeline.DoesNotExist:
+ logger.warning(
+ f"Pipeline {execution.pipeline_id} not found for execution {execution.id}"
+ )
+ destination_settings = workflow.destination_settings or {}
+ else:
+ # API deployment or general workflow execution
+ destination_settings = workflow.destination_settings or {}
+ logger.debug(
+ f"Workflow {workflow.id} destination settings: {bool(destination_settings)}"
+ )
+
+ # Get connection type and connector instance from workflow endpoints
+ from workflow_manager.endpoint_v2.models import WorkflowEndpoint
+
+ connection_type = "FILESYSTEM" # Default
+ is_api = False
+ connector_instance_data = None
+
+ try:
+ # Look for destination endpoint with connector instance
+ dest_endpoint = (
+ WorkflowEndpoint.objects.select_related("connector_instance")
+ .filter(
+ workflow=workflow,
+ endpoint_type=WorkflowEndpoint.EndpointType.DESTINATION,
+ )
+ .first()
+ )
+
+ if dest_endpoint:
+ connection_type = dest_endpoint.connection_type or "FILESYSTEM"
+ is_api = connection_type in ["API", "APPDEPLOYMENT"]
+
+ # Include connector instance details if available
+ if dest_endpoint.connector_instance:
+ connector_instance = dest_endpoint.connector_instance
+ connector_instance_data = {
+ "connector_id": connector_instance.connector_id,
+ "connector_settings": connector_instance.metadata or {},
+ "connector_name": getattr(
+ connector_instance, "connector_name", ""
+ ),
+ }
+ logger.debug(
+ f"Found connector instance: {connector_instance.connector_id}"
+ )
+
+ # Include endpoint configuration
+ if dest_endpoint.configuration:
+ destination_settings.update(dest_endpoint.configuration)
+
+ logger.debug(
+ f"Found destination endpoint: {connection_type}, is_api: {is_api}"
+ )
+ else:
+ # Check if workflow has API deployments
+ if (
+ hasattr(workflow, "api_deployments")
+ and workflow.api_deployments.filter(is_active=True).exists()
+ ):
+ connection_type = "API"
+ is_api = True
+ logger.debug(
+ "Workflow has active API deployments, treating as API destination"
+ )
+
+ except Exception as endpoint_error:
+ logger.warning(
+ f"Failed to get endpoint info for workflow {workflow.id}: {str(endpoint_error)}"
+ )
+
+ # Get source connector information for file reading in manual review
+ source_connector_data = None
+ try:
+ # Look for source endpoint with connector instance
+ source_endpoint = (
+ WorkflowEndpoint.objects.select_related("connector_instance")
+ .filter(
+ workflow=workflow,
+ endpoint_type=WorkflowEndpoint.EndpointType.SOURCE,
+ )
+ .first()
+ )
+
+ if source_endpoint and source_endpoint.connector_instance:
+ source_connector_instance = source_endpoint.connector_instance
+ source_connector_data = {
+ "source_connector_id": source_connector_instance.connector_id,
+ "source_connector_settings": source_connector_instance.metadata
+ or {},
+ }
+ logger.debug(
+ f"Found source connector instance: {source_connector_instance.connector_id}"
+ )
+ else:
+ logger.debug("No source connector instance found for workflow")
+
+ except Exception as source_error:
+ logger.warning(
+ f"Failed to get source connector info for workflow {workflow.id}: {str(source_error)}"
+ )
+
+ # Build comprehensive destination config
+ destination_config = {
+ "connection_type": connection_type,
+ "settings": destination_settings,
+ "is_api": is_api,
+ "use_file_history": True,
+ }
+
+ # Add connector instance data if available
+ if connector_instance_data:
+ destination_config.update(connector_instance_data)
+ logger.debug("Added connector instance data to destination config")
+ else:
+ logger.debug("No connector instance found for destination endpoint")
+
+ # Add source connector data for manual review file reading
+ if source_connector_data:
+ destination_config.update(source_connector_data)
+ logger.debug(
+ "Added source connector data to destination config for manual review"
+ )
+
+ return destination_config
+
+ except Exception as e:
+ logger.warning(
+ f"Failed to get destination config for execution {execution.id}: {str(e)}"
+ )
+ return {}
+
+ def _get_organization_context(self, execution: WorkflowExecution) -> dict:
+ """Get organization context for execution."""
+ try:
+ # Get organization from the workflow, not directly from execution
+ if execution.workflow and hasattr(execution.workflow, "organization"):
+ org = execution.workflow.organization
+ return {
+ "organization_id": str(org.id),
+ "organization_name": org.display_name,
+ "settings": {}, # Add organization-specific settings if needed
+ }
+ else:
+ logger.warning(f"No organization found for execution {execution.id}")
+ return {
+ "organization_id": None,
+ "organization_name": "Unknown",
+ "settings": {},
+ }
+ except Exception as e:
+ logger.warning(
+ f"Failed to get organization context for execution {execution.id}: {str(e)}"
+ )
+ return {
+ "organization_id": None,
+ "organization_name": "Unknown",
+ "settings": {},
+ }
+
+ @action(detail=True, methods=["post"])
+ def update_status(self, request, id=None):
+ """Update workflow execution status."""
+ try:
+ logger.info(f"Updating status for execution {id}")
+ execution = self.get_object()
+ serializer = WorkflowExecutionStatusUpdateSerializer(data=request.data)
+
+ if serializer.is_valid():
+ validated_data = serializer.validated_data
+
+ # FIXED: Use update_execution() method for proper wall-clock time calculation
+ # This replaces manual field setting which bypassed execution time logic
+
+ # Handle error message truncation before calling update_execution
+ error_message = None
+ if validated_data.get("error_message"):
+ error_msg = validated_data["error_message"]
+ if len(error_msg) > 256:
+ error_message = error_msg[:253] + "..."
+ logger.warning(
+ f"Error message truncated for execution {id} (original length: {len(error_msg)})"
+ )
+ else:
+ error_message = error_msg
+
+ # Handle attempts increment
+ increment_attempt = (
+ validated_data.get("attempts") is not None
+ and validated_data.get("attempts") > execution.attempts
+ )
+
+ # Use the model's update_execution method for proper wall-clock calculation
+ from workflow_manager.workflow_v2.enums import ExecutionStatus
+
+ status_enum = ExecutionStatus(validated_data["status"])
+ execution.update_execution(
+ status=status_enum,
+ error=error_message,
+ increment_attempt=increment_attempt,
+ )
+
+ # Update total_files separately (not handled by update_execution)
+ if validated_data.get("total_files") is not None:
+ execution.total_files = validated_data["total_files"]
+ execution.save()
+
+ logger.info(
+ f"Updated workflow execution {id} status to {validated_data['status']}"
+ )
+
+ return Response(
+ {
+ "status": "updated",
+ "execution_id": str(execution.id),
+ "new_status": execution.status,
+ }
+ )
+
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ except Exception as e:
+ logger.error(f"Failed to update workflow execution status {id}: {str(e)}")
+ return Response(
+ {"error": "Failed to update workflow execution status", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileBatchCreateAPIView(APIView):
+ """Internal API endpoint for creating file batches for workflow execution."""
+
+ def post(self, request):
+ """Create file execution records in batches."""
+ try:
+ serializer = FileBatchCreateSerializer(data=request.data)
+
+ if not serializer.is_valid():
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ validated_data = serializer.validated_data
+ workflow_execution_id = validated_data["workflow_execution_id"]
+ files = validated_data["files"]
+ is_api = validated_data.get("is_api", False)
+
+ # Get workflow execution
+ workflow_execution = get_object_or_404(
+ WorkflowExecution, id=workflow_execution_id
+ )
+
+ created_files = []
+ skipped_files = []
+ batch_id = uuid.uuid4()
+
+ with transaction.atomic():
+ for file_data in files:
+ try:
+ # Create file execution record
+ file_execution = WorkflowFileExecution.objects.create(
+ id=uuid.uuid4(),
+ workflow_execution=workflow_execution,
+ file_name=file_data.get("file_name", ""),
+ file_path=file_data.get("file_path", ""),
+ file_size=file_data.get("file_size", 0),
+ file_hash=file_data.get("file_hash", ""),
+ provider_file_uuid=file_data.get("provider_file_uuid", ""),
+ mime_type=file_data.get("mime_type", ""),
+ fs_metadata=file_data.get("fs_metadata", {}),
+ status="PENDING",
+ )
+
+ created_files.append(
+ {
+ "id": str(file_execution.id),
+ "file_name": file_execution.file_name,
+ "status": file_execution.status,
+ }
+ )
+
+ except Exception as file_error:
+ logger.warning(
+ f"Failed to create file execution for {file_data.get('file_name')}: {file_error}"
+ )
+ skipped_files.append(
+ {
+ "file_name": file_data.get("file_name", "unknown"),
+ "error": str(file_error),
+ }
+ )
+
+ response_data = {
+ "batch_id": batch_id,
+ "workflow_execution_id": workflow_execution_id,
+ "total_files": len(files),
+ "created_file_executions": created_files,
+ "skipped_files": skipped_files,
+ "is_api": is_api,
+ }
+
+ response_serializer = FileBatchResponseSerializer(response_data)
+
+ logger.info(
+ f"Created file batch {batch_id} with {len(created_files)} files for execution {workflow_execution_id}"
+ )
+
+ return Response(response_serializer.data, status=status.HTTP_201_CREATED)
+
+ except Exception as e:
+ logger.error(f"Failed to create file batch: {str(e)}")
+ return Response(
+ {"error": "Failed to create file batch", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class ToolExecutionInternalAPIView(APIView):
+ """Internal API endpoint for tool execution operations."""
+
+ def get(self, request, workflow_id):
+ """Get tool instances for a workflow."""
+ try:
+ # Get workflow with automatic organization filtering (via DefaultOrganizationManagerMixin)
+ try:
+ # This will automatically apply organization filtering via DefaultOrganizationManagerMixin
+ workflow = Workflow.objects.get(id=workflow_id)
+ logger.debug(f"Found workflow {workflow_id} for tool instances request")
+ except Workflow.DoesNotExist:
+ logger.error(f"Workflow {workflow_id} not found or not accessible")
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get tool instances for the workflow with organization filtering
+ # Filter through the relationship: ToolInstance -> Workflow -> Organization
+ tool_instances_queryset = ToolInstance.objects.filter(workflow=workflow)
+ tool_instances_queryset = filter_queryset_by_organization(
+ tool_instances_queryset, request, "workflow__organization"
+ )
+ tool_instances = tool_instances_queryset.order_by("step")
+
+ instances_data = []
+ for tool_instance in tool_instances:
+ instances_data.append(
+ {
+ "id": str(tool_instance.id),
+ "tool_id": str(tool_instance.tool_id)
+ if tool_instance.tool_id
+ else None,
+ "step": tool_instance.step,
+ "tool_settings": tool_instance.metadata or {},
+ "created_at": tool_instance.created_at.isoformat()
+ if tool_instance.created_at
+ else None,
+ "modified_at": tool_instance.modified_at.isoformat()
+ if tool_instance.modified_at
+ else None,
+ }
+ )
+
+ response_data = {
+ "workflow_id": workflow_id,
+ "tool_instances": instances_data,
+ "total_instances": len(instances_data),
+ }
+
+ logger.info(
+ f"Retrieved {len(instances_data)} tool instances for workflow {workflow_id}"
+ )
+ return Response(response_data)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get tool instances for workflow {workflow_id}: {str(e)}"
+ )
+ return Response(
+ {"error": "Failed to get tool instances", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+# ExecutionFinalizationAPIView class removed - it was unused dead code
+# Workers now use simple update_workflow_execution_status instead of complex finalization
+# This eliminates unnecessary API complexity and improves callback performance
+
+
+class WorkflowFileExecutionCheckActiveAPIView(APIView):
+ """Internal API for checking if files are actively being processed."""
+
+ def post(self, request):
+ """Check if files are in PENDING or EXECUTING state in other workflow executions."""
+ try:
+ workflow_id = request.data.get("workflow_id")
+ # Support both legacy and new formats
+ provider_file_uuids = request.data.get(
+ "provider_file_uuids", []
+ ) # Legacy format
+ files = request.data.get("files", []) # New format: [{uuid, path}]
+ current_execution_id = request.data.get("current_execution_id")
+
+ # Convert legacy format to new format for backward compatibility
+ if provider_file_uuids and not files:
+ files = [{"uuid": uuid, "path": None} for uuid in provider_file_uuids]
+ elif files:
+ # Ensure files have required fields
+ for file_data in files:
+ if "uuid" not in file_data:
+ return Response(
+ {"error": "Each file must have 'uuid' field"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ if not workflow_id or not files:
+ return Response(
+ {
+ "error": "workflow_id and files (or provider_file_uuids) are required"
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ logger.info(
+ f"Checking active files for workflow {workflow_id}, "
+ f"excluding execution {current_execution_id}, "
+ f"checking {len(files)} files"
+ )
+
+ # Check for files in PENDING or EXECUTING state in other workflow executions
+ active_files = {} # {uuid: [execution_data]} - legacy format
+ active_identifiers = set() # Composite identifiers for new format
+ cache_hits = 0
+ db_queries = 0
+
+ # Step 1: Check cache for all files and separate files that need database queries
+ files_needing_db_check = []
+
+ for file_data in files:
+ provider_uuid = file_data["uuid"]
+ file_path = file_data.get("path")
+ composite_id = (
+ f"{provider_uuid}:{file_path}" if file_path else provider_uuid
+ )
+
+ # 1. Check completion cache first (highest priority)
+ completion_key = f"file_completed:{workflow_id}:{provider_uuid}"
+ completion_data = cache.get(completion_key)
+
+ if completion_data:
+ logger.debug(
+ f"File {provider_uuid} found in completion cache, skipping"
+ )
+ continue # Skip - recently completed
+
+ # 2. Check active processing cache (path-aware)
+ cached_active = None
+
+ if file_path is not None:
+ # Use precise path-aware cache key
+ active_key = f"file_active:{workflow_id}:{provider_uuid}:{file_path}"
+ cached_active = cache.get(active_key)
+ if cached_active:
+ logger.debug(
+ f"File {provider_uuid}:{file_path} found in path-aware cache"
+ )
+ else:
+ # No file path available, skip cache check for files without path
+ cached_active = None
+
+ if cached_active:
+ # Verify it's not the current execution
+ if cached_active.get("execution_id") != current_execution_id:
+ # Track in both formats
+ active_files[provider_uuid] = [cached_active]
+ active_identifiers.add(composite_id)
+ cache_hits += 1
+ logger.debug(f"File {composite_id} found in active cache")
+ continue
+
+ # File needs database check - add to batch
+ files_needing_db_check.append(
+ {
+ "uuid": provider_uuid,
+ "path": file_path,
+ "composite_id": composite_id,
+ }
+ )
+
+ # Step 2: Bulk database queries for all files that need database check
+ if files_needing_db_check:
+ logger.info(
+ f"[ActiveCheck] Performing bulk database check for {len(files_needing_db_check)} files"
+ )
+ self._bulk_database_check(
+ files_needing_db_check=files_needing_db_check,
+ workflow_id=workflow_id,
+ current_execution_id=current_execution_id,
+ active_files=active_files,
+ active_identifiers=active_identifiers,
+ )
+ db_queries = 2 # At most 2 bulk queries (path-aware + legacy)
+
+ logger.info(
+ f"[ActiveCheck] Active check complete: {len(active_files)}/{len(files)} files active "
+ f"(cache_hits: {cache_hits}, db_queries: {db_queries})"
+ )
+
+ # Log final active identifiers for debugging
+ if active_identifiers:
+ logger.debug(
+ f"[ActiveCheck] Active identifiers: {sorted(active_identifiers)}"
+ )
+ else:
+ logger.debug("[ActiveCheck] No files are currently active")
+
+ return Response(
+ {
+ "active_files": active_files, # Legacy format: {uuid: [execution_data]}
+ "active_uuids": list(
+ active_files.keys()
+ ), # Legacy format: [uuid1, uuid2]
+ "active_identifiers": list(
+ active_identifiers
+ ), # New format: ["uuid:path", "uuid2:path2"]
+ "total_checked": len(files),
+ "total_active": len(active_files),
+ "cache_stats": {
+ "cache_hits": cache_hits,
+ "db_queries": db_queries,
+ "cache_hit_rate": f"{(cache_hits / len(files) * 100):.1f}%"
+ if files
+ else "0.0%",
+ },
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error checking active files: {str(e)}", exc_info=True)
+ return Response(
+ {"error": "Failed to check active files", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _bulk_database_check(
+ self,
+ files_needing_db_check: list[dict],
+ workflow_id: str,
+ current_execution_id: str | None,
+ active_files: dict,
+ active_identifiers: set,
+ ):
+ """Perform bulk database queries instead of individual queries for each file."""
+ if not files_needing_db_check:
+ return
+
+ # Separate files by query type
+ path_aware_files = [f for f in files_needing_db_check if f["path"] is not None]
+ legacy_files = [f for f in files_needing_db_check if f["path"] is None]
+
+ logger.debug(
+ f"[ActiveCheck] Querying {len(path_aware_files)} path-aware, "
+ f"{len(legacy_files)} UUID-only files"
+ )
+
+ # Query 1: Bulk query for path-aware files
+ if path_aware_files:
+ self._bulk_query_path_aware(
+ path_aware_files,
+ workflow_id,
+ current_execution_id,
+ active_files,
+ active_identifiers,
+ )
+
+ # Query 2: Bulk query for UUID-only files
+ if legacy_files:
+ self._bulk_query_uuid_only(
+ legacy_files,
+ workflow_id,
+ current_execution_id,
+ active_files,
+ active_identifiers,
+ )
+
+ def _bulk_query_path_aware(
+ self,
+ path_aware_files: list[dict],
+ workflow_id: str,
+ current_execution_id: str | None,
+ active_files: dict,
+ active_identifiers: set,
+ ):
+ """Bulk query for files with specific paths using two-step workflow scoping."""
+ from django.db.models import Q
+
+ # Step 1: Get ACTIVE workflow executions for this workflow
+ active_workflow_executions = WorkflowExecution.objects.filter(
+ workflow_id=workflow_id, status__in=["PENDING", "EXECUTING"]
+ )
+
+ if current_execution_id:
+ active_workflow_executions = active_workflow_executions.exclude(
+ id=current_execution_id
+ )
+
+ active_execution_ids = list(
+ active_workflow_executions.values_list("id", flat=True)
+ )
+
+ if not active_execution_ids:
+ logger.debug(
+ "[ActiveCheck] No active workflow executions found, path-aware query returns 0 results"
+ )
+ return
+
+ # Step 2: Build OR conditions for file matching: (uuid1 AND path1) OR (uuid2 AND path2) OR ...
+ path_conditions = Q()
+ for file_info in path_aware_files:
+ path_conditions |= Q(
+ provider_file_uuid=file_info["uuid"], file_path=file_info["path"]
+ )
+
+ # Step 3: Execute bulk query on workflow_file_executions from active workflow executions only
+ query = WorkflowFileExecution.objects.filter(
+ workflow_execution_id__in=active_execution_ids, # Scoped to active workflow executions
+ status__in=["PENDING", "EXECUTING"], # File execution must also be active
+ ).filter(path_conditions)
+
+ active_executions = query.values(
+ "id",
+ "workflow_execution_id",
+ "file_name",
+ "file_path",
+ "status",
+ "created_at",
+ "provider_file_uuid",
+ )
+
+ logger.info(
+ f"[ActiveCheck] Path-aware query found {active_executions.count()} active records"
+ )
+
+ # Map results back to files with validation
+ for record in active_executions:
+ provider_uuid = record["provider_file_uuid"]
+ file_path = record["file_path"]
+ composite_id = f"{provider_uuid}:{file_path}"
+ execution_id = record["workflow_execution_id"]
+
+ # Validation: Ensure this execution ID is in our expected active executions list
+ if execution_id not in active_execution_ids:
+ logger.error(
+ f"[ActiveCheck] VALIDATION ERROR: Found file execution {record['id']} "
+ f"with workflow_execution_id {execution_id} that's not in our active executions list!"
+ )
+ continue
+
+ logger.debug(
+ f"[ActiveCheck] Active record {record['id']}: "
+ f"uuid={provider_uuid[:8]}..., status={record['status']}, "
+ f"path={file_path}, workflow_execution={execution_id} ✓"
+ )
+
+ # Track in both formats
+ if provider_uuid not in active_files:
+ active_files[provider_uuid] = []
+ active_files[provider_uuid].append(dict(record))
+ active_identifiers.add(composite_id)
+
+ logger.debug(f"[ActiveCheck] File {composite_id} is actively being processed")
+
+ def _bulk_query_uuid_only(
+ self,
+ legacy_files: list[dict],
+ workflow_id: str,
+ current_execution_id: str | None,
+ active_files: dict,
+ active_identifiers: set,
+ ):
+ """Bulk query for UUID-only files (no path available) using two-step workflow scoping."""
+ # Step 1: Get ACTIVE workflow executions for this workflow
+ active_workflow_executions = WorkflowExecution.objects.filter(
+ workflow_id=workflow_id, status__in=["PENDING", "EXECUTING"]
+ )
+
+ if current_execution_id:
+ active_workflow_executions = active_workflow_executions.exclude(
+ id=current_execution_id
+ )
+
+ active_execution_ids = list(
+ active_workflow_executions.values_list("id", flat=True)
+ )
+
+ if not active_execution_ids:
+ logger.debug(
+ "[ActiveCheck] No active workflow executions found, UUID-only query returns 0 results"
+ )
+ return
+
+ # Step 2: Extract UUIDs for IN query
+ uuid_only_uuids = [f["uuid"] for f in legacy_files]
+
+ # Step 3: Execute bulk query on workflow_file_executions from active workflow executions only
+ query = WorkflowFileExecution.objects.filter(
+ workflow_execution_id__in=active_execution_ids, # Scoped to active workflow executions
+ provider_file_uuid__in=uuid_only_uuids,
+ status__in=["PENDING", "EXECUTING"], # File execution must also be active
+ )
+
+ logger.debug(f"[ActiveCheck] Legacy bulk SQL: {query.query}")
+
+ active_executions = query.values(
+ "id",
+ "workflow_execution_id",
+ "file_name",
+ "file_path",
+ "status",
+ "created_at",
+ "provider_file_uuid",
+ )
+
+ logger.info(
+ f"[ActiveCheck] UUID-only query found {active_executions.count()} active records"
+ )
+
+ # Map results back to files with validation
+ for record in active_executions:
+ provider_uuid = record["provider_file_uuid"]
+ composite_id = provider_uuid # Legacy: no path suffix
+ execution_id = record["workflow_execution_id"]
+
+ # Validation: Ensure this execution ID is in our expected active executions list
+ if execution_id not in active_execution_ids:
+ logger.error(
+ f"[ActiveCheck] VALIDATION ERROR: Found file execution {record['id']} "
+ f"with workflow_execution_id {execution_id} that's not in our active executions list!"
+ )
+ continue
+
+ logger.debug(
+ f"[ActiveCheck] Active record {record['id']}: "
+ f"uuid={provider_uuid[:8]}..., status={record['status']}, "
+ f"path={record['file_path']}, workflow_execution={execution_id} ✓"
+ )
+
+ # Track in both formats
+ if provider_uuid not in active_files:
+ active_files[provider_uuid] = []
+ active_files[provider_uuid].append(dict(record))
+ active_identifiers.add(composite_id)
+
+ logger.info(
+ f"[ActiveCheck] File {composite_id} is actively being processed (legacy)"
+ )
+
+
+class WorkflowFileExecutionAPIView(APIView):
+ """Internal API for workflow file execution operations."""
+
+ def post(self, request):
+ """Get or create workflow file execution record."""
+ try:
+ execution_id = request.data.get("execution_id")
+ file_hash = request.data.get("file_hash", {})
+ workflow_id = request.data.get("workflow_id")
+
+ logger.info(
+ f"1Received file execution request for execution {execution_id} and workflow {workflow_id}"
+ )
+
+ if not execution_id or not workflow_id:
+ return Response(
+ {"error": "execution_id and workflow_id are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ logger.info(
+ f"2Received file execution request for execution {execution_id} and workflow {workflow_id}"
+ )
+ # Get workflow execution
+ try:
+ workflow_execution = WorkflowExecution.objects.get(id=execution_id)
+ except WorkflowExecution.DoesNotExist:
+ return Response(
+ {"error": f"Workflow execution {execution_id} not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ logger.info(
+ f"3Received file execution request for execution {execution_id} and workflow {workflow_id}"
+ )
+ # Get or create workflow file execution
+ file_execution, created = WorkflowFileExecution.objects.get_or_create(
+ workflow_execution=workflow_execution,
+ file_hash=file_hash.get("file_hash", ""),
+ defaults={
+ "file_name": file_hash.get("file_name", ""),
+ "file_path": file_hash.get("file_path", ""),
+ "file_size": file_hash.get("file_size", 0),
+ "mime_type": file_hash.get("mime_type", ""),
+ "provider_file_uuid": file_hash.get("provider_file_uuid"),
+ "fs_metadata": file_hash.get("fs_metadata", {}),
+ "status": "PENDING",
+ },
+ )
+
+ logger.info(f"4Received file execution request for file_hash {file_hash}")
+ return Response(
+ {
+ "id": str(file_execution.id),
+ "file_name": file_execution.file_name,
+ "file_path": file_execution.file_path,
+ "status": file_execution.status,
+ "created": created,
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get/create workflow file execution: {str(e)}")
+ return Response(
+ {
+ "error": "Failed to get/create workflow file execution",
+ "detail": str(e),
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WorkflowExecuteFileAPIView(APIView):
+ """Internal API for executing workflow for a single file."""
+
+ def post(self, request):
+ """Execute workflow for a single file."""
+ try:
+ workflow_id = request.data.get("workflow_id")
+ execution_id = request.data.get("execution_id")
+ file_data = request.data.get("file_data", {})
+ organization_id = request.data.get("organization_id")
+
+ if not all([workflow_id, execution_id, file_data, organization_id]):
+ return Response(
+ {
+ "error": "workflow_id, execution_id, file_data, and organization_id are required"
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Set organization context
+ StateStore.set(Account.ORGANIZATION_ID, organization_id)
+
+ # Get workflow and execution
+ try:
+ workflow = Workflow.objects.get(id=workflow_id)
+ workflow_execution = WorkflowExecution.objects.get(id=execution_id)
+ except (Workflow.DoesNotExist, WorkflowExecution.DoesNotExist) as e:
+ return Response(
+ {"error": f"Workflow or execution not found: {str(e)}"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get tool instances
+ tool_instances = ToolInstance.objects.filter(workflow=workflow).order_by(
+ "step"
+ )
+
+ # Execute workflow using WorkflowExecutionServiceHelper
+ try:
+ from workflow_manager.workflow_v2.execution import (
+ WorkflowExecutionServiceHelper,
+ )
+
+ execution_helper = WorkflowExecutionServiceHelper(
+ workflow=workflow,
+ tool_instances=list(tool_instances),
+ organization_id=organization_id,
+ workflow_execution=workflow_execution,
+ )
+
+ # Execute the workflow for this file
+ result = execution_helper.execute_single_file(
+ file_data=file_data,
+ file_name=file_data.get("name", ""),
+ file_path=file_data.get("file_path", ""),
+ )
+
+ return Response(
+ {
+ "status": "success",
+ "execution_id": execution_id,
+ "result": result,
+ "file_name": file_data.get("name"),
+ }
+ )
+
+ except Exception as exec_error:
+ logger.error(f"Workflow execution failed: {str(exec_error)}")
+ return Response(
+ {
+ "status": "error",
+ "execution_id": execution_id,
+ "error": str(exec_error),
+ "file_name": file_data.get("name"),
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to execute workflow for file: {str(e)}")
+ return Response(
+ {"error": "Failed to execute workflow for file", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WorkflowEndpointAPIView(APIView):
+ """Internal API for getting workflow endpoints.
+ Used by workers to determine if a workflow is API-based or filesystem-based.
+ """
+
+ def get(self, request, workflow_id):
+ """Get workflow endpoints for connection type detection."""
+ try:
+ from utils.user_context import UserContext
+
+ from workflow_manager.endpoint_v2.models import WorkflowEndpoint
+
+ # Enhanced debug logging for organization context
+ organization_id = getattr(request, "organization_id", None)
+ organization_from_context = UserContext.get_organization()
+ statestore_org_id = StateStore.get(Account.ORGANIZATION_ID)
+
+ request_debug = {
+ "workflow_id": str(workflow_id),
+ "request_organization_id": organization_id,
+ "statestore_org_id": statestore_org_id,
+ "usercontext_organization": str(organization_from_context.id)
+ if organization_from_context
+ else None,
+ "usercontext_org_name": organization_from_context.display_name
+ if organization_from_context
+ else None,
+ "headers": dict(request.headers),
+ "internal_service": getattr(request, "internal_service", False),
+ "authenticated_via": getattr(request, "authenticated_via", None),
+ "path": request.path,
+ }
+ logger.info(f"WorkflowEndpointAPIView debug - {request_debug}")
+
+ # Get workflow using the DefaultOrganizationManagerMixin which automatically filters by organization
+ try:
+ # This will automatically apply organization filtering via DefaultOrganizationManagerMixin
+ workflow = Workflow.objects.get(id=workflow_id)
+
+ logger.info(
+ f"Found workflow {workflow_id}: organization={workflow.organization_id}, name={getattr(workflow, 'workflow_name', 'Unknown')}"
+ )
+
+ except Workflow.DoesNotExist:
+ logger.error(
+ f"Workflow {workflow_id} not found or not accessible by organization {organization_id}"
+ )
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get workflow endpoints with connector instance data
+ workflow_endpoints = WorkflowEndpoint.objects.select_related(
+ "connector_instance"
+ ).filter(workflow=workflow)
+
+ source_endpoint = None
+ destination_endpoint = None
+
+ has_api_endpoints = False
+
+ for endpoint in workflow_endpoints:
+ endpoint_data = WorkflowEndpointConfigData(
+ endpoint_id=endpoint.id,
+ endpoint_type=endpoint.endpoint_type,
+ connection_type=endpoint.connection_type,
+ configuration=endpoint.configuration,
+ )
+
+ # Include connector instance information if available
+ if endpoint.connector_instance:
+ connector_instance_data = ConnectorInstanceData(
+ connector_id=endpoint.connector_instance.connector_id,
+ connector_name=endpoint.connector_instance.connector_name,
+ connector_metadata=endpoint.connector_instance.metadata or {},
+ )
+ endpoint_data.connector_instance = connector_instance_data
+ # endpoint_data["connector_instance"] = connector_instance_data
+ logger.debug(
+ f"Added connector instance data for endpoint {endpoint.id}: {endpoint.connector_instance.connector_id}"
+ )
+ else:
+ endpoint_data.connector_instance = None
+ # endpoint_data["connector_instance"] = None
+ logger.debug(
+ f"No connector instance found for endpoint {endpoint.id}"
+ )
+
+ if endpoint.endpoint_type == WorkflowEndpoint.EndpointType.SOURCE:
+ source_endpoint = endpoint_data
+ elif endpoint.endpoint_type == WorkflowEndpoint.EndpointType.DESTINATION:
+ destination_endpoint = endpoint_data
+ if endpoint.connection_type == ConnectionType.API.value:
+ has_api_endpoints = True
+
+ endpoint_config = WorkflowEndpointConfigResponseData(
+ workflow_id=str(workflow_id),
+ has_api_endpoints=has_api_endpoints,
+ source_endpoint=source_endpoint,
+ destination_endpoint=destination_endpoint,
+ )
+
+ response_data = endpoint_config.to_dict()
+
+ logger.info(
+ f"Retrieved endpoints for workflow {workflow_id}, API endpoints: {has_api_endpoints}"
+ )
+ return Response(response_data, status=status.HTTP_200_OK)
+
+ except Exception as e:
+ logger.error(f"Failed to get workflow endpoints for {workflow_id}: {str(e)}")
+ return Response(
+ {"error": "Failed to get workflow endpoints", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WorkflowSourceFilesAPIView(APIView):
+ """Internal API for getting workflow source files.
+ Used by workers to get source files for processing.
+ """
+
+ def post(self, request, workflow_id):
+ """Get source files for a workflow execution."""
+ try:
+ from utils.user_context import UserContext
+
+ from unstract.workflow_execution.enums import LogStage
+ from workflow_manager.endpoint_v2.source import SourceConnector
+ from workflow_manager.utils.workflow_log import WorkflowLog
+
+ # Get request data
+ execution_id = request.data.get("execution_id")
+ pipeline_id = request.data.get("pipeline_id")
+ use_file_history = request.data.get("use_file_history", True)
+
+ if not execution_id:
+ return Response(
+ {"error": "execution_id is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Enhanced debug logging for organization context
+ organization_id = getattr(request, "organization_id", None)
+ organization_from_context = UserContext.get_organization()
+ statestore_org_id = StateStore.get(Account.ORGANIZATION_ID)
+
+ request_debug = {
+ "workflow_id": str(workflow_id),
+ "execution_id": str(execution_id),
+ "pipeline_id": str(pipeline_id) if pipeline_id else None,
+ "request_organization_id": organization_id,
+ "statestore_org_id": statestore_org_id,
+ "usercontext_organization": str(organization_from_context.id)
+ if organization_from_context
+ else None,
+ "use_file_history": use_file_history,
+ }
+ logger.info(f"WorkflowSourceFilesAPIView debug - {request_debug}")
+
+ # Get workflow using the DefaultOrganizationManagerMixin which automatically filters by organization
+ try:
+ workflow = Workflow.objects.get(id=workflow_id)
+ logger.info(f"Found workflow {workflow_id} for source files request")
+ except Workflow.DoesNotExist:
+ logger.error(f"Workflow {workflow_id} not found or not accessible")
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Get workflow execution
+ try:
+ WorkflowExecution.objects.get(id=execution_id)
+ logger.info(f"Found workflow execution {execution_id}")
+ except WorkflowExecution.DoesNotExist:
+ logger.error(f"Workflow execution {execution_id} not found")
+ return Response(
+ {"error": "Workflow execution not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Create workflow log
+ workflow_log = WorkflowLog(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ log_stage=LogStage.INITIALIZE,
+ pipeline_id=pipeline_id,
+ )
+
+ # Create source connector
+ source = SourceConnector(
+ workflow=workflow,
+ execution_id=str(execution_id),
+ workflow_log=workflow_log,
+ use_file_history=use_file_history,
+ organization_id=organization_id,
+ )
+
+ # Validate and get source files
+ source.validate()
+
+ # Get input files from source (this includes file listing and processing)
+ input_files, total_files = source.list_files_from_source({})
+
+ # Convert input_files to serializable format and include connector context
+ serializable_files = {}
+ connector_metadata = None
+ connector_id = None
+
+ # Get connector metadata from the workflow endpoint for FILESYSTEM access
+ if source.endpoint and source.endpoint.connector_instance:
+ connector_metadata = source.endpoint.connector_instance.connector_metadata
+ connector_id = source.endpoint.connector_instance.connector_id
+ logger.info(f"Including connector context: connector_id={connector_id}")
+
+ for file_name, file_hash in input_files.items():
+ if hasattr(file_hash, "to_json"):
+ file_data = file_hash.to_json()
+ else:
+ file_data = file_hash
+
+ # Add connector context to each file for worker access
+ if connector_metadata and connector_id:
+ file_data["connector_metadata"] = connector_metadata
+ file_data["connector_id"] = connector_id
+
+ serializable_files[file_name] = file_data
+
+ logger.info(
+ f"Retrieved {total_files} source files for workflow {workflow_id}, execution {execution_id}"
+ )
+
+ return Response(
+ {
+ "files": serializable_files,
+ "total_files": total_files,
+ "workflow_id": str(workflow_id),
+ "execution_id": str(execution_id),
+ "pipeline_id": str(pipeline_id) if pipeline_id else None,
+ }
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get source files for workflow {workflow_id}: {str(e)}",
+ exc_info=True,
+ )
+ return Response(
+ {"error": "Failed to get source files", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileCountIncrementAPIView(APIView):
+ """Internal API for incrementing file counts during execution.
+ Replicates Django ExecutionCacheUtils functionality for workers.
+ """
+
+ def post(self, request):
+ """Increment file counts for execution."""
+ try:
+ workflow_id = request.data.get("workflow_id")
+ execution_id = request.data.get("execution_id")
+ increment_type = request.data.get("increment_type") # 'completed' or 'failed'
+
+ if not all([workflow_id, execution_id, increment_type]):
+ return Response(
+ {
+ "error": "workflow_id, execution_id, and increment_type are required"
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get workflow execution
+ try:
+ WorkflowExecution.objects.get(id=execution_id)
+ except WorkflowExecution.DoesNotExist:
+ return Response(
+ {"error": "Workflow execution not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Use Django backend's ExecutionCacheUtils to increment counts
+ from workflow_manager.execution.execution_cache_utils import (
+ ExecutionCacheUtils,
+ )
+
+ if increment_type == "completed":
+ ExecutionCacheUtils.increment_completed_files(
+ workflow_id=workflow_id, execution_id=execution_id
+ )
+ logger.info(f"Incremented completed files for execution {execution_id}")
+ elif increment_type == "failed":
+ ExecutionCacheUtils.increment_failed_files(
+ workflow_id=workflow_id, execution_id=execution_id
+ )
+ logger.info(f"Incremented failed files for execution {execution_id}")
+ else:
+ return Response(
+ {
+ "error": f"Invalid increment_type: {increment_type}. Must be 'completed' or 'failed'"
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ return Response(
+ {
+ "success": True,
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "increment_type": increment_type,
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to increment file count: {str(e)}")
+ return Response(
+ {"error": "Failed to increment file count", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class PipelineStatusUpdateAPIView(APIView):
+ """Internal API for updating pipeline status.
+ Used by workers to update pipeline execution status.
+ """
+
+ def post(self, request, pipeline_id):
+ """Update pipeline status."""
+ try:
+ from pipeline_v2.models import Pipeline
+
+ from workflow_manager.utils.pipeline_utils import PipelineUtils
+
+ # Get request data
+ execution_id = request.data.get("execution_id")
+ status_value = request.data.get("status")
+
+ if not execution_id or not status_value:
+ return Response(
+ {"error": "execution_id and status are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get pipeline with organization filtering
+ try:
+ # Apply organization filtering to pipeline query
+ pipeline_queryset = Pipeline.objects.filter(id=pipeline_id)
+ pipeline_queryset = filter_queryset_by_organization(
+ pipeline_queryset, request, "organization"
+ )
+ pipeline_queryset.get()
+ logger.info(
+ f"Found pipeline {pipeline_id} for status update (org: {getattr(request, 'organization_id', 'unknown')})"
+ )
+ except Pipeline.DoesNotExist:
+ org_id = getattr(request, "organization_id", "unknown")
+ logger.error(
+ f"Pipeline {pipeline_id} not found or not accessible by organization {org_id}"
+ )
+ return Response(
+ {"error": "Pipeline not found"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ # Get workflow execution with organization filtering
+ try:
+ # Apply organization filtering to workflow execution query
+ execution_queryset = WorkflowExecution.objects.filter(id=execution_id)
+ execution_queryset = filter_queryset_by_organization(
+ execution_queryset, request, "workflow__organization"
+ )
+ workflow_execution = execution_queryset.get()
+ logger.info(
+ f"Found workflow execution {execution_id} (org: {getattr(request, 'organization_id', 'unknown')})"
+ )
+ except WorkflowExecution.DoesNotExist:
+ org_id = getattr(request, "organization_id", "unknown")
+ logger.error(
+ f"Workflow execution {execution_id} not found or not accessible by organization {org_id}"
+ )
+ return Response(
+ {"error": "Workflow execution not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Update pipeline status using the utility method
+ PipelineUtils.update_pipeline_status(
+ pipeline_id=str(pipeline_id), workflow_execution=workflow_execution
+ )
+
+ logger.info(
+ f"Updated pipeline {pipeline_id} status for execution {execution_id}"
+ )
+
+ return Response(
+ {
+ "status": "updated",
+ "pipeline_id": str(pipeline_id),
+ "execution_id": str(execution_id),
+ "new_status": status_value,
+ }
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to update pipeline {pipeline_id} status: {str(e)}", exc_info=True
+ )
+ return Response(
+ {"error": "Failed to update pipeline status", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WorkflowDefinitionAPIView(APIView):
+ """Internal API endpoint for getting workflow definitions.
+ Fixed to handle missing endpoints gracefully and use correct workflow type detection.
+ """
+
+ def get(self, request, workflow_id):
+ """Get workflow definition with proper type detection and endpoint handling."""
+ try:
+ from workflow_manager.workflow_v2.models.workflow import Workflow
+
+ # Get workflow with organization filtering
+ try:
+ workflow = Workflow.objects.get(id=workflow_id)
+ # Verify organization access
+ filter_queryset_by_organization(
+ Workflow.objects.filter(id=workflow_id), request, "organization"
+ ).get()
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Step 1: Get source configuration with graceful error handling
+ source_config = self._get_source_endpoint_config(workflow_id, workflow)
+
+ # Step 2: Get destination configuration with graceful error handling
+ destination_config = self._get_destination_endpoint_config(
+ workflow_id, workflow
+ )
+
+ # Step 3: Build comprehensive workflow definition using dataclasses
+ workflow_definition = WorkflowDefinitionResponseData(
+ workflow_id=str(workflow.id),
+ workflow_name=workflow.workflow_name,
+ source_config=source_config,
+ destination_config=destination_config,
+ organization_id=str(workflow.organization.organization_id),
+ created_at=workflow.created_at.isoformat(),
+ modified_at=workflow.modified_at.isoformat(),
+ is_active=workflow.is_active,
+ )
+
+ response_data = workflow_definition.to_dict()
+
+ logger.info(
+ f"Retrieved workflow definition for {workflow_id}: {workflow_definition.workflow_type} (source: {workflow_definition.source_config.connection_type})"
+ )
+ return Response(response_data, status=status.HTTP_200_OK)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get workflow definition for {workflow_id}: {str(e)}",
+ exc_info=True,
+ )
+ return Response(
+ {"error": "Failed to get workflow definition", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _get_source_endpoint_config(
+ self, workflow_id: str, workflow
+ ) -> WorkflowEndpointConfigData:
+ """Get source endpoint configuration with credential resolution."""
+ try:
+ source_endpoint = WorkflowEndpointUtils.get_endpoint_for_workflow_by_type(
+ workflow_id, WorkflowEndpoint.EndpointType.SOURCE
+ )
+
+ # Start with folder/path configuration from endpoint
+ merged_configuration = source_endpoint.configuration or {}
+
+ # Create connector instance data and resolve credentials if available
+ connector_instance_data = None
+ if source_endpoint.connector_instance:
+ connector_instance = source_endpoint.connector_instance
+
+ # Use exact same pattern as backend source.py
+ # Get connector metadata (which contains decrypted credentials)
+ connector_credentials = {}
+ try:
+ # Follow backend pattern: use connector.metadata for credentials
+ # This contains the actual decrypted credentials (json_credentials, project_id, etc.)
+ connector_credentials = connector_instance.metadata or {}
+
+ # Optionally refresh OAuth tokens if needed (like backend does)
+ if connector_instance.connector_auth:
+ try:
+ # This refreshes tokens and updates metadata if needed
+ connector_instance.get_connector_metadata()
+ # Use the updated metadata
+ connector_credentials = connector_instance.metadata or {}
+ logger.debug(
+ f"Refreshed connector metadata for {connector_instance.connector_id}"
+ )
+ except Exception as refresh_error:
+ logger.warning(
+ f"Failed to refresh connector metadata for {connector_instance.id}: {str(refresh_error)}"
+ )
+ # Continue with existing metadata
+
+ logger.debug(
+ f"Retrieved connector settings for {connector_instance.connector_id}"
+ )
+
+ except Exception as cred_error:
+ logger.warning(
+ f"Failed to retrieve connector settings for {connector_instance.id}: {str(cred_error)}"
+ )
+ # Continue without credentials - let connector handle the error
+
+ # Merge folder configuration with connector credentials
+ # Folder settings take precedence over connector defaults
+ merged_configuration = {**connector_credentials, **merged_configuration}
+
+ connector_instance_data = ConnectorInstanceData(
+ connector_id=connector_instance.connector_id,
+ connector_name=getattr(connector_instance, "connector_name", ""),
+ connector_metadata=connector_instance.metadata or {},
+ )
+
+ logger.debug(
+ f"Found source endpoint for workflow {workflow_id}: {source_endpoint.connection_type} with {len(merged_configuration)} config keys"
+ )
+ return WorkflowEndpointConfigData(
+ endpoint_id=str(source_endpoint.id),
+ endpoint_type=source_endpoint.endpoint_type,
+ connection_type=source_endpoint.connection_type,
+ configuration=merged_configuration,
+ connector_instance=connector_instance_data,
+ )
+
+ except WorkflowEndpoint.DoesNotExist:
+ logger.info(
+ f"No source endpoint found for workflow {workflow_id}, returning empty config"
+ )
+ return WorkflowEndpointConfigData(
+ endpoint_id="",
+ endpoint_type=WorkflowEndpoint.EndpointType.SOURCE,
+ connection_type="NONE",
+ )
+ except Exception as e:
+ logger.warning(
+ f"Error getting source endpoint for workflow {workflow_id}: {str(e)}"
+ )
+ return WorkflowEndpointConfigData(
+ endpoint_id="",
+ endpoint_type=WorkflowEndpoint.EndpointType.SOURCE,
+ connection_type="NONE",
+ )
+
+ def _get_destination_endpoint_config(
+ self, workflow_id: str, workflow
+ ) -> WorkflowEndpointConfigData:
+ """Get destination endpoint configuration with credential resolution."""
+ try:
+ destination_endpoint = (
+ WorkflowEndpointUtils.get_endpoint_for_workflow_by_type(
+ workflow_id, WorkflowEndpoint.EndpointType.DESTINATION
+ )
+ )
+
+ # Start with configuration from endpoint
+ merged_configuration = destination_endpoint.configuration or {}
+
+ # Create connector instance data and resolve credentials if available
+ connector_instance_data = None
+ if destination_endpoint.connector_instance:
+ connector_instance = destination_endpoint.connector_instance
+
+ # Use exact same pattern as backend source.py
+ # Get connector metadata (which contains decrypted credentials)
+ connector_credentials = {}
+ try:
+ # Follow backend pattern: use connector.metadata for credentials
+ # This contains the actual decrypted credentials (host, database, username, password, etc.)
+ connector_credentials = connector_instance.metadata or {}
+
+ # Optionally refresh OAuth tokens if needed (like backend does)
+ if connector_instance.connector_auth:
+ try:
+ # This refreshes tokens and updates metadata if needed
+ connector_instance.get_connector_metadata()
+ # Use the updated metadata
+ connector_credentials = connector_instance.metadata or {}
+ logger.debug(
+ f"Refreshed destination connector metadata for {connector_instance.connector_id}"
+ )
+ except Exception as refresh_error:
+ logger.warning(
+ f"Failed to refresh destination connector metadata for {connector_instance.id}: {str(refresh_error)}"
+ )
+ # Continue with existing metadata
+
+ logger.debug(
+ f"Retrieved destination connector settings for {connector_instance.connector_id}"
+ )
+
+ except Exception as cred_error:
+ logger.warning(
+ f"Failed to retrieve destination connector settings for {connector_instance.id}: {str(cred_error)}"
+ )
+ # Continue without credentials - let connector handle the error
+
+ # Merge configuration with connector credentials
+ # Endpoint settings take precedence over connector defaults
+ merged_configuration = {**connector_credentials, **merged_configuration}
+
+ connector_instance_data = ConnectorInstanceData(
+ connector_id=connector_instance.connector_id,
+ connector_name=connector_instance.connector_name,
+ connector_metadata=connector_instance.metadata or {},
+ )
+
+ logger.debug(
+ f"Found destination endpoint for workflow {workflow_id}: {destination_endpoint.connection_type} with {len(merged_configuration)} config keys"
+ )
+ return WorkflowEndpointConfigData(
+ endpoint_id=str(destination_endpoint.id),
+ endpoint_type=destination_endpoint.endpoint_type,
+ connection_type=destination_endpoint.connection_type,
+ configuration=merged_configuration,
+ connector_instance=connector_instance_data,
+ )
+
+ except WorkflowEndpoint.DoesNotExist:
+ logger.info(
+ f"No destination endpoint found for workflow {workflow_id}, returning empty config"
+ )
+ return WorkflowEndpointConfigData(
+ endpoint_id="",
+ endpoint_type=WorkflowEndpoint.EndpointType.DESTINATION,
+ connection_type="NONE",
+ )
+ except Exception as e:
+ logger.warning(
+ f"Error getting destination endpoint for workflow {workflow_id}: {str(e)}"
+ )
+ return WorkflowEndpointConfigData(
+ endpoint_id="",
+ endpoint_type=WorkflowEndpoint.EndpointType.DESTINATION,
+ connection_type="NONE",
+ )
+
+
+class PipelineTypeAPIView(APIView):
+ """Internal API endpoint for determining pipeline type.
+
+ Checks APIDeployment first, then Pipeline model to determine if pipeline is:
+ - API (if found in APIDeployment model)
+ - ETL/TASK/APP (if found in Pipeline model with pipeline_type field)
+ """
+
+ def get(self, request, pipeline_id):
+ """Determine pipeline type from APIDeployment or Pipeline models."""
+ try:
+ from api_v2.models import APIDeployment
+ from pipeline_v2.models import Pipeline
+
+ organization_id = getattr(request, "organization_id", None)
+
+ # First check if this is an API deployment
+ try:
+ api_deployment = APIDeployment.objects.get(id=pipeline_id)
+ # Verify organization access
+ if (
+ organization_id
+ and str(api_deployment.organization.organization_id)
+ != organization_id
+ ):
+ return Response(
+ {"error": "API deployment not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ logger.info(f"Pipeline {pipeline_id} identified as API deployment")
+ return Response(
+ {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_type": "API",
+ "source": "api_deployment",
+ "workflow_id": str(api_deployment.workflow_id),
+ "display_name": api_deployment.display_name,
+ "is_active": api_deployment.is_active,
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except APIDeployment.DoesNotExist:
+ # Not an API deployment, check Pipeline model
+ pass
+
+ # Check if this is a regular pipeline (ETL/TASK/APP)
+ try:
+ pipeline = Pipeline.objects.get(id=pipeline_id)
+ # Verify organization access
+ if (
+ organization_id
+ and str(pipeline.organization.organization_id) != organization_id
+ ):
+ return Response(
+ {"error": "Pipeline not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Map Pipeline.PipelineType to expected values
+ pipeline_type = pipeline.pipeline_type
+ if pipeline_type == Pipeline.PipelineType.ETL:
+ resolved_type = "ETL"
+ elif pipeline_type == Pipeline.PipelineType.TASK:
+ resolved_type = "TASK"
+ elif pipeline_type == Pipeline.PipelineType.APP:
+ resolved_type = "APP"
+ else:
+ resolved_type = "ETL" # Default fallback
+
+ logger.info(
+ f"Pipeline {pipeline_id} identified as {resolved_type} pipeline"
+ )
+ return Response(
+ {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_type": resolved_type,
+ "source": "pipeline",
+ "workflow_id": str(pipeline.workflow_id),
+ "pipeline_name": pipeline.pipeline_name,
+ "active": pipeline.active,
+ "scheduled": pipeline.scheduled,
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Pipeline.DoesNotExist:
+ # Pipeline not found in either model
+ logger.warning(
+ f"Pipeline {pipeline_id} not found in APIDeployment or Pipeline models"
+ )
+ return Response(
+ {
+ "error": "Pipeline not found",
+ "detail": f"Pipeline {pipeline_id} not found in APIDeployment or Pipeline models",
+ },
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to determine pipeline type for {pipeline_id}: {str(e)}")
+ return Response(
+ {"error": "Failed to determine pipeline type", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class BatchStatusUpdateAPIView(APIView):
+ """Internal API endpoint for batch status updates.
+ Allows updating multiple workflow executions in a single request.
+ """
+
+ def post(self, request):
+ """Update multiple workflow execution statuses."""
+ try:
+ updates = request.data.get("updates", [])
+
+ if not updates:
+ return Response(
+ {"error": "updates list is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ successful_updates = []
+ failed_updates = []
+
+ with transaction.atomic():
+ for update in updates:
+ try:
+ execution_id = update.get("execution_id")
+ status_value = update.get("status")
+
+ if not execution_id or not status_value:
+ failed_updates.append(
+ {
+ "execution_id": execution_id,
+ "error": "execution_id and status are required",
+ }
+ )
+ continue
+
+ # Get workflow execution with organization filtering
+ execution_queryset = WorkflowExecution.objects.filter(
+ id=execution_id
+ )
+ execution_queryset = filter_queryset_by_organization(
+ execution_queryset, request, "workflow__organization"
+ )
+ execution = execution_queryset.get()
+
+ # Update status
+ execution.status = status_value
+
+ # Update optional fields
+ if update.get("error_message"):
+ execution.error_message = update["error_message"][
+ :256
+ ] # Truncate to fit constraint
+ if update.get("total_files") is not None:
+ execution.total_files = update["total_files"]
+ if update.get("execution_time") is not None:
+ execution.execution_time = update["execution_time"]
+
+ execution.modified_at = timezone.now()
+ execution.save()
+
+ successful_updates.append(
+ {
+ "execution_id": str(execution.id),
+ "status": execution.status,
+ }
+ )
+
+ except WorkflowExecution.DoesNotExist:
+ failed_updates.append(
+ {
+ "execution_id": execution_id,
+ "error": "Workflow execution not found",
+ }
+ )
+ except Exception as e:
+ failed_updates.append(
+ {"execution_id": execution_id, "error": str(e)}
+ )
+
+ logger.info(
+ f"Batch status update completed: {len(successful_updates)} successful, {len(failed_updates)} failed"
+ )
+
+ return Response(
+ {
+ "successful_updates": successful_updates,
+ "failed_updates": failed_updates,
+ "total_processed": len(updates),
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to process batch status update: {str(e)}")
+ return Response(
+ {"error": "Failed to process batch status update", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WorkflowExecutionCleanupAPIView(APIView):
+ """Internal API endpoint for cleaning up workflow execution resources."""
+
+ def post(self, request):
+ """Cleanup resources for multiple workflow executions."""
+ try:
+ execution_ids = request.data.get("execution_ids", [])
+ cleanup_types = request.data.get("cleanup_types", ["cache", "temp_files"])
+
+ if not execution_ids:
+ return Response(
+ {"error": "execution_ids list is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ cleaned_executions = []
+ failed_cleanups = []
+
+ for execution_id in execution_ids:
+ try:
+ # Get workflow execution with organization filtering
+ execution_queryset = WorkflowExecution.objects.filter(id=execution_id)
+ execution_queryset = filter_queryset_by_organization(
+ execution_queryset, request, "workflow__organization"
+ )
+ execution = execution_queryset.get()
+
+ # Perform cleanup based on cleanup_types
+ cleanup_results = {}
+
+ if "cache" in cleanup_types:
+ # Clean execution cache
+ try:
+ from workflow_manager.execution.execution_cache_utils import (
+ ExecutionCacheUtils,
+ )
+
+ ExecutionCacheUtils.cleanup_execution_cache(str(execution.id))
+ cleanup_results["cache"] = "cleaned"
+ except Exception as cache_error:
+ cleanup_results["cache"] = f"error: {str(cache_error)}"
+
+ if "temp_files" in cleanup_types:
+ # Clean temporary files
+ try:
+ # Import filesystem utilities
+ from unstract.filesystem import FileStorageType, FileSystem
+
+ # Clean execution directory
+ file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ file_storage = file_system.get_file_storage()
+
+ org_id = (
+ execution.workflow.organization_id
+ if execution.workflow
+ else "default"
+ )
+ execution_dir = f"unstract/execution/{org_id}/{execution.workflow_id}/{execution.id}"
+
+ if file_storage.exists(execution_dir):
+ file_storage.delete(execution_dir)
+ cleanup_results["temp_files"] = "cleaned"
+ else:
+ cleanup_results["temp_files"] = "not_found"
+
+ except Exception as file_error:
+ cleanup_results["temp_files"] = f"error: {str(file_error)}"
+
+ cleaned_executions.append(
+ {
+ "execution_id": str(execution.id),
+ "cleanup_results": cleanup_results,
+ }
+ )
+
+ except WorkflowExecution.DoesNotExist:
+ failed_cleanups.append(
+ {
+ "execution_id": execution_id,
+ "error": "Workflow execution not found",
+ }
+ )
+ except Exception as e:
+ failed_cleanups.append(
+ {"execution_id": execution_id, "error": str(e)}
+ )
+
+ logger.info(
+ f"Cleanup completed: {len(cleaned_executions)} successful, {len(failed_cleanups)} failed"
+ )
+
+ return Response(
+ {
+ "cleaned_executions": cleaned_executions,
+ "failed_cleanups": failed_cleanups,
+ "total_processed": len(execution_ids),
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to process cleanup request: {str(e)}")
+ return Response(
+ {"error": "Failed to process cleanup request", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class WorkflowExecutionMetricsAPIView(APIView):
+ """Internal API endpoint for getting workflow execution metrics."""
+
+ def get(self, request):
+ """Get execution metrics with optional filtering."""
+ try:
+ # Get query parameters
+ start_date = request.query_params.get("start_date")
+ end_date = request.query_params.get("end_date")
+ workflow_id = request.query_params.get("workflow_id")
+ status = request.query_params.get("status")
+
+ # Build base queryset with organization filtering
+ executions = WorkflowExecution.objects.all()
+ executions = filter_queryset_by_organization(
+ executions, request, "workflow__organization"
+ )
+
+ # Apply filters
+ if start_date:
+ from datetime import datetime
+
+ executions = executions.filter(
+ created_at__gte=datetime.fromisoformat(start_date)
+ )
+ if end_date:
+ from datetime import datetime
+
+ executions = executions.filter(
+ created_at__lte=datetime.fromisoformat(end_date)
+ )
+ if workflow_id:
+ executions = executions.filter(workflow_id=workflow_id)
+ if status:
+ executions = executions.filter(status=status)
+
+ # Calculate metrics
+ from django.db.models import Avg, Count, Sum
+
+ total_executions = executions.count()
+
+ # Status breakdown
+ status_counts = executions.values("status").annotate(count=Count("id"))
+ status_breakdown = {item["status"]: item["count"] for item in status_counts}
+
+ # Success rate
+ completed_count = status_breakdown.get("COMPLETED", 0)
+ success_rate = (
+ (completed_count / total_executions) if total_executions > 0 else 0
+ )
+
+ # Average execution time
+ avg_execution_time = (
+ executions.aggregate(avg_time=Avg("execution_time"))["avg_time"] or 0
+ )
+
+ # Total files processed
+ total_files_processed = (
+ executions.aggregate(total_files=Sum("total_files"))["total_files"] or 0
+ )
+
+ metrics = {
+ "total_executions": total_executions,
+ "status_breakdown": status_breakdown,
+ "success_rate": success_rate,
+ "average_execution_time": avg_execution_time,
+ "total_files_processed": total_files_processed,
+ "filters_applied": {
+ "start_date": start_date,
+ "end_date": end_date,
+ "workflow_id": workflow_id,
+ "status": status,
+ },
+ }
+
+ logger.info(
+ f"Generated execution metrics: {total_executions} executions, {success_rate:.2%} success rate"
+ )
+
+ return Response(metrics)
+
+ except Exception as e:
+ logger.error(f"Failed to get execution metrics: {str(e)}")
+ return Response(
+ {"error": "Failed to get execution metrics", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileHistoryBatchCheckView(APIView):
+ """Internal API view to check file history in batch for workers.
+
+ This enables file deduplication by checking which files have already been processed.
+ """
+
+ def post(self, request):
+ """Check file history for a batch of file hashes.
+
+ POST /internal/workflows/{workflow_id}/file-history/batch-check/
+
+ Request body:
+ {
+ "workflow_id": "uuid",
+ "file_hashes": ["hash1", "hash2", ...],
+ "organization_id": "uuid"
+ }
+
+ Response:
+ {
+ "processed_file_hashes": ["hash1", "hash3", ...]
+ }
+ """
+ try:
+ workflow_id = request.data.get("workflow_id")
+ file_hashes = request.data.get("file_hashes", [])
+ organization_id = request.data.get("organization_id")
+
+ if not workflow_id or not file_hashes:
+ return Response(
+ {"error": "workflow_id and file_hashes are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Set organization context if provided
+ if organization_id:
+ StateStore.set(Account.ORGANIZATION_ID, organization_id)
+
+ # Get workflow
+ try:
+ workflow = filter_queryset_by_organization(
+ Workflow.objects.all(), request, "organization"
+ ).get(id=workflow_id)
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Check file history for the provided hashes
+ from workflow_manager.workflow_v2.models.file_history import FileHistory
+
+ # Apply organization filtering to FileHistory query
+ file_history_queryset = FileHistory.objects.filter(
+ workflow=workflow,
+ cache_key__in=file_hashes,
+ status="COMPLETED", # Only consider successfully completed files
+ )
+
+ # Apply organization filtering through workflow relationship
+ file_history_queryset = filter_queryset_by_organization(
+ file_history_queryset, request, "workflow__organization"
+ )
+
+ # Get full file history details for cached results
+ file_histories = file_history_queryset.values(
+ "cache_key",
+ "result",
+ "metadata",
+ "error",
+ "file_path",
+ "provider_file_uuid",
+ )
+
+ # Build response with both processed hashes (for compatibility) and full details
+ processed_file_hashes = []
+ file_history_details = {}
+
+ for fh in file_histories:
+ cache_key = fh["cache_key"]
+ processed_file_hashes.append(cache_key)
+ file_history_details[cache_key] = {
+ "result": fh["result"],
+ "metadata": fh["metadata"],
+ "error": fh["error"],
+ "file_path": fh["file_path"],
+ "provider_file_uuid": fh["provider_file_uuid"],
+ }
+
+ logger.info(
+ f"File history batch check: {len(processed_file_hashes)}/{len(file_hashes)} files already processed"
+ )
+
+ return Response(
+ {
+ "processed_file_hashes": processed_file_hashes, # For backward compatibility
+ "file_history_details": file_history_details, # Full details for cached results
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"File history batch check failed: {str(e)}")
+ return Response(
+ {"error": "File history batch check failed", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileHistoryCreateView(APIView):
+ """Internal API view to create file history entries for workers.
+
+ This enables workers to create file history entries after successful processing.
+ """
+
+ def post(self, request):
+ """Create a file history entry.
+
+ POST /internal/workflow-manager/file-history/create/
+
+ Request body:
+ {
+ "workflow_id": "uuid",
+ "cache_key": "file_hash",
+ "provider_file_uuid": "uuid_or_null",
+ "file_path": "path/to/file",
+ "file_name": "filename.ext",
+ "status": "COMPLETED",
+ "result": "execution_result",
+ "error": "error_message_or_empty",
+ "metadata": {},
+ "organization_id": "uuid"
+ }
+
+ Response:
+ {
+ "created": true,
+ "file_history_id": "uuid"
+ }
+ """
+ try:
+ workflow_id = request.data.get("workflow_id")
+ cache_key = request.data.get("cache_key")
+ organization_id = request.data.get("organization_id")
+ provider_file_uuid = request.data.get("provider_file_uuid")
+ file_path = request.data.get("file_path")
+ file_name = request.data.get("file_name")
+ file_size = request.data.get("file_size")
+ file_hash = request.data.get("file_hash")
+ mime_type = request.data.get("mime_type")
+ is_api = request.data.get("is_api")
+ status = request.data.get("status")
+ result = request.data.get("result")
+ error = request.data.get("error")
+ metadata = request.data.get("metadata")
+
+ logger.info(
+ f"File history create: workflow_id={workflow_id}, cache_key={cache_key}, organization_id={organization_id}"
+ )
+
+ if not workflow_id or not cache_key:
+ return Response(
+ {"error": "workflow_id and cache_key are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Set organization context if provided
+ if organization_id:
+ StateStore.set(Account.ORGANIZATION_ID, organization_id)
+
+ # Get workflow
+ try:
+ workflow = filter_queryset_by_organization(
+ Workflow.objects.all(), request, "organization"
+ ).get(id=workflow_id)
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found or access denied"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Create file history entry using the FileHistoryHelper
+ from unstract.core.data_models import FileHashData
+ from workflow_manager.workflow_v2.enums import ExecutionStatus
+ from workflow_manager.workflow_v2.file_history_helper import FileHistoryHelper
+
+ # Create FileHashData object from request data using shared class
+ file_hash = FileHashData(
+ file_name=file_name,
+ file_path=file_path,
+ file_hash=cache_key,
+ file_size=file_size,
+ mime_type=mime_type,
+ provider_file_uuid=provider_file_uuid,
+ fs_metadata={},
+ source_connection_type="",
+ file_destination="",
+ is_executed=False,
+ file_number=None,
+ connector_metadata={},
+ connector_id=None,
+ use_file_history=True,
+ )
+
+ # Check if file history should be created based on use_file_history flag
+ # if not file_hash.use_file_history:
+ # logger.info(
+ # f"Skipping file history creation for {file_hash.file_name} - use_file_history=False"
+ # )
+ # return Response({"created": False, "reason": "use_file_history=False"})
+
+ # Map string status to ExecutionStatus enum
+ status_str = request.data.get("status", "COMPLETED")
+ try:
+ execution_status = ExecutionStatus[status_str]
+ except KeyError:
+ execution_status = ExecutionStatus.COMPLETED
+
+ # Create file history entry
+ file_history = FileHistoryHelper.create_file_history(
+ file_hash=file_hash,
+ workflow=workflow,
+ status=execution_status,
+ result=result,
+ metadata=metadata,
+ error=error,
+ is_api=is_api,
+ )
+
+ logger.info(
+ f"Created file history entry {file_history.id} for file {file_name}"
+ )
+
+ return Response({"created": True, "file_history_id": str(file_history.id)})
+
+ except Exception as e:
+ logger.error(f"File history creation failed: {str(e)}")
+ return Response(
+ {"error": "File history creation failed", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class PipelineNameAPIView(APIView):
+ """Internal API endpoint for fetching pipeline names from models.
+
+ This endpoint fetches the actual pipeline name from Pipeline.pipeline_name
+ or APIDeployment.api_name based on the pipeline ID.
+
+ Used by callback workers to get correct pipeline names for notifications.
+ """
+
+ def get(self, request, pipeline_id):
+ """Fetch pipeline name from Pipeline or APIDeployment model."""
+ try:
+ from api_v2.models import APIDeployment
+ from pipeline_v2.models import Pipeline
+
+ organization_id = getattr(request, "organization_id", None)
+ if organization_id:
+ StateStore.set(Account.ORGANIZATION_ID, organization_id)
+
+ # First check if this is an API deployment
+ try:
+ api_deployment = APIDeployment.objects.get(id=pipeline_id)
+ logger.info(
+ f"Found API deployment {pipeline_id}: name='{api_deployment.api_name}'"
+ )
+ # Verify organization access
+ if (
+ organization_id
+ and str(api_deployment.organization.organization_id)
+ != organization_id
+ ):
+ logger.warning(
+ f"API deployment {pipeline_id} not found in organization {organization_id}"
+ )
+ return Response(
+ {"error": "API deployment not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ logger.info(
+ f"Found API deployment {pipeline_id}: name='{api_deployment.api_name}'"
+ )
+ return Response(
+ {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_name": api_deployment.api_name,
+ "pipeline_type": "API",
+ "source": "api_deployment",
+ "display_name": api_deployment.display_name,
+ }
+ )
+
+ except APIDeployment.DoesNotExist:
+ pass
+
+ # Check Pipeline model
+ try:
+ pipeline = Pipeline.objects.get(id=pipeline_id)
+
+ # Verify organization access
+ if (
+ organization_id
+ and str(pipeline.organization.organization_id) != organization_id
+ ):
+ logger.warning(
+ f"Pipeline {pipeline_id} not found in organization {organization_id}"
+ )
+ return Response(
+ {"error": "Pipeline not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ logger.info(
+ f"Found Pipeline {pipeline_id}: name='{pipeline.pipeline_name}', type='{pipeline.pipeline_type}'"
+ )
+ return Response(
+ {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_name": pipeline.pipeline_name,
+ "pipeline_type": pipeline.pipeline_type,
+ "source": "pipeline",
+ "workflow_id": str(pipeline.workflow_id)
+ if pipeline.workflow
+ else None,
+ }
+ )
+
+ except Pipeline.DoesNotExist:
+ logger.warning(
+ f"Pipeline {pipeline_id} not found in Pipeline model either"
+ )
+ pass
+
+ # Not found in either model
+ return Response(
+ {
+ "error": "Pipeline not found",
+ "detail": f"Pipeline {pipeline_id} not found in APIDeployment or Pipeline models",
+ "pipeline_id": str(pipeline_id),
+ },
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ except Exception as e:
+ logger.error(f"Error fetching pipeline name for {pipeline_id}: {str(e)}")
+ return Response(
+ {
+ "error": "Failed to fetch pipeline name",
+ "detail": str(e),
+ "pipeline_id": str(pipeline_id),
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
diff --git a/backend/workflow_manager/workflow_execution_internal_urls.py b/backend/workflow_manager/workflow_execution_internal_urls.py
new file mode 100644
index 000000000..f9ef02292
--- /dev/null
+++ b/backend/workflow_manager/workflow_execution_internal_urls.py
@@ -0,0 +1,27 @@
+"""Workflow Manager Internal API URLs
+Defines internal API endpoints for workflow execution operations.
+"""
+
+from django.urls import include, path
+from rest_framework.routers import DefaultRouter
+
+from .internal_views import FileBatchCreateAPIView, WorkflowExecutionInternalViewSet
+
+# Create router for internal API viewsets
+router = DefaultRouter()
+router.register(
+ r"",
+ WorkflowExecutionInternalViewSet,
+ basename="workflow-execution-internal",
+)
+
+urlpatterns = [
+ # Workflow execution internal APIs
+ path(
+ "create-file-batch/",
+ FileBatchCreateAPIView.as_view(),
+ name="create-file-batch",
+ ),
+ # Include router URLs for viewsets (this creates the CRUD endpoints)
+ path("", include(router.urls)),
+]
diff --git a/backend/workflow_manager/workflow_v2/enums.py b/backend/workflow_manager/workflow_v2/enums.py
index baebbf358..d30770c56 100644
--- a/backend/workflow_manager/workflow_v2/enums.py
+++ b/backend/workflow_manager/workflow_v2/enums.py
@@ -2,7 +2,10 @@ from __future__ import annotations
from enum import Enum
-from django.db.models import TextChoices
+from unstract.core.data_models import ExecutionStatus as SharedExecutionStatus
+
+# Alias shared ExecutionStatus to ensure consistency between backend and workers
+ExecutionStatus = SharedExecutionStatus
class WorkflowExecutionMethod(Enum):
@@ -10,105 +13,6 @@ class WorkflowExecutionMethod(Enum):
QUEUED = "QUEUED"
-class ExecutionStatus(TextChoices):
- """An enumeration representing the various statuses of an execution
- process.
-
- Statuses:
- PENDING: The execution's entry has been created in the database.
- EXECUTING: The execution is currently in progress.
- COMPLETED: The execution has been successfully completed.
- STOPPED: The execution was stopped by the user
- (applicable to step executions).
- ERROR: An error occurred during the execution process.
-
- Note:
- Intermediate statuses might not be experienced due to
- Django's query triggering once all processes are completed.
- """
-
- PENDING = "PENDING"
- EXECUTING = "EXECUTING"
- COMPLETED = "COMPLETED"
- STOPPED = "STOPPED"
- ERROR = "ERROR"
-
- @classmethod
- def is_completed(cls, status: str | ExecutionStatus) -> bool:
- """Check if the execution status is completed."""
- try:
- status_enum = cls(status)
- except ValueError:
- raise ValueError(
- f"Invalid status: {status}. Must be a valid ExecutionStatus."
- )
- return status_enum in [cls.COMPLETED, cls.STOPPED, cls.ERROR]
-
- @classmethod
- def is_active(cls, status: str | ExecutionStatus) -> bool:
- """Check if the workflow execution status is active (in progress)."""
- try:
- status_enum = cls(status)
- except ValueError:
- raise ValueError(
- f"Invalid status: {status}. Must be a valid ExecutionStatus."
- )
- return status_enum in [cls.PENDING, cls.EXECUTING]
-
- @classmethod
- def get_skip_processing_statuses(cls) -> list[ExecutionStatus]:
- """Get list of statuses that should skip file processing.
-
- Skip processing if:
- - EXECUTING: File is currently being processed
- - PENDING: File is queued to be processed
- - COMPLETED: File has already been successfully processed
-
- Returns:
- list[ExecutionStatus]: List of statuses where file processing should be skipped
- """
- return [cls.EXECUTING, cls.PENDING, cls.COMPLETED]
-
- @classmethod
- def should_skip_file_processing(cls, status: str | ExecutionStatus) -> bool:
- """Check if file processing should be skipped based on status.
-
- Allow processing (retry) if:
- - STOPPED: Processing was stopped, can retry
- - ERROR: Processing failed, can retry
- """
- try:
- status_enum = cls(status)
- except ValueError:
- raise ValueError(
- f"Invalid status: {status}. Must be a valid ExecutionStatus."
- )
- return status_enum in cls.get_skip_processing_statuses()
-
- @classmethod
- def can_update_to_pending(cls, status: str | ExecutionStatus) -> bool:
- """Check if a status can be updated to PENDING.
-
- Allow updating to PENDING if:
- - Status is STOPPED or ERROR (can retry)
- - Status is None (new record)
-
- Don't allow updating to PENDING if:
- - Status is EXECUTING (currently processing)
- - Status is COMPLETED (already done)
- - Status is already PENDING (no change needed)
- """
- if status is None:
- return True
-
- try:
- status_enum = cls(status)
- except ValueError:
- return True # Invalid status, allow update
-
- return status_enum in [cls.STOPPED, cls.ERROR]
-
-
class SchemaType(Enum):
"""Possible types for workflow module's JSON schema.
diff --git a/backend/workflow_manager/workflow_v2/execution.py b/backend/workflow_manager/workflow_v2/execution.py
index 68dfe78f5..d06cb0673 100644
--- a/backend/workflow_manager/workflow_v2/execution.py
+++ b/backend/workflow_manager/workflow_v2/execution.py
@@ -78,12 +78,12 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
log_events_id = StateStore.get(Common.LOG_EVENTS_ID)
self.execution_log_id = log_events_id if log_events_id else pipeline_id
self.execution_mode = mode
- self.execution_method: tuple[str, str] = (
+ self.execution_method = (
WorkflowExecution.Method.SCHEDULED
if scheduled
else WorkflowExecution.Method.DIRECT
)
- self.execution_type: tuple[str, str] = (
+ self.execution_type = (
WorkflowExecution.Type.STEP
if single_step
else WorkflowExecution.Type.COMPLETE
@@ -94,7 +94,7 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
execution_mode=mode,
execution_method=self.execution_method,
execution_type=self.execution_type,
- status=ExecutionStatus.EXECUTING,
+ status=ExecutionStatus.EXECUTING.value,
execution_log_id=self.execution_log_id,
)
workflow_execution.save()
@@ -140,12 +140,12 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
if existing_execution:
return existing_execution
- execution_method: tuple[str, str] = (
+ execution_method = (
WorkflowExecution.Method.SCHEDULED
if scheduled
else WorkflowExecution.Method.DIRECT
)
- execution_type: tuple[str, str] = (
+ execution_type = (
WorkflowExecution.Type.STEP
if single_step
else WorkflowExecution.Type.COMPLETE
@@ -159,7 +159,7 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
execution_mode=mode,
execution_method=execution_method,
execution_type=execution_type,
- status=ExecutionStatus.PENDING,
+ status=ExecutionStatus.PENDING.value,
execution_log_id=execution_log_id,
total_files=total_files,
)
@@ -396,7 +396,7 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
def update_execution_err(execution_id: str, err_msg: str = "") -> WorkflowExecution:
try:
execution = WorkflowExecution.objects.get(pk=execution_id)
- execution.status = ExecutionStatus.ERROR
+ execution.status = ExecutionStatus.ERROR.value
execution.error_message = err_msg[:EXECUTION_ERROR_LENGTH]
execution.save()
return execution
diff --git a/backend/workflow_manager/workflow_v2/execution_log_internal_urls.py b/backend/workflow_manager/workflow_v2/execution_log_internal_urls.py
new file mode 100644
index 000000000..7f60dc88d
--- /dev/null
+++ b/backend/workflow_manager/workflow_v2/execution_log_internal_urls.py
@@ -0,0 +1,36 @@
+"""Internal API URLs for Execution Log Operations
+
+URLs for internal APIs that workers use to communicate with Django backend
+for execution log operations. These handle database operations while business
+logic remains in workers.
+"""
+
+from django.urls import path
+
+from . import execution_log_internal_views
+
+app_name = "execution_log_internal"
+
+urlpatterns = [
+ # Execution log management endpoints
+ path(
+ "workflow-executions/by-ids/",
+ execution_log_internal_views.GetWorkflowExecutionsByIdsAPIView.as_view(),
+ name="get_workflow_executions_by_ids",
+ ),
+ path(
+ "file-executions/by-ids/",
+ execution_log_internal_views.GetFileExecutionsByIdsAPIView.as_view(),
+ name="get_file_executions_by_ids",
+ ),
+ path(
+ "executions/validate/",
+ execution_log_internal_views.ValidateExecutionReferencesAPIView.as_view(),
+ name="validate_execution_references",
+ ),
+ path(
+ "process-log-history/",
+ execution_log_internal_views.ProcessLogHistoryAPIView.as_view(),
+ name="process_log_history",
+ ),
+]
diff --git a/backend/workflow_manager/workflow_v2/execution_log_internal_views.py b/backend/workflow_manager/workflow_v2/execution_log_internal_views.py
new file mode 100644
index 000000000..dd839eb55
--- /dev/null
+++ b/backend/workflow_manager/workflow_v2/execution_log_internal_views.py
@@ -0,0 +1,171 @@
+"""Internal API Views for Execution Log Operations
+
+These views handle internal API requests from workers for execution log operations.
+They provide database access while keeping business logic in workers.
+"""
+
+import logging
+
+from rest_framework import status
+from rest_framework.request import Request
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from workflow_manager.file_execution.models import WorkflowFileExecution
+from workflow_manager.workflow_v2.execution_log_utils import (
+ process_log_history_from_cache,
+)
+from workflow_manager.workflow_v2.models import WorkflowExecution
+
+logger = logging.getLogger(__name__)
+
+
+class GetWorkflowExecutionsByIdsAPIView(APIView):
+ """API view for getting workflow executions by IDs."""
+
+ def post(self, request: Request) -> Response:
+ """Get workflow execution data for given IDs.
+
+ Args:
+ request: HTTP request containing execution IDs
+
+ Returns:
+ JSON response with execution data
+ """
+ try:
+ execution_ids = request.data.get("execution_ids", [])
+
+ executions = WorkflowExecution.objects.filter(id__in=execution_ids)
+ execution_data = {}
+
+ for execution in executions:
+ execution_data[str(execution.id)] = {
+ "id": str(execution.id),
+ "workflow_id": str(execution.workflow.id)
+ if execution.workflow
+ else None,
+ "status": execution.status,
+ "created_at": execution.created_at.isoformat()
+ if execution.created_at
+ else None,
+ }
+
+ return Response({"executions": execution_data})
+
+ except Exception as e:
+ logger.error(f"Error getting workflow executions: {e}", exc_info=True)
+ return Response(
+ {"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
+ )
+
+
+class GetFileExecutionsByIdsAPIView(APIView):
+ """API view for getting file executions by IDs."""
+
+ def post(self, request: Request) -> Response:
+ """Get file execution data for given IDs.
+
+ Args:
+ request: HTTP request containing file execution IDs
+
+ Returns:
+ JSON response with file execution data
+ """
+ try:
+ file_execution_ids = request.data.get("file_execution_ids", [])
+
+ file_executions = WorkflowFileExecution.objects.filter(
+ id__in=file_execution_ids
+ )
+ file_execution_data = {}
+
+ for file_execution in file_executions:
+ file_execution_data[str(file_execution.id)] = {
+ "id": str(file_execution.id),
+ "workflow_execution_id": str(file_execution.workflow_execution.id)
+ if file_execution.workflow_execution
+ else None,
+ "status": file_execution.status,
+ "created_at": file_execution.created_at.isoformat()
+ if file_execution.created_at
+ else None,
+ }
+
+ return Response({"file_executions": file_execution_data})
+
+ except Exception as e:
+ logger.error(f"Error getting file executions: {e}", exc_info=True)
+ return Response(
+ {"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
+ )
+
+
+class ValidateExecutionReferencesAPIView(APIView):
+ """API view for validating execution references exist."""
+
+ def post(self, request: Request) -> Response:
+ """Validate that execution references exist.
+
+ Args:
+ request: HTTP request containing execution and file execution IDs
+
+ Returns:
+ JSON response with validation results
+ """
+ try:
+ execution_ids = request.data.get("execution_ids", [])
+ file_execution_ids = request.data.get("file_execution_ids", [])
+
+ # Check which executions exist
+ existing_executions = {
+ str(obj.id)
+ for obj in WorkflowExecution.objects.filter(id__in=execution_ids)
+ }
+
+ # Check which file executions exist
+ existing_file_executions = {
+ str(obj.id)
+ for obj in WorkflowFileExecution.objects.filter(id__in=file_execution_ids)
+ }
+
+ return Response(
+ {
+ "valid_executions": list(existing_executions),
+ "valid_file_executions": list(existing_file_executions),
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Error validating execution references: {e}", exc_info=True)
+ return Response(
+ {"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
+ )
+
+
+class ProcessLogHistoryAPIView(APIView):
+ """API view for processing log history from scheduler.
+
+ This endpoint is called by the log history scheduler when logs exist in Redis queue.
+ It reuses the existing business logic from execution_log_utils.process_log_history_from_cache().
+ """
+
+ def post(self, request: Request) -> Response:
+ """Process log history batch from Redis cache.
+
+ Args:
+ request: HTTP request (no parameters needed)
+
+ Returns:
+ JSON response with processing results
+ """
+ try:
+ # Reuse existing business logic (uses ExecutionLogConstants for config)
+ result = process_log_history_from_cache()
+
+ return Response(result)
+
+ except Exception as e:
+ logger.error(f"Error processing log history: {e}", exc_info=True)
+ return Response(
+ {"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
+ )
diff --git a/backend/workflow_manager/workflow_v2/execution_log_utils.py b/backend/workflow_manager/workflow_v2/execution_log_utils.py
index ff1e99f74..f3914ceda 100644
--- a/backend/workflow_manager/workflow_v2/execution_log_utils.py
+++ b/backend/workflow_manager/workflow_v2/execution_log_utils.py
@@ -16,15 +16,35 @@ from workflow_manager.workflow_v2.models import ExecutionLog, WorkflowExecution
logger = logging.getLogger(__name__)
-@shared_task(name=ExecutionLogConstants.TASK_V2)
-def consume_log_history() -> None:
+def process_log_history_from_cache(
+ queue_name: str = ExecutionLogConstants.LOG_QUEUE_NAME,
+ batch_limit: int = ExecutionLogConstants.LOGS_BATCH_LIMIT,
+) -> dict:
+ """Process log history from Redis cache.
+
+ This function contains the core business logic for processing execution logs
+ from Redis cache to database. It can be called by both the Celery task and
+ internal API endpoints.
+
+ Args:
+ queue_name: Redis queue name to process logs from
+ batch_limit: Maximum number of logs to process in one batch
+
+ Returns:
+ Dictionary with processing results:
+ - processed_count: Number of logs successfully stored
+ - skipped_count: Number of logs skipped (invalid references)
+ - total_logs: Total number of logs retrieved from cache
+ - organizations_processed: Number of organizations affected
+ """
organization_logs = defaultdict(list)
logs_count = 0
logs_to_process = []
+ skipped_count = 0
# Collect logs from cache (batch retrieval)
- while logs_count < ExecutionLogConstants.LOGS_BATCH_LIMIT:
- log = CacheService.lpop(ExecutionLogConstants.LOG_QUEUE_NAME)
+ while logs_count < batch_limit:
+ log = CacheService.lpop(queue_name)
if not log:
break
@@ -34,9 +54,14 @@ def consume_log_history() -> None:
logs_count += 1
if not logs_to_process:
- return # No logs to process
+ return {
+ "processed_count": 0,
+ "skipped_count": 0,
+ "total_logs": 0,
+ "organizations_processed": 0,
+ }
- logger.info(f"Logs count: {logs_count}")
+ logger.info(f"Processing {logs_count} logs from queue '{queue_name}'")
# Preload required WorkflowExecution and WorkflowFileExecution objects
execution_ids = {log.execution_id for log in logs_to_process}
@@ -60,7 +85,8 @@ def consume_log_history() -> None:
f"Execution not found for execution_id: {log_data.execution_id}, "
"skipping log push"
)
- continue # Skip logs with missing execution reference
+ skipped_count += 1
+ continue
execution_log = ExecutionLog(
wf_execution=execution,
@@ -69,16 +95,42 @@ def consume_log_history() -> None:
)
if log_data.file_execution_id:
- execution_log.file_execution = file_execution_map.get(
- log_data.file_execution_id
- )
+ file_execution = file_execution_map.get(log_data.file_execution_id)
+ if file_execution:
+ execution_log.file_execution = file_execution
+ else:
+ logger.warning(
+ f"File execution not found for file_execution_id: {log_data.file_execution_id}, "
+ "skipping log push"
+ )
+ skipped_count += 1
+ continue
organization_logs[log_data.organization_id].append(execution_log)
# Bulk insert logs for each organization
+ processed_count = 0
for organization_id, logs in organization_logs.items():
- logger.info(f"Storing '{len(logs)}' logs for org: {organization_id}")
+ logger.info(f"Storing {len(logs)} logs for org: {organization_id}")
ExecutionLog.objects.bulk_create(objs=logs, ignore_conflicts=True)
+ processed_count += len(logs)
+
+ return {
+ "processed_count": processed_count,
+ "skipped_count": skipped_count,
+ "total_logs": logs_count,
+ "organizations_processed": len(organization_logs),
+ }
+
+
+@shared_task(name=ExecutionLogConstants.TASK_V2)
+def consume_log_history() -> None:
+ """Celery task to consume log history from Redis cache.
+
+ This task is a thin wrapper around process_log_history_from_cache() for
+ backward compatibility with existing Celery Beat schedules.
+ """
+ process_log_history_from_cache()
def create_log_consumer_scheduler_if_not_exists() -> None:
diff --git a/backend/workflow_manager/workflow_v2/file_history_helper.py b/backend/workflow_manager/workflow_v2/file_history_helper.py
index 3d730f7f9..df203b8b7 100644
--- a/backend/workflow_manager/workflow_v2/file_history_helper.py
+++ b/backend/workflow_manager/workflow_v2/file_history_helper.py
@@ -5,6 +5,7 @@ from typing import Any
from django.db.models import Q
from django.db.utils import IntegrityError
from django.utils import timezone
+from utils.cache_service import CacheService
from workflow_manager.endpoint_v2.dto import FileHash
from workflow_manager.endpoint_v2.models import WorkflowEndpoint
@@ -245,8 +246,8 @@ class FileHistoryHelper:
metadata: str | None,
error: str | None = None,
is_api: bool = False,
- ) -> None:
- """Create a new file history record.
+ ) -> FileHistory:
+ """Create a new file history record or return existing one.
Args:
file_hash (FileHash): The file hash for the file.
@@ -255,35 +256,90 @@ class FileHistoryHelper:
result (Any): The result from the execution.
metadata (str | None): The metadata from the execution.
error (str | None): The error from the execution.
- is_api (bool): Whether this is an API call.
+ is_api (bool): Whether this is for API workflow (affects file_path handling).
+
+ Returns:
+ FileHistory: Either newly created or existing file history record.
"""
+ file_path = file_hash.file_path if not is_api else None
+
+ # Prepare data for creation
+ create_data = {
+ "workflow": workflow,
+ "cache_key": file_hash.file_hash,
+ "provider_file_uuid": file_hash.provider_file_uuid,
+ "status": status,
+ "result": str(result),
+ "metadata": str(metadata) if metadata else "",
+ "error": str(error) if error else "",
+ "file_path": file_path,
+ }
+
try:
- file_path = file_hash.file_path if not is_api else None
+ # Try to create the file history record
+ file_history = FileHistory.objects.create(**create_data)
+ logger.info(
+ f"Created new FileHistory record - "
+ f"file_name='{file_hash.file_name}', file_path='{file_hash.file_path}', "
+ f"file_hash='{file_hash.file_hash[:16] if file_hash.file_hash else 'None'}', "
+ f"workflow={workflow}"
+ )
+ return file_history
- FileHistory.objects.create(
+ except IntegrityError as e:
+ # Race condition detected - another worker created the record
+ # Try to retrieve the existing record
+ logger.info(
+ f"FileHistory constraint violation (expected in concurrent environment) - "
+ f"file_name='{file_hash.file_name}', file_path='{file_hash.file_path}', "
+ f"file_hash='{file_hash.file_hash[:16] if file_hash.file_hash else 'None'}', "
+ f"workflow={workflow}. Error: {str(e)}"
+ )
+
+ # Use the existing get_file_history method to retrieve the record
+ existing_record = FileHistoryHelper.get_file_history(
workflow=workflow,
cache_key=file_hash.file_hash,
provider_file_uuid=file_hash.provider_file_uuid,
- status=status,
- result=str(result),
- metadata=str(metadata) if metadata else "",
- error=str(error) if error else "",
file_path=file_path,
)
- except IntegrityError as e:
- # TODO: Need to find why duplicate insert is coming
- logger.warning(
- f"Trying to insert duplication data for filename {file_hash.file_name} "
- f"for workflow {workflow}. Error: {str(e)} with metadata {metadata}",
- )
+
+ if existing_record:
+ logger.info(
+ f"Retrieved existing FileHistory record after constraint violation - "
+ f"ID: {existing_record.id}, workflow={workflow}"
+ )
+ return existing_record
+ else:
+ # This should rarely happen, but if we can't find the existing record,
+ # log the issue and re-raise the original exception
+ logger.error(
+ f"Failed to retrieve existing FileHistory record after constraint violation - "
+ f"file_name='{file_hash.file_name}', workflow={workflow}"
+ )
@staticmethod
def clear_history_for_workflow(
workflow: Workflow,
) -> None:
- """Clear all file history records associated with a workflow.
+ """Clear all file history records and Redis caches associated with a workflow.
Args:
workflow (Workflow): The workflow to clear the history for.
"""
+ # Clear database records
FileHistory.objects.filter(workflow=workflow).delete()
+ logger.info(f"Cleared database records for workflow {workflow.id}")
+
+ # Clear Redis caches for file_active entries
+ pattern = f"file_active:{workflow.id}:*"
+
+ try:
+ CacheService.clear_cache_optimized(pattern)
+ logger.info(
+ f"Cleared Redis cache entries for workflow {workflow.id} with pattern: {pattern}"
+ )
+ except Exception as e:
+ logger.warning(
+ f"Failed to clear Redis caches for workflow {workflow.id}: {str(e)}"
+ )
diff --git a/backend/workflow_manager/workflow_v2/file_history_internal_urls.py b/backend/workflow_manager/workflow_v2/file_history_internal_urls.py
new file mode 100644
index 000000000..28cb331d2
--- /dev/null
+++ b/backend/workflow_manager/workflow_v2/file_history_internal_urls.py
@@ -0,0 +1,45 @@
+"""Internal API URLs for file history operations."""
+
+from django.urls import path
+
+from .views import (
+ create_file_history_internal,
+ file_history_batch_lookup_internal,
+ file_history_by_cache_key_internal,
+ file_history_status_internal,
+ get_file_history_internal,
+ reserve_file_processing_internal,
+)
+
+urlpatterns = [
+ # File history endpoints
+ path(
+ "cache-key/<str:cache_key>/",
+ file_history_by_cache_key_internal,
+ name="file-history-by-cache-key-internal",
+ ),
+ # Flexible lookup endpoint (supports both cache_key and provider_file_uuid)
+ path(
+ "lookup/",
+ file_history_by_cache_key_internal,
+ name="file-history-lookup-internal",
+ ),
+ # Batch lookup endpoint for multiple files
+ path(
+ "batch-lookup/",
+ file_history_batch_lookup_internal,
+ name="file-history-batch-lookup-internal",
+ ),
+ path("create/", create_file_history_internal, name="create-file-history-internal"),
+ path(
+ "status/<str:file_history_id>/",
+ file_history_status_internal,
+ name="file-history-status-internal",
+ ),
+ path(
+ "reserve/",
+ reserve_file_processing_internal,
+ name="reserve-file-processing-internal",
+ ),
+ path("get/", get_file_history_internal, name="get-file-history-internal"),
+]
diff --git a/backend/workflow_manager/workflow_v2/models/execution.py b/backend/workflow_manager/workflow_v2/models/execution.py
index b927f1d65..f06baa6d6 100644
--- a/backend/workflow_manager/workflow_v2/models/execution.py
+++ b/backend/workflow_manager/workflow_v2/models/execution.py
@@ -6,7 +6,6 @@ from api_v2.models import APIDeployment
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.db.models import QuerySet, Sum
-from django.utils import timezone
from pipeline_v2.models import Pipeline
from tags.models import Tag
from usage_v2.constants import UsageKeys
@@ -226,6 +225,17 @@ class WorkflowExecution(BaseModel):
def is_completed(self) -> bool:
return ExecutionStatus.is_completed(self.status)
+ @property
+ def organization_id(self) -> str | None:
+ """Get the organization ID from the associated workflow."""
+ if (
+ self.workflow
+ and hasattr(self.workflow, "organization")
+ and self.workflow.organization
+ ):
+ return str(self.workflow.organization.organization_id)
+ return None
+
def __str__(self) -> str:
return (
f"Workflow execution: {self.id} ("
@@ -250,19 +260,15 @@ class WorkflowExecution(BaseModel):
increment_attempt (bool, optional): Whether to increment attempt counter. Defaults to False.
"""
if status is not None:
+ status = ExecutionStatus(status)
self.status = status.value
- if (
- status
- in [
- ExecutionStatus.COMPLETED,
- ExecutionStatus.ERROR,
- ExecutionStatus.STOPPED,
- ]
- and not self.execution_time
- ):
- self.execution_time = round(
- (timezone.now() - self.created_at).total_seconds(), 3
- )
+ if status in [
+ ExecutionStatus.COMPLETED,
+ ExecutionStatus.ERROR,
+ ExecutionStatus.STOPPED,
+ ]:
+ self.execution_time = CommonUtils.time_since(self.created_at, 3)
+
if error:
self.error_message = error[:EXECUTION_ERROR_LENGTH]
if increment_attempt:
diff --git a/backend/workflow_manager/workflow_v2/models/file_history.py b/backend/workflow_manager/workflow_v2/models/file_history.py
index 34a9f44a3..1935b246c 100644
--- a/backend/workflow_manager/workflow_v2/models/file_history.py
+++ b/backend/workflow_manager/workflow_v2/models/file_history.py
@@ -18,7 +18,7 @@ class FileHistory(BaseModel):
Returns:
bool: True if the execution status is completed, False otherwise.
"""
- return self.status is not None and self.status == ExecutionStatus.COMPLETED
+ return self.status is not None and self.status == ExecutionStatus.COMPLETED.value
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
cache_key = models.CharField(
diff --git a/backend/workflow_manager/workflow_v2/serializers.py b/backend/workflow_manager/workflow_v2/serializers.py
index 4c53ad28b..26e377a6a 100644
--- a/backend/workflow_manager/workflow_v2/serializers.py
+++ b/backend/workflow_manager/workflow_v2/serializers.py
@@ -21,6 +21,7 @@ from backend.serializers import AuditSerializer
from workflow_manager.workflow_v2.constants import WorkflowExecutionKey, WorkflowKey
from workflow_manager.workflow_v2.models.execution import WorkflowExecution
from workflow_manager.workflow_v2.models.execution_log import ExecutionLog
+from workflow_manager.workflow_v2.models.file_history import FileHistory
from workflow_manager.workflow_v2.models.workflow import Workflow
logger = logging.getLogger(__name__)
@@ -129,6 +130,12 @@ class WorkflowExecutionLogSerializer(ModelSerializer):
fields = "__all__"
+class FileHistorySerializer(ModelSerializer):
+ class Meta:
+ model = FileHistory
+ fields = "__all__"
+
+
class SharedUserListSerializer(ModelSerializer):
"""Serializer for returning workflow with shared user details."""
diff --git a/backend/workflow_manager/workflow_v2/views.py b/backend/workflow_manager/workflow_v2/views.py
index 8cb85a38c..64795c070 100644
--- a/backend/workflow_manager/workflow_v2/views.py
+++ b/backend/workflow_manager/workflow_v2/views.py
@@ -1,17 +1,24 @@
import logging
+import uuid
from typing import Any
from django.conf import settings
+from django.db import transaction
from django.db.models.query import QuerySet
+from django.shortcuts import get_object_or_404
+from django.utils import timezone
+from django.views.decorators.csrf import csrf_exempt
from permissions.permission import IsOwner, IsOwnerOrSharedUser
from pipeline_v2.models import Pipeline
from pipeline_v2.pipeline_processor import PipelineProcessor
from rest_framework import serializers, status, viewsets
-from rest_framework.decorators import action
+from rest_framework.decorators import action, api_view
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.versioning import URLPathVersioning
+from rest_framework.views import APIView
from utils.filtering import FilterHelper
+from utils.organization_utils import filter_queryset_by_organization, resolve_organization
try:
from plugins.notification.constants import ResourceType
@@ -25,10 +32,20 @@ except ImportError:
from backend.constants import RequestKey
+from unstract.core.data_models import FileHistoryCreateRequest
from workflow_manager.endpoint_v2.destination import DestinationConnector
from workflow_manager.endpoint_v2.dto import FileHash
from workflow_manager.endpoint_v2.endpoint_utils import WorkflowEndpointUtils
from workflow_manager.endpoint_v2.source import SourceConnector
+from workflow_manager.file_execution.models import WorkflowFileExecution
+from workflow_manager.internal_serializers import (
+ FileBatchCreateSerializer,
+ FileBatchResponseSerializer,
+ WorkflowExecutionContextSerializer,
+ WorkflowExecutionSerializer,
+ WorkflowExecutionStatusUpdateSerializer,
+ WorkflowFileExecutionSerializer,
+)
from workflow_manager.workflow_v2.constants import WorkflowKey
from workflow_manager.workflow_v2.dto import ExecutionResponse
from workflow_manager.workflow_v2.enums import SchemaEntity, SchemaType
@@ -246,7 +263,7 @@ class WorkflowViewSet(viewsets.ModelViewSet):
status=status.HTTP_200_OK,
)
except Exception as exception:
- logger.error(f"Error while executing workflow: {exception}")
+ logger.error(f"Error while executing workflow: {exception}", exc_info=True)
if file_objs and execution_id and workflow_id:
DestinationConnector.delete_api_storage_dir(
workflow_id=workflow_id, execution_id=execution_id
@@ -341,3 +358,1308 @@ class WorkflowViewSet(viewsets.ModelViewSet):
workflow = self.get_object()
serializer = SharedUserListSerializer(workflow)
return Response(serializer.data, status=status.HTTP_200_OK)
+
+
+# =============================================================================
+# INTERNAL API VIEWS - Used by Celery workers for service-to-service communication
+# =============================================================================
+
+
+class WorkflowExecutionInternalViewSet(viewsets.ReadOnlyModelViewSet):
+ """Internal API ViewSet for Workflow Execution operations.
+ Used by Celery workers for service-to-service communication.
+ """
+
+ serializer_class = WorkflowExecutionSerializer
+ lookup_field = "id"
+
+ def get_queryset(self):
+ """Get workflow executions filtered by organization context."""
+ queryset = WorkflowExecution.objects.all()
+ return filter_queryset_by_organization(queryset, self.request)
+
+ def retrieve(self, request, *args, **kwargs):
+ """Get specific workflow execution with context."""
+ try:
+ execution = self.get_object()
+
+ # Build comprehensive context
+ context_data = {
+ "execution": WorkflowExecutionSerializer(execution).data,
+ "workflow_definition": execution.workflow.workflow_definition
+ if execution.workflow
+ else {},
+ "source_config": self._get_source_config(execution),
+ "destination_config": self._get_destination_config(execution),
+ "organization_context": self._get_organization_context(execution),
+ "file_executions": WorkflowFileExecutionSerializer(
+ execution.file_executions.all(), many=True
+ ).data,
+ }
+
+ serializer = WorkflowExecutionContextSerializer(context_data)
+ return Response(serializer.data)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to retrieve workflow execution {kwargs.get('id')}: {str(e)}"
+ )
+ return Response(
+ {"error": "Failed to retrieve workflow execution", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ def _get_source_config(self, execution: WorkflowExecution) -> dict:
+ """Get source configuration for execution."""
+ try:
+ if execution.pipeline_id:
+ # Add organization filtering for pipeline lookup
+ org_id = getattr(self.request, "organization_id", None)
+ if org_id:
+ # Use shared utility to resolve organization
+ organization = resolve_organization(org_id, raise_on_not_found=False)
+ if organization:
+ pipeline = Pipeline.objects.get(
+ id=execution.pipeline_id, organization=organization
+ )
+ else:
+ logger.warning(
+ f"Organization {org_id} not found for pipeline lookup"
+ )
+ return {}
+ else:
+ pipeline = Pipeline.objects.get(id=execution.pipeline_id)
+ return {
+ "type": "pipeline",
+ "pipeline_id": str(pipeline.id),
+ "source_settings": pipeline.source,
+ "is_api": False,
+ }
+ else:
+ api_deployment = execution.workflow.api_deployments.first()
+ if api_deployment:
+ return {
+ "type": "api_deployment",
+ "deployment_id": str(api_deployment.id),
+ "is_api": True,
+ }
+ return {}
+ except Pipeline.DoesNotExist:
+ logger.warning(
+ f"Pipeline {execution.pipeline_id} not found for execution {execution.id}"
+ )
+ return {}
+ except Exception as e:
+ logger.warning(
+ f"Failed to get source config for execution {execution.id}: {str(e)}"
+ )
+ return {}
+
+ def _get_destination_config(self, execution: WorkflowExecution) -> dict:
+ """Get destination configuration for execution."""
+ try:
+ if execution.pipeline_id:
+ # Add organization filtering for pipeline lookup
+ org_id = getattr(self.request, "organization_id", None)
+ if org_id:
+ # Use shared utility to resolve organization
+ organization = resolve_organization(org_id, raise_on_not_found=False)
+ if organization:
+ pipeline = Pipeline.objects.get(
+ id=execution.pipeline_id, organization=organization
+ )
+ else:
+ logger.warning(
+ f"Organization {org_id} not found for destination pipeline lookup"
+ )
+ return {}
+ else:
+ pipeline = Pipeline.objects.get(id=execution.pipeline_id)
+ return {"destination_settings": pipeline.destination}
+ return {}
+ except Pipeline.DoesNotExist:
+ logger.warning(
+ f"Pipeline {execution.pipeline_id} not found for destination config in execution {execution.id}"
+ )
+ return {}
+ except Exception as e:
+ logger.warning(
+ f"Failed to get destination config for execution {execution.id}: {str(e)}"
+ )
+ return {}
+
+ def _get_organization_context(self, execution: WorkflowExecution) -> dict:
+ """Get organization context for execution."""
+ try:
+ return {
+ "organization_id": str(execution.organization.id),
+ "organization_name": execution.organization.display_name,
+ "settings": {},
+ }
+ except Exception as e:
+ logger.warning(
+ f"Failed to get organization context for execution {execution.id}: {str(e)}"
+ )
+ return {}
+
+ @action(detail=True, methods=["post"])
+ def status(self, request, id=None):
+ """Update workflow execution status."""
+ try:
+ execution = self.get_object()
+ serializer = WorkflowExecutionStatusUpdateSerializer(data=request.data)
+
+ if serializer.is_valid():
+ validated_data = serializer.validated_data
+
+ execution.status = validated_data["status"]
+ if validated_data.get("error_message"):
+ execution.error_message = validated_data["error_message"]
+ if validated_data.get("total_files") is not None:
+ execution.total_files = validated_data["total_files"]
+ if validated_data.get("attempts") is not None:
+ execution.attempts = validated_data["attempts"]
+ if validated_data.get("execution_time") is not None:
+ execution.execution_time = validated_data["execution_time"]
+
+ execution.modified_at = timezone.now()
+ execution.save()
+
+ logger.info(
+ f"Updated workflow execution {id} status to {validated_data['status']}"
+ )
+
+ return Response(
+ {
+ "status": "updated",
+ "execution_id": str(execution.id),
+ "new_status": execution.status,
+ }
+ )
+
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ except Exception as e:
+ logger.error(f"Failed to update workflow execution status {id}: {str(e)}")
+ return Response(
+ {"error": "Failed to update execution status", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+class FileBatchCreateInternalAPIView(APIView):
+ """Internal API endpoint for creating file batches for workflow execution.
+ Used by Celery workers for service-to-service communication.
+ """
+
+ def post(self, request):
+ """Create file execution records in batches."""
+ try:
+ serializer = FileBatchCreateSerializer(data=request.data)
+
+ if not serializer.is_valid():
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+ validated_data = serializer.validated_data
+ workflow_execution_id = validated_data["workflow_execution_id"]
+ files_data = validated_data["files"]
+ is_api = validated_data["is_api"]
+
+ workflow_execution = get_object_or_404(
+ WorkflowExecution, id=workflow_execution_id
+ )
+
+ created_file_executions = []
+
+ with transaction.atomic():
+ for file_data in files_data:
+ file_hash = FileHash(
+ file_name=file_data["file_name"],
+ file_path=file_data.get("file_path"),
+ file_size=file_data.get("file_size"),
+ file_hash=file_data.get("file_hash"),
+ provider_file_uuid=file_data.get("provider_file_uuid"),
+ mime_type=file_data.get("mime_type"),
+ fs_metadata=file_data.get("fs_metadata"),
+ )
+
+ file_execution = (
+ WorkflowFileExecution.objects.get_or_create_file_execution(
+ workflow_execution=workflow_execution,
+ file_hash=file_hash,
+ is_api=is_api,
+ )
+ )
+
+ created_file_executions.append(file_execution)
+
+ batch_id = str(uuid.uuid4())
+
+ response_data = {
+ "batch_id": batch_id,
+ "workflow_execution_id": workflow_execution_id,
+ "total_files": len(created_file_executions),
+ "created_file_executions": WorkflowFileExecutionSerializer(
+ created_file_executions, many=True
+ ).data,
+ }
+
+ response_serializer = FileBatchResponseSerializer(response_data)
+
+ logger.info(
+ f"Created file batch {batch_id} with {len(created_file_executions)} files for execution {workflow_execution_id}"
+ )
+
+ return Response(response_serializer.data, status=status.HTTP_201_CREATED)
+
+ except Exception as e:
+ logger.error(f"Failed to create file batch: {str(e)}")
+ return Response(
+ {"error": "Failed to create file batch", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+# =============================================================================
+# FILE HISTORY INTERNAL API VIEWS
+# =============================================================================
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET", "POST"])
+def file_history_by_cache_key_internal(request, cache_key=None):
+ """Get file history by cache key or provider_file_uuid for internal API calls.
+
+ CSRF exempt because this is an internal API that:
+ - Requires Bearer token authentication (INTERNAL_SERVICE_API_KEY)
+ - Is used for service-to-service communication only
+ - Performs read-only operations
+ - Does not rely on cookies or session-based authentication
+
+ Supports both GET (legacy) and POST (flexible) methods:
+
+ GET /file-history/cache-key/{cache_key}/?workflow_id=X&file_path=Y (legacy)
+ POST /file-history/lookup/ with JSON body (flexible)
+
+ This replaces the FileHistoryHelper.get_file_history() calls in heavy workers.
+ """
+ try:
+ from workflow_manager.workflow_v2.file_history_helper import FileHistoryHelper
+
+ organization_id = getattr(request, "organization_id", None)
+
+ # Handle both GET (legacy) and POST (flexible) requests
+ if request.method == "GET":
+ # Legacy GET method: extract from URL and query params
+ workflow_id = request.GET.get("workflow_id")
+ file_path = request.GET.get("file_path")
+ provider_file_uuid = None
+
+ if not cache_key:
+ return Response(
+ {"error": "cache_key is required for GET requests"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+ else:
+ # New POST method: extract from JSON body
+ workflow_id = request.data.get("workflow_id")
+ cache_key = request.data.get("cache_key")
+ provider_file_uuid = request.data.get("provider_file_uuid")
+ file_path = request.data.get("file_path")
+ organization_id = request.data.get("organization_id") or organization_id
+
+ if not workflow_id:
+ return Response(
+ {"error": "workflow_id parameter is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Must have either cache_key or provider_file_uuid
+ if not cache_key and not provider_file_uuid:
+ return Response(
+ {"error": "Either cache_key or provider_file_uuid is required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get workflow to pass to helper
+ try:
+ workflow = Workflow.objects.get(pk=workflow_id)
+ if (
+ organization_id
+ and workflow.organization.organization_id != organization_id
+ ):
+ return Response(
+ {"error": "Workflow not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ # Get file history using existing helper with flexible parameters
+ file_history = FileHistoryHelper.get_file_history(
+ workflow=workflow,
+ cache_key=cache_key,
+ provider_file_uuid=provider_file_uuid,
+ file_path=file_path,
+ )
+
+ if file_history:
+ from workflow_manager.workflow_v2.serializers import FileHistorySerializer
+
+ serializer = FileHistorySerializer(file_history)
+
+ return Response(
+ {"found": True, "cache_key": cache_key, "file_history": serializer.data},
+ status=status.HTTP_200_OK,
+ )
+ else:
+ return Response(
+ {"found": False, "cache_key": cache_key, "file_history": None},
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get file history for cache key {cache_key}: {e}")
+ return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def file_history_batch_lookup_internal(request):
+ """Get file history for multiple files in a single batch operation.
+
+ This endpoint optimizes file history checking by processing multiple files
+ in a single database query, reducing API calls from N to 1.
+
+ POST /file-history/batch-lookup/
+ {
+ "workflow_id": "uuid",
+ "organization_id": "uuid",
+ "files": [
+ {
+ "cache_key": "hash1", // Optional
+ "provider_file_uuid": "uuid1", // Optional
+ "file_path": "/dir1/file1.pdf", // Optional
+ "identifier": "custom_key1" // Optional unique identifier for response mapping
+ },
+ {
+ "provider_file_uuid": "uuid2",
+ "file_path": "/dir2/file2.pdf"
+ }
+ ]
+ }
+
+ Response:
+ {
+ "file_histories": {
+ "hash1": {"found": true, "is_completed": true, "file_path": "/dir1/file1.pdf", ...},
+ "uuid2": {"found": false, "is_completed": false, ...}
+ }
+ }
+ """
+ try:
+ import operator
+ from functools import reduce
+
+ from django.db.models import Q
+
+ from workflow_manager.workflow_v2.models.file_history import FileHistory
+ from workflow_manager.workflow_v2.serializers import FileHistorySerializer
+
+ organization_id = getattr(request, "organization_id", None)
+
+ # Extract parameters from request body
+ workflow_id = request.data.get("workflow_id")
+ files_data = request.data.get("files", [])
+ organization_id = request.data.get("organization_id") or organization_id
+
+ if not workflow_id or not files_data:
+ return Response(
+ {"error": "workflow_id and files array are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Validate that each file has at least one identifier
+ for i, file_data in enumerate(files_data):
+ if not any([file_data.get("cache_key"), file_data.get("provider_file_uuid")]):
+ return Response(
+ {
+ "error": f"File at index {i} must have either cache_key or provider_file_uuid"
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Deduplicate requests to prevent duplicate SQL conditions
+ seen_identifiers = set()
+ deduplicated_files = []
+
+ for file_data in files_data:
+ # Create identifier for deduplication
+ identifier = file_data.get("identifier")
+ if not identifier:
+ logger.info(
+ f"DEBUG: FileHistoryBatch - No identifier provided for file {file_data}, creating default"
+ )
+ # Create default identifier if not provided
+ identifier = _create_default_identifier(file_data)
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Identifier for file {file_data}: {identifier}"
+ )
+ if identifier not in seen_identifiers:
+ seen_identifiers.add(identifier)
+ # Ensure the file_data has the identifier for response mapping
+ file_data["identifier"] = identifier
+ deduplicated_files.append(file_data)
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Deduplicated {len(files_data)} → {len(deduplicated_files)} files"
+ )
+
+ # Use deduplicated files for processing
+ files_data = deduplicated_files
+
+ # Get workflow
+ try:
+ workflow = Workflow.objects.get(pk=workflow_id)
+ if (
+ organization_id
+ and workflow.organization.organization_id != organization_id
+ ):
+ return Response(
+ {"error": "Workflow not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ # Build optimized batch query using OR conditions
+ queries = []
+ # Enhanced mapping to handle UUID collisions
+ file_identifiers = {} # Maps provider_file_uuid -> identifier (legacy for simple cases)
+ composite_file_map = {} # Maps composite keys -> identifier for collision resolution
+ request_files_map = {} # Maps identifiers back to original request data
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Building queries for {len(files_data)} files"
+ )
+
+ for i, file_data in enumerate(files_data):
+ filters = Q(workflow=workflow)
+
+ # Primary identifier for this file (for response mapping)
+ identifier = (
+ file_data.get("identifier")
+ or file_data.get("cache_key")
+ or file_data.get("provider_file_uuid")
+ )
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1}: {file_data.get('file_path', 'NO_PATH')}"
+ f" (identifier: {identifier})"
+ )
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1} data: cache_key={file_data.get('cache_key')}, "
+ f"provider_file_uuid={file_data.get('provider_file_uuid')}, "
+ f"file_path={file_data.get('file_path')}"
+ )
+
+ # Store request data for later lookup
+ request_files_map[identifier] = file_data
+
+ if file_data.get("cache_key"):
+ cache_key_filters = Q(cache_key=file_data["cache_key"])
+ # Create composite mapping for collision resolution
+ if file_data.get("file_path"):
+ composite_key = f"cache_key:{file_data['cache_key']}:path:{file_data['file_path']}"
+ composite_file_map[composite_key] = identifier
+ # Legacy mapping (may have collisions)
+ file_identifiers[file_data["cache_key"]] = identifier
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1}: Using cache_key={file_data['cache_key']}, "
+ f"mapped to identifier={identifier}"
+ )
+ elif file_data.get("provider_file_uuid"):
+ cache_key_filters = Q(provider_file_uuid=file_data["provider_file_uuid"])
+ # Create composite mapping for collision resolution
+ if file_data.get("file_path"):
+ composite_key = f"uuid:{file_data['provider_file_uuid']}:path:{file_data['file_path']}"
+ composite_file_map[composite_key] = identifier
+ # Legacy mapping (may have collisions)
+ file_identifiers[file_data["provider_file_uuid"]] = identifier
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1}: Using provider_file_uuid={file_data['provider_file_uuid']}, "
+ f"mapped to identifier={identifier}"
+ )
+ else:
+ logger.warning(
+ f"DEBUG: FileHistoryBatch - File {i+1}: No cache_key or provider_file_uuid!"
+ )
+ continue
+
+ # Replicate the FileHistoryHelper.get_file_history logic:
+ # Try both exact file_path match AND file_path__isnull=True (legacy fallback)
+ if file_data.get("file_path"):
+ # Primary query: exact file_path match
+ path_filters = Q(file_path=file_data["file_path"])
+ # Fallback query: legacy records without file_path
+ fallback_filters = Q(file_path__isnull=True)
+ # Combine: match either exact path OR legacy null path
+ filters &= cache_key_filters & (path_filters | fallback_filters)
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1}: Added file_path constraint={file_data['file_path']} "
+ f"with legacy fallback (file_path__isnull=True)"
+ )
+ else:
+ # No file_path provided, only search legacy records
+ filters &= cache_key_filters & Q(file_path__isnull=True)
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1}: No file_path provided, using legacy fallback only"
+ )
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - File {i+1}: Final query filters: {filters}"
+ )
+
+ queries.append(filters)
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - file_identifiers mapping: {file_identifiers}"
+ )
+ logger.info(f"DEBUG: FileHistoryBatch - composite_file_map: {composite_file_map}")
+ logger.info(
+ f"DEBUG: FileHistoryBatch - request_files_map keys: {list(request_files_map.keys())}"
+ )
+
+ # Execute single batch query with OR conditions
+ if queries:
+ combined_query = reduce(operator.or_, queries)
+ file_histories_queryset = FileHistory.objects.filter(
+ combined_query
+ ).select_related("workflow")
+
+ # Log the exact SQL query for debugging
+ logger.info(
+ f"DEBUG: FileHistoryBatch SQL Query: {file_histories_queryset.query}"
+ )
+
+ file_histories = list(
+ file_histories_queryset
+ ) # Convert to list to allow multiple iterations
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Raw database results: {len(file_histories)} records found"
+ )
+ for i, fh in enumerate(file_histories):
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB Record {i+1}: "
+ f"provider_file_uuid={fh.provider_file_uuid}, "
+ f"cache_key={fh.cache_key}, "
+ f"file_path={fh.file_path}, "
+ f"status={fh.status}"
+ )
+ else:
+ file_histories = []
+ logger.info("DEBUG: FileHistoryBatch - No queries to execute")
+
+ # Build response mapping
+ response_data = {}
+
+ # Initialize all files as not found
+ for file_data in files_data:
+ identifier = (
+ file_data.get("identifier")
+ or file_data.get("cache_key")
+ or file_data.get("provider_file_uuid")
+ )
+ response_data[identifier] = {
+ "found": False,
+ "is_completed": False,
+ "file_history": None,
+ }
+
+ # Enhanced response mapping to handle UUID collisions
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Starting response mapping for {len(file_histories)} database records"
+ )
+
+ for i, fh in enumerate(file_histories):
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Processing DB record {i+1}: "
+ f"cache_key={fh.cache_key}, provider_file_uuid={fh.provider_file_uuid}, file_path={fh.file_path}"
+ )
+
+ # Strategy 1: Try composite key matching (handles UUID collisions)
+ matched_identifiers = []
+
+ if fh.cache_key and fh.file_path:
+ composite_key = f"cache_key:{fh.cache_key}:path:{fh.file_path}"
+ if composite_key in composite_file_map:
+ matched_identifiers.append(composite_file_map[composite_key])
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: Matched by composite cache_key={composite_key} "
+ f"-> identifier={composite_file_map[composite_key]}"
+ )
+
+ if fh.provider_file_uuid and fh.file_path:
+ composite_key = f"uuid:{fh.provider_file_uuid}:path:{fh.file_path}"
+ if composite_key in composite_file_map:
+ matched_identifiers.append(composite_file_map[composite_key])
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: Matched by composite uuid={composite_key} "
+ f"-> identifier={composite_file_map[composite_key]}"
+ )
+
+ # Strategy 2: If no composite match, try legacy UUID-only matching
+ if not matched_identifiers:
+ if fh.cache_key and fh.cache_key in file_identifiers:
+ matched_identifiers.append(file_identifiers[fh.cache_key])
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: Matched by legacy cache_key={fh.cache_key} "
+ f"-> identifier={file_identifiers[fh.cache_key]}"
+ )
+ elif fh.provider_file_uuid and fh.provider_file_uuid in file_identifiers:
+ matched_identifiers.append(file_identifiers[fh.provider_file_uuid])
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: Matched by legacy provider_file_uuid={fh.provider_file_uuid} "
+ f"-> identifier={file_identifiers[fh.provider_file_uuid]}"
+ )
+
+ # Strategy 3: Manual collision resolution for files with same UUID but different paths
+ if not matched_identifiers and fh.provider_file_uuid:
+ # Find all request files with this UUID
+ potential_matches = []
+ for req_identifier, req_data in request_files_map.items():
+ if req_data.get("provider_file_uuid") == fh.provider_file_uuid:
+ potential_matches.append((req_identifier, req_data))
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: Found {len(potential_matches)} potential UUID matches"
+ )
+
+ # Try to match by file path
+ for req_identifier, req_data in potential_matches:
+ req_path = req_data.get("file_path")
+ if fh.file_path == req_path:
+ matched_identifiers.append(req_identifier)
+ logger.info(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: Matched by manual path comparison "
+ f"db_path={fh.file_path} == req_path={req_path} -> identifier={req_identifier}"
+ )
+ break
+
+ # If still no exact path match, but we have UUID matches, log for fallback handling
+ if not matched_identifiers and potential_matches:
+ logger.warning(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: UUID collision detected! "
+ f"DB path={fh.file_path} doesn't match any request paths: "
+ f"{[req_data.get('file_path') for _, req_data in potential_matches]}"
+ )
+
+ # Process all matched identifiers
+ if not matched_identifiers:
+ logger.warning(
+ f"DEBUG: FileHistoryBatch - DB record {i+1}: NO MATCH FOUND! "
+ f"cache_key={fh.cache_key}, provider_file_uuid={fh.provider_file_uuid}, file_path={fh.file_path}"
+ )
+
+ # Update response data for all matches
+ for result_identifier in matched_identifiers:
+ is_completed_result = fh.is_completed()
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Found record for UUID: {fh.provider_file_uuid}, "
+ f"Path: {fh.file_path}, Status: {fh.status}, is_completed(): {is_completed_result}, "
+ f"result_identifier: {result_identifier}"
+ )
+
+ serializer = FileHistorySerializer(fh)
+ response_data[result_identifier] = {
+ "found": True,
+ "is_completed": is_completed_result,
+ "file_history": serializer.data,
+ }
+
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Response updated for {result_identifier}: "
+ f"found=True, is_completed={is_completed_result}, status={fh.status}"
+ )
+
+ logger.info(
+ f"Batch file history lookup for workflow {workflow_id}: "
+ f"requested {len(files_data)} files, found {len([r for r in response_data.values() if r['found']])} histories"
+ )
+
+ # Final response data debugging
+ logger.info("DEBUG: FileHistoryBatch - Final response data:")
+ for key, value in response_data.items():
+ logger.info(
+ f"DEBUG: FileHistoryBatch - Response[{key}]: "
+ f"found={value.get('found')}, is_completed={value.get('is_completed')}"
+ )
+
+ return Response({"file_histories": response_data}, status=status.HTTP_200_OK)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to batch lookup file history for workflow {workflow_id}: {e}"
+ )
+ return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def _create_default_identifier(file_data: dict) -> str:
+ """Create default identifier when not provided in request.
+
+ Args:
+ file_data: File data dictionary with provider_file_uuid and file_path
+
+ Returns:
+ Composite identifier in format 'uuid:path' or fallback to uuid or path
+ """
+ uuid = file_data.get("provider_file_uuid", "")
+ path = file_data.get("file_path", "")
+ cache_key = file_data.get("cache_key", "")
+
+ # Prefer provider_file_uuid + file_path combination
+ if uuid and path:
+ return f"{uuid}:{path}"
+ # Fallback to cache_key + path if available
+ elif cache_key and path:
+ return f"{cache_key}:{path}"
+ # Final fallbacks
+ elif uuid:
+ return uuid
+ elif cache_key:
+ return cache_key
+ elif path:
+ return path
+ else:
+ return "unknown"
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def create_file_history_internal(request):
+ """Create file history record for internal API calls.
+
+ Workers should check file history exists first via get_file_history API.
+ This API assumes pre-checking and only creates when confirmed not to exist.
+ """
+ try:
+ from workflow_manager.workflow_v2.file_history_helper import FileHistoryHelper
+
+ organization_id = getattr(request, "organization_id", None)
+
+ # Extract parameters from request data
+ data = request.data
+ workflow_id = data.get("workflow_id")
+ file_hash = data.get("file_hash")
+ is_api = data.get("is_api", False)
+ provider_file_uuid = data.get("provider_file_uuid")
+ file_path = data.get("file_path")
+ file_name = data.get("file_name")
+ file_size = data.get("file_size")
+ mime_type = data.get("mime_type")
+ source_connection_type = data.get("source_connection_type")
+
+ # Extract required parameters for FileHistoryHelper.create_file_history
+ execution_status = data.get("status", "COMPLETED")
+ result = data.get("result", "")
+ metadata = data.get("metadata", "")
+ error = data.get("error")
+
+ if not workflow_id or not file_hash:
+ return Response(
+ {"error": "workflow_id and file_hash are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get workflow
+ try:
+ workflow = Workflow.objects.get(pk=workflow_id)
+ if (
+ organization_id
+ and workflow.organization.organization_id != organization_id
+ ):
+ return Response(
+ {"error": "Workflow not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ # Create FileHash object from data
+ file_hash = FileHash(
+ file_path=file_path,
+ file_name=file_name,
+ source_connection_type=source_connection_type,
+ file_hash=file_hash,
+ file_size=file_size,
+ provider_file_uuid=provider_file_uuid,
+ mime_type=mime_type,
+ fs_metadata={},
+ file_destination="",
+ is_executed=False,
+ file_number=0,
+ )
+
+ # Import ExecutionStatus enum
+ from workflow_manager.workflow_v2.enums import ExecutionStatus
+
+ # Convert string status to ExecutionStatus enum
+ try:
+ status_enum = ExecutionStatus(execution_status)
+ except ValueError:
+ status_enum = ExecutionStatus.COMPLETED # Default fallback
+
+ # Create file history using existing helper
+ # IntegrityError will propagate as genuine error since worker should have checked first
+ file_history_record = FileHistoryHelper.create_file_history(
+ file_hash=file_hash,
+ workflow=workflow,
+ status=status_enum,
+ result=result,
+ metadata=metadata,
+ error=error,
+ is_api=is_api,
+ )
+
+ if not file_history_record:
+ # Helper returned None, this should not happen with our improved get-or-create logic
+ # But if it does, try to retrieve the existing record instead of failing
+ logger.warning(
+ f"create_file_history returned None for workflow {workflow_id} - attempting to retrieve existing record"
+ )
+
+ # Try to find the existing record that caused the constraint violation
+ try:
+ from workflow_manager.workflow_v2.file_history_helper import (
+ FileHistoryHelper,
+ )
+
+ existing_record = FileHistoryHelper.get_file_history(
+ workflow=workflow,
+ cache_key=file_hash.file_hash,
+ provider_file_uuid=file_hash.provider_file_uuid,
+ file_path=file_hash.file_path,
+ )
+
+ if existing_record:
+ logger.info(
+ f"Retrieved existing file history record for workflow {workflow_id}: {existing_record.id}"
+ )
+ file_history_record = existing_record
+ else:
+ # This is a genuine error - we couldn't create or find the record
+ logger.error(
+ f"Failed to create or find file history for workflow {workflow_id}"
+ )
+ return Response(
+ {
+ "error": "Failed to create file history record",
+ "detail": "Unable to create or retrieve file history record",
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ except Exception as retrieval_error:
+ logger.error(
+ f"Failed to retrieve existing file history record: {str(retrieval_error)}"
+ )
+ return Response(
+ {
+ "error": "Failed to create file history record",
+ "detail": str(retrieval_error),
+ },
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ logger.info(
+ f"Created file history record for workflow {workflow_id}: {file_history_record.id}"
+ )
+
+ # Convert Django model to dataclass for consistent API response
+ from unstract.core.data_models import FileHistoryData
+
+ file_history_data = FileHistoryData(
+ id=str(file_history_record.id),
+ workflow_id=str(workflow_id),
+ cache_key=file_history_record.cache_key,
+ provider_file_uuid=file_history_record.provider_file_uuid,
+ status=file_history_record.status.value
+ if hasattr(file_history_record.status, "value")
+ else str(file_history_record.status),
+ result=file_history_record.result,
+ metadata=file_history_record.metadata,
+ error=file_history_record.error,
+ file_path=file_hash.file_path,
+ created_at=file_history_record.created_at,
+ modified_at=file_history_record.modified_at,
+ )
+
+ # Use FileHistoryCreateRequest for consistent response format
+ response = FileHistoryCreateRequest(
+ status="created",
+ workflow_id=workflow_id,
+ file_history=file_history_data,
+ message="File history record created successfully",
+ )
+
+ return Response(response.to_dict(), status=status.HTTP_201_CREATED)
+
+ except Exception as e:
+ logger.error(f"Failed to create file history: {e}")
+ return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def reserve_file_processing_internal(request):
+ """Atomic check-and-reserve operation for file processing deduplication.
+
+ This endpoint handles the race condition by atomically checking if a file
+ should be processed and reserving it if not already processed/reserved.
+
+ Returns:
+ - 200: File already processed (with existing result)
+ - 201: File reserved for processing (worker should proceed)
+ - 409: File already reserved by another worker (worker should skip)
+ """
+ try:
+ from django.utils import timezone
+
+ from workflow_manager.workflow_v2.file_history_helper import FileHistoryHelper
+
+ organization_id = getattr(request, "organization_id", None)
+ data = request.data
+
+ workflow_id = data.get("workflow_id")
+ cache_key = data.get("cache_key")
+ provider_file_uuid = data.get("provider_file_uuid")
+ file_path = data.get("file_path")
+ worker_id = data.get("worker_id") # Unique worker identifier
+
+ if not workflow_id or not cache_key:
+ return Response(
+ {"error": "workflow_id and cache_key are required"},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ # Get workflow
+ try:
+ workflow = Workflow.objects.get(pk=workflow_id)
+ if (
+ organization_id
+ and workflow.organization.organization_id != organization_id
+ ):
+ return Response(
+ {"error": "Workflow not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ # Check if file already has completed history
+ existing_history = FileHistoryHelper.get_file_history(
+ workflow=workflow,
+ cache_key=cache_key,
+ provider_file_uuid=provider_file_uuid,
+ file_path=file_path,
+ )
+
+ from workflow_manager.workflow_v2.enums import ExecutionStatus
+
+ if (
+ existing_history
+ and existing_history.status == ExecutionStatus.COMPLETED.value
+ ):
+ # File already processed - return existing result
+ logger.info(
+ f"File already processed: cache_key={cache_key}, workflow={workflow_id}"
+ )
+
+ from unstract.core.data_models import FileHistoryData
+
+ file_history_data = FileHistoryData(
+ id=str(existing_history.id),
+ workflow_id=str(workflow_id),
+ cache_key=existing_history.cache_key,
+ provider_file_uuid=existing_history.provider_file_uuid,
+ status=existing_history.status.value
+ if hasattr(existing_history.status, "value")
+ else str(existing_history.status),
+ result=existing_history.result,
+ metadata=existing_history.metadata,
+ error=existing_history.error,
+ file_path=existing_history.file_path,
+ created_at=existing_history.created_at,
+ modified_at=existing_history.modified_at,
+ )
+
+ return Response(
+ {
+ "reserved": False,
+ "already_processed": True,
+ "file_history": file_history_data.to_dict(),
+ "message": "File already processed, use existing result",
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ # Use Django's get_or_create for atomic reservation
+ from workflow_manager.workflow_v2.enums import ExecutionStatus
+ from workflow_manager.workflow_v2.models.file_history import FileHistory
+
+ reservation_data = {
+ "workflow": workflow,
+ "cache_key": cache_key,
+ "provider_file_uuid": provider_file_uuid,
+ "status": ExecutionStatus.PENDING.value, # Use PENDING as reservation status
+ "result": f"Reserved by worker {worker_id}",
+ "metadata": f"Processing reserved at {timezone.now()}",
+ "error": "",
+ "file_path": file_path,
+ }
+
+ try:
+ # Atomic get_or_create operation
+ file_history, created = FileHistory.objects.get_or_create(
+ workflow=workflow,
+ cache_key=cache_key,
+ provider_file_uuid=provider_file_uuid,
+ file_path=file_path,
+ defaults=reservation_data,
+ )
+
+ if created:
+ # Successfully reserved for this worker
+ logger.info(
+ f"Reserved file for processing: cache_key={cache_key}, worker={worker_id}, workflow={workflow_id}"
+ )
+ return Response(
+ {
+ "reserved": True,
+ "file_history_id": str(file_history.id),
+ "message": "File reserved for processing",
+ },
+ status=status.HTTP_201_CREATED,
+ )
+ else:
+ # File already reserved/processed by another worker
+ if file_history.status == ExecutionStatus.COMPLETED.value:
+ # Another worker completed it while we were checking
+ logger.info(
+ f"File completed by another worker: cache_key={cache_key}, workflow={workflow_id}"
+ )
+
+ from unstract.core.data_models import FileHistoryData
+
+ file_history_data = FileHistoryData(
+ id=str(file_history.id),
+ workflow_id=str(workflow_id),
+ cache_key=file_history.cache_key,
+ provider_file_uuid=file_history.provider_file_uuid,
+ status=file_history.status.value
+ if hasattr(file_history.status, "value")
+ else str(file_history.status),
+ result=file_history.result,
+ metadata=file_history.metadata,
+ error=file_history.error,
+ file_path=file_history.file_path,
+ created_at=file_history.created_at,
+ modified_at=file_history.modified_at,
+ )
+
+ return Response(
+ {
+ "reserved": False,
+ "already_processed": True,
+ "file_history": file_history_data.to_dict(),
+ "message": "File completed by another worker",
+ },
+ status=status.HTTP_200_OK,
+ )
+ else:
+ # File reserved by another worker (PENDING status)
+ logger.info(
+ f"File already reserved by another worker: cache_key={cache_key}, workflow={workflow_id}"
+ )
+ return Response(
+ {
+ "reserved": False,
+ "already_reserved": True,
+ "message": "File already reserved by another worker",
+ },
+ status=status.HTTP_409_CONFLICT,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to reserve file for processing: {str(e)}")
+ return Response(
+ {"error": "Failed to reserve file for processing", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to process reservation request: {str(e)}")
+ return Response(
+ {"error": "Internal server error", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["POST"])
+def get_file_history_internal(request):
+ """Get file history for worker deduplication using backend FileHistoryHelper.
+
+ This endpoint exposes the same FileHistoryHelper.get_file_history() logic
+ used by the backend source.py to ensure consistent deduplication behavior.
+ """
+ try:
+ workflow_id = request.data.get("workflow_id")
+ provider_file_uuid = request.data.get("provider_file_uuid")
+ file_hash = request.data.get("file_hash") # Also accept file_hash (cache_key)
+ file_path = request.data.get("file_path")
+ organization_id = request.data.get("organization_id")
+
+ # Must have either provider_file_uuid or file_hash
+ if (
+ not workflow_id
+ or not organization_id
+ or (not provider_file_uuid and not file_hash)
+ ):
+ return Response(
+ {
+ "error": "Missing required parameters",
+ "required": [
+ "workflow_id",
+ "organization_id",
+ "either provider_file_uuid or file_hash",
+ ],
+ "optional": ["file_path"],
+ },
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
+ logger.info(
+ f"Getting file history for workflow {workflow_id}, provider_uuid: {provider_file_uuid}, "
+ f"file_hash: {file_hash}, file_path: {file_path}"
+ )
+ logger.info(f"Organization ID from request: {organization_id}")
+
+ # Get workflow
+ try:
+ workflow = Workflow.objects.get(
+ id=workflow_id, organization__organization_id=organization_id
+ )
+ logger.info(
+ f"Found workflow {workflow_id} with organization {workflow.organization.organization_id}"
+ )
+ except Workflow.DoesNotExist:
+ return Response(
+ {"error": "Workflow not found", "workflow_id": workflow_id},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+
+ # Use the same FileHistoryHelper logic as backend source.py:566-570
+ from workflow_manager.workflow_v2.file_history_helper import FileHistoryHelper
+
+ logger.info(
+ f"Calling FileHistoryHelper.get_file_history with workflow={workflow.id}, "
+ f"cache_key={file_hash}, provider_file_uuid={provider_file_uuid}, file_path={file_path}"
+ )
+ # Pass file_hash as cache_key to FileHistoryHelper
+ file_history = FileHistoryHelper.get_file_history(
+ workflow=workflow,
+ cache_key=file_hash, # Use file_hash as cache_key
+ provider_file_uuid=provider_file_uuid,
+ file_path=file_path,
+ )
+ logger.info(f"FileHistoryHelper returned: {file_history}")
+
+ if file_history:
+ # Convert to dictionary for JSON response
+ file_history_data = {
+ "id": str(file_history.id),
+ "workflow_id": str(file_history.workflow_id),
+ "cache_key": file_history.cache_key,
+ "provider_file_uuid": file_history.provider_file_uuid,
+ "file_path": file_history.file_path,
+ "status": file_history.status,
+ "is_completed": file_history.is_completed(),
+ "created_at": file_history.created_at.isoformat()
+ if file_history.created_at
+ else None,
+ "completed_at": file_history.modified_at.isoformat()
+ if file_history.modified_at
+ else None,
+ }
+
+ logger.info(
+ f"File history found for {file_path}: status={file_history.status}, completed={file_history.is_completed()}"
+ )
+
+ return Response(
+ {"file_history": file_history_data, "found": True},
+ status=status.HTTP_200_OK,
+ )
+ else:
+ logger.info(
+ f"No file history found for {file_path} with provider_uuid: {provider_file_uuid}"
+ )
+ return Response(
+ {"file_history": None, "found": False}, status=status.HTTP_200_OK
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get file history: {str(e)}")
+ return Response(
+ {"error": "Failed to get file history", "detail": str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
+
+
+@csrf_exempt # Safe: Internal API with Bearer token auth, no session/cookies
+@api_view(["GET"])
+def file_history_status_internal(request, file_history_id):
+ """Get file history status for internal API calls."""
+ try:
+ from workflow_manager.workflow_v2.models.file_history import FileHistory
+
+ organization_id = getattr(request, "organization_id", None)
+
+ # Get file history record
+ try:
+ file_history = FileHistory.objects.get(pk=file_history_id)
+ if organization_id and file_history.organization_id != organization_id:
+ return Response(
+ {"error": "File history not found in organization"},
+ status=status.HTTP_404_NOT_FOUND,
+ )
+ except FileHistory.DoesNotExist:
+ return Response(
+ {"error": "File history not found"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ return Response(
+ {
+ "file_history_id": file_history_id,
+ "status": "exists",
+ "cache_key": file_history.cache_key,
+ "workflow_id": str(file_history.workflow_id),
+ "created_at": file_history.created_at.isoformat(),
+ "is_api": getattr(file_history, "is_api", False),
+ },
+ status=status.HTTP_200_OK,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get file history status for {file_history_id}: {e}")
+ return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/backend/workflow_manager/workflow_v2/workflow_helper.py b/backend/workflow_manager/workflow_v2/workflow_helper.py
index c75d7718b..88f8d7110 100644
--- a/backend/workflow_manager/workflow_v2/workflow_helper.py
+++ b/backend/workflow_manager/workflow_v2/workflow_helper.py
@@ -483,18 +483,13 @@ class WorkflowHelper:
},
queue=queue,
)
-
- # Log task_id for debugging
logger.info(
- f"[{org_schema}] AsyncResult created with task_id: '{async_execution.id}' "
- f"(type: {type(async_execution.id).__name__})"
+ f"[{org_schema}] Job '{async_execution}' has been enqueued for "
+ f"execution_id '{execution_id}', '{len(hash_values_of_files)}' files"
)
-
workflow_execution: WorkflowExecution = WorkflowExecution.objects.get(
id=execution_id
)
-
- # Handle empty task_id gracefully using existing validation logic
if not async_execution.id:
logger.warning(
f"[{org_schema}] Celery returned empty task_id for execution_id '{execution_id}'. "
@@ -509,6 +504,7 @@ class WorkflowHelper:
f"[{org_schema}] Job '{async_execution.id}' has been enqueued for "
f"execution_id '{execution_id}', '{len(hash_values_of_files)}' files"
)
+
execution_status = workflow_execution.status
if timeout > -1:
while not ExecutionStatus.is_completed(execution_status) and timeout > 0:
@@ -779,17 +775,16 @@ class WorkflowHelper:
# Normal Workflow page execution
workflow_execution = WorkflowExecution.objects.get(pk=execution_id)
if (
- workflow_execution.status != ExecutionStatus.PENDING
+ workflow_execution.status != ExecutionStatus.PENDING.value
or workflow_execution.execution_type != WorkflowExecution.Type.COMPLETE
):
raise InvalidRequest(WorkflowErrors.INVALID_EXECUTION_ID)
- organization_identifier = UserContext.get_organization_identifier()
- result: ExecutionResponse = WorkflowHelper.run_workflow(
- workflow=workflow,
- workflow_execution=workflow_execution,
+ result: ExecutionResponse = WorkflowHelper.execute_workflow_async(
+ workflow_id=str(workflow.id) if workflow else None,
+ pipeline_id=str(pipeline_id) if pipeline_id else None,
+ execution_id=str(execution_id) if execution_id else None,
hash_values_of_files=hash_values_of_files,
use_file_history=use_file_history,
- organization_id=organization_identifier,
)
result = WorkflowHelper.wait_for_execution(result, timeout=timeout)
return result
@@ -813,7 +808,8 @@ class WorkflowHelper:
ExecutionResponse: The execution response.
"""
if (
- result.execution_status in [ExecutionStatus.COMPLETED, ExecutionStatus.ERROR]
+ result.execution_status
+ in [ExecutionStatus.COMPLETED.value, ExecutionStatus.ERROR.value]
or not timeout
):
return result
@@ -879,7 +875,7 @@ class WorkflowHelper:
except WorkflowExecution.DoesNotExist:
raise WorkflowExecutionNotExist(WorkflowErrors.INVALID_EXECUTION_ID)
if (
- workflow_execution.status != ExecutionStatus.PENDING
+ workflow_execution.status != ExecutionStatus.PENDING.value
or workflow_execution.execution_type != WorkflowExecution.Type.STEP
):
raise InvalidRequest(WorkflowErrors.INVALID_EXECUTION_ID)
diff --git a/docker/README.md b/docker/README.md
index d48268d08..9461511d3 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -30,6 +30,23 @@ VERSION=dev docker compose -f docker-compose.yaml --profile optional up -d
Now access frontend at http://frontend.unstract.localhost
+## V2 Workers (Optional)
+
+V2 workers use a unified container architecture and are **disabled by default**.
+
+```bash
+# Default: Run with legacy workers only
+VERSION=dev docker compose -f docker-compose.yaml up -d
+
+# Enable V2 workers (unified container)
+VERSION=dev docker compose -f docker-compose.yaml --profile workers-v2 up -d
+
+# Or use the platform script
+./run-platform.sh --workers-v2
+```
+
+V2 workers available: `api-deployment`, `callback`, `file-processing`, `general`, `notification`, `log-consumer`, `scheduler`
+
## Overriding a service's config
By making use of the [merge compose files](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/) feature its possible to override some configuration that's used by the services.
diff --git a/docker/docker-compose.build.yaml b/docker/docker-compose.build.yaml
index 8f4f1e8ae..3969b1f98 100644
--- a/docker/docker-compose.build.yaml
+++ b/docker/docker-compose.build.yaml
@@ -50,3 +50,11 @@ services:
build:
dockerfile: docker/dockerfiles/x2text.Dockerfile
context: ..
+ # Unified worker image (replaces all individual worker images)
+ worker-unified:
+ image: unstract/worker-unified:${VERSION}
+ build:
+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile
+ context: ..
+ args:
+ MINIMAL_BUILD: ${MINIMAL_BUILD:-0} # Set to 1 for faster dev builds
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index 19103207b..c47706052 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -239,6 +239,313 @@ services:
labels:
- traefik.enable=false
+ # ====================================================================
+ # V2 DEDICATED WORKER SERVICES (opt-in with --workers-v2 flag)
+ # ====================================================================
+
+ worker-api-deployment-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-api-deployment-v2
+ restart: unless-stopped
+ command: ["api-deployment"]
+ ports:
+ - "8085:8090"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-api-deployment-v2
+ - WORKER_TYPE=api_deployment
+ - CELERY_QUEUES_API_DEPLOYMENT=${CELERY_QUEUES_API_DEPLOYMENT:-celery_api_deployments}
+ - CELERY_POOL=${WORKER_API_DEPLOYMENT_POOL:-threads}
+ - CELERY_PREFETCH_MULTIPLIER=${WORKER_API_DEPLOYMENT_PREFETCH_MULTIPLIER:-1}
+ - CELERY_CONCURRENCY=${WORKER_API_DEPLOYMENT_CONCURRENCY:-4}
+ - CELERY_EXTRA_ARGS=${WORKER_API_DEPLOYMENT_EXTRA_ARGS:-}
+ - WORKER_NAME=api-deployment-worker-v2
+ - API_DEPLOYMENT_METRICS_PORT=8090
+ - HEALTH_PORT=8090
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
+ worker-callback-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-callback-v2
+ restart: unless-stopped
+ command: ["callback"]
+ ports:
+ - "8086:8083"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-callback-v2
+ - WORKER_TYPE=callback
+ - WORKER_NAME=callback-worker-v2
+ - CALLBACK_METRICS_PORT=8083
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
+ worker-file-processing-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-file-processing-v2
+ restart: unless-stopped
+ # command: ["file-processing"]
+ command: [".venv/bin/celery", "-A", "worker", "worker", "--queues=file_processing,api_file_processing,file_processing_priority", "--loglevel=INFO", "--pool=prefork", "--concurrency=4", "--prefetch-multiplier=1", "--without-gossip", "--without-mingle", "--without-heartbeat"]
+ ports:
+ - "8087:8082"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-file-processing-v2
+ - WORKER_TYPE=file_processing
+ - WORKER_MODE=oss
+ - WORKER_NAME=file-processing-worker-v2
+ - FILE_PROCESSING_METRICS_PORT=8082
+ # OSS Configuration - Enterprise features disabled
+ - MANUAL_REVIEW_ENABLED=false
+ - ENTERPRISE_FEATURES_ENABLED=false
+ - PLUGIN_REGISTRY_MODE=oss
+ # Configurable Celery options
+ - CELERY_QUEUES_FILE_PROCESSING=${CELERY_QUEUES_FILE_PROCESSING:-file_processing,api_file_processing}
+ - CELERY_POOL=${WORKER_FILE_PROCESSING_POOL:-threads}
+ - CELERY_PREFETCH_MULTIPLIER=${WORKER_FILE_PROCESSING_PREFETCH_MULTIPLIER:-1}
+ - CELERY_CONCURRENCY=${WORKER_FILE_PROCESSING_CONCURRENCY:-4}
+ - CELERY_EXTRA_ARGS=${WORKER_FILE_PROCESSING_EXTRA_ARGS:-}
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
+ worker-general-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-general-v2
+ restart: unless-stopped
+ command: ["general"]
+ ports:
+ - "8088:8082"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-general-v2
+ - WORKER_TYPE=general
+ - WORKER_NAME=general-worker-v2
+ - GENERAL_METRICS_PORT=8081
+ - HEALTH_PORT=8082
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
+ worker-notification-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-notification-v2
+ restart: unless-stopped
+ command: ["notification"]
+ ports:
+ - "8089:8085"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-notification-v2
+ - WORKER_TYPE=notification
+ - WORKER_NAME=notification-worker-v2
+ - NOTIFICATION_METRICS_PORT=8085
+ - HEALTH_PORT=8085
+ # Notification specific configs
+ - NOTIFICATION_QUEUE_NAME=notifications
+ - WEBHOOK_QUEUE_NAME=notifications_webhook
+ - EMAIL_QUEUE_NAME=notifications_email
+ - SMS_QUEUE_NAME=notifications_sms
+ - PRIORITY_QUEUE_NAME=notifications_priority
+ # Configurable Celery options
+ - CELERY_QUEUES_NOTIFICATION=${CELERY_QUEUES_NOTIFICATION:-notifications,notifications_webhook,notifications_email,notifications_sms,notifications_priority}
+ - CELERY_POOL=${WORKER_NOTIFICATION_POOL:-prefork}
+ - CELERY_PREFETCH_MULTIPLIER=${WORKER_NOTIFICATION_PREFETCH_MULTIPLIER:-1}
+ - CELERY_CONCURRENCY=${WORKER_NOTIFICATION_CONCURRENCY:-4}
+ - CELERY_EXTRA_ARGS=${WORKER_NOTIFICATION_EXTRA_ARGS:-}
+ # Complete command override (if set, ignores all other options)
+ - CELERY_COMMAND_OVERRIDE=${WORKER_NOTIFICATION_COMMAND_OVERRIDE:-}
+ # Individual argument overrides
+ - CELERY_APP_MODULE=${WORKER_NOTIFICATION_APP_MODULE:-worker}
+ - CELERY_LOG_LEVEL=${WORKER_NOTIFICATION_LOG_LEVEL:-INFO}
+ - CELERY_HOSTNAME=${WORKER_NOTIFICATION_HOSTNAME:-}
+ - CELERY_MAX_TASKS_PER_CHILD=${WORKER_NOTIFICATION_MAX_TASKS_PER_CHILD:-}
+ - CELERY_TIME_LIMIT=${WORKER_NOTIFICATION_TIME_LIMIT:-}
+ - CELERY_SOFT_TIME_LIMIT=${WORKER_NOTIFICATION_SOFT_TIME_LIMIT:-}
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
+ worker-log-consumer-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-log-consumer-v2
+ restart: unless-stopped
+ command: ["log-consumer"]
+ ports:
+ - "8090:8084"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-log-consumer-v2
+ - WORKER_TYPE=log_consumer
+ - WORKER_NAME=log-consumer-worker-v2
+ - LOG_CONSUMER_METRICS_PORT=8084
+ - HEALTH_PORT=8084
+ # Log consumer specific configs
+ - LOG_CONSUMER_QUEUE_NAME=celery_log_task_queue
+ # Multiple queue support - supports comma-separated queue names
+ - CELERY_QUEUES_LOG_CONSUMER=${CELERY_QUEUES_LOG_CONSUMER:-celery_log_task_queue,celery_periodic_logs}
+ - PERIODIC_LOGS_QUEUE_NAME=${PERIODIC_LOGS_QUEUE_NAME:-celery_periodic_logs}
+ # Log history configuration
+ - LOG_HISTORY_QUEUE_NAME=${LOG_HISTORY_QUEUE_NAME:-log_history_queue}
+ - LOGS_BATCH_LIMIT=${LOGS_BATCH_LIMIT:-100}
+ - ENABLE_LOG_HISTORY=${ENABLE_LOG_HISTORY:-true}
+ - CELERY_POOL=${WORKER_LOG_CONSUMER_POOL:-prefork}
+ - CELERY_PREFETCH_MULTIPLIER=${WORKER_LOG_CONSUMER_PREFETCH_MULTIPLIER:-1}
+ - CELERY_CONCURRENCY=${WORKER_LOG_CONSUMER_CONCURRENCY:-2}
+ - CELERY_EXTRA_ARGS=${WORKER_LOG_CONSUMER_EXTRA_ARGS:-}
+ # Complete command override (if set, ignores all other options)
+ - CELERY_COMMAND_OVERRIDE=${WORKER_LOG_CONSUMER_COMMAND_OVERRIDE:-}
+ # Individual argument overrides
+ - CELERY_APP_MODULE=${WORKER_LOG_CONSUMER_APP_MODULE:-worker}
+ - CELERY_LOG_LEVEL=${WORKER_LOG_CONSUMER_LOG_LEVEL:-INFO}
+ - CELERY_HOSTNAME=${WORKER_LOG_CONSUMER_HOSTNAME:-}
+ - CELERY_MAX_TASKS_PER_CHILD=${WORKER_LOG_CONSUMER_MAX_TASKS_PER_CHILD:-}
+ - CELERY_TIME_LIMIT=${WORKER_LOG_CONSUMER_TIME_LIMIT:-}
+ - CELERY_SOFT_TIME_LIMIT=${WORKER_LOG_CONSUMER_SOFT_TIME_LIMIT:-}
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
+ worker-log-history-scheduler-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-log-history-scheduler-v2
+ restart: unless-stopped
+ entrypoint: ["/bin/bash"]
+ command: ["/app/log_consumer/scheduler.sh"]
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-log-history-scheduler-v2
+ # Scheduler interval in seconds
+ - LOG_HISTORY_CONSUMER_INTERVAL=${LOG_HISTORY_CONSUMER_INTERVAL:-5}
+ # Override example: TASK_TRIGGER_COMMAND=/custom/trigger/script.sh
+ - TASK_TRIGGER_COMMAND=${TASK_TRIGGER_COMMAND:-}
+ labels:
+ - traefik.enable=false
+ profiles:
+ - workers-v2
+
+ worker-scheduler-v2:
+ image: unstract/worker-unified:${VERSION}
+ container_name: unstract-worker-scheduler-v2
+ restart: unless-stopped
+ command: ["scheduler"]
+ ports:
+ - "8091:8087"
+ env_file:
+ - ../workers/.env
+ - ./essentials.env
+ depends_on:
+ - db
+ - redis
+ - rabbitmq
+ environment:
+ - ENVIRONMENT=development
+ - APPLICATION_NAME=unstract-worker-scheduler-v2
+ - WORKER_TYPE=scheduler
+ - WORKER_NAME=scheduler-worker-v2
+ - SCHEDULER_METRICS_PORT=8087
+ - HEALTH_PORT=8087
+ # Scheduler specific configs
+ - SCHEDULER_QUEUE_NAME=scheduler
+ # Configurable Celery options
+ - CELERY_QUEUES_SCHEDULER=${CELERY_QUEUES_SCHEDULER:-scheduler}
+ - CELERY_POOL=${WORKER_SCHEDULER_POOL:-prefork}
+ - CELERY_PREFETCH_MULTIPLIER=${WORKER_SCHEDULER_PREFETCH_MULTIPLIER:-1}
+ - CELERY_CONCURRENCY=${WORKER_SCHEDULER_CONCURRENCY:-2}
+ - CELERY_EXTRA_ARGS=${WORKER_SCHEDULER_EXTRA_ARGS:-}
+ # Complete command override (if set, ignores all other options)
+ - CELERY_COMMAND_OVERRIDE=${WORKER_SCHEDULER_COMMAND_OVERRIDE:-}
+ # Individual argument overrides
+ - CELERY_APP_MODULE=${WORKER_SCHEDULER_APP_MODULE:-worker}
+ - CELERY_LOG_LEVEL=${WORKER_SCHEDULER_LOG_LEVEL:-INFO}
+ - CELERY_HOSTNAME=${WORKER_SCHEDULER_HOSTNAME:-}
+ - CELERY_MAX_TASKS_PER_CHILD=${WORKER_SCHEDULER_MAX_TASKS_PER_CHILD:-}
+ - CELERY_TIME_LIMIT=${WORKER_SCHEDULER_TIME_LIMIT:-}
+ - CELERY_SOFT_TIME_LIMIT=${WORKER_SCHEDULER_SOFT_TIME_LIMIT:-}
+ labels:
+ - traefik.enable=false
+ volumes:
+ - ./workflow_data:/data
+ - ${TOOL_REGISTRY_CONFIG_SRC_PATH}:/data/tool_registry_config
+ profiles:
+ - workers-v2
+
volumes:
prompt_studio_data:
unstract_data:
diff --git a/docker/dockerfiles/worker-unified.Dockerfile b/docker/dockerfiles/worker-unified.Dockerfile
new file mode 100644
index 000000000..5853000c0
--- /dev/null
+++ b/docker/dockerfiles/worker-unified.Dockerfile
@@ -0,0 +1,85 @@
+# Unified Worker Dockerfile - Optimized for fast builds
+FROM python:3.12.9-slim AS base
+
+ARG VERSION=dev
+LABEL maintainer="Zipstack Inc." \
+ description="Unified Worker Container for All Worker Types" \
+ version="${VERSION}"
+
+# Set environment variables (CRITICAL: PYTHONPATH makes paths work!)
+ENV PYTHONDONTWRITEBYTECODE=1 \
+ PYTHONUNBUFFERED=1 \
+ PYTHONPATH=/app:/unstract \
+ BUILD_CONTEXT_PATH=workers \
+ BUILD_PACKAGES_PATH=unstract \
+ APP_HOME=/app \
+ # OpenTelemetry configuration (disabled by default, enable in docker-compose)
+ OTEL_TRACES_EXPORTER=none \
+ OTEL_LOGS_EXPORTER=none \
+ OTEL_SERVICE_NAME=unstract_workers
+
+# Install system dependencies (minimal for workers)
+RUN apt-get update \
+ && apt-get --no-install-recommends install -y \
+ curl \
+ gcc \
+ libmagic-dev \
+ libssl-dev \
+ pkg-config \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
+
+# Install uv package manager
+COPY --from=ghcr.io/astral-sh/uv:0.6.14 /uv /uvx /bin/
+
+# Create non-root user early to avoid ownership issues
+RUN groupadd -r worker && useradd -r -g worker worker && \
+ mkdir -p /home/worker && chown -R worker:worker /home/worker
+
+# Create working directory
+WORKDIR ${APP_HOME}
+
+# -----------------------------------------------
+# EXTERNAL DEPENDENCIES STAGE - This layer gets cached
+# -----------------------------------------------
+FROM base AS ext-dependencies
+
+# Copy dependency files (including README.md like backend)
+COPY ${BUILD_CONTEXT_PATH}/pyproject.toml ${BUILD_CONTEXT_PATH}/uv.lock ./
+# Create empty README.md if it doesn't exist in the copy
+RUN touch README.md
+
+# Copy local package dependencies to /unstract directory
+# This provides the unstract packages for imports
+COPY ${BUILD_PACKAGES_PATH}/ /unstract/
+
+# Install external dependencies with --locked for FAST builds
+# No symlinks needed - PYTHONPATH handles the paths
+RUN uv sync --group deploy --locked --no-install-project --no-dev
+
+# -----------------------------------------------
+# FINAL STAGE - Minimal image for production
+# -----------------------------------------------
+FROM ext-dependencies AS production
+
+# Copy application code (this layer changes most frequently)
+COPY ${BUILD_CONTEXT_PATH}/ ./
+
+# Set shell with pipefail for proper error handling in pipes
+SHELL ["/bin/bash", "-o", "pipefail", "-c"]
+
+# Install project and OpenTelemetry instrumentation (as root to avoid permission issues)
+# No symlinks needed - PYTHONPATH handles the paths correctly
+RUN uv sync --group deploy --locked && \
+ uv run opentelemetry-bootstrap -a requirements | uv pip install --requirement - && \
+ { chmod +x ./run-worker.sh ./run-worker-docker.sh 2>/dev/null || true; } && \
+ touch requirements.txt && \
+ { chown -R worker:worker ./run-worker.sh ./run-worker-docker.sh 2>/dev/null || true; }
+
+# Switch to worker user
+USER worker
+
+
+# Default command - runs the Docker-optimized worker script
+ENTRYPOINT ["/app/run-worker-docker.sh"]
+CMD ["general"]
diff --git a/docker/dockerfiles/worker-unified.Dockerfile.dockerignore b/docker/dockerfiles/worker-unified.Dockerfile.dockerignore
new file mode 100644
index 000000000..909a0db8c
--- /dev/null
+++ b/docker/dockerfiles/worker-unified.Dockerfile.dockerignore
@@ -0,0 +1,74 @@
+# Unified Worker Docker ignore file
+# Based on worker-base.dockerignore but unified for all worker types
+
+# Virtual environments
+**/.venv/
+**/venv/
+**/__pycache__/
+**/.pytest_cache/
+**/.mypy_cache/
+
+# IDE and editor files
+**/.vscode/
+**/.idea/
+**/*.swp
+**/*.swo
+**/*~
+
+# OS files
+.DS_Store
+Thumbs.db
+
+# Git
+.git/
+.gitignore
+
+# Docker files (avoid recursion)
+**/Dockerfile*
+**/*.dockerignore
+
+# Build artifacts
+**/dist/
+**/build/
+**/*.egg-info/
+
+# Logs
+**/*.log
+**/logs/
+
+# Test files
+**/tests/
+**/test_*.py
+**/*_test.py
+
+# Development files
+**/dev-*
+**/sample.*
+**/example.*
+
+# Node modules (if any)
+**/node_modules/
+
+# Documentation
+**/docs/
+**/*.md
+!README.md
+
+# Configuration that shouldn't be in containers
+**/.env*
+**/local_settings.py
+
+# Coverage reports
+**/htmlcov/
+**/.coverage
+**/coverage.xml
+
+# Backup files
+**/*.bak
+**/*.backup
+**/*.orig
+
+# Temporary files
+**/tmp/
+**/temp/
+**/.tmp/
diff --git a/docker/sample.env b/docker/sample.env
index 942989ce4..7208207fe 100644
--- a/docker/sample.env
+++ b/docker/sample.env
@@ -11,3 +11,103 @@ WORKER_LOGGING_AUTOSCALE=4,1
WORKER_AUTOSCALE=4,1
WORKER_FILE_PROCESSING_AUTOSCALE=4,1
WORKER_FILE_PROCESSING_CALLBACK_AUTOSCALE=4,1
+
+# New unified worker autoscaling (matches hierarchical configuration below)
+WORKER_API_DEPLOYMENT_AUTOSCALE=4,1 # API deployment worker autoscale
+WORKER_CALLBACK_AUTOSCALE=4,1 # Callback worker autoscale
+WORKER_GENERAL_AUTOSCALE=6,2 # General worker autoscale (enhanced)
+WORKER_FILE_PROCESSING_NEW_AUTOSCALE=8,2 # File processing unified worker autoscale
+WORKER_NOTIFICATION_AUTOSCALE=4,1 # Notification worker autoscale
+WORKER_LOG_CONSUMER_AUTOSCALE=2,1 # Log consumer worker autoscale
+WORKER_SCHEDULER_AUTOSCALE=2,1 # Scheduler worker autoscale
+
+# Worker-specific configurations
+API_DEPLOYMENT_WORKER_NAME=api-deployment-worker
+API_DEPLOYMENT_HEALTH_PORT=8080
+API_DEPLOYMENT_MAX_CONCURRENT_TASKS=5
+
+CALLBACK_WORKER_NAME=callback-worker
+CALLBACK_HEALTH_PORT=8083
+CALLBACK_MAX_CONCURRENT_TASKS=3
+
+FILE_PROCESSING_WORKER_NAME=file-processing-worker
+FILE_PROCESSING_HEALTH_PORT=8082
+FILE_PROCESSING_MAX_CONCURRENT_TASKS=4
+
+GENERAL_WORKER_NAME=general-worker
+GENERAL_HEALTH_PORT=8081
+GENERAL_MAX_CONCURRENT_TASKS=10
+
+# =============================================================================
+# HIERARCHICAL CELERY CONFIGURATION SYSTEM
+# =============================================================================
+#
+# This system uses a 3-tier hierarchy for all Celery settings (most specific wins):
+# 1. {WORKER_TYPE}_{SETTING_NAME} - Worker-specific override (highest priority)
+# 2. CELERY_{SETTING_NAME} - Global override (medium priority)
+# 3. Code default - Celery standard default (lowest priority)
+#
+# Examples:
+# - CALLBACK_TASK_TIME_LIMIT=3600 (callback worker only)
+# - CELERY_TASK_TIME_LIMIT=300 (all workers)
+# - Code provides default if neither is set
+#
+# Worker types: API_DEPLOYMENT, GENERAL, FILE_PROCESSING, CALLBACK,
+# NOTIFICATION, LOG_CONSUMER, SCHEDULER
+# =============================================================================
+
+# Global Celery Configuration (applies to all workers unless overridden)
+CELERY_RESULT_CHORD_RETRY_INTERVAL=3 # Global chord unlock retry interval
+CELERY_TASK_TIME_LIMIT=7200 # Global task timeout (2 hours)
+CELERY_TASK_SOFT_TIME_LIMIT=6300 # Global soft timeout (1h 45m)
+CELERY_PREFETCH_MULTIPLIER=1 # Global prefetch multiplier
+CELERY_MAX_TASKS_PER_CHILD=1000 # Global max tasks per child process
+CELERY_TASK_ACKS_LATE=true # Global acks late setting
+CELERY_TASK_DEFAULT_RETRY_DELAY=60 # Global retry delay (1 minute)
+CELERY_TASK_MAX_RETRIES=3 # Global max retries
+
+# Worker-Specific Configuration Examples
+# Callback Worker - Chord settings and extended timeouts
+CALLBACK_RESULT_CHORD_RETRY_INTERVAL=3 # Callback-specific chord retry interval
+CALLBACK_TASK_TIME_LIMIT=7200 # Callback tasks need more time (2 hours)
+CALLBACK_TASK_SOFT_TIME_LIMIT=6300 # Callback soft timeout (1h 45m)
+
+# File Processing Worker - Thread pool and optimized settings
+FILE_PROCESSING_POOL_TYPE=threads # Use threads instead of prefork
+FILE_PROCESSING_CONCURRENCY=4 # Fixed concurrency for file processing
+FILE_PROCESSING_TASK_TIME_LIMIT=10800 # File processing timeout (3 hours)
+
+# API Deployment Worker - Autoscaling and timeout configuration
+API_DEPLOYMENT_AUTOSCALE=4,1 # Max 4, min 1 workers
+API_DEPLOYMENT_TASK_TIME_LIMIT=3600 # API deployment timeout (1 hour)
+
+# General Worker - Enhanced scaling for high-throughput tasks
+GENERAL_AUTOSCALE=6,2 # Max 6, min 2 workers
+
+# Docker Worker-Specific Concurrency Settings (for docker-compose.yaml)
+WORKER_API_DEPLOYMENT_CONCURRENCY=4 # API deployment fixed concurrency
+WORKER_FILE_PROCESSING_CONCURRENCY=8 # File processing fixed concurrency
+WORKER_NOTIFICATION_CONCURRENCY=4 # Notification worker concurrency
+WORKER_LOG_CONSUMER_CONCURRENCY=2 # Log consumer worker concurrency
+WORKER_SCHEDULER_CONCURRENCY=2 # Scheduler worker concurrency
+
+# Notification Worker - Optimized for quick message processing
+NOTIFICATION_AUTOSCALE=4,1 # Max 4, min 1 workers
+NOTIFICATION_TASK_TIME_LIMIT=120 # Quick timeout for notifications
+
+# Scheduler Worker - Conservative settings for scheduled tasks
+SCHEDULER_AUTOSCALE=2,1 # Max 2, min 1 workers
+SCHEDULER_TASK_TIME_LIMIT=1800 # Scheduler timeout (30 minutes)
+
+# Log Consumer Worker - Optimized for log processing
+LOG_CONSUMER_AUTOSCALE=2,1 # Max 2, min 1 workers
+LOG_CONSUMER_TASK_TIME_LIMIT=600 # Log processing timeout (10 minutes)
+
+# Worker Circuit Breaker Settings
+CIRCUIT_BREAKER_FAILURE_THRESHOLD=5
+CIRCUIT_BREAKER_RECOVERY_TIMEOUT=60
+
+# Worker Health Check Settings
+HEALTH_CHECK_INTERVAL=30
+HEALTH_CHECK_TIMEOUT=10
+ENABLE_METRICS=true
diff --git a/pyproject.toml b/pyproject.toml
index 72c83a3c3..fcee257b1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -22,6 +22,10 @@ dev = [
"types-tzlocal~=5.1.0.1",
]
+workers = [
+ "unstract-workers",
+]
+
hook-check-django-migrations = [
"celery>=5.3.4",
"cron-descriptor==1.4.0",
@@ -55,6 +59,8 @@ unstract-tool-registry = { path = "./unstract/tool-registry", editable = true }
unstract-flags = { path = "./unstract/flags", editable = true }
unstract-core = { path = "./unstract/core", editable = true }
unstract-connectors = { path = "./unstract/connectors", editable = true }
+# Workers
+unstract-workers = { path = "./workers", editable = true }
# === Development tool configurations ===
[tool.ruff]
diff --git a/run-platform.sh b/run-platform.sh
index 87250487d..54d61f586 100755
--- a/run-platform.sh
+++ b/run-platform.sh
@@ -71,6 +71,7 @@ display_help() {
echo -e " -p, --only-pull Only do docker images pull"
echo -e " -b, --build-local Build docker images locally"
echo -e " -u, --update Update services version"
+ echo -e " -w, --workers-v2 Use v2 dedicated worker containers"
echo -e " -x, --trace Enables trace mode"
echo -e " -V, --verbose Print verbose logs"
echo -e " -v, --version Docker images version tag (default \"latest\")"
@@ -97,6 +98,9 @@ parse_args() {
-u | --update)
opt_update=true
;;
+ -w | --workers-v2)
+ opt_workers_v2=true
+ ;;
-x | --trace)
set -o xtrace # display every line before execution; enables PS4
;;
@@ -128,6 +132,7 @@ parse_args() {
debug "OPTION only_pull: $opt_only_pull"
debug "OPTION build_local: $opt_build_local"
debug "OPTION upgrade: $opt_update"
+ debug "OPTION workers_v2: $opt_workers_v2"
debug "OPTION verbose: $opt_verbose"
debug "OPTION version: $opt_version"
}
@@ -280,8 +285,13 @@ build_services() {
run_services() {
pushd "$script_dir/docker" 1>/dev/null
- echo -e "$blue_text""Starting docker containers in detached mode""$default_text"
- VERSION=$opt_version $docker_compose_cmd up -d
+ if [ "$opt_workers_v2" = true ]; then
+ echo -e "$blue_text""Starting docker containers with V2 dedicated workers in detached mode""$default_text"
+ VERSION=$opt_version $docker_compose_cmd --profile workers-v2 up -d
+ else
+ echo -e "$blue_text""Starting docker containers with existing backend-based workers in detached mode""$default_text"
+ VERSION=$opt_version $docker_compose_cmd up -d
+ fi
if [ "$opt_update" = true ]; then
echo ""
@@ -324,6 +334,7 @@ opt_only_env=false
opt_only_pull=false
opt_build_local=false
opt_update=false
+opt_workers_v2=false
opt_verbose=false
opt_version="latest"
@@ -331,6 +342,8 @@ script_dir=$(dirname "$(readlink -f "$BASH_SOURCE")")
first_setup=false
# Extract service names from docker compose file
services=($(VERSION=$opt_version $docker_compose_cmd -f "$script_dir/docker/docker-compose.build.yaml" config --services))
+# Add workers manually for env setup
+services+=("workers")
spawned_services=("tool-structure" "tool-sidecar")
current_version=""
target_branch=""
diff --git a/runner/src/unstract/runner/controller/health.py b/runner/src/unstract/runner/controller/health.py
index 1bacc15ea..8c4349448 100644
--- a/runner/src/unstract/runner/controller/health.py
+++ b/runner/src/unstract/runner/controller/health.py
@@ -1,6 +1,6 @@
import logging
-from flask import Blueprint, Response, jsonify
+from flask import Blueprint
logger = logging.getLogger(__name__)
@@ -9,7 +9,6 @@ health_bp = Blueprint("health", __name__)
# Define a route to ping test
-@health_bp.route("/ping", methods=["GET"])
-def ping() -> Response:
- logger.info("Ping request received")
- return jsonify({"message": "pong!!!"})
+@health_bp.route("/health", methods=["GET"])
+def health_check() -> str:
+ return "OK"
diff --git a/runner/src/unstract/runner/runner.py b/runner/src/unstract/runner/runner.py
index 9f91148da..363ac9ed2 100644
--- a/runner/src/unstract/runner/runner.py
+++ b/runner/src/unstract/runner/runner.py
@@ -296,7 +296,7 @@ class UnstractRunner:
settings_json = json.dumps(settings).replace("'", "\\'")
# Prepare the tool execution command
tool_cmd = (
- f"opentelemetry-instrument python main.py --command RUN "
+ f"python main.py --command RUN "
f"--settings '{settings_json}' --log-level DEBUG"
)
diff --git a/tools/structure/Dockerfile b/tools/structure/Dockerfile
index bba392dc1..32348c8c5 100644
--- a/tools/structure/Dockerfile
+++ b/tools/structure/Dockerfile
@@ -17,7 +17,8 @@ ENV \
OTEL_METRICS_EXPORTER=none \
OTEL_LOGS_EXPORTER=none \
# Enable context propagation
- OTEL_PROPAGATORS="tracecontext"
+ OTEL_PROPAGATORS="tracecontext" \
+ PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
# Install system dependencies in one layer
RUN apt-get update && \
diff --git a/unstract/connectors/src/unstract/__init__.py b/unstract/connectors/src/unstract/__init__.py
new file mode 100644
index 000000000..980f04665
--- /dev/null
+++ b/unstract/connectors/src/unstract/__init__.py
@@ -0,0 +1,2 @@
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
+# Unstract namespace package
diff --git a/unstract/connectors/src/unstract/connectors/__init__.py b/unstract/connectors/src/unstract/connectors/__init__.py
index 530c92c8f..c83c7ded1 100644
--- a/unstract/connectors/src/unstract/connectors/__init__.py
+++ b/unstract/connectors/src/unstract/connectors/__init__.py
@@ -1,7 +1,10 @@
import logging
from logging import NullHandler
-from typing import Any
+
+from unstract.connectors.connection_types import ConnectionType
logging.getLogger(__name__).addHandler(NullHandler())
-ConnectorDict = dict[str, dict[str, Any]]
+__all__ = [
+ "ConnectionType",
+]
diff --git a/unstract/connectors/src/unstract/connectors/connection_types.py b/unstract/connectors/src/unstract/connectors/connection_types.py
new file mode 100644
index 000000000..67e028d07
--- /dev/null
+++ b/unstract/connectors/src/unstract/connectors/connection_types.py
@@ -0,0 +1,70 @@
+"""Unified Connection Types for Unstract Platform
+
+This module provides a centralized definition of connection types used across
+the entire Unstract platform to ensure consistency and prevent duplication.
+"""
+
+from enum import Enum
+
+
+class ConnectionType(str, Enum):
+ """Core connection types for workflow endpoints and connectors.
+
+ This enum provides the fundamental connection types used across:
+ - workers/shared/enums.py
+ - workers/shared/workflow/source_connector.py
+ - workers/shared/workflow/destination_connector.py
+ - unstract/core/src/unstract/core/data_models.py
+ - unstract/core/src/unstract/core/workflow_utils.py
+ """
+
+ FILESYSTEM = "FILESYSTEM"
+ DATABASE = "DATABASE"
+ API = "API"
+ MANUALREVIEW = "MANUALREVIEW"
+
+ def __str__(self):
+ return self.value
+
+ @property
+ def is_filesystem(self) -> bool:
+ """Check if this is a filesystem connection type."""
+ return self == ConnectionType.FILESYSTEM
+
+ @property
+ def is_database(self) -> bool:
+ """Check if this is a database connection type."""
+ return self == ConnectionType.DATABASE
+
+ @property
+ def is_api(self) -> bool:
+ """Check if this is an API connection type."""
+ return self == ConnectionType.API
+
+ @property
+ def is_manual_review(self) -> bool:
+ """Check if this is a manual review connection type."""
+ return self == ConnectionType.MANUALREVIEW
+
+ @classmethod
+ def from_string(cls, connection_type: str) -> "ConnectionType":
+ """Create ConnectionType from string, with validation.
+
+ Args:
+ connection_type: Connection type string
+
+ Returns:
+ ConnectionType enum value
+
+ Raises:
+ ValueError: If connection type is not recognized or is empty
+ """
+ if not connection_type:
+ raise ValueError("Connection type cannot be empty")
+
+ connection_type_upper = connection_type.upper()
+
+ try:
+ return cls(connection_type_upper)
+ except ValueError:
+ raise ValueError(f"Unknown connection type: {connection_type}")
diff --git a/unstract/connectors/src/unstract/connectors/connectorkit.py b/unstract/connectors/src/unstract/connectors/connectorkit.py
index e85ae852d..986ea10a6 100644
--- a/unstract/connectors/src/unstract/connectors/connectorkit.py
+++ b/unstract/connectors/src/unstract/connectors/connectorkit.py
@@ -3,9 +3,8 @@ from typing import Any
from singleton_decorator import singleton
-from unstract.connectors import ConnectorDict # type: ignore
from unstract.connectors.base import UnstractConnector
-from unstract.connectors.constants import Common
+from unstract.connectors.constants import Common, ConnectorDict
from unstract.connectors.databases import connectors as db_connectors
from unstract.connectors.enums import ConnectorMode
from unstract.connectors.filesystems import connectors as fs_connectors
diff --git a/unstract/connectors/src/unstract/connectors/constants.py b/unstract/connectors/src/unstract/connectors/constants.py
index 689134843..4774ee7e9 100644
--- a/unstract/connectors/src/unstract/connectors/constants.py
+++ b/unstract/connectors/src/unstract/connectors/constants.py
@@ -1,9 +1,16 @@
+from typing import Any
+
+
class Common:
METADATA = "metadata"
MODULE = "module"
CONNECTOR = "connector"
+# Type definitions
+ConnectorDict = dict[str, dict[str, Any]]
+
+
class DatabaseTypeConstants:
"""Central location for all database-specific type constants."""
diff --git a/unstract/connectors/src/unstract/connectors/databases/__init__.py b/unstract/connectors/src/unstract/connectors/databases/__init__.py
index fbdc6050e..378b69d94 100644
--- a/unstract/connectors/src/unstract/connectors/databases/__init__.py
+++ b/unstract/connectors/src/unstract/connectors/databases/__init__.py
@@ -1,4 +1,4 @@
-from unstract.connectors import ConnectorDict # type: ignore
+from unstract.connectors.constants import ConnectorDict
from unstract.connectors.databases.register import register_connectors
connectors: ConnectorDict = {}
diff --git a/unstract/connectors/src/unstract/connectors/databases/bigquery/bigquery.py b/unstract/connectors/src/unstract/connectors/databases/bigquery/bigquery.py
index 4713e3878..fef13666d 100644
--- a/unstract/connectors/src/unstract/connectors/databases/bigquery/bigquery.py
+++ b/unstract/connectors/src/unstract/connectors/databases/bigquery/bigquery.py
@@ -7,8 +7,6 @@ from enum import Enum
from typing import Any
import google.api_core.exceptions
-from google.cloud import bigquery
-from google.cloud.bigquery import Client
from unstract.connectors.constants import DatabaseTypeConstants
from unstract.connectors.databases.exceptions import (
@@ -28,6 +26,9 @@ BIG_QUERY_TABLE_SIZE = 3
class BigQuery(UnstractDB):
def __init__(self, settings: dict[str, Any]):
super().__init__("BigQuery")
+ from google.cloud import bigquery
+
+ self.bigquery = bigquery
self.json_credentials = json.loads(settings.get("json_credentials", "{}"))
self.big_query_table_size = BIG_QUERY_TABLE_SIZE
@@ -62,8 +63,8 @@ class BigQuery(UnstractDB):
def can_read() -> bool:
return True
- def get_engine(self) -> Client:
- return bigquery.Client.from_service_account_info( # type: ignore
+ def get_engine(self) -> Any:
+ return self.bigquery.Client.from_service_account_info( # type: ignore
info=self.json_credentials
)
@@ -208,21 +209,23 @@ class BigQuery(UnstractDB):
f"@`{key}`", f"PARSE_JSON(@`{key}`)"
)
query_parameters.append(
- bigquery.ScalarQueryParameter(key, "STRING", json_str)
+ self.bigquery.ScalarQueryParameter(key, "STRING", json_str)
)
elif isinstance(value, (dict, list)):
# For dict/list values in STRING columns, serialize to JSON string
json_str = json.dumps(value) if value else None
query_parameters.append(
- bigquery.ScalarQueryParameter(key, "STRING", json_str)
+ self.bigquery.ScalarQueryParameter(key, "STRING", json_str)
)
else:
# For other values, use STRING as before
query_parameters.append(
- bigquery.ScalarQueryParameter(key, "STRING", value)
+ self.bigquery.ScalarQueryParameter(key, "STRING", value)
)
- query_params = bigquery.QueryJobConfig(query_parameters=query_parameters)
+ query_params = self.bigquery.QueryJobConfig(
+ query_parameters=query_parameters
+ )
query_job = engine.query(modified_sql, job_config=query_params)
else:
query_job = engine.query(sql_query)
diff --git a/unstract/connectors/src/unstract/connectors/databases/postgresql/postgresql.py b/unstract/connectors/src/unstract/connectors/databases/postgresql/postgresql.py
index a3aca56de..7fb13a0c0 100644
--- a/unstract/connectors/src/unstract/connectors/databases/postgresql/postgresql.py
+++ b/unstract/connectors/src/unstract/connectors/databases/postgresql/postgresql.py
@@ -144,8 +144,9 @@ class PostgreSQL(UnstractDB, PsycoPgHandler):
Returns:
str: generates a create sql base query with the constant columns
"""
+ quoted_table = self._quote_identifier(table)
sql_query = (
- f"CREATE TABLE IF NOT EXISTS {table} "
+ f"CREATE TABLE IF NOT EXISTS {quoted_table} "
f"(id TEXT, "
f"created_by TEXT, created_at TIMESTAMP, "
f"metadata JSONB, "
@@ -158,8 +159,9 @@ class PostgreSQL(UnstractDB, PsycoPgHandler):
return sql_query
def prepare_multi_column_migration(self, table_name: str, column_name: str) -> str:
+ quoted_table = self._quote_identifier(table_name)
sql_query = (
- f"ALTER TABLE {table_name} "
+ f"ALTER TABLE {quoted_table} "
f"ADD COLUMN {column_name}_v2 JSONB, "
f"ADD COLUMN metadata JSONB, "
f"ADD COLUMN user_field_1 BOOLEAN DEFAULT FALSE, "
@@ -182,3 +184,41 @@ class PostgreSQL(UnstractDB, PsycoPgHandler):
schema=self.schema,
table_name=table_name,
)
+
+ @staticmethod
+ def _quote_identifier(identifier: str) -> str:
+ """Quote PostgreSQL identifier to handle special characters like hyphens.
+
+ PostgreSQL identifiers with special characters must be enclosed in double quotes.
+ This method adds proper quoting for table names containing hyphens, spaces,
+ or other special characters.
+
+ Args:
+ identifier (str): Table name or column name to quote
+
+ Returns:
+ str: Properly quoted identifier safe for PostgreSQL
+ """
+ # Always quote the identifier to handle special characters like hyphens
+ # This is safe even for valid identifiers and prevents SQL injection
+ return f'"{identifier}"'
+
+ def get_sql_insert_query(
+ self, table_name: str, sql_keys: list[str], sql_values: list[str] | None = None
+ ) -> str:
+ """Override base method to add PostgreSQL-specific table name quoting.
+
+ Generates INSERT query with properly quoted table name for PostgreSQL.
+
+ Args:
+ table_name (str): Name of the table
+ sql_keys (list[str]): List of column names
+ sql_values (list[str], optional): SQL values for database-specific handling (ignored for PostgreSQL)
+
+ Returns:
+ str: INSERT query with properly quoted table name
+ """
+ quoted_table = self._quote_identifier(table_name)
+ keys_str = ", ".join(sql_keys)
+ values_placeholder = ", ".join(["%s"] * len(sql_keys))
+ return f"INSERT INTO {quoted_table} ({keys_str}) VALUES ({values_placeholder})"
diff --git a/unstract/connectors/src/unstract/connectors/databases/register.py b/unstract/connectors/src/unstract/connectors/databases/register.py
index bf7617efb..f4ef0883e 100644
--- a/unstract/connectors/src/unstract/connectors/databases/register.py
+++ b/unstract/connectors/src/unstract/connectors/databases/register.py
@@ -33,7 +33,10 @@ def register_connectors(connectors: dict[str, Any]) -> None:
Common.METADATA: metadata,
}
except ModuleNotFoundError as exception:
- logger.error(f"Error while importing connectors : {exception}")
+ logger.error(
+ f"Error while importing connectors {connector} : {exception}",
+ exc_info=True,
+ )
if len(connectors) == 0:
logger.warning("No connector found.")
diff --git a/unstract/connectors/src/unstract/connectors/databases/snowflake/snowflake.py b/unstract/connectors/src/unstract/connectors/databases/snowflake/snowflake.py
index c44bde6e4..7156af515 100644
--- a/unstract/connectors/src/unstract/connectors/databases/snowflake/snowflake.py
+++ b/unstract/connectors/src/unstract/connectors/databases/snowflake/snowflake.py
@@ -6,10 +6,6 @@ import uuid
from enum import Enum
from typing import Any
-import snowflake.connector
-import snowflake.connector.errors as SnowflakeError
-from snowflake.connector.connection import SnowflakeConnection
-
from unstract.connectors.constants import DatabaseTypeConstants
from unstract.connectors.databases.exceptions import SnowflakeProgrammingException
from unstract.connectors.databases.unstract_db import UnstractDB
@@ -88,8 +84,10 @@ class SnowflakeDB(UnstractDB):
}
return str(mapping.get(data_type, DatabaseTypeConstants.SNOWFLAKE_TEXT))
- def get_engine(self) -> SnowflakeConnection:
- con = snowflake.connector.connect(
+ def get_engine(self) -> Any:
+ from snowflake.connector import connect
+
+ con = connect(
user=self.user,
password=self.password,
account=self.account,
@@ -134,6 +132,8 @@ class SnowflakeDB(UnstractDB):
def execute_query(
self, engine: Any, sql_query: str, sql_values: Any, **kwargs: Any
) -> None:
+ import snowflake.connector.errors as SnowflakeError
+
table_name = kwargs.get("table_name", None)
logger.debug(f"Snowflake execute_query called with sql_query: {sql_query}")
logger.debug(f"sql_values: {sql_values}")
@@ -169,6 +169,8 @@ class SnowflakeDB(UnstractDB):
) from e
def get_information_schema(self, table_name: str) -> dict[str, str]:
+ import snowflake.connector.errors as SnowflakeError
+
query = f"describe table {table_name}"
column_types: dict[str, str] = {}
try:
diff --git a/unstract/connectors/src/unstract/connectors/filesystems/__init__.py b/unstract/connectors/src/unstract/connectors/filesystems/__init__.py
index 7635b7ca1..0d0da63bf 100644
--- a/unstract/connectors/src/unstract/connectors/filesystems/__init__.py
+++ b/unstract/connectors/src/unstract/connectors/filesystems/__init__.py
@@ -1,4 +1,4 @@
-from unstract.connectors import ConnectorDict # type: ignore
+from unstract.connectors.constants import ConnectorDict
from unstract.connectors.filesystems.register import register_connectors
from .local_storage.local_storage import * # noqa: F401, F403
diff --git a/unstract/connectors/src/unstract/connectors/filesystems/azure_cloud_storage/azure_cloud_storage.py b/unstract/connectors/src/unstract/connectors/filesystems/azure_cloud_storage/azure_cloud_storage.py
index 2a8827313..4b2b71b51 100644
--- a/unstract/connectors/src/unstract/connectors/filesystems/azure_cloud_storage/azure_cloud_storage.py
+++ b/unstract/connectors/src/unstract/connectors/filesystems/azure_cloud_storage/azure_cloud_storage.py
@@ -5,7 +5,7 @@ from email.utils import parsedate_to_datetime
from typing import Any
import azure.core.exceptions as AzureException
-from adlfs import AzureBlobFileSystem
+from fsspec import AbstractFileSystem
from unstract.connectors.exceptions import AzureHttpError
from unstract.connectors.filesystems.azure_cloud_storage.exceptions import (
@@ -14,7 +14,17 @@ from unstract.connectors.filesystems.azure_cloud_storage.exceptions import (
from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
from unstract.filesystem import FileStorageType, FileSystem
+# Suppress verbose Azure SDK HTTP request/response logging
logging.getLogger("azurefs").setLevel(logging.ERROR)
+logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
+ logging.WARNING
+)
+logging.getLogger("azure.storage.blob").setLevel(logging.WARNING)
+logging.getLogger("azure.storage").setLevel(logging.WARNING)
+logging.getLogger("azure.core").setLevel(logging.WARNING)
+# Keep ADLFS filesystem errors visible but suppress HTTP noise
+logging.getLogger("adlfs").setLevel(logging.WARNING)
+
logger = logging.getLogger(__name__)
@@ -23,6 +33,8 @@ class AzureCloudStorageFS(UnstractFileSystem):
INVALID_PATH = "The specifed resource name contains invalid characters."
def __init__(self, settings: dict[str, Any]):
+ from adlfs import AzureBlobFileSystem
+
super().__init__("AzureCloudStorageFS")
account_name = settings.get("account_name", "")
access_key = settings.get("access_key", "")
@@ -70,7 +82,7 @@ class AzureCloudStorageFS(UnstractFileSystem):
def can_read() -> bool:
return True
- def get_fsspec_fs(self) -> AzureBlobFileSystem:
+ def get_fsspec_fs(self) -> AbstractFileSystem:
return self.azure_fs
def extract_metadata_file_hash(self, metadata: dict[str, Any]) -> str | None:
diff --git a/unstract/connectors/src/unstract/connectors/filesystems/google_cloud_storage/google_cloud_storage.py b/unstract/connectors/src/unstract/connectors/filesystems/google_cloud_storage/google_cloud_storage.py
index e77864192..03b3beb49 100644
--- a/unstract/connectors/src/unstract/connectors/filesystems/google_cloud_storage/google_cloud_storage.py
+++ b/unstract/connectors/src/unstract/connectors/filesystems/google_cloud_storage/google_cloud_storage.py
@@ -5,7 +5,7 @@ import os
from datetime import UTC, datetime
from typing import Any
-from gcsfs import GCSFileSystem
+from fsspec import AbstractFileSystem
from unstract.connectors.exceptions import ConnectorError
from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
@@ -26,6 +26,8 @@ class GoogleCloudStorageFS(UnstractFileSystem):
project_id = settings.get("project_id", "")
json_credentials_str = settings.get("json_credentials", "{}")
try:
+ from gcsfs import GCSFileSystem
+
json_credentials = json.loads(json_credentials_str)
self.gcs_fs = GCSFileSystem(
token=json_credentials,
@@ -81,7 +83,7 @@ class GoogleCloudStorageFS(UnstractFileSystem):
def can_read() -> bool:
return True
- def get_fsspec_fs(self) -> GCSFileSystem:
+ def get_fsspec_fs(self) -> AbstractFileSystem:
return self.gcs_fs
def extract_metadata_file_hash(self, metadata: dict[str, Any]) -> str | None:
@@ -109,8 +111,46 @@ class GoogleCloudStorageFS(UnstractFileSystem):
Returns:
bool: True if the path is a directory, False otherwise.
"""
- # Note: Here Metadata type seems to be always "file" even for directories
- return metadata.get("type") == "directory"
+ # Primary check: Standard directory type
+ if metadata.get("type") == "directory":
+ return True
+
+ # GCS-specific directory detection
+ # In GCS, folders are represented as objects with specific characteristics
+ object_name = metadata.get("name", "")
+ size = metadata.get("size", 0)
+ content_type = metadata.get("contentType", "")
+
+ # GCS folder indicators:
+ # 1. Object name ends with "/" (most reliable indicator)
+ if object_name.endswith("/"):
+ logger.debug(
+ f"[GCS Directory Check] '{object_name}' identified as directory: name ends with '/'"
+ )
+ return True
+
+ # 2. Zero-size object with text/plain content type (common for GCS folders)
+ if size == 0 and content_type == "text/plain":
+ logger.debug(
+ f"[GCS Directory Check] '{object_name}' identified as directory: zero-size with text/plain content type"
+ )
+ return True
+
+ # 3. Check for GCS-specific folder metadata
+ # Some GCS folder objects have no contentType or have application/x-www-form-urlencoded
+ if size == 0 and (
+ not content_type
+ or content_type
+ in ["application/x-www-form-urlencoded", "binary/octet-stream"]
+ ):
+ # Additional validation: check if this looks like a folder path
+ if "/" in object_name and not object_name.split("/")[-1]: # Path ends with /
+ logger.debug(
+ f"[GCS Directory Check] '{object_name}' identified as directory: zero-size folder-like object"
+ )
+ return True
+
+ return False
def extract_modified_date(self, metadata: dict[str, Any]) -> datetime | None:
"""Extract the last modified date from GCS metadata.
diff --git a/unstract/connectors/src/unstract/connectors/filesystems/register.py b/unstract/connectors/src/unstract/connectors/filesystems/register.py
index d820e5f62..15c630149 100644
--- a/unstract/connectors/src/unstract/connectors/filesystems/register.py
+++ b/unstract/connectors/src/unstract/connectors/filesystems/register.py
@@ -32,7 +32,10 @@ def register_connectors(connectors: dict[str, Any]) -> None:
Common.METADATA: metadata,
}
except ModuleNotFoundError as exception:
- logger.error(f"Error while importing connectors : {exception}")
+ logger.error(
+ f"Error while importing connectors {connector} : {exception}",
+ exc_info=True,
+ )
if len(connectors) == 0:
logger.warning("No connector found.")
diff --git a/unstract/connectors/src/unstract/connectors/filesystems/zs_dropbox/zs_dropbox.py b/unstract/connectors/src/unstract/connectors/filesystems/zs_dropbox/zs_dropbox.py
index 99151eaa3..a4b1c51fc 100644
--- a/unstract/connectors/src/unstract/connectors/filesystems/zs_dropbox/zs_dropbox.py
+++ b/unstract/connectors/src/unstract/connectors/filesystems/zs_dropbox/zs_dropbox.py
@@ -3,20 +3,18 @@ import os
from datetime import UTC, datetime
from typing import Any
-from dropbox.exceptions import ApiError as DropBoxApiError
-from dropbox.exceptions import DropboxException
-from dropboxdrivefs import DropboxDriveFileSystem
+from fsspec import AbstractFileSystem
from unstract.connectors.exceptions import ConnectorError
from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
-from .exceptions import handle_dropbox_exception
-
logger = logging.getLogger(__name__)
class DropboxFS(UnstractFileSystem):
def __init__(self, settings: dict[str, Any]):
+ from dropboxdrivefs import DropboxDriveFileSystem
+
super().__init__("Dropbox")
self.dropbox_fs = DropboxDriveFileSystem(token=settings["token"])
self.path = "///"
@@ -61,7 +59,7 @@ class DropboxFS(UnstractFileSystem):
def can_read() -> bool:
return True
- def get_fsspec_fs(self) -> DropboxDriveFileSystem:
+ def get_fsspec_fs(self) -> AbstractFileSystem:
return self.dropbox_fs
def extract_metadata_file_hash(self, metadata: dict[str, Any]) -> str | None:
@@ -132,10 +130,14 @@ class DropboxFS(UnstractFileSystem):
def test_credentials(self) -> bool:
"""To test credentials for Dropbox."""
+ from dropbox.exceptions import DropboxException
+
try:
# self.get_fsspec_fs().connect()
self.get_fsspec_fs().ls("")
except DropboxException as e:
+ from .exceptions import handle_dropbox_exception
+
raise handle_dropbox_exception(e) from e
except Exception as e:
raise ConnectorError(f"Error while connecting to Dropbox: {str(e)}") from e
@@ -143,11 +145,23 @@ class DropboxFS(UnstractFileSystem):
@staticmethod
def get_connector_root_dir(input_dir: str, **kwargs: Any) -> str:
- """Get roor dir of zs dropbox."""
- return f"/{input_dir.strip('/')}"
+ """Get root dir of zs dropbox with backward compatibility.
+
+ Dropbox requires leading slashes, so we override the base class behavior.
+ """
+ # Call base class implementation
+ result = super().get_connector_root_dir(input_dir, **kwargs)
+
+ # Dropbox needs leading slash - ensure it's present
+ if not result.startswith("/"):
+ result = f"/{result}"
+
+ return result
def create_dir_if_not_exists(self, input_dir: str) -> None:
"""Create roor dir of zs dropbox if not exists."""
+ from dropbox.exceptions import ApiError as DropBoxApiError
+
fs_fsspec = self.get_fsspec_fs()
try:
fs_fsspec.isdir(input_dir)
diff --git a/unstract/connectors/src/unstract/connectors/gcs_helper.py b/unstract/connectors/src/unstract/connectors/gcs_helper.py
index c4d110d4d..c8449cfd2 100644
--- a/unstract/connectors/src/unstract/connectors/gcs_helper.py
+++ b/unstract/connectors/src/unstract/connectors/gcs_helper.py
@@ -4,8 +4,6 @@ import logging
import os
from typing import Any
-from google.cloud import secretmanager
-from google.cloud.storage import Client
from google.oauth2 import service_account
from google.oauth2.credentials import Credentials
@@ -20,6 +18,9 @@ logger = logging.getLogger(__name__)
class GCSHelper:
def __init__(self) -> None:
+ from google.cloud.storage import Client
+
+ self.client = Client
self.google_service_json = os.environ.get("GDRIVE_GOOGLE_SERVICE_ACCOUNT")
self.google_project_id = os.environ.get("GDRIVE_GOOGLE_PROJECT_ID")
if self.google_service_json is None:
@@ -39,6 +40,8 @@ class GCSHelper:
return self.google_credentials
def get_secret(self, secret_name: str) -> str:
+ from google.cloud import secretmanager
+
google_secrets_client = secretmanager.SecretManagerServiceClient(
credentials=self.google_credentials
)
@@ -50,7 +53,7 @@ class GCSHelper:
return s.payload.data.decode("UTF-8")
def get_object_checksum(self, bucket_name: str, object_name: str) -> str:
- client = Client(credentials=self.google_credentials)
+ client = self.client(credentials=self.google_credentials)
bucket = client.bucket(bucket_name)
md5_hash_hex = ""
try:
@@ -62,26 +65,26 @@ class GCSHelper:
return md5_hash_hex
def upload_file(self, bucket_name: str, object_name: str, file_path: str) -> None:
- client = Client(credentials=self.google_credentials)
+ client = self.client(credentials=self.google_credentials)
bucket = client.bucket(bucket_name)
blob = bucket.blob(object_name)
blob.upload_from_filename(file_path)
def upload_text(self, bucket_name: str, object_name: str, text: str) -> None:
- client = Client(credentials=self.google_credentials)
+ client = self.client(credentials=self.google_credentials)
bucket = client.bucket(bucket_name)
blob = bucket.blob(object_name)
blob.upload_from_string(text)
def upload_object(self, bucket_name: str, object_name: str, object: Any) -> None:
- client = Client(credentials=self.google_credentials)
+ client = self.client(credentials=self.google_credentials)
bucket = client.bucket(bucket_name)
blob = bucket.blob(object_name)
blob.upload_from_string(object, content_type="application/octet-stream")
def read_file(self, bucket_name: str, object_name: str) -> Any:
logger.info(f"Reading file {object_name} from bucket {bucket_name}")
- client = Client(credentials=self.google_credentials)
+ client = self.client(credentials=self.google_credentials)
bucket = client.bucket(bucket_name)
logger.info(f"Reading file {object_name} from bucket {bucket_name}")
try:
diff --git a/unstract/connectors/src/unstract/connectors/operations.py b/unstract/connectors/src/unstract/connectors/operations.py
new file mode 100644
index 000000000..515e9ad87
--- /dev/null
+++ b/unstract/connectors/src/unstract/connectors/operations.py
@@ -0,0 +1,146 @@
+"""Connector Operations for Unstract Platform
+
+This module provides core connector operations for filesystem connectors
+and connector health checks.
+
+Used by:
+- workers/shared/workflow/connectors/service.py (for worker-native operations)
+"""
+
+import logging
+from typing import Any
+
+# Import internal connector components (no try/catch needed - proper dependencies)
+from unstract.connectors.constants import Common
+from unstract.connectors.filesystems import connectors as fs_connectors
+from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
+
+logger = logging.getLogger(__name__)
+
+
+class ConnectorOperations:
+ """Common connector operations shared between backend and workers with strict error handling"""
+
+ @staticmethod
+ def test_connector_connection(
+ connector_id: str, settings: dict[str, Any]
+ ) -> dict[str, Any]:
+ """Test connection to connector before attempting operations.
+
+ Args:
+ connector_id: Connector ID
+ settings: Connector settings
+
+ Returns:
+ Dictionary with connection test results: {'is_connected': bool, 'error': str}
+ """
+ try:
+ # Get connector instance
+ connector = ConnectorOperations.get_fs_connector(connector_id, settings)
+
+ # Test basic connectivity by getting fsspec filesystem
+ fs = connector.get_fsspec_fs()
+
+ # For filesystem connectors, try to check if root path exists
+ test_path = settings.get("path", "/")
+ try:
+ fs.exists(test_path)
+ return {"is_connected": True, "error": None}
+ except Exception as path_error:
+ return {
+ "is_connected": False,
+ "error": f"Cannot access path '{test_path}': {str(path_error)}",
+ }
+
+ except Exception as e:
+ return {"is_connected": False, "error": str(e)}
+
+ @staticmethod
+ def get_fs_connector(
+ connector_id: str, settings: dict[str, Any]
+ ) -> "UnstractFileSystem":
+ """Get filesystem connector instance using exact backend BaseConnector logic.
+
+ This replicates backend/workflow_manager/endpoint_v2/base_connector.py:get_fs_connector()
+
+ Args:
+ connector_id: Connector ID from the registry
+ settings: Connector-specific settings
+
+ Returns:
+ UnstractFileSystem instance
+
+ Raises:
+ ImportError: If connector registries not available (critical error)
+ ValueError: If connector_id is not supported
+ """
+ if not fs_connectors:
+ raise RuntimeError("Filesystem connectors registry not initialized")
+
+ if connector_id not in fs_connectors:
+ available_ids = list(fs_connectors.keys())
+ raise ValueError(
+ f"Connector '{connector_id}' is not supported. "
+ f"Available connectors: {available_ids}"
+ )
+
+ if not Common:
+ raise RuntimeError("Common connector constants not initialized")
+
+ # Use exact same pattern as backend BaseConnector
+ connector_class = fs_connectors[connector_id][Common.METADATA][Common.CONNECTOR]
+ return connector_class(settings)
+
+ @staticmethod
+ def get_connector_health(source_config: dict[str, Any]) -> dict[str, Any]:
+ """Get health status of a source connector.
+
+ Args:
+ source_config: Source configuration dictionary
+
+ Returns:
+ Dictionary with health status and metadata
+ """
+ try:
+ connector_id = source_config.get("connector_id") or source_config.get(
+ "connection_type"
+ )
+ settings = source_config.get("settings", {})
+
+ if not connector_id or not settings:
+ return {
+ "is_healthy": False,
+ "connection_type": connector_id,
+ "errors": ["Missing connector configuration"],
+ "response_time_ms": None,
+ }
+
+ import time
+
+ start_time = time.time()
+
+ # Test connection
+ connection_result = ConnectorOperations.test_connector_connection(
+ connector_id, settings
+ )
+
+ response_time = int(
+ (time.time() - start_time) * 1000
+ ) # Convert to milliseconds
+
+ return {
+ "is_healthy": connection_result["is_connected"],
+ "connection_type": connector_id,
+ "errors": [connection_result["error"]]
+ if connection_result["error"]
+ else [],
+ "response_time_ms": response_time,
+ }
+
+ except Exception as e:
+ return {
+ "is_healthy": False,
+ "connection_type": source_config.get("connector_id", "unknown"),
+ "errors": [str(e)],
+ "response_time_ms": None,
+ }
diff --git a/unstract/connectors/src/unstract/connectors/queues/__init__.py b/unstract/connectors/src/unstract/connectors/queues/__init__.py
index 8a6d8d0bd..91a53af74 100644
--- a/unstract/connectors/src/unstract/connectors/queues/__init__.py
+++ b/unstract/connectors/src/unstract/connectors/queues/__init__.py
@@ -1,4 +1,4 @@
-from unstract.connectors import ConnectorDict
+from unstract.connectors.constants import ConnectorDict
from unstract.connectors.queues.register import register_connectors
connectors: ConnectorDict = {}
diff --git a/unstract/connectors/src/unstract/connectors/queues/register.py b/unstract/connectors/src/unstract/connectors/queues/register.py
index 4eca532c6..c6ca8588f 100644
--- a/unstract/connectors/src/unstract/connectors/queues/register.py
+++ b/unstract/connectors/src/unstract/connectors/queues/register.py
@@ -32,7 +32,10 @@ def register_connectors(connectors: dict[str, Any]) -> None:
Common.METADATA: metadata,
}
except ModuleNotFoundError as exception:
- logger.error(f"Error while importing connectors : {exception}")
+ logger.error(
+ f"Error while importing connectors {connector} : {exception}",
+ exc_info=True,
+ )
if len(connectors) == 0:
logger.warning("No connector found.")
diff --git a/unstract/core/src/unstract/__init__.py b/unstract/core/src/unstract/__init__.py
new file mode 100644
index 000000000..a7d65b079
--- /dev/null
+++ b/unstract/core/src/unstract/__init__.py
@@ -0,0 +1,2 @@
+# Unstract namespace package
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/unstract/core/src/unstract/core/__init__.py b/unstract/core/src/unstract/core/__init__.py
index e69de29bb..deb84687f 100644
--- a/unstract/core/src/unstract/core/__init__.py
+++ b/unstract/core/src/unstract/core/__init__.py
@@ -0,0 +1,99 @@
+"""Unstract Core Library
+
+Core data models, utilities, and base classes for the Unstract platform.
+Provides shared functionality between backend and worker services.
+"""
+
+# Export core data models and enums
+# Export existing utilities and constants
+from .constants import LogEventArgument, LogFieldName, LogProcessingTask
+from .data_models import (
+ ConnectionType,
+ ExecutionStatus,
+ FileHashData,
+ SourceConnectionType,
+ WorkflowExecutionData,
+ WorkflowFileExecutionData,
+ WorkflowType,
+ serialize_dataclass_to_dict,
+)
+
+# Export worker base classes
+from .worker_base import (
+ CallbackTaskBase,
+ FileProcessingTaskBase,
+ WorkerTaskBase,
+ circuit_breaker,
+ create_callback_task,
+ create_file_processing_task,
+ create_task_decorator,
+ monitor_performance,
+ with_task_context,
+)
+
+# Note: Worker constants moved to workers/shared/ to remove Django dependency
+# These are now available directly from workers.shared.constants and workers.shared.worker_patterns
+# Export worker-specific models and enums
+from .worker_models import (
+ BatchExecutionResult,
+ CallbackExecutionData,
+ FileExecutionResult,
+ NotificationMethod,
+ NotificationRequest,
+ PipelineStatus,
+ PipelineStatusUpdateRequest,
+ QueueName,
+ StatusMappings,
+ TaskError,
+ TaskExecutionContext,
+ TaskName,
+ WebhookResult,
+ WebhookStatus,
+ WorkerTaskStatus,
+ WorkflowExecutionUpdateRequest,
+)
+
+__version__ = "1.0.0"
+
+__all__ = [
+ # Core data models and enums
+ "ExecutionStatus",
+ "WorkflowType",
+ "ConnectionType",
+ "FileHashData",
+ "WorkflowFileExecutionData",
+ "WorkflowExecutionData",
+ "SourceConnectionType",
+ "serialize_dataclass_to_dict",
+ # Worker models and enums
+ "TaskName",
+ "QueueName",
+ "WorkerTaskStatus",
+ "PipelineStatus",
+ "WebhookStatus",
+ "NotificationMethod",
+ "StatusMappings",
+ "WebhookResult",
+ "FileExecutionResult",
+ "BatchExecutionResult",
+ "CallbackExecutionData",
+ "WorkflowExecutionUpdateRequest",
+ "PipelineStatusUpdateRequest",
+ "NotificationRequest",
+ "TaskExecutionContext",
+ "TaskError",
+ # Worker base classes
+ "WorkerTaskBase",
+ "FileProcessingTaskBase",
+ "CallbackTaskBase",
+ "create_task_decorator",
+ "monitor_performance",
+ "with_task_context",
+ "circuit_breaker",
+ "create_file_processing_task",
+ "create_callback_task",
+ # Existing utilities
+ "LogFieldName",
+ "LogEventArgument",
+ "LogProcessingTask",
+]
diff --git a/unstract/core/src/unstract/core/constants.py b/unstract/core/src/unstract/core/constants.py
index 67264f9c6..44204416d 100644
--- a/unstract/core/src/unstract/core/constants.py
+++ b/unstract/core/src/unstract/core/constants.py
@@ -18,3 +18,114 @@ class LogEventArgument:
class LogProcessingTask:
TASK_NAME = "logs_consumer"
QUEUE_NAME = "celery_log_task_queue"
+
+
+class FileProcessingConstants:
+ """Constants for file processing operations."""
+
+ # File chunk size for reading/writing (4MB default)
+ READ_CHUNK_SIZE = 4194304 # 4MB chunks for file reading
+
+ # Log preview size for truncating file content in logs
+ LOG_PREVIEW_SIZE = 500 # 500 bytes for log preview
+
+ # File processing timeout in seconds
+ DEFAULT_PROCESSING_TIMEOUT = 300 # 5 minutes
+
+ # Maximum file size in bytes for validation
+ MAX_FILE_SIZE_BYTES = 100 * 1024 * 1024 # 100MB
+
+ @classmethod
+ def get_chunk_size(cls) -> int:
+ """Get the configured chunk size for file operations."""
+ return cls.READ_CHUNK_SIZE
+
+ @classmethod
+ def get_log_preview_size(cls) -> int:
+ """Get the configured log preview size."""
+ return cls.LOG_PREVIEW_SIZE
+
+
+class WorkerConstants:
+ """General worker operation constants."""
+
+ # Default retry attempts for worker operations
+ DEFAULT_RETRY_ATTEMPTS = 3
+
+ # Default timeout for API calls
+ API_TIMEOUT = 30
+
+ # Health check interval
+ HEALTH_CHECK_INTERVAL = 30
+
+
+class FilePatternConstants:
+ """Constants for file pattern matching and translation."""
+
+ # Display name to file pattern mappings
+ # Maps UI-friendly display names to actual file matching patterns
+ DISPLAY_NAME_TO_PATTERNS = {
+ "pdf documents": ["*.pdf"],
+ "word documents": ["*.doc", "*.docx"],
+ "excel documents": ["*.xls", "*.xlsx"],
+ "powerpoint documents": ["*.ppt", "*.pptx"],
+ "text files": ["*.txt"],
+ "image files": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.bmp", "*.tiff", "*.tif"],
+ "csv files": ["*.csv"],
+ "json files": ["*.json"],
+ "xml files": ["*.xml"],
+ "all files": ["*"],
+ "office documents": ["*.doc", "*.docx", "*.xls", "*.xlsx", "*.ppt", "*.pptx"],
+ "document files": ["*.pdf", "*.doc", "*.docx", "*.txt"],
+ "spreadsheet files": ["*.xls", "*.xlsx", "*.csv"],
+ "presentation files": ["*.ppt", "*.pptx"],
+ "archive files": ["*.zip", "*.rar", "*.7z", "*.tar", "*.gz"],
+ "video files": ["*.mp4", "*.avi", "*.mov", "*.wmv", "*.flv", "*.mkv"],
+ "audio files": ["*.mp3", "*.wav", "*.flac", "*.aac", "*.ogg"],
+ }
+
+ # Common file extension categories for inference
+ EXTENSION_CATEGORIES = {
+ "pdf": ["*.pdf"],
+ "doc": ["*.doc", "*.docx"],
+ "excel": ["*.xls", "*.xlsx"],
+ "image": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.bmp", "*.tiff", "*.tif"],
+ "text": ["*.txt"],
+ "csv": ["*.csv"],
+ "json": ["*.json"],
+ "xml": ["*.xml"],
+ "office": ["*.doc", "*.docx", "*.xls", "*.xlsx", "*.ppt", "*.pptx"],
+ "archive": ["*.zip", "*.rar", "*.7z", "*.tar", "*.gz"],
+ "video": ["*.mp4", "*.avi", "*.mov", "*.wmv", "*.flv", "*.mkv"],
+ "audio": ["*.mp3", "*.wav", "*.flac", "*.aac", "*.ogg"],
+ }
+
+ @classmethod
+ def get_patterns_for_display_name(cls, display_name: str) -> list[str] | None:
+ """Get file patterns for a given display name.
+
+ Args:
+ display_name: UI display name (e.g., "PDF documents")
+
+ Returns:
+ List of file patterns or None if not found
+ """
+ return cls.DISPLAY_NAME_TO_PATTERNS.get(display_name.strip().lower())
+
+ @classmethod
+ def infer_patterns_from_keyword(cls, keyword: str) -> list[str] | None:
+ """Infer file patterns from a keyword.
+
+ Args:
+ keyword: Keyword to search for (e.g., "pdf", "excel")
+
+ Returns:
+ List of file patterns or None if not found
+ """
+ keyword_lower = keyword.strip().lower()
+
+ for category, patterns in cls.EXTENSION_CATEGORIES.items():
+ if category in keyword_lower:
+ return patterns
+
+ return None
diff --git a/unstract/core/src/unstract/core/data_models.py b/unstract/core/src/unstract/core/data_models.py
new file mode 100644
index 000000000..6de7002a6
--- /dev/null
+++ b/unstract/core/src/unstract/core/data_models.py
@@ -0,0 +1,2296 @@
+"""Shared Data Models for Unstract Workflow Execution
+
+This module contains shared dataclasses used across backend and worker services
+to ensure type safety and consistent data structures for API communication.
+"""
+
+import json
+import logging
+import uuid
+from dataclasses import asdict, dataclass, field
+from datetime import UTC, datetime
+from enum import Enum
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+# Centralized field mapping configurations
+# These can be easily updated when model fields change
+FIELD_MAPPINGS = {
+ "WebhookConfigurationData": {
+ "notification_id": "id",
+ "url": "url",
+ "authorization_type": "authorization_type",
+ "authorization_key": "authorization_key",
+ "authorization_header": "authorization_header",
+ "max_retries": "max_retries",
+ "is_active": "is_active",
+ },
+ "HealthCheckResponse": {
+ # Direct mapping - model field names match dataclass field names
+ "status": "status",
+ "service": "service",
+ "version": "version",
+ "timestamp": "timestamp",
+ "authenticated": "authenticated",
+ "organization_id": "organization_id",
+ },
+}
+
+
+class ModelAdapterMixin:
+ """Mixin providing flexible model-to-dataclass conversion capabilities."""
+
+ @classmethod
+ def from_model(
+ cls,
+ model_instance: Any,
+ field_mapping: dict[str, str] | None = None,
+ transform_functions: dict[str, callable] | None = None,
+ ) -> Any:
+ """Create dataclass instance from any model with flexible field mapping.
+
+ Args:
+ model_instance: Django model instance or any object with attributes
+ field_mapping: Optional dict mapping dataclass_field -> model_field
+ If None, uses centralized FIELD_MAPPINGS or direct mapping
+ transform_functions: Optional dict mapping field_name -> transform_function
+ for custom field transformations
+
+ Returns:
+ Dataclass instance
+
+ This method is resilient to model changes:
+ - Missing fields use dataclass defaults
+ - Extra model fields are ignored
+ - Field name changes handled via mapping
+ - Custom transformations applied via transform_functions
+ - Centralized mapping configuration for maintainability
+ """
+ from dataclasses import MISSING, fields
+
+ # Get dataclass field definitions
+ dataclass_fields = {f.name: f for f in fields(cls)}
+
+ # Use centralized mapping, provided mapping, or direct mapping
+ if field_mapping is None:
+ # Try to get mapping from centralized config
+ class_name = cls.__name__
+ if class_name in FIELD_MAPPINGS:
+ field_mapping = FIELD_MAPPINGS[class_name]
+ logger.debug(f"Using centralized field mapping for {class_name}")
+ else:
+ # Fall back to direct mapping
+ field_mapping = {name: name for name in dataclass_fields.keys()}
+ logger.debug(f"Using direct field mapping for {class_name}")
+
+ # Build kwargs by mapping model fields to dataclass fields
+ kwargs = {}
+ for dataclass_field, model_field in field_mapping.items():
+ if dataclass_field in dataclass_fields:
+ field_def = dataclass_fields[dataclass_field]
+
+ # Get value from model with fallback handling
+ if hasattr(model_instance, model_field):
+ value = getattr(model_instance, model_field)
+ elif field_def.default != MISSING:
+ value = field_def.default
+ elif field_def.default_factory != MISSING: # type: ignore
+ value = field_def.default_factory()
+ else:
+ # Required field missing from model - this indicates a breaking change
+ logger.warning(
+ f"Required field '{model_field}' missing from model {type(model_instance).__name__} "
+ f"for dataclass {cls.__name__}. This may indicate a model schema change."
+ )
+ continue
+
+ # Apply transform function if provided
+ if transform_functions and dataclass_field in transform_functions:
+ try:
+ value = transform_functions[dataclass_field](value)
+ except Exception as e:
+ logger.warning(
+ f"Transform function failed for field '{dataclass_field}': {e}. "
+ f"Using original value."
+ )
+
+ kwargs[dataclass_field] = value
+
+ return cls(**kwargs)
+
+ @classmethod
+ def from_dict_safe(cls, data: dict[str, Any]) -> Any:
+ """Create dataclass instance from dictionary with safe handling of missing fields."""
+ from dataclasses import MISSING, fields
+
+ dataclass_fields = {f.name: f for f in fields(cls)}
+ kwargs = {}
+
+ for field_name, field_def in dataclass_fields.items():
+ if field_name in data:
+ kwargs[field_name] = data[field_name]
+ elif field_def.default != MISSING:
+ kwargs[field_name] = field_def.default
+ elif field_def.default_factory != MISSING: # type: ignore
+ kwargs[field_name] = field_def.default_factory()
+ # Required fields missing from dict will cause __init__ to fail with clear error
+
+ return cls(**kwargs)
+
+
+def create_dataclass_from_model(
+ dataclass_type: type, model_instance: Any, field_mapping: dict[str, str] | None = None
+) -> Any:
+ """Utility function to create any dataclass from a model instance.
+
+ This is a convenience function that works with any dataclass that inherits
+ from ModelAdapterMixin. It provides a consistent interface for model-to-dataclass
+ conversion.
+
+ Args:
+ dataclass_type: The dataclass type to create
+ model_instance: Django model instance or any object with attributes
+ field_mapping: Optional field mapping override
+
+ Returns:
+ Instance of dataclass_type
+
+ Example:
+ # Using centralized mapping
+ config = create_dataclass_from_model(WebhookConfigurationData, notification_model)
+
+ # Using custom mapping
+ config = create_dataclass_from_model(
+ WebhookConfigurationData,
+ notification_model,
+ field_mapping={"notification_id": "custom_id_field"}
+ )
+ """
+ if not hasattr(dataclass_type, "from_model"):
+ raise TypeError(f"{dataclass_type.__name__} must inherit from ModelAdapterMixin")
+
+ return dataclass_type.from_model(model_instance, field_mapping)
+
+
+@dataclass
+class OrganizationContext:
+ """Organization context for API requests."""
+
+ organization_id: str
+ tenant_id: str | None = None
+ subscription_plan: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "organization_id": self.organization_id,
+ "tenant_id": self.tenant_id,
+ "subscription_plan": self.subscription_plan,
+ }
+
+
+# File Operation Data Models
+
+
+class SourceConnectionType(str, Enum):
+ """Types of source connections supported."""
+
+ FILESYSTEM = "FILESYSTEM"
+ API = "API"
+
+
+class FileListingResult:
+ """Result of listing files from a source."""
+
+ def __init__(
+ self,
+ files: dict[str, "FileHashData"],
+ total_count: int,
+ connection_type: str,
+ is_api: bool = False,
+ used_file_history: bool = False,
+ ):
+ self.files = files
+ self.total_count = total_count
+ self.connection_type = connection_type
+ self.is_api = is_api
+ self.used_file_history = used_file_history
+
+
+# File Operation Constants
+class FileOperationConstants:
+ """Constants for file operations."""
+
+ READ_CHUNK_SIZE = 4194304 # 4MB chunks for file reading
+ MAX_RECURSIVE_DEPTH = 10 # Maximum directory traversal depth
+ DEFAULT_MAX_FILES = 100 # Default maximum files to process
+ MAX_FILES_FOR_SORTING = 40000
+
+ # File pattern defaults
+ DEFAULT_FILE_PATTERNS = ["*"]
+ ALL_FILES_PATTERN = "*"
+
+ # Common MIME types
+ MIME_TYPE_PDF = "application/pdf"
+ MIME_TYPE_TEXT = "text/plain"
+ MIME_TYPE_JSON = "application/json"
+ MIME_TYPE_CSV = "text/csv"
+
+
+class SourceKey:
+ """Unified keys used in source configuration across backend and workers.
+
+ This class provides both camelCase (backend) and snake_case (core) naming conventions
+ to ensure compatibility across different parts of the system.
+ """
+
+ # Snake case (core/workers preferred)
+ FILE_EXTENSIONS = "file_extensions"
+ PROCESS_SUB_DIRECTORIES = "process_sub_directories"
+ MAX_FILES = "max_files"
+ FOLDERS = "folders"
+ USE_FILE_HISTORY = "use_file_history"
+ FILE_PROCESSING_ORDER = "file_processing_order"
+
+ # CamelCase (backend compatibility)
+ FILE_EXTENSIONS_CAMEL = "fileExtensions"
+ PROCESS_SUB_DIRECTORIES_CAMEL = "processSubDirectories"
+ MAX_FILES_CAMEL = "maxFiles"
+ FILE_PROCESSING_ORDER_CAMEL = "fileProcessingOrder"
+
+ @classmethod
+ def get_file_extensions(cls, config: dict) -> list:
+ """Get file extensions from config using both naming conventions."""
+ return list(
+ config.get(cls.FILE_EXTENSIONS) or config.get(cls.FILE_EXTENSIONS_CAMEL, [])
+ )
+
+ @classmethod
+ def get_process_sub_directories(cls, config: dict) -> bool:
+ """Get process subdirectories setting from config using both naming conventions."""
+ return bool(
+ config.get(cls.PROCESS_SUB_DIRECTORIES)
+ or config.get(cls.PROCESS_SUB_DIRECTORIES_CAMEL, False)
+ )
+
+ @classmethod
+ def get_max_files(cls, config: dict, default: int = 100) -> int:
+ """Get max files setting from config using both naming conventions."""
+ return int(config.get(cls.MAX_FILES) or config.get(cls.MAX_FILES_CAMEL, default))
+
+ @classmethod
+ def get_folders(cls, config: dict) -> list:
+ """Get folders setting from config."""
+ return list(config.get(cls.FOLDERS, ["/"]))
+
+ @classmethod
+ def get_file_processing_order(cls, config: dict) -> str | None:
+ """Get file processing order setting from config using both naming conventions."""
+ return config.get(cls.FILE_PROCESSING_ORDER) or config.get(
+ cls.FILE_PROCESSING_ORDER_CAMEL
+ )
+
+
+def serialize_dataclass_to_dict(obj) -> dict[str, Any]:
+ """Helper function to serialize dataclass objects to JSON-compatible dictionaries.
+
+ Handles datetime objects, UUID objects, and other complex types.
+ Removes None values from the output.
+
+ Args:
+ obj: Dataclass object to serialize
+
+ Returns:
+ Dictionary with JSON-compatible values
+ """
+ from datetime import date, datetime, time
+ from uuid import UUID
+
+ def serialize_value(value):
+ """Recursively serialize values to JSON-compatible format."""
+ if isinstance(value, UUID):
+ return str(value)
+ elif isinstance(value, (datetime, date)):
+ return value.isoformat()
+ elif isinstance(value, time):
+ return value.isoformat()
+ elif isinstance(value, Enum):
+ return value.value
+ elif isinstance(value, dict):
+ return {k: serialize_value(v) for k, v in value.items()}
+ elif isinstance(value, list):
+ return [serialize_value(item) for item in value]
+ elif isinstance(value, tuple):
+ return [serialize_value(item) for item in value]
+ elif isinstance(value, set):
+ return [serialize_value(item) for item in value]
+ else:
+ return value
+
+ data = asdict(obj)
+ # Serialize all values and remove None values
+ return {k: serialize_value(v) for k, v in data.items() if v is not None}
+
+
+class ExecutionStatus(Enum):
+ """Unified execution status choices for backend and workers.
+
+ This enum is designed to work seamlessly with both Django CharField assignments
+ and worker API calls by implementing __str__ to return the enum value.
+
+ Statuses:
+ PENDING: The execution's entry has been created in the database.
+ EXECUTING: The execution is currently in progress.
+ COMPLETED: The execution has been successfully completed.
+ STOPPED: The execution was stopped by the user (applicable to step executions).
+ ERROR: An error occurred during the execution process.
+
+ Note: This enum aligns with backend workflow_manager.workflow_v2.enums.ExecutionStatus
+ """
+
+ PENDING = "PENDING"
+ EXECUTING = "EXECUTING" # Changed from INPROGRESS to match backend
+ COMPLETED = "COMPLETED"
+ STOPPED = "STOPPED" # Added to match backend
+ ERROR = "ERROR" # Changed from FAILED to match backend
+
+ # Keep legacy statuses for backward compatibility during transition
+ QUEUED = "QUEUED" # Legacy - consider deprecated
+ CANCELED = "CANCELED" # Legacy - maps to STOPPED
+
+ def __str__(self):
+ """Return enum value for Django CharField compatibility.
+
+ This ensures that Django model assignments like:
+ execution.status = ExecutionStatus.PENDING
+ will store "PENDING" in the database instead of "ExecutionStatus.PENDING"
+ """
+ return self.value
+
+ def __repr__(self):
+ """Keep standard enum representation for debugging."""
+ return f"ExecutionStatus.{self.name}"
+
+
+# Add Django-compatible choices attribute after class definition
+ExecutionStatus.choices = tuple(
+ (status.value, status.value) for status in ExecutionStatus
+)
+
+
+# Add the is_completed method as a class method
+def _is_completed(cls, status: str) -> bool:
+ """Check if the execution status represents a completed state."""
+ try:
+ status_enum = cls(status)
+ return status_enum in [cls.COMPLETED, cls.STOPPED, cls.ERROR]
+ except ValueError:
+ raise ValueError(f"Invalid status: {status}. Must be a valid ExecutionStatus.")
+
+
+ExecutionStatus.is_completed = classmethod(_is_completed)
+
+
+# Add the get_skip_processing_statuses method as a class method
+def _get_skip_processing_statuses(cls) -> list["ExecutionStatus"]:
+ """Get list of statuses that should skip file processing.
+
+ Skip processing if:
+ - EXECUTING: File is currently being processed
+ - PENDING: File is queued to be processed
+ - COMPLETED: File has already been successfully processed
+
+ Returns:
+ list[ExecutionStatus]: List of statuses where file processing should be skipped
+ """
+ return [cls.EXECUTING, cls.PENDING, cls.COMPLETED]
+
+
+ExecutionStatus.get_skip_processing_statuses = classmethod(_get_skip_processing_statuses)
+
+
+def _can_update_to_pending(cls, status) -> bool:
+ """Check if a status can be updated to PENDING.
+
+ Allow updating to PENDING if:
+ - Status is STOPPED or ERROR (can retry)
+ - Status is None (new record)
+
+ Don't allow updating to PENDING if:
+ - Status is EXECUTING (currently processing)
+ - Status is COMPLETED (already done)
+ - Status is already PENDING (no change needed)
+
+ Args:
+ status: Current execution status (string or ExecutionStatus enum)
+
+ Returns:
+ bool: True if status can be updated to PENDING, False otherwise
+ """
+ if status is None:
+ return True
+
+ try:
+ status_enum = cls(status)
+ except ValueError:
+ return True # Invalid status, allow update
+
+ return status_enum in [cls.STOPPED, cls.ERROR]
+
+
+ExecutionStatus.can_update_to_pending = classmethod(_can_update_to_pending)
+
+
+class WorkflowType(Enum):
+ """Workflow type choices matching backend models."""
+
+ ETL = "ETL"
+ TASK = "TASK"
+ API = "API"
+ APP = "APP"
+ DEFAULT = "DEFAULT"
+
+
+class NotificationType(Enum):
+ """Notification type choices matching backend models."""
+
+ WEBHOOK = "WEBHOOK"
+ EMAIL = "EMAIL"
+ SMS = "SMS"
+ PUSH = "PUSH"
+
+ def __str__(self):
+ """Return enum value for Django CharField compatibility."""
+ return self.value
+
+
+class NotificationStatus(Enum):
+ """Notification delivery status."""
+
+ SUCCESS = "SUCCESS"
+ FAILURE = "FAILURE"
+ COMPLETED = "COMPLETED"
+ ERROR = "ERROR"
+ STOPPED = "STOPPED"
+
+ def __str__(self):
+ """Return enum value for Django CharField compatibility."""
+ return self.value
+
+
+class NotificationSource(Enum):
+ """Source of notification trigger."""
+
+ BACKEND = "backend"
+ CALLBACK_WORKER = "callback-worker"
+ PIPELINE_COMPLETION = "pipeline-completion"
+ API_EXECUTION = "api-execution"
+ MANUAL_TRIGGER = "manual-trigger"
+
+ def __str__(self):
+ """Return enum value for Django CharField compatibility."""
+ return self.value
+
+
+@dataclass
+class NotificationPayload:
+ """Standardized notification payload structure.
+
+ This dataclass defines the canonical structure for all notification payloads
+ sent from workers to notification systems, ensuring type safety and consistency.
+ """
+
+ # Core notification data
+ type: WorkflowType
+ pipeline_id: str
+ pipeline_name: str
+ status: NotificationStatus
+
+ # Optional execution context
+ execution_id: str | None = None
+ error_message: str | None = None
+ organization_id: str | None = None
+
+ # Metadata
+ timestamp: datetime = field(default_factory=lambda: datetime.now(UTC))
+ additional_data: dict[str, Any] = field(default_factory=dict)
+
+ # Internal tracking (not sent to external webhooks)
+ _source: NotificationSource = field(default=NotificationSource.BACKEND, repr=False)
+
+ def __post_init__(self):
+ """Validate and normalize fields after initialization."""
+ # Ensure enums are properly set
+ if isinstance(self.type, str):
+ self.type = WorkflowType(self.type)
+ if isinstance(self.status, str):
+ self.status = NotificationStatus(self.status)
+ if isinstance(self._source, str):
+ self._source = NotificationSource(self._source)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary with JSON-compatible values (includes all fields)."""
+ return serialize_dataclass_to_dict(self)
+
+ def to_webhook_payload(self) -> dict[str, Any]:
+ """Convert to webhook payload format (excludes internal fields).
+
+ This is the payload structure that external webhook receivers will see.
+ Internal fields like _source are excluded from the external payload.
+ """
+ # Get full dict and remove internal fields
+ full_dict = serialize_dataclass_to_dict(self)
+
+ # Remove internal fields (those starting with _)
+ webhook_payload = {k: v for k, v in full_dict.items() if not k.startswith("_")}
+
+ # Also remove organization_id from external payloads for security
+ webhook_payload.pop("organization_id", None)
+
+ return webhook_payload
+
+ @property
+ def source(self) -> NotificationSource:
+ """Get the internal source for logging/debugging purposes."""
+ return self._source
+
+ @classmethod
+ def from_execution_status(
+ cls,
+ pipeline_id: str,
+ pipeline_name: str,
+ execution_status: ExecutionStatus,
+ workflow_type: WorkflowType,
+ source: NotificationSource,
+ execution_id: str | None = None,
+ error_message: str | None = None,
+ organization_id: str | None = None,
+ additional_data: dict[str, Any] | None = None,
+ ) -> "NotificationPayload":
+ """Create notification payload from execution status.
+
+ Args:
+ pipeline_id: Pipeline or API deployment ID
+ pipeline_name: Human readable name
+ execution_status: Current execution status
+ workflow_type: Type of workflow (ETL, API, etc.)
+ source: Source of the notification
+ execution_id: Optional execution ID
+ error_message: Optional error message for failed executions
+ organization_id: Optional organization context
+ additional_data: Optional additional metadata
+
+ Returns:
+ NotificationPayload instance
+ """
+ # Map execution status to notification status
+ if execution_status in [ExecutionStatus.COMPLETED]:
+ notification_status = NotificationStatus.COMPLETED
+ elif execution_status in [ExecutionStatus.ERROR]:
+ notification_status = NotificationStatus.ERROR
+ elif execution_status in [ExecutionStatus.STOPPED]:
+ notification_status = NotificationStatus.STOPPED
+ else:
+ # Don't send notifications for intermediate states like PENDING, EXECUTING
+ raise ValueError(
+ f"Cannot create notification for non-final status: {execution_status}"
+ )
+
+ return cls(
+ type=workflow_type,
+ pipeline_id=pipeline_id,
+ pipeline_name=pipeline_name,
+ status=notification_status,
+ execution_id=execution_id,
+ error_message=error_message,
+ organization_id=organization_id,
+ additional_data=additional_data or {},
+ _source=source,
+ )
+
+
+class ConnectionType(Enum):
+ """Connection types for workflow sources and destinations."""
+
+ FILESYSTEM = "FILESYSTEM"
+ API = "API"
+ API_DEPLOYMENT = "API_DEPLOYMENT"
+ DATABASE = "DATABASE"
+ QUEUE = "QUEUE"
+ MANUALREVIEW = "MANUALREVIEW"
+
+
+@dataclass
+class FileHashData:
+ """Shared data structure for file hash information and metadata.
+
+ This ensures consistency between backend and worker when handling file data,
+ providing clear separation between content hashing and filesystem identification.
+
+ FIELD USAGE PATTERNS:
+
+ file_hash (str):
+ - PURPOSE: SHA256 hash of actual file content for deduplication and integrity
+ - WHEN COMPUTED: During file processing when content is read
+ - EXAMPLES: "a7b2c4d5e6f7..." (64-char SHA256 hex)
+ - USED FOR: Content-based deduplication, cache keys, integrity verification
+
+ provider_file_uuid (Optional[str]):
+ - PURPOSE: Unique identifier assigned by storage provider (GCS, S3, etc.)
+ - WHEN COLLECTED: During file listing/metadata collection phase
+ - EXAMPLES: GCS generation ID, S3 ETag, file system inode
+ - USED FOR: Tracking files in external storage, detecting file changes
+
+ connector_metadata (Dict[str, Any]):
+ - PURPOSE: Connector credentials and configuration needed for file access
+ - WHEN COLLECTED: During source configuration processing
+ - EXAMPLES: GCS project_id, json_credentials; S3 access_key, secret_key
+ - USED FOR: File-processing worker to access source files
+
+ connector_id (Optional[str]):
+ - PURPOSE: Full connector ID from registry for file access
+ - WHEN COLLECTED: During source configuration processing
+ - EXAMPLES: "google_cloud_storage|109bbe7b-8861-45eb-8841-7244e833d97b"
+ - USED FOR: File-processing worker to instantiate correct connector
+
+ WORKFLOW PATTERNS:
+ 1. File Listing: provider_file_uuid collected from filesystem metadata
+ 2. File Processing: file_hash computed from actual content
+ 3. Deduplication: Both used for different purposes (content vs storage tracking)
+ 4. Caching: provider_file_uuid for quick existence checks, file_hash for content verification
+ 5. Worker Handoff: connector_metadata and connector_id for file access
+ """
+
+ file_name: str
+ file_path: str
+ file_hash: str = "" # SHA256 content hash - computed during file processing
+ file_size: int = 0
+ mime_type: str = ""
+ provider_file_uuid: str | None = (
+ None # Storage provider identifier - collected from metadata
+ )
+ fs_metadata: dict[str, Any] = field(default_factory=dict)
+ source_connection_type: str | None = None
+ file_destination: str | None = None
+ is_executed: bool = False
+ file_number: int | None = None
+ # New fields for connector metadata needed by file-processing workers
+ connector_metadata: dict[str, Any] = field(
+ default_factory=dict
+ ) # Connector credentials and settings
+ connector_id: str | None = None # Full connector ID from registry
+ use_file_history: bool = False # Whether to create file history entries for this file
+ is_manualreview_required: bool = False # Whether this file requires manual review
+ hitl_queue_name: str | None = None # HITL queue name for API deployments
+
+ def __post_init__(self):
+ """Validate required fields."""
+ if not self.file_name:
+ raise ValueError("file_name is required")
+ if not self.file_path:
+ raise ValueError("file_path is required")
+ # Don't validate file_hash here - it can be computed later
+
+ def compute_hash_from_content(self, content: bytes) -> str:
+ """Compute SHA256 hash from file content."""
+ import hashlib
+
+ hash_value = hashlib.sha256(content).hexdigest()
+ self.file_hash = hash_value
+ return hash_value
+
+ def compute_hash_from_file(self, file_path: str) -> str:
+ """Compute SHA256 hash from file path."""
+ import hashlib
+
+ with open(file_path, "rb") as f:
+ hash_value = hashlib.sha256(f.read()).hexdigest()
+ self.file_hash = hash_value
+ return hash_value
+
+ def compute_hash_from_provider_uuid(self) -> str:
+ """Use provider_file_uuid as hash if available (for cloud storage).
+
+ DEPRECATED: This method is deprecated. file_hash should only contain
+ SHA256 content hash, not provider_file_uuid.
+ """
+ if self.provider_file_uuid:
+ self.file_hash = self.provider_file_uuid
+ return self.provider_file_uuid
+ return ""
+
+ def ensure_hash(
+ self, content: bytes | None = None, file_path: str | None = None
+ ) -> str:
+ """Ensure file_hash is populated with SHA256 content hash only.
+
+ IMPORTANT: file_hash should ONLY contain SHA256 hash of actual file content.
+ It should NEVER contain provider_file_uuid or any other identifier.
+
+ USAGE PATTERN:
+ - Workers: Call during file processing when content is available
+ - Backend: Call when content hash is needed for deduplication/caching
+ - NOT for early metadata collection (use provider_file_uuid instead)
+
+ Args:
+ content: File content bytes (preferred - most accurate)
+ file_path: Local file path (fallback when content not available)
+
+ Returns:
+ SHA256 hex string of file content, or existing hash if already computed
+
+ Raises:
+ ValueError: If called without content or file_path when hash is missing
+ """
+ if self.file_hash:
+ return self.file_hash
+
+ # DESIGN FIX: Don't allow parameterless calls that can't compute hash
+ if not content and not file_path:
+ raise ValueError(
+ f"Cannot ensure hash for {self.file_name}: no content or file_path provided. "
+ f"Hash must be computed with actual file data."
+ )
+
+ # Only compute real content hash from file content or file path
+ if content:
+ return self.compute_hash_from_content(content)
+
+ # file_path is guaranteed to be truthy here (otherwise exception would have been raised)
+ return self.compute_hash_from_file(file_path)
+
+ def has_hash(self) -> bool:
+ """Check if file_hash is already populated without attempting to compute it.
+
+ Returns:
+ True if file_hash exists, False otherwise
+ """
+ return bool(self.file_hash)
+
+ def validate_for_api(self):
+ """Validate that all required fields are present for API calls.
+
+ VALIDATION RULES:
+ - file_name and file_path are always required
+ - Either file_hash OR provider_file_uuid must be present for database uniqueness
+
+ FAIL FAST BEHAVIOR:
+ If validation fails, raises ValueError immediately to ensure data integrity
+ and make metadata collection failures visible for debugging.
+ """
+ if not self.file_name:
+ raise ValueError("file_name is required")
+ if not self.file_path:
+ raise ValueError("file_path is required")
+ if not self.file_hash and not self.provider_file_uuid:
+ raise ValueError(
+ "Either file_hash or provider_file_uuid is required. "
+ "Check metadata collection process for failures."
+ )
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary with proper serialization of complex data types."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FileHashData":
+ """Create from dictionary and automatically compute hash if missing."""
+ instance = cls(
+ file_name=data.get("file_name", ""),
+ file_path=data.get("file_path", ""),
+ file_hash=data.get("file_hash", ""),
+ file_size=data.get("file_size", 0),
+ mime_type=data.get("mime_type", ""),
+ provider_file_uuid=data.get("provider_file_uuid"),
+ fs_metadata=data.get("fs_metadata", {}),
+ source_connection_type=data.get("source_connection_type"),
+ file_destination=data.get("file_destination"),
+ is_executed=data.get("is_executed", False),
+ file_number=data.get("file_number"),
+ connector_metadata=data.get("connector_metadata", {}),
+ connector_id=data.get("connector_id"),
+ use_file_history=data.get("use_file_history", False),
+ hitl_queue_name=data.get("hitl_queue_name"),
+ is_manualreview_required=data.get("is_manualreview_required", False),
+ )
+
+ # If no hash is provided, leave it empty - hash computation requires content or file_path
+ # The calling code should provide the hash or call ensure_hash() with proper parameters
+ if not instance.file_hash:
+ logger.debug(
+ f"FileHashData.from_dict: No file_hash provided for {instance.file_name} - leaving empty"
+ )
+
+ return instance
+
+ def to_json(self) -> dict[str, Any]:
+ """Convert to JSON-compatible dictionary for compatibility with FileHash interface."""
+ return self.to_dict()
+
+ def to_serialized_json(self) -> str:
+ """Serialize the FileHashData instance to a JSON string for compatibility with FileHash interface."""
+ import json
+
+ return json.dumps(self.to_dict())
+
+ @staticmethod
+ def from_json(json_str_or_dict: Any) -> "FileHashData":
+ """Deserialize a JSON string or dictionary to a FileHashData instance for compatibility with FileHash interface."""
+ import json
+
+ if isinstance(json_str_or_dict, dict):
+ # If already a dictionary, assume it's in the right format
+ data = json_str_or_dict
+ else:
+ # Otherwise, assume it's a JSON string
+ data = json.loads(json_str_or_dict)
+ return FileHashData.from_dict(data)
+
+
+@dataclass
+class WorkflowFileExecutionData:
+ """Shared data structure for workflow file execution.
+
+ This matches the WorkflowFileExecution model in the backend and provides
+ type safety for API communication between services.
+ """
+
+ id: str | uuid.UUID
+ workflow_execution_id: str | uuid.UUID
+ file_name: str
+ file_path: str
+ file_size: int
+ file_hash: str
+ status: str = ExecutionStatus.PENDING.value
+ provider_file_uuid: str | None = None
+ mime_type: str = ""
+ fs_metadata: dict[str, Any] = field(default_factory=dict)
+ execution_error: str | None = None
+ created_at: datetime | None = None
+ modified_at: datetime | None = None
+
+ def __post_init__(self):
+ """Validate and normalize fields."""
+ # Convert UUIDs to strings for serialization
+ if isinstance(self.id, uuid.UUID):
+ self.id = str(self.id)
+ if isinstance(self.workflow_execution_id, uuid.UUID):
+ self.workflow_execution_id = str(self.workflow_execution_id)
+
+ # Validate required fields
+ if not self.file_name:
+ raise ValueError("file_name is required")
+ if not self.file_path:
+ raise ValueError("file_path is required")
+ # file_hash can be empty initially - gets populated during file processing with SHA256 hash
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ data = asdict(self)
+ # Convert datetime objects to ISO strings
+ if self.created_at:
+ data["created_at"] = self.created_at.isoformat()
+ if self.modified_at:
+ data["modified_at"] = self.modified_at.isoformat()
+ return {k: v for k, v in data.items() if v is not None}
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowFileExecutionData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ id=data["id"],
+ workflow_execution_id=data["workflow_execution_id"],
+ file_name=data["file_name"],
+ file_path=data["file_path"],
+ file_size=data.get("file_size", 0),
+ file_hash=data["file_hash"],
+ status=data.get("status", ExecutionStatus.PENDING.value),
+ provider_file_uuid=data.get("provider_file_uuid"),
+ mime_type=data.get("mime_type", ""),
+ fs_metadata=data.get("fs_metadata", {}),
+ execution_error=data.get("execution_error"),
+ created_at=data.get("created_at"),
+ modified_at=data.get("modified_at"),
+ )
+
+ def update_status(self, status: str, error_message: str | None = None):
+ """Update status and error message."""
+ self.status = status
+ if error_message:
+ self.execution_error = error_message
+ self.modified_at = datetime.now()
+
+
+@dataclass
+class TagData:
+ """Shared data structure for tag information.
+
+ This matches the Tag model in the backend and provides
+ type safety for tag operations across services.
+ """
+
+ id: str | uuid.UUID
+ name: str
+ description: str | None = None
+
+ def __post_init__(self):
+ """Validate and normalize fields."""
+ # Convert UUID to string for serialization
+ if isinstance(self.id, uuid.UUID):
+ self.id = str(self.id)
+
+ # Validate tag name
+ if not self.name:
+ raise ValueError("Tag name is required")
+ if len(self.name) > 50: # Match backend TAG_NAME_LENGTH
+ raise ValueError("Tag name cannot exceed 50 characters")
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return {
+ "id": str(self.id),
+ "name": self.name,
+ "description": self.description,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "TagData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ id=data.get("id", str(uuid.uuid4())), # Generate ID if not provided
+ name=data.get("name", ""),
+ description=data.get("description"),
+ )
+
+ @classmethod
+ def from_name(cls, name: str) -> "TagData":
+ """Create tag from just a name (for backward compatibility)."""
+ return cls(
+ id=str(uuid.uuid4()),
+ name=name,
+ description=None,
+ )
+
+
+@dataclass
+class WorkflowExecutionData:
+ """Shared data structure for workflow execution.
+
+ This matches the WorkflowExecution model in the backend.
+ """
+
+ id: str | uuid.UUID
+ workflow_id: str | uuid.UUID
+ workflow_name: str | None = None
+ pipeline_id: str | uuid.UUID | None = None
+ task_id: str | None = None
+ execution_mode: str = "SYNC"
+ execution_method: str = "API"
+ execution_type: str = "FILE"
+ execution_log_id: str | None = None
+ status: str = ExecutionStatus.PENDING.value
+ result_acknowledged: bool = False
+ total_files: int = 0
+ error_message: str | None = None
+ attempts: int = 0
+ execution_time: float | None = None
+ created_at: datetime | None = None
+ modified_at: datetime | None = None
+ tags: list[TagData] = field(default_factory=list)
+
+ def __post_init__(self):
+ """Validate and normalize fields."""
+ # Convert UUIDs to strings for serialization
+ if isinstance(self.id, uuid.UUID):
+ self.id = str(self.id)
+ if isinstance(self.workflow_id, uuid.UUID):
+ self.workflow_id = str(self.workflow_id)
+ if isinstance(self.pipeline_id, uuid.UUID):
+ self.pipeline_id = str(self.pipeline_id)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ data = asdict(self)
+ # Convert datetime objects to ISO strings
+ if self.created_at:
+ data["created_at"] = self.created_at.isoformat()
+ if self.modified_at:
+ data["modified_at"] = self.modified_at.isoformat()
+ # Convert tags to dictionaries
+ if self.tags:
+ data["tags"] = [tag.to_dict() for tag in self.tags]
+ return {k: v for k, v in data.items() if v is not None}
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowExecutionData":
+ """Create from dictionary (e.g., API response)."""
+ # Handle tags - support both dict format and string format for backward compatibility
+ tags_data = data.get("tags", [])
+ tags = []
+ for tag in tags_data:
+ if isinstance(tag, dict):
+ tags.append(TagData.from_dict(tag))
+ elif isinstance(tag, str):
+ # Support simple tag names for backward compatibility
+ tags.append(TagData.from_name(tag))
+
+ return cls(
+ id=data["id"],
+ workflow_id=data["workflow_id"],
+ workflow_name=data.get("workflow_name"),
+ pipeline_id=data.get("pipeline_id"),
+ task_id=data.get("task_id"),
+ execution_mode=data.get("execution_mode", "SYNC"),
+ execution_method=data.get("execution_method", "API"),
+ execution_type=data.get("execution_type", "FILE"),
+ execution_log_id=data.get("execution_log_id"),
+ status=data.get("status", ExecutionStatus.PENDING.value),
+ result_acknowledged=data.get("result_acknowledged", False),
+ total_files=data.get("total_files", 0),
+ error_message=data.get("error_message"),
+ attempts=data.get("attempts", 0),
+ execution_time=data.get("execution_time"),
+ created_at=data.get("created_at"),
+ modified_at=data.get("modified_at"),
+ tags=tags,
+ )
+
+
+# Log Processing Data Models
+
+
+@dataclass
+class LogDataDTO:
+ """Log data DTO for storing execution logs to queue.
+
+ Shared between backend and workers for consistent log processing.
+
+ Attributes:
+ execution_id: execution id
+ organization_id: organization id
+ timestamp: timestamp
+ log_type: log type
+ data: log data
+ file_execution_id: Id for the file execution
+ """
+
+ execution_id: str
+ organization_id: str
+ timestamp: int
+ log_type: str
+ data: dict[str, Any]
+ file_execution_id: str | None = None
+
+ def __post_init__(self):
+ """Post-initialization to compute event_time from timestamp."""
+ self.event_time: datetime = datetime.fromtimestamp(self.timestamp, UTC)
+
+ @classmethod
+ def from_json(cls, json_data: str) -> "LogDataDTO | None":
+ """Create LogDataDTO from JSON string."""
+ try:
+ from unstract.core.constants import LogFieldName
+
+ json_obj = json.loads(json_data)
+ execution_id = json_obj.get(LogFieldName.EXECUTION_ID)
+ file_execution_id = json_obj.get(LogFieldName.FILE_EXECUTION_ID)
+ organization_id = json_obj.get(LogFieldName.ORGANIZATION_ID)
+ timestamp = json_obj.get(LogFieldName.TIMESTAMP)
+ log_type = json_obj.get(LogFieldName.TYPE)
+ data = json_obj.get(LogFieldName.DATA)
+
+ if all((execution_id, organization_id, timestamp, log_type, data)):
+ return cls(
+ execution_id=execution_id,
+ file_execution_id=file_execution_id,
+ organization_id=organization_id,
+ timestamp=timestamp,
+ log_type=log_type,
+ data=data,
+ )
+ except (json.JSONDecodeError, AttributeError):
+ logger.warning("Invalid log data: %s", json_data)
+ return None
+
+ def to_json(self) -> str:
+ """Convert LogDataDTO to JSON string."""
+ from unstract.core.constants import LogFieldName
+
+ return json.dumps(
+ {
+ LogFieldName.EXECUTION_ID: self.execution_id,
+ LogFieldName.ORGANIZATION_ID: self.organization_id,
+ LogFieldName.TIMESTAMP: self.timestamp,
+ LogFieldName.EVENT_TIME: self.event_time.isoformat(),
+ LogFieldName.TYPE: self.log_type,
+ LogFieldName.DATA: self.data,
+ LogFieldName.FILE_EXECUTION_ID: self.file_execution_id,
+ }
+ )
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return serialize_dataclass_to_dict(self)
+
+
+# Request/Response dataclasses for API operations
+
+
+@dataclass
+class FileExecutionCreateRequest:
+ """Request data for creating a workflow file execution."""
+
+ execution_id: str | uuid.UUID
+ file_hash: FileHashData
+ workflow_id: str | uuid.UUID
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ return {
+ "execution_id": str(self.execution_id),
+ "file_hash": self.file_hash.to_dict(),
+ "workflow_id": str(self.workflow_id),
+ }
+
+
+@dataclass
+class FileExecutionStatusUpdateRequest:
+ """Request data for updating file execution status."""
+
+ status: str
+ error_message: str | None = None
+ result: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ data = {"status": self.status}
+ if self.error_message:
+ data["error_message"] = self.error_message
+ if self.result:
+ data["result"] = self.result
+ return data
+
+
+@dataclass
+class FileHistoryData:
+ id: str | uuid.UUID
+ workflow_id: str | uuid.UUID
+ cache_key: str
+ provider_file_uuid: str | None = None
+ status: str = ExecutionStatus.PENDING.value
+ result: str | None = None
+ metadata: str | None = None
+ error: str | None = None
+ file_path: str | None = None
+ created_at: datetime | None = None
+ modified_at: datetime | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ data = asdict(self)
+ # Convert datetime objects to ISO strings
+ if self.created_at:
+ data["created_at"] = self.created_at.isoformat()
+ if self.modified_at:
+ data["modified_at"] = self.modified_at.isoformat()
+ return {k: v for k, v in data.items() if v is not None}
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FileHistoryData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ id=data.get("id"),
+ workflow_id=data.get("workflow_id"),
+ cache_key=data.get("cache_key"),
+ provider_file_uuid=data.get("provider_file_uuid"),
+ status=data.get("status", ExecutionStatus.PENDING.value),
+ result=data.get("result"),
+ metadata=data.get("metadata"),
+ error=data.get("error"),
+ file_path=data.get("file_path"),
+ created_at=data.get("created_at"),
+ modified_at=data.get("modified_at"),
+ )
+
+
+@dataclass
+class FileHistoryCreateRequest:
+ """Request data for creating a file history record."""
+
+ status: str
+ workflow_id: str | uuid.UUID
+ file_history: FileHistoryData
+ message: str
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ return {
+ "status": self.status,
+ "workflow_id": str(self.workflow_id),
+ "file_history": self.file_history.to_dict(),
+ "message": self.message,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FileHistoryCreateRequest":
+ """Create from dictionary (e.g., API request)."""
+ return cls(
+ status=data.get("status"),
+ workflow_id=data.get("workflow_id"),
+ file_history=FileHistoryData.from_dict(data.get("file_history")),
+ message=data.get("message"),
+ )
+
+
+# File Processing Batch Dataclasses
+# Moved from backend workflow_manager/workflow_v2/dto.py for shared usage
+
+
+@dataclass
+class SourceConfig:
+ """Configuration for workflow data sources."""
+
+ connection_type: ConnectionType
+ settings: dict[str, Any] = field(default_factory=dict)
+ connector_id: str | None = None
+ connector_metadata: dict[str, Any] = field(default_factory=dict)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary with string enum values."""
+ return {
+ "connection_type": self.connection_type.value,
+ "settings": self.settings,
+ "connector_id": self.connector_id,
+ "connector_metadata": self.connector_metadata,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "SourceConfig":
+ """Create from dictionary with string connection type."""
+ connection_type_str = data.get("connection_type", "FILESYSTEM")
+ try:
+ connection_type = ConnectionType(connection_type_str)
+ except ValueError:
+ logger.warning(
+ f"Unknown connection type: {connection_type_str}, defaulting to FILESYSTEM"
+ )
+ connection_type = ConnectionType.FILESYSTEM
+
+ return cls(
+ connection_type=connection_type,
+ settings=data.get("settings", {}),
+ connector_id=data.get("connector_id"),
+ connector_metadata=data.get("connector_metadata", {}),
+ )
+
+
+@dataclass
+class DestinationConfig:
+ """Configuration for workflow data destinations."""
+
+ connection_type: ConnectionType
+ settings: dict[str, Any] = field(default_factory=dict)
+ connector_id: str | None = None
+ connector_metadata: dict[str, Any] = field(default_factory=dict)
+ is_api: bool = False
+ use_file_history: bool = True
+ # Additional fields for worker compatibility
+ connector_settings: dict[str, Any] = field(default_factory=dict)
+ connector_name: str | None = None
+ # Source connector fields for manual review and file reading
+ source_connector_id: str | None = None
+ source_connector_settings: dict[str, Any] = field(default_factory=dict)
+ # HITL queue name for API deployments
+ hitl_queue_name: str | None = None
+
+ def __post_init__(self):
+ """Post-initialization to handle automatic API detection."""
+ # Enforce type safety - connection_type must be ConnectionType enum
+ if not isinstance(self.connection_type, ConnectionType):
+ raise TypeError(
+ f"connection_type must be ConnectionType enum, got {type(self.connection_type).__name__}: {self.connection_type}"
+ )
+
+ # Determine if this is an API destination based on connection type
+ if self.connection_type and "api" in self.connection_type.value.lower():
+ self.is_api = True
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary with string enum values."""
+ return {
+ "connection_type": self.connection_type.value,
+ "settings": self.settings,
+ "connector_id": self.connector_id,
+ "connector_metadata": self.connector_metadata,
+ "is_api": self.is_api,
+ "use_file_history": self.use_file_history,
+ "connector_settings": self.connector_settings,
+ "connector_name": self.connector_name,
+ "source_connector_id": self.source_connector_id,
+ "source_connector_settings": self.source_connector_settings,
+ "hitl_queue_name": self.hitl_queue_name,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "DestinationConfig":
+ """Create from dictionary with string connection type."""
+ connection_type_str = data.get("connection_type", "FILESYSTEM")
+ try:
+ connection_type = ConnectionType(connection_type_str)
+ except ValueError:
+ logger.warning(
+ f"Unknown connection type: {connection_type_str}, defaulting to FILESYSTEM"
+ )
+ connection_type = ConnectionType.FILESYSTEM
+
+ return cls(
+ connection_type=connection_type,
+ settings=data.get("settings", {}),
+ connector_id=data.get("connector_id"),
+ connector_metadata=data.get("connector_metadata", {}),
+ is_api=data.get("is_api", False),
+ use_file_history=data.get("use_file_history", True),
+ connector_settings=data.get("connector_settings", {}),
+ connector_name=data.get("connector_name"),
+ source_connector_id=data.get("source_connector_id"),
+ source_connector_settings=data.get("source_connector_settings", {}),
+ hitl_queue_name=data.get("hitl_queue_name"),
+ )
+
+
+@dataclass
+class PreCreatedFileData:
+ id: str
+ object: WorkflowFileExecutionData
+ file_hash: FileHashData
+
+
+@dataclass
+class WorkerFileData:
+ """Shared data structure for worker file processing context."""
+
+ workflow_id: str
+ execution_id: str
+ single_step: bool
+ organization_id: str
+ pipeline_id: str
+ scheduled: bool
+ execution_mode: str
+ use_file_history: bool
+ q_file_no_list: list[int]
+ source_config: dict[str, Any] = field(default_factory=dict)
+ destination_config: dict[str, Any] = field(default_factory=dict)
+ hitl_queue_name: str | None = field(default=None)
+ manual_review_config: dict[str, Any] = field(
+ default_factory=lambda: {
+ "review_required": False,
+ "review_percentage": 0,
+ "rule_logic": None,
+ "rule_json": None,
+ "file_decisions": [], # Pre-calculated boolean decisions for each file
+ }
+ )
+ is_manualreview_required: bool = field(default=False)
+ llm_profile_id: str | None = field(default=None)
+ tags: list[TagData] = field(default_factory=list)
+ custom_data: dict[str, Any] | None = field(default=None)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkerFileData":
+ """Create from dictionary (e.g., API request).
+
+ INPUT VALIDATION:
+ - data: Must be dictionary with required fields
+
+ VALIDATION ERRORS:
+ - TypeError: Input is not a dictionary
+ - ValueError: Missing required fields or invalid field values
+ """
+ if not isinstance(data, dict):
+ raise TypeError(
+ f"WorkerFileData requires dictionary input, got {type(data).__name__}"
+ )
+
+ # Enhanced required field validation
+ required_fields = ["workflow_id", "execution_id", "organization_id"]
+ missing_fields = [
+ field for field in required_fields if field not in data or not data[field]
+ ]
+ if missing_fields:
+ raise ValueError(
+ f"WorkerFileData missing or empty required fields: {missing_fields}. "
+ f"Provided fields: {list(data.keys())}"
+ )
+
+ # Extract only fields that match this dataclass
+ from dataclasses import fields
+
+ field_names = {f.name for f in fields(cls)}
+ filtered_data = {k: v for k, v in data.items() if k in field_names}
+
+ # Provide defaults for optional fields with validation
+ filtered_data.setdefault("single_step", False)
+ filtered_data.setdefault("scheduled", False)
+ filtered_data.setdefault("execution_mode", "SYNC")
+ filtered_data.setdefault("use_file_history", True)
+ filtered_data.setdefault("q_file_no_list", [])
+ filtered_data.setdefault("pipeline_id", "")
+
+ # Validate field types
+ if not isinstance(filtered_data.get("single_step"), bool):
+ raise TypeError(
+ f"single_step must be boolean, got {type(filtered_data.get('single_step')).__name__}"
+ )
+ if not isinstance(filtered_data.get("scheduled"), bool):
+ raise TypeError(
+ f"scheduled must be boolean, got {type(filtered_data.get('scheduled')).__name__}"
+ )
+ if not isinstance(filtered_data.get("use_file_history"), bool):
+ raise TypeError(
+ f"use_file_history must be boolean, got {type(filtered_data.get('use_file_history')).__name__}"
+ )
+ if not isinstance(filtered_data.get("q_file_no_list"), list):
+ raise TypeError(
+ f"q_file_no_list must be list, got {type(filtered_data.get('q_file_no_list')).__name__}"
+ )
+
+ # Handle tags field - support both dict format and string format
+ tags_data = filtered_data.get("tags", [])
+ tags = []
+ for tag in tags_data:
+ if isinstance(tag, dict):
+ tags.append(TagData.from_dict(tag))
+ elif isinstance(tag, str):
+ # Support simple tag names for backward compatibility
+ tags.append(TagData.from_name(tag))
+ filtered_data["tags"] = tags
+
+ try:
+ return cls(**filtered_data)
+ except TypeError as e:
+ raise ValueError(
+ f"Failed to create WorkerFileData: {str(e)}. Check field types and values."
+ ) from e
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ data = asdict(self)
+ # Convert tags to dictionaries
+ if self.tags:
+ data["tags"] = [tag.to_dict() for tag in self.tags]
+ return data
+
+
+@dataclass
+class FileBatchData:
+ """Shared data structure for file batch processing requests."""
+
+ files: list[dict[str, Any]] # List of file dictionaries
+ file_data: WorkerFileData
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FileBatchData":
+ """Create from dictionary (e.g., Celery task data).
+
+ INPUT VALIDATION:
+ - data: Must be dictionary with 'files' list and 'file_data' dict
+
+ VALIDATION ERRORS:
+ - TypeError: Input is not a dictionary or has wrong field types
+ - ValueError: Missing required fields or invalid field structure
+ """
+ if not isinstance(data, dict):
+ raise TypeError(
+ f"FileBatchData requires dictionary input, got {type(data).__name__}"
+ )
+
+ # Enhanced field validation
+ required_fields = ["file_data", "files"]
+ missing_fields = [field for field in required_fields if field not in data]
+ if missing_fields:
+ raise ValueError(
+ f"FileBatchData missing required fields: {missing_fields}. "
+ f"Provided fields: {list(data.keys())}"
+ )
+
+ if not isinstance(data["files"], list):
+ raise TypeError(
+ f"FileBatchData 'files' must be a list, got {type(data['files']).__name__}"
+ )
+
+ # Validate files list structure - Django sends lists due to asdict() serialization
+ for i, file_item in enumerate(data["files"]):
+ if isinstance(file_item, list):
+ # Django backend format after asdict(): [["file_name", file_hash_dict], ...]
+ if len(file_item) != 2:
+ raise ValueError(
+ f"FileBatchData 'files[{i}]' list must have exactly 2 elements [file_name, file_hash_dict], got {len(file_item)}"
+ )
+ file_name, file_hash_dict = file_item
+ if not isinstance(file_name, str):
+ raise TypeError(
+ f"FileBatchData 'files[{i}][0]' (file_name) must be string, got {type(file_name).__name__}"
+ )
+ if not isinstance(file_hash_dict, dict):
+ raise TypeError(
+ f"FileBatchData 'files[{i}][1]' (file_hash_dict) must be dictionary, got {type(file_hash_dict).__name__}"
+ )
+ elif isinstance(file_item, tuple):
+ # Legacy tuple format: [(file_name, file_hash_dict), ...]
+ if len(file_item) != 2:
+ raise ValueError(
+ f"FileBatchData 'files[{i}]' tuple must have exactly 2 elements (file_name, file_hash_dict), got {len(file_item)}"
+ )
+ file_name, file_hash_dict = file_item
+ if not isinstance(file_name, str):
+ raise TypeError(
+ f"FileBatchData 'files[{i}][0]' (file_name) must be string, got {type(file_name).__name__}"
+ )
+ if not isinstance(file_hash_dict, dict):
+ raise TypeError(
+ f"FileBatchData 'files[{i}][1]' (file_hash_dict) must be dictionary, got {type(file_hash_dict).__name__}"
+ )
+ elif isinstance(file_item, dict):
+ # Alternative dictionary format: [{"file_name": "...", "file_path": "..."}, ...]
+ required_file_fields = ["file_name", "file_path"]
+ missing_file_fields = [
+ field for field in required_file_fields if field not in file_item
+ ]
+ if missing_file_fields:
+ raise ValueError(
+ f"FileBatchData 'files[{i}]' missing required fields: {missing_file_fields}"
+ )
+ else:
+ raise TypeError(
+ f"FileBatchData 'files[{i}]' must be a list [file_name, file_hash_dict], tuple (file_name, file_hash_dict), or dictionary, got {type(file_item).__name__}"
+ )
+
+ try:
+ file_data = WorkerFileData.from_dict(data["file_data"])
+ except Exception as e:
+ raise ValueError(
+ f"Failed to create WorkerFileData from file_data field: {str(e)}"
+ ) from e
+
+ return cls(files=data["files"], file_data=file_data)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for serialization."""
+ return asdict(self)
+
+
+@dataclass
+class FileBatchResult:
+ """Shared data structure for file batch processing results."""
+
+ successful_files: int = 0
+ failed_files: int = 0
+ execution_time: float = 0.0 # Total execution time for all files in batch
+
+ @property
+ def total_files(self) -> int:
+ """Total number of files processed."""
+ return self.successful_files + self.failed_files
+
+ def to_dict(self) -> dict[str, int | float]:
+ """Convert to dictionary for API response."""
+ return {
+ "successful_files": self.successful_files,
+ "failed_files": self.failed_files,
+ "total_files": self.total_files, # Include calculated total_files property
+ "execution_time": self.execution_time, # Include batch execution time
+ }
+
+ def increment_success(self):
+ """Increment successful file count."""
+ self.successful_files += 1
+
+ def increment_failure(self):
+ """Increment failed file count."""
+ self.failed_files += 1
+
+ def add_execution_time(self, time_seconds: float):
+ """Add execution time for a file to the batch total."""
+ self.execution_time += time_seconds
+
+
+# Workflow Definition and Endpoint Dataclasses
+# Added to support proper serialization of backend workflow definitions
+
+
+@dataclass
+class ConnectorInstanceData:
+ """Shared data structure for connector instance information."""
+
+ connector_id: str
+ connector_name: str = ""
+ connector_metadata: dict[str, Any] = field(default_factory=dict)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return asdict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "ConnectorInstanceData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ connector_id=data.get("connector_id", ""),
+ connector_name=data.get("connector_name", ""),
+ connector_metadata=data.get("connector_metadata", {}),
+ )
+
+
+@dataclass
+class WorkflowEndpointConfigData:
+ """Shared data structure for workflow endpoint configuration."""
+
+ endpoint_id: str
+ endpoint_type: str # SOURCE or DESTINATION
+ connection_type: str # FILESYSTEM, DATABASE, API, etc.
+ configuration: dict[str, Any] = field(default_factory=dict)
+ connector_instance: ConnectorInstanceData | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ data = {
+ "endpoint_id": self.endpoint_id,
+ "endpoint_type": self.endpoint_type,
+ "connection_type": self.connection_type,
+ "configuration": self.configuration,
+ }
+ if self.connector_instance:
+ data["connector_instance"] = self.connector_instance.to_dict()
+ return data
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowEndpointConfigData":
+ """Create from dictionary (e.g., API response)."""
+ connector_instance = None
+ if data.get("connector_instance"):
+ connector_instance = ConnectorInstanceData.from_dict(
+ data["connector_instance"]
+ )
+
+ return cls(
+ endpoint_id=data.get("endpoint_id", ""),
+ endpoint_type=data.get("endpoint_type", ""),
+ connection_type=data.get("connection_type", ""),
+ configuration=data.get("configuration", {}),
+ connector_instance=connector_instance,
+ )
+
+
+@dataclass
+class WorkflowTypeDetectionData:
+ """Shared data structure for workflow type detection results."""
+
+ workflow_type: str # ETL, TASK, API, APP, DEFAULT
+ source_model: str # 'pipeline' or 'api_deployment' or 'workflow_fallback'
+ pipeline_id: str | None = None
+ api_deployment_id: str | None = None
+ is_api_workflow: bool = False
+ is_pipeline_workflow: bool = False
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return asdict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowTypeDetectionData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ workflow_type=data.get("workflow_type", "DEFAULT"),
+ source_model=data.get("source_model", "workflow_fallback"),
+ pipeline_id=data.get("pipeline_id"),
+ api_deployment_id=data.get("api_deployment_id"),
+ is_api_workflow=data.get("is_api_workflow", False),
+ is_pipeline_workflow=data.get("is_pipeline_workflow", False),
+ )
+
+
+@dataclass
+class WorkflowEndpointConfigResponseData:
+ """Shared data structure for workflow endpoint configuration API responses."""
+
+ workflow_id: str
+ source_endpoint: WorkflowEndpointConfigData | None = None
+ destination_endpoint: WorkflowEndpointConfigData | None = None
+ has_api_endpoints: bool = False
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "workflow_id": self.workflow_id,
+ "source_endpoint": self.source_endpoint.to_dict()
+ if self.source_endpoint
+ else None,
+ "destination_endpoint": self.destination_endpoint.to_dict()
+ if self.destination_endpoint
+ else None,
+ "has_api_endpoints": self.has_api_endpoints,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowEndpointConfigResponseData":
+ return cls(
+ workflow_id=data["workflow_id"],
+ source_endpoint=WorkflowEndpointConfigData.from_dict(data["source_endpoint"])
+ if data["source_endpoint"]
+ else None,
+ destination_endpoint=WorkflowEndpointConfigData.from_dict(
+ data["destination_endpoint"]
+ )
+ if data["destination_endpoint"]
+ else None,
+ has_api_endpoints=data["has_api_endpoints"],
+ )
+
+
+@dataclass
+class WorkflowDefinitionResponseData:
+ """Shared data structure for complete workflow definition API responses.
+
+ This ensures consistent serialization between backend and workers for workflow definitions.
+ """
+
+ workflow_id: str
+ workflow_name: str
+ source_config: WorkflowEndpointConfigData
+ destination_config: WorkflowEndpointConfigData
+ organization_id: str
+ workflow_type: WorkflowType = WorkflowType.DEFAULT
+ created_at: str | None = None
+ modified_at: str | None = None
+ is_active: bool = True
+
+ def __post_init__(self):
+ source_connection_type = self.source_config.connection_type
+ destination_connection_type = self.destination_config.connection_type
+ if (
+ source_connection_type == ConnectionType.FILESYSTEM.value
+ and destination_connection_type == ConnectionType.FILESYSTEM.value
+ ):
+ self.workflow_type = WorkflowType.TASK
+ elif (
+ source_connection_type == ConnectionType.FILESYSTEM.value
+ and destination_connection_type == ConnectionType.DATABASE.value
+ ):
+ self.workflow_type = WorkflowType.ETL
+ elif (
+ source_connection_type == ConnectionType.API.value
+ and destination_connection_type == ConnectionType.API.value
+ ):
+ self.workflow_type = WorkflowType.API
+ elif (
+ source_connection_type == ConnectionType.FILESYSTEM.value
+ and destination_connection_type == ConnectionType.MANUALREVIEW.value
+ ):
+ self.workflow_type = WorkflowType.DEFAULT
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return {
+ "id": self.workflow_id, # Match worker expectations for 'id' field
+ "workflow_id": self.workflow_id,
+ "workflow_name": self.workflow_name,
+ "workflow_type": self.workflow_type.value, # For backward compatibility
+ # "workflow_type_detection": self.workflow_type_detection.to_dict(),
+ "source_config": self.source_config.to_dict(),
+ "destination_config": self.destination_config.to_dict(),
+ "organization_id": self.organization_id,
+ "created_at": self.created_at,
+ "modified_at": self.modified_at,
+ "is_active": self.is_active,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowDefinitionResponseData":
+ """Create from dictionary (e.g., API response)."""
+ # Handle source_config field
+ source_config_data = data.get("source_config", {})
+ if isinstance(source_config_data, dict) and source_config_data:
+ source_config = WorkflowEndpointConfigData.from_dict(source_config_data)
+ else:
+ # Empty source config for workflows without source endpoints
+ source_config = WorkflowEndpointConfigData(
+ endpoint_id="", endpoint_type="SOURCE", connection_type="NONE"
+ )
+
+ # Handle destination_config field
+ destination_config_data = data.get("destination_config", {})
+ if isinstance(destination_config_data, dict) and destination_config_data:
+ destination_config = WorkflowEndpointConfigData.from_dict(
+ destination_config_data
+ )
+ else:
+ # Empty destination config for workflows without destination endpoints
+ destination_config = WorkflowEndpointConfigData(
+ endpoint_id="", endpoint_type="DESTINATION", connection_type="NONE"
+ )
+
+ return cls(
+ workflow_id=data.get("workflow_id") or data.get("id", ""),
+ workflow_name=data.get("workflow_name", ""),
+ workflow_type=data.get("workflow_type", "DEFAULT"),
+ source_config=source_config,
+ destination_config=destination_config,
+ organization_id=data.get("organization_id", ""),
+ created_at=data.get("created_at"),
+ modified_at=data.get("modified_at"),
+ is_active=data.get("is_active", True),
+ )
+
+
+# Legacy compatibility function for workers expecting old format
+def workflow_definition_to_legacy_format(
+ workflow_def: WorkflowDefinitionResponseData,
+) -> dict[str, Any]:
+ """Convert WorkflowDefinitionResponseData to legacy format expected by existing workers.
+
+ This ensures backward compatibility during the transition period.
+ """
+ legacy_format = workflow_def.to_dict()
+
+ # Legacy workers expect these specific field mappings
+ legacy_format["id"] = workflow_def.workflow_id
+ legacy_format["workflow_type"] = workflow_def.workflow_type_detection.workflow_type
+
+ # Simplify config structures for legacy workers
+ if workflow_def.source_config.connection_type != "NONE":
+ legacy_format["source_config"] = {
+ "connection_type": workflow_def.source_config.connection_type,
+ "settings": workflow_def.source_config.configuration,
+ "connector_id": workflow_def.source_config.connector_instance.connector_id
+ if workflow_def.source_config.connector_instance
+ else None,
+ }
+ else:
+ legacy_format["source_config"] = {}
+
+ if workflow_def.destination_config.connection_type != "NONE":
+ legacy_format["destination_config"] = {
+ "connection_type": workflow_def.destination_config.connection_type,
+ "settings": workflow_def.destination_config.configuration,
+ "connector_id": workflow_def.destination_config.connector_instance.connector_id
+ if workflow_def.destination_config.connector_instance
+ else None,
+ }
+ else:
+ legacy_format["destination_config"] = {}
+
+ return legacy_format
+
+
+# Source Connector Configuration Data Models
+# These models bridge the gap between backend source.py logic and worker operations
+
+
+@dataclass
+class SourceConnectorConfigData:
+ """Shared data structure for source connector configuration.
+
+ This separates connector metadata (credentials, root path) from endpoint
+ configuration (folders, patterns, limits) to match backend source.py logic.
+ """
+
+ connector_id: str
+ connector_metadata: dict[str, Any] = field(
+ default_factory=dict
+ ) # Credentials, root_path
+ endpoint_configuration: dict[str, Any] = field(
+ default_factory=dict
+ ) # Folders, patterns, limits
+ connection_type: str = ""
+
+ def get_root_dir_path(self) -> str:
+ """Extract root directory path from connector metadata."""
+ return self.connector_metadata.get("path", "")
+
+ def get_folders_to_process(self) -> list[str]:
+ """Extract folders to process from endpoint configuration."""
+ folders = self.endpoint_configuration.get("folders", ["/"])
+ return list(folders) if folders else ["/"]
+
+ def get_file_extensions(self) -> list[str]:
+ """Extract file extensions from endpoint configuration."""
+ return list(self.endpoint_configuration.get("fileExtensions", []))
+
+ def get_max_files(self) -> int:
+ """Extract max files limit from endpoint configuration."""
+ return int(self.endpoint_configuration.get("maxFiles", 1000))
+
+ def is_recursive(self) -> bool:
+ """Check if subdirectory processing is enabled."""
+ return bool(self.endpoint_configuration.get("processSubDirectories", False))
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return asdict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "SourceConnectorConfigData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ connector_id=data.get("connector_id", ""),
+ connector_metadata=data.get("connector_metadata", {}),
+ endpoint_configuration=data.get("endpoint_configuration", {}),
+ connection_type=data.get("connection_type", ""),
+ )
+
+
+@dataclass
+class DirectoryValidationData:
+ """Shared data structure for directory validation results.
+
+ Handles directory path transformation and validation results for
+ consistent processing between backend and workers.
+ """
+
+ original_path: str
+ transformed_path: str
+ is_valid: bool
+ error_message: str = ""
+ validation_method: str = "" # 'metadata', 'filesystem', 'fallback'
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return asdict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "DirectoryValidationData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ original_path=data.get("original_path", ""),
+ transformed_path=data.get("transformed_path", ""),
+ is_valid=data.get("is_valid", False),
+ error_message=data.get("error_message", ""),
+ validation_method=data.get("validation_method", ""),
+ )
+
+
+@dataclass
+class FilePatternConfigData:
+ """Shared data structure for file pattern configuration.
+
+ Handles file extension patterns and validation logic consistent
+ with backend source.py pattern processing.
+ """
+
+ raw_extensions: list[str] = field(default_factory=list)
+ wildcard_patterns: list[str] = field(default_factory=list)
+ allowed_mime_types: list[str] = field(default_factory=list)
+ blocked_mime_types: list[str] = field(default_factory=list)
+
+ def generate_wildcard_patterns(self) -> list[str]:
+ """Generate wildcard patterns from file extensions."""
+ if not self.raw_extensions:
+ return ["*"] # Process all files if no extensions specified
+
+ patterns = []
+ for ext in self.raw_extensions:
+ # Normalize extension format
+ ext = ext.lower().strip()
+ if not ext.startswith("."):
+ ext = "." + ext
+ patterns.append(f"*{ext}")
+
+ return patterns
+
+ def matches_pattern(self, file_name: str) -> bool:
+ """Check if file matches any of the configured patterns."""
+ if not self.wildcard_patterns:
+ self.wildcard_patterns = self.generate_wildcard_patterns()
+
+ if not self.wildcard_patterns or "*" in self.wildcard_patterns:
+ return True
+
+ import fnmatch
+
+ file_lower = file_name.lower()
+ return any(
+ fnmatch.fnmatchcase(file_lower, pattern.lower())
+ for pattern in self.wildcard_patterns
+ )
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return asdict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FilePatternConfigData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ raw_extensions=data.get("raw_extensions", []),
+ wildcard_patterns=data.get("wildcard_patterns", []),
+ allowed_mime_types=data.get("allowed_mime_types", []),
+ blocked_mime_types=data.get("blocked_mime_types", []),
+ )
+
+
+@dataclass
+class SourceFileListingRequest:
+ """Shared data structure for source file listing requests.
+
+ Standardizes the parameters for file listing operations to ensure
+ consistency between backend and worker implementations.
+ """
+
+ source_config: SourceConnectorConfigData
+ workflow_id: str
+ organization_id: str
+ execution_id: str | None = None
+ use_file_history: bool = True
+ max_files: int = 1000
+ recursive: bool = True
+ file_pattern_config: FilePatternConfigData | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ data = {
+ "source_config": self.source_config.to_dict(),
+ "workflow_id": self.workflow_id,
+ "organization_id": self.organization_id,
+ "execution_id": self.execution_id,
+ "use_file_history": self.use_file_history,
+ "max_files": self.max_files,
+ "recursive": self.recursive,
+ }
+ if self.file_pattern_config:
+ data["file_pattern_config"] = self.file_pattern_config.to_dict()
+ return data
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "SourceFileListingRequest":
+ """Create from dictionary (e.g., API request)."""
+ file_pattern_config = None
+ if data.get("file_pattern_config"):
+ file_pattern_config = FilePatternConfigData.from_dict(
+ data["file_pattern_config"]
+ )
+
+ return cls(
+ source_config=SourceConnectorConfigData.from_dict(data["source_config"]),
+ workflow_id=data["workflow_id"],
+ organization_id=data["organization_id"],
+ execution_id=data.get("execution_id"),
+ use_file_history=data.get("use_file_history", True),
+ max_files=data.get("max_files", 1000),
+ recursive=data.get("recursive", True),
+ file_pattern_config=file_pattern_config,
+ )
+
+
+@dataclass
+class SourceFileListingResponse:
+ """Shared data structure for source file listing responses.
+
+ Standardizes the response format for file listing operations to ensure
+ consistency between backend and worker implementations.
+ """
+
+ files: list[FileHashData] = field(default_factory=list)
+ total_files: int = 0
+ directories_processed: list[str] = field(default_factory=list)
+ validation_results: list[DirectoryValidationData] = field(default_factory=list)
+ processing_time: float = 0.0
+ errors: list[str] = field(default_factory=list)
+
+ def add_file(self, file_data: FileHashData):
+ """Add a file to the response."""
+ self.files.append(file_data)
+ self.total_files = len(self.files)
+
+ def add_directory(self, directory_path: str):
+ """Add a processed directory to the response."""
+ if directory_path not in self.directories_processed:
+ self.directories_processed.append(directory_path)
+
+ def add_validation_result(self, validation: DirectoryValidationData):
+ """Add a directory validation result."""
+ self.validation_results.append(validation)
+
+ def add_error(self, error_message: str):
+ """Add an error message to the response."""
+ self.errors.append(error_message)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return {
+ "files": [file_data.to_dict() for file_data in self.files],
+ "total_files": self.total_files,
+ "directories_processed": self.directories_processed,
+ "validation_results": [
+ validation.to_dict() for validation in self.validation_results
+ ],
+ "processing_time": self.processing_time,
+ "errors": self.errors,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "SourceFileListingResponse":
+ """Create from dictionary (e.g., API response)."""
+ files = [FileHashData.from_dict(file_data) for file_data in data.get("files", [])]
+ validation_results = [
+ DirectoryValidationData.from_dict(val)
+ for val in data.get("validation_results", [])
+ ]
+
+ return cls(
+ files=files,
+ total_files=data.get("total_files", 0),
+ directories_processed=data.get("directories_processed", []),
+ validation_results=validation_results,
+ processing_time=data.get("processing_time", 0.0),
+ errors=data.get("errors", []),
+ )
+
+
+# Internal API Response Data Models
+@dataclass
+class HealthCheckResponse(ModelAdapterMixin):
+ """Health check response data structure."""
+
+ status: str
+ service: str
+ version: str
+ timestamp: str | None = None
+ authenticated: bool = True
+ organization_id: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "status": self.status,
+ "service": self.service,
+ "version": self.version,
+ "timestamp": self.timestamp,
+ "authenticated": self.authenticated,
+ "organization_id": self.organization_id,
+ }
+
+ @classmethod
+ def healthy_response(
+ cls,
+ service: str = "internal_api",
+ version: str = "1.0.0",
+ timestamp: str | None = None,
+ organization_id: str | None = None,
+ ) -> "HealthCheckResponse":
+ """Create a healthy response."""
+ return cls(
+ status="healthy",
+ service=service,
+ version=version,
+ timestamp=timestamp,
+ organization_id=organization_id,
+ )
+
+
+@dataclass
+class WebhookConfigurationData(ModelAdapterMixin):
+ """Webhook configuration data structure."""
+
+ notification_id: str | uuid.UUID
+ url: str
+ authorization_type: str
+ authorization_key: str | None = None
+ authorization_header: str | None = None
+ max_retries: int = 3
+ is_active: bool = True
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "notification_id": str(self.notification_id),
+ "url": self.url,
+ "authorization_type": self.authorization_type,
+ "authorization_key": self.authorization_key,
+ "authorization_header": self.authorization_header,
+ "max_retries": self.max_retries,
+ "is_active": self.is_active,
+ }
+
+ @classmethod
+ def from_notification(cls, notification: Any) -> "WebhookConfigurationData":
+ """Create from notification model using centralized field mapping."""
+ # Uses centralized FIELD_MAPPINGS automatically via ModelAdapterMixin.from_model()
+ return cls.from_model(notification)
+
+
+@dataclass
+class WebhookTestResult(ModelAdapterMixin):
+ """Webhook test result data structure."""
+
+ success: bool
+ status_code: int | None = None
+ response_time: float | None = None
+ error_message: str | None = None
+ response_data: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "success": self.success,
+ "status_code": self.status_code,
+ "response_time": self.response_time,
+ "error_message": self.error_message,
+ "response_data": self.response_data,
+ }
+
+ @classmethod
+ def success_result(
+ cls,
+ status_code: int,
+ response_time: float,
+ response_data: dict[str, Any] | None = None,
+ ) -> "WebhookTestResult":
+ """Create a success result."""
+ return cls(
+ success=True,
+ status_code=status_code,
+ response_time=response_time,
+ response_data=response_data,
+ )
+
+ @classmethod
+ def error_result(
+ cls,
+ error_message: str,
+ status_code: int | None = None,
+ response_time: float | None = None,
+ ) -> "WebhookTestResult":
+ """Create an error result."""
+ return cls(
+ success=False,
+ status_code=status_code,
+ response_time=response_time,
+ error_message=error_message,
+ )
+
+
+@dataclass
+class UsageResponseData(ModelAdapterMixin):
+ """Shared data structure for usage aggregation API responses.
+
+ This ensures consistent serialization between backend and workers for usage data.
+ """
+
+ file_execution_id: str
+ embedding_tokens: int | None = None
+ prompt_tokens: int | None = None
+ completion_tokens: int | None = None
+ total_tokens: int | None = None
+ cost_in_dollars: float | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return asdict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "UsageResponseData":
+ """Create from dictionary (e.g., API response)."""
+ return cls(
+ file_execution_id=data.get("file_execution_id", ""),
+ embedding_tokens=data.get("embedding_tokens"),
+ prompt_tokens=data.get("prompt_tokens"),
+ completion_tokens=data.get("completion_tokens"),
+ total_tokens=data.get("total_tokens"),
+ cost_in_dollars=data.get("cost_in_dollars"),
+ )
diff --git a/unstract/core/src/unstract/core/file_operations.py b/unstract/core/src/unstract/core/file_operations.py
new file mode 100644
index 000000000..d6b42642c
--- /dev/null
+++ b/unstract/core/src/unstract/core/file_operations.py
@@ -0,0 +1,1079 @@
+"""Common File Operations for Unstract Platform
+
+This module provides shared file operations that can be used by both
+Django backend and Celery workers without Django dependencies.
+
+Shared between:
+- backend/workflow_manager/endpoint_v2/source.py
+- workers/shared/source_operations.py
+- Any other component that needs file operations
+"""
+
+import hashlib
+import logging
+import mimetypes
+import os
+from pathlib import Path
+from typing import Any
+
+from .constants import FilePatternConstants
+from .data_models import FileHashData, FileOperationConstants
+
+logger = logging.getLogger(__name__)
+
+
+class FileOperations:
+ """Common file operations shared between backend and workers"""
+
+ @staticmethod
+ def compute_file_content_hash_from_fsspec(source_fs, file_path: str) -> str:
+ """Generate a hash value from the file content using fsspec filesystem.
+
+ This matches the exact implementation from backend source.py:745
+
+ Args:
+ source_fs: The file system object (fsspec compatible)
+ file_path: The path of the file
+
+ Returns:
+ str: The SHA256 hash value of the file content
+ """
+ file_content_hash = hashlib.sha256()
+ source = (
+ source_fs.get_fsspec_fs()
+ if hasattr(source_fs, "get_fsspec_fs")
+ else source_fs
+ )
+
+ try:
+ with source.open(file_path, "rb") as remote_file:
+ while chunk := remote_file.read(FileOperationConstants.READ_CHUNK_SIZE):
+ file_content_hash.update(chunk)
+ return file_content_hash.hexdigest()
+ except Exception as e:
+ logger.warning(f"Failed to compute content hash for {file_path}: {e}")
+ # Return a fallback hash based on file path and current time
+ import time
+
+ fallback_string = f"{file_path}:{time.time()}"
+ return hashlib.sha256(fallback_string.encode()).hexdigest()
+
+ @staticmethod
+ def compute_file_hash(file_path: str, chunk_size: int = 8192) -> str:
+ """Compute SHA-256 hash of file content.
+
+ Args:
+ file_path: Path to the file
+ chunk_size: Size of chunks to read (default 8KB)
+
+ Returns:
+ SHA-256 hex string of file content
+
+ Raises:
+ FileNotFoundError: If file doesn't exist
+ PermissionError: If file cannot be read
+ """
+ if not os.path.exists(file_path):
+ raise FileNotFoundError(f"File not found: {file_path}")
+
+ hash_sha256 = hashlib.sha256()
+ try:
+ with open(file_path, "rb") as f:
+ for chunk in iter(lambda: f.read(chunk_size), b""):
+ hash_sha256.update(chunk)
+ return hash_sha256.hexdigest()
+ except Exception as e:
+ logger.error(f"Failed to compute hash for {file_path}: {str(e)}")
+ raise
+
+ @staticmethod
+ def detect_mime_type(file_path: str) -> str:
+ """Detect MIME type of file.
+
+ Args:
+ file_path: Path to the file
+
+ Returns:
+ MIME type string (default: 'application/octet-stream')
+ """
+ try:
+ mime_type, _ = mimetypes.guess_type(file_path)
+ return mime_type or "application/octet-stream"
+ except Exception as e:
+ logger.warning(f"Failed to detect MIME type for {file_path}: {str(e)}")
+ return "application/octet-stream"
+
+ @staticmethod
+ def create_file_hash_from_backend_logic(
+ file_path: str,
+ source_fs,
+ source_connection_type: str,
+ file_size: int,
+ fs_metadata: dict[str, Any],
+ compute_content_hash: bool = False,
+ ) -> FileHashData:
+ """Create FileHashData object matching backend source.py:352 _create_file_hash.
+
+ Args:
+ file_path: Path to the file
+ source_fs: File system object (UnstractFileSystem)
+ source_connection_type: Type of source connection (FILESYSTEM/API)
+ file_size: Size of the file in bytes
+ fs_metadata: Metadata from fsspec
+ compute_content_hash: Whether to compute file content hash (only for API deployments)
+
+ Returns:
+ FileHashData: Populated FileHashData object
+ """
+ # Only compute content hash for API deployments or when explicitly requested
+ file_hash = None
+ if compute_content_hash:
+ file_hash = FileOperations.compute_file_content_hash_from_fsspec(
+ source_fs, file_path
+ )
+
+ # Extract file name from path
+ file_name = os.path.basename(file_path)
+
+ # Get provider-specific file UUID (this is the primary identifier for ETL/TASK)
+ provider_file_uuid = None
+ # Use the correct method name - check the source_fs interface
+ if hasattr(source_fs, "get_file_system_uuid"):
+ provider_file_uuid = source_fs.get_file_system_uuid(
+ file_path=file_path, metadata=fs_metadata
+ )
+ elif hasattr(source_fs, "extract_metadata_file_hash"):
+ provider_file_uuid = source_fs.extract_metadata_file_hash(fs_metadata)
+
+ # Detect MIME type if possible
+ mime_type = fs_metadata.get("ContentType") or fs_metadata.get("content_type")
+
+ # Sanitize metadata for JSON serialization (critical for Celery tasks)
+ sanitized_metadata = FileOperations._sanitize_metadata_for_serialization(
+ fs_metadata
+ )
+
+ return FileHashData(
+ file_path=file_path,
+ file_name=file_name,
+ source_connection_type=source_connection_type,
+ file_hash=file_hash, # None for ETL/TASK, computed for API deployments
+ file_size=file_size,
+ provider_file_uuid=provider_file_uuid,
+ mime_type=mime_type,
+ fs_metadata=sanitized_metadata,
+ )
+
+ @staticmethod
+ def _sanitize_metadata_for_serialization(metadata: dict[str, Any]) -> dict[str, Any]:
+ """Sanitize file metadata for JSON serialization by converting non-serializable objects.
+
+ This is critical for Azure Blob Storage which includes ContentSettings objects
+ that cannot be serialized for Celery task distribution.
+
+ Args:
+ metadata: Raw metadata dictionary from fsspec/connector
+
+ Returns:
+ dict[str, Any]: Sanitized metadata safe for JSON serialization
+ """
+ if not isinstance(metadata, dict):
+ return {}
+
+ sanitized = {}
+
+ for key, value in metadata.items():
+ try:
+ # Handle Azure ContentSettings object or similar objects with content_type
+ if hasattr(value, "content_type") and hasattr(value, "__dict__"):
+ # Convert ContentSettings-like objects to dictionary
+ try:
+ sanitized[key] = {
+ "content_type": getattr(value, "content_type", None),
+ "content_encoding": getattr(value, "content_encoding", None),
+ "content_language": getattr(value, "content_language", None),
+ "content_disposition": getattr(
+ value, "content_disposition", None
+ ),
+ "cache_control": getattr(value, "cache_control", None),
+ "content_md5": value.content_md5.hex()
+ if getattr(value, "content_md5", None)
+ else None,
+ }
+ continue
+ except Exception as content_error:
+ logger.debug(
+ f"Failed to convert ContentSettings object: {content_error}"
+ )
+ sanitized[key] = str(value)
+ continue
+
+ # Handle bytearray objects (like content_md5)
+ if isinstance(value, bytearray):
+ sanitized[key] = value.hex()
+ continue
+
+ # Handle datetime objects
+ if hasattr(value, "isoformat"):
+ sanitized[key] = value.isoformat()
+ continue
+
+ # Handle other complex objects by converting to string
+ if not FileOperations._is_json_serializable(value):
+ sanitized[key] = str(value)
+ continue
+
+ # Keep as-is if it's JSON serializable
+ sanitized[key] = value
+
+ except Exception as e:
+ # If anything fails, convert to string as fallback
+ logger.debug(
+ f"Failed to sanitize metadata key '{key}': {e}, converting to string"
+ )
+ sanitized[key] = str(value)
+
+ return sanitized
+
+ @staticmethod
+ def _is_json_serializable(obj: Any) -> bool:
+ """Check if an object is JSON serializable."""
+ import json
+
+ try:
+ json.dumps(obj)
+ return True
+ except (TypeError, ValueError):
+ return False
+
+ @staticmethod
+ def process_file_fs_directory(
+ fs_metadata_list: list[dict[str, Any]],
+ count: int,
+ limit: int,
+ unique_file_paths: set[str],
+ matched_files: dict[str, FileHashData],
+ patterns: list[str],
+ source_fs,
+ source_connection_type: str,
+ dirs: list[str],
+ workflow_log=None,
+ connector_id: str | None = None,
+ ) -> int:
+ """Process directory items matching backend source.py:326 _process_file_fs_directory.
+
+ Args:
+ fs_metadata_list: List of file metadata from fsspec listdir
+ count: Current count of matched files
+ limit: Maximum number of files to process
+ unique_file_paths: Set of already seen file paths
+ matched_files: Dictionary to populate with matched files
+ patterns: File patterns to match
+ source_fs: File system object
+ source_connection_type: Type of source connection
+ dirs: List of directories from fsspec walk
+ workflow_log: Optional workflow logger
+
+ Returns:
+ int: Updated count of matched files
+ """
+ for fs_metadata in fs_metadata_list:
+ if count >= limit:
+ msg = f"Maximum limit of '{limit}' files to process reached"
+ if workflow_log:
+ workflow_log.publish_log(msg)
+ logger.info(msg)
+ break
+
+ file_path = fs_metadata.get("name")
+ file_size = fs_metadata.get("size", 0)
+
+ if not file_path or FileOperations._is_directory_backend_compatible(
+ source_fs, file_path, fs_metadata, dirs
+ ):
+ continue
+
+ # Add connector_id to fs_metadata if provided
+ if connector_id:
+ fs_metadata = fs_metadata.copy() # Don't modify original
+ fs_metadata["connector_id"] = connector_id
+
+ file_hash = FileOperations.create_file_hash_from_backend_logic(
+ file_path=file_path,
+ source_fs=source_fs,
+ source_connection_type=source_connection_type,
+ file_size=file_size,
+ fs_metadata=fs_metadata,
+ compute_content_hash=False, # ETL/TASK: Only use provider_file_uuid for deduplication
+ )
+
+ if FileOperations._should_skip_file_backend_compatible(file_hash, patterns):
+ continue
+
+ # Skip duplicate files
+ if FileOperations._is_duplicate_backend_compatible(
+ file_hash, unique_file_paths
+ ):
+ msg = f"Skipping execution of duplicate file '{file_path}'"
+ if workflow_log:
+ workflow_log.publish_log(msg)
+ logger.info(msg)
+ continue
+
+ FileOperations._update_unique_file_paths_backend_compatible(
+ file_hash, unique_file_paths
+ )
+
+ matched_files[file_path] = file_hash
+ count += 1
+
+ return count
+
+ @staticmethod
+ def _is_directory_backend_compatible(
+ source_fs, file_path: str, metadata: dict, dirs: list
+ ) -> bool:
+ """Check if path is directory matching backend logic."""
+ try:
+ # Check if basename is in dirs list from walk
+ if os.path.basename(file_path) in dirs:
+ return True
+
+ # Try fsspec isdir
+ fs_fsspec = (
+ source_fs.get_fsspec_fs()
+ if hasattr(source_fs, "get_fsspec_fs")
+ else source_fs
+ )
+ try:
+ if fs_fsspec.isdir(file_path):
+ return True
+ except Exception:
+ pass
+
+ # Check metadata type
+ file_type = metadata.get("type", "").lower()
+ if file_type in ["directory", "dir", "folder"]:
+ return True
+
+ return False
+
+ except Exception:
+ return False
+
+ @staticmethod
+ def _should_skip_file_backend_compatible(
+ file_hash: FileHashData, patterns: list[str]
+ ) -> bool:
+ """Check if file should be skipped based on patterns with case-insensitive matching."""
+ if not patterns or patterns == ["*"]:
+ return False
+
+ import fnmatch
+
+ file_name = file_hash.file_name
+
+ for pattern in patterns:
+ # Case-insensitive pattern matching to handle Azure Blob Storage case variations
+ if fnmatch.fnmatch(file_name.lower(), pattern.lower()):
+ return False
+
+ return True
+
+ @staticmethod
+ def _is_duplicate_backend_compatible(
+ file_hash: FileHashData, unique_file_paths: set[str]
+ ) -> bool:
+ """Check if file is duplicate."""
+ return file_hash.file_path in unique_file_paths
+
+ @staticmethod
+ def _update_unique_file_paths_backend_compatible(
+ file_hash: FileHashData, unique_file_paths: set
+ ) -> None:
+ """Update unique file paths."""
+ unique_file_paths.add(file_hash.file_path)
+
+ @staticmethod
+ def valid_file_patterns(required_patterns: list[str]) -> list[str]:
+ """Get valid file patterns matching backend logic with display name translation."""
+ if not required_patterns:
+ return ["*"]
+
+ valid_patterns = [p for p in required_patterns if p and p.strip()]
+
+ if not valid_patterns:
+ return ["*"]
+
+ # Translate display names to actual file patterns
+ translated_patterns = []
+ for pattern in valid_patterns:
+ translated = FileOperations._translate_display_name_to_pattern(pattern)
+ translated_patterns.extend(translated)
+
+ return translated_patterns if translated_patterns else ["*"]
+
+ @staticmethod
+ def _translate_display_name_to_pattern(display_name: str) -> list[str]:
+ """Translate UI display names to actual file matching patterns.
+
+ Args:
+ display_name: Display name from UI (e.g., "PDF documents")
+
+ Returns:
+ List of file patterns (e.g., ["*.pdf"])
+ """
+ # First, try exact display name match using constants
+ patterns = FilePatternConstants.get_patterns_for_display_name(display_name)
+ if patterns:
+ logger.info(
+ f"Translating display name '{display_name}' to patterns: {patterns}"
+ )
+ return patterns
+
+ # If it looks like a file pattern already (contains * or .), use as-is
+ if "*" in display_name or "." in display_name:
+ return [display_name]
+
+ # Try to infer patterns from keywords using constants
+ inferred_patterns = FilePatternConstants.infer_patterns_from_keyword(display_name)
+ if inferred_patterns:
+ logger.info(f"Inferred patterns for '{display_name}': {inferred_patterns}")
+ return inferred_patterns
+
+ # If no match, return the original pattern
+ logger.warning(
+ f"Unknown display name pattern '{display_name}', using as literal pattern"
+ )
+ return [display_name]
+
+ @staticmethod
+ def validate_file_compatibility(
+ file_data: FileHashData, workflow_config: dict[str, Any]
+ ) -> dict[str, Any]:
+ """Validate file against workflow requirements.
+
+ This shared validation logic ensures consistency between
+ backend endpoint validation and worker file processing.
+
+ Args:
+ file_data: FileHashData object with file information
+ workflow_config: Workflow configuration with validation rules
+
+ Returns:
+ Dictionary with 'is_valid' boolean and 'errors' list
+ """
+ validations = {"is_valid": True, "errors": []}
+
+ # Check file size limits
+ max_size = workflow_config.get(
+ "max_file_size", 100 * 1024 * 1024
+ ) # 100MB default
+ if file_data.file_size > max_size:
+ validations["is_valid"] = False
+ validations["errors"].append(
+ f"File size {file_data.file_size} bytes exceeds limit: {max_size} bytes"
+ )
+
+ # Check minimum file size
+ min_size = workflow_config.get("min_file_size", 1) # 1 byte default
+ if file_data.file_size < min_size:
+ validations["is_valid"] = False
+ validations["errors"].append(
+ f"File size {file_data.file_size} bytes below minimum: {min_size} bytes"
+ )
+
+ # Check allowed MIME types
+ allowed_types = workflow_config.get("allowed_mime_types", [])
+ if allowed_types and file_data.mime_type not in allowed_types:
+ validations["is_valid"] = False
+ validations["errors"].append(
+ f"MIME type not allowed: {file_data.mime_type}. Allowed: {allowed_types}"
+ )
+
+ # Check blocked MIME types
+ blocked_types = workflow_config.get("blocked_mime_types", [])
+ if blocked_types and file_data.mime_type in blocked_types:
+ validations["is_valid"] = False
+ validations["errors"].append(f"MIME type blocked: {file_data.mime_type}")
+
+ # Check file extensions
+ allowed_extensions = workflow_config.get("allowed_extensions", [])
+ if allowed_extensions:
+ file_ext = Path(file_data.file_name).suffix.lower()
+ if file_ext not in [ext.lower() for ext in allowed_extensions]:
+ validations["is_valid"] = False
+ validations["errors"].append(
+ f"File extension not allowed: {file_ext}. Allowed: {allowed_extensions}"
+ )
+
+ # Check blocked extensions
+ blocked_extensions = workflow_config.get("blocked_extensions", [])
+ if blocked_extensions:
+ file_ext = Path(file_data.file_name).suffix.lower()
+ if file_ext in [ext.lower() for ext in blocked_extensions]:
+ validations["is_valid"] = False
+ validations["errors"].append(f"File extension blocked: {file_ext}")
+
+ return validations
+
+ @staticmethod
+ def create_file_metadata(
+ file_path: str, compute_hash: bool = True, include_fs_metadata: bool = True
+ ) -> FileHashData:
+ """Create FileHashData with computed metadata.
+
+ This shared logic ensures consistent file metadata creation
+ across backend and workers.
+
+ Args:
+ file_path: Path to the file
+ compute_hash: Whether to compute SHA-256 content hash
+ include_fs_metadata: Whether to include filesystem metadata
+
+ Returns:
+ FileHashData object with computed metadata
+
+ Raises:
+ FileNotFoundError: If file doesn't exist
+ """
+ file_info = Path(file_path)
+
+ if not file_info.exists():
+ raise FileNotFoundError(f"File not found: {file_path}")
+
+ # Get basic file information
+ stat_info = file_info.stat()
+
+ file_data = FileHashData(
+ file_name=file_info.name,
+ file_path=str(file_path),
+ file_size=stat_info.st_size,
+ mime_type=FileOperations.detect_mime_type(str(file_path)),
+ )
+
+ # Compute content hash if requested
+ if compute_hash:
+ try:
+ file_data.file_hash = FileOperations.compute_file_hash(str(file_path))
+ except Exception as e:
+ logger.warning(f"Failed to compute hash for {file_path}: {str(e)}")
+ file_data.file_hash = ""
+
+ # Include filesystem metadata if requested
+ if include_fs_metadata:
+ file_data.fs_metadata = {
+ "created_time": stat_info.st_ctime,
+ "modified_time": stat_info.st_mtime,
+ "accessed_time": stat_info.st_atime,
+ "is_file": file_info.is_file(),
+ "is_dir": file_info.is_dir(),
+ "permissions": oct(stat_info.st_mode)[-3:],
+ }
+
+ return file_data
+
+ @staticmethod
+ def validate_file_path(
+ file_path: str, allowed_paths: list[str] | None = None
+ ) -> dict[str, Any]:
+ """Validate file path for security and access.
+
+ Args:
+ file_path: Path to validate
+ allowed_paths: List of allowed path prefixes (optional)
+
+ Returns:
+ Dictionary with 'is_valid' boolean and 'errors' list
+ """
+ validation = {"is_valid": True, "errors": []}
+
+ try:
+ # Resolve and normalize path
+ resolved_path = Path(file_path).resolve()
+
+ # Check for path traversal attempts
+ if ".." in str(resolved_path):
+ validation["is_valid"] = False
+ validation["errors"].append("Path traversal detected")
+
+ # Check against allowed paths if provided
+ if allowed_paths:
+ path_allowed = False
+ for allowed_path in allowed_paths:
+ try:
+ resolved_allowed = Path(allowed_path).resolve()
+ if resolved_path.is_relative_to(resolved_allowed):
+ path_allowed = True
+ break
+ except (ValueError, OSError):
+ continue
+
+ if not path_allowed:
+ validation["is_valid"] = False
+ validation["errors"].append(
+ f"Path not in allowed directories: {allowed_paths}"
+ )
+
+ # Check if file exists
+ if not resolved_path.exists():
+ validation["is_valid"] = False
+ validation["errors"].append("File does not exist")
+
+ # Check if it's actually a file (not a directory)
+ elif not resolved_path.is_file():
+ validation["is_valid"] = False
+ validation["errors"].append("Path is not a file")
+
+ except Exception as e:
+ validation["is_valid"] = False
+ validation["errors"].append(f"Path validation failed: {str(e)}")
+
+ return validation
+
+ @staticmethod
+ def get_file_batch_metadata(file_paths: list[str]) -> dict[str, Any]:
+ """Get metadata for a batch of files efficiently.
+
+ Args:
+ file_paths: List of file paths
+
+ Returns:
+ Dictionary with batch metadata and individual file data
+ """
+ batch_metadata = {
+ "total_files": len(file_paths),
+ "total_size": 0,
+ "valid_files": 0,
+ "invalid_files": 0,
+ "file_data": [],
+ "errors": [],
+ }
+
+ for file_path in file_paths:
+ try:
+ file_data = FileOperations.create_file_metadata(
+ file_path=file_path,
+ compute_hash=False, # Skip hash computation for batch operations
+ include_fs_metadata=False,
+ )
+
+ batch_metadata["file_data"].append(file_data.to_dict())
+ batch_metadata["total_size"] += file_data.file_size
+ batch_metadata["valid_files"] += 1
+
+ except Exception as e:
+ batch_metadata["invalid_files"] += 1
+ batch_metadata["errors"].append({"file_path": file_path, "error": str(e)})
+
+ return batch_metadata
+
+ @staticmethod
+ def is_directory_by_patterns(
+ file_path: str,
+ metadata: dict[str, Any] | None = None,
+ connector_name: str | None = None,
+ ) -> bool:
+ """Enhanced directory detection using file patterns and metadata.
+
+ This method provides connector-agnostic directory detection that works
+ across different storage backends (GCS, S3, Azure, local filesystem).
+
+ Args:
+ file_path: Path to check
+ metadata: Optional file metadata from connector
+ connector_name: Optional connector name for specific patterns
+
+ Returns:
+ True if the path appears to be a directory
+ """
+ # Primary check: Path ends with slash (universal directory indicator)
+ if file_path.endswith("/"):
+ logger.debug(
+ f"[Directory Check] '{file_path}' identified as directory: ends with '/'"
+ )
+ return True
+
+ # Check for common directory naming patterns
+ if FileOperations._looks_like_directory_path(file_path):
+ logger.debug(
+ f"[Directory Check] '{file_path}' identified as directory: naming pattern"
+ )
+ return True
+
+ # Connector-specific directory detection
+ if metadata and connector_name:
+ if FileOperations._is_directory_by_connector_patterns(
+ file_path, metadata, connector_name
+ ):
+ logger.debug(
+ f"[Directory Check] '{file_path}' identified as directory: connector-specific pattern"
+ )
+ return True
+
+ # Enhanced zero-size file check with additional validation
+ if metadata:
+ file_size = metadata.get("size", 0)
+ if file_size == 0:
+ # Only treat zero-size objects as directories if they have directory indicators
+ if FileOperations._has_directory_indicators(
+ file_path, metadata, connector_name
+ ):
+ logger.debug(
+ f"[Directory Check] '{file_path}' identified as directory: zero-size with directory indicators"
+ )
+ return True
+
+ return False
+
+ @staticmethod
+ def _looks_like_directory_path(file_path: str) -> bool:
+ """Check if a file path looks like a directory based on naming patterns."""
+ file_name = os.path.basename(file_path)
+
+ # Directory-like names (no file extension, common folder names)
+ common_dir_names = {
+ "tmp",
+ "temp",
+ "cache",
+ "logs",
+ "data",
+ "config",
+ "bin",
+ "lib",
+ "src",
+ "test",
+ "tests",
+ "docs",
+ "assets",
+ "images",
+ "files",
+ "duplicate-test", # Add the specific directory from the issue
+ }
+
+ # Check if it's a common directory name
+ if file_name.lower() in common_dir_names:
+ return True
+
+ # Check if it has no file extension and contains no dots (likely a folder)
+ if "." not in file_name and len(file_name) > 0:
+ return True
+
+ return False
+
+ @staticmethod
+ def _is_directory_by_connector_patterns(
+ file_path: str, metadata: dict[str, Any], connector_name: str
+ ) -> bool:
+ """Check connector-specific patterns that indicate a directory."""
+ connector_name = connector_name.lower()
+
+ # Google Cloud Storage specific patterns
+ if "google" in connector_name or "gcs" in connector_name:
+ content_type = metadata.get("contentType", "")
+ object_name = metadata.get("name", file_path)
+
+ # GCS folder objects often have specific content types
+ if content_type in ["text/plain", "application/x-www-form-urlencoded"]:
+ return True
+
+ # GCS folder objects may have no content type
+ if not content_type and metadata.get("size", 0) == 0:
+ return True
+
+ # Object name ends with "/" in GCS
+ if object_name.endswith("/"):
+ return True
+
+ # AWS S3 specific patterns (for future extensibility)
+ elif "s3" in connector_name or "amazon" in connector_name:
+ # S3 folder objects typically end with /
+ if file_path.endswith("/"):
+ return True
+
+ # S3 may have specific metadata markers
+ if metadata.get("ContentType") == "application/x-directory":
+ return True
+
+ # Azure Blob Storage specific patterns (for future extensibility)
+ elif "azure" in connector_name:
+ content_type = metadata.get("content_type", "")
+ if content_type == "httpd/unix-directory":
+ return True
+
+ return False
+
+ @staticmethod
+ def _has_directory_indicators(
+ file_path: str, metadata: dict[str, Any], connector_name: str | None = None
+ ) -> bool:
+ """Check if a zero-size object has additional directory indicators."""
+ # Path-based indicators
+ if file_path.endswith("/"):
+ return True
+
+ if FileOperations._looks_like_directory_path(file_path):
+ return True
+
+ # Metadata-based indicators
+ if connector_name:
+ connector_name = connector_name.lower()
+
+ # GCS-specific indicators
+ if "google" in connector_name or "gcs" in connector_name:
+ content_type = metadata.get("contentType", "")
+ if content_type in ["text/plain", "application/x-www-form-urlencoded"]:
+ return True
+
+ # Check for folder-like etag patterns in GCS
+ etag = metadata.get("etag", "")
+ if etag and not etag.startswith(
+ '"'
+ ): # GCS folders often have simple etags
+ return True
+
+ return False
+
+ @staticmethod
+ def should_skip_directory_object(
+ file_path: str,
+ metadata: dict[str, Any] | None = None,
+ connector_name: str | None = None,
+ ) -> bool:
+ """Determine if a file object should be skipped because it's actually a directory.
+
+ This method provides a single entry point for directory filtering
+ that can be used by both backend and workers.
+
+ Args:
+ file_path: Path to check
+ metadata: Optional file metadata from connector
+ connector_name: Optional connector name for specific patterns
+
+ Returns:
+ True if the object should be skipped (it's a directory)
+ """
+ is_directory = FileOperations.is_directory_by_patterns(
+ file_path=file_path, metadata=metadata, connector_name=connector_name
+ )
+
+ if is_directory:
+ logger.info(f"Skipping directory object: {file_path}")
+ return True
+
+ return False
+
+ @staticmethod
+ def validate_provider_file_uuid(
+ file_path: str,
+ provider_file_uuid: str | None,
+ metadata: dict[str, Any] | None = None,
+ connector_name: str | None = None,
+ ) -> dict[str, Any]:
+ """Validate provider file UUID and ensure it's not assigned to directories.
+
+ Args:
+ file_path: File path
+ provider_file_uuid: Provider-assigned file UUID
+ metadata: File metadata
+ connector_name: Connector name
+
+ Returns:
+ Dictionary with validation results
+ """
+ validation = {"is_valid": True, "should_have_uuid": True, "errors": []}
+
+ # Check if this is a directory - directories shouldn't have UUIDs
+ if FileOperations.is_directory_by_patterns(file_path, metadata, connector_name):
+ validation["should_have_uuid"] = False
+
+ if provider_file_uuid:
+ validation["is_valid"] = False
+ validation["errors"].append(
+ f"Directory object '{file_path}' should not have provider UUID: {provider_file_uuid}"
+ )
+
+ # Check UUID format if present
+ if provider_file_uuid and validation["should_have_uuid"]:
+ if not provider_file_uuid.strip():
+ validation["is_valid"] = False
+ validation["errors"].append("Provider UUID is empty or whitespace-only")
+
+ return validation
+
+ @staticmethod
+ def create_deduplication_key(
+ file_path: str | None = None,
+ provider_file_uuid: str | None = None,
+ file_hash: str | None = None,
+ ) -> list[str]:
+ """Create deduplication keys for file tracking.
+
+ Returns multiple keys to support different deduplication strategies.
+
+ Args:
+ file_path: File path
+ provider_file_uuid: Provider UUID
+ file_hash: Content hash
+
+ Returns:
+ List of deduplication keys
+ """
+ keys = []
+
+ # Path-based key
+ if file_path:
+ keys.append(f"path:{file_path}")
+
+ # UUID-based key (most reliable for same file across different paths)
+ if provider_file_uuid:
+ keys.append(f"uuid:{provider_file_uuid}")
+
+ # Content-based key (for content deduplication)
+ if file_hash:
+ keys.append(f"hash:{file_hash}")
+
+ return keys
+
+ @staticmethod
+ def is_file_already_processed(
+ api_client,
+ workflow_id: str,
+ provider_file_uuid: str | None,
+ file_path: str,
+ organization_id: str,
+ use_file_history: bool = True,
+ ) -> dict[str, Any]:
+ """Check if file is already processed using backend-compatible FileHistory logic.
+
+ This method replicates the exact logic from backend source.py:515-540 (_is_new_file)
+ to ensure consistent deduplication behavior between backend and workers.
+
+ Args:
+ api_client: API client for backend communication
+ workflow_id: Workflow ID
+ provider_file_uuid: Provider file UUID (from source connector)
+ file_path: File path
+ organization_id: Organization ID
+ use_file_history: Whether to use file history (matches backend parameter)
+
+ Returns:
+ Dictionary with processing status:
+ {
+ 'is_new_file': bool,
+ 'should_process': bool,
+ 'skip_reason': str,
+ 'file_history': dict
+ }
+ """
+ result = {
+ "is_new_file": True,
+ "should_process": True,
+ "skip_reason": None,
+ "file_history": None,
+ }
+
+ try:
+ # Always treat as new if history usage is not enforced (backend source.py:517-518)
+ if not use_file_history:
+ logger.debug(
+ f"File history not enforced - treating {file_path} as new file"
+ )
+ return result
+
+ # Always treat as new if provider_file_uuid is not available (backend source.py:521-522)
+ if not provider_file_uuid:
+ logger.debug(
+ f"No provider_file_uuid available for {file_path} - treating as new file"
+ )
+ return result
+
+ logger.info(
+ f"Checking file history for {file_path} with provider UUID: {provider_file_uuid}"
+ )
+
+ # Call backend API to get file history using FileHistoryHelper (backend source.py:566-570)
+ file_history_response = api_client.get_file_history(
+ workflow_id=workflow_id,
+ provider_file_uuid=provider_file_uuid,
+ file_path=file_path,
+ organization_id=organization_id,
+ )
+
+ if not file_history_response or "file_history" not in file_history_response:
+ logger.info(
+ f"No file history found for {file_path} - treating as new file"
+ )
+ return result
+
+ file_history = file_history_response["file_history"]
+ result["file_history"] = file_history
+
+ # No history or incomplete history means the file is new (backend source.py:528-529)
+ if not file_history or not file_history.get("is_completed", False):
+ logger.info(
+ f"File history incomplete for {file_path} - treating as new file"
+ )
+ return result
+
+ # Compare file paths (backend source.py:535-536)
+ history_file_path = file_history.get("file_path")
+ if history_file_path and history_file_path != file_path:
+ logger.info(
+ f"File path changed from {history_file_path} to {file_path} - treating as new file"
+ )
+ return result
+
+ # File has been processed with the same path (backend source.py:539-540)
+ result["is_new_file"] = False
+ result["should_process"] = False
+ result["skip_reason"] = (
+ f"File '{file_path}' has already been processed. Clear file markers to process again."
+ )
+
+ logger.info(f"File {file_path} already processed - skipping")
+ return result
+
+ except Exception as e:
+ # If file history check fails, err on the side of processing the file
+ logger.warning(
+ f"Failed to check file history for {file_path}: {str(e)} - treating as new file"
+ )
+ result["skip_reason"] = f"File history check failed: {str(e)}"
+ return result
+
+ @staticmethod
+ def is_file_already_processed_for_listing(
+ workflow_id: str,
+ provider_file_uuid: str | None,
+ file_path: str,
+ organization_id: str,
+ ) -> dict[str, Any]:
+ """Check if file is already processed for file listing phase (without API client).
+
+ This is a simplified version of is_file_already_processed that works during
+ file listing when we don't have API client access.
+
+ Args:
+ workflow_id: Workflow ID
+ provider_file_uuid: Provider file UUID
+ file_path: File path
+ organization_id: Organization ID
+
+ Returns:
+ Dictionary with should_process and skip_reason
+ """
+ # For file listing phase, we'll make a simplified check
+ # Since we don't have API client here, we'll return should_process=True
+ # and let the actual processing phase handle the deduplication
+
+ # TODO: Implement direct database access for file listing phase
+ # For now, return True to maintain existing behavior but log the check
+
+ return {
+ "should_process": True,
+ "is_new_file": True,
+ "skip_reason": None,
+ "file_history": None,
+ "note": "File listing phase - deduplication deferred to processing phase",
+ }
diff --git a/unstract/core/src/unstract/core/log_utils.py b/unstract/core/src/unstract/core/log_utils.py
new file mode 100644
index 000000000..718f559aa
--- /dev/null
+++ b/unstract/core/src/unstract/core/log_utils.py
@@ -0,0 +1,147 @@
+"""Shared log processing utilities for Unstract platform.
+
+This module contains log processing utilities that can be used by both
+backend Django services and worker processes for consistent log handling.
+"""
+
+import json
+import logging
+import os
+from typing import Any
+
+import redis
+
+from unstract.core.constants import LogFieldName
+from unstract.core.data_models import LogDataDTO
+from unstract.workflow_execution.enums import LogType
+
+logger = logging.getLogger(__name__)
+
+
+def get_validated_log_data(json_data: Any) -> LogDataDTO | None:
+ """Validate log data to persist history.
+
+ This function takes log data in JSON format, validates it, and returns a
+ LogDataDTO object if the data is valid. The validation process includes
+ decoding bytes to string, parsing the string as JSON, and checking for
+ required fields and log type.
+
+ Args:
+ json_data (Any): Log data in JSON format
+
+ Returns:
+ LogDataDTO | None: Log data DTO object if valid, None otherwise
+ """
+ if isinstance(json_data, bytes):
+ json_data = json_data.decode("utf-8")
+
+ if isinstance(json_data, str):
+ try:
+ # Parse the string as JSON
+ json_data = json.loads(json_data)
+ except json.JSONDecodeError:
+ logger.error(f"Error decoding JSON data while validating {json_data}")
+ return None
+
+ if not isinstance(json_data, dict):
+ logger.warning(f"Getting invalid data type while validating {json_data}")
+ return None
+
+ # Extract required fields from the JSON data
+ execution_id = json_data.get(LogFieldName.EXECUTION_ID)
+ organization_id = json_data.get(LogFieldName.ORGANIZATION_ID)
+ timestamp = json_data.get(LogFieldName.TIMESTAMP)
+ log_type = json_data.get(LogFieldName.TYPE)
+ file_execution_id = json_data.get(LogFieldName.FILE_EXECUTION_ID)
+
+ # Ensure the log type is LogType.LOG
+ if log_type != LogType.LOG.value:
+ return None
+
+ # Check if all required fields are present
+ if not all((execution_id, organization_id, timestamp)):
+ logger.debug(f"Missing required fields while validating {json_data}")
+ return None
+
+ return LogDataDTO(
+ execution_id=execution_id,
+ file_execution_id=file_execution_id,
+ organization_id=organization_id,
+ timestamp=timestamp,
+ log_type=log_type,
+ data=json_data,
+ )
+
+
+def store_execution_log(
+ data: dict[str, Any],
+ redis_client: redis.Redis,
+ log_queue_name: str,
+ is_enabled: bool = True,
+) -> None:
+ """Store execution log in Redis queue with automatic size protection.
+
+ Protects against memory overflow by capping queue at configurable maximum size.
+ When limit is reached, new logs are dropped to prevent queue overflow.
+
+ Args:
+ data: Execution log data
+ redis_client: Redis client instance
+ log_queue_name: Name of the Redis queue to store logs
+ is_enabled: Whether log storage is enabled
+ """
+ if not is_enabled:
+ return
+
+ try:
+ log_data = get_validated_log_data(json_data=data)
+ if not log_data:
+ return
+
+ # Get max queue size from environment (default: 10,000 logs ~10MB)
+ max_queue_size = int(os.getenv("LOG_QUEUE_MAX_SIZE", "10000"))
+
+ # Check if queue is at limit (O(1) operation)
+ queue_length = redis_client.llen(log_queue_name)
+
+ if queue_length >= max_queue_size:
+ logger.warning(
+ f"Log queue '{log_queue_name}' at capacity ({max_queue_size}), "
+ "dropping current log - scheduler may be falling behind"
+ )
+ return
+
+ # Add new log to end of queue (O(1) operation)
+ redis_client.rpush(log_queue_name, log_data.to_json())
+
+ except Exception as e:
+ logger.error(f"Error storing execution log: {e}")
+
+
+def create_redis_client(
+ host: str = "localhost",
+ port: int = 6379,
+ username: str | None = None,
+ password: str | None = None,
+ **kwargs,
+) -> redis.Redis:
+ """Create Redis client with configuration.
+
+ Args:
+ host: Redis host
+ port: Redis port
+ username: Redis username (optional)
+ password: Redis password (optional)
+ **kwargs: Additional Redis configuration
+
+ Returns:
+ Configured Redis client
+ """
+ return redis.Redis(
+ host=host,
+ port=port,
+ username=username,
+ password=password,
+ decode_responses=False, # Keep as bytes for consistency
+ **kwargs,
+ )
diff --git a/unstract/core/src/unstract/core/notification_enums.py b/unstract/core/src/unstract/core/notification_enums.py
new file mode 100644
index 000000000..75f192376
--- /dev/null
+++ b/unstract/core/src/unstract/core/notification_enums.py
@@ -0,0 +1,127 @@
+"""Shared notification enums for Unstract platform.
+
+This module contains notification-related enums that can be used by both
+backend Django services and worker processes for consistent notification handling.
+"""
+
+from enum import Enum
+
+
+class NotificationType(Enum):
+ """Types of notifications supported by the platform."""
+
+ WEBHOOK = "WEBHOOK"
+ EMAIL = "EMAIL" # Future implementation
+ SMS = "SMS" # Future implementation
+ PUSH = "PUSH" # Future implementation
+
+ def get_valid_platforms(self):
+ """Get valid platforms for this notification type."""
+ if self == NotificationType.WEBHOOK:
+ return [PlatformType.SLACK.value, PlatformType.API.value]
+ elif self == NotificationType.EMAIL:
+ return [PlatformType.SMTP.value, PlatformType.SENDGRID.value]
+ elif self == NotificationType.SMS:
+ return [PlatformType.TWILIO.value, PlatformType.AWS_SNS.value]
+ elif self == NotificationType.PUSH:
+ return [PlatformType.FIREBASE.value, PlatformType.APPLE_PUSH.value]
+ return []
+
+ @classmethod
+ def choices(cls):
+ """Get Django-compatible choices."""
+ return [(e.value, e.name.replace("_", " ").capitalize()) for e in cls]
+
+
+class AuthorizationType(Enum):
+ """Authorization types for notifications."""
+
+ BEARER = "BEARER"
+ API_KEY = "API_KEY"
+ CUSTOM_HEADER = "CUSTOM_HEADER"
+ NONE = "NONE"
+
+ @classmethod
+ def choices(cls):
+ """Get Django-compatible choices."""
+ return [(e.value, e.name.replace("_", " ").capitalize()) for e in cls]
+
+
+class PlatformType(Enum):
+ """Platform types for different notification channels."""
+
+ # Webhook platforms
+ SLACK = "SLACK"
+ API = "API"
+ TEAMS = "TEAMS" # Future implementation
+ DISCORD = "DISCORD" # Future implementation
+
+ # Email platforms
+ SMTP = "SMTP" # Future implementation
+ SENDGRID = "SENDGRID" # Future implementation
+ AWS_SES = "AWS_SES" # Future implementation
+
+ # SMS platforms
+ TWILIO = "TWILIO" # Future implementation
+ AWS_SNS = "AWS_SNS" # Future implementation
+
+ # Push notification platforms
+ FIREBASE = "FIREBASE" # Future implementation
+ APPLE_PUSH = "APPLE_PUSH" # Future implementation
+
+ @classmethod
+ def choices(cls):
+ """Get Django-compatible choices."""
+ return [(e.value, e.name.replace("_", " ").capitalize()) for e in cls]
+
+
+class DeliveryStatus(Enum):
+ """Delivery status for notifications."""
+
+ PENDING = "PENDING"
+ QUEUED = "QUEUED"
+ SENDING = "SENDING"
+ SUCCESS = "SUCCESS"
+ FAILED = "FAILED"
+ RETRYING = "RETRYING"
+ CANCELLED = "CANCELLED"
+
+ @classmethod
+ def choices(cls):
+ """Get Django-compatible choices."""
+ return [(e.value, e.name.replace("_", " ").capitalize()) for e in cls]
+
+ def is_final(self) -> bool:
+ """Check if this status represents a final state."""
+ return self in [
+ DeliveryStatus.SUCCESS,
+ DeliveryStatus.FAILED,
+ DeliveryStatus.CANCELLED,
+ ]
+
+ def is_active(self) -> bool:
+ """Check if this status represents an active processing state."""
+ return self in [
+ DeliveryStatus.PENDING,
+ DeliveryStatus.QUEUED,
+ DeliveryStatus.SENDING,
+ DeliveryStatus.RETRYING,
+ ]
+
+
+class NotificationPriority(Enum):
+ """Priority levels for notification processing."""
+
+ LOW = "LOW"
+ NORMAL = "NORMAL"
+ HIGH = "HIGH"
+ URGENT = "URGENT"
+
+ @classmethod
+ def choices(cls):
+ """Get Django-compatible choices."""
+ return [(e.value, e.name.replace("_", " ").capitalize()) for e in cls]
+
+ def get_queue_suffix(self) -> str:
+ """Get queue suffix for this priority level."""
+ return f"_{self.value.lower()}" if self != NotificationPriority.NORMAL else ""
diff --git a/unstract/core/src/unstract/core/notification_utils.py b/unstract/core/src/unstract/core/notification_utils.py
new file mode 100644
index 000000000..e62f6cd34
--- /dev/null
+++ b/unstract/core/src/unstract/core/notification_utils.py
@@ -0,0 +1,261 @@
+"""Shared notification utilities for Unstract platform.
+
+This module contains notification processing utilities that can be used by both
+backend Django services and worker processes for consistent notification handling.
+"""
+
+import logging
+from datetime import datetime
+from typing import Any
+from uuid import UUID
+
+import requests
+
+from unstract.core.notification_enums import AuthorizationType
+
+logger = logging.getLogger(__name__)
+
+# Constants
+APPLICATION_JSON = "application/json"
+
+
+def serialize_notification_data(data: Any) -> Any:
+ """Serialize notification data to handle UUIDs and datetimes.
+
+ Args:
+ data: Data to serialize (dict, list, or primitive)
+
+ Returns:
+ Serialized data safe for JSON encoding
+ """
+ if isinstance(data, UUID):
+ return str(data)
+ elif isinstance(data, datetime):
+ return data.isoformat()
+ elif isinstance(data, dict):
+ return {k: serialize_notification_data(v) for k, v in data.items()}
+ elif isinstance(data, list):
+ return [serialize_notification_data(item) for item in data]
+ return data
+
+
+def build_webhook_headers(
+ authorization_type: str,
+ authorization_key: str | None = None,
+ authorization_header: str | None = None,
+ custom_headers: dict[str, str] | None = None,
+) -> dict[str, str]:
+ """Build headers for webhook notifications based on authorization configuration.
+
+ This function replicates the exact logic from the backend webhook implementation
+ to maintain backward compatibility.
+
+ Args:
+ authorization_type: Type of authorization (BEARER, API_KEY, CUSTOM_HEADER, NONE)
+ authorization_key: Authorization key/token
+ authorization_header: Custom header name (for CUSTOM_HEADER type)
+ custom_headers: Additional custom headers
+
+ Returns:
+ Dictionary of headers for the webhook request
+
+ Raises:
+ ValueError: If authorization configuration is invalid
+ """
+ headers = {"Content-Type": APPLICATION_JSON}
+
+ # Add custom headers if provided
+ if custom_headers:
+ headers.update(custom_headers)
+
+ try:
+ auth_type = AuthorizationType(authorization_type.upper())
+ except ValueError:
+ raise ValueError(f"Unsupported authorization type: {authorization_type}")
+
+ # Header format mapping - identical to backend implementation
+ header_formats = {
+ AuthorizationType.BEARER: lambda key: {
+ "Authorization": f"Bearer {key}",
+ "Content-Type": APPLICATION_JSON,
+ },
+ AuthorizationType.API_KEY: lambda key: {
+ "Authorization": key,
+ "Content-Type": APPLICATION_JSON,
+ },
+ AuthorizationType.CUSTOM_HEADER: lambda key: {
+ authorization_header: key,
+ "Content-Type": APPLICATION_JSON,
+ },
+ AuthorizationType.NONE: lambda _: {
+ "Content-Type": APPLICATION_JSON,
+ },
+ }
+
+ if auth_type not in header_formats:
+ raise ValueError(f"Unsupported authorization type: {auth_type}")
+
+ # Build authorization headers
+ auth_headers = header_formats[auth_type](authorization_key)
+ headers.update(auth_headers)
+
+ # Validate custom header requirements
+ if auth_type == AuthorizationType.CUSTOM_HEADER:
+ if not authorization_header or not authorization_key:
+ raise ValueError("Custom header or key missing for custom authorization.")
+
+ return headers
+
+
+def send_webhook_request(
+ url: str,
+ payload: dict[str, Any],
+ headers: dict[str, str] | None = None,
+ timeout: int = 10,
+ max_retries: int | None = None,
+ retry_delay: int = 10,
+ current_retry: int = 0,
+) -> dict[str, Any]:
+ """Send webhook request with retry logic.
+
+ This function replicates the exact request logic from the backend webhook
+ implementation to maintain backward compatibility.
+
+ Args:
+ url: Target webhook URL
+ payload: JSON payload to send
+ headers: HTTP headers
+ timeout: Request timeout in seconds
+ max_retries: Maximum number of retries
+ retry_delay: Delay between retries in seconds
+ current_retry: Current retry attempt number
+
+ Returns:
+ Dictionary containing request result information
+
+ Raises:
+ requests.exceptions.RequestException: If request fails after all retries
+ """
+ # Serialize payload to handle UUIDs and datetimes
+ serialized_payload = serialize_notification_data(payload)
+
+ try:
+ logger.debug(f"Sending webhook to {url} (attempt {current_retry + 1})")
+
+ response = requests.post(
+ url=url, json=serialized_payload, headers=headers or {}, timeout=timeout
+ )
+
+ # Check response status
+ response.raise_for_status()
+
+ if not (200 <= response.status_code < 300):
+ error_msg = (
+ f"Request to {url} failed with status code {response.status_code}. "
+ f"Response: {response.text}"
+ )
+ logger.error(error_msg)
+ raise requests.exceptions.HTTPError(error_msg, response=response)
+
+ logger.info(
+ f"Webhook sent successfully to {url} (status: {response.status_code})"
+ )
+
+ return {
+ "success": True,
+ "status_code": response.status_code,
+ "response_text": response.text,
+ "attempts": current_retry + 1,
+ "url": url,
+ }
+
+ except requests.exceptions.RequestException as exc:
+ # Handle retries - exact logic from backend implementation
+ if max_retries is not None and current_retry < max_retries:
+ logger.warning(
+ f"Request to {url} failed. Retrying in {retry_delay} seconds. "
+ f"Attempt {current_retry + 1}/{max_retries}. Error: {exc}"
+ )
+
+ # For worker implementation, we'll raise with retry info
+ # The worker retry mechanism will handle the delay
+ raise exc
+ else:
+ error_msg = (
+ f"Failed to send webhook to {url} after {max_retries or 1} attempts. "
+ f"Error: {exc}"
+ )
+ logger.error(error_msg)
+
+ return {
+ "success": False,
+ "error": str(exc),
+ "attempts": current_retry + 1,
+ "url": url,
+ }
+
+
+def validate_webhook_data(
+ url: str | None,
+ payload: dict[str, Any] | None,
+ authorization_type: str | None = None,
+ authorization_key: str | None = None,
+ authorization_header: str | None = None,
+) -> bool:
+ """Validate webhook notification data.
+
+ Args:
+ url: Webhook URL
+ payload: Notification payload
+ authorization_type: Authorization type
+ authorization_key: Authorization key
+ authorization_header: Custom authorization header name
+
+ Returns:
+ True if validation passes
+
+ Raises:
+ ValueError: If validation fails
+ """
+ if not url:
+ raise ValueError("Webhook URL is required.")
+
+ if not payload:
+ raise ValueError("Payload is required.")
+
+ # Validate authorization configuration if provided
+ if authorization_type:
+ try:
+ auth_type = AuthorizationType(authorization_type.upper())
+
+ # Check custom header requirements
+ if auth_type == AuthorizationType.CUSTOM_HEADER:
+ if not authorization_header or not authorization_key:
+ raise ValueError(
+ "Custom header or key missing for custom authorization."
+ )
+
+ except ValueError:
+ raise ValueError(f"Unsupported authorization type: {authorization_type}")
+
+ return True
+
+
+def format_notification_error(
+ error: Exception, notification_type: str, destination: str, attempt: int = 1
+) -> str:
+ """Format notification error message consistently.
+
+ Args:
+ error: Exception that occurred
+ notification_type: Type of notification (WEBHOOK, EMAIL, etc.)
+ destination: Target destination (URL, email, etc.)
+ attempt: Attempt number
+
+ Returns:
+ Formatted error message
+ """
+ return (
+ f"{notification_type} notification failed to {destination} "
+ f"(attempt {attempt}): {str(error)}"
+ )
diff --git a/unstract/core/src/unstract/core/pubsub_helper.py b/unstract/core/src/unstract/core/pubsub_helper.py
index ff3d2b41f..6f96d9f7c 100644
--- a/unstract/core/src/unstract/core/pubsub_helper.py
+++ b/unstract/core/src/unstract/core/pubsub_helper.py
@@ -178,8 +178,8 @@ class LogPublisher:
"""
try:
logs_expiration = os.environ.get(
- "LOGS_EXPIRATION_TIME_IN_SECOND", "86400"
- ) # Defaults to 1 day
+ "LOGS_EXPIRATION_TIME_IN_SECOND", "3600"
+ ) # Defaults to 1 hour
timestamp = payload.get("timestamp", round(time.time(), 6))
redis_key = f"{event}:{timestamp}"
log_data = json.dumps(payload)
diff --git a/unstract/core/src/unstract/core/tool_execution_status.py b/unstract/core/src/unstract/core/tool_execution_status.py
index cf29d32f0..2fadba21e 100644
--- a/unstract/core/src/unstract/core/tool_execution_status.py
+++ b/unstract/core/src/unstract/core/tool_execution_status.py
@@ -1,3 +1,4 @@
+import logging
import os
from dataclasses import dataclass
from enum import Enum
@@ -9,6 +10,8 @@ from unstract.core.exceptions import (
ToolExecutionValueException,
)
+logger = logging.getLogger(__name__)
+
class ToolExecutionStatus(Enum):
RUNNING = "RUNNING"
@@ -178,6 +181,11 @@ class ToolExecutionTracker:
self.redis_client.delete(self.get_cache_key(tool_execution_data))
except ToolExecutionValueException:
return
+ except Exception as e:
+ logger.warning(
+ f"Failed to delete status for tool execution {tool_execution_data.execution_id}: {e}. "
+ )
+ return
def update_ttl(
self, tool_execution_data: ToolExecutionData, ttl_in_second: int
@@ -195,3 +203,8 @@ class ToolExecutionTracker:
)
except ToolExecutionValueException:
return
+ except Exception as e:
+ logger.warning(
+ f"Failed to update TTL for tool execution {tool_execution_data.execution_id}: {e}. "
+ )
+ return
diff --git a/unstract/core/src/unstract/core/worker_base.py b/unstract/core/src/unstract/core/worker_base.py
new file mode 100644
index 000000000..c04ee11da
--- /dev/null
+++ b/unstract/core/src/unstract/core/worker_base.py
@@ -0,0 +1,570 @@
+"""Worker Base Classes and Decorators
+
+This module provides base classes and decorators to reduce code duplication
+across worker implementations and standardize common patterns.
+"""
+
+import logging
+import time
+from abc import ABC, abstractmethod
+from collections.abc import Callable
+from contextlib import contextmanager
+from functools import wraps
+from typing import Any, TypeVar
+
+from .worker_models import (
+ ExecutionStatus,
+ QueueName,
+ TaskError,
+ TaskExecutionContext,
+ TaskName,
+ TaskPerformanceMetrics,
+ TaskRetryConfig,
+ TaskTimeoutConfig,
+)
+
+logger = logging.getLogger(__name__)
+
+# Type variables for generic base classes
+T = TypeVar("T")
+TaskFunc = TypeVar("TaskFunc", bound=Callable[..., Any])
+
+
+class WorkerTaskBase(ABC):
+ """Abstract base class for all worker task implementations.
+
+ Provides common functionality for:
+ - API client management
+ - Organization context handling
+ - Error handling patterns
+ - Performance monitoring
+ - Logging context
+ """
+
+ def __init__(self, config=None):
+ """Initialize base worker task.
+
+ Args:
+ config: Worker configuration instance (optional)
+ """
+ self.config = config
+ self._api_client = None
+ self._current_context: TaskExecutionContext | None = None
+ self.logger = logging.getLogger(self.__class__.__name__)
+
+ @property
+ def api_client(self):
+ """Get API client instance (lazy initialization)."""
+ if self._api_client is None and self.config:
+ from shared.api_client import InternalAPIClient
+
+ self._api_client = InternalAPIClient(self.config)
+ return self._api_client
+
+ def set_organization_context(self, organization_id: str):
+ """Set organization context for API operations."""
+ if self.api_client:
+ self.api_client.set_organization_context(organization_id)
+
+ @contextmanager
+ def task_context(self, context: TaskExecutionContext):
+ """Context manager for task execution with automatic cleanup."""
+ self._current_context = context
+ self.set_organization_context(context.organization_id)
+
+ # Set up structured logging context
+ old_extra = getattr(self.logger, "_extra", {})
+ self.logger._extra = context.get_log_context()
+
+ try:
+ self.logger.info(f"Starting task {context.task_name.value}")
+ yield context
+ except Exception as e:
+ self.logger.error(
+ f"Task {context.task_name.value} failed: {e}",
+ extra={"error_type": type(e).__name__, "error_message": str(e)},
+ )
+ raise
+ finally:
+ self.logger._extra = old_extra
+ self._current_context = None
+
+ @abstractmethod
+ def execute(self, *args, **kwargs) -> Any:
+ """Execute the main task logic.
+
+ This method must be implemented by all task classes.
+ """
+ pass
+
+ def handle_error(
+ self, error: Exception, context: TaskExecutionContext | None = None
+ ) -> TaskError:
+ """Handle task errors with structured error information."""
+ task_context = context or self._current_context
+ if not task_context:
+ raise ValueError("No task context available for error handling")
+
+ task_error = TaskError.from_exception(
+ task_id=task_context.task_id,
+ task_name=task_context.task_name,
+ exception=error,
+ retry_count=task_context.retry_count,
+ )
+
+ self.logger.error(
+ f"Task error: {task_error.error_message}", extra=task_error.to_dict()
+ )
+
+ return task_error
+
+ def update_execution_status(
+ self, execution_id: str, status: ExecutionStatus, error_message: str | None = None
+ ) -> bool:
+ """Update workflow execution status via API."""
+ if not self.api_client:
+ self.logger.warning("No API client available for status update")
+ return False
+
+ try:
+ from .worker_models import WorkflowExecutionUpdateRequest
+
+ update_request = WorkflowExecutionUpdateRequest(
+ status=status, error_message=error_message
+ )
+
+ response = self.api_client.update_workflow_execution_status(
+ execution_id=execution_id, **update_request.to_dict()
+ )
+
+ return response.get("updated", False)
+
+ except Exception as e:
+ self.logger.error(f"Failed to update execution status: {e}")
+ return False
+
+
+class FileProcessingTaskBase(WorkerTaskBase):
+ """Base class for file processing tasks.
+
+ Provides specialized functionality for:
+ - File handling operations
+ - Batch processing patterns
+ - File execution status updates
+ - File history management
+ """
+
+ def __init__(self, config=None):
+ """Initialize file processing task base."""
+ super().__init__(config)
+
+ def update_file_execution_status(
+ self,
+ file_execution_id: str,
+ status: ExecutionStatus,
+ error_message: str | None = None,
+ result: Any | None = None,
+ ) -> bool:
+ """Update file execution status via API."""
+ if not self.api_client:
+ self.logger.warning("No API client available for file status update")
+ return False
+
+ try:
+ from .worker_models import FileExecutionStatusUpdateRequest
+
+ update_request = FileExecutionStatusUpdateRequest(
+ status=status.value, error_message=error_message, result=result
+ )
+
+ response = self.api_client.update_file_execution_status(
+ file_execution_id=file_execution_id, **update_request.to_dict()
+ )
+
+ return response.get("updated", False)
+
+ except Exception as e:
+ self.logger.error(f"Failed to update file execution status: {e}")
+ return False
+
+ def process_file_batch(self, files: list[Any], file_data: Any) -> Any:
+ """Process a batch of files with error handling.
+
+ This method provides a template for batch processing with
+ individual file error handling and status updates.
+ """
+ from .worker_models import BatchExecutionResult, FileExecutionResult
+
+ batch_result = BatchExecutionResult(
+ total_files=len(files), successful_files=0, failed_files=0, execution_time=0.0
+ )
+
+ start_time = time.time()
+
+ for file_item in files:
+ file_start_time = time.time()
+
+ try:
+ # Process individual file (implemented by subclass)
+ result = self.process_single_file(file_item, file_data)
+
+ file_result = FileExecutionResult(
+ file=file_item.get("file_name", "unknown"),
+ file_execution_id=result.get("file_execution_id"),
+ status=ExecutionStatus.COMPLETED,
+ result=result,
+ processing_time=time.time() - file_start_time,
+ )
+
+ batch_result.add_file_result(file_result)
+
+ except Exception as e:
+ file_result = FileExecutionResult(
+ file=file_item.get("file_name", "unknown"),
+ file_execution_id=None,
+ status=ExecutionStatus.ERROR,
+ error=str(e),
+ processing_time=time.time() - file_start_time,
+ )
+
+ batch_result.add_file_result(file_result)
+ self.logger.error(f"Failed to process file {file_item}: {e}")
+
+ batch_result.execution_time = time.time() - start_time
+ return batch_result
+
+ @abstractmethod
+ def process_single_file(self, file_item: Any, file_data: Any) -> Any:
+ """Process a single file.
+
+ Must be implemented by concrete file processing tasks.
+ """
+ pass
+
+
+class CallbackTaskBase(WorkerTaskBase):
+ """Base class for callback tasks.
+
+ Provides specialized functionality for:
+ - Batch result aggregation
+ - Status updates and notifications
+ - Pipeline status mapping
+ - Callback execution context
+ """
+
+ def __init__(self, config=None):
+ """Initialize callback task base."""
+ super().__init__(config)
+ self._cache_manager = None
+
+ @property
+ def cache_manager(self):
+ """Get cache manager instance (lazy initialization)."""
+ if self._cache_manager is None and self.config:
+ from shared.cache_utils import WorkerCacheManager
+
+ self._cache_manager = WorkerCacheManager(self.config)
+ return self._cache_manager
+
+ def update_pipeline_status(
+ self,
+ pipeline_id: str,
+ status: Any, # PipelineStatus from worker_models
+ execution_summary: dict[str, Any] | None = None,
+ ) -> bool:
+ """Update pipeline status via API."""
+ if not self.api_client:
+ self.logger.warning("No API client available for pipeline status update")
+ return False
+
+ try:
+ from .worker_models import PipelineStatusUpdateRequest
+
+ update_request = PipelineStatusUpdateRequest(
+ status=status, execution_summary=execution_summary
+ )
+
+ response = self.api_client.update_pipeline_status(
+ pipeline_id=pipeline_id, **update_request.to_dict()
+ )
+
+ return response.get("updated", False)
+
+ except Exception as e:
+ self.logger.error(f"Failed to update pipeline status: {e}")
+ return False
+
+ def aggregate_batch_results(self, results: list[Any]) -> Any:
+ """Aggregate results from multiple batch executions."""
+ from .worker_models import BatchExecutionResult, CallbackExecutionData
+
+ if not results:
+ return CallbackExecutionData(
+ execution_id="",
+ pipeline_id="",
+ organization_id="",
+ workflow_id="",
+ total_batches=0,
+ completed_batches=0,
+ )
+
+ # Convert results to BatchExecutionResult if needed
+ batch_results = []
+ for result in results:
+ if isinstance(result, dict):
+ batch_results.append(BatchExecutionResult.from_dict(result))
+ elif hasattr(result, "to_dict"):
+ batch_results.append(result)
+ else:
+ self.logger.warning(f"Unknown result type: {type(result)}")
+
+ # Extract common context from first result
+ first_result = batch_results[0] if batch_results else None
+
+ return CallbackExecutionData(
+ execution_id=getattr(first_result, "execution_id", ""),
+ pipeline_id=getattr(first_result, "pipeline_id", ""),
+ organization_id=getattr(first_result, "organization_id", ""),
+ workflow_id=getattr(first_result, "workflow_id", ""),
+ batch_results=batch_results,
+ total_batches=len(results),
+ completed_batches=len([r for r in batch_results if r.total_files > 0]),
+ )
+
+
+# Task Decorators and Helpers
+def create_task_decorator(
+ task_name: TaskName,
+ queue_name: QueueName,
+ retry_config: TaskRetryConfig | None = None,
+ timeout_config: TaskTimeoutConfig | None = None,
+):
+ """Create a standardized Celery task decorator.
+
+ Args:
+ task_name: Standardized task name enum
+ queue_name: Target queue for task execution
+ retry_config: Retry configuration (uses defaults if None)
+ timeout_config: Timeout configuration (uses defaults if None)
+
+ Returns:
+ Configured Celery task decorator
+ """
+ retry_config = retry_config or TaskRetryConfig()
+ timeout_config = timeout_config or TaskTimeoutConfig()
+
+ def decorator(celery_app):
+ """Return the actual decorator that takes the Celery app."""
+
+ def task_decorator(func: TaskFunc) -> TaskFunc:
+ """Decorate the task function."""
+ # Combine all configuration
+ task_kwargs = {
+ "bind": True,
+ "name": task_name.value,
+ "queue": queue_name.value,
+ **retry_config.to_celery_kwargs(),
+ **timeout_config.to_celery_kwargs(),
+ }
+
+ return celery_app.task(**task_kwargs)(func)
+
+ return task_decorator
+
+ return decorator
+
+
+def monitor_performance(func: TaskFunc) -> TaskFunc:
+ """Decorator to monitor task performance metrics.
+
+ Automatically tracks execution time, memory usage, and errors.
+ """
+
+ @wraps(func)
+ def wrapper(self, *args, **kwargs):
+ start_time = time.time()
+ start_memory = None
+
+ try:
+ import psutil
+
+ process = psutil.Process()
+ start_memory = process.memory_info().rss / 1024 / 1024 # MB
+ except ImportError:
+ pass
+
+ task_name = getattr(self.request, "task", func.__name__)
+ retry_count = getattr(self.request, "retries", 0)
+
+ try:
+ result = func(self, *args, **kwargs)
+
+ # Record successful execution metrics
+ execution_time = time.time() - start_time
+ memory_usage = None
+
+ if start_memory is not None:
+ try:
+ end_memory = psutil.Process().memory_info().rss / 1024 / 1024
+ memory_usage = end_memory - start_memory
+ except ImportError:
+ pass
+
+ metrics = TaskPerformanceMetrics(
+ task_name=task_name,
+ execution_time=execution_time,
+ memory_usage=memory_usage,
+ retry_count=retry_count,
+ )
+
+ logger.info(
+ f"Task {task_name} completed successfully", extra=metrics.to_dict()
+ )
+
+ return result
+
+ except Exception as e:
+ # Record error metrics
+ execution_time = time.time() - start_time
+
+ metrics = TaskPerformanceMetrics(
+ task_name=task_name,
+ execution_time=execution_time,
+ error_count=1,
+ retry_count=retry_count,
+ )
+
+ logger.error(f"Task {task_name} failed: {e}", extra=metrics.to_dict())
+
+ raise
+
+ return wrapper
+
+
+def with_task_context(context_factory: Callable[..., TaskExecutionContext]):
+ """Decorator to automatically create and manage task execution context.
+
+ Args:
+ context_factory: Function that creates TaskExecutionContext from task args
+ """
+
+ def decorator(func: TaskFunc) -> TaskFunc:
+ @wraps(func)
+ def wrapper(self, *args, **kwargs):
+ # Create context from task arguments
+ context = context_factory(self, *args, **kwargs)
+
+ # Execute task with context
+ if hasattr(self, "task_context"):
+ with self.task_context(context):
+ return func(self, *args, **kwargs)
+ else:
+ return func(self, *args, **kwargs)
+
+ return wrapper
+
+ return decorator
+
+
+def circuit_breaker(failure_threshold: int = 5, recovery_timeout: float = 120.0):
+ """Decorator to implement circuit breaker pattern for external service calls.
+
+ Args:
+ failure_threshold: Number of failures before opening circuit
+ recovery_timeout: Time to wait before trying to close circuit
+ """
+
+ def decorator(func: TaskFunc) -> TaskFunc:
+ func._circuit_state = "closed" # closed, open, half_open
+ func._failure_count = 0
+ func._last_failure_time = 0
+
+ @wraps(func)
+ def wrapper(*args, **kwargs):
+ current_time = time.time()
+
+ # Check if circuit should transition from open to half_open
+ if (
+ func._circuit_state == "open"
+ and current_time - func._last_failure_time > recovery_timeout
+ ):
+ func._circuit_state = "half_open"
+ logger.info(
+ f"Circuit breaker for {func.__name__} transitioned to half-open"
+ )
+
+ # Reject calls if circuit is open
+ if func._circuit_state == "open":
+ raise Exception(f"Circuit breaker open for {func.__name__}")
+
+ try:
+ result = func(*args, **kwargs)
+
+ # Reset failure count on success
+ if func._circuit_state == "half_open":
+ func._circuit_state = "closed"
+ func._failure_count = 0
+ logger.info(f"Circuit breaker for {func.__name__} closed")
+
+ return result
+
+ except Exception:
+ func._failure_count += 1
+ func._last_failure_time = current_time
+
+ # Open circuit if failure threshold reached
+ if func._failure_count >= failure_threshold:
+ func._circuit_state = "open"
+ logger.warning(
+ f"Circuit breaker for {func.__name__} opened after {func._failure_count} failures"
+ )
+
+ raise
+
+ return wrapper
+
+ return decorator
+
+
+# Task Factory Functions
+def create_file_processing_task(
+ task_name: TaskName,
+ queue_name: QueueName = QueueName.FILE_PROCESSING,
+ retry_config: TaskRetryConfig | None = None,
+) -> Callable:
+ """Factory function to create file processing tasks with standard configuration."""
+
+ class FileProcessingTask(FileProcessingTaskBase):
+ """Generated file processing task class."""
+
+ def execute(self, *args, **kwargs):
+ """Execute file processing logic."""
+ return self.process_file_batch(*args, **kwargs)
+
+ def process_single_file(self, file_item: Any, file_data: Any) -> Any:
+ """Default single file processing (override in specific implementations)."""
+ raise NotImplementedError("process_single_file must be implemented")
+
+ return FileProcessingTask
+
+
+def create_callback_task(
+ task_name: TaskName,
+ queue_name: QueueName = QueueName.CALLBACK,
+ retry_config: TaskRetryConfig | None = None,
+) -> Callable:
+ """Factory function to create callback tasks with standard configuration."""
+
+ class CallbackTask(CallbackTaskBase):
+ """Generated callback task class."""
+
+ def execute(self, results, *args, **kwargs):
+ """Execute callback logic with result aggregation."""
+ callback_data = self.aggregate_batch_results(results)
+ return self.process_callback(callback_data, *args, **kwargs)
+
+ def process_callback(self, callback_data: Any, *args, **kwargs) -> Any:
+ """Default callback processing (override in specific implementations)."""
+ raise NotImplementedError("process_callback must be implemented")
+
+ return CallbackTask
diff --git a/unstract/core/src/unstract/core/worker_models.py b/unstract/core/src/unstract/core/worker_models.py
new file mode 100644
index 000000000..6c77c9836
--- /dev/null
+++ b/unstract/core/src/unstract/core/worker_models.py
@@ -0,0 +1,829 @@
+"""Worker-Specific Data Models and Enums
+
+This module provides worker-specific data models, enums, and base classes
+to replace hardcoded strings and dict patterns in the workers codebase.
+These models extend the core data models with worker-specific functionality.
+"""
+
+import logging
+from dataclasses import dataclass, field
+from datetime import datetime
+from enum import Enum
+from typing import Any
+
+from .data_models import ExecutionStatus, serialize_dataclass_to_dict
+
+logger = logging.getLogger(__name__)
+
+
+# Task and Queue Enums
+class TaskName(str, Enum):
+ """Standardized task names across all workers."""
+
+ # General worker tasks
+ SEND_WEBHOOK_NOTIFICATION = "send_webhook_notification"
+ ASYNC_EXECUTE_BIN_API = "async_execute_bin_api"
+ EXECUTE_WORKFLOW_WITH_FILES = "execute_workflow_with_files"
+ ORCHESTRATE_FILE_PROCESSING = "_orchestrate_file_processing_general"
+
+ # File processing worker tasks
+ PROCESS_FILE_BATCH = "process_file_batch"
+ EXECUTE_SINGLE_FILE = "execute_single_file"
+ UPDATE_FILE_EXECUTION_STATUS = "update_file_execution_status"
+
+ # Callback worker tasks
+ PROCESS_BATCH_CALLBACK = "process_batch_callback"
+ UPDATE_WORKFLOW_EXECUTION_STATUS = "update_workflow_execution_status"
+ UPDATE_PIPELINE_STATUS = "update_pipeline_status"
+
+ # API deployment worker tasks
+ CHECK_API_DEPLOYMENT_STATUS = "check_api_deployment_status"
+
+ def __str__(self):
+ """Return enum value for Celery task naming."""
+ return self.value
+
+
+class QueueName(str, Enum):
+ """Standardized queue names across all workers."""
+
+ GENERAL = "general"
+ FILE_PROCESSING = "file_processing"
+ CALLBACK = "callback"
+ API_DEPLOYMENTS = "api_deployments"
+ WEBHOOK = "webhook"
+
+ # Callback-specific queues
+ FILE_PROCESSING_CALLBACK = "file_processing_callback"
+ GENERAL_CALLBACK = "general_callback"
+
+ def __str__(self):
+ """Return enum value for Celery queue routing."""
+ return self.value
+
+
+class WorkerTaskStatus(str, Enum):
+ """Task execution status for workers."""
+
+ PENDING = "PENDING"
+ STARTED = "STARTED"
+ RETRY = "RETRY"
+ FAILURE = "FAILURE"
+ SUCCESS = "SUCCESS"
+ REVOKED = "REVOKED"
+
+ def __str__(self):
+ """Return enum value for Celery status comparison."""
+ return self.value
+
+
+class PipelineStatus(str, Enum):
+ """Pipeline execution status mapping."""
+
+ SUCCESS = "SUCCESS"
+ FAILURE = "FAILURE"
+ INPROGRESS = "INPROGRESS"
+ YET_TO_START = "YET_TO_START"
+ PARTIAL_SUCCESS = "PARTIAL_SUCCESS"
+
+ def __str__(self):
+ """Return enum value for API updates."""
+ return self.value
+
+
+class WebhookStatus(str, Enum):
+ """Webhook delivery status."""
+
+ DELIVERED = "delivered"
+ QUEUED = "queued"
+ FAILED = "failed"
+ TIMEOUT = "timeout"
+ RETRY = "retry"
+
+ def __str__(self):
+ """Return enum value for webhook tracking."""
+ return self.value
+
+
+class ApiDeploymentResultStatus(str, Enum):
+ """API deployment result status."""
+
+ SUCCESS = "Success"
+ FAILED = "Failed"
+
+
+class NotificationMethod(str, Enum):
+ """Notification delivery methods."""
+
+ WEBHOOK = "webhook"
+ EMAIL = "email"
+ SLACK = "slack"
+ TEAMS = "teams"
+
+ def __str__(self):
+ """Return enum value for notification routing."""
+ return self.value
+
+
+# Status Mapping Utilities
+class StatusMappings:
+ """Utilities for mapping between different status systems."""
+
+ EXECUTION_TO_PIPELINE = {
+ ExecutionStatus.COMPLETED: PipelineStatus.SUCCESS,
+ ExecutionStatus.ERROR: PipelineStatus.FAILURE,
+ ExecutionStatus.STOPPED: PipelineStatus.FAILURE,
+ ExecutionStatus.EXECUTING: PipelineStatus.INPROGRESS,
+ ExecutionStatus.PENDING: PipelineStatus.YET_TO_START,
+ ExecutionStatus.QUEUED: PipelineStatus.YET_TO_START, # Legacy compatibility
+ ExecutionStatus.CANCELED: PipelineStatus.FAILURE, # Legacy compatibility
+ }
+
+ PIPELINE_TO_EXECUTION = {
+ PipelineStatus.SUCCESS: ExecutionStatus.COMPLETED,
+ PipelineStatus.FAILURE: ExecutionStatus.ERROR,
+ PipelineStatus.INPROGRESS: ExecutionStatus.EXECUTING,
+ PipelineStatus.YET_TO_START: ExecutionStatus.PENDING,
+ PipelineStatus.PARTIAL_SUCCESS: ExecutionStatus.COMPLETED,
+ }
+
+ @classmethod
+ def map_execution_to_pipeline(
+ cls, execution_status: ExecutionStatus
+ ) -> PipelineStatus:
+ """Map execution status to pipeline status."""
+ return cls.EXECUTION_TO_PIPELINE.get(execution_status, PipelineStatus.FAILURE)
+
+ @classmethod
+ def map_pipeline_to_execution(
+ cls, pipeline_status: PipelineStatus
+ ) -> ExecutionStatus:
+ """Map pipeline status to execution status."""
+ return cls.PIPELINE_TO_EXECUTION.get(pipeline_status, ExecutionStatus.ERROR)
+
+ @classmethod
+ def is_final_status(cls, status: ExecutionStatus) -> bool:
+ """Check if execution status is final (no further processing)."""
+ return status in [
+ ExecutionStatus.COMPLETED,
+ ExecutionStatus.ERROR,
+ ExecutionStatus.STOPPED,
+ ]
+
+
+# Task Result Data Models
+@dataclass
+class WebhookResult:
+ """Structured result for webhook delivery tasks."""
+
+ status: WebhookStatus
+ url: str
+ task_id: str
+ webhook_task_id: str
+ webhook_status: str
+ payload_size: int
+ timeout: int
+ attempts: int
+ delivery_time: float
+ error_message: str | None = None
+ response_code: int | None = None
+ response_body: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WebhookResult":
+ """Create from dictionary (e.g., task result)."""
+ return cls(
+ status=WebhookStatus(data.get("status", WebhookStatus.FAILED)),
+ url=data.get("url", ""),
+ task_id=data.get("task_id", ""),
+ webhook_task_id=data.get("webhook_task_id", ""),
+ webhook_status=data.get("webhook_status", ""),
+ payload_size=data.get("payload_size", 0),
+ timeout=data.get("timeout", 30),
+ attempts=data.get("attempts", 1),
+ delivery_time=data.get("delivery_time", 0.0),
+ error_message=data.get("error_message"),
+ response_code=data.get("response_code"),
+ response_body=data.get("response_body"),
+ )
+
+
+@dataclass
+class FinalOutputResult:
+ """Structured result for final output tasks."""
+
+ output: Any | None
+ metadata: dict[str, Any] | None
+ error: str | None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "output": self.output,
+ "metadata": self.metadata,
+ "error": self.error,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FinalOutputResult":
+ return cls(
+ output=data.get("output"),
+ metadata=data.get("metadata"),
+ error=data.get("error"),
+ )
+
+
+@dataclass
+class FileExecutionResult:
+ """Structured result for file execution tasks."""
+
+ file: str
+ file_execution_id: str | None
+ status: ApiDeploymentResultStatus
+ error: str | None = None
+ result: Any | None = None
+ metadata: dict[str, Any] | None = None
+ processing_time: float = 0.0
+ file_size: int = 0
+
+ def __post_init__(self) -> None:
+ if self.error:
+ self.status = ApiDeploymentResultStatus.FAILED
+ else:
+ self.status = ApiDeploymentResultStatus.SUCCESS
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ def to_api_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API deployment response with correct status format."""
+ return {
+ "file": self.file,
+ "file_execution_id": self.file_execution_id,
+ "status": self.status.value, # Use API deployment status format
+ "result": self.result,
+ "error": self.error,
+ "metadata": self.metadata,
+ }
+
+ def to_json(self) -> dict[str, Any]:
+ """Convert to JSON-serializable dict for backward compatibility."""
+ return self.to_api_dict()
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FileExecutionResult":
+ """Create from dictionary (e.g., task result)."""
+ # Derive status from presence of error to avoid enum mismatch and be consistent with __post_init__
+ status = (
+ ApiDeploymentResultStatus.FAILED
+ if data.get("error")
+ else ApiDeploymentResultStatus.SUCCESS
+ )
+ return cls(
+ file=data.get("file", ""),
+ file_execution_id=data.get("file_execution_id"),
+ status=status,
+ error=data.get("error"),
+ result=data.get("result"),
+ metadata=data.get("metadata"),
+ processing_time=data.get("processing_time", 0.0),
+ file_size=data.get("file_size", 0),
+ )
+
+ def is_successful(self) -> bool:
+ """Check if file execution was successful."""
+ return self.status == ApiDeploymentResultStatus.SUCCESS
+
+ def has_error(self) -> bool:
+ """Check if file execution had errors."""
+ return self.error is not None or self.status == ApiDeploymentResultStatus.FAILED
+
+
+@dataclass
+class BatchExecutionResult:
+ """Structured result for batch execution tasks."""
+
+ total_files: int
+ successful_files: int
+ failed_files: int
+ execution_time: float
+ file_results: list[FileExecutionResult] = field(default_factory=list)
+ batch_id: str | None = None
+ errors: list[str] = field(default_factory=list)
+
+ @property
+ def success_rate(self) -> float:
+ """Calculate success rate as percentage."""
+ if self.total_files == 0:
+ return 0.0
+ return (self.successful_files / self.total_files) * 100
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "BatchExecutionResult":
+ """Create from dictionary (e.g., task result)."""
+ file_results = [
+ FileExecutionResult.from_dict(result)
+ for result in data.get("file_results", [])
+ ]
+
+ return cls(
+ total_files=data.get("total_files", 0),
+ successful_files=data.get("successful_files", 0),
+ failed_files=data.get("failed_files", 0),
+ execution_time=data.get("execution_time", 0.0),
+ file_results=file_results,
+ batch_id=data.get("batch_id"),
+ errors=data.get("errors", []),
+ )
+
+ def add_file_result(self, file_result: FileExecutionResult):
+ """Add a file execution result to the batch."""
+ self.file_results.append(file_result)
+ self.total_files = len(self.file_results)
+
+ if file_result.is_successful():
+ self.successful_files += 1
+ else:
+ self.failed_files += 1
+
+ self.execution_time += file_result.processing_time
+
+
+@dataclass
+class CallbackExecutionData:
+ """Data structure for callback task execution context."""
+
+ execution_id: str
+ pipeline_id: str
+ organization_id: str
+ workflow_id: str
+ batch_results: list[BatchExecutionResult] = field(default_factory=list)
+ total_batches: int = 0
+ completed_batches: int = 0
+ callback_triggered_at: datetime | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "CallbackExecutionData":
+ """Create from dictionary (e.g., callback kwargs)."""
+ batch_results = [
+ BatchExecutionResult.from_dict(result)
+ for result in data.get("batch_results", [])
+ ]
+
+ return cls(
+ execution_id=data.get("execution_id", ""),
+ pipeline_id=data.get("pipeline_id", ""),
+ organization_id=data.get("organization_id", ""),
+ workflow_id=data.get("workflow_id", ""),
+ batch_results=batch_results,
+ total_batches=data.get("total_batches", 0),
+ completed_batches=data.get("completed_batches", 0),
+ callback_triggered_at=data.get("callback_triggered_at"),
+ )
+
+ @property
+ def total_files_processed(self) -> int:
+ """Calculate total files processed across all batches."""
+ return sum(batch.total_files for batch in self.batch_results)
+
+ @property
+ def total_successful_files(self) -> int:
+ """Calculate total successful files across all batches."""
+ return sum(batch.successful_files for batch in self.batch_results)
+
+ @property
+ def total_failed_files(self) -> int:
+ """Calculate total failed files across all batches."""
+ return sum(batch.failed_files for batch in self.batch_results)
+
+ @property
+ def overall_success_rate(self) -> float:
+ """Calculate overall success rate across all batches."""
+ total = self.total_files_processed
+ if total == 0:
+ return 0.0
+ return (self.total_successful_files / total) * 100
+
+ def determine_final_status(self) -> ExecutionStatus:
+ """Determine final execution status based on batch results."""
+ if not self.batch_results:
+ return ExecutionStatus.ERROR
+
+ total_files = self.total_files_processed
+ successful_files = self.total_successful_files
+
+ if total_files == 0:
+ return ExecutionStatus.ERROR
+ elif successful_files == total_files:
+ return ExecutionStatus.COMPLETED
+ elif successful_files > 0:
+ return ExecutionStatus.COMPLETED # Partial success still marked as completed
+ else:
+ return ExecutionStatus.ERROR
+
+
+# API Request/Response Data Models
+@dataclass
+class WorkflowExecutionUpdateRequest:
+ """Request data for updating workflow execution status."""
+
+ status: ExecutionStatus
+ error_message: str | None = None
+ result: dict[str, Any] | None = None
+ execution_time: float | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ data = {"status": self.status.value}
+ if self.error_message:
+ data["error_message"] = self.error_message
+ if self.result:
+ data["result"] = self.result
+ if self.execution_time:
+ data["execution_time"] = self.execution_time
+ return data
+
+
+@dataclass
+class PipelineStatusUpdateRequest:
+ """Request data for updating pipeline status."""
+
+ status: PipelineStatus
+ last_run_details: dict[str, Any] | None = None
+ execution_summary: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ data = {"status": self.status.value}
+ if self.last_run_details:
+ data["last_run_details"] = self.last_run_details
+ if self.execution_summary:
+ data["execution_summary"] = self.execution_summary
+ return data
+
+
+@dataclass
+class NotificationRequest:
+ """Request data for sending notifications."""
+
+ method: NotificationMethod
+ recipients: list[str]
+ subject: str
+ message: str
+ metadata: dict[str, Any] = field(default_factory=dict)
+ priority: str = "normal" # low, normal, high, urgent
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ return serialize_dataclass_to_dict(self)
+
+
+# Performance Monitoring Data Models
+@dataclass
+class TaskPerformanceMetrics:
+ """Performance metrics for task execution monitoring."""
+
+ task_name: str
+ execution_time: float
+ memory_usage: float | None = None
+ cpu_usage: float | None = None
+ error_count: int = 0
+ retry_count: int = 0
+ timestamp: datetime | None = None
+
+ def __post_init__(self):
+ """Set timestamp if not provided."""
+ if self.timestamp is None:
+ self.timestamp = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for metrics collection."""
+ return serialize_dataclass_to_dict(self)
+
+
+@dataclass
+class WorkerHealthMetrics:
+ """Health metrics for worker instances."""
+
+ worker_name: str
+ worker_version: str
+ uptime: float
+ active_tasks: int
+ completed_tasks: int
+ failed_tasks: int
+ memory_usage: float | None = None
+ cpu_usage: float | None = None
+ last_heartbeat: datetime | None = None
+
+ def __post_init__(self):
+ """Set timestamp if not provided."""
+ if self.last_heartbeat is None:
+ self.last_heartbeat = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for health monitoring."""
+ return serialize_dataclass_to_dict(self)
+
+ @property
+ def success_rate(self) -> float:
+ """Calculate task success rate."""
+ total_tasks = self.completed_tasks + self.failed_tasks
+ if total_tasks == 0:
+ return 100.0
+ return (self.completed_tasks / total_tasks) * 100
+
+
+# Task Context Data Models
+@dataclass
+class TaskExecutionContext:
+ """Execution context for worker tasks."""
+
+ task_id: str
+ task_name: TaskName
+ organization_id: str
+ execution_id: str | None = None
+ workflow_id: str | None = None
+ pipeline_id: str | None = None
+ user_id: str | None = None
+ correlation_id: str | None = None
+ retry_count: int = 0
+ started_at: datetime | None = None
+
+ def __post_init__(self):
+ """Set started_at if not provided."""
+ if self.started_at is None:
+ self.started_at = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for logging and tracing."""
+ return serialize_dataclass_to_dict(self)
+
+ def get_log_context(self) -> dict[str, Any]:
+ """Get context suitable for structured logging."""
+ return {
+ "task_id": self.task_id,
+ "task_name": self.task_name.value,
+ "organization_id": self.organization_id,
+ "execution_id": self.execution_id,
+ "workflow_id": self.workflow_id,
+ "pipeline_id": self.pipeline_id,
+ "retry_count": self.retry_count,
+ }
+
+
+# Configuration Data Models
+@dataclass
+class TaskRetryConfig:
+ """Configuration for task retry behavior."""
+
+ max_retries: int = 3
+ retry_backoff: bool = True
+ retry_backoff_max: int = 500
+ retry_jitter: bool = True
+ autoretry_for: tuple[type, ...] = field(default_factory=lambda: (Exception,))
+
+ def to_celery_kwargs(self) -> dict[str, Any]:
+ """Convert to Celery task decorator kwargs."""
+ return {
+ "max_retries": self.max_retries,
+ "retry_backoff": self.retry_backoff,
+ "retry_backoff_max": self.retry_backoff_max,
+ "retry_jitter": self.retry_jitter,
+ "autoretry_for": self.autoretry_for,
+ }
+
+
+@dataclass
+class TaskTimeoutConfig:
+ """Configuration for task timeout behavior."""
+
+ soft_time_limit: int = 300 # 5 minutes
+ time_limit: int = 330 # 5.5 minutes (30s buffer)
+ task_acks_late: bool = True
+ task_reject_on_worker_lost: bool = True
+
+ def to_celery_kwargs(self) -> dict[str, Any]:
+ """Convert to Celery task decorator kwargs."""
+ return {
+ "soft_time_limit": self.soft_time_limit,
+ "time_limit": self.time_limit,
+ "task_acks_late": self.task_acks_late,
+ "task_reject_on_worker_lost": self.task_reject_on_worker_lost,
+ }
+
+
+# Error Handling Data Models
+@dataclass
+class TaskError:
+ """Structured error information for task failures."""
+
+ task_id: str
+ task_name: TaskName
+ error_type: str
+ error_message: str
+ traceback: str | None = None
+ retry_count: int = 0
+ occurred_at: datetime | None = None
+
+ def __post_init__(self):
+ """Set occurred_at if not provided."""
+ if self.occurred_at is None:
+ self.occurred_at = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for error reporting."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_exception(
+ cls, task_id: str, task_name: TaskName, exception: Exception, retry_count: int = 0
+ ) -> "TaskError":
+ """Create from Python exception."""
+ import traceback as tb
+
+ return cls(
+ task_id=task_id,
+ task_name=task_name,
+ error_type=type(exception).__name__,
+ error_message=str(exception),
+ traceback=tb.format_exc(),
+ retry_count=retry_count,
+ )
+
+
+# Workflow Execution Data Models
+@dataclass
+class WorkflowExecutionMetadata:
+ """Structured metadata for workflow execution."""
+
+ workflow_id: str
+ execution_id: str
+ execution_time: float
+ tool_count: int
+ workflow_executed: bool
+ destination_processed: bool
+ destination_error: str | None = None
+ workflow_type: str | None = None
+ cached: bool = False
+ cache_key: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for backward compatibility."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowExecutionMetadata":
+ """Create from dictionary (e.g., task result)."""
+ return cls(
+ workflow_id=data.get("workflow_id", ""),
+ execution_id=data.get("execution_id", ""),
+ execution_time=data.get("execution_time", 0.0),
+ tool_count=data.get("tool_count", 0),
+ workflow_executed=data.get("workflow_executed", False),
+ destination_processed=data.get("destination_processed", False),
+ destination_error=data.get("destination_error"),
+ workflow_type=data.get("workflow_type"),
+ cached=data.get("cached", False),
+ cache_key=data.get("cache_key"),
+ )
+
+
+@dataclass
+class WorkflowExecutionResult:
+ """Structured result for workflow execution operations."""
+
+ file_execution_id: str
+ file_name: str
+ success: bool
+ error: str | None = None
+ result: Any | None = None
+ source_hash: str | None = None
+ execution_time: float | None = None
+ metadata: WorkflowExecutionMetadata | None = None
+ destination_output: Any | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for backward compatibility."""
+ base_dict = {
+ "file_execution_id": self.file_execution_id,
+ "file": self.file_name,
+ "success": self.success,
+ "error": self.error,
+ "result": self.result,
+ "source_hash": self.source_hash,
+ }
+
+ if self.metadata:
+ base_dict["metadata"] = self.metadata.to_dict()
+
+ if self.destination_output is not None:
+ base_dict["destination_output"] = self.destination_output
+
+ return base_dict
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowExecutionResult":
+ """Create from dictionary (e.g., task result)."""
+ metadata = None
+ if "metadata" in data and data["metadata"]:
+ metadata = WorkflowExecutionMetadata.from_dict(data["metadata"])
+
+ return cls(
+ file_execution_id=data.get("file_execution_id", ""),
+ file_name=data.get("file", ""),
+ success=data.get("success", False),
+ error=data.get("error"),
+ result=data.get("result"),
+ source_hash=data.get("source_hash"),
+ execution_time=data.get("execution_time"),
+ metadata=metadata,
+ destination_output=data.get("destination_output"),
+ )
+
+ def is_successful(self) -> bool:
+ """Check if workflow execution was successful."""
+ return self.success and self.error is None
+
+ def has_error(self) -> bool:
+ """Check if workflow execution had errors."""
+ return not self.success or self.error is not None
+
+
+@dataclass
+class FileProcessingResult:
+ """Structured result for file processing operations."""
+
+ file_name: str
+ file_execution_id: str
+ success: bool
+ error: str | None = None
+ result: dict[str, Any] | None = None
+ metadata: dict[str, Any] = field(default_factory=dict)
+ execution_time: float = 0.0
+
+ # Source indicators (mutually exclusive)
+ from_cache: bool = False
+ from_file_history: bool = False
+
+ # Manual review routing
+ manual_review: bool = False
+ review_result: dict[str, Any] | None = None
+
+ # Destination processing indicators
+ destination_processed: bool = True
+ destination_error: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for backward compatibility."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "FileProcessingResult":
+ """Create from dictionary data."""
+ return cls(
+ file_name=data.get("file", ""),
+ file_execution_id=data.get("file_execution_id", ""),
+ success=not bool(data.get("error")),
+ error=data.get("error"),
+ result=data.get("result"),
+ metadata=data.get("metadata", {}),
+ execution_time=data.get("execution_time", 0.0),
+ from_cache=data.get("from_cache", False),
+ from_file_history=data.get("from_file_history", False),
+ manual_review=data.get("manual_review", False),
+ review_result=data.get("review_result"),
+ destination_processed=data.get("destination_processed", True),
+ destination_error=data.get("destination_error"),
+ )
+
+ def is_successful(self) -> bool:
+ """Check if file processing was successful."""
+ return self.success and self.error is None
+
+ def has_error(self) -> bool:
+ """Check if file processing had errors."""
+ return not self.success or self.error is not None
+
+ def is_from_cache(self) -> bool:
+ """Check if result came from cache."""
+ return self.from_cache
+
+ def is_from_history(self) -> bool:
+ """Check if result came from file history."""
+ return self.from_file_history
+
+ def requires_manual_review(self) -> bool:
+ """Check if file requires manual review."""
+ return self.manual_review
diff --git a/unstract/core/src/unstract/core/workflow_utils.py b/unstract/core/src/unstract/core/workflow_utils.py
new file mode 100644
index 000000000..a81596732
--- /dev/null
+++ b/unstract/core/src/unstract/core/workflow_utils.py
@@ -0,0 +1,369 @@
+"""Workflow utility functions shared between backend and workers.
+
+This module provides common utilities for workflow operations that need
+to be consistent between Django backend and Celery workers.
+"""
+
+import logging
+from typing import Any
+from uuid import UUID
+
+logger = logging.getLogger(__name__)
+
+
+class WorkflowConnectionTypes:
+ """Workflow connection type constants."""
+
+ FILESYSTEM = "FILESYSTEM"
+ DATABASE = "DATABASE"
+ API = "API"
+ APPDEPLOYMENT = "APPDEPLOYMENT"
+ MANUALREVIEW = "MANUALREVIEW"
+
+
+class PipelineTypes:
+ """Pipeline type constants matching backend models."""
+
+ ETL = "ETL"
+ TASK = "TASK"
+ API = "API"
+ APP = "APP"
+ DEFAULT = "DEFAULT"
+
+
+class WorkflowTypeDetector:
+ """Detects workflow and pipeline types using consistent logic.
+
+ This class provides methods to determine workflow types, pipeline types,
+ and connection types that work consistently between backend and workers.
+ """
+
+ @staticmethod
+ def get_pipeline_type_from_response(api_response: Any) -> str:
+ """Extract pipeline type from API response.
+
+ Args:
+ api_response: Response from pipeline-type API endpoint (dict or response object)
+
+ Returns:
+ Pipeline type (API, ETL, TASK, APP, or DEFAULT)
+ """
+ # Handle both new response objects and legacy dict responses
+ if hasattr(api_response, "success"):
+ # New APIResponse object
+ if not api_response.success:
+ raise Exception(
+ f"Pipeline type API failed: {api_response.error or api_response.message}"
+ )
+ response_data = api_response.data or {}
+ else:
+ # Legacy dict response
+ response_data = api_response or {}
+
+ return response_data.get("pipeline_type", PipelineTypes.ETL)
+
+ @staticmethod
+ def is_api_deployment(pipeline_type: str) -> bool:
+ """Check if pipeline type indicates an API deployment.
+
+ Args:
+ pipeline_type: Pipeline type string
+
+ Returns:
+ True if this is an API deployment
+ """
+ return pipeline_type == PipelineTypes.API
+
+ @staticmethod
+ def get_connection_type_from_endpoints(
+ endpoints_response: Any,
+ ) -> tuple[str, bool]:
+ """Determine connection type from workflow endpoints response.
+
+ Args:
+ endpoints_response: Response from workflow endpoints API (dict or dataclass)
+
+ Returns:
+ Tuple of (connection_type, is_api_workflow)
+ """
+ # Handle both dataclass and dict responses
+ if hasattr(endpoints_response, "has_api_endpoints"):
+ # Dataclass response object
+ has_api_endpoints = endpoints_response.has_api_endpoints
+ destination_endpoint = endpoints_response.destination_endpoint
+ else:
+ # Dict response
+ has_api_endpoints = endpoints_response.get("has_api_endpoints", False)
+ destination_endpoint = endpoints_response.get("destination_endpoint", {})
+
+ if has_api_endpoints:
+ return WorkflowConnectionTypes.API, True
+
+ # Check destination endpoint type
+ if hasattr(destination_endpoint, "get"):
+ # Dict format
+ connection_type = destination_endpoint.get(
+ "connection_type", WorkflowConnectionTypes.FILESYSTEM
+ )
+ else:
+ # Object format or None
+ connection_type = (
+ getattr(
+ destination_endpoint,
+ "connection_type",
+ WorkflowConnectionTypes.FILESYSTEM,
+ )
+ if destination_endpoint
+ else WorkflowConnectionTypes.FILESYSTEM
+ )
+
+ # API connection type also indicates API workflow
+ is_api = connection_type == WorkflowConnectionTypes.API
+
+ return connection_type, is_api
+
+ @staticmethod
+ def should_use_api_queue(
+ pipeline_id: str | None, pipeline_type: str, connection_type: str
+ ) -> bool:
+ """Determine if workflow should use API deployment queue.
+
+ Args:
+ pipeline_id: Pipeline ID (may be None)
+ pipeline_type: Pipeline type from API
+ connection_type: Connection type from workflow endpoints
+
+ Returns:
+ True if should use API deployment queue
+ """
+ # API deployments always use API queue
+ if WorkflowTypeDetector.is_api_deployment(pipeline_type):
+ return True
+
+ # Workflows with API connection type use API queue
+ if connection_type == WorkflowConnectionTypes.API:
+ return True
+
+ # All others use general queue
+ return False
+
+ @staticmethod
+ def get_queue_names(is_api_workflow: bool) -> tuple[str, str]:
+ """Get appropriate queue names based on workflow type.
+
+ Args:
+ is_api_workflow: Whether this is an API workflow
+
+ Returns:
+ Tuple of (file_processing_queue, callback_queue)
+ """
+ if is_api_workflow:
+ return "file_processing_lite", "file_processing_callback_lite"
+ else:
+ return "file_processing", "file_processing_callback"
+
+
+class PipelineTypeResolver:
+ """Resolves pipeline types using the improved logic.
+
+ This class encapsulates the logic for determining pipeline types
+ by checking APIDeployment first, then falling back to Pipeline model.
+ """
+
+ def __init__(self, api_client):
+ """Initialize resolver with API client.
+
+ Args:
+ api_client: Internal API client instance
+ """
+ self.api_client = api_client
+ self.logger = logger
+
+ def get_pipeline_type(self, pipeline_id: str | UUID) -> dict[str, Any]:
+ """Get pipeline type with improved logic.
+
+ Checks APIDeployment table first, then Pipeline table.
+ This ensures API deployments are correctly identified even if
+ they also exist in the Pipeline table.
+
+ Args:
+ pipeline_id: Pipeline or API deployment ID
+
+ Returns:
+ Dictionary with pipeline type information
+ """
+ if not pipeline_id:
+ return {
+ "pipeline_type": PipelineTypes.ETL,
+ "source": "default",
+ "error": "No pipeline_id provided",
+ }
+
+ try:
+ # Use the backend's pipeline-type endpoint which already implements
+ # the correct logic (APIDeployment first, then Pipeline)
+ # Pass organization_id to ensure proper access control
+ org_id = self.api_client.organization_id
+ self.logger.debug(
+ f"Getting pipeline type for {pipeline_id} with organization_id: {org_id}"
+ )
+
+ response = self.api_client.get_pipeline_type(
+ pipeline_id, organization_id=org_id
+ )
+
+ # Handle both new response objects and legacy dict responses
+ if hasattr(response, "success"):
+ # New APIResponse object
+ if not response.success:
+ raise Exception(
+ f"Pipeline type API failed: {response.error or response.message}"
+ )
+ response_data = response.data or {}
+ else:
+ # Legacy dict response
+ response_data = response
+
+ # Ensure we have the expected fields
+ return {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_type": response_data.get("pipeline_type", PipelineTypes.ETL),
+ "source": response_data.get("source", "unknown"),
+ "workflow_id": response_data.get("workflow_id"),
+ "display_name": response_data.get("display_name"),
+ "is_active": response_data.get("is_active", True),
+ "is_api_deployment": response_data.get("pipeline_type")
+ == PipelineTypes.API,
+ }
+
+ except Exception as e:
+ # If pipeline not found (404), it's likely a workflow without a pipeline
+ # This is normal for some workflows, so we return a default
+ if "404" in str(e) or "not found" in str(e).lower():
+ self.logger.debug(
+ f"Pipeline {pipeline_id} not found - likely a direct workflow execution"
+ )
+ return {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_type": PipelineTypes.ETL,
+ "source": "not_found",
+ "error": "Pipeline not found - using default ETL type",
+ "is_api_deployment": False,
+ }
+
+ self.logger.error(f"Failed to get pipeline type for {pipeline_id}: {e}")
+ return {
+ "pipeline_id": str(pipeline_id),
+ "pipeline_type": PipelineTypes.ETL,
+ "source": "error",
+ "error": str(e),
+ "is_api_deployment": False,
+ }
+
+ def get_workflow_connection_type(self, workflow_id: str | UUID) -> dict[str, Any]:
+ """Get workflow connection type from endpoints.
+
+ Args:
+ workflow_id: Workflow ID
+
+ Returns:
+ Dictionary with connection type information
+ """
+ try:
+ # Get workflow endpoints to determine connection type
+ endpoints = self.api_client.get_workflow_endpoints(workflow_id)
+
+ connection_type, is_api = (
+ WorkflowTypeDetector.get_connection_type_from_endpoints(endpoints)
+ )
+
+ # Handle both dataclass and dict responses
+ if hasattr(endpoints, "has_api_endpoints"):
+ # Dataclass response
+ has_api_endpoints = endpoints.has_api_endpoints
+ source_endpoint = endpoints.source_endpoint
+ destination_endpoint = endpoints.destination_endpoint
+ else:
+ # Dict response
+ has_api_endpoints = endpoints.get("has_api_endpoints", False)
+ source_endpoint = endpoints.get("source_endpoint")
+ destination_endpoint = endpoints.get("destination_endpoint")
+
+ return {
+ "workflow_id": str(workflow_id),
+ "connection_type": connection_type,
+ "is_api_workflow": is_api,
+ "has_api_endpoints": has_api_endpoints,
+ "source_endpoint": source_endpoint,
+ "destination_endpoint": destination_endpoint,
+ }
+
+ except Exception as e:
+ self.logger.error(
+ f"Failed to get workflow connection type for {workflow_id}: {e}"
+ )
+ return {
+ "workflow_id": str(workflow_id),
+ "connection_type": WorkflowConnectionTypes.FILESYSTEM,
+ "is_api_workflow": False,
+ "error": str(e),
+ }
+
+ def should_route_to_api_worker(
+ self, pipeline_id: str | UUID | None, workflow_id: str | UUID
+ ) -> tuple[bool, dict[str, Any]]:
+ """Determine if execution should be routed to API worker.
+
+ This method intelligently checks workflow endpoints first as the primary method,
+ then pipeline type if available to determine the correct worker routing.
+
+ Args:
+ pipeline_id: Pipeline ID (may be None)
+ workflow_id: Workflow ID
+
+ Returns:
+ Tuple of (should_use_api_worker, routing_info)
+ """
+ routing_info = {
+ "pipeline_id": str(pipeline_id) if pipeline_id else None,
+ "workflow_id": str(workflow_id),
+ "checks_performed": [],
+ }
+
+ # Check 1: Workflow connection type (primary method - always reliable)
+ workflow_info = self.get_workflow_connection_type(workflow_id)
+ routing_info["connection_type"] = workflow_info.get("connection_type")
+ routing_info["has_api_endpoints"] = workflow_info.get("has_api_endpoints")
+ routing_info["checks_performed"].append("workflow_endpoints")
+
+ if workflow_info.get("is_api_workflow"):
+ routing_info["routing_reason"] = "api_connection_type"
+ routing_info["should_use_api_worker"] = True
+ return True, routing_info
+
+ # Check 2: Pipeline type (secondary method - may fail due to backend organization check issues)
+ # Only check if pipeline_id provided and workflow isn't already identified as API
+ if pipeline_id:
+ pipeline_info = self.get_pipeline_type(pipeline_id)
+ routing_info["pipeline_type"] = pipeline_info.get("pipeline_type")
+ routing_info["pipeline_source"] = pipeline_info.get("source")
+ routing_info["checks_performed"].append("pipeline_type")
+
+ # Only consider valid pipeline type responses
+ # Note: 'not_found' may occur due to backend organization validation issues
+ if pipeline_info.get("source") not in ["not_found", "error"]:
+ if pipeline_info.get("is_api_deployment"):
+ routing_info["routing_reason"] = "api_deployment"
+ routing_info["should_use_api_worker"] = True
+ return True, routing_info
+ elif pipeline_info.get("source") == "not_found":
+ # Log this as info, not error, as it may be due to organization validation
+ self.logger.info(
+ f"Pipeline {pipeline_id} not found - may be due to organization validation. "
+ f"Falling back to workflow endpoint detection."
+ )
+
+ # Default: Route to general worker
+ routing_info["routing_reason"] = "general_workflow"
+ routing_info["should_use_api_worker"] = False
+ return False, routing_info
diff --git a/unstract/filesystem/src/unstract/__init__.py b/unstract/filesystem/src/unstract/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/unstract/flags/src/unstract/__init__.py b/unstract/flags/src/unstract/__init__.py
new file mode 100644
index 000000000..a7d65b079
--- /dev/null
+++ b/unstract/flags/src/unstract/__init__.py
@@ -0,0 +1,2 @@
+# Unstract namespace package
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/unstract/tool-registry/src/unstract/__init__.py b/unstract/tool-registry/src/unstract/__init__.py
new file mode 100644
index 000000000..a7d65b079
--- /dev/null
+++ b/unstract/tool-registry/src/unstract/__init__.py
@@ -0,0 +1,2 @@
+# Unstract namespace package
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/unstract/tool-sandbox/src/unstract/__init__.py b/unstract/tool-sandbox/src/unstract/__init__.py
new file mode 100644
index 000000000..a7d65b079
--- /dev/null
+++ b/unstract/tool-sandbox/src/unstract/__init__.py
@@ -0,0 +1,2 @@
+# Unstract namespace package
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py b/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py
index f15303113..091696491 100644
--- a/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py
+++ b/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py
@@ -201,9 +201,7 @@ class ToolSandboxHelper:
f"File execution data not found for execution_id: {self.execution_id} and file_execution_id: {file_execution_id}"
)
file_execution_tracker.set_data(
- execution_id=self.execution_id,
- file_execution_id=file_execution_id,
- file_execution_data=FileExecutionData(
+ data=FileExecutionData(
execution_id=self.execution_id,
file_execution_id=file_execution_id,
organization_id=self.organization_id,
diff --git a/unstract/workflow-execution/src/unstract/__init__.py b/unstract/workflow-execution/src/unstract/__init__.py
new file mode 100644
index 000000000..a7d65b079
--- /dev/null
+++ b/unstract/workflow-execution/src/unstract/__init__.py
@@ -0,0 +1,2 @@
+# Unstract namespace package
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/__init__.py b/unstract/workflow-execution/src/unstract/workflow_execution/__init__.py
index 3a1dcb800..c8a027719 100644
--- a/unstract/workflow-execution/src/unstract/workflow_execution/__init__.py
+++ b/unstract/workflow-execution/src/unstract/workflow_execution/__init__.py
@@ -1,3 +1,9 @@
+from .execution_file_handler import ExecutionFileHandler
+from .metadata_models import WorkflowExecutionMetadata
from .workflow_execution import WorkflowExecutionService
-__all__ = ["WorkflowExecutionService"]
+__all__ = [
+ "WorkflowExecutionService",
+ "ExecutionFileHandler",
+ "WorkflowExecutionMetadata",
+]
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/api_deployment/__init__.py b/unstract/workflow-execution/src/unstract/workflow_execution/api_deployment/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/api_deployment/cache_utils.py b/unstract/workflow-execution/src/unstract/workflow_execution/api_deployment/cache_utils.py
new file mode 100644
index 000000000..85b9a7ad4
--- /dev/null
+++ b/unstract/workflow-execution/src/unstract/workflow_execution/api_deployment/cache_utils.py
@@ -0,0 +1,127 @@
+"""Worker result caching utilities matching backend ResultCacheUtils pattern."""
+
+import json
+import logging
+import os
+from typing import Any
+
+import redis
+
+from unstract.core.worker_models import FileExecutionResult
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerResultCacheUtils:
+ """Worker result caching utilities matching backend ResultCacheUtils pattern."""
+
+ def __init__(self):
+ self.expire_time = int(
+ os.getenv("EXECUTION_RESULT_TTL_SECONDS", "86400")
+ ) # 24 hours default
+ self._redis_client = None
+
+ def _get_redis_client(self):
+ """Get Redis client instance."""
+ if self._redis_client is None:
+ host = os.getenv("REDIS_HOST", "localhost")
+ port = int(os.getenv("REDIS_PORT", "6379"))
+ db = int(os.getenv("REDIS_DB", "0"))
+
+ self._redis_client = redis.Redis(
+ host=host,
+ port=port,
+ db=db,
+ decode_responses=False, # Keep binary for JSON handling
+ socket_connect_timeout=5,
+ socket_timeout=5,
+ )
+
+ return self._redis_client
+
+ def check_redis_health(self, timeout_seconds: float = 2.0) -> bool:
+ """Check if Redis is healthy and accessible."""
+ try:
+ redis_client = self._get_redis_client()
+ redis_client.ping()
+ return True
+ except Exception as e:
+ logger.error(f"Redis health check failed: {e}")
+ raise
+
+ def _get_api_results_cache_key(self, workflow_id: str, execution_id: str) -> str:
+ """Get Redis cache key for api_results matching backend pattern."""
+ return f"api_results:{workflow_id}:{execution_id}"
+
+ def update_api_results(
+ self, workflow_id: str, execution_id: str, api_result: FileExecutionResult
+ ) -> None:
+ """Update api_results in Redis cache matching backend pattern."""
+ try:
+ cache_key = self._get_api_results_cache_key(workflow_id, execution_id)
+ redis_client = self._get_redis_client()
+
+ # Convert result to JSON string (matching backend CacheService.rpush_with_expire)
+ result_json = json.dumps(api_result.to_json())
+
+ # Use Redis pipeline for atomic operation
+ pipe = redis_client.pipeline()
+ pipe.rpush(cache_key, result_json)
+ pipe.expire(cache_key, self.expire_time)
+ pipe.execute()
+
+ logger.info(f"Successfully cached API result for execution {execution_id}")
+
+ except Exception as e:
+ logger.error(f"Failed to cache API result for execution {execution_id}: {e}")
+ # Re-raise to ensure caching failures are visible (fail-fast approach)
+ raise
+
+ def get_api_results(self, workflow_id: str, execution_id: str) -> list:
+ """Get api_results from Redis cache matching backend pattern."""
+ try:
+ cache_key = self._get_api_results_cache_key(workflow_id, execution_id)
+ redis_client = self._get_redis_client()
+
+ # Get all results from Redis list
+ result_strings = redis_client.lrange(cache_key, 0, -1)
+
+ # Convert back to dictionaries
+ results = []
+ for result_string in result_strings:
+ try:
+ result_dict = json.loads(result_string.decode("utf-8"))
+ results.append(result_dict)
+ except Exception as parse_error:
+ logger.error(f"Failed to parse cached result: {parse_error}")
+ continue
+
+ return results
+
+ except Exception as e:
+ logger.error(
+ f"Failed to retrieve API results for execution {execution_id}: {e}"
+ )
+ return []
+
+ def delete_api_results(self, workflow_id: str, execution_id: str) -> None:
+ """Delete api_results from Redis cache matching backend pattern."""
+ try:
+ cache_key = self._get_api_results_cache_key(workflow_id, execution_id)
+ redis_client = self._get_redis_client()
+ redis_client.delete(cache_key)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to delete API results for execution {execution_id}: {e}"
+ )
+
+ @staticmethod
+ def get_cached_result(cache_key: str) -> Any:
+ """Get cached result (legacy method)."""
+ return None
+
+ @staticmethod
+ def cache_result(cache_key: str, result: Any) -> bool:
+ """Cache result (legacy method)."""
+ return True
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/constants.py b/unstract/workflow-execution/src/unstract/workflow_execution/constants.py
index 4021deaba..53f1c8b1b 100644
--- a/unstract/workflow-execution/src/unstract/workflow_execution/constants.py
+++ b/unstract/workflow-execution/src/unstract/workflow_execution/constants.py
@@ -46,6 +46,9 @@ class MetaDataKey:
TOOL_METADATA = "tool_metadata"
TAGS = "tags"
LLM_PROFILE_ID = "llm_profile_id"
+ TOTAL_ELAPSED_TIME = "total_elapsed_time"
+ WORKFLOW_START_TIME = "workflow_start_time"
+ USER_DATA = "user_data"
CUSTOM_DATA = "custom_data"
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/execution_file_handler.py b/unstract/workflow-execution/src/unstract/workflow_execution/execution_file_handler.py
index 9bc46f703..3a836d96e 100644
--- a/unstract/workflow-execution/src/unstract/workflow_execution/execution_file_handler.py
+++ b/unstract/workflow-execution/src/unstract/workflow_execution/execution_file_handler.py
@@ -1,6 +1,7 @@
import json
import logging
import os
+import time
from pathlib import Path
from typing import Any
@@ -136,6 +137,7 @@ class ExecutionFileHandler:
MetaDataKey.EXECUTION_ID: str(self.execution_id),
MetaDataKey.FILE_EXECUTION_ID: str(file_execution_id),
MetaDataKey.TAGS: tags,
+ MetaDataKey.WORKFLOW_START_TIME: time.time(), # Capture workflow start time for accurate timing
}
# Add llm_profile_id to metadata if provided
@@ -238,3 +240,78 @@ class ExecutionFileHandler:
if not self.file_execution_dir:
return None
return os.path.join(self.file_execution_dir, WorkflowFileType.METADATA_JSON)
+
+ def delete_file_execution_directory(self) -> None:
+ """Delete the file execution directory and all its contents.
+
+ This method cleans up temporary files created during workflow execution.
+ It's safe to call even if the directory doesn't exist.
+ """
+ if not self.file_execution_dir:
+ logger.debug("No file execution directory to delete")
+ return
+
+ try:
+ file_path = Path(self.file_execution_dir)
+ if file_path.exists() and file_path.is_dir():
+ import shutil
+
+ shutil.rmtree(file_path)
+ logger.debug(
+ f"Deleted file execution directory: {self.file_execution_dir}"
+ )
+ else:
+ logger.debug(
+ f"File execution directory does not exist: {self.file_execution_dir}"
+ )
+ except Exception as e:
+ logger.warning(
+ f"Failed to delete file execution directory {self.file_execution_dir}: {str(e)}"
+ )
+ # Don't raise exception as cleanup failure shouldn't stop execution
+
+ def update_execution_timing(self, execution_time: float) -> None:
+ """Update METADATA.json with correct workflow execution timing.
+
+ This method reads existing metadata and adds the total_elapsed_time field
+ with the actual workflow execution time measured by workers while preserving
+ tool_metadata written by individual tools.
+
+ Args:
+ execution_time (float): Total execution time in seconds from worker
+ """
+ if not self.metadata_file:
+ raise FileMetadataJsonNotFound()
+
+ try:
+ # Read current metadata (may have been updated by tool execution)
+ existing_metadata = self.get_workflow_metadata()
+
+ # Update with workflow execution timing - this should be the final total time
+ existing_metadata[MetaDataKey.TOTAL_ELAPSED_TIME] = execution_time
+
+ # Write back to file - this ensures our timing is the final update
+ file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ file_storage = file_system.get_file_storage()
+ file_storage.json_dump(path=self.metadata_file, data=existing_metadata)
+
+ logger.info(
+ f"Updated metadata with execution time: {execution_time:.2f}s for {self.file_execution_id}"
+ )
+
+ # Log the current state for debugging
+ if MetaDataKey.TOOL_METADATA in existing_metadata:
+ tool_metadata = existing_metadata[MetaDataKey.TOOL_METADATA]
+ if (
+ tool_metadata
+ and isinstance(tool_metadata, list)
+ and len(tool_metadata) > 0
+ ):
+ tool_time = tool_metadata[-1].get("elapsed_time", 0)
+ logger.info(
+ f"TIMING: Tool internal time: {tool_time:.6f}s, Workflow total time: {execution_time:.3f}s"
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to update execution timing in metadata: {e}")
+ # Don't re-raise - timing update failure shouldn't stop execution
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/metadata_models.py b/unstract/workflow-execution/src/unstract/workflow_execution/metadata_models.py
new file mode 100644
index 000000000..4dd44df30
--- /dev/null
+++ b/unstract/workflow-execution/src/unstract/workflow_execution/metadata_models.py
@@ -0,0 +1,144 @@
+"""Metadata Models for Workflow Execution
+
+This module provides structured dataclasses for workflow execution metadata,
+eliminating hardcoded dictionary creation and providing type safety.
+"""
+
+import logging
+from dataclasses import asdict, dataclass, field
+from typing import Any
+
+from .constants import MetaDataKey
+
+logger = logging.getLogger(__name__)
+
+
+@dataclass
+class WorkflowExecutionMetadata:
+ """Structured metadata for workflow execution.
+
+ This dataclass provides a type-safe way to handle workflow execution metadata,
+ replacing hardcoded dictionary creation with structured data handling.
+ """
+
+ source_name: str
+ source_hash: str
+ organization_id: str
+ workflow_id: str
+ execution_id: str
+ file_execution_id: str
+ tags: list[str]
+ total_elapsed_time: float | None = None
+ tool_metadata: list[dict[str, Any]] = field(default_factory=list)
+ llm_profile_id: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary format for METADATA.json.
+
+ Returns:
+ dict[str, Any]: Dictionary representation compatible with existing format
+ """
+ result = asdict(self)
+ # Remove None values to maintain compatibility with existing code
+ return {k: v for k, v in result.items() if v is not None}
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowExecutionMetadata":
+ """Create metadata instance from existing METADATA.json data.
+
+ Args:
+ data: Dictionary data from METADATA.json
+
+ Returns:
+ WorkflowExecutionMetadata: Structured metadata instance
+ """
+ return cls(
+ source_name=data.get(MetaDataKey.SOURCE_NAME, ""),
+ source_hash=data.get(MetaDataKey.SOURCE_HASH, ""),
+ organization_id=data.get(MetaDataKey.ORGANIZATION_ID, ""),
+ workflow_id=data.get(MetaDataKey.WORKFLOW_ID, ""),
+ execution_id=data.get(MetaDataKey.EXECUTION_ID, ""),
+ file_execution_id=data.get(MetaDataKey.FILE_EXECUTION_ID, ""),
+ tags=data.get(MetaDataKey.TAGS, []),
+ total_elapsed_time=data.get(MetaDataKey.TOTAL_ELAPSED_TIME),
+ tool_metadata=data.get(MetaDataKey.TOOL_METADATA, []),
+ llm_profile_id=data.get(MetaDataKey.LLM_PROFILE_ID),
+ )
+
+ @classmethod
+ def create_initial(
+ cls,
+ source_name: str,
+ source_hash: str,
+ organization_id: str,
+ workflow_id: str,
+ execution_id: str,
+ file_execution_id: str,
+ tags: list[str],
+ llm_profile_id: str | None = None,
+ ) -> "WorkflowExecutionMetadata":
+ """Create initial metadata for workflow execution.
+
+ This is an alternative to the hardcoded dictionary creation in add_metadata_to_volume.
+
+ Args:
+ source_name: Name of the source file
+ source_hash: Hash of the source file
+ organization_id: Organization identifier
+ workflow_id: Workflow identifier
+ execution_id: Execution identifier
+ file_execution_id: File execution identifier
+ tags: List of tags
+ llm_profile_id: Optional LLM profile ID
+
+ Returns:
+ WorkflowExecutionMetadata: Initial metadata instance
+ """
+ return cls(
+ source_name=source_name,
+ source_hash=source_hash,
+ organization_id=organization_id,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ file_execution_id=file_execution_id,
+ tags=tags,
+ llm_profile_id=llm_profile_id,
+ )
+
+ def update_execution_time(self, execution_time: float) -> None:
+ """Update the total execution time.
+
+ Args:
+ execution_time: Total execution time in seconds
+ """
+ self.total_elapsed_time = execution_time
+ logger.debug(
+ f"Updated execution time to {execution_time:.2f}s for {self.file_execution_id}"
+ )
+
+ def add_tool_metadata(self, tool_metadata: dict[str, Any]) -> None:
+ """Add tool metadata to the collection.
+
+ Args:
+ tool_metadata: Metadata for a single tool execution
+ """
+ self.tool_metadata.append(tool_metadata)
+ logger.debug(f"Added tool metadata for {self.file_execution_id}")
+
+ def get_total_elapsed_time(self) -> float:
+ """Get total elapsed time, with fallback to sum of tool times.
+
+ Returns:
+ float: Total elapsed time in seconds
+ """
+ if self.total_elapsed_time is not None:
+ return self.total_elapsed_time
+
+ # Fallback: sum of individual tool elapsed times
+ total = 0.0
+ for tool_meta in self.tool_metadata:
+ elapsed = tool_meta.get("elapsed_time", 0)
+ if isinstance(elapsed, (int, float)):
+ total += elapsed
+
+ return total
diff --git a/unstract/workflow-execution/src/unstract/workflow_execution/workflow_execution.py b/unstract/workflow-execution/src/unstract/workflow_execution/workflow_execution.py
index 966c925c2..0a15a7c72 100644
--- a/unstract/workflow-execution/src/unstract/workflow_execution/workflow_execution.py
+++ b/unstract/workflow-execution/src/unstract/workflow_execution/workflow_execution.py
@@ -344,6 +344,7 @@ class WorkflowExecutionService:
return True
return False
except Exception:
+ logger.error("Error validating execution result ", exc_info=True)
return False
def publish_log(
diff --git a/uv.lock b/uv.lock
index d78743a48..c2dbde6ce 100644
--- a/uv.lock
+++ b/uv.lock
@@ -164,7 +164,7 @@ wheels = [
[[package]]
name = "anthropic"
-version = "0.68.0"
+version = "0.69.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "anyio" },
@@ -176,9 +176,9 @@ dependencies = [
{ name = "sniffio" },
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/64/46/da44bf087ddaf3f7dbe4808c00c7cde466fe68c4fc9fbebdfc231f4ea205/anthropic-0.68.0.tar.gz", hash = "sha256:507e9b5f627d1b249128ff15b21855e718fa4ed8dabc787d0e68860a4b32a7a8", size = 471584, upload-time = "2025-09-17T15:20:19.509Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/c8/9d/9ad1778b95f15c5b04e7d328c1b5f558f1e893857b7c33cd288c19c0057a/anthropic-0.69.0.tar.gz", hash = "sha256:c604d287f4d73640f40bd2c0f3265a2eb6ce034217ead0608f6b07a8bc5ae5f2", size = 480622, upload-time = "2025-09-29T16:53:45.282Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/60/32/2d7553184b05bdbec61dd600014a55b9028408aee6128b25cb6f20e3002c/anthropic-0.68.0-py3-none-any.whl", hash = "sha256:ac579ea5eca22a7165b1042e6af57c4bf556e51afae3ca80e24768d4756b78c0", size = 325199, upload-time = "2025-09-17T15:20:17.452Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/38/75129688de5637eb5b383e5f2b1570a5cc3aecafa4de422da8eea4b90a6c/anthropic-0.69.0-py3-none-any.whl", hash = "sha256:1f73193040f33f11e27c2cd6ec25f24fe7c3f193dc1c5cde6b7a08b18a16bcc5", size = 337265, upload-time = "2025-09-29T16:53:43.686Z" },
]
[package.optional-dependencies]
@@ -383,15 +383,24 @@ wheels = [
[[package]]
name = "beautifulsoup4"
-version = "4.13.5"
+version = "4.14.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "soupsieve" },
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/85/2e/3e5079847e653b1f6dc647aa24549d68c6addb4c595cc0d902d1b19308ad/beautifulsoup4-4.13.5.tar.gz", hash = "sha256:5e70131382930e7c3de33450a2f54a63d5e4b19386eab43a5b34d594268f3695", size = 622954, upload-time = "2025-08-24T14:06:13.168Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/77/e9/df2358efd7659577435e2177bfa69cba6c33216681af51a707193dec162a/beautifulsoup4-4.14.2.tar.gz", hash = "sha256:2a98ab9f944a11acee9cc848508ec28d9228abfd522ef0fad6a02a72e0ded69e", size = 625822, upload-time = "2025-09-29T10:05:42.613Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/04/eb/f4151e0c7377a6e08a38108609ba5cede57986802757848688aeedd1b9e8/beautifulsoup4-4.13.5-py3-none-any.whl", hash = "sha256:642085eaa22233aceadff9c69651bc51e8bf3f874fb6d7104ece2beb24b47c4a", size = 105113, upload-time = "2025-08-24T14:06:14.884Z" },
+ { url = "https://files.pythonhosted.org/packages/94/fe/3aed5d0be4d404d12d36ab97e2f1791424d9ca39c2f754a6285d59a3b01d/beautifulsoup4-4.14.2-py3-none-any.whl", hash = "sha256:5ef6fa3a8cbece8488d66985560f97ed091e22bbc4e9c2338508a9d5de6d4515", size = 106392, upload-time = "2025-09-29T10:05:43.771Z" },
+]
+
+[[package]]
+name = "bidict"
+version = "0.23.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/9a/6e/026678aa5a830e07cd9498a05d3e7e650a4f56a42f267a53d22bcda1bdc9/bidict-0.23.1.tar.gz", hash = "sha256:03069d763bc387bbd20e7d49914e75fc4132a41937fa3405417e1a5a2d006d71", size = 29093, upload-time = "2024-02-18T19:09:05.748Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/99/37/e8730c3587a65eb5645d4aba2d27aae48e8003614d6aaf15dda67f702f1f/bidict-0.23.1-py3-none-any.whl", hash = "sha256:5dae8d4d79b552a71cbabc7deb25dfe8ce710b17ff41711e13010ead2abfc3e5", size = 32764, upload-time = "2024-02-18T19:09:04.156Z" },
]
[[package]]
@@ -1223,7 +1232,7 @@ wheels = [
[[package]]
name = "google-genai"
-version = "1.39.0"
+version = "1.39.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "anyio" },
@@ -1235,9 +1244,9 @@ dependencies = [
{ name = "typing-extensions" },
{ name = "websockets" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/ee/30/eda6ec8d47946ddf25fc193d8a9be6f29296f6659ab4a482607a2cf32552/google_genai-1.39.0.tar.gz", hash = "sha256:995fbe76f3f094ed3a4122f5e5f34e3601b774aa025110a2b013a9a493eb2f81", size = 244435, upload-time = "2025-09-25T21:18:49.286Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/f4/3e/25b88bda07ca237043f1be45d13c49ffbc73f9edf45d3232345802f67197/google_genai-1.39.1.tar.gz", hash = "sha256:4721704b43d170fc3f1b1cb5494bee1a7f7aae20de3a5383cdf6a129139df80b", size = 244631, upload-time = "2025-09-26T20:56:19.5Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/c8/93/781ea98fd1dbf8ffaf78c494e59b6364b086e6cbc7dfbc1b750d92fbbe9e/google_genai-1.39.0-py3-none-any.whl", hash = "sha256:eaba325728ea8b90d6111ff009954f526ee10091badfabc31b84dbfcecdf2d02", size = 244544, upload-time = "2025-09-25T21:18:47.508Z" },
+ { url = "https://files.pythonhosted.org/packages/cb/c3/12c1f386184d2fcd694b73adeabc3714a5ed65c01cc183b4e3727a26b9d1/google_genai-1.39.1-py3-none-any.whl", hash = "sha256:6ca36c7e40db6fcba7049dfdd102c86da326804f34403bd7d90fa613a45e5a78", size = 244681, upload-time = "2025-09-26T20:56:17.527Z" },
]
[[package]]
@@ -1476,7 +1485,7 @@ http2 = [
[[package]]
name = "huggingface-hub"
-version = "0.35.1"
+version = "0.35.3"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "filelock" },
@@ -1488,9 +1497,9 @@ dependencies = [
{ name = "tqdm" },
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/f6/42/0e7be334a6851cd7d51cc11717cb95e89333ebf0064431c0255c56957526/huggingface_hub-0.35.1.tar.gz", hash = "sha256:3585b88c5169c64b7e4214d0e88163d4a709de6d1a502e0cd0459e9ee2c9c572", size = 461374, upload-time = "2025-09-23T13:43:47.074Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/10/7e/a0a97de7c73671863ca6b3f61fa12518caf35db37825e43d63a70956738c/huggingface_hub-0.35.3.tar.gz", hash = "sha256:350932eaa5cc6a4747efae85126ee220e4ef1b54e29d31c3b45c5612ddf0b32a", size = 461798, upload-time = "2025-09-29T14:29:58.625Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f1/60/4acf0c8a3925d9ff491dc08fe84d37e09cfca9c3b885e0db3d4dedb98cea/huggingface_hub-0.35.1-py3-none-any.whl", hash = "sha256:2f0e2709c711e3040e31d3e0418341f7092910f1462dd00350c4e97af47280a8", size = 563340, upload-time = "2025-09-23T13:43:45.343Z" },
+ { url = "https://files.pythonhosted.org/packages/31/a0/651f93d154cb72323358bf2bbae3e642bdb5d2f1bfc874d096f7cb159fa0/huggingface_hub-0.35.3-py3-none-any.whl", hash = "sha256:0e3a01829c19d86d03793e4577816fe3bdfc1602ac62c7fb220d593d351224ba", size = 564262, upload-time = "2025-09-29T14:29:55.813Z" },
]
[[package]]
@@ -2144,20 +2153,21 @@ wheels = [
[[package]]
name = "markupsafe"
-version = "3.0.2"
+version = "3.0.3"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/b2/97/5d42485e71dfc078108a86d6de8fa46db44a1a9295e89c5d6d4a06e23a62/markupsafe-3.0.2.tar.gz", hash = "sha256:ee55d3edf80167e48ea11a923c7386f4669df67d7994554387f84e7d8b0a2bf0", size = 20537, upload-time = "2024-10-18T15:21:54.129Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/7e/99/7690b6d4034fffd95959cbe0c02de8deb3098cc577c67bb6a24fe5d7caa7/markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698", size = 80313, upload-time = "2025-09-27T18:37:40.426Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/22/09/d1f21434c97fc42f09d290cbb6350d44eb12f09cc62c9476effdb33a18aa/MarkupSafe-3.0.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:9778bd8ab0a994ebf6f84c2b949e65736d5575320a17ae8984a77fab08db94cf", size = 14274, upload-time = "2024-10-18T15:21:13.777Z" },
- { url = "https://files.pythonhosted.org/packages/6b/b0/18f76bba336fa5aecf79d45dcd6c806c280ec44538b3c13671d49099fdd0/MarkupSafe-3.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846ade7b71e3536c4e56b386c2a47adf5741d2d8b94ec9dc3e92e5e1ee1e2225", size = 12348, upload-time = "2024-10-18T15:21:14.822Z" },
- { url = "https://files.pythonhosted.org/packages/e0/25/dd5c0f6ac1311e9b40f4af06c78efde0f3b5cbf02502f8ef9501294c425b/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1c99d261bd2d5f6b59325c92c73df481e05e57f19837bdca8413b9eac4bd8028", size = 24149, upload-time = "2024-10-18T15:21:15.642Z" },
- { url = "https://files.pythonhosted.org/packages/f3/f0/89e7aadfb3749d0f52234a0c8c7867877876e0a20b60e2188e9850794c17/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e17c96c14e19278594aa4841ec148115f9c7615a47382ecb6b82bd8fea3ab0c8", size = 23118, upload-time = "2024-10-18T15:21:17.133Z" },
- { url = "https://files.pythonhosted.org/packages/d5/da/f2eeb64c723f5e3777bc081da884b414671982008c47dcc1873d81f625b6/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:88416bd1e65dcea10bc7569faacb2c20ce071dd1f87539ca2ab364bf6231393c", size = 22993, upload-time = "2024-10-18T15:21:18.064Z" },
- { url = "https://files.pythonhosted.org/packages/da/0e/1f32af846df486dce7c227fe0f2398dc7e2e51d4a370508281f3c1c5cddc/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:2181e67807fc2fa785d0592dc2d6206c019b9502410671cc905d132a92866557", size = 24178, upload-time = "2024-10-18T15:21:18.859Z" },
- { url = "https://files.pythonhosted.org/packages/c4/f6/bb3ca0532de8086cbff5f06d137064c8410d10779c4c127e0e47d17c0b71/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:52305740fe773d09cffb16f8ed0427942901f00adedac82ec8b67752f58a1b22", size = 23319, upload-time = "2024-10-18T15:21:19.671Z" },
- { url = "https://files.pythonhosted.org/packages/a2/82/8be4c96ffee03c5b4a034e60a31294daf481e12c7c43ab8e34a1453ee48b/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ad10d3ded218f1039f11a75f8091880239651b52e9bb592ca27de44eed242a48", size = 23352, upload-time = "2024-10-18T15:21:20.971Z" },
- { url = "https://files.pythonhosted.org/packages/51/ae/97827349d3fcffee7e184bdf7f41cd6b88d9919c80f0263ba7acd1bbcb18/MarkupSafe-3.0.2-cp312-cp312-win32.whl", hash = "sha256:0f4ca02bea9a23221c0182836703cbf8930c5e9454bacce27e767509fa286a30", size = 15097, upload-time = "2024-10-18T15:21:22.646Z" },
- { url = "https://files.pythonhosted.org/packages/c1/80/a61f99dc3a936413c3ee4e1eecac96c0da5ed07ad56fd975f1a9da5bc630/MarkupSafe-3.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:8e06879fc22a25ca47312fbe7c8264eb0b662f6db27cb2d3bbbc74b1df4b9b87", size = 15601, upload-time = "2024-10-18T15:21:23.499Z" },
+ { url = "https://files.pythonhosted.org/packages/5a/72/147da192e38635ada20e0a2e1a51cf8823d2119ce8883f7053879c2199b5/markupsafe-3.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d53197da72cc091b024dd97249dfc7794d6a56530370992a5e1a08983ad9230e", size = 11615, upload-time = "2025-09-27T18:36:30.854Z" },
+ { url = "https://files.pythonhosted.org/packages/9a/81/7e4e08678a1f98521201c3079f77db69fb552acd56067661f8c2f534a718/markupsafe-3.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1872df69a4de6aead3491198eaf13810b565bdbeec3ae2dc8780f14458ec73ce", size = 12020, upload-time = "2025-09-27T18:36:31.971Z" },
+ { url = "https://files.pythonhosted.org/packages/1e/2c/799f4742efc39633a1b54a92eec4082e4f815314869865d876824c257c1e/markupsafe-3.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3a7e8ae81ae39e62a41ec302f972ba6ae23a5c5396c8e60113e9066ef893da0d", size = 24332, upload-time = "2025-09-27T18:36:32.813Z" },
+ { url = "https://files.pythonhosted.org/packages/3c/2e/8d0c2ab90a8c1d9a24f0399058ab8519a3279d1bd4289511d74e909f060e/markupsafe-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d6dd0be5b5b189d31db7cda48b91d7e0a9795f31430b7f271219ab30f1d3ac9d", size = 22947, upload-time = "2025-09-27T18:36:33.86Z" },
+ { url = "https://files.pythonhosted.org/packages/2c/54/887f3092a85238093a0b2154bd629c89444f395618842e8b0c41783898ea/markupsafe-3.0.3-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:94c6f0bb423f739146aec64595853541634bde58b2135f27f61c1ffd1cd4d16a", size = 21962, upload-time = "2025-09-27T18:36:35.099Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/2f/336b8c7b6f4a4d95e91119dc8521402461b74a485558d8f238a68312f11c/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:be8813b57049a7dc738189df53d69395eba14fb99345e0a5994914a3864c8a4b", size = 23760, upload-time = "2025-09-27T18:36:36.001Z" },
+ { url = "https://files.pythonhosted.org/packages/32/43/67935f2b7e4982ffb50a4d169b724d74b62a3964bc1a9a527f5ac4f1ee2b/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:83891d0e9fb81a825d9a6d61e3f07550ca70a076484292a70fde82c4b807286f", size = 21529, upload-time = "2025-09-27T18:36:36.906Z" },
+ { url = "https://files.pythonhosted.org/packages/89/e0/4486f11e51bbba8b0c041098859e869e304d1c261e59244baa3d295d47b7/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:77f0643abe7495da77fb436f50f8dab76dbc6e5fd25d39589a0f1fe6548bfa2b", size = 23015, upload-time = "2025-09-27T18:36:37.868Z" },
+ { url = "https://files.pythonhosted.org/packages/2f/e1/78ee7a023dac597a5825441ebd17170785a9dab23de95d2c7508ade94e0e/markupsafe-3.0.3-cp312-cp312-win32.whl", hash = "sha256:d88b440e37a16e651bda4c7c2b930eb586fd15ca7406cb39e211fcff3bf3017d", size = 14540, upload-time = "2025-09-27T18:36:38.761Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/5b/bec5aa9bbbb2c946ca2733ef9c4ca91c91b6a24580193e891b5f7dbe8e1e/markupsafe-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:26a5784ded40c9e318cfc2bdb30fe164bdb8665ded9cd64d500a34fb42067b1c", size = 15105, upload-time = "2025-09-27T18:36:39.701Z" },
+ { url = "https://files.pythonhosted.org/packages/e5/f1/216fc1bbfd74011693a4fd837e7026152e89c4bcf3e77b6692fba9923123/markupsafe-3.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:35add3b638a5d900e807944a078b51922212fb3dedb01633a8defc4b01a3c85f", size = 13906, upload-time = "2025-09-27T18:36:40.689Z" },
]
[[package]]
@@ -2619,6 +2629,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/f8/7c/f7a50d07ae9fa86d2149d4acb2daf61e7c0257b56bc1a24a7fb09c1b70df/pre_commit-3.6.2-py2.py3-none-any.whl", hash = "sha256:ba637c2d7a670c10daedc059f5c49b5bd0aadbccfcd7ec15592cf9665117532c", size = 204185, upload-time = "2024-02-18T18:19:38.953Z" },
]
+[[package]]
+name = "prometheus-client"
+version = "0.23.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/23/53/3edb5d68ecf6b38fcbcc1ad28391117d2a322d9a1a3eff04bfdb184d8c3b/prometheus_client-0.23.1.tar.gz", hash = "sha256:6ae8f9081eaaaf153a2e959d2e6c4f4fb57b12ef76c8c7980202f1e57b48b2ce", size = 80481, upload-time = "2025-09-18T20:47:25.043Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b8/db/14bafcb4af2139e046d03fd00dea7873e48eafe18b7d2797e73d6681f210/prometheus_client-0.23.1-py3-none-any.whl", hash = "sha256:dd1913e6e76b59cfe44e7a4b83e01afc9873c1bdfd2ed8739f1e76aeca115f99", size = 61145, upload-time = "2025-09-18T20:47:23.875Z" },
+]
+
[[package]]
name = "prompt-toolkit"
version = "3.0.52"
@@ -2682,6 +2701,20 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/0c/c1/6aece0ab5209981a70cd186f164c133fdba2f51e124ff92b73de7fd24d78/protobuf-4.25.8-py3-none-any.whl", hash = "sha256:15a0af558aa3b13efef102ae6e4f3efac06f1eea11afb3a57db2901447d9fb59", size = 156757, upload-time = "2025-05-28T14:22:24.135Z" },
]
+[[package]]
+name = "psutil"
+version = "5.9.8"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/90/c7/6dc0a455d111f68ee43f27793971cf03fe29b6ef972042549db29eec39a2/psutil-5.9.8.tar.gz", hash = "sha256:6be126e3225486dff286a8fb9a06246a5253f4c7c53b475ea5f5ac934e64194c", size = 503247, upload-time = "2024-01-19T20:47:09.517Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e7/e3/07ae864a636d70a8a6f58da27cb1179192f1140d5d1da10886ade9405797/psutil-5.9.8-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:aee678c8720623dc456fa20659af736241f575d79429a0e5e9cf88ae0605cc81", size = 248702, upload-time = "2024-01-19T20:47:36.303Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/bd/28c5f553667116b2598b9cc55908ec435cb7f77a34f2bff3e3ca765b0f78/psutil-5.9.8-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8cb6403ce6d8e047495a701dc7c5bd788add903f8986d523e3e20b98b733e421", size = 285242, upload-time = "2024-01-19T20:47:39.65Z" },
+ { url = "https://files.pythonhosted.org/packages/c5/4f/0e22aaa246f96d6ac87fe5ebb9c5a693fbe8877f537a1022527c47ca43c5/psutil-5.9.8-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d06016f7f8625a1825ba3732081d77c94589dca78b7a3fc072194851e88461a4", size = 288191, upload-time = "2024-01-19T20:47:43.078Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/f5/2aa3a4acdc1e5940b59d421742356f133185667dd190b166dbcfcf5d7b43/psutil-5.9.8-cp37-abi3-win32.whl", hash = "sha256:bc56c2a1b0d15aa3eaa5a60c9f3f8e3e565303b465dbf57a1b730e7a2b9844e0", size = 251252, upload-time = "2024-01-19T20:47:52.88Z" },
+ { url = "https://files.pythonhosted.org/packages/93/52/3e39d26feae7df0aa0fd510b14012c3678b36ed068f7d78b8d8784d61f0e/psutil-5.9.8-cp37-abi3-win_amd64.whl", hash = "sha256:8db4c1b57507eef143a15a6884ca10f7c73876cdf5d51e713151c1236a0e68cf", size = 255090, upload-time = "2024-01-19T20:47:56.019Z" },
+ { url = "https://files.pythonhosted.org/packages/05/33/2d74d588408caedd065c2497bdb5ef83ce6082db01289a1e1147f6639802/psutil-5.9.8-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:d16bbddf0693323b8c6123dd804100241da461e41d6e332fb0ba6058f630f8c8", size = 249898, upload-time = "2024-01-19T20:47:59.238Z" },
+]
+
[[package]]
name = "psycopg2-binary"
version = "2.9.9"
@@ -2944,11 +2977,11 @@ wheels = [
[[package]]
name = "pypdf"
-version = "6.1.0"
+version = "6.1.1"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/0b/ac/44d86f16b8ad9b42ea1da4b9aa145be71c89927566d9be87fe74bda1dfef/pypdf-6.1.0.tar.gz", hash = "sha256:0cba440d024da5a2a9304f03cd645346052827b84c5a461c6123e24ed5a3b0b9", size = 5072609, upload-time = "2025-09-21T13:38:39.1Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/a6/85/4c0f12616db83c2e3ef580c3cfa98bd082e88fc8d02e136bad3bede1e3fa/pypdf-6.1.1.tar.gz", hash = "sha256:10f44d49bf2a82e54c3c5ba3cdcbb118f2a44fc57df8ce51d6fb9b1ed9bfbe8b", size = 5074507, upload-time = "2025-09-28T13:29:16.165Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/07/f3/4939b609cfd374e495450b22a0385ee3f531e9aa40e8812e5c405f030c54/pypdf-6.1.0-py3-none-any.whl", hash = "sha256:6b34e4147df20978bf270af19826692e0485431a9d3944617b9533bc77efb695", size = 322468, upload-time = "2025-09-21T13:38:37.467Z" },
+ { url = "https://files.pythonhosted.org/packages/07/ed/adae13756d9dabdddee483fc7712905bb5585fbf6e922b1a19aca3a29cd1/pypdf-6.1.1-py3-none-any.whl", hash = "sha256:7781f99493208a37a7d4275601d883e19af24e62a525c25844d22157c2e4cde7", size = 323455, upload-time = "2025-09-28T13:29:14.392Z" },
]
[[package]]
@@ -3017,6 +3050,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/6a/3e/b68c118422ec867fa7ab88444e1274aa40681c606d59ac27de5a5588f082/python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a", size = 19863, upload-time = "2024-01-23T06:32:58.246Z" },
]
+[[package]]
+name = "python-engineio"
+version = "4.12.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "simple-websocket" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c9/d8/63e5535ab21dc4998ba1cfe13690ccf122883a38f025dca24d6e56c05eba/python_engineio-4.12.3.tar.gz", hash = "sha256:35633e55ec30915e7fc8f7e34ca8d73ee0c080cec8a8cd04faf2d7396f0a7a7a", size = 91910, upload-time = "2025-09-28T06:31:36.765Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d8/f0/c5aa0a69fd9326f013110653543f36ece4913c17921f3e1dbd78e1b423ee/python_engineio-4.12.3-py3-none-any.whl", hash = "sha256:7c099abb2a27ea7ab429c04da86ab2d82698cdd6c52406cb73766fe454feb7e1", size = 59637, upload-time = "2025-09-28T06:31:35.354Z" },
+]
+
[[package]]
name = "python-magic"
version = "0.4.27"
@@ -3026,6 +3071,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/6c/73/9f872cb81fc5c3bb48f7227872c28975f998f3e7c2b1c16e95e6432bbb90/python_magic-0.4.27-py2.py3-none-any.whl", hash = "sha256:c212960ad306f700aa0d01e5d7a325d20548ff97eb9920dcd29513174f0294d3", size = 13840, upload-time = "2022-06-07T20:16:57.763Z" },
]
+[[package]]
+name = "python-socketio"
+version = "5.13.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "bidict" },
+ { name = "python-engineio" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/21/1a/396d50ccf06ee539fa758ce5623b59a9cb27637fc4b2dc07ed08bf495e77/python_socketio-5.13.0.tar.gz", hash = "sha256:ac4e19a0302ae812e23b712ec8b6427ca0521f7c582d6abb096e36e24a263029", size = 121125, upload-time = "2025-04-12T15:46:59.933Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3c/32/b4fb8585d1be0f68bde7e110dffbcf354915f77ad8c778563f0ad9655c02/python_socketio-5.13.0-py3-none-any.whl", hash = "sha256:51f68d6499f2df8524668c24bcec13ba1414117cfb3a90115c559b601ab10caf", size = 77800, upload-time = "2025-04-12T15:46:58.412Z" },
+]
+
[[package]]
name = "python3-openid"
version = "3.2.0"
@@ -3342,6 +3400,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
]
+[[package]]
+name = "simple-websocket"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "wsproto" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b0/d4/bfa032f961103eba93de583b161f0e6a5b63cebb8f2c7d0c6e6efe1e3d2e/simple_websocket-1.1.0.tar.gz", hash = "sha256:7939234e7aa067c534abdab3a9ed933ec9ce4691b0713c78acb195560aa52ae4", size = 17300, upload-time = "2024-10-10T22:39:31.412Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/52/59/0782e51887ac6b07ffd1570e0364cf901ebc36345fea669969d2084baebb/simple_websocket-1.1.0-py3-none-any.whl", hash = "sha256:4af6069630a38ed6c561010f0e11a5bc0d4ca569b36306eb257cd9a192497c8c", size = 13842, upload-time = "2024-10-10T22:39:29.645Z" },
+]
+
[[package]]
name = "singleton-decorator"
version = "1.0.0"
@@ -3831,6 +3901,9 @@ hook-check-django-migrations = [
{ name = "unstract-tool-sandbox" },
{ name = "unstract-workflow-execution" },
]
+workers = [
+ { name = "unstract-workers" },
+]
[package.metadata]
@@ -3873,6 +3946,7 @@ hook-check-django-migrations = [
{ name = "unstract-tool-sandbox", editable = "unstract/tool-sandbox" },
{ name = "unstract-workflow-execution", editable = "unstract/workflow-execution" },
]
+workers = [{ name = "unstract-workers", editable = "workers" }]
[[package]]
name = "unstract-connectors"
@@ -4014,6 +4088,11 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d5/84/d596295fce3a713b1953a4fd7be3be1d788920e5633e28fbea7c7331b68a/unstract_sdk-0.77.3-py3-none-any.whl", hash = "sha256:74e83cbb68eef98fbaecfc83e0cfd2228e5958506e1b51a65fae0d891027aaee", size = 266640, upload-time = "2025-09-22T13:07:34.351Z" },
]
+[package.optional-dependencies]
+azure = [
+ { name = "adlfs" },
+]
+
[[package]]
name = "unstract-tool-registry"
version = "0.0.1"
@@ -4052,6 +4131,75 @@ requires-dist = [
{ name = "unstract-core", editable = "unstract/core" },
]
+[[package]]
+name = "unstract-workers"
+version = "1.0.0"
+source = { editable = "workers" }
+dependencies = [
+ { name = "celery" },
+ { name = "httpx" },
+ { name = "prometheus-client" },
+ { name = "psutil" },
+ { name = "python-dotenv" },
+ { name = "python-socketio" },
+ { name = "redis" },
+ { name = "requests" },
+ { name = "unstract-connectors" },
+ { name = "unstract-core" },
+ { name = "unstract-filesystem" },
+ { name = "unstract-flags" },
+ { name = "unstract-sdk", extra = ["azure"] },
+ { name = "unstract-tool-registry" },
+ { name = "unstract-tool-sandbox" },
+ { name = "unstract-workflow-execution" },
+ { name = "urllib3" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "celery", specifier = ">=5.5.3" },
+ { name = "httpx", specifier = ">=0.27.0" },
+ { name = "prometheus-client", specifier = ">=0.17.0,<1.0.0" },
+ { name = "psutil", specifier = ">=5.9.0,<6.0.0" },
+ { name = "python-dotenv", specifier = ">=1.0.0,<2.0.0" },
+ { name = "python-socketio", specifier = ">=5.9.0" },
+ { name = "redis", specifier = ">=4.5.0,<6.0.0" },
+ { name = "requests", specifier = ">=2.31.0,<3.0.0" },
+ { name = "unstract-connectors", editable = "unstract/connectors" },
+ { name = "unstract-core", editable = "unstract/core" },
+ { name = "unstract-filesystem", editable = "unstract/filesystem" },
+ { name = "unstract-flags", editable = "unstract/flags" },
+ { name = "unstract-sdk", extras = ["azure"], specifier = "~=0.77.3" },
+ { name = "unstract-tool-registry", editable = "unstract/tool-registry" },
+ { name = "unstract-tool-sandbox", editable = "unstract/tool-sandbox" },
+ { name = "unstract-workflow-execution", editable = "unstract/workflow-execution" },
+ { name = "urllib3", specifier = ">=1.26.0" },
+]
+
+[package.metadata.requires-dev]
+deploy = [
+ { name = "opentelemetry-distro" },
+ { name = "opentelemetry-exporter-otlp" },
+]
+dev = [
+ { name = "black", specifier = ">=23.7.0" },
+ { name = "flake8", specifier = ">=6.0.0" },
+ { name = "isort", specifier = ">=5.12.0" },
+ { name = "mypy", specifier = ">=1.5.0" },
+ { name = "pytest", specifier = ">=7.4.0" },
+ { name = "pytest-asyncio", specifier = ">=0.21.0" },
+ { name = "pytest-cov", specifier = ">=4.1.0" },
+ { name = "pytest-mock", specifier = ">=3.11.0" },
+]
+test = [
+ { name = "factory-boy", specifier = ">=3.3.0" },
+ { name = "pytest", specifier = ">=7.4.0" },
+ { name = "pytest-asyncio", specifier = ">=0.21.0" },
+ { name = "pytest-cov", specifier = ">=4.1.0" },
+ { name = "pytest-mock", specifier = ">=3.11.0" },
+ { name = "responses", specifier = ">=0.23.0" },
+]
+
[[package]]
name = "unstract-workflow-execution"
version = "0.0.1"
@@ -4134,7 +4282,7 @@ wheels = [
[[package]]
name = "weaviate-client"
-version = "4.16.10"
+version = "4.17.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "authlib" },
@@ -4145,9 +4293,9 @@ dependencies = [
{ name = "pydantic" },
{ name = "validators" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/f5/59/ff6d910425985e6ae19b17f9f9b1511aafb38cc2a146c9dbb01ffe3e3542/weaviate_client-4.16.10.tar.gz", hash = "sha256:c041e6ae5416b8db8ed53d961722f122b52516175da1d249601a87db327e9288", size = 770181, upload-time = "2025-09-15T15:21:45.091Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/bd/0e/e4582b007427187a9fde55fa575db4b766c81929d2b43a3dd8becce50567/weaviate_client-4.17.0.tar.gz", hash = "sha256:731d58d84b0989df4db399b686357ed285fb95971a492ccca8dec90bb2343c51", size = 769019, upload-time = "2025-09-26T11:20:27.381Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/e8/d6/347df480ba767d241bbf08321da593207d7188028a064568ffaa6cbdd1c1/weaviate_client-4.16.10-py3-none-any.whl", hash = "sha256:a2009530951ca08dc071dd74e13052de9ccc3830e9e57a3f292656efa386d6de", size = 583768, upload-time = "2025-09-15T15:21:43.274Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/c5/2da3a45866da7a935dab8ad07be05dcaee48b3ad4955144583b651929be7/weaviate_client-4.17.0-py3-none-any.whl", hash = "sha256:60e4a355b90537ee1e942ab0b76a94750897a13d9cf13c5a6decbd166d0ca8b5", size = 582763, upload-time = "2025-09-26T11:20:25.864Z" },
]
[[package]]
@@ -4198,6 +4346,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/1f/f6/a933bd70f98e9cf3e08167fc5cd7aaaca49147e48411c0bd5ae701bb2194/wrapt-1.17.3-py3-none-any.whl", hash = "sha256:7171ae35d2c33d326ac19dd8facb1e82e5fd04ef8c6c0e394d7af55a55051c22", size = 23591, upload-time = "2025-08-12T05:53:20.674Z" },
]
+[[package]]
+name = "wsproto"
+version = "1.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "h11" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c9/4a/44d3c295350d776427904d73c189e10aeae66d7f555bb2feee16d1e4ba5a/wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065", size = 53425, upload-time = "2022-08-23T19:58:21.447Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736", size = 24226, upload-time = "2022-08-23T19:58:19.96Z" },
+]
+
[[package]]
name = "yamllint"
version = "1.37.1"
diff --git a/workers/ARCHITECTURE.md b/workers/ARCHITECTURE.md
new file mode 100644
index 000000000..827d1abc2
--- /dev/null
+++ b/workers/ARCHITECTURE.md
@@ -0,0 +1,185 @@
+# Unstract Workers Architecture
+
+## Overview
+
+This package implements lightweight Celery workers that communicate with the Unstract Django backend via internal APIs, eliminating Django ORM dependencies and enabling independent deployment and scaling.
+
+## Architecture Decision
+
+### ✅ **CHOSEN: Clean Microservices Architecture**
+```
+unstract/
+├── workers/ # Independent worker package
+│ ├── shared/ # Common utilities (API client, logging, health)
+│ ├── api_deployment/ # API deployment worker
+│ ├── general/ # General worker (webhooks, general workflows)
+│ ├── file_processing/ # File processing worker
+│ ├── callback/ # Result aggregation and finalization worker
+│ ├── docker/ # Docker configurations
+│ ├── scripts/ # Deployment and management scripts
+│ └── pyproject.toml # Independent package definition
+└── backend/ # Django backend with internal APIs
+```
+
+### ❌ **REJECTED: Backend-Coupled Architecture**
+```
+backend/
+└── workers/ # Workers inside Django backend
+ ├── shared/ # Would still have Django coupling risk
+ └── ... # Tight coupling to backend deployment
+```
+
+## Benefits of Clean Architecture
+
+### 🎯 **Complete Separation**
+- **Zero Django Dependencies**: Workers don't import anything from Django
+- **Independent Packaging**: Own `pyproject.toml` with minimal dependencies
+- **Microservices Alignment**: Follows existing pattern (`platform-service/`, `prompt-service/`)
+
+### 🚀 **Deployment Flexibility**
+- **Independent Versioning**: Workers can be versioned separately from backend
+- **Separate Scaling**: Scale workers independently based on workload
+- **Different Infrastructure**: Workers can run on different machines/containers
+- **Fault Isolation**: Worker failures don't affect Django backend
+
+### 📦 **Resource Efficiency**
+- **Minimal Dependencies**: Only essential packages for task processing
+- **Smaller Images**: Docker images without Django bloat
+- **Faster Startup**: No Django initialization overhead
+- **Lower Memory**: ~50MB vs ~200MB for Django workers
+
+## Communication Pattern
+
+```
+┌─────────────────┐ HTTP API ┌──────────────────┐ ORM/DB ┌──────────────┐
+│ Workers │───────────────→│ Django Backend │─────────────→│ PostgreSQL │
+│ (Lightweight) │ │ (Internal APIs) │ │ Database │
+└─────────────────┘ └──────────────────┘ └──────────────┘
+ │ │
+ ├── Task Coordination ├── Business Logic
+ ├── Error Handling ├── Tool Execution
+ ├── Result Aggregation ├── Database Operations
+ └── Health Monitoring └── Complex Processing
+```
+
+## Worker Responsibilities
+
+### **Lightweight Workers Handle:**
+- Task orchestration and coordination
+- HTTP communication with Django backend
+- Error handling and retry logic
+- Result aggregation and status tracking
+- Health monitoring and metrics collection
+
+### **Django Backend Handles:**
+- Complex business logic (tool execution, file processing pipeline)
+- Database operations and ORM queries
+- Authentication and authorization
+- Multi-tenant organization scoping
+- Integration with external services
+
+## Package Structure
+
+```
+unstract/workers/
+├── __init__.py # Package interface
+├── pyproject.toml # Package definition and dependencies
+├── README.md # Documentation
+├── ARCHITECTURE.md # This file
+├── uv.lock # Dependency lock file
+├── shared/ # Shared infrastructure
+│ ├── __init__.py
+│ ├── api_client.py # Internal API HTTP client
+│ ├── config.py # Configuration management
+│ ├── health.py # Health checking system
+│ ├── logging_utils.py # Structured logging
+│ └── retry_utils.py # Circuit breakers and retry logic
+├── api_deployment/ # API deployment worker
+│ ├── __init__.py
+│ ├── worker.py # Celery app configuration
+│ └── tasks.py # async_execute_bin_api task
+├── general/ # General tasks worker
+│ ├── __init__.py
+│ ├── worker.py # Celery app configuration
+│ └── tasks.py # webhooks, general async_execute_bin
+├── file_processing/ # File processing worker
+│ ├── __init__.py
+│ ├── worker.py # Celery app configuration
+│ └── tasks.py # process_file_batch tasks
+├── callback/ # Result aggregation worker
+│ ├── __init__.py
+│ ├── worker.py # Celery app configuration
+│ └── tasks.py # process_batch_callback tasks
+├── docker/ # Container configurations
+│ ├── api_deployment.Dockerfile
+│ ├── general.Dockerfile
+│ ├── file_processing.Dockerfile
+│ ├── callback.Dockerfile
+│ └── docker-compose.workers.yml
+├── scripts/ # Management scripts
+│ ├── deploy.sh # Deployment automation
+│ └── fix_imports.py # Import path utilities
+├── monitoring/ # Monitoring and metrics
+│ └── prometheus_metrics.py # Prometheus metrics collection
+└── config/ # Configuration
+ └── queue_routing.py # Queue routing and scaling rules
+```
+
+## Development Workflow
+
+### **Setup**
+```bash
+cd unstract/workers
+uv sync # Install dependencies
+```
+
+### **Local Development**
+```bash
+# Run individual worker
+cd api_deployment
+python -m worker
+
+# Run with specific queue
+celery -A worker worker --loglevel=debug -Q celery_api_deployments
+```
+
+### **Testing**
+```bash
+pytest # Run tests
+pytest --cov # Run with coverage
+```
+
+### **Deployment**
+```bash
+# Deploy all workers
+./scripts/deploy.sh --environment production --action deploy
+
+# Deploy specific worker type
+./scripts/deploy.sh --workers file --action deploy
+```
+
+## Migration Path
+
+1. ✅ **Phase 1**: Created lightweight workers alongside existing heavy workers
+2. ✅ **Phase 2**: Implemented file processing and callback workers
+3. ✅ **Phase 3**: Moved to clean microservices architecture
+4. 🔮 **Future**: Gradual traffic migration and deprecation of heavy workers
+
+## Scalability Benefits
+
+### **Independent Scaling**
+- Scale each worker type based on specific workload patterns
+- Different concurrency settings per worker type
+- Auto-scaling rules based on queue depth
+
+### **Resource Optimization**
+- Deploy file processing workers on high-memory nodes
+- Deploy callback workers on standard nodes
+- Deploy API workers with high network bandwidth
+
+### **Fault Tolerance**
+- Worker failures isolated from Django backend
+- Circuit breaker patterns prevent cascade failures
+- Independent health monitoring and recovery
+
+This architecture provides the foundation for a highly scalable, maintainable, and efficient distributed task processing system for the Unstract platform.
diff --git a/workers/OPERATIONS.md b/workers/OPERATIONS.md
new file mode 100644
index 000000000..23faa5ca2
--- /dev/null
+++ b/workers/OPERATIONS.md
@@ -0,0 +1,219 @@
+# Unstract Workers - Operations Guide
+
+This guide consolidates deployment, monitoring, and troubleshooting information for Unstract workers.
+
+## Deployment
+
+### Development Setup
+
+```bash
+# Quick setup for development
+cd /home/ali/projects/unstract/workers
+./scripts/setup.sh --environment development
+
+# Install dependencies
+uv sync
+for dir in api-deployment general file-processing callback; do
+ cd $dir && uv sync && cd ..
+done
+```
+
+### Production Deployment
+
+#### Docker Deployment
+
+```bash
+# Build images
+VERSION=local docker compose -f docker-compose.build.yaml build \
+ worker-api-deployment worker-callback worker-file-processing worker-general
+
+# Run workers
+VERSION=local docker compose --profile workers-new up -d
+```
+
+#### Kubernetes Deployment
+
+```yaml
+# See docker/kubernetes/ for complete manifests
+kubectl apply -f docker/kubernetes/workers/
+```
+
+### Environment Configuration
+
+Copy `sample.env` to `.env` and configure:
+
+**Required:**
+- `INTERNAL_API_BASE_URL`: Backend internal API URL
+- `INTERNAL_SERVICE_API_KEY`: Authentication key
+- `CELERY_BROKER_URL`: Message broker URL
+- `CELERY_RESULT_BACKEND`: Result storage backend
+
+**Worker-Specific:**
+- `[WORKER]_MAX_CONCURRENT_TASKS`: Concurrency limits
+- `[WORKER]_HEALTH_PORT`: Health check ports
+- `[WORKER]_QUEUE`: Queue names
+
+## Monitoring
+
+### Health Checks
+
+```bash
+# Check all workers health
+./scripts/monitor.sh health
+
+# Individual worker health
+curl http://localhost:8080/health # API deployment worker
+curl http://localhost:8081/health # General worker
+curl http://localhost:8082/health # File processing worker
+curl http://localhost:8083/health # Callback worker
+```
+
+### Metrics (Prometheus)
+
+Workers expose metrics on their health ports at `/metrics`:
+- Task execution counts
+- Processing times
+- Queue depths
+- Error rates
+
+### Logging
+
+Workers use structured logging with configurable levels:
+```bash
+export LOG_LEVEL=DEBUG # DEBUG, INFO, WARNING, ERROR
+export LOG_FORMAT=json # json or simple
+```
+
+### Flower Dashboard
+
+```bash
+# Start Flower for task monitoring
+celery -A backend flower --port=5555
+# Access at http://localhost:5555
+```
+
+## Troubleshooting
+
+### Common Issues
+
+#### Workers Not Processing Tasks
+
+1. **Check connectivity:**
+ ```bash
+ # Test Redis/RabbitMQ connection
+ redis-cli ping
+ rabbitmqctl status
+ ```
+
+2. **Verify API access:**
+ ```bash
+ curl -H "X-API-Key: $INTERNAL_SERVICE_API_KEY" \
+ $INTERNAL_API_BASE_URL/v1/health/
+ ```
+
+3. **Check worker logs:**
+ ```bash
+ docker logs unstract-worker-api-deployment-new
+ # Or for local development
+ tail -f logs/api-deployment-worker.log
+ ```
+
+#### Memory Issues
+
+- Adjust `CELERY_WORKER_MAX_TASKS_PER_CHILD` (default: 1000)
+- Configure `[WORKER]_MAX_CONCURRENT_TASKS` based on available memory
+- Enable memory profiling with `ENABLE_MEMORY_PROFILING=true`
+
+#### Task Timeouts
+
+- Increase `CELERY_TASK_TIMEOUT` (default: 300s)
+- Adjust `CELERY_TASK_SOFT_TIMEOUT` (default: 270s)
+- Configure worker-specific timeouts in environment
+
+#### Circuit Breaker Trips
+
+When API calls fail repeatedly:
+- Check `CIRCUIT_BREAKER_FAILURE_THRESHOLD` (default: 5)
+- Adjust `CIRCUIT_BREAKER_RECOVERY_TIMEOUT` (default: 60s)
+- Review backend API logs for errors
+
+### Debug Mode
+
+Enable detailed debugging:
+```bash
+export DEBUG=true
+export LOG_LEVEL=DEBUG
+export CELERY_TASK_ALWAYS_EAGER=true # Run tasks synchronously
+```
+
+### Performance Tuning
+
+#### Concurrency Settings
+```bash
+# Per worker type
+API_DEPLOYMENT_MAX_CONCURRENT_TASKS=5
+GENERAL_MAX_CONCURRENT_TASKS=10
+FILE_PROCESSING_MAX_CONCURRENT_TASKS=4
+CALLBACK_MAX_CONCURRENT_TASKS=3
+```
+
+#### Autoscaling
+```bash
+# Format: max,min
+API_DEPLOYMENT_AUTOSCALE=4,1
+GENERAL_AUTOSCALE=6,2
+FILE_PROCESSING_AUTOSCALE=8,2
+CALLBACK_AUTOSCALE=4,1
+```
+
+#### Connection Pooling
+```bash
+CONNECTION_POOL_SIZE=10
+CONNECTION_POOL_MAX_OVERFLOW=20
+```
+
+## Maintenance
+
+### Log Rotation
+
+Configure log rotation in production:
+```bash
+# /etc/logrotate.d/unstract-workers
+/var/log/unstract/workers/*.log {
+ daily
+ rotate 7
+ compress
+ missingok
+ notifempty
+}
+```
+
+### Backup and Recovery
+
+- Task results are stored in Redis/PostgreSQL
+- Configure `EXECUTION_RESULT_TTL_SECONDS` for retention
+- Enable `ENABLE_TASK_BACKUP=true` for critical workflows
+
+### Upgrading Workers
+
+1. **Rolling update (recommended):**
+ ```bash
+ ./scripts/deploy.sh --environment production --action rolling-update
+ ```
+
+2. **Blue-green deployment:**
+ ```bash
+ # Deploy new version
+ ./scripts/deploy.sh --environment production --action deploy --version new
+ # Switch traffic
+ ./scripts/deploy.sh --environment production --action switch --to new
+ # Remove old version
+ ./scripts/deploy.sh --environment production --action cleanup --version old
+ ```
+
+## Support
+
+- **Documentation**: See README.md for architecture details
+- **Issues**: Report at https://github.com/unstract/unstract/issues
+- **Logs**: Check `/var/log/unstract/workers/` or Docker logs
+- **Metrics**: Access Prometheus at `:9090` and Grafana at `:3000`
diff --git a/workers/README.md b/workers/README.md
new file mode 100644
index 000000000..704ddb41b
--- /dev/null
+++ b/workers/README.md
@@ -0,0 +1,165 @@
+# Unstract Workers
+
+Lightweight Celery workers for distributed task processing in the Unstract platform.
+
+## Overview
+
+Independent, microservices-based workers that communicate with the Unstract backend via internal APIs, providing:
+- **75% memory reduction** compared to Django-based workers
+- **Independent scaling** and deployment
+- **Better fault isolation** and resilience
+- **Simplified dependencies** without Django ORM
+
+## Workers
+
+| Worker | Queue | Purpose |
+|--------|-------|---------|
+| **api-deployment** | `celery_api_deployments` | API workflow deployments and executions |
+| **general** | `celery` | General tasks, webhooks, standard workflows |
+| **file-processing** | `file_processing` | File processing through workflow tools |
+| **callback** | `file_processing_callback` | Result aggregation and workflow finalization |
+
+## Quick Start
+
+### 1. Install Dependencies
+
+```bash
+cd /home/ali/projects/unstract/workers
+uv sync
+
+# Install all workers
+for dir in api-deployment general file-processing callback; do
+ cd $dir && uv sync && cd ..
+done
+```
+
+### 2. Configuration
+
+**Quick Setup (Recommended):**
+```bash
+# Copy environment file
+cp sample.env .env
+
+# Automatic configuration for your development setup
+./setup-dev-env.sh
+```
+
+**Manual Setup:**
+```bash
+# Edit .env based on your setup:
+# 1. Full Docker: DJANGO_APP_BACKEND_URL=http://unstract-backend:8000
+# 2. Backend on host: DJANGO_APP_BACKEND_URL=http://172.17.0.1:8000 (Linux)
+# DJANGO_APP_BACKEND_URL=http://host.docker.internal:8000 (Mac/Win)
+# 3. Local dev: DJANGO_APP_BACKEND_URL=http://localhost:8000
+
+# Or use environment variables
+export INTERNAL_API_BASE_URL="http://localhost:8000/internal"
+export INTERNAL_SERVICE_API_KEY="internal-celery-worker-key-123"
+export CELERY_BROKER_URL="redis://localhost:6379/0"
+```
+
+**Test Configuration:**
+```bash
+python test_backend_connection.py # Verify backend connectivity
+```
+
+### 3. Run Workers
+
+```bash
+# Quick start - run all workers
+./run-worker.sh all
+
+# Or run individual workers
+./run-worker.sh api # API deployment worker
+./run-worker.sh general # General worker
+./run-worker.sh file # File processing worker
+./run-worker.sh callback # Callback worker
+
+# With options
+./run-worker.sh -l DEBUG api # Debug logging
+./run-worker.sh -d general # Background mode
+./run-worker.sh -s # Show status
+./run-worker.sh -k # Kill all
+```
+
+## Health Monitoring
+
+```bash
+# Check worker health
+curl http://localhost:8080/health # API deployment
+curl http://localhost:8081/health # General
+curl http://localhost:8082/health # File processing
+curl http://localhost:8083/health # Callback
+```
+
+## Architecture
+
+See [ARCHITECTURE.md](ARCHITECTURE.md) for detailed architecture decisions and design patterns.
+
+## Operations
+
+For deployment, monitoring, and troubleshooting, see [OPERATIONS.md](OPERATIONS.md).
+
+## Development
+
+### Project Structure
+
+```
+workers/
+├── shared/ # Common utilities and API clients
+│ ├── api_client.py # Main internal API client
+│ ├── clients/ # Modular API clients
+│ ├── config.py # Configuration management
+│ └── utils/ # Helper utilities
+├── api-deployment/ # API workflow deployment worker
+├── general/ # General purpose worker
+├── file-processing/ # File processing worker
+└── callback/ # Callback aggregation worker
+```
+
+### Adding New Workers
+
+1. Create worker directory with `pyproject.toml`
+2. Implement `worker.py` and `tasks.py`
+3. Add to `run-worker.sh` script
+4. Create deployment configurations
+
+### Testing
+
+```bash
+# Run tests
+cd /home/ali/projects/unstract/workers
+uv run pytest
+
+# Test individual worker
+cd api-deployment
+uv run pytest tests/
+```
+
+## Docker Deployment
+
+```bash
+# Build all workers
+VERSION=local docker compose -f docker-compose.build.yaml build \
+ worker-api-deployment worker-callback worker-file-processing worker-general
+
+# Run workers
+VERSION=local docker compose --profile workers-new up -d
+
+# Check status
+docker compose --profile workers-new ps
+
+# View logs
+docker compose --profile workers-new logs -f
+```
+
+## Contributing
+
+1. Follow the architecture principles in [ARCHITECTURE_PRINCIPLES.md](../ARCHITECTURE_PRINCIPLES.md)
+2. Ensure backward compatibility with existing workers
+3. Add tests for new functionality
+4. Update documentation as needed
+
+## License
+
+AGPL-3.0 - See LICENSE file for details
diff --git a/workers/__init__.py b/workers/__init__.py
new file mode 100644
index 000000000..37a0fd67a
--- /dev/null
+++ b/workers/__init__.py
@@ -0,0 +1,19 @@
+"""Unstract Workers Package
+
+Lightweight Celery workers for distributed task processing.
+"""
+
+__version__ = "1.0.0"
+__author__ = "Unstract Team"
+__email__ = "[email protected]"
+
+# Import only shared module to avoid circular imports
+# Individual worker modules are imported as needed
+
+__all__ = [
+ "shared",
+ "api-deployment",
+ "general",
+ "file_processing",
+ "callback",
+]
diff --git a/workers/api-deployment/__init__.py b/workers/api-deployment/__init__.py
new file mode 100644
index 000000000..59c73f8c1
--- /dev/null
+++ b/workers/api-deployment/__init__.py
@@ -0,0 +1,18 @@
+"""API Deployment Worker
+
+Lightweight Celery worker for handling API deployment workflows.
+Uses internal APIs instead of direct Django ORM access.
+
+This worker handles:
+- API deployment workflow executions
+- File batch processing for API deployments
+- Status tracking and error handling
+- API-specific execution logic
+"""
+
+from .tasks import async_execute_bin_api
+from .worker import app as celery_app
+
+__all__ = ["celery_app", "async_execute_bin_api"]
+
+__version__ = "1.0.0"
diff --git a/workers/api-deployment/tasks.py b/workers/api-deployment/tasks.py
new file mode 100644
index 000000000..04ef2de8c
--- /dev/null
+++ b/workers/api-deployment/tasks.py
@@ -0,0 +1,1191 @@
+"""API Deployment Worker Tasks
+
+Exact implementation matching Django backend patterns for API deployment tasks.
+Uses the same patterns as workflow_helper.py and file_execution_tasks.py
+"""
+
+import time
+from typing import Any
+
+from shared.api import InternalAPIClient
+from shared.enums.status_enums import PipelineStatus
+from shared.enums.task_enums import TaskName
+from shared.infrastructure.config import WorkerConfig
+from shared.infrastructure.logging import (
+ WorkerLogger,
+ monitor_performance,
+ with_execution_context,
+)
+from shared.infrastructure.logging.helpers import log_file_info
+from shared.infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+from shared.patterns.retry.utils import retry
+from shared.processing.files import FileProcessingUtils
+from shared.workflow.execution import WorkerExecutionContext, WorkflowOrchestrationUtils
+from shared.workflow.execution.tool_validation import validate_workflow_tool_instances
+from worker import app
+
+from unstract.core.data_models import ExecutionStatus, FileHashData, WorkerFileData
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+def _log_api_statistics_to_ui(
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None,
+ message: str,
+) -> None:
+ """Helper method to log API deployment statistics to UI.
+
+ Args:
+ execution_id: Execution ID for workflow logger
+ organization_id: Organization ID for workflow logger
+ pipeline_id: Pipeline ID for workflow logger
+ message: Message to log to UI
+ """
+ try:
+ workflow_logger = WorkerWorkflowLogger.create_for_api_workflow(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+
+ if workflow_logger:
+ log_file_info(
+ workflow_logger,
+ None, # Execution-level logging for API workflows
+ message,
+ )
+ except Exception as log_error:
+ logger.debug(f"Failed to log API statistics: {log_error}")
+
+
+def _log_api_file_history_statistics(
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None,
+ total_files: int,
+ cached_count: int,
+ use_file_history: bool,
+) -> None:
+ """Helper method to log file history statistics for API deployments.
+
+ Args:
+ execution_id: Execution ID for workflow logger
+ organization_id: Organization ID for workflow logger
+ pipeline_id: Pipeline ID for workflow logger
+ total_files: Total number of files
+ cached_count: Number of cached files
+ use_file_history: Whether file history is enabled
+ """
+ if use_file_history and cached_count > 0:
+ processing_count = total_files - cached_count
+ _log_api_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ message=f"📋 Processing {total_files} files: {cached_count} from cache, {processing_count} new files",
+ )
+ else:
+ _log_api_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ message=f"📋 Processing {total_files} files (file history disabled)",
+ )
+
+
+def _log_api_batch_creation_statistics(
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None,
+ batches: list,
+ total_files: int,
+) -> None:
+ """Helper method to log batch creation statistics for API deployments.
+
+ Args:
+ execution_id: Execution ID for workflow logger
+ organization_id: Organization ID for workflow logger
+ pipeline_id: Pipeline ID for workflow logger
+ batches: List of file batches created
+ total_files: Total number of files
+ """
+ batch_sizes = [len(batch) for batch in batches]
+ avg_batch_size = sum(batch_sizes) / len(batch_sizes) if batch_sizes else 0
+
+ _log_api_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ message=f"📦 Created {len(batches)} API batches for {total_files} files (avg: {avg_batch_size:.1f} files/batch)",
+ )
+
+ if len(batches) > 1:
+ _log_api_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ message=f"📊 API batch sizes: {', '.join(map(str, batch_sizes))}",
+ )
+
+
+@with_execution_context
+def _unified_api_execution(
+ task_instance,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[str, dict | FileHashData],
+ scheduled: bool = False,
+ execution_mode: tuple | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ use_file_history: bool = False,
+ task_type: str = "api",
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """Unified API deployment execution logic.
+
+ This consolidates the duplicate logic from async_execute_bin_api
+ and async_execute_bin methods.
+
+ Args:
+ task_instance: The Celery task instance
+ schema_name: Organization schema name
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ hash_values_of_files: File hash data
+ scheduled: Whether execution is scheduled
+ execution_mode: Execution mode tuple
+ pipeline_id: Pipeline ID (for API deployments)
+ log_events_id: Log events ID
+ use_file_history: Whether to use file history
+ task_type: Type of task (api/legacy) for differentiation
+ **kwargs: Additional keyword arguments
+
+ Returns:
+ Execution result dictionary
+ """
+ try:
+ # Set up execution context using shared utilities
+ organization_id = schema_name
+ config, api_client = WorkerExecutionContext.setup_execution_context(
+ organization_id, execution_id, workflow_id
+ )
+
+ # Log task start with standardized format
+ WorkerExecutionContext.log_task_start(
+ f"unified_api_execution_{task_type}",
+ execution_id,
+ workflow_id,
+ {
+ "pipeline_id": pipeline_id,
+ "scheduled": scheduled,
+ "use_file_history": use_file_history,
+ "files_count": len(hash_values_of_files) if hash_values_of_files else 0,
+ "hitl_queue_name": kwargs.get("hitl_queue_name"),
+ "llm_profile_id": kwargs.get("llm_profile_id"),
+ "custom_data": kwargs.get("custom_data"),
+ },
+ )
+
+ # Convert file hash data using standardized conversion
+ converted_files = FileProcessingUtils.convert_file_hash_data(hash_values_of_files)
+
+ if not converted_files:
+ logger.warning("No valid files to process after conversion")
+ return {
+ "execution_id": execution_id,
+ "status": "COMPLETED",
+ "message": "No files to process",
+ "files_processed": 0,
+ }
+
+ # Validate orchestration parameters
+ WorkflowOrchestrationUtils.validate_orchestration_parameters(
+ execution_id, workflow_id, organization_id, converted_files
+ )
+
+ logger.info(f"Processing {len(converted_files)} files")
+
+ # Execute workflow through direct API orchestration
+ result = _run_workflow_api(
+ api_client=api_client,
+ schema_name=organization_id,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ hash_values_of_files=converted_files, # Changed parameter name
+ scheduled=scheduled,
+ execution_mode=execution_mode,
+ pipeline_id=pipeline_id,
+ use_file_history=use_file_history,
+ task_id=task_instance.request.id, # Add required task_id
+ **kwargs,
+ )
+
+ # Log completion with standardized format
+ WorkerExecutionContext.log_task_completion(
+ f"unified_api_execution_{task_type}",
+ execution_id,
+ True,
+ f"files_processed={len(converted_files)}",
+ )
+
+ # CRITICAL: Clean up StateStore to prevent data leaks between tasks
+ try:
+ from shared.infrastructure.context import StateStore
+
+ StateStore.clear_all()
+ logger.debug("🧹 Cleaned up StateStore context to prevent data leaks")
+ except Exception as cleanup_error:
+ logger.warning(f"Failed to cleanup StateStore context: {cleanup_error}")
+
+ return result
+
+ except Exception as e:
+ logger.error(f"API execution failed: {e}")
+
+ # Handle execution error with standardized pattern
+ if "api_client" in locals():
+ WorkerExecutionContext.handle_execution_error(
+ api_client, execution_id, e, logger, f"api_execution_{task_type}"
+ )
+
+ # Log completion with error
+ WorkerExecutionContext.log_task_completion(
+ f"unified_api_execution_{task_type}",
+ execution_id,
+ False,
+ f"error={str(e)}",
+ )
+
+ # CRITICAL: Clean up StateStore to prevent data leaks between tasks (error path)
+ try:
+ from shared.infrastructure.context import StateStore
+
+ StateStore.clear_all()
+ logger.debug(
+ "🧹 Cleaned up StateStore context to prevent data leaks (error path)"
+ )
+ except Exception as cleanup_error:
+ logger.warning(
+ f"Failed to cleanup StateStore context on error: {cleanup_error}"
+ )
+
+ return {
+ "execution_id": execution_id,
+ "status": "ERROR",
+ "error": str(e),
+ "files_processed": 0,
+ }
+
+
+ bind=True,
+ name=TaskName.ASYNC_EXECUTE_BIN_API,
+ autoretry_for=(Exception,),
+ max_retries=0, # Match Django backend pattern
+ retry_backoff=True,
+ retry_backoff_max=500,
+ retry_jitter=True,
+)
+@monitor_performance
+def async_execute_bin_api(
+ self,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[
+ str, dict | FileHashData
+ ], # Backend sends dicts, we convert to FileHashData
+ scheduled: bool = False,
+ execution_mode: tuple | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ use_file_history: bool = False,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """API deployment workflow execution task.
+
+ This matches exactly the Django backend pattern for API deployments,
+ following the same execution flow as the current system.
+
+ Args:
+ schema_name: Organization schema name
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ hash_values_of_files: File hash data
+ scheduled: Whether execution is scheduled
+ execution_mode: Execution mode tuple
+ pipeline_id: Pipeline ID (for API deployments)
+ log_events_id: Log events ID
+ use_file_history: Whether to use file history
+ Returns:
+ Execution result dictionary
+ """
+ return _unified_api_execution(
+ task_instance=self,
+ schema_name=schema_name,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ hash_values_of_files=hash_values_of_files,
+ scheduled=scheduled,
+ execution_mode=execution_mode,
+ pipeline_id=pipeline_id,
+ log_events_id=log_events_id,
+ use_file_history=use_file_history,
+ task_type="api",
+ **kwargs,
+ )
+
+
+ bind=True,
+ name=TaskName.ASYNC_EXECUTE_BIN,
+ autoretry_for=(Exception,),
+ max_retries=0, # Match Django backend pattern
+ retry_backoff=True,
+ retry_backoff_max=500,
+ retry_jitter=True,
+)
+@monitor_performance
+def async_execute_bin(
+ self,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[
+ str, dict | FileHashData
+ ], # Backend sends dicts, we convert to FileHashData
+ scheduled: bool = False,
+ execution_mode: tuple | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ use_file_history: bool = False,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """API deployment workflow execution task (alias for backend compatibility).
+
+ The backend sends 'async_execute_bin' tasks but we want to handle them
+ as API deployments. This is identical to async_execute_bin_api.
+ """
+ return _unified_api_execution(
+ task_instance=self,
+ schema_name=schema_name,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ hash_values_of_files=hash_values_of_files,
+ scheduled=scheduled,
+ execution_mode=execution_mode,
+ pipeline_id=pipeline_id,
+ log_events_id=log_events_id,
+ use_file_history=use_file_history,
+ task_type="api",
+ **kwargs,
+ )
+
+
+def _run_workflow_api(
+ api_client: InternalAPIClient,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[str, FileHashData], # Already converted in task
+ scheduled: bool,
+ execution_mode: tuple | None,
+ pipeline_id: str | None,
+ use_file_history: bool,
+ task_id: str,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """Run workflow matching the exact pattern from Django backend.
+
+ This follows the same logic as WorkflowHelper.run_workflow() and
+ WorkflowHelper.process_input_files() methods.
+ """
+ total_files = len(hash_values_of_files)
+
+ # TOOL VALIDATION: Validate tool instances before API workflow orchestration
+ # Get workflow execution context to retrieve tool instances
+ execution_response = api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ logger.error(
+ f"Failed to get execution context: {execution_response.error} for execution {execution_id}"
+ )
+ raise Exception(f"Failed to get execution context: {execution_response.error}")
+
+ # TOOL VALIDATION: Validate tool instances before API workflow orchestration
+ # This prevents resource waste on invalid tool configurations
+ validate_workflow_tool_instances(
+ api_client=api_client,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ workflow_type="api",
+ )
+
+ # Update total_files at workflow start
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.EXECUTING.value,
+ total_files=total_files,
+ )
+
+ logger.info(f"Processing {total_files} files for execution {execution_id}")
+
+ if not hash_values_of_files:
+ logger.info(f"Execution {execution_id} no files to process")
+ # Complete immediately with no files
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id, status=ExecutionStatus.COMPLETED.value
+ )
+
+ # Update pipeline status if needed
+ if pipeline_id:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.SUCCESS.value,
+ )
+
+ return {
+ "status": "completed",
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "task_id": task_id,
+ "files_processed": 0,
+ "message": "No files to process",
+ }
+
+ # Check file history if enabled - get both files to process and cached results
+ files_to_process = hash_values_of_files
+ cached_results = {}
+ if use_file_history:
+ files_to_process, cached_results = _check_file_history_api(
+ api_client=api_client,
+ workflow_id=workflow_id,
+ hash_values_of_files=hash_values_of_files,
+ execution_id=execution_id,
+ )
+
+ # Mark cached files as executed and add their results to API cache
+ if cached_results:
+ logger.info(
+ f"Marking {len(cached_results)} files as already executed (cached)"
+ )
+
+ # CRITICAL FIX: Add cached file history results to API results cache
+ # This ensures cached files appear in the final API response
+ # NOTE: This fix is ONLY for API deployments, not for ETL/TASK workflows
+ try:
+ from shared.workflow.execution.service import (
+ WorkerWorkflowExecutionService,
+ )
+
+ # Create workflow service for caching (API deployment only)
+ workflow_service = WorkerWorkflowExecutionService(api_client=api_client)
+
+ for file_hash_str, cached_result in cached_results.items():
+ # Find the corresponding FileHashData object and mark it as executed
+ for hash_data in hash_values_of_files.values():
+ if hash_data.file_hash == file_hash_str:
+ hash_data.is_executed = True
+ logger.info(
+ f"Marked file {hash_data.file_name} as is_executed=True"
+ )
+
+ # Add cached result to API results cache for final response
+ # Parse cached result if it's a JSON string (from file_history storage)
+ cached_result_data = cached_result.get("result")
+ if isinstance(cached_result_data, str):
+ try:
+ import json
+
+ cached_result_data = json.loads(cached_result_data)
+ except (json.JSONDecodeError, TypeError) as e:
+ logger.warning(
+ f"Failed to parse cached result JSON for {hash_data.file_name}: {e}"
+ )
+ # Fallback: try to parse Python string representation (legacy format)
+ try:
+ import ast
+
+ cached_result_data = ast.literal_eval(
+ cached_result_data
+ )
+ logger.info(
+ f"Successfully parsed legacy Python string format for {hash_data.file_name}"
+ )
+ except (ValueError, SyntaxError) as parse_error:
+ logger.warning(
+ f"Failed to parse legacy format for {hash_data.file_name}: {parse_error}"
+ )
+ # Keep as string if all parsing fails
+
+ api_result = {
+ "file": hash_data.file_name,
+ "file_execution_id": hash_data.provider_file_uuid or "",
+ "status": "Success", # Cached results are always successful
+ "result": cached_result_data,
+ "error": None,
+ "metadata": {
+ "processing_time": 0.0, # Cached files take no time
+ "source": "file_history_cache",
+ },
+ }
+
+ # Cache the result for API response aggregation
+ workflow_service.cache_api_result(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ result=api_result,
+ is_api=True,
+ )
+ logger.info(
+ f"Added cached file history result to API results cache: {hash_data.file_name}"
+ )
+ break
+
+ except Exception as cache_error:
+ logger.error(
+ f"Failed to cache file history results for API response: {cache_error}"
+ )
+ # Continue execution - caching failures shouldn't stop the workflow
+
+ # Send ALL files to file worker (both cached and non-cached)
+ # File worker will handle cached files by checking is_executed flag
+ files_to_send = hash_values_of_files # Send all files, not just non-cached ones
+ total_files = len(files_to_send)
+ cached_count = len(cached_results)
+ if use_file_history:
+ logger.info(
+ f"Sending {total_files} files to file worker: {cached_count} cached, {total_files - cached_count} to process"
+ )
+ else:
+ logger.info(f"Sending {total_files} files to file worker (file history disabled)")
+
+ # Log file history statistics to UI
+ _log_api_file_history_statistics(
+ execution_id=execution_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ total_files=total_files,
+ cached_count=cached_count,
+ use_file_history=use_file_history,
+ )
+
+ # Get file batches using the exact same logic as Django backend with organization-specific config
+ batches = _get_file_batches(
+ input_files=files_to_send,
+ organization_id=schema_name, # schema_name is the organization_id
+ api_client=api_client,
+ )
+ logger.info(
+ f"Execution {execution_id} processing {total_files} files in {len(batches)} batches"
+ )
+
+ # Log batch creation statistics to UI
+ _log_api_batch_creation_statistics(
+ execution_id=execution_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ batches=batches,
+ total_files=total_files,
+ )
+
+ # Create batch tasks following the exact Django pattern
+ batch_tasks = []
+ execution_mode_str = (
+ (execution_mode[1] if isinstance(execution_mode, tuple) else str(execution_mode))
+ if execution_mode
+ else None
+ )
+
+ for batch_index, batch in enumerate(batches):
+ # Create file data exactly matching Django FileBatchData structure
+ file_data = _create_file_data(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ scheduled=scheduled,
+ execution_mode=execution_mode_str,
+ use_file_history=use_file_history,
+ api_client=api_client,
+ total_files=total_files,
+ **kwargs,
+ )
+
+ # Calculate manual review decisions for this specific batch
+ if file_data.manual_review_config.get("review_required", False):
+ file_decisions = _calculate_manual_review_decisions_for_batch_api(
+ batch=batch, manual_review_config=file_data.manual_review_config
+ )
+ # Update the file_data with batch-specific decisions
+ file_data.manual_review_config["file_decisions"] = file_decisions
+ logger.info(
+ f"Calculated manual review decisions for API batch: {sum(file_decisions)}/{len(file_decisions)} files selected"
+ )
+
+ # Determine queue using the same logic as Django backend
+ file_processing_queue = _get_queue_name_api()
+
+ # Create batch data exactly matching Django FileBatchData structure
+ batch_data = _create_batch_data(files=batch, file_data=file_data)
+
+ # Create task signature matching Django backend pattern
+ batch_tasks.append(
+ app.signature(
+ "process_file_batch",
+ args=[batch_data],
+ queue=file_processing_queue,
+ )
+ )
+
+ try:
+ # Create callback queue using same logic as Django backend
+ file_processing_callback_queue = _get_callback_queue_name_api()
+
+ # Execute chord exactly matching Django pattern
+ from celery import chord
+
+ result = chord(batch_tasks)(
+ app.signature(
+ "process_batch_callback_api", # Use API-specific callback
+ kwargs={
+ "execution_id": str(execution_id),
+ "pipeline_id": str(pipeline_id) if pipeline_id else None,
+ "organization_id": str(schema_name),
+ }, # Pass required parameters for API callback
+ queue=file_processing_callback_queue,
+ )
+ )
+
+ if not result:
+ exception = f"Failed to queue execution task {execution_id}"
+ logger.error(exception)
+ raise Exception(exception)
+
+ logger.info(f"Execution {execution_id} task queued successfully")
+
+ return {
+ "status": "orchestrated",
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "task_id": task_id,
+ "files_processed": total_files,
+ "files_from_cache": len(cached_results),
+ "batches_created": len(batches),
+ "chord_id": result.id,
+ "cached_results": list(cached_results.keys())
+ if cached_results
+ else [], # Include cache info
+ "message": f"File processing orchestrated: {total_files} files processing, {len(cached_results)} from cache",
+ }
+
+ except Exception as e:
+ # Update execution to ERROR status matching Django pattern
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=f"Error while processing files: {str(e)}",
+ )
+ logger.error(f"Execution {execution_id} failed: {str(e)}", exc_info=True)
+ raise
+
+
+def _get_file_batches(
+ input_files: dict[str, FileHashData],
+ organization_id: str | None = None,
+ api_client=None,
+) -> list:
+ """Get file batches using the exact same logic as Django backend with organization-specific config.
+
+ This matches WorkflowHelper.get_file_batches() exactly, but now supports organization-specific
+ MAX_PARALLEL_FILE_BATCHES configuration.
+
+ Args:
+ input_files: Dictionary of FileHashData objects (already converted by FileProcessingUtils)
+ organization_id: Organization ID for configuration lookup
+ api_client: Internal API client for configuration access
+
+ Returns:
+ List of file batches
+
+ Note:
+ This function expects FileHashData objects since convert_file_hash_data() is called upstream.
+ The function converts them to dict format for Celery serialization.
+ """
+ # Convert FileHashData objects to serializable format for batching
+ # At this point, input_files should contain only FileHashData objects
+ # (converted upstream by FileProcessingUtils.convert_file_hash_data)
+ if not isinstance(input_files, dict):
+ raise TypeError(f"Expected dict[str, FileHashData], got {type(input_files)}")
+
+ json_serializable_files = {}
+ for file_name, file_hash_data in input_files.items():
+ if isinstance(file_hash_data, FileHashData):
+ json_serializable_files[file_name] = file_hash_data.to_dict()
+ else:
+ # This should not happen if convert_file_hash_data was called upstream
+ logger.error(
+ f"Unexpected file data type for '{file_name}': {type(file_hash_data)}. "
+ f"Expected FileHashData object. This suggests convert_file_hash_data() was not called upstream."
+ )
+ # Try to handle gracefully
+ if isinstance(file_hash_data, dict):
+ json_serializable_files[file_name] = file_hash_data
+ else:
+ continue
+
+ # Use standardized round-robin batching for consistent distribution
+ file_batches = FileProcessingUtils.create_file_batches(
+ files=json_serializable_files,
+ organization_id=organization_id,
+ api_client=api_client,
+ batch_size_env_var="MAX_PARALLEL_FILE_BATCHES",
+ default_batch_size=1, # Match backend default
+ )
+ return file_batches
+
+
+def _calculate_q_file_no_list_api(
+ manual_review_config: dict, total_files: int
+) -> list[int]:
+ """Get pre-calculated file numbers for manual review queue for API deployments.
+
+ This uses the pre-calculated q_file_no_list from the ManualReviewAPIClient
+ which matches the Django backend WorkflowUtil.get_q_no_list() logic.
+
+ Args:
+ manual_review_config: Manual review configuration with pre-calculated list
+ total_files: Total number of files (not used, kept for compatibility)
+
+ Returns:
+ List of file numbers (1-indexed) that should go to manual review
+ """
+ if not manual_review_config:
+ return []
+
+ # Use pre-calculated list from the client if available
+ q_file_no_list = manual_review_config.get("q_file_no_list", [])
+ if q_file_no_list:
+ return q_file_no_list
+
+ # Fallback to percentage calculation if pre-calculated list is not available
+ percentage = manual_review_config.get("review_percentage", 0)
+ if percentage <= 0 or total_files <= 0:
+ return []
+
+ # Match Django backend _mrq_files() logic exactly as fallback
+ import random
+
+ num_to_select = max(1, int(total_files * (percentage / 100)))
+ return list(set(random.sample(range(1, total_files + 1), num_to_select)))
+
+
+def _create_file_data(
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None,
+ scheduled: bool,
+ execution_mode: str | None,
+ use_file_history: bool,
+ api_client: InternalAPIClient,
+ total_files: int = 0,
+ **kwargs: dict[str, Any],
+) -> WorkerFileData:
+ """Create file data matching Django FileData structure exactly.
+
+ Args:
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ organization_id: Organization ID
+ pipeline_id: Pipeline ID
+ scheduled: Whether scheduled execution
+ execution_mode: Execution mode string
+ use_file_history: Whether to use file history
+ api_client: API client for fetching manual review rules
+ **kwargs: Additional keyword arguments
+ expected_kwargs:
+ hitl_queue_name: Optional HITL queue name for manual review routing
+ llm_profile_id: Optional LLM profile ID for manual review routing
+ custom_data: Optional custom data for manual review routing
+
+ Returns:
+ File data dictionary matching Django FileData with manual review config
+ """
+ # Initialize manual review config with defaults
+ manual_review_config = {
+ "review_required": False,
+ "review_percentage": 0,
+ "rule_logic": None,
+ "rule_json": None,
+ }
+
+ # ARCHITECTURE FIX: Skip manual review DB rules for API deployments
+ # API deployments handle manual review through different mechanisms (if supported)
+ # The DB rules endpoint is designed for ETL workflows, not API deployments
+ logger.info(
+ "API deployment workflow detected - skipping manual review DB rules lookup"
+ )
+
+ # For future: API deployments could support manual review through other mechanisms
+ # such as workflow-specific configuration or query parameters passed in the API request
+ logger.info(
+ f"No manual review rules configured for API deployment workflow {workflow_id}"
+ )
+ hitl_queue_name = kwargs.get("hitl_queue_name")
+ llm_profile_id = kwargs.get("llm_profile_id")
+ custom_data = kwargs.get("custom_data")
+
+ file_data = WorkerFileData(
+ workflow_id=str(workflow_id),
+ execution_id=str(execution_id),
+ organization_id=organization_id,
+ pipeline_id=str(pipeline_id),
+ scheduled=scheduled,
+ execution_mode=execution_mode,
+ use_file_history=use_file_history,
+ single_step=False,
+ q_file_no_list=_calculate_q_file_no_list_api(manual_review_config, total_files),
+ hitl_queue_name=hitl_queue_name,
+ manual_review_config=manual_review_config,
+ is_manualreview_required=bool(hitl_queue_name),
+ llm_profile_id=llm_profile_id,
+ custom_data=custom_data,
+ )
+
+ return file_data
+
+
+def _create_batch_data(files: list, file_data: WorkerFileData) -> dict[str, Any]:
+ """Create batch data matching Django FileBatchData structure exactly.
+
+ Args:
+ files: List of (file_name, file_hash) tuples
+ file_data: File data dictionary
+
+ Returns:
+ Batch data dictionary matching Django FileBatchData
+ """
+ return {"files": files, "file_data": file_data.to_dict()}
+
+
+def _get_queue_name_api() -> str:
+ """Get queue name for API file processing matching Django logic.
+
+ This matches FileExecutionTasks.get_queue_name() for API deployments.
+
+ Returns:
+ Queue name for API file processing
+ """
+ # For API deployments, use api_file_processing queue
+ return "api_file_processing"
+
+
+def _get_callback_queue_name_api() -> str:
+ """Get callback queue name for API deployments matching Django logic.
+
+ This matches FileExecutionTasks.get_queue_name() for API callbacks.
+
+ Returns:
+ Queue name for API file processing callbacks
+ """
+ # For API deployments, use api_file_processing_callback queue
+ return "api_file_processing_callback"
+
+
+def _calculate_manual_review_decisions_for_batch_api(
+ batch: list, manual_review_config: dict
+) -> list[bool]:
+ """Calculate manual review decisions for files in this API batch.
+
+ Args:
+ batch: List of (file_name, file_hash) tuples
+ manual_review_config: Manual review configuration with percentage, etc.
+
+ Returns:
+ List of boolean decisions for each file in the batch
+ """
+ try:
+ percentage = manual_review_config.get("review_percentage", 0)
+
+ if percentage <= 0:
+ return [False] * len(batch)
+
+ # Calculate target count (at least 1 if percentage > 0)
+ target_count = max(1, (len(batch) * percentage) // 100)
+
+ if target_count >= len(batch):
+ return [True] * len(batch)
+
+ # Create deterministic selection based on file hashes
+ import hashlib
+
+ file_scores = []
+
+ for i, (file_name, file_hash) in enumerate(batch):
+ # For API batches, file_hash should be a dict with file info
+ file_path = ""
+ if isinstance(file_hash, dict):
+ file_path = file_hash.get("file_path", "")
+
+ # Use file name + path for consistent hashing
+ hash_input = f"{file_name}:{file_path}"
+ score = int(hashlib.sha256(hash_input.encode()).hexdigest()[:8], 16)
+ file_scores.append((score, i)) # Store index instead of file object
+
+ # Sort by score and select top N files
+ file_scores.sort(key=lambda x: x[0])
+ selected_indices = {item[1] for item in file_scores[:target_count]}
+
+ # Create boolean list for this batch
+ decisions = [i in selected_indices for i in range(len(batch))]
+
+ logger.info(
+ f"API manual review batch calculation: {len(batch)} files, {percentage}% = {target_count} files, selected indices: {sorted(selected_indices)}"
+ )
+
+ return decisions
+
+ except Exception as e:
+ logger.error(f"Error calculating manual review decisions for API batch: {e}")
+ return [False] * len(batch)
+
+
+@monitor_performance
+@retry(max_attempts=3, base_delay=2.0)
+@with_execution_context
+def api_deployment_status_check(
+ self, execution_id: str, organization_id: str
+) -> dict[str, Any]:
+ """Check status of API deployment execution.
+
+ Args:
+ execution_id: Execution ID to check
+ organization_id: Organization context
+
+ Returns:
+ Status information
+ """
+ logger.info(f"Checking status for API deployment execution {execution_id}")
+
+ try:
+ config = WorkerConfig()
+ with InternalAPIClient(config) as api_client:
+ api_client.set_organization_context(organization_id)
+
+ # Get execution status
+ execution_response = api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(
+ f"Failed to get execution context: {execution_response.error}"
+ )
+ execution_context = execution_response.data
+
+ # Set LOG_EVENTS_ID in StateStore for WebSocket messaging (critical for UI logs)
+ # This enables the WorkerWorkflowLogger to send logs to the UI via WebSocket
+ execution_data = execution_context.get("execution", {})
+ execution_log_id = execution_data.get("execution_log_id")
+ if execution_log_id:
+ # Import and set LOG_EVENTS_ID like backend Celery workers do
+ from shared.infrastructure.context import StateStore
+
+ StateStore.set("LOG_EVENTS_ID", execution_log_id)
+ logger.info(
+ f"Set LOG_EVENTS_ID for WebSocket messaging: {execution_log_id}"
+ )
+ else:
+ logger.warning(
+ f"No execution_log_id found for execution {execution_id}, WebSocket logs may not be delivered"
+ )
+
+ status_info = {
+ "execution_id": execution_id,
+ "status": execution_data.get("status"),
+ "created_at": execution_data.get("created_at"),
+ "modified_at": execution_data.get("modified_at"),
+ "total_files": execution_data.get("total_files"),
+ "attempts": execution_data.get("attempts"),
+ "execution_time": execution_data.get("execution_time"),
+ "error_message": execution_data.get("error_message"),
+ "is_api_deployment": True,
+ }
+
+ logger.info(
+ f"API deployment execution {execution_id} status: {status_info['status']}"
+ )
+
+ return status_info
+
+ except Exception as e:
+ logger.error(f"Failed to check API deployment status: {e}")
+ raise
+
+
+@monitor_performance
+@with_execution_context
+def api_deployment_cleanup(
+ self, execution_id: str, organization_id: str
+) -> dict[str, Any]:
+ """Cleanup resources after API deployment execution.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+
+ Returns:
+ Cleanup result
+ """
+ logger.info(f"Starting cleanup for API deployment execution {execution_id}")
+
+ try:
+ # Cleanup logic would go here
+ # - Remove temporary files
+ # - Clean up API deployment resources
+ # - Archive execution data if needed
+ task_id = self.request.id
+
+ cleanup_result = {
+ "execution_id": execution_id,
+ "cleanup_completed": True,
+ "cleanup_time": time.time(),
+ "task_id": task_id,
+ }
+
+ logger.info(f"Cleanup completed for API deployment execution {execution_id}")
+
+ return cleanup_result
+
+ except Exception as e:
+ logger.error(f"Cleanup failed for API deployment execution {execution_id}: {e}")
+ raise
+
+
+def _check_file_history_api(
+ api_client: InternalAPIClient,
+ workflow_id: str,
+ hash_values_of_files: dict[str, FileHashData], # Already converted from dicts
+ execution_id: str,
+) -> tuple[dict[str, FileHashData], dict[str, dict]]:
+ """Check file history for API deployment and return both files to process and cached results.
+
+ This implements the same logic as backend's _check_processing_history method.
+ When use_file_history=True:
+ - Files with existing successful results are returned as cached results
+ - Files without history are returned for processing
+
+ Args:
+ api_client: Internal API client
+ workflow_id: Workflow ID
+ hash_values_of_files: Dictionary of files to check
+ execution_id: Execution ID for logging
+
+ Returns:
+ Tuple of:
+ - Dictionary of files that need to be processed (excludes already completed)
+ - Dictionary of cached results from file history (file_hash -> result details)
+ """
+ try:
+ # Extract file hashes for batch check
+ file_hashes = []
+ hash_to_file = {}
+
+ for file_key, file_hash_data in hash_values_of_files.items():
+ # Handle both FileHashData objects and dict formats
+ if isinstance(file_hash_data, FileHashData):
+ file_hash = file_hash_data.file_hash
+ elif isinstance(file_hash_data, dict):
+ file_hash = file_hash_data.get("file_hash")
+ else:
+ logger.warning(f"Unexpected file data type: {type(file_hash_data)}")
+ continue
+
+ if file_hash:
+ file_hashes.append(file_hash)
+ hash_to_file[file_hash] = (file_key, file_hash_data)
+
+ if not file_hashes:
+ logger.info(
+ f"No file hashes available for history check in execution {execution_id}, processing all files"
+ )
+ return hash_values_of_files
+
+ logger.info(
+ f"Checking file history for {len(file_hashes)} files in execution {execution_id}"
+ )
+
+ # Check which files were already processed successfully
+ response = api_client.check_file_history_batch(
+ workflow_id=workflow_id,
+ file_hashes=file_hashes,
+ organization_id=None, # Will use the organization from api_client context
+ )
+
+ processed_hashes = set(response.get("processed_file_hashes", []))
+ file_history_details = response.get("file_history_details", {})
+ logger.info(
+ f"File history check found {len(processed_hashes)} already processed files"
+ )
+
+ # Separate files into: to process vs cached results
+ files_to_process = {}
+ cached_results = {}
+ skipped_files = []
+
+ for file_hash_str in file_hashes:
+ file_key, file_hash_data = hash_to_file[file_hash_str]
+
+ if file_hash_str in processed_hashes:
+ # Get file name for logging
+ if isinstance(file_hash_data, FileHashData):
+ file_name = file_hash_data.file_name
+ elif isinstance(file_hash_data, dict):
+ file_name = file_hash_data.get("file_name", file_key)
+ else:
+ file_name = file_key
+
+ # Store cached result details
+ if file_hash_str in file_history_details:
+ cached_results[file_hash_str] = {
+ "file_name": file_name,
+ "file_key": file_key,
+ "file_hash_data": file_hash_data,
+ **file_history_details[file_hash_str], # result, metadata, etc.
+ }
+
+ skipped_files.append(file_name)
+ logger.info(
+ f"Using cached result for file: {file_name} (hash: {file_hash_str[:16]}...)"
+ )
+ else:
+ files_to_process[file_key] = file_hash_data
+
+ # Add files without hashes (will be processed normally)
+ for file_key, file_hash_data in hash_values_of_files.items():
+ if isinstance(file_hash_data, FileHashData):
+ has_hash = bool(file_hash_data.file_hash)
+ elif isinstance(file_hash_data, dict):
+ has_hash = bool(file_hash_data.get("file_hash"))
+ else:
+ has_hash = False
+
+ if not has_hash and file_key not in files_to_process:
+ files_to_process[file_key] = file_hash_data
+
+ logger.info(
+ f"File history check completed for execution {execution_id}: {len(cached_results)} cached results, processing {len(files_to_process)} files"
+ )
+
+ return files_to_process, cached_results
+
+ except Exception as e:
+ logger.warning(
+ f"File history check failed for execution {execution_id}, processing all files: {e}"
+ )
+ return hash_values_of_files, {}
diff --git a/workers/api-deployment/worker.py b/workers/api-deployment/worker.py
new file mode 100644
index 000000000..8d29899d5
--- /dev/null
+++ b/workers/api-deployment/worker.py
@@ -0,0 +1,70 @@
+"""API Deployment Worker
+
+Celery worker for API deployment workflows.
+Handles API deployment, cleanup, and status checking tasks.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker
+logger = WorkerLogger.setup(WorkerType.API_DEPLOYMENT)
+app, config = WorkerBuilder.build_celery_app(WorkerType.API_DEPLOYMENT)
+
+
+def check_api_deployment_health():
+ """Custom health check for API deployment worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="api_deployment_health",
+ status=HealthStatus.HEALTHY,
+ message="API deployment worker is healthy",
+ details={
+ "worker_type": "api_deployment",
+ "api_client": "healthy",
+ "queue": "celery_api_deployments",
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="api_deployment_health",
+ status=HealthStatus.DEGRADED,
+ message="API connectivity degraded",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="api_deployment_health",
+ status=HealthStatus.UNHEALTHY,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.API_DEPLOYMENT, "api_deployment_health", check_api_deployment_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "api_deployment",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "api-deployment-worker",
+ }
diff --git a/workers/callback/__init__.py b/workers/callback/__init__.py
new file mode 100644
index 000000000..0210f58e5
--- /dev/null
+++ b/workers/callback/__init__.py
@@ -0,0 +1,19 @@
+"""Lightweight File Processing Callback Worker
+
+This worker handles file processing result aggregation and callbacks using
+internal APIs instead of direct Django ORM access.
+"""
+
+from .tasks import (
+ # finalize_execution_callback removed - dead code (never called)
+ process_batch_callback,
+ process_batch_callback_api,
+)
+from .worker import app as celery_app
+
+__all__ = [
+ "celery_app",
+ "process_batch_callback",
+ "process_batch_callback_api",
+ # "finalize_execution_callback" removed - dead code (never called)
+]
diff --git a/workers/callback/tasks.py b/workers/callback/tasks.py
new file mode 100644
index 000000000..93c5ded15
--- /dev/null
+++ b/workers/callback/tasks.py
@@ -0,0 +1,1777 @@
+"""File Processing Callback Worker Tasks
+
+Handles workflow execution finalization and status updates when file processing completes.
+Provides Redis-based caching, exponential backoff, and circuit breaker patterns for reliability.
+"""
+
+import time
+from typing import Any
+
+# Use Celery current_app to avoid circular imports
+from celery import current_app as app
+
+# Import shared worker infrastructure
+from shared.api import InternalAPIClient
+
+# Import from shared worker modules
+from shared.enums import PipelineType
+from shared.enums.status_enums import PipelineStatus
+from shared.enums.task_enums import TaskName
+from shared.infrastructure import create_api_client
+
+# Import performance optimization utilities
+from shared.infrastructure.caching.cache_utils import (
+ get_cache_manager,
+ initialize_cache_manager,
+)
+from shared.infrastructure.config import WorkerConfig
+from shared.infrastructure.logging import (
+ WorkerLogger,
+ log_context,
+ monitor_performance,
+)
+from shared.infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+from shared.patterns.notification.helper import handle_status_notifications
+from shared.patterns.retry.backoff import (
+ initialize_backoff_managers,
+)
+from shared.patterns.retry.utils import CircuitBreakerOpenError, circuit_breaker
+from shared.processing.files.time_utils import (
+ WallClockTimeCalculator,
+ aggregate_file_batch_results,
+)
+
+# Import shared data models for type safety
+from unstract.core.data_models import ExecutionStatus
+
+logger = WorkerLogger.get_logger(__name__)
+
+# Constants
+NOT_FOUND_MSG = "Not Found"
+
+# Initialize performance optimization managers on module load
+_performance_managers_initialized = False
+
+
+class CallbackContext:
+ """Container for callback processing context data."""
+
+ def __init__(self):
+ self.task_id: str = ""
+ self.execution_id: str = ""
+ self.pipeline_id: str | None = None
+ self.organization_id: str | None = None
+ self.workflow_id: str | None = None
+ self.pipeline_name: str | None = None
+ self.pipeline_type: str | None = None
+ self.pipeline_data: dict[str, Any] | None = None
+ self.api_client: InternalAPIClient | None = None
+
+
+def _initialize_performance_managers():
+ """Initialize performance optimization managers once per worker process."""
+ global _performance_managers_initialized
+
+ if _performance_managers_initialized:
+ return
+
+ try:
+ # Initialize with worker configuration
+ config = WorkerConfig()
+
+ # Initialize cache manager
+ cache_manager = initialize_cache_manager(config)
+ logger.info(f"Cache manager initialized: available={cache_manager.is_available}")
+
+ # Initialize backoff and retry managers
+ initialize_backoff_managers(cache_manager)
+ logger.info("Backoff and retry managers initialized")
+
+ _performance_managers_initialized = True
+ logger.info("All performance optimization managers initialized successfully")
+
+ except Exception as e:
+ logger.warning(
+ f"Failed to initialize performance managers: {e}. Callback will work without optimizations."
+ )
+
+
+def _map_execution_status_to_pipeline_status(execution_status: str) -> str:
+ """Map workflow execution status to pipeline status.
+
+ Based on the Pipeline model PipelineStatus choices:
+ - SUCCESS = "SUCCESS"
+ - FAILURE = "FAILURE"
+ - INPROGRESS = "INPROGRESS"
+ - YET_TO_START = "YET_TO_START"
+ - RESTARTING = "RESTARTING"
+ - PAUSED = "PAUSED"
+
+ Args:
+ execution_status: Workflow execution status
+
+ Returns:
+ Corresponding pipeline status
+ """
+ status_mapping = {
+ # ExecutionStatus enum values
+ ExecutionStatus.COMPLETED.value: PipelineStatus.SUCCESS.value,
+ ExecutionStatus.ERROR.value: PipelineStatus.FAILURE.value,
+ ExecutionStatus.EXECUTING.value: PipelineStatus.INPROGRESS.value,
+ ExecutionStatus.PENDING.value: PipelineStatus.YET_TO_START.value,
+ ExecutionStatus.STOPPED.value: PipelineStatus.FAILURE.value,
+ ExecutionStatus.QUEUED.value: PipelineStatus.INPROGRESS.value,
+ ExecutionStatus.CANCELED.value: PipelineStatus.FAILURE.value,
+ # Legacy status values for backward compatibility
+ "SUCCESS": PipelineStatus.SUCCESS.value, # Legacy alias for COMPLETED
+ "FAILED": PipelineStatus.FAILURE.value, # Legacy alias for ERROR
+ "FAILURE": PipelineStatus.FAILURE.value, # Legacy variant
+ "RUNNING": PipelineStatus.INPROGRESS.value, # Legacy alias for EXECUTING
+ "INPROGRESS": PipelineStatus.INPROGRESS.value, # Legacy variant
+ "YET_TO_START": PipelineStatus.YET_TO_START.value, # Legacy variant
+ }
+
+ # Default to FAILURE for unknown statuses
+ return status_mapping.get(execution_status.upper(), "FAILURE")
+
+
+def _fetch_pipeline_data_simplified(
+ pipeline_id: str,
+ organization_id: str,
+ api_client: InternalAPIClient,
+ is_api_deployment: bool = False,
+) -> tuple[str | None, str | None]:
+ """Simplified pipeline data fetching that returns only name and type.
+
+ Args:
+ pipeline_id: Pipeline or API deployment ID
+ organization_id: Organization context
+ api_client: API client instance
+ is_api_deployment: If True, use API deployment endpoint; otherwise try unified endpoint
+
+ Returns:
+ Tuple of (pipeline_name, pipeline_type) or (None, None) if not found
+ """
+ try:
+ api_client.set_organization_context(organization_id)
+
+ if is_api_deployment:
+ # Try API deployment endpoint first
+ response = api_client.get_api_deployment_data(pipeline_id, organization_id)
+ if response.success and response.data:
+ pipeline_data = response.data.get("pipeline", {})
+ return pipeline_data.get("api_name"), PipelineType.API.value
+
+ # Fallback to unified pipeline endpoint
+ response = api_client.get_pipeline_data(pipeline_id, organization_id)
+ if response.success and response.data:
+ pipeline_data = response.data.get("pipeline", response.data)
+
+ # Check if it's an API deployment or regular pipeline
+ if pipeline_data.get("api_name") or pipeline_data.get("api_endpoint"):
+ return pipeline_data.get("api_name"), PipelineType.API.value
+ else:
+ return pipeline_data.get("pipeline_name"), pipeline_data.get(
+ "pipeline_type", PipelineType.ETL.value
+ )
+
+ logger.warning(f"No pipeline data found for {pipeline_id}")
+ return None, None
+
+ except Exception as e:
+ logger.warning(f"Failed to fetch pipeline data for {pipeline_id}: {e}")
+ return None, None
+
+
+def _update_pipeline_directly(
+ pipeline_id: str,
+ execution_id: str,
+ status: str,
+ organization_id: str,
+ api_client: InternalAPIClient,
+ **additional_fields,
+) -> bool:
+ """Update pipeline status using direct API call.
+
+ Args:
+ pipeline_id: Pipeline ID
+ execution_id: Execution ID
+ status: Pipeline status
+ organization_id: Organization context
+ api_client: API client instance
+ **additional_fields: Additional pipeline fields
+
+ Returns:
+ True if update was successful
+ """
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=status,
+ organization_id=organization_id,
+ **additional_fields,
+ )
+
+ # Invalidate cache after successful update
+ cache_manager = get_cache_manager()
+ if cache_manager:
+ cache_manager.invalidate_pipeline_status(pipeline_id, organization_id)
+
+ logger.debug(f"Pipeline update for {pipeline_id}: {status}")
+ return True
+
+ except Exception as e:
+ logger.error(
+ f"Failed to update pipeline status for {pipeline_id}: {e}", exc_info=True
+ )
+ return False
+
+
+def _get_performance_stats() -> dict:
+ """Get performance optimization statistics.
+
+ Returns:
+ Dictionary with performance statistics
+ """
+ stats = {}
+
+ # Cache manager stats
+ cache_manager = get_cache_manager()
+ if cache_manager:
+ stats["cache"] = cache_manager.get_cache_stats()
+
+ # Note: Batch processor removed - it was ineffective with auto-flush disabled
+ stats["optimizations"] = {
+ "eliminated_batch_processor": True,
+ "using_direct_api_calls": True,
+ }
+
+ return stats
+
+
+def _determine_execution_status_unified(
+ file_batch_results: list[dict[str, Any]],
+ api_client: InternalAPIClient,
+ execution_id: str,
+ organization_id: str,
+) -> tuple[dict[str, Any], str, int]:
+ """Unified status determination logic with timeout detection for all callback types.
+
+ This function combines the logic from both process_batch_callback_api and
+ _process_batch_callback_core, ensuring consistent status determination across
+ all callback tasks including timeout failure detection.
+
+ Args:
+ file_batch_results: Results from all file processing tasks
+ api_client: Internal API client for workflow execution queries
+ execution_id: Workflow execution ID
+ organization_id: Organization context
+
+ Returns:
+ Tuple of (aggregated_results, final_status, expected_files)
+ """
+ # Step 1: Aggregate results from all file batches using existing helper
+ aggregated_results = aggregate_file_batch_results(file_batch_results)
+
+ # Step 2: Calculate wall-clock execution time (consistent across both implementations)
+ wall_clock_time = WallClockTimeCalculator.calculate_execution_time(
+ api_client,
+ execution_id,
+ organization_id,
+ aggregated_results.get("file_results", []),
+ )
+
+ # Update aggregated results with wall-clock time
+ original_time = aggregated_results.get("total_execution_time", 0)
+ if wall_clock_time != original_time:
+ logger.info(
+ f"FIXED: Wall-clock execution time: {wall_clock_time:.2f}s (was: {original_time:.2f}s summed)"
+ )
+ aggregated_results["total_execution_time"] = wall_clock_time
+
+ # Debug logging for execution time calculation
+ if wall_clock_time == 0:
+ logger.warning(f"Execution time is 0! File results for execution {execution_id}")
+
+ # Step 3: Get expected file count from workflow execution details for timeout detection
+ expected_files = 0
+ try:
+ execution_response = api_client.get_workflow_execution(
+ execution_id, file_execution=False
+ )
+ if execution_response.success:
+ execution_data = execution_response.data
+ expected_files = execution_data.get("total_files", 0)
+ logger.info(
+ f"Expected files from execution details: {expected_files} for execution {execution_id}"
+ )
+ else:
+ logger.warning(
+ f"Could not fetch execution details for {execution_id}: {execution_response.error}"
+ )
+ except Exception as e:
+ logger.warning(f"Could not fetch execution details for {execution_id}: {e}")
+
+ # Step 4: Extract file processing metrics for status determination
+ total_files_processed = aggregated_results.get("total_files_processed", 0)
+ failed_files = aggregated_results.get("failed_files", 0)
+ total_files = aggregated_results.get("total_files", 0)
+ successful_files = aggregated_results.get("successful_files", 0)
+
+ # Step 5: Unified status determination with timeout failure detection
+
+ # Detect timeout failures: expected files but processed none (likely SoftTimeLimitExceeded)
+ has_timeout_failure = (
+ total_files == 0 and total_files_processed == 0 and expected_files > 0
+ )
+
+ if has_timeout_failure:
+ # Timeout or complete failure - mark as ERROR
+ final_status = ExecutionStatus.ERROR.value
+ logger.error(
+ f"Execution {execution_id} failed - expected {expected_files} files "
+ f"but processed 0 (likely timeout/failure)"
+ )
+ elif failed_files > 0 and failed_files == total_files:
+ # ALL processed files failed - mark as ERROR
+ final_status = ExecutionStatus.ERROR.value
+ logger.error(f"Execution {execution_id} failed - all {total_files} files failed")
+ else:
+ # Some or all files succeeded, or legitimate empty batch - mark as COMPLETED
+ final_status = ExecutionStatus.COMPLETED.value
+ if failed_files > 0:
+ logger.warning(
+ f"Execution {execution_id} completed with {failed_files} failed files out of {total_files} total"
+ )
+ elif total_files == 0 and expected_files == 0:
+ logger.info(
+ f"Execution {execution_id} completed - legitimate empty batch (no files to process)"
+ )
+ else:
+ logger.info(
+ f"Execution {execution_id} completed successfully - {successful_files} files processed"
+ )
+
+ return aggregated_results, final_status, expected_files
+
+
+def _update_execution_status_unified(
+ api_client: InternalAPIClient,
+ execution_id: str,
+ final_status: str,
+ aggregated_results: dict[str, Any],
+ organization_id: str,
+ error_message: str | None = None,
+) -> dict[str, Any]:
+ """Unified workflow execution status update for all callback types.
+
+ This function provides consistent workflow execution status updates across
+ all callback tasks with proper error handling and result structure.
+
+ Args:
+ api_client: Internal API client for making the update call
+ execution_id: Workflow execution ID
+ final_status: Final execution status (COMPLETED, ERROR, etc.)
+ aggregated_results: Aggregated file processing results
+ organization_id: Organization context
+ error_message: Optional error message for failed executions
+
+ Returns:
+ Execution update result dictionary
+ """
+ try:
+ # Consistent workflow execution status update across all callback types
+ total_files = aggregated_results.get("total_files", 0)
+
+ # Make the unified API call
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=final_status,
+ total_files=total_files,
+ organization_id=organization_id,
+ error_message=error_message,
+ )
+
+ # Return consistent result structure
+ update_result = {
+ "status": "completed",
+ "method": "unified_execution_update",
+ "message": f"Execution status updated to {final_status}",
+ "execution_id": execution_id,
+ "final_status": final_status,
+ "total_files": total_files,
+ "organization_id": organization_id,
+ }
+
+ logger.info(
+ f"Successfully updated execution {execution_id} status to {final_status}"
+ )
+ return update_result
+
+ except Exception as e:
+ logger.error(
+ f"Failed to update execution status for {execution_id}: {e}", exc_info=True
+ )
+ # Return error result instead of re-raising to maintain callback flow
+ return {
+ "status": "failed",
+ "method": "unified_execution_update",
+ "error": str(e),
+ "execution_id": execution_id,
+ "final_status": final_status,
+ "organization_id": organization_id,
+ }
+
+
+def _handle_pipeline_updates_unified(
+ context: CallbackContext, final_status: str, is_api_deployment: bool = False
+) -> dict[str, Any]:
+ """Unified pipeline status handling for all callback types.
+
+ This function handles the difference between API deployments (which skip pipeline
+ updates) and ETL/TASK/APP workflows (which require pipeline status updates).
+
+ Args:
+ context: Callback context with pipeline details
+ final_status: Final execution status to map to pipeline status
+ is_api_deployment: Whether this is an API deployment (skips pipeline updates)
+
+ Returns:
+ Pipeline update result dictionary
+ """
+ if is_api_deployment:
+ # API deployments use APIDeployment model, not Pipeline model
+ # Pipeline status updates don't apply and would cause 404 errors
+ logger.info(
+ f"OPTIMIZATION: Skipping pipeline status update for API deployment {context.pipeline_id} "
+ f"(no Pipeline record exists)"
+ )
+ return {
+ "status": "skipped",
+ "reason": "api_deployment",
+ "message": "Pipeline update skipped for API deployment",
+ "pipeline_id": context.pipeline_id,
+ }
+
+ # Non-API workflows (ETL/TASK/APP) need pipeline status updates
+ if not context.pipeline_id:
+ logger.info("No pipeline_id provided - skipping pipeline status update")
+ return {
+ "status": "skipped",
+ "reason": "no_pipeline_id",
+ "message": "No pipeline_id available for update",
+ }
+
+ try:
+ # Validate pipeline_id is a proper UUID
+ import uuid
+
+ uuid.UUID(str(context.pipeline_id))
+ except ValueError:
+ # Invalid UUID - likely execution_log_id from worker-based execution
+ logger.info(
+ f"WORKERS FLOW: Skipping pipeline status update - pipeline_id '{context.pipeline_id}' "
+ f"is not a valid UUID (likely execution_log_id from worker-based execution)"
+ )
+ return {
+ "status": "skipped",
+ "reason": "invalid_uuid",
+ "message": "Pipeline ID is not a valid UUID",
+ "pipeline_id": context.pipeline_id,
+ }
+
+ # Perform pipeline status update for ETL/TASK/APP workflows
+ try:
+ logger.info(
+ f"Updating pipeline {context.pipeline_id} status with organization_id: {context.organization_id}"
+ )
+
+ # Map execution status to pipeline status
+ pipeline_status = _map_execution_status_to_pipeline_status(final_status)
+
+ # Use direct pipeline update
+ pipeline_updated = _update_pipeline_directly(
+ pipeline_id=context.pipeline_id,
+ execution_id=context.execution_id,
+ status=pipeline_status,
+ organization_id=context.organization_id,
+ api_client=context.api_client,
+ last_run_status=pipeline_status,
+ last_run_time=time.time(),
+ increment_run_count=True,
+ )
+
+ if pipeline_updated:
+ logger.info(
+ f"Successfully updated pipeline {context.pipeline_id} last_run_status to {pipeline_status}"
+ )
+ return {
+ "status": "completed",
+ "pipeline_status": pipeline_status,
+ "pipeline_id": context.pipeline_id,
+ "message": f"Pipeline status updated to {pipeline_status}",
+ }
+ else:
+ logger.warning(
+ f"Failed to update pipeline for {context.pipeline_id} - "
+ f"pipeline_status={pipeline_status}, pipeline_name={context.pipeline_name}"
+ )
+ return {
+ "status": "failed",
+ "pipeline_status": pipeline_status,
+ "pipeline_id": context.pipeline_id,
+ "message": "Pipeline update call failed",
+ }
+
+ except CircuitBreakerOpenError:
+ logger.warning("Pipeline status update circuit breaker open - skipping update")
+ return {
+ "status": "skipped",
+ "reason": "circuit_breaker_open",
+ "message": "Circuit breaker prevented pipeline update",
+ "pipeline_id": context.pipeline_id,
+ }
+ except Exception as e:
+ # Handle pipeline not found errors gracefully
+ if "404" in str(e) or "Pipeline not found" in str(e) or NOT_FOUND_MSG in str(e):
+ logger.info(
+ f"Pipeline {context.pipeline_id} not found - likely using stale reference, skipping update"
+ )
+ return {
+ "status": "skipped",
+ "reason": "pipeline_not_found",
+ "message": "Pipeline not found (stale reference)",
+ "pipeline_id": context.pipeline_id,
+ }
+ else:
+ logger.warning(f"Failed to update pipeline status: {str(e)}")
+ return {
+ "status": "failed",
+ "error": str(e),
+ "pipeline_id": context.pipeline_id,
+ "message": "Pipeline update failed with error",
+ }
+
+
+def _handle_notifications_unified(
+ api_client: InternalAPIClient,
+ status: str,
+ organization_id: str,
+ execution_id: str,
+ pipeline_id: str | None = None,
+ workflow_id: str | None = None,
+ pipeline_name: str | None = None,
+ pipeline_type: str | None = None,
+ error_message: str | None = None,
+) -> dict[str, Any]:
+ """Unified notification handling for all callback types.
+
+ Args:
+ api_client: Internal API client for notification calls
+ execution_id: Workflow execution ID
+ status: Execution status
+ pipeline_id: Pipeline or API deployment ID
+ workflow_id: Workflow ID (fallback if pipeline_id is None)
+ organization_id: Organization context
+ pipeline_name: Pipeline/API deployment name
+ pipeline_type: Pipeline/API deployment type
+ error_message: Error message (if any)
+
+ Returns:
+ Notification result dictionary
+ """
+ try:
+ if not pipeline_id:
+ logger.warning("No pipeline_id provided - skipping notifications")
+ return {
+ "status": "skipped",
+ "reason": "no_pipeline_id",
+ "message": "No pipeline_id available for notifications",
+ }
+
+ logger.info(
+ f"Triggering notifications for target_id={pipeline_id} (execution completed)"
+ )
+
+ # Ensure organization context is set for notification requests
+ api_client.set_organization_context(organization_id)
+
+ handle_status_notifications(
+ api_client=api_client,
+ pipeline_id=pipeline_id,
+ status=status,
+ execution_id=execution_id,
+ error_message=error_message,
+ pipeline_name=pipeline_name,
+ pipeline_type=pipeline_type,
+ organization_id=organization_id,
+ )
+
+ return {
+ "status": "completed",
+ "target_id": pipeline_id,
+ "message": "Notifications sent successfully",
+ }
+
+ except Exception as notif_error:
+ logger.warning(f"Failed to trigger completion notifications: {notif_error}")
+ return {
+ "status": "failed",
+ "error": str(notif_error),
+ "message": "Notification delivery failed",
+ }
+
+
+def _extract_callback_parameters(
+ task_instance, results: list, kwargs: dict[str, Any]
+) -> CallbackContext:
+ """Extract and validate all callback parameters using workflow execution as single source of truth.
+
+ Args:
+ task_instance: The Celery task instance
+ results: List of batch results
+ kwargs: Keyword arguments from the callback
+
+ Returns:
+ CallbackContext with all parameters populated
+
+ Raises:
+ ValueError: If required parameters are missing
+ """
+ context = CallbackContext()
+ context.task_id = (
+ task_instance.request.id if hasattr(task_instance, "request") else "unknown"
+ )
+
+ # 1. Get execution_id from kwargs (always present)
+ context.execution_id = kwargs.get("execution_id")
+ if not context.execution_id:
+ raise ValueError("execution_id is required in kwargs")
+
+ # 2. Check if organization_id is available in kwargs (fast path)
+ try:
+ org_id_from_kwargs = kwargs.get("organization_id")
+
+ if org_id_from_kwargs:
+ # Fast path: Create organization-scoped API client immediately
+ logger.info(f"Using organization ID from kwargs: {org_id_from_kwargs}")
+ api_client = create_api_client(org_id_from_kwargs)
+
+ logger.info(
+ f"Fetching complete context from workflow execution {context.execution_id}"
+ )
+
+ execution_response = api_client.get_workflow_execution(
+ context.execution_id, file_execution=False
+ )
+
+ if not execution_response.success:
+ raise ValueError(
+ f"Failed to get workflow execution: {execution_response.error}"
+ )
+ execution_data = execution_response.data
+
+ # Extract nested structures from response (corrected paths)
+ execution_info = execution_data.get("execution", {})
+ workflow_definition = execution_data.get("workflow_definition", {})
+ organization_context = execution_data.get("organization_context", {})
+ source_config = execution_data.get("source_config", {})
+
+ # 3. Extract parameters with kwargs as fast path, execution data as fallback
+ context.pipeline_id = kwargs.get("pipeline_id") or execution_info.get(
+ "pipeline_id"
+ )
+ context.organization_id = org_id_from_kwargs # Use from kwargs
+ else:
+ # Fallback path: Need to fetch execution data first to get organization context
+ logger.info(
+ f"Organization ID not in kwargs, fetching from workflow execution {context.execution_id}"
+ )
+
+ # Create temporary API client for initial execution fetch (no org context needed)
+ from shared.infrastructure.config import WorkerConfig
+
+ temp_config = WorkerConfig()
+ temp_api_client = InternalAPIClient(temp_config)
+ try:
+ execution_response = temp_api_client.get_workflow_execution(
+ context.execution_id,
+ file_execution=False,
+ )
+
+ if not execution_response.success:
+ raise ValueError(
+ f"Failed to get workflow execution: {execution_response.error}"
+ )
+
+ execution_data = execution_response.data
+
+ # Extract nested structures from response (corrected paths)
+ execution_info = execution_data.get("execution", {})
+ workflow_definition = execution_data.get("workflow_definition", {})
+ organization_context = execution_data.get("organization_context", {})
+ source_config = execution_data.get("source_config", {})
+
+ # Extract organization ID from execution data
+ context.organization_id = organization_context.get(
+ "organization_id"
+ ) or workflow_definition.get("organization_id")
+
+ if not context.organization_id:
+ raise ValueError(
+ "Could not determine organization_id from execution context"
+ )
+
+ # Now create the proper organization-scoped API client
+ api_client = create_api_client(context.organization_id)
+
+ # Extract other parameters
+ context.pipeline_id = kwargs.get("pipeline_id") or execution_info.get(
+ "pipeline_id"
+ )
+ if not context.pipeline_id:
+ execution_response = api_client.get_workflow_execution(
+ execution_id=context.execution_id,
+ file_execution=False,
+ )
+ execution_info = execution_response.data.get("execution", {})
+ context.pipeline_id = execution_info.get("pipeline_id")
+ finally:
+ # Clean up temporary client
+ if hasattr(temp_api_client, "close"):
+ temp_api_client.close()
+
+ # Common processing for both paths - variables are available in both scopes
+ # Always populate workflow_id from correct nested path
+ context.workflow_id = execution_info.get(
+ "workflow_id"
+ ) or workflow_definition.get("workflow_id")
+
+ # Use existing API detection from source_config (no additional API calls needed)
+ is_api_deployment = source_config.get("is_api", False)
+
+ if is_api_deployment:
+ # This is an API deployment
+ context.pipeline_data = {
+ "is_api": True,
+ "resolved_pipeline_type": "API",
+ "resolved_pipeline_name": workflow_definition.get(
+ "workflow_name", "Unknown API"
+ ),
+ }
+ context.pipeline_type = "API"
+ context.pipeline_name = workflow_definition.get(
+ "workflow_name", "Unknown API"
+ )
+ logger.info(
+ f"Detected API deployment from source_config: {context.pipeline_id}"
+ )
+ else:
+ # This is ETL/TASK/APP workflow
+ context.pipeline_data = {
+ "is_api": False,
+ "resolved_pipeline_type": "ETL",
+ "resolved_pipeline_name": workflow_definition.get(
+ "workflow_name", "Unknown Workflow"
+ ),
+ }
+ context.pipeline_type = "ETL"
+ context.pipeline_name = workflow_definition.get(
+ "workflow_name", "Unknown Workflow"
+ )
+ logger.info(
+ f"Detected ETL workflow from source_config: {context.pipeline_id}"
+ )
+
+ logger.info(
+ f"Extracted from kwargs: pipeline_id={kwargs.get('pipeline_id')}, org_id={kwargs.get('organization_id')}"
+ )
+ logger.info(
+ f"Extracted from execution: workflow_id={context.workflow_id}, is_api={is_api_deployment}, pipeline_type={context.pipeline_type}"
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to fetch workflow execution context: {e}")
+ raise ValueError(f"Could not get execution context: {e}")
+
+ # 4. Validate required context is now available
+ if not context.organization_id:
+ raise ValueError("organization_id could not be determined from execution context")
+
+ # 5. Assign the already-created organization-scoped API client to context
+ context.api_client = api_client
+
+ logger.info(
+ f"✅ Extracted complete callback context: execution={context.execution_id}, "
+ f"pipeline={context.pipeline_id}, workflow={context.workflow_id}, org={context.organization_id}, "
+ f"api_client=initialized, pipeline_data=✓, type={context.pipeline_type}"
+ )
+
+ return context
+
+
+def _is_api_deployment(context: CallbackContext) -> bool:
+ """Check if this is an API deployment execution.
+
+ API deployments should preserve cache for subsequent requests.
+ """
+ try:
+ # Check if this is an API deployment by looking at the pipeline type
+ if hasattr(context, "pipeline_type") and context.pipeline_type:
+ return context.pipeline_type.lower() == "api"
+
+ # Fallback: check execution type if available
+ if hasattr(context, "execution_type") and context.execution_type:
+ return "api" in context.execution_type.lower()
+
+ # If we can't determine, be conservative and assume it's not API
+ return False
+ except Exception:
+ # If any error occurs, be conservative
+ return False
+
+
+def _cleanup_execution_cache_direct(context: CallbackContext) -> None:
+ """Clean execution cache directly using cache manager.
+
+ This replaces the broken backend API call with direct cache operations.
+ """
+ try:
+ # Use the existing cache manager to clear execution cache
+ from shared.cache import get_cache_manager
+
+ cache_manager = get_cache_manager()
+ if cache_manager and hasattr(cache_manager, "delete_execution_cache"):
+ # Use the direct cache method similar to ExecutionCacheUtils.delete_execution
+ cache_manager.delete_execution_cache(
+ workflow_id=context.workflow_id, execution_id=context.execution_id
+ )
+ logger.info(f"Cleared execution cache for {context.execution_id}")
+ else:
+ logger.debug("Cache manager not available or method not found")
+ except ImportError:
+ logger.debug("Cache manager not available for direct cleanup")
+ except Exception as e:
+ logger.warning(f"Failed to clear execution cache directly: {e}")
+ # Don't raise - cache cleanup is not critical for callback success
+
+
+def _create_cleanup_result(cleanup_type: str, status: str, **kwargs) -> dict[str, Any]:
+ """Create standardized cleanup result structure.
+
+ Args:
+ cleanup_type: Type of cleanup (api, workflow, backend, etc.)
+ status: Status (success, failed, skipped)
+ **kwargs: Additional fields (message, error, cleaned_paths, files_deleted, etc.)
+
+ Returns:
+ Standardized cleanup result dictionary
+ """
+ result = {
+ "type": cleanup_type,
+ "status": status,
+ }
+
+ # Add optional fields if provided
+ if "message" in kwargs:
+ result["message"] = kwargs["message"]
+ if "error" in kwargs:
+ result["error"] = str(kwargs["error"])
+ if "cleaned_paths" in kwargs:
+ result["cleaned_paths"] = kwargs["cleaned_paths"]
+ if "failed_paths" in kwargs:
+ result["failed_paths"] = kwargs["failed_paths"]
+ if "files_deleted" in kwargs:
+ result["files_deleted"] = kwargs["files_deleted"]
+ if "method" in kwargs:
+ result["method"] = kwargs["method"]
+ if "reason" in kwargs:
+ result["reason"] = kwargs["reason"]
+
+ return result
+
+
+def _setup_file_system(storage_type):
+ """Setup FileSystem instance with error handling.
+
+ Args:
+ storage_type: FileStorageType enum value
+
+ Returns:
+ FileStorage instance
+
+ Raises:
+ Exception: If FileSystem setup fails
+ """
+ from unstract.filesystem import FileSystem
+
+ file_system = FileSystem(storage_type)
+ return file_system.get_file_storage()
+
+
+def _cleanup_directory(
+ file_storage, directory_path: str, cleanup_type: str
+) -> dict[str, Any]:
+ """Perform directory cleanup with file counting and logging.
+
+ Args:
+ file_storage: FileStorage instance
+ directory_path: Path to directory to clean
+ cleanup_type: Type identifier for logging (api/workflow)
+
+ Returns:
+ Cleanup result dictionary
+ """
+ try:
+ if file_storage.exists(directory_path):
+ # Get file count before cleanup
+ try:
+ files = file_storage.ls(directory_path)
+ file_count = len(files) if files else 0
+
+ # Remove the entire execution directory
+ file_storage.rm(directory_path, recursive=True)
+
+ logger.info(
+ f"✅ Successfully cleaned up {cleanup_type} execution directory: {directory_path} ({file_count} files)"
+ )
+
+ return _create_cleanup_result(
+ cleanup_type=cleanup_type,
+ status="success",
+ cleaned_paths=[directory_path],
+ files_deleted=file_count,
+ message=f"{cleanup_type.title()} execution directory cleaned: {directory_path}",
+ )
+
+ except Exception as cleanup_error:
+ logger.error(
+ f"Failed to clean {cleanup_type} execution directory: {cleanup_error}"
+ )
+ return _create_cleanup_result(
+ cleanup_type=cleanup_type,
+ status="failed",
+ error=cleanup_error,
+ failed_paths=[directory_path],
+ )
+ else:
+ logger.warning(
+ f"{cleanup_type.title()} execution directory not found: {directory_path}"
+ )
+ return _create_cleanup_result(
+ cleanup_type=cleanup_type,
+ status="skipped",
+ message=f"Directory not found: {directory_path}",
+ )
+
+ except Exception as e:
+ logger.error(f"Directory cleanup failed for {cleanup_type}: {e}")
+ return _create_cleanup_result(cleanup_type=cleanup_type, status="failed", error=e)
+
+
+def _get_execution_directories(context: CallbackContext) -> list[tuple[str, any, str]]:
+ """Determine execution directories to clean, supporting both API and workflow directories for API executions.
+
+ Args:
+ context: Callback context with execution details
+
+ Returns:
+ List of tuples (directory_path, storage_type, cleanup_type) to clean
+
+ Raises:
+ ValueError: If execution type cannot be determined
+ """
+ from unstract.filesystem import FileStorageType
+ from unstract.workflow_execution.execution_file_handler import ExecutionFileHandler
+
+ # Determine if this is an API or workflow execution
+ is_api_execution = context.pipeline_data and context.pipeline_data.get(
+ "is_api", False
+ )
+
+ directories_to_clean = []
+
+ if is_api_execution and context.pipeline_id and context.workflow_id:
+ # API execution - clean BOTH API execution directory AND workflow execution directory
+
+ # 1. API execution directory
+ try:
+ api_execution_dir = ExecutionFileHandler.get_api_execution_dir(
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ )
+ directories_to_clean.append((api_execution_dir, FileStorageType.API, "api"))
+ logger.info(f"Added API execution directory for cleanup: {api_execution_dir}")
+ except Exception as e:
+ logger.warning(f"Could not get API execution directory: {e}")
+
+ # 2. Workflow execution directory (files may exist here too for API executions)
+ try:
+ file_handler = ExecutionFileHandler(
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ )
+ workflow_execution_dir = file_handler.execution_dir
+ directories_to_clean.append(
+ (workflow_execution_dir, FileStorageType.WORKFLOW_EXECUTION, "workflow")
+ )
+ logger.info(
+ f"Added workflow execution directory for cleanup: {workflow_execution_dir}"
+ )
+ except Exception as e:
+ logger.warning(f"Could not get workflow execution directory: {e}")
+
+ elif context.workflow_id:
+ # Non-API workflow execution - clean only workflow execution directory
+ try:
+ file_handler = ExecutionFileHandler(
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ )
+ execution_dir = file_handler.execution_dir
+ directories_to_clean.append(
+ (execution_dir, FileStorageType.WORKFLOW_EXECUTION, "workflow")
+ )
+ logger.info(
+ f"Added workflow execution directory for cleanup: {execution_dir}"
+ )
+ except Exception as e:
+ logger.warning(f"Could not get workflow execution directory: {e}")
+
+ else:
+ raise ValueError(
+ f"Cannot determine execution type: is_api={is_api_execution}, "
+ f"workflow_id={context.workflow_id}, pipeline_id={context.pipeline_id}"
+ )
+
+ if not directories_to_clean:
+ raise ValueError("No directories could be determined for cleanup")
+
+ return directories_to_clean
+
+
+def _cleanup_execution_directory(context: CallbackContext) -> dict[str, Any]:
+ """Clean up execution directories with enhanced logic for API executions.
+
+ For API executions: Cleans both API execution directory AND workflow execution directory
+ For non-API executions: Cleans only workflow execution directory
+
+ Args:
+ context: Callback context with execution details
+
+ Returns:
+ Directory cleanup result dictionary with details for each directory cleaned
+ """
+ try:
+ # Get all directories to clean (multiple for API executions)
+ directories_to_clean = _get_execution_directories(context)
+
+ logger.info(
+ f"🧹 Starting directory cleanup for execution {context.execution_id} "
+ f"({len(directories_to_clean)} directories to clean)"
+ )
+
+ cleanup_results = []
+ total_files_deleted = 0
+ successful_cleanups = 0
+ failed_cleanups = 0
+
+ # Clean each directory
+ for directory_path, storage_type, cleanup_type in directories_to_clean:
+ try:
+ logger.info(f"🧹 Cleaning {cleanup_type} directory: {directory_path}")
+
+ # Setup file system for this directory type
+ file_storage = _setup_file_system(storage_type)
+
+ # Perform cleanup for this directory
+ cleanup_result = _cleanup_directory(
+ file_storage, directory_path, cleanup_type
+ )
+ cleanup_results.append(cleanup_result)
+
+ # Track statistics
+ if cleanup_result.get("status") == "success":
+ successful_cleanups += 1
+ total_files_deleted += cleanup_result.get("files_deleted", 0)
+ else:
+ if cleanup_result.get("status") == "failed":
+ failed_cleanups += 1
+
+ except Exception as dir_error:
+ logger.error(
+ f"Failed to clean {cleanup_type} directory {directory_path}: {dir_error}"
+ )
+ cleanup_results.append(
+ _create_cleanup_result(
+ cleanup_type=cleanup_type,
+ status="failed",
+ error=dir_error,
+ failed_paths=[directory_path],
+ )
+ )
+ failed_cleanups += 1
+
+ # Determine overall status
+ if successful_cleanups > 0 and failed_cleanups == 0:
+ overall_status = "success"
+ elif successful_cleanups > 0 and failed_cleanups > 0:
+ overall_status = "partial"
+ elif successful_cleanups == 0 and failed_cleanups > 0:
+ overall_status = "failed"
+ else:
+ overall_status = "skipped" # All directories were skipped (not found)
+
+ # Create comprehensive result
+ return {
+ "status": overall_status,
+ "directories_processed": len(directories_to_clean),
+ "successful_cleanups": successful_cleanups,
+ "failed_cleanups": failed_cleanups,
+ "total_files_deleted": total_files_deleted,
+ "cleanup_details": cleanup_results,
+ "message": f"Cleaned {successful_cleanups}/{len(directories_to_clean)} directories, {total_files_deleted} files deleted",
+ }
+
+ except ValueError as ve:
+ logger.warning(f"⚠️ {ve}")
+ return _create_cleanup_result(
+ cleanup_type="unknown", status="skipped", message=str(ve)
+ )
+ except Exception as e:
+ logger.error(f"Failed to setup directory cleanup: {e}")
+ return _create_cleanup_result(
+ cleanup_type="unknown", status="failed", error=f"Setup error: {str(e)}"
+ )
+
+
+def _cleanup_backend_cache(context: CallbackContext) -> dict[str, Any]:
+ """Clean up backend cache for non-API deployments.
+
+ Args:
+ context: Callback context with execution details
+
+ Returns:
+ Backend cleanup result dictionary
+ """
+ try:
+ # Only clear execution cache for non-API deployments
+ # API deployments may need cache persistence for subsequent requests
+ if not _is_api_deployment(context):
+ _cleanup_execution_cache_direct(context)
+ logger.info(
+ "✅ Direct execution cache cleanup completed for non-API deployment"
+ )
+ return _create_cleanup_result(
+ cleanup_type="backend",
+ status="cleaned_direct",
+ method="direct_cache_cleanup",
+ message="Execution cache cleared for non-API deployment",
+ )
+ else:
+ logger.info("ℹ️ Cache cleanup skipped for API deployment (cache preserved)")
+ return _create_cleanup_result(
+ cleanup_type="backend",
+ status="skipped",
+ reason="api_deployment",
+ message="Cache preserved for API deployment",
+ )
+ except Exception as e:
+ logger.warning(f"Direct cache cleanup failed: {e}")
+ return _create_cleanup_result(cleanup_type="backend", status="failed", error=e)
+
+
+def _cleanup_execution_resources(context: CallbackContext) -> dict[str, Any]:
+ """Streamlined resource cleanup with unified logic for backend cache and directories.
+
+ REFACTORED: Eliminated ~200 lines of duplicated code by extracting common utilities.
+ Now uses shared functions for consistent error handling and result structures.
+
+ Args:
+ context: Callback context with execution details
+
+ Returns:
+ Cleanup result dictionary with status and details
+ """
+ # 1. Backend cache cleanup
+ backend_result = _cleanup_backend_cache(context)
+
+ # 2. Directory cleanup (unified logic for API and workflow)
+ directory_result = _cleanup_execution_directory(context)
+
+ # 3. Aggregate results with consistent status logic
+ backend_success = backend_result.get("status") in [
+ "success",
+ "completed",
+ "skipped",
+ "cleaned_direct",
+ ]
+ directory_success = directory_result.get("status") in ["success", "skipped"]
+
+ overall_status = "completed" if (backend_success and directory_success) else "partial"
+
+ return {
+ "status": overall_status,
+ "backend": backend_result,
+ "directories": directory_result,
+ }
+
+
+def _process_batch_callback_core(
+ task_instance, results, *args, **kwargs
+) -> dict[str, Any]:
+ """Unified callback processing using shared helper functions.
+
+ Uses the same unified functions as API callbacks to eliminate code duplication
+ and ensure consistent timeout detection logic across all callback types.
+
+ Args:
+ task_instance: The Celery task instance (self)
+ results (list): List of results from each batch
+ **kwargs: Additional arguments including execution_id, pipeline_id, organization_id
+
+ Returns:
+ Callback processing result with unified execution flow
+ """
+ # Initialize performance optimizations
+ _initialize_performance_managers()
+
+ # Extract and validate all parameters using single source of truth
+ context = _extract_callback_parameters(task_instance, results, kwargs)
+
+ # Validate that context is properly set up (API client and organization already configured in _extract_callback_parameters)
+ if not context.organization_id or not context.api_client:
+ logger.error(
+ f"CRITICAL: Context not properly initialized for execution {context.execution_id}. "
+ f"organization_id={context.organization_id}, api_client={context.api_client is not None}"
+ )
+ raise RuntimeError(f"Invalid context for execution {context.execution_id}")
+ with log_context(
+ task_id=context.task_id,
+ execution_id=context.execution_id,
+ workflow_id=context.workflow_id,
+ organization_id=context.organization_id,
+ pipeline_id=context.pipeline_id,
+ ):
+ logger.info(
+ f"Starting batch callback processing for execution {context.execution_id}"
+ )
+
+ try:
+ # Use unified status determination with timeout detection (shared with API callback)
+ aggregated_results, execution_status, expected_files = (
+ _determine_execution_status_unified(
+ file_batch_results=results,
+ api_client=context.api_client,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ )
+ )
+ # Update workflow execution status using unified function
+ execution_update_result = _update_execution_status_unified(
+ api_client=context.api_client,
+ execution_id=context.execution_id,
+ final_status=execution_status,
+ aggregated_results=aggregated_results,
+ organization_id=context.organization_id,
+ error_message=None,
+ )
+ # Handle pipeline updates using unified function (non-API deployment)
+ pipeline_result = _handle_pipeline_updates_unified(
+ context, execution_status, is_api_deployment=False
+ )
+
+ # Add missing UI logs for cost and final workflow status (matching backend behavior)
+ _publish_final_workflow_ui_logs(
+ context=context,
+ aggregated_results=aggregated_results,
+ execution_status=execution_status,
+ )
+
+ # Handle resource cleanup using existing function
+ cleanup_result = _cleanup_execution_resources(context)
+ callback_result = {
+ "status": "completed",
+ "execution_id": context.execution_id,
+ "workflow_id": context.workflow_id,
+ "task_id": context.task_id,
+ "aggregated_results": aggregated_results,
+ "execution_status": execution_status,
+ "expected_files": expected_files,
+ "execution_update_result": execution_update_result,
+ "pipeline_result": pipeline_result,
+ "cleanup_result": cleanup_result,
+ "pipeline_id": context.pipeline_id,
+ "unified_callback": True,
+ "shared_timeout_detection": True,
+ }
+
+ logger.info(
+ f"Completed unified callback processing for execution {context.execution_id} "
+ f"with status {execution_status}"
+ )
+ # Handle notifications using unified function (non-critical)
+ try:
+ notification_result = _handle_notifications_unified(
+ api_client=context.api_client,
+ status=execution_status,
+ organization_id=context.organization_id,
+ execution_id=context.execution_id,
+ pipeline_id=context.pipeline_id,
+ workflow_id=context.workflow_id,
+ pipeline_name=context.pipeline_name,
+ pipeline_type=context.pipeline_type,
+ error_message=None,
+ )
+ callback_result["notification_result"] = notification_result
+ except Exception as notif_error:
+ logger.warning(f"Failed to handle notifications: {notif_error}")
+ callback_result["notification_result"] = {
+ "status": "failed",
+ "error": str(notif_error),
+ }
+
+ return callback_result
+
+ except Exception as e:
+ logger.error(
+ f"Unified batch callback processing failed for execution {context.execution_id}: {e}"
+ )
+
+ # Try to mark execution as failed using unified function
+ try:
+ _update_execution_status_unified(
+ context.api_client,
+ context.execution_id,
+ ExecutionStatus.ERROR.value,
+ {"error": str(e)[:500]},
+ context.organization_id,
+ error_message=str(e)[:500],
+ )
+ logger.info(
+ f"Marked execution {context.execution_id} as failed using unified function"
+ )
+ except Exception as cleanup_error:
+ logger.error(f"Failed to mark execution as failed: {cleanup_error}")
+
+ # Re-raise for Celery retry mechanism
+ raise
+
+
+ bind=True,
+ name=TaskName.PROCESS_BATCH_CALLBACK,
+ max_retries=0, # Match Django backend pattern
+ ignore_result=False, # Match Django backend pattern
+ # Timeout inherited from global Celery config (CALLBACK_TASK_TIME_LIMIT env var)
+)
+@monitor_performance
+@circuit_breaker(failure_threshold=5, recovery_timeout=120.0)
+def process_batch_callback(self, results, *args, **kwargs) -> dict[str, Any]:
+ """Callback task to handle batch processing results.
+
+ This is the main task entry point for new workers.
+
+ Args:
+ results (list): List of results from each batch
+ **kwargs: Additional arguments including execution_id
+
+ Returns:
+ Callback processing result
+ """
+ return _process_batch_callback_core(self, results, *args, **kwargs)
+
+
+ bind=True,
+ name="process_batch_callback_api",
+ autoretry_for=(Exception,),
+ max_retries=3,
+ retry_backoff=True,
+ retry_backoff_max=300,
+ retry_jitter=True,
+ # Timeout inherited from global Celery config (CALLBACK_TASK_TIME_LIMIT env var)
+)
+@monitor_performance
+@circuit_breaker(failure_threshold=5, recovery_timeout=120.0)
+def process_batch_callback_api(
+ self,
+ file_batch_results: list[dict[str, Any]],
+ *args,
+ **kwargs,
+) -> dict[str, Any]:
+ """Lightweight API batch callback processing task.
+
+ This handles the final step of API workflow execution after all file batches complete.
+ In a chord, this receives the results from all file processing tasks.
+
+ Args:
+ file_batch_results: Results from all file processing tasks (from chord)
+ kwargs: Contains execution_id, pipeline_id, organization_id
+
+ Returns:
+ Final execution result
+ """
+ task_id = self.request.id
+
+ # Extract parameters from kwargs (passed by API deployment worker)
+ execution_id = kwargs.get("execution_id")
+ pipeline_id = kwargs.get("pipeline_id")
+ organization_id = kwargs.get("organization_id")
+
+ if not execution_id:
+ raise ValueError("execution_id is required in kwargs")
+
+ logger.info(
+ f"API callback received: execution_id={execution_id}, pipeline_id={pipeline_id}, organization_id={organization_id}"
+ )
+
+ # Get workflow execution context via API to get workflow_id and schema_name
+ # Create organization-scoped API client using factory pattern
+ if not organization_id:
+ raise ValueError("organization_id is required for API callback")
+
+ api_client = create_api_client(organization_id)
+ logger.info(f"Created organization-scoped API client: {organization_id}")
+
+ execution_response = api_client.get_workflow_execution(
+ execution_id, file_execution=False
+ )
+ if not execution_response.success:
+ raise Exception(f"Failed to get execution context: {execution_response.error}")
+ execution_context = execution_response.data
+ workflow_execution = execution_context.get("execution", {})
+ workflow = execution_context.get("workflow", {})
+
+ # Extract schema_name and workflow_id from context
+ schema_name = organization_id # For API callbacks, schema_name = organization_id
+ workflow_id = workflow_execution.get("workflow_id") or workflow.get("id")
+
+ logger.info(
+ f"Extracted context: schema_name={schema_name}, workflow_id={workflow_id}, pipeline_id={pipeline_id}"
+ )
+
+ with log_context(
+ task_id=task_id,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ ):
+ logger.info(
+ f"Processing API callback for execution {execution_id} with {len(file_batch_results)} batch results"
+ )
+
+ try:
+ # Create organization-scoped API client using factory pattern
+ api_client = create_api_client(schema_name)
+
+ # Get pipeline name and type (simplified approach)
+ if not pipeline_id:
+ error_msg = f"No pipeline_id provided for API callback. execution_id={execution_id}, workflow_id={workflow_id}"
+ logger.error(error_msg)
+ raise ValueError(error_msg)
+
+ # Use simplified pipeline data fetching
+ pipeline_name, pipeline_type = _fetch_pipeline_data_simplified(
+ pipeline_id, schema_name, api_client, is_api_deployment=True
+ )
+
+ if pipeline_name:
+ logger.info(
+ f"✅ Found pipeline: name='{pipeline_name}', type='{pipeline_type}'"
+ )
+ else:
+ logger.warning(f"Could not fetch pipeline data for {pipeline_id}")
+ pipeline_name = "Unknown API"
+ pipeline_type = PipelineType.API.value
+
+ # Use unified status determination with timeout detection
+ aggregated_results, execution_status, expected_files = (
+ _determine_execution_status_unified(
+ file_batch_results=file_batch_results,
+ api_client=api_client,
+ execution_id=execution_id,
+ organization_id=organization_id,
+ )
+ )
+
+ # Update workflow execution status using unified function
+ execution_update_result = _update_execution_status_unified(
+ api_client=api_client,
+ execution_id=execution_id,
+ final_status=execution_status,
+ aggregated_results=aggregated_results,
+ organization_id=organization_id,
+ )
+
+ # Create minimal context for unified pipeline handling
+ context = CallbackContext()
+ context.pipeline_id = pipeline_id
+ context.execution_id = execution_id
+ context.organization_id = organization_id
+ context.workflow_id = workflow_id
+ context.pipeline_name = pipeline_name
+ context.pipeline_type = pipeline_type
+ context.api_client = api_client
+
+ # Add missing UI logs for cost and final workflow status (matching backend behavior)
+ _publish_final_workflow_ui_logs_api(
+ context=context,
+ aggregated_results=aggregated_results,
+ execution_status=execution_status,
+ )
+
+ # Handle pipeline updates (skip for API deployments)
+ pipeline_result = _handle_pipeline_updates_unified(
+ context=context, final_status=execution_status, is_api_deployment=True
+ )
+
+ # Handle notifications using unified function
+ notification_result = _handle_notifications_unified(
+ api_client=api_client,
+ status=execution_status,
+ organization_id=organization_id,
+ execution_id=execution_id,
+ pipeline_id=pipeline_id,
+ workflow_id=workflow_id,
+ pipeline_name=pipeline_name,
+ pipeline_type=pipeline_type,
+ error_message=None,
+ )
+
+ callback_result = {
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "pipeline_id": pipeline_id,
+ "status": "completed",
+ "total_files_processed": aggregated_results.get(
+ "total_files_processed", 0
+ ),
+ "total_execution_time": aggregated_results.get("total_execution_time", 0),
+ "batches_processed": len(file_batch_results),
+ "task_id": task_id,
+ "expected_files": expected_files, # Include expected files for debugging
+ "execution_update": execution_update_result,
+ "pipeline_update": pipeline_result,
+ "notifications": notification_result,
+ "optimization": {
+ "method": "unified_callback_functions",
+ "eliminated_code_duplication": True,
+ "shared_timeout_detection": True,
+ },
+ }
+
+ logger.info(
+ f"Successfully completed API callback for execution {execution_id}"
+ )
+ return callback_result
+
+ except Exception as e:
+ logger.error(
+ f"API callback processing failed for execution {execution_id}: {e}"
+ )
+
+ # Try to update execution status to failed
+ try:
+ # Create organization-scoped API client for error handling
+ api_client = create_api_client(schema_name)
+ # Update execution status to error
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=str(e)[:500], # Limit error message length
+ organization_id=schema_name,
+ )
+
+ # OPTIMIZATION: Skip pipeline status update for API deployments on error
+ if pipeline_id:
+ logger.info(
+ f"OPTIMIZATION: Skipping pipeline status update for API deployment {pipeline_id} on error (no Pipeline record exists)"
+ )
+ except Exception as update_error:
+ logger.error(f"Failed to update execution status: {update_error}")
+
+ raise
+
+
+def _publish_final_workflow_ui_logs(
+ context: "CallbackContext",
+ aggregated_results: dict[str, Any],
+ execution_status: str,
+) -> None:
+ """Publish final workflow UI logs for cost and execution summary.
+
+ This matches the backend's file_execution_tasks.py:361-371 behavior to provide
+ consistent UI feedback for workflow completion including cost tracking.
+
+ Args:
+ context: Callback context with execution details
+ aggregated_results: Aggregated file processing results
+ execution_status: Final execution status
+ """
+ try:
+ # Extract file statistics from aggregated results
+ total_files = aggregated_results.get("total_files", 0)
+ successful_files = aggregated_results.get("successful_files", 0)
+ failed_files = aggregated_results.get("failed_files", 0)
+
+ # Get execution data to extract cost information (with cost calculation)
+ execution_response = context.api_client.get_workflow_execution(
+ context.execution_id, include_cost=True, file_execution=False
+ )
+ if not execution_response.success:
+ logger.warning(
+ f"Could not get execution data for UI logging in {context.execution_id}: {execution_response.error}"
+ )
+ return
+
+ # Cost data is at the top level of response when include_cost=True
+ aggregated_usage_cost = execution_response.data.get("aggregated_usage_cost")
+
+ # Create workflow logger for UI feedback
+ # Use general workflow logger since this is called from general workflow callback
+ workflow_logger = WorkerWorkflowLogger.create_for_general_workflow(
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ pipeline_id=context.pipeline_id,
+ )
+
+ if workflow_logger:
+ # Publish average cost log (matches backend file_execution_tasks.py:361-366)
+ workflow_logger.publish_average_cost_log(
+ worker_logger=logger,
+ total_files=total_files,
+ execution_id=context.execution_id,
+ total_cost=aggregated_usage_cost,
+ )
+
+ # Publish final workflow logs (matches backend file_execution_tasks.py:367-371)
+ workflow_logger.publish_final_workflow_logs(
+ total_files=total_files,
+ successful_files=successful_files,
+ failed_files=failed_files,
+ )
+
+ logger.info(
+ f"Published final UI logs for execution {context.execution_id}: "
+ f"{total_files} total, {successful_files} successful, {failed_files} failed, "
+ f"cost: ${aggregated_usage_cost}"
+ )
+ else:
+ logger.warning(
+ f"Could not create workflow logger for UI logging in {context.execution_id}"
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to publish final workflow UI logs for {context.execution_id}: {str(e)}"
+ )
+
+
+def _publish_final_workflow_ui_logs_api(
+ context: "CallbackContext",
+ aggregated_results: dict[str, Any],
+ execution_status: str,
+) -> None:
+ """Publish final workflow UI logs for API workflow cost and execution summary.
+
+ This matches the backend's file_execution_tasks.py:361-371 behavior to provide
+ consistent UI feedback for API workflow completion including cost tracking.
+
+ Args:
+ context: Callback context with execution details
+ aggregated_results: Aggregated file processing results
+ execution_status: Final execution status
+ """
+ try:
+ # Extract file statistics from aggregated results
+ total_files = aggregated_results.get("total_files", 0)
+ successful_files = aggregated_results.get("successful_files", 0)
+ failed_files = aggregated_results.get("failed_files", 0)
+
+ # Get execution data to extract cost information (with cost calculation)
+ execution_response = context.api_client.get_workflow_execution(
+ context.execution_id, include_cost=True, file_execution=False
+ )
+ if not execution_response.success:
+ logger.warning(
+ f"Could not get execution data for UI logging in API workflow {context.execution_id}: {execution_response.error}"
+ )
+ return
+
+ # Cost data is at the top level of response when include_cost=True
+ aggregated_usage_cost = execution_response.data.get("aggregated_usage_cost")
+
+ # Create workflow logger for UI feedback
+ # Use API workflow logger since this is called from API workflow callback
+ workflow_logger = WorkerWorkflowLogger.create_for_api_workflow(
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ pipeline_id=context.pipeline_id,
+ )
+
+ if workflow_logger:
+ # Publish average cost log (matches backend file_execution_tasks.py:361-366)
+ workflow_logger.publish_average_cost_log(
+ worker_logger=logger,
+ total_files=total_files,
+ execution_id=context.execution_id,
+ total_cost=aggregated_usage_cost,
+ )
+
+ # Publish final workflow logs (matches backend file_execution_tasks.py:367-371)
+ workflow_logger.publish_final_workflow_logs(
+ total_files=total_files,
+ successful_files=successful_files,
+ failed_files=failed_files,
+ )
+
+ logger.info(
+ f"Published final UI logs for API workflow {context.execution_id}: "
+ f"{total_files} total, {successful_files} successful, {failed_files} failed, "
+ f"cost: ${aggregated_usage_cost}"
+ )
+ else:
+ logger.warning(
+ f"Could not create API workflow logger for UI logging in {context.execution_id}"
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to publish final workflow UI logs for API workflow {context.execution_id}: {str(e)}"
+ )
+
+
+ bind=True,
+ name="workflow_manager.workflow_v2.file_execution_tasks.process_batch_callback",
+ max_retries=0,
+ ignore_result=False,
+)
+def process_batch_callback_django_compat(
+ self, results, *args, **kwargs
+) -> dict[str, Any]:
+ """Backward compatibility wrapper for Django backend callback task name.
+
+ This allows new workers to handle callback tasks sent from the old Django backend
+ during the transition period when both systems are running.
+
+ Args:
+ results: Batch processing results from Django backend
+ *args: Additional arguments
+ **kwargs: Additional keyword arguments
+
+ Returns:
+ Same result as process_batch_callback
+ """
+ logger.info(
+ "Processing batch callback via Django compatibility task name: "
+ "workflow_manager.workflow_v2.file_execution_tasks.process_batch_callback"
+ )
+
+ # Delegate to the core implementation (same as main task)
+ return _process_batch_callback_core(self, results, *args, **kwargs)
diff --git a/workers/callback/worker.py b/workers/callback/worker.py
new file mode 100644
index 000000000..10f18e034
--- /dev/null
+++ b/workers/callback/worker.py
@@ -0,0 +1,72 @@
+"""Callback Worker
+
+Celery worker for processing file processing callbacks and status updates.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker - this executes when module is imported by Celery
+logger = WorkerLogger.setup(WorkerType.CALLBACK)
+app, config = WorkerBuilder.build_celery_app(WorkerType.CALLBACK)
+
+
+def check_callback_health():
+ """Custom health check for callback worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="callback_health",
+ status=HealthStatus.HEALTHY,
+ message="Callback worker is healthy",
+ details={
+ "worker_type": "callback",
+ "api_client": "healthy",
+ "queues": [
+ "file_processing_callback",
+ "api_file_processing_callback",
+ ],
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="callback_health",
+ status=HealthStatus.DEGRADED,
+ message="Callback worker partially functional",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="callback_health",
+ status=HealthStatus.DEGRADED,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.CALLBACK, "callback_health", check_callback_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "callback",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "callback-worker",
+ }
diff --git a/workers/client_plugin_registry.py b/workers/client_plugin_registry.py
new file mode 100644
index 000000000..41bc4d939
--- /dev/null
+++ b/workers/client_plugin_registry.py
@@ -0,0 +1,315 @@
+"""Client Plugin Registry for Workers
+
+This registry system allows dynamic loading of API client plugins based on
+Django settings configuration. This eliminates the need for conditional imports
+and try/except blocks while maintaining clean separation between OSS and cloud features.
+
+The registry follows the same pattern as the main plugin registry but is
+specifically designed for API client extensions.
+"""
+
+import logging
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+class APIClientPlugin:
+ """Base class for API client plugins."""
+
+ name: str = ""
+ description: str = ""
+ version: str = "1.0.0"
+
+ def __init__(self, config: Any):
+ """Initialize the plugin with configuration."""
+ self.config = config
+
+ def close(self):
+ """Clean up plugin resources."""
+ pass
+
+
+class ClientPluginRegistry:
+ """Registry for API client plugins loaded from Django settings."""
+
+ def __init__(self):
+ self._plugins: dict[str, type[APIClientPlugin]] = {}
+ self._instances: dict[str, APIClientPlugin] = {}
+ self._initialized = False
+
+ def initialize_from_settings(self):
+ """Initialize plugins from environment configuration (Django not required in workers)."""
+ if self._initialized:
+ return
+
+ try:
+ self._initialize_worker_plugins()
+ except Exception as e:
+ logger.error(
+ f"Failed to initialize client plugins from settings: {e}", exc_info=True
+ )
+
+ self._initialized = True
+
+ def _initialize_worker_plugins(self):
+ """Initialize plugins for workers environment (no Django dependencies)."""
+ # Auto-discover plugins from plugin directories
+ worker_plugins = self._discover_worker_plugins()
+
+ for plugin_name, plugin_config in worker_plugins.items():
+ if not plugin_config.get("enabled", False):
+ continue
+
+ try:
+ self._load_plugin_from_config_worker(plugin_name, plugin_config)
+ logger.debug(f"Loaded worker client plugin: {plugin_name}")
+ except Exception as e:
+ logger.debug(f"Failed to load worker client plugin {plugin_name}: {e}")
+
+ def _discover_worker_plugins(self) -> dict[str, dict[str, Any]]:
+ """Auto-discover plugins from plugin directories."""
+ import importlib.util
+ import os
+
+ discovered_plugins = {}
+
+ # Get plugins directory
+ workers_dir = os.path.dirname(__file__)
+ plugins_dir = os.path.join(workers_dir, "plugins")
+
+ if not os.path.exists(plugins_dir):
+ logger.debug(f"Plugins directory not found: {plugins_dir}")
+ return discovered_plugins
+
+ logger.debug(f"Scanning for plugins in: {plugins_dir}")
+
+ # Scan plugin directories
+ for item in os.listdir(plugins_dir):
+ plugin_path = os.path.join(plugins_dir, item)
+
+ # Skip files, only process directories
+ if not os.path.isdir(plugin_path):
+ continue
+
+ # Skip __pycache__ and other system directories
+ if item.startswith("__") or item.startswith("."):
+ continue
+
+ init_file = os.path.join(plugin_path, "__init__.py")
+ if not os.path.exists(init_file):
+ logger.debug(f"Skipping {item}: no __init__.py found")
+ continue
+
+ try:
+ # Load the plugin's __init__.py to check for CLIENT_PLUGIN_CONFIG
+ spec = importlib.util.spec_from_file_location(
+ f"plugins.{item}", init_file
+ )
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+
+ # Check if the plugin has CLIENT_PLUGIN_CONFIG
+ if hasattr(module, "CLIENT_PLUGIN_CONFIG"):
+ config = module.CLIENT_PLUGIN_CONFIG
+ # Use directory name as plugin name (standard convention)
+ discovered_plugins[item] = config
+ logger.debug(f"Discovered plugin: {item} with config: {config}")
+ else:
+ logger.debug(f"Plugin {item} has no CLIENT_PLUGIN_CONFIG, skipping")
+
+ except Exception as e:
+ logger.debug(f"Failed to load plugin {item}: {e}")
+
+ logger.debug(
+ f"Discovered {len(discovered_plugins)} plugins: {list(discovered_plugins.keys())}"
+ )
+ return discovered_plugins
+
+ def _load_plugin_from_config_worker(self, plugin_name: str, config: dict[str, Any]):
+ """Load a plugin from configuration for workers (handles relative imports better)."""
+ plugin_path = config.get("plugin_path")
+ if not plugin_path:
+ raise ValueError(f"Plugin {plugin_name} missing plugin_path")
+
+ try:
+ # For workers, use importlib with proper path handling
+ import importlib
+ import os
+
+ # Convert plugin path to file path
+ module_path, class_name = plugin_path.rsplit(".", 1)
+ relative_path = module_path.replace(".", os.sep) + ".py"
+
+ # Get absolute path from workers directory
+ workers_dir = os.path.dirname(__file__)
+ plugin_file_path = os.path.join(workers_dir, relative_path)
+
+ if os.path.exists(plugin_file_path):
+ # Use importlib.util for file-based import
+ import importlib.util
+
+ spec = importlib.util.spec_from_file_location(
+ module_path, plugin_file_path
+ )
+ module = importlib.util.module_from_spec(spec)
+
+ # Execute the module to load the class
+ spec.loader.exec_module(module)
+ plugin_class = getattr(module, class_name)
+
+ # Validate plugin class
+ if not issubclass(plugin_class, APIClientPlugin):
+ raise TypeError(
+ f"Plugin {plugin_name} must inherit from APIClientPlugin"
+ )
+
+ # Register the plugin class
+ self._plugins[plugin_name] = plugin_class
+ logger.debug(
+ f"Successfully loaded plugin class {class_name} from {plugin_file_path}"
+ )
+ else:
+ logger.debug(f"Plugin file not found: {plugin_file_path}")
+
+ except Exception as e:
+ logger.debug(f"Failed to load plugin {plugin_name} using worker loader: {e}")
+ # Fall back to standard import if file-based loading fails
+ try:
+ module_path, class_name = plugin_path.rsplit(".", 1)
+ module = __import__(module_path, fromlist=[class_name])
+ plugin_class = getattr(module, class_name)
+
+ if not issubclass(plugin_class, APIClientPlugin):
+ raise TypeError(
+ f"Plugin {plugin_name} must inherit from APIClientPlugin"
+ )
+
+ self._plugins[plugin_name] = plugin_class
+ logger.debug(f"Loaded plugin {plugin_name} using fallback import")
+ except Exception as fallback_error:
+ raise Exception(
+ f"Both file-based and import-based loading failed: {e}, {fallback_error}"
+ )
+
+ def _load_plugin_from_config(self, plugin_name: str, config: dict[str, Any]):
+ """Load a plugin from configuration."""
+ plugin_path = config.get("plugin_path")
+ if not plugin_path:
+ raise ValueError(f"Plugin {plugin_name} missing plugin_path")
+
+ # Import the plugin module
+ module_path, class_name = plugin_path.rsplit(".", 1)
+ module = __import__(module_path, fromlist=[class_name])
+ plugin_class = getattr(module, class_name)
+
+ # Validate plugin class
+ if not issubclass(plugin_class, APIClientPlugin):
+ raise TypeError(f"Plugin {plugin_name} must inherit from APIClientPlugin")
+
+ # Register the plugin class
+ self._plugins[plugin_name] = plugin_class
+
+ def register_plugin_class(self, name: str, plugin_class: type[APIClientPlugin]):
+ """Manually register a plugin class."""
+ if not issubclass(plugin_class, APIClientPlugin):
+ raise TypeError(f"Plugin {name} must inherit from APIClientPlugin")
+
+ self._plugins[name] = plugin_class
+ logger.debug(f"Manually registered client plugin: {name}")
+
+ def get_plugin_instance(
+ self, name: str, config: Any = None
+ ) -> APIClientPlugin | None:
+ """Get or create a plugin instance."""
+ self.initialize_from_settings()
+
+ # Return cached instance if available
+ if name in self._instances:
+ return self._instances[name]
+
+ # Create new instance if plugin class is registered
+ if name in self._plugins:
+ try:
+ plugin_class = self._plugins[name]
+ instance = plugin_class(config)
+ self._instances[name] = instance
+ logger.debug(f"Created instance for client plugin: {name}")
+ return instance
+ except Exception as e:
+ logger.error(f"Failed to create instance for client plugin {name}: {e}")
+ return None
+
+ return None
+
+ def has_plugin(self, name: str) -> bool:
+ """Check if a plugin is available."""
+ self.initialize_from_settings()
+ return name in self._plugins
+
+ def list_available_plugins(self) -> list[dict[str, Any]]:
+ """List all available client plugins."""
+ self.initialize_from_settings()
+
+ plugins = []
+ for name, plugin_class in self._plugins.items():
+ plugins.append(
+ {
+ "name": name,
+ "description": getattr(plugin_class, "description", ""),
+ "version": getattr(plugin_class, "version", "1.0.0"),
+ "enabled": True,
+ }
+ )
+
+ return plugins
+
+ def close_all_instances(self):
+ """Close all plugin instances."""
+ for instance in self._instances.values():
+ try:
+ instance.close()
+ except Exception as e:
+ logger.warning(f"Error closing client plugin instance: {e}")
+
+ self._instances.clear()
+
+ def clear(self):
+ """Clear all plugins and instances."""
+ self.close_all_instances()
+ self._plugins.clear()
+ self._initialized = False
+
+
+# Global registry instance
+_client_plugin_registry = ClientPluginRegistry()
+
+
+def get_client_plugin(name: str, config: Any = None) -> APIClientPlugin | None:
+ """Get a client plugin instance by name."""
+ return _client_plugin_registry.get_plugin_instance(name, config)
+
+
+def has_client_plugin(name: str) -> bool:
+ """Check if a client plugin is available."""
+ return _client_plugin_registry.has_plugin(name)
+
+
+def list_client_plugins() -> list[dict[str, Any]]:
+ """List all available client plugins."""
+ return _client_plugin_registry.list_available_plugins()
+
+
+def register_client_plugin(name: str, plugin_class: type[APIClientPlugin]):
+ """Register a client plugin class."""
+ _client_plugin_registry.register_plugin_class(name, plugin_class)
+
+
+def close_all_client_plugins():
+ """Close all client plugin instances."""
+ _client_plugin_registry.close_all_instances()
+
+
+def initialize_client_plugins():
+ """Initialize client plugins from settings."""
+ _client_plugin_registry.initialize_from_settings()
diff --git a/workers/file_processing/__init__.py b/workers/file_processing/__init__.py
new file mode 100644
index 000000000..b3f8b74a9
--- /dev/null
+++ b/workers/file_processing/__init__.py
@@ -0,0 +1,19 @@
+"""Lightweight File Processing Worker
+
+This worker handles file processing tasks using internal APIs instead of
+direct Django ORM access, implementing the hybrid approach for tool execution.
+"""
+
+from .tasks import (
+ process_file_batch,
+ process_file_batch_api,
+ process_file_batch_resilient,
+)
+from .worker import app as celery_app
+
+__all__ = [
+ "celery_app",
+ "process_file_batch",
+ "process_file_batch_api",
+ "process_file_batch_resilient",
+]
diff --git a/workers/file_processing/tasks.py b/workers/file_processing/tasks.py
new file mode 100644
index 000000000..2a0fc15ed
--- /dev/null
+++ b/workers/file_processing/tasks.py
@@ -0,0 +1,1840 @@
+"""File Processing Worker Tasks
+
+Exact implementation matching Django backend patterns for file processing tasks.
+Uses WorkflowExecutionService pattern exactly like the Django backend.
+This replaces the heavy Django process_file_batch task with API-based coordination.
+"""
+
+import json
+import os
+import time
+from typing import Any
+
+# Import shared worker infrastructure
+from shared.api import InternalAPIClient
+
+# Import from shared worker modules
+from shared.constants import Account
+
+# Import shared enums and dataclasses
+from shared.enums import ErrorType
+from shared.enums.task_enums import TaskName
+from shared.infrastructure import create_api_client
+from shared.infrastructure.context import StateStore
+from shared.infrastructure.logging import (
+ WorkerLogger,
+ WorkerWorkflowLogger,
+ log_context,
+ monitor_performance,
+ with_execution_context,
+)
+from shared.infrastructure.logging.helpers import (
+ log_file_info,
+ log_file_processing_error,
+ log_file_processing_start,
+ log_file_processing_success,
+)
+from shared.models.execution_models import (
+ WorkflowContextData,
+ create_organization_context,
+)
+from shared.processing.files.processor import FileProcessor
+
+# Import manual review service with WorkflowUtil access
+from worker import app
+
+from unstract.core.data_models import (
+ ExecutionStatus,
+ FileBatchData,
+ FileBatchResult,
+ FileHashData,
+ PreCreatedFileData,
+ WorkerFileData,
+)
+from unstract.core.worker_models import FileProcessingResult
+
+logger = WorkerLogger.get_logger(__name__)
+
+# Constants
+APPLICATION_OCTET_STREAM = "application/octet-stream"
+
+
+def _calculate_manual_review_requirements(
+ file_batch_data: dict[str, Any], api_client: InternalAPIClient
+) -> dict[int, bool]:
+ """Calculate manual review requirements for Django compatibility task.
+
+ This function replicates the MRQ logic from @workers/general for files
+ coming from the Django backend that lack manual review flags.
+
+ Args:
+ file_batch_data: File batch data from Django backend
+ api_client: API client for backend communication
+
+ Returns:
+ Dictionary mapping file numbers to is_manualreview_required flags
+ """
+ try:
+ # Get basic info from batch data
+ files = file_batch_data.get("files", [])
+ file_data = file_batch_data.get("file_data", {})
+
+ if not files:
+ logger.info("No files found, skipping MRQ calculation")
+ return {}
+
+ # Check if Django backend already provides q_file_no_list
+ q_file_no_list = file_data.get("q_file_no_list", [])
+
+ if not q_file_no_list:
+ logger.info("No q_file_no_list found in file_data, skipping MRQ calculation")
+ return {}
+
+ # Use Django backend's pre-calculated q_file_no_list
+ logger.info(
+ f"Django compatibility: Using provided q_file_no_list with {len(q_file_no_list)} files "
+ f"selected from {len(files)} total files for manual review"
+ )
+
+ # Create mapping of file numbers to manual review requirements
+ mrq_flags = {}
+ for file_item in files:
+ # Handle different file item formats (tuple, list, dict)
+ if len(file_item) < 2:
+ continue
+
+ file_number = file_item[1].get("file_number")
+
+ if not file_number:
+ continue
+
+ is_manual_review_required = file_number in q_file_no_list
+ mrq_flags[file_number] = is_manual_review_required
+
+ logger.debug(
+ f"File #{file_number}: is_manualreview_required={is_manual_review_required}"
+ )
+
+ return mrq_flags
+
+ except Exception as e:
+ logger.error(f"Error calculating manual review requirements: {e}", exc_info=True)
+ # Return empty dict so files proceed without manual review flags
+ return {}
+
+
+def _enhance_batch_with_mrq_flags(
+ file_batch_data: dict[str, Any], mrq_flags: dict[int, bool]
+) -> None:
+ """Enhance file batch data with manual review flags.
+
+ Args:
+ file_batch_data: File batch data to enhance (modified in place)
+ mrq_flags: Dictionary mapping file numbers to is_manualreview_required flags
+ """
+ try:
+ files = file_batch_data.get("files", [])
+
+ if not files:
+ logger.warning(
+ "Django compatibility: No files found in batch data, skipping MRQ flag enhancement"
+ )
+ return
+
+ if not mrq_flags:
+ logger.info(
+ "Django compatibility: No MRQ flags provided, all files will proceed without manual review"
+ )
+ # Set all files to not require manual review
+ for file_item in files:
+ if isinstance(file_item, (tuple, list)) and len(file_item) >= 2:
+ file_hash_dict = file_item[1]
+ if isinstance(file_hash_dict, dict):
+ file_hash_dict["is_manualreview_required"] = False
+ elif isinstance(file_item, dict):
+ file_item["is_manualreview_required"] = False
+ return
+
+ manual_review_count = 0
+ total_files = len(files)
+
+ for file_item in files:
+ try:
+ # Handle different file item formats consistently with calculation function
+ if isinstance(file_item, (tuple, list)) and len(file_item) >= 2:
+ # Format: (file_name, file_hash_dict)
+ file_name, file_hash_dict = file_item[0], file_item[1]
+ if isinstance(file_hash_dict, dict):
+ file_number = file_hash_dict.get("file_number", 1)
+ is_manual_review_required = mrq_flags.get(file_number, False)
+ file_hash_dict["is_manualreview_required"] = (
+ is_manual_review_required
+ )
+
+ if is_manual_review_required:
+ manual_review_count += 1
+ logger.debug(
+ f"Django compatibility: File '{file_name}' #{file_number} marked for manual review"
+ )
+ else:
+ logger.warning(
+ f"Django compatibility: Invalid file hash dict format for file {file_name}"
+ )
+
+ elif isinstance(file_item, dict):
+ # Format: {file_name: "...", file_number: ...}
+ file_number = file_item.get("file_number", 1)
+ is_manual_review_required = mrq_flags.get(file_number, False)
+ file_item["is_manualreview_required"] = is_manual_review_required
+
+ if is_manual_review_required:
+ manual_review_count += 1
+ file_name = file_item.get("file_name", f"file_{file_number}")
+ logger.debug(
+ f"Django compatibility: File '{file_name}' #{file_number} marked for manual review"
+ )
+ else:
+ logger.warning(
+ f"Django compatibility: Unknown file item format: {type(file_item)}, skipping MRQ flag enhancement"
+ )
+
+ except Exception as file_error:
+ logger.warning(
+ f"Django compatibility: Failed to enhance MRQ flag for file item {file_item}: {file_error}"
+ )
+ continue
+
+ logger.info(
+ f"Django compatibility: Enhanced {total_files} files with MRQ flags. "
+ f"{manual_review_count} files marked for manual review, "
+ f"{total_files - manual_review_count} files will proceed directly to destination."
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Django compatibility: Failed to enhance batch with MRQ flags: {e}",
+ exc_info=True,
+ )
+
+
+def _process_file_batch_core(
+ task_instance, file_batch_data: dict[str, Any]
+) -> dict[str, Any]:
+ """Core implementation of file batch processing.
+
+ This function contains the actual processing logic that both the new task
+ and Django compatibility task will use.
+
+ Args:
+ task_instance: The Celery task instance (self)
+ file_batch_data: Dictionary that will be converted to FileBatchData dataclass
+
+ Returns:
+ Dictionary with successful_files and failed_files counts
+ """
+ celery_task_id = (
+ task_instance.request.id if hasattr(task_instance, "request") else "unknown"
+ )
+
+ # Step 1: Validate and parse input data
+ batch_data = _validate_and_parse_batch_data(file_batch_data)
+
+ # Step 2: Setup execution context
+ context = _setup_execution_context(batch_data, celery_task_id)
+
+ # Step 3: Handle manual review logic
+ # context = _handle_manual_review_logic(context)
+
+ # Step 4: Pre-create file executions
+ context = _refactored_pre_create_file_executions(context)
+
+ # Step 5: Process individual files
+ context = _process_individual_files(context)
+
+ # Step 7: Compile and return final result
+ return _compile_batch_result(context)
+
+
+ bind=True,
+ name=TaskName.PROCESS_FILE_BATCH,
+ max_retries=0, # Match Django backend pattern
+ ignore_result=False, # Result is passed to the callback task
+ retry_backoff=True,
+ retry_backoff_max=500, # Match Django backend
+ retry_jitter=True,
+ default_retry_delay=5, # Match Django backend
+ # Timeout inherited from global Celery config (FILE_PROCESSING_TASK_TIME_LIMIT env var)
+)
+@monitor_performance
+def process_file_batch(self, file_batch_data: dict[str, Any]) -> dict[str, Any]:
+ """Process a batch of files in parallel using Celery.
+
+ This is the main task entry point for new workers.
+
+ Args:
+ file_batch_data: Dictionary that will be converted to FileBatchData dataclass
+
+ Returns:
+ Dictionary with successful_files and failed_files counts
+ """
+ return _process_file_batch_core(self, file_batch_data)
+
+
+def _validate_and_parse_batch_data(file_batch_data: dict[str, Any]) -> FileBatchData:
+ """Validate and parse input data into typed dataclass.
+
+ Args:
+ file_batch_data: Raw input dictionary
+
+ Returns:
+ Validated FileBatchData instance
+
+ Raises:
+ ValueError: If data structure is invalid
+ RuntimeError: If unexpected parsing error occurs
+ """
+ try:
+ batch_data = FileBatchData.from_dict(file_batch_data)
+ logger.info(
+ f"Successfully parsed FileBatchData with {len(batch_data.files)} files"
+ )
+ return batch_data
+ except (TypeError, ValueError) as e:
+ logger.error(f"FileBatchData validation failed: {str(e)}")
+ logger.error(
+ f"Input data structure: keys={list(file_batch_data.keys()) if isinstance(file_batch_data, dict) else 'not a dict'}"
+ )
+ raise ValueError(
+ f"Invalid file batch data structure: {str(e)}. "
+ f"Expected dict with 'files' (list) and 'file_data' (dict) fields."
+ ) from e
+ except Exception as e:
+ logger.error(f"Unexpected error parsing file batch data: {str(e)}", exc_info=True)
+ raise RuntimeError(f"Failed to parse file batch data: {str(e)}") from e
+
+
+def _setup_execution_context(
+ batch_data: FileBatchData, celery_task_id: str
+) -> WorkflowContextData:
+ """Setup execution context with validation and API client initialization.
+
+ Args:
+ batch_data: Validated batch data
+ celery_task_id: Celery task ID for tracking
+
+ Returns:
+ WorkflowContextData containing type-safe execution context
+
+ Raises:
+ ValueError: If required context fields are missing
+ """
+ # Extract context using dataclass
+ file_data = batch_data.file_data
+ files = batch_data.files
+ execution_id = file_data.execution_id
+ workflow_id = file_data.workflow_id
+ organization_id = file_data.organization_id
+
+ # Validate required context
+ if not execution_id or not workflow_id or not organization_id:
+ raise ValueError(
+ f"Invalid execution context: execution_id='{execution_id}', "
+ f"workflow_id='{workflow_id}', organization_id='{organization_id}'"
+ )
+
+ logger.info(
+ f"[Celery Task: {celery_task_id}] Processing {len(files)} files for execution {execution_id[:8]}..."
+ )
+
+ # Set organization context exactly like Django backend
+ StateStore.set(Account.ORGANIZATION_ID, organization_id)
+
+ # Create organization-scoped API client using factory pattern
+ api_client = create_api_client(organization_id)
+
+ # Create organization context
+ org_context = create_organization_context(organization_id, api_client)
+
+ logger.info(
+ f"Initializing file batch processing for execution {execution_id}, organization {organization_id}"
+ )
+
+ # Get workflow execution context
+ execution_response = api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(f"Failed to get execution context: {execution_response.error}")
+ execution_context = execution_response.data
+ workflow_execution = execution_context.get("execution", {})
+
+ # Set LOG_EVENTS_ID in StateStore for WebSocket messaging (critical for UI logs)
+ # This enables the WorkerWorkflowLogger to send logs to the UI via WebSocket
+ execution_log_id = workflow_execution.get("execution_log_id")
+ if execution_log_id:
+ # Set LOG_EVENTS_ID like backend Celery workers do
+ StateStore.set("LOG_EVENTS_ID", execution_log_id)
+ logger.info(f"Set LOG_EVENTS_ID for WebSocket messaging: {execution_log_id}")
+ else:
+ logger.warning(
+ f"No execution_log_id found for execution {execution_id}, WebSocket logs may not be delivered"
+ )
+
+ # Update execution status to EXECUTING when processing starts
+ # This fixes the missing EXECUTION status in logs
+ try:
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.EXECUTING.value,
+ )
+ logger.info(f"Updated workflow execution {execution_id} status to EXECUTING")
+ except Exception as status_error:
+ logger.warning(f"Failed to update execution status to EXECUTING: {status_error}")
+
+ # Initialize WebSocket logger for UI logs
+ from shared.infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+
+ workflow_logger = WorkerWorkflowLogger.create_for_file_processing(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=getattr(file_data, "pipeline_id", None)
+ if hasattr(file_data, "pipeline_id")
+ else None,
+ )
+
+ # Send initial workflow logs to UI
+ workflow_logger.publish_initial_workflow_logs(len(files))
+
+ # Set log events ID in StateStore like Django backend
+ log_events_id = workflow_execution.get("execution_log_id")
+ if log_events_id:
+ StateStore.set("LOG_EVENTS_ID", log_events_id)
+
+ # Get workflow name and type from execution context
+ workflow_name = workflow_execution.get("workflow_name", f"workflow-{workflow_id}")
+ workflow_type = workflow_execution.get("workflow_type", "TASK")
+
+ # Get use_file_history from execution parameters (passed from API request)
+ # This is the correct behavior - use_file_history should come from the API request, not workflow config
+ # file_data is a WorkerFileData dataclass, so we can access use_file_history directly
+ try:
+ use_file_history = file_data.use_file_history
+ logger.info(
+ f"File history from execution parameters for workflow {workflow_id}: use_file_history = {use_file_history}"
+ )
+ except AttributeError as e:
+ logger.warning(
+ f"Failed to access use_file_history from dataclass, trying dict access: {e}"
+ )
+ # Fallback to dict access for backward compatibility
+ if hasattr(file_data, "get"):
+ use_file_history = file_data.get("use_file_history", True)
+ else:
+ use_file_history = getattr(file_data, "use_file_history", True)
+ logger.info(
+ f"File history from fallback access for workflow {workflow_id}: use_file_history = {use_file_history}"
+ )
+
+ # Create type-safe workflow context
+ context_data = WorkflowContextData(
+ workflow_id=workflow_id,
+ workflow_name=workflow_name,
+ workflow_type=workflow_type,
+ execution_id=execution_id,
+ organization_context=org_context,
+ files={
+ f"file_{i}": file for i, file in enumerate(files)
+ }, # Convert list to dict format
+ settings={
+ "use_file_history": use_file_history,
+ "celery_task_id": celery_task_id,
+ },
+ metadata={
+ "batch_data": batch_data,
+ "file_data": file_data,
+ "result": FileBatchResult(),
+ "successful_files_for_manual_review": [],
+ "execution_context": execution_context,
+ "workflow_execution": workflow_execution,
+ "total_files": len(files),
+ "workflow_logger": workflow_logger,
+ },
+ is_scheduled=False,
+ )
+
+ return context_data
+
+
+def _refactored_pre_create_file_executions(
+ context: WorkflowContextData,
+) -> WorkflowContextData:
+ """Pre-create all WorkflowFileExecution records to prevent duplicates.
+
+ Args:
+ context: Workflow context data
+
+ Returns:
+ Updated context with pre-created file execution data
+ """
+ files = list(context.files.values()) # Convert dict back to list
+ workflow_id = context.workflow_id
+ execution_id = context.execution_id
+ api_client = context.organization_context.api_client
+ workflow_type = context.workflow_type
+ is_api_workflow = context.metadata.get("is_api_workflow", False)
+ file_data = context.metadata.get("file_data")
+
+ # CRITICAL: Pre-create all WorkflowFileExecution records to prevent duplicates
+ # This matches the backend's _pre_create_file_executions pattern for ALL workflow types
+ pre_created_file_executions: dict[str, PreCreatedFileData] = (
+ _pre_create_file_executions(
+ file_data=file_data,
+ files=files,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ api_client=api_client,
+ workflow_type=workflow_type,
+ is_api=is_api_workflow,
+ use_file_history=context.get_setting("use_file_history", True),
+ )
+ )
+ logger.info(
+ f"Pre-created {len(pre_created_file_executions)} WorkflowFileExecution records for {workflow_type} workflow"
+ )
+
+ # Add to metadata
+ context.pre_created_file_executions = pre_created_file_executions
+
+ return context
+
+
+def _process_individual_files(context: WorkflowContextData) -> WorkflowContextData:
+ """Process each file individually through the workflow.
+
+ Args:
+ context: Workflow context data
+
+ Returns:
+ Updated context with processing results
+ """
+ files = list(context.files.values()) # Convert dict back to list
+ file_data = context.metadata["file_data"]
+ # CRITICAL FIX: Use q_file_no_list from context metadata for manual review decisions
+ # q_file_no_list = context.metadata.get("q_file_no_list", set())
+ use_file_history = context.get_setting("use_file_history", True)
+ api_client = context.organization_context.api_client
+ workflow_execution = context.metadata["workflow_execution"]
+ pre_created_file_executions = context.pre_created_file_executions
+ result = context.metadata["result"]
+ successful_files_for_manual_review = context.metadata[
+ "successful_files_for_manual_review"
+ ]
+ celery_task_id = context.get_setting("celery_task_id", "unknown")
+ total_files = context.metadata["total_files"]
+
+ # Process each file - handle list, tuple, and dictionary formats
+ for file_number, file_item in enumerate(files, 1):
+ # Handle Django list format (from asdict serialization), tuple format, and dictionary format
+ if isinstance(file_item, list):
+ # Django backend format after asdict(): [file_name, file_hash_dict]
+ if len(file_item) != 2:
+ logger.error(
+ f"Invalid file item list length: expected 2, got {len(file_item)}"
+ )
+ result.increment_failure()
+ continue
+ file_name, file_hash_dict = file_item
+ elif isinstance(file_item, tuple):
+ # Legacy tuple format: (file_name, file_hash_dict)
+ file_name, file_hash_dict = file_item
+ elif isinstance(file_item, dict):
+ # Dictionary format: {"file_name": "...", "file_path": "...", ...}
+ file_name = file_item.get("file_name")
+ file_hash_dict = file_item # The entire dict is the file hash data
+ else:
+ logger.error(f"Unexpected file item format: {type(file_item)}")
+ result.increment_failure()
+ continue
+
+ pre_created_file_execution = pre_created_file_executions.get(file_name)
+
+ if not pre_created_file_execution:
+ logger.error(
+ f"No pre-created WorkflowFileExecution found for file '{file_name}' - skipping"
+ )
+ result.increment_failure()
+ continue
+
+ file_hash: FileHashData = pre_created_file_execution.file_hash
+ if not file_hash:
+ logger.error(f"File hash not found for file '{file_name}'")
+ result.increment_failure()
+ continue
+
+ logger.info(
+ f"[{celery_task_id}][{file_number}/{total_files}] Processing file '{file_name}'"
+ )
+
+ # Track individual file processing time
+ import time
+
+ file_start_time = time.time()
+ logger.info(
+ f"TIMING: File processing START for {file_name} at {file_start_time:.6f}"
+ )
+
+ # DEBUG: Log the file hash data being sent to ensure unique identification
+ logger.info(
+ f"File hash data for {file_name}: provider_file_uuid='{file_hash.provider_file_uuid}', file_path='{file_hash.file_path}'"
+ )
+
+ # CRITICAL FIX: Preserve original file_number from source, don't override with batch enumeration
+ original_file_number = (
+ file_hash_dict.get("file_number") if file_hash_dict else None
+ )
+ if original_file_number is not None:
+ # Use the original file number assigned in source connector (global numbering)
+ file_hash.file_number = original_file_number
+ logger.info(
+ f"Using original global file_number {original_file_number} for '{file_name}' (batch position {file_number})"
+ )
+ else:
+ # Fallback to batch enumeration if original file number not available
+ file_hash.file_number = file_number
+ logger.warning(
+ f"No original file_number found for '{file_name}', using batch position {file_number}"
+ )
+
+ # Set use_file_history flag based on workflow determination
+ file_hash.use_file_history = use_file_history
+
+ # Don't Remove These Comments
+ # CRITICAL FIX: Apply manual review decision using q_file_no_list with correct global file number
+ # Get WorkflowUtil via manual review service factory (handles plugin registry automatically)
+ # manual_review_service = get_manual_review_service(
+ # api_client=api_client, organization_id=context.organization_context.organization_id
+ # )
+ # workflow_util = manual_review_service.get_workflow_util()
+ # file_hash = workflow_util.add_file_destination_filehash(
+ # file_hash.file_number, q_file_no_list, file_hash
+ # )
+
+ # Log manual review decision
+ if file_hash.is_manualreview_required:
+ logger.info(
+ f"👥 File {file_name} (#{file_hash.file_number}) MARKED FOR MANUAL REVIEW - destination: {file_hash.file_destination}"
+ )
+ else:
+ logger.info(
+ f"File {file_name} (#{file_hash.file_number}) marked for destination processing - destination: {getattr(file_hash, 'file_destination', 'destination')}"
+ )
+
+ logger.debug(f"File hash for file {file_name}: {file_hash}")
+
+ # Get pre-created WorkflowFileExecution data
+
+ workflow_file_execution_id = pre_created_file_execution.id
+ workflow_file_execution_object = pre_created_file_execution.object
+
+ # Send file processing start log to UI with file_execution_id
+ workflow_logger = context.metadata.get("workflow_logger")
+ log_file_processing_start(
+ workflow_logger,
+ workflow_file_execution_id,
+ file_name,
+ file_number,
+ total_files,
+ )
+
+ # Send destination routing UI log now that we have workflow_logger and file_execution_id
+ if workflow_logger and workflow_file_execution_id:
+ if file_hash.is_manualreview_required:
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"🔄 File '{file_name}' marked for MANUAL REVIEW - sending to review queue",
+ )
+ else:
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"📤 File '{file_name}' marked for DESTINATION processing",
+ )
+
+ # Process single file using Django-like pattern but with API coordination
+ file_execution_result = _process_file(
+ current_file_idx=file_number,
+ total_files=total_files,
+ file_data=file_data,
+ file_hash=file_hash,
+ api_client=api_client,
+ workflow_execution=workflow_execution,
+ workflow_file_execution_id=workflow_file_execution_id, # Pass pre-created ID
+ workflow_file_execution_object=workflow_file_execution_object, # Pass pre-created object
+ workflow_logger=workflow_logger, # Pass workflow logger for UI logging
+ )
+
+ # Handle file processing result
+ _handle_file_processing_result(
+ file_execution_result,
+ file_name,
+ file_start_time,
+ result,
+ successful_files_for_manual_review,
+ file_hash,
+ api_client,
+ context.workflow_id,
+ context.execution_id,
+ workflow_logger,
+ workflow_file_execution_id,
+ celery_task_id, # Pass celery task ID to detect API queue
+ context.metadata.get(
+ "is_api_workflow", False
+ ), # Pass existing API workflow detection
+ )
+
+ # Update metadata with results
+ context.metadata["result"] = result
+ context.metadata["successful_files_for_manual_review"] = (
+ successful_files_for_manual_review
+ )
+
+ return context
+
+
+def _handle_file_processing_result(
+ file_execution_result: FileProcessingResult,
+ file_name: str,
+ file_start_time: float,
+ result: FileBatchResult,
+ successful_files_for_manual_review: list,
+ file_hash: FileHashData,
+ api_client: Any,
+ workflow_id: str,
+ execution_id: str,
+ workflow_logger: WorkerWorkflowLogger,
+ file_execution_id: str,
+ celery_task_id: str,
+ is_api_workflow: bool,
+) -> None:
+ """Handle the result of individual file processing.
+
+ Args:
+ file_execution_result: Result from file processing
+ file_name: Name of the processed file
+ file_start_time: Start time for performance tracking
+ result: Batch result tracker
+ successful_files_for_manual_review: List of successful files
+ file_hash: File hash data
+ api_client: Internal API client
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ workflow_logger: Workflow logger instance
+ file_execution_id: File execution ID
+ celery_task_id: Celery task ID for queue detection
+ is_api_workflow: Whether this is an API workflow (from existing detection)
+ """
+ # Handle null execution result
+ if file_execution_result is None:
+ _handle_null_execution_result(
+ file_name, result, api_client, workflow_id, execution_id
+ )
+ return
+
+ # Calculate execution time
+ file_execution_time = _calculate_execution_time(file_name, file_start_time)
+
+ # Update file execution status in database
+ _update_file_execution_status(
+ file_execution_result, file_name, file_execution_time, api_client
+ )
+
+ # Update batch execution time
+ _update_batch_execution_time(result, file_execution_time)
+
+ # Log cost details for this file (regardless of success/failure, matches backend pattern)
+ if workflow_logger:
+ # Create file-specific logger for proper log routing to UI
+ file_logger = workflow_logger.create_file_logger(file_execution_id)
+
+ # Log cost using file-specific logger (ensures file_execution_id context)
+ file_logger.log_total_cost_per_file(
+ worker_logger=logger,
+ file_execution_id=file_execution_id,
+ file_name=file_name,
+ api_client=api_client,
+ )
+
+ # Handle success or failure based on execution result
+ if _has_execution_errors(file_execution_result):
+ _handle_failed_execution(
+ file_execution_result,
+ file_name,
+ result,
+ workflow_logger,
+ file_execution_id,
+ api_client,
+ workflow_id,
+ execution_id,
+ )
+ else:
+ _handle_successful_execution(
+ file_execution_result,
+ file_name,
+ result,
+ successful_files_for_manual_review,
+ file_hash,
+ workflow_logger,
+ file_execution_id,
+ api_client,
+ workflow_id,
+ )
+
+
+def _compile_batch_result(context: WorkflowContextData) -> dict[str, Any]:
+ """Compile the final batch processing result.
+
+ Args:
+ context: Workflow context data
+
+ Returns:
+ Final result dictionary
+ """
+ result = context.metadata["result"]
+ workflow_logger = context.metadata.get("workflow_logger")
+
+ # Send execution completion summary to UI
+ if workflow_logger:
+ workflow_logger.publish_execution_complete(
+ successful_files=result.successful_files,
+ failed_files=result.failed_files,
+ total_time=result.execution_time,
+ )
+
+ logger.info(
+ f"Function tasks.process_file_batch completed successfully. "
+ f"Batch execution time: {result.execution_time:.2f}s for "
+ f"{result.successful_files + result.failed_files} files"
+ )
+
+ # CRITICAL: Clean up StateStore to prevent data leaks between tasks
+ try:
+ StateStore.clear_all()
+ logger.debug("🧹 Cleaned up StateStore context to prevent data leaks")
+ except Exception as cleanup_error:
+ logger.warning(f"Failed to cleanup StateStore context: {cleanup_error}")
+
+ # Return the final result matching Django backend format
+ return {
+ "successful_files": result.successful_files,
+ "failed_files": result.failed_files,
+ "total_files": result.successful_files + result.failed_files,
+ "execution_time": result.execution_time,
+ "organization_id": context.organization_context.organization_id,
+ }
+
+
+# HELPER FUNCTIONS (originally part of the massive process_file_batch function)
+# These functions support the refactored file processing workflow
+
+
+def _pre_create_file_executions(
+ file_data: WorkerFileData,
+ files: list[Any],
+ workflow_id: str,
+ execution_id: str,
+ api_client: InternalAPIClient,
+ workflow_type: str,
+ is_api: bool = False,
+ use_file_history: bool = True,
+) -> dict[str, Any]:
+ """Pre-create WorkflowFileExecution records with PENDING status to prevent race conditions.
+
+ This matches the backend's _pre_create_file_executions pattern for ALL workflow types
+ and includes file history deduplication for ETL workflows.
+
+ Args:
+ files: List of file items (can be tuples, lists, or dicts)
+ workflow_id: Workflow ID
+ execution_id: Workflow execution ID
+ api_client: Internal API client
+ workflow_type: Workflow type (API/ETL/TASK)
+ is_api: Whether this is an API workflow
+
+ Returns:
+ Dict mapping file names to {'id': str, 'object': WorkflowFileExecutionData}
+ """
+ pre_created_data: dict[str, PreCreatedFileData] = {}
+
+ # Use the file history flag passed from execution parameters
+ logger.info(
+ f"Using file history parameter for workflow {workflow_id} (type: {workflow_type}): use_file_history = {use_file_history}"
+ )
+
+ for file_item in files:
+ # Parse file item to get name and hash data
+ if isinstance(file_item, list) and len(file_item) == 2:
+ file_name, file_hash_dict = file_item
+ elif isinstance(file_item, tuple):
+ file_name, file_hash_dict = file_item
+ elif isinstance(file_item, dict):
+ file_name = file_item.get("file_name")
+ file_hash_dict = file_item
+ else:
+ logger.error(f"Skipping invalid file item format: {type(file_item)}")
+ continue
+
+ # Create FileHashData from dict
+ file_hash = _create_file_hash_from_dict(
+ file_name=file_name, file_hash_dict=file_hash_dict, file_data=file_data
+ )
+
+ # Set use_file_history flag on the file object for later use
+ file_hash.use_file_history = use_file_history
+
+ # NOTE: File history checking moved to individual file processing
+ # This ensures WorkflowFileExecution records are created for all files
+
+ # Convert to dict for API
+ file_hash_dict_for_api = file_hash.to_dict()
+
+ try:
+ # Create WorkflowFileExecution record for ALL workflow types
+ # CRITICAL FIX: For use_file_history=False, force create fresh records to prevent
+ # reusing completed records from previous executions
+ workflow_file_execution = api_client.get_or_create_workflow_file_execution(
+ execution_id=execution_id,
+ file_hash=file_hash_dict_for_api,
+ workflow_id=workflow_id,
+ force_create=not use_file_history, # Force create when file history is disabled
+ )
+
+ # PROGRESSIVE STATUS UPDATE: Set initial status to PENDING (FIXED)
+ # This ensures file executions start with PENDING status before processing begins
+ try:
+ api_client.file_client.update_file_execution_status(
+ file_execution_id=workflow_file_execution.id,
+ status=ExecutionStatus.PENDING.value,
+ )
+ except Exception as status_error:
+ logger.warning(
+ f"Failed to set initial PENDING status for file {file_name}: {status_error}"
+ )
+ # Don't fail the entire creation if status update fails
+
+ pre_created_data[file_name] = PreCreatedFileData(
+ id=str(workflow_file_execution.id),
+ object=workflow_file_execution,
+ file_hash=file_hash,
+ )
+ logger.info(
+ f"Pre-created WorkflowFileExecution {workflow_file_execution.id} for {workflow_type} file '{file_name}'"
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to pre-create WorkflowFileExecution for '{file_name}': {str(e)}"
+ )
+ # Continue with other files even if one fails
+
+ # File history deduplication now handled during individual file processing
+
+ return pre_created_data
+
+
+def _create_file_hash_from_dict(
+ file_name: str,
+ file_hash_dict: dict[str, Any],
+ file_data: WorkerFileData | None = None,
+) -> FileHashData:
+ """Create FileHashData object from dictionary using shared dataclass.
+
+ This uses the shared FileHashData dataclass for type safety and consistency.
+ It preserves the original file_hash from Django backend or leaves it empty for worker computation.
+
+ Args:
+ file_hash_dict: Dictionary containing file hash data
+
+ Returns:
+ FileHashData instance with type-safe access
+ """
+ if file_hash_dict is None:
+ logger.error("file_hash_dict is None, returning minimal FileHashData")
+ return FileHashData(
+ file_path="",
+ file_name="unknown.txt",
+ file_hash="", # Empty - will be computed during execution
+ file_size=0,
+ mime_type=APPLICATION_OCTET_STREAM,
+ fs_metadata={},
+ is_executed=False,
+ )
+
+ # Use FileHashData for type safety and validation
+ try:
+ # Create FileHashData from input dict for validation and type safety
+ if isinstance(file_hash_dict, dict):
+ file_hash_data = FileHashData.from_dict(file_hash_dict)
+ logger.debug(
+ f"Successfully created FileHashData for {file_hash_data.file_name}"
+ )
+ else:
+ logger.error(f"Expected dict for file_hash_dict, got {type(file_hash_dict)}")
+ raise ValueError(f"Invalid file_hash_dict type: {type(file_hash_dict)}")
+
+ # Return the FileHashData instance directly
+ file_hash = file_hash_data
+ logger.info(f"File hash for {file_hash.file_name}: {file_hash.file_hash}")
+ # Log warning if file_hash is empty to help with debugging
+ if not file_hash.file_hash:
+ logger.warning(
+ f"File hash is empty for '{file_hash.file_name}' - content hash computation may have failed"
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to create FileHashData from dict: {e}", exc_info=True)
+ logger.debug(
+ f"Input dict keys: {list(file_hash_dict.keys()) if isinstance(file_hash_dict, dict) else 'not a dict'}"
+ )
+
+ # Fallback to manual creation for backward compatibility
+ file_name = (
+ file_hash_dict.get("file_name") or file_hash_dict.get("name") or "unknown.txt"
+ )
+ file_path = file_hash_dict.get("file_path") or file_hash_dict.get("path") or ""
+ file_hash_value = file_hash_dict.get("file_hash") or ""
+
+ # Create FileHashData manually for fallback case
+ file_hash = FileHashData(
+ file_path=file_path,
+ file_name=file_name,
+ source_connection_type=file_hash_dict.get("source_connection_type"),
+ file_hash=file_hash_value.strip(), # Will be populated during execution
+ file_size=file_hash_dict.get("file_size") or 0,
+ provider_file_uuid=file_hash_dict.get("provider_file_uuid"),
+ mime_type=file_hash_dict.get("mime_type") or APPLICATION_OCTET_STREAM,
+ fs_metadata=file_hash_dict.get("fs_metadata") or {},
+ file_destination=file_hash_dict.get("file_destination"),
+ is_executed=file_hash_dict.get("is_executed", False),
+ file_number=file_hash_dict.get("file_number"),
+ is_manualreview_required=file_hash_dict.get(
+ "is_manualreview_required", False
+ ),
+ )
+
+ # Log warning if file_hash is empty (fallback case)
+ if not file_hash_value.strip():
+ logger.warning(
+ f"File hash is empty for '{file_name}' in fallback processing - content hash computation may have failed"
+ )
+
+ # Preserve connector metadata if present (for FILESYSTEM workflows)
+ # Store connector metadata in fs_metadata since FileHashData doesn't have dedicated connector fields
+ if "connector_metadata" in file_hash_dict or "connector_id" in file_hash_dict:
+ if not hasattr(file_hash, "fs_metadata") or file_hash.fs_metadata is None:
+ file_hash.fs_metadata = {}
+
+ if "connector_metadata" in file_hash_dict:
+ file_hash.fs_metadata["connector_metadata"] = file_hash_dict[
+ "connector_metadata"
+ ]
+ if "connector_id" in file_hash_dict:
+ file_hash.fs_metadata["connector_id"] = file_hash_dict["connector_id"]
+
+ # Log actual data state for debugging
+ file_name_for_logging = file_hash.file_name or "unknown"
+ if not file_hash_dict.get("file_name"):
+ logger.debug(f"Missing file_name, using: {file_name_for_logging}")
+ if not file_hash_dict.get("file_hash"):
+ logger.info(
+ f"File hash not provided, will be computed during execution for: {file_name_for_logging}"
+ )
+
+ if file_data and file_data.hitl_queue_name:
+ file_hash.hitl_queue_name = file_data.hitl_queue_name
+ file_hash.is_manualreview_required = True # Override manual review flag for HITL
+ logger.info(
+ f"Applied HITL queue name '{file_data.hitl_queue_name}' to file {file_name}"
+ )
+
+ return file_hash
+
+
+def _process_file(
+ current_file_idx: int,
+ total_files: int,
+ file_data: WorkerFileData,
+ file_hash: FileHashData,
+ api_client: InternalAPIClient,
+ workflow_execution: dict[str, Any],
+ workflow_file_execution_id: str = None,
+ workflow_file_execution_object: Any = None,
+ workflow_logger: Any = None,
+) -> dict[str, Any]:
+ """Process a single file matching Django backend _process_file pattern.
+
+ This uses API-based coordination but follows the exact same logic
+ as the Django backend file processing.
+
+ Args:
+ current_file_idx: Index of current file
+ total_files: Total number of files
+ file_data: File data context
+ file_hash: FileHashData instance with type-safe access
+ api_client: Internal API client
+ workflow_execution: Workflow execution context
+
+ Returns:
+ File execution result
+ """
+ # Delegate to the new FileProcessor for better maintainability and testability
+ return FileProcessor.process_file(
+ current_file_idx=current_file_idx,
+ total_files=total_files,
+ file_data=file_data,
+ file_hash=file_hash,
+ api_client=api_client,
+ workflow_execution=workflow_execution,
+ workflow_file_execution_id=workflow_file_execution_id,
+ workflow_file_execution_object=workflow_file_execution_object,
+ workflow_logger=workflow_logger,
+ )
+
+
+ bind=True,
+ name=TaskName.PROCESS_FILE_BATCH_API,
+ max_retries=0, # Match Django backend
+ ignore_result=False,
+ retry_backoff=True,
+ retry_backoff_max=500,
+ retry_jitter=True,
+ default_retry_delay=5,
+ # Timeout inherited from global Celery config (FILE_PROCESSING_TASK_TIME_LIMIT env var)
+)
+@monitor_performance
+def process_file_batch_api(
+ self,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ batch_id: str,
+ created_files: list[dict[str, Any]],
+ pipeline_id: str | None = None,
+ execution_mode: tuple | None = None,
+ use_file_history: bool = False,
+) -> dict[str, Any]:
+ """API file batch processing task matching Django backend pattern.
+
+ This processes files from a created batch for API executions using the
+ exact same pattern as Django backend but with API coordination.
+
+ Args:
+ schema_name: Organization schema name
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ batch_id: File batch ID
+ created_files: List of file execution records
+ pipeline_id: Pipeline ID
+ execution_mode: Execution mode tuple
+ use_file_history: Whether to use file history
+
+ Returns:
+ Processing result matching Django backend structure
+ """
+ task_id = self.request.id
+
+ with log_context(
+ task_id=task_id,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ ):
+ logger.info(
+ f"Processing API file batch {batch_id} with {len(created_files)} files"
+ )
+
+ try:
+ # Set organization context exactly like Django backend
+ StateStore.set(Account.ORGANIZATION_ID, schema_name)
+
+ # Create organization-scoped API client using factory pattern
+ api_client = create_api_client(schema_name)
+
+ # Get workflow execution context
+ execution_response = api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(
+ f"Failed to get execution context: {execution_response.error}"
+ )
+ execution_context = execution_response.data
+ workflow_execution = execution_context.get("execution", {})
+
+ # Set log events ID in StateStore like Django backend
+ log_events_id = workflow_execution.get("execution_log_id")
+ if log_events_id:
+ StateStore.set("LOG_EVENTS_ID", log_events_id)
+ logger.info(f"Set LOG_EVENTS_ID for WebSocket messaging: {log_events_id}")
+
+ # Process each file in the batch using Django-like pattern
+ file_results = []
+ successful_files = 0
+ failed_files = 0
+
+ for file_data in created_files:
+ file_result = _process_single_file_api(
+ api_client=api_client,
+ file_data=file_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ pipeline_id=pipeline_id,
+ use_file_history=use_file_history,
+ )
+ file_results.append(file_result)
+
+ # CRITICAL FIX: Cache ALL file results (including errors) for API response
+ # This ensures the backend can collect all results via get_api_results()
+ # INCLUDING error results which are needed for proper API error reporting
+ if file_result: # Cache both successful AND error results
+ try:
+ from shared.workflow.execution.service import (
+ WorkerWorkflowExecutionService,
+ )
+
+ # Create workflow service for caching
+ workflow_service = WorkerWorkflowExecutionService(
+ api_client=api_client
+ )
+
+ # Convert file result to FileExecutionResult format for caching
+ api_result = {
+ "file": file_result.get("file_name", "unknown"),
+ "file_execution_id": file_result.get("file_execution_id", ""),
+ "result": file_result.get("result_data"),
+ "error": file_result.get("error"),
+ "metadata": {
+ "processing_time": file_result.get("processing_time", 0)
+ },
+ }
+
+ # Cache the result for API response aggregation
+ workflow_service.cache_api_result(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ result=api_result,
+ is_api=True,
+ )
+
+ # Log differently for success vs error
+ if file_result.get("error"):
+ logger.info(
+ f"Cached API ERROR result for file {file_result.get('file_name')}: {file_result.get('error')}"
+ )
+ else:
+ logger.debug(
+ f"Cached API success result for file {file_result.get('file_name')}"
+ )
+
+ except Exception as cache_error:
+ logger.warning(
+ f"Failed to cache API result for file {file_result.get('file_name')}: {cache_error}"
+ )
+
+ # Count results like Django backend
+ if file_result.get("error"):
+ failed_files += 1
+ else:
+ successful_files += 1
+
+ # Return result matching Django FileBatchResult structure
+ batch_result = {
+ "successful_files": successful_files,
+ "failed_files": failed_files,
+ }
+
+ logger.info(f"Successfully processed API file batch {batch_id}")
+ return batch_result
+
+ except Exception as e:
+ logger.error(f"API file batch processing failed for {batch_id}: {e}")
+ raise
+
+
+def _process_single_file_api(
+ api_client: InternalAPIClient,
+ file_data: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ pipeline_id: str | None,
+ use_file_history: bool,
+) -> dict[str, Any]:
+ """Process a single file for API execution using runner service.
+
+ Args:
+ api_client: Internal API client
+ file_data: File execution data
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ pipeline_id: Pipeline ID
+ use_file_history: Whether to use file history
+
+ Returns:
+ File processing result
+ """
+ file_execution_id = file_data.get("id")
+ file_name = file_data.get("file_name", "unknown")
+
+ logger.info(f"Processing file: {file_name} (execution: {file_execution_id})")
+
+ # Update file execution status to EXECUTING when processing starts (using common method)
+ api_client.update_file_status_to_executing(file_execution_id, file_name)
+
+ start_time = time.time()
+
+ try:
+ # 1. Check file history if enabled
+ if use_file_history:
+ history_result = _check_file_history(api_client, file_data, workflow_id)
+ if history_result.get("found"):
+ logger.info(f"File {file_name} found in history, using cached result")
+ return history_result["result"]
+
+ # 2. Get workflow definition from API
+ workflow_definition = api_client.get_workflow_definition(workflow_id)
+ if not workflow_definition:
+ raise ValueError(f"Workflow definition not found for workflow {workflow_id}")
+
+ # 3. Get file content from storage
+ file_content = api_client.get_file_content(file_execution_id)
+ if not file_content:
+ raise ValueError(
+ f"File content not found for file execution {file_execution_id}"
+ )
+
+ # 3.1. Compute and update file hash and mime_type (FIXED: was missing)
+ import hashlib
+ import mimetypes
+
+ if isinstance(file_content, bytes):
+ file_hash_value = hashlib.sha256(file_content).hexdigest()
+ file_size = len(file_content)
+ else:
+ # Handle string content
+ file_bytes = (
+ file_content.encode("utf-8")
+ if isinstance(file_content, str)
+ else file_content
+ )
+ file_hash_value = hashlib.sha256(file_bytes).hexdigest()
+ file_size = len(file_bytes)
+
+ # Determine mime type from file name
+ mime_type, _ = mimetypes.guess_type(file_name)
+ if not mime_type:
+ mime_type = APPLICATION_OCTET_STREAM
+
+ # Update file execution with computed hash, mime_type, and metadata
+ try:
+ api_client.update_workflow_file_execution_hash(
+ file_execution_id=file_execution_id,
+ file_hash=file_hash_value,
+ mime_type=mime_type, # Now properly passed as separate parameter
+ fs_metadata={"computed_during_processing": True, "file_size": file_size},
+ )
+ except Exception as hash_error:
+ logger.warning(f"Failed to update file hash for {file_name}: {hash_error}")
+
+ # 4. Process file through runner service
+ runner_result = _call_runner_service(
+ file_content=file_content,
+ file_name=file_name,
+ workflow_definition=workflow_definition,
+ execution_id=execution_id,
+ pipeline_id=pipeline_id,
+ )
+
+ # 5. Store results via API
+ storage_result = api_client.store_file_execution_result(
+ file_execution_id=file_execution_id, result_data=runner_result
+ )
+
+ processing_time = time.time() - start_time
+
+ result = {
+ "file_execution_id": file_execution_id,
+ "file_name": file_name,
+ "status": "completed",
+ "processing_time": processing_time,
+ "result_data": runner_result,
+ "storage_result": storage_result,
+ }
+
+ logger.info(f"Successfully processed file: {file_name} in {processing_time:.2f}s")
+ return result
+
+ except Exception as e:
+ processing_time = time.time() - start_time
+ logger.error(
+ f"Failed to process file {file_name} after {processing_time:.2f}s: {e}"
+ )
+
+ # Try to update file execution status to failed
+ try:
+ api_client.update_file_execution_status(
+ file_execution_id=file_execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=str(e),
+ )
+ except Exception as update_error:
+ logger.error(f"Failed to update file execution status: {update_error}")
+
+ return {
+ "file_execution_id": file_execution_id,
+ "file_name": file_name,
+ "status": "failed",
+ "processing_time": processing_time,
+ "error": str(e),
+ }
+
+
+def _check_file_history(
+ api_client: InternalAPIClient, file_data: dict[str, Any], workflow_id: str
+) -> dict[str, Any]:
+ """Check if file has been processed before and return cached result.
+
+ Args:
+ api_client: Internal API client
+ file_data: File execution data
+ workflow_id: Workflow ID
+
+ Returns:
+ History check result
+ """
+ try:
+ file_hash = file_data.get("file_hash")
+ cache_key = file_data.get("cache_key", file_hash)
+
+ if not cache_key:
+ return {"found": False}
+
+ history_result = api_client.get_file_history(
+ workflow_id=workflow_id,
+ file_hash=cache_key, # Use cache_key as file_hash
+ file_path=file_data.get("file_path"),
+ )
+
+ return history_result
+
+ except Exception as e:
+ logger.warning(f"Failed to check file history: {e}")
+ return {"found": False}
+
+
+def _call_runner_service(
+ file_content: bytes,
+ file_name: str,
+ workflow_definition: dict[str, Any],
+ execution_id: str,
+ pipeline_id: str | None,
+) -> dict[str, Any]:
+ """Call the runner service to process file through workflow tools.
+
+ Args:
+ file_content: File content bytes
+ file_name: Name of the file
+ workflow_definition: Workflow configuration
+ execution_id: Execution ID
+ pipeline_id: Pipeline ID
+
+ Returns:
+ Processing result from runner service
+ """
+ import requests
+
+ # Build runner service URL
+ runner_host = os.getenv("UNSTRACT_RUNNER_HOST", "http://localhost")
+ runner_port = os.getenv("UNSTRACT_RUNNER_PORT", "5002")
+ runner_url = f"{runner_host}:{runner_port}/api/v1/tool/execute"
+
+ # Prepare request payload
+ payload = {
+ "workflow_definition": workflow_definition,
+ "execution_id": execution_id,
+ "pipeline_id": pipeline_id,
+ "file_metadata": {
+ "file_name": file_name,
+ "mime_type": _detect_mime_type(file_name),
+ "size": len(file_content),
+ },
+ }
+
+ # Prepare files for multipart upload
+ files = {
+ "file": (file_name, file_content, _detect_mime_type(file_name)),
+ "payload": (None, _safe_json_dumps(payload), "application/json"),
+ }
+
+ # Request configuration
+ timeout = int(os.getenv("UNSTRACT_RUNNER_API_TIMEOUT", "120"))
+ retry_count = int(os.getenv("UNSTRACT_RUNNER_API_RETRY_COUNT", "5"))
+ backoff_factor = float(os.getenv("UNSTRACT_RUNNER_API_BACKOFF_FACTOR", "3"))
+
+ logger.info(f"Calling runner service at {runner_url} for file {file_name}")
+
+ for attempt in range(retry_count):
+ try:
+ response = requests.post(
+ runner_url,
+ files=files,
+ timeout=timeout,
+ headers={
+ "X-Execution-ID": execution_id,
+ "X-Pipeline-ID": pipeline_id or "",
+ },
+ )
+
+ response.raise_for_status()
+ result = response.json()
+
+ logger.info(f"Runner service processed file {file_name} successfully")
+ return result
+
+ except requests.exceptions.RequestException as e:
+ if attempt < retry_count - 1:
+ wait_time = backoff_factor**attempt
+ logger.warning(
+ f"Runner service call failed (attempt {attempt + 1}/{retry_count}), retrying in {wait_time}s: {e}"
+ )
+ time.sleep(wait_time)
+ else:
+ logger.error(
+ f"Runner service call failed after {retry_count} attempts: {e}"
+ )
+ raise
+ except Exception as e:
+ logger.error(f"Unexpected error calling runner service: {e}")
+ raise
+
+ raise Exception(f"Failed to call runner service after {retry_count} attempts")
+
+
+def _detect_mime_type(file_name: str) -> str:
+ """Detect MIME type from file extension.
+
+ Args:
+ file_name: Name of the file
+
+ Returns:
+ MIME type string
+ """
+ import mimetypes
+
+ mime_type, _ = mimetypes.guess_type(file_name)
+ return mime_type or APPLICATION_OCTET_STREAM
+
+
+def _safe_json_dumps(data: Any) -> str:
+ """Safely encode data to JSON string with fallback error handling.
+
+ Args:
+ data: Data to be JSON encoded
+
+ Returns:
+ JSON string or fallback string representation
+ """
+ try:
+ return json.dumps(data)
+ except (TypeError, ValueError, json.JSONDecodeError) as e:
+ logger.warning(f"Failed to JSON encode data, falling back to str(): {e}")
+ try:
+ return str(data)
+ except Exception as str_error:
+ logger.error(f"Failed to convert data to string: {str_error}")
+ return "{}"
+
+
+# Simple resilient executor decorator (placeholder)
+def resilient_executor(func):
+ """Simple resilient executor decorator."""
+ return func
+
+
+# Resilient file processor
+@resilient_executor
+@with_execution_context
+def process_file_batch_resilient(
+ self,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[str, dict[str, Any]],
+ **kwargs,
+) -> dict[str, Any]:
+ """Resilient file batch processing with advanced error handling."""
+ logger.info(
+ f"Starting resilient file batch processing for {len(hash_values_of_files)} files"
+ )
+
+ try:
+ # Use the main processing function
+ result = process_file_batch(
+ schema_name=schema_name,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ hash_values_of_files=hash_values_of_files,
+ **kwargs,
+ )
+
+ return result
+
+ except Exception as e:
+ logger.error(f"Resilient file batch processing failed: {e}")
+ raise
+
+
+# Backward compatibility aliases for Django backend during transition
+# Register the same task function with the old Django task names for compatibility
+
+
+ bind=True,
+ name="workflow_manager.workflow_v2.file_execution_tasks.process_file_batch",
+ max_retries=0,
+ ignore_result=False,
+ retry_backoff=True,
+ retry_backoff_max=500,
+ retry_jitter=True,
+ default_retry_delay=5,
+)
+def process_file_batch_django_compat(
+ self, file_batch_data: dict[str, Any]
+) -> dict[str, Any]:
+ """Backward compatibility wrapper for Django backend task name.
+
+ This allows new workers to handle tasks sent from the old Django backend
+ during the transition period when both systems are running.
+
+ Args:
+ file_batch_data: File batch data from Django backend
+
+ Returns:
+ Same result as process_file_batch
+ """
+ logger.info(
+ "Processing file batch via Django compatibility task name: "
+ "workflow_manager.workflow_v2.file_execution_tasks.process_file_batch"
+ )
+
+ # Django compatibility: Calculate and apply manual review requirements
+ # This replicates the MRQ logic that was originally in Django backend
+ try:
+ # Extract organization_id from Django backend data structure
+ # Django sends: {files: [...], file_data: {organization_id: "...", ...}}
+ file_data = file_batch_data.get("file_data", {})
+ organization_id = file_data.get("organization_id")
+
+ if not organization_id:
+ logger.warning(
+ "Django compatibility: No organization_id found in file_data, skipping MRQ calculation"
+ )
+ else:
+ # Create organization-scoped API client
+ api_client = create_api_client(organization_id)
+
+ # Calculate manual review requirements
+ mrq_flags = _calculate_manual_review_requirements(file_batch_data, api_client)
+
+ # Enhance batch data with MRQ flags
+ _enhance_batch_with_mrq_flags(file_batch_data, mrq_flags)
+
+ logger.info(
+ f"Django compatibility: Applied manual review flags to file batch for org {organization_id}"
+ )
+
+ except Exception as e:
+ logger.warning(f"Django compatibility: Failed to calculate MRQ flags: {e}")
+ raise
+ # Continue processing without MRQ flags rather than failing
+
+ # Delegate to the core implementation (same as main task)
+ return _process_file_batch_core(self, file_batch_data)
+
+
+# Helper functions for refactored _handle_file_processing_result
+
+
+def _handle_null_execution_result(
+ file_name: str,
+ result: FileBatchResult,
+ api_client: Any,
+ workflow_id: str,
+ execution_id: str,
+) -> None:
+ """Handle case where file execution result is None."""
+ result.increment_failure()
+ logger.error(
+ f"File execution for file {file_name} returned None - treating as failed"
+ )
+
+ try:
+ api_client.increment_failed_files(
+ workflow_id=workflow_id, execution_id=execution_id
+ )
+ except Exception as increment_error:
+ logger.warning(f"Failed to increment failed files count: {increment_error}")
+
+
+def _calculate_execution_time(file_name: str, file_start_time: float) -> float:
+ """Calculate and log file execution time."""
+ import time
+
+ file_end_time = time.time()
+ file_execution_time = file_end_time - file_start_time
+
+ logger.info(f"TIMING: File processing END for {file_name} at {file_end_time:.6f}")
+ logger.info(f"TIMING: File processing TOTAL time: {file_execution_time:.3f}s")
+ logger.info(
+ f"File {file_name} processing completed in {file_execution_time:.2f} seconds"
+ )
+ return file_execution_time
+
+
+def _update_file_execution_status(
+ file_execution_result: FileProcessingResult,
+ file_name: str,
+ file_execution_time: float,
+ api_client: Any,
+) -> None:
+ """Update file execution status in database."""
+ file_execution_id = file_execution_result.file_execution_id
+ if not file_execution_id:
+ logger.warning(
+ f"No file_execution_id found for {file_name}, cannot update execution time"
+ )
+ return
+
+ try:
+ # Check for both workflow errors and destination errors
+ workflow_error = file_execution_result.error
+ destination_error = file_execution_result.destination_error
+ destination_processed = file_execution_result.destination_processed
+
+ # File should be marked as ERROR if there's any error or destination processing failed
+ has_error = workflow_error or destination_error or not destination_processed
+ final_status = (
+ ExecutionStatus.ERROR.value if has_error else ExecutionStatus.COMPLETED.value
+ )
+
+ # Combine error messages for better reporting
+ error_messages = []
+ if workflow_error:
+ error_messages.append(f"{ErrorType.WORKFLOW_ERROR}: {workflow_error}")
+ if destination_error:
+ error_messages.append(f"{ErrorType.DESTINATION_ERROR}: {destination_error}")
+ if not destination_processed and not destination_error:
+ error_messages.append("Destination processing failed")
+
+ combined_error = "; ".join(error_messages) if error_messages else None
+
+ # Update database
+ api_client.update_file_execution_status(
+ file_execution_id=file_execution_id,
+ status=final_status,
+ execution_time=file_execution_time,
+ error_message=combined_error,
+ )
+ logger.info(
+ f"Updated file execution {file_execution_id} with status {final_status} and time {file_execution_time:.2f}s"
+ )
+ except Exception as update_error:
+ logger.warning(
+ f"Failed to update file execution status for {file_name}: {update_error}"
+ )
+
+
+def _update_batch_execution_time(
+ result: FileBatchResult, file_execution_time: float
+) -> None:
+ """Update batch execution time."""
+ result.add_execution_time(file_execution_time)
+ logger.info(
+ f"Added {file_execution_time:.2f}s to batch execution time. "
+ f"Total batch time: {result.execution_time:.2f}s"
+ )
+
+
+def _has_execution_errors(file_execution_result: FileProcessingResult) -> bool:
+ """Check if file execution has any errors."""
+ workflow_error = file_execution_result.error
+ destination_error = file_execution_result.destination_error
+ destination_processed = file_execution_result.destination_processed
+
+ return bool(workflow_error or destination_error or not destination_processed)
+
+
+def _handle_failed_execution(
+ file_execution_result: FileProcessingResult,
+ file_name: str,
+ result: FileBatchResult,
+ workflow_logger: Any,
+ file_execution_id: str,
+ api_client: Any,
+ workflow_id: str,
+ execution_id: str,
+) -> None:
+ """Handle failed file execution."""
+ result.increment_failure()
+
+ # Determine error type and message
+ workflow_error = file_execution_result.error
+ destination_error = file_execution_result.destination_error
+
+ if workflow_error:
+ error_msg = workflow_error
+ error_type = ErrorType.WORKFLOW_ERROR
+ elif destination_error:
+ error_msg = destination_error
+ error_type = ErrorType.DESTINATION_ERROR
+ else:
+ error_msg = "Destination processing failed"
+ error_type = ErrorType.DESTINATION_ERROR
+
+ logger.info(
+ f"File execution for file {file_name} marked as failed with {error_type.lower()}: {error_msg}"
+ )
+
+ # Send failed processing log to UI
+ log_file_processing_error(
+ workflow_logger, file_execution_id, file_name, f"{error_type}: {error_msg}"
+ )
+
+ # Update failed file count in cache
+ try:
+ api_client.increment_failed_files(
+ workflow_id=workflow_id, execution_id=execution_id
+ )
+ except Exception as increment_error:
+ logger.warning(f"Failed to increment failed files count: {increment_error}")
+
+
+def _handle_successful_execution(
+ file_execution_result: FileProcessingResult,
+ file_name: str,
+ result: FileBatchResult,
+ successful_files_for_manual_review: list,
+ file_hash: FileHashData,
+ workflow_logger: Any,
+ file_execution_id: str,
+ api_client: Any,
+ workflow_id: str,
+) -> None:
+ """Handle successful file execution."""
+ result.increment_success()
+ logger.info(f"File execution for file {file_name} marked as successful")
+
+ # Add to successful files for manual review evaluation
+ successful_files_for_manual_review.append((file_name, file_hash))
+
+ # Send successful processing log to UI
+ log_file_processing_success(workflow_logger, file_execution_id, file_name)
diff --git a/workers/file_processing/worker.py b/workers/file_processing/worker.py
new file mode 100644
index 000000000..80794a35b
--- /dev/null
+++ b/workers/file_processing/worker.py
@@ -0,0 +1,70 @@
+"""File Processing Worker
+
+Celery worker for document processing and file handling.
+Handles file uploads, text extraction, and processing workflows.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker
+logger = WorkerLogger.setup(WorkerType.FILE_PROCESSING)
+app, config = WorkerBuilder.build_celery_app(WorkerType.FILE_PROCESSING)
+
+
+def check_file_processing_health():
+ """Custom health check for file processing worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="file_processing_health",
+ status=HealthStatus.HEALTHY,
+ message="File processing worker is healthy",
+ details={
+ "worker_type": "file_processing",
+ "api_client": "healthy",
+ "queues": ["file_processing", "api_file_processing"],
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="file_processing_health",
+ status=HealthStatus.DEGRADED,
+ message="File processing worker partially functional",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="file_processing_health",
+ status=HealthStatus.DEGRADED,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.FILE_PROCESSING, "file_processing_health", check_file_processing_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "file_processing",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "file-processing-worker",
+ }
diff --git a/workers/general/__init__.py b/workers/general/__init__.py
new file mode 100644
index 000000000..d1074d09c
--- /dev/null
+++ b/workers/general/__init__.py
@@ -0,0 +1,20 @@
+"""General Worker
+
+Lightweight Celery worker for general tasks and workflow executions.
+Uses internal APIs instead of direct Django ORM access.
+
+This worker handles:
+- General workflow executions (non-API deployments)
+- Background task processing
+- File processing tasks
+- Task orchestration and coordination
+
+Note: Webhook notifications are now handled by the dedicated notification worker.
+"""
+
+from .tasks import async_execute_bin_general
+from .worker import app as celery_app
+
+__all__ = ["celery_app", "async_execute_bin_general"]
+
+__version__ = "1.0.0"
diff --git a/workers/general/tasks.py b/workers/general/tasks.py
new file mode 100644
index 000000000..bbc0d7a1c
--- /dev/null
+++ b/workers/general/tasks.py
@@ -0,0 +1,1568 @@
+"""General Worker Tasks
+
+Lightweight implementations of general tasks including webhook notifications
+and general workflow executions using internal APIs.
+"""
+
+import time
+from typing import Any
+
+from celery import shared_task
+from scheduler.tasks import execute_pipeline_task_v2
+
+# Import shared worker infrastructure using new structure
+from shared.api import InternalAPIClient
+
+# Import worker-specific data models
+from shared.data.models import (
+ CallbackTaskData,
+ WorkerTaskResponse,
+ WorkflowExecutionStatusUpdate,
+)
+from shared.enums.status_enums import PipelineStatus
+from shared.enums.task_enums import TaskName
+from shared.infrastructure.logging import (
+ WorkerLogger,
+ log_context,
+ monitor_performance,
+)
+from shared.infrastructure.logging.helpers import log_file_info
+from shared.infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+
+# Import execution models for type-safe context handling
+from shared.models.execution_models import (
+ WorkflowContextData,
+ create_organization_context,
+)
+from shared.patterns.retry.utils import circuit_breaker
+from shared.processing.files import FileProcessingUtils
+from shared.processing.types import FileDataValidator, TypeConverter
+from shared.utils.manual_review_factory import get_manual_review_service
+from shared.workflow.connectors.source import WorkerSourceConnector
+from shared.workflow.execution import (
+ WorkerExecutionContext,
+ WorkflowOrchestrationUtils,
+)
+from shared.workflow.execution.tool_validation import validate_workflow_tool_instances
+
+# File management handled by StreamingFileDiscovery
+# Import from local worker module (avoid circular import)
+from worker import app, config
+
+# Import shared data models for type safety
+from unstract.core.data_models import (
+ ExecutionStatus,
+ FileBatchData,
+ FileHashData,
+ WorkerFileData,
+)
+
+# Import common workflow utilities
+from unstract.core.workflow_utils import WorkflowTypeDetector
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+# Webhook tasks removed - they should only be handled by the notification worker
+
+
+def _log_batch_statistics_to_ui(
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None,
+ message: str,
+) -> None:
+ """Helper method to log batch processing statistics to UI.
+
+ Args:
+ execution_id: Execution ID for workflow logger
+ organization_id: Organization ID for workflow logger
+ pipeline_id: Pipeline ID for workflow logger
+ message: Message to log to UI
+ """
+ try:
+ workflow_logger = WorkerWorkflowLogger.create_for_general_workflow(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+
+ if workflow_logger:
+ log_file_info(
+ workflow_logger,
+ None, # Execution-level logging
+ message,
+ )
+ except Exception as log_error:
+ logger.debug(f"Failed to log batch statistics: {log_error}")
+
+
+# File filtering handled by StreamingFileDiscovery
+
+
+def _log_batch_creation_statistics(
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None,
+ batches: list,
+) -> None:
+ """Helper method to log batch creation statistics to UI.
+
+ Args:
+ execution_id: Execution ID for workflow logger
+ organization_id: Organization ID for workflow logger
+ pipeline_id: Pipeline ID for workflow logger
+ batches: List of file batches created
+ """
+ total_files_in_batches = sum(len(batch) for batch in batches)
+ batch_sizes = [len(batch) for batch in batches]
+ avg_batch_size = sum(batch_sizes) / len(batch_sizes) if batch_sizes else 0
+
+ _log_batch_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ message=f"📦 Created {len(batches)} batches for {total_files_in_batches} files (avg: {avg_batch_size:.1f} files/batch)",
+ )
+
+ if len(batches) > 1:
+ _log_batch_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ message=f"📊 Batch sizes: {', '.join(map(str, batch_sizes))}",
+ )
+
+
+ bind=True,
+ name=TaskName.ASYNC_EXECUTE_BIN_GENERAL,
+ autoretry_for=(Exception,),
+ max_retries=3,
+ retry_backoff=True,
+ retry_backoff_max=500,
+ retry_jitter=True,
+)
+@monitor_performance
+@circuit_breaker(failure_threshold=5, recovery_timeout=60.0)
+def async_execute_bin_general(
+ self,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[str, FileHashData],
+ scheduled: bool = False,
+ execution_mode: tuple | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ use_file_history: bool = False,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """Lightweight general workflow execution task.
+
+ This handles general (non-API deployment) workflow executions,
+ using internal APIs instead of direct Django ORM access.
+
+ Args:
+ schema_name: Organization schema name
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ hash_values_of_files: File hash data
+ scheduled: Whether execution is scheduled
+ execution_mode: Execution mode tuple
+ pipeline_id: Pipeline ID (None for general workflows)
+ log_events_id: Log events ID
+ use_file_history: Whether to use file history
+
+ Returns:
+ Execution result dictionary
+ """
+ task_id = self.request.id
+
+ with log_context(
+ task_id=task_id,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ ):
+ logger.info(
+ f"Starting general workflow execution for workflow {workflow_id}, execution {execution_id}"
+ )
+
+ try:
+ # Initialize execution context with shared utility
+ config, api_client = WorkerExecutionContext.setup_execution_context(
+ schema_name, execution_id, workflow_id
+ )
+
+ # Get workflow execution context
+ execution_response = api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(
+ f"Failed to get execution context: {execution_response.error}"
+ )
+ execution_context = execution_response.data
+ logger.info(f"Retrieved execution context for {execution_id}")
+
+ # Set LOG_EVENTS_ID in StateStore for WebSocket messaging (critical for UI logs)
+ # This enables the WorkerWorkflowLogger to send logs to the UI via WebSocket
+ execution_data = execution_context.get("execution", {})
+ execution_log_id = execution_data.get("execution_log_id")
+ if execution_log_id:
+ # Import and set LOG_EVENTS_ID like backend Celery workers do
+ from shared.infrastructure.context import StateStore
+
+ StateStore.set("LOG_EVENTS_ID", execution_log_id)
+ logger.info(
+ f"Set LOG_EVENTS_ID for WebSocket messaging: {execution_log_id}"
+ )
+ else:
+ logger.warning(
+ f"No execution_log_id found for execution {execution_id}, WebSocket logs may not be delivered"
+ )
+
+ # Get execution and workflow information
+ current_status = execution_data.get("status")
+ workflow_id = execution_data.get("workflow_id")
+
+ logger.info(f"Execution {execution_id} status: {current_status}")
+ # Note: We allow PENDING executions to continue - they should process available files
+
+ # NOTE: Concurrent executions are allowed - individual active files are filtered out
+ # during source file discovery using cache + database checks
+
+ # TOOL VALIDATION: Validate tool instances before file processing
+ # This prevents resource waste on invalid tool configurations
+ validate_workflow_tool_instances(
+ api_client=api_client,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ workflow_type="general",
+ )
+
+ # Update execution status to in progress
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.EXECUTING.value,
+ attempts=self.request.retries + 1,
+ )
+
+ # Process file batches if files provided
+ file_batch_results = []
+ if hash_values_of_files:
+ file_batch_results = _process_file_batches_general(
+ api_client, execution_id, hash_values_of_files, pipeline_id
+ )
+
+ # Execute workflow-specific logic for general workflows
+ execution_result = _execute_general_workflow(
+ api_client,
+ execution_context,
+ file_batch_results,
+ pipeline_id,
+ execution_mode,
+ use_file_history,
+ scheduled,
+ schema_name,
+ **kwargs,
+ )
+
+ # Calculate execution time
+ execution_time = execution_result.get("execution_time", 0)
+
+ # Update execution status to completed
+ # Only include total_files if we have files to avoid overwriting with 0
+ update_request = WorkflowExecutionStatusUpdate(
+ execution_id=execution_id,
+ status=ExecutionStatus.COMPLETED.value,
+ execution_time=execution_time,
+ total_files=len(hash_values_of_files) if hash_values_of_files else None,
+ )
+
+ api_client.update_workflow_execution_status(**update_request.to_dict())
+
+ # Cache cleanup handled by callback worker
+
+ logger.info(
+ f"Successfully completed general workflow execution {execution_id}"
+ )
+
+ response = WorkerTaskResponse.success_response(
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ task_id=task_id,
+ execution_time=execution_time,
+ )
+ response.is_general_workflow = True
+
+ # Convert to dict and add additional fields for backward compatibility
+ response_dict = response.to_dict()
+ response_dict.update(
+ {
+ "files_processed": len(hash_values_of_files)
+ if hash_values_of_files
+ else 0,
+ "file_batch_results": file_batch_results,
+ "execution_result": execution_result,
+ }
+ )
+
+ # CRITICAL: Clean up StateStore to prevent data leaks between tasks
+ try:
+ from shared.infrastructure.context import StateStore
+
+ StateStore.clear_all()
+ logger.debug("🧹 Cleaned up StateStore context to prevent data leaks")
+ except Exception as cleanup_error:
+ logger.warning(f"Failed to cleanup StateStore context: {cleanup_error}")
+
+ return response_dict
+
+ except Exception as e:
+ logger.error(f"General workflow execution failed for {execution_id}: {e}")
+
+ # Try to update execution status to failed
+ try:
+ with InternalAPIClient(config) as api_client:
+ api_client.set_organization_context(schema_name)
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=str(e),
+ )
+
+ # CRITICAL FIX: Also update pipeline status to FAILED for consistency
+ if pipeline_id:
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.FAILURE.value,
+ )
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Pipeline status updated to FAILED after general workflow error"
+ )
+ except Exception as pipeline_error:
+ logger.error(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Failed to update pipeline status to FAILED: {pipeline_error}"
+ )
+
+ except Exception as update_error:
+ logger.error(f"Failed to update execution status: {update_error}")
+
+ # Cache cleanup not needed - no entries created
+
+ # CRITICAL: Clean up StateStore to prevent data leaks between tasks (error path)
+ try:
+ from shared.infrastructure.context import StateStore
+
+ StateStore.clear_all()
+ logger.debug(
+ "🧹 Cleaned up StateStore context to prevent data leaks (error path)"
+ )
+ except Exception as cleanup_error:
+ logger.warning(
+ f"Failed to cleanup StateStore context on error: {cleanup_error}"
+ )
+
+ # Re-raise for Celery retry mechanism
+ raise
+
+
+def _process_file_batches_general(
+ api_client: InternalAPIClient,
+ execution_id: str,
+ hash_values_of_files: dict[str, FileHashData],
+ pipeline_id: str | None = None,
+) -> list:
+ """Process file batches for general workflow execution.
+
+ Args:
+ api_client: Internal API client
+ execution_id: Execution ID
+ hash_values_of_files: File hash data
+ pipeline_id: Pipeline ID (may be None for general workflows)
+
+ Returns:
+ List of file batch results
+ """
+ logger.info(
+ f"Processing {len(hash_values_of_files)} files for general execution {execution_id}"
+ )
+
+ try:
+ # Convert FileHashData objects to file data format expected by API
+ files_data = []
+ skipped_files_count = 0
+ for file_key, file_hash_data in hash_values_of_files.items():
+ # TRACE: Log incoming file data
+ logger.info(f"Processing FileHashData for file '{file_key}'")
+ logger.info(f" FileHashData: {file_hash_data}")
+
+ # Validate that we have a FileHashData object
+ if not isinstance(file_hash_data, FileHashData):
+ logger.error(
+ f"Expected FileHashData object for '{file_key}', got {type(file_hash_data)}"
+ )
+ # Try to convert from dict if possible
+ if isinstance(file_hash_data, dict):
+ try:
+ file_hash_data = FileHashData.from_dict(file_hash_data)
+ logger.info(
+ f"Successfully converted dict to FileHashData for '{file_key}'"
+ )
+ except Exception as e:
+ logger.error(
+ f"Failed to convert dict to FileHashData for '{file_key}': {e}"
+ )
+ skipped_files_count += 1
+ continue
+ else:
+ logger.error(f"Cannot process file '{file_key}' - invalid data type")
+ skipped_files_count += 1
+ continue
+
+ # Use FileHashData to_dict method for consistent data structure
+ file_data = file_hash_data.to_dict()
+
+ # TRACE: Log final file data
+ logger.info(
+ f" Final file_data for '{file_key}': provider_file_uuid='{file_data.get('provider_file_uuid')}'"
+ )
+ files_data.append(file_data)
+
+ # VALIDATION: Check file data integrity before API call
+ _validate_provider_file_uuid_integrity(files_data, "process_file_batches_general")
+
+ # Log skipped files to UI if any
+ if skipped_files_count > 0:
+ _log_batch_statistics_to_ui(
+ execution_id=execution_id,
+ organization_id=api_client.organization_id,
+ pipeline_id=pipeline_id,
+ message=f"⚠️ Skipped {skipped_files_count} files due to data conversion errors",
+ )
+
+ # Create file batch via internal API
+ batch_response = api_client.create_file_batch(
+ workflow_execution_id=execution_id,
+ files=files_data,
+ is_api=False, # This is for general workflows, not API deployments
+ )
+
+ logger.info(
+ f"Created file batch {batch_response.get('batch_id')} with {batch_response.get('total_files')} files"
+ )
+
+ return [batch_response]
+
+ except Exception as e:
+ logger.error(f"Failed to process file batches: {e}")
+ raise
+
+
+def _execute_general_workflow(
+ api_client: InternalAPIClient,
+ execution_context: dict[str, Any],
+ file_batch_results: list,
+ pipeline_id: str | None,
+ execution_mode: tuple | None,
+ use_file_history: bool,
+ scheduled: bool,
+ schema_name: str,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """Execute general workflow specific logic for ETL/TASK workflows.
+
+ This implements real workflow execution using source/destination connectors
+ and file processing orchestration, similar to the API worker but for
+ FILESYSTEM-based workflows.
+
+ Args:
+ api_client: Internal API client
+ execution_context: Execution context from API
+ file_batch_results: File batch processing results (unused - we create our own)
+ pipeline_id: Pipeline ID (may be None)
+ execution_mode: Execution mode
+ use_file_history: Whether to use file history
+ scheduled: Whether execution is scheduled
+
+ Returns:
+ Execution result
+ """
+ start_time = time.time()
+
+ logger.info("Executing general workflow logic for ETL/TASK workflow")
+
+ try:
+ # Convert dictionary execution context to type-safe dataclass
+ execution_data = execution_context.get("execution", {})
+ workflow_definition = execution_context.get("workflow_definition", {})
+
+ execution_id = execution_data.get("id")
+ workflow_id = execution_data.get("workflow_id") or workflow_definition.get(
+ "workflow_id"
+ )
+ # Note: organization_id extracted but not used directly - schema_name is used instead
+
+ # Create organization context - use schema_name (org string) not numeric organization_id
+ org_context = create_organization_context(schema_name, api_client)
+
+ # Create type-safe workflow context
+ workflow_context = WorkflowContextData(
+ workflow_id=workflow_id,
+ workflow_name=workflow_definition.get(
+ "workflow_name", f"workflow-{workflow_id}"
+ ),
+ workflow_type=workflow_definition.get("workflow_type", "TASK"),
+ execution_id=execution_id,
+ organization_context=org_context,
+ files={}, # Will be populated from source connector
+ settings={
+ "use_file_history": use_file_history,
+ "pipeline_id": pipeline_id,
+ },
+ metadata={
+ "execution_data": execution_data,
+ "workflow_definition": workflow_definition,
+ "execution_context": execution_context,
+ "file_batch_results": file_batch_results,
+ "execution_mode": execution_mode,
+ },
+ is_scheduled=scheduled,
+ )
+
+ logger.info(
+ f"Starting real workflow execution for pipeline {pipeline_id}, workflow {workflow_id}, execution {execution_id}, organization_id={org_context.organization_id}"
+ )
+
+ # For ETL/TASK workflows, we need to:
+ # 1. Get source files from the source connector
+ # 2. Create file batches for processing
+ # 3. Orchestrate file processing through file_processing workers
+ # 4. Aggregate results through callback workers
+
+ # For ETL/TASK workflows, we use file processing orchestration
+ # The workflow execution already exists and is managed by the backend
+ if not execution_id:
+ raise ValueError("Execution ID required for general workflow execution")
+
+ logger.info(f"Processing general workflow execution: {execution_id}")
+
+ # Update status to EXECUTING
+ try:
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.EXECUTING.value,
+ )
+ except Exception as status_error:
+ logger.warning(f"Failed to update execution status: {status_error}")
+
+ # Create source connector instance
+ source_connector = WorkerSourceConnector(
+ api_client=api_client,
+ workflow_id=workflow_context.workflow_id,
+ execution_id=workflow_context.execution_id,
+ organization_id=workflow_context.organization_context.organization_id,
+ use_file_history=workflow_context.get_setting("use_file_history", True),
+ )
+
+ workflow_logger = WorkerWorkflowLogger.create_for_general_workflow(
+ execution_id=execution_id,
+ organization_id=api_client.organization_id,
+ pipeline_id=pipeline_id,
+ )
+
+ # Retrieve source files from the configured source
+ try:
+ source_files, total_files = source_connector.list_files_from_source()
+ logger.info(f"Retrieved {total_files} source files from configured source")
+
+ # Log source discovery to UI
+ if workflow_logger:
+ if total_files > 0:
+ workflow_logger.log_info(
+ logger, f"🔍 Found {total_files} new files to process from source"
+ )
+ else:
+ workflow_logger.log_info(
+ logger,
+ "🔍 No new files to process (files may have been found but filtered out during file history check)",
+ )
+
+ # Get connection type from endpoint config
+ connection_type = source_connector.endpoint_config.connection_type
+ except Exception as source_error:
+ logger.error(f"Failed to retrieve source files: {source_error}")
+
+ # CRITICAL FIX: Log source connector errors to UI
+ workflow_logger.log_error(
+ logger, f"❌ Failed to retrieve files from source: {source_error}"
+ )
+
+ # Continue with empty source files but log the error
+ source_files = {}
+ total_files = 0
+ connection_type = "unknown"
+
+ logger.info(
+ f"Processing {total_files} source files from {connection_type} source"
+ )
+
+ # FILE PROCESSING: Source connector now handles ALL filtering during discovery
+ # No duplicate filtering needed - files are already filtered with:
+ # 1. Pattern matching
+ # 2. File history check
+ # 3. Active file check (cache + database)
+ # 4. Hard limit enforcement
+
+ max_files_limit = source_connector.get_max_files_limit()
+
+ # Source files are now ALREADY filtered and limited
+ # The streaming discovery has already applied all filters
+ final_file_count = len(source_files) if source_files else 0
+
+ logger.info(
+ f"Source connector returned {final_file_count} files (already filtered, limit was {max_files_limit})"
+ )
+
+ # Log statistics to UI (source connector already logged detailed filtering info)
+ if total_files > 0:
+ workflow_logger.log_info(
+ logger,
+ f"✅ Ready to process {total_files} files (all filtering complete)",
+ )
+
+ # Send source logs to UI
+ workflow_logger.publish_source_logs(total_files)
+
+ # Update total_files at workflow start
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.EXECUTING.value,
+ total_files=total_files,
+ )
+
+ logger.info(f"Retrieved {total_files} source files for processing")
+
+ if not source_files:
+ logger.info(f"Execution {execution_id} no files to process")
+
+ # Log detailed explanation to UI
+ # The source connector has already applied all filters and logged details
+ workflow_logger.log_info(
+ logger,
+ "💤 No files to process - all files have been filtered out (already processed, active, or no matches)",
+ )
+
+ # Send completion log to UI
+ workflow_logger.publish_execution_complete(
+ successful_files=0, failed_files=0, total_time=0.0
+ )
+
+ # Complete immediately with no files
+ try:
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.COMPLETED.value,
+ total_files=0,
+ )
+ except Exception as status_error:
+ logger.warning(f"Failed to update execution status: {status_error}")
+
+ # Update pipeline status if needed
+ if pipeline_id:
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.SUCCESS.value,
+ )
+ except Exception as pipeline_error:
+ logger.warning(f"Failed to update pipeline status: {pipeline_error}")
+
+ execution_time = time.time() - start_time
+ response = WorkerTaskResponse.success_response(
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ execution_time=execution_time,
+ )
+ response.is_general_workflow = True
+
+ # Convert to dict and add additional fields for backward compatibility
+ response_dict = response.to_dict()
+ response_dict.update(
+ {
+ "files_processed": 0,
+ "message": "No files to process",
+ "processed_source_files": {},
+ "processed_files_count": 0,
+ }
+ )
+ return response_dict
+
+ # Orchestrate file processing using chord pattern
+ try:
+ # Use orchestration method that creates chord and returns immediately
+ orchestration_result = _orchestrate_file_processing_general(
+ api_client=api_client,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ source_files=source_files,
+ pipeline_id=pipeline_id,
+ scheduled=scheduled,
+ execution_mode=execution_mode,
+ use_file_history=use_file_history,
+ organization_id=api_client.organization_id,
+ **kwargs,
+ )
+
+ # The orchestration result contains the chord_id and batch information
+ # Pipeline status will be updated by the callback worker
+ logger.info(
+ f"General workflow orchestration completed in {time.time() - start_time:.2f}s"
+ )
+
+ except Exception as e:
+ logger.error(f"Workflow execution failed: {e}")
+ try:
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=str(e),
+ )
+ except Exception as status_error:
+ logger.warning(f"Failed to update error status: {status_error}")
+
+ orchestration_result = WorkerTaskResponse.error_response(
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ error=str(e),
+ ).to_dict()
+
+ # Include empty processed files info even on error
+ orchestration_result["processed_source_files"] = {}
+ orchestration_result["processed_files_count"] = 0
+
+ execution_time = time.time() - start_time
+ orchestration_result["execution_time"] = execution_time
+ orchestration_result["is_general_workflow"] = True
+
+ logger.info(f"General workflow orchestration completed in {execution_time:.2f}s")
+
+ return orchestration_result
+
+ except Exception as e:
+ execution_time = time.time() - start_time
+ logger.error(f"General workflow failed after {execution_time:.2f}s: {e}")
+ raise
+
+
+def _orchestrate_file_processing_general(
+ api_client: InternalAPIClient,
+ workflow_id: str,
+ execution_id: str,
+ source_files: dict[str, FileHashData],
+ pipeline_id: str | None,
+ scheduled: bool,
+ execution_mode: tuple | None,
+ use_file_history: bool,
+ organization_id: str,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """Orchestrate file processing for general workflows using the same pattern as API worker.
+
+ This creates file batches and sends them to file_processing workers using chord/callback.
+
+ Args:
+ api_client: Internal API client
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ source_files: Dictionary of source files to process
+ pipeline_id: Pipeline ID
+ scheduled: Whether execution is scheduled
+ execution_mode: Execution mode tuple
+ use_file_history: Whether to use file history
+ organization_id: Organization ID for callback context
+
+ Returns:
+ Orchestration result
+ """
+ logger.info(
+ f"Orchestrating file processing for {len(source_files)} files with organization_id={organization_id}"
+ )
+
+ try:
+ # Get file batches using the same logic as Django backend with organization-specific config
+ batches = _get_file_batches_general(
+ input_files=source_files,
+ organization_id=organization_id,
+ api_client=api_client,
+ )
+ logger.info(f"Created {len(batches)} file batches for processing")
+
+ # Log batch statistics to UI
+ _log_batch_creation_statistics(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ batches=batches,
+ )
+
+ # Create batch tasks following the exact Django pattern
+ batch_tasks = []
+ execution_mode_str = (
+ (
+ execution_mode[1]
+ if isinstance(execution_mode, tuple)
+ else str(execution_mode)
+ )
+ if execution_mode
+ else None
+ )
+
+ logger.debug(
+ f"Execution parameters: mode={execution_mode_str}, pipeline={pipeline_id}, scheduled={scheduled}, file_history={use_file_history}"
+ )
+
+ hitl_queue_name = kwargs.get("hitl_queue_name")
+ llm_profile_id = kwargs.get("llm_profile_id")
+ custom_data = kwargs.get("custom_data")
+
+ worker_file_data = WorkerFileData(
+ workflow_id=str(workflow_id),
+ execution_id=str(execution_id),
+ organization_id=str(organization_id),
+ pipeline_id=str(pipeline_id) if pipeline_id else "",
+ scheduled=scheduled,
+ execution_mode=execution_mode or "SYNC",
+ use_file_history=use_file_history,
+ single_step=False,
+ q_file_no_list=[],
+ manual_review_config={},
+ hitl_queue_name=hitl_queue_name,
+ llm_profile_id=llm_profile_id,
+ custom_data=custom_data,
+ )
+
+ # Calculate manual review configuration ONCE for all files before batching
+ manual_review_service = get_manual_review_service(
+ api_client=api_client, organization_id=api_client.organization_id
+ )
+ # Use consistent WorkflowUtil pattern like other workers
+ workflow_util = manual_review_service.get_workflow_util()
+ global_file_data = workflow_util.create_workflow_file_data_with_manual_review(
+ worker_file_data=worker_file_data,
+ use_file_history=use_file_history,
+ total_files=len(source_files),
+ )
+ logger.debug("Global file data configured for manual review")
+ # Pre-calculate file decisions for ALL files based on total count - not per batch!
+ q_file_no_list = global_file_data.manual_review_config.get("q_file_no_list", [])
+ logger.info(
+ f"Pre-calculated manual review selection: {len(q_file_no_list)} files selected from {len(source_files)} total files for manual review"
+ )
+
+ for batch_idx, batch in enumerate(batches):
+ # CRITICAL FIX: Use the pre-calculated global file data instead of recalculating
+ # This prevents random reselection of different files for each batch
+ file_data = global_file_data
+
+ # Calculate batch-specific decisions based on the global q_file_no_list
+ file_decisions = []
+ for file_name, file_hash in batch:
+ file_number = file_hash.get("file_number", 0)
+ is_selected = file_number in q_file_no_list
+ file_decisions.append(is_selected)
+
+ # Update the file_data with batch-specific decisions
+ file_data.manual_review_config["file_decisions"] = file_decisions
+ logger.info(
+ f"Calculated manual review decisions for batch {batch_idx + 1}: {sum(file_decisions)}/{len(file_decisions)} files selected"
+ )
+
+ # Create batch data exactly matching Django FileBatchData structure
+ batch_data = _create_batch_data_general(
+ files=batch, file_data=file_data, source_files=source_files
+ )
+
+ logger.debug(f"Processing batch {batch_idx + 1} with {len(batch)} files")
+
+ # Debug: Log the files in this batch BEFORE enhancement
+ logger.info(
+ f"Batch {batch_idx + 1} contains {len(batch)} files (BEFORE enhancement):"
+ )
+ for file_name, file_hash in batch:
+ provider_uuid = (
+ file_hash.get("provider_file_uuid")
+ if isinstance(file_hash, dict)
+ else "N/A"
+ )
+ logger.info(f" 📄 {file_name}: provider_file_uuid='{provider_uuid}'")
+
+ # Debug: Log the files in this batch AFTER enhancement
+ logger.info(f"Batch {batch_idx + 1} files AFTER enhancement:")
+ for file_name, file_hash in batch_data.files:
+ provider_uuid = (
+ file_hash.get("provider_file_uuid")
+ if isinstance(file_hash, dict)
+ else "N/A"
+ )
+ logger.info(f" 📄 {file_name}: provider_file_uuid='{provider_uuid}'")
+
+ # VALIDATION: Check batch data integrity using dataclass
+ _validate_batch_data_integrity_dataclass(batch_data, batch_idx + 1)
+
+ # Determine queue using FILESYSTEM logic (not API)
+ file_processing_queue = _get_queue_name_general()
+
+ # Create task signature matching Django backend pattern
+ batch_tasks.append(
+ app.signature(
+ TaskName.PROCESS_FILE_BATCH.value, # Use enum string value for Celery
+ args=[
+ batch_data.to_dict()
+ ], # Convert FileBatchData to dict for Celery serialization
+ queue=file_processing_queue,
+ )
+ )
+
+ # Create callback queue using FILESYSTEM logic
+ file_processing_callback_queue = _get_callback_queue_name_general()
+ callback_data = CallbackTaskData(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+ callback_kwargs = callback_data.to_dict()
+
+ # CRITICAL FIX: Pass pipeline_id directly to callback to ensure pipeline status updates
+ if pipeline_id:
+ logger.info(
+ f"Passing pipeline_id {pipeline_id} to callback for proper status updates"
+ )
+
+ # Import to ensure we have the right app context
+ from worker import app as celery_app
+
+ # Use shared orchestration utility for chord execution
+ result = WorkflowOrchestrationUtils.create_chord_execution(
+ batch_tasks=batch_tasks,
+ callback_task_name=TaskName.PROCESS_BATCH_CALLBACK.value,
+ callback_kwargs=callback_kwargs,
+ callback_queue=file_processing_callback_queue,
+ app_instance=celery_app,
+ )
+
+ if not result:
+ # Check if this is zero files case (no error, just no chord needed)
+ if not batch_tasks:
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] No chord created for zero files - updating pipeline status directly"
+ )
+
+ # Update pipeline status directly (same as manual execution path)
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.SUCCESS.value,
+ )
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Pipeline status updated to COMPLETED for zero-files execution"
+ )
+ except Exception as pipeline_error:
+ logger.error(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Failed to update pipeline status directly: {pipeline_error}"
+ )
+
+ # Try to update pipeline to FAILED status
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.FAILURE.value,
+ )
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Pipeline status updated to FAILED after error"
+ )
+ except Exception as failed_update_error:
+ logger.error(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Failed to update pipeline to FAILED status: {failed_update_error}"
+ )
+
+ # Re-raise to ensure proper error handling
+ raise pipeline_error
+
+ # Return success response only if pipeline status was updated successfully
+ response = WorkerTaskResponse.success_response(
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ task_id=None, # No chord task for zero files
+ )
+ response.status = "completed_zero_files"
+
+ # Convert to dict and add additional fields for backward compatibility
+ response_dict = response.to_dict()
+ response_dict.update(
+ {
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "files_processed": 0,
+ "message": "No files to process - pipeline status updated directly",
+ }
+ )
+ return response_dict
+ else:
+ # This is a real error - chord creation failed with non-empty batch_tasks
+ exception = f"Failed to queue execution task {execution_id}"
+ logger.error(exception)
+ raise Exception(exception)
+
+ logger.info(f"Execution {execution_id} file processing orchestrated successfully")
+
+ response = WorkerTaskResponse.success_response(
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ task_id=result.id,
+ )
+ response.status = "orchestrated"
+
+ # Convert to dict and add additional fields for backward compatibility
+ response_dict = response.to_dict()
+ response_dict.update(
+ {
+ "files_processed": len(source_files),
+ "batches_created": len(batches),
+ "chord_id": result.id,
+ "message": "File processing orchestrated, waiting for completion",
+ }
+ )
+ return response_dict
+
+ except Exception as e:
+ # Update execution to ERROR status matching Django pattern
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=f"Error while processing files: {str(e)}",
+ )
+ logger.error(
+ f"File processing orchestration failed for {execution_id}: {str(e)}",
+ exc_info=True,
+ )
+ raise
+
+
+def _get_file_batches_general(
+ input_files: dict[str, FileHashData],
+ organization_id: str | None = None,
+ api_client=None,
+) -> list:
+ """Get file batches using the exact same logic as Django backend with organization-specific config.
+
+ This matches WorkflowHelper.get_file_batches() exactly, but now supports organization-specific
+ MAX_PARALLEL_FILE_BATCHES configuration.
+
+ Args:
+ input_files: Dictionary of FileHashData objects
+
+ Returns:
+ List of file batches
+ """
+ # Convert FileHashData objects to dict format for serialization
+ try:
+ standardized_files = TypeConverter.ensure_file_dict_format(input_files)
+ logger.info(
+ f"Successfully standardized {len(standardized_files)} files to dict format"
+ )
+ except Exception as e:
+ logger.error(f"Failed to standardize input files: {e}")
+ raise TypeError(f"Could not convert input files to standard format: {e}")
+
+ # Validate file batch format
+ is_valid, errors = FileDataValidator.validate_file_batch_data(standardized_files)
+ if not is_valid:
+ logger.error(f"File batch validation failed: {errors}")
+ # Continue processing but log warnings
+ for error in errors:
+ logger.warning(f"Validation error: {error}")
+
+ # Convert FileHashData objects to serializable format for batching
+ json_serializable_files = {}
+ for file_name, file_hash_data in standardized_files.items():
+ try:
+ json_serializable_files[file_name] = file_hash_data.to_dict()
+ except Exception as e:
+ logger.error(f"Failed to serialize file '{file_name}': {e}")
+ continue
+
+ # Use shared file processing utility for batching with organization-specific config
+ return FileProcessingUtils.create_file_batches(
+ files=json_serializable_files,
+ organization_id=organization_id,
+ api_client=api_client,
+ batch_size_env_var="MAX_PARALLEL_FILE_BATCHES",
+ # default_batch_size not needed - will use environment default matching Django
+ )
+
+
+# Manual review logic has been moved to shared plugins for reusability
+
+
+def _create_batch_data_general(
+ files: list, file_data: WorkerFileData, source_files: dict[str, FileHashData] = None
+) -> FileBatchData:
+ """Create batch data matching Django FileBatchData structure exactly.
+
+ Args:
+ files: List of (file_name, file_hash) tuples
+ file_data: File data dictionary
+ source_files: Source files data containing connector metadata
+
+ Returns:
+ Batch data dictionary matching Django FileBatchData
+ """
+ # Create enhanced files list with proper metadata handling
+ enhanced_files = []
+
+ # Extract manual review decisions from file_data
+ manual_review_decisions = file_data.manual_review_config.get("file_decisions", [])
+ logger.info(
+ f"BATCH_DATA: Applying manual review decisions: {manual_review_decisions}"
+ )
+
+ if source_files:
+ for file_index, (file_name, file_hash) in enumerate(files):
+ # DEBUG: Log file metadata mapping to detect collisions
+ logger.info(f"BATCH_DATA: Processing file '{file_name}' in batch creation")
+ logger.info(
+ f" Original file_hash keys: {list(file_hash.keys()) if isinstance(file_hash, dict) else 'not a dict'}"
+ )
+ if isinstance(file_hash, dict):
+ logger.info(
+ f" Original provider_file_uuid: '{file_hash.get('provider_file_uuid')}' (type: {type(file_hash.get('provider_file_uuid'))})"
+ )
+ logger.info(f" Original file_path: '{file_hash.get('file_path')}'")
+
+ # Get source file data to extract connector metadata
+ source_file_data = source_files.get(file_name)
+
+ # DEBUG: Log source file data lookup
+ if source_file_data:
+ if isinstance(source_file_data, FileHashData):
+ logger.info(
+ f" Found FileHashData for '{file_name}': provider_file_uuid='{source_file_data.provider_file_uuid}'"
+ )
+ source_dict = source_file_data.to_dict()
+ elif isinstance(source_file_data, dict):
+ logger.info(
+ f" Found dict source file data for '{file_name}': {list(source_file_data.keys())}"
+ )
+ source_dict = source_file_data
+ else:
+ logger.warning(
+ f" Unexpected source file data type for '{file_name}': {type(source_file_data)}"
+ )
+ source_dict = {}
+ else:
+ logger.warning(
+ f" No source file data found for '{file_name}' in source_files with keys: {list(source_files.keys())}"
+ )
+ source_dict = {}
+
+ # CRITICAL FIX: Create deep copy and update with correct source file metadata
+ import copy
+
+ enhanced_file_hash = (
+ copy.deepcopy(file_hash) if isinstance(file_hash, dict) else {}
+ )
+
+ # TRACE: Before updating from source_files
+ logger.info(
+ f" Enhanced file_hash BEFORE update: provider_file_uuid='{enhanced_file_hash.get('provider_file_uuid')}'"
+ )
+
+ # Update core metadata from source_files to ensure each file gets correct data
+ if source_dict and isinstance(enhanced_file_hash, dict):
+ # CRITICAL: Handle provider_file_uuid correctly - prefer source_files but don't overwrite with None
+ original_uuid = enhanced_file_hash.get("provider_file_uuid")
+ source_uuid = source_dict.get("provider_file_uuid")
+
+ if source_uuid is not None:
+ # Source has a provider_file_uuid, use it
+ enhanced_file_hash["provider_file_uuid"] = source_uuid
+ logger.info(
+ f" Updated provider_file_uuid: '{original_uuid}' -> '{source_uuid}' (from source_files)"
+ )
+ elif original_uuid is not None:
+ # Keep original provider_file_uuid if source doesn't have one
+ logger.info(
+ f" Keeping original provider_file_uuid: '{original_uuid}' (source_files has None)"
+ )
+ else:
+ # Neither source nor original has provider_file_uuid
+ logger.warning(
+ f" No provider_file_uuid in source_files or original file_hash for '{file_name}'"
+ )
+
+ # Update file_path (always update if available)
+ if "file_path" in source_dict:
+ enhanced_file_hash["file_path"] = source_dict["file_path"]
+ logger.info(f" Updated file_path: '{source_dict['file_path']}'")
+
+ # Update additional metadata if available (but don't overwrite with None/empty)
+ for field in ["file_size", "mime_type", "file_hash", "fs_metadata"]:
+ if field in source_dict and source_dict[field] is not None:
+ # Only update if source has a non-None value
+ enhanced_file_hash[field] = source_dict[field]
+ logger.info(f" Updated {field}: '{source_dict[field]}'")
+
+ # Add connector metadata if available
+ connector_metadata = source_dict.get("connector_metadata")
+ connector_id = source_dict.get("connector_id")
+ if connector_metadata and connector_id:
+ enhanced_file_hash["connector_metadata"] = connector_metadata
+ enhanced_file_hash["connector_id"] = connector_id
+ logger.info(" Added connector_metadata and connector_id")
+ else:
+ logger.warning(
+ f" No source file data or enhanced_file_hash is not dict for '{file_name}'"
+ )
+
+ # CRITICAL FIX: Apply manual review decision to this file using GLOBAL file number
+ # Use the original file_number from the file hash, not the batch-local file_index
+ original_file_number = enhanced_file_hash.get(
+ "file_number", file_index + 1
+ ) # fallback to batch index + 1
+ global_q_file_no_list = file_data.manual_review_config.get(
+ "q_file_no_list", []
+ )
+
+ is_manual_review_required = original_file_number in global_q_file_no_list
+
+ # Set manual review fields in file hash
+ enhanced_file_hash["is_manualreview_required"] = is_manual_review_required
+ logger.info(
+ f" MANUAL REVIEW: File #{original_file_number} '{file_name}' (batch_index={file_index}) -> is_manualreview_required={is_manual_review_required}, global_q_file_no_list={global_q_file_no_list}"
+ )
+
+ if enhanced_file_hash.get("connector_id"):
+ logger.info(
+ f" connector_id: '{enhanced_file_hash.get('connector_id')}'"
+ )
+
+ enhanced_files.append((file_name, enhanced_file_hash))
+ else:
+ # No source files, use original files but still apply manual review decisions
+ for file_index, (file_name, file_hash) in enumerate(files):
+ # Ensure file_hash is a dictionary we can modify
+ if isinstance(file_hash, dict):
+ enhanced_file_hash = file_hash.copy()
+ else:
+ enhanced_file_hash = {}
+
+ # CRITICAL FIX: Apply manual review decision to this file using GLOBAL file number
+ # Use the original file_number from the file hash, not the batch-local file_index
+ original_file_number = enhanced_file_hash.get(
+ "file_number", file_index + 1
+ ) # fallback to batch index + 1
+ global_q_file_no_list = file_data.manual_review_config.get(
+ "q_file_no_list", []
+ )
+
+ is_manual_review_required = original_file_number in global_q_file_no_list
+
+ # Set manual review fields in file hash
+ enhanced_file_hash["is_manualreview_required"] = is_manual_review_required
+ logger.info(
+ f" MANUAL REVIEW (no source): File #{original_file_number} '{file_name}' (batch_index={file_index}) -> is_manualreview_required={is_manual_review_required}, global_q_file_no_list={global_q_file_no_list}"
+ )
+
+ enhanced_files.append((file_name, enhanced_file_hash))
+
+ # Create FileBatchData object
+ return FileBatchData(files=enhanced_files, file_data=file_data)
+
+
+def _get_queue_name_general() -> str:
+ """Get the appropriate file processing queue for general (FILESYSTEM) workflows.
+
+ For general workflows, we use the standard file_processing queue, not the API one.
+
+ Returns:
+ Queue name for file processing
+ """
+ # Use common utility for consistent queue naming
+ file_queue, _ = WorkflowTypeDetector.get_queue_names(is_api_workflow=False)
+ return file_queue
+
+
+def _get_callback_queue_name_general() -> str:
+ """Get the appropriate callback queue for general (FILESYSTEM) workflows.
+
+ For general workflows, we use the standard callback queue, not the API one.
+
+ Returns:
+ Queue name for callback processing
+ """
+ # Use common utility for consistent queue naming
+ _, callback_queue = WorkflowTypeDetector.get_queue_names(is_api_workflow=False)
+ return callback_queue
+
+
+def _validate_provider_file_uuid_integrity(files_data: list, operation_name: str) -> None:
+ """Validate that provider_file_uuid values are preserved and not corrupted.
+
+ Args:
+ files_data: List of file data dictionaries
+ operation_name: Name of the operation for logging
+ """
+ missing_uuid_count = 0
+ empty_uuid_count = 0
+ valid_uuid_count = 0
+
+ for file_data in files_data:
+ file_name = file_data.get("file_name", "unknown")
+ provider_uuid = file_data.get("provider_file_uuid")
+
+ if provider_uuid is None:
+ missing_uuid_count += 1
+ logger.warning(
+ f"VALIDATION [{operation_name}]: File '{file_name}' has missing provider_file_uuid"
+ )
+ elif isinstance(provider_uuid, str) and not provider_uuid.strip():
+ empty_uuid_count += 1
+ logger.warning(
+ f"VALIDATION [{operation_name}]: File '{file_name}' has empty provider_file_uuid"
+ )
+ else:
+ valid_uuid_count += 1
+ logger.debug(
+ f"VALIDATION [{operation_name}]: File '{file_name}' has valid provider_file_uuid: '{provider_uuid}'"
+ )
+
+ total_files = len(files_data)
+ logger.info(
+ f"VALIDATION [{operation_name}]: {valid_uuid_count}/{total_files} files have valid provider_file_uuid"
+ )
+
+ if missing_uuid_count > 0 or empty_uuid_count > 0:
+ logger.warning(
+ f"VALIDATION [{operation_name}]: {missing_uuid_count} missing, {empty_uuid_count} empty provider_file_uuid values"
+ )
+
+
+def _validate_batch_data_integrity(batch_data: dict[str, Any], batch_idx: int) -> None:
+ """Validate that batch data has proper provider_file_uuid values.
+
+ Args:
+ batch_data: Batch data dictionary
+ batch_idx: Batch index for logging
+ """
+ files = batch_data.get("files", [])
+
+ if not files:
+ logger.warning(f"VALIDATION [Batch {batch_idx}]: No files in batch data")
+ return
+
+ missing_uuid_count = 0
+ valid_uuid_count = 0
+
+ for file_name, file_hash in files:
+ provider_uuid = (
+ file_hash.get("provider_file_uuid") if isinstance(file_hash, dict) else None
+ )
+
+ if provider_uuid is None or (
+ isinstance(provider_uuid, str) and not provider_uuid.strip()
+ ):
+ missing_uuid_count += 1
+ logger.warning(
+ f"VALIDATION [Batch {batch_idx}]: File '{file_name}' missing/empty provider_file_uuid"
+ )
+ else:
+ valid_uuid_count += 1
+
+ total_files = len(files)
+ logger.info(
+ f"VALIDATION [Batch {batch_idx}]: {valid_uuid_count}/{total_files} files have valid provider_file_uuid"
+ )
+
+ if missing_uuid_count > 0:
+ logger.error(
+ f"VALIDATION [Batch {batch_idx}]: {missing_uuid_count} files missing provider_file_uuid - this may cause FileHistory issues"
+ )
+
+
+def _validate_batch_data_integrity_dataclass(
+ batch_data: FileBatchData, batch_idx: int
+) -> None:
+ """Validate that FileBatchData has proper provider_file_uuid values.
+
+ Args:
+ batch_data: FileBatchData object
+ batch_idx: Batch index for logging
+ """
+ files = batch_data.files
+
+ if not files:
+ logger.warning(f"VALIDATION [Batch {batch_idx}]: No files in FileBatchData")
+ return
+
+ missing_uuid_count = 0
+ valid_uuid_count = 0
+
+ for file_name, file_hash in files:
+ provider_uuid = (
+ file_hash.get("provider_file_uuid") if isinstance(file_hash, dict) else None
+ )
+ # For API workflows, check if file has file_hash (cache_key) instead
+ has_cache_key = (
+ file_hash.get("file_hash") if isinstance(file_hash, dict) else None
+ )
+
+ if provider_uuid is None or (
+ isinstance(provider_uuid, str) and not provider_uuid.strip()
+ ):
+ # If no provider_uuid but has cache_key (API workflow), count as valid
+ if has_cache_key:
+ valid_uuid_count += 1
+ logger.debug(
+ f"VALIDATION [Batch {batch_idx}]: File '{file_name}' using cache_key instead of provider_file_uuid (API workflow)"
+ )
+ else:
+ missing_uuid_count += 1
+ logger.warning(
+ f"VALIDATION [Batch {batch_idx}]: File '{file_name}' missing/empty provider_file_uuid and cache_key"
+ )
+ else:
+ valid_uuid_count += 1
+
+ total_files = len(files)
+ logger.info(
+ f"VALIDATION [Batch {batch_idx}]: {valid_uuid_count}/{total_files} files have valid provider_file_uuid or cache_key"
+ )
+
+ if missing_uuid_count > 0:
+ logger.warning(
+ f"VALIDATION [Batch {batch_idx}]: {missing_uuid_count} files missing both provider_file_uuid and cache_key - this may cause FileHistory issues"
+ )
+
+
+ bind=True,
+ name="async_execute_bin",
+ autoretry_for=(Exception,),
+ max_retries=0,
+ retry_backoff=True,
+ retry_backoff_max=500,
+ retry_jitter=True,
+)
+@monitor_performance
+def async_execute_bin(
+ self,
+ schema_name: str,
+ workflow_id: str,
+ execution_id: str,
+ hash_values_of_files: dict[str, Any],
+ scheduled: bool = False,
+ execution_mode: tuple | None = None,
+ pipeline_id: str | None = None,
+ use_file_history: bool = True,
+ **kwargs: dict[str, Any],
+) -> dict[str, Any]:
+ """Router task that determines workflow type and executes appropriately.
+
+ This task is called by the Django backend and routes to the appropriate
+ execution handler based on workflow type detection.
+
+ Args:
+ schema_name: Organization schema name
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ hash_values_of_files: File hash data
+ scheduled: Whether execution is scheduled
+ execution_mode: Execution mode tuple
+ pipeline_id: Pipeline ID
+ use_file_history: Whether to use file history
+
+ Returns:
+ Execution result
+ """
+ task_id = self.request.id
+
+ with log_context(
+ task_id=task_id,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=schema_name,
+ pipeline_id=pipeline_id,
+ ):
+ logger.info(
+ f"Router task async_execute_bin received for organization {schema_name} and execution {execution_id}"
+ )
+
+ try:
+ with InternalAPIClient(config) as api_client:
+ api_client.set_organization_context(schema_name)
+
+ return async_execute_bin_general(
+ schema_name=schema_name,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ hash_values_of_files=hash_values_of_files,
+ scheduled=scheduled,
+ execution_mode=execution_mode,
+ pipeline_id=pipeline_id,
+ use_file_history=use_file_history,
+ **kwargs,
+ )
+
+ except Exception as e:
+ logger.error(f"Router task failed for execution {execution_id}: {e}")
+
+ # Try to update execution status to failed
+ try:
+ with InternalAPIClient(config) as api_client:
+ api_client.set_organization_context(schema_name)
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=str(e),
+ )
+ except Exception as update_error:
+ logger.error(f"Failed to update execution status: {update_error}")
+
+ raise
+
+
+# Note: Webhook and API deployment tasks are handled by specialized workers
+# to prevent routing conflicts and ensure proper separation of concerns
+
+
+# BACKWARD COMPATIBILITY: Register scheduler tasks for general worker
+# This allows general worker to handle scheduler tasks sent to celery queue
+logger.info("✅ Registered scheduler tasks in general worker for backward compatibility")
+
+
+@shared_task(name="scheduler.tasks.execute_pipeline_task", bind=True)
+def execute_pipeline_task(
+ self,
+ workflow_id: Any,
+ org_schema: Any,
+ execution_action: Any,
+ execution_id: Any,
+ pipepline_id: Any, # Note: keeping original typo for compatibility
+ with_logs: Any,
+ name: Any,
+) -> None:
+ """Execute pipeline task - maintains exact signature from backend scheduler.
+
+ This is the main entry point for scheduled pipeline executions, delegating
+ to the v2 implementation for actual processing.
+ """
+ return execute_pipeline_task_v2(
+ organization_id=org_schema,
+ pipeline_id=pipepline_id,
+ pipeline_name=name,
+ )
diff --git a/workers/general/worker.py b/workers/general/worker.py
new file mode 100644
index 000000000..1d9920c8d
--- /dev/null
+++ b/workers/general/worker.py
@@ -0,0 +1,70 @@
+"""General Worker
+
+Celery worker for general tasks including webhooks, background
+processing, and workflow orchestration.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker
+logger = WorkerLogger.setup(WorkerType.GENERAL)
+app, config = WorkerBuilder.build_celery_app(WorkerType.GENERAL)
+
+
+def check_general_worker_health():
+ """Custom health check for general worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="general_worker_health",
+ status=HealthStatus.HEALTHY,
+ message="General worker is healthy",
+ details={
+ "worker_type": "general",
+ "api_client": "healthy",
+ "queue": "celery",
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="general_worker_health",
+ status=HealthStatus.DEGRADED,
+ message="General worker partially functional",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="general_worker_health",
+ status=HealthStatus.DEGRADED,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.GENERAL, "general_worker_health", check_general_worker_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "general",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "general-worker",
+ }
diff --git a/workers/log_consumer/__init__.py b/workers/log_consumer/__init__.py
new file mode 100644
index 000000000..52610109a
--- /dev/null
+++ b/workers/log_consumer/__init__.py
@@ -0,0 +1,5 @@
+"""Log Consumer Worker for Unstract Platform
+
+This worker consumes log messages from the celery_log_task_queue and processes them
+by storing to Redis and triggering WebSocket emissions through the backend API.
+"""
diff --git a/workers/log_consumer/process_log_history.py b/workers/log_consumer/process_log_history.py
new file mode 100755
index 000000000..fb6ece406
--- /dev/null
+++ b/workers/log_consumer/process_log_history.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+"""Check log history queue and trigger backend processing.
+
+This script:
+1. Checks if logs exist in Redis queue (lightweight LLEN operation)
+2. If logs exist, calls backend internal API to process them
+3. Backend handles Redis LPOP, validation, and bulk DB insert
+
+This avoids duplicating Redis/business logic in workers and minimizes API calls.
+
+Usage:
+ python process_log_history.py
+"""
+
+import logging
+import os
+import sys
+
+import httpx
+from shared.cache.redis_queue_client import RedisQueueClient
+
+logger = logging.getLogger(__name__)
+
+
+def process_log_history():
+ """Check if logs exist in queue and trigger backend processing."""
+ try:
+ # Backend API configuration
+ internal_api_base_url = os.getenv("INTERNAL_API_BASE_URL")
+ internal_api_key = os.getenv("INTERNAL_SERVICE_API_KEY")
+
+ if not internal_api_base_url:
+ logger.error("INTERNAL_API_BASE_URL environment variable not set")
+ return False
+
+ if not internal_api_key:
+ logger.error("INTERNAL_SERVICE_API_KEY environment variable not set")
+ return False
+
+ # Connect to Redis using shared utility (only for checking queue length)
+ log_queue_name = os.getenv("LOG_HISTORY_QUEUE_NAME")
+ if not log_queue_name:
+ logger.error("LOG_HISTORY_QUEUE_NAME environment variable not set")
+ return False
+ redis_client = RedisQueueClient.from_env()
+
+ # Check if logs exist in queue (lightweight operation)
+ queue_length = redis_client.llen(log_queue_name)
+
+ if queue_length == 0:
+ logger.info(f"No logs found in queue '{log_queue_name}'")
+ return True
+
+ logger.info(
+ f"Found {queue_length} logs in queue '{log_queue_name}', "
+ f"calling backend to process..."
+ )
+
+ # Call backend API to process logs (backend uses its own configured constants)
+ # Use client with automatic retries for transient network failures
+ transport = httpx.HTTPTransport(retries=3)
+ with httpx.Client(transport=transport) as client:
+ response = client.post(
+ f"{internal_api_base_url.rstrip('/')}/v1/execution-logs/process-log-history/",
+ headers={
+ "Authorization": f"Bearer {internal_api_key}",
+ },
+ timeout=30.0,
+ )
+
+ if response.status_code == 200:
+ result = response.json()
+ logger.info(
+ f"Successfully processed {result.get('processed_count', 0)} logs "
+ f"(skipped: {result.get('skipped_count', 0)})"
+ )
+ return True
+ else:
+ logger.error(
+ f"Error: Backend returned status {response.status_code}: {response.text}"
+ )
+ return False
+
+ except httpx.HTTPError as e:
+ logger.error(f"HTTP error calling backend: {e}")
+ return False
+ except Exception:
+ logger.exception("Unexpected error")
+ return False
+
+
+if __name__ == "__main__":
+ success = process_log_history()
+ sys.exit(0 if success else 1)
diff --git a/workers/log_consumer/scheduler.sh b/workers/log_consumer/scheduler.sh
new file mode 100755
index 000000000..a5572b21e
--- /dev/null
+++ b/workers/log_consumer/scheduler.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+INTERVAL="${LOG_HISTORY_CONSUMER_INTERVAL:-5}"
+TASK_NAME="process_log_history"
+
+# Task trigger command - can be overridden via environment variable
+DEFAULT_TRIGGER_CMD="/app/.venv/bin/python /app/log_consumer/process_log_history.py"
+TRIGGER_CMD="${TASK_TRIGGER_COMMAND:-$DEFAULT_TRIGGER_CMD}"
+
+echo "=========================================="
+echo "Log History Scheduler Starting"
+echo "=========================================="
+echo "Task: ${TASK_NAME}"
+echo "Interval: ${INTERVAL} seconds"
+echo "Trigger Command: ${TRIGGER_CMD}"
+echo "=========================================="
+
+cleanup() {
+ echo ""
+ echo "=========================================="
+ echo "Scheduler received shutdown signal"
+ echo "Exiting gracefully..."
+ echo "=========================================="
+ exit 0
+}
+
+trap cleanup SIGTERM SIGINT
+
+run_count=0
+
+while true; do
+ run_count=$((run_count + 1))
+
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [Run #${run_count}] Triggering ${TASK_NAME}..."
+
+ if eval "${TRIGGER_CMD}" 2>&1; then
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [Run #${run_count}] ✓ Task completed successfully"
+ else
+ exit_code=$?
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [Run #${run_count}] ✗ Task failed with exit code ${exit_code}"
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [Run #${run_count}] Will retry after ${INTERVAL} seconds"
+ fi
+
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] Sleeping for ${INTERVAL} seconds..."
+ echo ""
+
+ sleep "${INTERVAL}" &
+ wait $!
+done
diff --git a/workers/log_consumer/tasks.py b/workers/log_consumer/tasks.py
new file mode 100644
index 000000000..e30d523f2
--- /dev/null
+++ b/workers/log_consumer/tasks.py
@@ -0,0 +1,121 @@
+"""Log Consumer Tasks
+
+This module contains Celery tasks for processing execution logs.
+"""
+
+import os
+from typing import Any
+
+import socketio
+from celery import shared_task
+from shared.cache.redis_queue_client import RedisQueueClient
+from shared.infrastructure.config import WorkerConfig
+from shared.infrastructure.logging import WorkerLogger
+from shared.utils.api_client_singleton import get_singleton_api_client
+
+from unstract.core.constants import LogEventArgument, LogProcessingTask
+from unstract.core.log_utils import store_execution_log
+
+logger = WorkerLogger.get_logger(__name__)
+
+# Initialize worker configuration
+config = WorkerConfig.from_env("LOG_CONSUMER")
+
+# Redis configuration
+redis_client = RedisQueueClient.from_env()
+
+# Log storage configuration
+log_queue_name = os.getenv("LOG_HISTORY_QUEUE_NAME", "log_history_queue")
+log_storage_enabled = os.getenv("ENABLE_LOG_HISTORY", "true").lower() == "true"
+
+# Socket.IO client for emitting events (uses same KombuManager as backend)
+redis_host = os.getenv("REDIS_HOST", "localhost")
+redis_port = os.getenv("REDIS_PORT", "6379")
+socket_io_manager_url = f"redis://{redis_host}:{redis_port}"
+
+sio = socketio.Server(
+ async_mode="threading",
+ logger=False,
+ engineio_logger=False,
+ client_manager=socketio.KombuManager(url=socket_io_manager_url),
+)
+
+
+@shared_task(name=LogProcessingTask.TASK_NAME)
+def logs_consumer(**kwargs: Any) -> None:
+ """Task to process logs from log publisher.
+
+ This task processes execution logs by:
+ 1. Storing them to Redis queue for persistence
+ 2. Triggering WebSocket emission through backend API
+
+ Args:
+ kwargs: The arguments to process the logs.
+ Expected arguments:
+ USER_SESSION_ID: The room to be processed.
+ EVENT: The event to be processed Ex: logs:{session_id}.
+ MESSAGE: The message to be processed Ex: execution log.
+ """
+ log_message = kwargs.get(LogEventArgument.MESSAGE)
+ room = kwargs.get(LogEventArgument.USER_SESSION_ID)
+ event = kwargs.get(LogEventArgument.EVENT)
+
+ logger.debug(f"[{os.getpid()}] Log message received: {log_message} for room {room}")
+
+ # Validate required arguments
+ if not room or not event:
+ logger.warning(f"Message received without room and event: {log_message}")
+ return
+
+ # Store execution log to Redis
+ try:
+ store_execution_log(
+ data=log_message,
+ redis_client=redis_client.redis_client,
+ log_queue_name=log_queue_name,
+ is_enabled=log_storage_enabled,
+ )
+ except Exception as e:
+ logger.error(f"Failed to store execution log: {e}")
+
+ # Emit WebSocket event directly through Socket.IO (via Redis broker)
+ try:
+ payload = {"data": log_message}
+ sio.emit(event, data=payload, room=room)
+ logger.debug(f"WebSocket event emitted successfully for room {room}")
+ except Exception as e:
+ logger.error(f"Failed to emit WebSocket event: {e}")
+
+
+# Health check task for monitoring
+@shared_task(name="log_consumer_health_check")
+def health_check() -> dict[str, Any]:
+ """Health check task for log consumer worker.
+
+ Returns:
+ Health status information
+ """
+ try:
+ # Check Redis connectivity
+ redis_client.ping()
+ redis_status = "healthy"
+ except Exception as e:
+ redis_status = f"unhealthy: {e}"
+
+ try:
+ # Check API client connectivity
+ api_client = get_singleton_api_client(config)
+ api_status = "healthy" if api_client else "unhealthy"
+ except Exception as e:
+ api_status = f"unhealthy: {e}"
+
+ return {
+ "worker": "log_consumer",
+ "status": "healthy"
+ if redis_status == "healthy" and "healthy" in api_status
+ else "degraded",
+ "redis": redis_status,
+ "api": api_status,
+ "queue": log_queue_name,
+ "log_storage_enabled": log_storage_enabled,
+ }
diff --git a/workers/log_consumer/worker.py b/workers/log_consumer/worker.py
new file mode 100644
index 000000000..df90ca276
--- /dev/null
+++ b/workers/log_consumer/worker.py
@@ -0,0 +1,69 @@
+"""Log Consumer Worker
+
+Celery worker for processing execution logs and WebSocket emissions.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker
+logger = WorkerLogger.setup(WorkerType.LOG_CONSUMER)
+app, config = WorkerBuilder.build_celery_app(WorkerType.LOG_CONSUMER)
+
+
+def check_log_consumer_health():
+ """Custom health check for log consumer worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="log_consumer_health",
+ status=HealthStatus.HEALTHY,
+ message="Log consumer worker is healthy",
+ details={
+ "worker_type": "log_consumer",
+ "api_client": "healthy",
+ "queues": ["celery_log_task_queue", "celery_periodic_logs"],
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="log_consumer_health",
+ status=HealthStatus.DEGRADED,
+ message="Log consumer worker partially functional",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="log_consumer_health",
+ status=HealthStatus.DEGRADED,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.LOG_CONSUMER, "log_consumer_health", check_log_consumer_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "log_consumer",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "log-consumer-worker",
+ }
diff --git a/workers/notification/__init__.py b/workers/notification/__init__.py
new file mode 100644
index 000000000..48f6a97f7
--- /dev/null
+++ b/workers/notification/__init__.py
@@ -0,0 +1,6 @@
+"""Notification Worker for Unstract Platform
+
+This worker handles all types of notifications including webhooks, emails, SMS, and push notifications.
+It provides a unified interface for notification processing while maintaining backward compatibility
+with existing webhook functionality.
+"""
diff --git a/workers/notification/enums.py b/workers/notification/enums.py
new file mode 100644
index 000000000..4ce5883a6
--- /dev/null
+++ b/workers/notification/enums.py
@@ -0,0 +1,29 @@
+"""Notification-specific enums for workers.
+
+These enums are used to match the backend notification system exactly.
+Platform detection is done in the backend and stored in the database.
+"""
+
+from enum import Enum
+
+
+class PlatformType(Enum):
+ """Platform types for notifications.
+
+ Must match the backend PlatformType enum values exactly
+ to ensure compatibility when fetching configs from Django.
+
+ Platform selection is configuration-driven from the backend,
+ not based on URL pattern detection.
+ """
+
+ SLACK = "SLACK"
+ API = "API"
+ # Add other platforms as needed (must match backend)
+ # TEAMS = "TEAMS"
+ # DISCORD = "DISCORD"
+
+ @classmethod
+ def choices(cls):
+ """Get choices for forms/serializers."""
+ return [(e.value, e.name.replace("_", " ").capitalize()) for e in cls]
diff --git a/workers/notification/providers/__init__.py b/workers/notification/providers/__init__.py
new file mode 100644
index 000000000..91750cc13
--- /dev/null
+++ b/workers/notification/providers/__init__.py
@@ -0,0 +1,37 @@
+"""Notification Providers
+
+This module contains notification provider implementations for different notification types.
+Each provider handles the specific logic for sending notifications through their respective channels.
+"""
+
+from .api_webhook import APIWebhook
+from .base_provider import (
+ BaseNotificationProvider,
+ DeliveryError,
+ NotificationError,
+ ValidationError,
+)
+from .registry import (
+ create_notification_provider,
+ create_provider_from_config,
+ get_notification_provider,
+ is_combination_supported,
+ list_supported_combinations,
+)
+from .slack_webhook import SlackWebhook
+from .webhook_provider import WebhookProvider
+
+__all__ = [
+ "BaseNotificationProvider",
+ "WebhookProvider",
+ "SlackWebhook",
+ "APIWebhook",
+ "NotificationError",
+ "ValidationError",
+ "DeliveryError",
+ "get_notification_provider",
+ "create_notification_provider",
+ "create_provider_from_config",
+ "is_combination_supported",
+ "list_supported_combinations",
+]
diff --git a/workers/notification/providers/api_webhook.py b/workers/notification/providers/api_webhook.py
new file mode 100644
index 000000000..8c54d2d19
--- /dev/null
+++ b/workers/notification/providers/api_webhook.py
@@ -0,0 +1,41 @@
+"""API Webhook Notification Provider
+
+Standard API webhook provider for generic webhook endpoints.
+"""
+
+from typing import Any
+
+from notification.providers.webhook_provider import WebhookProvider
+from shared.infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class APIWebhook(WebhookProvider):
+ """Standard API webhook provider.
+
+ Handles generic webhook notifications without platform-specific formatting.
+ Sends the payload as-is in JSON format.
+ """
+
+ def __init__(self):
+ """Initialize API webhook provider."""
+ super().__init__()
+ self.provider_name = "APIWebhook"
+
+ def prepare_data(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Prepare API webhook data.
+
+ For standard API webhooks, we send the payload as-is without
+ any special formatting.
+
+ Args:
+ notification_data: Raw notification data
+
+ Returns:
+ Prepared notification data
+ """
+ logger.debug(
+ f"Preparing standard API webhook data for {notification_data.get('url')}"
+ )
+ return super().prepare_data(notification_data)
diff --git a/workers/notification/providers/base_provider.py b/workers/notification/providers/base_provider.py
new file mode 100644
index 000000000..4b894e558
--- /dev/null
+++ b/workers/notification/providers/base_provider.py
@@ -0,0 +1,183 @@
+"""Base Notification Provider
+
+Abstract base class for all notification providers. This ensures consistent
+interface across different notification types while allowing for specific
+implementation details.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any
+
+from shared.infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class BaseNotificationProvider(ABC):
+ """Abstract base class for notification providers.
+
+ All notification providers (webhook, email, SMS, push) should inherit from
+ this class and implement the required methods.
+ """
+
+ def __init__(self):
+ """Initialize the notification provider."""
+ self.provider_name = self.__class__.__name__
+ logger.debug(f"Initialized {self.provider_name}")
+
+ @abstractmethod
+ def send(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Send notification using this provider.
+
+ Args:
+ notification_data: Dictionary containing all necessary data for sending
+ the notification. The structure may vary by provider type.
+
+ Returns:
+ Dictionary containing the result of the send operation:
+ {
+ "success": bool,
+ "message": str,
+ "details": dict[str, Any], # Provider-specific details
+ "attempts": int,
+ "destination": str
+ }
+
+ Raises:
+ NotificationError: If sending fails critically
+ """
+ raise NotImplementedError("Subclasses must implement send method")
+
+ @abstractmethod
+ def validate(self, notification_data: dict[str, Any]) -> bool:
+ """Validate notification data before attempting to send.
+
+ Args:
+ notification_data: Dictionary containing notification data
+
+ Returns:
+ True if validation passes
+
+ Raises:
+ ValueError: If validation fails with specific error message
+ """
+ raise NotImplementedError("Subclasses must implement validate method")
+
+ def prepare_data(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Prepare notification data for sending.
+
+ This method can be overridden by subclasses to perform provider-specific
+ data preparation (formatting, serialization, etc.).
+
+ Args:
+ notification_data: Raw notification data
+
+ Returns:
+ Prepared notification data
+ """
+ return notification_data
+
+ def get_destination(self, notification_data: dict[str, Any]) -> str:
+ """Extract destination from notification data.
+
+ This method should be overridden by subclasses to extract the appropriate
+ destination identifier (URL for webhooks, email for email notifications, etc.).
+
+ Args:
+ notification_data: Notification data
+
+ Returns:
+ String representation of the destination
+ """
+ return notification_data.get("destination", "unknown")
+
+ def format_success_result(
+ self, destination: str, attempts: int = 1, details: dict[str, Any] | None = None
+ ) -> dict[str, Any]:
+ """Format successful notification result.
+
+ Args:
+ destination: Target destination
+ attempts: Number of attempts taken
+ details: Provider-specific success details
+
+ Returns:
+ Standardized success result
+ """
+ return {
+ "success": True,
+ "message": f"{self.provider_name} notification sent successfully",
+ "destination": destination,
+ "attempts": attempts,
+ "details": details or {},
+ }
+
+ def format_failure_result(
+ self,
+ destination: str,
+ error: Exception,
+ attempts: int = 1,
+ details: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Format failed notification result.
+
+ Args:
+ destination: Target destination
+ error: Exception that occurred
+ attempts: Number of attempts made
+ details: Provider-specific failure details
+
+ Returns:
+ Standardized failure result
+ """
+ return {
+ "success": False,
+ "message": f"{self.provider_name} notification failed: {str(error)}",
+ "destination": destination,
+ "attempts": attempts,
+ "error": str(error),
+ "error_type": error.__class__.__name__,
+ "details": details or {},
+ }
+
+
+class NotificationError(Exception):
+ """Base exception for notification provider errors."""
+
+ def __init__(
+ self, message: str, provider: str | None = None, destination: str | None = None
+ ):
+ """Initialize notification error.
+
+ Args:
+ message: Error message
+ provider: Provider name where error occurred
+ destination: Target destination
+ """
+ self.provider = provider
+ self.destination = destination
+ super().__init__(message)
+
+ def __str__(self) -> str:
+ """String representation of the error."""
+ error_parts = [super().__str__()]
+
+ if self.provider:
+ error_parts.append(f"Provider: {self.provider}")
+
+ if self.destination:
+ error_parts.append(f"Destination: {self.destination}")
+
+ return " | ".join(error_parts)
+
+
+class ValidationError(NotificationError):
+ """Exception raised when notification data validation fails."""
+
+ pass
+
+
+class DeliveryError(NotificationError):
+ """Exception raised when notification delivery fails."""
+
+ pass
diff --git a/workers/notification/providers/registry.py b/workers/notification/providers/registry.py
new file mode 100644
index 000000000..b6f4c58ac
--- /dev/null
+++ b/workers/notification/providers/registry.py
@@ -0,0 +1,135 @@
+"""Notification Provider Registry
+
+Registry pattern for mapping notification types and platform types
+to their appropriate provider implementations.
+"""
+
+from notification.enums import PlatformType
+from notification.providers.api_webhook import APIWebhook
+from notification.providers.base_provider import BaseNotificationProvider
+from notification.providers.slack_webhook import SlackWebhook
+from shared.infrastructure.logging import WorkerLogger
+
+from unstract.core.notification_enums import NotificationType
+
+logger = WorkerLogger.get_logger(__name__)
+
+# Provider registry mapping notification type and platform to provider class
+PROVIDER_REGISTRY = {
+ NotificationType.WEBHOOK: {
+ PlatformType.SLACK: SlackWebhook,
+ PlatformType.API: APIWebhook,
+ # Add other webhook platforms here
+ # PlatformType.TEAMS: TeamsWebhook,
+ # PlatformType.DISCORD: DiscordWebhook,
+ },
+ # Add other notification types here
+ # NotificationType.EMAIL: {
+ # PlatformType.SMTP: SMTPProvider,
+ # PlatformType.SENDGRID: SendGridProvider,
+ # },
+ # NotificationType.SMS: {
+ # PlatformType.TWILIO: TwilioProvider,
+ # PlatformType.AWS_SNS: SNSProvider,
+ # },
+}
+
+
+def get_notification_provider(
+ notification_type: NotificationType, platform_type: PlatformType
+) -> type[BaseNotificationProvider]:
+ """Get notification provider class based on type and platform.
+
+ Args:
+ notification_type: Type of notification (WEBHOOK, EMAIL, etc.)
+ platform_type: Platform/provider type (SLACK, API, etc.)
+
+ Returns:
+ Provider class for the given combination
+
+ Raises:
+ ValueError: If the combination is not supported
+ """
+ logger.debug(f"Looking up provider for {notification_type} + {platform_type}")
+
+ if notification_type not in PROVIDER_REGISTRY:
+ raise ValueError(f"Unsupported notification type: {notification_type}")
+
+ platform_registry = PROVIDER_REGISTRY[notification_type]
+ if platform_type not in platform_registry:
+ raise ValueError(
+ f"Unsupported platform type '{platform_type}' for notification type '{notification_type}'"
+ )
+
+ provider_class = platform_registry[platform_type]
+ logger.debug(f"Found provider: {provider_class.__name__}")
+ return provider_class
+
+
+def create_notification_provider(
+ notification_type: NotificationType, platform_type: PlatformType
+) -> BaseNotificationProvider:
+ """Create and instantiate a notification provider.
+
+ Args:
+ notification_type: Type of notification
+ platform_type: Platform/provider type
+
+ Returns:
+ Instantiated provider ready for use
+
+ Raises:
+ ValueError: If the combination is not supported
+ """
+ provider_class = get_notification_provider(notification_type, platform_type)
+ return provider_class()
+
+
+def create_provider_from_config(notification_config: dict) -> BaseNotificationProvider:
+ """Create provider instance from notification configuration.
+
+ Args:
+ notification_config: Notification config from backend API containing
+ 'notification_type' and 'platform' fields
+
+ Returns:
+ Instantiated provider ready for use
+
+ Raises:
+ ValueError: If the configuration is invalid or unsupported
+ """
+ notification_type = NotificationType(
+ notification_config.get("notification_type", "WEBHOOK")
+ )
+ platform_str = notification_config.get("platform")
+
+ if not platform_str:
+ # Default to API platform for backward compatibility
+ platform_type = PlatformType.API
+ logger.warning(f"No platform specified in config, defaulting to {platform_type}")
+ else:
+ platform_type = PlatformType(platform_str)
+
+ logger.debug(f"Creating provider for {notification_type} + {platform_type}")
+ return create_notification_provider(notification_type, platform_type)
+
+
+def list_supported_combinations() -> dict[str, list[str]]:
+ """List all supported notification type and platform combinations."""
+ combinations = {}
+ for notification_type, platforms in PROVIDER_REGISTRY.items():
+ combinations[notification_type.value] = [
+ platform.value for platform in platforms.keys()
+ ]
+ return combinations
+
+
+def is_combination_supported(
+ notification_type: NotificationType, platform_type: PlatformType
+) -> bool:
+ """Check if a notification type and platform combination is supported."""
+ try:
+ get_notification_provider(notification_type, platform_type)
+ return True
+ except ValueError:
+ return False
diff --git a/workers/notification/providers/slack_webhook.py b/workers/notification/providers/slack_webhook.py
new file mode 100644
index 000000000..cb80cfb68
--- /dev/null
+++ b/workers/notification/providers/slack_webhook.py
@@ -0,0 +1,233 @@
+"""Slack Webhook Notification Provider
+
+This provider handles Slack-specific webhook notifications with proper
+payload formatting for Slack's Block Kit API.
+"""
+
+from typing import Any
+
+from notification.providers.webhook_provider import WebhookProvider
+from shared.infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class SlackWebhook(WebhookProvider):
+ """Slack-specific webhook provider.
+
+ Formats payloads according to Slack's expected structure,
+ including support for Block Kit formatting.
+ """
+
+ def __init__(self):
+ """Initialize Slack webhook provider."""
+ super().__init__()
+ self.provider_name = "SlackWebhook"
+
+ def prepare_data(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Prepare Slack-specific webhook data.
+
+ Formats the payload to match Slack's expected structure
+ with 'text' field and optional Block Kit blocks.
+
+ Args:
+ notification_data: Raw notification data
+
+ Returns:
+ Prepared notification data with Slack formatting
+ """
+ prepared_data = super().prepare_data(notification_data)
+
+ # Format payload for Slack
+ if "payload" in prepared_data:
+ prepared_data["payload"] = self.format_payload(prepared_data["payload"])
+
+ return prepared_data
+
+ def format_payload(self, payload: dict[str, Any]) -> dict[str, Any]:
+ """Format the payload to match Slack's expected structure.
+
+ Args:
+ payload: Original payload
+
+ Returns:
+ Slack-formatted payload with 'text' field and optional blocks
+ """
+ # If payload already has 'text' field, enhance it with blocks
+ if "text" in payload:
+ formatted_payload = {
+ "text": payload.pop("text"),
+ "blocks": self.create_blocks_from_payload(payload),
+ }
+ else:
+ # Construct a Slack message from the payload
+ formatted_payload = {
+ "text": self._get_summary_text(payload),
+ "blocks": self.create_blocks_from_payload(payload),
+ }
+
+ return formatted_payload
+
+ def create_blocks_from_payload(self, payload: dict[str, Any]) -> list[dict[str, Any]]:
+ """Create Slack Block Kit blocks from the payload.
+
+ Args:
+ payload: Payload to convert to blocks
+
+ Returns:
+ List of Slack Block Kit blocks
+ """
+ blocks = []
+
+ # Header block
+ blocks.append(
+ {
+ "type": "section",
+ "text": {"type": "mrkdwn", "text": "*Unstract Notification*"},
+ }
+ )
+
+ # Add divider for visual separation
+ blocks.append({"type": "divider"})
+
+ # Add each key-value pair as a section
+ for key, value in payload.items():
+ if value is None or value == "":
+ continue
+
+ # Format key for display
+ formatted_key = self._format_key(key)
+
+ # Format value based on type
+ formatted_value = self._format_value(value)
+
+ # Create section block
+ blocks.append(
+ {
+ "type": "section",
+ "text": {
+ "type": "mrkdwn",
+ "text": f"*{formatted_key}:*\n{formatted_value}",
+ },
+ }
+ )
+
+ # Add timestamp footer if not already present
+ if not any("timestamp" in str(block).lower() for block in blocks):
+ from datetime import datetime
+
+ blocks.append({"type": "divider"})
+ blocks.append(
+ {
+ "type": "context",
+ "elements": [
+ {
+ "type": "mrkdwn",
+ "text": f"_Sent at {datetime.now().strftime('%Y-%m-%d %H:%M:%S UTC')}_",
+ }
+ ],
+ }
+ )
+
+ return blocks
+
+ def _get_summary_text(self, payload: dict[str, Any]) -> str:
+ """Generate summary text from payload.
+
+ Args:
+ payload: Payload to summarize
+
+ Returns:
+ Summary text for Slack notification
+ """
+ # Priority order for summary fields
+ summary_fields = [
+ "message",
+ "status",
+ "pipeline_name",
+ "workflow_name",
+ "api_name",
+ "error",
+ "result",
+ "summary",
+ ]
+
+ for field in summary_fields:
+ if field in payload and payload[field]:
+ return str(payload[field])
+
+ # Default summary
+ return "Unstract Notification"
+
+ def _format_key(self, key: str) -> str:
+ """Format dictionary key for display.
+
+ Args:
+ key: Raw key name
+
+ Returns:
+ Formatted key for display
+ """
+ # Replace underscores with spaces and capitalize
+ formatted = key.replace("_", " ").title()
+
+ # Special formatting for known keys
+ key_mapping = {
+ "Pipeline Name": "Pipeline Name",
+ "Api Name": "API Name",
+ "Workflow Name": "Workflow Name",
+ "Status": "Status",
+ "Error": "Error",
+ "Success": "Success",
+ "Execution Id": "Execution ID",
+ "Organization Id": "Organization ID",
+ }
+
+ return key_mapping.get(formatted, formatted)
+
+ def _format_value(self, value: Any) -> str:
+ """Format value for Slack display.
+
+ Args:
+ value: Value to format
+
+ Returns:
+ Formatted value string
+ """
+ if isinstance(value, bool):
+ return "✅ Yes" if value else "❌ No"
+ elif isinstance(value, (list, tuple)):
+ return "\n• " + "\n• ".join(str(item) for item in value)
+ elif isinstance(value, dict):
+ # Format nested dictionary
+ items = []
+ for k, v in value.items():
+ items.append(f" • {self._format_key(k)}: {v}")
+ return "\n" + "\n".join(items)
+ elif value is None:
+ return "_Not specified_"
+ else:
+ # Format long strings
+ value_str = str(value)
+ if len(value_str) > 500:
+ return value_str[:497] + "..."
+ return value_str
+
+ def get_destination(self, notification_data: dict[str, Any]) -> str:
+ """Extract webhook URL from notification data with masking for security."""
+ url = notification_data.get("url", "unknown")
+
+ # Mask sensitive webhook URLs for logging security
+ if isinstance(url, str) and url != "unknown":
+ if "hooks.slack.com" in url:
+ # Mask Slack webhook tokens
+ parts = url.split("/")
+ if len(parts) >= 3:
+ return (
+ f"hooks.slack.com/services/{parts[-3][:4]}.../{parts[-2][:4]}..."
+ )
+ elif len(url) > 50:
+ # Mask long URLs that might contain tokens
+ return url[:30] + "..." + url[-10:]
+
+ return url
diff --git a/workers/notification/providers/webhook_provider.py b/workers/notification/providers/webhook_provider.py
new file mode 100644
index 000000000..57a6382d5
--- /dev/null
+++ b/workers/notification/providers/webhook_provider.py
@@ -0,0 +1,256 @@
+"""Webhook Notification Provider
+
+Base webhook provider that handles webhook notifications. Provides the foundation for platform-specific
+webhook providers.
+"""
+
+from typing import Any
+
+import requests
+from notification.providers.base_provider import (
+ BaseNotificationProvider,
+ DeliveryError,
+ ValidationError,
+)
+from shared.infrastructure.logging import WorkerLogger
+
+from unstract.core.notification_utils import (
+ build_webhook_headers,
+ send_webhook_request,
+ serialize_notification_data,
+ validate_webhook_data,
+)
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WebhookProvider(BaseNotificationProvider):
+ """Webhook notification provider.
+
+ This provider implements webhook notifications with identical behavior to the
+ current backend implementation to maintain backward compatibility.
+ """
+
+ def __init__(self):
+ """Initialize webhook provider."""
+ super().__init__()
+ self.provider_name = "Webhook"
+
+ def validate(self, notification_data: dict[str, Any]) -> bool:
+ """Validate webhook notification data.
+
+ Args:
+ notification_data: Webhook notification data containing:
+ - url: Webhook URL (required)
+ - payload: JSON payload (required)
+ - authorization_type: Auth type (optional)
+ - authorization_key: Auth key (optional)
+ - authorization_header: Custom header name (optional)
+
+ Returns:
+ True if validation passes
+
+ Raises:
+ ValidationError: If validation fails
+ """
+ try:
+ validate_webhook_data(
+ url=notification_data.get("url"),
+ payload=notification_data.get("payload"),
+ authorization_type=notification_data.get("authorization_type"),
+ authorization_key=notification_data.get("authorization_key"),
+ authorization_header=notification_data.get("authorization_header"),
+ )
+ return True
+ except ValueError as e:
+ raise ValidationError(str(e), provider=self.provider_name)
+
+ def get_destination(self, notification_data: dict[str, Any]) -> str:
+ """Extract webhook URL from notification data."""
+ return notification_data.get("url", "unknown")
+
+ def prepare_data(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Prepare webhook data for sending.
+
+ This includes serializing UUIDs and datetimes in the payload.
+ """
+ prepared_data = notification_data.copy()
+
+ # Serialize payload to handle UUIDs and datetimes
+ if "payload" in prepared_data:
+ prepared_data["payload"] = serialize_notification_data(
+ prepared_data["payload"]
+ )
+
+ return prepared_data
+
+ def send(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Send webhook notification.
+
+ This method replicates the exact behavior of the current backend
+ send_webhook_notification task to maintain backward compatibility.
+
+ Args:
+ notification_data: Webhook data containing:
+ - url: Target webhook URL
+ - payload: JSON payload to send
+ - headers: Optional custom headers (defaults to auth-based headers)
+ - timeout: Request timeout in seconds (default: 10)
+ - max_retries: Maximum retry attempts (default: None)
+ - retry_delay: Delay between retries in seconds (default: 10)
+ - authorization_type: Authorization type (BEARER, API_KEY, etc.)
+ - authorization_key: Authorization key/token
+ - authorization_header: Custom header name (for CUSTOM_HEADER)
+
+ Returns:
+ Dictionary with send result
+
+ Raises:
+ ValidationError: If data validation fails
+ DeliveryError: If delivery fails after all retries
+ """
+ try:
+ # Validate notification data
+ self.validate(notification_data)
+
+ # Prepare data (serialize UUIDs, etc.)
+ prepared_data = self.prepare_data(notification_data)
+
+ # Extract parameters with defaults (matching backend implementation)
+ url = prepared_data["url"]
+ payload = prepared_data["payload"]
+ timeout = prepared_data.get("timeout", 10)
+ max_retries = prepared_data.get("max_retries")
+ retry_delay = prepared_data.get("retry_delay", 10)
+
+ # Build headers - either use provided headers or build from auth config
+ if "headers" in prepared_data and prepared_data["headers"]:
+ headers = prepared_data["headers"]
+ else:
+ headers = self._build_headers(prepared_data)
+
+ logger.debug(f"Sending webhook to {url} with {len(headers)} headers")
+
+ # Send webhook request using shared utility (identical to backend logic)
+ try:
+ result = send_webhook_request(
+ url=url,
+ payload=payload,
+ headers=headers,
+ timeout=timeout,
+ max_retries=max_retries,
+ retry_delay=retry_delay,
+ current_retry=0,
+ )
+
+ if result.get("success"):
+ return self.format_success_result(
+ destination=url,
+ attempts=result.get("attempts", 1),
+ details={
+ "status_code": result.get("status_code"),
+ "response_text": result.get("response_text", "")[
+ :500
+ ], # Limit response size
+ },
+ )
+ else:
+ return self.format_failure_result(
+ destination=url,
+ error=Exception(result.get("error", "Unknown error")),
+ attempts=result.get("attempts", 1),
+ details=result,
+ )
+
+ except requests.exceptions.RequestException as exc:
+ # This exception will be caught by the worker retry mechanism
+ # for Celery-based retry handling - identical to backend behavior
+ raise DeliveryError(
+ f"Webhook request failed: {str(exc)}",
+ provider=self.provider_name,
+ destination=url,
+ )
+
+ except ValidationError:
+ # Re-raise validation errors as-is
+ raise
+ except Exception as e:
+ # Wrap unexpected errors
+ raise DeliveryError(
+ f"Unexpected error sending webhook: {str(e)}",
+ provider=self.provider_name,
+ destination=notification_data.get("url", "unknown"),
+ )
+
+ def _build_headers(self, notification_data: dict[str, Any]) -> dict[str, str]:
+ """Build webhook headers based on authorization configuration.
+
+ This method uses the shared utility to maintain identical behavior
+ to the backend implementation.
+ """
+ try:
+ return build_webhook_headers(
+ authorization_type=notification_data.get("authorization_type", "NONE"),
+ authorization_key=notification_data.get("authorization_key"),
+ authorization_header=notification_data.get("authorization_header"),
+ custom_headers=notification_data.get("custom_headers"),
+ )
+ except ValueError as e:
+ raise ValidationError(str(e), provider=self.provider_name)
+
+
+# Future provider implementations can be added here:
+
+
+class EmailProvider(BaseNotificationProvider):
+ """Email notification provider (future implementation)."""
+
+ def __init__(self):
+ super().__init__()
+ self.provider_name = "Email"
+
+ def validate(self, notification_data: dict[str, Any]) -> bool:
+ """Validate email notification data (placeholder)."""
+ # TODO: Implement email validation
+ raise NotImplementedError("Email notifications not yet implemented")
+
+ def send(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Send email notification (placeholder)."""
+ # TODO: Implement email sending
+ raise NotImplementedError("Email notifications not yet implemented")
+
+
+class SMSProvider(BaseNotificationProvider):
+ """SMS notification provider (future implementation)."""
+
+ def __init__(self):
+ super().__init__()
+ self.provider_name = "SMS"
+
+ def validate(self, notification_data: dict[str, Any]) -> bool:
+ """Validate SMS notification data (placeholder)."""
+ # TODO: Implement SMS validation
+ raise NotImplementedError("SMS notifications not yet implemented")
+
+ def send(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Send SMS notification (placeholder)."""
+ # TODO: Implement SMS sending
+ raise NotImplementedError("SMS notifications not yet implemented")
+
+
+class PushProvider(BaseNotificationProvider):
+ """Push notification provider (future implementation)."""
+
+ def __init__(self):
+ super().__init__()
+ self.provider_name = "Push"
+
+ def validate(self, notification_data: dict[str, Any]) -> bool:
+ """Validate push notification data (placeholder)."""
+ # TODO: Implement push validation
+ raise NotImplementedError("Push notifications not yet implemented")
+
+ def send(self, notification_data: dict[str, Any]) -> dict[str, Any]:
+ """Send push notification (placeholder)."""
+ # TODO: Implement push sending
+ raise NotImplementedError("Push notifications not yet implemented")
diff --git a/workers/notification/tasks.py b/workers/notification/tasks.py
new file mode 100644
index 000000000..32a684ad9
--- /dev/null
+++ b/workers/notification/tasks.py
@@ -0,0 +1,401 @@
+"""Notification Worker Tasks
+
+This module contains Celery tasks for processing all types of notifications.
+It uses the provider registry pattern for platform-specific notification handling
+while maintaining backward compatibility.
+"""
+
+import os
+from typing import Any
+
+from celery import shared_task
+from notification.enums import PlatformType
+from notification.providers.base_provider import (
+ DeliveryError,
+ NotificationError,
+ ValidationError,
+)
+from notification.providers.registry import create_provider_from_config
+from notification.providers.webhook_provider import WebhookProvider
+from notification.utils import (
+ log_notification_attempt,
+ log_notification_failure,
+ log_notification_success,
+)
+from shared.infrastructure.config import WorkerConfig
+from shared.infrastructure.logging import WorkerLogger
+
+from unstract.core.notification_enums import NotificationType
+
+logger = WorkerLogger.get_logger(__name__)
+
+# Initialize worker configuration
+config = WorkerConfig.from_env("NOTIFICATION")
+
+
+def _get_webhook_provider_for_url(url: str):
+ """Get webhook provider for backward compatibility.
+
+ For backward compatibility with legacy webhook tasks that don't provide platform info.
+ Always defaults to API provider since platform should come from notification configuration.
+
+ Args:
+ url: Webhook URL (used for logging only)
+
+ Returns:
+ API webhook provider instance
+ """
+ logger.debug(
+ f"Legacy webhook task called without platform info for URL: {url[:50]}..."
+ )
+
+ # Always use API provider for backward compatibility
+ # Platform detection should be done in backend and stored in database
+ try:
+ config = {
+ "notification_type": NotificationType.WEBHOOK.value,
+ "platform": PlatformType.API.value,
+ }
+ return create_provider_from_config(config)
+ except Exception as e:
+ logger.warning(
+ f"Failed to create API provider: {e}. Using fallback WebhookProvider"
+ )
+ return WebhookProvider()
+
+
+@shared_task(name="process_notification")
+def process_notification(
+ notification_type: str, priority: bool = False, **kwargs: Any
+) -> dict[str, Any]:
+ """Universal notification processor.
+
+ This task routes notifications to the appropriate provider based on type.
+ It provides a unified interface for all notification types while maintaining
+ extensibility for future implementations.
+
+ Args:
+ notification_type: Type of notification (WEBHOOK, EMAIL, SMS, PUSH)
+ **kwargs: Notification-specific parameters
+
+ Returns:
+ Dictionary containing the processing result
+
+ Raises:
+ NotificationError: If notification processing fails
+ """
+ destination = (
+ kwargs.get("url") or kwargs.get("email") or kwargs.get("phone") or "unknown"
+ )
+
+ try:
+ logger.info(f"Processing {notification_type} notification to {destination}")
+
+ # Use the registry pattern with platform from config
+ if notification_type == NotificationType.WEBHOOK.value:
+ platform = kwargs.get("platform")
+ if platform:
+ config = {"notification_type": notification_type, "platform": platform}
+ provider = create_provider_from_config(config)
+ logger.debug(f"Selected provider: {provider.__class__.__name__}")
+ else:
+ # Backward compatibility: Default to API provider
+ logger.warning("No platform specified, using API provider")
+ provider = WebhookProvider()
+ else:
+ # For future notification types (EMAIL, SMS, etc.)
+ raise NotificationError(
+ f"Unsupported notification type: {notification_type}",
+ provider="NotificationDispatcher",
+ destination=destination,
+ )
+
+ log_notification_attempt(
+ notification_type=notification_type,
+ destination=destination,
+ attempt=1, # TODO: Track actual retry attempts
+ )
+
+ # Send notification
+ result = provider.send(kwargs)
+
+ if result.get("success"):
+ log_notification_success(
+ notification_type=notification_type,
+ destination=destination,
+ attempt=result.get("attempts", 1),
+ response_info=result.get("details"),
+ )
+ else:
+ log_notification_failure(
+ notification_type=notification_type,
+ destination=destination,
+ error=Exception(result.get("message", "Unknown error")),
+ attempt=result.get("attempts", 1),
+ is_final=True,
+ )
+
+ return result
+
+ except (ValidationError, DeliveryError) as e:
+ logger.error(f"Notification error: {str(e)}")
+ log_notification_failure(
+ notification_type=notification_type,
+ destination=destination,
+ error=e,
+ attempt=1,
+ is_final=True,
+ )
+ return {
+ "success": False,
+ "message": str(e),
+ "destination": destination,
+ "error_type": e.__class__.__name__,
+ }
+ except Exception as e:
+ logger.error(
+ f"Unexpected error processing {notification_type} notification: {str(e)}"
+ )
+ return {
+ "success": False,
+ "message": f"Unexpected error: {str(e)}",
+ "destination": destination,
+ "error_type": e.__class__.__name__,
+ }
+
+
+@shared_task(bind=True, name="send_webhook_notification")
+def send_webhook_notification(
+ self,
+ url: str,
+ payload: Any,
+ headers: Any = None,
+ timeout: int = 10,
+ max_retries: int | None = None,
+ retry_delay: int = 10,
+ platform: str | None = None,
+) -> None:
+ """Backward compatible webhook notification task.
+
+ This task maintains 100% compatibility with the existing backend
+ send_webhook_notification task. It delegates to the WebhookProvider
+ but preserves the exact same interface and behavior.
+
+ Args:
+ url: The URL to which the webhook should be sent
+ payload: The payload to be sent in the webhook request
+ headers: Optional headers to include in the request
+ timeout: The request timeout in seconds
+ max_retries: The maximum number of retries allowed
+ retry_delay: The delay between retries in seconds
+ platform: Platform type from notification config (SLACK, API, etc.)
+
+ Returns:
+ None (matches original behavior)
+
+ Raises:
+ Exception: If webhook delivery fails (for Celery retry mechanism)
+ """
+ try:
+ logger.debug(
+ f"[{os.getpid()}] Processing webhook notification to {url} "
+ f"(attempt {self.request.retries + 1})"
+ )
+ logger.debug(f"Task received platform parameter: {platform}")
+ logger.debug(f"Task received payload type: {type(payload)}")
+ logger.debug(f"Task received headers: {headers}")
+
+ # Use platform-specific provider if provided, otherwise default to API for backward compatibility
+ if platform:
+ config = {
+ "notification_type": NotificationType.WEBHOOK.value,
+ "platform": platform,
+ }
+ webhook_provider = create_provider_from_config(config)
+ else:
+ webhook_provider = _get_webhook_provider_for_url(url)
+
+ # Prepare notification data in the format expected by WebhookProvider
+ notification_data = {
+ "url": url,
+ "payload": payload,
+ "headers": headers,
+ "timeout": timeout,
+ "max_retries": max_retries,
+ "retry_delay": retry_delay,
+ "platform": platform,
+ }
+
+ # Send webhook notification
+ result = webhook_provider.send(notification_data)
+
+ # Handle result based on success/failure
+ if result.get("success"):
+ logger.info(
+ f"Webhook delivered successfully to {url} "
+ f"(status: {result.get('details', {}).get('status_code', 'unknown')})"
+ )
+ return None # Success - matches original behavior
+ else:
+ # Failed delivery - raise exception for retry handling
+ error_message = result.get("message", "Unknown webhook delivery error")
+ raise Exception(error_message)
+
+ except (ValidationError, DeliveryError) as e:
+ # Handle provider-specific errors
+ if max_retries is not None:
+ if self.request.retries < max_retries:
+ logger.warning(
+ f"Request to {url} failed. Retrying in {retry_delay} seconds. "
+ f"Attempt {self.request.retries + 1}/{max_retries}. Error: {e}"
+ )
+ # Use Celery's retry mechanism - identical to original behavior
+ raise self.retry(exc=e, countdown=retry_delay)
+ else:
+ logger.error(
+ f"Failed to send webhook to {url} after {max_retries} attempts. "
+ f"Error: {e}"
+ )
+ return None # Final failure - matches original behavior
+ else:
+ logger.error(f"Webhook request to {url} failed with error: {e}")
+ return None # No retries configured - matches original behavior
+
+ except Exception as e:
+ # Handle unexpected errors - preserve original retry logic
+ if max_retries is not None:
+ if self.request.retries < max_retries:
+ logger.warning(
+ f"Request to {url} failed. Retrying in {retry_delay} seconds. "
+ f"Attempt {self.request.retries + 1}/{max_retries}. Error: {e}"
+ )
+ raise self.retry(exc=e, countdown=retry_delay)
+ else:
+ logger.error(
+ f"Failed to send webhook to {url} after {max_retries} attempts. "
+ f"Error: {e}"
+ )
+ return None
+ else:
+ logger.error(f"Webhook request to {url} failed with error: {e}")
+ return None
+
+
+@shared_task(name="send_batch_notifications")
+def send_batch_notifications(
+ notifications: list[dict[str, Any]],
+ batch_id: str | None = None,
+ delay_between: int = 0,
+) -> dict[str, Any]:
+ """Send multiple notifications in batch.
+
+ This task processes multiple notifications with optional delays between them.
+ It's designed for future enhancement of the notification system.
+
+ Args:
+ notifications: List of notification configurations
+ batch_id: Optional batch identifier
+ delay_between: Delay between notifications in seconds
+
+ Returns:
+ Dictionary with batch processing results
+ """
+ import uuid
+ from datetime import datetime
+
+ batch_id = batch_id or str(uuid.uuid4())
+
+ logger.info(f"Processing batch {batch_id} with {len(notifications)} notifications")
+
+ results = {
+ "batch_id": batch_id,
+ "total_notifications": len(notifications),
+ "successful": [],
+ "failed": [],
+ "started_at": datetime.now().isoformat(),
+ }
+
+ for i, notification in enumerate(notifications):
+ try:
+ notification_type = notification.get("type", NotificationType.WEBHOOK.value)
+
+ # Add delay between notifications if specified
+ if delay_between > 0 and i > 0:
+ import time
+
+ time.sleep(delay_between)
+
+ # Process notification
+ result = process_notification(notification_type, **notification)
+
+ if result.get("success"):
+ results["successful"].append(
+ {
+ "index": i,
+ "destination": result.get("destination"),
+ "type": notification_type,
+ }
+ )
+ else:
+ results["failed"].append(
+ {
+ "index": i,
+ "destination": result.get("destination"),
+ "type": notification_type,
+ "error": result.get("message"),
+ }
+ )
+
+ except Exception as e:
+ logger.error(f"Batch notification {i} failed: {str(e)}")
+ results["failed"].append(
+ {
+ "index": i,
+ "destination": notification.get("url", "unknown"),
+ "type": notification.get("type", "unknown"),
+ "error": str(e),
+ }
+ )
+
+ results["completed_at"] = datetime.now().isoformat()
+
+ logger.info(
+ f"Batch {batch_id} completed: {len(results['successful'])} successful, "
+ f"{len(results['failed'])} failed"
+ )
+
+ return results
+
+
+@shared_task(name="priority_notification")
+def priority_notification(notification_type: str, **kwargs: Any) -> dict[str, Any]:
+ """High-priority notification processor.
+
+ This task is routed to the priority queue for urgent notifications
+ that need immediate processing.
+
+ Args:
+ notification_type: Type of notification (WEBHOOK, EMAIL, SMS, PUSH)
+ **kwargs: Notification-specific parameters
+
+ Returns:
+ Dictionary containing the processing result
+ """
+ logger.info(f"Processing priority {notification_type} notification")
+
+ # Set priority flag and delegate to main processor
+ return process_notification(notification_type, priority=True, **kwargs)
+
+
+@shared_task(name="notification_health_check")
+def notification_health_check() -> dict[str, Any]:
+ """Health check task for notification worker."""
+ try:
+ queue_name = os.getenv("NOTIFICATION_QUEUE_NAME", "notifications")
+ return {
+ "worker": "notification",
+ "status": "healthy",
+ "queue": queue_name,
+ }
+ except Exception as e:
+ return {"worker": "notification", "status": "unhealthy", "error": str(e)}
diff --git a/workers/notification/utils.py b/workers/notification/utils.py
new file mode 100644
index 000000000..001240636
--- /dev/null
+++ b/workers/notification/utils.py
@@ -0,0 +1,83 @@
+"""Notification Worker Utilities
+
+Worker-specific utility functions for notification processing.
+"""
+
+import logging
+from typing import Any
+
+from shared.infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+def log_notification_attempt(
+ notification_type: str,
+ destination: str,
+ attempt: int,
+ max_attempts: int | None = None,
+) -> None:
+ """Log notification attempt.
+
+ Args:
+ notification_type: Type of notification
+ destination: Target destination
+ attempt: Current attempt number
+ max_attempts: Maximum number of attempts
+ """
+ attempt_info = f"attempt {attempt}"
+ if max_attempts:
+ attempt_info += f"/{max_attempts}"
+
+ logger.info(
+ f"Sending {notification_type} notification to {destination} ({attempt_info})"
+ )
+
+
+def log_notification_success(
+ notification_type: str,
+ destination: str,
+ attempt: int,
+ response_info: dict[str, Any] | None = None,
+) -> None:
+ """Log successful notification delivery.
+
+ Args:
+ notification_type: Type of notification
+ destination: Target destination
+ attempt: Number of attempts taken
+ response_info: Additional response information
+ """
+ success_msg = f"{notification_type} notification sent successfully to {destination}"
+ if attempt > 1:
+ success_msg += f" (after {attempt} attempts)"
+
+ if response_info and response_info.get("status_code"):
+ success_msg += f" (status: {response_info['status_code']})"
+
+ logger.info(success_msg)
+
+
+def log_notification_failure(
+ notification_type: str,
+ destination: str,
+ error: Exception,
+ attempt: int,
+ is_final: bool = False,
+) -> None:
+ """Log notification failure.
+
+ Args:
+ notification_type: Type of notification
+ destination: Target destination
+ error: Exception that occurred
+ attempt: Current attempt number
+ is_final: Whether this is the final attempt
+ """
+ level = logging.ERROR if is_final else logging.WARNING
+
+ failure_msg = f"{notification_type} notification failed to {destination} (attempt {attempt}): {str(error)}"
+ if is_final:
+ failure_msg = f"Final failure - {failure_msg}"
+
+ logger.log(level, failure_msg)
diff --git a/workers/notification/worker.py b/workers/notification/worker.py
new file mode 100644
index 000000000..112a4b649
--- /dev/null
+++ b/workers/notification/worker.py
@@ -0,0 +1,73 @@
+"""Notification Worker
+
+Celery worker for processing notifications including webhooks, emails, SMS.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker
+logger = WorkerLogger.setup(WorkerType.NOTIFICATION)
+app, config = WorkerBuilder.build_celery_app(WorkerType.NOTIFICATION)
+
+
+def check_notification_health():
+ """Custom health check for notification worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="notification_health",
+ status=HealthStatus.HEALTHY,
+ message="Notification worker is healthy",
+ details={
+ "worker_type": "notification",
+ "api_client": "healthy",
+ "queues": [
+ "notifications_webhook",
+ "notifications_email",
+ "notifications_sms",
+ ],
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="notification_health",
+ status=HealthStatus.DEGRADED,
+ message="Notification worker partially functional",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="notification_health",
+ status=HealthStatus.DEGRADED,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.NOTIFICATION, "notification_health", check_notification_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "notification",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "notification-worker",
+ }
diff --git a/workers/plugin_registry.py b/workers/plugin_registry.py
new file mode 100644
index 000000000..bc6cd894d
--- /dev/null
+++ b/workers/plugin_registry.py
@@ -0,0 +1,237 @@
+"""Workers Plugin Registry System
+
+This registry system allows dynamic loading of worker plugins based on environment
+configuration, providing clean separation between OSS and cloud plugins.
+
+Architecture:
+- OSS: Only basic/OSS plugins are available
+- Cloud: Additional cloud plugins detected via CLOUD_DEPLOYMENT environment variable
+- Workers run independently from Django backend using environment-based configuration
+- No hardcoded imports - everything is environment-driven
+"""
+
+import logging
+import os
+from pathlib import Path
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+class WorkersPluginRegistry:
+ """Registry for managing worker plugins dynamically based on settings."""
+
+ def __init__(self):
+ self._plugins: dict[str, Any] = {}
+ self._plugin_configs: dict[str, dict[str, Any]] = {}
+ self._initialized = False
+
+ def register_plugin_from_config(self, name: str, config: dict[str, Any]) -> None:
+ """Register a plugin from configuration.
+
+ Args:
+ name: Plugin name
+ config: Plugin configuration dictionary
+ """
+ if not config.get("enabled", True):
+ logger.debug(f"Plugin '{name}' disabled, skipping registration")
+ return
+
+ if name in self._plugin_configs:
+ logger.warning(f"Plugin '{name}' already registered, skipping")
+ return
+
+ # Store configuration
+ self._plugin_configs[name] = config
+
+ # Try to load plugin
+ plugin_path = config.get("plugin_path")
+ if plugin_path:
+ self._load_plugin_module(name, plugin_path)
+
+ logger.info(f"Registered plugin: {name}")
+
+ def _load_plugin_module(self, name: str, plugin_path: str) -> None:
+ """Load a plugin module dynamically.
+
+ Args:
+ name: Plugin name
+ plugin_path: Python module path (e.g., "workers.plugins.manual_review")
+ """
+ try:
+ # Import the plugin module
+ module = __import__(plugin_path, fromlist=[""])
+
+ # Look for a Plugin class or client
+ plugin_instance = None
+
+ if hasattr(module, "Plugin"):
+ plugin_instance = module.Plugin()
+ elif hasattr(module, "ManualReviewClient"):
+ plugin_instance = module.ManualReviewClient
+ else:
+ # Store the module itself
+ plugin_instance = module
+
+ self._plugins[name] = plugin_instance
+ logger.debug(f"Loaded plugin module: {name} from {plugin_path}")
+
+ except ImportError as e:
+ logger.warning(f"Could not import plugin '{name}' from {plugin_path}: {e}")
+ except Exception as e:
+ logger.error(f"Error loading plugin '{name}': {e}")
+
+ def get_plugin(self, name: str) -> Any | None:
+ """Get a plugin by name."""
+ return self._plugins.get(name)
+
+ def list_available_plugins(self) -> list[dict[str, Any]]:
+ """List all available plugins with their configurations."""
+ plugins = []
+ for name, config in self._plugin_configs.items():
+ plugin_info = {
+ "name": name,
+ "enabled": config.get("enabled", True),
+ "description": config.get("description", ""),
+ "version": config.get("version", "unknown"),
+ "loaded": name in self._plugins,
+ }
+ plugins.append(plugin_info)
+ return plugins
+
+ def is_plugin_enabled(self, name: str) -> bool:
+ """Check if a plugin is enabled."""
+ config = self._plugin_configs.get(name, {})
+ return config.get("enabled", False)
+
+ def get_plugin_config(self, name: str) -> dict[str, Any]:
+ """Get plugin configuration."""
+ return self._plugin_configs.get(name, {})
+
+ def initialize_from_settings(self) -> None:
+ """Initialize plugins from environment configuration.
+
+ Workers run independently from Django backend and use environment-based
+ configuration for plugin discovery and management.
+ """
+ if self._initialized:
+ return
+
+ # Load plugin configuration from environment variables or defaults
+ plugin_modules = self._get_default_plugin_config()
+
+ logger.debug(
+ f"Loaded plugin configuration from environment: {len(plugin_modules)} modules"
+ )
+
+ # Register all configured plugins
+ for name, config in plugin_modules.items():
+ self.register_plugin_from_config(name, config)
+
+ self._initialized = True
+ logger.info(
+ f"Plugin registry initialized with {len(self._plugin_configs)} plugins"
+ )
+
+ def _get_default_plugin_config(self) -> dict[str, Any]:
+ """Get plugin configuration from environment variables and deployment type."""
+ # This provides minimal fallback configuration
+ default_config = {}
+
+ # Check if we're in a cloud environment via environment variables
+ if os.environ.get("CLOUD_DEPLOYMENT", "false").lower() == "true":
+ default_config.update(
+ {
+ "manual_review": {
+ "enabled": True,
+ "plugin_path": "workers.plugins.manual_review",
+ "description": "Manual review system",
+ "version": "1.0.0",
+ }
+ }
+ )
+
+ return default_config
+
+ def clear(self) -> None:
+ """Clear all plugins (for testing)."""
+ self._plugins.clear()
+ self._plugin_configs.clear()
+ self._initialized = False
+
+
+# Global registry instance
+_workers_plugin_registry = WorkersPluginRegistry()
+
+
+def get_plugin(name: str) -> Any | None:
+ """Get a plugin by name.
+
+ This automatically initializes the registry from settings if needed.
+ """
+ _workers_plugin_registry.initialize_from_settings()
+ return _workers_plugin_registry.get_plugin(name)
+
+
+def list_available_plugins() -> list[dict[str, Any]]:
+ """List all available plugins."""
+ _workers_plugin_registry.initialize_from_settings()
+ return _workers_plugin_registry.list_available_plugins()
+
+
+def is_plugin_enabled(name: str) -> bool:
+ """Check if a plugin is enabled."""
+ _workers_plugin_registry.initialize_from_settings()
+ return _workers_plugin_registry.is_plugin_enabled(name)
+
+
+def get_plugin_config(name: str) -> dict[str, Any]:
+ """Get plugin configuration."""
+ _workers_plugin_registry.initialize_from_settings()
+ return _workers_plugin_registry.get_plugin_config(name)
+
+
+def initialize_plugins() -> None:
+ """Explicitly initialize plugins from settings."""
+ _workers_plugin_registry.initialize_from_settings()
+
+
+# Backward compatibility - expose the old plugin system functions
+def validate_plugin_structure(plugin_name: str) -> dict[str, bool]:
+ """Validate plugin structure (backward compatibility)."""
+ config = get_plugin_config(plugin_name)
+ plugin_path = config.get("plugin_path", "")
+
+ if not plugin_path:
+ return {"exists": False}
+
+ # Convert module path to file path for validation
+ try:
+ module_parts = plugin_path.split(".")
+ if len(module_parts) >= 3 and module_parts[0] == "workers":
+ # e.g. workers.plugins.manual_review -> workers/plugins/manual_review
+ plugin_dir = Path(__file__).parent / "/".join(module_parts[1:])
+
+ return {
+ "exists": plugin_dir.exists(),
+ "has_init": (plugin_dir / "__init__.py").exists(),
+ "has_client": (plugin_dir / "client.py").exists(),
+ "has_tasks": (plugin_dir / "tasks.py").exists(),
+ "has_dto": (plugin_dir / "dto.py").exists(),
+ "has_readme": (plugin_dir / "README.md").exists(),
+ }
+ except Exception:
+ pass
+
+ return {"exists": False}
+
+
+__all__ = [
+ "get_plugin",
+ "list_available_plugins",
+ "is_plugin_enabled",
+ "get_plugin_config",
+ "initialize_plugins",
+ "validate_plugin_structure",
+ "WorkersPluginRegistry",
+]
diff --git a/workers/plugins/.gitignore b/workers/plugins/.gitignore
new file mode 100644
index 000000000..1f6369cb8
--- /dev/null
+++ b/workers/plugins/.gitignore
@@ -0,0 +1,7 @@
+# Ignore all plugin implementation directories
+# Keep only infrastructure files (__init__.py, plugin_manager.py, etc.)
+*/
+
+# But allow infrastructure files to be tracked
+!__init__.py
+!plugin_manager.py
diff --git a/workers/plugins/__init__.py b/workers/plugins/__init__.py
new file mode 100644
index 000000000..4de7747f5
--- /dev/null
+++ b/workers/plugins/__init__.py
@@ -0,0 +1,70 @@
+"""Workers Plugin System
+
+This module provides a settings-based plugin architecture for workers that allows
+modular functionality to be added without modifying core worker code.
+
+The system automatically loads plugins based on Django settings configuration,
+providing clean separation between OSS and cloud plugins.
+
+Architecture:
+- OSS: Only basic plugins available (configured in base.py)
+- Cloud: Additional cloud plugins loaded via cloud.py settings
+- Settings-driven: No hardcoded plugin discovery or try/except imports
+
+Usage:
+ from workers.plugins import get_plugin, list_available_plugins
+
+ # Get a specific plugin - automatically loads based on settings
+ manual_review = get_plugin("manual_review") # Available only in cloud
+
+ # List all available plugins - shows only enabled plugins
+ plugins = list_available_plugins()
+"""
+
+# Import the new settings-based registry system
+from plugin_registry import (
+ get_plugin,
+ get_plugin_config,
+ initialize_plugins,
+ is_plugin_enabled,
+ list_available_plugins,
+ validate_plugin_structure,
+)
+
+# Backward compatibility exports
+get_plugin_requirements = get_plugin_config
+
+
+def load_plugin_tasks(plugin_name: str):
+ """Load Celery tasks from a plugin."""
+ plugin = get_plugin(plugin_name)
+ if plugin and hasattr(plugin, "get_tasks"):
+ return plugin.get_tasks()
+ return None
+
+
+def get_all_plugin_tasks():
+ """Get all tasks from all enabled plugins."""
+ all_tasks = {}
+
+ for plugin_info in list_available_plugins():
+ if plugin_info["enabled"]:
+ plugin_name = plugin_info["name"]
+ tasks = load_plugin_tasks(plugin_name)
+ if tasks:
+ all_tasks[plugin_name] = tasks
+
+ return all_tasks
+
+
+__all__ = [
+ "get_plugin",
+ "list_available_plugins",
+ "is_plugin_enabled",
+ "get_plugin_requirements",
+ "get_plugin_config",
+ "initialize_plugins",
+ "load_plugin_tasks",
+ "get_all_plugin_tasks",
+ "validate_plugin_structure",
+]
diff --git a/workers/plugins/plugin_manager.py b/workers/plugins/plugin_manager.py
new file mode 100644
index 000000000..e3df1c426
--- /dev/null
+++ b/workers/plugins/plugin_manager.py
@@ -0,0 +1,274 @@
+"""Plugin Manager for Workers
+
+This module provides programmatic tools for managing worker plugins.
+CLI functionality has been removed as plugins are managed programmatically.
+"""
+
+import json
+import logging
+import sys
+from pathlib import Path
+
+# Add the workers directory to the path so we can import our modules
+sys.path.insert(0, str(Path(__file__).parent.parent))
+
+# Setup logger
+logger = logging.getLogger(__name__)
+
+try:
+ from plugins import (
+ get_plugin,
+ get_plugin_requirements,
+ list_available_plugins,
+ validate_plugin_structure,
+ )
+except ImportError as e:
+ logger.error(f"Error importing plugin system: {e}")
+ logger.error("Make sure you're running this from the workers directory")
+ sys.exit(1)
+
+
+class PluginManager:
+ """Plugin management operations."""
+
+ def list_plugins(self) -> None:
+ """List all available plugins."""
+ plugins = list_available_plugins()
+
+ if not plugins:
+ logger.info("No plugins found in the plugins directory.")
+ return
+
+ logger.info(f"Found {len(plugins)} plugin(s):\n")
+
+ for plugin in plugins:
+ logger.info(f"📦 {plugin['name']}")
+ logger.info(f" Path: {plugin['path']}")
+
+ # Show available components
+ components = []
+ if plugin.get("has_client", False):
+ components.append("client")
+ if plugin.get("has_tasks", False):
+ components.append("tasks")
+ if plugin.get("has_dto", False):
+ components.append("dto")
+ if plugin.get("has_backend_integration", False):
+ components.append("backend-integration")
+ if plugin.get("has_readme", False):
+ components.append("readme")
+
+ if components:
+ logger.info(f" Components: {', '.join(components)}")
+ else:
+ logger.info(" Components: none")
+
+ logger.info("")
+
+ def show_plugin_info(self, plugin_name: str) -> None:
+ """Show detailed information about a plugin."""
+ logger.info(f"Plugin Information: {plugin_name}")
+ logger.info("=" * 50)
+
+ self._show_plugin_metadata(plugin_name)
+ self._show_plugin_structure_validation(plugin_name)
+ self._show_plugin_loading_test(plugin_name)
+
+ def _show_plugin_metadata(self, plugin_name: str) -> None:
+ """Display plugin metadata information."""
+ requirements = get_plugin_requirements(plugin_name)
+ if not requirements:
+ return
+
+ logger.info("Metadata:")
+ for key, value in requirements.items():
+ if isinstance(value, (list, dict)):
+ logger.info(f" {key}: {json.dumps(value, indent=4)}")
+ else:
+ logger.info(f" {key}: {value}")
+ logger.info("")
+
+ def _show_plugin_structure_validation(self, plugin_name: str) -> None:
+ """Display plugin structure validation results."""
+ validation = validate_plugin_structure(plugin_name)
+ logger.info("Structure Validation:")
+ for check, result in validation.items():
+ status = "✅" if result else "❌"
+ logger.info(f" {status} {check}")
+ logger.info("")
+
+ def _show_plugin_loading_test(self, plugin_name: str) -> None:
+ """Test and display plugin loading results."""
+ logger.info("Plugin Loading Test:")
+ try:
+ plugin = get_plugin(plugin_name)
+ if plugin:
+ logger.info(" ✅ Plugin loaded successfully")
+ self._show_plugin_type_info(plugin)
+ else:
+ logger.error(" ❌ Plugin failed to load")
+ except Exception as e:
+ logger.error(f" ❌ Plugin loading error: {e}")
+ logger.info("")
+
+ def _show_plugin_type_info(self, plugin) -> None:
+ """Display plugin type information."""
+ if hasattr(plugin, "__name__"):
+ logger.info(f" 📋 Plugin type: {plugin.__name__}")
+ elif hasattr(plugin, "__class__"):
+ logger.info(f" 📋 Plugin type: {plugin.__class__.__name__}")
+
+ def validate_plugin(self, plugin_name: str) -> bool:
+ """Validate a plugin thoroughly."""
+ logger.info(f"Validating Plugin: {plugin_name}")
+ logger.info("=" * 50)
+
+ # Structure validation
+ if not self._validate_plugin_structure(plugin_name):
+ return False
+
+ # Import test
+ return self._validate_plugin_import(plugin_name)
+
+ def _validate_plugin_structure(self, plugin_name: str) -> bool:
+ """Validate plugin structure and return True if valid."""
+ validation = validate_plugin_structure(plugin_name)
+ structure_valid = True
+
+ logger.info("Structure Validation:")
+ for check, result in validation.items():
+ status = "✅" if result else "❌"
+ logger.info(f" {status} {check}")
+ if not result and check in ["exists", "has_init"]:
+ structure_valid = False
+
+ if not structure_valid:
+ logger.error("\n❌ Plugin has critical structure issues")
+ return False
+
+ logger.info("")
+ return True
+
+ def _validate_plugin_import(self, plugin_name: str) -> bool:
+ """Validate plugin import and methods."""
+ logger.info("Import Test:")
+ try:
+ plugin = get_plugin(plugin_name)
+ if not plugin:
+ logger.error(" ❌ Plugin failed to import")
+ return False
+
+ logger.info(" ✅ Plugin imports successfully")
+ self._test_plugin_methods(plugin)
+ logger.info("\n✅ Plugin validation completed successfully")
+ return True
+
+ except Exception as e:
+ logger.error(f" ❌ Import error: {e}")
+ return False
+
+ def _test_plugin_methods(self, plugin) -> None:
+ """Test plugin methods if available."""
+ if hasattr(plugin, "get_metadata"):
+ try:
+ plugin.get_metadata()
+ logger.info(" ✅ Plugin metadata accessible")
+ except Exception as e:
+ logger.warning(f" ⚠️ Plugin metadata error: {e}")
+
+ if hasattr(plugin, "validate_requirements"):
+ try:
+ plugin.validate_requirements()
+ logger.info(" ✅ Plugin requirements validation available")
+ except Exception as e:
+ logger.warning(f" ⚠️ Plugin requirements validation error: {e}")
+
+ def test_plugin(self, plugin_name: str) -> None:
+ """Run tests for a plugin."""
+ logger.info(f"Testing Plugin: {plugin_name}")
+ logger.info("=" * 50)
+
+ plugin_path = Path(__file__).parent / plugin_name
+ test_file = plugin_path / "test_plugin.py"
+
+ if not test_file.exists():
+ logger.error("❌ No test file found (test_plugin.py)")
+ return
+
+ logger.info("🧪 Running plugin tests...")
+
+ # Try to run the test file
+ import os
+ import subprocess
+
+ try:
+ # Set up environment
+ env = os.environ.copy()
+ env["PYTHONPATH"] = str(Path(__file__).parent.parent)
+
+ # Run the test
+ result = subprocess.run(
+ [sys.executable, str(test_file)],
+ cwd=str(Path(__file__).parent.parent),
+ env=env,
+ capture_output=True,
+ text=True,
+ timeout=60,
+ )
+
+ if result.returncode == 0:
+ logger.info("✅ Tests passed!")
+ logger.info("\nTest Output:")
+ logger.info(result.stdout)
+ else:
+ logger.error("❌ Tests failed!")
+ logger.info("\nTest Output:")
+ logger.info(result.stdout)
+ if result.stderr:
+ logger.error("\nError Output:")
+ logger.error(result.stderr)
+
+ except subprocess.TimeoutExpired:
+ logger.warning("⏰ Tests timed out after 60 seconds")
+ except Exception as e:
+ logger.error(f"❌ Error running tests: {e}")
+
+ def install_plugin_deps(self, plugin_name: str) -> None:
+ """Install dependencies for a plugin."""
+ logger.info(f"Installing Dependencies for Plugin: {plugin_name}")
+ logger.info("=" * 50)
+
+ requirements = get_plugin_requirements(plugin_name)
+
+ if not requirements:
+ logger.error("❌ No plugin requirements found")
+ return
+
+ dependencies = requirements.get("dependencies", [])
+
+ if not dependencies:
+ logger.info("ℹ️ No dependencies specified for this plugin")
+ return
+
+ logger.info("Dependencies to install:")
+ for dep in dependencies:
+ logger.info(f" - {dep}")
+
+ logger.info("\n🚀 Installing dependencies...")
+
+ import subprocess
+
+ try:
+ # Install using pip
+ cmd = [sys.executable, "-m", "pip", "install"] + dependencies
+ result = subprocess.run(cmd, capture_output=True, text=True)
+
+ if result.returncode == 0:
+ logger.info("✅ Dependencies installed successfully!")
+ else:
+ logger.error("❌ Failed to install dependencies")
+ logger.error("Error output:")
+ logger.error(result.stderr)
+
+ except Exception as e:
+ logger.error(f"❌ Error installing dependencies: {e}")
diff --git a/workers/pyproject.toml b/workers/pyproject.toml
new file mode 100644
index 000000000..cc03b8f18
--- /dev/null
+++ b/workers/pyproject.toml
@@ -0,0 +1,194 @@
+[project]
+name = "unstract-workers"
+version = "1.0.0"
+description = "Lightweight Celery workers for Unstract platform"
+authors = [
+ {name = "Unstract Team", email = "[email protected]"},
+]
+# readme = "README.md" # Temporarily disabled for Docker build
+license = {text = "AGPL-3.0"}
+requires-python = ">=3.12"
+dependencies = [
+ # Worker runtime
+ "celery>=5.5.3", # Latest stable version - AMQP support built into core
+ # HTTP clients and utilities (merged from shared package)
+ "requests>=2.31.0,<3.0.0", # HTTP client for internal API calls
+ "urllib3>=1.26.0", # HTTP utilities and retry strategies
+ "httpx>=0.27.0", # Async HTTP client
+ "python-dotenv>=1.0.0,<2.0.0", # Environment variable loading
+ # WebSocket support for log consumer
+ "python-socketio>=5.9.0", # Socket.IO client for emitting log events
+ # Monitoring and system utilities
+ "prometheus-client>=0.17.0,<1.0.0", # Metrics collection
+ "psutil>=5.9.0,<6.0.0", # System resource monitoring
+ # Essential Unstract packages - with Azure support for connectors
+ "unstract-sdk[azure]~=0.77.3", # Core SDK with Azure connector support
+ "unstract-connectors",
+ "unstract-core",
+ "unstract-flags",
+ "unstract-tool-registry",
+ "unstract-tool-sandbox",
+ "unstract-workflow-execution",
+ "unstract-filesystem",
+ # Caching
+ "redis>=4.5.0,<6.0.0", # Redis client for worker cache access
+ # Note: Using dataclasses instead of pydantic for lightweight typing
+ # Custom implementations replace tenancy (retry), pybreaker (circuit breaker)
+ # - python-dateutil: Standard datetime module sufficient
+]
+
+[dependency-groups]
+dev = [
+ "pytest>=7.4.0",
+ "pytest-asyncio>=0.21.0",
+ "pytest-mock>=3.11.0",
+ "pytest-cov>=4.1.0",
+ "black>=23.7.0",
+ "isort>=5.12.0",
+ "flake8>=6.0.0",
+ "mypy>=1.5.0"
+]
+
+test = [
+ "pytest>=7.4.0",
+ "pytest-asyncio>=0.21.0",
+ "pytest-mock>=3.11.0",
+ "pytest-cov>=4.1.0",
+ "factory-boy>=3.3.0",
+ "responses>=0.23.0"
+]
+
+deploy = [
+ # Minimal production dependencies - most are already in main deps
+ # Note: Workers don't need WSGI servers or profiling tools
+ # OpenTelemetry for tracing
+ # Keep versions empty and let uv decide version
+ # since we use no code instrumentation and don't use in code
+ "opentelemetry-distro",
+ "opentelemetry-exporter-otlp",
+]
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+
+[tool.hatch.metadata]
+allow-direct-references = true
+
+[tool.hatch.build.targets.wheel]
+packages = ["shared"]
+
+[tool.black]
+line-length = 88
+target-version = ['py312']
+include = '\.pyi?$'
+extend-exclude = '''
+/(
+ \.eggs
+ | \.git
+ | \.hg
+ | \.mypy_cache
+ | \.tox
+ | \.venv
+ | build
+ | dist
+)/
+'''
+
+[tool.isort]
+profile = "black"
+multi_line_output = 3
+line_length = 88
+known_first_party = [
+ "shared",
+ "api_deployment",
+ "general",
+ "file_processing",
+ "callback"
+]
+
+[tool.mypy]
+python_version = "3.12"
+warn_return_any = true
+warn_unused_configs = true
+disallow_untyped_defs = true
+disallow_incomplete_defs = true
+check_untyped_defs = true
+disallow_untyped_decorators = true
+no_implicit_optional = true
+warn_redundant_casts = true
+warn_unused_ignores = true
+warn_no_return = true
+warn_unreachable = true
+strict_equality = true
+
+[[tool.mypy.overrides]]
+module = [
+ "celery.*",
+ "kombu.*",
+ "prometheus_client.*",
+ "psutil.*"
+]
+ignore_missing_imports = true
+
+[tool.pytest.ini_options]
+testpaths = ["tests"]
+python_files = ["test_*.py", "*_test.py"]
+python_classes = ["Test*"]
+python_functions = ["test_*"]
+addopts = [
+ "--strict-markers",
+ "--strict-config",
+ "--verbose",
+ "--cov=shared",
+ "--cov=api_deployment",
+ "--cov=general",
+ "--cov=file_processing",
+ "--cov=callback",
+ "--cov-report=term-missing",
+ "--cov-report=html",
+ "--cov-report=xml"
+]
+markers = [
+ "unit: Unit tests",
+ "integration: Integration tests",
+ "slow: Slow tests"
+]
+
+[tool.coverage.run]
+source = [
+ "shared",
+ "api_deployment",
+ "general",
+ "file_processing",
+ "callback"
+]
+omit = [
+ "*/tests/*",
+ "*/test_*.py",
+ "*/*_test.py"
+]
+
+[tool.coverage.report]
+exclude_lines = [
+ "pragma: no cover",
+ "def __repr__",
+ "if self.debug:",
+ "if settings.DEBUG",
+ "raise AssertionError",
+ "raise NotImplementedError",
+ "if 0:",
+ "if __name__ == .__main__.:",
+ "class .*\\bProtocol\\):",
+ "@(abc\\.)?abstractmethod"
+]
+
+[tool.uv.sources]
+unstract-filesystem = { path = "../unstract/filesystem", editable = true }
+unstract-workflow-execution = { path = "../unstract/workflow-execution", editable = true }
+unstract-tool-sandbox = { path = "../unstract/tool-sandbox", editable = true }
+unstract-tool-registry = { path = "../unstract/tool-registry", editable = true }
+unstract-flags = { path = "../unstract/flags", editable = true }
+unstract-connectors = { path = "../unstract/connectors", editable = true }
+unstract-core = { path = "../unstract/core", editable = true }
diff --git a/workers/run-worker-docker.sh b/workers/run-worker-docker.sh
new file mode 100755
index 000000000..be8307426
--- /dev/null
+++ b/workers/run-worker-docker.sh
@@ -0,0 +1,458 @@
+#!/bin/bash
+# =============================================================================
+# Unstract Workers Runner Script - Docker Version
+# =============================================================================
+# This script is optimized for running workers inside Docker containers
+# where all dependencies are pre-installed during image build.
+#
+# For local development, use run-worker.sh instead.
+
+set -e
+
+# Colors for output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+NC='\033[0m' # No Color
+
+# Script directory - in Docker, everything runs from /app
+WORKERS_DIR="/app"
+
+# Default environment file
+ENV_FILE="/app/.env"
+
+# Available workers
+declare -A WORKERS=(
+ ["api"]="api_deployment"
+ ["api-deployment"]="api_deployment"
+ ["general"]="general"
+ ["file"]="file_processing"
+ ["file-processing"]="file_processing"
+ ["callback"]="callback"
+ ["notification"]="notification"
+ ["log"]="log_consumer"
+ ["log-consumer"]="log_consumer"
+ ["scheduler"]="scheduler"
+ ["schedule"]="scheduler"
+ ["all"]="all"
+)
+
+# Worker queue mappings
+declare -A WORKER_QUEUES=(
+ ["api_deployment"]="celery_api_deployments"
+ ["general"]="celery"
+ ["file_processing"]="file_processing,api_file_processing"
+ ["callback"]="file_processing_callback,api_file_processing_callback"
+ ["notification"]="notifications,notifications_webhook,notifications_email,notifications_sms,notifications_priority"
+ ["log_consumer"]="celery_log_task_queue"
+ ["scheduler"]="scheduler"
+)
+
+# Worker health ports
+declare -A WORKER_HEALTH_PORTS=(
+ ["api_deployment"]="8080"
+ ["general"]="8081"
+ ["file_processing"]="8082"
+ ["callback"]="8083"
+ ["log_consumer"]="8084"
+ ["notification"]="8085"
+ ["scheduler"]="8087"
+)
+
+# Function to print colored output
+print_status() {
+ local color=$1
+ local message=$2
+ echo -e "${color}${message}${NC}"
+}
+
+# Function to load environment file
+load_env() {
+ local env_file=$1
+
+ if [[ -f "$env_file" ]]; then
+ print_status $GREEN "Loading environment from: $env_file"
+ set -a # automatically export all variables
+ source "$env_file"
+ set +a
+ else
+ print_status $YELLOW "Warning: Environment file not found: $env_file"
+ print_status $YELLOW "Make sure required environment variables are set"
+ fi
+}
+
+
+# Function to detect worker type from command-line arguments
+detect_worker_type_from_args() {
+ local -n args_ref=$1
+
+ # Look for --queues argument to infer worker type
+ local queues=""
+ local i=0
+ while [[ $i -lt ${#args_ref[@]} ]]; do
+ local arg="${args_ref[$i]}"
+ case "$arg" in
+ --queues=*)
+ queues="${arg#--queues=}"
+ break
+ ;;
+ --queues)
+ ((i++))
+ if [[ $i -lt ${#args_ref[@]} ]]; then
+ queues="${args_ref[$i]}"
+ break
+ fi
+ ;;
+ esac
+ ((i++))
+ done
+
+ # Map queue patterns to worker types
+ case "$queues" in
+ *"file_processing"*) echo "file_processing" ;;
+ *"celery_api_deployments"*) echo "api_deployment" ;;
+ *"file_processing_callback"*) echo "callback" ;;
+ *"notifications"*) echo "notification" ;;
+ *"celery_log_task_queue"*) echo "log_consumer" ;;
+ *"scheduler"*) echo "scheduler" ;;
+ *"celery"*) echo "general" ;;
+ *) echo "general" ;; # fallback
+ esac
+}
+
+# Function to run a single worker
+run_worker() {
+ local worker_type=$1
+
+ # Normalize worker type - convert hyphens to underscores for consistency
+ case "$worker_type" in
+ "api-deployment"|"api")
+ worker_type="api_deployment"
+ ;;
+ "file-processing"|"file")
+ worker_type="file_processing"
+ ;;
+ "log-consumer"|"log")
+ worker_type="log_consumer"
+ ;;
+ # general, callback, and notification stay the same
+ esac
+
+ # Set worker-specific environment variables
+ export WORKER_TYPE="$worker_type"
+ export WORKER_NAME="${worker_type}-worker"
+
+ # Determine instance name
+ local worker_instance_name="${worker_type}-worker"
+ if [[ -n "$HOSTNAME" ]]; then
+ # In Docker/K8s, use the container hostname
+ worker_instance_name="${worker_type}-${HOSTNAME}"
+ elif [[ -n "$WORKER_INSTANCE_ID" ]]; then
+ worker_instance_name="${worker_type}-worker-${WORKER_INSTANCE_ID}"
+ else
+ # Default naming for production
+ worker_instance_name="${worker_type}-worker-prod-01"
+ fi
+
+ # Get queues for this worker - allow environment override
+ local queues="${WORKER_QUEUES[$worker_type]}"
+ case "$worker_type" in
+ "api_deployment")
+ queues="${CELERY_QUEUES_API_DEPLOYMENT:-$queues}"
+ ;;
+ "general")
+ queues="${CELERY_QUEUES_GENERAL:-$queues}"
+ ;;
+ "file_processing")
+ queues="${CELERY_QUEUES_FILE_PROCESSING:-$queues}"
+ ;;
+ "callback")
+ queues="${CELERY_QUEUES_CALLBACK:-$queues}"
+ ;;
+ "notification")
+ queues="${CELERY_QUEUES_NOTIFICATION:-$queues}"
+ ;;
+ "log_consumer")
+ queues="${CELERY_QUEUES_LOG_CONSUMER:-$queues}"
+ ;;
+ "scheduler")
+ queues="${CELERY_QUEUES_SCHEDULER:-$queues}"
+ ;;
+ esac
+
+ # Get health port
+ local health_port="${WORKER_HEALTH_PORTS[$worker_type]}"
+
+ # Set health port environment variable
+ case "$worker_type" in
+ "api_deployment")
+ export API_DEPLOYMENT_HEALTH_PORT="${health_port}"
+ export API_DEPLOYMENT_METRICS_PORT="${health_port}"
+ ;;
+ "general")
+ export GENERAL_HEALTH_PORT="${health_port}"
+ export GENERAL_METRICS_PORT="${health_port}"
+ ;;
+ "file_processing")
+ export FILE_PROCESSING_HEALTH_PORT="${health_port}"
+ export FILE_PROCESSING_METRICS_PORT="${health_port}"
+ ;;
+ "callback")
+ export CALLBACK_HEALTH_PORT="${health_port}"
+ export CALLBACK_METRICS_PORT="${health_port}"
+ ;;
+ "notification")
+ export NOTIFICATION_HEALTH_PORT="${health_port}"
+ export NOTIFICATION_METRICS_PORT="${health_port}"
+ ;;
+ "log_consumer")
+ export LOG_CONSUMER_HEALTH_PORT="${health_port}"
+ export LOG_CONSUMER_METRICS_PORT="${health_port}"
+ ;;
+ "scheduler")
+ export SCHEDULER_HEALTH_PORT="${health_port}"
+ export SCHEDULER_METRICS_PORT="${health_port}"
+ ;;
+ esac
+
+ # Determine concurrency settings
+ local concurrency=""
+ case "$worker_type" in
+ "api_deployment")
+ concurrency="${WORKER_API_DEPLOYMENT_CONCURRENCY:-2}"
+ ;;
+ "general")
+ concurrency="${WORKER_GENERAL_CONCURRENCY:-4}"
+ ;;
+ "file_processing")
+ concurrency="${WORKER_FILE_PROCESSING_CONCURRENCY:-4}"
+ ;;
+ "callback")
+ concurrency="${WORKER_CALLBACK_CONCURRENCY:-4}"
+ ;;
+ "notification")
+ concurrency="${WORKER_NOTIFICATION_CONCURRENCY:-2}"
+ ;;
+ "log_consumer")
+ concurrency="${WORKER_LOG_CONSUMER_CONCURRENCY:-2}"
+ ;;
+ "scheduler")
+ concurrency="${WORKER_SCHEDULER_CONCURRENCY:-2}"
+ ;;
+ esac
+
+ print_status $GREEN "Starting $worker_type worker..."
+ print_status $BLUE "Working Directory: /app"
+ print_status $BLUE "Worker Name: $worker_instance_name"
+ print_status $BLUE "Queues: $queues"
+ print_status $BLUE "Health Port: $health_port"
+ print_status $BLUE "Concurrency: $concurrency"
+
+ # Build Celery command with configurable options
+ local app_module="${CELERY_APP_MODULE:-worker}"
+
+ # Initial command without specific args - they'll be resolved with priority system
+ local celery_cmd="/app/.venv/bin/celery -A $app_module worker"
+ local celery_args=""
+
+ # =============================================================================
+ # Hierarchical Configuration Resolution (4-tier priority system)
+ # =============================================================================
+ # Resolve worker-specific overrides using the hierarchical configuration pattern:
+ # 1. Command-line arguments (highest priority)
+ # 2. {WORKER_TYPE}_{SETTING_NAME} (high priority)
+ # 3. CELERY_{SETTING_NAME} (medium priority)
+ # 4. Default value (lowest priority)
+
+ # Traditional environment-based command building (no CLI parsing needed)
+
+ # Convert worker_type to uppercase for environment variable resolution
+ local worker_type_upper=$(echo "$worker_type" | tr '[:lower:]' '[:upper:]' | tr '-' '_')
+
+ # Helper function for hierarchical configuration resolution (environment-based)
+ resolve_config() {
+ local setting_name=$1
+ local default_value=$2
+
+ # Check worker-specific setting (highest priority)
+ local worker_specific_var="${worker_type_upper}_${setting_name}"
+ local worker_value=$(eval echo "\${${worker_specific_var}:-}")
+ if [[ -n "$worker_value" ]]; then
+ echo "$worker_value"
+ return
+ fi
+
+ # Check global Celery setting (medium priority)
+ local global_var="CELERY_${setting_name}"
+ local global_value=$(eval echo "\${${global_var}:-}")
+ if [[ -n "$global_value" ]]; then
+ echo "$global_value"
+ return
+ fi
+
+ # Use default value (lowest priority)
+ echo "$default_value"
+ }
+
+ # Resolve configuration using environment variables only
+ local resolved_queues="$queues"
+ celery_args="$celery_args --queues=$resolved_queues"
+
+ # Resolve log level
+ local resolved_loglevel="${CELERY_LOG_LEVEL:-${LOG_LEVEL:-INFO}}"
+ celery_args="$celery_args --loglevel=$resolved_loglevel"
+
+ # Resolve hostname
+ local resolved_hostname="${CELERY_HOSTNAME:-${worker_instance_name}@%h}"
+ celery_args="$celery_args --hostname=$resolved_hostname"
+
+ # Apply hierarchical configuration for pool type
+ local pool_type=$(resolve_config "POOL_TYPE" "prefork")
+ # Override with legacy CELERY_POOL for backward compatibility
+ pool_type="${CELERY_POOL:-$pool_type}"
+ celery_args="$celery_args --pool=$pool_type"
+
+ # Configure concurrency with hierarchical resolution
+ local resolved_concurrency=$(resolve_config "CONCURRENCY" "$concurrency")
+ # Apply legacy CELERY_CONCURRENCY
+ resolved_concurrency="${CELERY_CONCURRENCY:-$resolved_concurrency}"
+ celery_args="$celery_args --concurrency=$resolved_concurrency"
+
+ # Apply hierarchical configuration for optional parameters
+
+ # Prefetch multiplier
+ local prefetch_multiplier=$(resolve_config "PREFETCH_MULTIPLIER" "")
+ prefetch_multiplier="${CELERY_PREFETCH_MULTIPLIER:-$prefetch_multiplier}"
+ if [[ -n "$prefetch_multiplier" ]]; then
+ celery_args="$celery_args --prefetch-multiplier=$prefetch_multiplier"
+ fi
+
+ # Max tasks per child
+ local max_tasks_per_child=$(resolve_config "MAX_TASKS_PER_CHILD" "")
+ max_tasks_per_child="${CELERY_MAX_TASKS_PER_CHILD:-$max_tasks_per_child}"
+ if [[ -n "$max_tasks_per_child" ]]; then
+ celery_args="$celery_args --max-tasks-per-child=$max_tasks_per_child"
+ fi
+
+ # Task time limit
+ local time_limit=$(resolve_config "TASK_TIME_LIMIT" "")
+ time_limit="${CELERY_TIME_LIMIT:-$time_limit}"
+ if [[ -n "$time_limit" ]]; then
+ celery_args="$celery_args --time-limit=$time_limit"
+ fi
+
+ # Task soft time limit
+ local soft_time_limit=$(resolve_config "TASK_SOFT_TIME_LIMIT" "")
+ soft_time_limit="${CELERY_SOFT_TIME_LIMIT:-$soft_time_limit}"
+ if [[ -n "$soft_time_limit" ]]; then
+ celery_args="$celery_args --soft-time-limit=$soft_time_limit"
+ fi
+
+ # Add gossip, mingle, and heartbeat control flags based on environment variables
+ # Default: gossip=true, mingle=true, heartbeat=true (Celery defaults)
+
+ if [[ "${CELERY_WORKER_GOSSIP:-true}" == "false" ]]; then
+ celery_args="$celery_args --without-gossip"
+ fi
+
+ if [[ "${CELERY_WORKER_MINGLE:-true}" == "false" ]]; then
+ celery_args="$celery_args --without-mingle"
+ fi
+
+ if [[ "${CELERY_WORKER_HEARTBEAT:-true}" == "false" ]]; then
+ celery_args="$celery_args --without-heartbeat"
+ fi
+
+ # Add any additional custom Celery arguments
+ if [[ -n "$CELERY_EXTRA_ARGS" ]]; then
+ celery_args="$celery_args $CELERY_EXTRA_ARGS"
+ fi
+
+ # Execute the command
+ exec $celery_cmd $celery_args
+}
+
+# Main execution
+# Load environment first for any needed variables
+load_env "$ENV_FILE"
+
+# Add PYTHONPATH for imports - include both /app and /unstract for packages
+export PYTHONPATH="/app:/unstract/core/src:/unstract/connectors/src:/unstract/filesystem/src:/unstract/flags/src:/unstract/tool-registry/src:/unstract/tool-sandbox/src:/unstract/workflow-execution/src:${PYTHONPATH:-}"
+
+# Two-path logic: Full Celery command vs Traditional worker type
+if [[ "$1" == *"celery"* ]] || [[ "$1" == *".venv"* ]]; then
+ # =============================================================================
+ # PATH 1: Full Celery Command Detected - Use Directly
+ # =============================================================================
+ print_status $BLUE "🚀 Full Celery command detected - executing directly"
+
+ # Extract worker type for environment setup
+ ALL_ARGS=("$@")
+ WORKER_TYPE=$(detect_worker_type_from_args ALL_ARGS)
+
+ print_status $BLUE "Detected worker type: $WORKER_TYPE"
+ print_status $BLUE "Command: $*"
+
+ # Set essential environment variables for worker identification
+ export WORKER_TYPE="$WORKER_TYPE"
+ export WORKER_NAME="${WORKER_TYPE}-worker"
+
+ # Set worker instance name for identification
+ if [[ -n "$HOSTNAME" ]]; then
+ worker_instance_name="${WORKER_TYPE}-${HOSTNAME}"
+ elif [[ -n "$WORKER_INSTANCE_ID" ]]; then
+ worker_instance_name="${WORKER_TYPE}-worker-${WORKER_INSTANCE_ID}"
+ else
+ worker_instance_name="${WORKER_TYPE}-worker-docker"
+ fi
+ export WORKER_NAME="$worker_instance_name"
+
+ # Set health port environment variable based on worker type
+ case "$WORKER_TYPE" in
+ "api_deployment")
+ export API_DEPLOYMENT_HEALTH_PORT="8080"
+ export API_DEPLOYMENT_METRICS_PORT="8080"
+ ;;
+ "general")
+ export GENERAL_HEALTH_PORT="8081"
+ export GENERAL_METRICS_PORT="8081"
+ ;;
+ "file_processing")
+ export FILE_PROCESSING_HEALTH_PORT="8082"
+ export FILE_PROCESSING_METRICS_PORT="8082"
+ ;;
+ "callback")
+ export CALLBACK_HEALTH_PORT="8083"
+ export CALLBACK_METRICS_PORT="8083"
+ ;;
+ "notification")
+ export NOTIFICATION_HEALTH_PORT="8085"
+ export NOTIFICATION_METRICS_PORT="8085"
+ ;;
+ "log_consumer")
+ export LOG_CONSUMER_HEALTH_PORT="8084"
+ export LOG_CONSUMER_METRICS_PORT="8084"
+ ;;
+ "scheduler")
+ export SCHEDULER_HEALTH_PORT="8087"
+ export SCHEDULER_METRICS_PORT="8087"
+ ;;
+ esac
+
+ print_status $GREEN "✅ Executing Celery command with highest priority..."
+
+ # Execute the full command directly - Celery will handle all arguments
+ exec "$@"
+
+else
+ # =============================================================================
+ # PATH 2: Traditional Worker Type - Build from Environment
+ # =============================================================================
+ WORKER_TYPE="${1:-general}"
+ print_status $BLUE "🔧 Traditional worker type detected: $WORKER_TYPE"
+ print_status $BLUE "Building command from environment variables..."
+
+ # Use existing run_worker function for environment-based building
+ run_worker "$WORKER_TYPE"
+fi
diff --git a/workers/run-worker.sh b/workers/run-worker.sh
new file mode 100755
index 000000000..ed3f44527
--- /dev/null
+++ b/workers/run-worker.sh
@@ -0,0 +1,514 @@
+#!/bin/bash
+# =============================================================================
+# Unstract Workers Runner Script
+# =============================================================================
+# This script provides a convenient way to run individual or multiple workers
+# with proper environment configuration and health monitoring.
+
+set -e
+
+# Colors for output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+NC='\033[0m' # No Color
+
+# Script directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+WORKERS_DIR="$SCRIPT_DIR"
+
+# Default environment file
+ENV_FILE="$WORKERS_DIR/.env"
+
+# Available workers
+declare -A WORKERS=(
+ ["api"]="api-deployment"
+ ["api-deployment"]="api-deployment"
+ ["general"]="general"
+ ["file"]="file_processing"
+ ["file-processing"]="file_processing"
+ ["callback"]="callback"
+ ["log"]="log_consumer"
+ ["log-consumer"]="log_consumer"
+ ["logs"]="log_consumer"
+ ["notification"]="notification"
+ ["notifications"]="notification"
+ ["notify"]="notification"
+ ["scheduler"]="scheduler"
+ ["schedule"]="scheduler"
+ ["all"]="all"
+)
+
+# Worker queue mappings
+declare -A WORKER_QUEUES=(
+ ["api-deployment"]="celery_api_deployments"
+ ["general"]="celery"
+ ["file_processing"]="file_processing,api_file_processing"
+ ["callback"]="file_processing_callback,api_file_processing_callback"
+ ["log_consumer"]="celery_log_task_queue"
+ ["notification"]="notifications,notifications_webhook,notifications_email,notifications_sms,notifications_priority"
+ ["scheduler"]="scheduler"
+)
+
+# Worker health ports
+declare -A WORKER_HEALTH_PORTS=(
+ ["api-deployment"]="8080"
+ ["general"]="8081"
+ ["file_processing"]="8082"
+ ["callback"]="8083"
+ ["log_consumer"]="8084"
+ ["notification"]="8085"
+ ["scheduler"]="8087"
+)
+
+# Function to display usage
+usage() {
+ cat << EOF
+Usage: $0 [OPTIONS] WORKER_TYPE
+
+Run Unstract Celery workers with proper environment configuration.
+
+WORKER_TYPE:
+ api, api-deployment Run API deployment worker
+ general Run general worker (webhooks, background tasks)
+ file, file-processing Run file processing worker
+ callback Run callback worker
+ log, log-consumer Run log consumer worker
+ notification, notify Run notification worker
+ scheduler, schedule Run scheduler worker (scheduled pipeline tasks)
+ all Run all workers (in separate processes)
+
+OPTIONS:
+ -e, --env-file FILE Use specific environment file (default: .env)
+ -d, --detach Run worker in background (daemon mode)
+ -l, --log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR)
+ -c, --concurrency N Set worker concurrency (default: auto)
+ -q, --queues QUEUES Override default queues (comma-separated)
+ -p, --health-port N Override health check port
+ -n, --hostname NAME Set custom worker hostname/name
+ -k, --kill Kill running workers and exit
+ -s, --status Show status of running workers
+ -h, --help Show this help message
+
+EXAMPLES:
+ # Run API deployment worker
+ $0 api
+
+ # Run general worker with debug logging
+ $0 -l DEBUG general
+
+ # Run file processing worker in background
+ $0 -d file
+
+ # Run with custom environment file
+ $0 -e production.env all
+
+ # Run with custom concurrency
+ $0 -c 4 general
+
+ # Run with custom worker name (useful for scaling)
+ $0 -n api-01 api
+ $0 -n api-02 api
+
+ # Check worker status
+ $0 -s
+
+ # Kill all running workers
+ $0 -k
+
+ENVIRONMENT:
+ The script will load environment variables from .env file if present.
+ Required variables:
+ - INTERNAL_SERVICE_API_KEY
+ - INTERNAL_API_BASE_URL
+ - CELERY_BROKER_BASE_URL
+ - DB_HOST, DB_USER, DB_PASSWORD, DB_NAME (for PostgreSQL result backend)
+
+ Plugin availability is detected dynamically via plugin registry.
+ See sample.env for full configuration options.
+
+HEALTH CHECKS:
+ Each worker exposes a health check endpoint:
+ - API Deployment: http://localhost:8080/health
+ - General: http://localhost:8081/health
+ - File Processing: http://localhost:8082/health
+ - Callback: http://localhost:8083/health
+ - Log Consumer: http://localhost:8084/health
+ - Notification: http://localhost:8085/health
+ - Scheduler: http://localhost:8087/health
+
+EOF
+}
+
+# Function to print colored output
+print_status() {
+ local color=$1
+ local message=$2
+ echo -e "${color}${message}${NC}"
+}
+
+# Function to load environment file
+load_env() {
+ local env_file=$1
+
+ if [[ -f "$env_file" ]]; then
+ print_status $GREEN "Loading environment from: $env_file"
+ set -a # automatically export all variables
+ source "$env_file"
+ set +a
+ else
+ print_status $YELLOW "Warning: Environment file not found: $env_file"
+ print_status $YELLOW "Make sure required environment variables are set"
+ fi
+}
+
+# Function to validate environment
+validate_env() {
+ local required_vars=(
+ "INTERNAL_SERVICE_API_KEY"
+ "INTERNAL_API_BASE_URL"
+ "CELERY_BROKER_BASE_URL"
+ "DB_HOST"
+ "DB_USER"
+ "DB_PASSWORD"
+ "DB_NAME"
+ )
+
+ local missing_vars=()
+
+ for var in "${required_vars[@]}"; do
+ if [[ -z "${!var}" ]]; then
+ missing_vars+=("$var")
+ fi
+ done
+
+ if [[ ${#missing_vars[@]} -gt 0 ]]; then
+ print_status $RED "Error: Missing required environment variables:"
+ for var in "${missing_vars[@]}"; do
+ print_status $RED " - $var"
+ done
+ print_status $YELLOW "Please check your .env file or set these variables manually"
+ exit 1
+ fi
+}
+
+# Function to get worker PIDs
+get_worker_pids() {
+ local worker_type=$1
+ pgrep -f "uv run celery.*worker.*$worker_type" || true
+}
+
+# Function to kill workers
+kill_workers() {
+ print_status $YELLOW "Killing all running workers..."
+
+ for worker in "${!WORKERS[@]}"; do
+ if [[ "$worker" == "all" ]]; then
+ continue
+ fi
+
+ local worker_dir="${WORKERS[${worker}]}"
+ local pids=$(pgrep -f "uv run celery.*worker" || true)
+
+ if [[ -n "$pids" ]]; then
+ print_status $YELLOW "Killing worker processes: $pids"
+ echo "$pids" | xargs kill -TERM 2>/dev/null || true
+ sleep 2
+ # Force kill if still running
+ echo "$pids" | xargs kill -KILL 2>/dev/null || true
+ fi
+ done
+
+ print_status $GREEN "All workers stopped"
+}
+
+# Function to show worker status
+show_status() {
+ print_status $BLUE "Worker Status:"
+ echo "=============="
+
+ for worker in api-deployment general file_processing callback log_consumer notification scheduler; do
+ local worker_dir="$WORKERS_DIR/$worker"
+ local health_port="${WORKER_HEALTH_PORTS[$worker]}"
+ local pids=$(get_worker_pids "$worker")
+
+ echo -n " $worker: "
+
+ if [[ -n "$pids" ]]; then
+ print_status $GREEN "RUNNING (PID: $pids)"
+
+ # Check health endpoint if possible
+ if command -v curl >/dev/null 2>&1; then
+ local health_url="http://localhost:$health_port/health"
+ if curl -s --max-time 2 "$health_url" >/dev/null 2>&1; then
+ echo " Health: http://localhost:$health_port/health - OK"
+ else
+ echo " Health: http://localhost:$health_port/health - UNREACHABLE"
+ fi
+ fi
+ else
+ print_status $RED "STOPPED"
+ fi
+ done
+}
+
+# Function to run a single worker
+run_worker() {
+ local worker_type=$1
+ local detach=$2
+ local log_level=$3
+ local concurrency=$4
+ local custom_queues=$5
+ local health_port=$6
+ local custom_hostname=$7
+
+ local worker_dir="$WORKERS_DIR/$worker_type"
+
+ if [[ ! -d "$worker_dir" ]]; then
+ print_status $RED "Error: Worker directory not found: $worker_dir"
+ exit 1
+ fi
+
+ # Set worker-specific environment variables
+ export WORKER_NAME="${worker_type}-worker"
+ export WORKER_TYPE="$(echo "$worker_type" | tr '-' '_')" # Convert hyphens to underscores for Python module names
+ export LOG_LEVEL="${log_level:-INFO}"
+
+ # Set health port if specified
+ if [[ -n "$health_port" ]]; then
+ case "$worker_type" in
+ "api-deployment")
+ export API_DEPLOYMENT_HEALTH_PORT="$health_port"
+ ;;
+ "general")
+ export GENERAL_HEALTH_PORT="$health_port"
+ ;;
+ "file_processing")
+ export FILE_PROCESSING_HEALTH_PORT="$health_port"
+ ;;
+ "callback")
+ export CALLBACK_HEALTH_PORT="$health_port"
+ ;;
+ "log_consumer")
+ export LOG_CONSUMER_HEALTH_PORT="$health_port"
+ ;;
+ "notification")
+ export NOTIFICATION_HEALTH_PORT="$health_port"
+ ;;
+ "scheduler")
+ export SCHEDULER_HEALTH_PORT="$health_port"
+ ;;
+ esac
+ fi
+
+ # Determine queues
+ local queues="${custom_queues:-${WORKER_QUEUES[$worker_type]}}"
+
+ # Build meaningful worker name
+ local worker_instance_name="${worker_type}-worker"
+ if [[ -n "$custom_hostname" ]]; then
+ worker_instance_name="$custom_hostname"
+ elif [[ -n "$WORKER_INSTANCE_ID" ]]; then
+ worker_instance_name="${worker_type}-worker-${WORKER_INSTANCE_ID}"
+ fi
+
+ # Build celery command
+ local cmd_args=(
+ "uv" "run" "celery" "-A" "worker" "worker"
+ "--loglevel=${log_level:-info}"
+ "--queues=$queues"
+ "--hostname=${worker_instance_name}@%h"
+ )
+
+ # Add concurrency if specified
+ if [[ -n "$concurrency" ]]; then
+ cmd_args+=("--concurrency=$concurrency")
+ fi
+
+ # Add concurrency for production-like setup
+ if [[ -z "$concurrency" ]]; then
+ case "$worker_type" in
+ "api-deployment")
+ cmd_args+=("--concurrency=2")
+ ;;
+ "general")
+ cmd_args+=("--concurrency=4")
+ ;;
+ "file_processing")
+ cmd_args+=("--concurrency=4")
+ ;;
+ "callback")
+ cmd_args+=("--concurrency=4")
+ ;;
+ "log_consumer")
+ cmd_args+=("--concurrency=2")
+ ;;
+ "notification")
+ cmd_args+=("--concurrency=2")
+ ;;
+ "scheduler")
+ cmd_args+=("--concurrency=2")
+ ;;
+ esac
+ fi
+
+ print_status $GREEN "Starting $worker_type worker..."
+ print_status $BLUE "Directory: $worker_dir"
+ print_status $BLUE "Worker Name: $worker_instance_name"
+ print_status $BLUE "Queues: $queues"
+ print_status $BLUE "Health Port: ${WORKER_HEALTH_PORTS[$worker_type]}"
+ print_status $BLUE "Command: ${cmd_args[*]}"
+
+ cd "$worker_dir"
+
+ if [[ "$detach" == "true" ]]; then
+ # Run in background
+ nohup "${cmd_args[@]}" > "$worker_type.log" 2>&1 &
+ local pid=$!
+ print_status $GREEN "$worker_type worker started in background (PID: $pid)"
+ print_status $BLUE "Logs: $worker_dir/$worker_type.log"
+ else
+ # Run in foreground
+ exec "${cmd_args[@]}"
+ fi
+}
+
+# Function to run all workers
+run_all_workers() {
+ local detach=$1
+ local log_level=$2
+ local concurrency=$3
+
+ print_status $GREEN "Starting all workers..."
+
+ # Always run all workers in background when using "all"
+ for worker in api-deployment general file_processing callback log_consumer notification scheduler; do
+ print_status $BLUE "Starting $worker worker in background..."
+
+ # Run each worker in background
+ (
+ run_worker "$worker" "true" "$log_level" "$concurrency" "" ""
+ ) &
+
+ sleep 2 # Give each worker time to start
+ done
+
+ if [[ "$detach" != "true" ]]; then
+ print_status $GREEN "All workers started. Press Ctrl+C to stop all workers."
+ print_status $BLUE "Worker status:"
+ sleep 3
+ show_status
+
+ # Wait for any background job to finish (they won't unless killed)
+ wait
+ else
+ print_status $GREEN "All workers started in background"
+ show_status
+ fi
+}
+
+# Parse command line arguments
+DETACH=false
+LOG_LEVEL=""
+CONCURRENCY=""
+CUSTOM_QUEUES=""
+HEALTH_PORT=""
+CUSTOM_HOSTNAME=""
+KILL_WORKERS=false
+SHOW_STATUS=false
+
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ -e|--env-file)
+ ENV_FILE="$2"
+ shift 2
+ ;;
+ -d|--detach)
+ DETACH=true
+ shift
+ ;;
+ -l|--log-level)
+ LOG_LEVEL="$2"
+ shift 2
+ ;;
+ -c|--concurrency)
+ CONCURRENCY="$2"
+ shift 2
+ ;;
+ -q|--queues)
+ CUSTOM_QUEUES="$2"
+ shift 2
+ ;;
+ -p|--health-port)
+ HEALTH_PORT="$2"
+ shift 2
+ ;;
+ -n|--hostname)
+ CUSTOM_HOSTNAME="$2"
+ shift 2
+ ;;
+ -k|--kill)
+ KILL_WORKERS=true
+ shift
+ ;;
+ -s|--status)
+ SHOW_STATUS=true
+ shift
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -*)
+ print_status $RED "Unknown option: $1"
+ usage
+ exit 1
+ ;;
+ *)
+ WORKER_TYPE="$1"
+ shift
+ ;;
+ esac
+done
+
+# Handle special actions
+if [[ "$KILL_WORKERS" == "true" ]]; then
+ kill_workers
+ exit 0
+fi
+
+if [[ "$SHOW_STATUS" == "true" ]]; then
+ show_status
+ exit 0
+fi
+
+# Validate worker type
+if [[ -z "$WORKER_TYPE" ]]; then
+ print_status $RED "Error: Worker type is required"
+ usage
+ exit 1
+fi
+
+if [[ -z "${WORKERS[$WORKER_TYPE]}" ]]; then
+ print_status $RED "Error: Unknown worker type: $WORKER_TYPE"
+ print_status $BLUE "Available workers: ${!WORKERS[*]}"
+ exit 1
+fi
+
+# Load environment
+load_env "$ENV_FILE"
+
+# Validate environment
+validate_env
+
+# Add PYTHONPATH for imports
+export PYTHONPATH="$WORKERS_DIR:${PYTHONPATH:-}"
+
+# Run the requested worker(s)
+if [[ "$WORKER_TYPE" == "all" ]]; then
+ run_all_workers "$DETACH" "$LOG_LEVEL" "$CONCURRENCY"
+else
+ WORKER_DIR_NAME="${WORKERS[$WORKER_TYPE]}"
+ run_worker "$WORKER_DIR_NAME" "$DETACH" "$LOG_LEVEL" "$CONCURRENCY" "$CUSTOM_QUEUES" "$HEALTH_PORT" "$CUSTOM_HOSTNAME"
+fi
diff --git a/workers/sample.env b/workers/sample.env
new file mode 100644
index 000000000..d5a5e8d76
--- /dev/null
+++ b/workers/sample.env
@@ -0,0 +1,334 @@
+# =============================================================================
+# Unstract Workers Environment Configuration
+# =============================================================================
+# Copy this file to .env and update the values for your environment
+
+# =============================================================================
+# Core Configuration (REQUIRED)
+# =============================================================================
+
+# Django Backend URL - REQUIRED
+# Docker (default): http://unstract-backend:8000
+# Local development: http://localhost:8000
+DJANGO_APP_BACKEND_URL=http://unstract-backend:8000
+
+# Internal API Base URL - REQUIRED
+# This is the full URL with /internal suffix for worker→backend communication
+# Docker: http://unstract-backend:8000/internal
+# Local: http://localhost:8000/internal
+INTERNAL_API_BASE_URL=http://unstract-backend:8000/internal
+
+# Internal API Configuration
+INTERNAL_API_PREFIX=/internal
+INTERNAL_API_VERSION=v1
+
+# Internal Service API Key - REQUIRED
+INTERNAL_SERVICE_API_KEY=dev-internal-key-123
+
+# Internal API Connection Settings
+INTERNAL_API_TIMEOUT=120
+INTERNAL_API_RETRY_ATTEMPTS=3
+INTERNAL_API_RETRY_BACKOFF_FACTOR=1.0
+
+# Internal API Endpoint Prefixes
+INTERNAL_API_HEALTH_PREFIX=v1/health/
+INTERNAL_API_TOOL_PREFIX=v1/tool-execution/
+INTERNAL_API_EXECUTION_PREFIX=v1/execution/
+INTERNAL_API_WEBHOOK_PREFIX=v1/webhook/
+INTERNAL_API_FILE_HISTORY_PREFIX=v1/file-history/
+INTERNAL_API_WORKFLOW_PREFIX=v1/workflow-execution/
+INTERNAL_API_ORGANIZATION_PREFIX=v1/organization/
+
+# =============================================================================
+# Celery Configuration
+# =============================================================================
+
+# Celery Broker (RabbitMQ) - REQUIRED
+# These credentials must match your RabbitMQ configuration
+CELERY_BROKER_BASE_URL=amqp://unstract-rabbitmq:5672//
+CELERY_BROKER_USER=admin
+CELERY_BROKER_PASS=password
+
+# =============================================================================
+# Database Configuration (REQUIRED)
+# =============================================================================
+
+# PostgreSQL (for Celery result backend) - REQUIRED
+# These credentials must match your PostgreSQL configuration
+DB_HOST=unstract-db
+DB_USER=unstract_dev
+DB_PASSWORD=unstract_pass
+DB_NAME=unstract_db
+DB_PORT=5432
+DB_SCHEMA=unstract
+
+# Celery Backend Database Schema
+CELERY_BACKEND_DB_SCHEMA=public
+
+# Redis (for caching and queues) - REQUIRED
+REDIS_HOST=unstract-redis
+REDIS_PORT=6379
+REDIS_PASSWORD=
+REDIS_USER=default
+REDIS_DB=0
+
+# Cache-Specific Redis Configuration
+CACHE_REDIS_ENABLED=true
+CACHE_REDIS_HOST=unstract-redis
+CACHE_REDIS_PORT=6379
+CACHE_REDIS_DB=1
+CACHE_REDIS_PASSWORD=
+CACHE_REDIS_USERNAME=
+CACHE_REDIS_SSL=false
+CACHE_REDIS_SSL_CERT_REQS=required
+
+# Database URL (for fallback usage)
+DATABASE_URL=postgresql://unstract_dev:unstract_pass@unstract-db:5432/unstract_db
+
+# =============================================================================
+# Worker Infrastructure Settings
+# =============================================================================
+
+# Worker Singleton Infrastructure - Controls shared resource management
+ENABLE_API_CLIENT_SINGLETON=true
+DEBUG_API_CLIENT_INIT=false
+WORKER_INFRASTRUCTURE_HEALTH_CHECK=true
+
+# API Client Configuration
+API_CLIENT_POOL_SIZE=3
+
+# Config Caching
+ENABLE_CONFIG_CACHE=true
+CONFIG_CACHE_TTL=300
+
+# Debug Settings
+ENABLE_DEBUG_LOGGING=false
+DEBUG_ORGANIZATION_CONTEXT=false
+
+# Worker Concurrency
+MAX_CONCURRENT_TASKS=10
+
+# =============================================================================
+# Worker Performance Settings
+# =============================================================================
+
+CELERY_WORKER_PREFETCH_MULTIPLIER=1
+CELERY_TASK_ACKS_LATE=true
+CELERY_WORKER_MAX_TASKS_PER_CHILD=1000
+
+# =============================================================================
+# Task Timeout Configuration (Celery Standard Naming Convention)
+# =============================================================================
+# Uses format: {WORKER_TYPE}_TASK_TIME_LIMIT and {WORKER_TYPE}_TASK_SOFT_TIME_LIMIT
+#
+# Resolution hierarchy:
+# 1. Worker-specific: FILE_PROCESSING_TASK_TIME_LIMIT (highest priority)
+# 2. General: TASK_TIME_LIMIT (fallback for all workers)
+# 3. Code defaults (lowest priority)
+
+# General Task Timeouts - Applies to all workers without specific overrides
+TASK_TIME_LIMIT=3600 # 1 hour - General hard timeout
+TASK_SOFT_TIME_LIMIT=3300 # 55 minutes - General soft timeout
+
+# Worker-Specific Timeouts - Overrides general timeouts for specific worker types
+FILE_PROCESSING_TASK_TIME_LIMIT=7200 # 2 hours - File processing hard timeout
+FILE_PROCESSING_TASK_SOFT_TIME_LIMIT=6300 # 1h 45m - File processing soft timeout
+CALLBACK_TASK_TIME_LIMIT=3600 # 1 hour - Callback hard timeout
+CALLBACK_TASK_SOFT_TIME_LIMIT=3300 # 55 minutes - Callback soft timeout
+
+# Retry Configuration
+CELERY_TASK_DEFAULT_RETRY_DELAY=60
+CELERY_TASK_MAX_RETRIES=3
+CELERY_TASK_REJECT_ON_WORKER_LOST=true
+
+# Advanced Celery Configuration
+CELERY_WORKER_POOL_RESTARTS=true
+CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP=true
+CELERY_RESULT_CHORD_RETRY_INTERVAL=3.0
+
+# =============================================================================
+# Worker-Specific Configuration
+# =============================================================================
+
+# API Deployment Worker
+API_DEPLOYMENT_WORKER_NAME=api-deployment-worker
+API_DEPLOYMENT_HEALTH_PORT=8080
+API_DEPLOYMENT_AUTOSCALE=4,1
+
+# General Worker
+GENERAL_WORKER_NAME=general-worker
+GENERAL_HEALTH_PORT=8081
+GENERAL_AUTOSCALE=6,2
+
+# File Processing Worker
+FILE_PROCESSING_WORKER_NAME=file-processing-worker
+FILE_PROCESSING_HEALTH_PORT=8082
+FILE_PROCESSING_AUTOSCALE=8,2
+
+# Callback Worker
+CALLBACK_WORKER_NAME=callback-worker
+CALLBACK_HEALTH_PORT=8083
+CALLBACK_AUTOSCALE=4,1
+
+# Scheduler Worker
+SCHEDULER_WORKER_NAME=scheduler-worker
+SCHEDULER_HEALTH_PORT=8087
+SCHEDULER_AUTOSCALE=2,1
+
+# Notification Worker
+NOTIFICATION_WORKER_NAME=notification-worker
+NOTIFICATION_HEALTH_PORT=8085
+NOTIFICATION_AUTOSCALE=4,1
+
+# Log Consumer Worker
+LOG_CONSUMER_WORKER_NAME=log-consumer-worker
+LOG_CONSUMER_HEALTH_PORT=8086
+LOG_CONSUMER_AUTOSCALE=2,1
+
+# =============================================================================
+# Logging Configuration
+# =============================================================================
+
+LOG_LEVEL=INFO
+# structured or django
+LOG_FORMAT=django
+DEFAULT_LOG_LEVEL=INFO
+WORKER_VERSION=1.0.0
+WORKER_INSTANCE_ID=dev-01
+
+# Log History Configuration
+ENABLE_LOG_HISTORY=true
+LOG_HISTORY_CONSUMER_INTERVAL=30
+LOGS_BATCH_LIMIT=30
+LOGS_EXPIRATION_TIME_IN_SECOND=86400
+LOG_HISTORY_QUEUE_NAME=log_history_queue
+
+# Log Queue Size Protection
+# Maximum number of logs in Redis queue before dropping new logs
+LOG_QUEUE_MAX_SIZE=10000
+
+# =============================================================================
+# Queue Configuration
+# =============================================================================
+
+# Notification Queue Name
+NOTIFICATION_QUEUE_NAME=notifications
+
+# =============================================================================
+# Backend Services
+# =============================================================================
+
+# Platform Service
+PLATFORM_SERVICE_HOST=http://unstract-platform-service
+PLATFORM_SERVICE_PORT=3001
+
+# Prompt Service
+PROMPT_HOST=http://unstract-prompt-service
+PROMPT_PORT=3003
+
+# X2Text Service
+X2TEXT_HOST=http://unstract-x2text-service
+X2TEXT_PORT=3004
+
+# Tool Runner
+UNSTRACT_RUNNER_HOST=http://unstract-runner
+UNSTRACT_RUNNER_PORT=5002
+UNSTRACT_RUNNER_API_TIMEOUT=120
+UNSTRACT_RUNNER_API_RETRY_COUNT=5
+UNSTRACT_RUNNER_API_BACKOFF_FACTOR=3
+
+# =============================================================================
+# File Storage Configuration
+# =============================================================================
+
+# File Storage Credentials (MinIO)
+WORKFLOW_EXECUTION_FILE_STORAGE_CREDENTIALS={"provider": "minio", "credentials": {"endpoint_url": "http://unstract-minio:9000", "key": "minio", "secret": "minio123"}}
+API_FILE_STORAGE_CREDENTIALS={"provider": "minio", "credentials": {"endpoint_url": "http://unstract-minio:9000", "key": "minio", "secret": "minio123"}}
+
+# File Execution Configuration
+WORKFLOW_EXECUTION_DIR_PREFIX=unstract/execution
+API_EXECUTION_DIR_PREFIX=unstract/api
+MAX_PARALLEL_FILE_BATCHES=1
+
+# File Execution TTL Configuration
+FILE_EXECUTION_TRACKER_TTL_IN_SECOND=18000
+FILE_EXECUTION_TRACKER_COMPLETED_TTL_IN_SECOND=600
+EXECUTION_RESULT_TTL_SECONDS=86400
+EXECUTION_CACHE_TTL_SECONDS=86400
+INSTANT_WF_POLLING_TIMEOUT=300
+
+# =============================================================================
+# Development Settings
+# =============================================================================
+
+DEBUG=false
+TESTING=false
+ENABLE_METRICS=true
+ENABLE_FILE_HISTORY=true
+ENABLE_WEBHOOK_DELIVERY=true
+
+# Tool Registry
+TOOL_REGISTRY_CONFIG_PATH=../unstract/tool-registry/tool_registry_config
+TOOL_REGISTRY_STORAGE_CREDENTIALS={"provider":"local"}
+
+# =============================================================================
+# Optional Advanced Settings
+# =============================================================================
+
+# Health Checks
+HEALTH_CHECK_INTERVAL=30
+HEALTH_CHECK_TIMEOUT=10
+METRICS_PORT=8080
+
+# Circuit Breaker
+CIRCUIT_BREAKER_FAILURE_THRESHOLD=5
+CIRCUIT_BREAKER_RECOVERY_TIMEOUT=60
+
+# Notifications
+NOTIFICATION_TIMEOUT=5
+
+# Cache
+CACHE_TTL_SEC=10800
+
+# Connection Pooling
+CONNECTION_POOL_SIZE=10
+CONNECTION_POOL_MAX_OVERFLOW=20
+
+# Task Routing and Backup
+ENABLE_PRIORITY_ROUTING=false
+HIGH_PRIORITY_QUEUE_SUFFIX=_high
+LOW_PRIORITY_QUEUE_SUFFIX=_low
+ENABLE_TASK_BACKUP=false
+BACKUP_INTERVAL=3600
+
+# Feature Flags
+ENABLE_DESTINATION_CONNECTORS=true
+ENABLE_CLEANUP_TASKS=true
+
+# Security (for production)
+SECURE_SSL_REDIRECT=false
+SESSION_COOKIE_SECURE=false
+CSRF_COOKIE_SECURE=false
+
+# Monitoring
+SENTRY_DSN=
+SENTRY_ENVIRONMENT=development
+
+# =============================================================================
+# Local Development Overrides
+# =============================================================================
+# For local development (all services on host), change Docker service names to localhost:
+# DJANGO_APP_BACKEND_URL=http://localhost:8000
+# INTERNAL_API_BASE_URL=http://localhost:8000/internal
+# CELERY_BROKER_BASE_URL=amqp://localhost:5672//
+# DB_HOST=localhost
+# REDIS_HOST=localhost
+# CACHE_REDIS_HOST=localhost
+# PLATFORM_SERVICE_HOST=http://localhost
+# PROMPT_HOST=http://localhost
+# X2TEXT_HOST=http://localhost
+# UNSTRACT_RUNNER_HOST=http://localhost
+# WORKFLOW_EXECUTION_FILE_STORAGE_CREDENTIALS={"provider": "minio", "credentials": {"endpoint_url": "http://localhost:9000", "key": "minio", "secret": "minio123"}}
+# API_FILE_STORAGE_CREDENTIALS={"provider": "minio", "credentials": {"endpoint_url": "http://localhost:9000", "key": "minio", "secret": "minio123"}}
+
+PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
diff --git a/workers/scheduler/__init__.py b/workers/scheduler/__init__.py
new file mode 100644
index 000000000..0b760bf33
--- /dev/null
+++ b/workers/scheduler/__init__.py
@@ -0,0 +1,5 @@
+"""Scheduler Worker Package
+
+This package contains the scheduler worker that handles scheduled pipeline executions.
+It replaces the backend scheduler.tasks functionality in the new workers architecture.
+"""
diff --git a/workers/scheduler/tasks.py b/workers/scheduler/tasks.py
new file mode 100644
index 000000000..a1a2aa78e
--- /dev/null
+++ b/workers/scheduler/tasks.py
@@ -0,0 +1,368 @@
+"""Scheduler Worker Tasks
+
+This worker handles scheduled pipeline executions, migrated from @backend/scheduler/tasks.py
+to support the new workers architecture while maintaining backward compatibility.
+"""
+
+import traceback
+from typing import Any
+
+from celery import shared_task
+from shared.enums.status_enums import PipelineStatus
+from shared.enums.worker_enums import QueueName
+from shared.infrastructure.config import WorkerConfig
+from shared.infrastructure.logging import WorkerLogger
+from shared.models.pipeline_models import PipelineApiResponse
+from shared.models.scheduler_models import (
+ ExecutionMode,
+ ScheduledPipelineContext,
+ SchedulerExecutionResult,
+ WorkflowExecutionRequest,
+)
+from shared.utils.api_client_singleton import get_singleton_api_client
+
+# Import the exact backend logic to ensure consistency
+
+logger = WorkerLogger.get_logger(__name__)
+
+# Initialize worker configuration
+config = WorkerConfig.from_env("SCHEDULER")
+
+
+def _execute_scheduled_workflow(
+ api_client,
+ context: ScheduledPipelineContext,
+) -> SchedulerExecutionResult:
+ """Execute scheduled workflow using worker-native logic with type safety.
+
+ This replaces the Django-heavy backend complete_execution method with
+ a worker-native implementation that uses internal APIs and dataclasses.
+
+ Args:
+ api_client: Internal API client instance
+ context: Scheduled pipeline execution context
+
+ Returns:
+ SchedulerExecutionResult with execution status and details
+ """
+ try:
+ logger.info(
+ f"Creating workflow execution for scheduled pipeline: {context.pipeline_name}"
+ )
+
+ # Step 1: Create workflow execution via internal API using dataclass
+ # For scheduled executions, let backend handle execution_log_id (falls back to pipeline_id)
+ # This matches the backend logic: log_events_id if provided, else pipeline_id
+ execution_request = WorkflowExecutionRequest(
+ workflow_id=context.workflow_id,
+ pipeline_id=context.pipeline_id,
+ organization_id=context.organization_id,
+ single_step=False,
+ mode=ExecutionMode.QUEUE,
+ total_files=0, # Will be updated during execution
+ scheduled=True,
+ # log_events_id=None - let backend fall back to pipeline_id for scheduled executions
+ )
+
+ workflow_execution = api_client.create_workflow_execution(
+ execution_request.to_dict()
+ )
+ execution_id = workflow_execution.get("execution_id")
+
+ if not execution_id:
+ return SchedulerExecutionResult.error(
+ error="Failed to create workflow execution",
+ workflow_id=context.workflow_id,
+ pipeline_id=context.pipeline_id,
+ )
+
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{context.pipeline_id}] Created workflow execution for scheduled pipeline {context.pipeline_name}"
+ )
+
+ # Step 2: Trigger async workflow execution via direct Celery dispatch
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{context.pipeline_id}] Triggering async execution for workflow {context.workflow_id}"
+ )
+
+ # Use Celery to dispatch async execution task directly (like backend scheduler does)
+ from celery import current_app
+
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{context.pipeline_id}] Dispatching async_execute_bin task for scheduled execution"
+ )
+
+ try:
+ # Dispatch the Celery task directly to the general queue
+ async_result = current_app.send_task(
+ "async_execute_bin",
+ args=[
+ context.organization_id, # schema_name (organization_id)
+ context.workflow_id, # workflow_id
+ execution_id, # execution_id
+ {}, # hash_values_of_files (empty for scheduled)
+ True, # scheduled (THIS IS A SCHEDULED EXECUTION)
+ ],
+ kwargs={
+ "use_file_history": context.use_file_history, # Pass as kwarg
+ "pipeline_id": context.pipeline_id, # CRITICAL FIX: Pass pipeline_id for direct status updates
+ },
+ queue=QueueName.GENERAL, # Route to General queue for proper separation
+ )
+
+ task_id = async_result.id
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{context.pipeline_id}] Successfully dispatched async_execute_bin task {task_id} for scheduled execution"
+ )
+
+ execution_response = SchedulerExecutionResult.success(
+ execution_id=execution_id,
+ workflow_id=context.workflow_id,
+ pipeline_id=context.pipeline_id,
+ task_id=task_id,
+ message="Async execution task dispatched successfully",
+ )
+ except Exception as e:
+ logger.error(f"Failed to dispatch async execution task: {e}")
+ execution_response = SchedulerExecutionResult.error(
+ error=f"Failed to dispatch async execution: {str(e)}",
+ execution_id=execution_id,
+ workflow_id=context.workflow_id,
+ pipeline_id=context.pipeline_id,
+ )
+
+ if execution_response.is_success:
+ logger.info(
+ f"Successfully started scheduled execution {execution_id} for pipeline '{context.pipeline_name}'"
+ )
+ return execution_response # Already a SchedulerExecutionResult
+ else:
+ logger.error(
+ f"Failed to start async execution for pipeline '{context.pipeline_name}': {execution_response.error}"
+ )
+ return execution_response # Already a SchedulerExecutionResult with error
+
+ except Exception as e:
+ logger.error(f"Exception in scheduled workflow execution: {e}")
+ return SchedulerExecutionResult.error(
+ error=f"Scheduler execution failed: {str(e)}",
+ workflow_id=context.workflow_id,
+ pipeline_id=context.pipeline_id,
+ )
+
+
+@shared_task(name="scheduler.tasks.execute_pipeline_task", bind=True)
+def execute_pipeline_task(
+ self,
+ workflow_id: Any,
+ org_schema: Any,
+ execution_action: Any,
+ execution_id: Any,
+ pipepline_id: Any, # Note: keeping original typo for compatibility
+ with_logs: Any,
+ name: Any,
+) -> None:
+ """Execute pipeline task - maintains exact signature from backend scheduler.
+
+ This is the main entry point for scheduled pipeline executions, delegating
+ to the v2 implementation for actual processing.
+ """
+ return execute_pipeline_task_v2(
+ organization_id=org_schema,
+ pipeline_id=pipepline_id,
+ pipeline_name=name,
+ )
+
+
+@shared_task(name="execute_pipeline_task_v2", bind=True)
+def execute_pipeline_task_v2(
+ self,
+ organization_id: Any,
+ pipeline_id: Any,
+ pipeline_name: Any,
+) -> None:
+ """V2 of execute_pipeline method - worker implementation.
+
+ This method replicates the exact logic from backend/scheduler/tasks.py
+ but uses worker clients instead of direct Django ORM access.
+
+ Args:
+ organization_id: Organization identifier
+ pipeline_id: UID of pipeline entity
+ pipeline_name: Pipeline name for logging
+ """
+ try:
+ # Initialize API client with organization context
+ api_client = get_singleton_api_client(config)
+ api_client.set_organization_context(organization_id)
+
+ logger.info(
+ f"Executing scheduled pipeline: {pipeline_id}, "
+ f"organization: {organization_id}, pipeline name: {pipeline_name}"
+ )
+
+ # Fetch pipeline data via API client with type safety
+ try:
+ pipeline_response = api_client.get_pipeline_data(
+ pipeline_id=pipeline_id, check_active=True
+ )
+
+ if not pipeline_response.success:
+ logger.error(
+ f"Failed to fetch pipeline {pipeline_id}: {pipeline_response.error}"
+ )
+ return
+
+ # Parse response using type-safe dataclass
+ pipeline_api_data = PipelineApiResponse.from_dict(pipeline_response.data)
+ pipeline_data = pipeline_api_data.pipeline
+
+ # Use dataclass properties for type-safe access
+ workflow_id = pipeline_data.workflow_id
+ pipeline_name_from_api = pipeline_data.pipeline_name
+
+ logger.info(
+ f"Found pipeline '{pipeline_name_from_api}' with workflow {workflow_id} "
+ f"for pipeline ID {pipeline_id}"
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Error fetching or parsing pipeline data for {pipeline_id}: {e}"
+ )
+ return
+
+ # Check subscription if validation is enabled
+ # Note: In workers, we'll skip subscription validation for now as it requires
+ # backend plugins. This can be added later via internal API if needed.
+ logger.debug("Skipping subscription validation in worker context")
+
+ # Update pipeline status to INPROGRESS when scheduled execution starts
+ try:
+ logger.info(
+ f"Updating pipeline {pipeline_id} status to {PipelineStatus.INPROGRESS}"
+ )
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.INPROGRESS.value,
+ organization_id=organization_id,
+ )
+ logger.info(
+ f"Successfully updated pipeline {pipeline_id} status to {PipelineStatus.INPROGRESS}"
+ )
+ except Exception as e:
+ logger.warning(f"Failed to update pipeline status to INPROGRESS: {e}")
+ # Don't fail the entire execution for status update failures
+
+ # Implement scheduler logic directly in worker using type-safe dataclasses
+ # This replaces the Django-heavy backend complete_execution method
+ try:
+ # Create execution context using dataclass
+ context = ScheduledPipelineContext(
+ pipeline_id=pipeline_id,
+ pipeline_name=pipeline_name_from_api,
+ workflow_id=workflow_id,
+ organization_id=organization_id,
+ use_file_history=True, # Always true for scheduled executions
+ )
+
+ execution_result = _execute_scheduled_workflow(
+ api_client=api_client,
+ context=context,
+ )
+
+ if execution_result.is_success:
+ logger.info(
+ f"[exec:{execution_result.execution_id}] [pipeline:{pipeline_id}] Scheduled execution task dispatched successfully for pipeline '{pipeline_name_from_api}' "
+ f"in organization {organization_id}"
+ )
+ # Pipeline status will be updated to COMPLETED/FAILED by the actual workflow execution
+ else:
+ logger.error(
+ f"[exec:{execution_result.execution_id}] [pipeline:{pipeline_id}] Failed to dispatch scheduled execution for pipeline '{pipeline_name_from_api}': {execution_result.error}"
+ )
+ # Update pipeline status to FAILED since we couldn't even start the execution
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.FAILURE.value,
+ organization_id=organization_id,
+ )
+ logger.info(
+ f"Updated pipeline {pipeline_id} status to {PipelineStatus.FAILURE} due to dispatch failure"
+ )
+ except Exception as e:
+ logger.warning(f"Failed to update pipeline status to FAILED: {e}")
+
+ except Exception as e:
+ logger.error(
+ f"Error during scheduled workflow execution for pipeline '{pipeline_name_from_api}': {e}"
+ )
+ # Update pipeline status to FAILED due to scheduler error
+ try:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.FAILURE.value,
+ organization_id=organization_id,
+ )
+ logger.info(
+ f"Updated pipeline {pipeline_id} status to {PipelineStatus.FAILURE} due to scheduler exception"
+ )
+ except Exception as status_error:
+ logger.warning(
+ f"Failed to update pipeline status to FAILED: {status_error}"
+ )
+ raise
+
+ except Exception as e:
+ logger.error(
+ f"Failed to execute pipeline: {pipeline_name}. Error: {e}"
+ f"\n\n'''{traceback.format_exc()}```"
+ )
+
+ # Update pipeline status to FAILED for top-level scheduler errors
+ try:
+ api_client = get_singleton_api_client(config)
+ api_client.set_organization_context(
+ organization_id if "organization_id" in locals() else None
+ )
+ if "pipeline_id" in locals() and pipeline_id:
+ api_client.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=PipelineStatus.FAILURE.value,
+ organization_id=organization_id
+ if "organization_id" in locals()
+ else None,
+ )
+ logger.info(
+ f"Updated pipeline {pipeline_id} status to {PipelineStatus.FAILURE} due to top-level scheduler error"
+ )
+ except Exception as status_error:
+ logger.warning(
+ f"Failed to update pipeline status to FAILED in outer exception: {status_error}"
+ )
+
+
+# Health check task for monitoring
+@shared_task(name="scheduler_health_check")
+def health_check() -> dict[str, Any]:
+ """Health check task for scheduler worker.
+
+ Returns:
+ Health status information
+ """
+ try:
+ # Check API client connectivity
+ api_client = get_singleton_api_client(config)
+ api_status = "healthy" if api_client else "unhealthy"
+ except Exception as e:
+ api_status = f"unhealthy: {e}"
+
+ return {
+ "worker": "scheduler",
+ "status": "healthy" if "healthy" in api_status else "degraded",
+ "api": api_status,
+ "config": {
+ "queue": config.queue_name,
+ },
+ }
diff --git a/workers/scheduler/worker.py b/workers/scheduler/worker.py
new file mode 100644
index 000000000..1a316d179
--- /dev/null
+++ b/workers/scheduler/worker.py
@@ -0,0 +1,69 @@
+"""Scheduler Worker
+
+Celery worker for scheduled tasks and background processing.
+"""
+
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config.builder import WorkerBuilder
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+
+# Setup worker
+logger = WorkerLogger.setup(WorkerType.SCHEDULER)
+app, config = WorkerBuilder.build_celery_app(WorkerType.SCHEDULER)
+
+
+def check_scheduler_health():
+ """Custom health check for scheduler worker."""
+ from shared.infrastructure.monitoring.health import HealthCheckResult, HealthStatus
+
+ try:
+ from shared.utils.api_client_singleton import get_singleton_api_client
+
+ client = get_singleton_api_client(config)
+ api_healthy = client is not None
+
+ if api_healthy:
+ return HealthCheckResult(
+ name="scheduler_health",
+ status=HealthStatus.HEALTHY,
+ message="Scheduler worker is healthy",
+ details={
+ "worker_type": "scheduler",
+ "api_client": "healthy",
+ "queue": "scheduler",
+ },
+ )
+ else:
+ return HealthCheckResult(
+ name="scheduler_health",
+ status=HealthStatus.DEGRADED,
+ message="Scheduler worker partially functional",
+ details={"api_client": "unhealthy"},
+ )
+
+ except Exception as e:
+ return HealthCheckResult(
+ name="scheduler_health",
+ status=HealthStatus.DEGRADED,
+ message=f"Health check failed: {e}",
+ details={"error": str(e)},
+ )
+
+
+# Register health check
+
+WorkerRegistry.register_health_check(
+ WorkerType.SCHEDULER, "scheduler_health", check_scheduler_health
+)
+
+
+def healthcheck(self):
+ """Health check task for monitoring systems."""
+ return {
+ "status": "healthy",
+ "worker_type": "scheduler",
+ "task_id": self.request.id,
+ "worker_name": config.worker_name if config else "scheduler-worker",
+ }
diff --git a/workers/shared/__init__.py b/workers/shared/__init__.py
new file mode 100644
index 000000000..39d4eee81
--- /dev/null
+++ b/workers/shared/__init__.py
@@ -0,0 +1,50 @@
+"""Shared Worker Infrastructure
+
+This module provides common infrastructure and utilities for lightweight Celery workers
+that communicate with Django backend via internal APIs instead of direct ORM access.
+
+Key components organized by SOLID principles:
+- API communication layer (api/)
+- Workflow execution components (workflow/)
+- File and data processing (processing/)
+- Infrastructure services (infrastructure/)
+- Design patterns and utilities (patterns/)
+- Core interfaces and types (core/)
+- Data models, enums, and constants (data/)
+"""
+
+# Simplified imports to avoid circular dependencies during initialization
+# Individual imports for key components
+
+# Import core exceptions directly
+from .core.exceptions.api_exceptions import APIClientError
+from .core.exceptions.base_exceptions import WorkerBaseError
+from .core.exceptions.workflow_exceptions import WorkflowExecutionError
+
+# Import configuration and logging directly
+from .infrastructure.config.worker_config import WorkerConfig
+from .infrastructure.logging.logger import WorkerLogger
+
+# Import execution context
+from .workflow.execution.context import WorkerExecutionContext
+
+# Import API client with fallback
+try:
+ from .api.internal_client import InternalAPIClient
+except ImportError:
+ # Fallback for workers that don't need the full API client
+ InternalAPIClient = None
+
+__all__ = [
+ # Backward compatibility - main interfaces
+ "InternalAPIClient",
+ "WorkerConfig",
+ "WorkerLogger",
+ "WorkerExecutionContext",
+ # Core interfaces and exceptions
+ "WorkerBaseError",
+ "APIClientError",
+ "WorkflowExecutionError",
+]
+
+__version__ = "1.0.0"
diff --git a/workers/shared/api/__init__.py b/workers/shared/api/__init__.py
new file mode 100644
index 000000000..fe9af6890
--- /dev/null
+++ b/workers/shared/api/__init__.py
@@ -0,0 +1,13 @@
+"""API communication layer for workers.
+
+This package provides all API-related functionality including clients,
+authentication, and communication with the backend.
+"""
+
+# Import the main internal API client
+from .internal_client import InternalAPIClient
+
+__all__ = [
+ # Main internal API client for backend communication
+ "InternalAPIClient",
+]
diff --git a/workers/shared/api/facades/__init__.py b/workers/shared/api/facades/__init__.py
new file mode 100644
index 000000000..630461cf6
--- /dev/null
+++ b/workers/shared/api/facades/__init__.py
@@ -0,0 +1,10 @@
+"""Backward compatibility facades for API clients.
+
+This package provides facades that maintain existing interfaces while
+delegating to the new modular client architecture.
+"""
+
+# Re-export from parent for backward compatibility
+from ..internal_client import InternalAPIClient
+
+__all__ = ["InternalAPIClient"]
diff --git a/workers/shared/api/internal_client.py b/workers/shared/api/internal_client.py
new file mode 100644
index 000000000..9689687cb
--- /dev/null
+++ b/workers/shared/api/internal_client.py
@@ -0,0 +1,1574 @@
+"""Backward Compatibility Facade for Internal API Client
+
+This facade provides backward compatibility for existing code that imports from
+the original api_client.py. It delegates calls to the specialized modular clients
+while maintaining the same interface.
+
+This maintains the original InternalAPIClient interface by composing all the
+specialized clients (ExecutionAPIClient, FileAPIClient, etc.) into a single
+unified interface.
+"""
+
+import logging
+import uuid
+from typing import Any
+from uuid import UUID
+
+# Manual review functionality loaded via plugin registry
+from client_plugin_registry import get_client_plugin
+from shared.cache import CachedAPIClientMixin, with_cache
+from shared.cache.cache_types import CacheType
+from shared.clients import (
+ BaseAPIClient,
+ ExecutionAPIClient,
+ FileAPIClient,
+ OrganizationAPIClient,
+ ToolAPIClient,
+ UsageAPIClient,
+ WebhookAPIClient,
+ WorkflowAPIClient,
+)
+
+# Import exceptions from base client
+# Re-export exceptions for backward compatibility
+from shared.clients.base_client import (
+ APIRequestError,
+ AuthenticationError,
+ InternalAPIClientError,
+)
+from shared.clients.manual_review_stub import ManualReviewNullClient
+from shared.data.response_models import APIResponse
+from shared.enums import HTTPMethod
+from shared.infrastructure.config.worker_config import WorkerConfig
+
+# Import new API response dataclasses for type safety
+from shared.models.api_responses import (
+ FileBatchResponse,
+ FileHistoryResponse,
+ ToolInstancesResponse,
+ WorkflowDefinitionResponse,
+ WorkflowExecutionResponse,
+)
+
+# Import execution models for type-safe execution contexts
+# Import notification models for type-safe notifications
+from shared.models.notification_models import (
+ WebhookNotificationRequest,
+)
+from shared.models.scheduler_models import SchedulerExecutionResult
+
+from unstract.core.data_models import (
+ ExecutionStatus,
+ FileExecutionCreateRequest,
+ FileExecutionStatusUpdateRequest,
+ FileHashData,
+ UsageResponseData,
+ WorkflowDefinitionResponseData,
+ WorkflowEndpointConfigResponseData,
+ WorkflowFileExecutionData,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class InternalAPIClient(CachedAPIClientMixin):
+ """Backward compatibility facade for the original monolithic InternalAPIClient.
+
+ This class provides the same interface as the original InternalAPIClient
+ but delegates all operations to the specialized modular clients with caching support.
+ This ensures existing code continues to work without modification while benefiting from
+ both the improved modular architecture and caching for better performance.
+ """
+
+ # Class-level shared base client for singleton pattern
+ _shared_base_client = None
+ _shared_session = None
+ _initialization_count = 0
+
+ def __init__(self, config: WorkerConfig | None = None):
+ """Initialize the facade with all specialized clients and caching.
+
+ Args:
+ config: Worker configuration. If None, uses default config.
+ """
+ self.config = config or WorkerConfig()
+
+ # Initialize caching (parent class)
+ super().__init__()
+
+ # Initialize core clients
+ self._initialize_core_clients()
+
+ # Initialize plugin clients
+ self._initialize_plugin_clients()
+
+ # Setup direct access references
+ self._setup_direct_access_references()
+
+ logger.info(
+ "Initialized InternalAPIClient facade with modular architecture and caching"
+ )
+
+ def _initialize_core_clients(self) -> None:
+ """Initialize all core API clients with performance optimizations."""
+ if self.config.enable_api_client_singleton:
+ self._initialize_core_clients_optimized()
+ else:
+ self._initialize_core_clients_traditional()
+
+ def _initialize_core_clients_optimized(self) -> None:
+ """Initialize clients using GIL-safe singleton pattern for better performance."""
+ InternalAPIClient._initialization_count += 1
+
+ # Create or reuse shared session - GIL provides atomicity
+ if InternalAPIClient._shared_session is None:
+ if self.config.debug_api_client_init:
+ logger.info("Creating shared HTTP session (GIL-safe singleton pattern)")
+ # Create the first base client to establish the session
+ self.base_client = BaseAPIClient(self.config)
+ # Share the session for reuse (atomic assignment)
+ InternalAPIClient._shared_session = self.base_client.session
+ InternalAPIClient._shared_base_client = self.base_client
+ else:
+ if self.config.debug_api_client_init:
+ logger.info(
+ f"Reusing shared HTTP session (#{InternalAPIClient._initialization_count})"
+ )
+ # Create base client and replace its session with shared one
+ self.base_client = BaseAPIClient(self.config)
+ self.base_client.session.close() # Close the new session
+ self.base_client.session = (
+ InternalAPIClient._shared_session
+ ) # Use shared session
+
+ # Create specialized clients with shared session (outside lock for performance)
+ self.execution_client = ExecutionAPIClient(self.config)
+ self.execution_client.session.close()
+ self.execution_client.session = InternalAPIClient._shared_session
+
+ self.workflow_client = WorkflowAPIClient()
+ self.workflow_client.session.close()
+ self.workflow_client.session = InternalAPIClient._shared_session
+
+ self.file_client = FileAPIClient(self.config)
+ self.file_client.session.close()
+ self.file_client.session = InternalAPIClient._shared_session
+
+ self.webhook_client = WebhookAPIClient(self.config)
+ self.webhook_client.session.close()
+ self.webhook_client.session = InternalAPIClient._shared_session
+
+ self.organization_client = OrganizationAPIClient(self.config)
+ self.organization_client.session.close()
+ self.organization_client.session = InternalAPIClient._shared_session
+
+ self.tool_client = ToolAPIClient(self.config)
+ self.tool_client.session.close()
+ self.tool_client.session = InternalAPIClient._shared_session
+
+ self.usage_client = UsageAPIClient(self.config)
+ self.usage_client.session.close()
+ self.usage_client.session = InternalAPIClient._shared_session
+
+ def _initialize_core_clients_traditional(self) -> None:
+ """Initialize clients the traditional way (for backward compatibility)."""
+ if self.config.debug_api_client_init:
+ logger.info(
+ "Using traditional API client initialization (6 separate instances)"
+ )
+ self.base_client = BaseAPIClient(self.config)
+ self.execution_client = ExecutionAPIClient(self.config)
+ self.file_client = FileAPIClient(self.config)
+ self.webhook_client = WebhookAPIClient(self.config)
+ self.organization_client = OrganizationAPIClient(self.config)
+ self.tool_client = ToolAPIClient(self.config)
+ self.usage_client = UsageAPIClient(self.config)
+
+ def _initialize_plugin_clients(self) -> None:
+ """Initialize plugin-based clients with error handling."""
+ self.manual_review_client = self._load_manual_review_client()
+ logger.debug(
+ f"Manual review client type: {type(self.manual_review_client).__name__}"
+ )
+
+ def _load_manual_review_client(self) -> Any:
+ """Load manual review client via plugin registry with fallback.
+
+ Returns:
+ ManualReviewClient or ManualReviewNullClient
+ """
+ try:
+ plugin_instance = get_client_plugin("manual_review", self.config)
+ if plugin_instance:
+ logger.debug("Using manual review plugin from registry")
+ return plugin_instance
+ else:
+ logger.debug("Manual review plugin not available, using null client")
+ return ManualReviewNullClient(self.config)
+ except Exception as e:
+ logger.warning(f"Failed to load manual review plugin, using null client: {e}")
+ return ManualReviewNullClient(self.config)
+
+ def _setup_direct_access_references(self) -> None:
+ """Setup direct access references for backward compatibility."""
+ self.base_url = self.base_client.base_url
+ self.api_key = self.base_client.api_key
+ self.organization_id = self.base_client.organization_id
+ self.session = self.base_client.session
+
+ # Delegate base client methods
+ def health_check(self) -> dict[str, Any]:
+ """Check API health status."""
+ return self.base_client.health_check()
+
+ def close(self):
+ """Close API client safely (respects shared session singleton).
+
+ When session sharing is enabled, this method only closes the client
+ wrappers but preserves the shared HTTP session for other instances.
+ """
+ if self.config.enable_api_client_singleton:
+ # With session sharing, we don't close individual sessions
+ # as they're shared. Only log for debugging.
+ if self.config.debug_api_client_init:
+ logger.debug(
+ "InternalAPIClient close() called - preserving shared session"
+ )
+ else:
+ # Traditional mode: close all sessions normally
+ self.base_client.close()
+ self.execution_client.close()
+ self.file_client.close()
+ self.webhook_client.close()
+ self.organization_client.close()
+ self.tool_client.close()
+ self.workflow_client.close()
+ self.usage_client.close()
+ logger.debug("Closed all InternalAPIClient sessions (traditional mode)")
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Context manager exit with safe cleanup."""
+ self.close()
+
+ # Close manual review client (plugin or null client)
+ if hasattr(self.manual_review_client, "close"):
+ self.manual_review_client.close()
+
+ def __enter__(self):
+ """Context manager entry."""
+ return self
+
+ # Delegate execution client methods
+ def get_workflow_executions_by_status(
+ self,
+ workflow_id: str | uuid.UUID,
+ statuses: list[str],
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get workflow executions by status for a specific workflow.
+
+ This gets ALL executions for a workflow that match the given statuses,
+ matching the backend logic in source.py _get_active_workflow_executions().
+
+ Args:
+ workflow_id: Workflow ID
+ statuses: List of status values (e.g., ['PENDING', 'EXECUTING'])
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with workflow executions data
+ """
+ try:
+ # Use workflow execution endpoint with status filtering (trailing slash required by Django)
+ response_data = self._make_request(
+ method=HTTPMethod.GET,
+ endpoint="v1/workflow-execution/",
+ params={
+ "workflow_id": str(workflow_id),
+ "status__in": ",".join(statuses), # Multiple status filter
+ },
+ organization_id=organization_id,
+ )
+
+ # Wrap filtered response data in APIResponse
+ return APIResponse(
+ success=True,
+ data=response_data,
+ )
+
+ except Exception as e:
+ logger.error(f"Error getting workflow executions by status: {e}")
+ return APIResponse(
+ success=False,
+ error=str(e),
+ )
+
+ def check_files_active_processing(
+ self,
+ workflow_id: str | uuid.UUID,
+ provider_file_uuids: list[str] = None,
+ files: list[dict] = None,
+ current_execution_id: str | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Check if specific files are being processed in PENDING/EXECUTING workflow executions.
+
+ Optimized single API call instead of querying all executions and their file executions.
+
+ Args:
+ workflow_id: Workflow ID to check
+ provider_file_uuids: [LEGACY] List of provider file UUIDs to check
+ files: [NEW] List of file objects with 'uuid' and 'path' fields: [{'uuid': str, 'path': str}]
+ current_execution_id: Current execution ID to exclude from active check
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with backend response format
+ """
+ try:
+ # Prepare request data with backward compatibility
+ request_data = {
+ "workflow_id": str(workflow_id),
+ "statuses": ["PENDING", "EXECUTING"],
+ "exclude_execution_id": str(current_execution_id)
+ if current_execution_id
+ else None,
+ }
+
+ # Support both legacy and new formats
+ if files:
+ # New path-aware format
+ request_data["files"] = files
+ elif provider_file_uuids:
+ # Legacy format - fallback
+ request_data["provider_file_uuids"] = provider_file_uuids
+ else:
+ raise ValueError(
+ "Either 'files' or 'provider_file_uuids' must be provided"
+ )
+
+ # Single optimized API call to check multiple files at once
+ response_data = self._make_request(
+ method=HTTPMethod.POST,
+ endpoint="v1/workflow-manager/file-execution/check-active",
+ data=request_data,
+ organization_id=organization_id,
+ )
+
+ return APIResponse(
+ success=True,
+ data=response_data,
+ )
+
+ except Exception as e:
+ logger.error(f"Error checking files active processing: {e}")
+ # Fallback: assume no files are active to avoid blocking
+ return APIResponse(
+ success=True,
+ data={"active_uuids": []},
+ )
+
+ def get_workflow_file_executions_by_execution(
+ self, execution_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get WorkflowFileExecutions for a specific execution using internal API.
+
+ This uses the existing /internal/api/v1/file-execution/?execution_id=<id> endpoint
+ to get all file executions for a workflow execution.
+
+ Args:
+ execution_id: Workflow execution ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with file executions data
+ """
+ try:
+ response = self._make_request(
+ method=HTTPMethod.GET,
+ endpoint="v1/file-execution/",
+ params={"execution_id": str(execution_id)},
+ organization_id=organization_id,
+ )
+
+ return response
+
+ except Exception as e:
+ logger.error(f"Error getting workflow file executions: {e}")
+ return APIResponse(
+ success=False,
+ error=str(e),
+ )
+
+ def get_workflow_execution(
+ self,
+ execution_id: str | uuid.UUID,
+ organization_id: str | None = None,
+ include_cost: bool = False,
+ file_execution: bool = True,
+ ) -> WorkflowExecutionResponse:
+ """Get workflow execution with context.
+
+ Args:
+ execution_id: Workflow execution ID
+ organization_id: Optional organization ID override
+ include_cost: Whether to include aggregated usage cost (expensive operation)
+
+ Returns:
+ WorkflowExecutionResponse containing workflow execution data
+ """
+ response = self.execution_client.get_workflow_execution(
+ execution_id,
+ organization_id,
+ include_cost=include_cost,
+ file_execution=file_execution,
+ )
+ # Convert ExecutionResponse to WorkflowExecutionResponse for type safety
+ if hasattr(response, "to_dict"):
+ response_dict = response.to_dict()
+ else:
+ response_dict = response
+ return WorkflowExecutionResponse.from_api_response(response_dict)
+
+ def get_workflow(
+ self, workflow_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> WorkflowDefinitionResponseData:
+ """Get workflow definition including workflow_type."""
+ response = self.workflow_client.get_workflow_definition(
+ workflow_id, organization_id
+ )
+ if not response.success_response:
+ raise APIRequestError(response.error_response)
+ return response.data
+
+ @with_cache(
+ CacheType.WORKFLOW_ENDPOINTS,
+ lambda self, workflow_id, organization_id=None: str(workflow_id),
+ )
+ def get_workflow_endpoints(
+ self, workflow_id: str | UUID, organization_id: str | None = None
+ ) -> WorkflowEndpointConfigResponseData:
+ """Get workflow endpoints for a specific workflow.
+
+ Caching is handled automatically through the @with_cache decorator.
+ """
+ # Direct API call - caching is handled by decorator
+ response = self.workflow_client.get_workflow_endpoints(
+ workflow_id, organization_id
+ )
+ if not response.success_response:
+ raise APIRequestError(response.error_response)
+ return response.data
+
+ @with_cache(
+ CacheType.WORKFLOW,
+ lambda self, workflow_id, organization_id=None: str(workflow_id),
+ )
+ def get_workflow_definition(
+ self, workflow_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> WorkflowDefinitionResponse:
+ """Get workflow definition including workflow_type.
+
+ This method automatically uses caching through the @with_cache decorator.
+ """
+ # Direct API call - caching is handled by decorator
+ response = self.execution_client.get_workflow_definition(
+ workflow_id, organization_id
+ )
+ # Convert to WorkflowDefinitionResponse for type safety
+ if hasattr(response, "to_dict"):
+ response_dict = response.to_dict()
+ else:
+ response_dict = response
+ return WorkflowDefinitionResponse.from_api_response(response_dict)
+
+ def get_pipeline_type(
+ self, pipeline_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get pipeline type by checking APIDeployment and Pipeline models."""
+ return self.execution_client.get_pipeline_type(pipeline_id, organization_id)
+
+ def get_pipeline_data(
+ self,
+ pipeline_id: str | uuid.UUID,
+ check_active: bool = True,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get pipeline data by checking APIDeployment and Pipeline models.
+
+ Args:
+ pipeline_id: Pipeline ID
+ check_active: Whether to check if pipeline is active (default: True)
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse containing pipeline data
+ """
+ return self.execution_client.get_pipeline_data(
+ pipeline_id=pipeline_id,
+ check_active=check_active,
+ organization_id=organization_id,
+ )
+
+ @with_cache(
+ CacheType.API_DEPLOYMENT, lambda self, api_id, organization_id=None: str(api_id)
+ )
+ def get_api_deployment_data(
+ self, api_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get APIDeployment data directly from v1 API deployment endpoint.
+
+ This method is optimized for callback workers that know they're dealing
+ with API deployments. It queries APIDeployment model directly.
+ Caching is handled automatically through the @with_cache decorator.
+ """
+ # Direct API call - caching is handled by decorator
+ return self.execution_client.get_api_deployment_data(api_id, organization_id)
+
+ def update_workflow_execution_status(
+ self,
+ execution_id: str | uuid.UUID,
+ status: str,
+ error_message: str | None = None,
+ total_files: int | None = None,
+ attempts: int | None = None,
+ execution_time: float | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Update workflow execution status."""
+ return self.execution_client.update_workflow_execution_status(
+ execution_id,
+ status,
+ error_message,
+ total_files,
+ attempts,
+ execution_time,
+ organization_id,
+ )
+
+ def create_workflow_execution(self, execution_data: dict[str, Any]) -> dict[str, Any]:
+ """Create workflow execution."""
+ return self.execution_client.create_workflow_execution(execution_data)
+
+ @with_cache(
+ CacheType.TOOL_INSTANCES, lambda self, workflow_id, organization_id: workflow_id
+ )
+ def get_tool_instances_by_workflow(
+ self, workflow_id: str, organization_id: str
+ ) -> ToolInstancesResponse:
+ """Get tool instances for a workflow.
+
+ Caching is handled automatically through the @with_cache decorator.
+ """
+ # Direct API call - caching is handled by decorator
+ response = self.execution_client.get_tool_instances_by_workflow(
+ workflow_id, organization_id
+ )
+ # Convert to ToolInstancesResponse for type safety
+ return ToolInstancesResponse.from_api_response(response)
+
+ def validate_tool_instances(
+ self, workflow_id: str, tool_instance_ids: list[str], organization_id: str
+ ) -> dict[str, Any]:
+ """Validate tool instances and ensure adapter IDs are migrated.
+
+ Args:
+ workflow_id: ID of the workflow
+ tool_instance_ids: List of tool instance IDs to validate
+ organization_id: Organization ID
+
+ Returns:
+ Dictionary with validation results:
+ {
+ "success": bool,
+ "validated_instances": [...], # List of validated instances with migrated metadata
+ "errors": [...], # List of validation errors
+ "workflow_id": str
+ }
+ """
+ validation_data = {
+ "workflow_id": workflow_id,
+ "tool_instances": tool_instance_ids,
+ }
+
+ try:
+ response = self.execution_client.post(
+ "v1/tool-execution/validate/",
+ validation_data,
+ organization_id=organization_id,
+ )
+ return response
+ except Exception as e:
+ logger.error(f"Tool validation API call failed: {e}")
+ # Return error response in expected format
+ return {
+ "success": False,
+ "validated_instances": [],
+ "errors": [{"error": f"API call failed: {str(e)}"}],
+ "workflow_id": workflow_id,
+ }
+
+ def compile_workflow(
+ self, workflow_id: str, execution_id: str, organization_id: str
+ ) -> dict[str, Any]:
+ """Compile workflow."""
+ return self.execution_client.compile_workflow(
+ workflow_id, execution_id, organization_id
+ )
+
+ def submit_file_batch_for_processing(
+ self, batch_data: dict[str, Any]
+ ) -> dict[str, Any]:
+ """Submit file batch for processing."""
+ return self.execution_client.submit_file_batch_for_processing(batch_data)
+
+ def execute_workflow_async(self, execution_data: dict[str, Any]) -> dict[str, Any]:
+ """Execute workflow asynchronously for scheduler.
+
+ This method triggers async workflow execution by dispatching to the
+ appropriate Celery task via internal API.
+
+ Args:
+ execution_data: Execution parameters including workflow_id, execution_id, etc.
+
+ Returns:
+ Dictionary with execution results
+ """
+ try:
+ # Use the internal API to trigger async workflow execution
+ # This replaces the Celery send_task("async_execute_bin") call from backend
+ response = self.execution_client.post(
+ "v1/workflow-manager/execute-async/",
+ execution_data,
+ organization_id=execution_data.get("organization_id"),
+ )
+
+ if isinstance(response, dict) and response.get("success"):
+ return {
+ "success": True,
+ "execution_id": response.get("execution_id"),
+ "task_id": response.get("task_id"),
+ "message": "Async workflow execution started",
+ }
+ else:
+ return {
+ "success": False,
+ "error": response.get("error", "Failed to start async execution"),
+ }
+ except Exception as e:
+ logger.error(f"Error starting async workflow execution: {e}")
+ return {
+ "success": False,
+ "error": f"API error: {str(e)}",
+ }
+
+ def execute_workflow_async_typed(
+ self, async_request: Any
+ ) -> SchedulerExecutionResult:
+ """Type-safe async workflow execution for scheduler using dataclasses.
+
+ Args:
+ async_request: AsyncExecutionRequest dataclass with execution parameters
+
+ Returns:
+ SchedulerExecutionResult with execution status and details
+ """
+ try:
+ # Convert dataclass to dict for API call
+ execution_data = async_request.to_dict()
+
+ # Use the internal API to trigger async workflow execution
+ response = self.execution_client.post(
+ "v1/workflow-manager/execute-async/",
+ execution_data,
+ organization_id=async_request.organization_id,
+ )
+
+ if isinstance(response, dict) and response.get("success"):
+ return SchedulerExecutionResult.success(
+ execution_id=async_request.execution_id,
+ workflow_id=async_request.workflow_id,
+ pipeline_id=async_request.pipeline_id,
+ task_id=response.get("task_id"),
+ message="Async workflow execution started successfully",
+ )
+ else:
+ return SchedulerExecutionResult.error(
+ error=response.get("error", "Failed to start async execution"),
+ execution_id=async_request.execution_id,
+ workflow_id=async_request.workflow_id,
+ pipeline_id=async_request.pipeline_id,
+ )
+ except Exception as e:
+ logger.error(f"Error starting async workflow execution: {e}")
+ return SchedulerExecutionResult.error(
+ error=f"API error: {str(e)}",
+ execution_id=async_request.execution_id,
+ workflow_id=async_request.workflow_id,
+ pipeline_id=async_request.pipeline_id,
+ )
+
+ def batch_update_execution_status(
+ self, updates: list[dict[str, Any]], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Update multiple execution statuses in a single request."""
+ # Validate that we have updates to process
+ if not updates:
+ return {
+ "success": True,
+ "message": "No updates provided",
+ "total_items": 0,
+ "successful_items": 0,
+ "failed_items": 0,
+ }
+
+ result = self.execution_client.batch_update_execution_status(
+ updates, organization_id
+ )
+
+ # Convert BatchOperationResponse to dict for consistency
+ if hasattr(result, "to_dict"):
+ response_dict = result.to_dict()
+ # Add success field for backward compatibility
+ response_dict["success"] = (
+ result.status == "SUCCESS" or result.successful_items > 0
+ )
+ return response_dict
+ else:
+ return result
+
+ def create_file_batch(
+ self,
+ workflow_execution_id: str | uuid.UUID,
+ files: list,
+ is_api: bool = False,
+ organization_id: str | None = None,
+ ) -> FileBatchResponse:
+ """Create file execution batch."""
+ response = self.execution_client.create_file_batch(
+ workflow_execution_id, files, is_api, organization_id
+ )
+ # Convert to FileBatchResponse for type safety
+ return FileBatchResponse.from_api_response(response)
+
+ def update_pipeline_status(
+ self,
+ pipeline_id: str | UUID,
+ status: str,
+ organization_id: str | None = None,
+ execution_id: str | UUID | None = None, # Optional for backward compatibility
+ **kwargs,
+ ) -> dict[str, Any]:
+ """Update pipeline status with flexible parameters."""
+ return self.execution_client.update_pipeline_status(
+ pipeline_id, status, organization_id, execution_id, **kwargs
+ ).data
+
+ def batch_update_pipeline_status(
+ self, updates: list[dict[str, Any]], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Update multiple pipeline statuses in a single request.
+
+ For now, this processes updates individually until a batch endpoint is available.
+ """
+ results = {"success": True, "updated": 0, "errors": []}
+
+ for update in updates:
+ try:
+ pipeline_id = update.pop("pipeline_id")
+ execution_id = update.pop("execution_id")
+ status = update.pop("status")
+
+ # Call individual update with remaining kwargs (last_run_time, last_run_status, etc)
+ self.update_pipeline_status(
+ pipeline_id=pipeline_id,
+ status=status,
+ organization_id=organization_id,
+ execution_id=execution_id, # Pass as optional parameter
+ **update,
+ )
+ results["updated"] += 1
+ except Exception as e:
+ results["errors"].append({"pipeline_id": pipeline_id, "error": str(e)})
+ results["success"] = False
+
+ return results
+
+ # Workflow execution finalization handled by status updates
+
+ def cleanup_execution_resources(
+ self, execution_ids: list[str | uuid.UUID], cleanup_types: list | None = None
+ ) -> dict[str, Any]:
+ """Cleanup execution resources."""
+ return self.execution_client.cleanup_execution_resources(
+ execution_ids, cleanup_types
+ )
+
+ # get_execution_finalization_status method removed - it was dead code
+ # Only used by finalize_execution_callback which was never called
+
+ def increment_completed_files(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any]:
+ """Increment completed files count for execution."""
+ return self.execution_client.increment_completed_files(workflow_id, execution_id)
+
+ def increment_failed_files(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any]:
+ """Increment failed files count for execution."""
+ return self.execution_client.increment_failed_files(workflow_id, execution_id)
+
+ def get_workflow_destination_config(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any]:
+ """Get destination configuration for workflow execution."""
+ return self.execution_client.get_workflow_destination_config(
+ workflow_id, execution_id
+ )
+
+ # Delegate file client methods
+ def get_workflow_file_execution(
+ self, file_execution_id: str | UUID, organization_id: str | None = None
+ ) -> WorkflowFileExecutionData:
+ """Get an existing workflow file execution by ID."""
+ return self.file_client.get_workflow_file_execution(
+ file_execution_id, organization_id
+ )
+
+ def get_or_create_workflow_file_execution(
+ self,
+ execution_id: str | UUID,
+ file_hash: dict[str, Any] | FileHashData,
+ workflow_id: str | UUID,
+ organization_id: str | None = None,
+ force_create: bool = False,
+ ) -> WorkflowFileExecutionData:
+ """Get or create a workflow file execution record using shared dataclasses."""
+ return self.file_client.get_or_create_workflow_file_execution(
+ execution_id, file_hash, workflow_id, organization_id, force_create
+ )
+
+ def update_workflow_file_execution_hash(
+ self,
+ file_execution_id: str | UUID,
+ file_hash: str,
+ fs_metadata: dict[str, Any] | None = None,
+ mime_type: str | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Update workflow file execution with computed file hash and mime_type."""
+ return self.file_client.update_workflow_file_execution_hash(
+ file_execution_id, file_hash, fs_metadata, mime_type, organization_id
+ )
+
+ def update_file_execution_status(
+ self,
+ file_execution_id: str | UUID,
+ status: str,
+ execution_time: float | None = None,
+ error_message: str | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Update workflow file execution status with execution time."""
+ return self.file_client.update_file_execution_status(
+ file_execution_id, status, execution_time, error_message, organization_id
+ )
+
+ def update_workflow_file_execution_status(
+ self,
+ file_execution_id: str,
+ status: str,
+ result: str | None = None,
+ error_message: str | None = None,
+ ) -> dict[str, Any]:
+ """Update WorkflowFileExecution status via internal API using shared dataclasses."""
+ return self.file_client.update_workflow_file_execution_status(
+ file_execution_id, status, result, error_message
+ )
+
+ def update_file_status_to_executing(
+ self,
+ file_execution_id: str | UUID | None,
+ file_name: str,
+ organization_id: str | None = None,
+ ) -> bool:
+ """Common method to update file execution status to EXECUTING with proper error handling.
+
+ This method provides consistent logging and error handling for updating file execution
+ status to EXECUTING across all workflow types (ETL, TASK, API).
+
+ Args:
+ file_execution_id: File execution ID to update
+ file_name: File name for logging purposes
+ organization_id: Optional organization ID override
+
+ Returns:
+ bool: True if update successful, False otherwise
+ """
+ if not file_execution_id:
+ return False
+
+ try:
+ result = self.update_file_execution_status(
+ file_execution_id=file_execution_id,
+ status=ExecutionStatus.EXECUTING.value,
+ organization_id=organization_id,
+ )
+ logger.info(
+ f"Updated file {file_name} (ID: {file_execution_id}) status to EXECUTING :{result}"
+ )
+ return True
+
+ except Exception as status_error:
+ logger.error(
+ f"CRITICAL: Failed to update file {file_name} (ID: {file_execution_id}) status to EXECUTING: {status_error}"
+ )
+ import traceback
+
+ logger.error(f"Traceback: {traceback.format_exc()}")
+ return False
+
+ def create_workflow_file_execution(
+ self,
+ workflow_execution_id: str,
+ file_name: str,
+ file_path: str,
+ file_hash: str,
+ file_execution_id: str | None = None,
+ file_size: int = 0,
+ mime_type: str = "",
+ provider_file_uuid: str | None = None,
+ fs_metadata: dict[str, Any] | None = None,
+ status: str = "QUEUED",
+ ) -> dict[str, Any]:
+ """Create WorkflowFileExecution record via internal API with complete metadata."""
+ return self.file_client.create_workflow_file_execution(
+ workflow_execution_id,
+ file_name,
+ file_path,
+ file_hash,
+ file_execution_id,
+ file_size,
+ mime_type,
+ provider_file_uuid,
+ fs_metadata,
+ status,
+ )
+
+ def batch_create_file_executions(
+ self, file_executions: list[dict[str, Any]], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Create multiple file executions in a single batch request."""
+ return self.file_client.batch_create_file_executions(
+ file_executions, organization_id
+ )
+
+ def batch_update_file_execution_status(
+ self, status_updates: list[dict[str, Any]], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Update multiple file execution statuses in a single batch request."""
+ return self.file_client.batch_update_file_execution_status(
+ status_updates, organization_id
+ )
+
+ def get_file_history_by_cache_key(
+ self, cache_key: str, workflow_id: str | uuid.UUID, file_path: str | None = None
+ ) -> dict[str, Any]:
+ """Get file history by cache key."""
+ return self.file_client.get_file_history_by_cache_key(
+ cache_key, workflow_id, file_path
+ )
+
+ def reserve_file_processing(
+ self,
+ workflow_id: str | uuid.UUID,
+ cache_key: str,
+ provider_file_uuid: str | None = None,
+ file_path: str | None = None,
+ worker_id: str | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Atomic check-and-reserve operation for file processing deduplication."""
+ result = self.file_client.reserve_file_processing(
+ workflow_id,
+ cache_key,
+ provider_file_uuid,
+ file_path,
+ worker_id,
+ organization_id,
+ )
+ return (
+ result.data if result.success else {"reserved": False, "error": result.error}
+ )
+
+ def create_file_history(
+ self,
+ file_path: str,
+ file_name: str,
+ source_connection_type: str,
+ workflow_id: str | uuid.UUID,
+ result: str | None = None,
+ metadata: dict[str, Any] | None = None,
+ status: str = "COMPLETED",
+ error: str | None = None,
+ provider_file_uuid: str | None = None,
+ is_api: bool = False,
+ file_size: int = 0,
+ file_hash: str = "",
+ mime_type: str = "",
+ ) -> dict[str, Any]:
+ """Create file history record matching backend expected format."""
+ return self.file_client.create_file_history(
+ file_path=file_path,
+ file_name=file_name,
+ source_connection_type=source_connection_type,
+ workflow_id=workflow_id,
+ result=result,
+ metadata=metadata,
+ status=status,
+ error=error,
+ provider_file_uuid=provider_file_uuid,
+ is_api=is_api,
+ file_size=file_size,
+ file_hash=file_hash,
+ mime_type=mime_type,
+ )
+
+ def get_file_history_status(self, file_history_id: str | uuid.UUID) -> dict[str, Any]:
+ """Get file history status."""
+ return self.file_client.get_file_history_status(file_history_id)
+
+ def get_file_history(
+ self,
+ workflow_id: str | uuid.UUID,
+ provider_file_uuid: str | None = None,
+ file_hash: str | None = None,
+ file_path: str | None = None,
+ organization_id: str | None = None,
+ ) -> FileHistoryResponse:
+ """Get file history by provider_file_uuid or file_hash.
+
+ This unified method handles both lookup patterns:
+ 1. By provider_file_uuid (for cloud storage files with unique IDs)
+ 2. By file_hash (content-based deduplication)
+
+ Args:
+ workflow_id: Workflow ID to check file history for
+ provider_file_uuid: Provider file UUID to search for (cloud storage)
+ file_hash: File content hash to search for (content-based)
+ file_path: Optional file path for additional filtering
+ organization_id: Organization ID for context
+
+ Returns:
+ FileHistoryResponse with file_history data
+ """
+ # If file_hash is provided, use the existing cache key lookup
+ if file_hash and not provider_file_uuid:
+ response = self.get_file_history_by_cache_key(
+ cache_key=file_hash, workflow_id=workflow_id, file_path=file_path
+ )
+ return FileHistoryResponse.from_api_response(response)
+
+ # Otherwise, use provider_file_uuid lookup
+ endpoint = "v1/file-history/get/"
+
+ payload = {
+ "workflow_id": str(workflow_id),
+ "provider_file_uuid": provider_file_uuid,
+ "file_path": file_path,
+ "organization_id": organization_id or self.organization_id,
+ }
+
+ try:
+ response = self.base_client._make_request(
+ method="POST",
+ endpoint=endpoint,
+ data=payload,
+ timeout=self.base_client.config.api_timeout,
+ organization_id=organization_id,
+ )
+
+ logger.debug(
+ f"File history lookup for provider_file_uuid {provider_file_uuid}: "
+ f"{'found' if response.get('file_history') else 'not found'}"
+ )
+ return FileHistoryResponse.from_api_response(response)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get file history for workflow {workflow_id}, "
+ f"provider_file_uuid {provider_file_uuid}: {str(e)}"
+ )
+ # Return empty result to continue without breaking the flow
+ return FileHistoryResponse(success=False, error=str(e))
+
+ def batch_create_file_history(
+ self, file_histories: list[dict[str, Any]], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Create multiple file history records in a single batch request."""
+ return self.file_client.batch_create_file_history(file_histories, organization_id)
+
+ def get_file_history_flexible(
+ self,
+ workflow_id: str | uuid.UUID,
+ cache_key: str | None = None,
+ provider_file_uuid: str | None = None,
+ file_path: str | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Get file history using flexible parameters (cache_key OR provider_file_uuid)."""
+ return self.file_client.get_file_history_flexible(
+ workflow_id=workflow_id,
+ cache_key=cache_key,
+ provider_file_uuid=provider_file_uuid,
+ file_path=file_path,
+ organization_id=organization_id,
+ )
+
+ def get_files_history_batch(
+ self,
+ workflow_id: str | uuid.UUID,
+ files: list[dict[str, str]],
+ organization_id: str | None = None,
+ ) -> dict[str, dict[str, Any]]:
+ """Get file history for multiple files in a single batch operation."""
+ return self.file_client.get_files_history_batch(
+ workflow_id=workflow_id,
+ files=files,
+ organization_id=organization_id,
+ )
+
+ # Delegate webhook client methods
+ def send_webhook(
+ self,
+ url: str,
+ payload: dict[str, Any],
+ notification_id: str | None = None,
+ authorization_type: str = "NONE",
+ authorization_key: str | None = None,
+ authorization_header: str | None = None,
+ timeout: int = 30,
+ max_retries: int = 3,
+ retry_delay: int = 5,
+ headers: dict[str, str] | None = None,
+ ) -> dict[str, Any]:
+ """Send webhook notification to external endpoint."""
+ return self.webhook_client.send_webhook(
+ url,
+ payload,
+ notification_id,
+ authorization_type,
+ authorization_key,
+ authorization_header,
+ timeout,
+ max_retries,
+ retry_delay,
+ headers,
+ )
+
+ def send_webhook_notification(
+ self,
+ notification_request: WebhookNotificationRequest,
+ ) -> dict[str, Any]:
+ """Send webhook notification using type-safe NotificationRequest dataclass.
+
+ Args:
+ notification_request: WebhookNotificationRequest dataclass with notification details
+
+ Returns:
+ Dictionary with webhook response data
+ """
+ return self.webhook_client.send_webhook(
+ url=notification_request.url,
+ payload=notification_request.payload,
+ notification_id=notification_request.notification_id,
+ authorization_type=notification_request.authorization_type,
+ authorization_key=notification_request.authorization_key,
+ authorization_header=notification_request.authorization_header,
+ timeout=notification_request.timeout,
+ max_retries=notification_request.max_retries,
+ retry_delay=notification_request.retry_delay,
+ headers=notification_request.headers,
+ )
+
+ def get_webhook_status(self, task_id: str) -> dict[str, Any]:
+ """Get webhook delivery status by task ID."""
+ return self.webhook_client.get_webhook_status(task_id)
+
+ def test_webhook(
+ self,
+ url: str,
+ payload: dict[str, Any],
+ authorization_type: str = "NONE",
+ authorization_key: str | None = None,
+ authorization_header: str | None = None,
+ timeout: int = 10,
+ ) -> dict[str, Any]:
+ """Test webhook configuration and connectivity."""
+ return self.webhook_client.test_webhook(
+ url,
+ payload,
+ authorization_type,
+ authorization_key,
+ authorization_header,
+ timeout,
+ )
+
+ # Delegate tool client methods (removing duplicates)
+ def get_tool_instances_by_workflow_tool_client(
+ self, workflow_id: str | uuid.UUID
+ ) -> dict[str, Any]:
+ """Get tool instances for a workflow using tool client."""
+ # Use the tool client for consistency
+ result = self.tool_client.get_tool_instances_by_workflow(workflow_id)
+ return result.data if hasattr(result, "data") else result
+
+ # File history methods
+ def check_file_history_batch(
+ self,
+ workflow_id: str | uuid.UUID,
+ file_hashes: list[str],
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Check file history for a batch of file hashes.
+
+ Args:
+ workflow_id: Workflow ID to check file history for
+ file_hashes: List of file hashes to check
+ organization_id: Organization ID for context (optional)
+
+ Returns:
+ Dictionary with 'processed_file_hashes' list
+ """
+ endpoint = "v1/workflow-manager/file-history/check-batch/"
+
+ payload = {
+ "workflow_id": str(workflow_id),
+ "file_hashes": file_hashes,
+ "organization_id": organization_id or self.organization_id,
+ }
+
+ try:
+ response = self.base_client._make_request(
+ method="POST",
+ endpoint=endpoint,
+ data=payload,
+ timeout=self.base_client.config.api_timeout,
+ organization_id=organization_id,
+ )
+
+ logger.debug(
+ f"File history batch check for {len(file_hashes)} hashes: {len(response.get('processed_file_hashes', []))} already processed"
+ )
+ return response
+
+ except Exception as e:
+ logger.error(
+ f"Failed to check file history batch for workflow {workflow_id}: {str(e)}"
+ )
+ # Return empty result to continue without file history filtering
+ return {"processed_file_hashes": []}
+
+ # Delegate organization client methods
+ def get_organization_context(self, org_id: str) -> dict[str, Any]:
+ """Get organization context and metadata."""
+ return self.organization_client.get_organization_context(org_id)
+
+ def set_organization_context(self, org_id: str):
+ """Set organization context for subsequent requests."""
+ # Update context on all clients
+ self.base_client.set_organization_context(org_id)
+ self.execution_client.set_organization_context(org_id)
+ self.file_client.set_organization_context(org_id)
+ self.webhook_client.set_organization_context(org_id)
+ self.organization_client.set_organization_context(org_id)
+ self.tool_client.set_organization_context(org_id)
+ self.workflow_client.set_organization_context(org_id)
+ self.usage_client.set_organization_context(org_id)
+
+ # Note: Manual review org context handled by plugins
+
+ # Update facade attributes
+ self.organization_id = org_id
+
+ logger.debug(f"Set organization context to {org_id} on all clients")
+
+ def clear_organization_context(self):
+ """Clear organization context."""
+ # Clear context on all clients
+ self.base_client.clear_organization_context()
+ self.execution_client.clear_organization_context()
+ self.file_client.clear_organization_context()
+ self.webhook_client.clear_organization_context()
+ self.organization_client.clear_organization_context()
+ self.tool_client.clear_organization_context()
+ self.workflow_client.clear_organization_context()
+ self.usage_client.clear_organization_context()
+
+ # Note: Manual review org context clearing handled by plugins
+
+ # Update facade attributes
+ self.organization_id = None
+
+ logger.debug("Cleared organization context on all clients")
+
+ # Manual review functionality is handled by enterprise plugins, not exposed in OSS API client
+
+ # Delegate tool client methods (consolidated)
+ def execute_tool(
+ self,
+ tool_instance_id: str | uuid.UUID,
+ input_data: dict[str, Any],
+ file_data: dict[str, Any] | None = None,
+ execution_context: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Execute a tool instance with provided data."""
+ result = self.tool_client.execute_tool(
+ tool_instance_id, input_data, file_data, execution_context
+ )
+ return result.data if hasattr(result, "data") else result
+
+ def get_tool_execution_status(self, execution_id: str | uuid.UUID) -> dict[str, Any]:
+ """Get tool execution status by execution ID."""
+ result = self.tool_client.get_tool_execution_status(execution_id)
+ return result.data if hasattr(result, "data") else result
+
+ def get_tool_by_id(self, tool_id: str | uuid.UUID) -> dict[str, Any]:
+ """Get tool information by tool ID."""
+ return self.base_client.get(
+ self.base_client._build_url("tool_execution", f"tool/{str(tool_id)}/")
+ )
+
+ # HTTP method helpers (delegate to base client)
+ def get(
+ self,
+ endpoint: str,
+ params: dict[str, Any] | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Make GET request."""
+ return self.base_client.get(endpoint, params, organization_id)
+
+ def post(
+ self, endpoint: str, data: dict[str, Any], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Make POST request."""
+ return self.base_client.post(endpoint, data, organization_id)
+
+ def put(
+ self, endpoint: str, data: dict[str, Any], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Make PUT request."""
+ return self.base_client.put(endpoint, data, organization_id)
+
+ def patch(
+ self, endpoint: str, data: dict[str, Any], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Make PATCH request."""
+ return self.base_client.patch(endpoint, data, organization_id)
+
+ def delete(self, endpoint: str, organization_id: str | None = None) -> dict[str, Any]:
+ """Make DELETE request."""
+ return self.base_client.delete(endpoint, organization_id)
+
+ # Private helpers for internal access
+ def _build_url(self, endpoint_key: str, path: str = "") -> str:
+ """Build consistent API URL using endpoint patterns."""
+ return self.base_client._build_url(endpoint_key, path)
+
+ def _make_request(
+ self,
+ method: str,
+ endpoint: str,
+ data: dict[str, Any] | None = None,
+ params: dict[str, Any] | None = None,
+ timeout: int | None = None,
+ max_retries: int = 3,
+ backoff_factor: float = 0.5,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Enhanced HTTP request with robust error handling and retry logic."""
+ return self.base_client._make_request(
+ method,
+ endpoint,
+ data,
+ params,
+ timeout,
+ max_retries,
+ backoff_factor,
+ organization_id,
+ )
+
+ def get_endpoint_config(self) -> dict[str, str]:
+ """Get current API endpoint configuration for debugging."""
+ return self.base_client.get_endpoint_config()
+
+ # Manual Review API methods (delegated to ManualReviewAPIClient)
+ def validate_manual_review_db_rule(
+ self,
+ execution_result: Any,
+ workflow_id: str | UUID,
+ file_destination: str | None = None,
+ organization_id: str | None = None,
+ ) -> bool:
+ """Validate if document should go to manual review based on DB rules."""
+ return self.manual_review_client.validate_manual_review_db_rule(
+ execution_result=execution_result,
+ workflow_id=workflow_id,
+ file_destination=file_destination,
+ organization_id=organization_id,
+ )
+
+ def enqueue_manual_review(
+ self,
+ queue_name: str,
+ message: dict[str, Any],
+ organization_id: str | None = None,
+ ) -> bool:
+ """Enqueue document for manual review."""
+ return self.manual_review_client.enqueue_manual_review(
+ queue_name=queue_name,
+ message=message,
+ organization_id=organization_id,
+ )
+
+ def route_to_manual_review(
+ self,
+ file_execution_id: str,
+ file_data: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Route file to manual review queue (delegates to manual review client)."""
+ return self.manual_review_client.route_to_manual_review(
+ file_execution_id=file_execution_id,
+ file_data=file_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=organization_id or self.organization_id,
+ )
+
+ def route_to_manual_review_with_results(
+ self,
+ file_execution_id: str,
+ file_data: dict[str, Any],
+ workflow_result: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str | None = None,
+ file_name: str = "unknown",
+ ) -> dict[str, Any]:
+ """Route file to manual review with tool execution results (delegates to manual review client)."""
+ return self.manual_review_client.route_with_results(
+ file_execution_id=file_execution_id,
+ file_data=file_data,
+ workflow_result=workflow_result,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=organization_id or self.organization_id,
+ file_name=file_name,
+ )
+
+ # Configuration client methods
+ def get_configuration(
+ self,
+ config_key: str,
+ organization_id: str | None = None,
+ ) -> "APIResponse":
+ """Get organization configuration value.
+
+ Args:
+ config_key: Configuration key name (e.g., "MAX_PARALLEL_FILE_BATCHES")
+ organization_id: Organization ID (uses client default if not provided)
+
+ Returns:
+ APIResponse with configuration data
+ """
+ try:
+ response = self._make_request(
+ method=HTTPMethod.GET,
+ endpoint=f"v1/configuration/{config_key}/",
+ params={"organization_id": organization_id or self.organization_id},
+ )
+
+ return response
+
+ except Exception as e:
+ logger.error(f"Error getting configuration {config_key}: {e}")
+ from .data.models import APIResponse
+
+ return APIResponse(
+ success=False,
+ error=str(e),
+ )
+
+ # Usage client methods (delegate to UsageAPIClient)
+ def get_aggregated_token_count(
+ self, file_execution_id: str, organization_id: str | None = None
+ ) -> UsageResponseData | None:
+ """Get aggregated token usage data for a file execution (backward compatibility wrapper).
+
+ Args:
+ file_execution_id: File execution ID to get usage data for
+ organization_id: Optional organization ID override
+
+ Returns:
+ Dictionary with aggregated usage data for backward compatibility
+ """
+ response = self.usage_client.get_aggregated_token_count(
+ file_execution_id, organization_id
+ )
+
+ if response.success and response.data:
+ # Return dict format for backward compatibility with existing code
+ return response.data
+ else:
+ logger.warning(
+ f"No usage data found for file_execution_id {file_execution_id}"
+ )
+ return None
+
+ # Export all classes and exceptions for backward compatibility
+ # =============================
+ # CACHE MANAGEMENT UTILITIES
+ # =============================
+ # These methods provide cache management without overriding existing methods
+ # The caching happens transparently in the execution client methods
+
+ def get_api_cache_stats(self) -> dict[str, Any]:
+ """Get API client cache statistics."""
+ if hasattr(self, "_cache") and self._cache.backend.available:
+ return self.get_cache_stats()
+ return {"available": False, "message": "Cache not available"}
+
+ def clear_api_cache_stats(self):
+ """Clear API client cache statistics."""
+ if hasattr(self, "_cache") and self._cache.backend.available:
+ self.clear_cache_stats()
+
+ def invalidate_workflow_related_cache(self, workflow_id: str):
+ """Invalidate all cache entries related to a workflow."""
+ if hasattr(self, "_cache") and self._cache.backend.available:
+ self.invalidate_workflow_cache(workflow_id)
+ logger.info(f"Invalidated all cache entries for workflow {workflow_id}")
+ else:
+ logger.debug(
+ f"Cache not available, skipping invalidation for workflow {workflow_id}"
+ )
+
+
+__all__ = [
+ # Main facade class
+ "InternalAPIClient",
+ # Exceptions
+ "InternalAPIClientError",
+ "APIRequestError",
+ "AuthenticationError",
+ # Data models
+ "WorkflowFileExecutionData",
+ "FileHashData",
+ "FileExecutionCreateRequest",
+ "FileExecutionStatusUpdateRequest",
+]
diff --git a/workers/shared/cache/__init__.py b/workers/shared/cache/__init__.py
new file mode 100644
index 000000000..1ddd66bff
--- /dev/null
+++ b/workers/shared/cache/__init__.py
@@ -0,0 +1,24 @@
+"""API Client Caching Framework
+
+This package provides caching functionality for API client operations to reduce
+internal API calls and improve performance for relatively static data.
+"""
+
+from .cache_backends import BaseCacheBackend, RedisCacheBackend
+from .cache_decorator import with_cache
+from .cache_keys import CacheKeyGenerator
+from .cache_manager import CacheManager
+from .cached_client_mixin import CachedAPIClientMixin
+
+# Backward compatibility alias
+APIClientCache = CacheManager
+
+__all__ = [
+ "CacheManager",
+ "APIClientCache",
+ "BaseCacheBackend",
+ "RedisCacheBackend",
+ "CacheKeyGenerator",
+ "CachedAPIClientMixin",
+ "with_cache",
+]
diff --git a/workers/shared/cache/cache_backends.py b/workers/shared/cache/cache_backends.py
new file mode 100644
index 000000000..695ba7665
--- /dev/null
+++ b/workers/shared/cache/cache_backends.py
@@ -0,0 +1,357 @@
+"""Cache Backend Implementations
+
+This module provides abstract and concrete cache backend implementations:
+- BaseCacheBackend: Abstract interface for cache backends
+- RedisCacheBackend: Redis-based cache implementation
+"""
+
+import json
+import logging
+from abc import ABC, abstractmethod
+from datetime import UTC, datetime
+from typing import Any
+
+from .redis_client import RedisClient
+
+logger = logging.getLogger(__name__)
+
+
+class BaseCacheBackend(ABC):
+ """Abstract base class for cache backends."""
+
+ @abstractmethod
+ def get(self, key: str) -> dict[str, Any] | None:
+ """Get value from cache."""
+ pass
+
+ @abstractmethod
+ def set(self, key: str, value: dict[str, Any], ttl: int) -> bool:
+ """Set value in cache with TTL."""
+ pass
+
+ @abstractmethod
+ def delete(self, key: str) -> bool:
+ """Delete key from cache."""
+ pass
+
+ @abstractmethod
+ def delete_pattern(self, pattern: str) -> int:
+ """Delete keys matching pattern."""
+ pass
+
+ @abstractmethod
+ def mget(self, keys: list[str]) -> dict[str, Any]:
+ """Get multiple values from cache in a single operation.
+
+ Args:
+ keys: List of cache keys to retrieve
+
+ Returns:
+ Dict mapping keys to their values (only includes keys that exist)
+ """
+ pass
+
+ @abstractmethod
+ def mset(self, data: dict[str, tuple[dict[str, Any], int]]) -> int:
+ """Set multiple values in cache with individual TTLs.
+
+ Args:
+ data: Dict mapping keys to (value, ttl) tuples
+
+ Returns:
+ Number of keys successfully set
+ """
+ pass
+
+ @abstractmethod
+ def keys(self, pattern: str) -> list[str]:
+ """Get keys matching a pattern."""
+ pass
+
+ @abstractmethod
+ def scan_keys(self, pattern: str, count: int = 100) -> list[str]:
+ """Non-blocking scan for keys matching a pattern using SCAN cursor."""
+ pass
+
+
+class RedisCacheBackend(BaseCacheBackend):
+ """Redis-based cache backend for workers."""
+
+ def __init__(self, config=None):
+ """Initialize Redis cache backend with configurable settings.
+
+ Args:
+ config: WorkerConfig instance or None to create default config
+ """
+ try:
+ # Use provided config or create default one
+ if config is None:
+ from ..infrastructure.config import WorkerConfig
+
+ config = WorkerConfig()
+
+ # Get Redis cache configuration from WorkerConfig
+ cache_config = config.get_cache_redis_config()
+
+ if not cache_config.get("enabled", False):
+ logger.info("Redis cache disabled in configuration")
+ self.redis_client = None
+ self.available = False
+ return
+
+ # Initialize RedisClient with cache configuration
+ self.redis_client = RedisClient(
+ host=cache_config["host"],
+ port=cache_config["port"],
+ username=cache_config.get("username"),
+ password=cache_config.get("password"),
+ db=cache_config["db"],
+ decode_responses=True,
+ socket_timeout=5,
+ socket_connect_timeout=5,
+ )
+
+ # Test connection
+ if not self.redis_client.ping():
+ raise ConnectionError("Failed to ping Redis server")
+
+ self.available = True
+ logger.info(
+ f"RedisCacheBackend initialized successfully: {cache_config['host']}:{cache_config['port']}/{cache_config['db']}"
+ )
+
+ except ImportError:
+ logger.error("Redis module not available - install with: pip install redis")
+ self.redis_client = None
+ self.available = False
+ except Exception as e:
+ logger.warning(f"Failed to initialize RedisCacheBackend: {e}")
+ self.redis_client = None
+ self.available = False
+
+ def get(self, key: str) -> dict[str, Any] | None:
+ """Get value from Redis cache."""
+ if not self.available:
+ return None
+
+ try:
+ data_str = self.redis_client.get(key)
+ data = json.loads(data_str) if data_str else None
+
+ if data:
+ # Check if cached data has timestamp and is still valid
+ if isinstance(data, dict) and "cached_at" in data:
+ return data
+ # Backward compatibility for data without metadata
+ return {"data": data, "cached_at": datetime.now(UTC).isoformat()}
+ return None
+ except Exception as e:
+ logger.error(f"Error getting cache key {key}: {e}")
+ return None
+
+ def set(self, key: str, value: dict[str, Any], ttl: int) -> bool:
+ """Set value in Redis cache with TTL."""
+ if not self.available:
+ return False
+
+ try:
+ # Add metadata to cached data
+ cache_data = {
+ "data": value,
+ "cached_at": datetime.now(UTC).isoformat(),
+ "ttl": ttl,
+ }
+
+ self.redis_client.setex(key, ttl, json.dumps(cache_data))
+ logger.debug(f"Cached key {key} with TTL {ttl}s")
+ return True
+ except Exception as e:
+ logger.error(f"Error setting cache key {key}: {e}")
+ return False
+
+ def delete(self, key: str) -> bool:
+ """Delete key from Redis cache."""
+ if not self.available:
+ return False
+
+ try:
+ deleted_count = self.redis_client.delete(key)
+ logger.debug(f"Deleted cache key {key} (count: {deleted_count})")
+ return deleted_count > 0
+ except Exception as e:
+ logger.error(f"Error deleting cache key {key}: {e}")
+ return False
+
+ def keys(self, pattern: str) -> list[str]:
+ """Get keys matching pattern.
+
+ ⚠️ WARNING: This method uses Redis KEYS command which can block the server!
+ For production use, prefer scan_keys() which uses non-blocking SCAN.
+ """
+ if not self.available:
+ return []
+
+ try:
+ # Log warning about blocking operation
+ logger.warning(
+ f"Using blocking KEYS command with pattern '{pattern}'. "
+ "Consider using scan_keys() for production safety."
+ )
+
+ keys = self.redis_client.keys(pattern)
+ # Convert bytes to strings if needed
+ return [
+ key.decode("utf-8") if isinstance(key, bytes) else key for key in keys
+ ]
+ except Exception as e:
+ logger.error(f"Error getting keys for pattern {pattern}: {e}")
+ return []
+
+ def delete_pattern(self, pattern: str) -> int:
+ """Delete keys matching pattern using non-blocking SCAN."""
+ if not self.available:
+ return 0
+
+ try:
+ # Use non-blocking SCAN instead of blocking KEYS
+ keys = self.scan_keys(pattern)
+ if keys:
+ count = self.redis_client.delete(*keys)
+ logger.debug(
+ f"Deleted {count} keys matching pattern {pattern} (using SCAN)"
+ )
+ return count
+ return 0
+ except Exception as e:
+ logger.error(f"Error deleting pattern {pattern}: {e}")
+ return 0
+
+ def scan_keys(self, pattern: str, count: int = 100) -> list[str]:
+ """Non-blocking scan for keys matching a pattern using SCAN cursor.
+
+ This replaces the blocking KEYS command with SCAN for production safety.
+ SCAN iterates through the keyspace in small chunks, preventing Redis blocking.
+
+ Args:
+ pattern: Redis pattern to match (e.g., "file_active:*")
+ count: Hint for number of keys to return per SCAN iteration
+
+ Returns:
+ List of matching keys
+ """
+ if not self.available:
+ return []
+
+ try:
+ keys = []
+ cursor = 0
+
+ # Use SCAN cursor to iterate through keyspace non-blocking
+ while True:
+ # SCAN returns (new_cursor, list_of_keys)
+ cursor, batch_keys = self.redis_client.scan(
+ cursor=cursor, match=pattern, count=count
+ )
+
+ # Convert bytes to strings if needed and add to result
+ batch_keys_str = [
+ key.decode("utf-8") if isinstance(key, bytes) else key
+ for key in batch_keys
+ ]
+ keys.extend(batch_keys_str)
+
+ # cursor=0 means we've completed the full iteration
+ if cursor == 0:
+ break
+
+ logger.debug(f"SCAN found {len(keys)} keys matching pattern {pattern}")
+ return keys
+
+ except Exception as e:
+ logger.error(f"Error scanning keys for pattern {pattern}: {e}")
+ return []
+
+ def mget(self, keys: list[str]) -> dict[str, Any]:
+ """Get multiple values from Redis cache in a single operation.
+
+ Args:
+ keys: List of cache keys to retrieve
+
+ Returns:
+ Dict mapping keys to their values (only includes keys that exist)
+ """
+ if not self.available or not keys:
+ return {}
+
+ try:
+ # Use Redis mget for batch retrieval
+ values = self.redis_client.mget(keys)
+ result = {}
+
+ for key, value_str in zip(keys, values, strict=False):
+ if value_str: # Skip None values (missing keys)
+ try:
+ data = json.loads(value_str)
+ if data:
+ # Check if cached data has timestamp and is still valid
+ if isinstance(data, dict) and "cached_at" in data:
+ result[key] = data
+ else:
+ # Backward compatibility for data without metadata
+ result[key] = {
+ "data": data,
+ "cached_at": datetime.now(UTC).isoformat(),
+ }
+ except json.JSONDecodeError:
+ logger.warning(f"Invalid JSON in cache key {key}, skipping")
+
+ logger.debug(f"Batch retrieved {len(result)}/{len(keys)} cache keys")
+ return result
+
+ except Exception as e:
+ logger.error(f"Error batch getting cache keys: {e}")
+ return {}
+
+ def mset(self, data: dict[str, tuple[dict[str, Any], int]]) -> int:
+ """Set multiple values in Redis cache with individual TTLs.
+
+ Args:
+ data: Dict mapping keys to (value, ttl) tuples
+
+ Returns:
+ Number of keys successfully set
+ """
+ if not self.available or not data:
+ return 0
+
+ try:
+ # Use Redis pipeline for efficient batch operations
+ pipe = self.redis_client.pipeline()
+ successful_keys = 0
+
+ for key, (value, ttl) in data.items():
+ try:
+ # Add metadata to cached data
+ cache_data = {
+ "data": value,
+ "cached_at": datetime.now(UTC).isoformat(),
+ "ttl": ttl,
+ }
+
+ # Use pipeline to batch the setex operations
+ pipe.setex(key, ttl, json.dumps(cache_data))
+ successful_keys += 1
+
+ except Exception as key_error:
+ logger.warning(f"Failed to prepare cache key {key}: {key_error}")
+
+ # Execute all operations in the pipeline
+ if successful_keys > 0:
+ pipe.execute()
+ logger.debug(f"Batch set {successful_keys} cache keys")
+
+ return successful_keys
+
+ except Exception as e:
+ logger.error(f"Error batch setting cache keys: {e}")
+ return 0
diff --git a/workers/shared/cache/cache_decorator.py b/workers/shared/cache/cache_decorator.py
new file mode 100644
index 000000000..044b9240f
--- /dev/null
+++ b/workers/shared/cache/cache_decorator.py
@@ -0,0 +1,148 @@
+"""Cache decorator for API client methods.
+
+This module provides a clean decorator-based approach for caching API responses
+without repetitive checks or hasattr calls.
+"""
+
+import functools
+import logging
+from collections.abc import Callable
+from typing import Union
+
+from .cache_keys import CacheKeyGenerator
+from .cache_types import CacheType
+
+logger = logging.getLogger(__name__)
+
+
+def with_cache(
+ cache_type: Union[str, "CacheType"],
+ key_extractor: Callable | None = None,
+ ttl: int | None = None,
+):
+ """Decorator to add caching to API client methods.
+
+ This decorator:
+ - Automatically checks if caching is available
+ - Handles cache hits/misses
+ - Caches successful results
+ - Falls back gracefully when cache is unavailable
+
+ Args:
+ cache_type: Type of cache operation (CacheType enum or string)
+ key_extractor: Optional function to extract cache key from arguments
+ ttl: Optional TTL override in seconds
+
+ Example:
+ @with_cache(CacheType.WORKFLOW, lambda self, wf_id, org_id: str(wf_id))
+ def get_workflow_definition(self, workflow_id, organization_id=None):
+ # Method implementation
+ """
+
+ def decorator(func: Callable) -> Callable:
+ @functools.wraps(func)
+ def wrapper(self, *args, **kwargs):
+ # Try to use cache if available (no hasattr needed)
+ try:
+ if getattr(self, "_cache", None) and self._cache.backend.available:
+ # Generate cache key
+ if key_extractor:
+ cache_key_suffix = key_extractor(self, *args, **kwargs)
+ else:
+ # Default: use first argument as key
+ cache_key_suffix = str(args[0]) if args else "default"
+
+ # Convert enum to string value if needed
+ from .cache_types import CacheType
+
+ cache_type_str = (
+ cache_type.value
+ if hasattr(cache_type, "value")
+ else str(cache_type)
+ )
+
+ # Build full cache key based on cache type
+ if cache_type_str == CacheType.WORKFLOW.value:
+ cache_key = CacheKeyGenerator.workflow_key(cache_key_suffix)
+ elif cache_type_str == CacheType.API_DEPLOYMENT.value:
+ # Need org_id for API deployment
+ org_id = kwargs.get("organization_id") or getattr(
+ self, "organization_id", None
+ )
+ if org_id:
+ cache_key = CacheKeyGenerator.api_deployment_key(
+ cache_key_suffix, org_id
+ )
+ else:
+ cache_key = None
+ elif cache_type_str == CacheType.TOOL_INSTANCES.value:
+ cache_key = CacheKeyGenerator.tool_instances_key(cache_key_suffix)
+ elif cache_type_str == CacheType.WORKFLOW_ENDPOINTS.value:
+ cache_key = CacheKeyGenerator.workflow_endpoints_key(
+ cache_key_suffix
+ )
+ else:
+ cache_key = CacheKeyGenerator.custom_key(
+ cache_type_str, cache_key_suffix
+ )
+
+ # Check cache if we have a valid key
+ if cache_key:
+ cached_result = self._cache.get(cache_key, cache_type_str)
+ if cached_result is not None:
+ logger.debug(
+ f"Cache HIT for {func.__name__} (key: {cache_key})"
+ )
+ return cached_result
+ logger.debug(f"Cache MISS for {func.__name__} (key: {cache_key})")
+
+ # Call original method
+ result = func(self, *args, **kwargs)
+
+ # Cache successful results
+ if cache_key and result:
+ # Check if result indicates success
+ is_successful = (
+ (hasattr(result, "success") and result.success)
+ or (isinstance(result, dict) and result.get("success"))
+ or (
+ not hasattr(result, "success")
+ ) # Assume success if no success attribute
+ )
+
+ if is_successful:
+ self._cache.set(cache_key, result, cache_type_str, ttl)
+ logger.debug(
+ f"Cached result for {func.__name__} (key: {cache_key})"
+ )
+
+ return result
+ else:
+ # No cache available, just call the method
+ return func(self, *args, **kwargs)
+
+ except Exception as e:
+ # If anything goes wrong with caching, just call the original method
+ logger.debug(
+ f"Cache error in {func.__name__}: {e}, falling back to direct call"
+ )
+ return func(self, *args, **kwargs)
+
+ return wrapper
+
+ return decorator
+
+
+def cache_key_from_first_arg(self, *args, **kwargs) -> str:
+ """Extract cache key from first argument."""
+ return str(args[0]) if args else "default"
+
+
+def cache_key_from_workflow_id(self, workflow_id, *args, **kwargs) -> str:
+ """Extract cache key from workflow_id parameter."""
+ return str(workflow_id)
+
+
+def cache_key_from_api_id(self, api_id, *args, **kwargs) -> str:
+ """Extract cache key from api_id parameter."""
+ return str(api_id)
diff --git a/workers/shared/cache/cache_keys.py b/workers/shared/cache/cache_keys.py
new file mode 100644
index 000000000..1ae71bb9a
--- /dev/null
+++ b/workers/shared/cache/cache_keys.py
@@ -0,0 +1,44 @@
+"""Cache Key Generation Utilities
+
+This module provides consistent cache key generation strategies for different
+types of cached data (workflows, pipelines, API deployments, etc.).
+"""
+
+import hashlib
+
+
+class CacheKeyGenerator:
+ """Generates consistent cache keys for API operations."""
+
+ @staticmethod
+ def workflow_key(workflow_id: str) -> str:
+ """Generate cache key for workflow data."""
+ return f"worker_cache:workflow:{workflow_id}"
+
+ @staticmethod
+ def pipeline_key(pipeline_id: str) -> str:
+ """Generate cache key for pipeline data."""
+ return f"worker_cache:pipeline:{pipeline_id}"
+
+ @staticmethod
+ def api_deployment_key(api_id: str, org_id: str) -> str:
+ """Generate cache key for API deployment data."""
+ return f"worker_cache:api_deployment:{org_id}:{api_id}"
+
+ @staticmethod
+ def tool_instances_key(workflow_id: str) -> str:
+ """Generate cache key for tool instances."""
+ return f"worker_cache:tool_instances:{workflow_id}"
+
+ @staticmethod
+ def workflow_endpoints_key(workflow_id: str) -> str:
+ """Generate cache key for workflow endpoints."""
+ return f"worker_cache:workflow_endpoints:{workflow_id}"
+
+ @staticmethod
+ def custom_key(operation: str, *args: str) -> str:
+ """Generate cache key for custom operations."""
+ # Create a hash of the arguments for consistent keys
+ # Using SHA-256 for SonarCloud compliance (cache key generation is not security-critical)
+ args_hash = hashlib.sha256(":".join(args).encode()).hexdigest()[:8]
+ return f"worker_cache:{operation}:{args_hash}"
diff --git a/workers/shared/cache/cache_manager.py b/workers/shared/cache/cache_manager.py
new file mode 100644
index 000000000..be535747b
--- /dev/null
+++ b/workers/shared/cache/cache_manager.py
@@ -0,0 +1,190 @@
+"""Cache Manager for API Client Operations
+
+This module provides a high-level caching interface for managing API response data.
+It handles cache operations with statistics tracking, TTL management, and automatic
+serialization/deserialization of cached data.
+"""
+
+import logging
+import time
+from typing import Any
+
+from .cache_backends import BaseCacheBackend, RedisCacheBackend
+from .cache_utils import make_json_serializable, reconstruct_from_cache
+
+logger = logging.getLogger(__name__)
+
+
+class CacheManager:
+ """Main caching interface for API client operations."""
+
+ def __init__(self, backend: BaseCacheBackend | None = None, config=None):
+ """Initialize cache manager.
+
+ Args:
+ backend: Cache backend to use. Defaults to RedisCacheBackend.
+ config: WorkerConfig instance for configuration
+ """
+ from .cache_types import CacheConfig
+
+ self.backend = backend or RedisCacheBackend(config)
+ self.cache_config = CacheConfig
+ self.stats = {"hits": 0, "misses": 0, "sets": 0, "deletes": 0, "errors": 0}
+
+ if self.backend.available:
+ logger.info("CacheManager initialized with Redis backend")
+ else:
+ logger.warning("CacheManager initialized with disabled backend")
+
+ def get(self, key: str, operation_type: str = "default") -> Any | None:
+ """Get value from cache.
+
+ Args:
+ key: Cache key
+ operation_type: Type of operation for TTL selection
+
+ Returns:
+ Cached data or None if not found
+ """
+ if not self.backend.available:
+ return None
+
+ try:
+ start_time = time.time()
+ cached_data = self.backend.get(key)
+
+ if cached_data:
+ self.stats["hits"] += 1
+ response_time = (time.time() - start_time) * 1000
+ logger.debug(
+ f"Cache HIT for {key} (type: {operation_type}) in {response_time:.1f}ms"
+ )
+ # Reconstruct objects from cached data with fallback handling
+ raw_data = cached_data.get("data")
+ try:
+ return reconstruct_from_cache(raw_data)
+ except Exception as e:
+ # Cache reconstruction failed - invalidate corrupted entry and fallback to API
+ logger.warning(
+ f"Cache reconstruction failed for {key}: {e}. Invalidating cache entry."
+ )
+ self.stats["errors"] += 1
+ # Delete the corrupted cache entry
+ self.backend.delete(key)
+ # Return None to trigger cache miss behavior (fallback to API call)
+ return None
+ else:
+ self.stats["misses"] += 1
+ response_time = (time.time() - start_time) * 1000
+ logger.debug(
+ f"Cache MISS for {key} (type: {operation_type}) in {response_time:.1f}ms"
+ )
+ return None
+
+ except Exception as e:
+ self.stats["errors"] += 1
+ logger.error(f"Error getting cache for {key}: {e}")
+ return None
+
+ def set(
+ self, key: str, value: Any, operation_type: str = "custom", ttl: int | None = None
+ ) -> bool:
+ """Set value in cache.
+
+ Args:
+ key: Cache key
+ value: Data to cache
+ operation_type: Type of operation for TTL selection (CacheType enum or string)
+ ttl: Override TTL in seconds
+
+ Returns:
+ True if successful, False otherwise
+ """
+ if not self.backend.available:
+ return False
+
+ try:
+ from .cache_types import CacheConfig, CacheType
+
+ # Convert string to enum if needed
+ if isinstance(operation_type, str):
+ try:
+ cache_type = CacheType(operation_type)
+ except ValueError:
+ cache_type = CacheType.CUSTOM
+ else:
+ cache_type = operation_type
+
+ # Convert value to JSON-serializable format before caching
+ serializable_value = self._make_json_serializable(value)
+
+ effective_ttl = ttl or CacheConfig.get_ttl(cache_type)
+ success = self.backend.set(key, serializable_value, effective_ttl)
+
+ if success:
+ self.stats["sets"] += 1
+ logger.debug(
+ f"Cached {key} (type: {cache_type.value}) with TTL {effective_ttl}s"
+ )
+
+ return success
+
+ except Exception as e:
+ self.stats["errors"] += 1
+ logger.error(f"Error setting cache for {key}: {e}")
+ return False
+
+ def delete(self, key: str) -> bool:
+ """Delete key from cache."""
+ if not self.backend.available:
+ return False
+
+ try:
+ success = self.backend.delete(key)
+ if success:
+ self.stats["deletes"] += 1
+ return success
+ except Exception as e:
+ self.stats["errors"] += 1
+ logger.error(f"Error deleting cache key {key}: {e}")
+ return False
+
+ def invalidate_workflow(self, workflow_id: str):
+ """Invalidate all cache entries related to a workflow."""
+ from .cache_keys import CacheKeyGenerator
+
+ keys_to_delete = [
+ CacheKeyGenerator.workflow_key(workflow_id),
+ CacheKeyGenerator.tool_instances_key(workflow_id),
+ CacheKeyGenerator.workflow_endpoints_key(workflow_id),
+ ]
+
+ for key in keys_to_delete:
+ self.delete(key)
+
+ logger.info(f"Invalidated cache for workflow {workflow_id}")
+
+ def get_stats(self) -> dict[str, Any]:
+ """Get cache statistics."""
+ total_requests = self.stats["hits"] + self.stats["misses"]
+ hit_rate = (
+ (self.stats["hits"] / total_requests * 100) if total_requests > 0 else 0
+ )
+
+ return {
+ **self.stats,
+ "hit_rate": f"{hit_rate:.1f}%",
+ "total_requests": total_requests,
+ "backend_available": self.backend.available,
+ }
+
+ def clear_stats(self):
+ """Clear cache statistics."""
+ self.stats = {key: 0 for key in self.stats}
+
+ def _make_json_serializable(self, obj: Any) -> Any:
+ """Convert an object to JSON-serializable format.
+
+ Delegates to the common serialization utility.
+ """
+ return make_json_serializable(obj)
diff --git a/workers/shared/cache/cache_types.py b/workers/shared/cache/cache_types.py
new file mode 100644
index 000000000..9522a7d66
--- /dev/null
+++ b/workers/shared/cache/cache_types.py
@@ -0,0 +1,134 @@
+"""Cache Type Constants and Enums
+
+This module defines constants for cache types to avoid magic strings
+and provide a single point of configuration for cache operations.
+"""
+
+from enum import Enum
+
+
+class CacheType(str, Enum):
+ """Enumeration of cache types for different API operations.
+
+ Using str enum so values can be used directly as strings while
+ providing IDE autocomplete and validation benefits.
+ """
+
+ # Core workflow operations
+ WORKFLOW = "workflow"
+ WORKFLOW_ENDPOINTS = "workflow_endpoints"
+ WORKFLOW_DEFINITION = "workflow_definition" # Alias for workflow
+
+ # API deployment operations
+ API_DEPLOYMENT = "api_deployment"
+
+ # Tool and component operations
+ TOOL_INSTANCES = "tool_instances"
+
+ # Pipeline operations
+ PIPELINE = "pipeline"
+ PIPELINE_DATA = "pipeline_data"
+
+ # Configuration and system operations
+ CONFIGURATION = "configuration"
+ PLATFORM_SETTINGS = "platform_settings"
+
+ # File and execution operations
+ FILE_BATCH = "file_batch"
+ EXECUTION_DATA = "execution_data"
+
+ # Custom/generic operations
+ CUSTOM = "custom"
+
+
+class CacheConfig:
+ """Configuration for cache operations including TTL values."""
+
+ # Default TTL values for different cache types (in seconds)
+ DEFAULT_TTLS: dict[CacheType, int] = {
+ CacheType.WORKFLOW: 60, # Workflow definitions change infrequently
+ CacheType.WORKFLOW_ENDPOINTS: 60, # Endpoints change infrequently
+ CacheType.WORKFLOW_DEFINITION: 60, # Alias for workflow
+ CacheType.API_DEPLOYMENT: 45, # API deployments may change more often
+ CacheType.TOOL_INSTANCES: 30, # Tool instances may change during development
+ CacheType.PIPELINE: 60, # Pipeline configurations change infrequently
+ CacheType.PIPELINE_DATA: 45, # Pipeline data may update more frequently
+ CacheType.CONFIGURATION: 120, # System configuration changes rarely
+ CacheType.PLATFORM_SETTINGS: 300, # Platform settings change very rarely
+ CacheType.FILE_BATCH: 15, # File batches are more dynamic
+ CacheType.EXECUTION_DATA: 30, # Execution data has moderate lifetime
+ CacheType.CUSTOM: 30, # Default for custom operations
+ }
+
+ @classmethod
+ def get_ttl(cls, cache_type: CacheType) -> int:
+ """Get TTL for a cache type.
+
+ Args:
+ cache_type: The cache type enum value
+
+ Returns:
+ TTL in seconds
+ """
+ return cls.DEFAULT_TTLS.get(cache_type, cls.DEFAULT_TTLS[CacheType.CUSTOM])
+
+ @classmethod
+ def set_ttl(cls, cache_type: CacheType, ttl: int):
+ """Update TTL for a cache type.
+
+ Args:
+ cache_type: The cache type enum value
+ ttl: TTL in seconds
+ """
+ cls.DEFAULT_TTLS[cache_type] = ttl
+
+ @classmethod
+ def get_all_types(cls) -> list[CacheType]:
+ """Get all available cache types.
+
+ Returns:
+ List of all cache type enum values
+ """
+ return list(CacheType)
+
+
+# Convenience constants for commonly used cache types
+# These can be imported directly for cleaner code
+WORKFLOW_CACHE = CacheType.WORKFLOW
+API_DEPLOYMENT_CACHE = CacheType.API_DEPLOYMENT
+TOOL_INSTANCES_CACHE = CacheType.TOOL_INSTANCES
+WORKFLOW_ENDPOINTS_CACHE = CacheType.WORKFLOW_ENDPOINTS
+PIPELINE_CACHE = CacheType.PIPELINE
+CONFIGURATION_CACHE = CacheType.CONFIGURATION
+
+
+# Validation helper
+def validate_cache_type(cache_type: str) -> CacheType:
+ """Validate and convert string to CacheType enum.
+
+ Args:
+ cache_type: String representation of cache type
+
+ Returns:
+ CacheType enum value
+
+ Raises:
+ ValueError: If cache_type is not valid
+ """
+ try:
+ return CacheType(cache_type)
+ except ValueError:
+ valid_types = [t.value for t in CacheType]
+ raise ValueError(f"Invalid cache type '{cache_type}'. Valid types: {valid_types}")
+
+
+# Backward compatibility mapping for any existing string usage
+LEGACY_MAPPING = {
+ "workflow": CacheType.WORKFLOW,
+ "api_deployment": CacheType.API_DEPLOYMENT,
+ "tool_instances": CacheType.TOOL_INSTANCES,
+ "workflow_endpoints": CacheType.WORKFLOW_ENDPOINTS,
+ "pipeline": CacheType.PIPELINE,
+ "configuration": CacheType.CONFIGURATION,
+ "custom": CacheType.CUSTOM,
+}
diff --git a/workers/shared/cache/cache_utils.py b/workers/shared/cache/cache_utils.py
new file mode 100644
index 000000000..e4766ae3c
--- /dev/null
+++ b/workers/shared/cache/cache_utils.py
@@ -0,0 +1,190 @@
+"""Cache Utilities
+
+Common utility functions for cache operations.
+"""
+
+import logging
+from dataclasses import asdict, is_dataclass
+from datetime import datetime
+from enum import Enum
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+def make_json_serializable(obj: Any) -> Any:
+ """Convert an object to JSON-serializable format.
+
+ Handles common non-serializable types like dataclasses, enums, and datetime objects.
+ This is the single source of truth for JSON serialization in the cache system.
+
+ Args:
+ obj: Object to serialize
+
+ Returns:
+ JSON-serializable version of the object with type information for reconstruction
+ """
+
+ def serialize_item(item):
+ if item is None:
+ return None
+ elif isinstance(item, (str, int, float, bool)):
+ return item
+ elif isinstance(item, (list, tuple)):
+ return [serialize_item(i) for i in item]
+ elif isinstance(item, dict):
+ return {k: serialize_item(v) for k, v in item.items()}
+ elif isinstance(item, Enum):
+ return item.value
+ elif isinstance(item, datetime):
+ return item.isoformat()
+ elif is_dataclass(item):
+ # Store type information for reconstruction
+ serialized = serialize_item(asdict(item))
+ return {
+ "__type__": f"{item.__class__.__module__}.{item.__class__.__name__}",
+ "__data__": serialized,
+ }
+ elif hasattr(item, "__dict__"):
+ # Handle objects with __dict__ (like API response objects)
+ serialized = serialize_item(item.__dict__)
+ return {
+ "__type__": f"{item.__class__.__module__}.{item.__class__.__name__}",
+ "__data__": serialized,
+ }
+ else:
+ # Fallback - convert to string
+ return str(item)
+
+ try:
+ return serialize_item(obj)
+ except Exception as e:
+ logger.warning(f"Failed to serialize object for caching: {e}")
+ # Return a simple representation that can be cached
+ return {"error": "serialization_failed", "type": str(type(obj))}
+
+
+def reconstruct_from_cache(cached_data: Any) -> Any:
+ """Reconstruct objects from cached data using type information.
+
+ Args:
+ cached_data: Data retrieved from cache
+
+ Returns:
+ Reconstructed object or original data if no type info
+ """
+
+ def reconstruct_item(item):
+ if item is None:
+ return None
+ elif isinstance(item, (str, int, float, bool)):
+ return item
+ elif isinstance(item, list):
+ return [reconstruct_item(i) for i in item]
+ elif isinstance(item, dict):
+ # Check if this is a typed object
+ if "__type__" in item and "__data__" in item:
+ return reconstruct_typed_object(item["__type__"], item["__data__"])
+ else:
+ return {k: reconstruct_item(v) for k, v in item.items()}
+ else:
+ return item
+
+ try:
+ return reconstruct_item(cached_data)
+ except Exception as e:
+ logger.warning(f"Failed to reconstruct object from cache: {e}")
+ return cached_data
+
+
+def reconstruct_typed_object(type_name: str, data: Any) -> Any:
+ """Reconstruct a typed object from cached data.
+
+ Args:
+ type_name: Full type name (module.ClassName)
+ data: Serialized object data
+
+ Returns:
+ Reconstructed object or original data if reconstruction fails
+ """
+ try:
+ # Registry of reconstructable types - cleaner than hardcoded strings
+ type_registry = _get_type_registry()
+
+ # Extract class name from full type path
+ class_name = type_name.split(".")[-1]
+
+ # Find matching class in registry
+ if class_name in type_registry:
+ cls = type_registry[class_name]
+
+ # Prefer from_dict method if available (handles nested objects properly)
+ if hasattr(cls, "from_dict") and callable(cls.from_dict):
+ logger.debug(f"Using from_dict method for {class_name}")
+ return cls.from_dict(data)
+ else:
+ # Fall back to direct constructor
+ logger.debug(f"Using direct constructor for {class_name}")
+ return cls(**data)
+ else:
+ logger.debug(f"Unknown type for reconstruction: {type_name}")
+ return data
+
+ except Exception as e:
+ logger.warning(f"Failed to reconstruct {type_name}: {e}")
+ return data
+
+
+def _get_type_registry() -> dict[str, type]:
+ """Get registry of reconstructable types.
+
+ Returns:
+ Dictionary mapping class names to classes
+ """
+ try:
+ # Import core data models that are being cached
+ from unstract.core.data_models import (
+ ConnectorInstanceData,
+ TagData,
+ WorkflowDefinitionResponseData,
+ WorkflowEndpointConfigData,
+ WorkflowEndpointConfigResponseData,
+ WorkflowExecutionData,
+ )
+
+ from ..data.response_models import APIResponse
+ from ..models.api_responses import (
+ FileBatchResponse,
+ FileExecutionResponse,
+ FileHistoryResponse,
+ ManualReviewResponse,
+ ToolExecutionResponse,
+ ToolInstancesResponse,
+ WorkflowDefinitionResponse,
+ WorkflowEndpointsResponse,
+ WorkflowExecutionResponse,
+ )
+
+ return {
+ # Standard API response models
+ "APIResponse": APIResponse,
+ "WorkflowEndpointsResponse": WorkflowEndpointsResponse,
+ "ToolInstancesResponse": ToolInstancesResponse,
+ "WorkflowDefinitionResponse": WorkflowDefinitionResponse,
+ "WorkflowExecutionResponse": WorkflowExecutionResponse,
+ "FileExecutionResponse": FileExecutionResponse,
+ "ManualReviewResponse": ManualReviewResponse,
+ "FileBatchResponse": FileBatchResponse,
+ "ToolExecutionResponse": ToolExecutionResponse,
+ "FileHistoryResponse": FileHistoryResponse,
+ # Core data models that are cached
+ "WorkflowEndpointConfigResponseData": WorkflowEndpointConfigResponseData,
+ "WorkflowEndpointConfigData": WorkflowEndpointConfigData,
+ "ConnectorInstanceData": ConnectorInstanceData,
+ "WorkflowDefinitionResponseData": WorkflowDefinitionResponseData,
+ "TagData": TagData,
+ "WorkflowExecutionData": WorkflowExecutionData,
+ }
+ except ImportError as e:
+ logger.warning(f"Failed to import response types for cache reconstruction: {e}")
+ return {}
diff --git a/workers/shared/cache/cached_client_mixin.py b/workers/shared/cache/cached_client_mixin.py
new file mode 100644
index 000000000..33534d45d
--- /dev/null
+++ b/workers/shared/cache/cached_client_mixin.py
@@ -0,0 +1,137 @@
+"""Cached API Client Mixin
+
+This mixin provides caching capabilities for API client operations, designed to be
+mixed into existing API client classes with minimal changes.
+"""
+
+import logging
+from collections.abc import Callable
+from functools import wraps
+from typing import Any
+
+from .cache_keys import CacheKeyGenerator
+from .cache_manager import CacheManager
+from .cache_utils import make_json_serializable, reconstruct_from_cache
+
+logger = logging.getLogger(__name__)
+
+
+def cached_request(
+ operation_type: str, cache_key_func: Callable | None = None, ttl: int | None = None
+):
+ """Decorator for caching API requests.
+
+ Args:
+ operation_type: Type of operation for TTL selection
+ cache_key_func: Function to generate cache key from method arguments
+ ttl: Override TTL in seconds
+ """
+
+ def decorator(func: Callable) -> Callable:
+ @wraps(func)
+ def wrapper(self, *args, **kwargs):
+ # Skip caching if cache is not available
+ if not hasattr(self, "_cache") or not self._cache.backend.available:
+ return func(self, *args, **kwargs)
+
+ # Generate cache key
+ if cache_key_func:
+ cache_key = cache_key_func(self, *args, **kwargs)
+ else:
+ # Default key generation based on method name and first argument
+ method_name = func.__name__
+ first_arg = str(args[0]) if args else "no_args"
+ cache_key = CacheKeyGenerator.custom_key(method_name, first_arg)
+
+ # Try to get from cache first
+ cached_result = self._cache.get(cache_key, operation_type)
+ if cached_result is not None:
+ logger.debug(f"Cache hit for {func.__name__} with key {cache_key}")
+ # Reconstruct the original object from cached data
+ reconstructed_result = reconstruct_from_cache(cached_result)
+ return reconstructed_result
+
+ # Cache miss - call the actual method
+ logger.debug(f"Cache miss for {func.__name__} with key {cache_key}")
+ result = func(self, *args, **kwargs)
+
+ # Cache successful results - convert to JSON-serializable format
+ if result and hasattr(result, "success") and result.success:
+ # Convert result to JSON-serializable format
+ serializable_result = self._make_json_serializable(result)
+ self._cache.set(cache_key, serializable_result, operation_type, ttl)
+ logger.debug(f"Cached result for {func.__name__} with key {cache_key}")
+
+ return result
+
+ return wrapper
+
+ return decorator
+
+
+class CachedAPIClientMixin:
+ """Mixin to add caching capabilities to API clients.
+
+ This mixin provides:
+ - Automatic cache initialization via _cache attribute
+ - Cache statistics and management methods
+ - Works seamlessly with @with_cache decorator
+
+ The @with_cache decorator automatically detects and uses the _cache attribute.
+ """
+
+ def __init__(self, *args, **kwargs):
+ """Initialize the cached client mixin."""
+ super().__init__(*args, **kwargs)
+ self._cache = CacheManager()
+
+ if self._cache.backend.available:
+ logger.info(f"Caching enabled for {self.__class__.__name__}")
+ else:
+ logger.warning(
+ f"Caching disabled for {self.__class__.__name__} - Redis not available"
+ )
+
+ def get_cache_stats(self) -> dict[str, Any]:
+ """Get cache statistics for this client."""
+ return self._cache.get_stats()
+
+ def clear_cache_stats(self):
+ """Clear cache statistics."""
+ self._cache.clear_stats()
+
+ def invalidate_cache(self, pattern: str):
+ """Invalidate cache entries matching pattern."""
+ # This is a simple implementation - could be enhanced with pattern matching
+ logger.info(f"Cache invalidation requested for pattern: {pattern}")
+
+ # Cache management methods
+ def invalidate_workflow_cache(self, workflow_id: str):
+ """Invalidate all cache entries for a specific workflow."""
+ if self._cache.backend.available:
+ self._cache.invalidate_workflow(workflow_id)
+
+ def invalidate_api_deployment_cache(
+ self, api_deployment_id: str, organization_id: str
+ ):
+ """Invalidate cache for a specific API deployment."""
+ if self._cache.backend.available:
+ cache_key = CacheKeyGenerator.api_deployment_key(
+ api_deployment_id, organization_id
+ )
+ self._cache.delete(cache_key)
+ logger.info(f"Invalidated cache for API deployment {api_deployment_id}")
+
+ def invalidate_pipeline_cache(self, pipeline_id: str):
+ """Invalidate cache for a specific pipeline."""
+ if self._cache.backend.available:
+ cache_key = CacheKeyGenerator.pipeline_key(pipeline_id)
+ self._cache.delete(cache_key)
+ logger.info(f"Invalidated cache for pipeline {pipeline_id}")
+
+ def _make_json_serializable(self, obj: Any) -> Any:
+ """Convert an object to JSON-serializable format.
+
+ Delegates to the common serialization utility.
+ """
+ return make_json_serializable(obj)
diff --git a/workers/shared/cache/redis_client.py b/workers/shared/cache/redis_client.py
new file mode 100644
index 000000000..5480aca8f
--- /dev/null
+++ b/workers/shared/cache/redis_client.py
@@ -0,0 +1,269 @@
+"""Base Redis Client for Workers
+
+Provides a comprehensive Redis client with all common Redis operations.
+This serves as the foundation for specialized clients (queue, cache, etc.).
+"""
+
+import logging
+from typing import Any
+
+import redis
+
+logger = logging.getLogger(__name__)
+
+
+class RedisClient:
+ """Base Redis client with comprehensive operations."""
+
+ def __init__(
+ self,
+ host: str = "localhost",
+ port: int = 6379,
+ username: str | None = None,
+ password: str | None = None,
+ db: int = 0,
+ decode_responses: bool = True,
+ socket_connect_timeout: int = 5,
+ socket_timeout: int = 5,
+ ):
+ """Initialize Redis client.
+
+ Args:
+ host: Redis host
+ port: Redis port
+ username: Redis username (optional)
+ password: Redis password (optional)
+ db: Redis database number
+ decode_responses: Whether to decode responses to strings
+ socket_connect_timeout: Connection timeout in seconds
+ socket_timeout: Socket timeout in seconds
+ """
+ self.redis_client = redis.Redis(
+ host=host,
+ port=port,
+ username=username,
+ password=password,
+ db=db,
+ decode_responses=decode_responses,
+ socket_connect_timeout=socket_connect_timeout,
+ socket_timeout=socket_timeout,
+ )
+
+ # Basic key-value operations
+ def get(self, key: str) -> Any:
+ """Get value by key.
+
+ Args:
+ key: Redis key
+
+ Returns:
+ Value or None if key doesn't exist
+ """
+ return self.redis_client.get(key)
+
+ def set(
+ self,
+ key: str,
+ value: Any,
+ ex: int | None = None,
+ px: int | None = None,
+ nx: bool = False,
+ xx: bool = False,
+ ) -> bool:
+ """Set key to value.
+
+ Args:
+ key: Redis key
+ value: Value to set
+ ex: Expire time in seconds
+ px: Expire time in milliseconds
+ nx: Only set if key doesn't exist
+ xx: Only set if key exists
+
+ Returns:
+ True if set successfully
+ """
+ return self.redis_client.set(key, value, ex=ex, px=px, nx=nx, xx=xx)
+
+ def setex(self, key: str, time: int, value: Any) -> bool:
+ """Set key with expiration time.
+
+ Args:
+ key: Redis key
+ time: Expiration time in seconds
+ value: Value to set
+
+ Returns:
+ True if set successfully
+ """
+ return self.redis_client.setex(key, time, value)
+
+ def delete(self, *keys: str) -> int:
+ """Delete one or more keys.
+
+ Args:
+ *keys: Keys to delete
+
+ Returns:
+ Number of keys deleted
+ """
+ return self.redis_client.delete(*keys)
+
+ def exists(self, *keys: str) -> int:
+ """Check if keys exist.
+
+ Args:
+ *keys: Keys to check
+
+ Returns:
+ Number of keys that exist
+ """
+ return self.redis_client.exists(*keys)
+
+ # TTL operations
+ def expire(self, key: str, time: int) -> bool:
+ """Set expiration time on key.
+
+ Args:
+ key: Redis key
+ time: Expiration time in seconds
+
+ Returns:
+ True if timeout was set
+ """
+ return self.redis_client.expire(key, time)
+
+ def ttl(self, key: str) -> int:
+ """Get time to live for key.
+
+ Args:
+ key: Redis key
+
+ Returns:
+ TTL in seconds, -1 if no expiry, -2 if key doesn't exist
+ """
+ return self.redis_client.ttl(key)
+
+ def persist(self, key: str) -> bool:
+ """Remove expiration from key.
+
+ Args:
+ key: Redis key
+
+ Returns:
+ True if expiration was removed
+ """
+ return self.redis_client.persist(key)
+
+ # Batch operations
+ def mget(self, keys: list[str]) -> list[Any]:
+ """Get multiple values at once.
+
+ Args:
+ keys: List of Redis keys
+
+ Returns:
+ List of values (None for non-existent keys)
+ """
+ return self.redis_client.mget(keys)
+
+ def mset(self, mapping: dict[str, Any]) -> bool:
+ """Set multiple key-value pairs at once.
+
+ Args:
+ mapping: Dictionary of key-value pairs
+
+ Returns:
+ True if all keys were set
+ """
+ return self.redis_client.mset(mapping)
+
+ # Key scanning and patterns
+ def keys(self, pattern: str = "*") -> list[str]:
+ """Get all keys matching pattern.
+
+ Warning: Use scan() for production - keys() blocks the server.
+
+ Args:
+ pattern: Key pattern (supports wildcards)
+
+ Returns:
+ List of matching keys
+ """
+ return self.redis_client.keys(pattern)
+
+ def scan(
+ self, cursor: int = 0, match: str | None = None, count: int | None = None
+ ) -> tuple[int, list[str]]:
+ """Incrementally iterate over keys (non-blocking).
+
+ Args:
+ cursor: Cursor position (0 to start)
+ match: Key pattern to match
+ count: Approximate number of keys to return
+
+ Returns:
+ Tuple of (next_cursor, list_of_keys)
+ """
+ return self.redis_client.scan(cursor=cursor, match=match, count=count)
+
+ # Pipeline support
+ def pipeline(self, transaction: bool = True) -> redis.client.Pipeline:
+ """Create a pipeline for batching commands.
+
+ Args:
+ transaction: Whether to use MULTI/EXEC transaction
+
+ Returns:
+ Redis pipeline object
+ """
+ return self.redis_client.pipeline(transaction=transaction)
+
+ # Health check
+ def ping(self) -> bool:
+ """Check Redis connectivity.
+
+ Returns:
+ True if connected, False otherwise
+ """
+ try:
+ self.redis_client.ping()
+ return True
+ except Exception:
+ return False
+
+ # Connection info
+ def info(self, section: str | None = None) -> dict[str, Any]:
+ """Get Redis server information.
+
+ Args:
+ section: Specific info section (e.g., 'memory', 'stats')
+
+ Returns:
+ Dictionary of server information
+ """
+ return self.redis_client.info(section=section)
+
+ @classmethod
+ def from_env(cls) -> "RedisClient":
+ """Create client from environment variables.
+
+ Environment variables:
+ REDIS_HOST: Redis host (default: localhost)
+ REDIS_PORT: Redis port (default: 6379)
+ REDIS_USER: Redis username (optional)
+ REDIS_PASSWORD: Redis password (optional)
+ REDIS_DB: Redis database number (default: 0)
+
+ Returns:
+ Configured RedisClient instance
+ """
+ import os
+
+ return cls(
+ host=os.getenv("REDIS_HOST", "localhost"),
+ port=int(os.getenv("REDIS_PORT", "6379")),
+ username=os.getenv("REDIS_USER"),
+ password=os.getenv("REDIS_PASSWORD"),
+ db=int(os.getenv("REDIS_DB", "0")),
+ )
diff --git a/workers/shared/cache/redis_queue_client.py b/workers/shared/cache/redis_queue_client.py
new file mode 100644
index 000000000..026cc9397
--- /dev/null
+++ b/workers/shared/cache/redis_queue_client.py
@@ -0,0 +1,160 @@
+"""Redis Queue Client for Workers
+
+Specialized Redis client for queue operations (LPOP, RPUSH, etc.).
+Inherits from RedisClient for basic Redis functionality.
+"""
+
+import logging
+from typing import Any
+
+from .redis_client import RedisClient
+
+logger = logging.getLogger(__name__)
+
+
+class RedisQueueClient(RedisClient):
+ """Redis client specialized for queue operations.
+
+ Inherits all basic Redis operations from RedisClient and adds
+ queue-specific list operations (LPOP, RPUSH, LLEN, etc.).
+ """
+
+ # Queue operations (List operations)
+ def llen(self, queue_name: str) -> int:
+ """Get queue length.
+
+ Args:
+ queue_name: Name of the queue (list key)
+
+ Returns:
+ Number of items in queue
+ """
+ return self.redis_client.llen(queue_name)
+
+ def lpop(self, queue_name: str, count: int | None = None) -> Any:
+ """Pop item(s) from left (head) of queue.
+
+ Args:
+ queue_name: Name of the queue
+ count: Number of items to pop (Redis 6.2+, optional)
+
+ Returns:
+ Item from queue or None if empty
+ If count is specified, returns list of items
+ """
+ if count is not None:
+ return self.redis_client.lpop(queue_name, count=count)
+ return self.redis_client.lpop(queue_name)
+
+ def rpop(self, queue_name: str, count: int | None = None) -> Any:
+ """Pop item(s) from right (tail) of queue.
+
+ Args:
+ queue_name: Name of the queue
+ count: Number of items to pop (Redis 6.2+, optional)
+
+ Returns:
+ Item from queue or None if empty
+ If count is specified, returns list of items
+ """
+ if count is not None:
+ return self.redis_client.rpop(queue_name, count=count)
+ return self.redis_client.rpop(queue_name)
+
+ def lpush(self, queue_name: str, *values) -> int:
+ """Push items to left (head) of queue.
+
+ Args:
+ queue_name: Name of the queue
+ *values: Values to push
+
+ Returns:
+ New queue length
+ """
+ return self.redis_client.lpush(queue_name, *values)
+
+ def rpush(self, queue_name: str, *values) -> int:
+ """Push items to right (tail) of queue.
+
+ Args:
+ queue_name: Name of the queue
+ *values: Values to push
+
+ Returns:
+ New queue length
+ """
+ return self.redis_client.rpush(queue_name, *values)
+
+ def lrange(self, queue_name: str, start: int, end: int) -> list[Any]:
+ """Get range of items from queue without removing them.
+
+ Args:
+ queue_name: Name of the queue
+ start: Start index (0-based)
+ end: End index (-1 for last item)
+
+ Returns:
+ List of items in the specified range
+ """
+ return self.redis_client.lrange(queue_name, start, end)
+
+ def lrem(self, queue_name: str, count: int, value: Any) -> int:
+ """Remove items from queue by value.
+
+ Args:
+ queue_name: Name of the queue
+ count: Number of occurrences to remove
+ count > 0: Remove from head to tail
+ count < 0: Remove from tail to head
+ count = 0: Remove all occurrences
+ value: Value to remove
+
+ Returns:
+ Number of items removed
+ """
+ return self.redis_client.lrem(queue_name, count, value)
+
+ def blpop(
+ self, queue_names: list[str] | str, timeout: int = 0
+ ) -> tuple[str, Any] | None:
+ """Blocking left pop - wait for item to be available.
+
+ Args:
+ queue_names: Single queue name or list of queue names
+ timeout: Timeout in seconds (0 = wait forever)
+
+ Returns:
+ Tuple of (queue_name, value) or None if timeout
+ """
+ if isinstance(queue_names, str):
+ queue_names = [queue_names]
+ return self.redis_client.blpop(queue_names, timeout=timeout)
+
+ def brpop(
+ self, queue_names: list[str] | str, timeout: int = 0
+ ) -> tuple[str, Any] | None:
+ """Blocking right pop - wait for item to be available.
+
+ Args:
+ queue_names: Single queue name or list of queue names
+ timeout: Timeout in seconds (0 = wait forever)
+
+ Returns:
+ Tuple of (queue_name, value) or None if timeout
+ """
+ if isinstance(queue_names, str):
+ queue_names = [queue_names]
+ return self.redis_client.brpop(queue_names, timeout=timeout)
+
+ def ltrim(self, queue_name: str, start: int, end: int) -> bool:
+ """Trim queue to specified range.
+
+ Args:
+ queue_name: Name of the queue
+ start: Start index (0-based, inclusive)
+ end: End index (-1 for last item, inclusive)
+
+ Returns:
+ True if successful
+ """
+ return self.redis_client.ltrim(queue_name, start, end)
diff --git a/workers/shared/clients/__init__.py b/workers/shared/clients/__init__.py
new file mode 100644
index 000000000..59af325b9
--- /dev/null
+++ b/workers/shared/clients/__init__.py
@@ -0,0 +1,41 @@
+"""Modular API Client Components
+
+This package contains specialized API clients that have been extracted from the monolithic
+InternalAPIClient to improve maintainability, testability, and performance.
+
+Each client handles a specific domain of operations:
+- BaseAPIClient: Core HTTP functionality, session management, retry logic
+- ExecutionAPIClient: Workflow execution operations
+- FileAPIClient: File execution and file history operations
+- ManualReviewAPIClient: Manual review/HITL operations
+- WebhookAPIClient: Webhook operations
+- OrganizationAPIClient: Organization context management
+- ToolAPIClient: Tool execution operations
+
+For backward compatibility, the original InternalAPIClient is still available
+as a facade that delegates to these specialized clients.
+"""
+
+from .base_client import BaseAPIClient
+from .execution_client import ExecutionAPIClient
+from .file_client import FileAPIClient
+
+# Manual review client - use null client as default, plugin registry handles dynamic loading
+from .manual_review_stub import ManualReviewNullClient as ManualReviewAPIClient
+from .organization_client import OrganizationAPIClient
+from .tool_client import ToolAPIClient
+from .usage_client import UsageAPIClient
+from .webhook_client import WebhookAPIClient
+from .workflow_client import WorkflowAPIClient
+
+__all__ = [
+ "BaseAPIClient",
+ "ExecutionAPIClient",
+ "FileAPIClient",
+ "UsageAPIClient",
+ "ManualReviewAPIClient",
+ "WebhookAPIClient",
+ "OrganizationAPIClient",
+ "ToolAPIClient",
+ "WorkflowAPIClient",
+]
diff --git a/workers/shared/clients/base_client.py b/workers/shared/clients/base_client.py
new file mode 100644
index 000000000..ee96ef3c0
--- /dev/null
+++ b/workers/shared/clients/base_client.py
@@ -0,0 +1,549 @@
+"""Base HTTP Client for Internal API Communication
+
+This module provides the foundational HTTP client functionality extracted from
+the monolithic InternalAPIClient. It handles session management, retry logic,
+authentication, and common request/response patterns.
+
+All specialized clients inherit from BaseAPIClient to get consistent HTTP behavior.
+"""
+
+import json
+import os
+import time
+import uuid
+from typing import Any
+
+import requests
+from celery.exceptions import SoftTimeLimitExceeded
+from requests.adapters import HTTPAdapter
+from urllib3.util.retry import Retry
+
+from ..data.models import APIResponse
+from ..enums import HTTPMethod
+from ..infrastructure.config.worker_config import WorkerConfig
+from ..infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+# HTTP Content Type Constants
+APPLICATION_JSON = "application/json"
+
+
+class InternalAPIClientError(Exception):
+ """Base exception for API client errors."""
+
+ pass
+
+
+class AuthenticationError(InternalAPIClientError):
+ """Raised when API authentication fails."""
+
+ pass
+
+
+class APIRequestError(InternalAPIClientError):
+ """Raised when API request fails."""
+
+ pass
+
+
+class BaseAPIClient:
+ """Base HTTP client for communicating with Django backend internal APIs.
+
+ Features:
+ - Bearer token authentication
+ - Automatic retries with exponential backoff
+ - Request/response logging
+ - Organization context support
+ - Circuit breaker pattern
+ - Connection pooling
+ - Request batching support
+ """
+
+ # Internal API URL patterns - can be overridden via environment variables
+ # Standardized to use v1/ prefix consistently, with v2/ for newer optimized endpoints
+ API_ENDPOINTS = {
+ "health": os.getenv("INTERNAL_API_HEALTH_PREFIX", "v1/health/"),
+ "workflow_execution": os.getenv(
+ "INTERNAL_API_WORKFLOW_PREFIX", "v1/workflow-execution/"
+ ),
+ "organization": os.getenv("INTERNAL_API_ORGANIZATION_PREFIX", "v1/organization/"),
+ "execution": os.getenv("INTERNAL_API_EXECUTION_PREFIX", "v1/execution/"),
+ "tool_execution": os.getenv(
+ "INTERNAL_API_TOOL_EXECUTION_PREFIX", "v1/tool-execution/"
+ ),
+ "file_execution": os.getenv(
+ "INTERNAL_API_FILE_EXECUTION_PREFIX", "v1/file-execution/"
+ ),
+ "file_history": os.getenv("INTERNAL_API_FILE_HISTORY_PREFIX", "v1/file-history/"),
+ "webhook": os.getenv("INTERNAL_API_WEBHOOK_PREFIX", "v1/webhook/"),
+ "workflow_manager": os.getenv(
+ "INTERNAL_API_WORKFLOW_MANAGER_PREFIX", "v1/workflow-manager/"
+ ),
+ "platform_settings": os.getenv(
+ "INTERNAL_API_PLATFORM_SETTINGS_PREFIX", "v1/platform-settings/"
+ ),
+ # API deployment endpoints for optimized type-aware operations
+ "api_deployments": os.getenv(
+ "INTERNAL_API_DEPLOYMENTS_PREFIX", "v1/api-deployments/"
+ ),
+ }
+
+ def __init__(self, config: WorkerConfig | None = None):
+ """Initialize base API client.
+
+ Args:
+ config: Worker configuration. If None, uses default config.
+ """
+ self.config = config or WorkerConfig()
+ self.base_url = self.config.internal_api_base_url
+ self.api_key = self.config.internal_api_key
+
+ # Organization ID is set dynamically via set_organization_context()
+ # It comes from task context, not from configuration
+ self.organization_id = None
+
+ # Initialize requests session with retry strategy
+ self.session = requests.Session()
+ self._setup_session()
+
+ # Always log initialization
+ logger.info(f"Initialized BaseAPIClient for {self.base_url}")
+
+ # Only add debug details if debug mode is enabled
+ if self.config.debug_api_client_init:
+ logger.debug(f"API endpoint configuration: {self.get_endpoint_config()}")
+
+ def get_endpoint_config(self) -> dict[str, str]:
+ """Get current API endpoint configuration for debugging."""
+ return dict(self.API_ENDPOINTS)
+
+ def _build_url(self, endpoint_key: str, path: str = "") -> str:
+ """Build consistent API URL using endpoint patterns.
+
+ Args:
+ endpoint_key: Key from API_ENDPOINTS dict
+ path: Additional path to append
+
+ Returns:
+ Complete endpoint path
+ """
+ base_path = self.API_ENDPOINTS.get(endpoint_key, endpoint_key)
+ if path:
+ return f"{base_path.rstrip('/')}/{path.lstrip('/')}"
+ # Preserve trailing slashes in base_path to avoid 301 redirects
+ return base_path
+
+ def _setup_session(self):
+ """Configure session with retry strategy, timeouts, and connection pooling."""
+ # Enhanced retry strategy with enum-based status codes
+ retry_status_codes = [429, 500, 502, 503, 504]
+ allowed_http_methods = [method.value for method in HTTPMethod]
+
+ retry_strategy = Retry(
+ total=self.config.api_retry_attempts,
+ backoff_factor=self.config.api_retry_backoff_factor,
+ status_forcelist=retry_status_codes,
+ allowed_methods=allowed_http_methods,
+ respect_retry_after_header=True,
+ )
+
+ # HTTP adapter with connection pooling
+ adapter = HTTPAdapter(
+ max_retries=retry_strategy,
+ pool_connections=10, # Number of connection pools
+ pool_maxsize=20, # Maximum number of connections per pool
+ pool_block=False, # Don't block when pool is full
+ )
+ self.session.mount("http://", adapter)
+ self.session.mount("https://", adapter)
+
+ # Default headers
+ self.session.headers.update(
+ {
+ "Authorization": f"Bearer {self.api_key}",
+ "Content-Type": APPLICATION_JSON,
+ "User-Agent": f"UnstractWorker/{self.config.worker_version}",
+ "Accept": APPLICATION_JSON,
+ "Connection": "keep-alive",
+ }
+ )
+
+ # Organization context header
+ if self.organization_id:
+ self.session.headers["X-Organization-ID"] = self.organization_id
+
+ def _serialize_data(self, data: Any) -> Any:
+ """Recursively serialize data to JSON-compatible format.
+ Handles UUID objects, datetime objects, and other complex types.
+ """
+ import datetime
+
+ if isinstance(data, uuid.UUID):
+ return str(data)
+ elif isinstance(data, (datetime.datetime, datetime.date)):
+ return data.isoformat()
+ elif isinstance(data, datetime.time):
+ return data.isoformat()
+ elif isinstance(data, dict):
+ return {key: self._serialize_data(value) for key, value in data.items()}
+ elif isinstance(data, (list, tuple)):
+ return [self._serialize_data(item) for item in data]
+ elif isinstance(data, set):
+ return [self._serialize_data(item) for item in data]
+ else:
+ return data
+
+ def _make_request(
+ self,
+ method: str,
+ endpoint: str,
+ data: dict[str, Any] | None = None,
+ params: dict[str, Any] | None = None,
+ timeout: int | None = None,
+ max_retries: int = 3,
+ backoff_factor: float = 0.5,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Enhanced HTTP request with robust error handling and retry logic.
+
+ Args:
+ method: HTTP method (GET, POST, PUT, DELETE, PATCH)
+ endpoint: API endpoint (relative to base URL)
+ data: Request payload for POST/PUT/PATCH
+ params: Query parameters
+ timeout: Request timeout in seconds
+ max_retries: Maximum number of retry attempts
+ backoff_factor: Exponential backoff factor
+ organization_id: Optional organization ID override
+
+ Returns:
+ Response data as dictionary
+
+ Raises:
+ AuthenticationError: If authentication fails
+ APIRequestError: If request fails after all retries
+ """
+ url = f"{self.base_url.rstrip('/')}/{endpoint.lstrip('/')}"
+ timeout = timeout or self.config.api_timeout
+
+ last_exception = None
+ # HTTP status codes that should trigger retries
+ retry_statuses = {500, 502, 503, 504} # Server errors to retry
+ auth_error_status = 401
+ client_error_range = range(400, 500)
+ timeout_statuses = {408, 429}
+
+ for attempt in range(max_retries + 1):
+ try:
+ # Prepare request kwargs
+ kwargs = {"timeout": timeout, "params": params, "allow_redirects": True}
+
+ # Handle dynamic organization context
+ headers = {}
+ current_org_id = organization_id or self.organization_id
+ if current_org_id:
+ headers["X-Organization-ID"] = current_org_id
+
+ if headers:
+ kwargs["headers"] = headers
+
+ # Serialize request data
+ if data is not None:
+ try:
+ kwargs["json"] = self._serialize_data(data)
+ except Exception as e:
+ logger.error(f"Failed to serialize request data: {e}")
+ raise APIRequestError(f"Data serialization failed: {str(e)}")
+
+ # Make request with session (includes connection pooling)
+ response = self.session.request(method, url, **kwargs)
+
+ # Handle authentication errors (don't retry)
+ if response.status_code == auth_error_status:
+ error_msg = "Authentication failed with internal API"
+ response_text = self._safe_get_response_text(response)
+ logger.error(f"{error_msg}: {response_text}")
+ raise AuthenticationError(f"{error_msg}: {response_text}")
+
+ # Handle client errors (don't retry most 4xx)
+ if (
+ response.status_code in client_error_range
+ and response.status_code not in timeout_statuses
+ ):
+ error_msg = f"Client error: {response.status_code} {response.reason}"
+ response_text = self._safe_get_response_text(response)
+ logger.error(f"{error_msg}: {response_text}")
+ raise APIRequestError(f"{error_msg}: {response_text}")
+
+ # Handle server errors (retry these)
+ if response.status_code in retry_statuses:
+ error_msg = f"Server error: {response.status_code} {response.reason}"
+ response_text = self._safe_get_response_text(response)
+
+ if attempt < max_retries:
+ sleep_time = backoff_factor * (2**attempt)
+ logger.warning(
+ f"{error_msg} - retrying in {sleep_time:.1f}s (attempt {attempt + 1}/{max_retries + 1})"
+ )
+ time.sleep(sleep_time)
+ continue
+ else:
+ logger.error(
+ f"{error_msg} - max retries exceeded: {response_text}"
+ )
+ raise APIRequestError(f"{error_msg}: {response_text}")
+
+ # Handle rate limiting (429)
+ rate_limit_status = 429
+ if response.status_code == rate_limit_status:
+ retry_after = int(
+ response.headers.get("Retry-After", backoff_factor * (2**attempt))
+ )
+ if attempt < max_retries:
+ logger.warning(
+ f"Rate limited - retrying in {retry_after}s (attempt {attempt + 1}/{max_retries + 1})"
+ )
+ time.sleep(retry_after)
+ continue
+ else:
+ raise APIRequestError(
+ f"Rate limited after {max_retries + 1} attempts"
+ )
+
+ # Success case
+ if response.ok:
+ return self._parse_response(response, endpoint)
+
+ # Other errors
+ error_msg = f"Request failed: {response.status_code} {response.reason}"
+ response_text = self._safe_get_response_text(response)
+ logger.error(f"{error_msg}: {response_text}")
+ raise APIRequestError(f"{error_msg}: {response_text}")
+
+ except (
+ requests.exceptions.Timeout,
+ requests.exceptions.ConnectionError,
+ ) as e:
+ last_exception = e
+ error_type = (
+ "timeout"
+ if isinstance(e, requests.exceptions.Timeout)
+ else "connection"
+ )
+
+ if attempt < max_retries:
+ sleep_time = backoff_factor * (2**attempt)
+ logger.warning(
+ f"Request {error_type} error - retrying in {sleep_time:.1f}s (attempt {attempt + 1}/{max_retries + 1}): {str(e)}"
+ )
+ time.sleep(sleep_time)
+ continue
+ else:
+ logger.error(
+ f"Request {error_type} error after {max_retries + 1} attempts: {str(e)}"
+ )
+ raise APIRequestError(f"Request {error_type} error: {str(e)}")
+
+ except requests.exceptions.RequestException as e:
+ last_exception = e
+ error_msg = f"Request exception: {str(e)}"
+ logger.error(error_msg)
+ raise APIRequestError(error_msg)
+
+ except (AuthenticationError, APIRequestError):
+ # Re-raise these without retrying
+ raise
+
+ except SoftTimeLimitExceeded:
+ # Don't wrap Celery timeout - let it propagate for graceful task shutdown
+ logger.warning(
+ f"Task soft time limit exceeded during API request to {endpoint}. "
+ "Task should begin cleanup."
+ )
+ raise
+
+ except Exception as e:
+ last_exception = e
+ error_msg = f"Unexpected error during API request: {str(e)}"
+ logger.error(error_msg, exc_info=True)
+ raise APIRequestError(error_msg)
+
+ # This shouldn't be reached, but just in case
+ error_msg = f"Request failed after {max_retries + 1} attempts"
+ if last_exception:
+ error_msg += f": {str(last_exception)}"
+ raise APIRequestError(error_msg)
+
+ def _safe_get_response_text(
+ self, response: requests.Response, max_length: int = 500
+ ) -> str:
+ """Safely get response text with error handling and length limiting."""
+ try:
+ text = response.text
+ if len(text) > max_length:
+ return f"{text[:max_length]}... (truncated)"
+ return text
+ except Exception as e:
+ return f"<Could not read response text: {str(e)}>"
+
+ def _parse_response(
+ self, response: requests.Response, endpoint: str
+ ) -> dict[str, Any]:
+ """Enhanced response parsing with better error handling."""
+ try:
+ # Check content type
+ content_type = response.headers.get("Content-Type", "").lower()
+
+ if APPLICATION_JSON in content_type:
+ json_data = response.json()
+ logger.debug(f"Successfully parsed JSON response from {endpoint}")
+ return json_data
+ elif response.text.strip():
+ # Try to parse as JSON anyway (some APIs don't set correct Content-Type)
+ try:
+ json_data = response.json()
+ logger.debug(
+ f"Successfully parsed JSON response (incorrect Content-Type) from {endpoint}"
+ )
+ return json_data
+ except json.JSONDecodeError:
+ # Return raw text
+ logger.debug(f"Returning raw text response from {endpoint}")
+ return {"raw_response": response.text}
+ else:
+ # Empty response
+ logger.debug(f"Empty response from {endpoint}")
+ return {}
+
+ except json.JSONDecodeError as e:
+ logger.warning(f"Failed to parse JSON response from {endpoint}: {str(e)}")
+ return {"raw_response": response.text, "parse_error": str(e)}
+ except Exception as e:
+ logger.error(f"Unexpected error parsing response from {endpoint}: {str(e)}")
+ return {"error": f"Response parsing failed: {str(e)}"}
+
+ def _batch_request(self, requests_data: list[dict[str, Any]]) -> list[dict[str, Any]]:
+ """Batch multiple requests for improved performance.
+
+ Args:
+ requests_data: List of request dictionaries with 'method', 'endpoint', and optional 'data', 'params'
+
+ Returns:
+ List of response dictionaries
+ """
+ results = []
+
+ for request_data in requests_data:
+ try:
+ method = request_data["method"]
+ endpoint = request_data["endpoint"]
+ data = request_data.get("data")
+ params = request_data.get("params")
+
+ result = self._make_request(method, endpoint, data=data, params=params)
+ results.append({"success": True, "data": result})
+
+ except Exception as e:
+ logger.error(f"Batch request failed for {request_data}: {str(e)}")
+ results.append({"success": False, "error": str(e)})
+
+ return results
+
+ # HTTP method helpers using enums
+ def get(
+ self,
+ endpoint: str,
+ params: dict[str, Any] | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Make GET request."""
+ return self._make_request(
+ HTTPMethod.GET.value, endpoint, params=params, organization_id=organization_id
+ )
+
+ def post(
+ self, endpoint: str, data: dict[str, Any], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Make POST request."""
+ return self._make_request(
+ HTTPMethod.POST.value, endpoint, data=data, organization_id=organization_id
+ )
+
+ def put(
+ self, endpoint: str, data: dict[str, Any], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Make PUT request."""
+ return self._make_request(
+ HTTPMethod.PUT.value, endpoint, data=data, organization_id=organization_id
+ )
+
+ def patch(
+ self, endpoint: str, data: dict[str, Any], organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Make PATCH request."""
+ return self._make_request(
+ HTTPMethod.PATCH.value, endpoint, data=data, organization_id=organization_id
+ )
+
+ def delete(self, endpoint: str, organization_id: str | None = None) -> dict[str, Any]:
+ """Make DELETE request."""
+ return self._make_request(
+ HTTPMethod.DELETE.value, endpoint, organization_id=organization_id
+ )
+
+ # Organization context management
+ def set_organization_context(self, org_id: str):
+ """Set organization context for subsequent requests with caching optimization."""
+ # Performance optimization: Skip redundant context setting
+ if (
+ hasattr(self, "_cached_org_id")
+ and self._cached_org_id == org_id
+ and self.config.enable_organization_context_cache
+ ):
+ return
+
+ if org_id is None or str(org_id).lower() == "none":
+ self.organization_id = None
+ self._cached_org_id = None
+ if "X-Organization-ID" in self.session.headers:
+ del self.session.headers["X-Organization-ID"]
+ return
+
+ self.organization_id = org_id
+ self._cached_org_id = org_id # Cache for future calls
+ self.session.headers["X-Organization-ID"] = org_id
+
+ def clear_organization_context(self):
+ """Clear organization context."""
+ self.organization_id = None
+ if "X-Organization-ID" in self.session.headers:
+ del self.session.headers["X-Organization-ID"]
+ logger.debug("Cleared organization context")
+
+ # Health check
+ def health_check(self) -> APIResponse:
+ """Check API health status."""
+ try:
+ response = self.get(self._build_url("health"))
+ return APIResponse(
+ success=response.get("status") == "healthy",
+ data=response,
+ status_code=200,
+ )
+ except Exception as e:
+ return APIResponse(success=False, error=str(e))
+
+ # Session management
+ def close(self):
+ """Close the HTTP session."""
+ self.session.close()
+ logger.debug("Closed API client session")
+
+ def __enter__(self):
+ """Context manager entry."""
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Context manager exit."""
+ self.close()
diff --git a/workers/shared/clients/execution_client.py b/workers/shared/clients/execution_client.py
new file mode 100644
index 000000000..d84ced3a7
--- /dev/null
+++ b/workers/shared/clients/execution_client.py
@@ -0,0 +1,747 @@
+"""Execution API Client for Workflow Operations
+
+This module provides specialized API client for workflow execution operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- Workflow execution management
+- Execution status updates
+- File batch operations
+- Pipeline operations
+- Execution finalization
+"""
+
+import logging
+import uuid
+from typing import Any
+from uuid import UUID
+
+from unstract.core.data_models import ExecutionStatus
+
+from ..data.models import (
+ BatchOperationRequest,
+ StatusUpdateRequest,
+)
+from ..data.response_models import (
+ APIResponse,
+ BatchOperationResponse,
+ ExecutionResponse,
+ convert_dict_response,
+)
+from ..enums import BatchOperationType, TaskStatus
+from ..enums.status_enums import PipelineStatus
+from ..models.pipeline_models import PipelineApiResponse
+from .base_client import BaseAPIClient
+
+# Import retry utilities directly to avoid patterns system circular imports
+# from ..patterns.retry.utils import CircuitBreakerOpenError, circuit_breaker
+
+
+# Temporary: Define minimal retry functionality directly here
+class CircuitBreakerOpenError(Exception):
+ """Circuit breaker is open - too many failures"""
+
+ pass
+
+
+def circuit_breaker(
+ max_failures=5, reset_timeout=60, failure_threshold=None, recovery_timeout=None
+):
+ """Simple circuit breaker decorator - temporary implementation"""
+ # Handle parameter mapping for compatibility
+ if failure_threshold is not None:
+ max_failures = failure_threshold
+ if recovery_timeout is not None:
+ reset_timeout = recovery_timeout
+
+ def decorator(func):
+ func._failures = 0
+ func._last_failure = 0
+
+ def wrapper(*args, **kwargs):
+ import time
+
+ current_time = time.time()
+
+ # Reset if timeout has passed
+ if current_time - func._last_failure > reset_timeout:
+ func._failures = 0
+
+ # Check if circuit is open
+ if func._failures >= max_failures:
+ raise CircuitBreakerOpenError(f"Circuit breaker open for {func.__name__}")
+
+ try:
+ result = func(*args, **kwargs)
+ func._failures = 0 # Reset on success
+ return result
+ except Exception:
+ func._failures += 1
+ func._last_failure = current_time
+ raise
+
+ return wrapper
+
+ return decorator
+
+
+logger = logging.getLogger(__name__)
+
+
+class ExecutionAPIClient(BaseAPIClient):
+ """Specialized API client for workflow execution operations.
+
+ This client handles all workflow execution related operations including:
+ - Getting workflow execution details
+ - Updating execution status
+ - Creating file batches
+ - Managing pipeline status
+ - Finalizing executions
+ """
+
+ def get_workflow_execution(
+ self,
+ execution_id: str | uuid.UUID,
+ organization_id: str | None = None,
+ include_cost: bool = False,
+ file_execution: bool = True,
+ ) -> ExecutionResponse:
+ """Get workflow execution with context.
+
+ Args:
+ execution_id: Workflow execution ID
+ organization_id: Optional organization ID override
+ include_cost: Whether to include aggregated usage cost (expensive operation)
+
+ Returns:
+ ExecutionResponse containing workflow execution data
+ """
+ try:
+ # Build URL with optional cost parameter
+ url = self._build_url("workflow_execution", f"{str(execution_id)}/")
+ if include_cost:
+ url += "?include_cost=true"
+ if file_execution:
+ url += "?file_execution=true"
+
+ response = self.get(
+ url,
+ organization_id=organization_id,
+ )
+ return ExecutionResponse.success_response(
+ execution_id=str(execution_id),
+ data=response,
+ message="Successfully retrieved workflow execution",
+ )
+ except Exception as e:
+ return ExecutionResponse.error_response(
+ error=str(e),
+ execution_id=str(execution_id),
+ message="Failed to retrieve workflow execution",
+ )
+
+ def get_workflow_definition(
+ self, workflow_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> ExecutionResponse:
+ """Get workflow definition including workflow_type.
+
+ Args:
+ workflow_id: Workflow ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ ExecutionResponse containing workflow definition data
+ """
+ try:
+ # Use the workflow management internal API to get workflow details
+ endpoint = f"v1/workflow-manager/workflow/{str(workflow_id)}/"
+ response = self.get(endpoint, organization_id=organization_id)
+ logger.info(
+ f"Retrieved workflow definition for {workflow_id}: {response.get('workflow_type', 'unknown')}"
+ )
+ return ExecutionResponse.success_response(
+ execution_id=str(workflow_id),
+ data=response,
+ message="Successfully retrieved workflow definition",
+ )
+ except Exception as e:
+ logger.error(f"Failed to get workflow definition for {workflow_id}: {str(e)}")
+ return ExecutionResponse.error_response(
+ error=str(e),
+ execution_id=str(workflow_id),
+ message="Failed to retrieve workflow definition",
+ )
+
+ def get_pipeline_type(
+ self, pipeline_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get pipeline type by checking APIDeployment and Pipeline models.
+
+ Args:
+ pipeline_id: Pipeline ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse containing pipeline type information
+ """
+ try:
+ # Use the internal API endpoint for pipeline type resolution
+ endpoint = f"v1/workflow-manager/pipeline-type/{str(pipeline_id)}/"
+ response = self.get(endpoint, organization_id=organization_id)
+
+ pipeline_type = response.get("pipeline_type", "ETL")
+ source = response.get("source", "unknown")
+
+ logger.debug(
+ f"Retrieved pipeline type for {pipeline_id}: {pipeline_type} (from {source})"
+ )
+ return APIResponse.success_response(
+ data=response,
+ message=f"Successfully retrieved pipeline type: {pipeline_type}",
+ )
+ except Exception as e:
+ # This is expected for non-API deployments - pipeline endpoint doesn't exist
+ logger.debug(
+ f"Pipeline type API not available for {pipeline_id} (expected for ETL workflows): {str(e)}"
+ )
+ # Return default structure - this is normal behavior
+ return APIResponse.success_response(
+ data={
+ "pipeline_id": str(pipeline_id),
+ "pipeline_type": "ETL", # Default to ETL for non-API workflows
+ "source": "fallback",
+ "note": "Pipeline type API not available - defaulted to ETL",
+ },
+ message="Pipeline type defaulted to ETL",
+ )
+
+ def get_api_deployment_data(
+ self, api_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get APIDeployment data directly from v1 API deployment endpoint.
+
+ This method is optimized for callback workers that know they're dealing
+ with API deployments. It uses the v1/api-deployments/{api_id}/data/ endpoint
+ which directly queries the APIDeployment model without checking Pipeline model.
+
+ Args:
+ api_id: API deployment ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse containing APIDeployment data
+ """
+ try:
+ logger.debug(
+ f"Fetching APIDeployment data for {api_id} via v1 API deployment endpoint"
+ )
+
+ # Use the v1 API deployment endpoint for APIDeployment data
+ endpoint = self._build_url("api_deployments", f"{str(api_id)}/")
+ response = self.get(endpoint, organization_id=organization_id)
+
+ logger.info(
+ f"Retrieved APIDeployment data for {api_id}: name='{response.get('pipeline_name')}', type='{response.get('pipeline_type')}'"
+ )
+
+ return APIResponse.success_response(
+ data=response,
+ message=f"Successfully retrieved APIDeployment data: {response.get('pipeline_name')}",
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to fetch APIDeployment data for {api_id}: {str(e)}",
+ exc_info=True,
+ )
+ return APIResponse.error_response(
+ error=str(e),
+ message="Failed to retrieve APIDeployment data",
+ )
+
+ def update_workflow_execution_status(
+ self,
+ execution_id: str | uuid.UUID,
+ status: str | TaskStatus,
+ error_message: str | None = None,
+ total_files: int | None = None,
+ attempts: int | None = None,
+ execution_time: float | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Update workflow execution status.
+
+ Args:
+ execution_id: Execution ID
+ status: New status (TaskStatus enum or string)
+ error_message: Optional error message
+ total_files: Optional total files count
+ attempts: Optional attempts count
+ execution_time: Optional execution time
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with update result
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if hasattr(status, "value") else status
+
+ data = {"status": status_str}
+
+ if error_message is not None:
+ data["error_message"] = error_message
+ if total_files is not None:
+ data["total_files"] = total_files
+ if attempts is not None:
+ data["attempts"] = attempts
+ if execution_time is not None:
+ data["execution_time"] = execution_time
+
+ # Validate execution_id before building URL
+ if not execution_id:
+ raise ValueError(f"execution_id is required but got: {execution_id}")
+
+ response = self.post(
+ self._build_url("workflow_execution", f"{str(execution_id)}/update_status/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ # Convert dict response to consistent APIResponse
+ return convert_dict_response(response, APIResponse)
+
+ def batch_update_execution_status(
+ self,
+ updates: list[dict[str, Any] | StatusUpdateRequest],
+ organization_id: str | None = None,
+ ) -> BatchOperationResponse:
+ """Update multiple execution statuses in a single request.
+
+ Args:
+ updates: List of StatusUpdateRequest objects or dictionaries
+ organization_id: Optional organization ID override
+
+ Returns:
+ BatchOperationResponse with results
+ """
+ # Validate that we have updates to process
+ if not updates:
+ return BatchOperationResponse(
+ operation_id=str(uuid.uuid4()),
+ total_items=0,
+ successful_items=0,
+ failed_items=0,
+ status=TaskStatus.SUCCESS,
+ results=[],
+ error_message="No updates provided",
+ )
+
+ # Convert updates to dictionaries if they are dataclasses
+ update_dicts = []
+ for update in updates:
+ if isinstance(update, StatusUpdateRequest):
+ update_dicts.append(update.to_dict())
+ else:
+ update_dicts.append(update)
+
+ # Final check after conversion
+ if not update_dicts:
+ return BatchOperationResponse(
+ operation_id=str(uuid.uuid4()),
+ total_items=0,
+ successful_items=0,
+ failed_items=0,
+ status=TaskStatus.SUCCESS,
+ results=[],
+ error_message="No valid updates after conversion",
+ )
+
+ batch_request = BatchOperationRequest(
+ operation_type=BatchOperationType.STATUS_UPDATE,
+ items=update_dicts,
+ organization_id=organization_id,
+ )
+
+ response = self.post(
+ "v1/workflow-manager/batch-status-update/",
+ batch_request.to_dict(),
+ organization_id=organization_id,
+ )
+
+ # Parse backend response format
+ successful_updates = response.get("successful_updates", [])
+ failed_updates = response.get("failed_updates", [])
+ total_processed = response.get("total_processed", 0)
+
+ # Use new consistent response format
+ if failed_updates:
+ return BatchOperationResponse.error_response(
+ total_items=total_processed,
+ errors=failed_updates,
+ successful_items=len(successful_updates),
+ message="Batch update completed with some failures",
+ )
+ else:
+ return BatchOperationResponse.success_response(
+ successful_items=len(successful_updates),
+ total_items=total_processed,
+ message="Batch update completed successfully",
+ )
+
+ def create_file_batch(
+ self,
+ workflow_execution_id: str | uuid.UUID,
+ files: list,
+ is_api: bool = False,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Create file execution batch.
+
+ Args:
+ workflow_execution_id: Workflow execution ID
+ files: List of files to process
+ is_api: Whether this is an API execution
+ organization_id: Optional organization ID override
+
+ Returns:
+ File batch creation response
+ """
+ data = {
+ "workflow_execution_id": str(workflow_execution_id),
+ "files": files,
+ "is_api": is_api,
+ }
+ return self.post(
+ "v1/workflow-manager/file-batch/", data, organization_id=organization_id
+ )
+
+ @circuit_breaker(failure_threshold=3, recovery_timeout=60.0)
+ def update_pipeline_status(
+ self,
+ pipeline_id: str | UUID,
+ status: str | TaskStatus,
+ organization_id: str | None = None,
+ execution_id: str | UUID | None = None, # Optional for backward compatibility
+ **kwargs,
+ ) -> APIResponse:
+ """Update pipeline status.
+
+ Args:
+ pipeline_id: Pipeline ID
+ status: New status
+ organization_id: Optional organization ID override
+ execution_id: Optional execution ID (for backward compatibility)
+
+ Returns:
+ Update response
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if hasattr(status, "value") else status
+
+ # Map execution status to pipeline status if needed
+ execution_to_pipeline_mapping = {
+ ExecutionStatus.COMPLETED.value: PipelineStatus.SUCCESS.value,
+ ExecutionStatus.ERROR.value: PipelineStatus.FAILURE.value,
+ ExecutionStatus.STOPPED.value: PipelineStatus.FAILURE.value,
+ ExecutionStatus.EXECUTING.value: PipelineStatus.INPROGRESS.value,
+ ExecutionStatus.PENDING.value: PipelineStatus.YET_TO_START.value,
+ ExecutionStatus.QUEUED.value: PipelineStatus.INPROGRESS.value,
+ ExecutionStatus.CANCELED.value: PipelineStatus.FAILURE.value,
+ }
+
+ # Map to pipeline status if it's an execution status, otherwise use as-is
+ pipeline_status = execution_to_pipeline_mapping.get(status_str, status_str)
+
+ # Use PipelineStatus to determine if this is a completion state
+ is_completion_state = PipelineStatus.is_completion_status(pipeline_status)
+
+ data = {
+ "status": pipeline_status, # Use mapped pipeline status
+ "is_end": is_completion_state, # Set is_end=True for completion states
+ **kwargs, # Include any additional parameters like error_message
+ }
+
+ # DON'T include execution_id to avoid duplicate notifications
+ # Callback worker already handles notifications via handle_status_notifications()
+
+ try:
+ # Use the pipeline internal API endpoint
+ endpoint = f"v1/pipeline/{pipeline_id}/"
+
+ response = self._make_request(
+ method="PUT", # Use PUT for update operation
+ endpoint=endpoint,
+ data=data,
+ timeout=self.config.api_timeout,
+ organization_id=organization_id,
+ )
+
+ logger.debug(
+ f"Updated pipeline {pipeline_id} status to {status_str} "
+ f"(is_end={is_completion_state})"
+ )
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to update pipeline {pipeline_id} status: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ # Workflow execution finalization handled by status updates
+
+ # Execution resource cleanup handled directly by workers
+
+ def increment_completed_files(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any]:
+ """Increment completed files count for execution.
+
+ Args:
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+
+ Returns:
+ Increment response
+ """
+ data = {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "increment_type": "completed",
+ }
+ try:
+ response = self.post("v1/workflow-manager/increment-files/", data)
+ logger.debug(f"Incremented completed files for execution {execution_id}")
+ return response
+ except Exception as e:
+ logger.error(f"Failed to increment completed files: {str(e)}")
+ return {"success": False, "error": str(e)}
+
+ def increment_failed_files(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any]:
+ """Increment failed files count for execution.
+
+ Args:
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+
+ Returns:
+ Increment response
+ """
+ data = {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "increment_type": "failed",
+ }
+ try:
+ response = self.post("v1/workflow-manager/increment-files/", data)
+ logger.debug(f"Incremented failed files for execution {execution_id}")
+ return response
+ except Exception as e:
+ logger.error(f"Failed to increment failed files: {str(e)}")
+ return {"success": False, "error": str(e)}
+
+ def get_workflow_destination_config(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any]:
+ """Get destination configuration for workflow execution.
+
+ Args:
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+
+ Returns:
+ Destination configuration
+ """
+ try:
+ # Use workflow execution endpoint to get destination config
+ response = self.get(f"v1/workflow-manager/{execution_id}/")
+ # Extract destination_config from the response
+ if isinstance(response, dict) and "destination_config" in response:
+ logger.debug(f"Retrieved destination config for workflow {workflow_id}")
+ return response["destination_config"]
+ # Fallback for backward compatibility
+ logger.debug(f"Retrieved full response for workflow {workflow_id}")
+ return response
+ except Exception as e:
+ logger.error(f"Failed to get destination config: {str(e)}")
+ return {"type": "none", "error": str(e)}
+
+ def check_file_history_batch(
+ self, workflow_id: str, file_hashes: list[str], organization_id: str
+ ) -> dict[str, Any]:
+ """Check file history for multiple files in batch.
+
+ Args:
+ workflow_id: Workflow ID
+ file_hashes: List of file hashes to check
+ organization_id: Organization ID
+
+ Returns:
+ Batch check response with processed_file_hashes list
+ """
+ try:
+ data = {
+ "workflow_id": workflow_id,
+ "file_hashes": file_hashes,
+ "organization_id": organization_id,
+ }
+ response = self.post("v1/workflow-manager/file-history/check-batch/", data)
+ logger.debug(f"Checked file history for {len(file_hashes)} files")
+ return response
+ except Exception as e:
+ error_str = str(e)
+ # Handle 404 specifically - this means either no file history or endpoint doesn't exist
+ if "404" in error_str or "Not Found" in error_str:
+ if "<!doctype html>" in error_str or "<html>" in error_str:
+ # HTML 404 response means the API endpoint doesn't exist
+ logger.info(
+ "File history batch check endpoint not available (404). Assuming no files have been processed previously."
+ )
+ else:
+ # JSON 404 would mean no history data found
+ logger.info(
+ f"No file history found for workflow {workflow_id} - all files will be processed"
+ )
+ else:
+ # Other errors should be logged as warnings
+ logger.warning(f"Failed to check file history batch: {error_str}")
+
+ # Return empty list so all files are processed (safe fallback)
+ return {"processed_file_hashes": []}
+
+ def create_workflow_execution(self, execution_data: dict[str, Any]) -> dict[str, Any]:
+ """Create workflow execution.
+
+ Args:
+ execution_data: Execution creation data
+
+ Returns:
+ Created execution data
+ """
+ return self.post(
+ "v1/workflow-manager/execution/create/",
+ execution_data,
+ organization_id=execution_data.get("organization_id"),
+ )
+
+ def get_tool_instances_by_workflow(
+ self, workflow_id: str, organization_id: str
+ ) -> dict[str, Any]:
+ """Get tool instances for a workflow.
+
+ Args:
+ workflow_id: Workflow ID
+ organization_id: Organization ID
+
+ Returns:
+ Tool instances data
+ """
+ return self.get(
+ f"v1/workflow-manager/workflow/{workflow_id}/tool-instances/",
+ organization_id=organization_id,
+ )
+
+ def compile_workflow(
+ self, workflow_id: str, execution_id: str, organization_id: str
+ ) -> dict[str, Any]:
+ """Compile workflow.
+
+ Args:
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ organization_id: Organization ID
+
+ Returns:
+ Compilation result
+ """
+ return self.post(
+ "v1/workflow-manager/workflow/compile/",
+ {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ },
+ organization_id=organization_id,
+ )
+
+ def submit_file_batch_for_processing(
+ self, batch_data: dict[str, Any]
+ ) -> dict[str, Any]:
+ """Submit file batch for processing.
+
+ Args:
+ batch_data: File batch data
+
+ Returns:
+ Submission result
+ """
+ return self.post(
+ "v1/workflow-manager/file-batch/submit/",
+ batch_data,
+ organization_id=batch_data.get("organization_id"),
+ )
+
+ # Pipeline Management Methods for Scheduler Worker
+
+ def get_pipeline_data(
+ self,
+ pipeline_id: str,
+ check_active: bool = True,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get pipeline data for scheduler execution.
+
+ Args:
+ pipeline_id: Pipeline ID
+ check_active: Whether to check if pipeline is active
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with properly typed pipeline data
+ """
+ params = {}
+ if check_active:
+ params["check_active"] = "true"
+
+ try:
+ response = self.get(
+ f"v1/pipeline/{pipeline_id}/",
+ params=params,
+ organization_id=organization_id,
+ )
+
+ # Handle the actual backend API response format: {"status": "success", "pipeline": {...}}
+ if isinstance(response, dict):
+ status = response.get("status")
+ if status == "success":
+ # Parse response with type safety
+ pipeline_api_response = PipelineApiResponse.from_dict(response)
+
+ logger.debug(
+ f"Parsed pipeline data for {pipeline_id}: "
+ f"name='{pipeline_api_response.pipeline.pipeline_name}', "
+ f"workflow='{pipeline_api_response.pipeline.workflow_id}'"
+ )
+
+ return APIResponse.success_response(
+ data=pipeline_api_response.to_dict(),
+ message=f"Successfully retrieved pipeline data for {pipeline_id}",
+ )
+ else:
+ return APIResponse.error_response(
+ error=response.get("error", "Unknown error"),
+ message=f"Failed to retrieve pipeline data for {pipeline_id}",
+ )
+ else:
+ # Fallback to legacy conversion
+ return convert_dict_response(response, APIResponse)
+
+ except Exception as e:
+ logger.error(f"Error parsing pipeline data for {pipeline_id}: {e}")
+ return APIResponse.error_response(
+ error=str(e),
+ message=f"Failed to parse pipeline data for {pipeline_id}",
+ )
diff --git a/workers/shared/clients/file_client.py b/workers/shared/clients/file_client.py
new file mode 100644
index 000000000..a0f8592bf
--- /dev/null
+++ b/workers/shared/clients/file_client.py
@@ -0,0 +1,889 @@
+"""File API Client for File Operations
+
+This module provides specialized API client for file-related operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- File execution management
+- File history operations
+- File batch operations
+- File status updates
+- File metadata management
+"""
+
+import logging
+import uuid
+from typing import Any
+from uuid import UUID
+
+from ..constants.api_endpoints import build_internal_endpoint
+from ..data.models import (
+ APIResponse,
+ BatchOperationRequest,
+ BatchOperationResponse,
+ StatusUpdateRequest,
+)
+from ..enums import BatchOperationType, TaskStatus
+from .base_client import APIRequestError, BaseAPIClient
+
+# Note: These would be imported from unstract.core.data_models in production
+# For now, using mock classes for testing
+try:
+ from unstract.core.data_models import (
+ FileExecutionCreateRequest,
+ FileExecutionStatusUpdateRequest,
+ FileHashData,
+ WorkflowFileExecutionData,
+ )
+except ImportError:
+ # Mock classes for testing when unstract.core is not available
+ class MockDataClass:
+ def __init__(self, **kwargs):
+ for key, value in kwargs.items():
+ setattr(self, key, value)
+
+ def to_dict(self):
+ return dict(self.__dict__.items())
+
+ @classmethod
+ def from_dict(cls, data):
+ return cls(**data)
+
+ def ensure_hash(self):
+ # Mock implementation - no hash computation needed for testing
+ pass
+
+ def validate_for_api(self):
+ # Mock implementation - no validation needed for testing
+ pass
+
+ WorkflowFileExecutionData = MockDataClass
+ FileHashData = MockDataClass
+ FileExecutionCreateRequest = MockDataClass
+ FileExecutionStatusUpdateRequest = MockDataClass
+
+logger = logging.getLogger(__name__)
+
+
+class FileAPIClient(BaseAPIClient):
+ """Specialized API client for file-related operations.
+
+ This client handles all file-related operations including:
+ - File execution management
+ - File history operations
+ - File metadata management
+ - File batch operations
+ - File status updates
+ """
+
+ def get_workflow_file_execution(
+ self, file_execution_id: str | UUID, organization_id: str | None = None
+ ) -> WorkflowFileExecutionData:
+ """Get an existing workflow file execution by ID.
+
+ Args:
+ file_execution_id: File execution ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ WorkflowFileExecutionData instance
+ """
+ # Build URL for file execution detail endpoint
+ url = build_internal_endpoint(f"file-execution/{file_execution_id}/").lstrip("/")
+
+ # Get the file execution record
+ response_data = self.client.get(url, organization_id=organization_id)
+
+ # Convert to WorkflowFileExecutionData
+ return WorkflowFileExecutionData.from_dict(response_data)
+
+ def get_or_create_workflow_file_execution(
+ self,
+ execution_id: str | UUID,
+ file_hash: dict[str, Any] | FileHashData,
+ workflow_id: str | UUID,
+ organization_id: str | None = None,
+ force_create: bool = False,
+ ) -> WorkflowFileExecutionData:
+ """Get or create a workflow file execution record using shared dataclasses.
+
+ Args:
+ execution_id: Execution ID
+ file_hash: File hash data (dict or FileHashData)
+ workflow_id: Workflow ID
+ organization_id: Optional organization ID override
+ force_create: If True, skip lookup and always create new record
+
+ Returns:
+ WorkflowFileExecutionData instance
+ """
+ # Convert file_hash to FileHashData if it's a dict
+ if isinstance(file_hash, dict):
+ file_hash_data = FileHashData.from_dict(file_hash)
+ else:
+ file_hash_data = file_hash
+
+ # Debug logging to understand API file detection
+ logger.info(
+ f"FileHashData debug: file_name='{file_hash_data.file_name}', "
+ f"has_hash={file_hash_data.has_hash()}, "
+ f"source_connection_type='{getattr(file_hash_data, 'source_connection_type', None)}'"
+ )
+
+ # CRITICAL FIX: For API files with pre-calculated hash, skip hash computation
+ # to prevent temporary MD5 path hash generation
+ if (
+ file_hash_data.has_hash()
+ and getattr(file_hash_data, "source_connection_type", None) == "API"
+ ):
+ logger.info(
+ f"API file with pre-calculated hash: {file_hash_data.file_hash[:16]}... - skipping validation"
+ )
+ else:
+ # For non-API files or files without hash, we'd need content/path to compute hash
+ # For now, just validate what we have
+ logger.info(
+ f"Non-API file or file without hash: {file_hash_data.file_name} - proceeding with validation"
+ )
+
+ # Enhanced validation with detailed error reporting
+ try:
+ file_hash_data.validate_for_api()
+ except ValueError as e:
+ logger.error(f"FileHashData validation failed: {str(e)}")
+ logger.error(
+ f"FileHashData details: file_name='{file_hash_data.file_name}', "
+ f"file_path='{file_hash_data.file_path}', "
+ f"file_hash='{file_hash_data.file_hash[:16]}...', "
+ f"provider_file_uuid='{file_hash_data.provider_file_uuid}'"
+ )
+
+ # Provide actionable error message based on validation failure
+ if not file_hash_data.file_name:
+ raise APIRequestError(
+ "File name is required for WorkflowFileExecution creation"
+ )
+ elif not file_hash_data.file_path:
+ raise APIRequestError(
+ "File path is required for WorkflowFileExecution creation"
+ )
+ else:
+ raise APIRequestError(
+ f"FileHashData validation failed: {str(e)}. "
+ f"Check file path accessibility and connector configuration."
+ ) from e
+
+ # First try to get existing record - CRITICAL FIX: Match backend manager logic
+ params = {
+ "execution_id": str(execution_id),
+ "workflow_id": str(workflow_id),
+ "file_path": file_hash_data.file_path, # CRITICAL: Include file_path to match unique constraints
+ }
+
+ # Match backend manager logic: use file_hash OR provider_file_uuid (not both)
+ if file_hash_data.file_hash:
+ params["file_hash"] = file_hash_data.file_hash
+ elif file_hash_data.provider_file_uuid:
+ params["provider_file_uuid"] = file_hash_data.provider_file_uuid
+ else:
+ logger.warning(
+ "No file_hash or provider_file_uuid available for lookup - this may cause issues"
+ )
+
+ logger.debug(f"Lookup parameters: {params}")
+
+ if not force_create:
+ try:
+ # Try to get existing record
+ response = self.get(
+ self._build_url("file_execution"),
+ params=params,
+ organization_id=organization_id,
+ )
+ if response and isinstance(response, list) and len(response) > 0:
+ logger.debug(
+ f"Found existing workflow file execution: {response[0].get('id')}"
+ )
+ return WorkflowFileExecutionData.from_dict(response[0])
+ except Exception as e:
+ logger.debug(f"Could not get existing workflow file execution: {str(e)}")
+ # Continue to create if not found
+ else:
+ logger.debug("Force create enabled - skipping existing record lookup")
+
+ # Create request using shared dataclass
+ create_request = FileExecutionCreateRequest(
+ execution_id=execution_id, file_hash=file_hash_data, workflow_id=workflow_id
+ )
+
+ data = create_request.to_dict()
+
+ logger.info(
+ f"Creating workflow file execution with file_hash: {file_hash_data.file_name}"
+ )
+ logger.info(
+ f"FileHashData key identifiers: provider_file_uuid='{file_hash_data.provider_file_uuid}', "
+ f"file_path='{file_hash_data.file_path}', file_hash='{file_hash_data.file_hash}'"
+ )
+ logger.debug(f"FileHashData: {file_hash_data.to_dict()}")
+
+ try:
+ result = self.post(
+ self._build_url("file_execution"), data, organization_id=organization_id
+ )
+
+ # Handle both list and dict responses (defensive programming)
+ if isinstance(result, list):
+ logger.warning(
+ f"Backend returned list instead of dict for file execution create: {len(result)} items"
+ )
+ if len(result) > 0:
+ file_execution_dict = result[0] # Take first item from list
+ logger.info(
+ f"Successfully created workflow file execution: {file_execution_dict.get('id') if isinstance(file_execution_dict, dict) else 'unknown'}"
+ )
+ return WorkflowFileExecutionData.from_dict(file_execution_dict)
+ else:
+ logger.error("Backend returned empty list for file execution create")
+ raise APIRequestError(
+ "Backend returned empty list for file execution create"
+ )
+ elif isinstance(result, dict):
+ file_execution_id = result.get("id", "unknown")
+ logger.info(
+ f"Successfully created workflow file execution: {file_execution_id}"
+ )
+ logger.info(
+ f"Created for file: {file_hash_data.file_name} with provider_file_uuid: {file_hash_data.provider_file_uuid}"
+ )
+ return WorkflowFileExecutionData.from_dict(result)
+ else:
+ logger.error(
+ f"Backend returned unexpected type for file execution create: {type(result)}"
+ )
+ raise APIRequestError(
+ f"Backend returned unexpected response type: {type(result)}"
+ )
+ except Exception as e:
+ logger.error(
+ f"Failed to create workflow file execution: {str(e)}", exc_info=True
+ )
+ logger.debug(f"Request data was: {data}")
+ raise
+
+ def update_workflow_file_execution_hash(
+ self,
+ file_execution_id: str | UUID,
+ file_hash: str,
+ fs_metadata: dict[str, Any] | None = None,
+ mime_type: str | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Update workflow file execution with computed file hash and mime_type.
+
+ This method should be used when the SHA256 content hash is computed
+ after the WorkflowFileExecution record is initially created.
+
+ Args:
+ file_execution_id: ID of the WorkflowFileExecution record to update
+ file_hash: Computed SHA256 hash of file content
+ fs_metadata: Optional filesystem metadata to update
+ mime_type: Optional MIME type to update
+ organization_id: Optional organization ID override
+
+ Returns:
+ Updated WorkflowFileExecution data
+ """
+ data = {"file_hash": file_hash}
+ if fs_metadata:
+ data["fs_metadata"] = fs_metadata
+ if mime_type:
+ data["mime_type"] = mime_type
+
+ logger.info(
+ f"Updating file execution {file_execution_id} with computed hash: {file_hash[:16]}..."
+ )
+
+ try:
+ response = self.patch(
+ self._build_url(
+ "file_execution", f"{str(file_execution_id)}/update_hash/"
+ ),
+ data,
+ organization_id=organization_id,
+ )
+
+ logger.info(
+ f"Successfully updated file execution {file_execution_id} with hash"
+ )
+ return response
+
+ except Exception as e:
+ logger.error(f"Failed to update file execution hash: {str(e)}")
+ raise APIRequestError(
+ f"Failed to update file execution hash: {str(e)}"
+ ) from e
+
+ def update_file_execution_status(
+ self,
+ file_execution_id: str | UUID,
+ status: str | TaskStatus,
+ execution_time: float | None = None,
+ error_message: str | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Update workflow file execution status with execution time.
+
+ This method updates the WorkflowFileExecution record with status and execution time,
+ matching the Django model's update_status() method behavior.
+
+ Args:
+ file_execution_id: ID of the WorkflowFileExecution record to update
+ status: New execution status (TaskStatus enum or string)
+ execution_time: Execution time in seconds (optional)
+ error_message: Error message if status is ERROR (optional)
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with update result
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ data = {"status": status_str}
+
+ if execution_time is not None:
+ data["execution_time"] = execution_time
+ if error_message is not None:
+ data["error_message"] = error_message
+
+ logger.info(
+ f"Updating file execution {file_execution_id} status to {status_str}"
+ f"{f' with execution_time {execution_time:.2f}s' if execution_time else ''}"
+ )
+
+ try:
+ response = self.post(
+ self._build_url("file_execution", f"{str(file_execution_id)}/status/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Successfully updated file execution {file_execution_id} status")
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to update file execution status: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def update_workflow_file_execution_status(
+ self,
+ file_execution_id: str,
+ status: str | TaskStatus,
+ result: str | None = None,
+ error_message: str | None = None,
+ ) -> APIResponse:
+ """Update WorkflowFileExecution status via internal API using shared dataclasses.
+
+ Args:
+ file_execution_id: File execution ID
+ status: New status (TaskStatus enum or string)
+ result: Execution result (optional)
+ error_message: Error message if any
+
+ Returns:
+ APIResponse with update result
+ """
+ try:
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ # Create status update request using shared dataclass
+ update_request = FileExecutionStatusUpdateRequest(
+ status=status_str, error_message=error_message, result=result
+ )
+
+ # Use the internal file execution status endpoint
+ endpoint = self._build_url("file_execution", f"{file_execution_id}/status/")
+ response = self.post(endpoint, update_request.to_dict())
+
+ logger.info(
+ f"Successfully updated WorkflowFileExecution {file_execution_id} status to {status_str}"
+ )
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to update WorkflowFileExecution status for {file_execution_id}: {str(e)}"
+ )
+ # Don't raise exception to avoid breaking worker flow
+ return APIResponse(success=False, error=str(e))
+
+ def create_workflow_file_execution(
+ self,
+ workflow_execution_id: str,
+ file_name: str,
+ file_path: str,
+ file_hash: str,
+ file_execution_id: str | None = None,
+ file_size: int = 0,
+ mime_type: str = "",
+ provider_file_uuid: str | None = None,
+ fs_metadata: dict[str, Any] | None = None,
+ status: str | TaskStatus = TaskStatus.PENDING,
+ ) -> APIResponse:
+ """Create WorkflowFileExecution record via internal API with complete metadata.
+
+ Uses the existing backend endpoint that expects file_hash object format.
+ Now supports all the fields needed for proper file hash generation.
+
+ Args:
+ workflow_execution_id: Workflow execution ID
+ file_name: File name
+ file_path: File path
+ file_hash: Actual computed SHA256 file hash (not dummy)
+ file_execution_id: Optional unique file execution ID
+ file_size: File size in bytes
+ mime_type: File MIME type
+ provider_file_uuid: Provider-specific file UUID
+ fs_metadata: File system metadata
+ status: Initial status
+
+ Returns:
+ Created WorkflowFileExecution data
+ """
+ try:
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ # Format data to match backend WorkflowFileExecutionAPIView expectations
+ data = {
+ "execution_id": workflow_execution_id,
+ "workflow_id": workflow_execution_id, # Will be extracted from execution
+ "file_hash": {
+ "file_name": file_name,
+ "file_path": file_path,
+ "file_hash": file_hash, # Actual computed hash
+ "file_size": file_size,
+ "mime_type": mime_type,
+ "provider_file_uuid": provider_file_uuid,
+ "fs_metadata": fs_metadata or {},
+ "is_executed": False,
+ },
+ "status": status_str,
+ }
+
+ # Include file_execution_id if provided
+ if file_execution_id:
+ data["file_execution_id"] = file_execution_id
+
+ # Log the actual hash being used
+ if file_hash:
+ logger.info(
+ f"Creating WorkflowFileExecution with actual hash {file_hash} for {file_name}"
+ )
+ else:
+ logger.warning(
+ f"Creating WorkflowFileExecution with empty hash for {file_name}"
+ )
+
+ response = self.post("v1/workflow-manager/file-execution/", data)
+ logger.info(
+ f"Successfully created WorkflowFileExecution for {file_name} with hash {file_hash[:8] if file_hash else 'empty'}..."
+ )
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+ except Exception as e:
+ logger.error(f"Failed to create WorkflowFileExecution: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def batch_create_file_executions(
+ self, file_executions: list[dict[str, Any]], organization_id: str | None = None
+ ) -> BatchOperationResponse:
+ """Create multiple file executions in a single batch request.
+
+ Args:
+ file_executions: List of file execution data dictionaries
+ organization_id: Optional organization ID override
+
+ Returns:
+ BatchOperationResponse with results
+ """
+ batch_request = BatchOperationRequest(
+ operation_type=BatchOperationType.CREATE,
+ items=file_executions,
+ organization_id=organization_id,
+ )
+
+ response = self.post(
+ "v1/workflow-manager/file-execution/batch-create/",
+ batch_request.to_dict(),
+ organization_id=organization_id,
+ )
+
+ return BatchOperationResponse(
+ operation_id=response.get("operation_id", str(uuid.uuid4())),
+ total_items=len(file_executions),
+ successful_items=response.get("successful_items", 0),
+ failed_items=response.get("failed_items", 0),
+ status=TaskStatus(response.get("status", TaskStatus.SUCCESS.value)),
+ results=response.get("results", []),
+ errors=response.get("errors", []),
+ execution_time=response.get("execution_time"),
+ )
+
+ def batch_update_file_execution_status(
+ self,
+ status_updates: list[dict[str, Any] | StatusUpdateRequest],
+ organization_id: str | None = None,
+ ) -> BatchOperationResponse:
+ """Update multiple file execution statuses in a single batch request.
+
+ Args:
+ status_updates: List of StatusUpdateRequest objects or dictionaries
+ organization_id: Optional organization ID override
+
+ Returns:
+ BatchOperationResponse with results
+ """
+ # Convert updates to dictionaries if they are dataclasses
+ update_dicts = []
+ for update in status_updates:
+ if isinstance(update, StatusUpdateRequest):
+ update_dicts.append(update.to_dict())
+ else:
+ update_dicts.append(update)
+
+ batch_request = BatchOperationRequest(
+ operation_type=BatchOperationType.STATUS_UPDATE,
+ items=update_dicts,
+ organization_id=organization_id,
+ )
+
+ response = self.post(
+ "v1/workflow-manager/file-execution/batch-status-update/",
+ batch_request.to_dict(),
+ organization_id=organization_id,
+ )
+
+ return BatchOperationResponse(
+ operation_id=response.get("operation_id", str(uuid.uuid4())),
+ total_items=len(status_updates),
+ successful_items=response.get("successful_items", 0),
+ failed_items=response.get("failed_items", 0),
+ status=TaskStatus(response.get("status", TaskStatus.SUCCESS.value)),
+ results=response.get("results", []),
+ errors=response.get("errors", []),
+ execution_time=response.get("execution_time"),
+ )
+
+ # File History API methods
+ def get_file_history_by_cache_key(
+ self, cache_key: str, workflow_id: str | uuid.UUID, file_path: str | None = None
+ ) -> dict[str, Any]:
+ """Get file history by cache key.
+
+ Args:
+ cache_key: Cache key to look up
+ workflow_id: Workflow ID
+ file_path: Optional file path
+
+ Returns:
+ File history data
+ """
+ params = {"workflow_id": str(workflow_id)}
+ if file_path:
+ params["file_path"] = file_path
+ return self.get(
+ self._build_url("file_history", f"cache-key/{cache_key}/"), params=params
+ )
+
+ def get_file_history_flexible(
+ self,
+ workflow_id: str | uuid.UUID,
+ cache_key: str | None = None,
+ provider_file_uuid: str | None = None,
+ file_path: str | None = None,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Get file history using flexible parameters (cache_key OR provider_file_uuid).
+
+ Args:
+ workflow_id: Workflow ID
+ cache_key: Optional cache key (content hash)
+ provider_file_uuid: Optional provider file UUID
+ file_path: Optional file path
+ organization_id: Optional organization ID
+
+ Returns:
+ File history data
+
+ Raises:
+ ValueError: If neither cache_key nor provider_file_uuid is provided
+ """
+ if not cache_key and not provider_file_uuid:
+ raise ValueError("Either cache_key or provider_file_uuid must be provided")
+
+ payload = {
+ "workflow_id": str(workflow_id),
+ "cache_key": cache_key,
+ "provider_file_uuid": provider_file_uuid,
+ "file_path": file_path,
+ "organization_id": organization_id,
+ }
+
+ # Remove None values to keep payload clean
+ payload = {k: v for k, v in payload.items() if v is not None}
+
+ return self.post(self._build_url("file_history", "lookup/"), data=payload)
+
+ def get_files_history_batch(
+ self,
+ workflow_id: str | uuid.UUID,
+ files: list[dict[str, str]],
+ organization_id: str | None = None,
+ ) -> dict[str, dict[str, Any]]:
+ """Get file history for multiple files in a single batch operation.
+
+ Args:
+ workflow_id: Workflow ID
+ files: List of file data dictionaries. Each dict can contain:
+ - cache_key (optional): Content hash
+ - provider_file_uuid (optional): Provider file UUID
+ - file_path (optional): File path
+ - identifier (optional): Custom identifier for response mapping
+ organization_id: Optional organization ID
+
+ Returns:
+ Dictionary mapping file identifiers to their history data:
+ {
+ "identifier1": {"found": True, "is_completed": True, "file_history": {...}},
+ "identifier2": {"found": False, "is_completed": False, "file_history": None}
+ }
+
+ Raises:
+ ValueError: If files list is empty or any file lacks required identifiers
+ """
+ if not files:
+ raise ValueError("Files list cannot be empty")
+
+ # Validate that each file has at least one identifier
+ for i, file_data in enumerate(files):
+ if not any([file_data.get("cache_key"), file_data.get("provider_file_uuid")]):
+ raise ValueError(
+ f"File at index {i} must have either 'cache_key' or 'provider_file_uuid'"
+ )
+
+ payload = {
+ "workflow_id": str(workflow_id),
+ "files": files,
+ "organization_id": organization_id,
+ }
+
+ # Remove None values to keep payload clean
+ payload = {k: v for k, v in payload.items() if v is not None}
+
+ response = self.post(
+ self._build_url("file_history", "batch-lookup/"), data=payload
+ )
+ return response.get("file_histories", {})
+
+ def reserve_file_processing(
+ self,
+ workflow_id: str | UUID,
+ cache_key: str,
+ provider_file_uuid: str | None = None,
+ file_path: str | None = None,
+ worker_id: str | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Atomic check-and-reserve operation for file processing deduplication.
+
+ This method handles race conditions by atomically checking if a file
+ should be processed and reserving it if not already processed/reserved.
+
+ Args:
+ workflow_id: Workflow ID
+ cache_key: File cache key (usually file hash or provider UUID)
+ provider_file_uuid: Provider file UUID (optional)
+ file_path: File path (optional)
+ worker_id: Unique worker identifier (optional)
+ organization_id: Optional organization ID override
+
+ Returns:
+ APIResponse with reservation result containing:
+ - reserved: bool - Whether file was reserved for this worker
+ - already_processed: bool - Whether file was already processed
+ - already_reserved: bool - Whether file was already reserved by another worker
+ - file_history: dict - Existing file history if already processed
+ """
+ data = {"workflow_id": str(workflow_id), "cache_key": cache_key}
+
+ if provider_file_uuid:
+ data["provider_file_uuid"] = provider_file_uuid
+ if file_path:
+ data["file_path"] = file_path
+ if worker_id:
+ data["worker_id"] = worker_id
+
+ logger.info(
+ f"Reserving file processing for workflow {workflow_id}, cache_key: {cache_key[:16]}..."
+ )
+
+ try:
+ response = self.post(
+ self._build_url("file_history", "reserve/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ return APIResponse(
+ success=response.get("reserved", False)
+ or response.get("already_processed", False),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to reserve file processing: {str(e)}")
+ raise APIRequestError(f"Failed to reserve file processing: {str(e)}") from e
+
+ def create_file_history(
+ self,
+ workflow_id: str | uuid.UUID,
+ file_name: str,
+ source_connection_type: str,
+ file_path: str,
+ result: str | None = None,
+ metadata: dict[str, Any] | None = None,
+ status: str | TaskStatus = TaskStatus.SUCCESS,
+ error: str | None = None,
+ provider_file_uuid: str | None = None,
+ is_api: bool = False,
+ file_size: int = 0,
+ file_hash: str = "",
+ mime_type: str = "",
+ ) -> APIResponse:
+ """Create file history record matching backend expected format.
+
+ Args:
+ workflow_id: Workflow ID
+ file_name: File name
+ source_connection_type: Source connection type
+ file_path: File path
+ result: Execution result
+ metadata: result metadata
+ status: Execution status
+ error: Error message if any
+ provider_file_uuid: Provider-specific file UUID
+ is_api: Whether this is an API execution
+ file_size: File size in bytes
+ file_hash: File hash
+ mime_type: File MIME type
+
+ Returns:
+ Created file history data
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ data = {
+ "organization_id": self.organization_id,
+ "workflow_id": str(workflow_id),
+ "provider_file_uuid": provider_file_uuid,
+ "mime_type": mime_type,
+ "file_path": file_path,
+ "file_name": file_name,
+ "source_connection_type": source_connection_type,
+ "file_size": file_size,
+ "file_hash": file_hash,
+ "is_api": is_api,
+ "status": status_str,
+ "metadata": metadata or {},
+ }
+ data = {k: v for k, v in data.items() if v is not None}
+
+ # Add optional fields if provided
+ if result is not None:
+ data["result"] = result
+ if error is not None:
+ data["error"] = error
+
+ logger.info(
+ f"Creating file history record for {file_name} with status: {status_str}"
+ )
+ try:
+ response = self.post(self._build_url("file_history", "create/"), data)
+ logger.info(
+ f"Successfully created file history record: {response.get('id') if response else 'unknown'}"
+ )
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+ except Exception as e:
+ logger.error(f"Failed to create file history record: {str(e)}")
+ logger.debug(f"Request data was: {data}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_file_history_status(self, file_history_id: str | uuid.UUID) -> dict[str, Any]:
+ """Get file history status.
+
+ Args:
+ file_history_id: File history ID
+
+ Returns:
+ File history status data
+ """
+ return self.get(
+ self._build_url("file_history", f"status/{str(file_history_id)}/")
+ )
+
+ def batch_create_file_history(
+ self, file_histories: list[dict[str, Any]], organization_id: str | None = None
+ ) -> BatchOperationResponse:
+ """Create multiple file history records in a single batch request.
+
+ Args:
+ file_histories: List of file history data dictionaries
+ organization_id: Optional organization ID override
+
+ Returns:
+ BatchOperationResponse with results
+ """
+ batch_request = BatchOperationRequest(
+ operation_type=BatchOperationType.CREATE,
+ items=file_histories,
+ organization_id=organization_id,
+ )
+
+ # Note: No batch endpoint exists, would need individual creation calls
+ # For now, this will return an error indicating batch operations not supported
+ response = self.post(
+ "v1/file-history/create/", # Use individual create endpoint
+ batch_request.to_dict(),
+ organization_id=organization_id,
+ )
+
+ return BatchOperationResponse(
+ operation_id=response.get("operation_id", str(uuid.uuid4())),
+ total_items=len(file_histories),
+ successful_items=response.get("successful_items", 0),
+ failed_items=response.get("failed_items", 0),
+ status=TaskStatus(response.get("status", TaskStatus.SUCCESS.value)),
+ results=response.get("results", []),
+ errors=response.get("errors", []),
+ execution_time=response.get("execution_time"),
+ )
diff --git a/workers/shared/clients/log_client.py b/workers/shared/clients/log_client.py
new file mode 100644
index 000000000..790591ca7
--- /dev/null
+++ b/workers/shared/clients/log_client.py
@@ -0,0 +1,144 @@
+"""Log operations client for internal API communication.
+
+This client handles log history operations through internal APIs to avoid
+direct Django ORM dependencies.
+"""
+
+import logging
+
+from ..data.response_models import APIResponse
+from .base_client import BaseAPIClient
+
+logger = logging.getLogger(__name__)
+
+
+class LogAPIClient(BaseAPIClient):
+ """Client for log-related operations through internal APIs."""
+
+ def get_workflow_executions(self, execution_ids: list[str]) -> APIResponse:
+ """Get workflow execution data for given IDs.
+
+ Args:
+ execution_ids: List of workflow execution IDs
+
+ Returns:
+ APIResponse containing executions data
+ """
+ try:
+ response_data = self.post(
+ endpoint="/v1/execution-logs/workflow-executions/by-ids/",
+ data={"execution_ids": execution_ids},
+ )
+
+ return APIResponse.success_response(
+ data=response_data,
+ message=f"Retrieved {len(execution_ids)} workflow executions",
+ )
+
+ except Exception as e:
+ logger.error(f"Exception getting workflow executions: {e}")
+ return APIResponse.error_response(
+ error=str(e), message="Failed to get workflow executions"
+ )
+
+ def get_file_executions(self, file_execution_ids: list[str]) -> APIResponse:
+ """Get file execution data for given IDs.
+
+ Args:
+ file_execution_ids: List of file execution IDs
+
+ Returns:
+ APIResponse containing file executions data
+ """
+ try:
+ response_data = self.post(
+ endpoint="/v1/execution-logs/file-executions/by-ids/",
+ data={"file_execution_ids": file_execution_ids},
+ )
+
+ return APIResponse.success_response(
+ data=response_data,
+ message=f"Retrieved {len(file_execution_ids)} file executions",
+ )
+
+ except Exception as e:
+ logger.error(f"Exception getting file executions: {e}")
+ return APIResponse.error_response(
+ error=str(e), message="Failed to get file executions"
+ )
+
+ def validate_execution_references(
+ self, execution_ids: list[str], file_execution_ids: list[str]
+ ) -> APIResponse:
+ """Validate that execution references exist before creating logs.
+
+ Args:
+ execution_ids: List of workflow execution IDs to validate
+ file_execution_ids: List of file execution IDs to validate
+
+ Returns:
+ APIResponse with validation results:
+ - valid_executions: Set of valid execution IDs
+ - valid_file_executions: Set of valid file execution IDs
+ """
+ try:
+ response_data = self.post(
+ endpoint="/v1/execution-logs/executions/validate/",
+ data={
+ "execution_ids": execution_ids,
+ "file_execution_ids": file_execution_ids,
+ },
+ )
+
+ # Convert lists to sets for easier validation logic
+ validation_data = {
+ "valid_executions": set(response_data.get("valid_executions", [])),
+ "valid_file_executions": set(
+ response_data.get("valid_file_executions", [])
+ ),
+ }
+
+ return APIResponse.success_response(
+ data=validation_data,
+ message=f"Validated {len(execution_ids)} executions and {len(file_execution_ids)} file executions",
+ )
+
+ except Exception as e:
+ logger.error(f"Exception validating execution references: {e}")
+ return APIResponse.error_response(
+ error=str(e), message="Failed to validate execution references"
+ )
+
+ def get_cache_log_batch(self, queue_name: str, batch_limit: int = 100) -> APIResponse:
+ """Get a batch of logs from Redis cache via internal API.
+
+ Args:
+ queue_name: Name of the Redis queue to retrieve logs from
+ batch_limit: Maximum number of logs to retrieve
+
+ Returns:
+ APIResponse containing logs data
+ """
+ try:
+ response_data = self.post(
+ endpoint="/v1/execution-logs/cache/log-batch/",
+ data={
+ "queue_name": queue_name,
+ "batch_limit": batch_limit,
+ },
+ )
+
+ logs = response_data.get("logs", [])
+ logs_count = response_data.get("count", len(logs))
+
+ logger.debug(f"Retrieved {logs_count} logs from cache queue {queue_name}")
+
+ return APIResponse.success_response(
+ data=response_data, message=f"Retrieved {logs_count} logs from cache"
+ )
+
+ except Exception as e:
+ logger.error(f"Exception getting log batch: {e}")
+ return APIResponse.error_response(
+ error=str(e), message="Failed to get log batch from cache"
+ )
diff --git a/workers/shared/clients/manual_review_stub.py b/workers/shared/clients/manual_review_stub.py
new file mode 100644
index 000000000..9768a64d9
--- /dev/null
+++ b/workers/shared/clients/manual_review_stub.py
@@ -0,0 +1,329 @@
+"""Manual Review Null Client - OSS Compatibility
+
+This module provides a null object implementation of the manual review client
+for the OSS version of Unstract. It provides safe defaults and no-op implementations
+for all manual review functionality, allowing the OSS version to work seamlessly
+without any manual review code.
+
+The null object pattern eliminates the need for conditional checks throughout
+the codebase while ensuring graceful degradation when manual review functionality
+is not available.
+"""
+
+import logging
+from typing import Any
+
+from ..enums import FileDestinationType
+from ..utils.manual_review_response import ManualReviewResponse
+
+logger = logging.getLogger(__name__)
+
+# Stub uses simple dicts - no need for complex dataclasses when manual review is disabled
+
+
+class ManualReviewNullClient:
+ """Null object implementation for manual review functionality in OSS.
+
+ This class provides safe, no-op implementations of all manual review
+ methods, allowing the OSS version to function without manual review
+ capabilities. All methods return appropriate default values that
+ indicate manual review is not available or not required.
+ """
+
+ def __init__(self, config: Any = None):
+ """Initialize the null client.
+
+ Args:
+ config: Configuration object (ignored in null implementation)
+ """
+ self.config = config
+ logger.debug("Initialized ManualReviewNullClient - manual review disabled in OSS")
+
+ def set_organization_context(self, organization_id: str) -> None:
+ """Set organization context (no-op in null implementation).
+
+ Args:
+ organization_id: Organization ID
+ """
+ logger.debug(
+ f"ManualReviewNullClient: set_organization_context called with {organization_id} - no-op"
+ )
+
+ def get_q_no_list(
+ self, workflow_id: str, total_files: int = 0, organization_id: str | None = None
+ ) -> ManualReviewResponse:
+ """Get queue file numbers for manual review (returns empty list in
+ OSS).
+
+ Args:
+ workflow_id: Workflow ID
+ total_files: Total number of files (unused in stub)
+ organization_id: Organization ID (unused in stub)
+
+ Returns:
+ ManualReviewResponse with empty q_file_no_list indicating no files for manual review
+ """
+ logger.debug(
+ f"ManualReviewNullClient: get_q_no_list called for workflow {workflow_id} - returning empty list"
+ )
+ return ManualReviewResponse.success_response(
+ data={"q_file_no_list": []},
+ message="Manual review not available in OSS - no files selected for review",
+ )
+
+ def get_db_rules_data(
+ self, workflow_id: str, _organization_id: str | None = None
+ ) -> ManualReviewResponse:
+ """Get database rules for manual review (returns no rules in OSS).
+
+ Args:
+ workflow_id: Workflow ID
+ _organization_id: Organization ID (unused in stub)
+
+ Returns:
+ ManualReviewResponse indicating no manual review rules are configured
+ """
+ logger.debug(
+ f"ManualReviewNullClient: get_db_rules_data called for workflow {workflow_id} - returning no rules"
+ )
+ return ManualReviewResponse.success_response(
+ data={"rules": [], "percentage": 0, "review_required": False},
+ message="Manual review not available in OSS - no rules configured",
+ )
+
+ def enqueue_manual_review(self, *args, **kwargs) -> dict[str, Any]:
+ """Enqueue item for manual review (no-op in OSS).
+
+ Returns:
+ Dictionary indicating manual review is not available
+ """
+ logger.debug(
+ "ManualReviewNullClient: enqueue_manual_review called - not available in OSS"
+ )
+ return {
+ "success": False,
+ "message": "Manual review not available in OSS version",
+ "queue_name": None,
+ }
+
+ def route_to_manual_review(
+ self,
+ file_execution_id: str,
+ file_data: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Route file to manual review (no-op in OSS).
+
+ In OSS, files marked for manual review are processed normally
+ since there's no manual review backend infrastructure.
+
+ Args:
+ file_execution_id: Workflow file execution ID
+ file_data: File hash data dictionary
+ workflow_id: Workflow UUID
+ execution_id: Execution UUID
+ organization_id: Organization context
+
+ Returns:
+ Dictionary indicating manual review routing skipped
+ """
+ logger.debug(
+ f"ManualReviewNullClient: route_to_manual_review called for file {file_data.get('file_name', 'unknown')} - skipping in OSS"
+ )
+ return {
+ "success": True, # Return success to avoid blocking workflow
+ "message": "Manual review not available in OSS - file will be processed normally",
+ "queue_name": f"review_queue_{organization_id}_{workflow_id}",
+ "skipped": True,
+ }
+
+ def route_with_results(
+ self,
+ file_execution_id: str,
+ file_data: dict[str, Any],
+ workflow_result: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str | None = None,
+ file_name: str = "unknown",
+ ) -> dict[str, Any]:
+ """Route file to manual review with results (no-op in OSS).
+
+ In OSS, files marked for manual review are processed normally
+ since manual review functionality is not available.
+
+ Args:
+ file_execution_id: Workflow file execution ID
+ file_data: File hash data dictionary
+ workflow_result: Results from tool execution
+ workflow_id: Workflow UUID
+ execution_id: Execution UUID
+ organization_id: Organization context
+ file_name: File name for logging
+
+ Returns:
+ Dictionary indicating manual review routing skipped, includes results
+ """
+ logger.debug(
+ f"ManualReviewNullClient: route_with_results called for file {file_name} - skipping in OSS"
+ )
+
+ # Extract tool results from workflow_result for consistency
+ tool_result = None
+ if workflow_result and "result" in workflow_result:
+ tool_result = workflow_result["result"]
+ elif workflow_result and "output" in workflow_result:
+ tool_result = workflow_result["output"]
+ else:
+ tool_result = workflow_result
+
+ # Simple dict return for OSS stub - no dataclass complexity needed
+ return {
+ "success": True, # Return success to avoid blocking workflow
+ "message": "Manual review not available in OSS - file processed normally with results",
+ "file": file_name,
+ "file_execution_id": file_execution_id,
+ "error": None,
+ "result": tool_result,
+ "metadata": {
+ "routed_to_manual_review": False,
+ "has_tool_results": tool_result is not None,
+ "processed_before_review": True,
+ "oss_mode": True,
+ },
+ "manual_review": False,
+ "skipped": True,
+ }
+
+ def dequeue_manual_review(self, *args, **kwargs) -> dict[str, Any]:
+ """Dequeue item from manual review (no-op in OSS).
+
+ Returns:
+ Dictionary indicating no items available for review
+ """
+ logger.debug(
+ "ManualReviewNullClient: dequeue_manual_review called - not available in OSS"
+ )
+ return {
+ "success": False,
+ "message": "Manual review not available in OSS version",
+ "item": None,
+ }
+
+ def validate_manual_review_db_rule(self, *args, **kwargs) -> dict[str, Any]:
+ """Validate manual review database rule (no-op in OSS).
+
+ Returns:
+ Dictionary indicating validation is not available
+ """
+ logger.debug(
+ "ManualReviewNullClient: validate_manual_review_db_rule called - not available in OSS"
+ )
+ return {
+ "valid": False,
+ "message": "Manual review validation not available in OSS version",
+ }
+
+ def get_hitl_settings(
+ self, workflow_id: str, organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Get HITL settings for workflow (returns disabled in OSS).
+
+ Args:
+ workflow_id: Workflow ID
+ organization_id: Organization ID
+
+ Returns:
+ Dictionary indicating HITL is disabled
+ """
+ logger.debug(
+ f"ManualReviewNullClient: get_hitl_settings called for workflow {workflow_id} - returning disabled"
+ )
+ return {
+ "enabled": False,
+ "percentage": 0,
+ "auto_approval": False,
+ "message": "HITL settings not available in OSS version",
+ }
+
+ def get_manual_review_workflows(
+ self,
+ connection_type: str = FileDestinationType.MANUALREVIEW.value,
+ organization_id: str | None = None,
+ ) -> list[dict[str, Any]]:
+ """Get workflows configured for manual review (returns empty list in
+ OSS).
+
+ Args:
+ connection_type: Connection type filter
+ organization_id: Organization ID
+
+ Returns:
+ Empty list indicating no workflows have manual review
+ """
+ logger.debug(
+ "ManualReviewNullClient: get_manual_review_workflows called - returning empty list"
+ )
+ return []
+
+ def get_queue_statistics(self, *args, **kwargs) -> dict[str, Any]:
+ """Get manual review queue statistics (returns empty stats in OSS).
+
+ Returns:
+ Dictionary with empty queue statistics
+ """
+ logger.debug(
+ "ManualReviewNullClient: get_queue_statistics called - returning empty stats"
+ )
+ return {
+ "total_queues": 0,
+ "total_items": 0,
+ "pending_review": 0,
+ "pending_approval": 0,
+ "message": "Queue statistics not available in OSS version",
+ }
+
+ def close(self) -> None:
+ """Close the client (no-op in null implementation)."""
+ logger.debug("ManualReviewNullClient: close called - no-op")
+
+ def __enter__(self):
+ """Context manager entry."""
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Context manager exit."""
+ self.close()
+
+ def __getattr__(self, name: str) -> Any:
+ """Handle any other method calls with safe defaults.
+
+ Args:
+ name: Method name that was called
+
+ Returns:
+ A function that returns safe defaults
+ """
+ logger.debug(
+ f"ManualReviewNullClient: unknown method '{name}' called - returning safe default"
+ )
+
+ def safe_default(*args, **kwargs):
+ return {
+ "success": False,
+ "message": f"Manual review method '{name}' not available in OSS version",
+ "data": None,
+ }
+
+ return safe_default
+
+
+# Alias for backward compatibility
+ManualReviewAPIClient = ManualReviewNullClient
+
+__all__ = [
+ "ManualReviewNullClient",
+ "ManualReviewAPIClient", # Backward compatibility alias
+]
diff --git a/workers/shared/clients/organization_client.py b/workers/shared/clients/organization_client.py
new file mode 100644
index 000000000..7e4737f2e
--- /dev/null
+++ b/workers/shared/clients/organization_client.py
@@ -0,0 +1,362 @@
+"""Organization API Client for Organization Context Management
+
+This module provides specialized API client for organization-related operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- Organization context management
+- Organization-specific API calls
+- Multi-tenant organization scoping
+- Organization permissions and access control
+"""
+
+import logging
+
+from unstract.core.data_models import OrganizationContext
+
+from ..data.models import APIResponse
+from ..utils.retry_temp import circuit_breaker
+from .base_client import BaseAPIClient
+
+logger = logging.getLogger(__name__)
+
+
+class OrganizationAPIClient(BaseAPIClient):
+ """Specialized API client for organization context management.
+
+ This client handles all organization-related operations including:
+ - Getting organization context and metadata
+ - Setting organization context for API calls
+ - Managing organization-scoped permissions
+ - Organization membership management
+ - Multi-tenant organization operations
+ """
+
+ def get_organization_context(self, org_id: str) -> OrganizationContext:
+ """Get organization context and metadata.
+
+ Args:
+ org_id: Organization ID
+
+ Returns:
+ Organization context data including permissions, settings, and metadata
+ """
+ logger.debug(f"Getting organization context for {org_id}")
+
+ try:
+ response = self.get(self._build_url("organization", f"{org_id}/context/"))
+
+ org_name = response.get("name", "Unknown")
+ logger.debug(f"Retrieved organization context for {org_name} ({org_id})")
+
+ return OrganizationContext(
+ organization_id=org_id,
+ tenant_id=response.get("tenant_id"),
+ subscription_plan=response.get("subscription_plan"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to get organization context for {org_id}: {str(e)}")
+ raise
+
+ def get_organization_details(self, org_id: str) -> APIResponse:
+ """Get detailed organization information.
+
+ Args:
+ org_id: Organization ID
+
+ Returns:
+ Detailed organization information
+ """
+ logger.debug(f"Getting organization details for {org_id}")
+
+ try:
+ response = self.get(self._build_url("organization", f"{org_id}/"))
+
+ org_name = response.get("name", "Unknown")
+ logger.debug(f"Retrieved organization details for {org_name} ({org_id})")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization details for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_settings(self, org_id: str) -> APIResponse:
+ """Get organization-specific settings and configuration.
+
+ Args:
+ org_id: Organization ID
+
+ Returns:
+ Organization settings and configuration
+ """
+ logger.debug(f"Getting organization settings for {org_id}")
+
+ try:
+ response = self.get(self._build_url("organization", f"{org_id}/settings/"))
+
+ logger.debug(f"Retrieved organization settings for {org_id}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization settings for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_permissions(
+ self, org_id: str, user_id: str | None = None
+ ) -> APIResponse:
+ """Get organization permissions for a user or current context.
+
+ Args:
+ org_id: Organization ID
+ user_id: Optional user ID (defaults to current user)
+
+ Returns:
+ Organization permissions data
+ """
+ params = {}
+ if user_id:
+ params["user_id"] = user_id
+
+ logger.debug(f"Getting organization permissions for {org_id}")
+
+ try:
+ response = self.get(
+ self._build_url("organization", f"{org_id}/permissions/"), params=params
+ )
+
+ logger.debug(f"Retrieved organization permissions for {org_id}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization permissions for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_members(
+ self, org_id: str, active_only: bool = True
+ ) -> APIResponse:
+ """Get organization members list.
+
+ Args:
+ org_id: Organization ID
+ active_only: Whether to return only active members
+
+ Returns:
+ Organization members data
+ """
+ params = {"active_only": active_only}
+
+ logger.debug(f"Getting organization members for {org_id}")
+
+ try:
+ response = self.get(
+ self._build_url("organization", f"{org_id}/members/"), params=params
+ )
+
+ member_count = len(response.get("members", []))
+ logger.debug(f"Retrieved {member_count} organization members for {org_id}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization members for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_usage(self, org_id: str, period: str = "month") -> APIResponse:
+ """Get organization usage statistics.
+
+ Args:
+ org_id: Organization ID
+ period: Usage period (day, week, month, year)
+
+ Returns:
+ Organization usage statistics
+ """
+ params = {"period": period}
+
+ logger.debug(f"Getting organization usage for {org_id} (period: {period})")
+
+ try:
+ response = self.get(
+ self._build_url("organization", f"{org_id}/usage/"), params=params
+ )
+
+ logger.debug(f"Retrieved organization usage for {org_id}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization usage for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_quota(self, org_id: str) -> APIResponse:
+ """Get organization resource quotas and limits.
+
+ Args:
+ org_id: Organization ID
+
+ Returns:
+ Organization quota information
+ """
+ logger.debug(f"Getting organization quota for {org_id}")
+
+ try:
+ response = self.get(self._build_url("organization", f"{org_id}/quota/"))
+
+ logger.debug(f"Retrieved organization quota for {org_id}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization quota for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def validate_organization_access(
+ self, org_id: str, resource_type: str, action: str
+ ) -> APIResponse:
+ """Validate organization access for a specific resource and action.
+
+ Args:
+ org_id: Organization ID
+ resource_type: Type of resource (workflow, file, etc.)
+ action: Action to validate (read, write, execute, etc.)
+
+ Returns:
+ Access validation result
+ """
+ data = {"resource_type": resource_type, "action": action}
+
+ logger.debug(
+ f"Validating organization access for {org_id}: {resource_type}.{action}"
+ )
+
+ try:
+ response = self.post(
+ self._build_url("organization", f"{org_id}/validate-access/"), data
+ )
+
+ is_allowed = response.get("allowed", False)
+ logger.debug(f"Organization access validation for {org_id}: {is_allowed}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to validate organization access for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ @circuit_breaker(failure_threshold=3, recovery_timeout=60.0)
+ def get_organization_health(self, org_id: str) -> APIResponse:
+ """Get organization health status and service availability.
+
+ Args:
+ org_id: Organization ID
+
+ Returns:
+ Organization health status
+ """
+ logger.debug(f"Getting organization health for {org_id}")
+
+ try:
+ response = self.get(self._build_url("organization", f"{org_id}/health/"))
+
+ status = response.get("status", "unknown")
+ logger.debug(f"Organization health for {org_id}: {status}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization health for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def switch_organization_context(self, org_id: str) -> APIResponse:
+ """Switch to a different organization context.
+
+ This method validates the organization access and switches the client context
+ to the specified organization for subsequent API calls.
+
+ Args:
+ org_id: Organization ID to switch to
+
+ Returns:
+ Organization context switch result
+ """
+ logger.info(f"Switching organization context to {org_id}")
+
+ try:
+ # Validate organization access first
+ context = self.get_organization_context(org_id)
+
+ # If successful, update the client's organization context
+ self.set_organization_context(org_id)
+
+ logger.info(f"Successfully switched organization context to {org_id}")
+ return APIResponse(
+ success=True,
+ data={"organization_id": org_id, "context": context.to_dict()},
+ status_code=200,
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to switch organization context to {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_workflows(
+ self, org_id: str, workflow_type: str | None = None
+ ) -> APIResponse:
+ """Get workflows for a specific organization.
+
+ Args:
+ org_id: Organization ID
+ workflow_type: Optional workflow type filter
+
+ Returns:
+ Organization workflows
+ """
+ params = {}
+ if workflow_type:
+ params["workflow_type"] = workflow_type
+
+ logger.debug(f"Getting organization workflows for {org_id}")
+
+ try:
+ response = self.get(
+ self._build_url("organization", f"{org_id}/workflows/"), params=params
+ )
+
+ workflow_count = len(response.get("workflows", []))
+ logger.debug(
+ f"Retrieved {workflow_count} workflows for organization {org_id}"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization workflows for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_organization_connectors(
+ self, org_id: str, connector_type: str | None = None
+ ) -> APIResponse:
+ """Get connectors for a specific organization.
+
+ Args:
+ org_id: Organization ID
+ connector_type: Optional connector type filter
+
+ Returns:
+ Organization connectors
+ """
+ params = {}
+ if connector_type:
+ params["connector_type"] = connector_type
+
+ logger.debug(f"Getting organization connectors for {org_id}")
+
+ try:
+ response = self.get(
+ self._build_url("organization", f"{org_id}/connectors/"), params=params
+ )
+
+ connector_count = len(response.get("connectors", []))
+ logger.debug(
+ f"Retrieved {connector_count} connectors for organization {org_id}"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get organization connectors for {org_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
diff --git a/workers/shared/clients/tool_client.py b/workers/shared/clients/tool_client.py
new file mode 100644
index 000000000..2907039cc
--- /dev/null
+++ b/workers/shared/clients/tool_client.py
@@ -0,0 +1,517 @@
+"""Tool API Client for Tool Execution Operations
+
+This module provides specialized API client for tool execution operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- Tool instance execution
+- Tool execution status tracking
+- Tool instance management
+- Tool workflow integration
+- Tool result handling
+"""
+
+import logging
+import uuid
+from typing import Any
+
+from ..data.models import (
+ APIResponse,
+ BatchOperationRequest,
+ BatchOperationResponse,
+)
+from ..enums import BatchOperationType, LogLevel, TaskStatus
+from ..utils.retry_temp import CircuitBreakerOpenError, circuit_breaker
+from .base_client import BaseAPIClient
+
+logger = logging.getLogger(__name__)
+
+
+class ToolAPIClient(BaseAPIClient):
+ """Specialized API client for tool execution operations.
+
+ This client handles all tool-related operations including:
+ - Executing tool instances
+ - Tracking tool execution status
+ - Managing tool instances
+ - Tool workflow integration
+ - Tool result processing
+ """
+
+ def execute_tool(
+ self,
+ tool_instance_id: str | uuid.UUID,
+ input_data: dict[str, Any],
+ file_data: dict[str, Any] | None = None,
+ execution_context: dict[str, Any] | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Execute a tool instance with provided data.
+
+ Args:
+ tool_instance_id: Tool instance ID to execute
+ input_data: Input data for the tool execution
+ file_data: Optional file data for processing
+ execution_context: Optional execution context
+ organization_id: Optional organization ID override
+
+ Returns:
+ Tool execution result
+ """
+ data = {
+ "input_data": input_data,
+ "file_data": file_data or {},
+ "execution_context": execution_context or {},
+ }
+
+ logger.info(f"Executing tool {tool_instance_id} with input data: {input_data}")
+ logger.debug(f"Tool execution context: {execution_context}")
+
+ try:
+ response = self.post(
+ self._build_url("tool_execution", f"{str(tool_instance_id)}/execute/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ execution_id = response.get("execution_id", "unknown")
+ logger.info(
+ f"Successfully started tool execution {execution_id} for tool {tool_instance_id}"
+ )
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to execute tool {tool_instance_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_tool_execution_status(
+ self, execution_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get tool execution status by execution ID.
+
+ Args:
+ execution_id: Tool execution ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ Tool execution status information
+ """
+ logger.debug(f"Getting tool execution status for {execution_id}")
+
+ try:
+ response = self.get(
+ self._build_url("tool_execution", f"status/{str(execution_id)}/"),
+ organization_id=organization_id,
+ )
+
+ status = response.get("status", "unknown")
+ logger.debug(f"Tool execution {execution_id} status: {status}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get tool execution status for {execution_id}: {str(e)}"
+ )
+ return APIResponse(success=False, error=str(e))
+
+ def get_tool_instances_by_workflow(
+ self, workflow_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get tool instances for a specific workflow.
+
+ Args:
+ workflow_id: Workflow ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ List of tool instances for the workflow
+ """
+ logger.debug(f"Getting tool instances for workflow {workflow_id}")
+
+ try:
+ response = self.get(
+ self._build_url(
+ "tool_execution", f"workflow/{str(workflow_id)}/instances/"
+ ),
+ organization_id=organization_id,
+ )
+
+ instance_count = len(response.get("instances", []))
+ logger.debug(
+ f"Retrieved {instance_count} tool instances for workflow {workflow_id}"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get tool instances for workflow {workflow_id}: {str(e)}"
+ )
+ return APIResponse(success=False, error=str(e))
+
+ def get_tool_instance_details(
+ self, tool_instance_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get detailed information about a tool instance.
+
+ Args:
+ tool_instance_id: Tool instance ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ Tool instance details
+ """
+ logger.debug(f"Getting tool instance details for {tool_instance_id}")
+
+ try:
+ response = self.get(
+ self._build_url("tool_execution", f"instance/{str(tool_instance_id)}/"),
+ organization_id=organization_id,
+ )
+
+ tool_name = response.get("tool_name", "unknown")
+ logger.debug(
+ f"Retrieved tool instance details for {tool_name} ({tool_instance_id})"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get tool instance details for {tool_instance_id}: {str(e)}"
+ )
+ return APIResponse(success=False, error=str(e))
+
+ def get_tool_execution_result(
+ self, execution_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> APIResponse:
+ """Get tool execution result by execution ID.
+
+ Args:
+ execution_id: Tool execution ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ Tool execution result data
+ """
+ logger.debug(f"Getting tool execution result for {execution_id}")
+
+ try:
+ response = self.get(
+ self._build_url("tool_execution", f"result/{str(execution_id)}/"),
+ organization_id=organization_id,
+ )
+
+ logger.debug(f"Retrieved tool execution result for {execution_id}")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get tool execution result for {execution_id}: {str(e)}"
+ )
+ return APIResponse(success=False, error=str(e))
+
+ def get_tool_execution_logs(
+ self,
+ execution_id: str | uuid.UUID,
+ level: str | LogLevel | None = None,
+ limit: int = 100,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get tool execution logs.
+
+ Args:
+ execution_id: Tool execution ID
+ level: Log level filter (DEBUG, INFO, WARNING, ERROR)
+ limit: Maximum number of log entries to return
+ organization_id: Optional organization ID override
+
+ Returns:
+ Tool execution logs
+ """
+ # Convert level to string if it's an enum
+ level_str = level.value if isinstance(level, LogLevel) else level
+
+ params = {"limit": limit}
+ if level_str:
+ params["level"] = level_str
+
+ logger.debug(f"Getting tool execution logs for {execution_id}")
+
+ try:
+ response = self.get(
+ self._build_url("tool_execution", f"logs/{str(execution_id)}/"),
+ params=params,
+ organization_id=organization_id,
+ )
+
+ log_count = len(response.get("logs", []))
+ logger.debug(
+ f"Retrieved {log_count} log entries for tool execution {execution_id}"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get tool execution logs for {execution_id}: {str(e)}"
+ )
+ return APIResponse(success=False, error=str(e))
+
+ @circuit_breaker(failure_threshold=3, recovery_timeout=60.0)
+ def cancel_tool_execution(
+ self,
+ execution_id: str | uuid.UUID,
+ reason: str | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Cancel a running tool execution.
+
+ Args:
+ execution_id: Tool execution ID to cancel
+ reason: Optional cancellation reason
+ organization_id: Optional organization ID override
+
+ Returns:
+ Cancellation response
+ """
+ data = {"execution_id": str(execution_id)}
+ if reason:
+ data["reason"] = reason
+
+ logger.info(f"Cancelling tool execution {execution_id}")
+
+ try:
+ response = self.post(
+ self._build_url("tool_execution", f"cancel/{str(execution_id)}/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Successfully cancelled tool execution {execution_id}")
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except CircuitBreakerOpenError:
+ logger.warning(
+ f"Tool execution cancellation circuit breaker open for {execution_id}"
+ )
+ return APIResponse(
+ success=False,
+ error="Circuit breaker open - tool cancellation service unavailable",
+ )
+ except Exception as e:
+ logger.error(f"Failed to cancel tool execution {execution_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def batch_execute_tools(
+ self, tool_executions: list[dict[str, Any]], organization_id: str | None = None
+ ) -> BatchOperationResponse:
+ """Execute multiple tools in a single batch request.
+
+ Args:
+ tool_executions: List of tool execution configurations
+ organization_id: Optional organization ID override
+
+ Returns:
+ BatchOperationResponse with execution results
+ """
+ batch_request = BatchOperationRequest(
+ operation_type=BatchOperationType.CREATE,
+ items=tool_executions,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Batch executing {len(tool_executions)} tools")
+
+ try:
+ response = self.post(
+ self._build_url("tool_execution", "batch-execute/"),
+ batch_request.to_dict(),
+ organization_id=organization_id,
+ )
+
+ successful = response.get("successful", 0)
+ failed = response.get("failed", 0)
+ logger.info(
+ f"Batch tool execution completed: {successful} successful, {failed} failed"
+ )
+
+ return BatchOperationResponse(
+ operation_id=response.get("operation_id", str(uuid.uuid4())),
+ total_items=len(tool_executions),
+ successful_items=successful,
+ failed_items=failed,
+ status=TaskStatus(response.get("status", TaskStatus.SUCCESS.value)),
+ results=response.get("results", []),
+ errors=response.get("errors", []),
+ execution_time=response.get("execution_time"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to batch execute tools: {str(e)}")
+ return BatchOperationResponse(
+ operation_id=str(uuid.uuid4()),
+ total_items=len(tool_executions),
+ successful_items=0,
+ failed_items=len(tool_executions),
+ status=TaskStatus.FAILURE,
+ results=[],
+ errors=[{"error": str(e)}],
+ )
+
+ def get_tool_execution_history(
+ self,
+ tool_instance_id: str | uuid.UUID | None = None,
+ workflow_id: str | uuid.UUID | None = None,
+ status: str | TaskStatus | None = None,
+ limit: int = 100,
+ offset: int = 0,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get tool execution history with filtering options.
+
+ Args:
+ tool_instance_id: Filter by tool instance ID
+ workflow_id: Filter by workflow ID
+ status: Filter by execution status
+ limit: Maximum number of records to return
+ offset: Number of records to skip
+ organization_id: Optional organization ID override
+
+ Returns:
+ Paginated tool execution history
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ params = {"limit": limit, "offset": offset}
+
+ if tool_instance_id:
+ params["tool_instance_id"] = str(tool_instance_id)
+ if workflow_id:
+ params["workflow_id"] = str(workflow_id)
+ if status_str:
+ params["status"] = status_str
+
+ logger.debug(f"Getting tool execution history with filters: {params}")
+
+ try:
+ response = self.get(
+ self._build_url("tool_execution", "history/"),
+ params=params,
+ organization_id=organization_id,
+ )
+
+ count = response.get("count", 0)
+ logger.debug(f"Retrieved {count} tool execution history records")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get tool execution history: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_tool_execution_metrics(
+ self,
+ start_date: str | None = None,
+ end_date: str | None = None,
+ tool_instance_id: str | uuid.UUID | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get tool execution metrics and statistics.
+
+ Args:
+ start_date: Start date for metrics (ISO format)
+ end_date: End date for metrics (ISO format)
+ tool_instance_id: Optional tool instance ID filter
+ organization_id: Optional organization ID override
+
+ Returns:
+ Tool execution metrics
+ """
+ params = {}
+
+ if start_date:
+ params["start_date"] = start_date
+ if end_date:
+ params["end_date"] = end_date
+ if tool_instance_id:
+ params["tool_instance_id"] = str(tool_instance_id)
+
+ logger.debug(
+ f"Getting tool execution metrics for date range: {start_date} to {end_date}"
+ )
+
+ try:
+ response = self.get(
+ self._build_url("tool_execution", "metrics/"),
+ params=params,
+ organization_id=organization_id,
+ )
+
+ total_executions = response.get("total_executions", 0)
+ success_rate = response.get("success_rate", 0.0)
+ logger.debug(
+ f"Tool execution metrics: {total_executions} executions, {success_rate:.1%} success rate"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get tool execution metrics: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def update_tool_execution_status(
+ self,
+ execution_id: str | uuid.UUID,
+ status: str | TaskStatus,
+ result: dict[str, Any] | None = None,
+ error_message: str | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Update tool execution status and result.
+
+ Args:
+ execution_id: Tool execution ID
+ status: New execution status
+ result: Optional execution result data
+ error_message: Optional error message
+ organization_id: Optional organization ID override
+
+ Returns:
+ Update response
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ data = {"status": status_str}
+
+ if result is not None:
+ data["result"] = result
+ if error_message is not None:
+ data["error_message"] = error_message
+
+ logger.info(f"Updating tool execution {execution_id} status to {status_str}")
+
+ try:
+ response = self.post(
+ self._build_url("tool_execution", f"status/{str(execution_id)}/update/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Successfully updated tool execution {execution_id} status")
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to update tool execution status for {execution_id}: {str(e)}"
+ )
+ return APIResponse(success=False, error=str(e))
diff --git a/workers/shared/clients/usage_client.py b/workers/shared/clients/usage_client.py
new file mode 100644
index 000000000..39c30fcc9
--- /dev/null
+++ b/workers/shared/clients/usage_client.py
@@ -0,0 +1,172 @@
+"""Usage API Client for Usage Operations
+
+This module provides specialized API client for usage-related operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- Token usage aggregation
+- Usage statistics retrieval
+- Usage metadata management
+"""
+
+import logging
+import uuid
+from dataclasses import dataclass
+from typing import Generic, TypeVar
+from uuid import UUID
+
+from shared.data.response_models import APIResponse, ResponseStatus
+
+from unstract.core.data_models import UsageResponseData
+
+from .base_client import BaseAPIClient
+
+logger = logging.getLogger(__name__)
+
+
+T = TypeVar("T")
+
+
+@dataclass
+class BaseUsageResponse(APIResponse, Generic[T]):
+ """Base response class for all usage operations with generic data typing."""
+
+ file_execution_id: str | UUID | None = None
+ status: str = ResponseStatus.SUCCESS
+ data: T | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ data: T | None = None,
+ file_execution_id: str | UUID | None = None,
+ status: str = ResponseStatus.SUCCESS,
+ message: str | None = None,
+ ) -> "BaseUsageResponse[T]":
+ """Create a successful response."""
+ return cls(
+ success=True,
+ file_execution_id=file_execution_id,
+ status=status,
+ data=data,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ file_execution_id: str | UUID | None = None,
+ status: str = ResponseStatus.ERROR,
+ message: str | None = None,
+ ) -> "BaseUsageResponse[T]":
+ """Create an error response."""
+ return cls(
+ success=False,
+ file_execution_id=file_execution_id,
+ status=status,
+ error=error,
+ message=message,
+ )
+
+ def is_success(self) -> bool:
+ """Check if the response indicates success."""
+ return self.success_response and self.status == ResponseStatus.SUCCESS
+
+
+@dataclass
+class UsageResponse(BaseUsageResponse[UsageResponseData]):
+ """Response for usage operations."""
+
+ pass
+
+
+class UsageOperationMixin:
+ """Mixin providing common usage operation utilities."""
+
+ def _validate_file_execution_id(self, file_execution_id: str | UUID) -> str:
+ """Validate and convert file execution ID to string."""
+ if isinstance(file_execution_id, UUID):
+ return str(file_execution_id)
+ if not file_execution_id or not isinstance(file_execution_id, str):
+ raise ValueError("file_execution_id must be a non-empty string or UUID")
+ try:
+ # Validate it's a proper UUID format
+ UUID(file_execution_id)
+ return file_execution_id
+ except ValueError:
+ raise ValueError(f"Invalid file_execution_id format: {file_execution_id}")
+
+
+class UsageAPIClient(BaseAPIClient, UsageOperationMixin):
+ """Specialized API client for usage-related operations.
+
+ This client handles all usage-related operations including:
+ - Token usage aggregation
+ - Usage statistics retrieval
+ - Usage metadata management
+ """
+
+ def get_aggregated_token_count(
+ self, file_execution_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> UsageResponse:
+ """Get aggregated token usage data for a file execution.
+
+ Args:
+ file_execution_id: File execution ID to get usage data for
+ organization_id: Optional organization ID override
+
+ Returns:
+ UsageResponse containing aggregated usage data
+ """
+ try:
+ validated_file_execution_id = self._validate_file_execution_id(
+ file_execution_id
+ )
+ # Use the usage internal API to get aggregated token count
+ endpoint = f"v1/usage/aggregated-token-count/{validated_file_execution_id}/"
+ response = self.get(endpoint, organization_id=organization_id)
+
+ logger.info(
+ f"Retrieved usage data for {validated_file_execution_id}: {response.get('success', False)}"
+ )
+
+ if response and response.get("success"):
+ # Extract usage data from the response
+ usage_dict = response.get("data", {}).get("usage", {})
+ usage_data = UsageResponseData(
+ file_execution_id=validated_file_execution_id,
+ embedding_tokens=usage_dict.get("embedding_tokens"),
+ prompt_tokens=usage_dict.get("prompt_tokens"),
+ completion_tokens=usage_dict.get("completion_tokens"),
+ total_tokens=usage_dict.get("total_tokens"),
+ cost_in_dollars=usage_dict.get("cost_in_dollars"),
+ )
+ return UsageResponse.success_response(
+ data=usage_data,
+ file_execution_id=validated_file_execution_id,
+ message="Successfully retrieved usage data",
+ )
+ else:
+ logger.warning(
+ f"No usage data found for file_execution_id {validated_file_execution_id}"
+ )
+ # Return empty usage data instead of error for backward compatibility
+ usage_data = UsageResponseData(
+ file_execution_id=validated_file_execution_id
+ )
+ return UsageResponse.success_response(
+ data=usage_data,
+ file_execution_id=validated_file_execution_id,
+ message="No usage data found, returning empty data",
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get usage data for {validated_file_execution_id}: {str(e)}"
+ )
+ return UsageResponse.error_response(
+ error=str(e),
+ file_execution_id=validated_file_execution_id,
+ message="Failed to retrieve usage data",
+ )
diff --git a/workers/shared/clients/webhook_client.py b/workers/shared/clients/webhook_client.py
new file mode 100644
index 000000000..f6008c858
--- /dev/null
+++ b/workers/shared/clients/webhook_client.py
@@ -0,0 +1,457 @@
+"""Webhook API Client for Webhook Operations
+
+This module provides specialized API client for webhook operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- Webhook sending and delivery
+- Webhook status tracking
+- Webhook testing
+- Webhook batch operations
+- Webhook configuration management
+"""
+
+import logging
+
+# Import shared AuthorizationType from core
+import os
+import sys
+from typing import Any
+
+from ..data.models import (
+ APIResponse,
+ BatchOperationRequest,
+ BatchOperationResponse,
+)
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core.notification_enums import AuthorizationType
+
+from ..enums import (
+ BatchOperationType,
+ TaskStatus,
+)
+from ..utils.retry_temp import CircuitBreakerOpenError, circuit_breaker
+from .base_client import BaseAPIClient
+
+logger = logging.getLogger(__name__)
+
+
+class WebhookAPIClient(BaseAPIClient):
+ """Specialized API client for webhook operations.
+
+ This client handles all webhook-related operations including:
+ - Sending webhook notifications
+ - Checking webhook delivery status
+ - Testing webhook configurations
+ - Batch webhook operations
+ - Webhook retry handling
+ """
+
+ def send_webhook(
+ self,
+ url: str,
+ payload: dict[str, Any],
+ notification_id: str | None = None,
+ authorization_type: str | AuthorizationType = AuthorizationType.NONE,
+ authorization_key: str | None = None,
+ authorization_header: str | None = None,
+ timeout: int = 30,
+ max_retries: int = 3,
+ retry_delay: int = 5,
+ headers: dict[str, str] | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Send webhook notification to external endpoint.
+
+ Args:
+ url: Webhook endpoint URL
+ payload: Webhook payload data
+ notification_id: Optional notification ID for tracking
+ authorization_type: Type of authorization (none, bearer, basic, custom)
+ authorization_key: Authorization key/token
+ authorization_header: Custom authorization header
+ timeout: Request timeout in seconds
+ max_retries: Maximum retry attempts
+ retry_delay: Delay between retries in seconds
+ headers: Additional HTTP headers
+ organization_id: Optional organization ID override
+
+ Returns:
+ Webhook delivery response
+ """
+ # Convert authorization_type to string if it's an enum
+ auth_type_str = (
+ authorization_type.value
+ if isinstance(authorization_type, AuthorizationType)
+ else authorization_type
+ )
+
+ data = {
+ "url": url,
+ "payload": payload,
+ "authorization_type": auth_type_str,
+ "timeout": timeout,
+ "max_retries": max_retries,
+ "retry_delay": retry_delay,
+ }
+
+ # Add optional parameters
+ if notification_id:
+ data["notification_id"] = notification_id
+ if authorization_key:
+ data["authorization_key"] = authorization_key
+ if authorization_header:
+ data["authorization_header"] = authorization_header
+ if headers:
+ data["headers"] = headers
+
+ logger.info(
+ f"Sending webhook to {url} with payload size {len(str(payload))} characters"
+ )
+ logger.debug(f"Webhook authorization_type: {auth_type_str}")
+
+ try:
+ response = self.post(
+ self._build_url("webhook", "send/"), data, organization_id=organization_id
+ )
+
+ logger.info(f"Successfully sent webhook to {url}")
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to send webhook to {url}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_webhook_status(
+ self, task_id: str, organization_id: str | None = None
+ ) -> dict[str, Any]:
+ """Get webhook delivery status by task ID.
+
+ Args:
+ task_id: Webhook task ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ Webhook status information
+ """
+ logger.debug(f"Getting webhook status for task {task_id}")
+
+ try:
+ response = self.get(
+ self._build_url("webhook", f"status/{task_id}/"),
+ organization_id=organization_id,
+ )
+
+ status = response.get("status", "unknown")
+ logger.debug(f"Webhook task {task_id} status: {status}")
+ return response
+
+ except Exception as e:
+ logger.error(f"Failed to get webhook status for task {task_id}: {str(e)}")
+ raise
+
+ def test_webhook(
+ self,
+ url: str,
+ payload: dict[str, Any],
+ authorization_type: str | AuthorizationType = AuthorizationType.NONE,
+ authorization_key: str | None = None,
+ authorization_header: str | None = None,
+ timeout: int = 10,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Test webhook configuration and connectivity.
+
+ Args:
+ url: Webhook endpoint URL to test
+ payload: Test payload data
+ authorization_type: Type of authorization (none, bearer, basic, custom)
+ authorization_key: Authorization key/token
+ authorization_header: Custom authorization header
+ timeout: Request timeout in seconds
+ organization_id: Optional organization ID override
+
+ Returns:
+ Test result with success status and response details
+ """
+ # Convert authorization_type to string if it's an enum
+ auth_type_str = (
+ authorization_type.value
+ if isinstance(authorization_type, AuthorizationType)
+ else authorization_type
+ )
+
+ data = {
+ "url": url,
+ "payload": payload,
+ "authorization_type": auth_type_str,
+ "timeout": timeout,
+ }
+
+ # Add optional authorization
+ if authorization_key:
+ data["authorization_key"] = authorization_key
+ if authorization_header:
+ data["authorization_header"] = authorization_header
+
+ logger.info(f"Testing webhook configuration for {url}")
+ logger.debug(f"Test webhook authorization_type: {auth_type_str}")
+
+ try:
+ response = self.post(
+ self._build_url("webhook", "test/"), data, organization_id=organization_id
+ )
+
+ success = response.get("success", False)
+ logger.info(f"Webhook test for {url} {'succeeded' if success else 'failed'}")
+ return APIResponse(
+ success=success, data=response, status_code=response.get("status_code")
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to test webhook {url}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def batch_send_webhooks(
+ self, webhooks: list[dict[str, Any]], organization_id: str | None = None
+ ) -> BatchOperationResponse:
+ """Send multiple webhooks in a single batch request.
+
+ Args:
+ webhooks: List of webhook configurations
+ organization_id: Optional organization ID override
+
+ Returns:
+ BatchOperationResponse with individual results
+ """
+ import uuid
+
+ batch_request = BatchOperationRequest(
+ operation_type=BatchOperationType.CREATE,
+ items=webhooks,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Sending batch of {len(webhooks)} webhooks")
+
+ try:
+ response = self.post(
+ self._build_url("webhook", "batch-send/"),
+ batch_request.to_dict(),
+ organization_id=organization_id,
+ )
+
+ successful = response.get("successful", 0)
+ failed = response.get("failed", 0)
+ logger.info(
+ f"Batch webhook send completed: {successful} successful, {failed} failed"
+ )
+
+ return BatchOperationResponse(
+ operation_id=response.get("operation_id", str(uuid.uuid4())),
+ total_items=len(webhooks),
+ successful_items=successful,
+ failed_items=failed,
+ status=TaskStatus(response.get("status", TaskStatus.SUCCESS.value)),
+ results=response.get("results", []),
+ errors=response.get("errors", []),
+ execution_time=response.get("execution_time"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to send batch webhooks: {str(e)}")
+ return BatchOperationResponse(
+ operation_id=str(uuid.uuid4()),
+ total_items=len(webhooks),
+ successful_items=0,
+ failed_items=len(webhooks),
+ status=TaskStatus.FAILURE,
+ results=[],
+ errors=[{"error": str(e)}],
+ )
+
+ def get_webhook_delivery_history(
+ self,
+ notification_id: str | None = None,
+ url: str | None = None,
+ status: str | TaskStatus | None = None,
+ limit: int = 100,
+ offset: int = 0,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get webhook delivery history with filtering options.
+
+ Args:
+ notification_id: Filter by notification ID
+ url: Filter by webhook URL
+ status: Filter by delivery status
+ limit: Maximum number of records to return
+ offset: Number of records to skip
+ organization_id: Optional organization ID override
+
+ Returns:
+ Paginated webhook delivery history
+ """
+ # Convert status to string if it's an enum
+ status_str = status.value if isinstance(status, TaskStatus) else status
+
+ params = {"limit": limit, "offset": offset}
+
+ if notification_id:
+ params["notification_id"] = notification_id
+ if url:
+ params["url"] = url
+ if status_str:
+ params["status"] = status_str
+
+ logger.debug(f"Getting webhook delivery history with filters: {params}")
+
+ try:
+ response = self.get(
+ self._build_url("webhook", "history/"),
+ params=params,
+ organization_id=organization_id,
+ )
+
+ count = response.get("count", 0)
+ logger.debug(f"Retrieved {count} webhook delivery records")
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get webhook delivery history: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ @circuit_breaker(failure_threshold=3, recovery_timeout=60.0)
+ def retry_failed_webhook(
+ self,
+ task_id: str,
+ max_retries: int = 3,
+ retry_delay: int = 5,
+ organization_id: str | None = None,
+ ) -> dict[str, Any]:
+ """Retry a failed webhook delivery.
+
+ Args:
+ task_id: Failed webhook task ID
+ max_retries: Maximum retry attempts
+ retry_delay: Delay between retries in seconds
+ organization_id: Optional organization ID override
+
+ Returns:
+ Retry response
+ """
+ data = {
+ "task_id": task_id,
+ "max_retries": max_retries,
+ "retry_delay": retry_delay,
+ }
+
+ logger.info(f"Retrying failed webhook task {task_id}")
+
+ try:
+ response = self.post(
+ self._build_url("webhook", "retry/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Successfully initiated retry for webhook task {task_id}")
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except CircuitBreakerOpenError:
+ logger.warning(f"Webhook retry circuit breaker open for task {task_id}")
+ return APIResponse(
+ success=False,
+ error="Circuit breaker open - webhook retry service unavailable",
+ )
+ except Exception as e:
+ logger.error(f"Failed to retry webhook task {task_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def cancel_webhook(
+ self, task_id: str, organization_id: str | None = None
+ ) -> APIResponse:
+ """Cancel a pending webhook delivery.
+
+ Args:
+ task_id: Webhook task ID to cancel
+ organization_id: Optional organization ID override
+
+ Returns:
+ Cancellation response
+ """
+ data = {"task_id": task_id}
+
+ logger.info(f"Cancelling webhook task {task_id}")
+
+ try:
+ response = self.post(
+ self._build_url("webhook", "cancel/"),
+ data,
+ organization_id=organization_id,
+ )
+
+ logger.info(f"Successfully cancelled webhook task {task_id}")
+ return APIResponse(
+ success=response.get("success", True),
+ data=response,
+ status_code=response.get("status_code"),
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to cancel webhook task {task_id}: {str(e)}")
+ return APIResponse(success=False, error=str(e))
+
+ def get_webhook_metrics(
+ self,
+ start_date: str | None = None,
+ end_date: str | None = None,
+ organization_id: str | None = None,
+ ) -> APIResponse:
+ """Get webhook delivery metrics and statistics.
+
+ Args:
+ start_date: Start date for metrics (ISO format)
+ end_date: End date for metrics (ISO format)
+ organization_id: Optional organization ID override
+
+ Returns:
+ Webhook metrics including success rates, response times, etc.
+ """
+ params = {}
+
+ if start_date:
+ params["start_date"] = start_date
+ if end_date:
+ params["end_date"] = end_date
+
+ logger.debug(
+ f"Getting webhook metrics for date range: {start_date} to {end_date}"
+ )
+
+ try:
+ response = self.get(
+ self._build_url("webhook", "metrics/"),
+ params=params,
+ organization_id=organization_id,
+ )
+
+ total_sent = response.get("total_sent", 0)
+ success_rate = response.get("success_rate", 0.0)
+ logger.debug(
+ f"Webhook metrics: {total_sent} sent, {success_rate:.1%} success rate"
+ )
+ return APIResponse(success=True, data=response, status_code=200)
+
+ except Exception as e:
+ logger.error(f"Failed to get webhook metrics: {str(e)}")
+ return APIResponse(success=False, error=str(e))
diff --git a/workers/shared/clients/workflow_client.py b/workers/shared/clients/workflow_client.py
new file mode 100644
index 000000000..42c1ab549
--- /dev/null
+++ b/workers/shared/clients/workflow_client.py
@@ -0,0 +1,196 @@
+"""Workflow API Client for Workflow Operations
+
+This module provides specialized API client for workflow-related operations,
+extracted from the monolithic InternalAPIClient to improve maintainability.
+
+Handles:
+- Workflow definition retrieval
+- Workflow execution management
+- Workflow history operations
+- Workflow batch operations
+- Workflow status updates
+- Workflow metadata management
+"""
+
+import logging
+import uuid
+from dataclasses import dataclass
+from typing import Generic, TypeVar
+from uuid import UUID
+
+from shared.data.response_models import APIResponse, ResponseStatus
+
+from unstract.core.data_models import (
+ WorkflowDefinitionResponseData,
+ WorkflowEndpointConfigResponseData,
+)
+
+from .base_client import BaseAPIClient
+
+logger = logging.getLogger(__name__)
+
+
+T = TypeVar("T")
+
+
+@dataclass
+class BaseWorkflowResponse(APIResponse, Generic[T]):
+ """Base response class for all workflow operations with generic data typing."""
+
+ workflow_id: str | UUID | None = None
+ status: str = ResponseStatus.SUCCESS
+ data: T | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ data: T | None = None,
+ workflow_id: str | UUID | None = None,
+ status: str = ResponseStatus.SUCCESS,
+ message: str | None = None,
+ ) -> "BaseWorkflowResponse[T]":
+ """Create a successful response."""
+ return cls(
+ success=True,
+ workflow_id=workflow_id,
+ status=status,
+ data=data,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ workflow_id: str | UUID | None = None,
+ status: str = ResponseStatus.ERROR,
+ message: str | None = None,
+ ) -> "BaseWorkflowResponse[T]":
+ """Create an error response."""
+ return cls(
+ success=False,
+ workflow_id=workflow_id,
+ status=status,
+ error=error,
+ message=message,
+ )
+
+ def is_success(self) -> bool:
+ """Check if the response indicates success."""
+ return self.success_response and self.status == ResponseStatus.SUCCESS
+
+
+@dataclass
+class WorkflowDefinitionResponse(BaseWorkflowResponse[WorkflowDefinitionResponseData]):
+ """Response for workflow definition operations."""
+
+ pass
+
+
+@dataclass
+class WorkflowEndpointConfigResponse(
+ BaseWorkflowResponse[WorkflowEndpointConfigResponseData]
+):
+ """Response for workflow endpoint configuration operations."""
+
+ pass
+
+
+class WorkflowOperationMixin:
+ """Mixin providing common workflow operation utilities."""
+
+ def _validate_workflow_id(self, workflow_id: str | UUID) -> str:
+ """Validate and convert workflow ID to string."""
+ if isinstance(workflow_id, UUID):
+ return str(workflow_id)
+ if not workflow_id or not isinstance(workflow_id, str):
+ raise ValueError("workflow_id must be a non-empty string or UUID")
+ try:
+ # Validate it's a proper UUID format
+ UUID(workflow_id)
+ return workflow_id
+ except ValueError:
+ raise ValueError(f"Invalid workflow_id format: {workflow_id}")
+
+
+class WorkflowAPIClient(BaseAPIClient, WorkflowOperationMixin):
+ """Specialized API client for workflow-related operations.
+
+ This client handles all workflow-related operations including:
+ - Workflow definition retrieval
+ - Workflow execution management
+ - Workflow history operations
+ - Workflow batch operations
+ - Workflow status updates
+ - Workflow metadata management
+ """
+
+ def get_workflow_definition(
+ self, workflow_id: str | uuid.UUID, organization_id: str | None = None
+ ) -> WorkflowDefinitionResponse:
+ """Get workflow definition including workflow_type.
+
+ Args:
+ workflow_id: Workflow ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ WorkflowDefinitionResponse containing workflow definition data
+ """
+ try:
+ validated_workflow_id = self._validate_workflow_id(workflow_id)
+ # Use the workflow management internal API to get workflow details
+ endpoint = f"v1/workflow-manager/workflow/{validated_workflow_id}/"
+ response = self.get(endpoint, organization_id=organization_id)
+ logger.info(
+ f"Retrieved workflow definition for {validated_workflow_id}: {response.get('workflow_type', 'unknown')}"
+ )
+ return WorkflowDefinitionResponse.success_response(
+ data=WorkflowDefinitionResponseData.from_dict(response),
+ workflow_id=validated_workflow_id,
+ message="Successfully retrieved workflow definition",
+ )
+ except Exception as e:
+ logger.error(
+ f"Failed to get workflow definition for {validated_workflow_id}: {str(e)}"
+ )
+ return WorkflowDefinitionResponse.error_response(
+ error=str(e),
+ workflow_id=validated_workflow_id,
+ message="Failed to retrieve workflow definition",
+ )
+
+ def get_workflow_endpoints(
+ self, workflow_id: str | UUID, organization_id: str | None = None
+ ) -> WorkflowEndpointConfigResponse:
+ """Get endpoint definition including endpoint_type.
+
+ Args:
+ workflow_id: Workflow ID
+ organization_id: Optional organization ID override
+
+ Returns:
+ WorkflowEndpointConfigResponse containing workflow endpoint config data
+ """
+ try:
+ validated_workflow_id = self._validate_workflow_id(workflow_id)
+ # Use the workflow management internal API to get workflow details
+ endpoint = f"v1/workflow-manager/{validated_workflow_id}/endpoint/"
+ response = self.get(endpoint, organization_id=organization_id)
+ logger.info(
+ f"Retrieved workflow endpoints for {validated_workflow_id}: {response.get('workflow_type', 'unknown')}"
+ )
+ return WorkflowEndpointConfigResponse.success_response(
+ workflow_id=validated_workflow_id,
+ data=WorkflowEndpointConfigResponseData.from_dict(response),
+ message="Successfully retrieved workflow endpoints",
+ )
+ except Exception as e:
+ logger.error(
+ f"Failed to get workflow endpoints for {validated_workflow_id}: {str(e)}"
+ )
+ return WorkflowEndpointConfigResponse.error_response(
+ error=str(e),
+ workflow_id=validated_workflow_id,
+ message="Failed to retrieve workflow endpoints",
+ )
diff --git a/workers/shared/constants.py b/workers/shared/constants.py
new file mode 100644
index 000000000..d8ec11111
--- /dev/null
+++ b/workers/shared/constants.py
@@ -0,0 +1,20 @@
+"""Worker-specific constants without Django dependencies.
+This provides the essential constants needed by workers.
+Re-exports shared constants from unstract.core for consistency.
+"""
+
+# Re-export shared constants from core
+
+
+class Account:
+ CREATED_BY = "created_by"
+ MODIFIED_BY = "modified_by"
+ ORGANIZATION_ID = "organization_id"
+
+
+class Common:
+ METADATA = "metadata"
+
+
+# ExecutionStatus is now imported from shared data models above
+# This ensures consistency between backend and workers
diff --git a/workers/shared/constants/__init__.py b/workers/shared/constants/__init__.py
new file mode 100644
index 000000000..ef83406dd
--- /dev/null
+++ b/workers/shared/constants/__init__.py
@@ -0,0 +1,25 @@
+"""Worker Constants
+
+Configuration values and constants specific to workers.
+"""
+
+from .account import Account, Common
+from .api_endpoints import APIEndpoints
+from .cache import CacheConfig
+from .env_vars import EnvVars
+from .errors import ErrorMessages
+from .logging import LogMessages
+from .monitoring import MonitoringConfig
+from .security import SecurityConfig
+
+__all__ = [
+ "APIEndpoints",
+ "ErrorMessages",
+ "LogMessages",
+ "CacheConfig",
+ "SecurityConfig",
+ "MonitoringConfig",
+ "EnvVars",
+ "Account",
+ "Common",
+]
diff --git a/workers/shared/constants/account.py b/workers/shared/constants/account.py
new file mode 100644
index 000000000..c93d90317
--- /dev/null
+++ b/workers/shared/constants/account.py
@@ -0,0 +1,18 @@
+"""Account Constants
+
+Account-related constants for workers.
+"""
+
+
+class Account:
+ """Account-related field names."""
+
+ CREATED_BY = "created_by"
+ MODIFIED_BY = "modified_by"
+ ORGANIZATION_ID = "organization_id"
+
+
+class Common:
+ """Common field names."""
+
+ METADATA = "metadata"
diff --git a/workers/shared/constants/api_endpoints.py b/workers/shared/constants/api_endpoints.py
new file mode 100644
index 000000000..0737c202c
--- /dev/null
+++ b/workers/shared/constants/api_endpoints.py
@@ -0,0 +1,65 @@
+"""API Endpoint Constants
+
+Internal API endpoint paths used by workers.
+Configurable via environment variables for flexibility.
+"""
+
+# Avoid patterns import to prevent circular dependencies
+# from ..patterns.worker_patterns import build_internal_endpoint
+
+
+# Simple implementation to avoid circular imports
+def build_internal_endpoint(endpoint: str) -> str:
+ """Build internal API endpoint URL - simplified to avoid circular imports."""
+ import os
+
+ base_url = os.getenv("INTERNAL_API_BASE_URL")
+ if not base_url:
+ raise ValueError("INTERNAL_API_BASE_URL environment variable not set")
+ return f"{base_url.rstrip('/')}/{endpoint.lstrip('/')}"
+
+
+class APIEndpoints:
+ """Internal API endpoint paths."""
+
+ # Workflow execution endpoints
+ WORKFLOW_EXECUTION_STATUS = build_internal_endpoint(
+ "workflow-execution/{execution_id}/status/"
+ )
+ WORKFLOW_EXECUTION_DATA = build_internal_endpoint(
+ "workflow-execution/{execution_id}/"
+ )
+ WORKFLOW_FILE_EXECUTION_CREATE = build_internal_endpoint(
+ "workflow-file-execution/create/"
+ )
+ WORKFLOW_FILE_EXECUTION_STATUS = build_internal_endpoint(
+ "workflow-file-execution/{file_execution_id}/status/"
+ )
+
+ # Pipeline endpoints
+ PIPELINE_STATUS = build_internal_endpoint("pipeline/{pipeline_id}/status/")
+ PIPELINE_LAST_RUN = build_internal_endpoint("pipeline/{pipeline_id}/last-run/")
+
+ # File history endpoints
+ FILE_HISTORY_CREATE = build_internal_endpoint("file-history/create/")
+ FILE_HISTORY_CHECK_BATCH = build_internal_endpoint("file-history/check-batch/")
+ FILE_HISTORY_BY_WORKFLOW = build_internal_endpoint(
+ "file-history/workflow/{workflow_id}/"
+ )
+
+ # Workflow definition endpoints
+ WORKFLOW_DEFINITION = build_internal_endpoint("workflow/{workflow_id}/")
+ WORKFLOW_SOURCE_CONFIG = build_internal_endpoint(
+ "workflow/{workflow_id}/source-config/"
+ )
+ WORKFLOW_DESTINATION_CONFIG = build_internal_endpoint(
+ "workflow/{workflow_id}/destination-config/"
+ )
+
+ # Notification endpoints
+ WEBHOOK_SEND = build_internal_endpoint("webhook/send/")
+ NOTIFICATION_SEND = build_internal_endpoint("notification/send/")
+
+ # Health and monitoring endpoints
+ WORKER_HEALTH = build_internal_endpoint("worker/health/")
+ WORKER_METRICS = build_internal_endpoint("worker/metrics/")
diff --git a/workers/shared/constants/cache.py b/workers/shared/constants/cache.py
new file mode 100644
index 000000000..817637b7b
--- /dev/null
+++ b/workers/shared/constants/cache.py
@@ -0,0 +1,33 @@
+"""Cache Configuration Constants
+
+Redis cache configuration and patterns.
+"""
+
+
+class CacheConfig:
+ """Redis cache configuration and patterns."""
+
+ # Cache key patterns
+ EXECUTION_STATUS_PATTERN = "exec_status:{org_id}:{execution_id}"
+ PIPELINE_STATUS_PATTERN = "pipeline_status:{org_id}:{pipeline_id}"
+ BATCH_SUMMARY_PATTERN = "batch_summary:{org_id}:{execution_id}"
+ CALLBACK_ATTEMPTS_PATTERN = "callback_attempts:{org_id}:{execution_id}"
+ BACKOFF_ATTEMPTS_PATTERN = "backoff_attempts:{org_id}:{execution_id}:{operation}"
+ CIRCUIT_BREAKER_PATTERN = "circuit_breaker:{service}:{operation}"
+
+ # TTL values (in seconds)
+ EXECUTION_STATUS_TTL = 60
+ PIPELINE_STATUS_TTL = 120
+ BATCH_SUMMARY_TTL = 90
+ CALLBACK_ATTEMPTS_TTL = 3600 # 1 hour
+ BACKOFF_ATTEMPTS_TTL = 1800 # 30 minutes
+ CIRCUIT_BREAKER_TTL = 300 # 5 minutes
+
+ # Cache validation settings
+ MAX_CACHE_AGE = 300 # 5 minutes absolute max
+ STALE_DATA_THRESHOLD = 120 # 2 minutes
+
+ # Connection settings
+ REDIS_SOCKET_TIMEOUT = 5
+ REDIS_SOCKET_CONNECT_TIMEOUT = 5
+ REDIS_HEALTH_CHECK_INTERVAL = 30
diff --git a/workers/shared/constants/env_vars.py b/workers/shared/constants/env_vars.py
new file mode 100644
index 000000000..675145f12
--- /dev/null
+++ b/workers/shared/constants/env_vars.py
@@ -0,0 +1,55 @@
+"""Environment Variable Names
+
+Environment variable names for worker configuration.
+"""
+
+
+class EnvVars:
+ """Environment variable names for configuration."""
+
+ # Worker identification
+ WORKER_NAME = "WORKER_NAME"
+ WORKER_VERSION = "WORKER_VERSION"
+ WORKER_INSTANCE_ID = "HOSTNAME"
+
+ # Celery configuration
+ CELERY_BROKER_BASE_URL = "CELERY_BROKER_BASE_URL"
+ CELERY_BROKER_USER = "CELERY_BROKER_USER"
+ CELERY_BROKER_PASS = "CELERY_BROKER_PASS"
+
+ # Celery backend database
+ CELERY_BACKEND_DB_HOST = "CELERY_BACKEND_DB_HOST"
+ CELERY_BACKEND_DB_PORT = "CELERY_BACKEND_DB_PORT"
+ CELERY_BACKEND_DB_NAME = "CELERY_BACKEND_DB_NAME"
+ CELERY_BACKEND_DB_USER = "CELERY_BACKEND_DB_USER"
+ CELERY_BACKEND_DB_PASSWORD = "CELERY_BACKEND_DB_PASSWORD"
+ CELERY_BACKEND_DB_SCHEMA = "CELERY_BACKEND_DB_SCHEMA"
+
+ # Redis cache configuration
+ CACHE_REDIS_ENABLED = "CACHE_REDIS_ENABLED"
+ CACHE_REDIS_HOST = "CACHE_REDIS_HOST"
+ CACHE_REDIS_PORT = "CACHE_REDIS_PORT"
+ CACHE_REDIS_DB = "CACHE_REDIS_DB"
+ CACHE_REDIS_PASSWORD = "CACHE_REDIS_PASSWORD" # gitleaks:allow
+ CACHE_REDIS_USERNAME = "CACHE_REDIS_USERNAME"
+ CACHE_REDIS_SSL = "CACHE_REDIS_SSL"
+
+ # Internal API configuration
+ INTERNAL_API_BASE_URL = "INTERNAL_API_BASE_URL"
+ DJANGO_APP_BACKEND_URL = "DJANGO_APP_BACKEND_URL"
+ INTERNAL_SERVICE_API_KEY = "INTERNAL_SERVICE_API_KEY"
+
+ # Performance settings
+ MAX_CONCURRENT_TASKS = "MAX_CONCURRENT_TASKS"
+ TASK_TIMEOUT = "TASK_TIMEOUT"
+ MAX_PARALLEL_FILE_BATCHES = "MAX_PARALLEL_FILE_BATCHES"
+
+ # Monitoring settings
+ ENABLE_METRICS = "ENABLE_METRICS"
+ ENABLE_HEALTH_SERVER = "ENABLE_HEALTH_SERVER"
+ METRICS_PORT = "METRICS_PORT"
+
+ # Logging configuration
+ LOG_LEVEL = "LOG_LEVEL"
+ LOG_FORMAT = "LOG_FORMAT"
+ LOG_FILE = "LOG_FILE"
diff --git a/workers/shared/constants/errors.py b/workers/shared/constants/errors.py
new file mode 100644
index 000000000..0c2bb3556
--- /dev/null
+++ b/workers/shared/constants/errors.py
@@ -0,0 +1,38 @@
+"""Error Message Constants
+
+Standardized error messages for workers.
+"""
+
+
+class ErrorMessages:
+ """Standardized error messages."""
+
+ # Task execution errors
+ TASK_TIMEOUT = "Task execution timed out after {timeout} seconds"
+ TASK_RETRY_EXHAUSTED = "Task failed after {max_retries} retry attempts"
+ TASK_INVALID_INPUT = "Task received invalid input: {details}"
+ TASK_MISSING_CONTEXT = "Task execution context is missing or invalid"
+
+ # File processing errors
+ FILE_NOT_FOUND = "File not found: {file_path}"
+ FILE_ACCESS_DENIED = "Access denied for file: {file_path}"
+ FILE_SIZE_EXCEEDED = "File size {size}MB exceeds maximum limit of {max_size}MB"
+ FILE_FORMAT_UNSUPPORTED = "Unsupported file format: {mime_type}"
+ FILE_PROCESSING_FAILED = "Failed to process file {file_name}: {error}"
+
+ # API communication errors
+ API_CONNECTION_FAILED = "Failed to connect to internal API: {error}"
+ API_AUTHENTICATION_FAILED = "API authentication failed: {error}"
+ API_REQUEST_TIMEOUT = "API request timed out after {timeout} seconds"
+ API_INVALID_RESPONSE = "Invalid API response format: {details}"
+ API_SERVER_ERROR = "Internal API server error: {status_code} - {message}"
+
+ # Configuration errors
+ CONFIG_MISSING_REQUIRED = "Missing required configuration: {field}"
+ CONFIG_INVALID_VALUE = "Invalid configuration value for {field}: {value}"
+ CONFIG_VALIDATION_FAILED = "Configuration validation failed: {errors}"
+
+ # Worker errors
+ WORKER_INITIALIZATION_FAILED = "Worker initialization failed: {error}"
+ WORKER_HEALTH_CHECK_FAILED = "Worker health check failed: {error}"
+ WORKER_RESOURCE_EXHAUSTED = "Worker resources exhausted: {resource}"
diff --git a/workers/shared/constants/logging.py b/workers/shared/constants/logging.py
new file mode 100644
index 000000000..2f0fd530d
--- /dev/null
+++ b/workers/shared/constants/logging.py
@@ -0,0 +1,43 @@
+"""Logging Message Constants
+
+Standardized log messages for workers.
+"""
+
+
+class LogMessages:
+ """Standardized log messages."""
+
+ # Task lifecycle
+ TASK_STARTED = "Task {task_name} started with ID {task_id}"
+ TASK_COMPLETED = "Task {task_name} completed successfully in {execution_time:.2f}s"
+ TASK_FAILED = "Task {task_name} failed: {error}"
+ TASK_RETRYING = "Task {task_name} retrying attempt {attempt}/{max_retries}"
+
+ # File processing
+ FILE_PROCESSING_STARTED = "Started processing file batch with {file_count} files"
+ FILE_PROCESSING_COMPLETED = (
+ "Completed file batch processing: {successful}/{total} files successful"
+ )
+ FILE_EXECUTION_CREATED = "Created file execution record for {file_name}"
+ FILE_STATUS_UPDATED = "Updated file execution status to {status} for {file_name}"
+
+ # Callback processing
+ CALLBACK_TRIGGERED = (
+ "Callback triggered for execution {execution_id} with {batch_count} batches"
+ )
+ CALLBACK_AGGREGATING = "Aggregating results from {batch_count} batch executions"
+ CALLBACK_STATUS_UPDATE = "Updating execution status to {status} for {execution_id}"
+ CALLBACK_COMPLETED = "Callback processing completed for execution {execution_id}"
+
+ # Cache operations
+ CACHE_HIT = "Cache hit for {cache_key}"
+ CACHE_MISS = "Cache miss for {cache_key}"
+ CACHE_SET = "Cached data for {cache_key} with TTL {ttl}s"
+ CACHE_INVALIDATED = "Invalidated cache for {cache_key}"
+ CACHE_CONNECTION_LOST = "Redis connection lost, clearing potentially stale cache"
+
+ # Health and monitoring
+ WORKER_STARTED = "Worker {worker_name} started with version {version}"
+ WORKER_HEALTH_OK = "Worker health check passed"
+ WORKER_HEALTH_DEGRADED = "Worker health check degraded: {issues}"
+ METRICS_COLLECTED = "Performance metrics collected: {metrics}"
diff --git a/workers/shared/constants/monitoring.py b/workers/shared/constants/monitoring.py
new file mode 100644
index 000000000..66250cb51
--- /dev/null
+++ b/workers/shared/constants/monitoring.py
@@ -0,0 +1,28 @@
+"""Monitoring Configuration Constants
+
+Monitoring and metrics configuration.
+"""
+
+
+class MonitoringConfig:
+ """Monitoring and metrics configuration."""
+
+ # Metric collection intervals
+ TASK_METRICS_INTERVAL = 10 # 10 seconds
+ WORKER_METRICS_INTERVAL = 30 # 30 seconds
+ HEALTH_CHECK_INTERVAL = 60 # 1 minute
+
+ # Performance thresholds
+ TASK_SLOW_THRESHOLD = 30.0 # 30 seconds
+ MEMORY_WARNING_THRESHOLD = 80 # 80% of max memory
+ ERROR_RATE_WARNING_THRESHOLD = 5.0 # 5% error rate
+
+ # Metric retention periods
+ TASK_METRICS_RETENTION = 3600 # 1 hour
+ WORKER_METRICS_RETENTION = 86400 # 24 hours
+ ERROR_METRICS_RETENTION = 604800 # 7 days
+
+ # Alert thresholds
+ CONSECUTIVE_FAILURES_ALERT = 5
+ HIGH_ERROR_RATE_ALERT = 10.0 # 10%
+ MEMORY_CRITICAL_ALERT = 95 # 95%
diff --git a/workers/shared/constants/security.py b/workers/shared/constants/security.py
new file mode 100644
index 000000000..3649cdc29
--- /dev/null
+++ b/workers/shared/constants/security.py
@@ -0,0 +1,34 @@
+"""Security Configuration Constants
+
+Security and validation configuration.
+"""
+
+
+class SecurityConfig:
+ """Security and validation configuration."""
+
+ # Input validation patterns
+ VALID_UUID_PATTERN = r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
+ VALID_ORGANIZATION_ID_PATTERN = r"^[a-zA-Z0-9_-]+$"
+ VALID_FILE_NAME_PATTERN = r'^[^<>:"/\\|?*\x00-\x1f]+$'
+
+ # Maximum field lengths
+ MAX_ERROR_MESSAGE_LENGTH = 2048
+ MAX_TASK_NAME_LENGTH = 100
+ MAX_FILE_NAME_LENGTH = 255
+ MAX_FILE_PATH_LENGTH = 4096
+
+ # Allowed characters
+ SAFE_FILENAME_CHARS = (
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._- "
+ )
+
+ # Security headers for API requests
+ REQUIRED_HEADERS = [
+ "Authorization",
+ "Content-Type",
+ ]
+
+ # Rate limiting
+ API_RATE_LIMIT_PER_MINUTE = 1000
+ WEBHOOK_RATE_LIMIT_PER_MINUTE = 100
diff --git a/workers/shared/core/__init__.py b/workers/shared/core/__init__.py
new file mode 100644
index 000000000..8993d368f
--- /dev/null
+++ b/workers/shared/core/__init__.py
@@ -0,0 +1,24 @@
+"""Core interfaces and abstractions for the workers shared library.
+
+This package provides the foundational interfaces, exceptions, and type definitions
+that serve as contracts for the entire workers system.
+"""
+
+from .exceptions import * # noqa: F403
+from .interfaces import * # noqa: F403
+
+__all__ = [
+ # Interfaces
+ "APIClientInterface",
+ "CacheInterface",
+ "ConnectorInterface",
+ "WorkflowExecutorInterface",
+ # Exceptions
+ "WorkerBaseError",
+ "APIClientError",
+ "WorkflowExecutionError",
+ "ConnectorError",
+ # Types
+ "APIResponse",
+ "WorkflowContext",
+]
diff --git a/workers/shared/core/exceptions/__init__.py b/workers/shared/core/exceptions/__init__.py
new file mode 100644
index 000000000..2a9e9da49
--- /dev/null
+++ b/workers/shared/core/exceptions/__init__.py
@@ -0,0 +1,41 @@
+"""Centralized exception hierarchy for workers.
+
+This module provides a unified exception hierarchy following SOLID principles,
+ensuring consistent error handling across all worker components.
+"""
+
+from .api_exceptions import (
+ APIClientError,
+ APIRequestError,
+ AuthenticationError,
+ InternalAPIClientError,
+)
+from .base_exceptions import WorkerBaseError
+from .connector_exceptions import (
+ ConnectorConfigurationError,
+ ConnectorConnectionError,
+ ConnectorError,
+)
+from .workflow_exceptions import (
+ WorkflowConfigurationError,
+ WorkflowExecutionError,
+ WorkflowValidationError,
+)
+
+__all__ = [
+ # Base exception
+ "WorkerBaseError",
+ # API exceptions
+ "APIClientError",
+ "APIRequestError",
+ "AuthenticationError",
+ "InternalAPIClientError",
+ # Connector exceptions
+ "ConnectorError",
+ "ConnectorConfigurationError",
+ "ConnectorConnectionError",
+ # Workflow exceptions
+ "WorkflowExecutionError",
+ "WorkflowConfigurationError",
+ "WorkflowValidationError",
+]
diff --git a/workers/shared/core/exceptions/api_exceptions.py b/workers/shared/core/exceptions/api_exceptions.py
new file mode 100644
index 000000000..2f48a92fa
--- /dev/null
+++ b/workers/shared/core/exceptions/api_exceptions.py
@@ -0,0 +1,52 @@
+"""API client related exceptions.
+
+These exceptions follow the Single Responsibility Principle by handling
+only API-related error scenarios.
+"""
+
+from .base_exceptions import WorkerBaseError
+
+
+class APIClientError(WorkerBaseError):
+ """Base exception for API client errors."""
+
+ pass
+
+
+class APIRequestError(APIClientError):
+ """Raised when an API request fails."""
+
+ def __init__(
+ self, message: str, status_code: int = None, response_body: str = None, **kwargs
+ ):
+ super().__init__(message, **kwargs)
+ self.status_code = status_code
+ self.response_body = response_body
+
+
+class AuthenticationError(APIClientError):
+ """Raised when API authentication fails."""
+
+ pass
+
+
+class InternalAPIClientError(APIClientError):
+ """Raised for internal API client configuration or logic errors."""
+
+ pass
+
+
+class RateLimitError(APIClientError):
+ """Raised when API rate limits are exceeded."""
+
+ def __init__(self, message: str, retry_after: int = None, **kwargs):
+ super().__init__(message, **kwargs)
+ self.retry_after = retry_after
+
+
+class TimeoutError(APIClientError):
+ """Raised when API requests timeout."""
+
+ def __init__(self, message: str, timeout_duration: float = None, **kwargs):
+ super().__init__(message, **kwargs)
+ self.timeout_duration = timeout_duration
diff --git a/workers/shared/core/exceptions/base_exceptions.py b/workers/shared/core/exceptions/base_exceptions.py
new file mode 100644
index 000000000..447439bbf
--- /dev/null
+++ b/workers/shared/core/exceptions/base_exceptions.py
@@ -0,0 +1,34 @@
+"""Base exception classes for the workers system.
+
+Following the Liskov Substitution Principle, all worker exceptions inherit from
+WorkerBaseError, ensuring consistent error handling interfaces.
+"""
+
+
+class WorkerBaseError(Exception):
+ """Base exception for all worker-related errors.
+
+ This provides a consistent interface for error handling across all worker
+ components, following the Interface Segregation Principle.
+ """
+
+ def __init__(self, message: str, details: dict = None, cause: Exception = None):
+ super().__init__(message)
+ self.message = message
+ self.details = details or {}
+ self.cause = cause
+
+ def __str__(self) -> str:
+ return self.message
+
+ def __repr__(self) -> str:
+ return f"{self.__class__.__name__}('{self.message}')"
+
+ def to_dict(self) -> dict:
+ """Convert exception to dictionary for serialization."""
+ return {
+ "error_type": self.__class__.__name__,
+ "message": self.message,
+ "details": self.details,
+ "cause": str(self.cause) if self.cause else None,
+ }
diff --git a/workers/shared/core/exceptions/connector_exceptions.py b/workers/shared/core/exceptions/connector_exceptions.py
new file mode 100644
index 000000000..bf4b2ed16
--- /dev/null
+++ b/workers/shared/core/exceptions/connector_exceptions.py
@@ -0,0 +1,42 @@
+"""Connector related exceptions.
+
+These exceptions handle connector-specific error scenarios following
+the Single Responsibility Principle.
+"""
+
+from .base_exceptions import WorkerBaseError
+
+
+class ConnectorError(WorkerBaseError):
+ """Base exception for connector errors."""
+
+ def __init__(
+ self, message: str, connector_type: str = None, connector_id: str = None, **kwargs
+ ):
+ super().__init__(message, **kwargs)
+ self.connector_type = connector_type
+ self.connector_id = connector_id
+
+
+class ConnectorConfigurationError(ConnectorError):
+ """Raised when connector configuration is invalid."""
+
+ pass
+
+
+class ConnectorConnectionError(ConnectorError):
+ """Raised when connector fails to establish connection."""
+
+ pass
+
+
+class ConnectorAuthenticationError(ConnectorError):
+ """Raised when connector authentication fails."""
+
+ pass
+
+
+class ConnectorPermissionError(ConnectorError):
+ """Raised when connector lacks required permissions."""
+
+ pass
diff --git a/workers/shared/core/exceptions/workflow_exceptions.py b/workers/shared/core/exceptions/workflow_exceptions.py
new file mode 100644
index 000000000..dc35282b3
--- /dev/null
+++ b/workers/shared/core/exceptions/workflow_exceptions.py
@@ -0,0 +1,46 @@
+"""Workflow execution related exceptions.
+
+These exceptions handle workflow-specific error scenarios following
+the Single Responsibility Principle.
+"""
+
+from .base_exceptions import WorkerBaseError
+
+
+class WorkflowExecutionError(WorkerBaseError):
+ """Base exception for workflow execution errors."""
+
+ def __init__(
+ self, message: str, workflow_id: str = None, execution_id: str = None, **kwargs
+ ):
+ super().__init__(message, **kwargs)
+ self.workflow_id = workflow_id
+ self.execution_id = execution_id
+
+
+class WorkflowConfigurationError(WorkflowExecutionError):
+ """Raised when workflow configuration is invalid."""
+
+ pass
+
+
+class WorkflowValidationError(WorkflowExecutionError):
+ """Raised when workflow validation fails."""
+
+ pass
+
+
+class WorkflowTimeoutError(WorkflowExecutionError):
+ """Raised when workflow execution times out."""
+
+ def __init__(self, message: str, timeout_duration: float = None, **kwargs):
+ super().__init__(message, **kwargs)
+ self.timeout_duration = timeout_duration
+
+
+class WorkflowFileProcessingError(WorkflowExecutionError):
+ """Raised when file processing within workflow fails."""
+
+ def __init__(self, message: str, file_name: str = None, **kwargs):
+ super().__init__(message, **kwargs)
+ self.file_name = file_name
diff --git a/workers/shared/core/interfaces/__init__.py b/workers/shared/core/interfaces/__init__.py
new file mode 100644
index 000000000..4c8ee9891
--- /dev/null
+++ b/workers/shared/core/interfaces/__init__.py
@@ -0,0 +1,27 @@
+"""Core interfaces and protocols for the workers system.
+
+These interfaces define contracts that must be followed by all implementations,
+adhering to the Interface Segregation Principle by providing focused,
+role-specific interfaces.
+"""
+
+from .api_interfaces import APIClientInterface, CacheInterface
+from .connector_interfaces import (
+ ConnectorInterface,
+ DestinationConnectorInterface,
+ SourceConnectorInterface,
+)
+from .workflow_interfaces import WorkflowExecutorInterface, WorkflowValidatorInterface
+
+__all__ = [
+ # API interfaces
+ "APIClientInterface",
+ "CacheInterface",
+ # Connector interfaces
+ "ConnectorInterface",
+ "SourceConnectorInterface",
+ "DestinationConnectorInterface",
+ # Workflow interfaces
+ "WorkflowExecutorInterface",
+ "WorkflowValidatorInterface",
+]
diff --git a/workers/shared/core/interfaces/api_interfaces.py b/workers/shared/core/interfaces/api_interfaces.py
new file mode 100644
index 000000000..ae28b0d40
--- /dev/null
+++ b/workers/shared/core/interfaces/api_interfaces.py
@@ -0,0 +1,85 @@
+"""API client interfaces following Interface Segregation Principle.
+
+These interfaces define minimal contracts for API client implementations,
+allowing for flexible and testable code.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any
+
+
+class APIClientInterface(ABC):
+ """Base interface for API clients."""
+
+ @abstractmethod
+ def get(self, endpoint: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
+ """Perform GET request to API endpoint."""
+ pass
+
+ @abstractmethod
+ def post(self, endpoint: str, data: dict[str, Any] | None = None) -> dict[str, Any]:
+ """Perform POST request to API endpoint."""
+ pass
+
+ @abstractmethod
+ def put(self, endpoint: str, data: dict[str, Any] | None = None) -> dict[str, Any]:
+ """Perform PUT request to API endpoint."""
+ pass
+
+ @abstractmethod
+ def delete(self, endpoint: str) -> dict[str, Any]:
+ """Perform DELETE request to API endpoint."""
+ pass
+
+ @abstractmethod
+ def set_organization_context(self, organization_id: str) -> None:
+ """Set organization context for subsequent requests."""
+ pass
+
+
+class CacheInterface(ABC):
+ """Interface for caching implementations."""
+
+ @abstractmethod
+ def get(self, key: str) -> Any | None:
+ """Retrieve value from cache."""
+ pass
+
+ @abstractmethod
+ def set(self, key: str, value: Any, ttl: int | None = None) -> bool:
+ """Store value in cache with optional TTL."""
+ pass
+
+ @abstractmethod
+ def delete(self, key: str) -> bool:
+ """Remove value from cache."""
+ pass
+
+ @abstractmethod
+ def clear(self) -> bool:
+ """Clear all cached values."""
+ pass
+
+ @abstractmethod
+ def exists(self, key: str) -> bool:
+ """Check if key exists in cache."""
+ pass
+
+
+class AuthenticationInterface(ABC):
+ """Interface for authentication handlers."""
+
+ @abstractmethod
+ def authenticate(self) -> dict[str, str]:
+ """Perform authentication and return headers."""
+ pass
+
+ @abstractmethod
+ def refresh_token(self) -> bool:
+ """Refresh authentication token if needed."""
+ pass
+
+ @abstractmethod
+ def is_authenticated(self) -> bool:
+ """Check if currently authenticated."""
+ pass
diff --git a/workers/shared/core/interfaces/connector_interfaces.py b/workers/shared/core/interfaces/connector_interfaces.py
new file mode 100644
index 000000000..edab23d0a
--- /dev/null
+++ b/workers/shared/core/interfaces/connector_interfaces.py
@@ -0,0 +1,86 @@
+"""Connector interfaces following Interface Segregation Principle.
+
+These interfaces define contracts for different types of connectors,
+allowing for flexible connector implementations.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any
+
+
+class ConnectorInterface(ABC):
+ """Base interface for all connectors."""
+
+ @abstractmethod
+ def validate_configuration(self, config: dict[str, Any]) -> bool:
+ """Validate connector configuration."""
+ pass
+
+ @abstractmethod
+ def test_connection(self) -> bool:
+ """Test connector connection."""
+ pass
+
+ @abstractmethod
+ def get_connection_info(self) -> dict[str, Any]:
+ """Get connector connection information."""
+ pass
+
+
+class SourceConnectorInterface(ConnectorInterface):
+ """Interface for source connectors (read data)."""
+
+ @abstractmethod
+ def list_files(self, path: str | None = None) -> list[dict[str, Any]]:
+ """List files from source."""
+ pass
+
+ @abstractmethod
+ def read_file(self, file_path: str) -> bytes:
+ """Read file content from source."""
+ pass
+
+ @abstractmethod
+ def get_file_metadata(self, file_path: str) -> dict[str, Any]:
+ """Get file metadata from source."""
+ pass
+
+
+class DestinationConnectorInterface(ConnectorInterface):
+ """Interface for destination connectors (write data)."""
+
+ @abstractmethod
+ def write_file(self, file_path: str, content: bytes) -> bool:
+ """Write file content to destination."""
+ pass
+
+ @abstractmethod
+ def create_directory(self, directory_path: str) -> bool:
+ """Create directory at destination."""
+ pass
+
+ @abstractmethod
+ def delete_file(self, file_path: str) -> bool:
+ """Delete file from destination."""
+ pass
+
+
+class DatabaseConnectorInterface(ConnectorInterface):
+ """Interface for database connectors."""
+
+ @abstractmethod
+ def execute_query(
+ self, query: str, params: dict[str, Any] | None = None
+ ) -> list[dict[str, Any]]:
+ """Execute database query."""
+ pass
+
+ @abstractmethod
+ def insert_records(self, table_name: str, records: list[dict[str, Any]]) -> bool:
+ """Insert records into database table."""
+ pass
+
+ @abstractmethod
+ def get_schema(self) -> dict[str, Any]:
+ """Get database schema information."""
+ pass
diff --git a/workers/shared/core/interfaces/workflow_interfaces.py b/workers/shared/core/interfaces/workflow_interfaces.py
new file mode 100644
index 000000000..04e461eb2
--- /dev/null
+++ b/workers/shared/core/interfaces/workflow_interfaces.py
@@ -0,0 +1,81 @@
+"""Workflow execution interfaces following Interface Segregation Principle.
+
+These interfaces define contracts for workflow execution components,
+ensuring modular and testable workflow implementations.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any
+
+
+class WorkflowExecutorInterface(ABC):
+ """Interface for workflow executors."""
+
+ @abstractmethod
+ def execute(self, workflow_context: dict[str, Any]) -> dict[str, Any]:
+ """Execute workflow with given context."""
+ pass
+
+ @abstractmethod
+ def validate_context(self, workflow_context: dict[str, Any]) -> bool:
+ """Validate workflow context before execution."""
+ pass
+
+ @abstractmethod
+ def get_execution_status(self, execution_id: str) -> str:
+ """Get current execution status."""
+ pass
+
+
+class WorkflowValidatorInterface(ABC):
+ """Interface for workflow validators."""
+
+ @abstractmethod
+ def validate_workflow_definition(self, definition: dict[str, Any]) -> list[str]:
+ """Validate workflow definition and return errors."""
+ pass
+
+ @abstractmethod
+ def validate_input_data(self, data: dict[str, Any]) -> list[str]:
+ """Validate input data and return errors."""
+ pass
+
+
+class WorkflowOrchestratorInterface(ABC):
+ """Interface for workflow orchestrators."""
+
+ @abstractmethod
+ def orchestrate_execution(
+ self, workflow_id: str, execution_context: dict[str, Any]
+ ) -> str:
+ """Orchestrate workflow execution and return execution ID."""
+ pass
+
+ @abstractmethod
+ def monitor_execution(self, execution_id: str) -> dict[str, Any]:
+ """Monitor workflow execution progress."""
+ pass
+
+ @abstractmethod
+ def cancel_execution(self, execution_id: str) -> bool:
+ """Cancel ongoing workflow execution."""
+ pass
+
+
+class FileProcessorInterface(ABC):
+ """Interface for file processors."""
+
+ @abstractmethod
+ def process_file(self, file_data: dict[str, Any]) -> dict[str, Any]:
+ """Process individual file."""
+ pass
+
+ @abstractmethod
+ def process_batch(self, file_batch: list[dict[str, Any]]) -> list[dict[str, Any]]:
+ """Process batch of files."""
+ pass
+
+ @abstractmethod
+ def validate_file_format(self, file_data: dict[str, Any]) -> bool:
+ """Validate file format for processing."""
+ pass
diff --git a/workers/shared/data/__init__.py b/workers/shared/data/__init__.py
new file mode 100644
index 000000000..bc715f25f
--- /dev/null
+++ b/workers/shared/data/__init__.py
@@ -0,0 +1,20 @@
+"""Data models and structures for workers.
+
+This package provides data models, response models, enums, and constants
+used throughout the workers system.
+"""
+
+from .models import * # noqa: F403
+from .response_models import * # noqa: F403
+
+# Models are imported above
+
+__all__ = [
+ # Data models
+ "CallbackTaskData",
+ "WorkerTaskResponse",
+ "WorkflowExecutionStatusUpdate",
+ # Response models
+ "APIResponse",
+ # Enums and constants are imported from subpackages
+]
diff --git a/workers/shared/data/models.py b/workers/shared/data/models.py
new file mode 100644
index 000000000..1263e9fec
--- /dev/null
+++ b/workers/shared/data/models.py
@@ -0,0 +1,562 @@
+"""Shared Data Models for Worker Services
+
+This module contains dataclass definitions used across worker services
+to ensure type safety and prevent dictionary usage for structured data.
+"""
+
+from dataclasses import dataclass
+from datetime import datetime
+from typing import Any
+from uuid import UUID
+
+from ..enums import (
+ BatchOperationType,
+ CircuitBreakerState,
+ ConnectionType,
+ EndpointType,
+ FileOperationType,
+ HTTPMethod,
+ LogLevel,
+ NotificationPlatform,
+ TaskStatus,
+ ToolOutputType,
+)
+
+
+@dataclass
+class WorkflowExecutionData:
+ """Workflow execution data structure."""
+
+ id: str | UUID
+ workflow_id: str | UUID
+ status: TaskStatus
+ created_at: datetime
+ updated_at: datetime
+ execution_method: str | None = None
+ total_files: int | None = None
+ completed_files: int | None = None
+ failed_files: int | None = None
+ error_message: str | None = None
+ execution_time: float | None = None
+ attempts: int | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "workflow_id": str(self.workflow_id),
+ "status": self.status.value,
+ "created_at": self.created_at.isoformat(),
+ "updated_at": self.updated_at.isoformat(),
+ "execution_method": self.execution_method,
+ "total_files": self.total_files,
+ "completed_files": self.completed_files,
+ "failed_files": self.failed_files,
+ "error_message": self.error_message,
+ "execution_time": self.execution_time,
+ "attempts": self.attempts,
+ }
+
+
+@dataclass
+class WorkflowDefinition:
+ """Workflow definition data structure."""
+
+ id: str | UUID
+ workflow_name: str
+ workflow_type: str
+ description: str | None = None
+ created_at: datetime | None = None
+ updated_at: datetime | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "workflow_name": self.workflow_name,
+ "workflow_type": self.workflow_type,
+ "description": self.description,
+ "created_at": self.created_at.isoformat() if self.created_at else None,
+ "updated_at": self.updated_at.isoformat() if self.updated_at else None,
+ }
+
+
+@dataclass
+class FileExecutionData:
+ """File execution data structure."""
+
+ id: str | UUID
+ workflow_execution_id: str | UUID
+ file_path: str
+ file_name: str
+ status: TaskStatus
+ created_at: datetime
+ updated_at: datetime
+ file_size: int | None = None
+ mime_type: str | None = None
+ file_hash: str | None = None
+ processing_time: float | None = None
+ error_message: str | None = None
+ result_data: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "workflow_execution_id": str(self.workflow_execution_id),
+ "file_path": self.file_path,
+ "file_name": self.file_name,
+ "status": self.status.value,
+ "created_at": self.created_at.isoformat(),
+ "updated_at": self.updated_at.isoformat(),
+ "file_size": self.file_size,
+ "mime_type": self.mime_type,
+ "file_hash": self.file_hash,
+ "processing_time": self.processing_time,
+ "error_message": self.error_message,
+ "result_data": self.result_data,
+ }
+
+
+@dataclass
+class ToolExecutionData:
+ """Tool execution data structure."""
+
+ id: str | UUID
+ tool_name: str
+ tool_version: str
+ status: TaskStatus
+ output_type: ToolOutputType
+ created_at: datetime
+ updated_at: datetime
+ input_data: dict[str, Any] | None = None
+ output_data: dict[str, Any] | None = None
+ execution_time: float | None = None
+ error_message: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "tool_name": self.tool_name,
+ "tool_version": self.tool_version,
+ "status": self.status.value,
+ "output_type": self.output_type.value,
+ "created_at": self.created_at.isoformat(),
+ "updated_at": self.updated_at.isoformat(),
+ "input_data": self.input_data,
+ "output_data": self.output_data,
+ "execution_time": self.execution_time,
+ "error_message": self.error_message,
+ }
+
+
+@dataclass
+class WebhookDeliveryData:
+ """Webhook delivery data structure."""
+
+ id: str | UUID
+ url: str
+ method: HTTPMethod
+ platform: NotificationPlatform
+ status: TaskStatus
+ created_at: datetime
+ updated_at: datetime
+ payload: dict[str, Any] | None = None
+ headers: dict[str, str] | None = None
+ response_code: int | None = None
+ response_data: dict[str, Any] | None = None
+ attempts: int | None = None
+ next_retry_at: datetime | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "url": self.url,
+ "method": self.method.value,
+ "platform": self.platform.value,
+ "status": self.status.value,
+ "created_at": self.created_at.isoformat(),
+ "updated_at": self.updated_at.isoformat(),
+ "payload": self.payload,
+ "headers": self.headers,
+ "response_code": self.response_code,
+ "response_data": self.response_data,
+ "attempts": self.attempts,
+ "next_retry_at": self.next_retry_at.isoformat()
+ if self.next_retry_at
+ else None,
+ }
+
+
+@dataclass
+class EndpointConfiguration:
+ """Endpoint configuration data structure."""
+
+ id: str | UUID
+ endpoint_type: EndpointType
+ connection_type: ConnectionType
+ configuration: dict[str, Any]
+ name: str | None = None
+ description: str | None = None
+ is_active: bool = True
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "endpoint_type": self.endpoint_type.value,
+ "connection_type": self.connection_type.value,
+ "configuration": self.configuration,
+ "name": self.name,
+ "description": self.description,
+ "is_active": self.is_active,
+ }
+
+
+@dataclass
+class BatchOperationRequest:
+ """Batch operation request data structure."""
+
+ operation_type: BatchOperationType
+ items: list[dict[str, Any]]
+ organization_id: str | None = None
+ batch_size: int = 100
+ parallel_processing: bool = True
+
+ def to_dict(self) -> dict[str, Any]:
+ # Use 'updates' field name for status update operations to match backend API
+ items_field_name = (
+ "updates"
+ if self.operation_type == BatchOperationType.STATUS_UPDATE
+ else "items"
+ )
+
+ return {
+ "operation_type": self.operation_type.value,
+ items_field_name: self.items,
+ "organization_id": self.organization_id,
+ "batch_size": self.batch_size,
+ "parallel_processing": self.parallel_processing,
+ }
+
+
+@dataclass
+class BatchOperationResponse:
+ """Batch operation response data structure."""
+
+ operation_id: str
+ total_items: int
+ successful_items: int
+ failed_items: int
+ status: TaskStatus
+ results: list[dict[str, Any]]
+ errors: list[dict[str, Any]]
+ execution_time: float | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "operation_id": self.operation_id,
+ "total_items": self.total_items,
+ "successful_items": self.successful_items,
+ "failed_items": self.failed_items,
+ "status": self.status.value,
+ "results": self.results,
+ "errors": self.errors,
+ "execution_time": self.execution_time,
+ }
+
+
+@dataclass
+class FileHistoryData:
+ """File history data structure."""
+
+ id: str | UUID
+ file_execution_id: str | UUID
+ operation_type: FileOperationType
+ timestamp: datetime
+ file_path: str
+ file_name: str
+ file_size: int | None = None
+ status: TaskStatus | None = None
+ metadata: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "file_execution_id": str(self.file_execution_id),
+ "operation_type": self.operation_type.value,
+ "timestamp": self.timestamp.isoformat(),
+ "file_path": self.file_path,
+ "file_name": self.file_name,
+ "file_size": self.file_size,
+ "status": self.status.value if self.status else None,
+ "metadata": self.metadata,
+ }
+
+
+@dataclass
+class CircuitBreakerStatus:
+ """Circuit breaker status data structure."""
+
+ state: CircuitBreakerState
+ failure_count: int
+ last_failure_time: datetime | None = None
+ next_attempt_time: datetime | None = None
+ success_count: int = 0
+ total_requests: int = 0
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "state": self.state.value,
+ "failure_count": self.failure_count,
+ "last_failure_time": self.last_failure_time.isoformat()
+ if self.last_failure_time
+ else None,
+ "next_attempt_time": self.next_attempt_time.isoformat()
+ if self.next_attempt_time
+ else None,
+ "success_count": self.success_count,
+ "total_requests": self.total_requests,
+ }
+
+
+@dataclass
+class LogEntry:
+ """Log entry data structure."""
+
+ timestamp: datetime
+ level: LogLevel
+ message: str
+ logger_name: str
+ module: str | None = None
+ function: str | None = None
+ line_number: int | None = None
+ context: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "timestamp": self.timestamp.isoformat(),
+ "level": self.level.value,
+ "message": self.message,
+ "logger_name": self.logger_name,
+ "module": self.module,
+ "function": self.function,
+ "line_number": self.line_number,
+ "context": self.context,
+ }
+
+
+@dataclass
+class APIResponse:
+ """Generic API response data structure."""
+
+ success: bool
+ data: dict[str, Any] | None = None
+ error: str | None = None
+ status_code: int | None = None
+ timestamp: datetime | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "success": self.success,
+ "data": self.data,
+ "error": self.error,
+ "status_code": self.status_code,
+ "timestamp": self.timestamp.isoformat() if self.timestamp else None,
+ }
+
+
+@dataclass
+class StatusUpdateRequest:
+ """Status update request data structure."""
+
+ id: str | UUID
+ status: TaskStatus
+ error_message: str | None = None
+ metadata: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "id": str(self.id),
+ "status": self.status.value,
+ "error_message": self.error_message,
+ "metadata": self.metadata,
+ }
+
+
+@dataclass
+class MetricsData:
+ """Metrics data structure."""
+
+ timestamp: datetime
+ metric_name: str
+ value: int | float
+ unit: str
+ tags: dict[str, str] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "timestamp": self.timestamp.isoformat(),
+ "metric_name": self.metric_name,
+ "value": self.value,
+ "unit": self.unit,
+ "tags": self.tags,
+ }
+
+
+@dataclass
+class WorkerTaskResponse:
+ """Generic worker task response structure."""
+
+ status: str
+ execution_id: str | UUID
+ workflow_id: str | UUID
+ task_id: str | None = None
+ execution_time: float | None = None
+ success: bool = True
+ error: str | None = None
+ is_general_workflow: bool | None = None
+ pipeline_id: str | UUID | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return {
+ "status": self.status,
+ "execution_id": str(self.execution_id),
+ "workflow_id": str(self.workflow_id),
+ "task_id": self.task_id,
+ "execution_time": self.execution_time,
+ "success": self.success,
+ "error": self.error,
+ "is_general_workflow": self.is_general_workflow,
+ "pipeline_id": str(self.pipeline_id) if self.pipeline_id else None,
+ }
+
+ @classmethod
+ def success_response(
+ cls,
+ execution_id: str | UUID,
+ workflow_id: str | UUID,
+ task_id: str | None = None,
+ execution_time: float | None = None,
+ pipeline_id: str | UUID | None = None,
+ ) -> "WorkerTaskResponse":
+ """Create a success response."""
+ return cls(
+ status="success",
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ task_id=task_id,
+ execution_time=execution_time,
+ success=True,
+ pipeline_id=pipeline_id,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ execution_id: str | UUID,
+ workflow_id: str | UUID,
+ error: str,
+ task_id: str | None = None,
+ execution_time: float | None = None,
+ ) -> "WorkerTaskResponse":
+ """Create an error response."""
+ return cls(
+ status="error",
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ task_id=task_id,
+ execution_time=execution_time,
+ success=False,
+ error=error,
+ )
+
+
+def validate_uuid(value: str | UUID | None) -> UUID | None:
+ if value is None:
+ return None
+ if isinstance(value, UUID):
+ return value
+ try:
+ return UUID(str(value))
+ except (ValueError, AttributeError, TypeError):
+ return None
+
+
+@dataclass
+class CallbackTaskData:
+ """Callback task data structure for worker callbacks."""
+
+ execution_id: str | UUID
+ organization_id: str | UUID
+ pipeline_id: str | UUID | None = None
+
+ def __post_init__(self):
+ # Validate and convert to UUID or None
+ self.execution_id = validate_uuid(self.execution_id)
+ self.organization_id = validate_uuid(self.organization_id)
+ self.pipeline_id = validate_uuid(self.pipeline_id)
+
+ def to_dict(self) -> dict[str, Any]:
+ data = {
+ "execution_id": str(self.execution_id) if self.execution_id else None,
+ "organization_id": str(self.organization_id)
+ if self.organization_id
+ else None,
+ }
+ if self.pipeline_id:
+ data["pipeline_id"] = str(self.pipeline_id)
+ return data
+
+
+@dataclass
+class WorkflowExecutionStatusUpdate:
+ """Workflow execution status update data structure."""
+
+ execution_id: str | UUID
+ status: str
+ execution_time: float | None = None
+ total_files: int | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ data = {
+ "execution_id": str(self.execution_id),
+ "status": self.status,
+ }
+ if self.execution_time is not None:
+ data["execution_time"] = self.execution_time
+ if self.total_files is not None:
+ data["total_files"] = self.total_files
+ return data
+
+
+# Utility functions for data model conversion
+def dict_to_dataclass(data: dict[str, Any], dataclass_type):
+ """Convert dictionary to dataclass instance."""
+ if not isinstance(data, dict):
+ return data
+
+ # Get field names and types from dataclass
+ from dataclasses import fields
+
+ if not hasattr(dataclass_type, "__dataclass_fields__"):
+ return data
+
+ field_types = {field.name: field.type for field in fields(dataclass_type)}
+ kwargs = {}
+
+ for field_name, field_type in field_types.items():
+ if field_name in data:
+ value = data[field_name]
+
+ # Handle datetime conversion
+ if field_type == datetime and isinstance(value, str):
+ kwargs[field_name] = datetime.fromisoformat(value.replace("Z", "+00:00"))
+ # Handle UUID conversion
+ elif field_type in [UUID, str | UUID] and isinstance(value, str):
+ kwargs[field_name] = value
+ # Handle enum conversion
+ elif hasattr(field_type, "__bases__") and any(
+ base.__name__ == "Enum" for base in field_type.__bases__
+ ):
+ kwargs[field_name] = field_type(value)
+ else:
+ kwargs[field_name] = value
+
+ return dataclass_type(**kwargs)
diff --git a/workers/shared/data/response_models.py b/workers/shared/data/response_models.py
new file mode 100644
index 000000000..08d44da0f
--- /dev/null
+++ b/workers/shared/data/response_models.py
@@ -0,0 +1,444 @@
+"""Consistent Response Models for Workers
+
+These models provide consistent response formats across all worker operations,
+eliminating dict-based response handling and ensuring type safety.
+"""
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import Any
+
+
+class ResponseStatus(str, Enum):
+ """Standard response status values."""
+
+ SUCCESS = "success"
+ ERROR = "error"
+ PENDING = "pending"
+ COMPLETED = "completed"
+ FAILED = "failed"
+
+
+@dataclass
+class BaseResponse:
+ """Base response class for all worker operations."""
+
+ success: bool
+ message: str | None = None
+ status_code: int | None = None
+
+ @classmethod
+ def success_response(
+ cls, message: str | None = None, status_code: int = 200
+ ) -> "BaseResponse":
+ """Create a successful response."""
+ return cls(success=True, message=message, status_code=status_code)
+
+ @classmethod
+ def error_response(cls, message: str, status_code: int = 400) -> "BaseResponse":
+ """Create an error response."""
+ return cls(success=False, message=message, status_code=status_code)
+
+
+@dataclass
+class APIResponse(BaseResponse):
+ """Standard API response with data payload."""
+
+ data: dict[str, Any] | None = None
+ error: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert response to dictionary format for compatibility."""
+ result = {
+ "success": self.success,
+ "data": self.data or {},
+ "status_code": self.status_code,
+ }
+ if self.message:
+ result["message"] = self.message
+ if self.error:
+ result["error"] = self.error
+ return result
+
+ @classmethod
+ def success_response(
+ cls,
+ data: dict[str, Any] | None = None,
+ message: str | None = None,
+ status_code: int = 200,
+ ) -> "APIResponse":
+ """Create a successful API response."""
+ return cls(success=True, data=data, message=message, status_code=status_code)
+
+ @classmethod
+ def error_response(
+ cls, error: str, message: str | None = None, status_code: int = 400
+ ) -> "APIResponse":
+ """Create an error API response."""
+ return cls(success=False, error=error, message=message, status_code=status_code)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "APIResponse":
+ """Reconstruct APIResponse from dictionary (for cache deserialization)."""
+ return cls(
+ success=data.get("success", True),
+ data=data.get("data"),
+ error=data.get("error"),
+ message=data.get("message"),
+ status_code=data.get("status_code", 200),
+ )
+
+
+@dataclass
+class BatchOperationResponse(BaseResponse):
+ """Response for batch operations."""
+
+ successful_items: int = 0
+ failed_items: int = 0
+ total_items: int = 0
+ errors: list[str] = None
+
+ def __post_init__(self):
+ if self.errors is None:
+ self.errors = []
+
+ @classmethod
+ def success_response(
+ cls,
+ successful_items: int,
+ total_items: int,
+ failed_items: int = 0,
+ errors: list[str] | None = None,
+ message: str | None = None,
+ ) -> "BatchOperationResponse":
+ """Create a successful batch response."""
+ return cls(
+ success=True,
+ successful_items=successful_items,
+ failed_items=failed_items,
+ total_items=total_items,
+ errors=errors or [],
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ total_items: int,
+ errors: list[str],
+ successful_items: int = 0,
+ message: str | None = None,
+ ) -> "BatchOperationResponse":
+ """Create an error batch response."""
+ failed_items = total_items - successful_items
+ return cls(
+ success=False,
+ successful_items=successful_items,
+ failed_items=failed_items,
+ total_items=total_items,
+ errors=errors,
+ message=message,
+ )
+
+ @property
+ def success_rate(self) -> float:
+ """Calculate success rate as percentage."""
+ if self.total_items == 0:
+ return 0.0
+ return (self.successful_items / self.total_items) * 100.0
+
+
+@dataclass
+class WorkflowResponse(APIResponse):
+ """Response for workflow operations."""
+
+ workflow_id: str | None = None
+ status: str | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ workflow_id: str | None = None,
+ status: str = ResponseStatus.SUCCESS,
+ data: dict[str, Any] | None = None,
+ message: str | None = None,
+ ) -> "WorkflowResponse":
+ """Create a successful workflow response."""
+ return cls(
+ success=True,
+ workflow_id=workflow_id,
+ status=status,
+ data=data,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ workflow_id: str | None = None,
+ status: str = ResponseStatus.ERROR,
+ message: str | None = None,
+ ) -> "WorkflowResponse":
+ """Create an error workflow response."""
+ return cls(
+ success=False,
+ workflow_id=workflow_id,
+ status=status,
+ error=error,
+ message=message,
+ )
+
+
+@dataclass
+class ExecutionResponse(APIResponse):
+ """Response for workflow/task execution operations."""
+
+ execution_id: str | None = None
+ status: str | None = None
+ metadata: dict[str, Any] | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ execution_id: str | None = None,
+ status: str = ResponseStatus.SUCCESS,
+ data: dict[str, Any] | None = None,
+ metadata: dict[str, Any] | None = None,
+ message: str | None = None,
+ ) -> "ExecutionResponse":
+ """Create a successful execution response."""
+ return cls(
+ success=True,
+ execution_id=execution_id,
+ status=status,
+ data=data,
+ metadata=metadata,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ execution_id: str | None = None,
+ status: str = ResponseStatus.ERROR,
+ message: str | None = None,
+ ) -> "ExecutionResponse":
+ """Create an error execution response."""
+ return cls(
+ success=False,
+ execution_id=execution_id,
+ status=status,
+ error=error,
+ message=message,
+ )
+
+
+@dataclass
+class WebhookResponse(APIResponse):
+ """Response for webhook operations."""
+
+ task_id: str | None = None
+ url: str | None = None
+ delivery_status: str | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ task_id: str | None = None,
+ url: str | None = None,
+ delivery_status: str = "delivered",
+ data: dict[str, Any] | None = None,
+ message: str | None = None,
+ ) -> "WebhookResponse":
+ """Create a successful webhook response."""
+ return cls(
+ success=True,
+ task_id=task_id,
+ url=url,
+ delivery_status=delivery_status,
+ data=data,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ task_id: str | None = None,
+ url: str | None = None,
+ delivery_status: str = "failed",
+ message: str | None = None,
+ ) -> "WebhookResponse":
+ """Create an error webhook response."""
+ return cls(
+ success=False,
+ task_id=task_id,
+ url=url,
+ delivery_status=delivery_status,
+ error=error,
+ message=message,
+ )
+
+
+@dataclass
+class FileOperationResponse(APIResponse):
+ """Response for file operations."""
+
+ file_id: str | None = None
+ file_name: str | None = None
+ file_size: int | None = None
+ processing_time: float | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ file_id: str | None = None,
+ file_name: str | None = None,
+ file_size: int | None = None,
+ processing_time: float | None = None,
+ data: dict[str, Any] | None = None,
+ message: str | None = None,
+ ) -> "FileOperationResponse":
+ """Create a successful file operation response."""
+ return cls(
+ success=True,
+ file_id=file_id,
+ file_name=file_name,
+ file_size=file_size,
+ processing_time=processing_time,
+ data=data,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ file_id: str | None = None,
+ file_name: str | None = None,
+ message: str | None = None,
+ ) -> "FileOperationResponse":
+ """Create an error file operation response."""
+ return cls(
+ success=False,
+ file_id=file_id,
+ file_name=file_name,
+ error=error,
+ message=message,
+ )
+
+
+@dataclass
+class ConnectorResponse(APIResponse):
+ """Response for connector operations."""
+
+ connector_id: str | None = None
+ connector_type: str | None = None
+ connection_status: str | None = None
+
+ @classmethod
+ def success_response(
+ cls,
+ connector_id: str | None = None,
+ connector_type: str | None = None,
+ connection_status: str = "connected",
+ data: dict[str, Any] | None = None,
+ message: str | None = None,
+ ) -> "ConnectorResponse":
+ """Create a successful connector response."""
+ return cls(
+ success=True,
+ connector_id=connector_id,
+ connector_type=connector_type,
+ connection_status=connection_status,
+ data=data,
+ message=message,
+ )
+
+ @classmethod
+ def error_response(
+ cls,
+ error: str,
+ connector_id: str | None = None,
+ connector_type: str | None = None,
+ connection_status: str = "failed",
+ message: str | None = None,
+ ) -> "ConnectorResponse":
+ """Create an error connector response."""
+ return cls(
+ success=False,
+ connector_id=connector_id,
+ connector_type=connector_type,
+ connection_status=connection_status,
+ error=error,
+ message=message,
+ )
+
+
+# Helper function to convert legacy dict responses to consistent objects
+def convert_dict_response(
+ response_dict: dict[str, Any], response_class: type = APIResponse
+) -> APIResponse | BaseResponse:
+ """Convert legacy dict response to consistent response object.
+
+ This is a migration helper to gradually convert from dict-based responses
+ to consistent response objects.
+
+ Args:
+ response_dict: Legacy dict response
+ response_class: Target response class to convert to
+
+ Returns:
+ Consistent response object
+ """
+ if not isinstance(response_dict, dict):
+ raise ValueError("Expected dict response for conversion")
+
+ success = response_dict.get("success", True)
+
+ if success:
+ if response_class == APIResponse:
+ return APIResponse.success_response(
+ data=response_dict.get("data"),
+ message=response_dict.get("message"),
+ status_code=response_dict.get("status_code", 200),
+ )
+ elif response_class == BatchOperationResponse:
+ return BatchOperationResponse.success_response(
+ successful_items=response_dict.get("successful_items", 0),
+ total_items=response_dict.get("total_items", 0),
+ failed_items=response_dict.get("failed_items", 0),
+ errors=response_dict.get("errors", []),
+ message=response_dict.get("message"),
+ )
+ else:
+ return response_class.success_response(
+ message=response_dict.get("message"),
+ status_code=response_dict.get("status_code", 200),
+ )
+ else:
+ error = (
+ response_dict.get("error")
+ or response_dict.get("error_message")
+ or "Unknown error"
+ )
+ return response_class.error_response(
+ error=error,
+ message=response_dict.get("message"),
+ status_code=response_dict.get("status_code", 400),
+ )
+
+
+__all__ = [
+ "ResponseStatus",
+ "BaseResponse",
+ "APIResponse",
+ "BatchOperationResponse",
+ "ExecutionResponse",
+ "WebhookResponse",
+ "FileOperationResponse",
+ "ConnectorResponse",
+ "convert_dict_response",
+]
diff --git a/workers/shared/enums.py b/workers/shared/enums.py
new file mode 100644
index 000000000..4ffb4430a
--- /dev/null
+++ b/workers/shared/enums.py
@@ -0,0 +1,166 @@
+"""Shared Enums for Worker Services
+
+This module contains enum definitions used across worker services
+to ensure type safety and prevent hardcoded string values.
+"""
+
+from enum import Enum
+
+# Import unified ConnectionType from connectors package
+from unstract.connectors import ConnectionType as UnifiedConnectionType
+
+# AuthorizationType moved to unstract.core.notification_enums to avoid duplication
+# Import from: from unstract.core.notification_enums import AuthorizationType
+
+
+# Re-export for backward compatibility
+ConnectionType = UnifiedConnectionType
+
+
+class EndpointType(Enum):
+ """Endpoint types for workflow configuration."""
+
+ SOURCE = "SOURCE"
+ DESTINATION = "DESTINATION"
+
+ def __str__(self):
+ return self.value
+
+
+class HTTPMethod(Enum):
+ """HTTP methods for API requests."""
+
+ GET = "GET"
+ POST = "POST"
+ PUT = "PUT"
+ PATCH = "PATCH"
+ DELETE = "DELETE"
+ HEAD = "HEAD"
+ OPTIONS = "OPTIONS"
+
+ def __str__(self):
+ return self.value
+
+
+class CircuitBreakerState(Enum):
+ """Circuit breaker states for resilience patterns."""
+
+ CLOSED = "closed"
+ OPEN = "open"
+ HALF_OPEN = "half_open"
+
+ def __str__(self):
+ return self.value
+
+
+class LogLevel(Enum):
+ """Log levels for structured logging."""
+
+ DEBUG = "DEBUG"
+ INFO = "INFO"
+ WARNING = "WARNING"
+ ERROR = "ERROR"
+ CRITICAL = "CRITICAL"
+
+ def __str__(self):
+ return self.value
+
+
+class TaskStatus(Enum):
+ """Task status for asynchronous operations."""
+
+ PENDING = "PENDING"
+ STARTED = "STARTED"
+ SUCCESS = "SUCCESS"
+ FAILURE = "FAILURE"
+ RETRY = "RETRY"
+ REVOKED = "REVOKED"
+
+ def __str__(self):
+ return self.value
+
+
+class FileOperationType(Enum):
+ """File operation types for file processing."""
+
+ UPLOAD = "upload"
+ DOWNLOAD = "download"
+ DELETE = "delete"
+ MOVE = "move"
+ COPY = "copy"
+ LIST = "list"
+
+ def __str__(self):
+ return self.value
+
+
+class ToolOutputType(Enum):
+ """Tool output types for processing results."""
+
+ JSON = "JSON"
+ TXT = "TXT"
+ CSV = "CSV"
+ XML = "XML"
+
+ def __str__(self):
+ return self.value
+
+
+# Note: ExecutionStatus is imported from unstract.core.data_models to maintain consistency
+
+# PipelineType moved to status_enums.py to avoid duplication
+# Import from: from shared.enums import PipelineType
+
+
+class NotificationPlatform(Enum):
+ """Notification platforms for webhook delivery."""
+
+ WEBHOOK = "webhook"
+ EMAIL = "email"
+ SLACK = "slack"
+ TEAMS = "teams"
+
+ def __str__(self):
+ return self.value
+
+
+class BatchOperationType(Enum):
+ """Batch operation types for bulk processing."""
+
+ CREATE = "create"
+ UPDATE = "update"
+ DELETE = "delete"
+ STATUS_UPDATE = "status_update"
+
+ def __str__(self):
+ return self.value
+
+
+# FileDestinationType moved to method_enums.py to avoid duplication
+# Import from: from shared.enums import FileDestinationType
+
+
+class FileHistoryStatus(Enum):
+ """File history status types."""
+
+ SUCCESS = "SUCCESS"
+ ERROR = "ERROR"
+ PARTIAL = "PARTIAL"
+
+ def __str__(self):
+ return self.value
+
+
+# Legacy compatibility mappings
+LEGACY_STATUS_MAPPING = {
+ "INPROGRESS": "EXECUTING",
+ "FAILED": "ERROR",
+ "CANCELED": "STOPPED",
+}
+
+LEGACY_CONNECTION_TYPES = {
+ "APPDEPLOYMENT": "API",
+ "FILESYSTEM": "FILESYSTEM",
+ "DATABASE": "DATABASE",
+ "API": "API",
+}
diff --git a/workers/shared/enums/__init__.py b/workers/shared/enums/__init__.py
new file mode 100644
index 000000000..56e65d136
--- /dev/null
+++ b/workers/shared/enums/__init__.py
@@ -0,0 +1,56 @@
+"""Worker Enumerations
+
+Task names, queue names, and status enums used by workers.
+"""
+
+from .batch_enums import BatchOperationType
+from .file_types import AllowedFileTypes
+from .method_enums import (
+ CircuitBreakerState,
+ ConnectionType,
+ DestinationConfigKey,
+ EndpointType,
+ ErrorType,
+ FileDestinationType,
+ FileOperationType,
+ HTTPMethod,
+ LogLevel,
+ NotificationMethod,
+ NotificationPlatform,
+)
+from .status_enums import (
+ PipelineStatus,
+ PipelineType,
+ QueueResultStatus,
+ TaskStatus,
+ ToolOutputType,
+ WebhookStatus,
+ WorkerTaskStatus,
+)
+from .task_enums import TaskName
+from .worker_enums import QueueName
+
+__all__ = [
+ "TaskName",
+ "QueueName",
+ "WorkerTaskStatus",
+ "PipelineStatus",
+ "PipelineType",
+ "WebhookStatus",
+ "TaskStatus",
+ "ToolOutputType",
+ "NotificationMethod",
+ "BatchOperationType",
+ "AllowedFileTypes",
+ "CircuitBreakerState",
+ "ConnectionType",
+ "DestinationConfigKey",
+ "EndpointType",
+ "ErrorType",
+ "FileDestinationType",
+ "FileOperationType",
+ "HTTPMethod",
+ "LogLevel",
+ "NotificationPlatform",
+ "QueueResultStatus",
+]
diff --git a/workers/shared/enums/batch_enums.py b/workers/shared/enums/batch_enums.py
new file mode 100644
index 000000000..e75856e14
--- /dev/null
+++ b/workers/shared/enums/batch_enums.py
@@ -0,0 +1,19 @@
+"""Batch Operation Enumerations
+
+Enums for batch processing operations.
+"""
+
+from enum import Enum
+
+
+class BatchOperationType(str, Enum):
+ """Types of batch operations."""
+
+ STATUS_UPDATE = "status_update"
+ PIPELINE_UPDATE = "pipeline_update"
+ FILE_STATUS_UPDATE = "file_status_update"
+ WEBHOOK_NOTIFICATION = "webhook_notification"
+
+ def __str__(self):
+ """Return string value for operation type."""
+ return self.value
diff --git a/workers/shared/enums/file_types.py b/workers/shared/enums/file_types.py
new file mode 100644
index 000000000..f49b7880e
--- /dev/null
+++ b/workers/shared/enums/file_types.py
@@ -0,0 +1,120 @@
+"""File type validation enums for worker processing.
+
+This module defines allowed MIME types for file processing, matching the backend's
+validation rules from workflow_manager/endpoint_v2/enums.py.
+"""
+
+from enum import Enum
+from typing import Any
+
+
+class AllowedFileTypes(Enum):
+ """Allowed MIME types for file processing.
+
+ This enum defines all supported file types that can be processed
+ through the workflow system. It mirrors the backend's AllowedFileTypes
+ to ensure consistency across the system.
+ """
+
+ # Text formats
+ PLAIN_TEXT = "text/plain"
+ CSV = "text/csv"
+ JSON = "application/json"
+
+ # Document formats
+ PDF = "application/pdf"
+
+ # Image formats
+ JPEG = "image/jpeg"
+ PNG = "image/png"
+ TIFF = "image/tiff"
+ BMP = "image/bmp"
+ GIF = "image/gif"
+ WEBP = "image/webp"
+
+ # Microsoft Office formats
+ DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
+ DOC = "application/msword"
+ XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
+ XLS = "application/vnd.ms-excel"
+ PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
+ PPT = "application/vnd.ms-powerpoint"
+
+ # OpenDocument formats
+ ODT = "application/vnd.oasis.opendocument.text"
+ ODS = "application/vnd.oasis.opendocument.spreadsheet"
+ ODP = "application/vnd.oasis.opendocument.presentation"
+
+ # Other formats
+ CDFV2 = "application/CDFV2"
+ OCTET_STREAM = "application/octet-stream"
+
+ @classmethod
+ def is_allowed(cls, mime_type: str) -> bool:
+ """Check if a MIME type is allowed for processing.
+
+ Args:
+ mime_type: The MIME type string to validate
+
+ Returns:
+ bool: True if the MIME type is allowed, False otherwise
+ """
+ return mime_type in cls._value2member_map_
+
+
+class FileProcessingOrder(str, Enum):
+ """File processing order for SourceKey.FILE_PROCESSING_ORDER.
+
+ This enum matches exactly with backend/workflow_manager/endpoint_v2/constants.py:FileProcessingOrder
+ to ensure consistent ordering behavior across backend and workers.
+
+ Semantics:
+ - oldest_first: ascending last-modified time (mtime) - FIFO
+ - newest_first: descending mtime - LIFO
+ - unordered: no explicit ordering (OS enumeration order; may be nondeterministic)
+ """
+
+ UNORDERED = "unordered"
+ OLDEST_FIRST = "oldest_first" # FIFO
+ NEWEST_FIRST = "newest_first" # LIFO
+
+ @classmethod
+ def values(cls) -> list[str]:
+ """Get all enum values as a list."""
+ return [v.value for v in cls]
+
+ @classmethod
+ def from_value(
+ cls, value: Any, default: "FileProcessingOrder" = None
+ ) -> "FileProcessingOrder":
+ """Convert a value to FileProcessingOrder enum, with fallback to default.
+
+ Args:
+ value: The value to convert (can be string, enum, or None)
+ default: Default value if conversion fails (defaults to UNORDERED)
+
+ Returns:
+ FileProcessingOrder enum value
+ """
+ if default is None:
+ default = cls.UNORDERED
+
+ if not value:
+ return default
+
+ # Handle string values
+ if isinstance(value, str):
+ try:
+ return cls(value)
+ except ValueError:
+ return default
+
+ # Handle enum values
+ if isinstance(value, cls):
+ return value
+
+ # Handle other types by converting to string
+ try:
+ return cls(str(value))
+ except (ValueError, TypeError):
+ return default
diff --git a/workers/shared/enums/method_enums.py b/workers/shared/enums/method_enums.py
new file mode 100644
index 000000000..86f66d7fc
--- /dev/null
+++ b/workers/shared/enums/method_enums.py
@@ -0,0 +1,151 @@
+"""Method Enumerations
+
+Worker-specific method enums for notifications and processing.
+"""
+
+from enum import Enum
+
+
+class NotificationMethod(str, Enum):
+ """Notification delivery methods."""
+
+ WEBHOOK = "webhook"
+ EMAIL = "email"
+ SLACK = "slack"
+ TEAMS = "teams"
+
+ def __str__(self):
+ """Return enum value for notification routing."""
+ return self.value
+
+
+class CircuitBreakerState(str, Enum):
+ """Circuit breaker states."""
+
+ CLOSED = "CLOSED"
+ OPEN = "OPEN"
+ HALF_OPEN = "HALF_OPEN"
+
+ def __str__(self):
+ return self.value
+
+
+class ConnectionType(str, Enum):
+ """API connection types."""
+
+ HTTP = "HTTP"
+ HTTPS = "HTTPS"
+ WEBSOCKET = "WEBSOCKET"
+
+ def __str__(self):
+ return self.value
+
+
+class EndpointType(str, Enum):
+ """API endpoint types."""
+
+ REST = "REST"
+ GRAPHQL = "GRAPHQL"
+ WEBHOOK = "WEBHOOK"
+
+ def __str__(self):
+ return self.value
+
+
+class FileOperationType(str, Enum):
+ """File operation types."""
+
+ READ = "READ"
+ WRITE = "WRITE"
+ DELETE = "DELETE"
+ COPY = "COPY"
+ MOVE = "MOVE"
+
+ def __str__(self):
+ return self.value
+
+
+class FileDestinationType(str, Enum):
+ """File destination types for workflow processing."""
+
+ DESTINATION = "destination"
+ MANUALREVIEW = "MANUALREVIEW" # Backend uses this exact format
+
+ def __str__(self):
+ return self.value
+
+
+class HTTPMethod(str, Enum):
+ """HTTP methods."""
+
+ GET = "GET"
+ POST = "POST"
+ PUT = "PUT"
+ DELETE = "DELETE"
+ PATCH = "PATCH"
+ HEAD = "HEAD"
+ OPTIONS = "OPTIONS"
+
+ def __str__(self):
+ return self.value
+
+
+class LogLevel(str, Enum):
+ """Logging levels."""
+
+ DEBUG = "DEBUG"
+ INFO = "INFO"
+ WARNING = "WARNING"
+ ERROR = "ERROR"
+ CRITICAL = "CRITICAL"
+
+ def __str__(self):
+ return self.value
+
+
+class NotificationPlatform(str, Enum):
+ """Notification platforms."""
+
+ SLACK = "SLACK"
+ DISCORD = "DISCORD"
+ TEAMS = "TEAMS"
+ EMAIL = "EMAIL"
+
+ def __str__(self):
+ return self.value
+
+
+# AuthorizationType moved to unstract.core.notification_enums to avoid duplication
+# Import from: from unstract.core.notification_enums import AuthorizationType
+
+
+class ErrorType(str, Enum):
+ """File processing error types."""
+
+ WORKFLOW_ERROR = "Workflow error"
+ DESTINATION_ERROR = "Destination error"
+ PROCESSING_ERROR = "Processing error"
+ VALIDATION_ERROR = "Validation error"
+
+ def __str__(self):
+ return self.value
+
+
+class DestinationConfigKey(str, Enum):
+ """Destination configuration keys for API response parsing.
+
+ Prevents camelCase vs snake_case mismatches between backend API
+ responses and worker parsing logic. This mirrors backend's
+ DestinationKey class but is accessible to workers.
+ """
+
+ # Connector settings keys (snake_case from connector configuration)
+ PATH = "path"
+ BUCKET = "bucket"
+ CONTAINER = "container"
+
+ # Destination settings keys (camelCase from API response)
+ OUTPUT_FOLDER = "outputFolder" # Backend API returns camelCase
+
+ def __str__(self):
+ return self.value
diff --git a/workers/shared/enums/status_enums.py b/workers/shared/enums/status_enums.py
new file mode 100644
index 000000000..e20b6d29d
--- /dev/null
+++ b/workers/shared/enums/status_enums.py
@@ -0,0 +1,145 @@
+"""Status Enumerations
+
+Worker-specific status enums for tasks, pipelines, and webhooks.
+"""
+
+from enum import Enum
+
+
+class FileProcessingStatus(str, Enum):
+ """File processing status to be used in destination database."""
+
+ SUCCESS = "SUCCESS"
+ ERROR = "ERROR"
+
+
+class WorkerTaskStatus(str, Enum):
+ """Task execution status for workers."""
+
+ PENDING = "PENDING"
+ STARTED = "STARTED"
+ RETRY = "RETRY"
+ FAILURE = "FAILURE"
+ SUCCESS = "SUCCESS"
+ REVOKED = "REVOKED"
+
+ def __str__(self):
+ """Return enum value for Celery status comparison."""
+ return self.value
+
+
+class PipelineStatus(str, Enum):
+ """Pipeline execution status mapping."""
+
+ SUCCESS = "SUCCESS"
+ FAILURE = "FAILURE"
+ INPROGRESS = "INPROGRESS"
+ YET_TO_START = "YET_TO_START"
+ PARTIAL_SUCCESS = "PARTIAL_SUCCESS"
+ RESTARTING = "RESTARTING"
+ PAUSED = "PAUSED"
+
+ def __str__(self):
+ """Return enum value for API updates."""
+ return self.value
+
+ @classmethod
+ def is_completion_status(cls, status: str) -> bool:
+ """Check if a pipeline status represents a completion state.
+
+ Completion states are final states that should trigger last_run_time updates.
+
+ Args:
+ status: Status string to check
+
+ Returns:
+ True if status is a completion state
+ """
+ # Pipeline completion states - these are final states
+ completion_statuses = {
+ cls.SUCCESS.value,
+ cls.FAILURE.value,
+ cls.PARTIAL_SUCCESS.value, # Also a completion state with mixed results
+ }
+
+ # Check if the status (uppercased) matches any completion status
+ status_upper = status.upper()
+ return status_upper in completion_statuses
+
+
+class PipelineType(str, Enum):
+ """Pipeline types for workflows."""
+
+ ETL = "ETL"
+ TASK = "TASK"
+ API = "API"
+ APP = "APP"
+ DEFAULT = "DEFAULT"
+
+ def __str__(self):
+ return self.value
+
+
+class WebhookStatus(str, Enum):
+ """Webhook delivery status."""
+
+ DELIVERED = "delivered"
+ QUEUED = "queued"
+ FAILED = "failed"
+ TIMEOUT = "timeout"
+ RETRY = "retry"
+
+ def __str__(self):
+ """Return enum value for webhook tracking."""
+ return self.value
+
+
+class TaskStatus(str, Enum):
+ """Generic task status."""
+
+ PENDING = "pending"
+ RUNNING = "running"
+ COMPLETED = "completed"
+ SUCCESS = "success" # Alias for completed
+ FAILED = "failed"
+ CANCELLED = "cancelled"
+ RETRYING = "retrying"
+
+ def __str__(self):
+ return self.value
+
+ @classmethod
+ def is_completion_status(cls, status: str) -> bool:
+ """Check if a status represents a completion state.
+
+ Args:
+ status: Status string to check
+
+ Returns:
+ True if status is a completion state
+ """
+ completion_statuses = {
+ cls.COMPLETED.value.upper(),
+ cls.SUCCESS.value.upper(),
+ cls.FAILED.value.upper(),
+ cls.CANCELLED.value.upper(),
+ }
+ return status.upper() in completion_statuses
+
+
+class ToolOutputType(str, Enum):
+ """Tool output types."""
+
+ TEXT = "text"
+ JSON = "json"
+ XML = "xml"
+ BINARY = "binary"
+ IMAGE = "image"
+
+ def __str__(self):
+ return self.value
+
+
+class QueueResultStatus(Enum):
+ SUCCESS = "success"
+ FAILURE = "failure"
diff --git a/workers/shared/enums/task_enums.py b/workers/shared/enums/task_enums.py
new file mode 100644
index 000000000..5f57913cd
--- /dev/null
+++ b/workers/shared/enums/task_enums.py
@@ -0,0 +1,38 @@
+"""Task and Queue Enumerations
+
+Worker-specific task names and queue names.
+"""
+
+from enum import Enum
+
+
+class TaskName(str, Enum):
+ """Standardized task names across all workers."""
+
+ # General worker tasks
+ SEND_WEBHOOK_NOTIFICATION = "send_webhook_notification"
+ ASYNC_EXECUTE_BIN_GENERAL = "async_execute_bin_general"
+ EXECUTE_WORKFLOW_WITH_FILES = "execute_workflow_with_files"
+ ORCHESTRATE_FILE_PROCESSING = "_orchestrate_file_processing_general"
+
+ # API deployment worker tasks
+ ASYNC_EXECUTE_BIN_API = "async_execute_bin_api"
+ ASYNC_EXECUTE_BIN = "async_execute_bin"
+
+ # File processing worker tasks
+ PROCESS_FILE_BATCH = "process_file_batch"
+ PROCESS_FILE_BATCH_API = "process_file_batch_api"
+ EXECUTE_SINGLE_FILE = "execute_single_file"
+ UPDATE_FILE_EXECUTION_STATUS = "update_file_execution_status"
+
+ # Callback worker tasks
+ PROCESS_BATCH_CALLBACK = "process_batch_callback"
+ UPDATE_WORKFLOW_EXECUTION_STATUS = "update_workflow_execution_status"
+ UPDATE_PIPELINE_STATUS = "update_pipeline_status"
+
+ # API deployment worker tasks
+ CHECK_API_DEPLOYMENT_STATUS = "check_api_deployment_status"
+
+ def __str__(self):
+ """Return enum value for Celery task naming."""
+ return self.value
diff --git a/workers/shared/enums/worker_enums.py b/workers/shared/enums/worker_enums.py
new file mode 100644
index 000000000..0f6d7bb32
--- /dev/null
+++ b/workers/shared/enums/worker_enums.py
@@ -0,0 +1,167 @@
+"""Worker Type and Queue Name Enumerations
+
+This module provides centralized enums for worker types and queue names,
+ensuring type safety and preventing hardcoded string errors.
+
+Migration Note: This is part of the worker refactoring to reduce duplication
+and improve maintainability. All workers should use these enums instead of
+hardcoded strings.
+"""
+
+from enum import Enum
+from typing import Optional
+
+
+class WorkerType(str, Enum):
+ """Worker types matching actual worker implementations.
+
+ Values match Python module names (underscores, not hyphens).
+ Directory names may differ (e.g., api-deployment vs api_deployment).
+ """
+
+ API_DEPLOYMENT = "api_deployment"
+ GENERAL = "general"
+ FILE_PROCESSING = "file_processing"
+ CALLBACK = "callback"
+ NOTIFICATION = "notification"
+ LOG_CONSUMER = "log_consumer"
+ SCHEDULER = "scheduler"
+
+ @classmethod
+ def from_directory_name(cls, name: str) -> "WorkerType":
+ """Convert directory name to enum value.
+
+ Args:
+ name: Directory name (e.g., 'api-deployment', 'file_processing')
+
+ Returns:
+ Corresponding WorkerType enum
+
+ Example:
+ >>> WorkerType.from_directory_name("api-deployment")
+ <WorkerType.API_DEPLOYMENT: 'api_deployment'>
+ """
+ normalized = name.replace("-", "_")
+ return cls(normalized)
+
+ def to_import_path(self) -> str:
+ """Return standardized Python import path for tasks module.
+
+ Returns:
+ Import path string (e.g., 'api-deployment.tasks')
+
+ Note:
+ Handles the directory naming convention where some workers
+ use hyphens in directory names but underscores in Python modules.
+ """
+ # Map to actual directory structure
+ directory_mapping = {
+ "api_deployment": "api-deployment",
+ # All others use same name for directory and module
+ }
+ directory = directory_mapping.get(self.value, self.value)
+ return f"{directory}.tasks"
+
+ def to_worker_name(self) -> str:
+ """Return human-readable worker name for logging.
+
+ Returns:
+ Worker name (e.g., 'api-deployment-worker')
+ """
+ return f"{self.value.replace('_', '-')}-worker"
+
+ def to_health_port(self) -> int:
+ """Return health check port for this worker.
+
+ Checks environment variable first, then falls back to defaults.
+
+ Returns:
+ Port number for health server
+ """
+ import os
+
+ # Check for environment variable first
+ env_var = f"{self.name}_HEALTH_PORT"
+ if env_port := os.getenv(env_var):
+ try:
+ return int(env_port)
+ except ValueError:
+ pass # Fall back to default
+
+ # Default port mapping
+ port_mapping = {
+ WorkerType.API_DEPLOYMENT: 8080,
+ WorkerType.GENERAL: 8081,
+ WorkerType.FILE_PROCESSING: 8082,
+ WorkerType.CALLBACK: 8083,
+ WorkerType.NOTIFICATION: 8085,
+ WorkerType.LOG_CONSUMER: 8086,
+ WorkerType.SCHEDULER: 8087,
+ }
+ return port_mapping.get(self, 8080)
+
+
+class QueueName(str, Enum):
+ """Standard queue names used across the platform.
+
+ These match the actual queue names in RabbitMQ/Redis.
+ Using enums prevents typos and makes refactoring easier.
+ """
+
+ # Core queues
+ API_DEPLOYMENTS = "celery_api_deployments"
+ GENERAL = "celery" # Default Celery queue
+
+ # File processing queues
+ FILE_PROCESSING = "file_processing"
+ FILE_PROCESSING_API = "api_file_processing"
+
+ # Callback queues
+ CALLBACK = "file_processing_callback"
+ CALLBACK_API = "api_file_processing_callback"
+
+ # Notification queues
+ NOTIFICATION = "notifications"
+ NOTIFICATION_WEBHOOK = "notifications_webhook"
+ NOTIFICATION_EMAIL = "notifications_email"
+ NOTIFICATION_SMS = "notifications_sms"
+ NOTIFICATION_PRIORITY = "notifications_priority"
+
+ # Log processing queues
+ LOG_CONSUMER = "celery_log_task_queue"
+ PERIODIC_LOGS = "celery_periodic_logs"
+
+ # Scheduler queue
+ SCHEDULER = "scheduler"
+
+ def to_env_var_name(self) -> str:
+ """Convert queue name to environment variable name.
+
+ Returns:
+ Environment variable name (e.g., 'CELERY_API_DEPLOYMENTS_QUEUE')
+ """
+ return f"{self.value.upper().replace('-', '_')}_QUEUE"
+
+ @classmethod
+ def from_string(cls, queue_name: str) -> Optional["QueueName"]:
+ """Safe conversion from string to QueueName enum.
+
+ Args:
+ queue_name: Queue name string
+
+ Returns:
+ QueueName enum or None if not found
+ """
+ for queue in cls:
+ if queue.value == queue_name:
+ return queue
+ return None
+
+
+class WorkerStatus(str, Enum):
+ """Worker migration status for tracking."""
+
+ NOT_MIGRATED = "not_migrated"
+ IN_PROGRESS = "in_progress"
+ MIGRATED = "migrated"
+ VALIDATED = "validated"
diff --git a/workers/shared/exceptions.py b/workers/shared/exceptions.py
new file mode 100644
index 000000000..fe7566bcd
--- /dev/null
+++ b/workers/shared/exceptions.py
@@ -0,0 +1,209 @@
+"""Worker-Specific Exceptions
+
+This module provides worker-specific exceptions that mirror the backend endpoint exceptions
+for consistent error handling between backend API endpoints and worker operations.
+
+These exceptions are designed to be raised by workers and handled by the task execution
+system for proper error reporting and debugging.
+"""
+
+
+class WorkerError(Exception):
+ """Base exception for all worker-related errors."""
+
+ def __init__(self, message: str, details: str = None):
+ self.message = message
+ self.details = details
+ super().__init__(message)
+
+ def __str__(self):
+ if self.details:
+ return f"{self.message}. Details: {self.details}"
+ return self.message
+
+
+class ConnectorError(WorkerError):
+ """Base exception for connector-related errors."""
+
+ pass
+
+
+class ConnectorNotAvailableError(ConnectorError):
+ """Raised when connector packages/modules are not available in worker environment."""
+
+ def __init__(self, connector_type: str = None, import_error: str = None):
+ if connector_type:
+ message = f"Connector type '{connector_type}' is not available in worker environment"
+ else:
+ message = "Connector packages are not available in worker environment"
+
+ details = f"Import error: {import_error}" if import_error else None
+ super().__init__(message, details)
+
+
+class InvalidSourceConnectionType(ConnectorError):
+ """Raised when the provided source connection type is invalid."""
+
+ def __init__(self, connection_type: str = None, valid_types: list = None):
+ if connection_type:
+ message = f"Invalid source connection type: '{connection_type}'"
+ if valid_types:
+ message += f". Valid types: {valid_types}"
+ else:
+ message = "The provided source connection type is invalid"
+ super().__init__(message)
+
+
+class MissingSourceConnectionType(ConnectorError):
+ """Raised when the source connection type is missing."""
+
+ def __init__(self):
+ super().__init__(
+ "The source connection type is missing from source configuration"
+ )
+
+
+class SourceConnectorNotConfigured(ConnectorError):
+ """Raised when the source connector is not properly configured."""
+
+ def __init__(self, connector_id: str = None):
+ if connector_id:
+ message = f"Source connector '{connector_id}' is not properly configured"
+ else:
+ message = "The source connector is not configured"
+ super().__init__(message)
+
+
+class ConnectorConnectionError(ConnectorError):
+ """Raised when unable to connect to the source connector."""
+
+ def __init__(self, connector_id: str, connection_details: str = None):
+ message = f"Failed to connect to source connector '{connector_id}'"
+ super().__init__(message, connection_details)
+
+
+class InvalidInputDirectory(ConnectorError):
+ """Raised when the provided directory path is not valid or accessible."""
+
+ def __init__(self, directory: str = None, reason: str = None):
+ if directory:
+ message = f"Invalid input directory: '{directory}'"
+ else:
+ message = "The provided path is not a valid directory"
+ super().__init__(message, reason)
+
+
+class SourceFileListingError(ConnectorError):
+ """Raised when file listing from source connector fails."""
+
+ def __init__(self, connector_id: str, error_details: str = None):
+ message = f"Failed to list files from source connector '{connector_id}'"
+ super().__init__(message, error_details)
+
+
+class UnsupportedConnectorType(ConnectorError):
+ """Raised when the connector type is not supported by the worker."""
+
+ def __init__(self, connector_id: str, available_connectors: list = None):
+ message = f"Connector '{connector_id}' is not supported"
+ details = None
+ if available_connectors:
+ details = f"Available connectors: {available_connectors}"
+ super().__init__(message, details)
+
+
+class ConnectorConfigurationError(ConnectorError):
+ """Raised when connector configuration is invalid or incomplete."""
+
+ def __init__(
+ self, connector_id: str, missing_fields: list = None, invalid_values: dict = None
+ ):
+ message = f"Invalid configuration for connector '{connector_id}'"
+
+ details_parts = []
+ if missing_fields:
+ details_parts.append(f"Missing required fields: {missing_fields}")
+ if invalid_values:
+ details_parts.append(f"Invalid values: {invalid_values}")
+
+ details = "; ".join(details_parts) if details_parts else None
+ super().__init__(message, details)
+
+
+class WorkflowSourceError(WorkerError):
+ """Base exception for workflow source-related errors."""
+
+ pass
+
+
+class WorkflowNotFound(WorkflowSourceError):
+ """Raised when workflow is not found or not accessible."""
+
+ def __init__(self, workflow_id: str, organization_id: str = None):
+ message = f"Workflow '{workflow_id}' not found"
+ details = f"Organization: {organization_id}" if organization_id else None
+ super().__init__(message, details)
+
+
+class SourceConfigurationNotFound(WorkflowSourceError):
+ """Raised when workflow source configuration is missing."""
+
+ def __init__(self, workflow_id: str):
+ message = f"Source configuration not found for workflow '{workflow_id}'"
+ super().__init__(message)
+
+
+class InvalidSourceConfiguration(WorkflowSourceError):
+ """Raised when workflow source configuration is invalid."""
+
+ def __init__(self, workflow_id: str, validation_errors: list = None):
+ message = f"Invalid source configuration for workflow '{workflow_id}'"
+ details = f"Validation errors: {validation_errors}" if validation_errors else None
+ super().__init__(message, details)
+
+
+class OrganizationContextError(WorkerError):
+ """Raised when organization context is missing or invalid."""
+
+ def __init__(self, organization_id: str = None):
+ if organization_id:
+ message = f"Invalid organization context: '{organization_id}'"
+ else:
+ message = "Organization context is missing or not accessible"
+ super().__init__(message)
+
+
+class WorkerExecutionError(WorkerError):
+ """Raised when worker execution setup or execution fails."""
+
+ def __init__(self, message: str, execution_id: str = None, details: str = None):
+ self.execution_id = execution_id
+ if execution_id:
+ message = f"Execution {execution_id}: {message}"
+ super().__init__(message, details)
+
+
+# Exception mapping for converting backend exceptions to worker exceptions
+BACKEND_TO_WORKER_EXCEPTION_MAP = {
+ "InvalidInputDirectory": InvalidInputDirectory,
+ "InvalidSourceConnectionType": InvalidSourceConnectionType,
+ "MissingSourceConnectionType": MissingSourceConnectionType,
+ "SourceConnectorNotConfigured": SourceConnectorNotConfigured,
+ "OrganizationIdNotFound": OrganizationContextError,
+}
+
+
+def map_backend_exception(backend_exception_name: str, *args, **kwargs) -> WorkerError:
+ """Map a backend exception name to the corresponding worker exception.
+
+ Args:
+ backend_exception_name: Name of the backend exception class
+ *args, **kwargs: Arguments to pass to the worker exception constructor
+
+ Returns:
+ WorkerError instance
+ """
+ worker_exception_class = BACKEND_TO_WORKER_EXCEPTION_MAP.get(
+ backend_exception_name, WorkerError
+ )
+ return worker_exception_class(*args, **kwargs)
diff --git a/workers/shared/exceptions/__init__.py b/workers/shared/exceptions/__init__.py
new file mode 100644
index 000000000..9029b6f28
--- /dev/null
+++ b/workers/shared/exceptions/__init__.py
@@ -0,0 +1,20 @@
+"""Worker Exception Classes
+
+Common exceptions used across worker implementations.
+"""
+
+from .execution_exceptions import (
+ ExecutionException,
+ NotFoundDestinationConfiguration,
+ NotFoundSourceConfiguration,
+)
+from .file_exceptions import EmptyFileError, FileProcessingError, UnsupportedMimeTypeError
+
+__all__ = [
+ "NotFoundDestinationConfiguration",
+ "NotFoundSourceConfiguration",
+ "ExecutionException",
+ "UnsupportedMimeTypeError",
+ "FileProcessingError",
+ "EmptyFileError",
+]
diff --git a/workers/shared/exceptions/execution_exceptions.py b/workers/shared/exceptions/execution_exceptions.py
new file mode 100644
index 000000000..922b9c92a
--- /dev/null
+++ b/workers/shared/exceptions/execution_exceptions.py
@@ -0,0 +1,22 @@
+class NotFoundDestinationConfiguration(Exception):
+ """Exception raised when destination configuration is not found."""
+
+ def __init__(self, message="Destination configuration not found"):
+ self.message = message
+ super().__init__(self.message)
+
+
+class NotFoundSourceConfiguration(Exception):
+ """Exception raised when source configuration is not found."""
+
+ def __init__(self, message="Source configuration not found"):
+ self.message = message
+ super().__init__(self.message)
+
+
+class ExecutionException(Exception):
+ """Exception raised when execution fails."""
+
+ def __init__(self, message="Execution failed"):
+ self.message = message
+ super().__init__(self.message)
diff --git a/workers/shared/exceptions/file_exceptions.py b/workers/shared/exceptions/file_exceptions.py
new file mode 100644
index 000000000..ab657e041
--- /dev/null
+++ b/workers/shared/exceptions/file_exceptions.py
@@ -0,0 +1,58 @@
+"""File processing exception classes for workers.
+
+This module defines exceptions related to file processing operations,
+matching the backend's exception patterns.
+"""
+
+
+class UnsupportedMimeTypeError(Exception):
+ """Exception raised when a file's MIME type is not supported.
+
+ This exception is raised during file processing when a file's
+ detected MIME type is not in the list of allowed types.
+ """
+
+ def __init__(self, message: str = "Unsupported MIME type"):
+ """Initialize the exception with an error message.
+
+ Args:
+ message: Descriptive error message about the unsupported MIME type
+ """
+ self.message = message
+ super().__init__(self.message)
+
+
+class FileProcessingError(Exception):
+ """Base exception class for file processing errors.
+
+ This can be used as a base class for other file-related exceptions
+ or raised directly for generic file processing issues.
+ """
+
+ def __init__(self, message: str = "File processing error occurred"):
+ """Initialize the exception with an error message.
+
+ Args:
+ message: Descriptive error message about the file processing error
+ """
+ self.message = message
+ super().__init__(self.message)
+
+
+class EmptyFileError(FileProcessingError):
+ """Exception raised when a file is empty (0 bytes).
+
+ Empty files cannot be processed through workflows as they contain
+ no meaningful content. This exception is raised to fail fast and
+ provide clear feedback to users.
+ """
+
+ def __init__(self, file_path: str):
+ """Initialize the exception with the empty file path.
+
+ Args:
+ file_path: Path to the empty file that caused the error
+ """
+ message = f"File is empty (0 bytes): {file_path}"
+ super().__init__(message)
+ self.file_path = file_path
diff --git a/workers/shared/infrastructure/__init__.py b/workers/shared/infrastructure/__init__.py
new file mode 100644
index 000000000..45101092e
--- /dev/null
+++ b/workers/shared/infrastructure/__init__.py
@@ -0,0 +1,42 @@
+"""Infrastructure components for workers.
+
+This package provides all infrastructure-related functionality including
+configuration, logging, monitoring, and database utilities.
+"""
+
+from .caching import * # noqa: F403
+from .config import * # noqa: F403
+from .database import * # noqa: F403
+from .logging import * # noqa: F403
+from .monitoring import * # noqa: F403
+from .worker_singleton import * # noqa: F403
+
+__all__ = [
+ # Caching
+ "WorkerCacheManager",
+ "get_cache_manager",
+ "initialize_cache_manager",
+ # Configuration
+ "WorkerBuilder",
+ "WorkerRegistry",
+ "WorkerConfig",
+ # Logging
+ "helpers",
+ "WorkerLogger",
+ "log_context",
+ "monitor_performance",
+ "with_execution_context",
+ "WorkerWorkflowLogger",
+ # Monitoring
+ "HealthChecker",
+ "HealthServer",
+ # Database
+ "DatabaseUtils",
+ # Worker Infrastructure Factory
+ "WorkerInfrastructure",
+ "get_worker_infrastructure",
+ "create_api_client",
+ "initialize_worker_infrastructure",
+ "get_worker_config",
+ "worker_infrastructure_health_check",
+]
diff --git a/workers/shared/infrastructure/caching/__init__.py b/workers/shared/infrastructure/caching/__init__.py
new file mode 100644
index 000000000..e3a807731
--- /dev/null
+++ b/workers/shared/infrastructure/caching/__init__.py
@@ -0,0 +1,20 @@
+"""Caching infrastructure for workers.
+
+This package provides caching utilities and cache management
+functionality for worker performance optimization.
+"""
+
+# Import from the existing cache directory
+from ...cache import CachedAPIClientMixin, with_cache
+from ...cache.cache_types import CacheType
+from .cache_utils import WorkerCacheManager, get_cache_manager, initialize_cache_manager
+
+__all__ = [
+ "WorkerCacheManager",
+ "get_cache_manager",
+ "initialize_cache_manager",
+ # From cache subdirectory
+ "CachedAPIClientMixin",
+ "with_cache",
+ "CacheType",
+]
diff --git a/workers/shared/infrastructure/caching/cache_utils.py b/workers/shared/infrastructure/caching/cache_utils.py
new file mode 100644
index 000000000..3d85db4d3
--- /dev/null
+++ b/workers/shared/infrastructure/caching/cache_utils.py
@@ -0,0 +1,582 @@
+"""Redis Cache Utilities for Workers
+
+Provides caching mechanisms to reduce database queries and improve performance.
+Specifically optimized for callback pattern performance optimizations.
+"""
+
+import json
+import logging
+import time
+
+import redis
+from shared.infrastructure.config import WorkerConfig
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerCacheManager:
+ """Redis cache manager for worker performance optimization."""
+
+ def __init__(self, config: WorkerConfig):
+ """Initialize cache manager with worker configuration.
+
+ Args:
+ config: Worker configuration containing Redis settings
+ """
+ self.config = config
+ self._redis_client = None
+ self._last_connection_time = 0
+ self._connection_id = None
+ self._initialize_redis_client()
+
+ def _initialize_redis_client(self):
+ """Initialize Redis client from cache-specific configuration."""
+ try:
+ # Get cache-specific Redis configuration
+ cache_config = self.config.get_cache_redis_config()
+
+ if not cache_config.get("enabled"):
+ logger.info("Redis cache disabled via configuration")
+ return
+
+ # Use direct cache Redis configuration (not Celery broker)
+ redis_kwargs = {
+ "host": cache_config["host"],
+ "port": cache_config["port"],
+ "db": cache_config["db"],
+ "decode_responses": True,
+ "socket_connect_timeout": 5,
+ "socket_timeout": 5,
+ "health_check_interval": 30,
+ }
+
+ # Add authentication if configured
+ if cache_config.get("password"):
+ redis_kwargs["password"] = cache_config["password"]
+ if cache_config.get("username"):
+ redis_kwargs["username"] = cache_config["username"]
+
+ # Add SSL configuration if enabled
+ if cache_config.get("ssl"):
+ redis_kwargs["ssl"] = True
+ redis_kwargs["ssl_cert_reqs"] = self.config.cache_redis_ssl_cert_reqs
+
+ self._redis_client = redis.Redis(**redis_kwargs)
+
+ # Test connection
+ self._redis_client.ping()
+ self._last_connection_time = time.time()
+ # Create unique connection ID to detect reconnections
+ self._connection_id = f"cache_conn_{int(self._last_connection_time)}"
+ logger.info(
+ f"Redis cache initialized: {cache_config['host']}:{cache_config['port']}/{cache_config['db']}"
+ )
+
+ except Exception as e:
+ logger.warning(f"Failed to initialize Redis cache: {e}. Cache disabled.")
+ self._redis_client = None
+ self._connection_id = None
+
+ @property
+ def is_available(self) -> bool:
+ """Check if Redis cache is available and detect reconnections."""
+ if not self._redis_client:
+ return False
+ try:
+ self._redis_client.ping()
+ current_time = time.time()
+
+ # Check if connection was lost and restored (potential stale data)
+ if current_time - self._last_connection_time > 120: # 2 minutes gap
+ logger.warning(
+ "Redis connection gap detected, clearing potentially stale cache"
+ )
+ self._clear_all_cache()
+ self._last_connection_time = current_time
+ # Update connection ID to mark new session
+ self._connection_id = f"cache_conn_{int(current_time)}"
+
+ return True
+ except Exception:
+ return False
+
+ def _clear_all_cache(self):
+ """Clear all cache data to prevent stale data after reconnection."""
+ if not self._redis_client:
+ return
+
+ try:
+ # Find all cache keys with our patterns
+ patterns = [
+ "exec_status:*",
+ "pipeline_status:*",
+ "batch_summary:*",
+ "callback_attempts:*",
+ "backoff_attempts:*",
+ "circuit_breaker:*",
+ ]
+
+ keys_to_delete = []
+ for pattern in patterns:
+ keys = self._redis_client.keys(pattern)
+ keys_to_delete.extend(keys)
+
+ if keys_to_delete:
+ self._redis_client.delete(*keys_to_delete)
+ logger.info(f"Cleared {len(keys_to_delete)} potentially stale cache keys")
+
+ except Exception as e:
+ logger.warning(f"Failed to clear cache after reconnection: {e}")
+
+ def _is_cache_data_valid(self, cache_data: dict) -> bool:
+ """Validate cache data to detect staleness after reconnection.
+
+ Args:
+ cache_data: Cached data dictionary
+
+ Returns:
+ True if cache data is valid and not stale
+ """
+ if not isinstance(cache_data, dict):
+ return False
+
+ # Check if data has connection ID (new feature)
+ data_connection_id = cache_data.get("connection_id")
+ if data_connection_id and data_connection_id != self._connection_id:
+ logger.debug("Cache data from previous connection, treating as stale")
+ return False
+
+ # Check timestamp-based expiration
+ cached_at = cache_data.get("cached_at", 0)
+ if time.time() - cached_at > 300: # 5 minutes absolute max
+ logger.debug("Cache data too old, treating as stale")
+ return False
+
+ return True
+
+ def get_execution_status(
+ self, execution_id: str, organization_id: str
+ ) -> dict | None:
+ """Get cached execution status.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+
+ Returns:
+ Cached status data or None if not found/expired
+ """
+ if not self.is_available:
+ return None
+
+ try:
+ cache_key = f"exec_status:{organization_id}:{execution_id}"
+ cached_data = self._redis_client.get(cache_key)
+
+ if cached_data:
+ data = json.loads(cached_data)
+
+ # Validate cache data for staleness
+ if self._is_cache_data_valid(data):
+ # Check if cache is fresh (within 30 seconds)
+ if time.time() - data.get("cached_at", 0) < 30:
+ logger.debug(f"Cache hit for execution {execution_id}")
+ return data.get("status_data")
+
+ # Remove expired or stale cache
+ self._redis_client.delete(cache_key)
+ logger.debug(f"Removed stale/expired cache for execution {execution_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache get error for execution {execution_id}: {e}")
+
+ return None
+
+ def set_execution_status(
+ self, execution_id: str, organization_id: str, status_data: dict, ttl: int = 60
+ ):
+ """Cache execution status data.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+ status_data: Status data to cache
+ ttl: Time-to-live in seconds
+ """
+ if not self.is_available:
+ return
+
+ try:
+ cache_key = f"exec_status:{organization_id}:{execution_id}"
+ cache_data = {
+ "status_data": status_data,
+ "cached_at": time.time(),
+ "connection_id": self._connection_id, # Track which connection created this cache
+ }
+
+ self._redis_client.setex(cache_key, ttl, json.dumps(cache_data))
+ logger.debug(f"Cached execution status for {execution_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache set error for execution {execution_id}: {e}")
+
+ def invalidate_execution_status(self, execution_id: str, organization_id: str):
+ """Invalidate cached execution status.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+ """
+ if not self.is_available:
+ return
+
+ try:
+ cache_key = f"exec_status:{organization_id}:{execution_id}"
+ self._redis_client.delete(cache_key)
+ logger.debug(f"Invalidated cache for execution {execution_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache invalidation error for execution {execution_id}: {e}")
+
+ def get_pipeline_status(self, pipeline_id: str, organization_id: str) -> dict | None:
+ """Get cached pipeline status.
+
+ Args:
+ pipeline_id: Pipeline ID
+ organization_id: Organization context
+
+ Returns:
+ Cached pipeline data or None if not found/expired
+ """
+ if not self.is_available:
+ return None
+
+ try:
+ cache_key = f"pipeline_status:{organization_id}:{pipeline_id}"
+ cached_data = self._redis_client.get(cache_key)
+
+ if cached_data:
+ data = json.loads(cached_data)
+
+ # Validate cache data for staleness
+ if self._is_cache_data_valid(data):
+ # Check if cache is fresh (within 60 seconds for pipelines)
+ if time.time() - data.get("cached_at", 0) < 60:
+ logger.debug(f"Cache hit for pipeline {pipeline_id}")
+ return data.get("pipeline_data")
+
+ # Remove expired or stale cache
+ self._redis_client.delete(cache_key)
+ logger.debug(f"Removed stale/expired cache for pipeline {pipeline_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache get error for pipeline {pipeline_id}: {e}")
+
+ return None
+
+ def set_pipeline_status(
+ self, pipeline_id: str, organization_id: str, pipeline_data: dict, ttl: int = 120
+ ):
+ """Cache pipeline status data.
+
+ Args:
+ pipeline_id: Pipeline ID
+ organization_id: Organization context
+ pipeline_data: Pipeline data to cache
+ ttl: Time-to-live in seconds
+ """
+ if not self.is_available:
+ return
+
+ try:
+ cache_key = f"pipeline_status:{organization_id}:{pipeline_id}"
+ cache_data = {
+ "pipeline_data": pipeline_data,
+ "cached_at": time.time(),
+ "connection_id": self._connection_id, # Track which connection created this cache
+ }
+
+ self._redis_client.setex(cache_key, ttl, json.dumps(cache_data))
+ logger.debug(f"Cached pipeline status for {pipeline_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache set error for pipeline {pipeline_id}: {e}")
+
+ def invalidate_pipeline_status(self, pipeline_id: str, organization_id: str):
+ """Invalidate cached pipeline status.
+
+ Args:
+ pipeline_id: Pipeline ID
+ organization_id: Organization context
+ """
+ if not self.is_available:
+ return
+
+ try:
+ cache_key = f"pipeline_status:{organization_id}:{pipeline_id}"
+ self._redis_client.delete(cache_key)
+ logger.debug(f"Invalidated pipeline cache for {pipeline_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache invalidation error for pipeline {pipeline_id}: {e}")
+
+ def get_batch_status_summary(
+ self, execution_id: str, organization_id: str
+ ) -> dict | None:
+ """Get cached batch processing summary.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+
+ Returns:
+ Cached batch summary or None if not found/expired
+ """
+ if not self.is_available:
+ return None
+
+ try:
+ cache_key = f"batch_summary:{organization_id}:{execution_id}"
+ cached_data = self._redis_client.get(cache_key)
+
+ if cached_data:
+ data = json.loads(cached_data)
+
+ # Validate cache data for staleness
+ if self._is_cache_data_valid(data):
+ # Batch summaries are fresh for 45 seconds
+ if time.time() - data.get("cached_at", 0) < 45:
+ logger.debug(f"Cache hit for batch summary {execution_id}")
+ return data.get("summary_data")
+
+ # Remove expired or stale cache
+ self._redis_client.delete(cache_key)
+ logger.debug(
+ f"Removed stale/expired cache for batch summary {execution_id}"
+ )
+
+ except Exception as e:
+ logger.warning(f"Cache get error for batch summary {execution_id}: {e}")
+
+ return None
+
+ def set_batch_status_summary(
+ self, execution_id: str, organization_id: str, summary_data: dict, ttl: int = 90
+ ):
+ """Cache batch processing summary.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+ summary_data: Batch summary data to cache
+ ttl: Time-to-live in seconds
+ """
+ if not self.is_available:
+ return
+
+ try:
+ cache_key = f"batch_summary:{organization_id}:{execution_id}"
+ cache_data = {
+ "summary_data": summary_data,
+ "cached_at": time.time(),
+ "connection_id": self._connection_id, # Track which connection created this cache
+ }
+
+ self._redis_client.setex(cache_key, ttl, json.dumps(cache_data))
+ logger.debug(f"Cached batch summary for {execution_id}")
+
+ except Exception as e:
+ logger.warning(f"Cache set error for batch summary {execution_id}: {e}")
+
+ def increment_callback_attempt(self, execution_id: str, organization_id: str) -> int:
+ """Increment and get callback attempt counter.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+
+ Returns:
+ Current attempt count
+ """
+ if not self.is_available:
+ return 1
+
+ try:
+ cache_key = f"callback_attempts:{organization_id}:{execution_id}"
+ current_attempts = self._redis_client.incr(cache_key)
+
+ # Set expiration on first increment
+ if current_attempts == 1:
+ self._redis_client.expire(cache_key, 3600) # Expire after 1 hour
+
+ return current_attempts
+
+ except Exception as e:
+ logger.warning(
+ f"Failed to increment callback attempts for {execution_id}: {e}"
+ )
+ return 1
+
+ def get_callback_backoff_delay(
+ self, execution_id: str, organization_id: str
+ ) -> float:
+ """Calculate exponential backoff delay for callback retries.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+
+ Returns:
+ Delay in seconds (exponential backoff)
+ """
+ attempt_count = self.increment_callback_attempt(execution_id, organization_id)
+
+ # Exponential backoff: 2^attempt seconds, max 300 seconds (5 minutes)
+ base_delay = 2.0
+ max_delay = 300.0
+
+ delay = min(base_delay ** min(attempt_count, 8), max_delay)
+
+ logger.debug(
+ f"Callback attempt {attempt_count} for {execution_id}, delay: {delay}s"
+ )
+ return delay
+
+ def clear_callback_attempts(self, execution_id: str, organization_id: str):
+ """Clear callback attempt counter after successful completion.
+
+ Args:
+ execution_id: Execution ID
+ organization_id: Organization context
+ """
+ if not self.is_available:
+ return
+
+ try:
+ cache_key = f"callback_attempts:{organization_id}:{execution_id}"
+ self._redis_client.delete(cache_key)
+ logger.debug(f"Cleared callback attempts for {execution_id}")
+
+ except Exception as e:
+ logger.warning(f"Failed to clear callback attempts for {execution_id}: {e}")
+
+ def batch_invalidate_execution_cache(
+ self, execution_ids: list[str], organization_id: str
+ ):
+ """Batch invalidate multiple execution caches.
+
+ Args:
+ execution_ids: List of execution IDs
+ organization_id: Organization context
+ """
+ if not self.is_available or not execution_ids:
+ return
+
+ try:
+ # Build cache keys
+ cache_keys = []
+ for execution_id in execution_ids:
+ cache_keys.extend(
+ [
+ f"exec_status:{organization_id}:{execution_id}",
+ f"batch_summary:{organization_id}:{execution_id}",
+ f"callback_attempts:{organization_id}:{execution_id}",
+ ]
+ )
+
+ # Delete in batches
+ if cache_keys:
+ self._redis_client.delete(*cache_keys)
+ logger.debug(
+ f"Batch invalidated cache for {len(execution_ids)} executions"
+ )
+
+ except Exception as e:
+ logger.warning(f"Batch cache invalidation error: {e}")
+
+ def get_cache_stats(self) -> dict:
+ """Get cache performance statistics.
+
+ Returns:
+ Dictionary with cache statistics
+ """
+ if not self.is_available:
+ return {"status": "unavailable", "reason": "redis_not_connected"}
+
+ try:
+ info = self._redis_client.info()
+
+ return {
+ "status": "available",
+ "connected_clients": info.get("connected_clients", 0),
+ "used_memory": info.get("used_memory_human", "unknown"),
+ "total_commands_processed": info.get("total_commands_processed", 0),
+ "keyspace_hits": info.get("keyspace_hits", 0),
+ "keyspace_misses": info.get("keyspace_misses", 0),
+ "hit_rate": round(
+ info.get("keyspace_hits", 0)
+ / max(
+ info.get("keyspace_hits", 0) + info.get("keyspace_misses", 0), 1
+ )
+ * 100,
+ 2,
+ ),
+ }
+
+ except Exception as e:
+ return {"status": "error", "error": str(e)}
+
+
+class CacheDecorator:
+ """Decorator for caching API responses to reduce database queries."""
+
+ def __init__(self, cache_manager: WorkerCacheManager, ttl: int = 60):
+ """Initialize cache decorator.
+
+ Args:
+ cache_manager: Cache manager instance
+ ttl: Time-to-live in seconds
+ """
+ self.cache_manager = cache_manager
+ self.ttl = ttl
+
+ def __call__(self, func):
+ """Wrap function with caching logic."""
+
+ def wrapper(*args, **kwargs):
+ # Extract cache key from function arguments
+ # This is a simple implementation - can be enhanced for specific use cases
+ if not self.cache_manager.is_available:
+ return func(*args, **kwargs)
+
+ # For now, just call the function (can be enhanced with specific caching logic)
+ return func(*args, **kwargs)
+
+ return wrapper
+
+
+# Global cache manager instance (initialized per worker)
+_cache_manager = None
+
+
+def get_cache_manager() -> WorkerCacheManager | None:
+ """Get global cache manager instance.
+
+ Returns:
+ Cache manager instance or None if not initialized
+ """
+ return _cache_manager
+
+
+def initialize_cache_manager(config: WorkerConfig) -> WorkerCacheManager:
+ """Initialize global cache manager.
+
+ Args:
+ config: Worker configuration
+
+ Returns:
+ Initialized cache manager
+ """
+ global _cache_manager
+ _cache_manager = WorkerCacheManager(config)
+ return _cache_manager
diff --git a/workers/shared/infrastructure/config/__init__.py b/workers/shared/infrastructure/config/__init__.py
new file mode 100644
index 000000000..66f513721
--- /dev/null
+++ b/workers/shared/infrastructure/config/__init__.py
@@ -0,0 +1,15 @@
+"""Configuration management infrastructure.
+
+This package provides configuration management, worker registration,
+and builder patterns for workers infrastructure.
+"""
+
+from .builder import WorkerBuilder
+from .registry import WorkerRegistry
+from .worker_config import WorkerConfig
+
+__all__ = [
+ "WorkerBuilder",
+ "WorkerRegistry",
+ "WorkerConfig",
+]
diff --git a/workers/shared/infrastructure/config/builder.py b/workers/shared/infrastructure/config/builder.py
new file mode 100644
index 000000000..57bf28b4d
--- /dev/null
+++ b/workers/shared/infrastructure/config/builder.py
@@ -0,0 +1,354 @@
+"""Worker Builder - Factory for Creating Configured Celery Workers
+
+This module provides a builder pattern for creating Celery workers with
+standardized configuration, reducing duplication across worker implementations.
+
+Migration Note: This is the core factory that creates workers using the
+centralized registry, replacing individual worker.py configuration code.
+"""
+
+import logging
+import os
+from typing import Any
+
+from celery import Celery
+
+from ...enums.worker_enums import WorkerType
+from ..logging import WorkerLogger
+from ..monitoring.health import HealthChecker, HealthServer
+from .registry import WorkerRegistry
+from .worker_config import WorkerConfig
+
+logger = logging.getLogger(__name__)
+
+
+# Chord configuration now handled by hierarchical environment-based configuration
+# See shared/models/worker_models.py:get_celery_setting() and _add_chord_configuration()
+
+
+class WorkerBuilder:
+ """Builder for creating configured Celery workers.
+
+ This class uses the builder pattern to create fully configured
+ Celery workers with health checks, logging, and proper routing.
+ """
+
+ @staticmethod
+ def build_celery_app(
+ worker_type: WorkerType,
+ app_name: str | None = None,
+ override_config: dict[str, Any] | None = None,
+ ) -> tuple[Celery, WorkerConfig]:
+ """Build a configured Celery app for the specified worker type.
+
+ Args:
+ worker_type: Type of worker to build
+ app_name: Optional custom app name
+ override_config: Optional config overrides
+
+ Returns:
+ Tuple of (Celery app, WorkerConfig)
+
+ Raises:
+ ValueError: If worker type is not properly configured
+ """
+ logger.info(f"Building Celery app for {worker_type}")
+
+ # Get configuration from environment
+ config = WorkerConfig.from_env(worker_type.name)
+
+ # Get complete configuration from registry
+ worker_celery_config = WorkerRegistry.get_complete_config(worker_type)
+
+ # Create Celery app
+ app_name = app_name or f"{worker_type.value}_worker"
+ app = Celery(app_name)
+
+ # Build Celery configuration
+ celery_config = worker_celery_config.to_celery_dict(
+ broker_url=config.celery_broker_url,
+ result_backend=config.celery_result_backend,
+ )
+
+ # Add Django-style log format configuration to override Celery's default formats
+ logging_config = WorkerRegistry.get_logging_config(worker_type)
+ log_format = os.getenv("LOG_FORMAT", logging_config.get("log_format", "django"))
+
+ if log_format.lower() == "django":
+ # Use Django-style format for both worker and task logs
+ django_log_format = (
+ "%(levelname)s : [%(asctime)s]"
+ "{module:%(module)s process:%(process)d "
+ "thread:%(thread)d request_id:%(request_id)s "
+ "trace_id:%(otelTraceID)s span_id:%(otelSpanID)s} :- %(message)s"
+ )
+
+ # Override Celery's default log formats
+ celery_config.update(
+ {
+ "worker_log_format": django_log_format,
+ "worker_task_log_format": f"[%(task_name)s(%(task_id)s)] {django_log_format}",
+ # Disable Celery's default logging setup to prevent conflicts
+ "worker_hijack_root_logger": False,
+ "worker_log_color": False,
+ }
+ )
+
+ # Apply any additional overrides
+ if override_config:
+ celery_config.update(override_config)
+
+ # Apply configuration to Celery app
+ app.conf.update(celery_config)
+
+ logger.info(
+ f"Built {worker_type} worker with queues: "
+ f"{worker_celery_config.queue_config.all_queues()}"
+ )
+
+ return app, config
+
+ @staticmethod
+ def setup_logging(worker_type: WorkerType) -> logging.Logger:
+ """Setup standardized logging for a worker.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Configured logger instance
+ """
+ logging_config = WorkerRegistry.get_logging_config(worker_type)
+
+ # Determine log format from environment or config
+ log_format = os.getenv("LOG_FORMAT", logging_config.get("log_format", "django"))
+ log_level = os.getenv("LOG_LEVEL", logging_config.get("log_level", "INFO"))
+
+ # Configure worker logging
+ WorkerLogger.configure(
+ log_level=log_level,
+ log_format=log_format,
+ worker_name=worker_type.to_worker_name(),
+ )
+
+ # Configure Celery's built-in loggers to use the same format
+ WorkerBuilder._configure_celery_loggers(log_format, log_level)
+
+ return WorkerLogger.get_logger(worker_type.to_worker_name())
+
+ @staticmethod
+ def _configure_celery_loggers(log_format: str, log_level: str) -> None:
+ """Configure Celery's built-in loggers and root logger to use consistent formatting.
+
+ This ensures that ALL loggers (including task execution loggers) use the same format
+ as the rest of the application, eliminating mixed log formats completely.
+
+ Args:
+ log_format: Log format to use ('django' or 'structured')
+ log_level: Log level to set
+ """
+ from ..logging.logger import (
+ DjangoStyleFormatter,
+ StructuredFormatter,
+ WorkerFieldFilter,
+ )
+
+ # Choose the appropriate formatter
+ if log_format.lower() == "django":
+ formatter = DjangoStyleFormatter()
+ elif log_format.lower() == "structured":
+ formatter = StructuredFormatter()
+ else:
+ formatter = DjangoStyleFormatter() # Default to Django format
+
+ # CRITICAL: Configure root logger to catch ALL loggers
+ root_logger = logging.getLogger()
+ root_logger.setLevel(getattr(logging, log_level.upper()))
+
+ # Clear all existing handlers on root logger
+ root_logger.handlers.clear()
+
+ # Add our custom handler to root logger
+ root_handler = logging.StreamHandler()
+ root_handler.setFormatter(formatter)
+
+ # Add field filter for Django format to ensure required fields
+ if log_format.lower() == "django":
+ root_handler.addFilter(WorkerFieldFilter())
+
+ root_logger.addHandler(root_handler)
+
+ # Configure specific Celery loggers for extra assurance
+ celery_loggers = [
+ "celery",
+ "celery.worker",
+ "celery.task",
+ "celery.worker.strategy",
+ "celery.worker.consumer",
+ "celery.worker.job",
+ "celery.worker.control",
+ "celery.worker.heartbeat",
+ "celery.redirected",
+ # Add more specific loggers that might be used in tasks
+ "shared",
+ "api-deployment",
+ "callback",
+ "file_processing",
+ "notification",
+ "general",
+ "scheduler",
+ "log_consumer",
+ ]
+
+ for logger_name in celery_loggers:
+ celery_logger = logging.getLogger(logger_name)
+ celery_logger.setLevel(getattr(logging, log_level.upper()))
+
+ # Remove existing handlers to avoid duplication
+ celery_logger.handlers.clear()
+
+ # Add our custom handler with consistent formatting
+ handler = logging.StreamHandler()
+ handler.setFormatter(formatter)
+
+ # Add field filter for Django format to ensure required fields
+ if log_format.lower() == "django":
+ handler.addFilter(WorkerFieldFilter())
+
+ celery_logger.addHandler(handler)
+
+ # Disable propagation to avoid duplicate logs (each logger has its own handler)
+ celery_logger.propagate = False
+
+ @staticmethod
+ def setup_health_monitoring(
+ worker_type: WorkerType, config: WorkerConfig
+ ) -> tuple[HealthChecker, HealthServer]:
+ """Setup health monitoring for a worker.
+
+ Args:
+ worker_type: Type of worker
+ config: Worker configuration
+
+ Returns:
+ Tuple of (HealthChecker, HealthServer)
+ """
+ health_checker = HealthChecker(config)
+
+ # Register all health checks from registry
+ for name, check_func in WorkerRegistry.get_health_checks(worker_type):
+ health_checker.add_custom_check(name, check_func)
+
+ # Get health port from worker type or environment
+ health_port = int(
+ os.getenv(
+ f"{worker_type.name}_HEALTH_PORT", str(worker_type.to_health_port())
+ )
+ )
+
+ health_server = HealthServer(health_checker=health_checker, port=health_port)
+
+ logger.info(f"Health monitoring configured on port {health_port}")
+
+ return health_checker, health_server
+
+ @staticmethod
+ def create_worker(
+ worker_type: WorkerType,
+ with_health: bool = True,
+ with_logging: bool = True,
+ override_config: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Create a complete worker with all components.
+
+ Args:
+ worker_type: Type of worker to create
+ with_health: Enable health monitoring
+ with_logging: Setup logging
+ override_config: Optional config overrides
+
+ Returns:
+ Dictionary with worker components:
+ - app: Celery application
+ - config: WorkerConfig
+ - logger: Logger instance (if with_logging)
+ - health_checker: HealthChecker (if with_health)
+ - health_server: HealthServer (if with_health)
+ """
+ components = {}
+
+ # Setup logging if requested
+ if with_logging:
+ components["logger"] = WorkerBuilder.setup_logging(worker_type)
+ components["logger"].info(f"Creating {worker_type} worker")
+
+ # Build Celery app
+ app, config = WorkerBuilder.build_celery_app(
+ worker_type, override_config=override_config
+ )
+ components["app"] = app
+ components["config"] = config
+
+ # Setup health monitoring if requested
+ if with_health:
+ health_checker, health_server = WorkerBuilder.setup_health_monitoring(
+ worker_type, config
+ )
+ components["health_checker"] = health_checker
+ components["health_server"] = health_server
+
+ if with_logging:
+ components["logger"].info(f"{worker_type} worker created successfully")
+
+ return components
+
+ @staticmethod
+ def validate_worker(worker_type: WorkerType) -> list[str]:
+ """Validate worker configuration before building.
+
+ Args:
+ worker_type: Type of worker to validate
+
+ Returns:
+ List of validation errors (empty if valid)
+ """
+ errors = []
+
+ # Check if worker is registered
+ try:
+ WorkerRegistry.get_queue_config(worker_type)
+ except KeyError:
+ errors.append(f"No queue configuration for {worker_type}")
+
+ try:
+ WorkerRegistry.get_task_routing(worker_type)
+ except KeyError:
+ errors.append(f"No task routing for {worker_type}")
+
+ # Check if tasks module exists
+ import_path = worker_type.to_import_path()
+ try:
+ import importlib
+
+ importlib.import_module(import_path)
+ except ImportError as e:
+ errors.append(f"Cannot import {import_path}: {e}")
+
+ return errors
+
+ @staticmethod
+ def get_cli_command(worker_type: WorkerType) -> list[str]:
+ """Get Celery CLI command for running the worker.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ List of command arguments for celery worker
+ """
+ worker_config = WorkerRegistry.get_complete_config(worker_type)
+ return worker_config.to_cli_args()
+
+
+# LegacyWorkerAdapter removed - no more fallback logic
+# All workers now use the direct WorkerBuilder.build_celery_app() approach
diff --git a/workers/shared/infrastructure/config/registry.py b/workers/shared/infrastructure/config/registry.py
new file mode 100644
index 000000000..edb53bcf2
--- /dev/null
+++ b/workers/shared/infrastructure/config/registry.py
@@ -0,0 +1,366 @@
+"""Worker Registry - Central Configuration Hub
+
+This module provides a centralized registry for all worker configurations,
+including queue configs, task routing, health checks, and logging settings.
+
+Migration Note: This replaces scattered configuration across multiple worker.py
+files with a single source of truth, making it easier to maintain and update
+worker configurations.
+"""
+
+import logging
+from collections.abc import Callable
+
+from shared.enums.worker_enums import QueueName, WorkerType
+from shared.models.worker_models import (
+ TaskRoute,
+ WorkerCeleryConfig,
+ WorkerHealthConfig,
+ WorkerQueueConfig,
+ WorkerTaskRouting,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerRegistry:
+ """Central registry for all worker configurations.
+
+ This class acts as the single source of truth for:
+ - Queue configurations
+ - Task routing rules
+ - Health check functions
+ - Logging configurations
+ - Worker-specific settings
+ """
+
+ # Queue configurations for each worker type
+ _QUEUE_CONFIGS: dict[WorkerType, WorkerQueueConfig] = {
+ WorkerType.API_DEPLOYMENT: WorkerQueueConfig(
+ primary_queue=QueueName.API_DEPLOYMENTS
+ ),
+ WorkerType.GENERAL: WorkerQueueConfig(primary_queue=QueueName.GENERAL),
+ WorkerType.FILE_PROCESSING: WorkerQueueConfig(
+ primary_queue=QueueName.FILE_PROCESSING,
+ additional_queues=[QueueName.FILE_PROCESSING_API],
+ ),
+ WorkerType.CALLBACK: WorkerQueueConfig(
+ primary_queue=QueueName.CALLBACK, additional_queues=[QueueName.CALLBACK_API]
+ ),
+ WorkerType.NOTIFICATION: WorkerQueueConfig(
+ primary_queue=QueueName.NOTIFICATION,
+ additional_queues=[
+ QueueName.NOTIFICATION_WEBHOOK,
+ QueueName.NOTIFICATION_EMAIL,
+ QueueName.NOTIFICATION_SMS,
+ QueueName.NOTIFICATION_PRIORITY,
+ ],
+ ),
+ WorkerType.LOG_CONSUMER: WorkerQueueConfig(
+ primary_queue=QueueName.LOG_CONSUMER,
+ additional_queues=[QueueName.PERIODIC_LOGS],
+ ),
+ WorkerType.SCHEDULER: WorkerQueueConfig(
+ primary_queue=QueueName.SCHEDULER, additional_queues=[QueueName.GENERAL]
+ ),
+ }
+
+ # Task routing rules for each worker type
+ _TASK_ROUTES: dict[WorkerType, WorkerTaskRouting] = {
+ WorkerType.API_DEPLOYMENT: WorkerTaskRouting(
+ worker_type=WorkerType.API_DEPLOYMENT,
+ routes=[
+ TaskRoute("async_execute_bin_api", QueueName.API_DEPLOYMENTS),
+ TaskRoute("api_deployment_cleanup", QueueName.API_DEPLOYMENTS),
+ TaskRoute("api_deployment_status_check", QueueName.API_DEPLOYMENTS),
+ TaskRoute("api_deployment_worker.*", QueueName.API_DEPLOYMENTS),
+ ],
+ ),
+ WorkerType.GENERAL: WorkerTaskRouting(
+ worker_type=WorkerType.GENERAL,
+ routes=[
+ TaskRoute("async_execute_bin", QueueName.GENERAL),
+ TaskRoute("async_execute_bin_general", QueueName.GENERAL),
+ TaskRoute("general_worker.*", QueueName.GENERAL),
+ ],
+ ),
+ WorkerType.FILE_PROCESSING: WorkerTaskRouting(
+ worker_type=WorkerType.FILE_PROCESSING,
+ routes=[
+ TaskRoute("process_file_batch", QueueName.FILE_PROCESSING),
+ TaskRoute("process_file_batch_api", QueueName.FILE_PROCESSING_API),
+ ],
+ ),
+ WorkerType.CALLBACK: WorkerTaskRouting(
+ worker_type=WorkerType.CALLBACK,
+ routes=[
+ TaskRoute("process_batch_callback", QueueName.CALLBACK),
+ TaskRoute("process_batch_callback_api", QueueName.CALLBACK_API),
+ # TaskRoute("finalize_execution_callback", QueueName.CALLBACK), removed - dead code
+ ],
+ ),
+ WorkerType.NOTIFICATION: WorkerTaskRouting(
+ worker_type=WorkerType.NOTIFICATION,
+ routes=[
+ TaskRoute("process_notification", QueueName.NOTIFICATION),
+ TaskRoute("send_webhook_notification", QueueName.NOTIFICATION),
+ TaskRoute("send_batch_notifications", QueueName.NOTIFICATION),
+ TaskRoute("notification_health_check", QueueName.NOTIFICATION),
+ TaskRoute("notification.tasks.*", QueueName.NOTIFICATION),
+ TaskRoute("send_email_notification", QueueName.NOTIFICATION_EMAIL),
+ TaskRoute("send_sms_notification", QueueName.NOTIFICATION_SMS),
+ TaskRoute("priority_notification", QueueName.NOTIFICATION_PRIORITY),
+ ],
+ ),
+ WorkerType.LOG_CONSUMER: WorkerTaskRouting(
+ worker_type=WorkerType.LOG_CONSUMER,
+ routes=[
+ TaskRoute("logs_consumer", QueueName.LOG_CONSUMER),
+ TaskRoute("consume_log_history", QueueName.PERIODIC_LOGS),
+ TaskRoute("log_consumer.tasks.*", QueueName.LOG_CONSUMER),
+ TaskRoute("log_consumer_health_check", QueueName.LOG_CONSUMER),
+ ],
+ ),
+ WorkerType.SCHEDULER: WorkerTaskRouting(
+ worker_type=WorkerType.SCHEDULER,
+ routes=[
+ TaskRoute("execute_pipeline_task", QueueName.SCHEDULER),
+ TaskRoute("execute_pipeline_task_v2", QueueName.SCHEDULER),
+ TaskRoute("scheduler_health_check", QueueName.SCHEDULER),
+ TaskRoute("scheduler.tasks.*", QueueName.SCHEDULER),
+ ],
+ ),
+ }
+
+ # Health check functions registry
+ _HEALTH_CHECKS: dict[WorkerType, list[tuple[str, Callable]]] = {}
+
+ # Note: Worker-specific Celery settings moved to environment-based configuration
+ # See shared/models/worker_models.py:get_celery_setting() for hierarchical config
+ # Use environment variables like CALLBACK_TASK_TIME_LIMIT=3600 or CELERY_TASK_TIME_LIMIT=300
+
+ # Logging configurations - All workers use Django format for consistency
+ _LOGGING_CONFIGS: dict[WorkerType, dict] = {
+ WorkerType.API_DEPLOYMENT: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.GENERAL: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.FILE_PROCESSING: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.CALLBACK: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.NOTIFICATION: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.LOG_CONSUMER: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.SCHEDULER: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ }
+
+ @classmethod
+ def get_queue_config(cls, worker_type: WorkerType) -> WorkerQueueConfig:
+ """Get queue configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Queue configuration
+
+ Raises:
+ KeyError: If worker type not registered
+ """
+ if worker_type not in cls._QUEUE_CONFIGS:
+ raise KeyError(f"No queue config registered for {worker_type}")
+ return cls._QUEUE_CONFIGS[worker_type]
+
+ @classmethod
+ def get_task_routing(cls, worker_type: WorkerType) -> WorkerTaskRouting:
+ """Get task routing configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Task routing configuration
+
+ Raises:
+ KeyError: If worker type not registered
+ """
+ if worker_type not in cls._TASK_ROUTES:
+ raise KeyError(f"No task routing registered for {worker_type}")
+ return cls._TASK_ROUTES[worker_type]
+
+ @classmethod
+ def register_health_check(
+ cls, worker_type: WorkerType, name: str, check_func: Callable
+ ) -> None:
+ """Register a health check function for a worker type.
+
+ Args:
+ worker_type: Type of worker
+ name: Name of the health check
+ check_func: Health check function
+ """
+ if worker_type not in cls._HEALTH_CHECKS:
+ cls._HEALTH_CHECKS[worker_type] = []
+
+ cls._HEALTH_CHECKS[worker_type].append((name, check_func))
+ logger.info(f"Registered health check '{name}' for {worker_type}")
+
+ @classmethod
+ def get_health_checks(cls, worker_type: WorkerType) -> list[tuple[str, Callable]]:
+ """Get all health check functions for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ List of (name, function) tuples
+ """
+ return cls._HEALTH_CHECKS.get(worker_type, [])
+
+ @classmethod
+ def get_worker_settings(cls, worker_type: WorkerType) -> dict:
+ """Get worker-specific Celery settings.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Empty dict (settings moved to environment-based configuration)
+ """
+ # Worker settings moved to hierarchical environment-based configuration
+ # See shared/models/worker_models.py:get_celery_setting()
+ return {}
+
+ @classmethod
+ def get_logging_config(cls, worker_type: WorkerType) -> dict:
+ """Get logging configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Logging configuration dict
+ """
+ return cls._LOGGING_CONFIGS.get(
+ worker_type,
+ {
+ "log_format": "structured",
+ "log_level": "INFO",
+ },
+ )
+
+ @classmethod
+ def get_complete_config(cls, worker_type: WorkerType) -> WorkerCeleryConfig:
+ """Get complete configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Complete WorkerCeleryConfig object
+ """
+ queue_config = cls.get_queue_config(worker_type)
+ task_routing = cls.get_task_routing(worker_type)
+
+ # Build health config
+ health_checks = cls.get_health_checks(worker_type)
+ health_config = WorkerHealthConfig(
+ port=worker_type.to_health_port(), custom_checks=health_checks
+ )
+
+ # Create complete config (worker settings now come from environment variables)
+ config = WorkerCeleryConfig(
+ worker_type=worker_type,
+ queue_config=queue_config,
+ task_routing=task_routing,
+ health_config=health_config,
+ )
+
+ return config
+
+ @classmethod
+ def validate_registry(cls) -> list[str]:
+ """Validate the registry configuration.
+
+ Returns:
+ List of validation errors (empty if all valid)
+ """
+ errors = []
+
+ # Check all WorkerTypes have configurations
+ for worker_type in WorkerType:
+ if worker_type not in cls._QUEUE_CONFIGS:
+ errors.append(f"Missing queue config for {worker_type}")
+
+ if worker_type not in cls._TASK_ROUTES:
+ errors.append(f"Missing task routes for {worker_type}")
+
+ # Validate queue names in task routes
+ for worker_type, routing in cls._TASK_ROUTES.items():
+ queue_config = cls._QUEUE_CONFIGS.get(worker_type)
+ if not queue_config:
+ continue
+
+ valid_queues = queue_config.all_queues()
+ for route in routing.routes:
+ if route.queue.value not in valid_queues:
+ # Check if it's a valid queue for cross-worker routing
+ if route.queue not in QueueName:
+ errors.append(
+ f"Invalid queue {route.queue} in {worker_type} routing"
+ )
+
+ return errors
+
+ @classmethod
+ def list_workers(cls) -> list[dict]:
+ """List all registered workers with their configurations.
+
+ Returns:
+ List of worker configuration summaries
+ """
+ workers = []
+ for worker_type in WorkerType:
+ try:
+ queue_config = cls.get_queue_config(worker_type)
+ task_routing = cls.get_task_routing(worker_type)
+ health_checks = cls.get_health_checks(worker_type)
+
+ workers.append(
+ {
+ "type": worker_type.value,
+ "name": worker_type.to_worker_name(),
+ "import_path": worker_type.to_import_path(),
+ "health_port": worker_type.to_health_port(),
+ "queues": list(queue_config.all_queues()),
+ "task_count": len(task_routing.routes),
+ "health_checks": len(health_checks),
+ }
+ )
+ except KeyError:
+ workers.append(
+ {
+ "type": worker_type.value,
+ "name": worker_type.to_worker_name(),
+ "error": "Not configured in registry",
+ }
+ )
+
+ return workers
diff --git a/workers/shared/infrastructure/config/worker_config.py b/workers/shared/infrastructure/config/worker_config.py
new file mode 100644
index 000000000..4f3c4c3e0
--- /dev/null
+++ b/workers/shared/infrastructure/config/worker_config.py
@@ -0,0 +1,607 @@
+"""Worker Configuration Management
+
+Centralized configuration for lightweight workers with environment variable support.
+"""
+
+import logging
+import os
+from dataclasses import dataclass, field
+from typing import Any
+
+from dotenv import load_dotenv
+
+# Load environment variables from .env file if it exists
+env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")
+if os.path.exists(env_path):
+ load_dotenv(env_path)
+
+
+# Configuration Constants Classes
+class DefaultConfig:
+ """Default configuration values for workers."""
+
+ # Task timeouts moved to WorkerSettings._get_worker_specific_timeout_defaults()
+ # and configured via environment variables (TASK_TIME_LIMIT, TASK_SOFT_TIME_LIMIT, etc.)
+ WEBHOOK_TIMEOUT = 30 # 30 seconds (keep short for webhooks)
+
+ # Retry configuration
+ DEFAULT_MAX_RETRIES = 3
+ FILE_PROCESSING_MAX_RETRIES = 5
+ CALLBACK_MAX_RETRIES = 8
+ WEBHOOK_MAX_RETRIES = 3
+
+ # Performance limits
+ MAX_CONCURRENT_TASKS = 10
+ MAX_FILE_BATCH_SIZE = 20
+ MAX_PARALLEL_FILE_BATCHES = 4
+ MAX_MEMORY_USAGE_MB = 2048
+
+ # Cache settings
+ DEFAULT_CACHE_TTL = 60 # 1 minute
+ EXECUTION_STATUS_CACHE_TTL = 30 # 30 seconds
+ PIPELINE_STATUS_CACHE_TTL = 60 # 1 minute
+ BATCH_SUMMARY_CACHE_TTL = 90 # 90 seconds
+
+ # Health check intervals
+ HEALTH_CHECK_INTERVAL = 30 # 30 seconds
+ METRICS_COLLECTION_INTERVAL = 60 # 1 minute
+
+ # File processing limits
+ MAX_FILE_SIZE_MB = 100
+ DEFAULT_FILE_PATTERNS = ["*"]
+ MAX_FILES_PER_EXECUTION = 1000
+
+ # API client settings
+ API_REQUEST_TIMEOUT = 30
+ API_RETRY_ATTEMPTS = 3
+ API_RETRY_BACKOFF_FACTOR = 1.0
+
+
+class FileProcessingConfig:
+ """File processing specific configuration."""
+
+ # Supported file types
+ SUPPORTED_MIME_TYPES = [
+ "application/pdf",
+ "text/plain",
+ "text/csv",
+ "application/json",
+ "application/xml",
+ "text/xml",
+ "application/msword",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ "application/vnd.ms-excel",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "image/jpeg",
+ "image/png",
+ "image/gif",
+ "image/bmp",
+ "image/tiff",
+ ]
+
+ # File size limits (in bytes)
+ MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
+ MIN_FILE_SIZE = 1 # 1 byte
+
+ # Batch processing limits
+ MIN_BATCH_SIZE = 1
+ MAX_BATCH_SIZE = 20
+ DEFAULT_BATCH_SIZE = 5
+
+ # Processing timeouts
+ SINGLE_FILE_TIMEOUT = 300 # 5 minutes per file
+ BATCH_TIMEOUT = 1800 # 30 minutes per batch
+
+ # Retry configuration for file operations
+ FILE_RETRY_MAX_ATTEMPTS = 3
+ FILE_RETRY_BACKOFF_FACTOR = 2.0
+ FILE_RETRY_MAX_DELAY = 60 # 1 minute
+
+
+@dataclass
+class WorkerConfig:
+ """Configuration class for lightweight workers.
+
+ Loads configuration from environment variables with sensible defaults.
+ Supports validation and type conversion.
+ """
+
+ # Internal API Configuration (matches backend patterns)
+ internal_api_base_url: str = field(
+ default_factory=lambda: os.getenv("INTERNAL_API_BASE_URL") or ""
+ )
+ internal_api_key: str = field(
+ default_factory=lambda: os.getenv("INTERNAL_SERVICE_API_KEY") or ""
+ )
+
+ # Celery Broker Configuration (matches backend/settings/base.py exactly)
+ celery_broker_base_url: str = field(
+ default_factory=lambda: os.getenv("CELERY_BROKER_BASE_URL", "")
+ )
+ celery_broker_user: str = field(
+ default_factory=lambda: os.getenv("CELERY_BROKER_USER", "")
+ )
+ celery_broker_pass: str = field(
+ default_factory=lambda: os.getenv("CELERY_BROKER_PASS", "")
+ )
+
+ # Celery Backend Database Configuration (with CELERY_BACKEND_ prefix)
+ celery_backend_db_host: str = field(
+ default_factory=lambda: os.getenv(
+ "CELERY_BACKEND_DB_HOST", os.getenv("DB_HOST", "")
+ ) # Fallback to main DB config
+ )
+ celery_backend_db_port: str = field(
+ default_factory=lambda: os.getenv(
+ "CELERY_BACKEND_DB_PORT", os.getenv("DB_PORT", "5432")
+ ) # Port default is OK
+ )
+ celery_backend_db_name: str = field(
+ default_factory=lambda: os.getenv(
+ "CELERY_BACKEND_DB_NAME", os.getenv("DB_NAME", "")
+ )
+ )
+ celery_backend_db_user: str = field(
+ default_factory=lambda: os.getenv(
+ "CELERY_BACKEND_DB_USER", os.getenv("DB_USER", "")
+ )
+ )
+ celery_backend_db_password: str = field(
+ default_factory=lambda: os.getenv(
+ "CELERY_BACKEND_DB_PASSWORD", os.getenv("DB_PASSWORD", "")
+ )
+ )
+ celery_backend_db_schema: str = field(
+ default_factory=lambda: os.getenv("CELERY_BACKEND_DB_SCHEMA") or "public"
+ )
+
+ # Redis Cache Configuration (separate from Celery broker)
+ cache_redis_enabled: bool = field(
+ default_factory=lambda: os.getenv("CACHE_REDIS_ENABLED", "true").lower() == "true"
+ )
+ cache_redis_host: str = field(
+ default_factory=lambda: os.getenv("CACHE_REDIS_HOST", "localhost")
+ )
+ cache_redis_port: int = field(
+ default_factory=lambda: int(os.getenv("CACHE_REDIS_PORT", "6379"))
+ )
+ cache_redis_db: int = field(
+ default_factory=lambda: int(os.getenv("CACHE_REDIS_DB", "0"))
+ )
+ cache_redis_password: str = field(
+ default_factory=lambda: os.getenv("CACHE_REDIS_PASSWORD", "")
+ )
+ cache_redis_username: str = field(
+ default_factory=lambda: os.getenv("CACHE_REDIS_USERNAME", "")
+ )
+ cache_redis_ssl: bool = field(
+ default_factory=lambda: os.getenv("CACHE_REDIS_SSL", "false").lower() == "true"
+ )
+ cache_redis_ssl_cert_reqs: str = field(
+ default_factory=lambda: os.getenv("CACHE_REDIS_SSL_CERT_REQS", "required")
+ )
+
+ # Computed URLs (built from components like backend does)
+ celery_broker_url: str = field(init=False)
+ celery_result_backend: str = field(init=False)
+ cache_redis_url: str = field(init=False)
+
+ # Worker Identity
+ worker_name: str = field(
+ default_factory=lambda: os.getenv("WORKER_NAME", "unstract-worker")
+ )
+ worker_version: str = field(
+ default_factory=lambda: os.getenv("WORKER_VERSION", "1.0.0")
+ )
+ worker_instance_id: str = field(
+ default_factory=lambda: os.getenv("HOSTNAME", "unknown")
+ )
+
+ # API Client Settings
+ api_timeout: int = field(
+ default_factory=lambda: int(os.getenv("INTERNAL_API_TIMEOUT", "30"))
+ )
+ api_retry_attempts: int = field(
+ default_factory=lambda: int(os.getenv("INTERNAL_API_RETRY_ATTEMPTS", "3"))
+ )
+ api_retry_backoff_factor: float = field(
+ default_factory=lambda: float(
+ os.getenv("INTERNAL_API_RETRY_BACKOFF_FACTOR", "1.0")
+ )
+ )
+
+ # Logging Configuration
+ log_level: str = field(default_factory=lambda: os.getenv("LOG_LEVEL", "INFO"))
+ log_format: str = field(default_factory=lambda: os.getenv("LOG_FORMAT", "structured"))
+ log_file: str | None = field(default_factory=lambda: os.getenv("LOG_FILE"))
+
+ # Circuit Breaker Settings
+ circuit_breaker_failure_threshold: int = field(
+ default_factory=lambda: int(os.getenv("CIRCUIT_BREAKER_FAILURE_THRESHOLD", "5"))
+ )
+ circuit_breaker_recovery_timeout: int = field(
+ default_factory=lambda: int(os.getenv("CIRCUIT_BREAKER_RECOVERY_TIMEOUT", "60"))
+ )
+ circuit_breaker_expected_exception: str = field(
+ default_factory=lambda: os.getenv(
+ "CIRCUIT_BREAKER_EXPECTED_EXCEPTION", "Exception"
+ )
+ )
+
+ # Health Check Settings
+ health_check_interval: int = field(
+ default_factory=lambda: int(os.getenv("HEALTH_CHECK_INTERVAL", "30"))
+ )
+ health_check_timeout: int = field(
+ default_factory=lambda: int(os.getenv("HEALTH_CHECK_TIMEOUT", "10"))
+ )
+
+ # Performance Settings
+ max_concurrent_tasks: int = field(
+ default_factory=lambda: int(os.getenv("MAX_CONCURRENT_TASKS", "10"))
+ )
+
+ # API Client Performance Optimization
+ enable_api_client_singleton: bool = field(
+ default_factory=lambda: os.getenv("ENABLE_API_CLIENT_SINGLETON", "true").lower()
+ == "true"
+ )
+ enable_organization_context_cache: bool = field(
+ default_factory=lambda: os.getenv(
+ "ENABLE_ORGANIZATION_CONTEXT_CACHE", "true"
+ ).lower()
+ == "true"
+ )
+ api_client_pool_size: int = field(
+ default_factory=lambda: int(os.getenv("API_CLIENT_POOL_SIZE", "3"))
+ )
+
+ # Configuration Caching
+ enable_config_cache: bool = field(
+ default_factory=lambda: os.getenv("ENABLE_CONFIG_CACHE", "true").lower() == "true"
+ )
+ config_cache_ttl: int = field(
+ default_factory=lambda: int(os.getenv("CONFIG_CACHE_TTL", "300"))
+ )
+
+ # Debug Logging Control (Performance Optimization)
+ enable_debug_logging: bool = field(
+ default_factory=lambda: os.getenv("ENABLE_DEBUG_LOGGING", "false").lower()
+ == "true"
+ )
+ debug_api_client_init: bool = field(
+ default_factory=lambda: os.getenv("DEBUG_API_CLIENT_INIT", "false").lower()
+ == "true"
+ )
+ debug_organization_context: bool = field(
+ default_factory=lambda: os.getenv("DEBUG_ORGANIZATION_CONTEXT", "false").lower()
+ == "true"
+ )
+
+ # Task Timeout Settings (in seconds)
+ # NOTE: Task timeouts are now configured via Celery's standard naming convention:
+ # - General: TASK_TIME_LIMIT, TASK_SOFT_TIME_LIMIT
+ # - Worker-specific: {WORKER_TYPE}_TASK_TIME_LIMIT, {WORKER_TYPE}_TASK_SOFT_TIME_LIMIT
+ # Examples: FILE_PROCESSING_TASK_TIME_LIMIT, CALLBACK_TASK_SOFT_TIME_LIMIT
+ # These are handled by WorkerSettings.get_celery_config() automatically
+
+ # Monitoring Settings
+ enable_metrics: bool = field(
+ default_factory=lambda: os.getenv("ENABLE_METRICS", "true").lower() == "true"
+ )
+ enable_health_server: bool = field(
+ default_factory=lambda: os.getenv("ENABLE_HEALTH_SERVER", "true").lower()
+ == "true"
+ )
+ metrics_port: int = field(
+ default_factory=lambda: int(os.getenv("METRICS_PORT", "8080"))
+ )
+
+ def __post_init__(self):
+ """Validate configuration after initialization."""
+ # Build broker URL from components (matches backend/settings/base.py pattern)
+ if self.celery_broker_base_url:
+ if self.celery_broker_user and self.celery_broker_pass:
+ # RabbitMQ with authentication
+ try:
+ import httpx
+
+ self.celery_broker_url = str(
+ httpx.URL(self.celery_broker_base_url).copy_with(
+ username=self.celery_broker_user,
+ password=self.celery_broker_pass,
+ )
+ )
+ except ImportError:
+ # Fallback if httpx not available
+ from urllib.parse import urlparse, urlunparse
+
+ parsed = urlparse(self.celery_broker_base_url)
+ parsed = parsed._replace(
+ netloc=f"{self.celery_broker_user}:{self.celery_broker_pass}@{parsed.netloc}"
+ )
+ self.celery_broker_url = urlunparse(parsed)
+ else:
+ # Redis or broker without authentication
+ self.celery_broker_url = self.celery_broker_base_url
+ else:
+ # No broker URL could be built - will be caught in validation
+ self.celery_broker_url = ""
+
+ # Build PostgreSQL result backend with configurable schema support
+ from urllib.parse import quote_plus
+
+ # Only build the URL if all required components are present
+ if (
+ self.celery_backend_db_host
+ and self.celery_backend_db_user
+ and self.celery_backend_db_password
+ and self.celery_backend_db_name
+ ):
+ self.celery_result_backend = (
+ f"db+postgresql://{self.celery_backend_db_user}:{quote_plus(self.celery_backend_db_password)}"
+ f"@{self.celery_backend_db_host}:{self.celery_backend_db_port}/"
+ f"{self.celery_backend_db_name}"
+ )
+
+ # Add schema parameter if not using default 'public' schema
+ if (
+ self.celery_backend_db_schema
+ and self.celery_backend_db_schema != "public"
+ ):
+ self.celery_result_backend += (
+ f"?options=-csearch_path%3D{self.celery_backend_db_schema}"
+ )
+ else:
+ # Missing required database configuration
+ self.celery_result_backend = ""
+
+ # Build Redis cache URL for separate cache instance
+ self._build_cache_redis_url()
+
+ # Allow worker startup even with incomplete config for chord settings
+ try:
+ self.validate()
+ except ValueError as e:
+ # Log validation errors but don't prevent worker startup
+ logging.warning(
+ f"Worker configuration validation failed (worker will continue with defaults): {e}"
+ )
+ logging.info(
+ "To fix this, ensure all required environment variables are set. See workers/sample.env"
+ )
+
+ def _build_cache_redis_url(self):
+ """Build Redis cache URL from configuration components."""
+ if not self.cache_redis_enabled:
+ self.cache_redis_url = ""
+ return
+
+ # Build Redis URL with all authentication and SSL options
+ scheme = "rediss" if self.cache_redis_ssl else "redis"
+
+ # Build authentication part
+ auth_part = ""
+ if self.cache_redis_username and self.cache_redis_password:
+ auth_part = f"{self.cache_redis_username}:{self.cache_redis_password}@"
+ elif self.cache_redis_password:
+ auth_part = f":{self.cache_redis_password}@"
+
+ # Build base URL
+ self.cache_redis_url = (
+ f"{scheme}://{auth_part}{self.cache_redis_host}:{self.cache_redis_port}/"
+ f"{self.cache_redis_db}"
+ )
+
+ # Add SSL parameters if needed
+ if self.cache_redis_ssl:
+ ssl_params = []
+ if self.cache_redis_ssl_cert_reqs != "required":
+ ssl_params.append(f"ssl_cert_reqs={self.cache_redis_ssl_cert_reqs}")
+
+ if ssl_params:
+ self.cache_redis_url += "?" + "&".join(ssl_params)
+
+ def validate(self):
+ """Validate configuration values."""
+ errors = []
+
+ # Required fields - provide defaults for development
+ if not self.internal_api_key:
+ # Provide development default instead of error
+ self.internal_api_key = "dev-internal-key-123"
+ logging.warning("Using development default for INTERNAL_SERVICE_API_KEY")
+
+ if not self.internal_api_base_url:
+ # This should not happen due to default factory, but just in case
+ self.internal_api_base_url = "http://unstract-backend:8000/internal"
+ logging.warning("Using Docker default for INTERNAL_API_BASE_URL")
+
+ # Validate that Celery URLs were properly built from environment variables
+ if not self.celery_broker_url:
+ errors.append(
+ "CELERY_BROKER_URL could not be built. Please set the following environment variables: "
+ "CELERY_BROKER_BASE_URL (e.g., 'amqp://unstract-rabbitmq:5672//'), "
+ "CELERY_BROKER_USER, and CELERY_BROKER_PASS. "
+ "See workers/sample.env for examples."
+ )
+
+ if not self.celery_result_backend:
+ errors.append(
+ "CELERY_RESULT_BACKEND could not be built. Please set the following environment variables: "
+ "DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, and DB_PORT. "
+ "These are required for Celery to store task results. "
+ "See workers/sample.env for examples."
+ )
+
+ # Cache Redis validation
+ if self.cache_redis_enabled:
+ if not self.cache_redis_host:
+ errors.append("CACHE_REDIS_HOST is required when cache is enabled")
+ if self.cache_redis_port <= 0:
+ errors.append("CACHE_REDIS_PORT must be positive")
+ if self.cache_redis_db < 0:
+ errors.append("CACHE_REDIS_DB must be non-negative")
+
+ # Numeric validations
+ if self.api_timeout <= 0:
+ errors.append("API_TIMEOUT must be positive")
+
+ if self.api_retry_attempts < 0:
+ errors.append("API_RETRY_ATTEMPTS must be non-negative")
+
+ if self.api_retry_backoff_factor <= 0:
+ errors.append("API_RETRY_BACKOFF_FACTOR must be positive")
+
+ if self.circuit_breaker_failure_threshold <= 0:
+ errors.append("CIRCUIT_BREAKER_FAILURE_THRESHOLD must be positive")
+
+ if self.circuit_breaker_recovery_timeout <= 0:
+ errors.append("CIRCUIT_BREAKER_RECOVERY_TIMEOUT must be positive")
+
+ # Log level validation
+ valid_log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
+ if self.log_level.upper() not in valid_log_levels:
+ errors.append(f"LOG_LEVEL must be one of {valid_log_levels}")
+
+ if errors:
+ raise ValueError(f"Configuration validation failed: {'; '.join(errors)}")
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert configuration to dictionary."""
+ return {
+ field.name: getattr(self, field.name)
+ for field in self.__dataclass_fields__.values()
+ }
+
+ def get_log_level(self) -> int:
+ """Get numeric log level."""
+ return getattr(logging, self.log_level.upper())
+
+ @classmethod
+ def from_env(cls, prefix: str = "") -> "WorkerConfig":
+ """Create configuration from environment variables with optional prefix.
+
+ Args:
+ prefix: Environment variable prefix (e.g., 'WEBHOOK_' for webhook worker)
+
+ Returns:
+ WorkerConfig instance
+ """
+ if prefix and not prefix.endswith("_"):
+ prefix += "_"
+
+ # Create a temporary environment with prefixed variables
+ original_env = dict(os.environ)
+
+ try:
+ # Override with prefixed environment variables
+ for key, value in original_env.items():
+ if key.startswith(prefix):
+ unprefixed_key = key[len(prefix) :]
+ os.environ[unprefixed_key] = value
+
+ return cls()
+
+ finally:
+ # Restore original environment
+ os.environ.clear()
+ os.environ.update(original_env)
+
+ def update_from_dict(self, config_dict: dict[str, Any]):
+ """Update configuration from dictionary."""
+ for key, value in config_dict.items():
+ if hasattr(self, key):
+ setattr(self, key, value)
+
+ # Re-validate after updates
+ self.validate()
+
+ def get_celery_config(self) -> dict[str, Any]:
+ """Get Celery-specific configuration matching backend patterns."""
+ return {
+ "broker_url": self.celery_broker_url,
+ "result_backend": self.celery_result_backend,
+ "task_serializer": "json",
+ "accept_content": ["json"],
+ "result_serializer": "json",
+ "timezone": "UTC",
+ "enable_utc": True,
+ "task_routes": {f"{self.worker_name}.*": {"queue": self.worker_name}},
+ "worker_prefetch_multiplier": int(
+ os.getenv("CELERY_WORKER_PREFETCH_MULTIPLIER", "1")
+ ),
+ "task_acks_late": os.getenv("CELERY_TASK_ACKS_LATE", "true").lower()
+ == "true",
+ "worker_max_tasks_per_child": int(
+ os.getenv("CELERY_WORKER_MAX_TASKS_PER_CHILD", "1000")
+ ),
+ # Default timeouts (individual workers override these in task decorators)
+ "task_time_limit": 3600, # 1 hour default
+ "task_soft_time_limit": 3300, # 55 minutes default
+ "task_reject_on_worker_lost": True,
+ "task_acks_on_failure_or_timeout": True,
+ "worker_disable_rate_limits": False,
+ "task_default_retry_delay": int(
+ os.getenv("CELERY_TASK_DEFAULT_RETRY_DELAY", "60")
+ ),
+ "task_max_retries": int(os.getenv("CELERY_TASK_MAX_RETRIES", "3")),
+ # Worker stability (useful for all workers)
+ "worker_pool_restarts": os.getenv(
+ "CELERY_WORKER_POOL_RESTARTS", "true"
+ ).lower()
+ == "true",
+ "broker_connection_retry_on_startup": os.getenv(
+ "CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP", "true"
+ ).lower()
+ == "true",
+ "worker_send_task_events": True,
+ "task_send_sent_event": True,
+ "worker_log_format": "[%(asctime)s: %(levelname)s/%(processName)s] %(message)s",
+ "worker_task_log_format": "[%(asctime)s: %(levelname)s/%(processName)s][%(task_name)s(%(task_id)s)] %(message)s",
+ }
+
+ def __repr__(self) -> str:
+ """String representation masking sensitive values."""
+ safe_dict = self.to_dict()
+ # Mask sensitive fields
+ sensitive_fields = [
+ "internal_api_key",
+ "celery_broker_pass",
+ "celery_broker_url",
+ "celery_result_backend",
+ "celery_backend_db_password",
+ "cache_redis_password",
+ "cache_redis_url",
+ ]
+ for field_name in sensitive_fields:
+ if field_name in safe_dict and safe_dict[field_name]:
+ safe_dict[field_name] = "*" * 8
+
+ return f"WorkerConfig({safe_dict})"
+
+ def get_cache_redis_config(self) -> dict[str, Any]:
+ """Get Redis cache-specific configuration for cache manager.
+
+ Returns:
+ Dictionary with Redis cache configuration
+ """
+ if not self.cache_redis_enabled:
+ return {"enabled": False}
+
+ config = {
+ "enabled": True,
+ "host": self.cache_redis_host,
+ "port": self.cache_redis_port,
+ "db": self.cache_redis_db,
+ "url": self.cache_redis_url,
+ "ssl": self.cache_redis_ssl,
+ }
+
+ # Add authentication if configured
+ if self.cache_redis_password:
+ config["password"] = self.cache_redis_password
+ if self.cache_redis_username:
+ config["username"] = self.cache_redis_username
+
+ return config
diff --git a/workers/shared/infrastructure/context.py b/workers/shared/infrastructure/context.py
new file mode 100644
index 000000000..fea3e1973
--- /dev/null
+++ b/workers/shared/infrastructure/context.py
@@ -0,0 +1,87 @@
+"""Worker Context Management - Thread-safe state storage for workers.
+
+This provides StateStore functionality for workers without Django dependencies,
+replacing the duplicated 'legacy' version with a proper shared infrastructure module.
+"""
+
+import os
+import threading
+from enum import Enum
+from typing import Any
+
+
+class ConcurrencyMode(Enum):
+ THREAD = "thread"
+ COROUTINE = "coroutine"
+
+
+class Exceptions:
+ UNKNOWN_MODE = "Unknown concurrency mode"
+
+
+class StateStore:
+ """Thread-safe context storage for worker tasks.
+
+ This replaces the Django StateStore functionality for workers,
+ enabling context sharing across worker task execution.
+ """
+
+ mode = os.environ.get("CONCURRENCY_MODE", ConcurrencyMode.THREAD)
+ # Thread-safe storage.
+ thread_local = threading.local()
+
+ @classmethod
+ def _get_thread_local(cls, key: str) -> Any:
+ return getattr(cls.thread_local, key, None)
+
+ @classmethod
+ def _set_thread_local(cls, key: str, val: Any) -> None:
+ setattr(cls.thread_local, key, val)
+
+ @classmethod
+ def _del_thread_local(cls, key: str) -> None:
+ try:
+ delattr(cls.thread_local, key)
+ except AttributeError:
+ pass # Key doesn't exist, ignore
+
+ @classmethod
+ def get(cls, key: str) -> Any:
+ """Get value from context storage."""
+ if cls.mode == ConcurrencyMode.THREAD:
+ return cls._get_thread_local(key)
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
+
+ @classmethod
+ def set(cls, key: str, val: Any) -> None:
+ """Set value in context storage."""
+ if cls.mode == ConcurrencyMode.THREAD:
+ return cls._set_thread_local(key, val)
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
+
+ @classmethod
+ def clear(cls, key: str) -> None:
+ """Clear value from context storage."""
+ if cls.mode == ConcurrencyMode.THREAD:
+ return cls._del_thread_local(key)
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
+
+ @classmethod
+ def clear_all(cls) -> None:
+ """Clear ALL values from context storage (critical for preventing data leaks).
+
+ This must be called after each task to prevent data leaking between
+ different executions when Celery reuses worker threads.
+ """
+ if cls.mode == ConcurrencyMode.THREAD:
+ # Clear all attributes from thread_local
+ for attr in list(vars(cls.thread_local).keys()):
+ try:
+ delattr(cls.thread_local, attr)
+ except AttributeError:
+ pass # Already cleared, ignore
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
diff --git a/workers/shared/infrastructure/database/__init__.py b/workers/shared/infrastructure/database/__init__.py
new file mode 100644
index 000000000..8b0cf5d1f
--- /dev/null
+++ b/workers/shared/infrastructure/database/__init__.py
@@ -0,0 +1,9 @@
+"""Database infrastructure utilities.
+
+This package provides database connection and utility functionality
+for workers that need direct database access.
+"""
+
+from .utils import WorkerDatabaseUtils as DatabaseUtils
+
+__all__ = ["DatabaseUtils"]
diff --git a/workers/shared/infrastructure/database/utils.py b/workers/shared/infrastructure/database/utils.py
new file mode 100644
index 000000000..1a112be6b
--- /dev/null
+++ b/workers/shared/infrastructure/database/utils.py
@@ -0,0 +1,584 @@
+"""Worker-Compatible Database Utils
+
+This module provides database utilities for workers that replicate the functionality
+of backend/workflow_manager/endpoint_v2/database_utils.py without Django dependencies.
+"""
+
+import datetime
+import json
+from typing import Any
+
+from shared.enums.status_enums import FileProcessingStatus
+
+# Import unstract database connectors
+from unstract.connectors.databases import connectors as db_connectors
+from unstract.connectors.databases.exceptions import UnstractDBConnectorException
+from unstract.connectors.databases.unstract_db import UnstractDB
+from unstract.connectors.exceptions import ConnectorError
+
+from ..logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class DBConnectionClass:
+ """Database connection class constants."""
+
+ SNOWFLAKE = "SnowflakeDB"
+ POSTGRESQL = "PostgreSQLDB"
+ MYSQL = "MySQLDB"
+ BIGQUERY = "BigQueryDB"
+
+
+class TableColumns:
+ """Common table column names."""
+
+ CREATED_BY = "created_by"
+ CREATED_AT = "created_at"
+ METADATA = "metadata"
+ ERROR_MESSAGE = "error_message"
+ STATUS = "status"
+ USER_FIELD_1 = "user_field_1"
+ USER_FIELD_2 = "user_field_2"
+ USER_FIELD_3 = "user_field_3"
+ PERMANENT_COLUMNS = [
+ "created_by",
+ "created_at",
+ "metadata",
+ "error_message",
+ "status",
+ "user_field_1",
+ "user_field_2",
+ "user_field_3",
+ ]
+
+
+class ColumnModes:
+ """Column mode enumeration for data storage."""
+
+ WRITE_JSON_TO_A_SINGLE_COLUMN = "WRITE_JSON_TO_A_SINGLE_COLUMN"
+ SPLIT_JSON_INTO_COLUMNS = "SPLIT_JSON_INTO_COLUMNS"
+
+
+class AgentName:
+ """Agent name constants."""
+
+ UNSTRACT_DBWRITER = "UNSTRACT_DBWRITER"
+
+
+class WorkerDBException(Exception):
+ """Worker database exception."""
+
+ def __init__(self, detail: str):
+ self.detail = detail
+ super().__init__(detail)
+
+
+class WorkerDatabaseUtils:
+ """Worker-compatible database utilities following production patterns."""
+
+ @staticmethod
+ def get_sql_values_for_query(
+ conn_cls: Any,
+ values: dict[str, Any],
+ column_types: dict[str, str],
+ ) -> dict[str, str]:
+ """Making SQL Columns and Values for Query.
+
+ Args:
+ conn_cls (Any): DB Connection class
+ values (Dict[str, Any]): dictionary of columns and values
+ column_types (Dict[str, str]): types of columns
+
+ Returns:
+ Dict[str, str]: SQL values formatted for the specific database type
+
+ """
+ return conn_cls.get_sql_values_for_query(values=values, column_types=column_types)
+
+ @staticmethod
+ def get_column_types(conn_cls: Any, table_name: str) -> Any:
+ """Function to return connector db column and types by calling
+ connector table information schema.
+
+ Args:
+ conn_cls (Any): DB Connection class
+ table_name (str): DB table-name
+
+ Raises:
+ WorkerDBException: Database operation error
+
+ Returns:
+ Any: db column name and db column types of corresponding table
+ """
+ try:
+ return conn_cls.get_information_schema(table_name=table_name)
+ except ConnectorError as e:
+ raise WorkerDBException(detail=e.message) from e
+ except Exception as e:
+ logger.error(
+ f"Error getting db-column-name and db-column-type "
+ f"for {table_name}: {str(e)}"
+ )
+ raise
+
+ @staticmethod
+ def _create_safe_error_json(data_description: str, original_error: Exception) -> dict:
+ """Create a standardized error JSON object that can be safely serialized.
+
+ Args:
+ data_description (str): Description of the data being serialized
+ original_error (Exception): The original exception that occurred
+
+ Returns:
+ dict: A safely serializable JSON object with error details
+ """
+ return {
+ "error": "JSON serialization failed",
+ "error_type": original_error.__class__.__name__,
+ "error_message": str(original_error),
+ "data_type": str(type(original_error)),
+ "data_description": data_description,
+ "timestamp": datetime.datetime.now().isoformat(),
+ }
+
+ @staticmethod
+ def get_columns_and_values(
+ column_mode_str: str,
+ data: Any,
+ file_path: str,
+ execution_id: str,
+ file_path_name: str = "file_path",
+ execution_id_name: str = "execution_id",
+ include_timestamp: bool = False,
+ include_agent: bool = False,
+ agent_name: str | None = AgentName.UNSTRACT_DBWRITER,
+ single_column_name: str = "data",
+ table_info: dict[str, str] | None = None,
+ metadata: dict[str, Any] | None = None,
+ error: str | None = None,
+ ) -> dict[str, Any]:
+ """Generate a dictionary of columns and values based on specified parameters.
+
+ Args:
+ column_mode_str (str): The string representation of the column mode,
+ which determines how data is stored in the dictionary.
+ data (Any): The data to be stored in the dictionary.
+ file_path (str): The file path to include in the data.
+ execution_id (str): The execution ID to include in the data.
+ file_path_name (str, optional): Column name for file path. Defaults to "file_path".
+ execution_id_name (str, optional): Column name for execution ID. Defaults to "execution_id".
+ include_timestamp (bool, optional): Whether to include the
+ current timestamp in the dictionary. Defaults to False.
+ include_agent (bool, optional): Whether to include the agent's name
+ in the dictionary. Defaults to False.
+ agent_name (str, optional): The name of the agent when include_agent
+ is true. Defaults to AgentName.UNSTRACT_DBWRITER.
+ single_column_name (str, optional): The name of the single column
+ when using 'WRITE_JSON_TO_A_SINGLE_COLUMN' mode.
+ Defaults to "data".
+ table_info (dict[str, str], optional): Information about the table
+ to be used for generating the columns and values.
+ Defaults to None.
+ metadata (dict[str, Any], optional): Metadata to be included in the
+ dictionary. Defaults to None.
+ error (str, optional): Error message to be included in the dictionary.
+ Defaults to None.
+
+ Returns:
+ Dict[str, Any]: A dictionary containing columns and values based on
+ the specified parameters.
+ """
+ values: dict[str, Any] = {}
+
+ # Determine column mode
+ column_mode = WorkerDatabaseUtils._determine_column_mode(column_mode_str)
+
+ # Add metadata columns (agent, timestamp)
+ WorkerDatabaseUtils._add_metadata_columns(
+ values, include_agent, agent_name, include_timestamp
+ )
+
+ # Add processing columns (metadata, error, status)
+ WorkerDatabaseUtils._add_processing_columns(values, table_info, metadata, error)
+
+ # Process data based on column mode
+ WorkerDatabaseUtils._process_data_by_mode(
+ values=values,
+ column_mode=column_mode,
+ data=data,
+ single_column_name=single_column_name,
+ table_info=table_info,
+ )
+
+ # Add required identifier columns
+ values[file_path_name] = file_path
+ values[execution_id_name] = execution_id
+
+ return values
+
+ @staticmethod
+ def _determine_column_mode(column_mode_str: str) -> ColumnModes:
+ """Determine column mode from string, defaulting to single column mode."""
+ try:
+ if column_mode_str == ColumnModes.WRITE_JSON_TO_A_SINGLE_COLUMN:
+ return ColumnModes.WRITE_JSON_TO_A_SINGLE_COLUMN
+ elif column_mode_str == ColumnModes.SPLIT_JSON_INTO_COLUMNS:
+ return ColumnModes.SPLIT_JSON_INTO_COLUMNS
+ else:
+ return ColumnModes.WRITE_JSON_TO_A_SINGLE_COLUMN
+ except Exception:
+ # Handle the case where the string is not a valid enum value
+ return ColumnModes.WRITE_JSON_TO_A_SINGLE_COLUMN
+
+ @staticmethod
+ def _has_table_column(table_info: dict[str, str] | None, column_name: str) -> bool:
+ """Check if a column exists in table info (case-insensitive).
+
+ Args:
+ table_info: Dictionary containing table column information
+ column_name: Name of the column to check for existence
+
+ Returns:
+ bool: True if column exists or table_info is None, False otherwise
+ """
+ return (
+ (table_info is None)
+ or any(k.lower() == column_name.lower() for k in table_info)
+ if table_info
+ else True
+ )
+
+ @staticmethod
+ def _add_metadata_columns(
+ values: dict[str, Any],
+ include_agent: bool,
+ agent_name: str | None,
+ include_timestamp: bool,
+ ) -> None:
+ """Add metadata columns (agent, timestamp) to values dictionary."""
+ if include_agent and agent_name:
+ values[TableColumns.CREATED_BY] = agent_name
+
+ if include_timestamp:
+ values[TableColumns.CREATED_AT] = datetime.datetime.now()
+
+ @staticmethod
+ def _add_processing_columns(
+ values: dict[str, Any],
+ table_info: dict[str, str] | None,
+ metadata: dict[str, Any] | None,
+ error: str | None,
+ ) -> None:
+ """Add metadata, error, and status columns to values dictionary.
+
+ Args:
+ values: Dictionary to add columns to
+ table_info: Table column information for existence checking
+ metadata: Metadata to serialize and store
+ error: Error message to store
+ """
+ # Check column existence once
+ has_metadata_col = WorkerDatabaseUtils._has_table_column(
+ table_info, TableColumns.METADATA
+ )
+ has_error_col = WorkerDatabaseUtils._has_table_column(
+ table_info, TableColumns.ERROR_MESSAGE
+ )
+ has_status_col = WorkerDatabaseUtils._has_table_column(
+ table_info, TableColumns.STATUS
+ )
+
+ # Add metadata with safe JSON serialization
+ if metadata and has_metadata_col:
+ try:
+ values[TableColumns.METADATA] = json.dumps(metadata)
+ except (TypeError, ValueError) as e:
+ logger.error(f"Failed to serialize metadata to JSON: {e}")
+ # Create a safe fallback error object
+ fallback_metadata = WorkerDatabaseUtils._create_safe_error_json(
+ "metadata", e
+ )
+ values[TableColumns.METADATA] = json.dumps(fallback_metadata)
+
+ # Add error message
+ if error and has_error_col:
+ values[TableColumns.ERROR_MESSAGE] = error
+
+ # Add status based on error presence
+ if has_status_col:
+ values[TableColumns.STATUS] = (
+ FileProcessingStatus.ERROR if error else FileProcessingStatus.SUCCESS
+ )
+
+ @staticmethod
+ def _process_data_by_mode(
+ values: dict[str, Any],
+ column_mode: ColumnModes,
+ data: Any,
+ single_column_name: str,
+ table_info: dict[str, str] | None = None,
+ ) -> None:
+ """Process data based on the specified column mode."""
+ if column_mode == ColumnModes.WRITE_JSON_TO_A_SINGLE_COLUMN:
+ WorkerDatabaseUtils._process_single_column_mode(
+ values=values,
+ data=data,
+ single_column_name=single_column_name,
+ table_info=table_info,
+ )
+ elif column_mode == ColumnModes.SPLIT_JSON_INTO_COLUMNS:
+ # Note: This function is not used in the current implementation
+ WorkerDatabaseUtils._process_split_column_mode(
+ values=values,
+ data=data,
+ single_column_name=single_column_name,
+ )
+
+ @staticmethod
+ def _process_single_column_mode(
+ values: dict[str, Any],
+ data: Any,
+ single_column_name: str,
+ table_info: dict[str, str] | None = None,
+ ) -> None:
+ """Process data for single column mode."""
+ v2_col_name = f"{single_column_name}_v2"
+ has_v2_col = WorkerDatabaseUtils._has_table_column(table_info, v2_col_name)
+
+ # Safety check: Handle None data (from failed tool executions)
+ if data is None:
+ # Don't add data columns - let database handle as NULL
+ # This prevents 'None' string from being passed to JSON columns
+ return
+
+ if isinstance(data, str):
+ wrapped_dict = {"result": data}
+ values[single_column_name] = wrapped_dict
+ if has_v2_col:
+ values[v2_col_name] = wrapped_dict
+ else:
+ values[single_column_name] = data
+ if has_v2_col:
+ values[v2_col_name] = data
+
+ @staticmethod
+ def _process_split_column_mode(
+ values: dict[str, Any], data: Any, single_column_name: str
+ ) -> None:
+ """Process data for split column mode."""
+ if isinstance(data, dict):
+ values.update(data)
+ elif isinstance(data, str):
+ values[single_column_name] = data
+ else:
+ try:
+ values[single_column_name] = json.dumps(data)
+ except (TypeError, ValueError) as e:
+ logger.error(
+ f"Failed to serialize data to JSON in split column mode: {e}"
+ )
+ # Create a safe fallback error object
+ fallback_data = WorkerDatabaseUtils._create_safe_error_json(
+ "split_column_data", e
+ )
+ values[single_column_name] = json.dumps(fallback_data)
+
+ @staticmethod
+ def get_sql_query_data(
+ conn_cls: Any,
+ table_name: str,
+ values: dict[str, Any],
+ ) -> dict[str, Any]:
+ """Generate SQL columns and values for an insert query based on the
+ provided values and table schema.
+
+ Args:
+ conn_cls: DB connection class
+ table_name (str): The name of the target table for the insert query.
+ values (Dict[str, Any]): A dictionary containing column-value pairs
+ for the insert query.
+
+ Returns:
+ Dict[str, Any]: A dictionary of SQL values suitable for use in an insert query.
+ """
+ column_types: dict[str, str] = WorkerDatabaseUtils.get_column_types(
+ conn_cls=conn_cls, table_name=table_name
+ )
+ sql_columns_and_values = WorkerDatabaseUtils.get_sql_values_for_query(
+ conn_cls=conn_cls,
+ values=values,
+ column_types=column_types,
+ )
+ return sql_columns_and_values
+
+ @staticmethod
+ def execute_write_query(
+ db_class: UnstractDB,
+ engine: Any,
+ table_name: str,
+ sql_keys: list[str],
+ sql_values: list[str],
+ ) -> None:
+ """Execute Insert Query.
+
+ Args:
+ db_class (UnstractDB): Database connection class
+ engine (Any): Database engine
+ table_name (str): table name
+ sql_keys (list[str]): columns
+ sql_values (list[str]): values
+
+ """
+ sql = db_class.get_sql_insert_query(
+ table_name=table_name, sql_keys=sql_keys, sql_values=sql_values
+ )
+
+ logger.debug(f"Inserting into table {table_name} with: {sql} query")
+ logger.debug(f"SQL values: {sql_values}")
+
+ try:
+ db_class.execute_query(
+ engine=engine,
+ sql_query=sql,
+ sql_values=sql_values,
+ table_name=table_name,
+ sql_keys=sql_keys,
+ )
+ except UnstractDBConnectorException as e:
+ raise WorkerDBException(detail=e.detail) from e
+
+ logger.debug(f"Successfully inserted into table {table_name} with: {sql} query")
+
+ @staticmethod
+ def get_db_class(connector_id: str, connector_settings: dict[str, Any]) -> UnstractDB:
+ """Get database class instance for the given connector.
+
+ Args:
+ connector_id (str): The connector identifier (may include UUID or be simple name)
+ connector_settings (Dict[str, Any]): Connector configuration settings
+
+ Returns:
+ UnstractDB: Database connector instance
+ """
+ try:
+ # Use the constant 'CONNECTOR' key to access connector metadata
+ CONNECTOR_KEY = "connector" # Following backend pattern
+
+ logger.debug(f"Looking for connector: {connector_id}")
+ logger.debug(f"Available connectors: {list(db_connectors.keys())}")
+
+ # First try exact match
+ if connector_id in db_connectors:
+ connector_metadata = db_connectors[connector_id]
+ else:
+ # If exact match fails, try to find by prefix (for simple names like 'postgresql')
+ matching_connectors = [
+ key
+ for key in db_connectors.keys()
+ if key.startswith(f"{connector_id}|")
+ ]
+
+ if not matching_connectors:
+ available_types = [key.split("|")[0] for key in db_connectors.keys()]
+ raise WorkerDBException(
+ f"Database connector '{connector_id}' not found. "
+ f"Available types: {available_types}"
+ )
+
+ # Use the first matching connector
+ full_connector_id = matching_connectors[0]
+ connector_metadata = db_connectors[full_connector_id]
+ logger.info(
+ f"Resolved connector '{connector_id}' to '{full_connector_id}'"
+ )
+
+ if "metadata" not in connector_metadata:
+ raise WorkerDBException(
+ f"No metadata found for connector '{connector_id}'"
+ )
+
+ if CONNECTOR_KEY not in connector_metadata["metadata"]:
+ raise WorkerDBException(f"No connector class found for '{connector_id}'")
+
+ connector = connector_metadata["metadata"][CONNECTOR_KEY]
+ connector_class: UnstractDB = connector(connector_settings)
+ logger.info(
+ f"Successfully created database connector instance for '{connector_id}'"
+ )
+ return connector_class
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get database class for connector '{connector_id}': {str(e)}"
+ )
+ raise WorkerDBException(
+ f"Failed to initialize database connector: {str(e)}"
+ ) from e
+
+ @staticmethod
+ def create_table_if_not_exists(
+ db_class: UnstractDB,
+ engine: Any,
+ table_name: str,
+ database_entry: dict[str, Any],
+ ) -> None:
+ """Creates table if not exists.
+
+ Args:
+ db_class (UnstractDB): Type of Unstract DB connector
+ engine (Any): Database engine
+ table_name (str): Name of the table to create
+ database_entry (Dict[str, Any]): Sample data entry for table schema creation
+
+ Raises:
+ WorkerDBException: Database operation error
+ """
+ try:
+ sql = db_class.create_table_query(
+ table=table_name,
+ database_entry=database_entry,
+ permanent_columns=TableColumns.PERMANENT_COLUMNS,
+ )
+ logger.debug(f"Creating table {table_name} with: {sql} query")
+
+ db_class.execute_query(
+ engine=engine, sql_query=sql, sql_values=None, table_name=table_name
+ )
+
+ logger.debug(f"Successfully created table {table_name} with: {sql} query")
+
+ except UnstractDBConnectorException as e:
+ raise WorkerDBException(detail=e.detail) from e
+ except Exception as e:
+ logger.error(f"Failed to create table {table_name}: {str(e)}")
+ raise WorkerDBException(f"Table creation failed: {str(e)}") from e
+
+ @staticmethod
+ def migrate_table_to_v2(
+ db_class: UnstractDB,
+ engine: Any,
+ table_name: str,
+ column_name: str,
+ ) -> dict[str, str]:
+ """Migrate table to v2 by adding _v2 columns.
+
+ Args:
+ db_class (UnstractDB): DB Connection class
+ engine (Any): Database engine
+ table_name (str): Name of the table to migrate
+ column_name (str): Base column name for v2 migration
+ Returns:
+ dict[str, str]: Updated table information schema
+ Raises:
+ UnstractDBException: If migration fails
+ """
+ try:
+ result: dict[str, str] = db_class.migrate_table_to_v2(
+ table_name=table_name,
+ column_name=column_name,
+ engine=engine,
+ )
+ return result
+ except UnstractDBConnectorException as e:
+ raise WorkerDBException(detail=e.detail) from e
diff --git a/workers/shared/infrastructure/logging/__init__.py b/workers/shared/infrastructure/logging/__init__.py
new file mode 100644
index 000000000..e41cde3a1
--- /dev/null
+++ b/workers/shared/infrastructure/logging/__init__.py
@@ -0,0 +1,18 @@
+"""Logging infrastructure for workers.
+
+This package provides comprehensive logging functionality including
+configuration, utilities, helpers, and workflow-specific logging.
+"""
+
+from . import helpers
+from .logger import WorkerLogger, log_context, monitor_performance, with_execution_context
+from .workflow_logger import WorkerWorkflowLogger
+
+__all__ = [
+ "helpers",
+ "WorkerLogger",
+ "log_context",
+ "monitor_performance",
+ "with_execution_context",
+ "WorkerWorkflowLogger",
+]
diff --git a/workers/shared/infrastructure/logging/config.py b/workers/shared/infrastructure/logging/config.py
new file mode 100644
index 000000000..95319545b
--- /dev/null
+++ b/workers/shared/infrastructure/logging/config.py
@@ -0,0 +1,68 @@
+"""Shared logging configuration for workers to match Django backend format."""
+
+import logging
+import logging.config
+import os
+
+# Default log level from environment
+DEFAULT_LOG_LEVEL = os.environ.get("DEFAULT_LOG_LEVEL", "INFO")
+
+
+class WorkerFieldFilter(logging.Filter):
+ """Filter to add missing fields for worker logging."""
+
+ def filter(self, record):
+ # Add missing fields with default values
+ for attr in ["request_id", "otelTraceID", "otelSpanID"]:
+ if not hasattr(record, attr):
+ setattr(record, attr, "-")
+ return True
+
+
+def setup_worker_logging():
+ """Setup logging configuration that matches Django backend format."""
+ logging_config = {
+ "version": 1,
+ "disable_existing_loggers": False,
+ "filters": {
+ "worker_fields": {"()": "shared.logging_config.WorkerFieldFilter"},
+ },
+ "formatters": {
+ "enriched": {
+ "format": (
+ "%(levelname)s : [%(asctime)s]"
+ "{module:%(module)s process:%(process)d "
+ "thread:%(thread)d request_id:%(request_id)s "
+ "trace_id:%(otelTraceID)s span_id:%(otelSpanID)s} :- %(message)s"
+ ),
+ },
+ "simple": {
+ "format": "{levelname} {message}",
+ "style": "{",
+ },
+ },
+ "handlers": {
+ "console": {
+ "level": DEFAULT_LOG_LEVEL,
+ "class": "logging.StreamHandler",
+ "filters": ["worker_fields"],
+ "formatter": "enriched",
+ },
+ },
+ "root": {
+ "handlers": ["console"],
+ "level": DEFAULT_LOG_LEVEL,
+ },
+ }
+
+ # Configure logging
+ logging.config.dictConfig(logging_config)
+
+ return logging.getLogger()
+
+
+def get_worker_logger(name: str = None) -> logging.Logger:
+ """Get a logger configured for worker use."""
+ if name:
+ return logging.getLogger(name)
+ return logging.getLogger()
diff --git a/workers/shared/infrastructure/logging/helpers.py b/workers/shared/infrastructure/logging/helpers.py
new file mode 100644
index 000000000..23c451c5b
--- /dev/null
+++ b/workers/shared/infrastructure/logging/helpers.py
@@ -0,0 +1,266 @@
+"""Logging Helper Functions
+
+Utility functions to reduce repetitive null checking and make logging code cleaner and more readable.
+"""
+
+from unstract.workflow_execution.enums import LogLevel, LogStage
+
+from .workflow_logger import WorkerWorkflowLogger
+
+
+def safe_publish_processing_start(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ file_name: str,
+ current_file_idx: int,
+ total_files: int,
+ execution_id: str | None = None,
+ organization_id: str | None = None,
+) -> None:
+ """Safely publish processing start log with proper null checking.
+
+ Args:
+ workflow_logger: WorkerWorkflowLogger instance (can be None)
+ file_execution_id: File execution ID for file-specific logging (can be None)
+ file_name: Name of the file being processed
+ current_file_idx: Current file index
+ total_files: Total number of files
+ execution_id: Execution ID for fallback logger creation
+ organization_id: Organization ID for fallback logger creation
+ """
+ if not workflow_logger:
+ return
+
+ if file_execution_id:
+ # Create file-specific logger to associate logs with WorkflowFileExecution
+ file_logger = workflow_logger.create_file_logger(file_execution_id)
+ file_logger.publish_processing_start(file_name, current_file_idx, total_files)
+ else:
+ # Fallback to execution-level logging if no file_execution_id
+ workflow_logger.publish_processing_start(file_name, current_file_idx, total_files)
+
+
+def safe_publish_processing_complete(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ file_name: str,
+ success: bool,
+ error: str | None = None,
+ execution_id: str | None = None,
+ organization_id: str | None = None,
+) -> None:
+ """Safely publish processing completion log with proper null checking.
+
+ Args:
+ workflow_logger: WorkerWorkflowLogger instance (can be None)
+ file_execution_id: File execution ID for file-specific logging (can be None)
+ file_name: Name of the processed file
+ success: Whether processing was successful
+ error: Error message if processing failed
+ execution_id: Execution ID for fallback logger creation
+ organization_id: Organization ID for fallback logger creation
+ """
+ if not workflow_logger:
+ return
+
+ if file_execution_id:
+ # Create file-specific logger for this completion
+ file_logger = workflow_logger.create_file_logger(file_execution_id)
+ file_logger.publish_processing_complete(file_name, success, error)
+ else:
+ # Fallback to execution-level logging
+ workflow_logger.publish_processing_complete(file_name, success, error)
+
+
+def safe_publish_log(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ message: str,
+ level: LogLevel = LogLevel.INFO,
+ execution_id: str | None = None,
+ organization_id: str | None = None,
+) -> None:
+ """Safely publish a general log message with proper null checking.
+
+ Args:
+ workflow_logger: WorkerWorkflowLogger instance (can be None)
+ file_execution_id: File execution ID for file-specific logging (can be None)
+ message: Log message to publish
+ level: Log level (INFO, ERROR, etc.)
+ execution_id: Execution ID for fallback logger creation
+ organization_id: Organization ID for fallback logger creation
+ """
+ if not workflow_logger:
+ return
+
+ if file_execution_id:
+ # Create file-specific logger for this message
+ file_logger = workflow_logger.create_file_logger(file_execution_id)
+ file_logger.publish_log(message, level)
+ else:
+ # Fallback to execution-level logging
+ workflow_logger.publish_log(message, level)
+
+
+def create_file_logger_safe(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ execution_id: str | None = None,
+ organization_id: str | None = None,
+ log_stage: LogStage = LogStage.PROCESSING,
+) -> WorkerWorkflowLogger | None:
+ """Safely create a file-specific logger with null checking.
+
+ Args:
+ workflow_logger: Parent workflow logger (can be None)
+ file_execution_id: File execution ID (can be None)
+ execution_id: Execution ID for fallback logger creation
+ organization_id: Organization ID for fallback logger creation
+ log_stage: Log stage for new logger creation
+
+ Returns:
+ File-specific logger or None if inputs are invalid
+ """
+ if not workflow_logger or not file_execution_id:
+ return workflow_logger # Return parent logger or None
+
+ try:
+ return workflow_logger.create_file_logger(file_execution_id)
+ except Exception:
+ # If file logger creation fails, return parent logger
+ return workflow_logger
+
+
+def ensure_workflow_logger(
+ workflow_logger: WorkerWorkflowLogger | None,
+ execution_id: str,
+ organization_id: str | None = None,
+ pipeline_id: str | None = None,
+ log_stage: LogStage = LogStage.PROCESSING,
+) -> WorkerWorkflowLogger | None:
+ """Ensure a workflow logger exists, creating one if needed.
+
+ Args:
+ workflow_logger: Existing workflow logger (can be None)
+ execution_id: Execution ID for logger creation
+ organization_id: Organization ID for logger creation
+ pipeline_id: Pipeline ID for logger creation
+ log_stage: Log stage for logger creation
+
+ Returns:
+ WorkerWorkflowLogger instance or None if creation fails
+ """
+ if workflow_logger:
+ return workflow_logger
+
+ if not execution_id:
+ return None
+
+ try:
+ return WorkerWorkflowLogger(
+ execution_id=execution_id,
+ log_stage=log_stage,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+ except Exception:
+ return None
+
+
+def with_file_logging(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ execution_id: str | None = None,
+ organization_id: str | None = None,
+):
+ """Context manager for file-specific logging operations.
+
+ Usage:
+ with with_file_logging(workflow_logger, file_execution_id) as logger:
+ if logger:
+ logger.publish_log("Processing file...")
+
+ Args:
+ workflow_logger: Parent workflow logger (can be None)
+ file_execution_id: File execution ID (can be None)
+ execution_id: Execution ID for fallback
+ organization_id: Organization ID for fallback
+
+ Returns:
+ Context manager that yields appropriate logger or None
+ """
+
+ class LoggingContext:
+ def __init__(self, logger):
+ self.logger = logger
+
+ def __enter__(self):
+ return self.logger
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ pass
+
+ # Return file-specific logger if available, otherwise parent logger
+ if workflow_logger and file_execution_id:
+ try:
+ file_logger = workflow_logger.create_file_logger(file_execution_id)
+ return LoggingContext(file_logger)
+ except Exception:
+ pass
+
+ return LoggingContext(workflow_logger)
+
+
+# Convenience functions for common logging patterns
+def log_file_processing_start(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ file_name: str,
+ current_idx: int,
+ total_files: int,
+) -> None:
+ """Log file processing start with automatic null checking."""
+ safe_publish_processing_start(
+ workflow_logger, file_execution_id, file_name, current_idx, total_files
+ )
+
+
+def log_file_processing_success(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ file_name: str,
+) -> None:
+ """Log file processing success with automatic null checking."""
+ safe_publish_processing_complete(
+ workflow_logger, file_execution_id, file_name, success=True
+ )
+
+
+def log_file_processing_error(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ file_name: str,
+ error: str,
+) -> None:
+ """Log file processing error with automatic null checking."""
+ safe_publish_processing_complete(
+ workflow_logger, file_execution_id, file_name, success=False, error=error
+ )
+
+
+def log_file_info(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ message: str,
+) -> None:
+ """Log file info message with automatic null checking."""
+ safe_publish_log(workflow_logger, file_execution_id, message, LogLevel.INFO)
+
+
+def log_file_error(
+ workflow_logger: WorkerWorkflowLogger | None,
+ file_execution_id: str | None,
+ message: str,
+) -> None:
+ """Log file error message with automatic null checking."""
+ safe_publish_log(workflow_logger, file_execution_id, message, LogLevel.ERROR)
diff --git a/workers/shared/infrastructure/logging/logger.py b/workers/shared/infrastructure/logging/logger.py
new file mode 100644
index 000000000..2375bdfef
--- /dev/null
+++ b/workers/shared/infrastructure/logging/logger.py
@@ -0,0 +1,701 @@
+"""Logging and Monitoring Utilities for Workers
+
+Provides structured logging, performance monitoring, and metrics collection for workers.
+"""
+
+import functools
+import json
+import logging
+import os
+import sys
+import time
+import traceback
+from collections.abc import Callable
+from contextlib import contextmanager
+from dataclasses import asdict, dataclass
+from datetime import UTC, datetime
+from threading import local
+from typing import Any
+
+# Thread-local storage for context
+_context = local()
+
+
+@dataclass
+class LogContext:
+ """Context information for structured logging."""
+
+ worker_name: str | None = None
+ task_id: str | None = None
+ execution_id: str | None = None
+ organization_id: str | None = None
+ correlation_id: str | None = None
+ request_id: str | None = None
+
+
+class WorkerFieldFilter(logging.Filter):
+ """Filter to add missing fields for worker logging."""
+
+ def filter(self, record):
+ # Add missing fields with default values to match Django backend
+ for attr in ["request_id", "otelTraceID", "otelSpanID"]:
+ if not hasattr(record, attr):
+ setattr(record, attr, "-")
+ return True
+
+
+class DjangoStyleFormatter(logging.Formatter):
+ """Custom formatter to match Django backend logging format exactly."""
+
+ def __init__(self, include_context: bool = True):
+ """Initialize formatter.
+
+ Args:
+ include_context: Whether to include thread-local context in logs
+ """
+ # Use Django backend's exact format
+ format_string = (
+ "%(levelname)s : [%(asctime)s]"
+ "{module:%(module)s process:%(process)d "
+ "thread:%(thread)d request_id:%(request_id)s "
+ "trace_id:%(otelTraceID)s span_id:%(otelSpanID)s} :- %(message)s"
+ )
+ super().__init__(fmt=format_string)
+ self.include_context = include_context
+
+
+class StructuredFormatter(logging.Formatter):
+ """Custom formatter for structured JSON logging."""
+
+ def __init__(self, include_context: bool = True):
+ """Initialize formatter.
+
+ Args:
+ include_context: Whether to include thread-local context in logs
+ """
+ super().__init__()
+ self.include_context = include_context
+
+ def format(self, record: logging.LogRecord) -> str:
+ """Format log record as structured JSON."""
+ # Base log entry
+ log_entry = {
+ "timestamp": datetime.now(UTC).isoformat() + "Z",
+ "level": record.levelname,
+ "logger": record.name,
+ "message": record.getMessage(),
+ "module": record.module,
+ "function": record.funcName,
+ "line": record.lineno,
+ "process": record.process,
+ "thread": record.thread,
+ }
+
+ # Add exception information if present
+ if record.exc_info:
+ log_entry["exception"] = {
+ "type": record.exc_info[0].__name__,
+ "message": str(record.exc_info[1]),
+ "traceback": traceback.format_exception(*record.exc_info),
+ }
+
+ # Add extra fields from log record
+ extra_fields = {}
+ for key, value in record.__dict__.items():
+ if key not in {
+ "name",
+ "msg",
+ "args",
+ "levelname",
+ "levelno",
+ "pathname",
+ "filename",
+ "module",
+ "lineno",
+ "funcName",
+ "created",
+ "msecs",
+ "relativeCreated",
+ "thread",
+ "threadName",
+ "processName",
+ "process",
+ "getMessage",
+ "exc_info",
+ "exc_text",
+ "stack_info",
+ }:
+ extra_fields[key] = value
+
+ if extra_fields:
+ log_entry["extra"] = extra_fields
+
+ # Add context information if available and enabled
+ if self.include_context and hasattr(_context, "log_context"):
+ context_dict = asdict(_context.log_context)
+ # Only include non-None values
+ context_dict = {k: v for k, v in context_dict.items() if v is not None}
+ if context_dict:
+ log_entry["context"] = context_dict
+
+ return json.dumps(log_entry, default=str)
+
+
+class WorkerLogger:
+ """Enhanced logger for worker processes with structured logging and context management."""
+
+ _loggers: dict[str, logging.Logger] = {}
+ _configured = False
+
+ @classmethod
+ def configure(
+ cls,
+ log_level: str = "INFO",
+ log_format: str = "structured",
+ log_file: str | None = None,
+ worker_name: str | None = None,
+ ):
+ """Configure global logging settings.
+
+ Args:
+ log_level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
+ log_format: Log format ('structured' for JSON, 'simple' for text)
+ log_file: Optional log file path
+ worker_name: Worker name for context
+ """
+ if cls._configured:
+ return
+
+ # Set root logger level
+ root_logger = logging.getLogger()
+ root_logger.setLevel(getattr(logging, log_level.upper()))
+
+ # Clear existing handlers
+ root_logger.handlers.clear()
+
+ # Choose formatter
+ if log_format.lower() == "structured":
+ formatter = StructuredFormatter()
+ elif log_format.lower() == "django":
+ formatter = DjangoStyleFormatter()
+ else:
+ formatter = logging.Formatter(
+ "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
+ )
+
+ # Console handler
+ console_handler = logging.StreamHandler(sys.stdout)
+ console_handler.setFormatter(formatter)
+
+ # Add filter for Django-style format to ensure required fields are present
+ if log_format.lower() == "django":
+ console_handler.addFilter(WorkerFieldFilter())
+
+ root_logger.addHandler(console_handler)
+
+ # File handler if specified
+ if log_file:
+ file_handler = logging.FileHandler(log_file)
+ file_handler.setFormatter(formatter)
+
+ # Add filter for Django-style format to ensure required fields are present
+ if log_format.lower() == "django":
+ file_handler.addFilter(WorkerFieldFilter())
+
+ root_logger.addHandler(file_handler)
+
+ # Set worker context if provided
+ if worker_name:
+ cls.set_context(LogContext(worker_name=worker_name))
+
+ # Suppress only generic HTTP/network libraries that are universally noisy
+ # Cloud-specific SDK logging is handled by each connector
+ logging.getLogger("urllib3").setLevel(logging.WARNING)
+ logging.getLogger("requests").setLevel(logging.WARNING)
+ logging.getLogger("httpx").setLevel(logging.WARNING)
+
+ cls._configured = True
+
+ @classmethod
+ def get_logger(cls, name: str) -> logging.Logger:
+ """Get or create a logger instance.
+
+ Args:
+ name: Logger name (typically __name__)
+
+ Returns:
+ Logger instance
+ """
+ if name not in cls._loggers:
+ logger = logging.getLogger(name)
+ cls._loggers[name] = logger
+
+ return cls._loggers[name]
+
+ @classmethod
+ def setup(cls, worker_type) -> logging.Logger:
+ """Centralized setup for worker logging using WorkerType enum.
+
+ Args:
+ worker_type: WorkerType enum instance
+
+ Returns:
+ Configured logger for the worker
+
+ Note:
+ This method uses the WorkerRegistry to get logging configuration,
+ ensuring consistency across all workers.
+ """
+ from shared.enums.worker_enums import WorkerType
+ from shared.worker_registry import WorkerRegistry
+
+ # Validate worker_type
+ if not isinstance(worker_type, WorkerType):
+ raise TypeError(f"Expected WorkerType enum, got {type(worker_type)}")
+
+ # Get logging config from registry
+ logging_config = WorkerRegistry.get_logging_config(worker_type)
+
+ # Configure logging with registry settings
+ cls.configure(
+ log_level=os.getenv("LOG_LEVEL", logging_config.get("log_level", "INFO")),
+ log_format=os.getenv(
+ "LOG_FORMAT", logging_config.get("log_format", "structured")
+ ),
+ worker_name=worker_type.to_worker_name(),
+ )
+
+ # Return logger for the worker
+ return cls.get_logger(worker_type.to_worker_name())
+
+ @classmethod
+ def set_context(cls, context: LogContext):
+ """Set thread-local logging context."""
+ _context.log_context = context
+
+ @classmethod
+ def update_context(cls, **kwargs):
+ """Update thread-local logging context."""
+ if not hasattr(_context, "log_context"):
+ _context.log_context = LogContext()
+
+ for key, value in kwargs.items():
+ if hasattr(_context.log_context, key):
+ setattr(_context.log_context, key, value)
+
+ @classmethod
+ def clear_context(cls):
+ """Clear thread-local logging context."""
+ if hasattr(_context, "log_context"):
+ delattr(_context, "log_context")
+
+ @classmethod
+ def get_context(cls) -> LogContext | None:
+ """Get current thread-local logging context."""
+ return getattr(_context, "log_context", None)
+
+
+@dataclass
+class PerformanceMetrics:
+ """Performance metrics for function execution."""
+
+ function_name: str
+ execution_time: float
+ success: bool
+ error_type: str | None = None
+ error_message: str | None = None
+ memory_usage: float | None = None
+ start_time: datetime | None = None
+ end_time: datetime | None = None
+
+
+class PerformanceMonitor:
+ """Performance monitoring utilities for tracking function execution metrics."""
+
+ def __init__(self, logger: logging.Logger | None = None):
+ """Initialize performance monitor.
+
+ Args:
+ logger: Logger instance. Uses default if None.
+ """
+ self.logger = logger or WorkerLogger.get_logger(__name__)
+ self.metrics: dict[str, list] = {}
+
+ def __call__(self, func: Callable) -> Callable:
+ """Decorator to monitor function performance."""
+
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ return self.monitor_execution(func, *args, **kwargs)
+
+ return wrapper
+
+ def monitor_execution(self, func: Callable, *args, **kwargs) -> Any:
+ """Monitor function execution and collect metrics.
+
+ Args:
+ func: Function to monitor
+ *args: Function arguments
+ **kwargs: Function keyword arguments
+
+ Returns:
+ Function result
+ """
+ start_time = time.time()
+ start_datetime = datetime.now(UTC)
+ function_name = f"{func.__module__}.{func.__name__}"
+
+ try:
+ # Get memory usage before execution (if psutil available)
+ memory_before = self._get_memory_usage()
+
+ self.logger.debug(f"Starting execution of {function_name}")
+
+ # Execute function
+ result = func(*args, **kwargs)
+
+ # Calculate metrics
+ end_time = time.time()
+ end_datetime = datetime.now(UTC)
+ execution_time = end_time - start_time
+ memory_after = self._get_memory_usage()
+ memory_usage = (
+ memory_after - memory_before if memory_before and memory_after else None
+ )
+
+ # Create metrics record
+ metrics = PerformanceMetrics(
+ function_name=function_name,
+ execution_time=execution_time,
+ success=True,
+ memory_usage=memory_usage,
+ start_time=start_datetime,
+ end_time=end_datetime,
+ )
+
+ # Log successful execution
+ self.logger.info(
+ f"Function {function_name} completed successfully",
+ extra={
+ "execution_time": execution_time,
+ "memory_usage": memory_usage,
+ "performance_metrics": asdict(metrics),
+ },
+ )
+
+ # Store metrics
+ self._store_metrics(metrics)
+
+ return result
+
+ except Exception as e:
+ # Calculate metrics for failed execution
+ end_time = time.time()
+ end_datetime = datetime.now(UTC)
+ execution_time = end_time - start_time
+
+ metrics = PerformanceMetrics(
+ function_name=function_name,
+ execution_time=execution_time,
+ success=False,
+ error_type=type(e).__name__,
+ error_message=str(e),
+ start_time=start_datetime,
+ end_time=end_datetime,
+ )
+
+ # Log failed execution
+ self.logger.error(
+ f"Function {function_name} failed after {execution_time:.3f}s",
+ extra={
+ "execution_time": execution_time,
+ "error_type": type(e).__name__,
+ "error_message": str(e),
+ "performance_metrics": asdict(metrics),
+ },
+ exc_info=True,
+ )
+
+ # Store metrics
+ self._store_metrics(metrics)
+
+ raise
+
+ def _get_memory_usage(self) -> float | None:
+ """Get current memory usage in MB."""
+ try:
+ import psutil
+
+ process = psutil.Process(os.getpid())
+ return process.memory_info().rss / 1024 / 1024 # Convert to MB
+ except ImportError:
+ return None
+ except Exception:
+ return None
+
+ def _store_metrics(self, metrics: PerformanceMetrics):
+ """Store metrics for later analysis."""
+ function_name = metrics.function_name
+ if function_name not in self.metrics:
+ self.metrics[function_name] = []
+
+ self.metrics[function_name].append(metrics)
+
+ # Keep only last 100 metrics per function to prevent memory bloat
+ if len(self.metrics[function_name]) > 100:
+ self.metrics[function_name] = self.metrics[function_name][-100:]
+
+ def get_metrics(self, function_name: str | None = None) -> dict[str, Any]:
+ """Get performance metrics.
+
+ Args:
+ function_name: Specific function name. Returns all if None.
+
+ Returns:
+ Metrics dictionary
+ """
+ if function_name:
+ function_metrics = self.metrics.get(function_name, [])
+ else:
+ function_metrics = []
+ for metrics_list in self.metrics.values():
+ function_metrics.extend(metrics_list)
+
+ if not function_metrics:
+ return {}
+
+ # Calculate aggregated metrics
+ total_executions = len(function_metrics)
+ successful_executions = sum(1 for m in function_metrics if m.success)
+ failed_executions = total_executions - successful_executions
+
+ execution_times = [m.execution_time for m in function_metrics]
+ avg_execution_time = sum(execution_times) / len(execution_times)
+ min_execution_time = min(execution_times)
+ max_execution_time = max(execution_times)
+
+ return {
+ "function_name": function_name,
+ "total_executions": total_executions,
+ "successful_executions": successful_executions,
+ "failed_executions": failed_executions,
+ "success_rate": successful_executions / total_executions
+ if total_executions > 0
+ else 0,
+ "avg_execution_time": avg_execution_time,
+ "min_execution_time": min_execution_time,
+ "max_execution_time": max_execution_time,
+ "recent_metrics": [
+ asdict(m) for m in function_metrics[-10:]
+ ], # Last 10 executions
+ }
+
+ def get_summary(self) -> dict[str, Any]:
+ """Get summary of all monitored functions."""
+ summary = {}
+ for function_name in self.metrics:
+ summary[function_name] = self.get_metrics(function_name)
+
+ return summary
+
+
+@contextmanager
+def log_context(**kwargs):
+ """Context manager for temporary logging context.
+
+ Usage:
+ with log_context(task_id='123', execution_id='456'):
+ logger.info("This will include context")
+ """
+ # Save current context
+ original_context = WorkerLogger.get_context()
+
+ try:
+ # Update context
+ WorkerLogger.update_context(**kwargs)
+ yield
+ finally:
+ # Restore original context
+ if original_context:
+ WorkerLogger.set_context(original_context)
+ else:
+ WorkerLogger.clear_context()
+
+
+def with_execution_context(func: Callable) -> Callable:
+ """Decorator to automatically set up logging context for execution functions.
+
+ This decorator extracts common execution context parameters from function arguments
+ and sets up logging context automatically, eliminating the need for repetitive
+ log_context() usage in task functions.
+
+ Expected function signature patterns:
+ - func(self, schema_name, workflow_id, execution_id, pipeline_id=None, ...)
+ - func(self, schema_name, execution_id, workflow_id, organization_id=None, ...)
+
+ Args:
+ func: The function to wrap with execution context
+
+ Returns:
+ Wrapped function with automatic logging context setup
+
+ Usage:
+ @with_execution_context
+ def my_task(self, schema_name: str, workflow_id: str, execution_id: str, ...):
+ # Function body - logging context is automatically available
+ logger.info("This will include task_id, execution_id, etc.")
+ """
+ from functools import wraps
+
+ @wraps(func)
+ def wrapper(task_instance, *args, **kwargs) -> Any:
+ # Extract task_id from Celery task instance
+ task_id = (
+ getattr(task_instance.request, "id", None)
+ if hasattr(task_instance, "request")
+ else None
+ )
+
+ # Extract common context parameters from arguments
+ # Handle different argument patterns used across tasks
+ context = {"task_id": task_id}
+
+ if args:
+ # Most common pattern: (schema_name, workflow_id, execution_id, ...)
+ if len(args) >= 1:
+ schema_name = args[0]
+ context["organization_id"] = schema_name
+
+ if len(args) >= 2:
+ # Could be workflow_id or execution_id depending on task
+ if len(args) >= 3:
+ # Pattern: (schema_name, workflow_id, execution_id, ...)
+ context["workflow_id"] = args[1]
+ context["execution_id"] = args[2]
+ else:
+ # Pattern: (schema_name, execution_id, ...)
+ context["execution_id"] = args[1]
+
+ if len(args) >= 4:
+ # Check if 4th argument is pipeline_id or another param
+ pipeline_id = (
+ args[3] if args[3] is not None else kwargs.get("pipeline_id")
+ )
+ if pipeline_id:
+ context["pipeline_id"] = pipeline_id
+
+ # Extract additional context from kwargs
+ for key in ["workflow_id", "execution_id", "pipeline_id", "organization_id"]:
+ if key in kwargs and kwargs[key] is not None:
+ context[key] = kwargs[key]
+
+ # Remove None values from context
+ context = {k: v for k, v in context.items() if v is not None}
+
+ # Execute function with logging context
+ with log_context(**context):
+ return func(task_instance, *args, **kwargs)
+
+ return wrapper
+
+
+def logged_execution(logger: logging.Logger | None = None):
+ """Decorator for automatic logging of function execution.
+
+ Args:
+ logger: Logger instance. Uses default if None.
+
+ Returns:
+ Decorated function
+ """
+
+ def decorator(func: Callable) -> Callable:
+ actual_logger = logger or WorkerLogger.get_logger(func.__module__)
+
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ function_name = f"{func.__module__}.{func.__name__}"
+ actual_logger.debug(f"Starting execution of {function_name}")
+
+ try:
+ result = func(*args, **kwargs)
+ actual_logger.debug(f"Successfully completed {function_name}")
+ return result
+ except Exception as e:
+ actual_logger.error(
+ f"Function {function_name} failed: {e}", exc_info=True
+ )
+ raise
+
+ return wrapper
+
+ return decorator
+
+
+# Create global performance monitor instance
+performance_monitor = PerformanceMonitor()
+
+
+# Convenience decorators
+def monitor_performance(func: Callable) -> Callable:
+ """Decorator for performance monitoring."""
+ return performance_monitor(func)
+
+
+def log_execution(func: Callable) -> Callable:
+ """Decorator for execution logging."""
+ return logged_execution()(func)
+
+
+# Dataclass/Dictionary Access Utilities
+
+
+def safe_get_attr(obj: Any, key: str, default: Any = None) -> Any:
+ """Safely get value from object using both attribute and dictionary access patterns.
+
+ This utility handles the common pattern where objects may be either dataclass instances
+ or dictionaries, providing consistent access regardless of the actual type.
+
+ Args:
+ obj: Object to get value from (dataclass instance or dictionary)
+ key: Key/attribute name to access
+ default: Default value if key/attribute not found
+
+ Returns:
+ Value from object or default if not found
+
+ Examples:
+ >>> safe_get_attr(WorkerFileData(execution_id="123"), "execution_id")
+ "123"
+ >>> safe_get_attr({"execution_id": "456"}, "execution_id")
+ "456"
+ >>> safe_get_attr({}, "missing_key", "default")
+ "default"
+ """
+ # First try attribute access (for dataclass objects)
+ if hasattr(obj, key):
+ return getattr(obj, key, default)
+ # Then try dictionary access
+ elif isinstance(obj, dict):
+ return obj.get(key, default)
+ # Fallback to default
+ else:
+ return default
+
+
+def ensure_dict_access(obj: Any, keys: list, default: Any = None) -> dict[str, Any]:
+ """Extract multiple values from object using safe access patterns.
+
+ Args:
+ obj: Object to extract values from
+ keys: List of keys/attributes to extract
+ default: Default value for missing keys
+
+ Returns:
+ Dictionary with extracted values
+
+ Example:
+ >>> ensure_dict_access(file_data, ["execution_id", "workflow_id", "organization_id"])
+ {'execution_id': '123', 'workflow_id': '456', 'organization_id': 'org_789'}
+ """
+ return {key: safe_get_attr(obj, key, default) for key in keys}
diff --git a/workers/shared/infrastructure/logging/workflow_logger.py b/workers/shared/infrastructure/logging/workflow_logger.py
new file mode 100644
index 000000000..1f7f57223
--- /dev/null
+++ b/workers/shared/infrastructure/logging/workflow_logger.py
@@ -0,0 +1,557 @@
+"""Worker Workflow Logger - WebSocket Log Publisher for Workers
+
+This module provides WebSocket logging functionality for workers, matching
+the backend's workflow_log.py functionality but adapted for the worker environment.
+
+Usage:
+ # Initialize logger
+ workflow_logger = WorkerWorkflowLogger(
+ execution_id=execution_id,
+ log_stage=LogStage.PROCESSING,
+ file_execution_id=file_execution_id,
+ organization_id=organization_id
+ )
+
+ # Send logs to UI via WebSocket
+ workflow_logger.log_info(logger, "Processing file batch...")
+ workflow_logger.log_error(logger, "Failed to process file")
+ workflow_logger.publish_update_log(LogState.RUNNING, "File processing started")
+"""
+
+import logging
+from typing import TYPE_CHECKING
+
+from unstract.core.pubsub_helper import LogPublisher
+from unstract.workflow_execution.enums import (
+ LogComponent,
+ LogLevel,
+ LogStage,
+ LogState,
+)
+
+from .logger import WorkerLogger
+
+if TYPE_CHECKING:
+ from shared.api import InternalAPIClient
+
+# Get worker logger for internal logging
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WorkerWorkflowLogger:
+ """Worker-compatible workflow logger that sends logs to UI via WebSocket.
+
+ This mirrors the backend's WorkflowLog class but adapted for workers:
+ - Uses worker StateStore equivalent
+ - Compatible with worker environment variables
+ - Maintains the same API for easy migration
+ """
+
+ def __init__(
+ self,
+ execution_id: str,
+ log_stage: LogStage,
+ file_execution_id: str | None = None,
+ organization_id: str | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ ):
+ """Initialize workflow logger for worker environment.
+
+ Args:
+ execution_id: Workflow execution ID
+ log_stage: Current processing stage (SOURCE, DESTINATION, PROCESSING, etc.)
+ file_execution_id: Optional file execution ID for file-specific logs
+ organization_id: Organization ID for message routing
+ pipeline_id: Pipeline ID for message routing (fallback)
+ log_events_id: Explicit log events ID (overrides other channel logic)
+ """
+ # Try to get log_events_id from worker StateStore if not provided
+ if not log_events_id:
+ try:
+ # Try to import and use the worker's StateStore equivalent
+ from ..context import StateStore
+
+ log_events_id = StateStore.get("LOG_EVENTS_ID")
+ except ImportError:
+ logger.debug(
+ "StateStore not available in worker, using pipeline_id for messaging channel"
+ )
+
+ # Determine messaging channel (matches backend logic)
+ self.messaging_channel = log_events_id if log_events_id else pipeline_id
+ self.execution_id = str(execution_id)
+ self.file_execution_id = str(file_execution_id) if file_execution_id else None
+ self.organization_id = str(organization_id) if organization_id else None
+ self.log_stage = log_stage
+
+ if not self.messaging_channel:
+ logger.warning(
+ f"No messaging channel available for execution {execution_id}. "
+ f"WebSocket logs may not be delivered to UI."
+ )
+
+ def publish_log(
+ self,
+ message: str,
+ level: LogLevel = LogLevel.INFO,
+ step: int | None = None,
+ cost_type: str | None = None,
+ cost_units: str | None = None,
+ cost_value: float | None = None,
+ ) -> None:
+ """Publish a log message to the WebSocket channel.
+
+ Args:
+ message: Log message to display in UI
+ level: Log level (INFO, ERROR)
+ step: Optional step number for multi-step processes
+ cost_type: Optional cost tracking type
+ cost_units: Optional cost units
+ cost_value: Optional cost value
+ """
+ try:
+ if not self.messaging_channel:
+ logger.warning(f"No messaging channel, skipping WebSocket log: {message}")
+ return
+
+ log_details = LogPublisher.log_workflow(
+ stage=self.log_stage.value,
+ message=message,
+ level=level.value,
+ step=step,
+ execution_id=self.execution_id,
+ file_execution_id=self.file_execution_id,
+ organization_id=self.organization_id,
+ cost_type=cost_type,
+ cost_units=cost_units,
+ cost_value=cost_value,
+ )
+
+ # Publish to WebSocket channel
+ success = LogPublisher.publish(self.messaging_channel, log_details)
+ if not success:
+ logger.warning(f"Failed to publish WebSocket log: {message}")
+
+ except Exception as e:
+ logger.error(f"Error publishing WebSocket log: {e}")
+
+ def log_error(self, worker_logger: logging.Logger, message: str, **kwargs) -> None:
+ """Log an error message both to worker logs and WebSocket.
+
+ Args:
+ worker_logger: Worker logger instance for console/file logging
+ message: Error message to log
+ **kwargs: Additional logging kwargs
+ """
+ # Send to WebSocket for UI display
+ self.publish_log(message, level=LogLevel.ERROR)
+
+ # Log to worker logger for debugging
+ worker_logger.error(message, **kwargs)
+
+ def log_info(self, worker_logger: logging.Logger, message: str, **kwargs) -> None:
+ """Log an info message both to worker logs and WebSocket.
+
+ Args:
+ worker_logger: Worker logger instance for console/file logging
+ message: Info message to log
+ **kwargs: Additional logging kwargs
+ """
+ # Send to WebSocket for UI display
+ self.publish_log(message, level=LogLevel.INFO)
+
+ # Log to worker logger for debugging
+ worker_logger.info(message, **kwargs)
+
+ def publish_update_log(
+ self,
+ state: LogState,
+ message: str,
+ component: str | LogComponent | None = None,
+ ) -> None:
+ """Publish update logs for monitoring workflow execution progress.
+
+ These are used for status updates, progress indicators, and component state changes.
+
+ Args:
+ state: Log state (RUNNING, SUCCESS, ERROR, etc.)
+ message: Update message
+ component: Optional component name (SOURCE, DESTINATION, etc.)
+ """
+ try:
+ if not self.messaging_channel:
+ logger.warning(
+ f"No messaging channel, skipping WebSocket update: {message}"
+ )
+ return
+
+ if isinstance(component, LogComponent):
+ component = component.value
+
+ log_details = LogPublisher.log_workflow_update(
+ state=state.value,
+ message=message,
+ component=component,
+ )
+
+ # Publish to WebSocket channel
+ success = LogPublisher.publish(self.messaging_channel, log_details)
+ if not success:
+ logger.warning(f"Failed to publish WebSocket update: {message}")
+
+ except Exception as e:
+ logger.error(f"Error publishing WebSocket update: {e}")
+
+ def publish_initial_workflow_logs(self, total_files: int) -> None:
+ """Publish initial workflow startup logs.
+
+ Args:
+ total_files: Total number of files to process
+ """
+ self.publish_update_log(
+ LogState.BEGIN_WORKFLOW,
+ f"Starting workflow execution with {total_files} files",
+ LogComponent.WORKFLOW,
+ )
+
+ def publish_source_logs(self, files_found: int, files_filtered: int = 0) -> None:
+ """Publish source connector logs.
+
+ Args:
+ files_found: Number of files found by source connector
+ files_filtered: Number of files filtered out (optional)
+ """
+ if files_filtered > 0:
+ message = f"Found {files_found} files, filtered to {files_found - files_filtered} files"
+ else:
+ message = f"Found {files_found} files from source"
+
+ self.publish_update_log(LogState.SUCCESS, message, LogComponent.SOURCE)
+
+ def publish_processing_start(
+ self, file_name: str, current_idx: int, total_files: int
+ ) -> None:
+ """Publish file processing start log.
+
+ Args:
+ file_name: Name of file being processed
+ current_idx: Current file index (1-based)
+ total_files: Total number of files
+ """
+ message = f"Processing file {current_idx}/{total_files}: {file_name}"
+ self.publish_log(message, LogLevel.INFO)
+
+ def publish_processing_complete(
+ self, file_name: str, success: bool, error: str | None = None
+ ) -> None:
+ """Publish file processing completion log.
+
+ Args:
+ file_name: Name of processed file
+ success: Whether processing was successful
+ error: Error message if processing failed
+ """
+ if success:
+ message = f"✓ File '{file_name}' processed successfully"
+ level = LogLevel.INFO
+ else:
+ message = f"✗ File '{file_name}' processing failed"
+ if error:
+ message += f" - {error}"
+ level = LogLevel.ERROR
+
+ self.publish_log(message, level)
+
+ def publish_destination_logs(
+ self, files_sent: int, destination_type: str = "destination"
+ ) -> None:
+ """Publish destination connector logs.
+
+ Args:
+ files_sent: Number of files sent to destination
+ destination_type: Type of destination (destination, manual_review, etc.)
+ """
+ message = f"Sent {files_sent} files to {destination_type}"
+ self.publish_update_log(LogState.SUCCESS, message, LogComponent.DESTINATION)
+
+ def publish_execution_complete(
+ self, successful_files: int, failed_files: int, total_time: float
+ ) -> None:
+ """Publish execution completion summary.
+
+ Args:
+ successful_files: Number of successfully processed files
+ failed_files: Number of failed files
+ total_time: Total execution time in seconds
+ """
+ if failed_files > 0:
+ message = f"Execution completed: {successful_files} successful, {failed_files} failed ({total_time:.1f}s)"
+ state = LogState.ERROR if successful_files == 0 else LogState.SUCCESS
+ else:
+ message = f"Execution completed successfully: {successful_files} files processed ({total_time:.1f}s)"
+ state = LogState.SUCCESS
+
+ self.publish_update_log(state, message, LogComponent.WORKFLOW)
+
+ @classmethod
+ def create_for_file_processing(
+ cls,
+ execution_id: str,
+ file_execution_id: str | None = None,
+ organization_id: str | None = None,
+ pipeline_id: str | None = None,
+ ) -> "WorkerWorkflowLogger":
+ """Factory method for file processing workflows.
+
+ Args:
+ execution_id: Workflow execution ID
+ file_execution_id: File execution ID
+ organization_id: Organization ID
+ pipeline_id: Pipeline ID
+
+ Returns:
+ Configured WorkerWorkflowLogger for file processing
+ """
+ return cls(
+ execution_id=execution_id,
+ log_stage=LogStage.PROCESSING,
+ file_execution_id=file_execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+
+ @classmethod
+ def create_for_source(
+ cls,
+ execution_id: str,
+ organization_id: str | None = None,
+ pipeline_id: str | None = None,
+ ) -> "WorkerWorkflowLogger":
+ """Factory method for source connector workflows.
+
+ Args:
+ execution_id: Workflow execution ID
+ organization_id: Organization ID
+ pipeline_id: Pipeline ID
+
+ Returns:
+ Configured WorkerWorkflowLogger for source processing
+ """
+ return cls(
+ execution_id=execution_id,
+ log_stage=LogStage.SOURCE,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+
+ @classmethod
+ def create_for_general_workflow(
+ cls,
+ execution_id: str,
+ organization_id: str | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ ) -> "WorkerWorkflowLogger":
+ """Factory method for general workflow execution.
+
+ Args:
+ execution_id: Workflow execution ID
+ organization_id: Organization ID
+ pipeline_id: Pipeline ID
+ log_events_id: Log events ID
+
+ Returns:
+ Configured WorkerWorkflowLogger for general workflow
+ """
+ return cls(
+ execution_id=execution_id,
+ log_stage=LogStage.RUN,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ log_events_id=log_events_id,
+ )
+
+ @classmethod
+ def create_for_api_workflow(
+ cls,
+ execution_id: str,
+ organization_id: str | None = None,
+ pipeline_id: str | None = None,
+ log_events_id: str | None = None,
+ ) -> "WorkerWorkflowLogger":
+ """Factory method for API workflow execution.
+
+ Args:
+ execution_id: Workflow execution ID
+ organization_id: Organization ID
+ pipeline_id: Pipeline ID (for API deployments)
+ log_events_id: Log events ID
+
+ Returns:
+ Configured WorkerWorkflowLogger for API workflow
+ """
+ return cls(
+ execution_id=execution_id,
+ log_stage=LogStage.RUN, # Same as general workflow
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ log_events_id=log_events_id,
+ )
+
+ def create_file_logger(self, file_execution_id: str) -> "WorkerWorkflowLogger":
+ """Create a file-specific logger from an existing workflow logger.
+
+ This preserves all the same settings but adds the file_execution_id for
+ file-specific log tracking.
+
+ Args:
+ file_execution_id: WorkflowFileExecution ID to associate with logs
+
+ Returns:
+ New WorkerWorkflowLogger instance with file_execution_id
+ """
+ return WorkerWorkflowLogger(
+ execution_id=self.execution_id,
+ log_stage=self.log_stage,
+ file_execution_id=file_execution_id, # Add file association
+ organization_id=self.organization_id,
+ pipeline_id=None, # Use the messaging channel from parent
+ log_events_id=self.messaging_channel, # Preserve messaging channel
+ )
+
+ def publish_average_cost_log(
+ self,
+ worker_logger: logging.Logger,
+ total_files: int,
+ execution_id: str,
+ total_cost: float | None,
+ ) -> None:
+ """Publish average cost log for the workflow execution.
+
+ This matches the backend's WorkflowLog.publish_average_cost_log method
+ to provide consistent UI feedback for cost tracking.
+
+ Args:
+ worker_logger: Worker logger instance for console/file logging
+ total_files: Total number of files processed
+ execution_id: Execution ID for cost calculation
+ total_cost: Total aggregated cost in dollars (can be None)
+ """
+ try:
+ if total_cost is not None and total_files > 0:
+ average_cost = round(total_cost / total_files, 5)
+ message = (
+ f"The average cost per file for execution "
+ f"'{execution_id}' is '${average_cost}'"
+ )
+
+ # Send to WebSocket for UI display
+ self.publish_log(message, level=LogLevel.INFO)
+
+ # Log to worker logger for debugging
+ worker_logger.info(message)
+ else:
+ # Handle cases where cost data is unavailable
+ if total_cost is None:
+ worker_logger.debug(
+ f"No cost data available for execution {execution_id}"
+ )
+ elif total_files == 0:
+ worker_logger.debug(f"No files processed in execution {execution_id}")
+
+ except Exception as e:
+ error_msg = f"Unable to get aggregated cost for '{execution_id}': {str(e)}"
+ worker_logger.warning(error_msg)
+
+ def publish_final_workflow_logs(
+ self,
+ total_files: int,
+ successful_files: int,
+ failed_files: int,
+ ) -> None:
+ """Publish final workflow execution logs.
+
+ This matches the backend's WorkflowLog.publish_final_workflow_logs method
+ to provide consistent UI feedback for execution completion.
+
+ Args:
+ total_files: Total number of files processed
+ successful_files: Number of successfully processed files
+ failed_files: Number of files that failed processing
+ """
+ # Publish workflow end status to UI status bar
+ self.publish_update_log(LogState.END_WORKFLOW, "1", LogComponent.STATUS_BAR)
+
+ # Publish workflow completion status
+ self.publish_update_log(
+ LogState.SUCCESS, "Executed successfully", LogComponent.WORKFLOW
+ )
+
+ # Publish detailed execution summary
+ summary_message = (
+ f"Total files: {total_files}, "
+ f"{successful_files} successfully executed and {failed_files} error(s)"
+ )
+ self.publish_log(summary_message, level=LogLevel.INFO)
+
+ def log_total_cost_per_file(
+ self,
+ worker_logger: logging.Logger,
+ file_execution_id: str,
+ file_name: str,
+ api_client: "InternalAPIClient",
+ ) -> None:
+ """Log total cost for a specific file execution.
+
+ This matches the backend's WorkflowLog.log_total_cost_per_file method
+ which uses UsageHelper.get_aggregated_token_count() directly.
+
+ Args:
+ worker_logger: Worker logger instance for console/file logging
+ file_execution_id: File execution ID to get cost data for (run_id)
+ file_name: Name of the file being executed
+ api_client: Internal API client for usage data retrieval
+ """
+ try:
+ # Use existing usage_client from InternalAPIClient (matches backend's UsageHelper.get_aggregated_token_count)
+ usage_response = api_client.usage_client.get_aggregated_token_count(
+ file_execution_id=file_execution_id,
+ organization_id=api_client.organization_id,
+ )
+
+ if not usage_response.is_success() or not usage_response.data:
+ # Handle no cost data - matches backend behavior (uses WARN level)
+ message = f"No cost data available for file '{file_name}'"
+ self.publish_log(message, level=LogLevel.ERROR)
+ worker_logger.warning(message)
+ return
+
+ # Extract cost from usage data (matches backend: cost_dict.get("cost_in_dollars"))
+ cost_in_dollars = usage_response.data.cost_in_dollars
+ if cost_in_dollars is None:
+ message = f"No cost data available for file '{file_name}'"
+ self.publish_log(message, level=LogLevel.ERROR)
+ worker_logger.warning(message)
+ return
+
+ # Round cost to 5 decimal places (matches backend implementation)
+ cost = round(cost_in_dollars or 0, 5)
+
+ # Log the total cost for the file (matches backend message format exactly)
+ message = f"Total cost for file '{file_name}' is '${cost}'"
+
+ # Send to WebSocket for UI display (matches backend: self.publish_log)
+ self.publish_log(message, level=LogLevel.INFO)
+
+ # Log to worker logger for debugging
+ worker_logger.info(message)
+
+ except Exception as e:
+ error_msg = f"Unable to get cost data for file '{file_name}' (execution: {file_execution_id}): {str(e)}"
+
+ # Send error to WebSocket for UI display
+ self.publish_log(error_msg, level=LogLevel.ERROR)
+
+ # Log to worker logger for debugging
+ worker_logger.warning(error_msg)
diff --git a/workers/shared/infrastructure/monitoring/__init__.py b/workers/shared/infrastructure/monitoring/__init__.py
new file mode 100644
index 000000000..c0772787f
--- /dev/null
+++ b/workers/shared/infrastructure/monitoring/__init__.py
@@ -0,0 +1,12 @@
+"""Monitoring infrastructure for workers.
+
+This package provides health monitoring and performance tracking
+functionality for workers.
+"""
+
+from .health import HealthChecker, HealthServer
+
+__all__ = [
+ "HealthChecker",
+ "HealthServer",
+]
diff --git a/workers/shared/infrastructure/monitoring/health.py b/workers/shared/infrastructure/monitoring/health.py
new file mode 100644
index 000000000..3a9b90ff5
--- /dev/null
+++ b/workers/shared/infrastructure/monitoring/health.py
@@ -0,0 +1,505 @@
+"""Health Check and Monitoring for Workers
+
+Provides health check endpoints and monitoring capabilities for worker processes.
+"""
+
+import json
+import threading
+import time
+from collections.abc import Callable
+from dataclasses import asdict, dataclass
+from datetime import UTC, datetime
+from enum import Enum
+from http.server import BaseHTTPRequestHandler, HTTPServer
+from typing import Any
+
+import psutil
+
+from ...core.exceptions.api_exceptions import APIRequestError
+from ..config.worker_config import WorkerConfig
+from ..logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class HealthStatus(Enum):
+ """Health check status levels."""
+
+ HEALTHY = "healthy"
+ DEGRADED = "degraded"
+ UNHEALTHY = "unhealthy"
+
+
+@dataclass
+class HealthCheckResult:
+ """Result of a health check."""
+
+ name: str
+ status: HealthStatus
+ message: str
+ details: dict[str, Any] | None = None
+ execution_time: float | None = None
+ timestamp: datetime | None = None
+
+
+@dataclass
+class SystemMetrics:
+ """System metrics for health monitoring."""
+
+ cpu_percent: float
+ memory_percent: float
+ memory_used_mb: float
+ memory_available_mb: float
+ disk_usage_percent: float
+ uptime_seconds: float
+ process_count: int
+ thread_count: int
+ timestamp: datetime
+
+
+class HealthChecker:
+ """Comprehensive health checker for worker processes.
+
+ Monitors:
+ - API connectivity
+ - System resources
+ - Worker-specific health
+ - Custom health checks
+ """
+
+ def __init__(self, config: WorkerConfig | None = None):
+ """Initialize health checker.
+
+ Args:
+ config: Worker configuration. Uses default if None.
+ """
+ self.config = config or WorkerConfig()
+ self.api_client = None
+ self.start_time = time.time()
+ self.custom_checks: dict[str, Callable[[], HealthCheckResult]] = {}
+ self.last_health_check = None
+ self.health_history: list[dict[str, Any]] = []
+ self._lock = threading.Lock()
+
+ def add_custom_check(self, name: str, check_func: Callable[[], HealthCheckResult]):
+ """Add custom health check.
+
+ Args:
+ name: Check name
+ check_func: Function that returns HealthCheckResult
+ """
+ self.custom_checks[name] = check_func
+ logger.debug(f"Added custom health check: {name}")
+
+ def remove_custom_check(self, name: str):
+ """Remove custom health check."""
+ if name in self.custom_checks:
+ del self.custom_checks[name]
+ logger.debug(f"Removed custom health check: {name}")
+
+ def check_api_connectivity(self) -> HealthCheckResult:
+ """Check connectivity to internal API."""
+ start_time = time.time()
+
+ try:
+ if not self.api_client:
+ # Use singleton API client to reduce initialization noise
+ from .api_client_singleton import get_singleton_api_client
+
+ self.api_client = get_singleton_api_client(self.config)
+
+ # Simply check if API client can be configured properly
+ # Avoid making actual API calls that might hit non-existent endpoints
+ execution_time = time.time() - start_time
+
+ # If we can create the client without errors, consider API connectivity healthy
+ return HealthCheckResult(
+ name="api_connectivity",
+ status=HealthStatus.HEALTHY,
+ message="API client configuration successful",
+ details={
+ "api_base_url": getattr(
+ self.config, "internal_api_base_url", "unknown"
+ )
+ },
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ except APIRequestError as e:
+ execution_time = time.time() - start_time
+ return HealthCheckResult(
+ name="api_connectivity",
+ status=HealthStatus.UNHEALTHY,
+ message=f"API request failed: {str(e)}",
+ details={"error": str(e)},
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+ except Exception as e:
+ execution_time = time.time() - start_time
+ return HealthCheckResult(
+ name="api_connectivity",
+ status=HealthStatus.UNHEALTHY,
+ message=f"Unexpected error: {str(e)}",
+ details={"error": str(e)},
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ def check_system_resources(self) -> HealthCheckResult:
+ """Check system resource utilization."""
+ start_time = time.time()
+
+ try:
+ # Get system metrics
+ metrics = self.get_system_metrics()
+ execution_time = time.time() - start_time
+
+ # Determine health status based on resource usage
+ status = HealthStatus.HEALTHY
+ issues = []
+
+ # CPU check
+ if metrics.cpu_percent > 90:
+ status = HealthStatus.UNHEALTHY
+ issues.append(f"High CPU usage: {metrics.cpu_percent:.1f}%")
+ elif metrics.cpu_percent > 75:
+ status = HealthStatus.DEGRADED
+ issues.append(f"Elevated CPU usage: {metrics.cpu_percent:.1f}%")
+
+ # Memory check
+ if metrics.memory_percent > 95:
+ status = HealthStatus.UNHEALTHY
+ issues.append(f"Critical memory usage: {metrics.memory_percent:.1f}%")
+ elif metrics.memory_percent > 85:
+ if status == HealthStatus.HEALTHY:
+ status = HealthStatus.DEGRADED
+ issues.append(f"High memory usage: {metrics.memory_percent:.1f}%")
+
+ # Disk check
+ if metrics.disk_usage_percent > 95:
+ status = HealthStatus.UNHEALTHY
+ issues.append(f"Critical disk usage: {metrics.disk_usage_percent:.1f}%")
+ elif metrics.disk_usage_percent > 85:
+ if status == HealthStatus.HEALTHY:
+ status = HealthStatus.DEGRADED
+ issues.append(f"High disk usage: {metrics.disk_usage_percent:.1f}%")
+
+ message = (
+ "System resources OK"
+ if status == HealthStatus.HEALTHY
+ else "; ".join(issues)
+ )
+
+ return HealthCheckResult(
+ name="system_resources",
+ status=status,
+ message=message,
+ details=asdict(metrics),
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ except Exception as e:
+ execution_time = time.time() - start_time
+ return HealthCheckResult(
+ name="system_resources",
+ status=HealthStatus.UNHEALTHY,
+ message=f"Failed to check system resources: {str(e)}",
+ details={"error": str(e)},
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ def check_worker_process(self) -> HealthCheckResult:
+ """Check worker process health."""
+ start_time = time.time()
+
+ try:
+ process = psutil.Process()
+ execution_time = time.time() - start_time
+
+ # Check if process is responding
+ if process.status() == psutil.STATUS_ZOMBIE:
+ return HealthCheckResult(
+ name="worker_process",
+ status=HealthStatus.UNHEALTHY,
+ message="Worker process is zombie",
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ # Check worker uptime
+ uptime = time.time() - self.start_time
+ process_info = {
+ "pid": process.pid,
+ "status": process.status(),
+ "cpu_percent": process.cpu_percent(),
+ "memory_info": process.memory_info()._asdict(),
+ "uptime_seconds": uptime,
+ "num_threads": process.num_threads(),
+ }
+
+ return HealthCheckResult(
+ name="worker_process",
+ status=HealthStatus.HEALTHY,
+ message=f"Worker process healthy (uptime: {uptime:.0f}s)",
+ details=process_info,
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ except Exception as e:
+ execution_time = time.time() - start_time
+ return HealthCheckResult(
+ name="worker_process",
+ status=HealthStatus.UNHEALTHY,
+ message=f"Failed to check worker process: {str(e)}",
+ details={"error": str(e)},
+ execution_time=execution_time,
+ timestamp=datetime.now(UTC),
+ )
+
+ def run_all_checks(self) -> dict[str, Any]:
+ """Run all health checks and return comprehensive health report.
+
+ Returns:
+ Health report dictionary
+ """
+ start_time = time.time()
+
+ # Built-in checks
+ checks = [
+ self.check_api_connectivity(),
+ self.check_system_resources(),
+ self.check_worker_process(),
+ ]
+
+ # Custom checks
+ for name, check_func in self.custom_checks.items():
+ try:
+ result = check_func()
+ checks.append(result)
+ except Exception as e:
+ checks.append(
+ HealthCheckResult(
+ name=name,
+ status=HealthStatus.UNHEALTHY,
+ message=f"Custom check failed: {str(e)}",
+ details={"error": str(e)},
+ timestamp=datetime.now(UTC),
+ )
+ )
+
+ # Determine overall health status
+ overall_status = HealthStatus.HEALTHY
+ unhealthy_checks = []
+ degraded_checks = []
+
+ for check in checks:
+ if check.status == HealthStatus.UNHEALTHY:
+ overall_status = HealthStatus.UNHEALTHY
+ unhealthy_checks.append(check.name)
+ elif (
+ check.status == HealthStatus.DEGRADED
+ and overall_status == HealthStatus.HEALTHY
+ ):
+ overall_status = HealthStatus.DEGRADED
+ degraded_checks.append(check.name)
+
+ execution_time = time.time() - start_time
+
+ # Build health report
+ health_report = {
+ "status": overall_status.value,
+ "timestamp": datetime.now(UTC).isoformat() + "Z",
+ "uptime_seconds": time.time() - self.start_time,
+ "worker_name": self.config.worker_name,
+ "worker_version": self.config.worker_version,
+ "instance_id": self.config.worker_instance_id,
+ "execution_time": execution_time,
+ "checks": {check.name: asdict(check) for check in checks},
+ "summary": {
+ "total_checks": len(checks),
+ "healthy_checks": len(
+ [c for c in checks if c.status == HealthStatus.HEALTHY]
+ ),
+ "degraded_checks": len(
+ [c for c in checks if c.status == HealthStatus.DEGRADED]
+ ),
+ "unhealthy_checks": len(
+ [c for c in checks if c.status == HealthStatus.UNHEALTHY]
+ ),
+ "unhealthy_check_names": unhealthy_checks,
+ "degraded_check_names": degraded_checks,
+ },
+ }
+
+ # Store in history
+ with self._lock:
+ self.last_health_check = health_report
+ self.health_history.append(health_report)
+ # Keep only last 50 health checks
+ if len(self.health_history) > 50:
+ self.health_history = self.health_history[-50:]
+
+ return health_report
+
+ def get_system_metrics(self) -> SystemMetrics:
+ """Get current system metrics."""
+ # CPU and memory
+ cpu_percent = psutil.cpu_percent(interval=1)
+ memory = psutil.virtual_memory()
+
+ # Disk usage for current directory
+ disk_usage = psutil.disk_usage("/")
+
+ # Process info
+ process = psutil.Process()
+
+ return SystemMetrics(
+ cpu_percent=cpu_percent,
+ memory_percent=memory.percent,
+ memory_used_mb=memory.used / 1024 / 1024,
+ memory_available_mb=memory.available / 1024 / 1024,
+ disk_usage_percent=(disk_usage.used / disk_usage.total) * 100,
+ uptime_seconds=time.time() - self.start_time,
+ process_count=len(psutil.pids()),
+ thread_count=process.num_threads(),
+ timestamp=datetime.now(UTC),
+ )
+
+ def get_last_health_check(self) -> dict[str, Any] | None:
+ """Get last health check result."""
+ return self.last_health_check
+
+ def get_health_history(self, limit: int = 10) -> list[dict[str, Any]]:
+ """Get recent health check history."""
+ with self._lock:
+ return self.health_history[-limit:] if self.health_history else []
+
+
+class HealthHTTPHandler(BaseHTTPRequestHandler):
+ """HTTP handler for health check endpoints."""
+
+ def __init__(self, health_checker: HealthChecker, *args, **kwargs):
+ self.health_checker = health_checker
+ super().__init__(*args, **kwargs)
+
+ def do_GET(self):
+ """Handle GET requests."""
+ try:
+ if self.path == "/health":
+ # Full health check
+ health_report = self.health_checker.run_all_checks()
+ status_code = 200 if health_report["status"] == "healthy" else 503
+ self._send_json_response(health_report, status_code)
+
+ elif self.path == "/health/quick":
+ # Quick health check (last result)
+ last_check = self.health_checker.get_last_health_check()
+ if last_check:
+ status_code = 200 if last_check["status"] == "healthy" else 503
+ self._send_json_response(last_check, status_code)
+ else:
+ self._send_json_response(
+ {
+ "status": "no_data",
+ "message": "No health check data available",
+ },
+ 503,
+ )
+
+ elif self.path == "/health/metrics":
+ # System metrics only
+ metrics = self.health_checker.get_system_metrics()
+ self._send_json_response(asdict(metrics), 200)
+
+ elif self.path == "/health/history":
+ # Health check history
+ history = self.health_checker.get_health_history()
+ self._send_json_response({"history": history}, 200)
+
+ else:
+ self._send_json_response({"error": "Not found"}, 404)
+
+ except Exception as e:
+ logger.error(f"Health check endpoint error: {e}")
+ self._send_json_response(
+ {"error": "Internal server error", "detail": str(e)}, 500
+ )
+
+ def _send_json_response(self, data: dict[str, Any], status_code: int):
+ """Send JSON response."""
+ self.send_response(status_code)
+ self.send_header("Content-Type", "application/json")
+ self.end_headers()
+ response_data = json.dumps(data, default=str, indent=2)
+ self.wfile.write(response_data.encode("utf-8"))
+
+ def log_message(self, format, *args):
+ """Override to suppress routine health check request logs."""
+ # Only log errors, not routine health check requests
+ pass
+
+
+class HealthServer:
+ """HTTP server for health check endpoints."""
+
+ def __init__(self, health_checker: HealthChecker, port: int = 8080):
+ """Initialize health server.
+
+ Args:
+ health_checker: HealthChecker instance
+ port: Port to listen on
+ """
+ self.health_checker = health_checker
+ self.port = port
+ self.server = None
+ self.server_thread = None
+
+ def start(self):
+ """Start health check server."""
+ try:
+ # Create server with custom handler
+ def handler_factory(*args, **kwargs):
+ return HealthHTTPHandler(self.health_checker, *args, **kwargs)
+
+ self.server = HTTPServer(("0.0.0.0", self.port), handler_factory)
+
+ # Start server in background thread
+ self.server_thread = threading.Thread(
+ target=self.server.serve_forever, daemon=True
+ )
+ self.server_thread.start()
+
+ logger.debug(f"Health check server started on port {self.port}")
+
+ except Exception as e:
+ logger.error(f"Failed to start health check server: {e}")
+ raise
+
+ def stop(self):
+ """Stop health check server."""
+ if self.server:
+ self.server.shutdown()
+ self.server.server_close()
+
+ if self.server_thread:
+ self.server_thread.join(timeout=5)
+
+ logger.debug("Health check server stopped")
+
+ def is_running(self) -> bool:
+ """Check if server is running."""
+ return (
+ self.server is not None
+ and self.server_thread is not None
+ and self.server_thread.is_alive()
+ )
+
+
+def create_default_health_checker(config: WorkerConfig | None = None) -> HealthChecker:
+ """Create health checker with default configuration."""
+ return HealthChecker(config)
diff --git a/workers/shared/infrastructure/worker_singleton.py b/workers/shared/infrastructure/worker_singleton.py
new file mode 100644
index 000000000..f0c14bb09
--- /dev/null
+++ b/workers/shared/infrastructure/worker_singleton.py
@@ -0,0 +1,252 @@
+"""Worker Infrastructure with Lock-Free Factory Pattern
+
+This module provides a lock-free factory pattern for managing worker-level infrastructure
+components. Expensive resources like configuration and connection pools are shared,
+but API clients are created per-task to ensure organization isolation and eliminate
+threading issues.
+
+Architecture:
+- WorkerInfrastructure: Manages shared expensive resources (config, connection pools)
+- API Client Factory: Creates isolated API clients per organization per task
+- No locks: Eliminates deadlock risks and performance bottlenecks
+- Organization isolation: Complete separation of API contexts between tasks
+"""
+
+import logging
+from typing import Optional
+
+from shared.api.internal_client import InternalAPIClient
+from shared.infrastructure.caching import WorkerCacheManager
+from shared.infrastructure.config import WorkerConfig
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerInfrastructure:
+ """Simple factory for worker-level infrastructure components.
+
+ This class manages shared expensive resources (configuration, connection pools)
+ while providing a factory method for creating isolated API clients per task.
+ Uses Python's GIL for natural thread safety - simple and efficient.
+ """
+
+ _instance: Optional["WorkerInfrastructure"] = None
+ _initialized: bool = False
+
+ def __new__(cls) -> "WorkerInfrastructure":
+ """GIL-safe singleton instantiation."""
+ if cls._instance is None:
+ cls._instance = super().__new__(cls)
+ return cls._instance
+
+ def __init__(self):
+ """Initialize worker infrastructure if not already done."""
+ # Simple idempotent initialization - GIL provides safety
+ if WorkerInfrastructure._initialized:
+ return
+
+ logger.info("Initializing WorkerInfrastructure factory (GIL-safe)...")
+
+ # Initialize configuration (shared across all tasks)
+ self.config = WorkerConfig()
+
+ # Initialize cache manager (shared across all tasks)
+ self._initialize_cache_manager()
+
+ # Mark as initialized (atomic assignment)
+ WorkerInfrastructure._initialized = True
+
+ logger.info(
+ f"WorkerInfrastructure factory initialized successfully: "
+ f"Config={type(self.config).__name__}, "
+ f"Cache={type(self.cache_manager).__name__}"
+ )
+
+ def _initialize_cache_manager(self) -> None:
+ """Initialize the worker cache manager for shared caching across tasks."""
+ try:
+ self.cache_manager = WorkerCacheManager(self.config)
+ logger.debug("WorkerCacheManager initialized successfully")
+ except Exception as e:
+ logger.warning(f"Failed to initialize WorkerCacheManager: {e}")
+ # Set to None so tasks can handle gracefully
+ self.cache_manager = None
+
+ def create_api_client(self, organization_id: str) -> InternalAPIClient:
+ """Create a new API client instance for a specific organization.
+
+ This factory method creates isolated API client instances per task,
+ ensuring complete organization separation and eliminating threading issues.
+ The client reuses the shared configuration but maintains its own state.
+
+ Args:
+ organization_id: The organization ID to set as context for this client
+
+ Returns:
+ A new InternalAPIClient instance configured for the specified organization
+
+ Raises:
+ RuntimeError: If worker infrastructure is not initialized
+ """
+ if not WorkerInfrastructure._initialized:
+ raise RuntimeError("Worker infrastructure not initialized")
+
+ try:
+ # Create new API client instance for this task/organization
+ api_client = InternalAPIClient(self.config)
+ api_client.set_organization_context(organization_id)
+
+ logger.debug(f"Created new API client for organization: {organization_id}")
+ return api_client
+
+ except Exception as e:
+ logger.error(f"Failed to create API client for org {organization_id}: {e}")
+ raise RuntimeError(f"API client creation failed: {e}") from e
+
+ @classmethod
+ def get_instance(cls) -> "WorkerInfrastructure":
+ """Get the singleton instance of WorkerInfrastructure.
+
+ Returns:
+ The singleton WorkerInfrastructure instance
+ """
+ if cls._instance is None:
+ cls() # This will create and initialize the instance
+ return cls._instance
+
+ @classmethod
+ def is_initialized(cls) -> bool:
+ """Check if the worker infrastructure has been initialized.
+
+ Returns:
+ True if infrastructure is ready, False otherwise
+ """
+ return cls._initialized and cls._instance is not None
+
+ def get_cache_manager(self) -> WorkerCacheManager | None:
+ """Get the shared cache manager instance.
+
+ Returns:
+ The shared WorkerCacheManager instance, or None if not available
+ """
+ return getattr(self, "cache_manager", None)
+
+ def get_config(self) -> WorkerConfig:
+ """Get the worker configuration.
+
+ Returns:
+ The WorkerConfig instance
+ """
+ return self.config
+
+ def health_check(self) -> dict[str, bool]:
+ """Perform health check on infrastructure components.
+
+ Returns:
+ Dictionary with health status of each component
+ """
+ health = {
+ "infrastructure_initialized": self._initialized,
+ "config_available": hasattr(self, "config") and self.config is not None,
+ "cache_manager_available": hasattr(self, "cache_manager")
+ and self.cache_manager is not None,
+ "api_client_factory_available": True, # Factory is always available if initialized
+ }
+
+ # Check cache manager health if available
+ if health["cache_manager_available"]:
+ health["cache_manager_redis_available"] = self.cache_manager.is_available
+
+ return health
+
+
+# Global convenience functions for easy access to shared infrastructure
+# These functions provide a clean API for tasks to access shared resources
+
+
+def get_worker_infrastructure() -> WorkerInfrastructure:
+ """Get the worker infrastructure singleton instance.
+
+ Returns:
+ The WorkerInfrastructure singleton instance
+ """
+ return WorkerInfrastructure.get_instance()
+
+
+def create_api_client(organization_id: str) -> InternalAPIClient:
+ """Create a new API client instance for a specific organization.
+
+ This function provides a lock-free factory for creating isolated API client
+ instances per task. Each client is bound to a specific organization and
+ maintains its own state, eliminating threading issues and organization conflicts.
+
+ Args:
+ organization_id: The organization ID to set as context for this client
+
+ Returns:
+ A new InternalAPIClient instance configured for the specified organization
+
+ Raises:
+ RuntimeError: If worker infrastructure is not initialized
+ """
+ infrastructure = get_worker_infrastructure()
+ return infrastructure.create_api_client(organization_id)
+
+
+def get_cache_manager() -> WorkerCacheManager | None:
+ """Get the shared cache manager instance.
+
+ This function provides convenient access to the shared WorkerCacheManager
+ that is reused across all tasks within the worker process.
+
+ Returns:
+ The shared WorkerCacheManager instance, or None if not available
+ """
+ infrastructure = get_worker_infrastructure()
+ return infrastructure.get_cache_manager()
+
+
+def get_worker_config() -> WorkerConfig:
+ """Get the worker configuration.
+
+ Returns:
+ The WorkerConfig instance
+ """
+ infrastructure = get_worker_infrastructure()
+ return infrastructure.get_config()
+
+
+def initialize_worker_infrastructure() -> WorkerInfrastructure:
+ """Explicitly initialize worker infrastructure.
+
+ This function should be called during worker startup to ensure
+ all infrastructure components are ready before task execution begins.
+
+ Returns:
+ The initialized WorkerInfrastructure instance
+ """
+ logger.info("Explicitly initializing worker infrastructure...")
+ infrastructure = WorkerInfrastructure.get_instance()
+
+ # Perform health check to ensure everything is working
+ health = infrastructure.health_check()
+ logger.info(f"Worker infrastructure health check: {health}")
+
+ if not health["infrastructure_initialized"] or not health["config_available"]:
+ raise RuntimeError(f"Worker infrastructure initialization failed: {health}")
+
+ logger.info("Worker infrastructure initialization completed successfully")
+ return infrastructure
+
+
+def worker_infrastructure_health_check() -> dict[str, bool]:
+ """Get health status of worker infrastructure components.
+
+ Returns:
+ Dictionary with health status of each component
+ """
+ if not WorkerInfrastructure.is_initialized():
+ return {"infrastructure_initialized": False}
+
+ infrastructure = get_worker_infrastructure()
+ return infrastructure.health_check()
diff --git a/workers/shared/models/__init__.py b/workers/shared/models/__init__.py
new file mode 100644
index 000000000..0d93fd12b
--- /dev/null
+++ b/workers/shared/models/__init__.py
@@ -0,0 +1,54 @@
+"""Worker Data Models
+
+Dataclasses and models specific to worker implementation.
+"""
+
+from unstract.core.worker_models import FileExecutionResult
+
+from .batch_models import (
+ FileStatusUpdateRequest,
+ PipelineUpdateRequest,
+ StatusUpdateRequest,
+ WebhookNotificationRequest,
+)
+from .callback_models import CallbackExecutionData
+from .file_processing import FileProcessingContext
+from .request_models import (
+ FileExecutionStatusUpdateRequest,
+ NotificationRequest,
+ PipelineStatusUpdateRequest,
+ WorkflowExecutionUpdateRequest,
+)
+from .result_models import BatchExecutionResult, WebhookResult
+from .task_models import (
+ TaskError,
+ TaskExecutionContext,
+ TaskPerformanceMetrics,
+ WorkerHealthMetrics,
+)
+
+__all__ = [
+ # Task models
+ "TaskExecutionContext",
+ "TaskError",
+ "TaskPerformanceMetrics",
+ "WorkerHealthMetrics",
+ # Result models
+ "WebhookResult",
+ "FileExecutionResult",
+ "BatchExecutionResult",
+ # Callback models
+ "CallbackExecutionData",
+ # Request models
+ "WorkflowExecutionUpdateRequest",
+ "PipelineStatusUpdateRequest",
+ "NotificationRequest",
+ "FileExecutionStatusUpdateRequest",
+ # Batch models
+ "StatusUpdateRequest",
+ "PipelineUpdateRequest",
+ "FileStatusUpdateRequest",
+ "WebhookNotificationRequest",
+ # File processing models
+ "FileProcessingContext",
+]
diff --git a/workers/shared/models/api_responses.py b/workers/shared/models/api_responses.py
new file mode 100644
index 000000000..cc409ca45
--- /dev/null
+++ b/workers/shared/models/api_responses.py
@@ -0,0 +1,466 @@
+"""API Response Data Models
+
+This module provides strongly-typed dataclasses for API responses,
+replacing fragile dictionary-based response handling with type-safe structures.
+"""
+
+# Import shared domain models from core
+import os
+import sys
+from dataclasses import dataclass, field
+from datetime import datetime
+from typing import Any
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core.data_models import ExecutionStatus
+
+from ..enums import PipelineType
+
+
+@dataclass
+class BaseAPIResponse:
+ """Base class for all API responses with common fields."""
+
+ success: bool
+ data: dict[str, Any] | None = None
+ error: str | None = None
+ status_code: int | None = None
+ timestamp: datetime | None = None
+
+ def __post_init__(self):
+ """Set timestamp if not provided."""
+ if self.timestamp is None:
+ self.timestamp = datetime.now()
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if the response was successful."""
+ return self.success and not self.error
+
+ @property
+ def has_data(self) -> bool:
+ """Check if the response contains data."""
+ return bool(self.data)
+
+ def get_data_field(self, field_name: str, default: Any = None) -> Any:
+ """Safely get a field from response data."""
+ if not self.data:
+ return default
+ return self.data.get(field_name, default)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert response to dictionary for serialization."""
+ result = {
+ "success": self.success,
+ "status_code": self.status_code,
+ }
+
+ if self.data is not None:
+ result["data"] = self.data
+
+ if self.error:
+ result["error"] = self.error
+
+ if self.timestamp:
+ result["timestamp"] = self.timestamp.isoformat()
+
+ return result
+
+
+@dataclass
+class WorkflowExecutionResponse(BaseAPIResponse):
+ """Response from workflow execution API calls."""
+
+ execution_id: str | None = None
+ workflow_id: str | None = None
+ status: str | None = None
+ execution_time: float | None = None
+ total_files: int | None = None
+ completed_files: int | None = None
+ failed_files: int | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "WorkflowExecutionResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", {})
+ execution = data.get("execution", {})
+
+ return cls(
+ success=response.get("success", False),
+ data=data,
+ error=response.get("error"),
+ status_code=response.get("status_code"),
+ execution_id=execution.get("id") or data.get("execution_id"),
+ workflow_id=execution.get("workflow_id") or data.get("workflow_id"),
+ status=execution.get("status") or data.get("status"),
+ execution_time=execution.get("execution_time"),
+ total_files=execution.get("total_files"),
+ completed_files=execution.get("completed_files"),
+ failed_files=execution.get("failed_files"),
+ )
+
+ @property
+ def is_completed(self) -> bool:
+ """Check if execution is completed."""
+ return self.status == ExecutionStatus.COMPLETED.value
+
+ @property
+ def is_failed(self) -> bool:
+ """Check if execution failed."""
+ return self.status == ExecutionStatus.ERROR.value
+
+ @property
+ def is_executing(self) -> bool:
+ """Check if execution is in progress."""
+ return self.status == ExecutionStatus.EXECUTING.value
+
+
+@dataclass
+class FileExecutionResponse(BaseAPIResponse):
+ """Response from file execution API calls."""
+
+ file_execution_id: str | None = None
+ file_name: str | None = None
+ file_path: str | None = None
+ file_hash: str | None = None
+ status: str | None = None
+ processing_time: float | None = None
+ error_message: str | None = None
+ result_data: dict[str, Any] | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "FileExecutionResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", {})
+
+ return cls(
+ success=response.get("success", False),
+ data=data,
+ error=response.get("error"),
+ status_code=response.get("status_code"),
+ file_execution_id=data.get("id") or data.get("file_execution_id"),
+ file_name=data.get("file_name"),
+ file_path=data.get("file_path"),
+ file_hash=data.get("file_hash"),
+ status=data.get("status"),
+ processing_time=data.get("processing_time") or data.get("execution_time"),
+ error_message=data.get("error_message"),
+ result_data=data.get("result_data") or data.get("result"),
+ )
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if file execution was successful."""
+ return self.success and self.status == ExecutionStatus.COMPLETED.value
+
+
+@dataclass
+class WorkflowEndpointsResponse(BaseAPIResponse):
+ """Response from workflow endpoints API calls."""
+
+ endpoints: list[dict[str, Any]] = field(default_factory=list)
+ has_api_endpoints: bool = False
+ source_endpoint: dict[str, Any] | None = None
+ destination_endpoint: dict[str, Any] | None = None
+
+ @classmethod
+ def from_api_response(
+ cls, response: dict[str, Any] | list
+ ) -> "WorkflowEndpointsResponse":
+ """Create from raw API response (handles both dict and list formats)."""
+ # Handle new enhanced format (dict)
+ if isinstance(response, dict):
+ return cls(
+ success=response.get("success", True),
+ data=response,
+ endpoints=response.get("endpoints", []),
+ has_api_endpoints=response.get("has_api_endpoints", False),
+ source_endpoint=cls._find_endpoint(
+ response.get("endpoints", []), "SOURCE"
+ ),
+ destination_endpoint=cls._find_endpoint(
+ response.get("endpoints", []), "DESTINATION"
+ ),
+ )
+ # Handle legacy format (list)
+ elif isinstance(response, list):
+ return cls(
+ success=True,
+ data={"endpoints": response},
+ endpoints=response,
+ has_api_endpoints=len(response) > 0,
+ source_endpoint=cls._find_endpoint(response, "SOURCE"),
+ destination_endpoint=cls._find_endpoint(response, "DESTINATION"),
+ )
+ else:
+ return cls(
+ success=False,
+ error=f"Invalid response type: {type(response)}",
+ )
+
+ @staticmethod
+ def _find_endpoint(
+ endpoints: list[dict[str, Any]], endpoint_type: str
+ ) -> dict[str, Any] | None:
+ """Find endpoint by type."""
+ for endpoint in endpoints:
+ if endpoint.get("endpoint_type") == endpoint_type:
+ return endpoint
+ return None
+
+ @property
+ def source_connection_type(self) -> str | None:
+ """Get source connection type."""
+ if self.source_endpoint:
+ return self.source_endpoint.get("connection_type")
+ return None
+
+ @property
+ def destination_connection_type(self) -> str | None:
+ """Get destination connection type."""
+ if self.destination_endpoint:
+ return self.destination_endpoint.get("connection_type")
+ return None
+
+ @property
+ def is_api_workflow(self) -> bool:
+ """Check if this is an API workflow."""
+ return self.has_api_endpoints or self.source_connection_type == "API"
+
+
+@dataclass
+class FileBatchResponse(BaseAPIResponse):
+ """Response from file batch creation API calls."""
+
+ batch_id: str | None = None
+ total_files: int = 0
+ created_files: list[dict[str, Any]] = field(default_factory=list)
+ execution_id: str | None = None
+ workflow_id: str | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "FileBatchResponse":
+ """Create from raw API response dictionary."""
+ data = response.get(
+ "data", response
+ ) # Handle both wrapped and unwrapped responses
+
+ return cls(
+ success=response.get("success", True),
+ data=data,
+ error=response.get("error"),
+ status_code=response.get("status_code"),
+ batch_id=data.get("batch_id"),
+ total_files=data.get("total_files", 0),
+ created_files=data.get("created_files", []),
+ execution_id=data.get("execution_id"),
+ workflow_id=data.get("workflow_id"),
+ )
+
+ @property
+ def file_count(self) -> int:
+ """Get the number of files in the batch."""
+ return len(self.created_files)
+
+
+@dataclass
+class ToolExecutionResponse(BaseAPIResponse):
+ """Response from tool execution API calls."""
+
+ tool_id: str | None = None
+ tool_name: str | None = None
+ execution_result: dict[str, Any] | None = None
+ execution_time: float | None = None
+ step: int | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "ToolExecutionResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", {})
+
+ return cls(
+ success=response.get("success", False),
+ data=data,
+ error=response.get("error") or data.get("error_message"),
+ status_code=response.get("status_code"),
+ tool_id=data.get("tool_id"),
+ tool_name=data.get("tool_name") or data.get("tool_function"),
+ execution_result=data.get("execution_result") or data.get("output"),
+ execution_time=data.get("execution_time"),
+ step=data.get("step"),
+ )
+
+
+@dataclass
+class FileHistoryResponse(BaseAPIResponse):
+ """Response from file history API calls."""
+
+ found: bool = False
+ file_history: dict[str, Any] | None = None
+ is_completed: bool = False
+ cached_result: dict[str, Any] | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "FileHistoryResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", response)
+ file_history = data.get("file_history")
+
+ # Determine if file was found in history
+ found = bool(file_history)
+ is_completed = False
+
+ if file_history:
+ if isinstance(file_history, dict):
+ is_completed = (
+ file_history.get("is_completed", False)
+ or file_history.get("status") == "COMPLETED"
+ )
+ elif isinstance(file_history, list) and len(file_history) > 0:
+ # Check if any history record is completed
+ for record in file_history:
+ if (
+ record.get("is_completed", False)
+ or record.get("status") == "COMPLETED"
+ ):
+ is_completed = True
+ break
+
+ return cls(
+ success=response.get("success", True),
+ data=data,
+ error=response.get("error"),
+ found=found,
+ file_history=file_history,
+ is_completed=is_completed,
+ cached_result=data.get("cached_result") or data.get("result"),
+ )
+
+
+@dataclass
+class ManualReviewResponse(BaseAPIResponse):
+ """Response from manual review API calls."""
+
+ q_file_no_list: list[int] = field(default_factory=list)
+ total_files_for_review: int = 0
+ review_rules: dict[str, Any] | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "ManualReviewResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", {})
+
+ return cls(
+ success=response.get("success", False),
+ data=data,
+ error=response.get("error"),
+ q_file_no_list=data.get("q_file_no_list", []),
+ total_files_for_review=len(data.get("q_file_no_list", [])),
+ review_rules=data.get("review_rules"),
+ )
+
+ @property
+ def has_files_for_review(self) -> bool:
+ """Check if there are files marked for manual review."""
+ return self.total_files_for_review > 0
+
+
+@dataclass
+class WorkflowDefinitionResponse(BaseAPIResponse):
+ """Response from workflow definition API calls."""
+
+ workflow_id: str | None = None
+ workflow_name: str | None = None
+ workflow_type: str | None = None
+ tools: list[dict[str, Any]] = field(default_factory=list)
+ settings: dict[str, Any] | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "WorkflowDefinitionResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", response)
+
+ return cls(
+ success=response.get("success", True),
+ data=data,
+ error=response.get("error"),
+ workflow_id=data.get("workflow_id") or data.get("id"),
+ workflow_name=data.get("workflow_name") or data.get("name"),
+ workflow_type=data.get("workflow_type") or data.get("type"),
+ tools=data.get("tools", []),
+ settings=data.get("settings"),
+ )
+
+ @property
+ def pipeline_type(self) -> PipelineType | None:
+ """Get the workflow type as a PipelineType enum."""
+ if self.workflow_type:
+ try:
+ return PipelineType(self.workflow_type.upper())
+ except ValueError:
+ return None
+ return None
+
+ @property
+ def tool_count(self) -> int:
+ """Get the number of tools in the workflow."""
+ return len(self.tools)
+
+
+@dataclass
+class ToolInstancesResponse(BaseAPIResponse):
+ """Response from tool instances API calls."""
+
+ tool_instances: list[dict[str, Any]] = field(default_factory=list)
+ workflow_id: str | None = None
+
+ @classmethod
+ def from_api_response(cls, response: dict[str, Any]) -> "ToolInstancesResponse":
+ """Create from raw API response dictionary."""
+ data = response.get("data", response)
+
+ return cls(
+ success=response.get("success", True),
+ data=data,
+ error=response.get("error"),
+ tool_instances=data.get("tool_instances", []),
+ workflow_id=data.get("workflow_id"),
+ )
+
+ @property
+ def has_tools(self) -> bool:
+ """Check if there are any tool instances."""
+ return len(self.tool_instances) > 0
+
+ def get_tools_by_step(self) -> list[dict[str, Any]]:
+ """Get tool instances sorted by step number."""
+ return sorted(self.tool_instances, key=lambda t: t.get("step", 0))
+
+
+# Utility functions for converting API responses
+def parse_api_response(response: Any, response_class: type) -> BaseAPIResponse:
+ """Parse an API response into the appropriate dataclass.
+
+ Args:
+ response: Raw API response (dict, list, or other)
+ response_class: The dataclass type to parse into
+
+ Returns:
+ Instance of the specified response class
+ """
+ if hasattr(response_class, "from_api_response"):
+ return response_class.from_api_response(response)
+ else:
+ # Fallback to base response
+ if isinstance(response, dict):
+ return BaseAPIResponse(
+ success=response.get("success", False),
+ data=response.get("data"),
+ error=response.get("error"),
+ status_code=response.get("status_code"),
+ )
+ else:
+ return BaseAPIResponse(
+ success=False,
+ error=f"Cannot parse response of type {type(response)}",
+ )
diff --git a/workers/shared/models/batch_models.py b/workers/shared/models/batch_models.py
new file mode 100644
index 000000000..4496663e2
--- /dev/null
+++ b/workers/shared/models/batch_models.py
@@ -0,0 +1,114 @@
+"""Batch Operation Models
+
+Dataclasses for batch operations to replace dict patterns.
+"""
+
+import time
+from dataclasses import dataclass, field
+from typing import Any
+
+
+@dataclass
+class StatusUpdateRequest:
+ """Request model for execution status updates."""
+
+ execution_id: str
+ status: str
+ error_message: str | None = None
+ execution_time: float | None = None
+ total_files: int | None = None
+ updated_at: float = field(default_factory=time.time)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API calls."""
+ data = {
+ "execution_id": self.execution_id,
+ "status": self.status,
+ "updated_at": self.updated_at,
+ }
+ if self.error_message is not None:
+ data["error_message"] = self.error_message
+ if self.execution_time is not None:
+ data["execution_time"] = self.execution_time
+ if self.total_files is not None:
+ data["total_files"] = self.total_files
+ return data
+
+
+@dataclass
+class PipelineUpdateRequest:
+ """Request model for pipeline status updates."""
+
+ pipeline_id: str
+ execution_id: str
+ status: str
+ last_run_status: str | None = None
+ last_run_time: float | None = None
+ increment_run_count: bool = False
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API calls."""
+ data = {
+ "pipeline_id": self.pipeline_id,
+ "execution_id": self.execution_id,
+ "status": self.status,
+ "increment_run_count": self.increment_run_count,
+ }
+ if self.last_run_status is not None:
+ data["last_run_status"] = self.last_run_status
+ if self.last_run_time is not None:
+ data["last_run_time"] = self.last_run_time
+ return data
+
+
+@dataclass
+class FileStatusUpdateRequest:
+ """Request model for file execution status updates."""
+
+ file_execution_id: str
+ status: str
+ result: dict[str, Any] | None = None
+ error_message: str | None = None
+ processing_time: float | None = None
+ updated_at: float = field(default_factory=time.time)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API calls."""
+ data = {
+ "file_execution_id": self.file_execution_id,
+ "status": self.status,
+ "updated_at": self.updated_at,
+ }
+ if self.result is not None:
+ data["result"] = self.result
+ if self.error_message is not None:
+ data["error_message"] = self.error_message
+ if self.processing_time is not None:
+ data["processing_time"] = self.processing_time
+ return data
+
+
+@dataclass
+class WebhookNotificationRequest:
+ """Request model for webhook notifications."""
+
+ url: str
+ payload: dict[str, Any]
+ notification_id: str | None = None
+ headers: dict[str, str] | None = None
+ timeout: int = 30
+ retry_count: int = 3
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API calls."""
+ data = {
+ "url": self.url,
+ "payload": self.payload,
+ "timeout": self.timeout,
+ "retry_count": self.retry_count,
+ }
+ if self.notification_id is not None:
+ data["notification_id"] = self.notification_id
+ if self.headers is not None:
+ data["headers"] = self.headers
+ return data
diff --git a/workers/shared/models/callback_models.py b/workers/shared/models/callback_models.py
new file mode 100644
index 000000000..386b1ae85
--- /dev/null
+++ b/workers/shared/models/callback_models.py
@@ -0,0 +1,94 @@
+"""Callback Task Models
+
+Dataclasses for callback task execution and aggregation.
+"""
+
+import os
+import sys
+from dataclasses import dataclass, field
+from datetime import datetime
+from typing import Any
+
+# Import shared domain models from core
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core import ExecutionStatus, serialize_dataclass_to_dict
+
+# Import result models
+from .result_models import BatchExecutionResult
+
+
+@dataclass
+class CallbackExecutionData:
+ """Data structure for callback task execution context."""
+
+ execution_id: str
+ pipeline_id: str
+ organization_id: str
+ workflow_id: str
+ batch_results: list[BatchExecutionResult] = field(default_factory=list)
+ total_batches: int = 0
+ completed_batches: int = 0
+ callback_triggered_at: datetime | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API serialization."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "CallbackExecutionData":
+ """Create from dictionary (e.g., callback kwargs)."""
+ batch_results = [
+ BatchExecutionResult.from_dict(result)
+ for result in data.get("batch_results", [])
+ ]
+
+ return cls(
+ execution_id=data.get("execution_id", ""),
+ pipeline_id=data.get("pipeline_id", ""),
+ organization_id=data.get("organization_id", ""),
+ workflow_id=data.get("workflow_id", ""),
+ batch_results=batch_results,
+ total_batches=data.get("total_batches", 0),
+ completed_batches=data.get("completed_batches", 0),
+ callback_triggered_at=data.get("callback_triggered_at"),
+ )
+
+ @property
+ def total_files_processed(self) -> int:
+ """Calculate total files processed across all batches."""
+ return sum(batch.total_files for batch in self.batch_results)
+
+ @property
+ def total_successful_files(self) -> int:
+ """Calculate total successful files across all batches."""
+ return sum(batch.successful_files for batch in self.batch_results)
+
+ @property
+ def total_failed_files(self) -> int:
+ """Calculate total failed files across all batches."""
+ return sum(batch.failed_files for batch in self.batch_results)
+
+ @property
+ def overall_success_rate(self) -> float:
+ """Calculate overall success rate across all batches."""
+ total = self.total_files_processed
+ if total == 0:
+ return 0.0
+ return (self.total_successful_files / total) * 100
+
+ def determine_final_status(self) -> ExecutionStatus:
+ """Determine final execution status based on batch results."""
+ if not self.batch_results:
+ return ExecutionStatus.ERROR
+
+ total_files = self.total_files_processed
+ successful_files = self.total_successful_files
+
+ if total_files == 0:
+ return ExecutionStatus.ERROR
+ elif successful_files == total_files:
+ return ExecutionStatus.COMPLETED
+ elif successful_files > 0:
+ return ExecutionStatus.COMPLETED # Partial success still marked as completed
+ else:
+ return ExecutionStatus.ERROR
diff --git a/workers/shared/models/config_models.py b/workers/shared/models/config_models.py
new file mode 100644
index 000000000..f4381fedd
--- /dev/null
+++ b/workers/shared/models/config_models.py
@@ -0,0 +1,658 @@
+"""Configuration Dataclass Models
+
+Enhanced configuration dataclasses for type-safe, validated worker configuration management.
+These dataclasses complement the existing config.py patterns with stronger typing and validation.
+"""
+
+import logging
+import os
+import sys
+from dataclasses import dataclass, field
+from enum import Enum
+from pathlib import Path
+from typing import Any
+
+# Import shared domain models from core
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core import serialize_dataclass_to_dict
+
+logger = logging.getLogger(__name__)
+
+
+class CacheBackend(Enum):
+ """Supported cache backends."""
+
+ REDIS = "redis"
+ MEMORY = "memory"
+ DISABLED = "disabled"
+
+
+class LogLevel(Enum):
+ """Supported log levels."""
+
+ DEBUG = "DEBUG"
+ INFO = "INFO"
+ WARNING = "WARNING"
+ ERROR = "ERROR"
+ CRITICAL = "CRITICAL"
+
+
+class PluginType(Enum):
+ """Supported plugin types."""
+
+ PROCESSOR = "processor"
+ CONNECTOR = "connector"
+ AUTHENTICATION = "authentication"
+ MODIFIER = "modifier"
+ QUEUES = "queues"
+ SUBSCRIPTION = "subscription"
+
+
+@dataclass
+class CacheConfig:
+ """Type-safe cache configuration with validation."""
+
+ backend: CacheBackend
+ enabled: bool = True
+ default_ttl: int = 60 # seconds
+ max_entries: int = 10000
+
+ # Redis-specific configuration
+ redis_host: str = "localhost"
+ redis_port: int = 6379
+ redis_db: int = 1
+ redis_password: str | None = None
+ redis_username: str | None = None
+ redis_ssl: bool = False
+ redis_ssl_cert_reqs: str = "required"
+ redis_url: str | None = None
+
+ # Memory cache specific
+ memory_max_size_mb: int = 256
+
+ # TTL configurations for different cache types
+ execution_status_ttl: int = 30
+ pipeline_status_ttl: int = 60
+ batch_summary_ttl: int = 90
+ workflow_definition_ttl: int = 300
+
+ def __post_init__(self):
+ """Validate cache configuration after initialization."""
+ if self.backend == CacheBackend.DISABLED:
+ self.enabled = False
+ return
+
+ if not self.enabled:
+ return
+
+ errors = []
+
+ # Validate TTL values
+ if self.default_ttl <= 0:
+ errors.append("default_ttl must be positive")
+ if self.execution_status_ttl <= 0:
+ errors.append("execution_status_ttl must be positive")
+ if self.pipeline_status_ttl <= 0:
+ errors.append("pipeline_status_ttl must be positive")
+ if self.batch_summary_ttl <= 0:
+ errors.append("batch_summary_ttl must be positive")
+ if self.workflow_definition_ttl <= 0:
+ errors.append("workflow_definition_ttl must be positive")
+
+ # Redis-specific validation
+ if self.backend == CacheBackend.REDIS:
+ if not self.redis_host:
+ errors.append("redis_host is required for Redis backend")
+ if self.redis_port <= 0 or self.redis_port > 65535:
+ errors.append("redis_port must be between 1 and 65535")
+ if self.redis_db < 0:
+ errors.append("redis_db must be non-negative")
+
+ # Memory cache validation
+ if self.backend == CacheBackend.MEMORY:
+ if self.memory_max_size_mb <= 0:
+ errors.append("memory_max_size_mb must be positive")
+ if self.max_entries <= 0:
+ errors.append("max_entries must be positive")
+
+ if errors:
+ raise ValueError(
+ f"Cache configuration validation failed: {'; '.join(errors)}"
+ )
+
+ def get_redis_url(self) -> str:
+ """Build Redis URL from configuration components."""
+ if self.backend != CacheBackend.REDIS or not self.enabled:
+ return ""
+
+ if self.redis_url:
+ return self.redis_url
+
+ # Build Redis URL with authentication and SSL options
+ scheme = "rediss" if self.redis_ssl else "redis"
+
+ # Build authentication part
+ auth_part = ""
+ if self.redis_username and self.redis_password:
+ auth_part = f"{self.redis_username}:{self.redis_password}@"
+ elif self.redis_password:
+ auth_part = f":{self.redis_password}@"
+
+ # Build base URL
+ url = f"{scheme}://{auth_part}{self.redis_host}:{self.redis_port}/{self.redis_db}"
+
+ # Add SSL parameters if needed
+ if self.redis_ssl and self.redis_ssl_cert_reqs != "required":
+ url += f"?ssl_cert_reqs={self.redis_ssl_cert_reqs}"
+
+ return url
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_env(cls, prefix: str = "CACHE_") -> "CacheConfig":
+ """Create cache configuration from environment variables."""
+ backend_str = os.getenv(f"{prefix}BACKEND", "redis").lower()
+ backend = CacheBackend.REDIS if backend_str == "redis" else CacheBackend.MEMORY
+
+ if os.getenv(f"{prefix}REDIS_ENABLED", "true").lower() == "false":
+ backend = CacheBackend.DISABLED
+
+ return cls(
+ backend=backend,
+ enabled=os.getenv(f"{prefix}ENABLED", "true").lower() == "true",
+ default_ttl=int(os.getenv(f"{prefix}DEFAULT_TTL", "60")),
+ max_entries=int(os.getenv(f"{prefix}MAX_ENTRIES", "10000")),
+ redis_host=os.getenv(f"{prefix}REDIS_HOST", "localhost"),
+ redis_port=int(os.getenv(f"{prefix}REDIS_PORT", "6379")),
+ redis_db=int(os.getenv(f"{prefix}REDIS_DB", "1")),
+ redis_password=os.getenv(f"{prefix}REDIS_PASSWORD"),
+ redis_username=os.getenv(f"{prefix}REDIS_USERNAME"),
+ redis_ssl=os.getenv(f"{prefix}REDIS_SSL", "false").lower() == "true",
+ redis_ssl_cert_reqs=os.getenv(f"{prefix}REDIS_SSL_CERT_REQS", "required"),
+ redis_url=os.getenv(f"{prefix}REDIS_URL"),
+ memory_max_size_mb=int(os.getenv(f"{prefix}MEMORY_MAX_SIZE_MB", "256")),
+ execution_status_ttl=int(os.getenv(f"{prefix}EXECUTION_STATUS_TTL", "30")),
+ pipeline_status_ttl=int(os.getenv(f"{prefix}PIPELINE_STATUS_TTL", "60")),
+ batch_summary_ttl=int(os.getenv(f"{prefix}BATCH_SUMMARY_TTL", "90")),
+ workflow_definition_ttl=int(
+ os.getenv(f"{prefix}WORKFLOW_DEFINITION_TTL", "300")
+ ),
+ )
+
+
+@dataclass
+class PluginConfig:
+ """Type-safe plugin configuration with validation."""
+
+ plugin_id: str
+ plugin_name: str
+ plugin_type: PluginType
+ enabled: bool = True
+ version: str = "1.0.0"
+
+ # Plugin-specific settings
+ settings: dict[str, Any] = field(default_factory=dict)
+
+ # Plugin loading configuration
+ module_path: str | None = None
+ class_name: str | None = None
+ priority: int = 100 # Lower number = higher priority
+
+ # Dependencies and requirements
+ dependencies: list[str] = field(default_factory=list)
+ required_env_vars: list[str] = field(default_factory=list)
+
+ # Resource limits
+ max_memory_mb: int = 512
+ max_execution_time: int = 300 # seconds
+
+ # Error handling
+ retry_attempts: int = 3
+ retry_backoff_factor: float = 1.5
+
+ def __post_init__(self):
+ """Validate plugin configuration after initialization."""
+ errors = []
+
+ # Required fields validation
+ if not self.plugin_id:
+ errors.append("plugin_id is required")
+ if not self.plugin_name:
+ errors.append("plugin_name is required")
+
+ # Numeric validations
+ if self.priority < 0:
+ errors.append("priority must be non-negative")
+ if self.max_memory_mb <= 0:
+ errors.append("max_memory_mb must be positive")
+ if self.max_execution_time <= 0:
+ errors.append("max_execution_time must be positive")
+ if self.retry_attempts < 0:
+ errors.append("retry_attempts must be non-negative")
+ if self.retry_backoff_factor <= 0:
+ errors.append("retry_backoff_factor must be positive")
+
+ # Module path validation
+ if self.module_path and not self.class_name:
+ errors.append("class_name is required when module_path is specified")
+
+ # Check required environment variables
+ if self.enabled:
+ missing_env_vars = [
+ var for var in self.required_env_vars if not os.getenv(var)
+ ]
+ if missing_env_vars:
+ errors.append(
+ f"Missing required environment variables: {missing_env_vars}"
+ )
+
+ if errors:
+ raise ValueError(
+ f"Plugin configuration validation failed: {'; '.join(errors)}"
+ )
+
+ def is_loadable(self) -> bool:
+ """Check if plugin can be loaded based on configuration."""
+ if not self.enabled:
+ return False
+
+ # Check if module path exists
+ if self.module_path:
+ try:
+ module_file = Path(self.module_path)
+ if not module_file.exists():
+ return False
+ except Exception:
+ return False
+
+ # Check required environment variables
+ for var in self.required_env_vars:
+ if not os.getenv(var):
+ return False
+
+ return True
+
+ def get_import_path(self) -> str | None:
+ """Get the full import path for the plugin."""
+ if not self.module_path or not self.class_name:
+ return None
+ return f"{self.module_path}.{self.class_name}"
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "PluginConfig":
+ """Create PluginConfig from dictionary data."""
+ plugin_type_str = data.get("plugin_type", "processor")
+ plugin_type = (
+ PluginType(plugin_type_str)
+ if isinstance(plugin_type_str, str)
+ else plugin_type_str
+ )
+
+ return cls(
+ plugin_id=data["plugin_id"],
+ plugin_name=data["plugin_name"],
+ plugin_type=plugin_type,
+ enabled=data.get("enabled", True),
+ version=data.get("version", "1.0.0"),
+ settings=data.get("settings", {}),
+ module_path=data.get("module_path"),
+ class_name=data.get("class_name"),
+ priority=data.get("priority", 100),
+ dependencies=data.get("dependencies", []),
+ required_env_vars=data.get("required_env_vars", []),
+ max_memory_mb=data.get("max_memory_mb", 512),
+ max_execution_time=data.get("max_execution_time", 300),
+ retry_attempts=data.get("retry_attempts", 3),
+ retry_backoff_factor=data.get("retry_backoff_factor", 1.5),
+ )
+
+
+@dataclass
+class PluginRegistry:
+ """Registry for managing multiple plugin configurations."""
+
+ plugins: list[PluginConfig] = field(default_factory=list)
+ enabled_only: bool = True
+
+ def add_plugin(self, plugin: PluginConfig) -> None:
+ """Add a plugin to the registry."""
+ # Check for duplicate plugin IDs
+ existing_ids = {p.plugin_id for p in self.plugins}
+ if plugin.plugin_id in existing_ids:
+ raise ValueError(f"Plugin with ID '{plugin.plugin_id}' already exists")
+
+ self.plugins.append(plugin)
+
+ def get_plugin(self, plugin_id: str) -> PluginConfig | None:
+ """Get a plugin by ID."""
+ for plugin in self.plugins:
+ if plugin.plugin_id == plugin_id:
+ return plugin
+ return None
+
+ def get_plugins_by_type(self, plugin_type: PluginType) -> list[PluginConfig]:
+ """Get all plugins of a specific type."""
+ plugins = [p for p in self.plugins if p.plugin_type == plugin_type]
+ if self.enabled_only:
+ plugins = [p for p in plugins if p.enabled]
+ return sorted(plugins, key=lambda p: p.priority)
+
+ def get_enabled_plugins(self) -> list[PluginConfig]:
+ """Get all enabled plugins sorted by priority."""
+ plugins = [p for p in self.plugins if p.enabled]
+ return sorted(plugins, key=lambda p: p.priority)
+
+ def get_loadable_plugins(self) -> list[PluginConfig]:
+ """Get all plugins that can be loaded."""
+ return [p for p in self.plugins if p.is_loadable()]
+
+ def validate_dependencies(self) -> list[str]:
+ """Validate plugin dependencies and return any errors."""
+ errors = []
+ plugin_ids = {p.plugin_id for p in self.plugins}
+
+ for plugin in self.plugins:
+ if not plugin.enabled:
+ continue
+
+ for dependency in plugin.dependencies:
+ if dependency not in plugin_ids:
+ errors.append(
+ f"Plugin '{plugin.plugin_id}' depends on missing plugin '{dependency}'"
+ )
+ else:
+ # Check if dependency is enabled
+ dep_plugin = self.get_plugin(dependency)
+ if dep_plugin and not dep_plugin.enabled:
+ errors.append(
+ f"Plugin '{plugin.plugin_id}' depends on disabled plugin '{dependency}'"
+ )
+
+ return errors
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert registry to dictionary."""
+ return {
+ "plugins": [plugin.to_dict() for plugin in self.plugins],
+ "enabled_only": self.enabled_only,
+ "plugin_count": len(self.plugins),
+ "enabled_count": len([p for p in self.plugins if p.enabled]),
+ "loadable_count": len(self.get_loadable_plugins()),
+ }
+
+ @classmethod
+ def from_config_dir(cls, config_dir: str | Path) -> "PluginRegistry":
+ """Load plugin registry from configuration directory."""
+ registry = cls()
+ config_path = Path(config_dir)
+
+ if not config_path.exists():
+ return registry
+
+ # Look for plugin configuration files
+ for config_file in config_path.glob("plugin_*.json"):
+ try:
+ import json
+
+ with open(config_file) as f:
+ plugin_data = json.load(f)
+
+ if isinstance(plugin_data, list):
+ # Multiple plugins in one file
+ for plugin_dict in plugin_data:
+ plugin = PluginConfig.from_dict(plugin_dict)
+ registry.add_plugin(plugin)
+ else:
+ # Single plugin in file
+ plugin = PluginConfig.from_dict(plugin_data)
+ registry.add_plugin(plugin)
+
+ except Exception as e:
+ # Log error but continue loading other plugins
+ logger.exception(f"Error loading plugin config from {config_file}: {e}")
+
+ return registry
+
+
+@dataclass
+class WorkerMetrics:
+ """Configuration for worker metrics and monitoring."""
+
+ enabled: bool = True
+ collection_interval: int = 60 # seconds
+ retention_days: int = 7
+
+ # Metric types to collect
+ collect_performance_metrics: bool = True
+ collect_error_metrics: bool = True
+ collect_queue_metrics: bool = True
+ collect_resource_metrics: bool = True
+
+ # Export configuration
+ export_prometheus: bool = False
+ export_statsd: bool = False
+ export_cloudwatch: bool = False
+
+ # Prometheus configuration
+ prometheus_port: int = 8080
+ prometheus_path: str = "/metrics"
+
+ # StatsD configuration
+ statsd_host: str = "localhost"
+ statsd_port: int = 8125
+ statsd_prefix: str = "unstract.worker"
+
+ # CloudWatch configuration
+ cloudwatch_namespace: str = "Unstract/Workers"
+ cloudwatch_region: str = "us-east-1"
+
+ def __post_init__(self):
+ """Validate metrics configuration."""
+ errors = []
+
+ if self.collection_interval <= 0:
+ errors.append("collection_interval must be positive")
+ if self.retention_days <= 0:
+ errors.append("retention_days must be positive")
+
+ if self.export_prometheus:
+ if self.prometheus_port <= 0 or self.prometheus_port > 65535:
+ errors.append("prometheus_port must be between 1 and 65535")
+ if not self.prometheus_path.startswith("/"):
+ errors.append("prometheus_path must start with '/'")
+
+ if self.export_statsd:
+ if not self.statsd_host:
+ errors.append("statsd_host is required for StatsD export")
+ if self.statsd_port <= 0 or self.statsd_port > 65535:
+ errors.append("statsd_port must be between 1 and 65535")
+
+ if errors:
+ raise ValueError(
+ f"Metrics configuration validation failed: {'; '.join(errors)}"
+ )
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_env(cls, prefix: str = "METRICS_") -> "WorkerMetrics":
+ """Create metrics configuration from environment variables."""
+ return cls(
+ enabled=os.getenv(f"{prefix}ENABLED", "true").lower() == "true",
+ collection_interval=int(os.getenv(f"{prefix}COLLECTION_INTERVAL", "60")),
+ retention_days=int(os.getenv(f"{prefix}RETENTION_DAYS", "7")),
+ collect_performance_metrics=os.getenv(
+ f"{prefix}COLLECT_PERFORMANCE", "true"
+ ).lower()
+ == "true",
+ collect_error_metrics=os.getenv(f"{prefix}COLLECT_ERROR", "true").lower()
+ == "true",
+ collect_queue_metrics=os.getenv(f"{prefix}COLLECT_QUEUE", "true").lower()
+ == "true",
+ collect_resource_metrics=os.getenv(
+ f"{prefix}COLLECT_RESOURCE", "true"
+ ).lower()
+ == "true",
+ export_prometheus=os.getenv(f"{prefix}EXPORT_PROMETHEUS", "false").lower()
+ == "true",
+ export_statsd=os.getenv(f"{prefix}EXPORT_STATSD", "false").lower() == "true",
+ export_cloudwatch=os.getenv(f"{prefix}EXPORT_CLOUDWATCH", "false").lower()
+ == "true",
+ prometheus_port=int(os.getenv(f"{prefix}PROMETHEUS_PORT", "8080")),
+ prometheus_path=os.getenv(f"{prefix}PROMETHEUS_PATH", "/metrics"),
+ statsd_host=os.getenv(f"{prefix}STATSD_HOST", "localhost"),
+ statsd_port=int(os.getenv(f"{prefix}STATSD_PORT", "8125")),
+ statsd_prefix=os.getenv(f"{prefix}STATSD_PREFIX", "unstract.worker"),
+ cloudwatch_namespace=os.getenv(
+ f"{prefix}CLOUDWATCH_NAMESPACE", "Unstract/Workers"
+ ),
+ cloudwatch_region=os.getenv(f"{prefix}CLOUDWATCH_REGION", "us-east-1"),
+ )
+
+
+@dataclass
+class SecurityConfig:
+ """Security configuration for workers."""
+
+ # API security
+ require_api_key: bool = True
+ api_key_header_name: str = "X-API-Key"
+
+ # SSL/TLS configuration
+ ssl_verify: bool = True
+ ssl_cert_path: str | None = None
+ ssl_key_path: str | None = None
+ ssl_ca_path: str | None = None
+
+ # Request validation
+ max_request_size_mb: int = 100
+ allowed_mime_types: list[str] = field(
+ default_factory=lambda: [
+ "application/pdf",
+ "text/plain",
+ "text/csv",
+ "application/json",
+ ]
+ )
+
+ # Rate limiting
+ rate_limit_enabled: bool = False
+ rate_limit_requests_per_minute: int = 100
+ rate_limit_burst_size: int = 20
+
+ # Content security
+ sanitize_file_names: bool = True
+ allow_external_urls: bool = False
+ blocked_ip_ranges: list[str] = field(default_factory=list)
+
+ def __post_init__(self):
+ """Validate security configuration."""
+ errors = []
+
+ if self.max_request_size_mb <= 0:
+ errors.append("max_request_size_mb must be positive")
+
+ if self.rate_limit_enabled:
+ if self.rate_limit_requests_per_minute <= 0:
+ errors.append("rate_limit_requests_per_minute must be positive")
+ if self.rate_limit_burst_size <= 0:
+ errors.append("rate_limit_burst_size must be positive")
+
+ # Validate SSL paths if provided
+ if self.ssl_cert_path and not Path(self.ssl_cert_path).exists():
+ errors.append(f"SSL certificate file not found: {self.ssl_cert_path}")
+ if self.ssl_key_path and not Path(self.ssl_key_path).exists():
+ errors.append(f"SSL key file not found: {self.ssl_key_path}")
+ if self.ssl_ca_path and not Path(self.ssl_ca_path).exists():
+ errors.append(f"SSL CA file not found: {self.ssl_ca_path}")
+
+ if errors:
+ raise ValueError(
+ f"Security configuration validation failed: {'; '.join(errors)}"
+ )
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_env(cls, prefix: str = "SECURITY_") -> "SecurityConfig":
+ """Create security configuration from environment variables."""
+ # Parse allowed MIME types from comma-separated string
+ mime_types_str = os.getenv(f"{prefix}ALLOWED_MIME_TYPES", "")
+ allowed_mime_types = (
+ [mime.strip() for mime in mime_types_str.split(",") if mime.strip()]
+ if mime_types_str
+ else ["application/pdf", "text/plain", "text/csv", "application/json"]
+ )
+
+ # Parse blocked IP ranges
+ ip_ranges_str = os.getenv(f"{prefix}BLOCKED_IP_RANGES", "")
+ blocked_ip_ranges = (
+ [ip.strip() for ip in ip_ranges_str.split(",") if ip.strip()]
+ if ip_ranges_str
+ else []
+ )
+
+ return cls(
+ require_api_key=os.getenv(f"{prefix}REQUIRE_API_KEY", "true").lower()
+ == "true",
+ api_key_header_name=os.getenv(f"{prefix}API_KEY_HEADER_NAME", "X-API-Key"),
+ ssl_verify=os.getenv(f"{prefix}SSL_VERIFY", "true").lower() == "true",
+ ssl_cert_path=os.getenv(f"{prefix}SSL_CERT_PATH"),
+ ssl_key_path=os.getenv(f"{prefix}SSL_KEY_PATH"),
+ ssl_ca_path=os.getenv(f"{prefix}SSL_CA_PATH"),
+ max_request_size_mb=int(os.getenv(f"{prefix}MAX_REQUEST_SIZE_MB", "100")),
+ allowed_mime_types=allowed_mime_types,
+ rate_limit_enabled=os.getenv(f"{prefix}RATE_LIMIT_ENABLED", "false").lower()
+ == "true",
+ rate_limit_requests_per_minute=int(
+ os.getenv(f"{prefix}RATE_LIMIT_REQUESTS_PER_MINUTE", "100")
+ ),
+ rate_limit_burst_size=int(os.getenv(f"{prefix}RATE_LIMIT_BURST_SIZE", "20")),
+ sanitize_file_names=os.getenv(f"{prefix}SANITIZE_FILE_NAMES", "true").lower()
+ == "true",
+ allow_external_urls=os.getenv(f"{prefix}ALLOW_EXTERNAL_URLS", "false").lower()
+ == "true",
+ blocked_ip_ranges=blocked_ip_ranges,
+ )
+
+
+# Utility functions for configuration management
+def load_configuration_from_env(prefix: str = "") -> dict[str, Any]:
+ """Load all configuration dataclasses from environment variables."""
+ cache_prefix = f"{prefix}CACHE_" if prefix else "CACHE_"
+ metrics_prefix = f"{prefix}METRICS_" if prefix else "METRICS_"
+ security_prefix = f"{prefix}SECURITY_" if prefix else "SECURITY_"
+
+ return {
+ "cache": CacheConfig.from_env(cache_prefix),
+ "metrics": WorkerMetrics.from_env(metrics_prefix),
+ "security": SecurityConfig.from_env(security_prefix),
+ }
+
+
+def validate_all_configurations(configs: dict[str, Any]) -> list[str]:
+ """Validate all configuration dataclasses and return any errors."""
+ errors = []
+
+ for config_name, config in configs.items():
+ try:
+ # Dataclasses with __post_init__ validation will raise ValueError
+ if hasattr(config, "__post_init__"):
+ config.__post_init__()
+ except ValueError as e:
+ errors.append(f"{config_name}: {str(e)}")
+ except Exception as e:
+ errors.append(f"{config_name}: Unexpected validation error: {str(e)}")
+
+ return errors
diff --git a/workers/shared/models/conversion_utils.py b/workers/shared/models/conversion_utils.py
new file mode 100644
index 000000000..3998491c9
--- /dev/null
+++ b/workers/shared/models/conversion_utils.py
@@ -0,0 +1,338 @@
+"""Conversion Utilities for Dataclass Migration
+
+Utility functions to handle conversion between dictionaries and dataclasses
+during the migration process. These utilities help maintain backward compatibility
+while gradually moving to type-safe dataclass patterns.
+"""
+
+import os
+import sys
+from dataclasses import is_dataclass
+from typing import Any, TypeVar
+
+# Import shared domain models from core
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core import serialize_dataclass_to_dict
+
+from .api_responses import (
+ BaseAPIResponse,
+ FileExecutionResponse,
+ WorkflowExecutionResponse,
+)
+
+# Import our dataclasses
+from .execution_models import (
+ WorkflowConfig,
+ WorkflowContextData,
+)
+from .notification_models import (
+ NotificationRequest,
+ WebhookNotificationRequest,
+)
+
+T = TypeVar("T")
+
+
+class ConversionError(Exception):
+ """Exception raised when conversion between dict and dataclass fails."""
+
+ pass
+
+
+def ensure_dataclass(data: dict[str, Any] | T, target_class: type[T]) -> T:
+ """Ensure data is converted to target dataclass if it's a dictionary.
+
+ Args:
+ data: Either a dictionary or an instance of target_class
+ target_class: The dataclass type to convert to
+
+ Returns:
+ Instance of target_class
+
+ Raises:
+ ConversionError: If conversion fails
+ """
+ if isinstance(data, target_class):
+ return data
+
+ if isinstance(data, dict):
+ try:
+ if hasattr(target_class, "from_dict"):
+ return target_class.from_dict(data)
+ else:
+ # Try direct instantiation with dict unpacking
+ return target_class(**data)
+ except Exception as e:
+ raise ConversionError(
+ f"Failed to convert dict to {target_class.__name__}: {str(e)}"
+ ) from e
+
+ raise ConversionError(
+ f"Cannot convert {type(data)} to {target_class.__name__}. "
+ f"Expected dict or {target_class.__name__} instance."
+ )
+
+
+def ensure_dict(data: dict[str, Any] | Any) -> dict[str, Any]:
+ """Ensure data is converted to dictionary if it's a dataclass.
+
+ Args:
+ data: Either a dictionary or a dataclass instance
+
+ Returns:
+ Dictionary representation of the data
+
+ Raises:
+ ConversionError: If conversion fails
+ """
+ if isinstance(data, dict):
+ return data
+
+ if is_dataclass(data):
+ try:
+ if hasattr(data, "to_dict"):
+ return data.to_dict()
+ else:
+ return serialize_dataclass_to_dict(data)
+ except Exception as e:
+ raise ConversionError(
+ f"Failed to convert {type(data).__name__} to dict: {str(e)}"
+ ) from e
+
+ # For other types, try to convert to dict if possible
+ if hasattr(data, "__dict__"):
+ return data.__dict__
+
+ raise ConversionError(
+ f"Cannot convert {type(data)} to dict. Expected dict or dataclass instance."
+ )
+
+
+def convert_workflow_config(config: dict[str, Any] | WorkflowConfig) -> WorkflowConfig:
+ """Convert workflow configuration to WorkflowConfig dataclass.
+
+ Args:
+ config: Dictionary or WorkflowConfig instance
+
+ Returns:
+ WorkflowConfig dataclass instance
+ """
+ return ensure_dataclass(config, WorkflowConfig)
+
+
+def convert_execution_context(
+ context: dict[str, Any] | WorkflowContextData,
+) -> WorkflowContextData:
+ """Convert execution context to WorkflowContextData dataclass.
+
+ Args:
+ context: Dictionary or WorkflowContextData instance
+
+ Returns:
+ WorkflowContextData dataclass instance
+ """
+ return ensure_dataclass(context, WorkflowContextData)
+
+
+def convert_notification_request(
+ request: dict[str, Any] | NotificationRequest | WebhookNotificationRequest,
+) -> NotificationRequest | WebhookNotificationRequest:
+ """Convert notification request to appropriate dataclass.
+
+ Args:
+ request: Dictionary, NotificationRequest, or WebhookNotificationRequest
+
+ Returns:
+ Appropriate notification request dataclass
+ """
+ if isinstance(request, (NotificationRequest, WebhookNotificationRequest)):
+ return request
+
+ if isinstance(request, dict):
+ # Determine the appropriate dataclass based on the data
+ notification_type = request.get("notification_type", "WEBHOOK")
+
+ if notification_type == "WEBHOOK" or "url" in request:
+ return ensure_dataclass(request, WebhookNotificationRequest)
+ else:
+ return ensure_dataclass(request, NotificationRequest)
+
+ raise ConversionError(
+ f"Cannot convert {type(request)} to notification request dataclass"
+ )
+
+
+def batch_convert_to_dataclass(
+ items: list[dict[str, Any] | T], target_class: type[T]
+) -> list[T]:
+ """Convert a list of dictionaries/dataclasses to target dataclass type.
+
+ Args:
+ items: List of dictionaries or dataclass instances
+ target_class: The dataclass type to convert to
+
+ Returns:
+ List of target_class instances
+
+ Raises:
+ ConversionError: If any conversion fails
+ """
+ converted = []
+ for i, item in enumerate(items):
+ try:
+ converted.append(ensure_dataclass(item, target_class))
+ except ConversionError as e:
+ raise ConversionError(f"Failed to convert item {i}: {str(e)}") from e
+
+ return converted
+
+
+def batch_convert_to_dict(items: list[dict[str, Any] | Any]) -> list[dict[str, Any]]:
+ """Convert a list of dataclasses/dictionaries to dictionaries.
+
+ Args:
+ items: List of dataclass instances or dictionaries
+
+ Returns:
+ List of dictionaries
+
+ Raises:
+ ConversionError: If any conversion fails
+ """
+ converted = []
+ for i, item in enumerate(items):
+ try:
+ converted.append(ensure_dict(item))
+ except ConversionError as e:
+ raise ConversionError(f"Failed to convert item {i}: {str(e)}") from e
+
+ return converted
+
+
+def safe_convert_to_dataclass(
+ data: dict[str, Any] | T, target_class: type[T], default: T | None = None
+) -> T | None:
+ """Safely convert data to dataclass, returning default on failure.
+
+ Args:
+ data: Data to convert
+ target_class: Target dataclass type
+ default: Default value to return on conversion failure
+
+ Returns:
+ Converted dataclass instance or default value
+ """
+ try:
+ return ensure_dataclass(data, target_class)
+ except ConversionError:
+ return default
+
+
+def safe_convert_to_dict(
+ data: dict[str, Any] | Any, default: dict[str, Any] | None = None
+) -> dict[str, Any] | None:
+ """Safely convert data to dictionary, returning default on failure.
+
+ Args:
+ data: Data to convert
+ default: Default value to return on conversion failure
+
+ Returns:
+ Converted dictionary or default value
+ """
+ try:
+ return ensure_dict(data)
+ except ConversionError:
+ return default or {}
+
+
+def create_backward_compatible_function(original_func, conversion_mapping):
+ """Create a backward compatible version of a function with automatic conversion.
+
+ This decorator can be used to wrap functions that have been updated to use
+ dataclasses but need to maintain backward compatibility with dictionary inputs.
+
+ Args:
+ original_func: The function to wrap
+ conversion_mapping: Dict mapping parameter names to conversion functions
+
+ Returns:
+ Wrapped function that automatically converts parameters
+ """
+
+ def wrapper(*args, **kwargs):
+ # Convert positional arguments if needed
+ converted_args = list(args)
+
+ # Convert keyword arguments if needed
+ converted_kwargs = {}
+ for key, value in kwargs.items():
+ if key in conversion_mapping:
+ converter = conversion_mapping[key]
+ try:
+ converted_kwargs[key] = converter(value)
+ except ConversionError:
+ # Keep original value if conversion fails
+ converted_kwargs[key] = value
+ else:
+ converted_kwargs[key] = value
+
+ return original_func(*converted_args, **converted_kwargs)
+
+ return wrapper
+
+
+# Pre-configured conversion functions for common use cases
+def convert_workflow_execution_data(
+ data: dict[str, Any] | WorkflowContextData,
+) -> WorkflowContextData:
+ """Convert workflow execution data with enhanced error handling."""
+ if isinstance(data, WorkflowContextData):
+ return data
+
+ if not isinstance(data, dict):
+ raise ConversionError(f"Expected dict or WorkflowContextData, got {type(data)}")
+
+ # Ensure required fields are present
+ required_fields = ["workflow_id", "workflow_name", "workflow_type", "execution_id"]
+ missing_fields = [field for field in required_fields if field not in data]
+
+ if missing_fields:
+ raise ConversionError(f"Missing required fields: {missing_fields}")
+
+ return WorkflowContextData.from_dict(data)
+
+
+def convert_api_response_data(data: dict[str, Any] | BaseAPIResponse) -> BaseAPIResponse:
+ """Convert API response data with type detection."""
+ if isinstance(data, BaseAPIResponse):
+ return data
+
+ if not isinstance(data, dict):
+ raise ConversionError(f"Expected dict or BaseAPIResponse, got {type(data)}")
+
+ # Try to determine the specific response type based on data content
+ if "workflow_id" in data:
+ return WorkflowExecutionResponse.from_api_response(data)
+ elif "file_execution_id" in data:
+ return FileExecutionResponse.from_api_response(data)
+ else:
+ return BaseAPIResponse.from_api_response(data)
+
+
+# Utility constants for common conversion patterns
+def _workflow_config_converter(x):
+ return convert_workflow_config(x)
+
+
+def _execution_context_converter(x):
+ return convert_execution_context(x)
+
+
+def _notification_request_converter(x):
+ return convert_notification_request(x)
+
+
+WORKFLOW_CONFIG_CONVERTER = _workflow_config_converter
+EXECUTION_CONTEXT_CONVERTER = _execution_context_converter
+NOTIFICATION_REQUEST_CONVERTER = _notification_request_converter
diff --git a/workers/shared/models/execution_models.py b/workers/shared/models/execution_models.py
new file mode 100644
index 000000000..e9149b4e9
--- /dev/null
+++ b/workers/shared/models/execution_models.py
@@ -0,0 +1,978 @@
+"""Execution Context Models for Worker Operations
+
+This module provides strongly-typed dataclasses for workflow execution contexts,
+replacing fragile dictionary-based parameter passing with type-safe structures.
+"""
+
+from dataclasses import dataclass, field
+from typing import TYPE_CHECKING, Any
+
+# Import shared domain models from core
+from unstract.core.data_models import (
+ ExecutionStatus,
+ PreCreatedFileData,
+ serialize_dataclass_to_dict,
+)
+
+# Avoid circular imports by using TYPE_CHECKING
+if TYPE_CHECKING:
+ from ..api_client import InternalAPIClient
+
+from ..enums import PipelineType
+
+
+@dataclass
+class WorkflowExecutionContext:
+ """Strongly-typed context for workflow execution operations.
+
+ Replaces dictionary-based context passing with type-safe dataclass
+ that provides validation, autocomplete, and clear documentation.
+ """
+
+ files: dict[str, Any]
+ workflow_id: str
+ execution_id: str
+ api_client: "InternalAPIClient"
+ workflow_type: str
+ is_api_workflow: bool
+ organization_id: str | None = None
+ pipeline_id: str | None = None
+ use_file_history: bool | None = False
+ scheduled: bool | None = False
+
+ def __post_init__(self):
+ """Validate required fields and normalize data after initialization."""
+ if not self.workflow_id:
+ raise ValueError("workflow_id is required for workflow execution")
+
+ if not self.execution_id:
+ raise ValueError("execution_id is required for workflow execution")
+
+ if not self.files:
+ raise ValueError("files dictionary cannot be empty")
+
+ # Normalize workflow_type to ensure consistency
+ if self.workflow_type:
+ self.workflow_type = self.workflow_type.upper()
+
+ # Validate workflow_type against known types
+ valid_types = {pt.value for pt in PipelineType}
+ if self.workflow_type not in valid_types:
+ raise ValueError(
+ f"Invalid workflow_type '{self.workflow_type}'. "
+ f"Must be one of: {valid_types}"
+ )
+
+ @property
+ def file_count(self) -> int:
+ """Get the number of files in this execution context."""
+ return len(self.files) if self.files else 0
+
+ @property
+ def is_scheduled_execution(self) -> bool:
+ """Check if this is a scheduled execution."""
+ return bool(self.scheduled)
+
+ @property
+ def pipeline_type_enum(self) -> PipelineType:
+ """Get the workflow type as a PipelineType enum."""
+ return PipelineType(self.workflow_type)
+
+ def validate_for_api_workflow(self) -> None:
+ """Validate context for API workflow requirements."""
+ if self.is_api_workflow and not self.pipeline_id:
+ raise ValueError("API workflows require pipeline_id")
+
+ def validate_for_file_processing(self) -> None:
+ """Validate context for file processing requirements."""
+ if not self.files:
+ raise ValueError("File processing requires non-empty files dictionary")
+
+ if self.file_count == 0:
+ raise ValueError("File processing requires at least one file")
+
+
+@dataclass
+class FileProcessingBatch:
+ """Strongly-typed batch of files for processing.
+
+ Represents a batch of files that will be processed together,
+ with metadata about the batch and processing context.
+ """
+
+ batch_index: int
+ files: dict[str, Any]
+ execution_context: WorkflowExecutionContext
+ total_batches: int
+ queue_name: str
+
+ def __post_init__(self):
+ """Validate batch data after initialization."""
+ if self.batch_index < 0:
+ raise ValueError("batch_index cannot be negative")
+
+ if self.total_batches <= 0:
+ raise ValueError("total_batches must be positive")
+
+ if self.batch_index >= self.total_batches:
+ raise ValueError("batch_index cannot be >= total_batches")
+
+ if not self.files:
+ raise ValueError("Batch files cannot be empty")
+
+ if not self.queue_name:
+ raise ValueError("queue_name is required for batch processing")
+
+ @property
+ def batch_size(self) -> int:
+ """Get the number of files in this batch."""
+ return len(self.files)
+
+ @property
+ def is_final_batch(self) -> bool:
+ """Check if this is the final batch in the sequence."""
+ return self.batch_index == (self.total_batches - 1)
+
+ @property
+ def batch_progress(self) -> str:
+ """Get human-readable batch progress string."""
+ return f"Batch {self.batch_index + 1}/{self.total_batches}"
+
+
+@dataclass
+class CallbackExecutionContext:
+ """Strongly-typed context for callback execution operations.
+
+ Provides type-safe structure for callback task parameters,
+ replacing dictionary-based parameter passing.
+ """
+
+ execution_id: str
+ organization_id: str
+ workflow_id: str
+ results: list
+ pipeline_id: str | None = None
+ callback_type: str = "batch_callback"
+
+ def __post_init__(self):
+ """Validate callback context after initialization."""
+ if not self.execution_id:
+ raise ValueError("execution_id is required for callback execution")
+
+ if not self.organization_id:
+ raise ValueError("organization_id is required for callback execution")
+
+ if not self.workflow_id:
+ raise ValueError("workflow_id is required for callback execution")
+
+ if self.results is None:
+ raise ValueError("results list is required (can be empty)")
+
+ @property
+ def result_count(self) -> int:
+ """Get the number of results in this callback."""
+ return len(self.results) if self.results else 0
+
+ @property
+ def has_results(self) -> bool:
+ """Check if this callback has any results."""
+ return self.result_count > 0
+
+ def get_successful_results(self) -> list:
+ """Filter and return only successful results."""
+ if not self.results:
+ return []
+
+ return [
+ result
+ for result in self.results
+ if isinstance(result, dict) and not result.get("error")
+ ]
+
+ def get_failed_results(self) -> list:
+ """Filter and return only failed results."""
+ if not self.results:
+ return []
+
+ return [
+ result
+ for result in self.results
+ if isinstance(result, dict) and result.get("error")
+ ]
+
+
+@dataclass
+class TaskExecutionResult:
+ """Strongly-typed result from task execution operations.
+
+ Standardizes task result format across all workers with
+ type safety and validation.
+ """
+
+ execution_id: str
+ status: str
+ files_processed: int
+ success: bool
+ error_message: str | None = None
+ result_data: dict[str, Any] | None = None
+ execution_time_seconds: float | None = None
+ metadata: dict[str, Any] | None = None
+
+ def __post_init__(self):
+ """Validate result data after initialization."""
+ if not self.execution_id:
+ raise ValueError("execution_id is required for task results")
+
+ if not self.status:
+ raise ValueError("status is required for task results")
+
+ if self.files_processed < 0:
+ raise ValueError("files_processed cannot be negative")
+
+ # If success is False, error_message should be provided
+ if not self.success and not self.error_message:
+ raise ValueError("error_message required when success=False")
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if the task execution was successful."""
+ return self.success and not self.error_message
+
+ @property
+ def has_results(self) -> bool:
+ """Check if the task produced result data."""
+ return bool(self.result_data)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert result to dictionary for serialization."""
+ result = {
+ "execution_id": self.execution_id,
+ "status": self.status,
+ "files_processed": self.files_processed,
+ "success": self.success,
+ }
+
+ if self.error_message:
+ result["error_message"] = self.error_message
+
+ if self.result_data:
+ result["result_data"] = self.result_data
+
+ if self.execution_time_seconds is not None:
+ result["execution_time_seconds"] = self.execution_time_seconds
+
+ if self.metadata:
+ result["metadata"] = self.metadata
+
+ return result
+
+
+# Utility functions for converting from existing dictionary patterns
+def create_execution_context_from_dict(
+ context_dict: dict[str, Any],
+) -> WorkflowExecutionContext:
+ """Convert dictionary-based context to strongly-typed dataclass.
+
+ Provides migration path from existing dictionary-based patterns
+ to type-safe dataclass approach.
+
+ Args:
+ context_dict: Dictionary containing execution context data
+
+ Returns:
+ WorkflowExecutionContext dataclass instance
+
+ Raises:
+ ValueError: If required fields are missing from dictionary
+ """
+ required_fields = [
+ "files",
+ "workflow_id",
+ "execution_id",
+ "api_client",
+ "workflow_type",
+ "is_api_workflow",
+ ]
+ missing_fields = [field for field in required_fields if field not in context_dict]
+
+ if missing_fields:
+ raise ValueError(f"Missing required context fields: {missing_fields}")
+
+ return WorkflowExecutionContext(
+ files=context_dict["files"],
+ workflow_id=context_dict["workflow_id"],
+ execution_id=context_dict["execution_id"],
+ api_client=context_dict["api_client"],
+ workflow_type=context_dict["workflow_type"],
+ is_api_workflow=context_dict["is_api_workflow"],
+ organization_id=context_dict.get("organization_id"),
+ pipeline_id=context_dict.get("pipeline_id"),
+ use_file_history=context_dict.get("use_file_history", False),
+ scheduled=context_dict.get("scheduled", False),
+ )
+
+
+def create_callback_context_from_kwargs(
+ kwargs: dict[str, Any],
+) -> CallbackExecutionContext:
+ """Convert kwargs dictionary to strongly-typed callback context.
+
+ Args:
+ kwargs: Keyword arguments from callback task
+
+ Returns:
+ CallbackExecutionContext dataclass instance
+ """
+ return CallbackExecutionContext(
+ execution_id=kwargs["execution_id"],
+ organization_id=kwargs["organization_id"],
+ workflow_id=kwargs["workflow_id"],
+ results=kwargs.get("results", []),
+ pipeline_id=kwargs.get("pipeline_id"),
+ callback_type=kwargs.get("callback_type", "batch_callback"),
+ )
+
+
+@dataclass
+class WorkerOrganizationContext:
+ """Worker-specific organization context with API client integration.
+
+ Extends the basic organization context from core with worker-specific
+ functionality including API client integration.
+ Note: For basic organization context, use unstract.core.data_models.OrganizationContext
+ """
+
+ organization_id: str
+ api_client: "InternalAPIClient"
+ organization_data: dict[str, Any] | None = None
+ cached_at: str | None = None
+
+ def __post_init__(self):
+ """Validate organization context after initialization."""
+ if not self.organization_id:
+ raise ValueError("organization_id is required for organization context")
+
+ if not self.api_client:
+ raise ValueError("api_client is required for organization context")
+
+ @property
+ def is_cached(self) -> bool:
+ """Check if organization data is cached."""
+ return bool(self.organization_data and self.cached_at)
+
+ def get_organization_setting(self, setting_key: str, default: Any = None) -> Any:
+ """Get organization-specific setting value."""
+ if not self.organization_data:
+ return default
+
+ return self.organization_data.get("settings", {}).get(setting_key, default)
+
+
+@dataclass
+class WorkflowContextData:
+ """Strongly-typed workflow context data.
+
+ Replaces dictionary-based workflow context with type-safe structure
+ containing all workflow execution metadata.
+ """
+
+ workflow_id: str
+ workflow_name: str
+ workflow_type: str
+ execution_id: str
+ organization_context: WorkerOrganizationContext
+ files: dict[str, Any]
+ settings: dict[str, Any] | None = None
+ metadata: dict[str, Any] | None = None
+ is_scheduled: bool = False
+ pre_created_file_executions: dict[str, PreCreatedFileData] = field(
+ default_factory=dict
+ )
+
+ def __post_init__(self):
+ """Validate workflow context after initialization."""
+ if not self.workflow_id:
+ raise ValueError("workflow_id is required for workflow context")
+
+ if not self.execution_id:
+ raise ValueError("execution_id is required for workflow context")
+
+ if not self.workflow_name:
+ raise ValueError("workflow_name is required for workflow context")
+
+ if not self.workflow_type:
+ raise ValueError("workflow_type is required for workflow context")
+
+ # Normalize workflow_type
+ self.workflow_type = self.workflow_type.upper()
+
+ # Validate workflow_type
+ valid_types = {pt.value for pt in PipelineType}
+ if self.workflow_type not in valid_types:
+ raise ValueError(
+ f"Invalid workflow_type '{self.workflow_type}'. "
+ f"Must be one of: {valid_types}"
+ )
+
+ @property
+ def file_count(self) -> int:
+ """Get the number of files in this workflow context."""
+ return len(self.files) if self.files else 0
+
+ @property
+ def pipeline_type_enum(self) -> PipelineType:
+ """Get the workflow type as a PipelineType enum."""
+ return PipelineType(self.workflow_type)
+
+ @property
+ def is_api_workflow(self) -> bool:
+ """Check if this is an API workflow."""
+ return self.pipeline_type_enum == PipelineType.API
+
+ def get_setting(self, setting_key: str, default: Any = None) -> Any:
+ """Get workflow-specific setting value."""
+ if not self.settings:
+ return default
+
+ return self.settings.get(setting_key, default)
+
+ def get_metadata(self, metadata_key: str, default: Any = None) -> Any:
+ """Get workflow metadata value."""
+ if not self.metadata:
+ return default
+
+ return self.metadata.get(metadata_key, default)
+
+
+@dataclass
+class ExecutionStatusUpdate:
+ """Strongly-typed execution status update.
+
+ Provides type-safe structure for workflow execution status updates
+ with validation and consistency checks.
+ """
+
+ execution_id: str
+ status: str
+ organization_id: str | None = None
+ workflow_id: str | None = None
+ error_message: str | None = None
+ metadata: dict[str, Any] | None = None
+ timestamp: str | None = None
+
+ def __post_init__(self):
+ """Validate status update after initialization."""
+ if not self.execution_id:
+ raise ValueError("execution_id is required for status update")
+
+ if not self.status:
+ raise ValueError("status is required for status update")
+
+ # Normalize status to uppercase for consistency
+ self.status = self.status.upper()
+
+ # Validate status against known execution statuses
+ valid_statuses = {status.value for status in ExecutionStatus}
+ if self.status not in valid_statuses:
+ raise ValueError(
+ f"Invalid status '{self.status}'. Must be one of: {valid_statuses}"
+ )
+
+ @property
+ def status_enum(self) -> ExecutionStatus:
+ """Get the status as an ExecutionStatus enum."""
+ return ExecutionStatus(self.status)
+
+ @property
+ def is_completed(self) -> bool:
+ """Check if the execution has completed (successfully or with error)."""
+ return ExecutionStatus.is_completed(self.status)
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if the execution completed successfully."""
+ return self.status_enum == ExecutionStatus.COMPLETED
+
+ @property
+ def is_failed(self) -> bool:
+ """Check if the execution failed."""
+ return self.status_enum == ExecutionStatus.ERROR
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert status update to dictionary for API calls."""
+ result = {"execution_id": self.execution_id, "status": self.status}
+
+ if self.organization_id:
+ result["organization_id"] = self.organization_id
+
+ if self.workflow_id:
+ result["workflow_id"] = self.workflow_id
+
+ if self.error_message:
+ result["error_message"] = self.error_message
+
+ if self.metadata:
+ result["metadata"] = self.metadata
+
+ if self.timestamp:
+ result["timestamp"] = self.timestamp
+
+ return result
+
+
+@dataclass
+class WorkflowConfig:
+ """Type-safe workflow configuration dataclass."""
+
+ workflow_id: str
+ workflow_name: str
+ workflow_type: str = "ETL"
+ tools: list[dict[str, Any]] = field(default_factory=list)
+ settings: dict[str, Any] = field(default_factory=dict)
+ metadata: dict[str, Any] = field(default_factory=dict)
+ version: str = "1.0.0"
+
+ def __post_init__(self):
+ """Validate workflow configuration after initialization."""
+ if not self.workflow_id:
+ raise ValueError("workflow_id is required")
+ if not self.workflow_name:
+ raise ValueError("workflow_name is required")
+ if not isinstance(self.tools, list):
+ raise ValueError("tools must be a list")
+ if not isinstance(self.settings, dict):
+ raise ValueError("settings must be a dictionary")
+ if not isinstance(self.metadata, dict):
+ raise ValueError("metadata must be a dictionary")
+
+ def get_tools_config(self) -> list[dict[str, Any]]:
+ """Get tools configuration as list of dictionaries."""
+ return self.tools
+
+ def add_tool(self, tool_config: dict[str, Any]) -> None:
+ """Add a tool configuration to the workflow."""
+ if not isinstance(tool_config, dict):
+ raise ValueError("tool_config must be a dictionary")
+ if "tool_id" not in tool_config:
+ raise ValueError("tool_config must contain tool_id")
+ self.tools.append(tool_config)
+
+ def get_tool_by_id(self, tool_id: str) -> dict[str, Any] | None:
+ """Get a tool configuration by ID."""
+ for tool in self.tools:
+ if tool.get("tool_id") == tool_id:
+ return tool
+ return None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert workflow config to dictionary for backward compatibility."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowConfig":
+ """Create WorkflowConfig from dictionary data."""
+ return cls(
+ workflow_id=data["workflow_id"],
+ workflow_name=data["workflow_name"],
+ workflow_type=data.get("workflow_type", "ETL"),
+ tools=data.get("tools", []),
+ settings=data.get("settings", {}),
+ metadata=data.get("metadata", {}),
+ version=data.get("version", "1.0.0"),
+ )
+
+
+# Additional utility functions for context conversion
+def create_organization_context(
+ organization_id: str,
+ api_client: "InternalAPIClient",
+ organization_data: dict[str, Any] | None = None,
+) -> WorkerOrganizationContext:
+ """Create organization context from basic parameters."""
+ return WorkerOrganizationContext(
+ organization_id=organization_id,
+ api_client=api_client,
+ organization_data=organization_data,
+ )
+
+
+@dataclass
+class WorkflowEndpointContext:
+ """Strongly-typed context for workflow endpoint configuration.
+
+ Provides type-safe structure for workflow source and destination
+ endpoint configurations with validation and utility methods.
+ """
+
+ source_endpoint: dict[str, Any] | None = None
+ destination_endpoint: dict[str, Any] | None = None
+ endpoints: list[dict[str, Any]] = field(default_factory=list)
+ has_api_endpoints: bool = False
+
+ def __post_init__(self):
+ """Validate endpoint context after initialization."""
+ # Automatically detect API endpoints if not explicitly set
+ if not self.has_api_endpoints and self.endpoints:
+ self.has_api_endpoints = any(
+ endpoint.get("connection_type") == "API" for endpoint in self.endpoints
+ )
+
+ @property
+ def has_source_endpoint(self) -> bool:
+ """Check if workflow has a source endpoint."""
+ return bool(self.source_endpoint)
+
+ @property
+ def has_destination_endpoint(self) -> bool:
+ """Check if workflow has a destination endpoint."""
+ return bool(self.destination_endpoint)
+
+ @property
+ def source_connection_type(self) -> str | None:
+ """Get source connection type."""
+ if self.source_endpoint:
+ return self.source_endpoint.get("connection_type")
+ return None
+
+ @property
+ def destination_connection_type(self) -> str | None:
+ """Get destination connection type."""
+ if self.destination_endpoint:
+ return self.destination_endpoint.get("connection_type")
+ return None
+
+ @property
+ def is_api_workflow(self) -> bool:
+ """Check if this is an API workflow."""
+ return (
+ self.has_api_endpoints
+ or self.source_connection_type == "API"
+ or self.destination_connection_type == "API"
+ )
+
+ @property
+ def is_filesystem_workflow(self) -> bool:
+ """Check if this is a filesystem-based workflow."""
+ return (
+ self.source_connection_type == "FILESYSTEM"
+ or self.destination_connection_type == "FILESYSTEM"
+ )
+
+ def get_endpoint_by_type(self, endpoint_type: str) -> dict[str, Any] | None:
+ """Get endpoint by type (SOURCE or DESTINATION)."""
+ for endpoint in self.endpoints:
+ if endpoint.get("endpoint_type") == endpoint_type:
+ return endpoint
+ return None
+
+
+@dataclass
+class WorkflowCompilationContext:
+ """Strongly-typed context for workflow compilation results.
+
+ Contains compilation status, tools configuration, and any compilation
+ errors or warnings generated during workflow preparation.
+ """
+
+ workflow_id: str
+ compilation_successful: bool
+ tools_config: dict[str, Any] | None = None
+ compilation_errors: list[str] = field(default_factory=list)
+ compilation_warnings: list[str] = field(default_factory=list)
+ compiled_at: str | None = None
+ compilation_time: float | None = None
+
+ def __post_init__(self):
+ """Validate compilation context after initialization."""
+ if not self.workflow_id:
+ raise ValueError("workflow_id is required for compilation context")
+
+ @property
+ def has_errors(self) -> bool:
+ """Check if compilation has errors."""
+ return bool(self.compilation_errors)
+
+ @property
+ def has_warnings(self) -> bool:
+ """Check if compilation has warnings."""
+ return bool(self.compilation_warnings)
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if compilation was successful."""
+ return self.compilation_successful and not self.has_errors
+
+ def add_error(self, error_message: str) -> None:
+ """Add a compilation error."""
+ self.compilation_errors.append(error_message)
+ self.compilation_successful = False
+
+ def add_warning(self, warning_message: str) -> None:
+ """Add a compilation warning."""
+ self.compilation_warnings.append(warning_message)
+
+ def get_error_summary(self) -> str:
+ """Get a summary of all compilation errors."""
+ if not self.compilation_errors:
+ return "No compilation errors"
+ return "; ".join(self.compilation_errors)
+
+
+@dataclass
+class WorkflowSourceContext:
+ """Strongly-typed context for workflow source configuration.
+
+ Manages source file access, connection details, and file listing
+ operations for workflow execution.
+ """
+
+ connection_type: str
+ endpoint_config: dict[str, Any]
+ use_file_history: bool = True
+ total_files: int = 0
+ source_files: list[dict[str, Any]] = field(default_factory=list)
+ file_listing_errors: list[str] = field(default_factory=list)
+
+ def __post_init__(self):
+ """Validate source context after initialization."""
+ if not self.connection_type:
+ raise ValueError("connection_type is required for source context")
+
+ if not isinstance(self.endpoint_config, dict):
+ raise ValueError("endpoint_config must be a dictionary")
+
+ @property
+ def has_files(self) -> bool:
+ """Check if source has files available."""
+ return self.total_files > 0
+
+ @property
+ def is_api_source(self) -> bool:
+ """Check if this is an API source."""
+ return self.connection_type == "API"
+
+ @property
+ def is_filesystem_source(self) -> bool:
+ """Check if this is a filesystem source."""
+ return self.connection_type == "FILESYSTEM"
+
+ @property
+ def has_listing_errors(self) -> bool:
+ """Check if file listing had errors."""
+ return bool(self.file_listing_errors)
+
+ def add_listing_error(self, error_message: str) -> None:
+ """Add a file listing error."""
+ self.file_listing_errors.append(error_message)
+
+ def update_file_count(self, count: int) -> None:
+ """Update the total file count."""
+ self.total_files = count
+
+
+@dataclass
+class WorkflowDestinationContext:
+ """Strongly-typed context for workflow destination configuration.
+
+ Manages destination output configuration, connection details, and
+ result delivery settings for workflow execution.
+ """
+
+ connection_type: str
+ endpoint_config: dict[str, Any]
+ output_format: str = "JSON"
+ delivery_method: str = "PUSH"
+ destination_errors: list[str] = field(default_factory=list)
+
+ def __post_init__(self):
+ """Validate destination context after initialization."""
+ if not self.connection_type:
+ raise ValueError("connection_type is required for destination context")
+
+ if not isinstance(self.endpoint_config, dict):
+ raise ValueError("endpoint_config must be a dictionary")
+
+ @property
+ def is_api_destination(self) -> bool:
+ """Check if this is an API destination."""
+ return self.connection_type == "API"
+
+ @property
+ def is_filesystem_destination(self) -> bool:
+ """Check if this is a filesystem destination."""
+ return self.connection_type == "FILESYSTEM"
+
+ @property
+ def is_manual_review_destination(self) -> bool:
+ """Check if this is a manual review destination."""
+ return self.connection_type == "MANUALREVIEW"
+
+ @property
+ def has_errors(self) -> bool:
+ """Check if destination has errors."""
+ return bool(self.destination_errors)
+
+ def add_error(self, error_message: str) -> None:
+ """Add a destination error."""
+ self.destination_errors.append(error_message)
+
+
+@dataclass
+class EnhancedWorkflowContext:
+ """Enhanced workflow context that combines all workflow-related contexts.
+
+ This provides a comprehensive, strongly-typed workflow context that includes
+ execution, endpoints, compilation, source, and destination information.
+ """
+
+ # Core execution context
+ execution_context: WorkflowContextData
+
+ # Endpoint configuration context
+ endpoint_context: WorkflowEndpointContext | None = None
+
+ # Compilation context
+ compilation_context: WorkflowCompilationContext | None = None
+
+ # Source context
+ source_context: WorkflowSourceContext | None = None
+
+ # Destination context
+ destination_context: WorkflowDestinationContext | None = None
+
+ # Additional metadata
+ created_at: str | None = None
+ updated_at: str | None = None
+
+ def __post_init__(self):
+ """Validate enhanced workflow context."""
+ if not self.execution_context:
+ raise ValueError(
+ "execution_context is required for enhanced workflow context"
+ )
+
+ @property
+ def workflow_id(self) -> str:
+ """Get workflow ID from execution context."""
+ return self.execution_context.workflow_id
+
+ @property
+ def execution_id(self) -> str:
+ """Get execution ID from execution context."""
+ return self.execution_context.execution_id
+
+ @property
+ def organization_id(self) -> str:
+ """Get organization ID from execution context."""
+ return self.execution_context.organization_context.organization_id
+
+ @property
+ def is_api_workflow(self) -> bool:
+ """Check if this is an API workflow based on all available context."""
+ # Check execution context first
+ if self.execution_context.is_api_workflow:
+ return True
+
+ # Check endpoint context
+ if self.endpoint_context and self.endpoint_context.is_api_workflow:
+ return True
+
+ return False
+
+ @property
+ def is_compilation_successful(self) -> bool:
+ """Check if workflow compilation was successful."""
+ if not self.compilation_context:
+ return True # Assume success if no compilation context
+ return self.compilation_context.is_successful
+
+ @property
+ def has_source_files(self) -> bool:
+ """Check if workflow has source files available."""
+ if not self.source_context:
+ return False
+ return self.source_context.has_files
+
+ @property
+ def total_files(self) -> int:
+ """Get total number of files in the workflow."""
+ if self.source_context:
+ return self.source_context.total_files
+ return self.execution_context.file_count
+
+ def validate_for_execution(self) -> list[str]:
+ """Validate the complete workflow context for execution readiness.
+
+ Returns:
+ List of validation errors (empty if valid)
+ """
+ errors = []
+
+ # Check compilation
+ if self.compilation_context and not self.compilation_context.is_successful:
+ errors.extend(self.compilation_context.compilation_errors)
+
+ # Check source context
+ if self.source_context and self.source_context.has_listing_errors:
+ errors.extend(self.source_context.file_listing_errors)
+
+ # Check destination context
+ if self.destination_context and self.destination_context.has_errors:
+ errors.extend(self.destination_context.destination_errors)
+
+ # Check if API workflow has required pipeline_id
+ if self.is_api_workflow:
+ try:
+ self.execution_context.validate_for_api_workflow()
+ except ValueError as e:
+ errors.append(str(e))
+
+ return errors
+
+
+def create_workflow_context_from_dict(
+ context_dict: dict[str, Any],
+) -> WorkflowContextData:
+ """Convert dictionary-based workflow context to strongly-typed dataclass.
+
+ Args:
+ context_dict: Dictionary containing workflow context data
+
+ Returns:
+ WorkflowContextData dataclass instance
+ """
+ required_fields = [
+ "workflow_id",
+ "workflow_name",
+ "workflow_type",
+ "execution_id",
+ "files",
+ ]
+ missing_fields = [field for field in required_fields if field not in context_dict]
+
+ if missing_fields:
+ raise ValueError(f"Missing required workflow context fields: {missing_fields}")
+
+ # Create organization context if not provided
+ org_context = context_dict.get("organization_context")
+ if not org_context:
+ org_id = context_dict.get("organization_id")
+ api_client = context_dict.get("api_client")
+ if org_id and api_client:
+ org_context = create_organization_context(org_id, api_client)
+ else:
+ raise ValueError(
+ "Either organization_context or both organization_id and api_client are required"
+ )
+
+ return WorkflowContextData(
+ workflow_id=context_dict["workflow_id"],
+ workflow_name=context_dict["workflow_name"],
+ workflow_type=context_dict["workflow_type"],
+ execution_id=context_dict["execution_id"],
+ organization_context=org_context,
+ files=context_dict["files"],
+ settings=context_dict.get("settings"),
+ metadata=context_dict.get("metadata"),
+ is_scheduled=context_dict.get("scheduled", False),
+ )
diff --git a/workers/shared/models/file_processing.py b/workers/shared/models/file_processing.py
new file mode 100644
index 000000000..af4062417
--- /dev/null
+++ b/workers/shared/models/file_processing.py
@@ -0,0 +1,66 @@
+"""File processing context and state models.
+
+This module contains data structures related to file processing
+that are shared across worker modules.
+"""
+
+import time
+from typing import Any
+
+# Note: We're not importing these here to avoid potential circular dependencies
+# They will be injected via constructor parameters
+# from unstract.api.internal_client import InternalAPIClient
+# from unstract.infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+from shared.infrastructure.logging import WorkerLogger
+
+from unstract.core.data_models import FileHashData, WorkerFileData
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class FileProcessingContext:
+ """Container for file processing context and state."""
+
+ def __init__(
+ self,
+ file_data: WorkerFileData,
+ file_hash: FileHashData,
+ api_client: Any, # Type as Any to avoid import dependency
+ workflow_execution: dict[str, Any],
+ workflow_file_execution_id: str = None,
+ workflow_file_execution_object: Any = None,
+ workflow_logger: Any = None, # Type as Any to avoid import dependency
+ current_file_idx: int = 1,
+ total_files: int = 1,
+ ):
+ self.file_data = file_data
+ self.file_hash = file_hash
+ self.api_client = api_client
+ self.workflow_execution = workflow_execution
+ self.workflow_file_execution_id = workflow_file_execution_id
+ self.workflow_file_execution_object = workflow_file_execution_object
+ self.workflow_logger = workflow_logger
+ self.current_file_idx = current_file_idx
+ self.total_files = total_files
+
+ # Extract common identifiers
+ self.execution_id = file_data.execution_id
+ self.workflow_id = file_data.workflow_id
+ self.organization_id = file_data.organization_id
+ self.use_file_history = getattr(file_data, "use_file_history", True)
+
+ self.file_name = file_hash.file_name or "unknown"
+ self.file_start_time = time.time()
+
+ logger.info(
+ f"[Execution {self.execution_id}] Processing file: '{self.file_name}'"
+ )
+
+ @property
+ def is_api_workflow(self) -> bool:
+ """Check if this is an API workflow based on file path."""
+ return self.file_hash.file_path and "/api/" in self.file_hash.file_path
+
+ def get_processing_duration(self) -> float:
+ """Get the processing duration in seconds."""
+ return time.time() - self.file_start_time
diff --git a/workers/shared/models/notification_models.py b/workers/shared/models/notification_models.py
new file mode 100644
index 000000000..f161e618b
--- /dev/null
+++ b/workers/shared/models/notification_models.py
@@ -0,0 +1,577 @@
+"""Notification Data Models
+
+This module provides strongly-typed dataclasses for notification operations,
+replacing fragile dictionary-based notification handling with type-safe structures.
+"""
+
+# Import shared domain models from core
+import os
+import sys
+from dataclasses import dataclass, field
+from datetime import datetime
+from typing import Any
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+
+
+@dataclass
+class NotificationRequest:
+ """Strongly-typed notification request."""
+
+ notification_type: str
+ destination: str
+ payload: dict[str, Any]
+ priority: bool = False
+ timeout: int = 30
+ max_retries: int = 3
+ retry_delay: float = 1.0
+ headers: dict[str, str] | None = None
+ metadata: dict[str, Any] | None = None
+ organization_id: str | None = None
+ workflow_id: str | None = None
+ execution_id: str | None = None
+
+ def __post_init__(self):
+ """Validate notification request after initialization."""
+ if not self.notification_type:
+ raise ValueError("notification_type is required for notification request")
+
+ if not self.destination:
+ raise ValueError("destination is required for notification request")
+
+ if not isinstance(self.payload, dict):
+ raise ValueError("payload must be a dictionary")
+
+ if self.timeout <= 0:
+ raise ValueError("timeout must be positive")
+
+ if self.max_retries < 0:
+ raise ValueError("max_retries cannot be negative")
+
+ @property
+ def is_high_priority(self) -> bool:
+ """Check if this is a high priority notification."""
+ return self.priority
+
+ @property
+ def is_webhook(self) -> bool:
+ """Check if this is a webhook notification."""
+ return self.notification_type.upper() == "WEBHOOK"
+
+ @property
+ def is_email(self) -> bool:
+ """Check if this is an email notification."""
+ return self.notification_type.upper() == "EMAIL"
+
+ @property
+ def is_sms(self) -> bool:
+ """Check if this is an SMS notification."""
+ return self.notification_type.upper() == "SMS"
+
+ @property
+ def payload_size(self) -> int:
+ """Get the size of the payload in bytes."""
+ import json
+
+ return len(json.dumps(self.payload, default=str).encode("utf-8"))
+
+ def get_header(self, header_name: str, default: str = "") -> str:
+ """Get a header value."""
+ if not self.headers:
+ return default
+ return self.headers.get(header_name, default)
+
+ def set_header(self, header_name: str, header_value: str) -> None:
+ """Set a header value."""
+ if not self.headers:
+ self.headers = {}
+ self.headers[header_name] = header_value
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert notification request to dictionary."""
+ result = {
+ "notification_type": self.notification_type,
+ "destination": self.destination,
+ "payload": self.payload,
+ "priority": self.priority,
+ "timeout": self.timeout,
+ "max_retries": self.max_retries,
+ "retry_delay": self.retry_delay,
+ }
+
+ if self.headers:
+ result["headers"] = self.headers
+
+ if self.metadata:
+ result["metadata"] = self.metadata
+
+ if self.organization_id:
+ result["organization_id"] = self.organization_id
+
+ if self.workflow_id:
+ result["workflow_id"] = self.workflow_id
+
+ if self.execution_id:
+ result["execution_id"] = self.execution_id
+
+ return result
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "NotificationRequest":
+ """Create NotificationRequest from dictionary data."""
+ return cls(
+ notification_type=data["notification_type"],
+ destination=data["destination"],
+ payload=data["payload"],
+ priority=data.get("priority", False),
+ timeout=data.get("timeout", 30),
+ max_retries=data.get("max_retries", 3),
+ retry_delay=data.get("retry_delay", 1.0),
+ headers=data.get("headers"),
+ metadata=data.get("metadata"),
+ organization_id=data.get("organization_id"),
+ workflow_id=data.get("workflow_id"),
+ execution_id=data.get("execution_id"),
+ )
+
+
+@dataclass
+class NotificationResult:
+ """Strongly-typed result from notification delivery."""
+
+ notification_id: str
+ notification_type: str
+ destination: str
+ status: str
+ success: bool
+ delivery_time: float = 0.0
+ attempts: int = 1
+ response_code: int | None = None
+ response_body: str | None = None
+ error_message: str | None = None
+ metadata: dict[str, Any] | None = None
+ delivered_at: datetime | None = None
+
+ def __post_init__(self):
+ """Validate notification result after initialization."""
+ if not self.notification_id:
+ raise ValueError("notification_id is required for notification result")
+
+ if not self.notification_type:
+ raise ValueError("notification_type is required for notification result")
+
+ if not self.destination:
+ raise ValueError("destination is required for notification result")
+
+ if not self.status:
+ raise ValueError("status is required for notification result")
+
+ # Set delivered_at if not provided and successful
+ if self.delivered_at is None and self.success:
+ self.delivered_at = datetime.now()
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if notification delivery was successful."""
+ return self.success and self.status.upper() in [
+ "SUCCESS",
+ "DELIVERED",
+ "COMPLETED",
+ ]
+
+ @property
+ def is_failed(self) -> bool:
+ """Check if notification delivery failed."""
+ return not self.success or self.status.upper() in ["FAILED", "ERROR"]
+
+ @property
+ def is_pending(self) -> bool:
+ """Check if notification is still pending."""
+ return self.status.upper() in ["PENDING", "QUEUED", "PROCESSING"]
+
+ @property
+ def has_error(self) -> bool:
+ """Check if notification has an error message."""
+ return bool(self.error_message)
+
+ @property
+ def response_ok(self) -> bool:
+ """Check if HTTP response was successful (2xx)."""
+ if self.response_code is None:
+ return False
+ return 200 <= self.response_code < 300
+
+ @property
+ def delivery_time_ms(self) -> float:
+ """Get delivery time in milliseconds."""
+ return self.delivery_time * 1000
+
+ def get_metadata_field(self, field_name: str, default: Any = None) -> Any:
+ """Get a field from the metadata."""
+ if not self.metadata:
+ return default
+ return self.metadata.get(field_name, default)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert notification result to dictionary."""
+ result = {
+ "notification_id": self.notification_id,
+ "notification_type": self.notification_type,
+ "destination": self.destination,
+ "status": self.status,
+ "success": self.success,
+ "delivery_time": self.delivery_time,
+ "attempts": self.attempts,
+ }
+
+ if self.response_code is not None:
+ result["response_code"] = self.response_code
+
+ if self.response_body:
+ result["response_body"] = self.response_body
+
+ if self.error_message:
+ result["error_message"] = self.error_message
+
+ if self.metadata:
+ result["metadata"] = self.metadata
+
+ if self.delivered_at:
+ result["delivered_at"] = self.delivered_at.isoformat()
+
+ return result
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "NotificationResult":
+ """Create NotificationResult from dictionary data."""
+ delivered_at = None
+ if "delivered_at" in data and data["delivered_at"]:
+ if isinstance(data["delivered_at"], str):
+ delivered_at = datetime.fromisoformat(
+ data["delivered_at"].replace("Z", "+00:00")
+ )
+ elif isinstance(data["delivered_at"], datetime):
+ delivered_at = data["delivered_at"]
+
+ return cls(
+ notification_id=data["notification_id"],
+ notification_type=data["notification_type"],
+ destination=data["destination"],
+ status=data["status"],
+ success=data["success"],
+ delivery_time=data.get("delivery_time", 0.0),
+ attempts=data.get("attempts", 1),
+ response_code=data.get("response_code"),
+ response_body=data.get("response_body"),
+ error_message=data.get("error_message"),
+ metadata=data.get("metadata"),
+ delivered_at=delivered_at,
+ )
+
+
+@dataclass
+class WebhookNotificationRequest(NotificationRequest):
+ """Specialized notification request for webhooks."""
+
+ url: str = ""
+ method: str = "POST"
+
+ def __post_init__(self):
+ """Validate webhook notification request."""
+ # Set destination to URL for webhook requests
+ if not self.destination and self.url:
+ self.destination = self.url
+ elif not self.url and self.destination:
+ self.url = self.destination
+
+ super().__post_init__()
+
+ if not self.url:
+ raise ValueError("url is required for webhook notification")
+
+ if self.method.upper() not in ["GET", "POST", "PUT", "PATCH", "DELETE"]:
+ raise ValueError(f"Invalid HTTP method: {self.method}")
+
+ @property
+ def is_post_request(self) -> bool:
+ """Check if this is a POST request."""
+ return self.method.upper() == "POST"
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert webhook request to dictionary."""
+ result = super().to_dict()
+ result.update(
+ {
+ "url": self.url,
+ "method": self.method,
+ }
+ )
+ return result
+
+
+@dataclass
+class NotificationBatch:
+ """Strongly-typed batch of notifications."""
+
+ batch_id: str
+ notifications: list[NotificationRequest] = field(default_factory=list)
+ priority: bool = False
+ created_at: datetime | None = None
+ processed_at: datetime | None = None
+ total_notifications: int = 0
+ successful_notifications: int = 0
+ failed_notifications: int = 0
+ pending_notifications: int = 0
+ batch_status: str = "PENDING"
+ results: list[NotificationResult] = field(default_factory=list)
+
+ def __post_init__(self):
+ """Validate notification batch after initialization."""
+ if not self.batch_id:
+ raise ValueError("batch_id is required for notification batch")
+
+ # Set created_at if not provided
+ if self.created_at is None:
+ self.created_at = datetime.now()
+
+ # Auto-calculate total if not provided
+ if self.total_notifications == 0:
+ self.total_notifications = len(self.notifications)
+
+ @property
+ def completion_percentage(self) -> float:
+ """Get completion percentage of the batch."""
+ if self.total_notifications == 0:
+ return 100.0
+ processed = self.successful_notifications + self.failed_notifications
+ return (processed / self.total_notifications) * 100.0
+
+ @property
+ def success_rate(self) -> float:
+ """Get success rate of processed notifications."""
+ processed = self.successful_notifications + self.failed_notifications
+ if processed == 0:
+ return 0.0
+ return (self.successful_notifications / processed) * 100.0
+
+ @property
+ def is_completed(self) -> bool:
+ """Check if batch processing is completed."""
+ return self.batch_status.upper() == "COMPLETED"
+
+ @property
+ def is_failed(self) -> bool:
+ """Check if batch processing failed."""
+ return self.batch_status.upper() == "FAILED"
+
+ @property
+ def has_errors(self) -> bool:
+ """Check if batch has any failed notifications."""
+ return self.failed_notifications > 0
+
+ def add_notification(self, notification: NotificationRequest) -> None:
+ """Add a notification to the batch."""
+ self.notifications.append(notification)
+ self.total_notifications = len(self.notifications)
+
+ def add_result(self, result: NotificationResult) -> None:
+ """Add a notification result to the batch."""
+ self.results.append(result)
+
+ # Update counts
+ if result.is_successful:
+ self.successful_notifications += 1
+ elif result.is_failed:
+ self.failed_notifications += 1
+ else:
+ self.pending_notifications += 1
+
+ def get_successful_results(self) -> list[NotificationResult]:
+ """Get only the successful notification results."""
+ return [r for r in self.results if r.is_successful]
+
+ def get_failed_results(self) -> list[NotificationResult]:
+ """Get only the failed notification results."""
+ return [r for r in self.results if r.is_failed]
+
+ def get_error_messages(self) -> list[str]:
+ """Get all error messages from failed results."""
+ return [r.error_message for r in self.results if r.error_message]
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert notification batch to dictionary."""
+ result = {
+ "batch_id": self.batch_id,
+ "total_notifications": self.total_notifications,
+ "successful_notifications": self.successful_notifications,
+ "failed_notifications": self.failed_notifications,
+ "pending_notifications": self.pending_notifications,
+ "batch_status": self.batch_status,
+ "priority": self.priority,
+ "completion_percentage": self.completion_percentage,
+ "success_rate": self.success_rate,
+ }
+
+ if self.notifications:
+ result["notifications"] = [n.to_dict() for n in self.notifications]
+
+ if self.results:
+ result["results"] = [r.to_dict() for r in self.results]
+
+ if self.created_at:
+ result["created_at"] = self.created_at.isoformat()
+
+ if self.processed_at:
+ result["processed_at"] = self.processed_at.isoformat()
+
+ return result
+
+
+@dataclass
+class NotificationTemplate:
+ """Strongly-typed notification template."""
+
+ template_id: str
+ template_name: str
+ notification_type: str
+ template_content: str
+ variables: list[str] = field(default_factory=list)
+ default_headers: dict[str, str] | None = None
+ default_timeout: int = 30
+ default_retries: int = 3
+ is_active: bool = True
+ created_at: datetime | None = None
+
+ def __post_init__(self):
+ """Validate notification template after initialization."""
+ if not self.template_id:
+ raise ValueError("template_id is required for notification template")
+
+ if not self.template_name:
+ raise ValueError("template_name is required for notification template")
+
+ if not self.notification_type:
+ raise ValueError("notification_type is required for notification template")
+
+ if not self.template_content:
+ raise ValueError("template_content is required for notification template")
+
+ # Set created_at if not provided
+ if self.created_at is None:
+ self.created_at = datetime.now()
+
+ @property
+ def has_variables(self) -> bool:
+ """Check if template has variables."""
+ return bool(self.variables)
+
+ @property
+ def variable_count(self) -> int:
+ """Get the number of variables in the template."""
+ return len(self.variables)
+
+ def render(self, variables: dict[str, Any]) -> str:
+ """Render the template with provided variables."""
+ content = self.template_content
+
+ for var_name in self.variables:
+ if var_name in variables:
+ placeholder = f"{{{var_name}}}"
+ content = content.replace(placeholder, str(variables[var_name]))
+
+ return content
+
+ def create_notification_request(
+ self, destination: str, variables: dict[str, Any] | None = None, **kwargs
+ ) -> NotificationRequest:
+ """Create a notification request from this template."""
+ # Render template content
+ rendered_content = self.render(variables or {})
+
+ # Create base payload
+ payload = {"content": rendered_content}
+ if "payload" in kwargs:
+ payload.update(kwargs.pop("payload"))
+
+ return NotificationRequest(
+ notification_type=self.notification_type,
+ destination=destination,
+ payload=payload,
+ timeout=kwargs.get("timeout", self.default_timeout),
+ max_retries=kwargs.get("max_retries", self.default_retries),
+ headers=kwargs.get("headers", self.default_headers),
+ **kwargs,
+ )
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert notification template to dictionary."""
+ result = {
+ "template_id": self.template_id,
+ "template_name": self.template_name,
+ "notification_type": self.notification_type,
+ "template_content": self.template_content,
+ "variables": self.variables,
+ "default_timeout": self.default_timeout,
+ "default_retries": self.default_retries,
+ "is_active": self.is_active,
+ }
+
+ if self.default_headers:
+ result["default_headers"] = self.default_headers
+
+ if self.created_at:
+ result["created_at"] = self.created_at.isoformat()
+
+ return result
+
+
+# Utility functions for notification operations
+def create_webhook_notification(
+ url: str, payload: dict[str, Any], method: str = "POST", **kwargs
+) -> WebhookNotificationRequest:
+ """Create a webhook notification request."""
+ return WebhookNotificationRequest(
+ notification_type="WEBHOOK",
+ url=url,
+ method=method,
+ destination=url,
+ payload=payload,
+ **kwargs,
+ )
+
+
+def create_notification_batch(
+ notifications: list[NotificationRequest],
+ batch_id: str | None = None,
+ priority: bool = False,
+) -> NotificationBatch:
+ """Create a notification batch from a list of notifications."""
+ import uuid
+
+ if batch_id is None:
+ batch_id = str(uuid.uuid4())
+
+ return NotificationBatch(
+ batch_id=batch_id,
+ notifications=notifications,
+ priority=priority,
+ )
+
+
+def aggregate_notification_results(results: list[dict[str, Any]]) -> dict[str, Any]:
+ """Aggregate multiple notification results into summary statistics."""
+ total = len(results)
+ successful = len([r for r in results if r.get("success", False)])
+ failed = total - successful
+
+ total_time = sum(r.get("delivery_time", 0.0) for r in results)
+ avg_time = total_time / total if total > 0 else 0.0
+
+ return {
+ "total_notifications": total,
+ "successful_notifications": successful,
+ "failed_notifications": failed,
+ "success_rate": (successful / total * 100) if total > 0 else 0.0,
+ "total_delivery_time": total_time,
+ "average_delivery_time": avg_time,
+ }
diff --git a/workers/shared/models/pipeline_models.py b/workers/shared/models/pipeline_models.py
new file mode 100644
index 000000000..f0946e91e
--- /dev/null
+++ b/workers/shared/models/pipeline_models.py
@@ -0,0 +1,220 @@
+"""Pipeline Data Models for Workers
+
+Type-safe dataclasses for pipeline API responses to avoid dict parsing issues.
+Uses the architectural principles from @unstract/core/data_models.py
+"""
+
+from dataclasses import dataclass
+from typing import Any
+
+from unstract.core.data_models import serialize_dataclass_to_dict
+
+
+@dataclass
+class PipelineData:
+ """Pipeline information returned from internal API.
+
+ This matches the structure returned by the backend's pipeline endpoint.
+ """
+
+ id: str
+ pipeline_name: str
+ workflow: str # UUID of the associated workflow
+ pipeline_type: str = "ETL"
+ active: bool = True
+ scheduled: bool = False
+ cron_string: str | None = None
+ run_count: int = 0
+ last_run_time: str | None = None
+ last_run_status: str | None = None
+ is_api: bool = False
+ resolved_pipeline_type: str = "ETL"
+ resolved_pipeline_name: str = ""
+ created_at: str | None = None
+ modified_at: str | None = None
+ app_id: str | None = None
+ app_icon: str | None = None
+ app_url: str | None = None
+ access_control_bundle_id: str | None = None
+ organization: int | None = None
+ created_by: int | None = None
+ modified_by: int | None = None
+
+ def __post_init__(self):
+ """Validate required fields."""
+ if not self.id:
+ raise ValueError("Pipeline ID is required")
+ if not self.workflow:
+ raise ValueError("Workflow UUID is required")
+ if not self.pipeline_name:
+ raise ValueError("Pipeline name is required")
+
+ @property
+ def workflow_id(self) -> str:
+ """Get workflow UUID (alias for consistency)."""
+ return self.workflow
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary with proper serialization."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "PipelineData":
+ """Create from dictionary (backend API response).
+
+ Args:
+ data: Dictionary from backend API
+
+ Returns:
+ PipelineData instance
+
+ Raises:
+ ValueError: If required fields are missing
+ TypeError: If data is not a dictionary
+ """
+ if not isinstance(data, dict):
+ raise TypeError(f"Expected dict, got {type(data).__name__}")
+
+ # Extract required fields with validation
+ pipeline_id = data.get("id")
+ if not pipeline_id:
+ raise ValueError("Pipeline ID is required in API response")
+
+ workflow = data.get("workflow")
+ if not workflow:
+ raise ValueError("Workflow UUID is required in API response")
+
+ pipeline_name = data.get("pipeline_name")
+ if not pipeline_name:
+ raise ValueError("Pipeline name is required in API response")
+
+ return cls(
+ id=pipeline_id,
+ pipeline_name=pipeline_name,
+ workflow=workflow,
+ pipeline_type=data.get("pipeline_type", "ETL"),
+ active=data.get("active", True),
+ scheduled=data.get("scheduled", False),
+ cron_string=data.get("cron_string"),
+ run_count=data.get("run_count", 0),
+ last_run_time=data.get("last_run_time"),
+ last_run_status=data.get("last_run_status"),
+ is_api=data.get("is_api", False),
+ resolved_pipeline_type=data.get("resolved_pipeline_type", "ETL"),
+ resolved_pipeline_name=data.get("resolved_pipeline_name", ""),
+ created_at=data.get("created_at"),
+ modified_at=data.get("modified_at"),
+ app_id=data.get("app_id"),
+ app_icon=data.get("app_icon"),
+ app_url=data.get("app_url"),
+ access_control_bundle_id=data.get("access_control_bundle_id"),
+ organization=data.get("organization"),
+ created_by=data.get("created_by"),
+ modified_by=data.get("modified_by"),
+ )
+
+
+@dataclass
+class PipelineApiResponse:
+ """Complete pipeline API response structure.
+
+ This wraps the pipeline data and provides proper status handling.
+ """
+
+ status: str
+ pipeline: PipelineData
+
+ def __post_init__(self):
+ """Validate response structure."""
+ if self.status not in ["success", "error"]:
+ raise ValueError(
+ f"Invalid status: {self.status}. Must be 'success' or 'error'"
+ )
+
+ @property
+ def is_success(self) -> bool:
+ """Check if the API response was successful."""
+ return self.status == "success"
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary matching backend API format."""
+ return {"status": self.status, "pipeline": self.pipeline.to_dict()}
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "PipelineApiResponse":
+ """Create from backend API response dictionary.
+
+ Args:
+ data: Raw API response from backend
+
+ Returns:
+ PipelineApiResponse instance
+
+ Raises:
+ ValueError: If response structure is invalid
+ TypeError: If data is not a dictionary
+ """
+ if not isinstance(data, dict):
+ raise TypeError(f"Expected dict, got {type(data).__name__}")
+
+ status = data.get("status")
+ if not status:
+ raise ValueError("Status is required in API response")
+
+ pipeline_data = data.get("pipeline")
+ if not pipeline_data:
+ raise ValueError("Pipeline data is required in API response")
+
+ # Create pipeline data object
+ pipeline = PipelineData.from_dict(pipeline_data)
+
+ return cls(status=status, pipeline=pipeline)
+
+
+@dataclass
+class APIDeploymentData:
+ """API Deployment information for API-type workflows."""
+
+ id: str
+ api_name: str
+ display_name: str
+ pipeline: str # UUID of the associated pipeline
+ pipeline_type: str = "API"
+ is_active: bool = True
+ created_at: str | None = None
+ modified_at: str | None = None
+
+ def __post_init__(self):
+ """Validate required fields."""
+ if not self.id:
+ raise ValueError("API deployment ID is required")
+ if not self.pipeline:
+ raise ValueError("Pipeline UUID is required")
+ if not self.api_name:
+ raise ValueError("API name is required")
+
+ @property
+ def pipeline_id(self) -> str:
+ """Get pipeline UUID (alias for consistency)."""
+ return self.pipeline
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary with proper serialization."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "APIDeploymentData":
+ """Create from dictionary (backend API response)."""
+ if not isinstance(data, dict):
+ raise TypeError(f"Expected dict, got {type(data).__name__}")
+
+ return cls(
+ id=data["id"],
+ api_name=data["api_name"],
+ display_name=data["display_name"],
+ pipeline=data["pipeline"],
+ pipeline_type=data.get("pipeline_type", "API"),
+ is_active=data.get("is_active", True),
+ created_at=data.get("created_at"),
+ modified_at=data.get("modified_at"),
+ )
diff --git a/workers/shared/models/request_models.py b/workers/shared/models/request_models.py
new file mode 100644
index 000000000..661039c8e
--- /dev/null
+++ b/workers/shared/models/request_models.py
@@ -0,0 +1,96 @@
+"""API Request Models
+
+Dataclasses for API request payloads.
+"""
+
+import os
+import sys
+from dataclasses import dataclass, field
+from typing import Any
+
+# Import shared domain models from core
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core import ExecutionStatus
+
+# Import worker enums
+from ..enums import NotificationMethod, PipelineStatus
+
+
+@dataclass
+class WorkflowExecutionUpdateRequest:
+ """Request data for updating workflow execution status."""
+
+ status: ExecutionStatus
+ error_message: str | None = None
+ result: dict[str, Any] | None = None
+ execution_time: float | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ data = {"status": str(self.status)}
+ if self.error_message:
+ data["error_message"] = self.error_message
+ if self.result:
+ data["result"] = self.result
+ if self.execution_time:
+ data["execution_time"] = self.execution_time
+ return data
+
+
+@dataclass
+class PipelineStatusUpdateRequest:
+ """Request data for updating pipeline status."""
+
+ status: PipelineStatus
+ last_run_details: dict[str, Any] | None = None
+ execution_summary: dict[str, Any] | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ data = {"status": self.status.value}
+ if self.last_run_details:
+ data["last_run_details"] = self.last_run_details
+ if self.execution_summary:
+ data["execution_summary"] = self.execution_summary
+ return data
+
+
+@dataclass
+class NotificationRequest:
+ """Request data for sending notifications."""
+
+ method: NotificationMethod
+ recipients: list[str]
+ subject: str
+ message: str
+ metadata: dict[str, Any] = field(default_factory=dict)
+ priority: str = "normal" # low, normal, high, urgent
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ return {
+ "method": self.method.value,
+ "recipients": self.recipients,
+ "subject": self.subject,
+ "message": self.message,
+ "metadata": self.metadata,
+ "priority": self.priority,
+ }
+
+
+@dataclass
+class FileExecutionStatusUpdateRequest:
+ """Request data for updating file execution status."""
+
+ status: str
+ error_message: str | None = None
+ result: Any | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API request."""
+ data = {"status": self.status}
+ if self.error_message:
+ data["error_message"] = self.error_message
+ if self.result:
+ data["result"] = self.result
+ return data
diff --git a/workers/shared/models/result_models.py b/workers/shared/models/result_models.py
new file mode 100644
index 000000000..99fa04432
--- /dev/null
+++ b/workers/shared/models/result_models.py
@@ -0,0 +1,256 @@
+"""Worker Result Models
+
+Dataclasses for task execution results.
+"""
+
+import os
+import sys
+import time
+from dataclasses import dataclass, field
+from typing import Any
+
+# Import shared domain models from core
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from shared.enums import QueueResultStatus
+
+from unstract.core import ExecutionStatus, serialize_dataclass_to_dict
+from unstract.core.worker_models import FileExecutionResult
+
+# Import worker enums
+from ..enums import WebhookStatus
+
+
+@dataclass
+class WebhookResult:
+ """Structured result for webhook delivery tasks."""
+
+ status: WebhookStatus
+ url: str
+ task_id: str
+ webhook_task_id: str
+ webhook_status: str
+ payload_size: int
+ timeout: int
+ attempts: int
+ delivery_time: float
+ error_message: str | None = None
+ response_code: int | None = None
+ response_body: str | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WebhookResult":
+ """Create from dictionary (e.g., task result)."""
+ return cls(
+ status=WebhookStatus(data.get("status", WebhookStatus.FAILED)),
+ url=data.get("url", ""),
+ task_id=data.get("task_id", ""),
+ webhook_task_id=data.get("webhook_task_id", ""),
+ webhook_status=data.get("webhook_status", ""),
+ payload_size=data.get("payload_size", 0),
+ timeout=data.get("timeout", 30),
+ attempts=data.get("attempts", 1),
+ delivery_time=data.get("delivery_time", 0.0),
+ error_message=data.get("error_message"),
+ response_code=data.get("response_code"),
+ response_body=data.get("response_body"),
+ )
+
+
+@dataclass
+class BatchExecutionResult:
+ """Structured result for batch execution tasks."""
+
+ total_files: int
+ successful_files: int
+ failed_files: int
+ execution_time: float
+ file_results: list[FileExecutionResult] = field(default_factory=list)
+ batch_id: str | None = None
+ errors: list[str] = field(default_factory=list)
+
+ @property
+ def success_rate(self) -> float:
+ """Calculate success rate as percentage."""
+ if self.total_files == 0:
+ return 0.0
+ return (self.successful_files / self.total_files) * 100
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API response."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "BatchExecutionResult":
+ """Create from dictionary (e.g., task result)."""
+ file_results = [
+ FileExecutionResult.from_dict(result)
+ for result in data.get("file_results", [])
+ ]
+
+ return cls(
+ total_files=data.get("total_files", 0),
+ successful_files=data.get("successful_files", 0),
+ failed_files=data.get("failed_files", 0),
+ execution_time=data.get("execution_time", 0.0),
+ file_results=file_results,
+ batch_id=data.get("batch_id"),
+ errors=data.get("errors", []),
+ )
+
+ def add_file_result(self, file_result: FileExecutionResult):
+ """Add a file execution result to the batch."""
+ self.file_results.append(file_result)
+ self.total_files = len(self.file_results)
+
+ if file_result.is_successful():
+ self.successful_files += 1
+ else:
+ self.failed_files += 1
+
+ self.execution_time += file_result.processing_time
+
+
+@dataclass
+class CallbackProcessingResult:
+ """Result for callback processing operations."""
+
+ callback_id: str
+ execution_id: str
+ organization_id: str
+ workflow_id: str
+ results: list[dict[str, Any]] = field(default_factory=list)
+ callback_status: ExecutionStatus = ExecutionStatus.COMPLETED
+ processing_time: float = 0.0
+ successful_callbacks: int = 0
+ failed_callbacks: int = 0
+ error_message: str | None = None
+ metadata: dict[str, Any] | None = None
+
+ @property
+ def result_count(self) -> int:
+ """Get the number of results in this callback."""
+ return len(self.results) if self.results else 0
+
+ @property
+ def has_results(self) -> bool:
+ """Check if this callback has any results."""
+ return self.result_count > 0
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if callback processing was successful."""
+ return (
+ self.callback_status == ExecutionStatus.COMPLETED and not self.error_message
+ )
+
+ def get_successful_results(self) -> list[dict[str, Any]]:
+ """Filter and return only successful results."""
+ if not self.results:
+ return []
+
+ return [
+ result
+ for result in self.results
+ if isinstance(result, dict) and not result.get("error")
+ ]
+
+ def get_failed_results(self) -> list[dict[str, Any]]:
+ """Filter and return only failed results."""
+ if not self.results:
+ return []
+
+ return [
+ result
+ for result in self.results
+ if isinstance(result, dict) and result.get("error")
+ ]
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert callback result to dictionary."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "CallbackProcessingResult":
+ """Create CallbackProcessingResult from dictionary data."""
+ status_str = data.get("callback_status", ExecutionStatus.COMPLETED.value)
+ status = (
+ ExecutionStatus(status_str) if isinstance(status_str, str) else status_str
+ )
+
+ return cls(
+ callback_id=data["callback_id"],
+ execution_id=data["execution_id"],
+ organization_id=data["organization_id"],
+ workflow_id=data["workflow_id"],
+ results=data.get("results", []),
+ callback_status=status,
+ processing_time=data.get("processing_time", 0.0),
+ successful_callbacks=data.get("successful_callbacks", 0),
+ failed_callbacks=data.get("failed_callbacks", 0),
+ error_message=data.get("error_message"),
+ metadata=data.get("metadata"),
+ )
+
+
+# Utility functions for result aggregation
+def aggregate_file_results(
+ file_results: list[FileExecutionResult],
+) -> BatchExecutionResult:
+ """Aggregate multiple file results into a batch result."""
+ successful = len([r for r in file_results if r.is_successful()])
+ failed = len([r for r in file_results if r.has_error()])
+ total_time = sum(r.processing_time for r in file_results)
+
+ return BatchExecutionResult(
+ total_files=len(file_results),
+ successful_files=successful,
+ failed_files=failed,
+ execution_time=total_time,
+ file_results=file_results,
+ )
+
+
+@dataclass
+class QueueResult:
+ file: str
+ status: QueueResultStatus
+ result: Any
+ workflow_id: str
+ file_content: str | None = None
+ whisper_hash: str | None = None
+ file_execution_id: str | None = None
+ enqueued_at: float | None = None
+ ttl_seconds: int | None = None
+ extracted_text: str | None = None
+
+ def __post_init__(self):
+ """Initialize enqueued_at timestamp if not provided and validate required fields"""
+ if self.enqueued_at is None:
+ self.enqueued_at = time.time()
+
+ # Validate required fields
+ if not self.file:
+ raise ValueError("QueueResult requires a valid file name")
+ if not self.workflow_id:
+ raise ValueError("QueueResult requires a valid workflow_id")
+ if self.status is None:
+ raise ValueError("QueueResult requires a valid status")
+
+ def to_dict(self) -> Any:
+ result_dict = {
+ "file": self.file,
+ "whisper_hash": self.whisper_hash,
+ "status": self.status.value,
+ "result": self.result,
+ "workflow_id": self.workflow_id,
+ "file_content": self.file_content,
+ "file_execution_id": self.file_execution_id,
+ "enqueued_at": self.enqueued_at,
+ "ttl_seconds": self.ttl_seconds,
+ "extracted_text": self.extracted_text,
+ }
+ return result_dict
diff --git a/workers/shared/models/scheduler_models.py b/workers/shared/models/scheduler_models.py
new file mode 100644
index 000000000..df1f67bac
--- /dev/null
+++ b/workers/shared/models/scheduler_models.py
@@ -0,0 +1,206 @@
+"""Scheduler Data Models for Workers
+
+Type-safe dataclasses for scheduler operations to replace dict-based approaches.
+Uses the architectural principles from @unstract/core/data_models.py
+"""
+
+from dataclasses import dataclass, field
+from enum import Enum
+from typing import Any
+
+from unstract.core.data_models import serialize_dataclass_to_dict
+
+# Error message constants
+WORKFLOW_ID_REQUIRED = "Workflow ID is required"
+PIPELINE_ID_REQUIRED = "Pipeline ID is required"
+ORGANIZATION_ID_REQUIRED = "Organization ID is required"
+
+
+class ExecutionMode(str, Enum):
+ """Workflow execution modes."""
+
+ INSTANT = "INSTANT"
+ QUEUE = "QUEUE"
+ SCHEDULED = "SCHEDULED"
+
+
+class SchedulerExecutionStatus(str, Enum):
+ """Scheduler execution status values."""
+
+ SUCCESS = "success"
+ ERROR = "error"
+ PENDING = "pending"
+ IN_PROGRESS = "in_progress"
+ COMPLETED = "completed"
+ FAILED = "failed"
+
+
+@dataclass
+class WorkflowExecutionRequest:
+ """Request to create a workflow execution."""
+
+ workflow_id: str
+ pipeline_id: str
+ organization_id: str
+ single_step: bool = False
+ mode: ExecutionMode = ExecutionMode.QUEUE
+ total_files: int = 0
+ scheduled: bool = True
+ log_events_id: str | None = None # WebSocket channel ID for UI logs
+
+ def __post_init__(self):
+ """Validate required fields."""
+ if not self.workflow_id:
+ raise ValueError(WORKFLOW_ID_REQUIRED)
+ if not self.pipeline_id:
+ raise ValueError(PIPELINE_ID_REQUIRED)
+ if not self.organization_id:
+ raise ValueError(ORGANIZATION_ID_REQUIRED)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API calls."""
+ return serialize_dataclass_to_dict(self)
+
+
+@dataclass
+class AsyncExecutionRequest:
+ """Request to trigger async workflow execution."""
+
+ execution_id: str
+ workflow_id: str
+ pipeline_id: str
+ organization_id: str
+ scheduled: bool = True
+ use_file_history: bool = True
+ hash_values_of_files: dict[str, Any] = field(default_factory=dict)
+
+ def __post_init__(self):
+ """Validate required fields."""
+ if not self.execution_id:
+ raise ValueError("Execution ID is required")
+ if not self.workflow_id:
+ raise ValueError(WORKFLOW_ID_REQUIRED)
+ if not self.pipeline_id:
+ raise ValueError(PIPELINE_ID_REQUIRED)
+ if not self.organization_id:
+ raise ValueError(ORGANIZATION_ID_REQUIRED)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for API calls."""
+ return serialize_dataclass_to_dict(self)
+
+
+@dataclass
+class SchedulerExecutionResult:
+ """Result of a scheduler execution operation."""
+
+ status: SchedulerExecutionStatus
+ execution_id: str | None = None
+ workflow_id: str | None = None
+ pipeline_id: str | None = None
+ task_id: str | None = None
+ message: str = ""
+ error: str | None = None
+
+ def __post_init__(self):
+ """Ensure status is valid."""
+ if not isinstance(self.status, SchedulerExecutionStatus):
+ if isinstance(self.status, str):
+ try:
+ self.status = SchedulerExecutionStatus(self.status)
+ except ValueError:
+ raise ValueError(f"Invalid status: {self.status}")
+
+ @property
+ def is_success(self) -> bool:
+ """Check if the execution was successful."""
+ return self.status in [
+ SchedulerExecutionStatus.SUCCESS,
+ SchedulerExecutionStatus.COMPLETED,
+ ]
+
+ @property
+ def is_error(self) -> bool:
+ """Check if the execution failed."""
+ return self.status in [
+ SchedulerExecutionStatus.ERROR,
+ SchedulerExecutionStatus.FAILED,
+ ]
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary."""
+ return serialize_dataclass_to_dict(self)
+
+ @classmethod
+ def success(
+ cls,
+ execution_id: str,
+ workflow_id: str | None = None,
+ pipeline_id: str | None = None,
+ task_id: str | None = None,
+ message: str = "Execution completed successfully",
+ ) -> "SchedulerExecutionResult":
+ """Create a success result."""
+ return cls(
+ status=SchedulerExecutionStatus.SUCCESS,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ pipeline_id=pipeline_id,
+ task_id=task_id,
+ message=message,
+ )
+
+ @classmethod
+ def error(
+ cls,
+ error: str,
+ execution_id: str | None = None,
+ workflow_id: str | None = None,
+ pipeline_id: str | None = None,
+ message: str = "Execution failed",
+ ) -> "SchedulerExecutionResult":
+ """Create an error result."""
+ return cls(
+ status=SchedulerExecutionStatus.ERROR,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ pipeline_id=pipeline_id,
+ message=message,
+ error=error,
+ )
+
+
+@dataclass
+class ScheduledPipelineContext:
+ """Context information for a scheduled pipeline execution."""
+
+ pipeline_id: str
+ pipeline_name: str
+ workflow_id: str
+ organization_id: str
+ use_file_history: bool = True
+
+ def __post_init__(self):
+ """Validate required fields."""
+ if not self.pipeline_id:
+ raise ValueError(PIPELINE_ID_REQUIRED)
+ if not self.pipeline_name:
+ raise ValueError("Pipeline name is required")
+ if not self.workflow_id:
+ raise ValueError(WORKFLOW_ID_REQUIRED)
+ if not self.organization_id:
+ raise ValueError(ORGANIZATION_ID_REQUIRED)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary."""
+ return serialize_dataclass_to_dict(self)
+
+
+__all__ = [
+ "ExecutionMode",
+ "SchedulerExecutionStatus",
+ "WorkflowExecutionRequest",
+ "AsyncExecutionRequest",
+ "SchedulerExecutionResult",
+ "ScheduledPipelineContext",
+]
diff --git a/workers/shared/models/task_models.py b/workers/shared/models/task_models.py
new file mode 100644
index 000000000..3b61949a8
--- /dev/null
+++ b/workers/shared/models/task_models.py
@@ -0,0 +1,181 @@
+"""Task Context and Error Models
+
+Dataclasses for task execution context and error handling.
+"""
+
+import logging
+from dataclasses import dataclass
+from datetime import datetime
+from typing import Any
+
+# Import worker enums
+from ..enums import TaskName
+
+logger = logging.getLogger(__name__)
+
+
+@dataclass
+class TaskExecutionContext:
+ """Execution context for worker tasks."""
+
+ task_id: str
+ task_name: TaskName
+ organization_id: str
+ execution_id: str | None = None
+ workflow_id: str | None = None
+ pipeline_id: str | None = None
+ user_id: str | None = None
+ correlation_id: str | None = None
+ retry_count: int = 0
+ started_at: datetime | None = None
+
+ def __post_init__(self):
+ """Set started_at if not provided."""
+ if self.started_at is None:
+ self.started_at = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for logging and tracing."""
+ return {
+ "task_id": self.task_id,
+ "task_name": self.task_name.value,
+ "organization_id": self.organization_id,
+ "execution_id": self.execution_id,
+ "workflow_id": self.workflow_id,
+ "pipeline_id": self.pipeline_id,
+ "retry_count": self.retry_count,
+ "started_at": self.started_at.isoformat() if self.started_at else None,
+ }
+
+ def get_log_context(self) -> dict[str, Any]:
+ """Get context suitable for structured logging."""
+ return {
+ "task_id": self.task_id,
+ "task_name": self.task_name.value,
+ "organization_id": self.organization_id,
+ "execution_id": self.execution_id,
+ "workflow_id": self.workflow_id,
+ "pipeline_id": self.pipeline_id,
+ "retry_count": self.retry_count,
+ }
+
+
+@dataclass
+class TaskError:
+ """Structured error information for task failures."""
+
+ task_id: str
+ task_name: TaskName
+ error_type: str
+ error_message: str
+ traceback: str | None = None
+ retry_count: int = 0
+ occurred_at: datetime | None = None
+
+ def __post_init__(self):
+ """Set occurred_at if not provided."""
+ if self.occurred_at is None:
+ self.occurred_at = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for error reporting."""
+ return {
+ "task_id": self.task_id,
+ "task_name": self.task_name.value,
+ "error_type": self.error_type,
+ "error_message": self.error_message,
+ "traceback": self.traceback,
+ "retry_count": self.retry_count,
+ "occurred_at": self.occurred_at.isoformat() if self.occurred_at else None,
+ }
+
+ @classmethod
+ def from_exception(
+ cls, task_id: str, task_name: TaskName, exception: Exception, retry_count: int = 0
+ ) -> "TaskError":
+ """Create from Python exception."""
+ import traceback as tb
+
+ return cls(
+ task_id=task_id,
+ task_name=task_name,
+ error_type=type(exception).__name__,
+ error_message=str(exception),
+ traceback=tb.format_exc(),
+ retry_count=retry_count,
+ )
+
+
+@dataclass
+class TaskPerformanceMetrics:
+ """Performance metrics for task execution monitoring."""
+
+ task_name: str
+ execution_time: float
+ memory_usage: float | None = None
+ cpu_usage: float | None = None
+ error_count: int = 0
+ retry_count: int = 0
+ timestamp: datetime | None = None
+
+ def __post_init__(self):
+ """Set timestamp if not provided."""
+ if self.timestamp is None:
+ self.timestamp = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for metrics collection."""
+ return {
+ "task_name": self.task_name,
+ "execution_time": self.execution_time,
+ "memory_usage": self.memory_usage,
+ "cpu_usage": self.cpu_usage,
+ "error_count": self.error_count,
+ "retry_count": self.retry_count,
+ "timestamp": self.timestamp.isoformat() if self.timestamp else None,
+ }
+
+
+@dataclass
+class WorkerHealthMetrics:
+ """Health metrics for worker instances."""
+
+ worker_name: str
+ worker_version: str
+ uptime: float
+ active_tasks: int
+ completed_tasks: int
+ failed_tasks: int
+ memory_usage: float | None = None
+ cpu_usage: float | None = None
+ last_heartbeat: datetime | None = None
+
+ def __post_init__(self):
+ """Set timestamp if not provided."""
+ if self.last_heartbeat is None:
+ self.last_heartbeat = datetime.now()
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary for health monitoring."""
+ return {
+ "worker_name": self.worker_name,
+ "worker_version": self.worker_version,
+ "uptime": self.uptime,
+ "active_tasks": self.active_tasks,
+ "completed_tasks": self.completed_tasks,
+ "failed_tasks": self.failed_tasks,
+ "memory_usage": self.memory_usage,
+ "cpu_usage": self.cpu_usage,
+ "last_heartbeat": self.last_heartbeat.isoformat()
+ if self.last_heartbeat
+ else None,
+ "success_rate": self.success_rate,
+ }
+
+ @property
+ def success_rate(self) -> float:
+ """Calculate task success rate."""
+ total_tasks = self.completed_tasks + self.failed_tasks
+ if total_tasks == 0:
+ return 100.0
+ return (self.completed_tasks / total_tasks) * 100
diff --git a/workers/shared/models/tool_models.py b/workers/shared/models/tool_models.py
new file mode 100644
index 000000000..941017299
--- /dev/null
+++ b/workers/shared/models/tool_models.py
@@ -0,0 +1,364 @@
+"""Tool Configuration Data Models
+
+This module provides strongly-typed dataclasses for tool configurations,
+replacing fragile dictionary-based tool handling with type-safe structures.
+"""
+
+from dataclasses import dataclass, field
+from typing import Any
+
+
+@dataclass
+class ToolInstanceConfig:
+ """Strongly-typed configuration for tool instances.
+
+ Replaces dictionary-based tool configuration with type-safe structure
+ that provides validation, autocomplete, and clear documentation.
+ """
+
+ tool_id: str
+ tool_name: str
+ tool_settings: dict[str, Any] = field(default_factory=dict)
+ step_name: str = ""
+ prompt_registry_id: str | None = None
+ enable: bool = True
+ step: int | None = None
+ tool_version: str | None = None
+ tool_description: str | None = None
+ input_schema: dict[str, Any] | None = None
+ output_schema: dict[str, Any] | None = None
+
+ def __post_init__(self):
+ """Validate tool configuration after initialization."""
+ if not self.tool_id:
+ raise ValueError("tool_id is required for tool configuration")
+
+ if not self.tool_name:
+ raise ValueError("tool_name is required for tool configuration")
+
+ # Ensure tool_settings is a dictionary
+ if not isinstance(self.tool_settings, dict):
+ raise ValueError("tool_settings must be a dictionary")
+
+ @property
+ def is_enabled(self) -> bool:
+ """Check if the tool is enabled."""
+ return self.enable
+
+ @property
+ def has_prompt_registry(self) -> bool:
+ """Check if the tool has a prompt registry."""
+ return bool(self.prompt_registry_id)
+
+ @property
+ def has_settings(self) -> bool:
+ """Check if the tool has any settings."""
+ return bool(self.tool_settings)
+
+ def get_setting(self, setting_key: str, default: Any = None) -> Any:
+ """Get a tool setting value."""
+ return self.tool_settings.get(setting_key, default)
+
+ def set_setting(self, setting_key: str, value: Any) -> None:
+ """Set a tool setting value."""
+ self.tool_settings[setting_key] = value
+
+ def update_settings(self, settings: dict[str, Any]) -> None:
+ """Update multiple tool settings."""
+ self.tool_settings.update(settings)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert tool configuration to dictionary for serialization."""
+ result = {
+ "tool_id": self.tool_id,
+ "tool_name": self.tool_name,
+ "settings": self.tool_settings,
+ "step_name": self.step_name,
+ "enable": self.enable,
+ }
+
+ if self.prompt_registry_id:
+ result["prompt_registry_id"] = self.prompt_registry_id
+
+ if self.step is not None:
+ result["step"] = self.step
+
+ if self.tool_version:
+ result["tool_version"] = self.tool_version
+
+ if self.tool_description:
+ result["tool_description"] = self.tool_description
+
+ if self.input_schema:
+ result["input_schema"] = self.input_schema
+
+ if self.output_schema:
+ result["output_schema"] = self.output_schema
+
+ return result
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "ToolInstanceConfig":
+ """Create ToolInstanceConfig from dictionary data.
+
+ Args:
+ data: Dictionary containing tool configuration data
+
+ Returns:
+ ToolInstanceConfig instance
+ """
+ return cls(
+ tool_id=data["tool_id"],
+ tool_name=data.get("tool_name", ""),
+ tool_settings=data.get("settings", {}),
+ step_name=data.get("step_name", ""),
+ prompt_registry_id=data.get("prompt_registry_id"),
+ enable=data.get("enable", True),
+ step=data.get("step"),
+ tool_version=data.get("tool_version"),
+ tool_description=data.get("tool_description"),
+ input_schema=data.get("input_schema"),
+ output_schema=data.get("output_schema"),
+ )
+
+
+@dataclass
+class ToolExecutionRequest:
+ """Strongly-typed request for tool execution."""
+
+ tool_instance_id: str
+ input_data: dict[str, Any]
+ file_data: dict[str, Any] | None = None
+ execution_context: dict[str, Any] | None = None
+ organization_id: str | None = None
+ timeout: int | None = None
+
+ def __post_init__(self):
+ """Validate execution request after initialization."""
+ if not self.tool_instance_id:
+ raise ValueError("tool_instance_id is required for tool execution")
+
+ if not isinstance(self.input_data, dict):
+ raise ValueError("input_data must be a dictionary")
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert execution request to dictionary for API calls."""
+ result = {
+ "input_data": self.input_data,
+ "file_data": self.file_data or {},
+ "execution_context": self.execution_context or {},
+ }
+
+ if self.organization_id:
+ result["organization_id"] = self.organization_id
+
+ if self.timeout:
+ result["timeout"] = self.timeout
+
+ return result
+
+
+@dataclass
+class ToolExecutionResult:
+ """Strongly-typed result from tool execution."""
+
+ execution_id: str
+ tool_instance_id: str
+ status: str
+ output_data: dict[str, Any] | None = None
+ execution_time: float | None = None
+ error_message: str | None = None
+ step_results: list[dict[str, Any]] = field(default_factory=list)
+ metadata: dict[str, Any] | None = None
+
+ def __post_init__(self):
+ """Validate execution result after initialization."""
+ if not self.execution_id:
+ raise ValueError("execution_id is required for tool execution result")
+
+ if not self.tool_instance_id:
+ raise ValueError("tool_instance_id is required for tool execution result")
+
+ if not self.status:
+ raise ValueError("status is required for tool execution result")
+
+ @property
+ def is_successful(self) -> bool:
+ """Check if tool execution was successful."""
+ return self.status == "COMPLETED" and not self.error_message
+
+ @property
+ def is_failed(self) -> bool:
+ """Check if tool execution failed."""
+ return self.status == "ERROR" or bool(self.error_message)
+
+ @property
+ def has_output(self) -> bool:
+ """Check if tool execution produced output."""
+ return bool(self.output_data)
+
+ def get_output_field(self, field_name: str, default: Any = None) -> Any:
+ """Get a field from the output data."""
+ if not self.output_data:
+ return default
+ return self.output_data.get(field_name, default)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert execution result to dictionary for serialization."""
+ result = {
+ "execution_id": self.execution_id,
+ "tool_instance_id": self.tool_instance_id,
+ "status": self.status,
+ }
+
+ if self.output_data:
+ result["output_data"] = self.output_data
+
+ if self.execution_time is not None:
+ result["execution_time"] = self.execution_time
+
+ if self.error_message:
+ result["error_message"] = self.error_message
+
+ if self.step_results:
+ result["step_results"] = self.step_results
+
+ if self.metadata:
+ result["metadata"] = self.metadata
+
+ return result
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "ToolExecutionResult":
+ """Create ToolExecutionResult from dictionary data."""
+ return cls(
+ execution_id=data["execution_id"],
+ tool_instance_id=data["tool_instance_id"],
+ status=data["status"],
+ output_data=data.get("output_data"),
+ execution_time=data.get("execution_time"),
+ error_message=data.get("error_message"),
+ step_results=data.get("step_results", []),
+ metadata=data.get("metadata"),
+ )
+
+
+@dataclass
+class WorkflowToolsConfig:
+ """Strongly-typed configuration for workflow tools.
+
+ Contains the complete set of tool configurations for a workflow
+ with validation and management methods.
+ """
+
+ tools: list[ToolInstanceConfig] = field(default_factory=list)
+ workflow_id: str | None = None
+ execution_id: str | None = None
+
+ def __post_init__(self):
+ """Validate workflow tools configuration."""
+ if not isinstance(self.tools, list):
+ raise ValueError("tools must be a list of ToolInstanceConfig instances")
+
+ for i, tool in enumerate(self.tools):
+ if not isinstance(tool, ToolInstanceConfig):
+ raise ValueError(
+ f"Tool at index {i} must be a ToolInstanceConfig instance"
+ )
+
+ @property
+ def tool_count(self) -> int:
+ """Get the number of tools in the workflow."""
+ return len(self.tools)
+
+ @property
+ def enabled_tools(self) -> list[ToolInstanceConfig]:
+ """Get only the enabled tools."""
+ return [tool for tool in self.tools if tool.is_enabled]
+
+ @property
+ def enabled_tool_count(self) -> int:
+ """Get the number of enabled tools."""
+ return len(self.enabled_tools)
+
+ def get_tool_by_id(self, tool_id: str) -> ToolInstanceConfig | None:
+ """Get a tool by its ID."""
+ for tool in self.tools:
+ if tool.tool_id == tool_id:
+ return tool
+ return None
+
+ def get_tool_by_name(self, tool_name: str) -> ToolInstanceConfig | None:
+ """Get a tool by its name."""
+ for tool in self.tools:
+ if tool.tool_name == tool_name:
+ return tool
+ return None
+
+ def get_tools_by_step(self) -> list[ToolInstanceConfig]:
+ """Get tools sorted by step number."""
+ return sorted(
+ [tool for tool in self.tools if tool.step is not None],
+ key=lambda t: t.step or 0,
+ )
+
+ def add_tool(self, tool: ToolInstanceConfig) -> None:
+ """Add a tool to the workflow."""
+ if not isinstance(tool, ToolInstanceConfig):
+ raise ValueError("Tool must be a ToolInstanceConfig instance")
+ self.tools.append(tool)
+
+ def remove_tool(self, tool_id: str) -> bool:
+ """Remove a tool from the workflow by ID."""
+ for i, tool in enumerate(self.tools):
+ if tool.tool_id == tool_id:
+ del self.tools[i]
+ return True
+ return False
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert workflow tools configuration to dictionary."""
+ return {
+ "tools": [tool.to_dict() for tool in self.tools],
+ "workflow_id": self.workflow_id,
+ "execution_id": self.execution_id,
+ }
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "WorkflowToolsConfig":
+ """Create WorkflowToolsConfig from dictionary data."""
+ tools_data = data.get("tools", [])
+ tools = [ToolInstanceConfig.from_dict(tool_data) for tool_data in tools_data]
+
+ return cls(
+ tools=tools,
+ workflow_id=data.get("workflow_id"),
+ execution_id=data.get("execution_id"),
+ )
+
+
+# Utility functions for tool configuration conversion
+def convert_tools_config_from_dict(
+ tools_config: list[dict[str, Any]],
+) -> list[ToolInstanceConfig]:
+ """Convert list of tool configuration dictionaries to ToolInstanceConfig list.
+
+ Args:
+ tools_config: List of tool configuration dictionaries
+
+ Returns:
+ List of ToolInstanceConfig instances
+ """
+ return [ToolInstanceConfig.from_dict(tool_config) for tool_config in tools_config]
+
+
+def convert_tools_config_to_dict(tools: list[ToolInstanceConfig]) -> list[dict[str, Any]]:
+ """Convert list of ToolInstanceConfig to dictionary list.
+
+ Args:
+ tools: List of ToolInstanceConfig instances
+
+ Returns:
+ List of tool configuration dictionaries
+ """
+ return [tool.to_dict() for tool in tools]
diff --git a/workers/shared/models/worker_models.py b/workers/shared/models/worker_models.py
new file mode 100644
index 000000000..b894eabdf
--- /dev/null
+++ b/workers/shared/models/worker_models.py
@@ -0,0 +1,533 @@
+"""Worker Configuration Data Models
+
+This module provides dataclasses for worker configuration, task routing,
+and queue management. These replace dictionary-based configurations with
+type-safe, validated dataclasses.
+
+Migration Note: Part of the worker refactoring initiative to improve
+code maintainability and reduce duplication across workers.
+"""
+
+import os
+import sys
+from collections.abc import Callable
+from dataclasses import dataclass, field
+from typing import Any
+
+from shared.enums.worker_enums import QueueName, WorkerType
+
+# Global cache for command-line Celery settings
+_CMDLINE_CELERY_SETTINGS: dict[str, str] | None = None
+
+
+def _parse_celery_cmdline_args() -> dict[str, str]:
+ """Parse Celery settings from command-line arguments.
+
+ Extracts --setting=value pairs from sys.argv and converts them to
+ setting names compatible with get_celery_setting().
+
+ Returns:
+ Dictionary mapping setting names to values from command-line
+
+ Examples:
+ --pool=prefork -> {"POOL_TYPE": "prefork"}
+ --concurrency=20 -> {"CONCURRENCY": "20"}
+ --loglevel=INFO -> {"LOG_LEVEL": "INFO"}
+ """
+ settings = {}
+
+ # Convert common Celery argument names to setting names
+ setting_mapping = {
+ "pool": "POOL_TYPE",
+ "concurrency": "CONCURRENCY",
+ "loglevel": "LOG_LEVEL",
+ "prefetch-multiplier": "PREFETCH_MULTIPLIER",
+ "max-tasks-per-child": "MAX_TASKS_PER_CHILD",
+ "time-limit": "TASK_TIME_LIMIT",
+ "soft-time-limit": "TASK_SOFT_TIME_LIMIT",
+ "without-gossip": "WORKER_GOSSIP",
+ "without-mingle": "WORKER_MINGLE",
+ "without-heartbeat": "WORKER_HEARTBEAT",
+ # Add more mappings as needed
+ }
+
+ for arg in sys.argv:
+ if arg.startswith("--"):
+ if "=" in arg:
+ # Handle --setting=value
+ setting_arg, value = arg[2:].split("=", 1)
+ setting_name = setting_mapping.get(
+ setting_arg, setting_arg.upper().replace("-", "_")
+ )
+ settings[setting_name] = value
+ elif arg[2:] in setting_mapping:
+ # Handle --without-* flags (they don't have values)
+ setting_arg = arg[2:]
+ if setting_arg.startswith("without-"):
+ setting_name = setting_mapping[setting_arg]
+ settings[setting_name] = "false"
+
+ return settings
+
+
+def _get_cmdline_celery_settings() -> dict[str, str]:
+ """Get cached command-line Celery settings, parsing if needed."""
+ global _CMDLINE_CELERY_SETTINGS
+ if _CMDLINE_CELERY_SETTINGS is None:
+ _CMDLINE_CELERY_SETTINGS = _parse_celery_cmdline_args()
+ return _CMDLINE_CELERY_SETTINGS
+
+
+def get_celery_setting(
+ setting_name: str, worker_type: WorkerType, default: Any, setting_type: type = str
+) -> Any:
+ """Get Celery configuration setting with 4-tier hierarchy resolution.
+
+ Resolution order (most specific wins):
+ 1. Command-line arguments (--pool=prefork, --concurrency=20, etc.) - HIGHEST
+ 2. {WORKER_TYPE}_{SETTING_NAME} (worker-specific env override)
+ 3. CELERY_{SETTING_NAME} (global env override)
+ 4. default (Celery standard/provided default) - LOWEST
+
+ Args:
+ setting_name: The setting name (e.g., "TASK_TIME_LIMIT")
+ worker_type: Worker type for worker-specific overrides
+ default: Default value if no settings are found
+ setting_type: Type to convert the setting value to (str, int, bool, etc.)
+
+ Returns:
+ Resolved configuration value with proper type conversion
+
+ Examples:
+ # Check --pool=, then FILE_PROCESSING_POOL_TYPE, then CELERY_POOL_TYPE, then default
+ pool = get_celery_setting("POOL_TYPE", WorkerType.FILE_PROCESSING, "prefork", str)
+
+ # Check --concurrency=, then CALLBACK_CONCURRENCY, then CELERY_CONCURRENCY, then default
+ concurrency = get_celery_setting("CONCURRENCY", WorkerType.CALLBACK, 4, int)
+ """
+ # 1. Check command-line arguments first (highest priority)
+ cmdline_settings = _get_cmdline_celery_settings()
+ if setting_name in cmdline_settings:
+ cmdline_value = cmdline_settings[setting_name]
+ converted_value = _convert_setting_value(cmdline_value, setting_type)
+ if converted_value is not None:
+ return converted_value
+
+ # 2. Check worker-specific setting (high priority)
+ worker_specific_key = f"{worker_type.name}_{setting_name}"
+ worker_value = os.getenv(worker_specific_key)
+ if worker_value is not None:
+ converted_value = _convert_setting_value(worker_value, setting_type)
+ if converted_value is not None:
+ return converted_value
+
+ # 3. Check global Celery setting (medium priority)
+ global_key = f"CELERY_{setting_name}"
+ global_value = os.getenv(global_key)
+ if global_value is not None:
+ converted_value = _convert_setting_value(global_value, setting_type)
+ if converted_value is not None:
+ return converted_value
+
+ # 4. Use provided default (lowest priority)
+ return default
+
+
+def _convert_setting_value(value: str, setting_type: type) -> Any:
+ """Convert string environment variable to appropriate type.
+
+ Args:
+ value: String value from environment variable
+ setting_type: Target type for conversion
+
+ Returns:
+ Converted value or None if empty/invalid
+
+ Raises:
+ ValueError: If conversion fails for non-empty values
+ """
+ # Handle empty or whitespace-only values
+ if not value or not value.strip():
+ return None
+
+ # Clean the value
+ value = value.strip()
+
+ if setting_type == bool:
+ return value.lower() in ("true", "1", "yes", "on")
+ elif setting_type == int:
+ try:
+ return int(value)
+ except ValueError:
+ raise ValueError(f"Cannot convert '{value}' to integer")
+ elif setting_type == float:
+ try:
+ return float(value)
+ except ValueError:
+ raise ValueError(f"Cannot convert '{value}' to float")
+ elif setting_type == tuple:
+ # For autoscale tuples like "4,1" -> (4, 1)
+ try:
+ parts = [x.strip() for x in value.split(",") if x.strip()]
+ if not parts:
+ return None
+ return tuple(int(x) for x in parts)
+ except ValueError:
+ raise ValueError(f"Cannot convert '{value}' to tuple of integers")
+ else:
+ # Default to string (already cleaned)
+ return value
+
+
+@dataclass
+class TaskRoute:
+ """Single task routing configuration.
+
+ Defines how a task pattern maps to a specific queue.
+ """
+
+ pattern: str # Task name or pattern (e.g., "process_file_batch" or "worker.*")
+ queue: QueueName # Target queue enum
+
+ def to_dict(self) -> dict[str, str]:
+ """Convert to Celery-compatible routing dict."""
+ return {"queue": self.queue.value}
+
+
+@dataclass
+class WorkerQueueConfig:
+ """Queue configuration for a worker.
+
+ Defines primary and additional queues that a worker consumes from.
+ """
+
+ primary_queue: QueueName
+ additional_queues: list[QueueName] = field(default_factory=list)
+
+ def all_queues(self) -> set[str]:
+ """Get all queue names as strings.
+
+ Returns:
+ Set of queue name strings
+ """
+ queues = {self.primary_queue.value}
+ queues.update(q.value for q in self.additional_queues)
+ return queues
+
+ def to_queue_list(self) -> list[str]:
+ """Get ordered list of queue names.
+
+ Returns:
+ List with primary queue first, then additional queues
+ """
+ result = [self.primary_queue.value]
+ result.extend(q.value for q in self.additional_queues)
+ return result
+
+ def to_cli_queues(self) -> str:
+ """Format queues for Celery CLI --queues parameter.
+
+ Returns:
+ Comma-separated queue names
+ """
+ return ",".join(self.to_queue_list())
+
+
+@dataclass
+class WorkerTaskRouting:
+ """Complete task routing configuration for a worker.
+
+ Encapsulates all task routes for a specific worker type.
+ """
+
+ worker_type: WorkerType
+ routes: list[TaskRoute]
+
+ def to_celery_config(self) -> dict[str, dict[str, str]]:
+ """Convert to Celery task_routes configuration.
+
+ Returns:
+ Dictionary compatible with Celery's task_routes setting
+ """
+ return {route.pattern: route.to_dict() for route in self.routes}
+
+ def add_route(self, pattern: str, queue: QueueName) -> None:
+ """Add a new task route.
+
+ Args:
+ pattern: Task name or pattern
+ queue: Target queue
+ """
+ self.routes.append(TaskRoute(pattern, queue))
+
+ def get_queue_for_task(self, task_name: str) -> QueueName | None:
+ """Find queue for a specific task name.
+
+ Args:
+ task_name: Full task name
+
+ Returns:
+ Queue name if route found, None otherwise
+ """
+ # Check exact matches first
+ for route in self.routes:
+ if route.pattern == task_name:
+ return route.queue
+
+ # Check wildcard patterns
+ for route in self.routes:
+ if route.pattern.endswith("*"):
+ prefix = route.pattern[:-1]
+ if task_name.startswith(prefix):
+ return route.queue
+
+ return None
+
+
+@dataclass
+class WorkerHealthConfig:
+ """Health check configuration for a worker."""
+
+ port: int
+ custom_checks: list[Callable] = field(default_factory=list)
+ check_interval: int = 30 # seconds
+
+ def add_check(self, name: str, check_func: Callable) -> None:
+ """Add a custom health check function."""
+ self.custom_checks.append((name, check_func))
+
+
+@dataclass
+class WorkerCeleryConfig:
+ """Complete Celery configuration for a worker.
+
+ Combines all configuration aspects into a single dataclass.
+ """
+
+ worker_type: WorkerType
+ queue_config: WorkerQueueConfig
+ task_routing: WorkerTaskRouting
+ health_config: WorkerHealthConfig | None = None
+
+ # Celery worker settings
+ prefetch_multiplier: int = 1
+ max_tasks_per_child: int = 1000
+ task_acks_late: bool = True
+ task_reject_on_worker_lost: bool = True
+
+ # Timeouts
+ task_time_limit: int = 7200 # 2 hours
+ task_soft_time_limit: int = 6300 # 1h 45m
+
+ # Retry settings
+ task_default_retry_delay: int = 60
+ task_max_retries: int = 3
+
+ # Pool settings
+ pool_type: str = "prefork" # or "threads", "solo", "eventlet"
+ concurrency: int | None = None # None means auto
+ autoscale: tuple[int, int] | None = None # (max, min) workers
+
+ # Task annotations (for task-specific settings like retry policies)
+ task_annotations: dict[str, dict[str, Any]] = field(default_factory=dict)
+
+ def _get_worker_specific_timeout_defaults(self) -> tuple[int, int]:
+ """Get worker-specific timeout defaults.
+
+ Returns static defaults based on worker type that will be overridden
+ by environment variables like FILE_PROCESSING_TASK_TIME_LIMIT.
+
+ Returns:
+ tuple[int, int]: (hard_timeout, soft_timeout) in seconds
+ """
+ # Worker-specific defaults (will be overridden by env vars)
+ if self.worker_type == WorkerType.FILE_PROCESSING:
+ return 7200, 6300 # 2 hours / 1h 45m (large files)
+ elif self.worker_type == WorkerType.CALLBACK:
+ return 3600, 3300 # 1 hour / 55 min
+ else:
+ # Conservative defaults for other workers
+ return 3600, 3300 # 1 hour / 55 min
+
+ def to_celery_dict(self, broker_url: str, result_backend: str) -> dict[str, Any]:
+ """Generate complete Celery configuration dictionary with hierarchical resolution.
+
+ Uses 3-tier hierarchy: Worker-specific > Global > Default
+ Includes feature-specific logic for chord workers, pool types, etc.
+
+ Args:
+ broker_url: Celery broker URL
+ result_backend: Celery result backend URL
+
+ Returns:
+ Dictionary suitable for app.conf.update()
+ """
+ config = {
+ # Connection settings
+ "broker_url": broker_url,
+ "result_backend": result_backend,
+ # Task routing
+ "task_routes": self.task_routing.to_celery_config(),
+ # Serialization (configurable from env)
+ "task_serializer": get_celery_setting(
+ "TASK_SERIALIZER", self.worker_type, "json"
+ ),
+ "accept_content": ["json"], # Could make this configurable too
+ "result_serializer": get_celery_setting(
+ "RESULT_SERIALIZER", self.worker_type, "json"
+ ),
+ "timezone": get_celery_setting("TIMEZONE", self.worker_type, "UTC"),
+ "enable_utc": get_celery_setting("ENABLE_UTC", self.worker_type, True, bool),
+ # Worker settings (all configurable from env with Celery defaults)
+ "worker_prefetch_multiplier": get_celery_setting(
+ "PREFETCH_MULTIPLIER",
+ self.worker_type,
+ 1,
+ int, # Celery default is 4, but 1 is safer
+ ),
+ "task_acks_late": get_celery_setting(
+ "TASK_ACKS_LATE", self.worker_type, True, bool
+ ),
+ "worker_max_tasks_per_child": get_celery_setting(
+ "MAX_TASKS_PER_CHILD",
+ self.worker_type,
+ 1000,
+ int, # Prevent memory leaks
+ ),
+ "task_reject_on_worker_lost": get_celery_setting(
+ "TASK_REJECT_ON_WORKER_LOST", self.worker_type, True, bool
+ ),
+ "task_acks_on_failure_or_timeout": get_celery_setting(
+ "TASK_ACKS_ON_FAILURE_OR_TIMEOUT", self.worker_type, True, bool
+ ),
+ "worker_disable_rate_limits": get_celery_setting(
+ "DISABLE_RATE_LIMITS", self.worker_type, False, bool
+ ),
+ # Timeouts (configurable from env with worker-specific defaults)
+ # Falls back to task-specific timeout env vars (FILE_PROCESSING_TIMEOUT, etc.)
+ "task_time_limit": get_celery_setting(
+ "TASK_TIME_LIMIT",
+ self.worker_type,
+ self._get_worker_specific_timeout_defaults()[0],
+ int,
+ ),
+ "task_soft_time_limit": get_celery_setting(
+ "TASK_SOFT_TIME_LIMIT",
+ self.worker_type,
+ self._get_worker_specific_timeout_defaults()[1],
+ int,
+ ),
+ # Retry configuration (configurable from env)
+ "task_default_retry_delay": get_celery_setting(
+ "TASK_DEFAULT_RETRY_DELAY",
+ self.worker_type,
+ 60,
+ int, # 1 minute default
+ ),
+ "task_max_retries": get_celery_setting(
+ "TASK_MAX_RETRIES", self.worker_type, 3, int
+ ),
+ # Stability (configurable from env)
+ "worker_pool_restarts": get_celery_setting(
+ "POOL_RESTARTS", self.worker_type, True, bool
+ ),
+ "broker_connection_retry_on_startup": get_celery_setting(
+ "BROKER_CONNECTION_RETRY_ON_STARTUP", self.worker_type, True, bool
+ ),
+ # Monitoring (configurable from env)
+ "worker_send_task_events": get_celery_setting(
+ "SEND_TASK_EVENTS", self.worker_type, True, bool
+ ),
+ "task_send_sent_event": get_celery_setting(
+ "TASK_SEND_SENT_EVENT", self.worker_type, True, bool
+ ),
+ # Task imports
+ "imports": [self.worker_type.to_import_path()],
+ }
+
+ # Feature-specific configurations
+ self._add_pool_configuration(config)
+ self._add_worker_scaling_configuration(config)
+ self._add_chord_configuration(config)
+
+ # Add task annotations if present
+ if self.task_annotations:
+ config["task_annotations"] = self.task_annotations
+
+ return config
+
+ def _add_pool_configuration(self, config: dict[str, Any]) -> None:
+ """Add worker pool configuration based on worker type and environment."""
+ # All workers use prefork as default (consistent with command-line args)
+ default_pool = "prefork"
+
+ pool_type = get_celery_setting("POOL_TYPE", self.worker_type, default_pool)
+ if pool_type == "threads":
+ config["worker_pool"] = "threads"
+ # prefork is Celery's default, so no need to set it explicitly
+
+ def _add_worker_scaling_configuration(self, config: dict[str, Any]) -> None:
+ """Add concurrency and autoscaling configuration."""
+ # Concurrency (fixed number of workers)
+ concurrency = get_celery_setting("CONCURRENCY", self.worker_type, None, int)
+ if concurrency is not None:
+ config["worker_concurrency"] = concurrency
+
+ # Autoscaling (dynamic worker count)
+ autoscale = get_celery_setting("AUTOSCALE", self.worker_type, None, tuple)
+ if autoscale is not None:
+ config["worker_autoscaler"] = "celery.worker.autoscale.Autoscaler"
+ config["worker_autoscale_max"] = autoscale[0]
+ config["worker_autoscale_min"] = autoscale[1]
+
+ def _add_chord_configuration(self, config: dict[str, Any]) -> None:
+ """Add chord-specific configuration only for workers that use chords."""
+ # Only workers that actually use chords need chord configuration
+ chord_workers = {
+ WorkerType.CALLBACK,
+ WorkerType.GENERAL,
+ WorkerType.API_DEPLOYMENT,
+ }
+
+ if self.worker_type in chord_workers:
+ # Chord retry interval - defaults to Celery standard (1 second)
+ config["result_chord_retry_interval"] = get_celery_setting(
+ "RESULT_CHORD_RETRY_INTERVAL", self.worker_type, 1, int
+ )
+
+ def to_cli_args(self) -> list[str]:
+ """Generate Celery worker CLI arguments.
+
+ Returns:
+ List of CLI arguments for celery worker command
+ """
+ args = [
+ "worker",
+ "--loglevel=info",
+ f"--queues={self.queue_config.to_cli_queues()}",
+ ]
+
+ if self.pool_type == "threads":
+ args.append("--pool=threads")
+
+ if self.concurrency:
+ args.append(f"--concurrency={self.concurrency}")
+
+ if self.autoscale:
+ args.append(f"--autoscale={self.autoscale[0]},{self.autoscale[1]}")
+
+ return args
+
+
+@dataclass
+class WorkerMigrationStatus:
+ """Track migration status of a worker."""
+
+ worker_type: WorkerType
+ migrated: bool = False
+ validated: bool = False
+ notes: str = ""
+
+ def __post_init__(self):
+ """Mark in worker file with __migrated__ flag."""
+ self.marker = f"__migrated__ = {self.migrated}"
diff --git a/workers/shared/patterns/__init__.py b/workers/shared/patterns/__init__.py
new file mode 100644
index 000000000..cdefb450e
--- /dev/null
+++ b/workers/shared/patterns/__init__.py
@@ -0,0 +1,19 @@
+"""Design patterns and utilities for workers.
+
+This package provides various design pattern implementations including
+factories, retry mechanisms, and notification patterns.
+"""
+
+from .notification import * # noqa: F403
+from .retry import * # noqa: F403
+
+__all__ = [
+ # Factory patterns - commented out to avoid circular imports
+ # "InternalAPIClientFactory",
+ # Retry patterns
+ "BackoffUtils",
+ "RetryUtils",
+ # Notification patterns
+ "helper",
+ "WorkerWebhookService",
+]
diff --git a/workers/shared/patterns/factory/__init__.py b/workers/shared/patterns/factory/__init__.py
new file mode 100644
index 000000000..ef61e95d1
--- /dev/null
+++ b/workers/shared/patterns/factory/__init__.py
@@ -0,0 +1,9 @@
+"""Factory patterns for workers.
+
+This package provides factory implementations following the Factory
+pattern for creating various worker components.
+"""
+
+from .client_factory import InternalAPIClientFactory
+
+__all__ = ["InternalAPIClientFactory"]
diff --git a/workers/shared/patterns/factory/client_factory.py b/workers/shared/patterns/factory/client_factory.py
new file mode 100644
index 000000000..419a494d8
--- /dev/null
+++ b/workers/shared/patterns/factory/client_factory.py
@@ -0,0 +1,199 @@
+"""API Client Factory for Performance-Optimized Client Creation
+
+This module provides a clean factory pattern for creating API clients with
+performance optimizations while maintaining readability and testability.
+"""
+
+from threading import Lock
+from typing import TypeVar
+
+from ...clients.base_client import BaseAPIClient
+from ...clients.execution_client import ExecutionAPIClient
+from ...clients.file_client import FileAPIClient
+from ...clients.organization_client import OrganizationAPIClient
+from ...clients.tool_client import ToolAPIClient
+from ...clients.webhook_client import WebhookAPIClient
+from ...infrastructure.config.worker_config import WorkerConfig
+from ...infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+ClientType = TypeVar("ClientType", bound=BaseAPIClient)
+
+
+class ClientFactory:
+ """Thread-safe factory for creating API clients with performance optimizations."""
+
+ # Class-level shared resources
+ _shared_base_client: BaseAPIClient | None = None
+ _client_lock = Lock()
+ _initialization_count = 0
+
+ # Client type registry
+ CLIENT_TYPES = {
+ "execution": ExecutionAPIClient,
+ "file": FileAPIClient,
+ "webhook": WebhookAPIClient,
+ "organization": OrganizationAPIClient,
+ "tool": ToolAPIClient,
+ }
+
+ def __init__(self, config: WorkerConfig):
+ """Initialize factory with worker configuration.
+
+ Args:
+ config: Worker configuration instance
+ """
+ self.config = config
+
+ def create_base_client(self) -> BaseAPIClient:
+ """Create or return shared base client using singleton pattern.
+
+ Returns:
+ BaseAPIClient instance (shared if singleton enabled)
+ """
+ if not self.config.enable_api_client_singleton:
+ return self._create_new_base_client()
+
+ with ClientFactory._client_lock:
+ if ClientFactory._shared_base_client is None:
+ if self.config.debug_api_client_init:
+ logger.info(
+ "Creating shared BaseAPIClient instance (singleton pattern)"
+ )
+ ClientFactory._shared_base_client = self._create_new_base_client()
+
+ ClientFactory._initialization_count += 1
+
+ if self.config.debug_api_client_init:
+ logger.info(
+ f"Reusing shared BaseAPIClient instance (#{ClientFactory._initialization_count})"
+ )
+
+ return ClientFactory._shared_base_client
+
+ def _create_new_base_client(self) -> BaseAPIClient:
+ """Create a new BaseAPIClient instance.
+
+ Returns:
+ New BaseAPIClient instance
+ """
+ return BaseAPIClient(self.config)
+
+ def create_specialized_client(
+ self, client_type: str, base_client: BaseAPIClient
+ ) -> BaseAPIClient:
+ """Create a specialized client with proper fallback handling.
+
+ Args:
+ client_type: Type of client to create ('execution', 'file', etc.)
+ base_client: Base client to potentially share configuration
+
+ Returns:
+ Specialized client instance
+
+ Raises:
+ ValueError: If client_type is not supported
+ """
+ if client_type not in self.CLIENT_TYPES:
+ raise ValueError(f"Unknown client type: {client_type}")
+
+ client_class = self.CLIENT_TYPES[client_type]
+
+ # Try to use from_base_client if available, otherwise fallback to config
+ if hasattr(client_class, "from_base_client") and callable(
+ client_class.from_base_client
+ ):
+ try:
+ return client_class.from_base_client(base_client)
+ except Exception as e:
+ logger.warning(
+ f"Failed to create {client_type} client from base client: {e}"
+ )
+ logger.info(
+ f"Falling back to config-based initialization for {client_type} client"
+ )
+
+ return client_class(self.config)
+
+ def create_all_clients(self) -> dict[str, BaseAPIClient]:
+ """Create all specialized clients using the factory pattern.
+
+ Returns:
+ Dictionary mapping client names to client instances
+ """
+ base_client = self.create_base_client()
+
+ clients = {"base": base_client}
+
+ for client_type in self.CLIENT_TYPES.keys():
+ try:
+ clients[client_type] = self.create_specialized_client(
+ client_type, base_client
+ )
+ except Exception as e:
+ logger.error(f"Failed to create {client_type} client: {e}")
+ # Continue with other clients even if one fails
+ continue
+
+ return clients
+
+ @classmethod
+ def reset_shared_state(cls) -> None:
+ """Reset shared state for testing purposes.
+
+ Warning:
+ This should only be used in tests or during graceful shutdown.
+ """
+ with cls._client_lock:
+ if cls._shared_base_client:
+ try:
+ cls._shared_base_client.close()
+ except Exception as e:
+ logger.warning(f"Error closing shared base client: {e}")
+
+ cls._shared_base_client = None
+ cls._initialization_count = 0
+ logger.debug("Client factory shared state reset")
+
+
+class CachingConfigurationMixin:
+ """Mixin for adding caching functionality to configuration clients."""
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self._cache: dict[str, any] = {}
+ self._cache_timestamps: dict[str, float] = {}
+ self._cache_lock = Lock()
+
+ def _get_cache_key(self, key: str, org_id: str | None = None) -> str:
+ """Generate cache key for configuration values."""
+ return f"{key}:{org_id or 'default'}"
+
+ def _is_cache_valid(self, cache_key: str, ttl: int = 300) -> bool:
+ """Check if cached value is still valid."""
+ import time
+
+ if cache_key not in self._cache_timestamps:
+ return False
+
+ return (time.time() - self._cache_timestamps[cache_key]) < ttl
+
+ def _get_from_cache(self, cache_key: str) -> any | None:
+ """Thread-safe cache retrieval."""
+ with self._cache_lock:
+ return self._cache.get(cache_key)
+
+ def _set_cache(self, cache_key: str, value: any) -> None:
+ """Thread-safe cache storage."""
+ import time
+
+ with self._cache_lock:
+ self._cache[cache_key] = value
+ self._cache_timestamps[cache_key] = time.time()
+
+ def _clear_cache(self) -> None:
+ """Clear all cached values."""
+ with self._cache_lock:
+ self._cache.clear()
+ self._cache_timestamps.clear()
diff --git a/workers/shared/patterns/notification/__init__.py b/workers/shared/patterns/notification/__init__.py
new file mode 100644
index 000000000..4e3c4a47a
--- /dev/null
+++ b/workers/shared/patterns/notification/__init__.py
@@ -0,0 +1,14 @@
+"""Notification patterns and services.
+
+This package provides notification functionality including webhook
+services and notification helpers.
+"""
+
+# Helper functions, no classes to import
+from . import helper
+from .webhook import WorkerWebhookService
+
+__all__ = [
+ "helper",
+ "WorkerWebhookService",
+]
diff --git a/workers/shared/patterns/notification/helper.py b/workers/shared/patterns/notification/helper.py
new file mode 100644
index 000000000..a56a6ade7
--- /dev/null
+++ b/workers/shared/patterns/notification/helper.py
@@ -0,0 +1,391 @@
+"""Lightweight notification helper for callback worker.
+
+Handles notification triggering integrated with status updates.
+No Django dependencies, works in pure worker environment.
+"""
+
+import logging
+
+from celery import current_app
+
+# Import shared data models from @unstract/core
+from unstract.core.data_models import (
+ ExecutionStatus,
+ NotificationPayload,
+ NotificationSource,
+ WorkflowType,
+)
+
+logger = logging.getLogger(__name__)
+
+
+def get_webhook_headers(
+ auth_type: str, auth_key: str | None, auth_header: str | None
+) -> dict[str, str]:
+ """Generate webhook headers based on authorization configuration."""
+ headers = {"Content-Type": "application/json"}
+
+ try:
+ if auth_type and auth_key:
+ auth_type_upper = auth_type.upper()
+
+ if auth_type_upper == "BEARER":
+ headers["Authorization"] = f"Bearer {auth_key}"
+ elif auth_type_upper == "API_KEY":
+ headers["Authorization"] = auth_key
+ elif auth_type_upper == "CUSTOM_HEADER" and auth_header:
+ headers[auth_header] = auth_key
+ # NONE type just uses Content-Type header
+ except Exception as e:
+ logger.warning(f"Error generating webhook headers: {e}")
+ # Use default headers if auth config is invalid
+
+ return headers
+
+
+def send_notification_to_worker(
+ url: str,
+ payload: NotificationPayload,
+ auth_type: str,
+ auth_key: str | None,
+ auth_header: str | None,
+ max_retries: int = 0,
+ platform: str | None = None,
+) -> bool:
+ """Send a single notification to the notification worker queue.
+
+ Args:
+ url: Webhook URL to send notification to
+ payload: Structured notification payload
+ auth_type: Authorization type (NONE, BEARER, API_KEY, CUSTOM_HEADER)
+ auth_key: Authorization key/token
+ auth_header: Custom header name for CUSTOM_HEADER auth type
+ max_retries: Maximum number of retry attempts
+ platform: Platform type from notification config (SLACK, API, etc.)
+
+ Returns:
+ True if task was successfully queued, False otherwise
+ """
+ try:
+ headers = get_webhook_headers(auth_type, auth_key, auth_header)
+
+ # Convert payload to webhook format (excludes internal fields)
+ payload_dict = payload.to_webhook_payload()
+
+ # Send task to notification worker
+ current_app.send_task(
+ "send_webhook_notification",
+ args=[
+ url,
+ payload_dict,
+ headers,
+ 10, # timeout
+ ],
+ kwargs={
+ "max_retries": max_retries,
+ "retry_delay": 10,
+ "platform": platform,
+ },
+ queue="notifications",
+ )
+
+ logger.info(
+ f"Sent webhook notification to worker queue for {url} (pipeline: {payload.pipeline_id})"
+ )
+ return True
+
+ except Exception as e:
+ logger.error(f"Failed to send notification to {url}: {e}")
+ return False
+
+
+def trigger_pipeline_notifications(
+ api_client,
+ pipeline_id: str,
+ pipeline_name: str,
+ pipeline_type: str,
+ status: str,
+ execution_id: str | None = None,
+ error_message: str | None = None,
+) -> None:
+ """Trigger notifications for pipeline status updates.
+
+ Called by callback worker after successful status update.
+ Uses API client to fetch notification configuration.
+ """
+ # Only send notifications for final states
+ try:
+ execution_status = ExecutionStatus(status)
+ except Exception as e:
+ logger.error(f"Error triggering pipeline notifications for {pipeline_id}: {e}")
+ return
+
+ try:
+ # Fetch pipeline notifications via API
+ response_data = api_client._make_request(
+ method="GET",
+ endpoint=f"v1/webhook/pipeline/{pipeline_id}/notifications/",
+ timeout=10,
+ )
+
+ # _make_request already handles status codes and returns parsed data
+ # If we get here, the request was successful (status 200)
+ notifications_data = response_data.get("notifications", [])
+ active_notifications = [
+ n for n in notifications_data if n.get("is_active", False)
+ ]
+
+ if not active_notifications:
+ logger.info(f"No active notifications found for pipeline {pipeline_id}")
+ return
+
+ # Convert pipeline type string to WorkflowType enum
+ if pipeline_type == "API":
+ workflow_type = WorkflowType.API
+ elif pipeline_type == "ETL":
+ workflow_type = WorkflowType.ETL
+ elif pipeline_type == "TASK":
+ workflow_type = WorkflowType.TASK
+ else:
+ workflow_type = WorkflowType.ETL # Default fallback
+
+ # Create notification payload using dataclass
+ payload = NotificationPayload.from_execution_status(
+ pipeline_id=pipeline_id,
+ pipeline_name=pipeline_name,
+ execution_status=execution_status,
+ workflow_type=workflow_type,
+ source=NotificationSource.CALLBACK_WORKER,
+ execution_id=execution_id,
+ error_message=error_message,
+ )
+
+ logger.info(
+ f"Sending {len(active_notifications)} notifications for pipeline {pipeline_name}"
+ )
+
+ # Send each notification
+ for notification in active_notifications:
+ if notification.get("notification_type") == "WEBHOOK":
+ send_notification_to_worker(
+ url=notification["url"],
+ payload=payload,
+ auth_type=notification.get("authorization_type", "NONE"),
+ auth_key=notification.get("authorization_key"),
+ auth_header=notification.get("authorization_header"),
+ max_retries=notification.get("max_retries", 0),
+ platform=notification.get("platform"),
+ )
+ else:
+ logger.debug(
+ f"Skipping non-webhook notification type: {notification.get('notification_type')}"
+ )
+
+ except Exception as e:
+ logger.error(f"Error triggering pipeline notifications for {pipeline_id}: {e}")
+
+
+def trigger_api_notifications(
+ api_client,
+ api_id: str,
+ api_name: str,
+ status: str,
+ execution_id: str | None = None,
+ error_message: str | None = None,
+) -> None:
+ """Trigger notifications for API deployment status updates.
+
+ Called by callback worker after successful API status update.
+ Uses API client to fetch notification configuration.
+ """
+ # Only send notifications for final states
+ try:
+ execution_status = ExecutionStatus(status)
+ except Exception as e:
+ logger.error(f"Error triggering API notifications for {api_id}: {e}")
+ return
+
+ try:
+ # Fetch API notifications via API
+ response_data = api_client._make_request(
+ method="GET", endpoint=f"v1/webhook/api/{api_id}/notifications/", timeout=10
+ )
+
+ # _make_request already handles status codes and returns parsed data
+ # If we get here, the request was successful (status 200)
+ notifications_data = response_data.get("notifications", [])
+ active_notifications = [
+ n for n in notifications_data if n.get("is_active", False)
+ ]
+
+ if not active_notifications:
+ logger.info(f"No active notifications found for API {api_id}")
+ return
+
+ # Create notification payload using dataclass
+ payload = NotificationPayload.from_execution_status(
+ pipeline_id=api_id,
+ pipeline_name=api_name,
+ execution_status=execution_status,
+ workflow_type=WorkflowType.API,
+ source=NotificationSource.CALLBACK_WORKER,
+ execution_id=execution_id,
+ error_message=error_message,
+ )
+
+ logger.info(
+ f"Sending {len(active_notifications)} notifications for API {api_name}"
+ )
+
+ # Send each notification
+ for notification in active_notifications:
+ if notification.get("notification_type") == "WEBHOOK":
+ send_notification_to_worker(
+ url=notification["url"],
+ payload=payload,
+ auth_type=notification.get("authorization_type", "NONE"),
+ auth_key=notification.get("authorization_key"),
+ auth_header=notification.get("authorization_header"),
+ max_retries=notification.get("max_retries", 0),
+ platform=notification.get("platform"),
+ )
+ else:
+ logger.debug(
+ f"Skipping non-webhook notification type: {notification.get('notification_type')}"
+ )
+
+ except Exception as e:
+ logger.error(f"Error triggering API notifications for {api_id}: {e}")
+
+
+def handle_status_notifications(
+ api_client,
+ pipeline_id: str,
+ status: str,
+ execution_id: str | None = None,
+ error_message: str | None = None,
+ pipeline_name: str | None = None,
+ pipeline_type: str | None = None,
+ organization_id: str | None = None,
+) -> None:
+ """Handle notifications for status updates.
+
+ Determines if this is a pipeline or API deployment and triggers appropriate notifications.
+ This is the main entry point called by callback worker.
+
+ Args:
+ api_client: API client for backend communication
+ pipeline_id: Pipeline or API deployment ID
+ status: Execution status (string)
+ execution_id: Optional execution ID
+ error_message: Optional error message for failed executions
+ pipeline_name: Optional pipeline/API name
+ pipeline_type: Optional workflow type (ETL, API, etc.)
+ organization_id: Optional organization context
+ """
+ try:
+ # Convert string status to ExecutionStatus enum
+ try:
+ execution_status = ExecutionStatus(status)
+ except ValueError:
+ logger.warning(
+ f"Unknown status '{status}', attempting to map to known statuses"
+ )
+ # Map common status variations
+ status_mapping = {
+ "SUCCESS": ExecutionStatus.COMPLETED,
+ "COMPLETED": ExecutionStatus.COMPLETED,
+ "FAILURE": ExecutionStatus.ERROR,
+ "FAILED": ExecutionStatus.ERROR,
+ "ERROR": ExecutionStatus.ERROR,
+ "STOPPED": ExecutionStatus.STOPPED,
+ }
+ execution_status = status_mapping.get(status.upper())
+ if not execution_status:
+ logger.error(f"Cannot map status '{status}' to ExecutionStatus enum")
+ return
+
+ # Only send notifications for final states
+ if not ExecutionStatus.is_completed(execution_status.value):
+ logger.debug(f"Skipping notifications for non-final status: {status}")
+ return
+
+ # Determine workflow type - default to API if not specified
+ workflow_type = WorkflowType.API
+ if pipeline_type:
+ try:
+ workflow_type = WorkflowType(pipeline_type.upper())
+ except ValueError:
+ logger.warning(
+ f"Unknown workflow type '{pipeline_type}', defaulting to API"
+ )
+
+ # Pipeline name MUST exist in models - no fallback allowed
+ if not pipeline_name:
+ logger.error(
+ f"Pipeline name is required but not provided for {workflow_type.value} {pipeline_id}"
+ )
+ logger.error(
+ "Pipeline names must come from Pipeline/APIDeployment models via workflow context"
+ )
+ return
+
+ logger.debug(f"Using {workflow_type.value} name from model: {pipeline_name}")
+
+ # Validate execution status for notifications
+ try:
+ # Just validate the status can be converted - we use separate functions below
+ NotificationPayload.from_execution_status(
+ pipeline_id=pipeline_id,
+ pipeline_name=pipeline_name,
+ execution_status=execution_status,
+ workflow_type=workflow_type,
+ source=NotificationSource.CALLBACK_WORKER,
+ execution_id=execution_id,
+ error_message=error_message,
+ organization_id=organization_id,
+ )
+ except ValueError as e:
+ logger.warning(f"Cannot create notification payload: {e}")
+ return
+
+ logger.info(
+ f"Processing notification for {workflow_type.value} {pipeline_id} with status {execution_status.value}"
+ )
+
+ # Use proper notification configuration lookup based on workflow type
+ try:
+ if workflow_type == WorkflowType.API:
+ trigger_api_notifications(
+ api_client=api_client,
+ api_id=pipeline_id,
+ api_name=pipeline_name,
+ status=status,
+ execution_id=execution_id,
+ error_message=error_message,
+ )
+ else:
+ # For ETL/TASK/other pipeline types
+ trigger_pipeline_notifications(
+ api_client=api_client,
+ pipeline_id=pipeline_id,
+ pipeline_name=pipeline_name,
+ pipeline_type=workflow_type.value,
+ status=status,
+ execution_id=execution_id,
+ error_message=error_message,
+ )
+
+ logger.info(
+ f"Notification sent successfully for {workflow_type.value} {pipeline_id}"
+ )
+ except Exception as notification_error:
+ logger.warning(
+ f"Failed to send notification for {workflow_type.value} {pipeline_id}: {notification_error}"
+ )
+
+ except Exception as e:
+ logger.error(f"Error handling status notifications for {pipeline_id}: {e}")
+ import traceback
+
+ traceback.print_exc()
diff --git a/workers/shared/patterns/notification/webhook.py b/workers/shared/patterns/notification/webhook.py
new file mode 100644
index 000000000..c7f26036c
--- /dev/null
+++ b/workers/shared/patterns/notification/webhook.py
@@ -0,0 +1,520 @@
+"""Worker-Native Webhook Service
+
+This module provides worker-native webhook operations without backend dependency.
+Handles all external HTTP requests within workers to eliminate backend load.
+"""
+
+import asyncio
+import json
+import time
+from typing import Any
+from urllib.parse import urlparse
+
+import httpx
+
+# Import worker infrastructure
+from ...infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WorkerWebhookService:
+ """Handle webhook operations within workers without backend dependency"""
+
+ DEFAULT_TIMEOUT = 30 # seconds
+ DEFAULT_MAX_ATTEMPTS = 3
+ DEFAULT_BACKOFF_FACTOR = 2.0
+
+ @staticmethod
+ def validate_webhook_url(webhook_url: str) -> dict[str, Any]:
+ """Validate webhook URL for security and accessibility.
+
+ Args:
+ webhook_url: URL to validate
+
+ Returns:
+ Dictionary with validation results
+ """
+ validation = {"is_valid": True, "errors": []}
+
+ try:
+ # Parse URL
+ parsed = urlparse(webhook_url)
+
+ # Check scheme
+ if parsed.scheme not in ["http", "https"]:
+ validation["is_valid"] = False
+ validation["errors"].append(
+ f"Invalid scheme: {parsed.scheme}. Only http/https allowed."
+ )
+
+ # Check hostname
+ if not parsed.hostname:
+ validation["is_valid"] = False
+ validation["errors"].append("Missing hostname in URL")
+
+ # Security checks - block localhost and internal IPs
+ if parsed.hostname in ["localhost", "127.0.0.1", "0.0.0.0"]:
+ validation["is_valid"] = False
+ validation["errors"].append("Localhost URLs not allowed for security")
+
+ # Block private IP ranges (basic check)
+ if parsed.hostname.startswith(("10.", "172.", "192.168.")):
+ validation["is_valid"] = False
+ validation["errors"].append("Private IP addresses not allowed")
+
+ except Exception as e:
+ validation["is_valid"] = False
+ validation["errors"].append(f"URL parsing failed: {str(e)}")
+
+ return validation
+
+ @staticmethod
+ async def send_webhook_async(
+ webhook_url: str,
+ payload: dict[str, Any],
+ organization_id: str,
+ retry_config: dict[str, Any] | None = None,
+ headers: dict[str, str] | None = None,
+ ) -> dict[str, Any]:
+ """Send webhook with worker-native retry logic (async version).
+
+ Args:
+ webhook_url: Webhook URL to send to
+ payload: JSON payload to send
+ organization_id: Organization ID for context
+ retry_config: Retry configuration (optional)
+ headers: Additional headers (optional)
+
+ Returns:
+ Dictionary with send results
+ """
+ # Validate webhook URL first
+ url_validation = WorkerWebhookService.validate_webhook_url(webhook_url)
+ if not url_validation["is_valid"]:
+ return {
+ "status": "failed",
+ "error": f"Invalid webhook URL: {url_validation['errors']}",
+ "attempts": 0,
+ }
+
+ # Configure retry parameters
+ retry_config = retry_config or {}
+ max_attempts = retry_config.get(
+ "max_attempts", WorkerWebhookService.DEFAULT_MAX_ATTEMPTS
+ )
+ backoff_factor = retry_config.get(
+ "backoff_factor", WorkerWebhookService.DEFAULT_BACKOFF_FACTOR
+ )
+ timeout = retry_config.get("timeout", WorkerWebhookService.DEFAULT_TIMEOUT)
+
+ # Prepare headers
+ request_headers = {
+ "Content-Type": "application/json",
+ "User-Agent": "Unstract-Worker/1.0",
+ "X-Organization-ID": organization_id,
+ "X-Timestamp": str(int(time.time())),
+ }
+
+ if headers:
+ request_headers.update(headers)
+
+ logger.info(f"Sending webhook to {webhook_url} for org {organization_id}")
+
+ # Attempt webhook delivery with retries
+ async with httpx.AsyncClient(timeout=timeout, follow_redirects=True) as client:
+ for attempt in range(max_attempts):
+ attempt_start = time.time()
+
+ try:
+ logger.debug(
+ f"Webhook attempt {attempt + 1}/{max_attempts} to {webhook_url}"
+ )
+
+ response = await client.post(
+ webhook_url, json=payload, headers=request_headers
+ )
+
+ response_time = int((time.time() - attempt_start) * 1000)
+
+ # Check if request was successful
+ response.raise_for_status()
+
+ # Try to parse response JSON
+ try:
+ response_data = response.json() if response.content else None
+ except json.JSONDecodeError:
+ response_data = response.text if response.content else None
+
+ result = {
+ "status": "success",
+ "response_status": response.status_code,
+ "response_data": response_data,
+ "response_headers": dict(response.headers),
+ "response_time_ms": response_time,
+ "attempt": attempt + 1,
+ "url": webhook_url,
+ }
+
+ logger.info(
+ f"Webhook delivered successfully to {webhook_url} (attempt {attempt + 1}, {response_time}ms)"
+ )
+ return result
+
+ except httpx.HTTPStatusError as e:
+ error_msg = f"HTTP error {e.response.status_code}: {e.response.text}"
+ logger.warning(
+ f"Webhook attempt {attempt + 1} HTTP error: {error_msg}"
+ )
+
+ # Don't retry on client errors (4xx)
+ if 400 <= e.response.status_code < 500:
+ return {
+ "status": "failed",
+ "error": error_msg,
+ "response_status": e.response.status_code,
+ "attempts": attempt + 1,
+ "url": webhook_url,
+ }
+
+ except (httpx.RequestError, httpx.TimeoutException) as e:
+ error_msg = f"Request error: {str(e)}"
+ logger.warning(f"Webhook attempt {attempt + 1} failed: {error_msg}")
+
+ except Exception as e:
+ error_msg = f"Unexpected error: {str(e)}"
+ logger.error(
+ f"Webhook attempt {attempt + 1} unexpected error: {error_msg}"
+ )
+
+ # If this was the last attempt, return failure
+ if attempt == max_attempts - 1:
+ return {
+ "status": "failed",
+ "error": error_msg,
+ "attempts": max_attempts,
+ "url": webhook_url,
+ }
+
+ # Wait before retry with exponential backoff
+ wait_time = backoff_factor**attempt
+ logger.debug(f"Waiting {wait_time}s before retry")
+ await asyncio.sleep(wait_time)
+
+ @staticmethod
+ def send_webhook(
+ webhook_url: str,
+ payload: dict[str, Any],
+ organization_id: str,
+ retry_config: dict[str, Any] | None = None,
+ headers: dict[str, str] | None = None,
+ ) -> dict[str, Any]:
+ """Send webhook with worker-native retry logic (synchronous wrapper).
+
+ Args:
+ webhook_url: Webhook URL to send to
+ payload: JSON payload to send
+ organization_id: Organization ID for context
+ retry_config: Retry configuration (optional)
+ headers: Additional headers (optional)
+
+ Returns:
+ Dictionary with send results
+ """
+ try:
+ # Run async webhook in event loop
+ return asyncio.run(
+ WorkerWebhookService.send_webhook_async(
+ webhook_url=webhook_url,
+ payload=payload,
+ organization_id=organization_id,
+ retry_config=retry_config,
+ headers=headers,
+ )
+ )
+ except Exception as e:
+ logger.error(f"Failed to send webhook to {webhook_url}: {str(e)}")
+ return {
+ "status": "failed",
+ "error": f"Webhook execution failed: {str(e)}",
+ "attempts": 0,
+ "url": webhook_url,
+ }
+
+ @staticmethod
+ async def send_webhooks_batch(
+ webhooks: list[dict[str, Any]], organization_id: str, max_concurrent: int = 5
+ ) -> list[dict[str, Any]]:
+ """Send multiple webhooks concurrently.
+
+ Args:
+ webhooks: List of webhook configurations
+ organization_id: Organization ID for context
+ max_concurrent: Maximum concurrent webhook sends
+
+ Returns:
+ List of webhook send results
+ """
+ logger.info(
+ f"Sending {len(webhooks)} webhooks concurrently (max {max_concurrent})"
+ )
+
+ semaphore = asyncio.Semaphore(max_concurrent)
+
+ async def send_single_webhook(webhook_config: dict[str, Any]) -> dict[str, Any]:
+ async with semaphore:
+ return await WorkerWebhookService.send_webhook_async(
+ webhook_url=webhook_config["url"],
+ payload=webhook_config["payload"],
+ organization_id=organization_id,
+ retry_config=webhook_config.get("retry_config"),
+ headers=webhook_config.get("headers"),
+ )
+
+ # Execute all webhooks concurrently
+ tasks = [send_single_webhook(webhook) for webhook in webhooks]
+ results = await asyncio.gather(*tasks, return_exceptions=True)
+
+ # Process results
+ processed_results = []
+ for i, result in enumerate(results):
+ if isinstance(result, Exception):
+ processed_results.append(
+ {
+ "status": "failed",
+ "error": f"Exception during webhook send: {str(result)}",
+ "url": webhooks[i].get("url", "unknown"),
+ "attempts": 0,
+ }
+ )
+ else:
+ processed_results.append(result)
+
+ success_count = sum(1 for r in processed_results if r.get("status") == "success")
+ logger.info(f"Batch webhook results: {success_count}/{len(webhooks)} successful")
+
+ return processed_results
+
+ @staticmethod
+ def create_webhook_payload(
+ event_type: str,
+ execution_id: str,
+ workflow_id: str,
+ organization_id: str,
+ data: dict[str, Any],
+ metadata: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Create standardized webhook payload.
+
+ Args:
+ event_type: Type of event (e.g., 'workflow.completed')
+ execution_id: Execution ID
+ workflow_id: Workflow ID
+ organization_id: Organization ID
+ data: Event-specific data
+ metadata: Additional metadata (optional)
+
+ Returns:
+ Standardized webhook payload
+ """
+ payload = {
+ "event_type": event_type,
+ "timestamp": int(time.time()),
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "organization_id": organization_id,
+ "data": data,
+ "metadata": metadata or {},
+ "version": "1.0",
+ }
+
+ logger.debug(f"Created webhook payload for event {event_type}")
+ return payload
+
+ @staticmethod
+ def test_webhook_connectivity(
+ webhook_url: str, organization_id: str, timeout: int = 10
+ ) -> dict[str, Any]:
+ """Test webhook connectivity without sending actual data.
+
+ Args:
+ webhook_url: Webhook URL to test
+ organization_id: Organization ID for context
+ timeout: Timeout in seconds
+
+ Returns:
+ Dictionary with connectivity test results
+ """
+ logger.info(f"Testing webhook connectivity to {webhook_url}")
+
+ # Validate URL first
+ url_validation = WorkerWebhookService.validate_webhook_url(webhook_url)
+ if not url_validation["is_valid"]:
+ return {
+ "is_reachable": False,
+ "errors": url_validation["errors"],
+ "response_time_ms": None,
+ }
+
+ test_payload = {
+ "event_type": "test.connectivity",
+ "timestamp": int(time.time()),
+ "organization_id": organization_id,
+ "test": True,
+ }
+
+ try:
+ result = asyncio.run(
+ WorkerWebhookService.send_webhook_async(
+ webhook_url=webhook_url,
+ payload=test_payload,
+ organization_id=organization_id,
+ retry_config={"max_attempts": 1, "timeout": timeout},
+ )
+ )
+
+ return {
+ "is_reachable": result["status"] == "success",
+ "response_status": result.get("response_status"),
+ "response_time_ms": result.get("response_time_ms"),
+ "errors": [] if result["status"] == "success" else [result.get("error")],
+ }
+
+ except Exception as e:
+ return {
+ "is_reachable": False,
+ "errors": [f"Connectivity test failed: {str(e)}"],
+ "response_time_ms": None,
+ }
+
+
+class WorkerWebhookEventPublisher:
+ """Publish workflow events via webhooks using worker-native operations"""
+
+ def __init__(self, organization_id: str):
+ """Initialize webhook event publisher.
+
+ Args:
+ organization_id: Organization ID for context
+ """
+ self.organization_id = organization_id
+ self.webhook_service = WorkerWebhookService()
+
+ def publish_workflow_started(
+ self,
+ execution_id: str,
+ workflow_id: str,
+ webhook_urls: list[str],
+ total_files: int = 0,
+ ) -> list[dict[str, Any]]:
+ """Publish workflow started event.
+
+ Args:
+ execution_id: Execution ID
+ workflow_id: Workflow ID
+ webhook_urls: List of webhook URLs to notify
+ total_files: Total number of files to process
+
+ Returns:
+ List of webhook send results
+ """
+ payload = self.webhook_service.create_webhook_payload(
+ event_type="workflow.started",
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=self.organization_id,
+ data={"total_files": total_files, "status": "EXECUTING"},
+ )
+
+ return self._send_to_multiple_webhooks(webhook_urls, payload)
+
+ def publish_workflow_completed(
+ self,
+ execution_id: str,
+ workflow_id: str,
+ webhook_urls: list[str],
+ execution_results: dict[str, Any],
+ ) -> list[dict[str, Any]]:
+ """Publish workflow completed event.
+
+ Args:
+ execution_id: Execution ID
+ workflow_id: Workflow ID
+ webhook_urls: List of webhook URLs to notify
+ execution_results: Workflow execution results
+
+ Returns:
+ List of webhook send results
+ """
+ payload = self.webhook_service.create_webhook_payload(
+ event_type="workflow.completed",
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=self.organization_id,
+ data={"status": "COMPLETED", "results": execution_results},
+ )
+
+ return self._send_to_multiple_webhooks(webhook_urls, payload)
+
+ def publish_workflow_failed(
+ self,
+ execution_id: str,
+ workflow_id: str,
+ webhook_urls: list[str],
+ error_details: dict[str, Any],
+ ) -> list[dict[str, Any]]:
+ """Publish workflow failed event.
+
+ Args:
+ execution_id: Execution ID
+ workflow_id: Workflow ID
+ webhook_urls: List of webhook URLs to notify
+ error_details: Error details
+
+ Returns:
+ List of webhook send results
+ """
+ payload = self.webhook_service.create_webhook_payload(
+ event_type="workflow.failed",
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ organization_id=self.organization_id,
+ data={"status": "ERROR", "error": error_details},
+ )
+
+ return self._send_to_multiple_webhooks(webhook_urls, payload)
+
+ def _send_to_multiple_webhooks(
+ self, webhook_urls: list[str], payload: dict[str, Any]
+ ) -> list[dict[str, Any]]:
+ """Send payload to multiple webhook URLs.
+
+ Args:
+ webhook_urls: List of webhook URLs
+ payload: Payload to send
+
+ Returns:
+ List of send results
+ """
+ if not webhook_urls:
+ return []
+
+ webhooks = [{"url": url, "payload": payload} for url in webhook_urls]
+
+ try:
+ return asyncio.run(
+ self.webhook_service.send_webhooks_batch(
+ webhooks=webhooks, organization_id=self.organization_id
+ )
+ )
+ except Exception as e:
+ logger.error(f"Failed to send batch webhooks: {str(e)}")
+ return [
+ {
+ "status": "failed",
+ "error": f"Batch send failed: {str(e)}",
+ "url": url,
+ "attempts": 0,
+ }
+ for url in webhook_urls
+ ]
diff --git a/workers/shared/patterns/retry/__init__.py b/workers/shared/patterns/retry/__init__.py
new file mode 100644
index 000000000..961422055
--- /dev/null
+++ b/workers/shared/patterns/retry/__init__.py
@@ -0,0 +1,15 @@
+"""Retry patterns and utilities.
+
+This package provides retry mechanisms including backoff strategies
+and retry utilities following the Single Responsibility Principle.
+"""
+
+from .backoff import ExponentialBackoff as BackoffUtils
+from .utils import CircuitBreakerOpenError, circuit_breaker, retry
+
+__all__ = [
+ "BackoffUtils",
+ "circuit_breaker",
+ "CircuitBreakerOpenError",
+ "retry",
+]
diff --git a/workers/shared/patterns/retry/backoff.py b/workers/shared/patterns/retry/backoff.py
new file mode 100644
index 000000000..9bcea0825
--- /dev/null
+++ b/workers/shared/patterns/retry/backoff.py
@@ -0,0 +1,451 @@
+"""Exponential Backoff Utilities for Workers
+
+Provides smart retry logic with exponential backoff and circuit breaker patterns
+to reduce database load and improve resilience.
+"""
+
+import logging
+import random
+import time
+from collections.abc import Callable
+from functools import wraps
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+class ExponentialBackoff:
+ """Exponential backoff calculator with jitter and maximum delay."""
+
+ def __init__(
+ self,
+ base_delay: float = 1.0,
+ max_delay: float = 300.0,
+ backoff_factor: float = 2.0,
+ jitter: bool = True,
+ max_attempts: int = 10,
+ ):
+ """Initialize exponential backoff calculator.
+
+ Args:
+ base_delay: Base delay in seconds
+ max_delay: Maximum delay in seconds
+ backoff_factor: Multiplier for each retry
+ jitter: Whether to add random jitter to delays
+ max_attempts: Maximum number of attempts before giving up
+ """
+ self.base_delay = base_delay
+ self.max_delay = max_delay
+ self.backoff_factor = backoff_factor
+ self.jitter = jitter
+ self.max_attempts = max_attempts
+
+ def calculate_delay(self, attempt: int) -> float:
+ """Calculate delay for given attempt number.
+
+ Args:
+ attempt: Attempt number (1-based)
+
+ Returns:
+ Delay in seconds
+ """
+ if attempt <= 0:
+ return 0.0
+
+ # Calculate exponential delay
+ delay = self.base_delay * (self.backoff_factor ** (attempt - 1))
+
+ # Apply maximum delay limit
+ delay = min(delay, self.max_delay)
+
+ # Add jitter to prevent thundering herd
+ if self.jitter:
+ jitter_range = delay * 0.1 # 10% jitter
+ jitter = random.uniform(-jitter_range, jitter_range)
+ delay = max(0.1, delay + jitter) # Minimum 0.1 second delay
+
+ logger.debug(f"Attempt {attempt}: calculated delay {delay:.2f}s")
+ return delay
+
+ def should_retry(self, attempt: int) -> bool:
+ """Check if should retry for given attempt number.
+
+ Args:
+ attempt: Attempt number (1-based)
+
+ Returns:
+ True if should retry, False otherwise
+ """
+ return attempt <= self.max_attempts
+
+
+class CallbackBackoffManager:
+ """Manages exponential backoff specifically for callback pattern optimization."""
+
+ def __init__(self, cache_manager=None):
+ """Initialize callback backoff manager.
+
+ Args:
+ cache_manager: Optional cache manager for persistent attempt tracking
+ """
+ self.cache_manager = cache_manager
+ self.backoff_configs = {
+ "status_check": ExponentialBackoff(
+ base_delay=2.0, max_delay=60.0, backoff_factor=1.5, max_attempts=8
+ ),
+ "pipeline_update": ExponentialBackoff(
+ base_delay=1.0, max_delay=30.0, backoff_factor=2.0, max_attempts=5
+ ),
+ "database_operation": ExponentialBackoff(
+ base_delay=0.5, max_delay=10.0, backoff_factor=2.0, max_attempts=6
+ ),
+ "api_call": ExponentialBackoff(
+ base_delay=1.0, max_delay=45.0, backoff_factor=1.8, max_attempts=7
+ ),
+ }
+
+ def get_delay(
+ self, operation_type: str, execution_id: str, organization_id: str = None
+ ) -> float:
+ """Get backoff delay for specific operation and execution.
+
+ Args:
+ operation_type: Type of operation (status_check, pipeline_update, etc.)
+ execution_id: Execution ID for tracking attempts
+ organization_id: Organization context
+
+ Returns:
+ Delay in seconds
+ """
+ if operation_type not in self.backoff_configs:
+ logger.warning(
+ f"Unknown operation type: {operation_type}, using default backoff"
+ )
+ operation_type = "api_call"
+
+ backoff = self.backoff_configs[operation_type]
+
+ # Get attempt count from cache if available
+ attempt_count = 1
+ if self.cache_manager and self.cache_manager.is_available:
+ try:
+ cache_key = f"backoff_attempts:{operation_type}:{organization_id or 'global'}:{execution_id}"
+ attempt_count = self.cache_manager._redis_client.incr(cache_key)
+
+ # Set expiration on first increment (operation-specific TTL)
+ if attempt_count == 1:
+ ttl = 3600 if operation_type == "status_check" else 1800
+ self.cache_manager._redis_client.expire(cache_key, ttl)
+ except Exception as e:
+ logger.warning(f"Failed to track backoff attempts: {e}")
+ attempt_count = 1
+
+ return backoff.calculate_delay(attempt_count)
+
+ def should_retry(
+ self, operation_type: str, execution_id: str, organization_id: str = None
+ ) -> bool:
+ """Check if operation should be retried.
+
+ Args:
+ operation_type: Type of operation
+ execution_id: Execution ID
+ organization_id: Organization context
+
+ Returns:
+ True if should retry
+ """
+ if operation_type not in self.backoff_configs:
+ return True
+
+ backoff = self.backoff_configs[operation_type]
+
+ # Get current attempt count
+ attempt_count = 1
+ if self.cache_manager and self.cache_manager.is_available:
+ try:
+ cache_key = f"backoff_attempts:{operation_type}:{organization_id or 'global'}:{execution_id}"
+ attempt_count = int(self.cache_manager._redis_client.get(cache_key) or 1)
+ except Exception:
+ pass
+
+ should_retry = backoff.should_retry(attempt_count)
+ logger.debug(
+ f"Operation {operation_type} attempt {attempt_count}: should_retry={should_retry}"
+ )
+ return should_retry
+
+ def clear_attempts(
+ self, operation_type: str, execution_id: str, organization_id: str = None
+ ):
+ """Clear attempt counter after successful operation.
+
+ Args:
+ operation_type: Type of operation
+ execution_id: Execution ID
+ organization_id: Organization context
+ """
+ if not self.cache_manager or not self.cache_manager.is_available:
+ return
+
+ try:
+ cache_key = f"backoff_attempts:{operation_type}:{organization_id or 'global'}:{execution_id}"
+ self.cache_manager._redis_client.delete(cache_key)
+ logger.debug(f"Cleared backoff attempts for {operation_type}:{execution_id}")
+ except Exception as e:
+ logger.warning(f"Failed to clear backoff attempts: {e}")
+
+
+def with_exponential_backoff(
+ operation_type: str = "api_call",
+ max_attempts: int = 5,
+ base_delay: float = 1.0,
+ max_delay: float = 60.0,
+ backoff_factor: float = 2.0,
+ exceptions: tuple = (Exception,),
+ give_up_on: tuple = (),
+):
+ """Decorator for adding exponential backoff to functions.
+
+ Args:
+ operation_type: Type of operation for backoff configuration
+ max_attempts: Maximum retry attempts
+ base_delay: Base delay in seconds
+ max_delay: Maximum delay in seconds
+ backoff_factor: Exponential backoff factor
+ exceptions: Exception types that trigger retry
+ give_up_on: Exception types that should not retry
+ """
+
+ def decorator(func: Callable) -> Callable:
+ @wraps(func)
+ def wrapper(*args, **kwargs) -> Any:
+ backoff = ExponentialBackoff(
+ base_delay=base_delay,
+ max_delay=max_delay,
+ backoff_factor=backoff_factor,
+ max_attempts=max_attempts,
+ )
+
+ last_exception = None
+
+ for attempt in range(1, max_attempts + 1):
+ try:
+ result = func(*args, **kwargs)
+
+ # Success - log if this was a retry
+ if attempt > 1:
+ logger.info(
+ f"Function {func.__name__} succeeded on attempt {attempt}"
+ )
+
+ return result
+
+ except give_up_on as e:
+ # Don't retry for these exceptions
+ logger.error(
+ f"Function {func.__name__} failed with non-retryable error: {e}"
+ )
+ raise
+
+ except exceptions as e:
+ last_exception = e
+
+ if attempt == max_attempts:
+ logger.error(
+ f"Function {func.__name__} failed after {max_attempts} attempts: {e}"
+ )
+ raise
+
+ delay = backoff.calculate_delay(attempt)
+ logger.warning(
+ f"Function {func.__name__} failed on attempt {attempt}/{max_attempts}: {e}. "
+ f"Retrying in {delay:.2f}s"
+ )
+
+ time.sleep(delay)
+
+ # This should never be reached, but just in case
+ if last_exception:
+ raise last_exception
+
+ return wrapper
+
+ return decorator
+
+
+class SmartRetryManager:
+ """Advanced retry manager with circuit breaker and adaptive backoff."""
+
+ def __init__(self, cache_manager=None):
+ """Initialize smart retry manager.
+
+ Args:
+ cache_manager: Cache manager for persistent state
+ """
+ self.cache_manager = cache_manager
+ self.circuit_breakers = {}
+
+ def execute_with_smart_retry(
+ self,
+ func: Callable,
+ operation_id: str,
+ args: tuple = (),
+ kwargs: dict = None,
+ max_attempts: int = 5,
+ circuit_breaker: bool = True,
+ **backoff_kwargs,
+ ) -> Any:
+ """Execute function with smart retry logic.
+
+ Args:
+ func: Function to execute
+ operation_id: Unique operation identifier
+ args: Function arguments
+ kwargs: Function keyword arguments
+ max_attempts: Maximum retry attempts
+ circuit_breaker: Whether to use circuit breaker
+ **backoff_kwargs: Backoff configuration
+
+ Returns:
+ Function result
+
+ Raises:
+ Exception: If all retries fail or circuit breaker is open
+ """
+ kwargs = kwargs or {}
+
+ # Check circuit breaker
+ if circuit_breaker and self._is_circuit_open(operation_id):
+ raise Exception(f"Circuit breaker open for operation: {operation_id}")
+
+ backoff = ExponentialBackoff(max_attempts=max_attempts, **backoff_kwargs)
+
+ last_exception = None
+ consecutive_failures = 0
+
+ for attempt in range(1, max_attempts + 1):
+ try:
+ result = func(*args, **kwargs)
+
+ # Success - reset circuit breaker
+ if circuit_breaker:
+ self._reset_circuit_breaker(operation_id)
+
+ if attempt > 1:
+ logger.info(
+ f"Operation {operation_id} succeeded on attempt {attempt}"
+ )
+
+ return result
+
+ except Exception as e:
+ last_exception = e
+ consecutive_failures += 1
+
+ # Update circuit breaker
+ if circuit_breaker:
+ self._record_failure(operation_id)
+
+ if attempt == max_attempts:
+ logger.error(
+ f"Operation {operation_id} failed after {max_attempts} attempts: {e}"
+ )
+ break
+
+ delay = backoff.calculate_delay(attempt)
+ logger.warning(
+ f"Operation {operation_id} failed on attempt {attempt}/{max_attempts}: {e}. "
+ f"Retrying in {delay:.2f}s"
+ )
+
+ time.sleep(delay)
+
+ # All attempts failed
+ if circuit_breaker and consecutive_failures >= 3:
+ self._open_circuit_breaker(operation_id)
+
+ if last_exception:
+ raise last_exception
+
+ def _is_circuit_open(self, operation_id: str) -> bool:
+ """Check if circuit breaker is open for operation."""
+ if not self.cache_manager or not self.cache_manager.is_available:
+ return False
+
+ try:
+ cache_key = f"circuit_breaker:{operation_id}"
+ state = self.cache_manager._redis_client.get(cache_key)
+ return state == "open"
+ except Exception:
+ return False
+
+ def _open_circuit_breaker(self, operation_id: str, timeout: int = 300):
+ """Open circuit breaker for operation."""
+ if not self.cache_manager or not self.cache_manager.is_available:
+ return
+
+ try:
+ cache_key = f"circuit_breaker:{operation_id}"
+ self.cache_manager._redis_client.setex(cache_key, timeout, "open")
+ logger.warning(f"Opened circuit breaker for operation: {operation_id}")
+ except Exception as e:
+ logger.warning(f"Failed to open circuit breaker: {e}")
+
+ def _reset_circuit_breaker(self, operation_id: str):
+ """Reset circuit breaker after successful operation."""
+ if not self.cache_manager or not self.cache_manager.is_available:
+ return
+
+ try:
+ cache_key = f"circuit_breaker:{operation_id}"
+ self.cache_manager._redis_client.delete(cache_key)
+
+ # Also clear failure count
+ failure_key = f"circuit_failures:{operation_id}"
+ self.cache_manager._redis_client.delete(failure_key)
+ except Exception:
+ pass
+
+ def _record_failure(self, operation_id: str):
+ """Record failure for circuit breaker calculation."""
+ if not self.cache_manager or not self.cache_manager.is_available:
+ return
+
+ try:
+ failure_key = f"circuit_failures:{operation_id}"
+ failures = self.cache_manager._redis_client.incr(failure_key)
+
+ # Set expiration on first failure
+ if failures == 1:
+ self.cache_manager._redis_client.expire(failure_key, 600) # 10 minutes
+
+ # Open circuit after 5 failures in 10 minutes
+ if failures >= 5:
+ self._open_circuit_breaker(operation_id, timeout=600)
+
+ except Exception:
+ pass
+
+
+# Global instances
+_backoff_manager = None
+_retry_manager = None
+
+
+def get_backoff_manager() -> CallbackBackoffManager | None:
+ """Get global backoff manager instance."""
+ return _backoff_manager
+
+
+def get_retry_manager() -> SmartRetryManager | None:
+ """Get global retry manager instance."""
+ return _retry_manager
+
+
+def initialize_backoff_managers(cache_manager=None):
+ """Initialize global backoff and retry managers."""
+ global _backoff_manager, _retry_manager
+ _backoff_manager = CallbackBackoffManager(cache_manager)
+ _retry_manager = SmartRetryManager(cache_manager)
+ return _backoff_manager, _retry_manager
diff --git a/workers/shared/patterns/retry/utils.py b/workers/shared/patterns/retry/utils.py
new file mode 100644
index 000000000..c0862569e
--- /dev/null
+++ b/workers/shared/patterns/retry/utils.py
@@ -0,0 +1,406 @@
+"""Retry Logic and Circuit Breaker Implementation
+
+Provides robust retry mechanisms and circuit breaker patterns for worker operations.
+"""
+
+import functools
+import random
+import time
+from collections.abc import Callable
+from dataclasses import dataclass
+from enum import Enum
+from threading import Lock
+from typing import Any
+
+from ...infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class CircuitBreakerState(Enum):
+ """Circuit breaker states."""
+
+ CLOSED = "closed" # Normal operation
+ OPEN = "open" # Failing, rejecting calls
+ HALF_OPEN = "half_open" # Testing if service recovered
+
+
+@dataclass
+class RetryConfig:
+ """Configuration for retry behavior."""
+
+ max_attempts: int = 3
+ base_delay: float = 1.0
+ max_delay: float = 60.0
+ exponential_base: float = 2.0
+ jitter: bool = True
+ backoff_strategy: str = "exponential" # 'exponential', 'linear', 'fixed'
+ retryable_exceptions: tuple[type[Exception], ...] = (Exception,)
+
+
+class RetryHandler:
+ """Configurable retry handler with multiple backoff strategies.
+
+ Supports:
+ - Exponential backoff with jitter
+ - Linear backoff
+ - Fixed delay
+ - Custom exception filtering
+ - Retry attempt logging
+ """
+
+ def __init__(self, config: RetryConfig | None = None):
+ """Initialize retry handler.
+
+ Args:
+ config: Retry configuration. Uses defaults if None.
+ """
+ self.config = config or RetryConfig()
+
+ def __call__(self, func: Callable) -> Callable:
+ """Decorator to add retry logic to a function."""
+
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ return self.execute_with_retry(func, *args, **kwargs)
+
+ return wrapper
+
+ def execute_with_retry(self, func: Callable, *args, **kwargs) -> Any:
+ """Execute function with retry logic.
+
+ Args:
+ func: Function to execute
+ *args: Function arguments
+ **kwargs: Function keyword arguments
+
+ Returns:
+ Function result
+
+ Raises:
+ Last exception if all retries failed
+ """
+ last_exception = None
+
+ for attempt in range(1, self.config.max_attempts + 1):
+ try:
+ logger.debug(
+ f"Executing {func.__name__}, attempt {attempt}/{self.config.max_attempts}"
+ )
+ result = func(*args, **kwargs)
+
+ if attempt > 1:
+ logger.info(
+ f"Function {func.__name__} succeeded on attempt {attempt}"
+ )
+
+ return result
+
+ except Exception as e:
+ last_exception = e
+
+ # Check if exception is retryable
+ if not isinstance(e, self.config.retryable_exceptions):
+ logger.warning(f"Non-retryable exception in {func.__name__}: {e}")
+ raise
+
+ # Don't retry on last attempt
+ if attempt == self.config.max_attempts:
+ logger.error(
+ f"Function {func.__name__} failed after {attempt} attempts: {e}"
+ )
+ break
+
+ # Calculate delay
+ delay = self._calculate_delay(attempt)
+ logger.warning(
+ f"Function {func.__name__} failed on attempt {attempt}: {e}. Retrying in {delay:.2f}s"
+ )
+
+ time.sleep(delay)
+
+ # All retries exhausted
+ raise last_exception
+
+ def _calculate_delay(self, attempt: int) -> float:
+ """Calculate delay for retry attempt."""
+ if self.config.backoff_strategy == "exponential":
+ delay = self.config.base_delay * (
+ self.config.exponential_base ** (attempt - 1)
+ )
+ elif self.config.backoff_strategy == "linear":
+ delay = self.config.base_delay * attempt
+ else: # fixed
+ delay = self.config.base_delay
+
+ # Apply maximum delay limit
+ delay = min(delay, self.config.max_delay)
+
+ # Add jitter to prevent thundering herd
+ if self.config.jitter:
+ delay *= 0.5 + random.random() * 0.5 # 50-100% of calculated delay
+
+ return delay
+
+
+@dataclass
+class CircuitBreakerConfig:
+ """Configuration for circuit breaker."""
+
+ failure_threshold: int = 5
+ recovery_timeout: float = 60.0
+ expected_exception: type[Exception] = Exception
+ success_threshold: int = 3 # Successes needed to close circuit in half-open state
+
+
+class CircuitBreaker:
+ """Circuit breaker implementation to prevent cascading failures.
+
+ States:
+ - CLOSED: Normal operation, counting failures
+ - OPEN: Rejecting calls, waiting for recovery timeout
+ - HALF_OPEN: Testing if service recovered
+ """
+
+ def __init__(self, config: CircuitBreakerConfig | None = None):
+ """Initialize circuit breaker.
+
+ Args:
+ config: Circuit breaker configuration. Uses defaults if None.
+ """
+ self.config = config or CircuitBreakerConfig()
+ self.state = CircuitBreakerState.CLOSED
+ self.failure_count = 0
+ self.success_count = 0
+ self.last_failure_time = 0
+ self._lock = Lock()
+
+ def __call__(self, func: Callable) -> Callable:
+ """Decorator to add circuit breaker to a function."""
+
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ return self.call(func, *args, **kwargs)
+
+ return wrapper
+
+ def call(self, func: Callable, *args, **kwargs) -> Any:
+ """Execute function with circuit breaker protection.
+
+ Args:
+ func: Function to execute
+ *args: Function arguments
+ **kwargs: Function keyword arguments
+
+ Returns:
+ Function result
+
+ Raises:
+ CircuitBreakerOpenError: If circuit is open
+ Original exception: If function fails
+ """
+ with self._lock:
+ current_state = self.state
+
+ # Check if circuit should transition to half-open
+ if current_state == CircuitBreakerState.OPEN:
+ if time.time() - self.last_failure_time >= self.config.recovery_timeout:
+ self.state = CircuitBreakerState.HALF_OPEN
+ self.success_count = 0
+ logger.info("Circuit breaker transitioning to HALF_OPEN")
+ current_state = CircuitBreakerState.HALF_OPEN
+ else:
+ raise CircuitBreakerOpenError(
+ f"Circuit breaker is OPEN. Recovery timeout: {self.config.recovery_timeout}s"
+ )
+
+ try:
+ # Execute function
+ logger.debug(
+ f"Executing {func.__name__} with circuit breaker in {current_state.value} state"
+ )
+ result = func(*args, **kwargs)
+
+ # Handle success
+ with self._lock:
+ if self.state == CircuitBreakerState.HALF_OPEN:
+ self.success_count += 1
+ if self.success_count >= self.config.success_threshold:
+ self.state = CircuitBreakerState.CLOSED
+ self.failure_count = 0
+ logger.info("Circuit breaker CLOSED after successful recovery")
+ elif self.state == CircuitBreakerState.CLOSED:
+ self.failure_count = 0 # Reset failure count on success
+
+ return result
+
+ except Exception as e:
+ # Handle failure
+ if isinstance(e, self.config.expected_exception):
+ with self._lock:
+ if self.state == CircuitBreakerState.HALF_OPEN:
+ # Failed during recovery test - back to open
+ self.state = CircuitBreakerState.OPEN
+ self.last_failure_time = time.time()
+ logger.warning(
+ "Circuit breaker back to OPEN after failed recovery test"
+ )
+ elif self.state == CircuitBreakerState.CLOSED:
+ self.failure_count += 1
+ if self.failure_count >= self.config.failure_threshold:
+ self.state = CircuitBreakerState.OPEN
+ self.last_failure_time = time.time()
+ logger.warning(
+ f"Circuit breaker OPENED after {self.failure_count} failures"
+ )
+
+ raise
+
+ def reset(self):
+ """Manually reset circuit breaker to CLOSED state."""
+ with self._lock:
+ self.state = CircuitBreakerState.CLOSED
+ self.failure_count = 0
+ self.success_count = 0
+ self.last_failure_time = 0
+ logger.info("Circuit breaker manually reset to CLOSED")
+
+ def force_open(self):
+ """Manually force circuit breaker to OPEN state."""
+ with self._lock:
+ self.state = CircuitBreakerState.OPEN
+ self.last_failure_time = time.time()
+ logger.warning("Circuit breaker manually forced to OPEN")
+
+ def get_state(self) -> CircuitBreakerState:
+ """Get current circuit breaker state."""
+ return self.state
+
+ def get_stats(self) -> dict:
+ """Get circuit breaker statistics."""
+ return {
+ "state": self.state.value,
+ "failure_count": self.failure_count,
+ "success_count": self.success_count,
+ "last_failure_time": self.last_failure_time,
+ "time_since_last_failure": time.time() - self.last_failure_time
+ if self.last_failure_time
+ else 0,
+ }
+
+
+class CircuitBreakerOpenError(Exception):
+ """Raised when circuit breaker is in OPEN state."""
+
+ pass
+
+
+class ResilientExecutor:
+ """Combines retry logic and circuit breaker for maximum resilience.
+
+ Usage:
+ executor = ResilientExecutor(
+ retry_config=RetryConfig(max_attempts=3),
+ circuit_breaker_config=CircuitBreakerConfig(failure_threshold=5)
+ )
+
+ @executor
+ def unreliable_function():
+ # Function that might fail
+ pass
+ """
+
+ def __init__(
+ self,
+ retry_config: RetryConfig | None = None,
+ circuit_breaker_config: CircuitBreakerConfig | None = None,
+ ):
+ """Initialize resilient executor.
+
+ Args:
+ retry_config: Retry configuration
+ circuit_breaker_config: Circuit breaker configuration
+ """
+ self.retry_handler = RetryHandler(retry_config)
+ self.circuit_breaker = CircuitBreaker(circuit_breaker_config)
+
+ def __call__(self, func: Callable) -> Callable:
+ """Apply both retry and circuit breaker to function."""
+
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ # Apply circuit breaker first, then retry
+ circuit_protected_func = self.circuit_breaker(func)
+ return self.retry_handler.execute_with_retry(
+ circuit_protected_func, *args, **kwargs
+ )
+
+ return wrapper
+
+ def execute(self, func: Callable, *args, **kwargs) -> Any:
+ """Execute function with both retry and circuit breaker protection."""
+ circuit_protected_func = self.circuit_breaker(func)
+ return self.retry_handler.execute_with_retry(
+ circuit_protected_func, *args, **kwargs
+ )
+
+ def get_stats(self) -> dict:
+ """Get combined statistics."""
+ return {
+ "circuit_breaker": self.circuit_breaker.get_stats(),
+ "retry_config": {
+ "max_attempts": self.retry_handler.config.max_attempts,
+ "base_delay": self.retry_handler.config.base_delay,
+ "backoff_strategy": self.retry_handler.config.backoff_strategy,
+ },
+ }
+
+
+# Convenience decorators
+def retry(
+ max_attempts: int = 3,
+ base_delay: float = 1.0,
+ backoff_strategy: str = "exponential",
+ retryable_exceptions: tuple[type[Exception], ...] = (Exception,),
+) -> Callable:
+ """Simple retry decorator.
+
+ Args:
+ max_attempts: Maximum retry attempts
+ base_delay: Base delay between retries
+ backoff_strategy: Backoff strategy ('exponential', 'linear', 'fixed')
+ retryable_exceptions: Exceptions to retry on
+
+ Returns:
+ Decorated function
+ """
+ config = RetryConfig(
+ max_attempts=max_attempts,
+ base_delay=base_delay,
+ backoff_strategy=backoff_strategy,
+ retryable_exceptions=retryable_exceptions,
+ )
+ return RetryHandler(config)
+
+
+def circuit_breaker(
+ failure_threshold: int = 5,
+ recovery_timeout: float = 60.0,
+ expected_exception: type[Exception] = Exception,
+) -> Callable:
+ """Simple circuit breaker decorator.
+
+ Args:
+ failure_threshold: Number of failures to open circuit
+ recovery_timeout: Seconds to wait before testing recovery
+ expected_exception: Exception type that triggers circuit breaker
+
+ Returns:
+ Decorated function
+ """
+ config = CircuitBreakerConfig(
+ failure_threshold=failure_threshold,
+ recovery_timeout=recovery_timeout,
+ expected_exception=expected_exception,
+ )
+ return CircuitBreaker(config)
diff --git a/workers/shared/patterns/worker_patterns.py b/workers/shared/patterns/worker_patterns.py
new file mode 100644
index 000000000..77acb32dd
--- /dev/null
+++ b/workers/shared/patterns/worker_patterns.py
@@ -0,0 +1,264 @@
+"""Worker-Specific Patterns
+
+This module contains worker-specific dataclasses, enums, and patterns
+that are only used within the worker services. Domain models that are
+shared between backend and workers remain in unstract.core.
+"""
+
+import logging
+import os
+
+# Import only the shared domain models from core
+import sys
+from dataclasses import dataclass, field
+from datetime import datetime
+from enum import Enum
+from typing import Any
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../unstract/core/src"))
+
+from unstract.core import ExecutionStatus, serialize_dataclass_to_dict
+from unstract.core.worker_models import FileExecutionResult
+
+logger = logging.getLogger(__name__)
+
+
+# Worker-Specific Enums (NOT in core)
+class TaskName(str, Enum):
+ """Worker task names - only used by workers."""
+
+ SEND_WEBHOOK_NOTIFICATION = "send_webhook_notification"
+ ASYNC_EXECUTE_BIN_API = "async_execute_bin_api"
+ EXECUTE_WORKFLOW_WITH_FILES = "execute_workflow_with_files"
+ ORCHESTRATE_FILE_PROCESSING = "_orchestrate_file_processing_general"
+ PROCESS_FILE_BATCH = "process_file_batch"
+ PROCESS_BATCH_CALLBACK = "process_batch_callback"
+
+ def __str__(self):
+ return self.value
+
+
+class QueueName(str, Enum):
+ """Worker queue names - only used by workers."""
+
+ GENERAL = "general"
+ FILE_PROCESSING = "file_processing"
+ CALLBACK = "callback"
+ API_DEPLOYMENTS = "api_deployments"
+
+ def __str__(self):
+ return self.value
+
+
+class WebhookStatus(str, Enum):
+ """Webhook delivery status - worker implementation detail."""
+
+ DELIVERED = "delivered"
+ QUEUED = "queued"
+ FAILED = "failed"
+ TIMEOUT = "timeout"
+
+ def __str__(self):
+ return self.value
+
+
+class PipelineStatus(str, Enum):
+ """Pipeline status for worker-backend communication."""
+
+ SUCCESS = "SUCCESS"
+ FAILURE = "FAILURE"
+ INPROGRESS = "INPROGRESS"
+ YET_TO_START = "YET_TO_START"
+
+ def __str__(self):
+ return self.value
+
+
+# Worker-Specific Data Models
+@dataclass
+class WebhookResult:
+ """Worker webhook delivery result - not used by backend directly."""
+
+ status: WebhookStatus
+ url: str
+ task_id: str
+ webhook_task_id: str
+ webhook_status: str
+ payload_size: int
+ timeout: int
+ attempts: int
+ delivery_time: float
+ error_message: str | None = None
+ response_code: int | None = None
+
+ def to_dict(self) -> dict[str, Any]:
+ return serialize_dataclass_to_dict(self)
+
+
+@dataclass
+class BatchExecutionResult:
+ """Worker batch processing result - worker-specific aggregation."""
+
+ total_files: int
+ successful_files: int
+ failed_files: int
+ execution_time: float
+ file_results: list[FileExecutionResult] = field(default_factory=list)
+ batch_id: str | None = None
+
+ @property
+ def success_rate(self) -> float:
+ if self.total_files == 0:
+ return 0.0
+ return (self.successful_files / self.total_files) * 100
+
+ def to_dict(self) -> dict[str, Any]:
+ return serialize_dataclass_to_dict(self)
+
+
+# Worker Configuration and Constants
+
+# Internal API Configuration - Environment configurable
+INTERNAL_API_PREFIX = os.getenv("INTERNAL_API_PREFIX", "/internal")
+INTERNAL_API_VERSION = os.getenv("INTERNAL_API_VERSION", "v1")
+INTERNAL_API_BASE_PATH = f"{INTERNAL_API_PREFIX}/{INTERNAL_API_VERSION}"
+
+
+def build_internal_endpoint(path: str) -> str:
+ """Build a complete internal API endpoint path.
+
+ Args:
+ path: The endpoint path without the internal prefix (e.g., "health/")
+
+ Returns:
+ Complete internal API path (e.g., "/internal/v1/health/")
+ """
+ # Ensure path starts and ends with /
+ if not path.startswith("/"):
+ path = f"/{path}"
+ if not path.endswith("/"):
+ path = f"{path}/"
+
+ return f"{INTERNAL_API_BASE_PATH}{path}"
+
+
+class APIEndpoints:
+ """Internal API endpoints - worker implementation detail with environment configuration."""
+
+ WORKFLOW_EXECUTION_STATUS = build_internal_endpoint(
+ "workflow-execution/{execution_id}/status/"
+ )
+ WORKFLOW_FILE_EXECUTION_CREATE = build_internal_endpoint(
+ "workflow-file-execution/create/"
+ )
+ PIPELINE_STATUS = build_internal_endpoint("pipeline/{pipeline_id}/status/")
+ WEBHOOK_SEND = build_internal_endpoint("webhook/send/")
+
+
+class WorkerConfig:
+ """Worker-specific configuration - not shared with backend."""
+
+ DEFAULT_TASK_TIMEOUT = 300
+ FILE_PROCESSING_TIMEOUT = 1800
+ CALLBACK_TIMEOUT = 120
+ WEBHOOK_TIMEOUT = 30
+
+ MAX_FILE_BATCH_SIZE = 20
+ MAX_PARALLEL_FILE_BATCHES = 4
+
+ API_REQUEST_TIMEOUT = 30
+ CACHE_TTL = 60
+
+
+class ErrorMessages:
+ """Worker-specific error messages."""
+
+ TASK_TIMEOUT = "Task execution timed out after {timeout} seconds"
+ FILE_PROCESSING_FAILED = "Failed to process file {file_name}: {error}"
+ API_CONNECTION_FAILED = "Failed to connect to internal API: {error}"
+ WEBHOOK_DELIVERY_FAILED = "Webhook delivery failed: {error}"
+
+
+# Status Mapping Utilities (Worker-Specific)
+class StatusMappings:
+ """Map between core domain status and worker implementation status."""
+
+ EXECUTION_TO_PIPELINE = {
+ ExecutionStatus.COMPLETED: PipelineStatus.SUCCESS,
+ ExecutionStatus.ERROR: PipelineStatus.FAILURE,
+ ExecutionStatus.EXECUTING: PipelineStatus.INPROGRESS,
+ ExecutionStatus.PENDING: PipelineStatus.YET_TO_START,
+ }
+
+ @classmethod
+ def map_execution_to_pipeline(
+ cls, execution_status: ExecutionStatus
+ ) -> PipelineStatus:
+ """Convert core ExecutionStatus to worker PipelineStatus."""
+ return cls.EXECUTION_TO_PIPELINE.get(execution_status, PipelineStatus.FAILURE)
+
+
+# Example: Worker-Specific Base Class (NOT in core)
+class WorkerTaskBase:
+ """Base class for worker tasks - worker implementation detail."""
+
+ def __init__(self):
+ self.logger = logging.getLogger(self.__class__.__name__)
+
+ def log_task_start(self, task_name: TaskName, task_id: str):
+ """Worker-specific logging."""
+ self.logger.info(f"Starting worker task {task_name.value} with ID {task_id}")
+
+ def handle_worker_error(self, error: Exception, context: dict) -> dict:
+ """Worker-specific error handling."""
+ return {
+ "error_type": type(error).__name__,
+ "error_message": str(error),
+ "worker_context": context,
+ "timestamp": datetime.now().isoformat(),
+ }
+
+
+# Demonstration
+def demonstrate_separation():
+ """Show the clean separation between core domain models and worker patterns."""
+ logger.info("🏗️ Architecture Separation Demo")
+
+ # 1. Core domain model (shared with backend)
+ logger.info("\n1. Core Domain Model:")
+ logger.info(f" ExecutionStatus.COMPLETED = {ExecutionStatus.COMPLETED}")
+ logger.info(" (Shared between backend and workers)")
+
+ # 2. Worker-specific enums (NOT shared with backend)
+ logger.info("\n2. Worker-Specific Patterns:")
+ logger.info(f" TaskName.PROCESS_FILE_BATCH = {TaskName.PROCESS_FILE_BATCH}")
+ logger.info(f" QueueName.FILE_PROCESSING = {QueueName.FILE_PROCESSING}")
+ logger.info(f" WebhookStatus.DELIVERED = {WebhookStatus.DELIVERED}")
+ logger.info(" (Worker implementation details)")
+
+ # 3. Worker result using core status
+ logger.info("\n3. Worker Result with Core Status:")
+ result = FileExecutionResult(
+ file="test.pdf",
+ file_execution_id="exec-123",
+ status=ExecutionStatus.COMPLETED, # Core domain model
+ processing_time=1.5,
+ )
+ logger.info(
+ f" File: {result.file}, Status: {result.status}, Success: {result.is_successful()}"
+ )
+
+ # 4. Status mapping between domains
+ logger.info("\n4. Status Mapping:")
+ pipeline_status = StatusMappings.map_execution_to_pipeline(ExecutionStatus.COMPLETED)
+ logger.info(
+ f" Core ExecutionStatus.COMPLETED → Worker PipelineStatus.{pipeline_status}"
+ )
+
+ logger.info(
+ "\n✅ Clean separation: Core has domain models, Workers have implementation patterns"
+ )
+
+
+if __name__ == "__main__":
+ demonstrate_separation()
diff --git a/workers/shared/processing/__init__.py b/workers/shared/processing/__init__.py
new file mode 100644
index 000000000..0f30383de
--- /dev/null
+++ b/workers/shared/processing/__init__.py
@@ -0,0 +1,21 @@
+"""Processing utilities for files and data types.
+
+This package provides file processing and type conversion functionality
+organized by responsibility.
+
+Note: BatchUtils was removed as it was unused dead code.
+"""
+
+from .files import * # noqa: F403
+from .types import * # noqa: F403
+
+__all__ = [
+ # File processing
+ "WorkerFileProcessor",
+ "FileProcessingUtils",
+ "FileProcessingMixin",
+ # Type processing
+ "TypeConverter",
+ "FileDataValidator",
+ "FileProcessingContext",
+]
diff --git a/workers/shared/processing/file_discovery.py b/workers/shared/processing/file_discovery.py
new file mode 100644
index 000000000..942926df0
--- /dev/null
+++ b/workers/shared/processing/file_discovery.py
@@ -0,0 +1,963 @@
+"""File Discovery Service
+
+This module provides the StreamingFileDiscovery service, moved to shared/processing
+to avoid circular imports and provide clean separation of concerns.
+"""
+
+import time
+from typing import Any
+
+from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
+from unstract.core.data_models import ConnectionType, FileHashData, FileOperationConstants
+from unstract.core.file_operations import FileOperations
+
+from ..infrastructure.logging import WorkerLogger
+from .filter_pipeline import FilterPipeline
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class StreamingFileDiscovery:
+ """Streams files from directories with early filtering and termination.
+
+ This class replaces the inefficient "discover-all-then-filter" approach with
+ a streaming system that:
+ 1. Walks directories incrementally
+ 2. Applies ALL filters as files are discovered
+ 3. Stops immediately when limit is reached
+ 4. Uses batch processing for efficient API calls
+ """
+
+ def __init__(
+ self,
+ source_fs: UnstractFileSystem,
+ api_client, # Removed type hint to avoid import
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ connector_id: str | None = None,
+ ):
+ """Initialize streaming file discovery.
+
+ Args:
+ source_fs: Filesystem connector
+ api_client: API client for backend communication
+ workflow_id: Workflow ID for filtering
+ execution_id: Current execution ID
+ organization_id: Organization ID
+ connector_id: Optional connector ID for metadata
+ """
+ self.source_fs = source_fs
+ self.api_client = api_client
+ self.workflow_id = workflow_id
+ self.execution_id = execution_id
+ self.organization_id = organization_id
+ self.connector_id = connector_id
+ self.fs_fsspec = source_fs.get_fsspec_fs()
+
+ def discover_files_streaming(
+ self,
+ directories: list[str],
+ patterns: list[str],
+ recursive: bool,
+ file_hard_limit: int,
+ filter_pipeline: FilterPipeline,
+ batch_size: int = 100,
+ ) -> tuple[dict[str, FileHashData], int]:
+ """Discover files using streaming with early filtering.
+
+ This is the main entry point that replaces the old _get_matched_files.
+ It discovers files incrementally and applies all filters immediately.
+
+ Args:
+ directories: List of directories to search
+ patterns: File patterns to match
+ recursive: Whether to search recursively
+ file_hard_limit: Maximum files to return (hard stop)
+ filter_pipeline: Pipeline of filters to apply
+ batch_size: Size of batches for processing
+
+ Returns:
+ Tuple of (matched_files, count)
+ """
+ start_time = time.time()
+
+ matched_files: dict[str, FileHashData] = {}
+ batch_buffer: list[tuple[str, dict[str, Any]]] = []
+
+ # Metrics tracking
+ metrics = {
+ "total_files_discovered": 0,
+ "files_pattern_matched": 0,
+ "files_after_filtering": 0,
+ "batches_processed": 0,
+ "directories_walked": 0,
+ }
+
+ # Calculate max depth for recursive search
+ max_depth = int(FileOperationConstants.MAX_RECURSIVE_DEPTH) if recursive else 1
+
+ logger.info(
+ f"[StreamingDiscovery] Starting streaming discovery for {len(directories)} directories "
+ f"with limit={file_hard_limit}, batch_size={batch_size}, recursive={recursive}, patterns={patterns}, "
+ f"max_depth={max_depth}"
+ )
+
+ try:
+ for directory in directories:
+ # Check if we've reached the limit
+ if len(matched_files) >= file_hard_limit:
+ logger.info(
+ f"[StreamingDiscovery] Reached file limit ({file_hard_limit}), "
+ f"stopping discovery early"
+ )
+ break
+
+ logger.info(f"[StreamingDiscovery] Processing directory: {directory}")
+
+ # Walk directory with max depth control
+ for root, dirs, _ in self.fs_fsspec.walk(directory, maxdepth=max_depth):
+ metrics["directories_walked"] += 1
+
+ # Check limit before processing directory
+ if len(matched_files) >= file_hard_limit:
+ break
+
+ try:
+ # Get all items in directory with metadata
+ fs_metadata_list: list[dict[str, Any]] = self.fs_fsspec.listdir(
+ root
+ )
+ except Exception as e:
+ logger.warning(f"Failed to list directory {root}: {e}")
+ continue
+
+ # Process files in this directory
+ for fs_metadata in fs_metadata_list:
+ # Early termination check
+ if len(matched_files) >= file_hard_limit:
+ break
+
+ file_path = fs_metadata.get("name")
+ if not file_path:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Skipping item with no name: {fs_metadata}"
+ )
+ continue
+
+ # Log detailed file metadata for debugging
+ file_type = fs_metadata.get("type", "unknown")
+ file_size = fs_metadata.get("size", "unknown")
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Discovered item: '{file_path}' (type: {file_type}, size: {file_size})"
+ )
+
+ metrics["total_files_discovered"] += 1
+
+ # Skip directories with detailed logging
+ is_directory = self._is_directory(file_path, fs_metadata, dirs)
+ if is_directory:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Skipping directory: {file_path}"
+ )
+ continue
+
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] File passed directory check: {file_path}"
+ )
+
+ # Apply pattern filter first (cheapest)
+ pattern_matches = self._matches_patterns(file_path, patterns)
+ if not pattern_matches:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] File failed pattern match: {file_path} (patterns: {patterns})"
+ )
+ continue
+
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] File passed pattern match: {file_path}"
+ )
+ metrics["files_pattern_matched"] += 1
+
+ # Add to batch buffer
+ batch_buffer.append((file_path, fs_metadata))
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Added to batch buffer: {file_path} (buffer size: {len(batch_buffer)})"
+ )
+
+ # Process batch when full
+ if len(batch_buffer) >= batch_size:
+ self._process_batch(
+ batch_buffer,
+ matched_files,
+ filter_pipeline,
+ file_hard_limit,
+ )
+ metrics["batches_processed"] += 1
+ batch_buffer = []
+
+ # Check if we've reached limit after batch processing
+ if len(matched_files) >= file_hard_limit:
+ logger.info(
+ "[StreamingDiscovery] Reached limit after batch processing"
+ )
+ break
+
+ # Process remaining files in buffer
+ if batch_buffer and len(matched_files) < file_hard_limit:
+ self._process_batch(
+ batch_buffer, matched_files, filter_pipeline, file_hard_limit
+ )
+ metrics["batches_processed"] += 1
+
+ # Ensure we never exceed the hard limit
+ if len(matched_files) > file_hard_limit:
+ logger.info(
+ f"[StreamingDiscovery] Trimming results from {len(matched_files)} to {file_hard_limit}"
+ )
+ matched_files = dict(list(matched_files.items())[:file_hard_limit])
+
+ final_count = len(matched_files)
+ metrics["files_after_filtering"] = final_count
+ elapsed_time = time.time() - start_time
+
+ # Log comprehensive metrics
+ logger.info(
+ f"[StreamingDiscovery] 🎯 Discovery complete in {elapsed_time:.2f}s:\n"
+ f" • Directories walked: {metrics['directories_walked']}\n"
+ f" • Total files discovered: {metrics['total_files_discovered']}\n"
+ f" • Files matching patterns: {metrics['files_pattern_matched']}\n"
+ f" • Files after all filters: {metrics['files_after_filtering']}\n"
+ f" • Batches processed: {metrics['batches_processed']}\n"
+ f" • Hard limit: {file_hard_limit}\n"
+ f" • Early termination: {'Yes' if final_count >= file_hard_limit else 'No'}"
+ )
+
+ # Performance metrics
+ if metrics["total_files_discovered"] > 0:
+ filter_efficiency = (
+ (metrics["total_files_discovered"] - final_count)
+ / metrics["total_files_discovered"]
+ * 100
+ )
+ logger.info(
+ f"[StreamingDiscovery] 📊 Performance metrics:\n"
+ f" • Filter efficiency: {filter_efficiency:.1f}% files filtered out\n"
+ f" • Discovery rate: {metrics['total_files_discovered'] / elapsed_time:.0f} files/sec\n"
+ f" • Final rate: {final_count / elapsed_time:.0f} accepted files/sec"
+ )
+
+ # Create cache entries for files that will be processed to prevent race conditions
+ try:
+ from ..workflow.execution.active_file_manager import ActiveFileManager
+
+ cache_stats = ActiveFileManager.create_cache_entries_simple(
+ files_to_cache=matched_files, # Create cache entries for all final files
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ logger_instance=logger,
+ )
+
+ logger.info(
+ f"[StreamingDiscovery] 🔒 Created {cache_stats.get('cache_created', 0)} cache entries "
+ f"for race condition prevention"
+ )
+
+ # Return original matched_files since FilterPipeline already applied all filtering
+ return matched_files, final_count
+
+ except Exception as cache_error:
+ logger.warning(
+ f"[StreamingDiscovery] Cache creation failed (proceeding anyway): {cache_error}"
+ )
+ return matched_files, final_count
+
+ except Exception as e:
+ logger.error(
+ f"[StreamingDiscovery] Error during file discovery: {e}", exc_info=True
+ )
+ # Return what we've collected so far
+ return matched_files, len(matched_files)
+
+ def _process_batch(
+ self,
+ batch_buffer: list[tuple[str, dict[str, Any]]],
+ matched_files: dict[str, FileHashData],
+ filter_pipeline: FilterPipeline,
+ file_hard_limit: int,
+ ) -> None:
+ """Process a batch of files through the filter pipeline.
+
+ Args:
+ batch_buffer: Buffer of (file_path, metadata) tuples
+ matched_files: Dictionary to add accepted files to
+ filter_pipeline: Pipeline of filters to apply
+ file_hard_limit: Maximum number of files to collect
+ """
+ if not batch_buffer:
+ return
+
+ logger.info(f"[StreamingDiscovery] Processing batch of {len(batch_buffer)} files")
+
+ # Log the files being processed in this batch for debugging
+ batch_files = [file_path for file_path, _ in batch_buffer]
+ logger.info(f"DEBUG: [StreamingDiscovery] Batch files: {batch_files}")
+
+ # Convert batch to FileHashData objects with defensive validation
+ file_hash_batch: dict[str, FileHashData] = {}
+ for file_path, fs_metadata in batch_buffer:
+ try:
+ # Validate file path and extract file name
+ if not file_path or not isinstance(file_path, str):
+ logger.warning(
+ f"[StreamingDiscovery] Skipping invalid file path: {file_path}"
+ )
+ continue
+
+ # Extract and validate file name
+ import os
+
+ file_name = os.path.basename(file_path.rstrip("/"))
+ if not file_name or file_name in ["", ".", ".."]:
+ logger.warning(
+ f"[StreamingDiscovery] Skipping file with invalid name: '{file_path}' -> '{file_name}'"
+ )
+ continue
+
+ # Check if this looks like a directory path
+ if file_path.endswith("/") or not file_name:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Skipping directory-like path: {file_path}"
+ )
+ continue
+
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Processing file: '{file_path}' (name: '{file_name}', size: {fs_metadata.get('size', 0)})"
+ )
+
+ # Add connector_id to metadata if available
+ if self.connector_id:
+ fs_metadata = fs_metadata.copy()
+ fs_metadata["connector_id"] = self.connector_id
+
+ # Create FileHashData object with proper error handling
+ file_hash = FileOperations.create_file_hash_from_backend_logic(
+ file_path=file_path,
+ source_fs=self.source_fs,
+ source_connection_type=ConnectionType.FILESYSTEM,
+ file_size=fs_metadata.get("size", 0),
+ fs_metadata=fs_metadata,
+ compute_content_hash=False, # Only use provider_file_uuid
+ )
+
+ file_hash_batch[file_path] = file_hash
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Successfully created FileHashData for: {file_path}"
+ )
+
+ except ValueError as ve:
+ logger.error(
+ f"[StreamingDiscovery] FileHashData creation failed for '{file_path}': {ve}"
+ )
+ logger.info(f"DEBUG: [StreamingDiscovery] File metadata: {fs_metadata}")
+ continue
+ except Exception as e:
+ logger.error(
+ f"[StreamingDiscovery] Unexpected error processing '{file_path}': {e}",
+ exc_info=True,
+ )
+ continue
+
+ # Apply filter pipeline to batch
+ filtered_batch = filter_pipeline.apply_filters(
+ files=file_hash_batch,
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ api_client=self.api_client,
+ organization_id=self.organization_id,
+ )
+
+ logger.info(
+ f"[StreamingDiscovery] Batch processing complete: {len(batch_buffer)} raw → {len(file_hash_batch)} valid → {len(filtered_batch)} filtered"
+ )
+
+ # Add filtered files to results (respecting limit)
+ added_count = 0
+ for file_path, file_hash in filtered_batch.items():
+ if len(matched_files) >= file_hard_limit:
+ break
+ matched_files[file_path] = file_hash
+ added_count += 1
+
+ if added_count > 0:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Added {added_count} files to final results"
+ )
+
+ def _is_directory(
+ self, file_path: str, metadata: dict[str, Any], dirs: list[str]
+ ) -> bool:
+ """Check if path is a directory using multiple detection methods.
+
+ Args:
+ file_path: Path to check
+ metadata: File metadata from fsspec
+ dirs: List of directories from walk
+
+ Returns:
+ True if path is a directory
+ """
+ import os
+
+ if not file_path:
+ return False
+
+ # 1. Check if path ends with directory separator
+ if file_path.endswith("/") or file_path.endswith("\\"):
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory detected by path suffix: {file_path}"
+ )
+ return True
+
+ # 2. Check if basename is in dirs list from walk
+ basename = os.path.basename(file_path)
+ if basename in dirs:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory detected in dirs list: {file_path}"
+ )
+ return True
+
+ # 3. Check metadata type with broader detection
+ file_type = metadata.get("type", "").lower()
+ if file_type in ["directory", "dir", "folder", "d"]:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory detected by metadata type '{file_type}': {file_path}"
+ )
+ return True
+
+ # 4. Check size - directories often have size 0 or None
+ file_size = metadata.get("size")
+ if file_size is None and metadata.get("type") != "file":
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Possible directory (no size, not file type): {file_path}"
+ )
+ return True
+
+ # 5. Check for common directory characteristics
+ if not basename or basename in [".", ".."]:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory detected by special name: {file_path}"
+ )
+ return True
+
+ # 6. Try connector-specific directory check
+ try:
+ if hasattr(self.source_fs, "is_dir_by_metadata"):
+ is_dir = self.source_fs.is_dir_by_metadata(metadata)
+ if is_dir:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory detected by connector-specific check: {file_path}"
+ )
+ return is_dir
+ else:
+ is_dir = self.fs_fsspec.isdir(file_path)
+ if is_dir:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory detected by fsspec.isdir: {file_path}"
+ )
+ return is_dir
+ except Exception as e:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Directory check failed for {file_path}: {e}"
+ )
+
+ # 7. Final check: if no file extension and metadata suggests it might be a directory
+ if "." not in basename and file_size == 0:
+ logger.info(
+ f"DEBUG: [StreamingDiscovery] Possible directory (no extension, zero size): {file_path}"
+ )
+ # Don't return True here, just log - this is too aggressive
+
+ return False
+
+ def _matches_patterns(self, file_path: str, patterns: list[str]) -> bool:
+ """Check if file matches any of the patterns.
+
+ Args:
+ file_path: File path to check
+ patterns: List of file patterns
+
+ Returns:
+ True if file matches any pattern
+ """
+ if not patterns or patterns == ["*"]:
+ return True
+
+ import fnmatch
+ import os
+
+ file_name = os.path.basename(file_path)
+ for pattern in patterns:
+ # Case-insensitive matching
+ if fnmatch.fnmatch(file_name.lower(), pattern.lower()):
+ return True
+
+ return False
+
+
+class OrderedFileDiscovery:
+ """Ordered file discovery with sorting and chunked filtering.
+
+ This class handles ORDERED file processing (FIFO/LIFO) by:
+ 1. Loading all file metadata into memory (up to MAX_FILES_FOR_SORTING)
+ 2. Sorting by modification time (oldest/newest first)
+ 3. Filtering in chunks using FilterPipeline to avoid overwhelming backend APIs
+
+ This provides the same memory behavior as backend source.py while maintaining
+ clean architecture separation.
+ """
+
+ def __init__(
+ self,
+ source_fs: UnstractFileSystem,
+ api_client, # Removed type hint to avoid import
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ use_file_history: bool = True,
+ connector_id: str | None = None,
+ ):
+ """Initialize ordered file discovery.
+
+ Args:
+ source_fs: Filesystem connector
+ api_client: API client for backend communication
+ workflow_id: Workflow ID for filtering
+ execution_id: Current execution ID
+ organization_id: Organization ID
+ use_file_history: Whether to use file history filtering
+ connector_id: Optional connector ID for metadata
+ """
+ self.source_fs = source_fs
+ self.api_client = api_client
+ self.workflow_id = workflow_id
+ self.execution_id = execution_id
+ self.organization_id = organization_id
+ self.use_file_history = use_file_history
+ self.connector_id = connector_id
+ self.fs_fsspec = source_fs.get_fsspec_fs()
+
+ def discover_files_ordered(
+ self,
+ directories: list[str],
+ patterns: list[str],
+ recursive: bool,
+ file_hard_limit: int,
+ file_processing_order: str, # FileProcessingOrder enum value
+ batch_size: int = 100,
+ ) -> tuple[dict[str, FileHashData], int]:
+ """Discover files with ordering (OLDEST_FIRST/NEWEST_FIRST).
+
+ Memory behavior: Load all files → Sort → Filter in chunks
+ This mirrors the backend logic exactly.
+
+ Args:
+ directories: List of directories to search
+ patterns: File patterns to match
+ recursive: Whether to search recursively
+ file_hard_limit: Maximum files to return (hard stop)
+ file_processing_order: Order to process files (OLDEST_FIRST/NEWEST_FIRST)
+ batch_size: Size of filter processing chunks
+
+ Returns:
+ Tuple of (matched_files, count)
+ """
+ start_time = time.time()
+
+ # Metrics tracking for comprehensive analysis
+ metrics = {
+ "total_files_collected": 0,
+ "directories_processed": 0,
+ "files_matching_patterns": 0,
+ "files_after_filtering": 0,
+ "batches_processed": 0,
+ "collection_time": 0.0,
+ "filtering_time": 0.0,
+ }
+
+ logger.info(
+ f"[OrderedDiscovery] Starting ordered file discovery for {len(directories)} directories "
+ f"with limit={file_hard_limit}, batch_size={batch_size}, recursive={recursive}, "
+ f"patterns={patterns}, order={file_processing_order}"
+ )
+
+ try:
+ # Step 1: Collect and sort all files (load into memory)
+ collection_start = time.time()
+ sorted_files = self._collect_and_sort_files(
+ directories, recursive, file_processing_order, metrics
+ )
+ metrics["collection_time"] = time.time() - collection_start
+
+ logger.info(
+ f"[OrderedDiscovery] Collected {len(sorted_files)} files for ordered processing "
+ f"in {metrics['collection_time']:.2f}s"
+ )
+
+ if not sorted_files:
+ # Log comprehensive metrics even for empty results
+ elapsed_time = time.time() - start_time
+ logger.info(
+ f"[OrderedDiscovery] 🎯 Discovery complete in {elapsed_time:.2f}s:\n"
+ f" • Directories processed: {metrics['directories_processed']}\n"
+ f" • Total files collected: {metrics['total_files_collected']}\n"
+ f" • Files matching patterns: 0\n"
+ f" • Files after all filters: 0\n"
+ f" • Batches processed: 0\n"
+ f" • Hard limit: {file_hard_limit}\n"
+ f" • Processing order: {file_processing_order}\n"
+ f" • Early termination: No"
+ )
+ return {}, 0
+
+ # Step 2: Process in chunks with FilterPipeline
+ filtering_start = time.time()
+ matched_files, total_processed = self._process_sorted_files_in_chunks(
+ sorted_files, patterns, file_hard_limit, batch_size, metrics
+ )
+ metrics["filtering_time"] = time.time() - filtering_start
+ final_count = total_processed
+
+ # Update final metrics
+ elapsed_time = time.time() - start_time
+ metrics["files_after_filtering"] = final_count
+
+ # Log comprehensive metrics
+ logger.info(
+ f"[OrderedDiscovery] 🎯 Discovery complete in {elapsed_time:.2f}s:\n"
+ f" • Directories processed: {metrics['directories_processed']}\n"
+ f" • Total files collected: {metrics['total_files_collected']}\n"
+ f" • Files matching patterns: {metrics['files_matching_patterns']}\n"
+ f" • Files after all filters: {metrics['files_after_filtering']}\n"
+ f" • Batches processed: {metrics['batches_processed']}\n"
+ f" • Hard limit: {file_hard_limit}\n"
+ f" • Processing order: {file_processing_order}\n"
+ f" • Early termination: {'Yes' if final_count >= file_hard_limit else 'No'}"
+ )
+
+ # Performance metrics
+ if metrics["total_files_collected"] > 0:
+ filter_efficiency = (
+ (metrics["total_files_collected"] - final_count)
+ / metrics["total_files_collected"]
+ * 100
+ )
+ collection_rate = (
+ metrics["total_files_collected"] / metrics["collection_time"]
+ if metrics["collection_time"] > 0
+ else 0
+ )
+ processing_rate = final_count / elapsed_time if elapsed_time > 0 else 0
+
+ logger.info(
+ f"[OrderedDiscovery] 📊 Performance metrics:\n"
+ f" • Filter efficiency: {filter_efficiency:.1f}% files filtered out\n"
+ f" • Collection rate: {collection_rate:.0f} files/sec\n"
+ f" • Processing rate: {processing_rate:.0f} accepted files/sec\n"
+ f" • Phase timing - Collection: {metrics['collection_time']:.1f}s, "
+ f"Filtering: {metrics['filtering_time']:.1f}s"
+ )
+
+ return matched_files, total_processed
+
+ except Exception as e:
+ elapsed_time = time.time() - start_time
+ logger.error(
+ f"[OrderedDiscovery] Error during ordered file discovery after {elapsed_time:.1f}s: {e}",
+ exc_info=True,
+ )
+ # Return partial results if available
+ return {}, 0
+
+ def _collect_and_sort_files(
+ self,
+ directories: list[str],
+ recursive: bool,
+ file_processing_order: str,
+ metrics: dict[str, Any],
+ ) -> list[dict[str, Any]]:
+ """Collect files from all directories and sort globally.
+
+ This matches the backend logic from source.py:282-370 exactly.
+
+ Args:
+ directories: List of directories to search
+ recursive: Whether to search recursively
+ file_processing_order: Order to sort files
+ metrics: Metrics dictionary to populate
+
+ Returns:
+ List of file metadata dictionaries sorted by modified date
+ """
+ all_files_metadata = []
+ max_depth = FileOperationConstants.MAX_RECURSIVE_DEPTH if recursive else 1
+ max_files_for_sorting = FileOperationConstants.MAX_FILES_FOR_SORTING
+ total_collected = 0
+
+ # Collect files from all directories (matching backend logic)
+ for directory in directories:
+ logger.debug(f"[OrderedDiscovery] Collecting files from: {directory}")
+ metrics["directories_processed"] += 1
+
+ # Calculate remaining limit for this directory
+ remaining_limit = max_files_for_sorting - total_collected
+ if remaining_limit <= 0:
+ logger.debug(
+ "[OrderedDiscovery] Reached collection limit, stopping directory processing"
+ )
+ break
+
+ try:
+ files_metadata = self.source_fs.list_files(
+ directory=directory,
+ max_depth=max_depth,
+ include_dirs=False,
+ limit=remaining_limit,
+ )
+ all_files_metadata.extend(files_metadata)
+ total_collected += len(files_metadata)
+
+ logger.debug(
+ f"[OrderedDiscovery] Collected {len(files_metadata)} files from {directory} "
+ f"(total: {total_collected}/{max_files_for_sorting})"
+ )
+
+ # Check if we've hit the limit
+ if total_collected >= max_files_for_sorting:
+ logger.warning(
+ f"[OrderedDiscovery] File collection limit of '{max_files_for_sorting}' reached. "
+ "Ordering may not reflect all available files."
+ )
+ break
+
+ except Exception as e:
+ error_msg = f"Failed to collect files from {directory}"
+ logger.error(f"[OrderedDiscovery] {error_msg}: {e}")
+ continue
+
+ # Update metrics with collection results
+ metrics["total_files_collected"] = total_collected
+
+ # Apply sorting (matching backend logic)
+ if file_processing_order == "oldest_first":
+ sorted_files = self.source_fs.sort_files_by_modified_date(
+ all_files_metadata, ascending=True
+ )
+ order_desc = "FIFO (oldest first)"
+ else: # newest_first
+ sorted_files = self.source_fs.sort_files_by_modified_date(
+ all_files_metadata, ascending=False
+ )
+ order_desc = "LIFO (newest first)"
+
+ logger.info(
+ f"[OrderedDiscovery] Collected {len(all_files_metadata)} files, processing in {order_desc} order"
+ )
+
+ return sorted_files
+
+ def _process_sorted_files_in_chunks(
+ self,
+ sorted_files: list[dict[str, Any]],
+ patterns: list[str],
+ file_hard_limit: int,
+ batch_size: int,
+ metrics: dict[str, Any],
+ ) -> tuple[dict[str, FileHashData], int]:
+ """Process sorted files in chunks using FilterPipeline.
+
+ This avoids sending 40K files to backend APIs at once by processing
+ in manageable chunks of ~100 files each.
+
+ Args:
+ sorted_files: Pre-sorted list of file metadata
+ patterns: File patterns for filtering
+ file_hard_limit: Maximum files to return
+ batch_size: Size of each processing chunk
+ metrics: Metrics dictionary to populate
+
+ Returns:
+ Tuple of (matched_files, total_count)
+ """
+ from .filter_pipeline import create_standard_pipeline
+
+ matched_files = {}
+ total_processed = 0
+ files_pattern_matched = 0
+
+ # Create FilterPipeline for chunked processing
+ filter_pipeline = create_standard_pipeline(
+ use_file_history=self.use_file_history,
+ enable_active_filtering=True, # Always enable for ordered processing
+ )
+
+ logger.info(
+ f"[OrderedDiscovery] Processing {len(sorted_files)} sorted files in chunks of {batch_size}"
+ )
+
+ for i in range(0, len(sorted_files), batch_size):
+ # Check if we've reached the limit
+ if total_processed >= file_hard_limit:
+ logger.info(
+ f"[OrderedDiscovery] Hard limit of '{file_hard_limit}' files reached"
+ )
+ break
+
+ # Get current chunk
+ chunk_files = sorted_files[i : i + batch_size]
+ chunk_num = (i // batch_size) + 1
+ metrics["batches_processed"] += 1
+
+ logger.debug(
+ f"[OrderedDiscovery] Processing chunk {chunk_num}: files {i + 1}-{min(i + batch_size, len(sorted_files))}"
+ )
+
+ # Convert metadata to FileHashData for this chunk (with pattern filtering)
+ chunk_file_dict = {}
+ chunk_pattern_matched = 0
+
+ for file_metadata in chunk_files:
+ file_path = file_metadata.get("name")
+ if not file_path:
+ continue
+
+ # Create FileHashData from metadata
+ file_hash_data = self._create_file_hash_from_metadata(
+ file_path, file_metadata
+ )
+
+ # Apply pattern matching (same as backend logic)
+ if not self._should_process_file(file_hash_data.file_name, patterns):
+ logger.debug(
+ f"[OrderedDiscovery] File failed pattern match: {file_path} (patterns: {patterns})"
+ )
+ continue
+
+ chunk_file_dict[file_path] = file_hash_data
+ chunk_pattern_matched += 1
+
+ files_pattern_matched += chunk_pattern_matched
+
+ if not chunk_file_dict:
+ logger.debug(
+ f"[OrderedDiscovery] Chunk {chunk_num}: No files passed pattern matching"
+ )
+ continue
+
+ # Apply FilterPipeline to this chunk (DeduplicationFilter, FileHistoryFilter, ActiveFileFilter)
+ filtered_chunk = filter_pipeline.apply_filters(
+ files=chunk_file_dict,
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ api_client=self.api_client,
+ organization_id=self.organization_id,
+ )
+
+ # Add filtered files to results (respecting hard limit)
+ chunk_accepted = 0
+ for file_path, file_hash_data in filtered_chunk.items():
+ if total_processed >= file_hard_limit:
+ break
+ matched_files[file_path] = file_hash_data
+ total_processed += 1
+ chunk_accepted += 1
+
+ logger.debug(
+ f"[OrderedDiscovery] Chunk {chunk_num}: {len(chunk_files)} → {chunk_pattern_matched} → {len(filtered_chunk)} → {chunk_accepted} files "
+ f"(total: {total_processed})"
+ )
+
+ # Update metrics
+ metrics["files_matching_patterns"] = files_pattern_matched
+
+ logger.info(
+ f"[OrderedDiscovery] Ordered processing complete: {len(sorted_files)} → {files_pattern_matched} → {total_processed} files matched"
+ )
+
+ # Create cache entries for files that will be processed to prevent race conditions
+ try:
+ from ..workflow.execution.active_file_manager import ActiveFileManager
+
+ cache_stats = ActiveFileManager.create_cache_entries_simple(
+ files_to_cache=matched_files, # Create cache entries for all final files
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ logger_instance=logger,
+ )
+
+ logger.info(
+ f"[OrderedDiscovery] 🔒 Created {cache_stats.get('cache_created', 0)} cache entries "
+ f"for race condition prevention"
+ )
+
+ # Return original matched_files since FilterPipeline already applied all filtering
+ return matched_files, total_processed
+
+ except Exception as cache_error:
+ logger.warning(
+ f"[OrderedDiscovery] Cache creation failed (proceeding anyway): {cache_error}"
+ )
+ return matched_files, total_processed
+
+ def _create_file_hash_from_metadata(
+ self, file_path: str, file_metadata: dict[str, Any]
+ ) -> FileHashData:
+ """Create FileHashData from file metadata.
+
+ Args:
+ file_path: Path to the file
+ file_metadata: File metadata dictionary
+
+ Returns:
+ FileHashData: File hash data object
+ """
+ file_name = file_path.split("/")[-1] # Get basename
+ file_size = file_metadata.get("size", 0)
+ provider_file_uuid = self.source_fs.get_file_system_uuid(
+ file_path=file_path, metadata=file_metadata
+ )
+ serialized_metadata = self.source_fs.serialize_metadata_value(value=file_metadata)
+
+ return FileHashData(
+ file_path=file_path,
+ source_connection_type=ConnectionType.FILESYSTEM,
+ file_name=file_name,
+ file_size=file_size,
+ provider_file_uuid=provider_file_uuid,
+ fs_metadata=serialized_metadata,
+ )
+
+ def _should_process_file(self, file_name: str, patterns: list[str]) -> bool:
+ """Check if file matches the given patterns.
+
+ Args:
+ file_name: Name of the file to check
+ patterns: List of patterns to match against
+
+ Returns:
+ bool: True if file should be processed, False otherwise
+ """
+ if not patterns:
+ return True
+
+ # Use the existing pattern matching logic from StreamingFileDiscovery
+ import fnmatch
+ import os
+
+ file_name = os.path.basename(file_name)
+ for pattern in patterns:
+ # Case-insensitive matching
+ if fnmatch.fnmatch(file_name.lower(), pattern.lower()):
+ return True
+
+ return False
diff --git a/workers/shared/processing/files/__init__.py b/workers/shared/processing/files/__init__.py
new file mode 100644
index 000000000..08fd401f6
--- /dev/null
+++ b/workers/shared/processing/files/__init__.py
@@ -0,0 +1,17 @@
+"""File processing utilities and components.
+
+This package provides file processing and utility functions
+following the Single Responsibility Principle.
+"""
+
+from .processor import FileProcessor as WorkerFileProcessor
+from .time_utils import WallClockTimeCalculator, aggregate_file_batch_results
+from .utils import FileProcessingMixin, FileProcessingUtils
+
+__all__ = [
+ "WorkerFileProcessor",
+ "FileProcessingUtils",
+ "FileProcessingMixin",
+ "WallClockTimeCalculator",
+ "aggregate_file_batch_results",
+]
diff --git a/workers/shared/processing/files/processor.py b/workers/shared/processing/files/processor.py
new file mode 100644
index 000000000..69480b77e
--- /dev/null
+++ b/workers/shared/processing/files/processor.py
@@ -0,0 +1,680 @@
+"""File Processing Helper for Complex File Operations
+
+This module provides a helper class to break down the extremely complex
+_process_file method found in file_processing/tasks.py into manageable,
+testable, and maintainable components.
+
+UI/WebSocket Log Icons:
+- 🚀 File processing started
+- 🔍 Checking cache/history
+- 📜 Checking processing history
+- ✅ Validating execution status
+- ⚡ File found in cache or history (fast path)
+- 🚀 Starting AI tool execution
+- 🔄 File marked for manual review
+- 📤 File marked for destination processing
+- 📥 Data inserted into database
+- 💾 Files copied to filesystem
+- 🔌 File processed via API
+- ✅ Processing completed successfully
+"""
+
+import ast
+import json
+from typing import Any
+
+from shared.models.file_processing import FileProcessingContext
+
+from unstract.core.data_models import ExecutionStatus, FileHashData, WorkerFileData
+from unstract.core.worker_models import FileProcessingResult, WorkflowExecutionResult
+
+from ...api.internal_client import InternalAPIClient
+from ...enums import FileDestinationType
+from ...infrastructure.logging import WorkerLogger
+from ...infrastructure.logging.helpers import (
+ log_file_error,
+ log_file_info,
+ log_file_processing_error,
+ log_file_processing_success,
+)
+from ...infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+from ...utils.api_result_cache import get_api_cache_manager
+from ...workflow.execution.service import WorkerWorkflowExecutionService
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class CachedFileHandler:
+ """Handles cached file processing logic with file history support."""
+
+ @staticmethod
+ def handle_cached_file(context: FileProcessingContext) -> FileProcessingResult | None:
+ """Handle files with file history enabled (cached/historical files).
+
+ Args:
+ context: File processing context
+
+ Returns:
+ FileProcessingResult if found, None otherwise
+ """
+ if not context.file_hash.use_file_history:
+ return None
+
+ logger.info(
+ f"Checking file history for {context.file_name} with use_file_history=True"
+ )
+
+ try:
+ cache_key = context.file_hash.file_hash
+ if not cache_key:
+ logger.warning(f"No cache key available for file {context.file_name}")
+ return None
+
+ # For API workflows, don't pass file_path since execution paths are unique per execution
+ lookup_file_path = (
+ None if context.is_api_workflow else context.file_hash.file_path
+ )
+
+ history_result = context.api_client.get_file_history_by_cache_key(
+ cache_key=cache_key,
+ workflow_id=context.workflow_id,
+ file_path=lookup_file_path,
+ )
+
+ # Handle both legacy format (result field) and new format (file_history field)
+ if history_result.get("found") and history_result.get("file_history"):
+ # Legacy format - direct result field
+ logger.info(f"✓ Retrieved cached result for {context.file_name}")
+
+ file_history_data = history_result.get("file_history")
+
+ if not file_history_data:
+ logger.warning(
+ f"No file history data available for file {context.file_name}"
+ )
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=False,
+ error="No file history result available",
+ result=None,
+ metadata=None,
+ from_cache=True,
+ )
+
+ # Parse cached JSON result
+ try:
+ cached_result = json.loads(file_history_data.get("result", "{}"))
+ except json.JSONDecodeError:
+ try:
+ cached_result = ast.literal_eval(
+ file_history_data.get("result", "{}")
+ )
+ except (ValueError, SyntaxError) as ast_error:
+ logger.warning(
+ f"Failed to parse result with both JSON and ast: {ast_error}"
+ )
+ cached_result = file_history_data.get("result", "{}")
+
+ try:
+ cached_metadata = json.loads(file_history_data.get("metadata", "{}"))
+ except json.JSONDecodeError:
+ try:
+ cached_metadata = ast.literal_eval(
+ file_history_data.get("metadata", "{}")
+ )
+ except (ValueError, SyntaxError) as ast_error:
+ logger.warning(
+ f"Failed to parse metadata with both JSON and ast: {ast_error}"
+ )
+ cached_metadata = file_history_data.get("metadata", "{}")
+
+ logger.info(
+ f"✓ Cached cached_metadata {cached_metadata} for {context.file_name}"
+ )
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=True,
+ error=None,
+ result=cached_result,
+ metadata=cached_metadata,
+ from_file_history=True,
+ )
+
+ return None
+
+ except Exception as history_error:
+ logger.error(
+ f"Failed to check file history for {context.file_name}: {history_error}"
+ )
+ return None
+
+
+class WorkflowFileExecutionHandler:
+ """Handles workflow file execution validation and management."""
+
+ @staticmethod
+ def validate_workflow_file_execution(
+ context: FileProcessingContext,
+ ) -> FileProcessingResult | None:
+ """Validate and check workflow file execution status.
+
+ Args:
+ context: File processing context
+
+ Returns:
+ FileProcessingResult if already completed, None if processing should continue
+
+ Raises:
+ ValueError: If workflow file execution is not properly configured
+ """
+ if (
+ not context.workflow_file_execution_id
+ or not context.workflow_file_execution_object
+ ):
+ raise ValueError(
+ f"No pre-created WorkflowFileExecution provided for file {context.file_hash.file_name}"
+ )
+
+ logger.info(
+ f"Using pre-created workflow file execution: {context.workflow_file_execution_id}"
+ )
+
+ # workflow_file_execution_object is guaranteed to be truthy (validated above)
+ workflow_file_execution = context.workflow_file_execution_object
+
+ # Check if file execution is already completed
+ if workflow_file_execution.status == ExecutionStatus.COMPLETED.value:
+ logger.info(
+ f"File already completed. Skipping execution for execution_id: {context.execution_id}, "
+ f"file_execution_id: {workflow_file_execution.id}"
+ )
+
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=workflow_file_execution.id,
+ success=True,
+ error=None,
+ result=getattr(workflow_file_execution, "result", None),
+ metadata=getattr(workflow_file_execution, "metadata", None) or {},
+ )
+
+ return None
+
+
+class ManualReviewHandler:
+ """Handles manual review routing logic."""
+
+ @staticmethod
+ def check_manual_review_routing(
+ context: FileProcessingContext,
+ ) -> FileProcessingResult | None:
+ """Check if file should be routed to manual review.
+
+ Args:
+ context: File processing context
+
+ Returns:
+ FileProcessingResult if applicable, None otherwise
+ """
+ # Check if file is destined for manual review
+ if context.file_hash.file_destination == FileDestinationType.MANUALREVIEW.value:
+ logger.info(f"File {context.file_name} routed to manual review queue")
+
+ # Log manual review routing to UI
+ if context.workflow_logger and context.workflow_file_execution_id:
+ log_file_info(
+ context.workflow_logger,
+ context.workflow_file_execution_id,
+ f"🔄 File '{context.file_name}' flagged for MANUAL REVIEW based on destination rules",
+ )
+
+ try:
+ # Route to manual review queue
+ review_result = context.api_client.route_to_manual_review(
+ file_execution_id=context.workflow_file_execution_id,
+ file_data=context.file_hash.to_dict(),
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ )
+
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=True,
+ error=None,
+ result=None,
+ metadata={"routed_to_manual_review": True},
+ manual_review=True,
+ review_result=review_result,
+ )
+
+ except Exception as review_error:
+ logger.error(f"Failed to route file to manual review: {review_error}")
+ # Fall through to normal processing
+
+ return None
+
+ @staticmethod
+ def route_with_results(
+ context: FileProcessingContext, workflow_result: FileProcessingResult
+ ) -> FileProcessingResult | None:
+ """Route file to manual review with tool execution results via plugin.
+
+ Args:
+ context: File processing context
+ workflow_result: FileProcessingResult from tool execution
+
+ Returns:
+ FileProcessingResult with execution data, None if routing failed
+ """
+ try:
+ logger.info(
+ f"Routing file {context.file_name} to manual review with execution results via plugin"
+ )
+
+ # Delegate to the manual review plugin through the API client facade
+ # This will automatically handle plugin availability and fallback to stub
+ result = context.api_client.route_to_manual_review_with_results(
+ file_execution_id=context.workflow_file_execution_id,
+ file_data=context.file_hash.to_dict(),
+ workflow_result=workflow_result.to_dict(),
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ file_name=context.file_name,
+ )
+
+ logger.info(
+ f"Manual review routing result for {context.file_name}: {result.get('success', False)}"
+ )
+ return result
+
+ except Exception as review_error:
+ logger.error(
+ f"Failed to route file to manual review with results: {review_error}"
+ )
+ return None
+
+
+class WorkflowExecutionProcessor:
+ """Handles the actual workflow execution processing."""
+
+ @staticmethod
+ def execute_workflow_processing(
+ context: FileProcessingContext,
+ ) -> FileProcessingResult:
+ """Execute the main workflow processing for the file.
+
+ Args:
+ context: File processing context
+
+ Returns:
+ Workflow execution result
+ """
+ try:
+ logger.info(f"Starting workflow execution for {context.file_name}")
+
+ working_service = WorkerWorkflowExecutionService(
+ api_client=context.api_client
+ )
+
+ # Execute the workflow using the working service implementation
+ logger.info(
+ f"Starting tool execution for {context.file_name} using working service..."
+ )
+ execution_result: WorkflowExecutionResult = (
+ working_service.execute_workflow_for_file(
+ file_processing_context=context,
+ organization_id=context.organization_id,
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ is_api=context.is_api_workflow,
+ use_file_history=context.use_file_history,
+ workflow_file_execution_id=context.workflow_file_execution_id,
+ workflow_logger=context.workflow_logger,
+ )
+ )
+ logger.info(
+ f"Tool execution completed for {context.file_name}. Result success: {execution_result.success}"
+ )
+
+ if not execution_result.success or execution_result.error:
+ # Workflow execution failed - update file status and return error
+ error_message = execution_result.error or "Workflow execution failed"
+ logger.error(
+ f"Tool processing failed for {context.file_name}: {error_message}"
+ )
+
+ # Update file execution status to ERROR
+ try:
+ context.api_client.update_file_execution_status(
+ file_execution_id=context.workflow_file_execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=error_message,
+ )
+ logger.info(
+ f"Updated file execution {context.workflow_file_execution_id} status to ERROR"
+ )
+ except Exception as status_error:
+ logger.error(
+ f"Failed to update file execution status: {status_error}"
+ )
+
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=False,
+ error=error_message,
+ result=None,
+ metadata={
+ "error_occurred": True,
+ "workflow_execution_failed": True,
+ },
+ execution_time=context.get_processing_duration(),
+ )
+
+ logger.info(
+ f"✓ Workflow execution completed successfully for {context.file_name}"
+ )
+
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=True,
+ error=None,
+ result=execution_result.result,
+ metadata=execution_result.metadata.to_dict()
+ if execution_result.metadata
+ else {},
+ execution_time=context.get_processing_duration(),
+ destination_processed=execution_result.metadata.destination_processed
+ if execution_result.metadata
+ else True,
+ destination_error=execution_result.metadata.destination_error
+ if execution_result.metadata
+ else None,
+ )
+
+ except Exception as execution_error:
+ logger.error(
+ f"File processing failed for {context.file_name}: {execution_error}",
+ exc_info=True,
+ )
+
+ # Update file execution status to ERROR
+ try:
+ context.api_client.update_file_execution_status(
+ file_execution_id=context.workflow_file_execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=str(execution_error),
+ )
+ except Exception as status_error:
+ logger.error(
+ f"Failed to update file execution status: {status_error}",
+ exc_info=True,
+ )
+
+ return FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=False,
+ error=str(execution_error),
+ result=None,
+ metadata={"error_occurred": True},
+ execution_time=context.get_processing_duration(),
+ )
+
+
+class FileProcessor:
+ """Main file processor orchestrator that coordinates all processing steps."""
+
+ @staticmethod
+ def process_file(
+ current_file_idx: int,
+ total_files: int,
+ file_data: WorkerFileData,
+ file_hash: FileHashData,
+ api_client: InternalAPIClient,
+ workflow_execution: dict[str, Any],
+ workflow_file_execution_id: str = None,
+ workflow_file_execution_object: Any = None,
+ workflow_logger: WorkerWorkflowLogger = None,
+ ) -> FileProcessingResult:
+ """Main orchestrator method that replaces the complex _process_file method.
+
+ This method coordinates the file processing workflow by:
+ 1. Setting up processing context
+ 2. Checking for cached results
+ 3. Checking file history
+ 4. Validating workflow file execution
+ 5. Checking manual review routing
+ 6. Executing workflow processing
+
+ Args:
+ current_file_idx: Index of current file
+ total_files: Total number of files
+ file_data: File data context
+ file_hash: FileHashData instance with type-safe access
+ api_client: Internal API client
+ workflow_execution: Workflow execution context
+ workflow_file_execution_id: Pre-created workflow file execution ID
+ workflow_file_execution_object: Pre-created workflow file execution object
+
+ Returns:
+ FileProcessingResult dataclass
+ """
+ # Create processing context
+ context = FileProcessingContext(
+ file_data=file_data,
+ file_hash=file_hash,
+ api_client=api_client,
+ workflow_execution=workflow_execution,
+ workflow_file_execution_id=workflow_file_execution_id,
+ workflow_file_execution_object=workflow_file_execution_object,
+ workflow_logger=workflow_logger,
+ current_file_idx=current_file_idx,
+ total_files=total_files,
+ )
+
+ logger.debug(
+ f"File processing context created for {context.file_name} "
+ f"({current_file_idx + 1}/{total_files})"
+ )
+
+ # Send file processing start log to UI
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"🚀 Starting processing for file '{context.file_name}' ({current_file_idx + 1}/{total_files})",
+ )
+
+ # Update file execution status to EXECUTING when processing starts (using common method)
+ context.api_client.update_file_status_to_executing(
+ context.workflow_file_execution_id, context.file_name
+ )
+
+ try:
+ # Step 1: Check if file is already executed (cached)
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"🔍 Checking if '{context.file_name}' has been processed before",
+ )
+
+ cached_result = CachedFileHandler.handle_cached_file(context)
+ if cached_result and not context.is_api_workflow:
+ logger.info(f"Returning cached result for {context.file_name}")
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"⚡ File '{context.file_name}' already processed - Skipping processing",
+ )
+ return cached_result
+
+ if cached_result and context.is_api_workflow and context.use_file_history:
+ logger.info(f"Returning cached result for {context.file_name}")
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"⚡ File '{context.file_name}' already processed - using cached results",
+ )
+
+ # Cache the file history result as API result with clean metadata format
+ try:
+ api_cache_manager = get_api_cache_manager()
+ api_cache_manager.cache_file_history_result_for_api(
+ file_processing_result=cached_result,
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ file_hash=context.file_hash,
+ )
+ logger.info(
+ f"Successfully cached API result for file history file {context.file_name}"
+ )
+ except Exception as cache_error:
+ logger.warning(
+ f"Failed to cache API result for file history file {context.file_name}: {cache_error}"
+ )
+ # Continue execution - caching failure shouldn't stop processing
+
+ return cached_result
+
+ # Step 2: Validate workflow file execution
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"✅ Validating execution status for '{context.file_name}'",
+ )
+
+ completed_result = (
+ WorkflowFileExecutionHandler.validate_workflow_file_execution(context)
+ )
+ if completed_result:
+ logger.info(f"File already completed: {context.file_name}")
+ log_file_processing_success(
+ workflow_logger, workflow_file_execution_id, context.file_name
+ )
+ return completed_result
+
+ # Step 3: Check file history (if enabled)
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"📜 Checking processing history for '{context.file_name}'",
+ )
+
+ # Step 4: Execute workflow processing (always run tools first)
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"🚀 Starting tool execution for '{context.file_name}'",
+ )
+
+ workflow_result = WorkflowExecutionProcessor.execute_workflow_processing(
+ context
+ )
+
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"✅ Tool execution completed for '{context.file_name}'",
+ )
+
+ # Step 5: Tool execution completed - destination processing will handle routing
+ # Send appropriate completion log based on workflow result
+ if workflow_result.error:
+ log_file_processing_error(
+ workflow_logger,
+ workflow_file_execution_id,
+ context.file_name,
+ workflow_result.error,
+ )
+ else:
+ # Check if destination processing failed
+ destination_error = workflow_result.destination_error
+ destination_processed = workflow_result.destination_processed
+
+ if destination_error or not destination_processed:
+ # Log destination failure
+ error_msg = destination_error or "Destination processing failed"
+ log_file_error(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"❌ File '{context.file_name}' destination processing failed: {error_msg}",
+ )
+
+ # Update file execution status to ERROR
+ logger.info(
+ f"Updating file execution status to ERROR for {context.workflow_file_execution_id} due to destination failure"
+ )
+ try:
+ context.api_client.update_file_execution_status(
+ file_execution_id=context.workflow_file_execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=error_msg,
+ )
+ logger.info(
+ f"Updated file execution {context.workflow_file_execution_id} status to ERROR"
+ )
+ except Exception as status_error:
+ logger.error(
+ f"Failed to update file execution status: {status_error}"
+ )
+
+ # Update workflow result since destination failed
+ workflow_result.success = False
+ workflow_result.error = error_msg
+ else:
+ log_file_info(
+ workflow_logger,
+ workflow_file_execution_id,
+ f"✅ File '{context.file_name}' processing completed, preparing for destination routing",
+ )
+
+ # Return workflow results - destination processing will handle API caching and manual review routing
+ return workflow_result
+
+ except Exception as e:
+ logger.error(f"File processing failed for {context.file_name}: {e}")
+
+ # Send file processing error log to UI
+ log_file_processing_error(
+ workflow_logger, workflow_file_execution_id, context.file_name, str(e)
+ )
+
+ # Return error result
+ error_result = FileProcessingResult(
+ file_name=context.file_name,
+ file_execution_id=context.workflow_file_execution_id,
+ success=False,
+ error=str(e),
+ result=None,
+ metadata={"processing_failed": True},
+ execution_time=context.get_processing_duration(),
+ )
+
+ # Cache API error result for API workflows with clean metadata format
+ if context.is_api_workflow:
+ try:
+ api_cache_manager = get_api_cache_manager()
+ api_cache_manager.cache_error_result_for_api(
+ file_processing_result=error_result,
+ workflow_id=context.workflow_id,
+ execution_id=context.execution_id,
+ organization_id=context.organization_id,
+ file_hash=context.file_hash,
+ )
+ logger.info(
+ f"Successfully cached API error result for file {context.file_name}"
+ )
+ except Exception as cache_error:
+ logger.warning(
+ f"Failed to cache API error result for file {context.file_name}: {cache_error}"
+ )
+ # Continue execution - caching failure shouldn't stop processing
+
+ return error_result
diff --git a/workers/shared/processing/files/time_utils.py b/workers/shared/processing/files/time_utils.py
new file mode 100644
index 000000000..f04545527
--- /dev/null
+++ b/workers/shared/processing/files/time_utils.py
@@ -0,0 +1,207 @@
+"""Time calculation utilities for workflow execution timing."""
+
+import time
+from datetime import datetime
+from typing import Any
+
+import pytz
+from shared.api import InternalAPIClient
+from shared.infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WallClockTimeCalculator:
+ """Utility class to calculate wall-clock execution time with fallback strategies."""
+
+ @staticmethod
+ def calculate_execution_time(
+ api_client: InternalAPIClient,
+ execution_id: str,
+ organization_id: str,
+ fallback_results: list[dict[str, Any]] = None,
+ ) -> float:
+ """Calculate wall-clock execution time with multiple fallback strategies.
+
+ Args:
+ api_client: API client instance
+ execution_id: Workflow execution ID
+ organization_id: Organization context
+ fallback_results: List of file results for summing as fallback
+
+ Returns:
+ Execution time in seconds
+ """
+ try:
+ # Primary: Get workflow execution start time from backend
+ return WallClockTimeCalculator._get_wall_clock_time(
+ api_client, execution_id, organization_id
+ )
+ except Exception as e:
+ logger.error(f"Error calculating wall-clock time: {e}")
+ # Fallback: Sum individual file processing times
+ return WallClockTimeCalculator._get_fallback_time(fallback_results or [])
+
+ @staticmethod
+ def _get_wall_clock_time(
+ api_client: InternalAPIClient, execution_id: str, organization_id: str
+ ) -> float:
+ """Get wall-clock time from execution created_at timestamp."""
+ execution_response = api_client.get_workflow_execution(
+ execution_id, organization_id
+ )
+
+ if not (execution_response.success and execution_response.data):
+ raise ValueError("Failed to get execution data from API")
+
+ # Extract execution data from the nested structure
+ execution_data = execution_response.data.get("execution", {})
+ if not execution_data:
+ logger.error(
+ f"No 'execution' key in API response. Available keys: {list(execution_response.data.keys())}"
+ )
+ raise ValueError("No execution data found in API response")
+
+ # Get created_at from the execution data
+ created_at_str = execution_data.get("created_at")
+
+ if not created_at_str:
+ logger.error(
+ f"Missing timestamp field in API response. Available fields: {list(execution_response.data.keys())}"
+ )
+ # Don't raise error, let it fall back to file timing calculation
+ raise ValueError("No created_at timestamp found in execution data")
+
+ # Parse Django timestamp format
+ created_at = WallClockTimeCalculator._parse_django_timestamp(created_at_str)
+
+ # Calculate wall-clock execution time
+ now = datetime.now(pytz.UTC)
+ wall_clock_time = (now - created_at).total_seconds()
+
+ logger.info(f"✅ Wall-clock execution time: {wall_clock_time:.2f}s")
+ return wall_clock_time
+
+ @staticmethod
+ def _parse_django_timestamp(timestamp_str: str) -> datetime:
+ """Parse Django timestamp format with timezone handling."""
+ if timestamp_str.endswith("Z"):
+ # UTC format: "2024-01-01T12:00:00.123456Z"
+ return datetime.fromisoformat(timestamp_str[:-1]).replace(tzinfo=pytz.UTC)
+ else:
+ # Local format: "2024-01-01T12:00:00.123456"
+ dt = datetime.fromisoformat(timestamp_str)
+ if dt.tzinfo is None:
+ dt = dt.replace(tzinfo=pytz.UTC)
+ return dt
+
+ @staticmethod
+ def _get_fallback_time(file_results: list[dict[str, Any]]) -> float:
+ """Calculate fallback time by summing individual file processing times."""
+ if not file_results:
+ logger.warning(
+ "⚠️ No file results available for timing calculation, using default 30s"
+ )
+ return 30.0 # Reasonable default for pipeline execution
+
+ # Try different possible field names for processing time
+ fallback_time = 0.0
+ for file_result in file_results:
+ processing_time = (
+ file_result.get("processing_time", 0)
+ or file_result.get("execution_time", 0)
+ or file_result.get("duration", 0)
+ or file_result.get("time_taken", 0)
+ )
+ fallback_time += processing_time
+
+ if fallback_time <= 0.0:
+ # If still no timing data, use reasonable estimate based on file count
+ estimated_time = len(file_results) * 15.0 # ~15s per file estimate
+ logger.warning(
+ f"⚠️ No timing data in file results, estimating {estimated_time:.2f}s for {len(file_results)} files"
+ )
+ return estimated_time
+
+ logger.warning(f"⚠️ Using fallback sum of file times: {fallback_time:.2f}s")
+ return fallback_time
+
+
+def aggregate_file_batch_results(
+ file_batch_results: list[dict[str, Any]],
+) -> dict[str, Any]:
+ """Aggregate results from multiple file batches.
+
+ Args:
+ file_batch_results: List of file batch processing results
+
+ Returns:
+ Aggregated results summary
+ """
+ start_time = time.time()
+
+ total_files = 0
+ successful_files = 0
+ failed_files = 0
+ skipped_files = 0
+ total_execution_time = 0.0
+ all_file_results = []
+ errors = {}
+
+ for batch_result in file_batch_results:
+ if isinstance(batch_result, dict):
+ # Aggregate file counts - now total_files should be included from FileBatchResult.to_dict()
+ batch_total = batch_result.get("total_files", 0)
+ batch_successful = batch_result.get("successful_files", 0)
+ batch_failed = batch_result.get("failed_files", 0)
+ batch_skipped = batch_result.get("skipped_files", 0)
+
+ # If total_files is missing but we have successful+failed, calculate it
+ if batch_total == 0 and (batch_successful > 0 or batch_failed > 0):
+ batch_total = batch_successful + batch_failed + batch_skipped
+
+ total_files += batch_total
+ successful_files += batch_successful
+ failed_files += batch_failed
+ skipped_files += batch_skipped
+
+ # Aggregate execution times - now get from batch result directly
+ batch_time = batch_result.get("execution_time", 0)
+ file_results = batch_result.get("file_results", [])
+
+ # Fallback to individual file processing times if batch time not available
+ if batch_time == 0:
+ for file_result in file_results:
+ if isinstance(file_result, dict):
+ batch_time += file_result.get("processing_time", 0)
+
+ # Collect error information from file results
+ for file_result in file_results:
+ if isinstance(file_result, dict) and file_result.get("status") == "error":
+ file_name = file_result.get("file_name", "unknown")
+ error_msg = file_result.get("error", "Unknown error")
+ errors[file_name] = error_msg
+
+ total_execution_time += batch_time
+ all_file_results.extend(file_results)
+
+ aggregation_time = time.time() - start_time
+
+ aggregated_results = {
+ "total_files": total_files,
+ "successful_files": successful_files,
+ "failed_files": failed_files,
+ "skipped_files": skipped_files,
+ "total_execution_time": total_execution_time,
+ "aggregation_time": aggregation_time,
+ "success_rate": (successful_files / total_files) * 100 if total_files > 0 else 0,
+ "file_results": all_file_results,
+ "errors": errors,
+ "batches_processed": len(file_batch_results),
+ }
+
+ logger.info(
+ f"Aggregated {len(file_batch_results)} batches: {successful_files}/{total_files} successful files"
+ )
+
+ return aggregated_results
diff --git a/workers/shared/processing/files/utils.py b/workers/shared/processing/files/utils.py
new file mode 100644
index 000000000..a423b7e27
--- /dev/null
+++ b/workers/shared/processing/files/utils.py
@@ -0,0 +1,441 @@
+"""File Processing Utilities for Worker Tasks
+
+This module provides standardized file processing operations, batching,
+validation, and conversion utilities used across worker implementations.
+"""
+
+import time
+from typing import Any
+
+from unstract.core.data_models import FileHashData
+
+from ...infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class FileProcessingUtils:
+ """Centralized file processing operations and utilities."""
+
+ @staticmethod
+ def convert_file_hash_data(
+ hash_values_of_files: dict[str, Any] | None,
+ ) -> dict[str, FileHashData]:
+ """Standardized file hash conversion with comprehensive error handling.
+
+ Args:
+ hash_values_of_files: Raw file hash data from API
+
+ Returns:
+ Dictionary of converted FileHashData objects
+
+ Note:
+ This consolidates the repeated file conversion logic found across
+ api-deployment, general, and file_processing workers.
+ """
+ if not hash_values_of_files:
+ logger.warning("No file hash data provided for conversion")
+ return {}
+
+ converted_files = {}
+ conversion_errors = []
+
+ for file_key, file_data in hash_values_of_files.items():
+ try:
+ if isinstance(file_data, dict):
+ # Convert dictionary to FileHashData
+ converted_files[file_key] = FileHashData.from_dict(file_data)
+
+ elif isinstance(file_data, FileHashData):
+ # Already converted
+ converted_files[file_key] = file_data
+
+ else:
+ # Attempt manual conversion for other types
+ logger.warning(
+ f"Unexpected file data type for {file_key}: {type(file_data)}. "
+ "Attempting manual conversion."
+ )
+ converted_files[file_key] = FileHashData(
+ file_name=str(file_data),
+ file_path="", # Will be populated later
+ file_hash=file_key,
+ )
+
+ except Exception as e:
+ error_msg = f"Failed to convert file data for {file_key}: {e}"
+ logger.error(error_msg)
+ conversion_errors.append(error_msg)
+ continue
+
+ if conversion_errors:
+ logger.warning(
+ f"File conversion completed with {len(conversion_errors)} errors. "
+ f"Successfully converted {len(converted_files)} files."
+ )
+
+ return converted_files
+
+ @staticmethod
+ def create_file_batches(
+ files: dict[str, Any],
+ organization_id: str | None = None,
+ api_client=None,
+ batch_size_env_var: str = "MAX_PARALLEL_FILE_BATCHES",
+ default_batch_size: int = 1,
+ ) -> list[list[tuple[str, Any]]]:
+ """Standardized file batching algorithm used across workers with organization-specific config.
+
+ Args:
+ files: Dictionary of files to batch
+ organization_id: Organization ID for configuration lookup
+ api_client: Internal API client for configuration access
+ batch_size_env_var: Environment variable for batch size config (fallback)
+ default_batch_size: Default batch size if all else fails
+
+ Returns:
+ List of file batches, each batch is a list of (key, value) tuples
+
+ Note:
+ This consolidates the math.ceil batching logic found in
+ api-deployment and general workers, now with organization-specific configuration support.
+ """
+ if not files:
+ logger.warning("No files provided for batching")
+ return []
+
+ # Get batch size using internal API client (consistent with other worker operations)
+ batch_size = FileProcessingUtils._get_batch_size_via_api(
+ organization_id=organization_id,
+ api_client=api_client,
+ env_var_name=batch_size_env_var,
+ default_value=default_batch_size,
+ )
+
+ # Convert to list of items
+ file_items = list(files.items())
+ # calculate number of files
+ num_files = len(file_items)
+ # Target number of batches (can't exceed number of files)
+ num_batches = min(batch_size, num_files)
+
+ logger.info(
+ f"Arranging {num_files} files into {num_batches} batches "
+ f"(max_batch_size={batch_size})"
+ )
+
+ # Arrange files in batches
+ batches = FileProcessingUtils._arrange_files_in_batches(
+ file_items=file_items, num_files=num_files, num_batches=num_batches
+ )
+
+ return batches
+
+ @staticmethod
+ def _arrange_files_in_batches(
+ file_items: list[tuple[str, Any]],
+ num_files: int,
+ num_batches: int,
+ ) -> list[list[tuple[str, Any]]]:
+ """Arrange files in batches using round-robin distribution for even workload.
+
+ Distributes files evenly across batches in round-robin fashion to ensure
+ balanced workload, especially when files vary in size or complexity.
+
+ Note:
+ There is an optimization opportunity here to use weighted round-robin distribution
+ to balance large files with small files across batches for more even workload
+ distribution based on actual processing requirements rather than just file count.
+
+ Args:
+ file_items: List of file items to batch
+ num_files: Total number of files
+ num_batches: Number of batches to create
+
+ Returns:
+ List of file batches with files distributed evenly
+ """
+ # Initialize empty batches
+ batches = [[] for _ in range(num_batches)]
+
+ # Distribute files in round-robin fashion
+ for index, file_item in enumerate(file_items):
+ batch_index = index % num_batches
+ batches[batch_index].append(file_item)
+
+ # Remove any empty batches (shouldn't happen, but safety check)
+ batches = [batch for batch in batches if batch]
+
+ logger.info(
+ f"Created {len(batches)} batches from {num_files} files "
+ f"(round-robin distribution)"
+ )
+
+ return batches
+
+ @staticmethod
+ def validate_file_data(
+ file_data: Any, operation_name: str, required_fields: list[str] | None = None
+ ) -> dict[str, Any]:
+ """Common file validation logic with standardized error handling.
+
+ Args:
+ file_data: File data to validate
+ operation_name: Name of operation for logging context
+ required_fields: List of required field names
+
+ Returns:
+ Validated file data dictionary
+
+ Raises:
+ ValueError: If validation fails
+
+ Note:
+ This consolidates validation patterns found across multiple workers.
+ """
+ if not file_data:
+ raise ValueError(f"{operation_name}: No file data provided")
+
+ # Convert to dict if it's a FileHashData object
+ if isinstance(file_data, FileHashData):
+ file_dict = file_data.__dict__
+ elif isinstance(file_data, dict):
+ file_dict = file_data.copy()
+ else:
+ raise ValueError(
+ f"{operation_name}: Invalid file data type: {type(file_data)}"
+ )
+
+ # Validate required fields
+ if required_fields:
+ missing_fields = [
+ field for field in required_fields if not file_dict.get(field)
+ ]
+ if missing_fields:
+ raise ValueError(
+ f"{operation_name}: Missing required fields: {missing_fields}"
+ )
+
+ # Standardize file name handling
+ file_name = file_dict.get("file_name")
+ if not file_name or file_name == "unknown":
+ logger.warning(
+ f"{operation_name}: File missing or unknown name, "
+ f"generating timestamp-based name"
+ )
+ file_dict["file_name"] = f"unknown_file_{int(time.time())}"
+
+ # Validate execution ID
+ execution_id = file_dict.get("file_execution_id")
+ if not execution_id:
+ logger.warning(f"{operation_name}: File missing execution ID: {file_dict}")
+
+ return file_dict
+
+ @staticmethod
+ def extract_file_metadata(
+ files: dict[str, FileHashData], include_sensitive: bool = False
+ ) -> dict[str, dict[str, Any]]:
+ """Extract standardized metadata from file collection.
+
+ Args:
+ files: Dictionary of FileHashData objects
+ include_sensitive: Whether to include potentially sensitive data
+
+ Returns:
+ Dictionary of metadata per file
+
+ Note:
+ This provides consistent metadata extraction used in logging
+ and debugging across workers.
+ """
+ metadata = {}
+
+ for file_key, file_data in files.items():
+ file_metadata = {
+ "file_name": getattr(file_data, "file_name", "unknown"),
+ "file_size": getattr(file_data, "file_size", 0),
+ "file_type": getattr(file_data, "file_type", "unknown"),
+ "created_at": getattr(file_data, "created_at", None),
+ }
+
+ if include_sensitive:
+ file_metadata.update(
+ {
+ "file_path": getattr(file_data, "file_path", ""),
+ "file_hash": getattr(file_data, "file_hash", ""),
+ }
+ )
+
+ metadata[file_key] = file_metadata
+
+ return metadata
+
+ @staticmethod
+ def _get_batch_size_via_api(
+ organization_id: str | None = None,
+ api_client=None,
+ env_var_name: str = "MAX_PARALLEL_FILE_BATCHES",
+ default_value: int = 1,
+ ) -> int:
+ """Get batch size using internal API client (unified approach).
+
+ This replaces the complex infrastructure config client with direct API calls,
+ maintaining the same fallback behavior as the backend Configuration.get_value_by_organization().
+
+ Args:
+ organization_id: Organization ID for configuration lookup
+ api_client: Internal API client for configuration access
+ env_var_name: Environment variable for batch size config (fallback)
+ default_value: Default batch size if all else fails
+
+ Returns:
+ Batch size (guaranteed to be >= 1)
+ """
+ # Try organization-specific configuration via internal API
+ if api_client and organization_id:
+ try:
+ response = api_client.get_configuration(
+ config_key=env_var_name,
+ organization_id=organization_id,
+ )
+
+ if (
+ response.get("success")
+ and response.get("data", {}).get("value") is not None
+ ):
+ config_value = int(response["data"]["value"])
+ if config_value >= 1:
+ logger.info(
+ f"Using organization configuration for {organization_id} {env_var_name}: {config_value}"
+ )
+ return config_value
+
+ except Exception as e:
+ logger.warning(f"Failed to get organization config, falling back: {e}")
+
+ # Fall back to environment variable
+ import os
+
+ try:
+ env_value = int(os.getenv(env_var_name, str(default_value)))
+ if env_value >= 1:
+ logger.info(f"Using environment variable {env_var_name}: {env_value}")
+ return env_value
+ except (ValueError, TypeError):
+ logger.warning(f"Invalid {env_var_name} environment variable")
+
+ # Final fallback to backend default (matching backend logic)
+ try:
+ final_value = int(os.getenv(env_var_name, str(default_value)))
+ final_value = max(1, final_value)
+ logger.info(f"Using final environment fallback: {final_value}")
+ return final_value
+ except (ValueError, TypeError):
+ logger.info(f"Using absolute fallback: {default_value}")
+ return 1
+
+ @staticmethod
+ def create_file_processing_summary(
+ total_files: int,
+ successful_files: int,
+ failed_files: int,
+ skipped_files: int = 0,
+ duration_seconds: float | None = None,
+ ) -> str:
+ """Create standardized file processing summary string.
+
+ Args:
+ total_files: Total number of files processed
+ successful_files: Number of successfully processed files
+ failed_files: Number of failed files
+ skipped_files: Number of skipped files
+ duration_seconds: Optional processing duration
+
+ Returns:
+ Formatted summary string
+
+ Note:
+ This provides consistent result reporting across all workers.
+ """
+ summary_parts = [
+ f"total={total_files}",
+ f"success={successful_files}",
+ f"failed={failed_files}",
+ ]
+
+ if skipped_files > 0:
+ summary_parts.append(f"skipped={skipped_files}")
+
+ if duration_seconds is not None:
+ summary_parts.append(f"duration={duration_seconds:.2f}s")
+
+ success_rate = (successful_files / total_files * 100) if total_files > 0 else 0
+ summary_parts.append(f"success_rate={success_rate:.1f}%")
+
+ return " - ".join(summary_parts)
+
+ @staticmethod
+ def handle_file_format_variations(
+ files_data: dict | list | tuple | Any,
+ ) -> dict[str, Any]:
+ """Handle various file data format variations found across workers.
+
+ Args:
+ files_data: File data in various possible formats
+
+ Returns:
+ Normalized dictionary format
+
+ Note:
+ This consolidates the complex file format handling found in
+ file_processing worker's _process_individual_files method.
+ """
+ if isinstance(files_data, dict):
+ return files_data
+
+ elif isinstance(files_data, (list, tuple)):
+ # Convert list/tuple to dict with index as key
+ normalized = {}
+ for i, item in enumerate(files_data):
+ if isinstance(item, dict):
+ # Use file_name as key if available, otherwise use index
+ key = item.get("file_name", f"file_{i}")
+ normalized[key] = item
+ else:
+ normalized[f"file_{i}"] = {"file_data": item}
+ return normalized
+
+ else:
+ # Single item - wrap in dict
+ logger.warning(
+ f"Unexpected file data type: {type(files_data)}. "
+ "Wrapping as single file."
+ )
+ return {"single_file": {"file_data": files_data}}
+
+
+class FileProcessingMixin:
+ """Mixin class to add file processing utilities to worker tasks."""
+
+ def convert_files(
+ self, hash_values_of_files: dict[str, Any] | None
+ ) -> dict[str, FileHashData]:
+ """Convert file hash data using standardized logic."""
+ return FileProcessingUtils.convert_file_hash_data(hash_values_of_files)
+
+ def create_batches(
+ self, files: dict[str, Any], **kwargs
+ ) -> list[list[tuple[str, Any]]]:
+ """Create file batches using standardized algorithm."""
+ return FileProcessingUtils.create_file_batches(files, **kwargs)
+
+ def validate_file(
+ self, file_data: Any, operation_name: str, **kwargs
+ ) -> dict[str, Any]:
+ """Validate file data using standardized logic."""
+ return FileProcessingUtils.validate_file_data(file_data, operation_name, **kwargs)
+
+ def create_summary(self, **kwargs) -> str:
+ """Create processing summary using standardized format."""
+ return FileProcessingUtils.create_file_processing_summary(**kwargs)
diff --git a/workers/shared/processing/filter_pipeline.py b/workers/shared/processing/filter_pipeline.py
new file mode 100644
index 000000000..a02b955df
--- /dev/null
+++ b/workers/shared/processing/filter_pipeline.py
@@ -0,0 +1,809 @@
+"""Filter Pipeline for File Processing
+
+This module provides a composable filter pipeline that applies multiple filters
+to file batches efficiently. Moved to shared/processing to avoid circular imports.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any
+
+from unstract.core.data_models import ExecutionStatus, FileHashData
+
+from ..api.internal_client import InternalAPIClient
+from ..cache.cache_backends import RedisCacheBackend
+from ..infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class FileFilter(ABC):
+ """Abstract base class for file filters."""
+
+ @abstractmethod
+ def apply(
+ self,
+ files: dict[str, FileHashData],
+ context: dict[str, Any],
+ ) -> dict[str, FileHashData]:
+ """Apply filter to a batch of files.
+
+ Args:
+ files: Dictionary of files to filter
+ context: Context containing workflow_id, execution_id, api_client, etc.
+
+ Returns:
+ Filtered dictionary of files
+ """
+ pass
+
+ @abstractmethod
+ def get_name(self) -> str:
+ """Get the name of this filter for logging."""
+ pass
+
+
+class DeduplicationFilter(FileFilter):
+ """Filter to remove duplicate files within the current discovery session."""
+
+ def __init__(self):
+ self.seen_files: set[tuple[str | None, str]] = (
+ set()
+ ) # (provider_file_uuid, file_path)
+
+ def apply(
+ self,
+ files: dict[str, FileHashData],
+ context: dict[str, Any],
+ ) -> dict[str, FileHashData]:
+ """Remove duplicate files based on composite key (provider_uuid, path)."""
+ filtered = {}
+
+ for file_path, file_hash in files.items():
+ # Create composite key (provider_file_uuid, file_path)
+ composite_key = (file_hash.provider_file_uuid, file_path)
+
+ # Check for duplicate composite key
+ if composite_key in self.seen_files:
+ continue
+
+ # Add composite key to seen set
+ self.seen_files.add(composite_key)
+
+ filtered[file_path] = file_hash
+
+ logger.debug(
+ f"[DeduplicationFilter] {len(files)} → {len(filtered)} files "
+ f"({len(files) - len(filtered)} duplicates removed)"
+ )
+
+ return filtered
+
+ def get_name(self) -> str:
+ return "DeduplicationFilter"
+
+
+class FileHistoryFilter(FileFilter):
+ """Filter files based on file history (already processed files)."""
+
+ def __init__(self, use_file_history: bool = True):
+ self.use_file_history = use_file_history
+ self._cache: dict[str, bool] = {} # Cache results to avoid duplicate API calls
+
+ @staticmethod
+ def _create_file_identifier(provider_file_uuid: str, file_path: str) -> str:
+ """Create unique identifier for file in batch operations.
+
+ Args:
+ provider_file_uuid: Provider file UUID
+ file_path: File path
+
+ Returns:
+ Composite identifier in format 'uuid:path'
+ """
+ return f"{provider_file_uuid}:{file_path}"
+
+ @staticmethod
+ def _create_cache_key(
+ workflow_id: str, provider_file_uuid: str, file_path: str
+ ) -> str:
+ """Create composite cache key for file history caching.
+
+ Args:
+ workflow_id: Workflow ID
+ provider_file_uuid: Provider file UUID
+ file_path: File path
+
+ Returns:
+ Composite cache key in format 'workflow_id:uuid:path'
+ """
+ return f"{workflow_id}:{provider_file_uuid}:{file_path}"
+
+ def apply(
+ self,
+ files: dict[str, FileHashData],
+ context: dict[str, Any],
+ ) -> dict[str, FileHashData]:
+ """Filter out files that have already been processed."""
+ if not self.use_file_history:
+ return files
+
+ workflow_id = context.get("workflow_id")
+ organization_id = context.get("organization_id")
+ api_client: InternalAPIClient = context.get("api_client")
+
+ if not all([workflow_id, organization_id, api_client]):
+ logger.warning(
+ "[FileHistoryFilter] Missing required context, skipping filter"
+ )
+ return files
+
+ filtered = {}
+
+ # Batch check for efficiency (collect composite identifiers to avoid UUID collisions)
+ identifiers_to_check = []
+ identifier_to_data = {}
+
+ for file_path, file_hash in files.items():
+ if file_hash.provider_file_uuid:
+ # Check cache first using composite key helper method
+ cache_key = self._create_cache_key(
+ workflow_id, file_hash.provider_file_uuid, file_path
+ )
+ if cache_key in self._cache:
+ if not self._cache[cache_key]: # False means not processed
+ filtered[file_path] = file_hash
+ else:
+ # Use composite identifier to avoid UUID collision with different paths
+ identifier = self._create_file_identifier(
+ file_hash.provider_file_uuid, file_path
+ )
+ identifiers_to_check.append(identifier)
+ identifier_to_data[identifier] = {
+ "uuid": file_hash.provider_file_uuid,
+ "path": file_path,
+ "file_hash": file_hash,
+ }
+ else:
+ # Files without UUID are always included
+ filtered[file_path] = file_hash
+
+ # Process uncached identifiers in smaller batches for better performance
+ if identifiers_to_check:
+ logger.info(
+ f"[FileHistoryFilter] Checking history for {len(identifiers_to_check)} files"
+ )
+
+ # Process all files and collect results using composite identifiers
+ self._process_file_history_batch(
+ identifiers_to_check=identifiers_to_check,
+ identifier_to_data=identifier_to_data,
+ filtered=filtered,
+ workflow_id=workflow_id,
+ organization_id=organization_id,
+ api_client=api_client,
+ )
+
+ logger.info(
+ f"[FileHistoryFilter] {len(files)} → {len(filtered)} files "
+ f"({len(files) - len(filtered)} already processed)"
+ )
+
+ return filtered
+
+ def _process_file_history_batch(
+ self,
+ identifiers_to_check: list[str],
+ identifier_to_data: dict[str, dict[str, Any]],
+ filtered: dict[str, FileHashData],
+ workflow_id: str,
+ organization_id: str,
+ api_client: InternalAPIClient,
+ ) -> None:
+ """Process file history checks for a batch of composite identifiers using optimized batch API.
+
+ This method uses the new batch file history API to check multiple files
+ in a single database query, dramatically improving performance.
+
+ Args:
+ identifiers_to_check: List of composite identifiers (uuid:path format)
+ identifier_to_data: Mapping of identifiers to file data {uuid, path, file_hash}
+ """
+ try:
+ # Prepare batch request data with composite identifiers (already unique)
+ batch_files = []
+ for identifier in identifiers_to_check:
+ data = identifier_to_data[identifier]
+ batch_files.append(
+ {
+ "provider_file_uuid": data["uuid"],
+ "file_path": data["path"],
+ "identifier": identifier, # Use composite identifier for response mapping
+ }
+ )
+
+ logger.info(
+ f"[FileHistoryFilter] Making batch API call for {len(batch_files)} files"
+ )
+
+ # Single batch API call instead of N individual calls
+ batch_response = api_client.get_files_history_batch(
+ workflow_id=workflow_id,
+ files=batch_files,
+ organization_id=organization_id,
+ )
+
+ logger.info(
+ f"[FileHistoryFilter] Batch API response received for {len(batch_response)} files"
+ )
+
+ # Process batch response using composite identifiers (no UUID collision!)
+ for identifier in identifiers_to_check:
+ data = identifier_to_data[identifier]
+ uuid = data["uuid"]
+ file_path = data["path"]
+ file_hash = data["file_hash"]
+
+ # Get response for this file using composite identifier (guaranteed unique)
+ file_result = batch_response.get(
+ identifier, {"found": False, "is_completed": False}
+ )
+
+ logger.info(
+ f"FileHistoryFilter - Batch API response for {file_hash.file_name} (ID: {identifier}): "
+ f"found={file_result.get('found', False)}, is_completed={file_result.get('is_completed', False)}"
+ )
+
+ # Determine if file should be processed using batch result
+ is_processed = self._evaluate_batch_file_history(
+ file_result=file_result,
+ file_hash=file_hash,
+ file_path=file_path,
+ )
+
+ # Cache result using composite key helper method
+ cache_key = self._create_cache_key(workflow_id, uuid, file_path)
+ self._cache[cache_key] = is_processed
+
+ # Add to filtered if not processed
+ if not is_processed:
+ filtered[file_path] = file_hash
+
+ except Exception as e:
+ logger.error(
+ f"FileHistoryFilter - Error processing batch file history: {e}",
+ exc_info=True,
+ )
+ raise e
+
+ def _evaluate_file_history(
+ self,
+ history_response,
+ file_hash: FileHashData,
+ file_path: str,
+ ) -> bool:
+ """Evaluate if a file should be considered as already processed.
+
+ Returns:
+ True if file should be skipped (already processed), False if should be processed
+ """
+ if (
+ not history_response
+ or not history_response.success
+ or not history_response.found
+ ):
+ return False
+
+ file_history = history_response.file_history
+ if not file_history:
+ logger.warning(
+ f"FileHistoryFilter - {file_hash.file_name}: Found=True but no file_history data!"
+ )
+ return False
+
+ # Check using proper status-based logic instead of just is_completed
+ status = file_history.get("status", "UNKNOWN")
+ is_completed = file_history.get("is_completed", False)
+
+ logger.info(
+ f"FileHistoryFilter - Evaluating {file_hash.file_name} "
+ f"(UUID: {file_hash.provider_file_uuid}): found=True, is_completed={is_completed}, status={status}"
+ )
+
+ # Import ExecutionStatus for proper status checking
+
+ # Check if file should be skipped based on status
+ try:
+ if status in [
+ ExecutionStatus.EXECUTING.value,
+ ExecutionStatus.PENDING.value,
+ ExecutionStatus.COMPLETED.value,
+ ]:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: Status check: SKIP "
+ f"(status={status} is in skip-processing list)"
+ )
+ else:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: Status check: ACCEPT "
+ f"(status={status} allows reprocessing)"
+ )
+ return False
+ except Exception as e:
+ logger.warning(f"FileHistoryFilter - Error checking status {status}: {e}")
+ # Fallback to original is_completed logic if status checking fails
+ if not is_completed:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: ACCEPT "
+ f"(fallback: history exists but not completed, status={status})"
+ )
+ return False
+
+ # If we reach here, should_skip is True (status is in skip list)
+ # Now check path matching - only skip if paths match
+ history_path = file_history.get("file_path")
+
+ if history_path == file_path:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: SKIP "
+ f"(status={status} requires skip and same path: {file_path})"
+ )
+ return True
+ else:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: ACCEPT "
+ f"(status={status} but different path: {history_path} vs {file_path})"
+ )
+ return False
+
+ def _evaluate_batch_file_history(
+ self,
+ file_result: dict[str, Any],
+ file_hash: FileHashData,
+ file_path: str,
+ ) -> bool:
+ """Evaluate if a file should be considered as already processed using batch API result.
+
+ Args:
+ file_result: Result from batch API call
+ file_hash: FileHashData object
+ file_path: File path
+
+ Returns:
+ True if file should be skipped (already processed), False if should be processed
+ """
+ # Enhanced debug logging to trace evaluation flow
+ found = file_result.get("found", False)
+ is_completed = file_result.get("is_completed", False)
+ file_history = file_result.get("file_history", {})
+
+ logger.info(
+ f"FileHistoryFilter - Evaluating {file_hash.file_name} "
+ f"(UUID: {file_hash.provider_file_uuid}): found={found}, is_completed={is_completed}"
+ )
+
+ if not found:
+ return False
+
+ # Extract detailed status information from file history
+ if file_history:
+ status = file_history.get("status", "UNKNOWN")
+ history_path = file_history.get("file_path")
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: History details: "
+ f"status={status}, path={history_path}, current_path={file_path}"
+ )
+ else:
+ logger.warning(
+ f"FileHistoryFilter - {file_hash.file_name}: Found=True but no file_history data!"
+ )
+
+ # Check using proper status-based logic instead of just is_completed
+ status = (
+ file_history.get("status", "UNKNOWN") if file_history else "NO_HISTORY_DATA"
+ )
+
+ # Import ExecutionStatus for proper status checking
+
+ # Check if file should be skipped based on status
+ try:
+ if status in [
+ ExecutionStatus.EXECUTING.value,
+ ExecutionStatus.PENDING.value,
+ ExecutionStatus.COMPLETED.value,
+ ]:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: SKIP "
+ f"(status={status} is in skip-processing list)"
+ )
+ else:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: ACCEPT "
+ f"(status={status} allows reprocessing)"
+ )
+ return False
+ except Exception as e:
+ logger.warning(f"FileHistoryFilter - Error checking status {status}: {e}")
+ # Fallback to original is_completed logic if status checking fails
+ if not is_completed:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: ACCEPT "
+ f"(fallback: history exists but not completed, status={status})"
+ )
+ return False
+
+ # Now check path matching - only skip if paths match
+ history_path = file_history.get("file_path") if file_history else None
+
+ if history_path == file_path:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: SKIP "
+ f"(status={status} requires skip and same path: {file_path})"
+ )
+ return True
+ else:
+ logger.info(
+ f"FileHistoryFilter - {file_hash.file_name}: ACCEPT "
+ f"(status={status} but different path: {history_path} vs {file_path})"
+ )
+ return False
+
+ def _process_file_history_individual(
+ self,
+ identifiers_to_check: list[str],
+ identifier_to_data: dict[str, dict[str, Any]],
+ filtered: dict[str, FileHashData],
+ workflow_id: str,
+ organization_id: str,
+ api_client: InternalAPIClient,
+ ) -> None:
+ """Fallback method for individual file history checks when batch API fails.
+
+ This method processes files one by one using the original individual API calls.
+ Used as a backup when the batch API is unavailable or fails.
+
+ Args:
+ identifiers_to_check: List of composite identifiers (uuid:path format)
+ identifier_to_data: Mapping of identifiers to file data {uuid, path, file_hash}
+ """
+ logger.info(
+ f"[FileHistoryFilter] Processing {len(identifiers_to_check)} files individually (fallback mode)"
+ )
+
+ for identifier in identifiers_to_check:
+ data = identifier_to_data[identifier]
+ uuid = data["uuid"]
+ file_path = data["path"]
+ file_hash = data["file_hash"]
+
+ try:
+ # Check file history via individual API call
+ history_response = api_client.get_file_history(
+ workflow_id=workflow_id,
+ provider_file_uuid=uuid,
+ file_path=file_path,
+ organization_id=organization_id,
+ )
+
+ logger.info(
+ f"FileHistoryFilter - Individual API response for {file_hash.file_name}: "
+ f"success={history_response.success if history_response else 'None'}"
+ )
+
+ # Determine if file should be processed
+ is_processed = self._evaluate_file_history(
+ history_response=history_response,
+ file_hash=file_hash,
+ file_path=file_path,
+ )
+
+ # Cache result using composite key helper method
+ cache_key = self._create_cache_key(workflow_id, uuid, file_path)
+ self._cache[cache_key] = is_processed
+
+ # Add to filtered if not processed
+ if not is_processed:
+ filtered[file_path] = file_hash
+
+ except Exception as e:
+ logger.warning(
+ f"[FileHistoryFilter] Error checking individual history for {uuid}: {e}"
+ )
+ # On error, include the file (fail-safe approach)
+ filtered[file_path] = file_hash
+
+ def get_name(self) -> str:
+ return "FileHistoryFilter"
+
+
+class ActiveFileFilter(FileFilter):
+ """Filter files that are currently being processed by other executions."""
+
+ def __init__(self):
+ self._cache_checked: set[str] = (
+ set()
+ ) # Track composite identifiers we've already checked
+
+ @staticmethod
+ def _create_file_identifier(provider_file_uuid: str, file_path: str) -> str:
+ """Create unique identifier for file in active checking.
+
+ Args:
+ provider_file_uuid: Provider file UUID
+ file_path: File path
+
+ Returns:
+ Composite identifier in format 'uuid:path'
+ """
+ return f"{provider_file_uuid}:{file_path}"
+
+ def apply(
+ self,
+ files: dict[str, FileHashData],
+ context: dict[str, Any],
+ ) -> dict[str, FileHashData]:
+ """Filter out files being processed by other executions."""
+ workflow_id = context.get("workflow_id")
+ execution_id = context.get("execution_id")
+ api_client = context.get("api_client")
+
+ if not all([workflow_id, execution_id, api_client]):
+ logger.warning("[ActiveFileFilter] Missing required context, skipping filter")
+ return files
+
+ # Extract file identifiers for batch checking (avoid UUID collision)
+ file_identifiers = {} # identifier -> {uuid, path, file_hash}
+ for file_path, file_hash in files.items():
+ if file_hash.provider_file_uuid:
+ identifier = self._create_file_identifier(
+ file_hash.provider_file_uuid, file_path
+ )
+ file_identifiers[identifier] = {
+ "uuid": file_hash.provider_file_uuid,
+ "path": file_path,
+ "file_hash": file_hash,
+ }
+
+ if not file_identifiers:
+ logger.info("ActiveFileFilter - No files with provider_uuid, accepting all")
+ return files
+
+ # Batch check active files (cache + database) using composite identifiers
+ active_identifiers = self._check_active_files_batch(
+ file_identifiers=file_identifiers,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ api_client=api_client,
+ )
+
+ # Filter out active files using composite identifier matching
+ filtered = {}
+ for identifier, data in file_identifiers.items():
+ file_hash = data["file_hash"]
+ file_path = data["path"]
+
+ if identifier in active_identifiers:
+ # Skip active files
+ pass
+ else:
+ filtered[file_path] = file_hash
+
+ # Also include files without provider_file_uuid (they were not in file_identifiers)
+ for file_path, file_hash in files.items():
+ if not file_hash.provider_file_uuid and file_path not in filtered:
+ filtered[file_path] = file_hash
+
+ logger.info(
+ f"[ActiveFileFilter] {len(files)} → {len(filtered)} files "
+ f"({len(active_identifiers)} currently active)"
+ )
+
+ return filtered
+
+ def _check_active_files_batch(
+ self,
+ file_identifiers: dict[str, dict[str, Any]],
+ workflow_id: str,
+ execution_id: str,
+ api_client, # Removed type hint to avoid import
+ ) -> set[str]:
+ """Check which files are currently active (cache + database) using composite identifiers.
+
+ Args:
+ file_identifiers: Dict mapping composite identifiers to file data
+
+ Returns:
+ Set of composite identifiers that are currently active
+ """
+ active_identifiers = set()
+
+ # Filter out already checked identifiers
+ identifiers_to_check = [
+ identifier
+ for identifier in file_identifiers.keys()
+ if identifier not in self._cache_checked
+ ]
+
+ if not identifiers_to_check:
+ return active_identifiers
+
+ # 1. Check Redis cache for active files using precise cache keys
+ try:
+ cache = RedisCacheBackend()
+ for identifier in identifiers_to_check:
+ data = file_identifiers[identifier]
+ uuid = data["uuid"]
+ file_path = data["path"]
+
+ # Create precise cache key instead of pattern matching
+ cache_key = f"file_active:{workflow_id}:{uuid}:{file_path}"
+ cached_data = cache.get(cache_key)
+
+ if cached_data and isinstance(cached_data, dict):
+ cached_exec_id = cached_data.get("execution_id")
+ if cached_exec_id and cached_exec_id != execution_id:
+ active_identifiers.add(identifier)
+ logger.debug(
+ f"[ActiveFileFilter] File {identifier} active in cache (exec: {cached_exec_id})"
+ )
+ except Exception as e:
+ logger.warning(f"[ActiveFileFilter] Cache check failed: {e}")
+
+ # 2. Check database for active files (single batch API call)
+ try:
+ # Prepare composite file information for the API call
+ files_for_api = []
+ for identifier in identifiers_to_check:
+ data = file_identifiers[identifier]
+ files_for_api.append({"uuid": data["uuid"], "path": data["path"]})
+
+ response = api_client.check_files_active_processing(
+ workflow_id=workflow_id,
+ files=files_for_api,
+ current_execution_id=execution_id,
+ )
+
+ if response.success and response.data:
+ # Backend returns: {"active_files": {uuid: [exec_data]}, "active_uuids": [uuid1, uuid2], "active_identifiers": ["uuid:path"]}
+ # Use the new composite identifiers if available, fallback to legacy format
+ active_composite_ids = response.data.get("active_identifiers", [])
+ if active_composite_ids:
+ # New path-aware format
+ logger.debug(
+ f"[ActiveFileFilter] Backend reported {len(active_composite_ids)} active identifiers: {active_composite_ids}"
+ )
+ for composite_id in active_composite_ids:
+ if composite_id in identifiers_to_check:
+ active_identifiers.add(composite_id)
+ logger.debug(
+ f"[ActiveFileFilter] File {composite_id} active in database"
+ )
+ else:
+ # Fallback to legacy format
+ active_uuids = response.data.get("active_uuids", [])
+ logger.debug(
+ f"[ActiveFileFilter] Backend reported {len(active_uuids)} active UUIDs (legacy): {active_uuids}"
+ )
+
+ # Map back to identifiers
+ for identifier in identifiers_to_check:
+ data = file_identifiers[identifier]
+ uuid = data["uuid"]
+
+ if uuid in active_uuids:
+ active_identifiers.add(identifier)
+ logger.debug(
+ f"[ActiveFileFilter] File {identifier} active in database (legacy mapping)"
+ )
+ except Exception as e:
+ logger.warning(f"[ActiveFileFilter] Database check failed: {e}")
+
+ # Mark these identifiers as checked
+ self._cache_checked.update(identifiers_to_check)
+
+ return active_identifiers
+
+ def get_name(self) -> str:
+ return "ActiveFileFilter"
+
+
+class FilterPipeline:
+ """Composable pipeline of file filters."""
+
+ def __init__(self, filters: list[FileFilter] | None = None):
+ """Initialize filter pipeline.
+
+ Args:
+ filters: List of filters to apply in order
+ """
+ self.filters = filters or []
+ logger.info(
+ f"[FilterPipeline] Initialized with {len(self.filters)} filters: "
+ f"{[f.get_name() for f in self.filters]}"
+ )
+
+ def add_filter(self, filter: FileFilter) -> None:
+ """Add a filter to the pipeline."""
+ self.filters.append(filter)
+ logger.debug(f"[FilterPipeline] Added filter: {filter.get_name()}")
+
+ def apply_filters(
+ self,
+ files: dict[str, FileHashData],
+ workflow_id: str,
+ execution_id: str,
+ api_client, # Removed type hint to avoid import
+ organization_id: str | None = None,
+ ) -> dict[str, FileHashData]:
+ """Apply all filters in the pipeline to the files.
+
+ Args:
+ files: Dictionary of files to filter
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ api_client: API client for backend calls
+ organization_id: Organization ID
+
+ Returns:
+ Filtered dictionary of files
+ """
+ if not self.filters:
+ return files
+
+ # Build context for filters
+ context = {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "api_client": api_client,
+ "organization_id": organization_id,
+ }
+
+ filtered = files
+ initial_count = len(files)
+
+ # Apply each filter in sequence
+ for filter in self.filters:
+ if not filtered: # Early exit if no files left
+ break
+
+ before_count = len(filtered)
+ filtered = filter.apply(filtered, context)
+ after_count = len(filtered)
+
+ if before_count != after_count:
+ logger.debug(
+ f"[FilterPipeline] {filter.get_name()}: {before_count} → {after_count} files"
+ )
+
+ if initial_count != len(filtered):
+ logger.info(
+ f"[FilterPipeline] Total filtering: {initial_count} → {len(filtered)} files "
+ f"({initial_count - len(filtered)} filtered out)"
+ )
+
+ return filtered
+
+
+def create_standard_pipeline(
+ use_file_history: bool = True,
+ enable_active_filtering: bool = True,
+) -> FilterPipeline:
+ """Create a standard filter pipeline with common filters.
+
+ Args:
+ use_file_history: Whether to use file history filtering
+ enable_active_filtering: Whether to filter active files
+
+ Returns:
+ Configured FilterPipeline
+ """
+ filters = [
+ DeduplicationFilter(), # Always remove duplicates
+ ]
+
+ if use_file_history:
+ filters.append(FileHistoryFilter(use_file_history=True))
+
+ if enable_active_filtering:
+ filters.append(ActiveFileFilter())
+
+ return FilterPipeline(filters=filters)
diff --git a/workers/shared/processing/types/__init__.py b/workers/shared/processing/types/__init__.py
new file mode 100644
index 000000000..e4b3b70de
--- /dev/null
+++ b/workers/shared/processing/types/__init__.py
@@ -0,0 +1,12 @@
+"""Type conversion and processing utilities.
+
+This package provides type conversion utilities following
+the Single Responsibility Principle.
+"""
+
+from .converter import FileDataValidator, TypeConverter
+
+__all__ = [
+ "TypeConverter",
+ "FileDataValidator",
+]
diff --git a/workers/shared/processing/types/converter.py b/workers/shared/processing/types/converter.py
new file mode 100644
index 000000000..afd0e73b4
--- /dev/null
+++ b/workers/shared/processing/types/converter.py
@@ -0,0 +1,333 @@
+"""Type Utilities for Workers
+
+This module provides type checking, validation, and conversion utilities
+for consistent handling of data types across all worker modules.
+"""
+
+import logging
+import os
+from datetime import date, datetime, time
+from typing import Any
+from uuid import UUID
+
+from unstract.core.data_models import FileHashData
+
+logger = logging.getLogger(__name__)
+
+
+class TypeConverter:
+ """Utility class for type conversion and validation across workers."""
+
+ @staticmethod
+ def ensure_file_dict_format(
+ input_files: dict[str, FileHashData] | list[dict] | dict[str, dict],
+ ) -> dict[str, FileHashData]:
+ """Convert various input formats to the standard Dict[str, FileHashData] format.
+
+ Args:
+ input_files: Files in various formats (dict, list, etc.)
+
+ Returns:
+ Dictionary with file names as keys and FileHashData objects as values
+
+ Raises:
+ TypeError: If input format is not supported
+ """
+ if isinstance(input_files, dict):
+ # Check if values are already FileHashData objects
+ if input_files and isinstance(next(iter(input_files.values())), FileHashData):
+ return input_files
+
+ # Convert dict of dicts to dict of FileHashData objects
+ result = {}
+ for file_name, file_data in input_files.items():
+ if isinstance(file_data, dict):
+ result[file_name] = TypeConverter.dict_to_file_hash_data(file_data)
+ elif isinstance(file_data, FileHashData):
+ result[file_name] = file_data
+ # FileHash is deprecated - only FileHashData should be used
+ else:
+ logger.error(
+ f"Unsupported file data type for '{file_name}': {type(file_data)}"
+ )
+ continue
+ return result
+
+ elif isinstance(input_files, list):
+ # Convert list to dict format
+ result = {}
+ for file_data in input_files:
+ if isinstance(file_data, dict):
+ file_name = file_data.get("file_name", f"file_{len(result)}")
+ # Handle duplicate file names
+ if file_name in result:
+ file_name = TypeConverter._make_unique_filename(file_name, result)
+ result[file_name] = TypeConverter.dict_to_file_hash_data(file_data)
+ elif isinstance(file_data, FileHashData):
+ file_name = file_data.file_name
+ if file_name in result:
+ file_name = TypeConverter._make_unique_filename(file_name, result)
+ result[file_name] = file_data
+ else:
+ logger.error(f"Unsupported file data type in list: {type(file_data)}")
+ continue
+ return result
+
+ else:
+ raise TypeError(f"Unsupported input_files type: {type(input_files)}")
+
+ @staticmethod
+ def dict_to_file_hash_data(file_dict: dict[str, Any]) -> FileHashData:
+ """Convert a dictionary to FileHashData object safely.
+
+ Args:
+ file_dict: Dictionary with file data
+
+ Returns:
+ FileHashData object
+ """
+ try:
+ # Try using the from_dict method if available
+ if hasattr(FileHashData, "from_dict"):
+ return FileHashData.from_dict(file_dict)
+
+ # Manual creation as fallback
+ return FileHashData(
+ file_name=file_dict.get("file_name", "unknown.txt"),
+ file_path=file_dict.get("file_path", ""),
+ file_hash=file_dict.get("file_hash", ""),
+ file_size=file_dict.get("file_size", 0),
+ mime_type=file_dict.get("mime_type", ""),
+ provider_file_uuid=TypeConverter.serialize_uuid(
+ file_dict.get("provider_file_uuid")
+ ),
+ fs_metadata=file_dict.get("fs_metadata", {}),
+ source_connection_type=file_dict.get("source_connection_type"),
+ file_destination=file_dict.get("file_destination"),
+ is_executed=file_dict.get("is_executed", False),
+ file_number=file_dict.get("file_number"),
+ connector_metadata=file_dict.get("connector_metadata", {}),
+ connector_id=file_dict.get("connector_id"),
+ )
+ except Exception as e:
+ logger.error(f"Failed to convert dict to FileHashData: {e}")
+ # Return minimal valid FileHashData
+ return FileHashData(
+ file_name=file_dict.get("file_name", "unknown.txt"),
+ file_path=file_dict.get("file_path", ""),
+ file_hash="",
+ file_size=0,
+ mime_type="application/octet-stream",
+ connector_metadata=file_dict.get("connector_metadata", {}),
+ connector_id=file_dict.get("connector_id"),
+ )
+
+ @staticmethod
+ def serialize_uuid(uuid_value: Any) -> str | None:
+ """Safely serialize UUID objects to strings.
+
+ Args:
+ uuid_value: UUID object, string, or other value
+
+ Returns:
+ String representation of UUID or None
+ """
+ if uuid_value is None:
+ return None
+
+ if isinstance(uuid_value, UUID):
+ return str(uuid_value)
+
+ if isinstance(uuid_value, str):
+ return uuid_value
+
+ if hasattr(uuid_value, "hex"):
+ return str(uuid_value)
+
+ # Convert other types to string
+ return str(uuid_value)
+
+ @staticmethod
+ def serialize_datetime(datetime_value: Any) -> str | None:
+ """Safely serialize datetime objects to ISO format strings.
+
+ Args:
+ datetime_value: datetime, date, time object, string, or other value
+
+ Returns:
+ ISO format string representation or None
+ """
+ if datetime_value is None:
+ return None
+
+ if isinstance(datetime_value, (datetime, date)):
+ return datetime_value.isoformat()
+
+ if isinstance(datetime_value, time):
+ return datetime_value.isoformat()
+
+ if isinstance(datetime_value, str):
+ # If it's already a string, assume it's properly formatted
+ return datetime_value
+
+ # Convert other types to string
+ return str(datetime_value)
+
+ @staticmethod
+ def serialize_complex_data(data: Any) -> Any:
+ """Recursively serialize complex data structures to JSON-compatible format.
+
+ Handles datetime objects, UUID objects, tuples, sets, and nested structures.
+
+ Args:
+ data: Data to serialize
+
+ Returns:
+ JSON-compatible data structure
+ """
+ if isinstance(data, UUID):
+ return TypeConverter.serialize_uuid(data)
+ elif isinstance(data, (datetime, date, time)):
+ return TypeConverter.serialize_datetime(data)
+ elif isinstance(data, dict):
+ return {
+ key: TypeConverter.serialize_complex_data(value)
+ for key, value in data.items()
+ }
+ elif isinstance(data, list):
+ return [TypeConverter.serialize_complex_data(item) for item in data]
+ elif isinstance(data, tuple):
+ # Convert tuple to list for JSON compatibility
+ return [TypeConverter.serialize_complex_data(item) for item in data]
+ elif isinstance(data, set):
+ # Convert set to list for JSON compatibility
+ return [TypeConverter.serialize_complex_data(item) for item in data]
+ else:
+ return data
+
+ @staticmethod
+ def _make_unique_filename(filename: str, existing_files: dict[str, Any]) -> str:
+ """Generate a unique filename by appending a counter.
+
+ Args:
+ filename: Original filename
+ existing_files: Dictionary of existing files
+
+ Returns:
+ Unique filename
+ """
+ if filename not in existing_files:
+ return filename
+
+ base_name, ext = os.path.splitext(filename)
+ counter = 1
+
+ while f"{base_name}_{counter}{ext}" in existing_files:
+ counter += 1
+
+ unique_name = f"{base_name}_{counter}{ext}"
+ logger.warning(
+ f"Duplicate filename detected, renamed '{filename}' to '{unique_name}'"
+ )
+ return unique_name
+
+ @staticmethod
+ def validate_file_batch_format(
+ files: dict[str, FileHashData] | list[dict],
+ ) -> tuple[bool, str]:
+ """Validate that file batch format is correct.
+
+ Args:
+ files: Files in various formats
+
+ Returns:
+ Tuple of (is_valid, error_message)
+ """
+ if not files:
+ return False, "Files list is empty"
+
+ if isinstance(files, dict):
+ # Check if all values are FileHashData objects
+ for file_name, file_data in files.items():
+ if not isinstance(file_data, (FileHashData, dict)):
+ return (
+ False,
+ f"File '{file_name}' has invalid type: {type(file_data)}",
+ )
+ return True, "Valid dict format"
+
+ elif isinstance(files, list):
+ # Check if all items are dictionaries
+ for i, file_data in enumerate(files):
+ if not isinstance(file_data, dict):
+ return False, f"File at index {i} has invalid type: {type(file_data)}"
+ if "file_name" not in file_data:
+ return False, f"File at index {i} missing 'file_name' field"
+ return True, "Valid list format"
+
+ else:
+ return False, f"Unsupported files type: {type(files)}"
+
+
+class FileDataValidator:
+ """Validator for FileHashData objects and related data."""
+
+ @staticmethod
+ def validate_file_hash_data(file_data: FileHashData) -> tuple[bool, list[str]]:
+ """Validate FileHashData object fields.
+
+ Args:
+ file_data: FileHashData object to validate
+
+ Returns:
+ Tuple of (is_valid, list_of_errors)
+ """
+ errors = []
+
+ if not file_data.file_name:
+ errors.append("file_name is required")
+
+ if not file_data.file_path:
+ errors.append("file_path is required")
+
+ if file_data.file_size < 0:
+ errors.append("file_size cannot be negative")
+
+ # Validate mime_type if present
+ if file_data.mime_type and not file_data.mime_type.strip():
+ errors.append("mime_type cannot be empty string")
+
+ # Validate fs_metadata if present
+ if file_data.fs_metadata and not isinstance(file_data.fs_metadata, dict):
+ errors.append("fs_metadata must be a dictionary")
+
+ return len(errors) == 0, errors
+
+ @staticmethod
+ def validate_file_batch_data(
+ files: dict[str, FileHashData],
+ ) -> tuple[bool, list[str]]:
+ """Validate a batch of FileHashData objects.
+
+ Args:
+ files: Dictionary of FileHashData objects
+
+ Returns:
+ Tuple of (is_valid, list_of_errors)
+ """
+ errors = []
+
+ if not files:
+ errors.append("File batch is empty")
+ return False, errors
+
+ for file_name, file_data in files.items():
+ if not isinstance(file_data, FileHashData):
+ errors.append(f"File '{file_name}' is not a FileHashData object")
+ continue
+
+ is_valid, file_errors = FileDataValidator.validate_file_hash_data(file_data)
+ if not is_valid:
+ errors.extend([f"File '{file_name}': {error}" for error in file_errors])
+
+ return len(errors) == 0, errors
diff --git a/workers/shared/utils/__init__.py b/workers/shared/utils/__init__.py
new file mode 100644
index 000000000..348417043
--- /dev/null
+++ b/workers/shared/utils/__init__.py
@@ -0,0 +1,5 @@
+"""Shared utilities for workers.
+
+Utilities are imported directly from their respective modules.
+Example: from shared.utils.api_client_singleton import get_singleton_api_client
+"""
diff --git a/workers/shared/utils/api_client_singleton.py b/workers/shared/utils/api_client_singleton.py
new file mode 100644
index 000000000..4f812c108
--- /dev/null
+++ b/workers/shared/utils/api_client_singleton.py
@@ -0,0 +1,89 @@
+"""Global API Client Singleton Manager
+
+Provides a singleton pattern for API clients to reduce repeated initialization
+and eliminate excessive logging noise from health checks.
+"""
+
+import threading
+
+from ..api.internal_client import InternalAPIClient
+from ..infrastructure.config import WorkerConfig
+from ..infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class APIClientSingleton:
+ """Thread-safe singleton manager for API clients."""
+
+ _instance = None
+ _lock = threading.Lock()
+ _clients: dict[str, InternalAPIClient] = {}
+ _initialized = False
+
+ def __new__(cls):
+ if cls._instance is None:
+ with cls._lock:
+ if cls._instance is None:
+ cls._instance = super().__new__(cls)
+ return cls._instance
+
+ def get_client(self, config: WorkerConfig | None = None) -> InternalAPIClient:
+ """Get or create an API client for the given configuration.
+
+ Args:
+ config: Worker configuration. Uses default if None.
+
+ Returns:
+ InternalAPIClient instance (cached)
+ """
+ if config is None:
+ config = WorkerConfig()
+
+ # Create a cache key based on API base URL and key
+ cache_key = f"{config.internal_api_base_url}:{config.internal_api_key[:8] if config.internal_api_key else 'none'}"
+
+ if cache_key not in self._clients:
+ with self._lock:
+ # Double-check pattern
+ if cache_key not in self._clients:
+ if not self._initialized:
+ logger.debug("Initializing global API client singleton")
+ self._initialized = True
+ else:
+ logger.debug(f"Creating new API client for config: {cache_key}")
+
+ self._clients[cache_key] = InternalAPIClient(config)
+
+ return self._clients[cache_key]
+
+ def clear_cache(self):
+ """Clear all cached clients (useful for testing)."""
+ with self._lock:
+ self._clients.clear()
+ self._initialized = False
+ logger.debug("Cleared API client cache")
+
+
+# Global singleton instance
+_api_client_singleton = APIClientSingleton()
+
+
+def get_singleton_api_client(config: WorkerConfig | None = None) -> InternalAPIClient:
+ """Get a singleton API client instance.
+
+ This function provides a convenient way to get a cached API client
+ that reduces initialization overhead and logging noise.
+
+ Args:
+ config: Worker configuration. Uses default if None.
+
+ Returns:
+ InternalAPIClient instance (cached)
+ """
+ return _api_client_singleton.get_client(config)
+
+
+def clear_api_client_cache():
+ """Clear the API client cache (useful for testing)."""
+ _api_client_singleton.clear_cache()
diff --git a/workers/shared/utils/api_hub_factory.py b/workers/shared/utils/api_hub_factory.py
new file mode 100644
index 000000000..b2f2dc4b2
--- /dev/null
+++ b/workers/shared/utils/api_hub_factory.py
@@ -0,0 +1,150 @@
+"""API Hub Usage Service Factory.
+
+Plugin-aware factory for API Hub usage tracking services.
+Uses complete service implementations from plugins when available,
+falls back to minimal OSS null service otherwise.
+"""
+
+from typing import Protocol
+
+from client_plugin_registry import get_client_plugin, has_client_plugin
+
+from ..infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+API_HUB_PLUGIN_NAME = "api_hub"
+
+
+class APIHubServiceProtocol(Protocol):
+ """Protocol defining the interface for API Hub usage services."""
+
+ def track_api_hub_usage(
+ self,
+ workflow_execution_id: str,
+ workflow_file_execution_id: str,
+ organization_id: str | None = None,
+ ) -> bool:
+ """Track API hub usage for billing purposes."""
+ ...
+
+
+class NullAPIHubService:
+ """Null implementation for OSS deployments.
+
+ Provides safe no-op methods that don't raise errors when API Hub
+ functionality is not available.
+ """
+
+ def track_api_hub_usage(
+ self,
+ workflow_execution_id: str,
+ workflow_file_execution_id: str,
+ organization_id: str | None = None,
+ ) -> bool:
+ """No-op implementation for OSS - always returns False."""
+ logger.debug(
+ f"API Hub plugin not available - skipping usage tracking for execution {workflow_execution_id}"
+ )
+ return False
+
+
+def get_api_hub_service() -> APIHubServiceProtocol:
+ """Get API Hub service instance.
+
+ Returns enterprise plugin implementation if available,
+ otherwise returns null service for graceful OSS fallback.
+
+ Returns:
+ APIHubServiceProtocol: Service instance (plugin or null implementation)
+ """
+ logger.info("Checking for API Hub plugin availability")
+ if has_client_plugin(API_HUB_PLUGIN_NAME):
+ logger.info("API Hub plugin available - using enterprise implementation")
+ try:
+ # Get plugin instance from registry
+ plugin_instance = get_client_plugin(API_HUB_PLUGIN_NAME)
+ if plugin_instance:
+ # Plugin provides direct access to APIHubUsageUtil methods
+ return plugin_instance
+ else:
+ logger.warning(
+ "API Hub plugin instance creation failed - using null service"
+ )
+ return NullAPIHubService()
+ except Exception as e:
+ logger.warning(f"Error loading API Hub plugin - using null service: {e}")
+ return NullAPIHubService()
+ else:
+ logger.error("API Hub plugin not available - using null service for OSS")
+ return NullAPIHubService()
+
+
+def has_api_hub_plugin() -> bool:
+ """Check if API Hub plugin is available.
+
+ Returns:
+ bool: True if plugin is available, False for OSS deployments
+ """
+ return has_client_plugin(API_HUB_PLUGIN_NAME)
+
+
+# Legacy compatibility - create a default service instance
+# that can be imported directly for backward compatibility
+_default_service = None
+
+
+def get_default_api_hub_service() -> APIHubServiceProtocol:
+ """Get default API Hub service instance (cached).
+
+ This provides a cached instance for performance when the same
+ service is used multiple times.
+
+ Returns:
+ APIHubServiceProtocol: Cached service instance
+ """
+ global _default_service
+ if _default_service is None:
+ _default_service = get_api_hub_service()
+ return _default_service
+
+
+# Create compatibility class that mimics the original APIHubUsageUtil
+class APIHubUsageUtil:
+ """Compatibility wrapper for the original APIHubUsageUtil class.
+
+ This class provides the same interface as the original backend APIHubUsageUtil
+ but uses the plugin system internally for proper separation of concerns.
+ """
+
+ _service = None
+
+ @classmethod
+ def _get_service(cls) -> APIHubServiceProtocol:
+ """Get service instance (cached)."""
+ if cls._service is None:
+ cls._service = get_api_hub_service()
+ return cls._service
+
+ @staticmethod
+ def track_api_hub_usage(
+ workflow_execution_id: str,
+ workflow_file_execution_id: str,
+ organization_id: str | None = None,
+ ) -> bool:
+ """Track API hub usage for billing purposes.
+
+ Args:
+ workflow_execution_id: The workflow execution ID
+ workflow_file_execution_id: The file execution ID
+ organization_id: Optional organization ID
+
+ Returns:
+ bool: True if usage was tracked successfully, False otherwise.
+ """
+ service = APIHubUsageUtil._get_service()
+ return service.track_api_hub_usage(
+ workflow_execution_id=workflow_execution_id,
+ workflow_file_execution_id=workflow_file_execution_id,
+ organization_id=organization_id,
+ )
diff --git a/workers/shared/utils/api_metadata.py b/workers/shared/utils/api_metadata.py
new file mode 100644
index 000000000..b12a67c8c
--- /dev/null
+++ b/workers/shared/utils/api_metadata.py
@@ -0,0 +1,222 @@
+"""API Result Metadata Structures
+
+This module provides structured dataclasses for creating clean, type-safe
+metadata for API deployment results, eliminating hardcoded dictionary creation.
+"""
+
+import logging
+from dataclasses import asdict, dataclass
+from typing import Any
+
+from unstract.core.data_models import FileHashData
+from unstract.core.worker_models import FileProcessingResult
+
+logger = logging.getLogger(__name__)
+
+
+@dataclass
+class BaseApiMetadata:
+ """Base metadata structure for all API results.
+
+ Contains common fields that appear in all API result metadata.
+ """
+
+ workflow_id: str
+ execution_id: str
+ execution_time: float
+ source_name: str
+ source_hash: str
+ organization_id: str | None = None
+ total_elapsed_time: float | None = None
+ tool_metadata: dict[str, Any] | None = None
+
+ @classmethod
+ def from_context(
+ cls,
+ workflow_id: str,
+ execution_id: str,
+ file_processing_result: FileProcessingResult,
+ file_hash: FileHashData,
+ ) -> "BaseApiMetadata":
+ """Create base metadata from processing context.
+
+ Args:
+ workflow_id: Workflow identifier
+ execution_id: Execution identifier
+ file_processing_result: Source processing result
+ file_hash: File hash information
+
+ Returns:
+ BaseApiMetadata instance with populated common fields
+ """
+ metadata = file_processing_result.metadata or {}
+ return cls(
+ workflow_id=metadata.get("workflow_id", workflow_id),
+ execution_id=metadata.get("execution_id", execution_id),
+ execution_time=metadata.get(
+ "execution_time", getattr(file_processing_result, "execution_time", 0.0)
+ ),
+ source_name=metadata.get("source_name", file_hash.file_name),
+ source_hash=metadata.get("source_hash", file_hash.file_hash),
+ organization_id=metadata.get("organization_id"),
+ total_elapsed_time=metadata.get("total_elapsed_time"),
+ tool_metadata=metadata.get("tool_metadata"),
+ )
+
+
+@dataclass
+class FileHistoryApiMetadata(BaseApiMetadata):
+ """Metadata structure for file history API results.
+
+ Used when API results come from cached file processing history.
+ """
+
+ from_file_history: bool = True
+ tool_count: int | None = None
+
+
+@dataclass
+class ErrorApiMetadata(BaseApiMetadata):
+ """Metadata structure for error API results.
+
+ Used when API results represent processing errors or exceptions.
+ """
+
+ error_occurred: bool = True
+ workflow_execution_failed: bool | None = None
+ processing_failed: bool | None = None
+
+
+class ApiMetadataBuilder:
+ """Helper class for building structured API metadata dictionaries.
+
+ Provides static methods to create clean, consistent metadata structures
+ for different types of API results while avoiding code duplication.
+ """
+
+ @staticmethod
+ def build_file_history_metadata(
+ workflow_id: str,
+ execution_id: str,
+ file_processing_result: FileProcessingResult,
+ file_hash: FileHashData,
+ ) -> dict[str, Any]:
+ """Build metadata for file history API results.
+
+ Args:
+ workflow_id: Workflow identifier
+ execution_id: Execution identifier
+ file_processing_result: Source processing result
+ file_hash: File hash information
+
+ Returns:
+ Dictionary with clean file history metadata structure
+ """
+ try:
+ metadata = FileHistoryApiMetadata.from_context(
+ workflow_id, execution_id, file_processing_result, file_hash
+ )
+
+ return asdict(metadata)
+
+ except Exception as e:
+ logger.error(f"Failed to build file history metadata: {e}")
+ # Fallback to minimal structure
+ return {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "from_file_history": True,
+ "source_name": file_hash.file_name,
+ "source_hash": file_hash.file_hash,
+ }
+
+ @staticmethod
+ def build_error_metadata(
+ workflow_id: str,
+ execution_id: str,
+ file_processing_result: FileProcessingResult,
+ file_hash: FileHashData,
+ ) -> dict[str, Any]:
+ """Build metadata for error API results.
+
+ Args:
+ workflow_id: Workflow identifier
+ execution_id: Execution identifier
+ file_processing_result: Source processing result with error
+ file_hash: File hash information
+
+ Returns:
+ Dictionary with clean error metadata structure
+ """
+ try:
+ metadata = ErrorApiMetadata.from_context(
+ workflow_id, execution_id, file_processing_result, file_hash
+ )
+
+ # Add optional error context from original metadata if available
+ original_metadata = file_processing_result.metadata or {}
+ if "workflow_execution_failed" in original_metadata:
+ metadata.workflow_execution_failed = original_metadata[
+ "workflow_execution_failed"
+ ]
+ if "processing_failed" in original_metadata:
+ metadata.processing_failed = original_metadata["processing_failed"]
+
+ return asdict(metadata)
+
+ except Exception as e:
+ logger.error(f"Failed to build error metadata: {e}", exc_info=True)
+ # Fallback to minimal structure
+ return {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "error_occurred": True,
+ "source_name": file_hash.file_name,
+ "source_hash": file_hash.file_hash,
+ }
+
+ @staticmethod
+ def build_base_metadata(
+ workflow_id: str,
+ execution_id: str,
+ file_processing_result: FileProcessingResult,
+ file_hash: FileHashData,
+ additional_fields: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Build base metadata with optional additional fields.
+
+ Args:
+ workflow_id: Workflow identifier
+ execution_id: Execution identifier
+ file_processing_result: Source processing result
+ file_hash: File hash information
+ additional_fields: Optional additional metadata fields
+
+ Returns:
+ Dictionary with base metadata structure plus additional fields
+ """
+ try:
+ metadata = BaseApiMetadata.from_context(
+ workflow_id, execution_id, file_processing_result, file_hash
+ )
+
+ result = asdict(metadata)
+
+ # Add additional fields if provided
+ if additional_fields:
+ result.update(additional_fields)
+
+ return result
+
+ except Exception as e:
+ logger.error(f"Failed to build base metadata: {e}")
+ # Fallback to minimal structure
+ result = {
+ "workflow_id": workflow_id,
+ "execution_id": execution_id,
+ "source_name": file_hash.file_name,
+ "source_hash": file_hash.file_hash,
+ }
+ if additional_fields:
+ result.update(additional_fields)
+ return result
diff --git a/workers/shared/utils/api_result_cache.py b/workers/shared/utils/api_result_cache.py
new file mode 100644
index 000000000..8fcec05be
--- /dev/null
+++ b/workers/shared/utils/api_result_cache.py
@@ -0,0 +1,345 @@
+"""API Result Caching Utilities
+
+This module provides utilities for caching API deployment results,
+extracted from destination connector to provide reusable caching functionality
+across worker components.
+"""
+
+import logging
+from typing import Any
+
+from shared.utils.api_hub_factory import APIHubUsageUtil
+
+from unstract.core.data_models import FileHashData
+from unstract.core.worker_models import (
+ ApiDeploymentResultStatus,
+ FileExecutionResult,
+ FileProcessingResult,
+)
+from unstract.workflow_execution.api_deployment.cache_utils import WorkerResultCacheUtils
+
+from .api_metadata import ApiMetadataBuilder
+
+logger = logging.getLogger(__name__)
+
+
+class APIResultCacheManager:
+ """Manages caching of API deployment results for worker components.
+
+ This class provides a centralized way to cache API results from various
+ worker components without requiring a full destination connector instance.
+ """
+
+ def __init__(self):
+ """Initialize the API result cache manager."""
+ self._cache_utils = None
+
+ @property
+ def cache_utils(self) -> WorkerResultCacheUtils:
+ """Get cache utils instance (lazy initialization)."""
+ if self._cache_utils is None:
+ self._cache_utils = WorkerResultCacheUtils()
+ return self._cache_utils
+
+ def _track_api_hub_usage(
+ self, organization_id: str, execution_id: str, file_execution_id: str
+ ):
+ """Track API Hub usage."""
+ # Track usage for API Hub deployments (graceful fallback for OSS)
+ try:
+ logger.info(
+ f"_track_api_hub_usage: Tracking API Hub usage for {execution_id} : {file_execution_id}"
+ )
+ APIHubUsageUtil.track_api_hub_usage(
+ workflow_execution_id=execution_id,
+ workflow_file_execution_id=file_execution_id,
+ organization_id=organization_id,
+ )
+ except Exception as e:
+ # Log but don't fail the main execution for usage tracking issues
+ logger.warning(
+ f"Could not track API hub usage for {execution_id} : {file_execution_id}: {e}"
+ )
+
+ def cache_file_processing_result(
+ self,
+ file_processing_result: FileProcessingResult,
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ file_hash: FileHashData,
+ metadata: dict[str, Any] | None = None,
+ ) -> bool:
+ """Cache a FileProcessingResult as an API deployment result.
+
+ Args:
+ file_processing_result: The file processing result to cache
+ workflow_id: Workflow ID for caching key
+ execution_id: Execution ID for caching key
+ organization_id: Organization ID for context
+ file_hash: File hash data for file info
+ metadata: Optional additional metadata
+
+ Returns:
+ True if caching succeeded, False otherwise
+ """
+ try:
+ # Convert FileProcessingResult to FileExecutionResult for API caching
+ api_result = self._convert_to_file_execution_result(
+ file_processing_result=file_processing_result,
+ file_hash=file_hash,
+ metadata=metadata,
+ )
+
+ # Cache the result using WorkerResultCacheUtils
+ self.cache_utils.update_api_results(
+ workflow_id=workflow_id, execution_id=execution_id, api_result=api_result
+ )
+
+ logger.info(
+ f"Successfully cached API result for file {file_hash.file_name} "
+ f"in execution {execution_id}"
+ )
+
+ return True
+
+ except Exception as e:
+ logger.error(
+ f"Failed to cache API result for file {file_hash.file_name} "
+ f"in execution {execution_id}: {str(e)}"
+ )
+ # Return False but don't re-raise - caching failures shouldn't stop execution
+ return False
+
+ def _convert_to_file_execution_result(
+ self,
+ file_processing_result: FileProcessingResult,
+ file_hash: FileHashData,
+ metadata: dict[str, Any] | None = None,
+ ) -> FileExecutionResult:
+ """Convert FileProcessingResult to FileExecutionResult for API caching.
+
+ Args:
+ file_processing_result: Source result to convert
+ file_hash: File hash data for file info
+ metadata: Optional additional metadata
+
+ Returns:
+ FileExecutionResult ready for API caching
+ """
+ # Determine status based on result success and error
+ if file_processing_result.success and not file_processing_result.error:
+ status = ApiDeploymentResultStatus.SUCCESS
+ else:
+ status = ApiDeploymentResultStatus.FAILED
+
+ # Merge metadata from result and additional metadata
+ result_metadata = file_processing_result.metadata or {}
+ additional_metadata = metadata or {}
+
+ # Add processing context to metadata
+ combined_metadata = {
+ **result_metadata,
+ **additional_metadata,
+ "from_cache": getattr(file_processing_result, "from_cache", False),
+ "from_file_history": getattr(
+ file_processing_result, "from_file_history", False
+ ),
+ "manual_review": getattr(file_processing_result, "manual_review", False),
+ "execution_time": getattr(file_processing_result, "execution_time", 0.0),
+ }
+
+ # Create FileExecutionResult matching destination connector pattern
+ return FileExecutionResult(
+ file=file_hash.file_name,
+ status=status,
+ file_execution_id=file_processing_result.file_execution_id,
+ result=file_processing_result.result,
+ error=file_processing_result.error,
+ metadata=combined_metadata,
+ )
+
+ def cache_file_history_result_for_api(
+ self,
+ file_processing_result: FileProcessingResult,
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ file_hash: FileHashData,
+ ) -> bool:
+ """Cache file history result as API result with clean metadata format.
+
+ This method specifically handles file history results and formats them
+ with the clean metadata structure expected by API deployments.
+
+ Args:
+ file_processing_result: The cached file processing result
+ workflow_id: Workflow ID for caching key
+ execution_id: Execution ID for caching key
+ organization_id: Organization ID for context
+ file_hash: File hash data for file info
+
+ Returns:
+ True if caching succeeded, False otherwise
+ """
+ try:
+ # Create clean metadata using structured builder
+ clean_metadata = ApiMetadataBuilder.build_file_history_metadata(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ file_processing_result=file_processing_result,
+ file_hash=file_hash,
+ )
+
+ # Use direct caching with clean metadata
+ return self.cache_api_result_direct(
+ file_name=file_hash.file_name,
+ file_execution_id=file_processing_result.file_execution_id,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ result=file_processing_result.result,
+ error=file_processing_result.error,
+ organization_id=organization_id,
+ metadata=clean_metadata,
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to cache file history result for API for file {file_hash.file_name}: {str(e)}"
+ )
+ return False
+
+ def cache_error_result_for_api(
+ self,
+ file_processing_result: FileProcessingResult,
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ file_hash: FileHashData,
+ ) -> bool:
+ """Cache error result as API result with clean metadata format.
+
+ This method specifically handles error/exception results and formats them
+ with the clean metadata structure expected by API deployments.
+
+ Args:
+ file_processing_result: The error file processing result
+ workflow_id: Workflow ID for caching key
+ execution_id: Execution ID for caching key
+ organization_id: Organization ID for context
+ file_hash: File hash data for file info
+
+ Returns:
+ True if caching succeeded, False otherwise
+ """
+ try:
+ # Create clean metadata using structured builder
+ clean_metadata = ApiMetadataBuilder.build_error_metadata(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ file_processing_result=file_processing_result,
+ file_hash=file_hash,
+ )
+
+ # Use direct caching with clean metadata
+ return self.cache_api_result_direct(
+ file_name=file_hash.file_name,
+ file_execution_id=file_processing_result.file_execution_id,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ result=file_processing_result.result,
+ error=file_processing_result.error,
+ organization_id=organization_id,
+ metadata=clean_metadata,
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to cache error result for API for file {file_hash.file_name}: {str(e)}"
+ )
+ return False
+
+ def cache_api_result_direct(
+ self,
+ file_name: str,
+ file_execution_id: str,
+ workflow_id: str,
+ execution_id: str,
+ result: dict[str, Any] | None,
+ error: str | None = None,
+ organization_id: str | None = None,
+ metadata: dict[str, Any] | None = None,
+ ) -> bool:
+ """Cache API result directly without FileProcessingResult conversion.
+
+ This method provides a direct interface for caching API results
+ when you already have the raw result data.
+
+ Args:
+ file_name: Name of the file
+ file_execution_id: File execution ID
+ workflow_id: Workflow ID for caching key
+ execution_id: Execution ID for caching key
+ organization_id: Organization ID for context
+ result: Result data to cache
+ error: Optional error message
+ metadata: Optional metadata
+
+ Returns:
+ True if caching succeeded, False otherwise
+ """
+ try:
+ # Determine status
+ status = (
+ ApiDeploymentResultStatus.FAILED
+ if error
+ else ApiDeploymentResultStatus.SUCCESS
+ )
+
+ # Create FileExecutionResult
+ api_result = FileExecutionResult(
+ file=file_name,
+ status=status,
+ file_execution_id=file_execution_id,
+ result=result,
+ error=error,
+ metadata=metadata or {},
+ )
+
+ # Cache the result
+ self.cache_utils.update_api_results(
+ workflow_id=workflow_id, execution_id=execution_id, api_result=api_result
+ )
+
+ logger.info(
+ f"Successfully cached direct API result for file {file_name} "
+ f"in execution {execution_id} for organization {organization_id}"
+ )
+
+ if organization_id:
+ self._track_api_hub_usage(
+ organization_id=organization_id,
+ execution_id=execution_id,
+ file_execution_id=file_execution_id,
+ )
+
+ return True
+
+ except Exception as e:
+ logger.error(
+ f"Failed to cache direct API result for file {file_name} "
+ f"in execution {execution_id}: {str(e)}"
+ )
+ return False
+
+
+# Singleton instance for easy access
+_api_cache_manager = None
+
+
+def get_api_cache_manager() -> APIResultCacheManager:
+ """Get singleton instance of APIResultCacheManager."""
+ global _api_cache_manager
+ if _api_cache_manager is None:
+ _api_cache_manager = APIResultCacheManager()
+ return _api_cache_manager
diff --git a/workers/shared/utils/cache_keys.py b/workers/shared/utils/cache_keys.py
new file mode 100644
index 000000000..f91ca1114
--- /dev/null
+++ b/workers/shared/utils/cache_keys.py
@@ -0,0 +1,12 @@
+"""Cache Key Utilities
+
+Cache key generation and management.
+"""
+
+
+def get_cache_key(pattern: str, **kwargs) -> str:
+ """Generate cache key from pattern and parameters."""
+ try:
+ return pattern.format(**kwargs)
+ except KeyError as e:
+ raise ValueError(f"Missing parameter for cache key pattern {pattern}: {e}")
diff --git a/workers/shared/utils/local_context.py b/workers/shared/utils/local_context.py
new file mode 100644
index 000000000..340d39b12
--- /dev/null
+++ b/workers/shared/utils/local_context.py
@@ -0,0 +1,56 @@
+"""Worker-specific local context without Django dependencies.
+This provides the StateStore functionality needed by workers.
+"""
+
+import os
+import threading
+from enum import Enum
+from typing import Any
+
+
+class ConcurrencyMode(Enum):
+ THREAD = "thread"
+ COROUTINE = "coroutine"
+
+
+class Exceptions:
+ UNKNOWN_MODE = "Unknown concurrency mode"
+
+
+class StateStore:
+ mode = os.environ.get("CONCURRENCY_MODE", ConcurrencyMode.THREAD)
+ # Thread-safe storage.
+ thread_local = threading.local()
+
+ @classmethod
+ def _get_thread_local(cls, key: str) -> Any:
+ return getattr(cls.thread_local, key, None)
+
+ @classmethod
+ def _set_thread_local(cls, key: str, val: Any) -> None:
+ setattr(cls.thread_local, key, val)
+
+ @classmethod
+ def _del_thread_local(cls, key: str) -> None:
+ delattr(cls.thread_local, key)
+
+ @classmethod
+ def get(cls, key: str) -> Any:
+ if cls.mode == ConcurrencyMode.THREAD:
+ return cls._get_thread_local(key)
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
+
+ @classmethod
+ def set(cls, key: str, val: Any) -> None:
+ if cls.mode == ConcurrencyMode.THREAD:
+ return cls._set_thread_local(key, val)
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
+
+ @classmethod
+ def clear(cls, key: str) -> None:
+ if cls.mode == ConcurrencyMode.THREAD:
+ return cls._del_thread_local(key)
+ else:
+ raise RuntimeError(Exceptions.UNKNOWN_MODE)
diff --git a/workers/shared/utils/manual_review_factory.py b/workers/shared/utils/manual_review_factory.py
new file mode 100644
index 000000000..8f1c40942
--- /dev/null
+++ b/workers/shared/utils/manual_review_factory.py
@@ -0,0 +1,424 @@
+"""Manual Review Service Factory.
+
+Simplified plugin-aware factory for manual review services.
+Uses complete service implementations from plugins when available,
+falls back to minimal OSS null service otherwise.
+"""
+
+from typing import Any, Protocol
+
+from client_plugin_registry import get_client_plugin, has_client_plugin
+
+from unstract.core.data_models import WorkerFileData
+
+from ..infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+MANUAL_REVIEW_PLUGIN_NAME = "manual_review"
+
+
+class ManualReviewServiceProtocol(Protocol):
+ """Protocol defining the interface for manual review services."""
+
+ def get_manual_review_config(
+ self, workflow_id: str, total_files: int = 0
+ ) -> dict[str, Any]:
+ """Get manual review configuration for a workflow."""
+ ...
+
+ def calculate_q_file_no_list(
+ self, config: dict[str, Any], total_files: int
+ ) -> list[int]:
+ """Calculate file numbers for manual review queue."""
+ ...
+
+ def calculate_batch_decisions(
+ self,
+ batch: list[tuple[str, Any]],
+ source_files: dict[str, Any],
+ config: dict[str, Any],
+ ) -> list[bool]:
+ """Calculate manual review decisions for files in a batch."""
+ ...
+
+ def create_workflow_file_data_with_manual_review(
+ self,
+ worker_file_data: WorkerFileData,
+ use_file_history: bool,
+ total_files: int = 0,
+ ) -> Any:
+ """Create WorkerFileData with manual review configuration."""
+ ...
+
+ def get_workflow_util(self) -> Any:
+ """Get WorkflowUtil instance for this service."""
+ ...
+
+
+class ManualReviewNullService:
+ """Null implementation of manual review service for OSS compatibility."""
+
+ def __init__(self, api_client: Any, organization_id: str):
+ """Initialize null service."""
+ self.api_client = api_client
+ self.organization_id = organization_id
+ logger.debug("Using ManualReviewNullService - manual review disabled in OSS")
+
+ def get_manual_review_config(
+ self, workflow_id: str, total_files: int = 0
+ ) -> dict[str, Any]:
+ """Return default config indicating no manual review."""
+ return {
+ "review_required": False,
+ "review_percentage": 0,
+ "rule_logic": None,
+ "rule_json": None,
+ "q_file_no_list": [],
+ "file_decisions": [],
+ }
+
+ def calculate_q_file_no_list(
+ self, config: dict[str, Any], total_files: int
+ ) -> list[int]:
+ """Return empty list for OSS."""
+ return []
+
+ def calculate_batch_decisions(
+ self,
+ batch: list[tuple[str, Any]],
+ source_files: dict[str, Any],
+ config: dict[str, Any],
+ ) -> list[bool]:
+ """Return all False for OSS."""
+ return [False] * len(batch)
+
+ def create_workflow_file_data_with_manual_review(
+ self,
+ worker_file_data: WorkerFileData,
+ use_file_history: bool,
+ total_files: int = 0,
+ ) -> WorkerFileData:
+ """Create WorkerFileData without manual review for OSS."""
+ worker_file_data.manual_review_config = self.get_manual_review_config(
+ worker_file_data.workflow_id, total_files
+ )
+ worker_file_data.use_file_history = False
+ worker_file_data.q_file_no_list = []
+ return worker_file_data
+
+ def get_workflow_util(self) -> Any:
+ """Get WorkflowUtil instance (returns null implementation for OSS)."""
+
+ # Return a simple null implementation for OSS
+ class WorkflowUtilNull:
+ @staticmethod
+ def add_file_destination_filehash(file_number, q_file_no_list, file_hash):
+ # OSS: No manual review processing, return file_hash unchanged
+ return file_hash
+
+ @staticmethod
+ def get_q_no_list(workflow, total_files):
+ # OSS: No manual review queue
+ return None
+
+ @staticmethod
+ def validate_db_rule(
+ result, workflow_id, file_destination, is_manual_review_required
+ ):
+ # OSS: No rule validation
+ return False
+
+ @staticmethod
+ def get_hitl_ttl_seconds(workflow):
+ # OSS: No TTL restrictions
+ return None
+
+ return WorkflowUtilNull()
+
+
+class ManualReviewServiceFactory:
+ """Plugin-aware factory for manual review services."""
+
+ @staticmethod
+ def create_service(
+ api_client: Any, organization_id: str
+ ) -> ManualReviewServiceProtocol:
+ """Create manual review service using plugins when available.
+
+ Args:
+ api_client: Internal API client
+ organization_id: Organization ID
+
+ Returns:
+ Enhanced service if plugin available, null service otherwise
+ """
+ # Try to get enhanced service from plugin first
+ enhanced_service = ManualReviewServiceFactory._try_plugin_service(
+ api_client, organization_id
+ )
+
+ if enhanced_service:
+ logger.debug("Using enhanced manual review service from plugin")
+ return enhanced_service
+
+ # Fall back to OSS null service
+ logger.debug("Using OSS null manual review service")
+ return ManualReviewNullService(api_client, organization_id)
+
+ @staticmethod
+ def _try_plugin_service(
+ api_client: Any, organization_id: str
+ ) -> ManualReviewServiceProtocol | None:
+ """Try to create enhanced service from plugins."""
+ try:
+ # Check for manual review service plugin
+ if has_client_plugin(MANUAL_REVIEW_PLUGIN_NAME):
+ service_plugin = get_client_plugin(
+ MANUAL_REVIEW_PLUGIN_NAME, api_client.config
+ )
+ if service_plugin:
+ # Set organization context on the service
+ service_plugin.set_organization_context(organization_id)
+
+ # Create enhanced service with WorkflowUtil access
+ enhanced_service = ManualReviewEnhancedService(
+ service_plugin, api_client, organization_id
+ )
+ return enhanced_service
+
+ return None
+
+ except Exception as e:
+ logger.debug(f"Plugin service creation failed: {e}")
+ return None
+
+
+class ManualReviewEnhancedService:
+ """Enhanced manual review service with plugin-based WorkflowUtil access."""
+
+ def __init__(self, service_plugin: Any, api_client: Any, organization_id: str):
+ """Initialize enhanced service with plugin access."""
+ self.service_plugin = service_plugin
+ self.api_client = api_client
+ self.organization_id = organization_id
+ self._workflow_util = None
+
+ def get_manual_review_config(
+ self, workflow_id: str, total_files: int = 0
+ ) -> dict[str, Any]:
+ """Delegate to plugin service."""
+ if hasattr(self.service_plugin, "get_manual_review_config"):
+ return self.service_plugin.get_manual_review_config(workflow_id, total_files)
+ return {}
+
+ def calculate_q_file_no_list(
+ self, config: dict[str, Any], total_files: int
+ ) -> list[int]:
+ """Delegate to plugin service."""
+ if hasattr(self.service_plugin, "calculate_q_file_no_list"):
+ return self.service_plugin.calculate_q_file_no_list(config, total_files)
+ return []
+
+ def calculate_batch_decisions(
+ self,
+ batch: list[tuple[str, Any]],
+ source_files: dict[str, Any],
+ config: dict[str, Any],
+ ) -> list[bool]:
+ """Delegate to plugin service."""
+ if hasattr(self.service_plugin, "calculate_batch_decisions"):
+ return self.service_plugin.calculate_batch_decisions(
+ batch, source_files, config
+ )
+ return [False] * len(batch)
+
+ def create_workflow_file_data_with_manual_review(
+ self,
+ worker_file_data: WorkerFileData,
+ use_file_history: bool,
+ total_files: int = 0,
+ ) -> WorkerFileData:
+ """Delegate to plugin service."""
+ if hasattr(self.service_plugin, "create_workflow_file_data_with_manual_review"):
+ return self.service_plugin.create_workflow_file_data_with_manual_review(
+ worker_file_data,
+ use_file_history,
+ total_files,
+ )
+ worker_file_data.manual_review_config = self.get_manual_review_config(
+ worker_file_data.workflow_id, total_files
+ )
+ worker_file_data.use_file_history = False
+ worker_file_data.q_file_no_list = []
+ return worker_file_data
+
+ def get_workflow_util(self) -> Any:
+ """Get WorkflowUtil instance from plugin."""
+ if self._workflow_util is None:
+ # Try to get WorkflowUtil from the plugin service's components
+ try:
+ # Check if the service plugin has a get_workflow_util method
+ if hasattr(self.service_plugin, "get_workflow_util"):
+ self._workflow_util = self.service_plugin.get_workflow_util()
+ logger.debug("Using WorkflowUtil from service plugin method")
+ else:
+ # Try to get WorkflowUtil from plugin components
+ try:
+ from plugins.manual_review import ManualReviewWorkflowUtil
+
+ self._workflow_util = ManualReviewWorkflowUtil(
+ self.api_client.config
+ )
+ logger.debug(
+ "Using enterprise ManualReviewWorkflowUtil from plugin import"
+ )
+ except ImportError:
+ logger.debug(
+ "Plugin WorkflowUtil not available via import, using null implementation"
+ )
+ self._workflow_util = self._create_null_workflow_util()
+ except Exception as e:
+ logger.debug(f"Failed to get WorkflowUtil from plugin: {e}")
+ self._workflow_util = self._create_null_workflow_util()
+
+ return self._workflow_util
+
+ def _create_null_workflow_util(self):
+ """Create null WorkflowUtil implementation."""
+
+ class WorkflowUtilNull:
+ @staticmethod
+ def add_file_destination_filehash(file_number, q_file_no_list, file_hash):
+ return file_hash
+
+ @staticmethod
+ def get_q_no_list(workflow, total_files):
+ return None
+
+ @staticmethod
+ def validate_db_rule(
+ result, workflow_id, file_destination, is_manual_review_required
+ ):
+ return False
+
+ @staticmethod
+ def get_hitl_ttl_seconds(workflow):
+ return None
+
+ return WorkflowUtilNull()
+
+
+# Simplified direct access functions
+def get_manual_review_workflow_util(api_client: Any, organization_id: str) -> Any | None:
+ """Get WorkflowUtil directly via plugin registry (simplified access).
+
+ This eliminates the service layer for direct WorkflowUtil access.
+
+ Args:
+ api_client: Internal API client
+ organization_id: Organization ID
+
+ Returns:
+ ManualReviewWorkflowUtil if plugin available, null implementation otherwise
+ """
+ try:
+ if has_client_plugin(MANUAL_REVIEW_PLUGIN_NAME):
+ # Get WorkflowUtil directly from plugin registry
+ workflow_util = get_client_plugin(
+ MANUAL_REVIEW_PLUGIN_NAME, api_client.config
+ )
+ if workflow_util:
+ # Set organization context
+ workflow_util.organization_id = organization_id
+ workflow_util.client.set_organization_context(organization_id)
+ return workflow_util
+
+ return _create_null_workflow_util()
+
+ except Exception as e:
+ logger.debug(f"Failed to get WorkflowUtil from plugin: {e}")
+ return _create_null_workflow_util()
+
+
+def has_manual_review_plugin():
+ return has_client_plugin(MANUAL_REVIEW_PLUGIN_NAME)
+
+
+def _create_null_workflow_util():
+ """Create null WorkflowUtil implementation for OSS compatibility."""
+
+ class WorkflowUtilNull:
+ def __init__(self):
+ self.organization_id = None
+
+ @staticmethod
+ def add_file_destination_filehash(file_number, q_file_no_list, file_hash):
+ return file_hash
+
+ @staticmethod
+ def get_q_no_list(workflow, total_files):
+ return None
+
+ @staticmethod
+ def validate_db_rule(
+ result, workflow_id, file_destination, is_manual_review_required
+ ):
+ return False
+
+ def create_workflow_file_data_with_manual_review(
+ self,
+ worker_file_data: WorkerFileData,
+ use_file_history,
+ total_files=0,
+ ):
+ """Create workflow file data with manual review."""
+ worker_file_data.manual_review_config = self.get_manual_review_config(
+ worker_file_data.workflow_id, total_files
+ )
+ worker_file_data.use_file_history = False
+ worker_file_data.q_file_no_list = []
+ return worker_file_data
+
+ def calculate_batch_decisions(self, batch, source_files, config):
+ return [False] * len(batch)
+
+ def enqueue_manual_review(self, *args, **kwargs):
+ return
+
+ def get_hitl_ttl_seconds(self, *args, **kwargs):
+ return None
+
+ def get_manual_review_config(self, workflow_id, total_files):
+ return {}
+
+ return WorkflowUtilNull()
+
+
+# Legacy compatibility function
+def get_manual_review_service(
+ api_client: Any, organization_id: str
+) -> ManualReviewServiceProtocol:
+ """Legacy function for backward compatibility.
+
+ This maintains compatibility while internally using the simplified pattern.
+ """
+ # Return a wrapper that delegates to WorkflowUtil
+ workflow_util = get_manual_review_workflow_util(api_client, organization_id)
+
+ class LegacyServiceWrapper:
+ def __init__(self, workflow_util: Any | None):
+ self.workflow_util = workflow_util
+
+ def get_workflow_util(self):
+ return self.workflow_util
+
+ def create_workflow_file_data_with_manual_review(self, *args, **kwargs):
+ return self.workflow_util.create_workflow_file_data_with_manual_review(
+ *args, **kwargs
+ )
+
+ def calculate_batch_decisions(self, *args, **kwargs):
+ return self.workflow_util.calculate_batch_decisions(*args, **kwargs)
+
+ return LegacyServiceWrapper(workflow_util)
diff --git a/workers/shared/utils/manual_review_response.py b/workers/shared/utils/manual_review_response.py
new file mode 100644
index 000000000..d22735d11
--- /dev/null
+++ b/workers/shared/utils/manual_review_response.py
@@ -0,0 +1,53 @@
+"""Manual Review Response Classes.
+
+Consistent response formats for manual review operations. Extends the
+base response system for consistency.
+"""
+
+from dataclasses import dataclass
+from typing import Any
+
+from ..data.response_models import APIResponse
+
+
+@dataclass
+class ManualReviewResponse(APIResponse):
+ """Consistent response format for manual review operations.
+
+ Extends APIResponse to maintain consistency with the overall
+ response system.
+ """
+
+ @classmethod
+ def success_response(
+ cls, data: dict[str, Any], message: str | None = None, status_code: int = 200
+ ) -> "ManualReviewResponse":
+ """Create a successful manual review response."""
+ return cls(success=True, data=data, message=message, status_code=status_code)
+
+ @classmethod
+ def error_response(
+ cls, error: str, message: str | None = None, status_code: int = 400
+ ) -> "ManualReviewResponse":
+ """Create an error manual review response."""
+ return cls(success=False, error=error, message=message, status_code=status_code)
+
+ def to_dict(self) -> dict[str, Any]:
+ """Convert to dictionary format for backward compatibility."""
+ result = {
+ "success": self.success,
+ }
+
+ if self.data is not None:
+ result["data"] = self.data
+
+ if self.error is not None:
+ result["error"] = self.error
+
+ if self.message is not None:
+ result["message"] = self.message
+
+ if self.status_code is not None:
+ result["status_code"] = self.status_code
+
+ return result
diff --git a/workers/shared/utils/retry_temp.py b/workers/shared/utils/retry_temp.py
new file mode 100644
index 000000000..74bfc57ff
--- /dev/null
+++ b/workers/shared/utils/retry_temp.py
@@ -0,0 +1,79 @@
+"""Temporary Retry Utilities to Avoid Circular Imports
+
+Simple circuit breaker implementation to replace patterns imports temporarily.
+This avoids circular imports while maintaining functionality.
+"""
+
+
+class CircuitBreakerOpenError(Exception):
+ """Circuit breaker is open - too many failures"""
+
+ pass
+
+
+def circuit_breaker(
+ max_failures=5, reset_timeout=60, failure_threshold=None, recovery_timeout=None
+):
+ """Simple circuit breaker decorator - temporary implementation"""
+ # Handle parameter mapping for compatibility
+ if failure_threshold is not None:
+ max_failures = failure_threshold
+ if recovery_timeout is not None:
+ reset_timeout = recovery_timeout
+
+ def decorator(func):
+ func._failures = 0
+ func._last_failure = 0
+
+ def wrapper(*args, **kwargs):
+ import time
+
+ current_time = time.time()
+
+ # Reset if timeout has passed
+ if current_time - func._last_failure > reset_timeout:
+ func._failures = 0
+
+ # Check if circuit is open
+ if func._failures >= max_failures:
+ raise CircuitBreakerOpenError(f"Circuit breaker open for {func.__name__}")
+
+ try:
+ result = func(*args, **kwargs)
+ func._failures = 0 # Reset on success
+ return result
+ except Exception:
+ func._failures += 1
+ func._last_failure = current_time
+ raise
+
+ return wrapper
+
+ return decorator
+
+
+def retry(max_attempts=3, base_delay=1.0):
+ """Simple retry decorator - temporary implementation"""
+
+ def decorator(func):
+ def wrapper(*args, **kwargs):
+ import random
+ import time
+
+ last_exception = None
+
+ for attempt in range(max_attempts):
+ try:
+ return func(*args, **kwargs)
+ except Exception as e:
+ last_exception = e
+ if attempt < max_attempts - 1: # Don't sleep on last attempt
+ delay = base_delay * (2**attempt) + random.uniform(0, 1)
+ time.sleep(delay)
+
+ # If we get here, all attempts failed
+ raise last_exception
+
+ return wrapper
+
+ return decorator
diff --git a/workers/shared/utils/status_mapping.py b/workers/shared/utils/status_mapping.py
new file mode 100644
index 000000000..c21d9cb37
--- /dev/null
+++ b/workers/shared/utils/status_mapping.py
@@ -0,0 +1,59 @@
+"""Status Mapping Utilities
+
+Map between core domain status and worker implementation status.
+"""
+
+import os
+import sys
+
+# Import shared domain models from core
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../unstract/core/src"))
+from unstract.core import ExecutionStatus
+
+# Import worker enums
+from ..enums import PipelineStatus
+
+
+class StatusMappings:
+ """Utilities for mapping between different status systems."""
+
+ EXECUTION_TO_PIPELINE = {
+ ExecutionStatus.COMPLETED: PipelineStatus.SUCCESS,
+ ExecutionStatus.ERROR: PipelineStatus.FAILURE,
+ ExecutionStatus.STOPPED: PipelineStatus.FAILURE,
+ ExecutionStatus.EXECUTING: PipelineStatus.INPROGRESS,
+ ExecutionStatus.PENDING: PipelineStatus.YET_TO_START,
+ ExecutionStatus.QUEUED: PipelineStatus.YET_TO_START, # Legacy compatibility
+ ExecutionStatus.CANCELED: PipelineStatus.FAILURE, # Legacy compatibility
+ }
+
+ PIPELINE_TO_EXECUTION = {
+ PipelineStatus.SUCCESS: ExecutionStatus.COMPLETED,
+ PipelineStatus.FAILURE: ExecutionStatus.ERROR,
+ PipelineStatus.INPROGRESS: ExecutionStatus.EXECUTING,
+ PipelineStatus.YET_TO_START: ExecutionStatus.PENDING,
+ PipelineStatus.PARTIAL_SUCCESS: ExecutionStatus.COMPLETED,
+ }
+
+ @classmethod
+ def map_execution_to_pipeline(
+ cls, execution_status: ExecutionStatus
+ ) -> PipelineStatus:
+ """Map execution status to pipeline status."""
+ return cls.EXECUTION_TO_PIPELINE.get(execution_status, PipelineStatus.FAILURE)
+
+ @classmethod
+ def map_pipeline_to_execution(
+ cls, pipeline_status: PipelineStatus
+ ) -> ExecutionStatus:
+ """Map pipeline status to execution status."""
+ return cls.PIPELINE_TO_EXECUTION.get(pipeline_status, ExecutionStatus.ERROR)
+
+ @classmethod
+ def is_final_status(cls, status: ExecutionStatus) -> bool:
+ """Check if execution status is final (no further processing)."""
+ return status in [
+ ExecutionStatus.COMPLETED,
+ ExecutionStatus.ERROR,
+ ExecutionStatus.STOPPED,
+ ]
diff --git a/workers/shared/utils/task_helpers.py b/workers/shared/utils/task_helpers.py
new file mode 100644
index 000000000..4616d0a2b
--- /dev/null
+++ b/workers/shared/utils/task_helpers.py
@@ -0,0 +1,37 @@
+"""Task Helper Utilities
+
+Helper functions for task configuration and management.
+"""
+
+# Avoid circular import - define constants directly
+# from ..infrastructure.config import DefaultConfig
+
+# Default timeouts to avoid circular imports
+DEFAULT_FILE_PROCESSING_TIMEOUT = 1800 # 30 minutes
+DEFAULT_CALLBACK_TIMEOUT = 600 # 10 minutes
+DEFAULT_WEBHOOK_TIMEOUT = 30 # 30 seconds
+
+# Default retry counts to avoid circular imports
+DEFAULT_FILE_PROCESSING_MAX_RETRIES = 3
+DEFAULT_CALLBACK_MAX_RETRIES = 2
+DEFAULT_WEBHOOK_MAX_RETRIES = 3
+
+
+def get_task_timeout(task_name: str) -> int:
+ """Get timeout for specific task type."""
+ timeouts = {
+ "process_file_batch": DEFAULT_FILE_PROCESSING_TIMEOUT,
+ "process_batch_callback": DEFAULT_CALLBACK_TIMEOUT,
+ "send_webhook_notification": DEFAULT_WEBHOOK_TIMEOUT,
+ }
+ return timeouts.get(task_name, 300) # 5 minutes default
+
+
+def get_task_max_retries(task_name: str) -> int:
+ """Get max retries for specific task type."""
+ retries = {
+ "process_file_batch": DEFAULT_FILE_PROCESSING_MAX_RETRIES,
+ "process_batch_callback": DEFAULT_CALLBACK_MAX_RETRIES,
+ "send_webhook_notification": DEFAULT_WEBHOOK_MAX_RETRIES,
+ }
+ return retries.get(task_name, 3) # Default 3 retries
diff --git a/workers/shared/utils/validation.py b/workers/shared/utils/validation.py
new file mode 100644
index 000000000..09d82a82a
--- /dev/null
+++ b/workers/shared/utils/validation.py
@@ -0,0 +1,31 @@
+"""Validation Utilities
+
+Input validation functions for workers.
+"""
+
+import os
+import re
+
+from ..constants import SecurityConfig
+
+
+def validate_execution_id(execution_id: str) -> bool:
+ """Validate execution ID format."""
+ return bool(re.match(SecurityConfig.VALID_UUID_PATTERN, execution_id))
+
+
+def validate_organization_id(org_id: str) -> bool:
+ """Validate organization ID format."""
+ return bool(re.match(SecurityConfig.VALID_ORGANIZATION_ID_PATTERN, org_id))
+
+
+def sanitize_filename(filename: str) -> str:
+ """Sanitize filename for safe storage."""
+ # Remove invalid characters
+ sanitized = re.sub(r'[<>:"/\\|?*\x00-\x1f]', "_", filename)
+ # Limit length
+ if len(sanitized) > SecurityConfig.MAX_FILE_NAME_LENGTH:
+ name, ext = os.path.splitext(sanitized)
+ max_name_length = SecurityConfig.MAX_FILE_NAME_LENGTH - len(ext)
+ sanitized = name[:max_name_length] + ext
+ return sanitized
diff --git a/workers/shared/worker_builder.py b/workers/shared/worker_builder.py
new file mode 100644
index 000000000..f229dec57
--- /dev/null
+++ b/workers/shared/worker_builder.py
@@ -0,0 +1,235 @@
+"""Worker Builder - Factory for Creating Configured Celery Workers
+
+This module provides a builder pattern for creating Celery workers with
+standardized configuration, reducing duplication across worker implementations.
+
+Migration Note: This is the core factory that creates workers using the
+centralized registry, replacing individual worker.py configuration code.
+"""
+
+import logging
+import os
+from typing import Any
+
+from celery import Celery
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure.config import WorkerConfig
+from shared.infrastructure.config.registry import WorkerRegistry
+from shared.infrastructure.logging import WorkerLogger
+from shared.infrastructure.monitoring.health import HealthChecker, HealthServer
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerBuilder:
+ """Builder for creating configured Celery workers.
+
+ This class uses the builder pattern to create fully configured
+ Celery workers with health checks, logging, and proper routing.
+ """
+
+ @staticmethod
+ def build_celery_app(
+ worker_type: WorkerType,
+ app_name: str | None = None,
+ override_config: dict[str, Any] | None = None,
+ ) -> tuple[Celery, WorkerConfig]:
+ """Build a configured Celery app for the specified worker type.
+
+ Args:
+ worker_type: Type of worker to build
+ app_name: Optional custom app name
+ override_config: Optional config overrides
+
+ Returns:
+ Tuple of (Celery app, WorkerConfig)
+
+ Raises:
+ ValueError: If worker type is not properly configured
+ """
+ logger.info(f"Building Celery app for {worker_type}")
+
+ # Get configuration from environment
+ config = WorkerConfig.from_env(worker_type.name)
+
+ # Get complete configuration from registry
+ worker_celery_config = WorkerRegistry.get_complete_config(worker_type)
+
+ # Create Celery app
+ app_name = app_name or f"{worker_type.value}_worker"
+ app = Celery(app_name)
+
+ # Build Celery configuration
+ celery_config = worker_celery_config.to_celery_dict(
+ broker_url=config.celery_broker_url,
+ result_backend=config.celery_result_backend,
+ )
+
+ # Apply any overrides
+ if override_config:
+ celery_config.update(override_config)
+
+ # Apply configuration to Celery app
+ app.conf.update(celery_config)
+
+ logger.info(
+ f"Built {worker_type} worker with queues: "
+ f"{worker_celery_config.queue_config.all_queues()}"
+ )
+
+ return app, config
+
+ @staticmethod
+ def setup_logging(worker_type: WorkerType) -> logging.Logger:
+ """Setup standardized logging for a worker.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Configured logger instance
+ """
+ logging_config = WorkerRegistry.get_logging_config(worker_type)
+
+ WorkerLogger.configure(
+ log_level=os.getenv("LOG_LEVEL", logging_config.get("log_level", "INFO")),
+ log_format=os.getenv(
+ "LOG_FORMAT", logging_config.get("log_format", "structured")
+ ),
+ worker_name=worker_type.to_worker_name(),
+ )
+
+ return WorkerLogger.get_logger(worker_type.to_worker_name())
+
+ @staticmethod
+ def setup_health_monitoring(
+ worker_type: WorkerType, config: WorkerConfig
+ ) -> tuple[HealthChecker, HealthServer]:
+ """Setup health monitoring for a worker.
+
+ Args:
+ worker_type: Type of worker
+ config: Worker configuration
+
+ Returns:
+ Tuple of (HealthChecker, HealthServer)
+ """
+ health_checker = HealthChecker(config)
+
+ # Register all health checks from registry
+ for name, check_func in WorkerRegistry.get_health_checks(worker_type):
+ health_checker.add_custom_check(name, check_func)
+
+ # Get health port from worker type or environment
+ health_port = int(
+ os.getenv(
+ f"{worker_type.name}_HEALTH_PORT", str(worker_type.to_health_port())
+ )
+ )
+
+ health_server = HealthServer(health_checker=health_checker, port=health_port)
+
+ logger.info(f"Health monitoring configured on port {health_port}")
+
+ return health_checker, health_server
+
+ @staticmethod
+ def create_worker(
+ worker_type: WorkerType,
+ with_health: bool = True,
+ with_logging: bool = True,
+ override_config: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Create a complete worker with all components.
+
+ Args:
+ worker_type: Type of worker to create
+ with_health: Enable health monitoring
+ with_logging: Setup logging
+ override_config: Optional config overrides
+
+ Returns:
+ Dictionary with worker components:
+ - app: Celery application
+ - config: WorkerConfig
+ - logger: Logger instance (if with_logging)
+ - health_checker: HealthChecker (if with_health)
+ - health_server: HealthServer (if with_health)
+ """
+ components = {}
+
+ # Setup logging if requested
+ if with_logging:
+ components["logger"] = WorkerBuilder.setup_logging(worker_type)
+ components["logger"].info(f"Creating {worker_type} worker")
+
+ # Build Celery app
+ app, config = WorkerBuilder.build_celery_app(
+ worker_type, override_config=override_config
+ )
+ components["app"] = app
+ components["config"] = config
+
+ # Setup health monitoring if requested
+ if with_health:
+ health_checker, health_server = WorkerBuilder.setup_health_monitoring(
+ worker_type, config
+ )
+ components["health_checker"] = health_checker
+ components["health_server"] = health_server
+
+ if with_logging:
+ components["logger"].info(f"{worker_type} worker created successfully")
+
+ return components
+
+ @staticmethod
+ def validate_worker(worker_type: WorkerType) -> list[str]:
+ """Validate worker configuration before building.
+
+ Args:
+ worker_type: Type of worker to validate
+
+ Returns:
+ List of validation errors (empty if valid)
+ """
+ errors = []
+
+ # Check if worker is registered
+ try:
+ WorkerRegistry.get_queue_config(worker_type)
+ except KeyError:
+ errors.append(f"No queue configuration for {worker_type}")
+
+ try:
+ WorkerRegistry.get_task_routing(worker_type)
+ except KeyError:
+ errors.append(f"No task routing for {worker_type}")
+
+ # Check if tasks module exists
+ import_path = worker_type.to_import_path()
+ try:
+ import importlib
+
+ importlib.import_module(import_path)
+ except ImportError as e:
+ errors.append(f"Cannot import {import_path}: {e}")
+
+ return errors
+
+ @staticmethod
+ def get_cli_command(worker_type: WorkerType) -> list[str]:
+ """Get Celery CLI command for running the worker.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ List of command arguments for celery worker
+ """
+ worker_config = WorkerRegistry.get_complete_config(worker_type)
+ return worker_config.to_cli_args()
+
+
+# LegacyWorkerAdapter removed - no more fallback logic
+# All workers now use the direct WorkerBuilder.build_celery_app() approach
diff --git a/workers/shared/worker_registry.py b/workers/shared/worker_registry.py
new file mode 100644
index 000000000..d709a7311
--- /dev/null
+++ b/workers/shared/worker_registry.py
@@ -0,0 +1,391 @@
+"""Worker Registry - Central Configuration Hub
+
+This module provides a centralized registry for all worker configurations,
+including queue configs, task routing, health checks, and logging settings.
+
+Migration Note: This replaces scattered configuration across multiple worker.py
+files with a single source of truth, making it easier to maintain and update
+worker configurations.
+"""
+
+import logging
+from collections.abc import Callable
+
+from shared.enums.worker_enums import QueueName, WorkerType
+from shared.models.worker_models import (
+ TaskRoute,
+ WorkerCeleryConfig,
+ WorkerHealthConfig,
+ WorkerQueueConfig,
+ WorkerTaskRouting,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerRegistry:
+ """Central registry for all worker configurations.
+
+ This class acts as the single source of truth for:
+ - Queue configurations
+ - Task routing rules
+ - Health check functions
+ - Logging configurations
+ - Worker-specific settings
+ """
+
+ # Queue configurations for each worker type
+ _QUEUE_CONFIGS: dict[WorkerType, WorkerQueueConfig] = {
+ WorkerType.API_DEPLOYMENT: WorkerQueueConfig(
+ primary_queue=QueueName.API_DEPLOYMENTS
+ ),
+ WorkerType.GENERAL: WorkerQueueConfig(primary_queue=QueueName.GENERAL),
+ WorkerType.FILE_PROCESSING: WorkerQueueConfig(
+ primary_queue=QueueName.FILE_PROCESSING,
+ additional_queues=[QueueName.FILE_PROCESSING_API],
+ ),
+ WorkerType.CALLBACK: WorkerQueueConfig(
+ primary_queue=QueueName.CALLBACK, additional_queues=[QueueName.CALLBACK_API]
+ ),
+ WorkerType.NOTIFICATION: WorkerQueueConfig(
+ primary_queue=QueueName.NOTIFICATION,
+ additional_queues=[
+ QueueName.NOTIFICATION_WEBHOOK,
+ QueueName.NOTIFICATION_EMAIL,
+ QueueName.NOTIFICATION_SMS,
+ QueueName.NOTIFICATION_PRIORITY,
+ ],
+ ),
+ WorkerType.LOG_CONSUMER: WorkerQueueConfig(
+ primary_queue=QueueName.LOG_CONSUMER,
+ additional_queues=[QueueName.PERIODIC_LOGS],
+ ),
+ WorkerType.SCHEDULER: WorkerQueueConfig(
+ primary_queue=QueueName.SCHEDULER, additional_queues=[QueueName.GENERAL]
+ ),
+ }
+
+ # Task routing rules for each worker type
+ _TASK_ROUTES: dict[WorkerType, WorkerTaskRouting] = {
+ WorkerType.API_DEPLOYMENT: WorkerTaskRouting(
+ worker_type=WorkerType.API_DEPLOYMENT,
+ routes=[
+ TaskRoute("async_execute_bin_api", QueueName.API_DEPLOYMENTS),
+ TaskRoute("api_deployment_cleanup", QueueName.API_DEPLOYMENTS),
+ TaskRoute("api_deployment_status_check", QueueName.API_DEPLOYMENTS),
+ TaskRoute("api_deployment_worker.*", QueueName.API_DEPLOYMENTS),
+ ],
+ ),
+ WorkerType.GENERAL: WorkerTaskRouting(
+ worker_type=WorkerType.GENERAL,
+ routes=[
+ TaskRoute("async_execute_bin", QueueName.GENERAL),
+ TaskRoute("async_execute_bin_general", QueueName.GENERAL),
+ TaskRoute("general_worker.*", QueueName.GENERAL),
+ ],
+ ),
+ WorkerType.FILE_PROCESSING: WorkerTaskRouting(
+ worker_type=WorkerType.FILE_PROCESSING,
+ routes=[
+ TaskRoute("process_file_batch", QueueName.FILE_PROCESSING),
+ TaskRoute("process_file_batch_api", QueueName.FILE_PROCESSING_API),
+ ],
+ ),
+ WorkerType.CALLBACK: WorkerTaskRouting(
+ worker_type=WorkerType.CALLBACK,
+ routes=[
+ TaskRoute("process_batch_callback", QueueName.CALLBACK),
+ TaskRoute("process_batch_callback_api", QueueName.CALLBACK_API),
+ # TaskRoute("finalize_execution_callback", QueueName.CALLBACK), removed - dead code
+ ],
+ ),
+ WorkerType.NOTIFICATION: WorkerTaskRouting(
+ worker_type=WorkerType.NOTIFICATION,
+ routes=[
+ TaskRoute("process_notification", QueueName.NOTIFICATION),
+ TaskRoute("send_webhook_notification", QueueName.NOTIFICATION),
+ TaskRoute("send_batch_notifications", QueueName.NOTIFICATION),
+ TaskRoute("notification_health_check", QueueName.NOTIFICATION),
+ TaskRoute("notification.tasks.*", QueueName.NOTIFICATION),
+ TaskRoute("send_email_notification", QueueName.NOTIFICATION_EMAIL),
+ TaskRoute("send_sms_notification", QueueName.NOTIFICATION_SMS),
+ TaskRoute("priority_notification", QueueName.NOTIFICATION_PRIORITY),
+ ],
+ ),
+ WorkerType.LOG_CONSUMER: WorkerTaskRouting(
+ worker_type=WorkerType.LOG_CONSUMER,
+ routes=[
+ TaskRoute("logs_consumer", QueueName.LOG_CONSUMER),
+ TaskRoute("consume_log_history", QueueName.PERIODIC_LOGS),
+ TaskRoute("log_consumer.tasks.*", QueueName.LOG_CONSUMER),
+ TaskRoute("log_consumer_health_check", QueueName.LOG_CONSUMER),
+ ],
+ ),
+ WorkerType.SCHEDULER: WorkerTaskRouting(
+ worker_type=WorkerType.SCHEDULER,
+ routes=[
+ TaskRoute("execute_pipeline_task", QueueName.SCHEDULER),
+ TaskRoute("execute_pipeline_task_v2", QueueName.SCHEDULER),
+ TaskRoute("scheduler_health_check", QueueName.SCHEDULER),
+ TaskRoute("scheduler.tasks.*", QueueName.SCHEDULER),
+ ],
+ ),
+ }
+
+ # Health check functions registry
+ _HEALTH_CHECKS: dict[WorkerType, list[tuple[str, Callable]]] = {}
+
+ # Worker-specific Celery settings
+ _WORKER_SETTINGS: dict[WorkerType, dict] = {
+ WorkerType.FILE_PROCESSING: {
+ "pool_type": "threads",
+ "concurrency": 4,
+ "prefetch_multiplier": 4, # Fix task starvation: 4×4=16 task buffer
+ "max_tasks_per_child": 100, # Lower due to memory usage
+ },
+ WorkerType.CALLBACK: {
+ "autoscale": (4, 1),
+ "prefetch_multiplier": 2,
+ "max_tasks_per_child": 2000,
+ "task_time_limit": 3600, # 1 hour
+ "task_soft_time_limit": 3300, # 55 minutes
+ },
+ WorkerType.NOTIFICATION: {
+ "task_time_limit": 30, # 30 seconds for webhooks
+ "task_max_retries": 3,
+ },
+ WorkerType.LOG_CONSUMER: {
+ "prefetch_multiplier": 1,
+ "max_tasks_per_child": 1000,
+ },
+ }
+
+ # Logging configurations
+ _LOGGING_CONFIGS: dict[WorkerType, dict] = {
+ WorkerType.API_DEPLOYMENT: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.GENERAL: {
+ "log_format": "structured",
+ "log_level": "INFO",
+ },
+ WorkerType.FILE_PROCESSING: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.CALLBACK: {
+ "log_format": "django",
+ "log_level": "INFO",
+ },
+ WorkerType.NOTIFICATION: {
+ "log_format": "structured",
+ "log_level": "INFO",
+ },
+ WorkerType.LOG_CONSUMER: {
+ "log_format": "structured",
+ "log_level": "INFO",
+ },
+ WorkerType.SCHEDULER: {
+ "log_format": "structured",
+ "log_level": "INFO",
+ },
+ }
+
+ @classmethod
+ def get_queue_config(cls, worker_type: WorkerType) -> WorkerQueueConfig:
+ """Get queue configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Queue configuration
+
+ Raises:
+ KeyError: If worker type not registered
+ """
+ if worker_type not in cls._QUEUE_CONFIGS:
+ raise KeyError(f"No queue config registered for {worker_type}")
+ return cls._QUEUE_CONFIGS[worker_type]
+
+ @classmethod
+ def get_task_routing(cls, worker_type: WorkerType) -> WorkerTaskRouting:
+ """Get task routing configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Task routing configuration
+
+ Raises:
+ KeyError: If worker type not registered
+ """
+ if worker_type not in cls._TASK_ROUTES:
+ raise KeyError(f"No task routing registered for {worker_type}")
+ return cls._TASK_ROUTES[worker_type]
+
+ @classmethod
+ def register_health_check(
+ cls, worker_type: WorkerType, name: str, check_func: Callable
+ ) -> None:
+ """Register a health check function for a worker type.
+
+ Args:
+ worker_type: Type of worker
+ name: Name of the health check
+ check_func: Health check function
+ """
+ if worker_type not in cls._HEALTH_CHECKS:
+ cls._HEALTH_CHECKS[worker_type] = []
+
+ cls._HEALTH_CHECKS[worker_type].append((name, check_func))
+ logger.info(f"Registered health check '{name}' for {worker_type}")
+
+ @classmethod
+ def get_health_checks(cls, worker_type: WorkerType) -> list[tuple[str, Callable]]:
+ """Get all health check functions for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ List of (name, function) tuples
+ """
+ return cls._HEALTH_CHECKS.get(worker_type, [])
+
+ @classmethod
+ def get_worker_settings(cls, worker_type: WorkerType) -> dict:
+ """Get worker-specific Celery settings.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Dictionary of worker-specific settings
+ """
+ return cls._WORKER_SETTINGS.get(worker_type, {})
+
+ @classmethod
+ def get_logging_config(cls, worker_type: WorkerType) -> dict:
+ """Get logging configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Logging configuration dict
+ """
+ return cls._LOGGING_CONFIGS.get(
+ worker_type,
+ {
+ "log_format": "structured",
+ "log_level": "INFO",
+ },
+ )
+
+ @classmethod
+ def get_complete_config(cls, worker_type: WorkerType) -> WorkerCeleryConfig:
+ """Get complete configuration for a worker type.
+
+ Args:
+ worker_type: Type of worker
+
+ Returns:
+ Complete WorkerCeleryConfig object
+ """
+ queue_config = cls.get_queue_config(worker_type)
+ task_routing = cls.get_task_routing(worker_type)
+ settings = cls.get_worker_settings(worker_type)
+
+ # Build health config
+ health_checks = cls.get_health_checks(worker_type)
+ health_config = WorkerHealthConfig(
+ port=worker_type.to_health_port(), custom_checks=health_checks
+ )
+
+ # Create complete config with defaults and overrides
+ config = WorkerCeleryConfig(
+ worker_type=worker_type,
+ queue_config=queue_config,
+ task_routing=task_routing,
+ health_config=health_config,
+ )
+
+ # Apply worker-specific settings
+ for key, value in settings.items():
+ if hasattr(config, key):
+ setattr(config, key, value)
+
+ return config
+
+ @classmethod
+ def validate_registry(cls) -> list[str]:
+ """Validate the registry configuration.
+
+ Returns:
+ List of validation errors (empty if all valid)
+ """
+ errors = []
+
+ # Check all WorkerTypes have configurations
+ for worker_type in WorkerType:
+ if worker_type not in cls._QUEUE_CONFIGS:
+ errors.append(f"Missing queue config for {worker_type}")
+
+ if worker_type not in cls._TASK_ROUTES:
+ errors.append(f"Missing task routes for {worker_type}")
+
+ # Validate queue names in task routes
+ for worker_type, routing in cls._TASK_ROUTES.items():
+ queue_config = cls._QUEUE_CONFIGS.get(worker_type)
+ if not queue_config:
+ continue
+
+ valid_queues = queue_config.all_queues()
+ for route in routing.routes:
+ if route.queue.value not in valid_queues:
+ # Check if it's a valid queue for cross-worker routing
+ if route.queue not in QueueName:
+ errors.append(
+ f"Invalid queue {route.queue} in {worker_type} routing"
+ )
+
+ return errors
+
+ @classmethod
+ def list_workers(cls) -> list[dict]:
+ """List all registered workers with their configurations.
+
+ Returns:
+ List of worker configuration summaries
+ """
+ workers = []
+ for worker_type in WorkerType:
+ try:
+ queue_config = cls.get_queue_config(worker_type)
+ task_routing = cls.get_task_routing(worker_type)
+ health_checks = cls.get_health_checks(worker_type)
+
+ workers.append(
+ {
+ "type": worker_type.value,
+ "name": worker_type.to_worker_name(),
+ "import_path": worker_type.to_import_path(),
+ "health_port": worker_type.to_health_port(),
+ "queues": list(queue_config.all_queues()),
+ "task_count": len(task_routing.routes),
+ "health_checks": len(health_checks),
+ }
+ )
+ except KeyError:
+ workers.append(
+ {
+ "type": worker_type.value,
+ "name": worker_type.to_worker_name(),
+ "error": "Not configured in registry",
+ }
+ )
+
+ return workers
diff --git a/workers/shared/workflow/__init__.py b/workers/shared/workflow/__init__.py
new file mode 100644
index 000000000..e3c0599c0
--- /dev/null
+++ b/workers/shared/workflow/__init__.py
@@ -0,0 +1,19 @@
+"""Workflow Service Components
+
+This package contains specialized workflow service components for handling
+workflow execution sources, destinations and related functionality.
+
+Components:
+- SourceConnector: Handles workflow input sources (filesystem, API storage, etc.)
+- DestinationConnector: Handles workflow output destinations (database, filesystem, API, etc.)
+"""
+
+from .destination_connector import DestinationConfig, WorkerDestinationConnector
+from .source_connector import SourceConfig, WorkerSourceConnector
+
+__all__ = [
+ "WorkerDestinationConnector",
+ "DestinationConfig",
+ "WorkerSourceConnector",
+ "SourceConfig",
+]
diff --git a/workers/shared/workflow/connectors/__init__.py b/workers/shared/workflow/connectors/__init__.py
new file mode 100644
index 000000000..0a2e9bbaa
--- /dev/null
+++ b/workers/shared/workflow/connectors/__init__.py
@@ -0,0 +1,13 @@
+"""Connector services for workflow data sources and destinations.
+
+This package provides connector services for various data sources
+and destinations used in workflow executions.
+"""
+
+from .service import WorkerConnectorService
+from .source import WorkerSourceConnector
+
+__all__ = [
+ "WorkerConnectorService",
+ "WorkerSourceConnector",
+]
diff --git a/workers/shared/workflow/connectors/service.py b/workers/shared/workflow/connectors/service.py
new file mode 100644
index 000000000..166d33ef1
--- /dev/null
+++ b/workers/shared/workflow/connectors/service.py
@@ -0,0 +1,46 @@
+"""Worker-Native Connector Service
+
+This module provides connector factory operations for workers.
+"""
+
+from typing import Any
+
+# Import shared operations
+from unstract.connectors.operations import ConnectorOperations
+
+from ...api.internal_client import InternalAPIClient
+from ...infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WorkerConnectorService:
+ """Factory service for creating destination connectors in workers"""
+
+ def __init__(self, api_client: InternalAPIClient):
+ """Initialize connector service.
+
+ Args:
+ api_client: API client (preserved for compatibility but unused)
+ """
+ self.api_client = api_client # Preserved for compatibility
+
+ def _get_destination_connector(
+ self, connector_id: str, connector_settings: dict[str, Any]
+ ):
+ """Get destination connector using exact backend registry pattern.
+
+ This method uses the same connector registry pattern as:
+ - backend/workflow_manager/endpoint_v2/destination.py
+ - backend/workflow_manager/endpoint_v2/base_connector.py
+
+ Args:
+ connector_id: Connector ID from registry (not connection_type)
+ connector_settings: Connector configuration settings
+
+ Returns:
+ Connector instance
+ """
+ return ConnectorOperations.get_fs_connector(
+ connector_id=connector_id, settings=connector_settings
+ )
diff --git a/workers/shared/workflow/connectors/source.py b/workers/shared/workflow/connectors/source.py
new file mode 100644
index 000000000..5ff0bb0dc
--- /dev/null
+++ b/workers/shared/workflow/connectors/source.py
@@ -0,0 +1,612 @@
+"""Unified Source Connector for Workers
+
+This module provides a worker-compatible implementation of the SourceConnector
+that matches the exact logic from backend/workflow_manager/endpoint_v2/source.py
+"""
+
+import logging
+from typing import Any
+
+from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
+from unstract.core.data_models import (
+ ConnectorInstanceData,
+ FileHashData,
+ FileOperationConstants,
+ SourceConnectionType,
+ SourceKey,
+ WorkflowEndpointConfigData,
+ WorkflowEndpointConfigResponseData,
+)
+from unstract.core.file_operations import FileOperations
+
+from ...api.internal_client import InternalAPIClient
+from ...enums.file_types import FileProcessingOrder
+from .utils import get_connector_instance
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerSourceConnector:
+ """Worker-compatible source connector matching backend source.py logic exactly.
+
+ This class provides the same file listing functionality as the backend
+ SourceConnector but adapted for worker processes that communicate via
+ internal APIs rather than direct database access.
+ """
+
+ READ_CHUNK_SIZE = FileOperationConstants.READ_CHUNK_SIZE
+
+ def __init__(
+ self,
+ api_client: InternalAPIClient,
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ use_file_history: bool = False,
+ ):
+ """Initialize the worker source connector.
+
+ Args:
+ api_client: Internal API client for backend communication
+ workflow_id: Workflow ID
+ execution_id: Execution ID
+ organization_id: Organization ID
+ use_file_history: Whether to use file history for deduplication
+ """
+ self.api_client = api_client
+ self.workflow_id = workflow_id
+ self.execution_id = execution_id
+ self.organization_id = organization_id
+ self.use_file_history = use_file_history
+ self.logger = logger
+
+ # Get workflow endpoint configuration via API
+ self.endpoint_config: WorkflowEndpointConfigData | None = (
+ self._get_endpoint_configuration()
+ )
+ self.is_api: bool = self._is_api()
+
+ def _is_api(self) -> bool:
+ """Check if the source connector is an API connector."""
+ if self.endpoint_config:
+ return self.endpoint_config.connection_type == SourceConnectionType.API
+ return False
+
+ def _get_endpoint_configuration(self) -> WorkflowEndpointConfigData | None:
+ """Get workflow endpoint configuration from backend."""
+ try:
+ workflow_endpoint_config: WorkflowEndpointConfigResponseData = (
+ self.api_client.get_workflow_endpoints(
+ workflow_id=self.workflow_id,
+ organization_id=self.organization_id,
+ )
+ )
+ return workflow_endpoint_config.source_endpoint
+ except Exception as e:
+ logger.error(f"Failed to get endpoint configuration: {e}")
+ raise
+
+ def list_files_from_source(
+ self, file_hashes: dict[str, FileHashData] | None = None
+ ) -> tuple[dict[str, FileHashData], int]:
+ """List files from source connector matching backend source.py:721.
+
+ Args:
+ file_hashes: Optional existing file hashes for API workflows
+
+ Returns:
+ tuple: (matched_files, total_count)
+ """
+ connection_type = self.endpoint_config.connection_type
+
+ if connection_type == SourceConnectionType.FILESYSTEM:
+ files, count = self.list_files_from_file_connector()
+ elif connection_type == SourceConnectionType.API:
+ files, count = self.list_files_from_api_storage(file_hashes or {})
+ else:
+ raise ValueError(f"Invalid source connection type: {connection_type}")
+
+ # Number files (matching backend source.py:740)
+ for index, file_hash in enumerate(files.values(), start=1):
+ file_hash.file_number = index
+
+ return files, count
+
+ def list_files_from_file_connector(self) -> tuple[dict[str, FileHashData], int]:
+ """List files from filesystem connector using streaming discovery.
+
+ This method now uses the new StreamingFileDiscovery system that:
+ 1. Applies all filters during discovery (not after)
+ 2. Stops immediately when limit is reached
+ 3. Uses batch processing for efficiency
+
+ Returns:
+ tuple: (matched_files, total_count)
+ """
+ # Get connector configuration
+ connector_config: ConnectorInstanceData | None = (
+ self.endpoint_config.connector_instance
+ )
+ connector_id = connector_config.connector_id if connector_config else None
+ connector_settings = (
+ connector_config.connector_metadata if connector_config else None
+ )
+
+ # Get source configuration using unified SourceKey helper methods
+ source_config = self.endpoint_config.configuration if self.endpoint_config else {}
+ required_patterns = SourceKey.get_file_extensions(source_config)
+ recursive = SourceKey.get_process_sub_directories(source_config)
+ limit = SourceKey.get_max_files(
+ source_config, FileOperationConstants.DEFAULT_MAX_FILES
+ )
+ # Get file processing order (matching backend source.py:175)
+ file_processing_order = FileProcessingOrder.from_value(
+ SourceKey.get_file_processing_order(source_config)
+ )
+ root_dir_path = connector_settings.get("path", "")
+ folders_to_process = SourceKey.get_folders(source_config)
+
+ logger.info(
+ f"Source connector configuration - Connector ID: {connector_id}, Root path: '{root_dir_path}', Folders: {folders_to_process}"
+ )
+ logger.info(
+ f"File processing limits - Max files: {limit}, Recursive: {recursive}, Patterns: {required_patterns}"
+ )
+ logger.debug(f"Raw source_config for max_files debug: {source_config}")
+
+ # Process from root if folder list is empty
+ if not folders_to_process:
+ folders_to_process = ["/"]
+
+ # Get valid patterns
+ patterns = FileOperations.valid_file_patterns(required_patterns)
+
+ logger.info(
+ f"Matching for patterns '{', '.join(patterns)}' from "
+ f"'{', '.join(folders_to_process)}'"
+ )
+
+ # Get filesystem connector
+ source_fs = self._get_fs_connector(
+ settings=connector_settings, connector_id=connector_id
+ )
+ source_fs_fsspec = source_fs.get_fsspec_fs()
+
+ # Validate directories
+ valid_directories = []
+ for input_directory in folders_to_process:
+ try:
+ # Use connector's root dir resolution (all connectors have this method)
+ resolved_directory = source_fs.get_connector_root_dir(
+ input_dir=input_directory, root_path=root_dir_path
+ )
+
+ logger.info(
+ f"[exec:{self.execution_id}] Checking directory: '{input_directory}' → '{resolved_directory}'"
+ )
+
+ # Use connector-specific directory check instead of generic fsspec.isdir()
+ # This is especially important for GCS where fsspec.isdir() doesn't work correctly
+ is_directory = False
+ try:
+ if hasattr(source_fs, "is_dir_by_metadata"):
+ # Get directory info and check using connector's method
+ dir_info = source_fs_fsspec.info(resolved_directory)
+ is_directory = source_fs.is_dir_by_metadata(dir_info)
+ else:
+ # Fallback to fsspec's isdir for other connectors
+ is_directory = source_fs_fsspec.isdir(resolved_directory)
+ except Exception as dir_check_error:
+ logger.warning(
+ f"[exec:{self.execution_id}] Failed to check if '{resolved_directory}' is directory: {dir_check_error}"
+ )
+ is_directory = False
+
+ if not is_directory:
+ logger.warning(
+ f"[exec:{self.execution_id}] Source directory not found or not accessible: '{resolved_directory}'. "
+ f"This may be expected if the directory doesn't exist in the connector storage."
+ )
+ continue
+
+ valid_directories.append(resolved_directory)
+ logger.info(
+ f"[exec:{self.execution_id}] ✓ Validated directory: '{resolved_directory}'"
+ )
+
+ except Exception as e:
+ logger.error(
+ f"[exec:{self.execution_id}] Error accessing directory '{input_directory}': {e}"
+ )
+ continue
+
+ # Choose processing strategy based on file_processing_order (matching backend source.py:215-231)
+ if not valid_directories:
+ logger.warning("No valid directories found to process")
+ return {}, 0
+
+ if file_processing_order == FileProcessingOrder.UNORDERED:
+ # Use existing StreamingFileDiscovery for unordered processing
+ logger.info(
+ f"[exec:{self.execution_id}] Starting unordered streaming file discovery for {len(valid_directories)} directories"
+ )
+ matched_files, total_count = self._process_without_sorting(
+ source_fs=source_fs,
+ valid_directories=valid_directories,
+ patterns=patterns,
+ recursive=recursive,
+ limit=limit,
+ )
+ else:
+ # Use new sorting-based processing for OLDEST_FIRST/NEWEST_FIRST
+ logger.info(
+ f"[exec:{self.execution_id}] Starting ordered file processing ({file_processing_order.value}) for {len(valid_directories)} directories"
+ )
+ matched_files, total_count = self._process_with_sorting(
+ source_fs=source_fs,
+ valid_directories=valid_directories,
+ patterns=patterns,
+ recursive=recursive,
+ limit=limit,
+ file_processing_order=file_processing_order,
+ )
+
+ logger.info(
+ f"[exec:{self.execution_id}] Streaming discovery complete: {total_count} files found "
+ f"(limit was {limit})"
+ )
+
+ return matched_files, total_count
+
+ # NOTE: The old _get_matched_files method has been removed and replaced with
+ # StreamingFileDiscovery which applies all filters during discovery, not after.
+ # This eliminates duplicate filtering and improves performance significantly.
+
+ def get_max_files_limit(self) -> int:
+ """Get the max files limit from source configuration.
+
+ Returns:
+ Maximum number of files to process
+ """
+ source_config = self.endpoint_config.configuration if self.endpoint_config else {}
+ return SourceKey.get_max_files(
+ source_config, FileOperationConstants.DEFAULT_MAX_FILES
+ )
+
+ def list_files_from_api_storage(
+ self, existing_file_hashes: dict[str, FileHashData]
+ ) -> tuple[dict[str, FileHashData], int]:
+ """List files from API storage.
+
+ For API workflows, files are already uploaded and we just process them.
+ NOTE: File history filtering is NOT applied here for API workflows as they
+ have different processing patterns than ETL/TASK workflows.
+
+ Args:
+ existing_file_hashes: Pre-uploaded files
+
+ Returns:
+ tuple: (files, count)
+ """
+ logger.info(f"Listing {len(existing_file_hashes)} files from API storage")
+
+ # API workflows handle filtering differently - they don't use file history
+ # or active file filtering in the same way as ETL/TASK workflows
+ return existing_file_hashes, len(existing_file_hashes)
+
+ def _get_existing_file_executions_optimized(
+ self, provider_file_uuids: list[str]
+ ) -> dict[str, str]:
+ """Check specific files against active executions in single API call.
+
+ Instead of:
+ 1. Get ALL PENDING/EXECUTING executions (100+ executions)
+ 2. For each execution, get file executions (100+ API calls)
+ 3. Build massive lookup table
+
+ Do this:
+ 1. Single API call to check specific files
+ 2. Return only files that are actively being processed
+
+ Args:
+ provider_file_uuids: List of file UUIDs to check
+
+ Returns:
+ dict: Mapping of provider_file_uuid to status for files being processed
+ """
+ if not provider_file_uuids:
+ return {}
+
+ try:
+ if not self.workflow_id:
+ return {}
+
+ # Single optimized API call
+ response = self.api_client.check_files_active_processing(
+ workflow_id=self.workflow_id,
+ provider_file_uuids=provider_file_uuids,
+ current_execution_id=self.execution_id,
+ )
+
+ if not response.success:
+ logger.warning(
+ f"Failed to check files active processing: {response.error}"
+ )
+ return {}
+
+ active_data = response.data or {}
+ active_uuids = active_data.get("active_uuids", [])
+
+ if not active_uuids:
+ return {}
+
+ # Convert to expected format
+ result = {}
+ for uuid in active_uuids:
+ result[uuid] = "PENDING_OR_EXECUTING" # Status for filtering
+
+ return result
+
+ except Exception as e:
+ logger.warning(f"Error in optimized file execution check: {e}")
+ # Fallback to empty dict (assume no conflicts) to avoid blocking workflow
+ return {}
+
+ def _get_existing_file_executions(self) -> dict[str, str]:
+ """Get existing file executions for ALL active workflow executions.
+
+ This mimics the backend logic from source.py exactly:
+ 1. Get ALL active executions for the workflow (PENDING/EXECUTING status)
+ 2. For each active execution, get file executions
+ 3. Skip files that are being processed in ANY active execution
+
+ This prevents race conditions between concurrent executions of the same workflow.
+
+ Returns:
+ dict: Mapping of provider_file_uuid to execution status
+ """
+ try:
+ if not self.workflow_id:
+ return {}
+
+ from unstract.core.data_models import ExecutionStatus
+
+ # Step 1: Get ALL active workflow executions (matching backend _get_active_workflow_executions)
+ try:
+ # Get workflow executions with PENDING or EXECUTING status
+ workflow_response = self.api_client.get_workflow_executions_by_status(
+ workflow_id=self.workflow_id,
+ statuses=[
+ ExecutionStatus.PENDING.value,
+ ExecutionStatus.EXECUTING.value,
+ ],
+ )
+
+ if not workflow_response.success:
+ logger.warning(
+ f"Failed to get active workflow executions: {workflow_response.error}"
+ )
+ return {}
+
+ active_executions = workflow_response.data or []
+
+ if not active_executions:
+ logger.info(
+ f"No active executions found for workflow {self.workflow_id}"
+ )
+ return {}
+
+ logger.info(
+ f"Found {len(active_executions)} active executions for workflow {self.workflow_id}"
+ )
+
+ except Exception as workflow_error:
+ logger.warning(
+ f"Error getting active workflow executions: {workflow_error}"
+ )
+ return {}
+
+ # Step 2: For each active execution, get file executions (matching backend loop)
+ all_file_executions = {}
+
+ for execution_data in active_executions:
+ execution_id = execution_data.get("id")
+ execution_status = execution_data.get("status")
+
+ if not execution_id:
+ continue
+
+ logger.info(
+ f"Checking file executions for execution {execution_id} (status: {execution_status})"
+ )
+
+ try:
+ # Get file executions for this specific execution
+ response = self.api_client.get_workflow_file_executions_by_execution(
+ execution_id
+ )
+
+ if not response.success:
+ logger.warning(
+ f"Failed to get file executions for {execution_id}: {response.error}"
+ )
+ continue
+
+ file_executions_data = response.data or []
+
+ except Exception as api_error:
+ logger.warning(
+ f"Error getting file executions for {execution_id}: {api_error}"
+ )
+ continue
+
+ # Process file executions for this execution
+ if file_executions_data and isinstance(file_executions_data, list):
+ skip_statuses = ExecutionStatus.get_skip_processing_statuses()
+ skip_status_values = [status.value for status in skip_statuses]
+
+ for file_exec in file_executions_data:
+ provider_uuid = file_exec.get("provider_file_uuid")
+ status = file_exec.get("status")
+ file_name = file_exec.get("file_name", "unknown")
+ file_path = file_exec.get("file_path", "")
+
+ # Only include files that should be skipped (matching backend logic)
+ if provider_uuid and status and status in skip_status_values:
+ # Keep track of which execution is blocking this file
+ all_file_executions[provider_uuid] = {
+ "status": status,
+ "execution_id": execution_id,
+ "file_name": file_name,
+ "file_path": file_path,
+ }
+
+ # Convert to the expected format (provider_uuid -> status)
+ file_executions = {
+ uuid: data["status"] for uuid, data in all_file_executions.items()
+ }
+
+ if file_executions:
+ logger.info(
+ f"Found {len(file_executions)} existing file executions to skip across {len(active_executions)} active executions "
+ f"(PENDING: {sum(1 for s in file_executions.values() if s == ExecutionStatus.PENDING.value)}, "
+ f"EXECUTING: {sum(1 for s in file_executions.values() if s == ExecutionStatus.EXECUTING.value)}, "
+ f"COMPLETED: {sum(1 for s in file_executions.values() if s == ExecutionStatus.COMPLETED.value)})"
+ )
+ else:
+ logger.info(
+ f"No blocking file executions found across {len(active_executions)} active workflow executions. "
+ f"This is normal when no files are currently being processed."
+ )
+
+ return file_executions
+
+ except Exception as e:
+ logger.warning(f"Error getting existing file executions: {e}")
+ # Return empty dict to allow processing to continue
+ return {}
+
+ # NOTE: The _apply_file_history_filtering method has been removed.
+ # File history filtering is now handled by the FileHistoryFilter in FilterPipeline
+ # during streaming discovery, eliminating duplicate API calls.
+
+ def _get_fs_connector(
+ self, settings: dict[str, Any], connector_id: str
+ ) -> UnstractFileSystem:
+ """Get filesystem connector instance.
+
+ Args:
+ settings: Connector settings
+ connector_id: Connector ID
+
+ Returns:
+ UnstractFileSystem: Connector instance
+ """
+ return get_connector_instance(connector_id, settings)
+
+ def get_file_content_hash(self, source_fs: UnstractFileSystem, file_path: str) -> str:
+ """Get file content hash matching backend source.py:745.
+
+ Args:
+ source_fs: Filesystem connector
+ file_path: Path to file
+
+ Returns:
+ str: SHA256 hash of file content
+ """
+ return FileOperations.compute_file_content_hash_from_fsspec(source_fs, file_path)
+
+ def _process_without_sorting(
+ self,
+ source_fs: UnstractFileSystem,
+ valid_directories: list[str],
+ patterns: list[str],
+ recursive: bool,
+ limit: int,
+ ) -> tuple[dict[str, FileHashData], int]:
+ """Process files without ordering using StreamingFileDiscovery (existing logic).
+
+ This method wraps the existing StreamingFileDiscovery logic to maintain
+ compatibility with unordered processing while allowing ordered processing
+ via the new _process_with_sorting method.
+ """
+ # Import from shared processing module - no circular dependency
+ from ...processing.file_discovery import StreamingFileDiscovery
+ from ...processing.filter_pipeline import create_standard_pipeline
+
+ # Create the streaming discovery instance
+ streaming_discovery = StreamingFileDiscovery(
+ source_fs=source_fs,
+ api_client=self.api_client,
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ organization_id=self.organization_id,
+ connector_id=None, # Set to None if not available
+ )
+
+ # Create filter pipeline with all filters applied during discovery
+ # File history and active file filtering are now done during discovery, not after
+ filter_pipeline = create_standard_pipeline(
+ use_file_history=self.use_file_history,
+ enable_active_filtering=True, # Always enable for ETL/TASK workflows
+ )
+
+ # Discover files with streaming and early filtering
+ matched_files, total_count = streaming_discovery.discover_files_streaming(
+ directories=valid_directories,
+ patterns=patterns,
+ recursive=recursive,
+ file_hard_limit=limit, # Hard limit - will stop when reached
+ filter_pipeline=filter_pipeline,
+ batch_size=100, # Process files in batches of 100
+ )
+
+ return matched_files, total_count
+
+ def _process_with_sorting(
+ self,
+ source_fs: UnstractFileSystem,
+ valid_directories: list[str],
+ patterns: list[str],
+ recursive: bool,
+ limit: int,
+ file_processing_order: FileProcessingOrder,
+ ) -> tuple[dict[str, FileHashData], int]:
+ """Process files with ordering using OrderedFileDiscovery.
+
+ This method delegates to OrderedFileDiscovery for clean architecture separation.
+
+ Args:
+ source_fs: Filesystem connector
+ valid_directories: List of validated directories to process
+ patterns: File patterns to match
+ recursive: Whether to search recursively
+ limit: Maximum number of files to return
+ file_processing_order: Order to process files (OLDEST_FIRST or NEWEST_FIRST)
+
+ Returns:
+ tuple: (matched_files_dict, total_count)
+ """
+ # Lazy import to avoid circular dependencies
+ from ...processing.file_discovery import OrderedFileDiscovery
+
+ # Create ordered file discovery instance
+ ordered_discovery = OrderedFileDiscovery(
+ source_fs=source_fs,
+ api_client=self.api_client,
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ organization_id=self.organization_id,
+ use_file_history=self.use_file_history,
+ connector_id=None, # Set to None if not available
+ )
+
+ # Discover files with ordering and chunked filtering
+ return ordered_discovery.discover_files_ordered(
+ directories=valid_directories,
+ patterns=patterns,
+ recursive=recursive,
+ file_hard_limit=limit,
+ file_processing_order=file_processing_order.value, # Convert enum to string
+ batch_size=100, # Process in batches of 100 files
+ )
diff --git a/workers/shared/workflow/connectors/utils.py b/workers/shared/workflow/connectors/utils.py
new file mode 100644
index 000000000..e9eebd70f
--- /dev/null
+++ b/workers/shared/workflow/connectors/utils.py
@@ -0,0 +1,113 @@
+"""Connector utilities for workers.
+
+This module provides utilities for working with Unstract connectors
+in worker processes.
+"""
+
+import logging
+from typing import Any
+
+from unstract.connectors.connectorkit import Connectorkit
+from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
+
+logger = logging.getLogger(__name__)
+
+
+def get_connector_instance(
+ connector_id: str, settings: dict[str, Any]
+) -> UnstractFileSystem:
+ """Get a filesystem connector instance.
+
+ Args:
+ connector_id: Connector ID (e.g., "google_cloud_storage|uuid")
+ settings: Connector settings/credentials
+
+ Returns:
+ UnstractFileSystem: Instantiated connector
+
+ Raises:
+ ValueError: If connector not found or instantiation fails
+ """
+ try:
+ # Use Connectorkit to get connector class
+ connectorkit = Connectorkit()
+ connector_class = connectorkit.get_connector_class_by_connector_id(connector_id)
+
+ if not connector_class:
+ raise ValueError(f"Connector not found: {connector_id}")
+
+ # Instantiate connector with settings
+ connector = connector_class(settings)
+
+ logger.info(f"Successfully instantiated connector: {connector_id}")
+ return connector
+
+ except Exception as e:
+ logger.error(f"Failed to instantiate connector {connector_id}: {e}")
+ raise ValueError(f"Failed to instantiate connector: {e}")
+
+
+def validate_connector_settings(
+ connector_id: str, settings: dict[str, Any]
+) -> tuple[bool, str]:
+ """Validate connector settings.
+
+ Args:
+ connector_id: Connector ID
+ settings: Connector settings to validate
+
+ Returns:
+ tuple: (is_valid, error_message)
+ """
+ try:
+ # Try to instantiate connector - if it works, settings are valid
+ connector = get_connector_instance(connector_id, settings)
+
+ # Additional validation if connector supports it
+ if hasattr(connector, "validate_settings"):
+ return connector.validate_settings()
+
+ return True, ""
+
+ except Exception as e:
+ return False, str(e)
+
+
+def get_connector_capabilities(connector_id: str) -> dict[str, bool]:
+ """Get capabilities of a connector.
+
+ Args:
+ connector_id: Connector ID
+
+ Returns:
+ dict: Connector capabilities (can_read, can_write, etc.)
+ """
+ try:
+ # Use Connectorkit to get connector class
+ connectorkit = Connectorkit()
+ connector_class = connectorkit.get_connector_class_by_connector_id(connector_id)
+
+ if not connector_class:
+ return {"error": f"Connector not found: {connector_id}"}
+
+ return {
+ "can_read": connector_class.can_read()
+ if hasattr(connector_class, "can_read")
+ else False,
+ "can_write": connector_class.can_write()
+ if hasattr(connector_class, "can_write")
+ else False,
+ "requires_oauth": connector_class.requires_oauth()
+ if hasattr(connector_class, "requires_oauth")
+ else False,
+ "name": connector_class.get_name()
+ if hasattr(connector_class, "get_name")
+ else "Unknown",
+ "description": connector_class.get_description()
+ if hasattr(connector_class, "get_description")
+ else "",
+ }
+
+ except Exception as e:
+ logger.error(f"Failed to get connector capabilities: {e}")
+ return {"error": str(e)}
diff --git a/workers/shared/workflow/destination_connector.py b/workers/shared/workflow/destination_connector.py
new file mode 100644
index 000000000..a0bcc3c1c
--- /dev/null
+++ b/workers/shared/workflow/destination_connector.py
@@ -0,0 +1,1445 @@
+"""Destination Connector for Workflow Output Handling
+
+This module provides specialized destination connector for handling workflow outputs,
+extracted from the monolithic workflow_service.py to improve maintainability.
+
+Handles:
+- Filesystem destination output
+- Database destination output
+- API destination output
+- Manual review queue output
+- Output processing and validation
+"""
+
+import ast
+import base64
+import json
+import os
+import time
+from dataclasses import dataclass
+from typing import TYPE_CHECKING, Any, Optional
+
+from shared.enums import QueueResultStatus
+
+# Import database utils (stable path)
+from shared.infrastructure.database.utils import WorkerDatabaseUtils
+from shared.models.result_models import QueueResult
+from shared.utils.manual_review_factory import (
+ get_manual_review_service,
+ has_manual_review_plugin,
+)
+
+from unstract.connectors.connectorkit import Connectorkit
+from unstract.connectors.exceptions import ConnectorError
+from unstract.core.data_models import ConnectionType as CoreConnectionType
+from unstract.core.data_models import FileHashData
+from unstract.filesystem import FileStorageType, FileSystem
+from unstract.sdk.constants import ToolExecKey
+from unstract.sdk.tool.mime_types import EXT_MIME_MAP
+from unstract.workflow_execution.constants import (
+ MetaDataKey,
+ ToolMetadataKey,
+ ToolOutputType,
+)
+from unstract.workflow_execution.execution_file_handler import (
+ ExecutionFileHandler,
+)
+
+from ..enums import DestinationConfigKey
+from ..infrastructure.logging import WorkerLogger
+from ..infrastructure.logging.helpers import log_file_error, log_file_info
+from ..utils.api_result_cache import get_api_cache_manager
+from .connectors.service import WorkerConnectorService
+
+if TYPE_CHECKING:
+ from ..api_client import InternalAPIClient
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+@dataclass
+class HandleOutputResult:
+ """Result of handle_output method."""
+
+ output: dict[str, Any] | str | None
+ metadata: dict[str, Any] | None
+ connection_type: str
+
+
+@dataclass
+class ExecutionContext:
+ """Execution context for destination processing."""
+
+ workflow_id: str
+ execution_id: str
+ organization_id: str
+ file_execution_id: str
+ api_client: Optional["InternalAPIClient"] = None
+ workflow_log: Any = None
+
+
+@dataclass
+class FileContext:
+ """File-specific context for processing."""
+
+ file_hash: FileHashData
+ file_name: str
+ input_file_path: str
+ workflow: dict[str, Any]
+ execution_error: str | None = None
+
+
+@dataclass
+class ProcessingResult:
+ """Result of destination processing."""
+
+ tool_execution_result: dict | str | None = None
+ metadata: dict[str, Any] | None = None
+ has_hitl: bool = False
+
+
+@dataclass
+class DestinationConfig:
+ """Worker-compatible DestinationConfig implementation."""
+
+ connection_type: str
+ source_connection_type: str
+ settings: dict[str, Any] = None
+ is_api: bool = False
+ use_file_history: bool = True
+ # New connector instance fields from backend API
+ connector_id: str | None = None
+ connector_settings: dict[str, Any] = None
+ connector_name: str | None = None
+ # Manual review / HITL support
+ hitl_queue_name: str | None = None
+ # Source connector configuration for reading files
+ source_connector_id: str | None = None
+ source_connector_settings: dict[str, Any] = None
+ file_execution_id: str | None = None
+
+ def __post_init__(self):
+ if self.settings is None:
+ self.settings = {}
+ if self.connector_settings is None:
+ self.connector_settings = {}
+ if self.source_connector_settings is None:
+ self.source_connector_settings = {}
+ # Determine if this is an API destination
+ if self.connection_type and "api" in self.connection_type.lower():
+ self.is_api = True
+
+ def get_core_connection_type(self) -> CoreConnectionType:
+ """Convert string connection_type to CoreConnectionType enum."""
+ try:
+ # Use the enum directly for consistent mapping
+ connection_type_upper = self.connection_type.upper()
+
+ # Try to get enum member by value
+ for connection_type_enum in CoreConnectionType:
+ if connection_type_enum.value == connection_type_upper:
+ return connection_type_enum
+
+ # Fallback: handle legacy/unknown types
+ logger.warning(
+ f"Unknown connection type '{self.connection_type}', defaulting to DATABASE"
+ )
+ return CoreConnectionType.DATABASE
+
+ except Exception as e:
+ logger.error(
+ f"Failed to convert connection type '{self.connection_type}' to enum: {e}"
+ )
+ return CoreConnectionType.DATABASE
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "DestinationConfig":
+ """Create DestinationConfig from dictionary data."""
+ connector_instance = data.get("connector_instance", {})
+ return cls(
+ connection_type=data.get("connection_type", ""),
+ source_connection_type=data.get("source_connection_type"),
+ settings=data.get("configuration", {}),
+ use_file_history=data.get("use_file_history", True),
+ connector_id=connector_instance.get("connector_id"),
+ connector_settings=connector_instance.get("connector_metadata", {}),
+ connector_name=connector_instance.get("connector_name"),
+ hitl_queue_name=data.get("hitl_queue_name"),
+ source_connector_id=data.get("source_connector_id"),
+ source_connector_settings=data.get("source_connector_settings", {}),
+ file_execution_id=data.get("file_execution_id"),
+ )
+
+
+class WorkerDestinationConnector:
+ """Worker-compatible destination connector following production patterns.
+
+ This class replicates the functionality of backend DestinationConnector
+ from workflow_manager/endpoint_v2/destination.py without Django dependencies.
+ """
+
+ # Use CoreConnectionType directly - no need for wrapper class
+
+ def __init__(self, config: DestinationConfig, workflow_log=None):
+ self.config = config
+ self.connection_type = config.connection_type
+ self.is_api = config.is_api
+ self.use_file_history = config.use_file_history
+ self.settings = config.settings
+ self.workflow_log = workflow_log
+
+ # Store destination connector instance details
+ self.connector_id = config.connector_id
+ self.connector_settings = config.connector_settings
+ self.connector_name = config.connector_name
+
+ # Store source connector instance details for file reading
+ self.source_connector_id = config.source_connector_id
+ self.source_connector_settings = config.source_connector_settings
+
+ # Manual review / HITL support
+ self.hitl_queue_name = config.hitl_queue_name
+
+ # Workflow and execution context (will be set when handling output)
+ self.organization_id = None
+ self.workflow_id = None
+ self.execution_id = None
+ self.file_execution_id = None
+
+ # Manual review service and API client (will be set when first needed)
+ self.manual_review_service = None
+ self._api_client = None
+
+ @classmethod
+ def from_config(cls, workflow_log, config: DestinationConfig):
+ """Create destination connector from config (matching Django backend interface)."""
+ return cls(config, workflow_log)
+
+ def _ensure_manual_review_service(
+ self, api_client: Optional["InternalAPIClient"] = None
+ ):
+ """Ensure manual review service is initialized (lazy loading)."""
+ if self.manual_review_service is None and api_client is not None:
+ self._api_client = api_client
+ self.manual_review_service = get_manual_review_service(
+ api_client, api_client.organization_id
+ )
+ return self.manual_review_service
+
+ def _get_destination_display_name(self) -> str:
+ """Get human-readable destination name for logging."""
+ if self.connection_type == CoreConnectionType.DATABASE.value:
+ # Try to get database type from settings
+ if self.connector_name:
+ return f"database ({self.connector_name})"
+ elif self.settings and "table" in self.settings:
+ return f"database table '{self.settings['table']}'"
+ return "database"
+ elif self.connection_type == CoreConnectionType.FILESYSTEM.value:
+ if self.connector_name:
+ return f"filesystem ({self.connector_name})"
+ return "filesystem destination"
+ elif self.connection_type == CoreConnectionType.API.value:
+ if self.connector_name:
+ return f"API ({self.connector_name})"
+ return "API endpoint"
+ elif self.connection_type == CoreConnectionType.MANUALREVIEW.value:
+ return "manual review queue"
+ else:
+ return f"{self.connection_type} destination"
+
+ def _setup_execution_context(
+ self,
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ file_execution_id: str,
+ api_client: Optional["InternalAPIClient"],
+ ) -> ExecutionContext:
+ """Setup and store execution context."""
+ # Store in instance for backward compatibility with other methods
+ self.workflow_id = workflow_id
+ self.execution_id = execution_id
+ self.organization_id = organization_id
+ self.file_execution_id = file_execution_id
+
+ return ExecutionContext(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=organization_id,
+ file_execution_id=file_execution_id,
+ api_client=api_client,
+ workflow_log=self.workflow_log,
+ )
+
+ def _setup_file_context(
+ self,
+ file_hash: FileHashData,
+ workflow: dict[str, Any],
+ execution_error: str | None,
+ ) -> FileContext:
+ """Setup file processing context."""
+ return FileContext(
+ file_hash=file_hash,
+ file_name=file_hash.file_name,
+ input_file_path=file_hash.file_path,
+ workflow=workflow,
+ execution_error=execution_error,
+ )
+
+ def _extract_processing_data(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext
+ ) -> ProcessingResult:
+ """Extract tool results and metadata for processing."""
+ tool_result = None
+ if not file_ctx.execution_error:
+ tool_result = self.get_tool_execution_result_from_execution_context(
+ workflow_id=exec_ctx.workflow_id,
+ execution_id=exec_ctx.execution_id,
+ file_execution_id=exec_ctx.file_execution_id,
+ organization_id=exec_ctx.organization_id,
+ )
+
+ metadata = self.get_metadata()
+
+ return ProcessingResult(tool_execution_result=tool_result, metadata=metadata)
+
+ def _check_and_handle_hitl(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, result: ProcessingResult
+ ) -> bool:
+ """Check HITL requirements and push to queue if needed."""
+ has_hitl = self._should_handle_hitl(
+ file_name=file_ctx.file_name,
+ file_hash=file_ctx.file_hash,
+ workflow=file_ctx.workflow,
+ api_client=exec_ctx.api_client,
+ error=file_ctx.execution_error,
+ )
+
+ if has_hitl:
+ self._push_data_to_queue(
+ file_name=file_ctx.file_name,
+ workflow=file_ctx.workflow,
+ input_file_path=file_ctx.input_file_path,
+ file_execution_id=exec_ctx.file_execution_id,
+ tool_execution_result=result.tool_execution_result,
+ api_client=exec_ctx.api_client,
+ )
+
+ return has_hitl
+
+ def _process_destination(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, result: ProcessingResult
+ ):
+ """Route to appropriate destination handler."""
+ handlers = {
+ CoreConnectionType.API.value: self._handle_api_destination,
+ CoreConnectionType.FILESYSTEM.value: self._handle_filesystem_destination,
+ CoreConnectionType.DATABASE.value: self._handle_database_destination,
+ CoreConnectionType.MANUALREVIEW.value: self._handle_manual_review_destination,
+ }
+
+ handler = handlers.get(self.connection_type)
+ if handler:
+ handler(exec_ctx, file_ctx, result)
+ else:
+ logger.warning(f"Unknown destination connection type: {self.connection_type}")
+
+ def _handle_api_destination(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, result: ProcessingResult
+ ):
+ """Handle API destination processing."""
+ log_file_info(
+ exec_ctx.workflow_log,
+ exec_ctx.file_execution_id,
+ f"🔌 File '{file_ctx.file_name}' marked for API processing - preparing response",
+ )
+
+ self.cache_api_result(
+ api_client=exec_ctx.api_client,
+ file_hash=file_ctx.file_hash,
+ workflow_id=exec_ctx.workflow_id,
+ execution_id=exec_ctx.execution_id,
+ result=result.tool_execution_result if not result.has_hitl else None,
+ file_execution_id=exec_ctx.file_execution_id,
+ organization_id=exec_ctx.organization_id,
+ error=file_ctx.execution_error,
+ metadata=result.metadata,
+ )
+
+ def _handle_filesystem_destination(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, result: ProcessingResult
+ ):
+ """Handle filesystem destination processing."""
+ if not result.has_hitl:
+ log_file_info(
+ exec_ctx.workflow_log,
+ exec_ctx.file_execution_id,
+ f"📤 File '{file_ctx.file_name}' marked for FILESYSTEM processing - copying to destination",
+ )
+ self.copy_output_to_output_directory(
+ file_ctx.input_file_path, exec_ctx.file_execution_id, exec_ctx.api_client
+ )
+ else:
+ logger.info(
+ f"File '{file_ctx.file_name}' sent to HITL queue - FILESYSTEM processing will be handled after review"
+ )
+
+ def _handle_database_destination(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, result: ProcessingResult
+ ):
+ """Handle database destination processing."""
+ if not result.has_hitl:
+ log_file_info(
+ exec_ctx.workflow_log,
+ exec_ctx.file_execution_id,
+ f"📤 File '{file_ctx.file_name}' marked for DATABASE processing - preparing to insert data",
+ )
+ if result.tool_execution_result or file_ctx.execution_error:
+ self.insert_into_db(
+ file_ctx.input_file_path,
+ result.tool_execution_result,
+ result.metadata,
+ exec_ctx.file_execution_id,
+ error_message=file_ctx.execution_error,
+ api_client=exec_ctx.api_client,
+ )
+ else:
+ logger.warning(
+ f"No tool execution result or execution error found for file {file_ctx.file_name}, skipping database insertion"
+ )
+ else:
+ logger.info(
+ f"File '{file_ctx.file_name}' sent to HITL queue - DATABASE processing will be handled after review"
+ )
+
+ def _handle_manual_review_destination(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, result: ProcessingResult
+ ):
+ """Handle manual review destination processing."""
+ log_file_info(
+ exec_ctx.workflow_log,
+ exec_ctx.file_execution_id,
+ f"🔄 File '{file_ctx.file_name}' explicitly configured for MANUAL REVIEW - sending to queue",
+ )
+
+ if not result.has_hitl:
+ self._push_data_to_queue(
+ file_name=file_ctx.file_name,
+ workflow=file_ctx.workflow,
+ input_file_path=file_ctx.input_file_path,
+ file_execution_id=exec_ctx.file_execution_id,
+ tool_execution_result=result.tool_execution_result,
+ api_client=exec_ctx.api_client,
+ )
+
+ def _handle_destination_error(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, error: Exception
+ ):
+ """Handle destination processing errors."""
+ logger.error(f"Destination handle_output failed: {str(error)}")
+ log_file_error(
+ exec_ctx.workflow_log,
+ exec_ctx.file_execution_id,
+ f"❌ File '{file_ctx.file_name}' failed to send to destination: {str(error)}",
+ )
+
+ def _log_processing_success(
+ self, exec_ctx: ExecutionContext, file_ctx: FileContext, has_hitl: bool
+ ):
+ """Log successful processing."""
+ if has_hitl:
+ destination_name = "HITL/MANUAL REVIEW"
+ else:
+ destination_name = self._get_destination_display_name()
+ log_file_info(
+ exec_ctx.workflow_log,
+ exec_ctx.file_execution_id,
+ f"✅ File '{file_ctx.file_name}' successfully sent to {destination_name}",
+ )
+
+ def cache_api_result(
+ self,
+ file_hash: FileHashData,
+ workflow_id: str,
+ execution_id: str,
+ file_execution_id: str,
+ organization_id: str,
+ api_client: Any | None,
+ # file_history: dict[str, Any] | None,
+ result: dict[str, Any] | None,
+ error: str | None = None,
+ metadata: dict[str, Any] | None = None,
+ ) -> bool:
+ """Cache API result using APIResultCacheManager."""
+ try:
+ # Calculate accurate elapsed time from workflow start time
+ if metadata and MetaDataKey.WORKFLOW_START_TIME in metadata:
+ workflow_start_time = metadata[MetaDataKey.WORKFLOW_START_TIME]
+ current_time = time.time()
+ actual_elapsed_time = current_time - workflow_start_time
+
+ # Update total_elapsed_time with accurate measurement
+ metadata[MetaDataKey.TOTAL_ELAPSED_TIME] = actual_elapsed_time
+
+ logger.info(
+ f"TIMING: Calculated accurate elapsed time for API caching: {actual_elapsed_time:.3f}s "
+ f"(from workflow start: {workflow_start_time:.6f} to now: {current_time:.6f})"
+ )
+
+ # Use APIResultCacheManager for consistent caching behavior
+ api_cache_manager = get_api_cache_manager()
+ success = api_cache_manager.cache_api_result_direct(
+ file_name=file_hash.file_name,
+ file_execution_id=file_execution_id,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ result=result,
+ error=error,
+ organization_id=organization_id,
+ metadata=metadata,
+ )
+
+ if success:
+ logger.info(
+ f"Successfully cached API result for execution {execution_id}"
+ )
+ else:
+ logger.warning(f"Failed to cache API result for execution {execution_id}")
+
+ return success
+
+ except Exception as e:
+ logger.error(
+ f"Failed to cache API result for execution {execution_id}: {str(e)}"
+ )
+ # Return False but don't re-raise - caching failures shouldn't stop execution
+ raise
+
+ def handle_output(
+ self,
+ is_success: bool,
+ file_hash: FileHashData,
+ # file_history: dict[str, Any] | None,
+ workflow: dict[str, Any],
+ file_execution_id: str = None,
+ api_client: Optional["InternalAPIClient"] = None,
+ workflow_id: str = None,
+ execution_id: str = None,
+ organization_id: str = None,
+ execution_error: str = None,
+ ) -> HandleOutputResult:
+ """Handle the output based on the connection type.
+
+ This refactored version uses clean architecture with context objects
+ and single-responsibility methods for better maintainability.
+ """
+ # Setup contexts
+ exec_ctx = self._setup_execution_context(
+ workflow_id, execution_id, organization_id, file_execution_id, api_client
+ )
+ file_ctx = self._setup_file_context(file_hash, workflow, execution_error)
+
+ # Log if HITL queue is configured (reduced debug logging)
+ if self.hitl_queue_name:
+ logger.debug(f"HITL queue configured: {self.hitl_queue_name}")
+
+ # Extract processing data
+ result = self._extract_processing_data(exec_ctx, file_ctx)
+
+ # Check and handle HITL if needed
+ result.has_hitl = self._check_and_handle_hitl(exec_ctx, file_ctx, result)
+
+ # Process through appropriate destination
+ try:
+ self._process_destination(exec_ctx, file_ctx, result)
+ except Exception as e:
+ self._handle_destination_error(exec_ctx, file_ctx, e)
+ raise
+
+ # Log success
+ self._log_processing_success(exec_ctx, file_ctx, result.has_hitl)
+
+ return HandleOutputResult(
+ output=result.tool_execution_result,
+ metadata=result.metadata,
+ connection_type=self.connection_type,
+ )
+
+ def get_combined_metadata(
+ self, api_client: "InternalAPIClient", metadata: dict[str, Any] = None
+ ) -> dict[str, Any]:
+ """Get combined workflow and usage metadata.
+
+ Returns:
+ dict[str, Any]: Combined metadata including workflow and usage data.
+ """
+ file_execution_id = self.file_execution_id
+ usage_metadata = api_client.get_aggregated_token_count(file_execution_id)
+
+ if metadata and usage_metadata:
+ metadata["usage"] = usage_metadata.to_dict()
+ return metadata
+
+ def insert_into_db(
+ self,
+ input_file_path: str,
+ tool_execution_result: str = None,
+ metadata: dict[str, Any] = None,
+ file_execution_id: str = None,
+ error_message: str = None,
+ api_client: "InternalAPIClient" = None,
+ ) -> None:
+ """Insert data into the database (following production pattern)."""
+ # If no data and no error, don't execute CREATE or INSERT query
+ if not (tool_execution_result or error_message):
+ raise ValueError("No tool_execution_result or error_message provided")
+
+ if error_message:
+ logger.info(
+ f"Proceeding with error record insertion for {input_file_path}: {error_message}"
+ )
+
+ # Store file_execution_id for logging
+ if file_execution_id:
+ self.current_file_execution_id = file_execution_id
+
+ # Extract connector instance details from instance variables (now properly set)
+ connector_id = self.connector_id
+ connector_settings = self.connector_settings
+
+ logger.info(f"Database destination - Connector ID: {connector_id}")
+ logger.info(
+ f"Database destination - Connector settings available: {bool(connector_settings)}"
+ )
+ logger.info(
+ f"Database destination - Settings keys: {list(self.settings.keys()) if self.settings else 'None'}"
+ )
+
+ if not connector_id:
+ raise ValueError("No connector_id provided in destination configuration")
+
+ if not connector_settings:
+ raise ValueError(
+ "No connector_settings provided in destination configuration"
+ )
+
+ db_class = WorkerDatabaseUtils.get_db_class(
+ connector_id=connector_id,
+ connector_settings=connector_settings,
+ )
+
+ # Get combined metadata including usage data
+ metadata = self.get_combined_metadata(api_client, metadata)
+ logger.info(f"Database destination - Metadata: {metadata}")
+
+ # Get table configuration from destination settings (table-specific config)
+ table_name = str(self.settings.get("table", "unstract_results"))
+ include_agent = bool(self.settings.get("includeAgent", False))
+ include_timestamp = bool(self.settings.get("includeTimestamp", False))
+ agent_name = str(self.settings.get("agentName", "UNSTRACT_DBWRITER"))
+ column_mode = str(
+ self.settings.get("columnMode", "WRITE_JSON_TO_A_SINGLE_COLUMN")
+ )
+ single_column_name = str(self.settings.get("singleColumnName", "data"))
+ file_path_name = str(self.settings.get("filePath", "file_path"))
+ execution_id_name = str(self.settings.get("executionId", "execution_id"))
+
+ # Get tool execution result (use provided result only)
+ data = tool_execution_result
+
+ # Remove metadata from result
+ # Tool text-extractor returns data in the form of string.
+ # Don't pop out metadata in this case.
+ if isinstance(data, dict):
+ data.pop("metadata", None)
+
+ # Use the workflow execution ID - warn if not available
+ if not self.execution_id:
+ logger.warning("Workflow execution_id not provided, using NULL in database")
+ execution_id = None
+ else:
+ execution_id = self.execution_id
+
+ engine = None
+ try:
+ logger.info(f"Creating database connection with connector ID: {connector_id}")
+ db_class = WorkerDatabaseUtils.get_db_class(
+ connector_id=connector_id,
+ connector_settings=connector_settings,
+ )
+ table_info = db_class.get_information_schema(table_name=table_name)
+
+ logger.info(
+ f"destination connector table_name: {table_name} with table_info: {table_info}"
+ )
+ engine = db_class.get_engine()
+
+ if table_info:
+ if db_class.has_no_metadata(table_info=table_info):
+ table_info = WorkerDatabaseUtils.migrate_table_to_v2(
+ db_class=db_class,
+ engine=engine,
+ table_name=table_name,
+ column_name=single_column_name,
+ )
+
+ logger.info(f"Creating table {table_name} if not exists")
+
+ values = WorkerDatabaseUtils.get_columns_and_values(
+ column_mode_str=column_mode,
+ data=data,
+ include_timestamp=include_timestamp,
+ include_agent=include_agent,
+ agent_name=agent_name,
+ single_column_name=single_column_name,
+ file_path_name=file_path_name,
+ execution_id_name=execution_id_name,
+ file_path=input_file_path,
+ execution_id=execution_id,
+ metadata=metadata,
+ error=error_message,
+ )
+
+ WorkerDatabaseUtils.create_table_if_not_exists(
+ db_class=db_class,
+ engine=engine,
+ table_name=table_name,
+ database_entry=values,
+ )
+
+ logger.info(f"Preparing SQL query data for table {table_name}")
+ sql_columns_and_values = WorkerDatabaseUtils.get_sql_query_data(
+ conn_cls=db_class,
+ table_name=table_name,
+ values=values,
+ )
+ logger.info(
+ f"sql_columns_and_values for table_name: {table_name} are: {sql_columns_and_values}"
+ )
+ logger.info(
+ f"Executing insert query for {len(sql_columns_and_values)} columns"
+ )
+ WorkerDatabaseUtils.execute_write_query(
+ db_class=db_class,
+ engine=engine,
+ table_name=table_name,
+ sql_keys=list(sql_columns_and_values.keys()),
+ sql_values=list(sql_columns_and_values.values()),
+ )
+
+ logger.info(f"Successfully inserted data into database table {table_name}")
+
+ # Log to UI with file_execution_id for better correlation
+ if self.workflow_log and hasattr(self, "current_file_execution_id"):
+ log_file_info(
+ self.workflow_log,
+ self.current_file_execution_id,
+ f"📥 Data successfully inserted into database table '{table_name}'",
+ )
+ except ConnectorError as e:
+ error_msg = f"Database connection failed for {input_file_path}: {str(e)}"
+ logger.error(error_msg)
+ raise
+ except Exception as e:
+ error_msg = (
+ f"Failed to insert data into database for {input_file_path}: {str(e)}"
+ )
+ logger.error(error_msg)
+ raise
+ finally:
+ self._close_engine(engine, input_file_path)
+
+ def _close_engine(self, engine: Any, input_file_path: str) -> None:
+ """Safely close database engine."""
+ if engine:
+ try:
+ engine.close()
+ except Exception as e:
+ logger.error(
+ f"Failed to close database engine for {input_file_path}: {str(e)}"
+ )
+
+ def copy_output_to_output_directory(
+ self,
+ input_file_path: str,
+ file_execution_id: str = None,
+ api_client: Optional["InternalAPIClient"] = None,
+ ) -> None:
+ """Copy output to the destination directory (following backend production pattern).
+
+ This method should ONLY be called for TASK workflows where destination is FILESYSTEM.
+ ETL workflows (destination=DATABASE) use insert_into_db() instead.
+ API workflows don't use this destination copying logic.
+ """
+ # Store file_execution_id for logging
+ if file_execution_id:
+ self.current_file_execution_id = file_execution_id
+
+ # ARCHITECTURE VALIDATION: Ensure this is only called for TASK workflows
+ if api_client and self.workflow_id:
+ if self.connection_type != CoreConnectionType.FILESYSTEM.value:
+ logger.warning(
+ f"copy_output_to_output_directory called for destination connection_type {self.connection_type} with workflow {self.workflow_id} - this should only be used for {CoreConnectionType.FILESYSTEM.value} workflows"
+ )
+ return
+
+ # Copy output to filesystem destination
+
+ try:
+ # Get destination connector settings - exactly like backend
+ if not self.connector_id or not self.connector_settings:
+ raise ValueError(
+ f"Missing destination connector configuration: connector_id={self.connector_id}, "
+ f"settings={bool(self.connector_settings)}"
+ )
+
+ # Import necessary modules for file operations
+
+ # Get connector settings and configuration like backend (lines 262-265)
+ connector_settings = self.connector_settings
+ destination_configurations = self.settings or {}
+
+ # Extract destination path configuration using enums to prevent camelCase/snake_case issues
+ root_path = str(connector_settings.get(DestinationConfigKey.PATH, ""))
+ output_directory = str(
+ destination_configurations.get(DestinationConfigKey.OUTPUT_FOLDER, "/")
+ )
+
+ # Get the destination connector instance (lines 270-272)
+ logger.debug(f"Initializing destination connector: {self.connector_id}")
+ connector_service = WorkerConnectorService(api_client)
+ destination_fs = connector_service._get_destination_connector(
+ connector_id=self.connector_id, connector_settings=connector_settings
+ )
+
+ # Get connector root directory like backend (lines 273-275)
+ output_directory = destination_fs.get_connector_root_dir(
+ input_dir=output_directory, root_path=root_path
+ )
+
+ # Build destination volume path like backend (lines 277-279)
+ # Backend uses self.file_execution_dir which maps to our execution path
+ execution_dir_path = f"unstract/execution/{self.organization_id}/{self.workflow_id}/{self.execution_id}/{file_execution_id}"
+ destination_volume_path = os.path.join(
+ execution_dir_path, ToolExecKey.OUTPUT_DIR
+ )
+
+ # Get workflow execution file system for reading (like backend lines 285-286)
+ file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ fs = file_system.get_file_storage()
+
+ # Backend logic: Create destination directory if needed (line 282)
+ try:
+ # CONNECTOR COMPATIBILITY: Skip root directory creation for certain paths
+ normalized_output_dir = output_directory.strip("/")
+ if normalized_output_dir and normalized_output_dir != ".":
+ destination_fs.create_dir_if_not_exists(
+ input_dir=normalized_output_dir
+ )
+ else:
+ logger.debug(
+ f"Skipping root directory creation for path: '{output_directory}'"
+ )
+ except Exception as e:
+ logger.warning(
+ f"Could not create destination directory {output_directory}: {e}"
+ )
+
+ # Backend logic: Walk the OUTPUT_DIR and copy everything (lines 287-307)
+ copied_files = []
+ failed_files = []
+ total_copied = 0
+
+ # Check if OUTPUT_DIR exists before walking
+ if not fs.exists(destination_volume_path):
+ logger.warning(
+ f"Output directory does not exist: {destination_volume_path}"
+ )
+ logger.info(
+ "No output files to copy - workflow may not have produced output"
+ )
+ else:
+ # Walk directory structure like backend (lines 289-307)
+ try:
+ dir_path = fs.walk(str(destination_volume_path))
+
+ for root, dirs, files in dir_path:
+ # Create directories in destination (lines 290-296)
+ for dir_name in dirs:
+ current_dir = os.path.join(
+ output_directory,
+ os.path.relpath(root, destination_volume_path),
+ dir_name,
+ )
+ try:
+ # CONNECTOR COMPATIBILITY: Skip root directory creation for certain paths
+ normalized_current_dir = current_dir.strip("/")
+ if (
+ normalized_current_dir
+ and normalized_current_dir != "."
+ ):
+ destination_fs.create_dir_if_not_exists(
+ input_dir=normalized_current_dir
+ )
+ logger.debug(
+ f"Created directory: {normalized_current_dir}"
+ )
+ else:
+ logger.debug(
+ f"Skipping root directory creation for path: '{current_dir}'"
+ )
+ except Exception as e:
+ logger.warning(
+ f"Could not create directory {current_dir}: {e}"
+ )
+
+ # Copy files (lines 298-307)
+ for file_name in files:
+ source_path = os.path.join(root, file_name)
+
+ # Calculate relative path and handle path construction properly
+ relative_path = os.path.relpath(root, destination_volume_path)
+
+ if relative_path == "." or not relative_path:
+ # When root == destination_volume_path, use output_directory directly
+ destination_path = os.path.join(
+ output_directory, file_name
+ )
+ else:
+ destination_path = os.path.join(
+ output_directory,
+ relative_path,
+ file_name,
+ )
+
+ # Normalize path and validate
+ destination_path = os.path.normpath(destination_path)
+
+ # ARCHITECTURE FIX: Proper error handling instead of inconsistent fallbacks
+ if not destination_path or destination_path in [".", "/"]:
+ error_msg = f"Invalid destination path '{destination_path}' constructed for file {file_name}"
+ logger.error(f"ERROR: {error_msg}")
+ logger.error(
+ f"ERROR: Debug info - output_directory='{output_directory}', relative_path='{relative_path}', root='{root}', destination_volume_path='{destination_volume_path}'"
+ )
+ raise ValueError(error_msg)
+
+ try:
+ # CONNECTOR COMPATIBILITY: Handle path normalization for worker context
+ # Remove leading slash that can cause issues with various connectors
+ final_destination_path = (
+ destination_path.lstrip("/")
+ if destination_path.startswith("/")
+ else destination_path
+ )
+
+ # Validate the final path is not empty after normalization
+ if (
+ not final_destination_path
+ or final_destination_path in [".", ""]
+ ):
+ raise ValueError(
+ f"Invalid destination path after normalization: '{final_destination_path}' (original: '{destination_path}')"
+ )
+
+ destination_fs.upload_file_to_storage(
+ source_path=source_path,
+ destination_path=final_destination_path,
+ )
+ copied_files.append(file_name)
+ total_copied += 1
+ logger.debug(f"✅ Successfully copied: {file_name}")
+
+ except Exception as copy_error:
+ logger.error(
+ f"Failed to copy {file_name}: {copy_error}",
+ exc_info=True,
+ )
+ failed_files.append(file_name)
+ # Continue with other files even if one fails
+
+ except Exception as walk_error:
+ logger.error(
+ f"Failed to walk output directory {destination_volume_path}: {walk_error}"
+ )
+
+ # Report results - handle both successes and failures
+ if failed_files:
+ # If any files failed, this should be treated as an error
+ failed_count = len(failed_files)
+ if failed_count == 1:
+ error_message = (
+ f"❌ Failed to copy file to destination: {failed_files[0]}"
+ )
+ else:
+ error_message = (
+ f"❌ Failed to copy {failed_count} files to destination"
+ )
+ logger.error(error_message)
+
+ # Log to UI with file_execution_id
+ if self.workflow_log and hasattr(self, "current_file_execution_id"):
+ log_file_info(
+ self.workflow_log,
+ self.current_file_execution_id,
+ error_message,
+ )
+
+ # Raise exception to trigger proper error handling
+ raise Exception(f"Destination copy failed: {error_message}")
+ elif total_copied > 0:
+ success_message = f"💾 Successfully copied {total_copied} files to filesystem destination"
+ logger.info(success_message)
+
+ # Log to UI
+ if self.workflow_log and hasattr(self, "current_file_execution_id"):
+ log_file_info(
+ self.workflow_log,
+ self.current_file_execution_id,
+ success_message,
+ )
+ else:
+ success_message = (
+ "💾 No output files found to copy to filesystem destination"
+ )
+ logger.info(success_message)
+
+ # Log to UI
+ if self.workflow_log and hasattr(self, "current_file_execution_id"):
+ log_file_info(
+ self.workflow_log,
+ self.current_file_execution_id,
+ success_message,
+ )
+
+ except Exception as e:
+ error_msg = f"Failed to copy files to filesystem destination: {str(e)}"
+ logger.error(error_msg, exc_info=True)
+
+ # Log error to UI
+ if self.workflow_log and hasattr(self, "current_file_execution_id"):
+ log_file_info(
+ self.workflow_log,
+ self.current_file_execution_id,
+ f"❌ {error_msg}",
+ )
+
+ # Re-raise the exception so that destination processing can fail properly
+ raise Exception(f"Destination filesystem copy failed: {str(e)}") from e
+
+ def get_tool_execution_result(
+ self, file_history=None, tool_execution_result: str = None
+ ) -> Any:
+ """Get result data from the output file (following production pattern)."""
+ if tool_execution_result:
+ return tool_execution_result
+
+ if file_history and hasattr(file_history, "result") and file_history.result:
+ return self.parse_string(file_history.result)
+
+ # Default fallback - could be enhanced to read from actual execution files
+ return None
+
+ def get_tool_execution_result_from_execution_context(
+ self,
+ workflow_id: str,
+ execution_id: str,
+ file_execution_id: str,
+ organization_id: str,
+ ) -> dict | str:
+ """Get tool execution result using proper execution context (preferred method)."""
+ try:
+ # Use ExecutionFileHandler to get proper paths (matching backend)
+ file_handler = ExecutionFileHandler(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=organization_id,
+ file_execution_id=file_execution_id,
+ )
+ metadata_file_path = file_handler.metadata_file
+ # Get workflow metadata (following backend pattern)
+ file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ file_storage = file_system.get_file_storage()
+
+ if not metadata_file_path:
+ return None
+
+ if not file_storage.exists(metadata_file_path):
+ return None
+
+ metadata_content = file_storage.read(path=metadata_file_path, mode="r")
+ metadata = json.loads(metadata_content)
+
+ # Get output type from metadata (following backend pattern)
+ output_type = self._get_output_type_from_metadata(metadata)
+
+ # Get the output file path using the file handler (matching backend pattern)
+ output_file_path = file_handler.infile
+
+ if not output_file_path:
+ return None
+
+ if not file_storage.exists(output_file_path):
+ return None
+
+ file_type = file_storage.mime_type(path=output_file_path)
+ if output_type == ToolOutputType.JSON:
+ if file_type != EXT_MIME_MAP[ToolOutputType.JSON.lower()]:
+ msg = f"Expected tool output type: JSON, got: '{file_type}'"
+ logger.error(msg)
+ raise Exception(msg)
+ file_content = file_storage.read(output_file_path, mode="r")
+ result = json.loads(file_content)
+ return result
+ elif output_type == ToolOutputType.TXT:
+ if file_type != EXT_MIME_MAP[ToolOutputType.TXT.lower()]:
+ msg = f"Expected tool output type: TXT, got: '{file_type}'"
+ logger.error(msg)
+ raise Exception(msg)
+ file_content = file_storage.read(output_file_path, mode="r")
+ result = file_content.encode("utf-8").decode("unicode-escape")
+ return result
+ else:
+ raise Exception(f"Unsupported output type: {output_type}")
+
+ except Exception as e:
+ logger.error(
+ f"Exception while getting tool execution result from execution context: {str(e)}",
+ exc_info=True,
+ )
+ raise
+
+ def _get_output_type_from_metadata(self, metadata: dict[str, Any]) -> str:
+ """Get output type from metadata (following backend pattern)."""
+ try:
+ # Get tool metadata list
+ tool_metadata = metadata.get(MetaDataKey.TOOL_METADATA, [])
+ if not tool_metadata:
+ logger.warning("No tool metadata found, defaulting to TXT output")
+ return ToolOutputType.TXT
+
+ # Get last tool metadata (like backend)
+ last_tool_metadata = tool_metadata[-1]
+ output_type = last_tool_metadata.get(
+ ToolMetadataKey.OUTPUT_TYPE, ToolOutputType.TXT
+ )
+
+ logger.debug(f"Detected output type: {output_type}")
+ return output_type
+
+ except Exception as e:
+ logger.error(f"Failed to get output type from metadata: {str(e)}")
+ return ToolOutputType.TXT
+
+ def parse_string(self, original_string: str) -> Any:
+ """Parse the given string, attempting to evaluate it as a Python literal."""
+ try:
+ # Try to evaluate as a Python literal
+ python_literal = ast.literal_eval(original_string)
+ return python_literal
+ except (SyntaxError, ValueError):
+ # If evaluating as a Python literal fails,
+ # assume it's a plain string
+ return original_string
+
+ def get_metadata(self, file_history=None) -> dict[str, Any] | None:
+ """Get metadata from the output file (matching backend pattern).
+
+ This matches backend DestinationConnector.get_metadata.
+ """
+ if file_history:
+ if self.has_valid_metadata(getattr(file_history, "metadata", None)):
+ return self.parse_string(file_history.metadata)
+ else:
+ return None
+ metadata: dict[str, Any] = self._get_workflow_metadata()
+ return metadata
+
+ def _get_workflow_metadata(self) -> dict[str, Any]:
+ """Get metadata from the workflow (matching backend pattern)."""
+ file_handler = ExecutionFileHandler(
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ organization_id=self.organization_id,
+ file_execution_id=self.file_execution_id,
+ )
+ metadata: dict[str, Any] = file_handler.get_workflow_metadata()
+ return metadata
+
+ def has_valid_metadata(self, metadata: Any) -> bool:
+ """Check if metadata is valid (matching backend pattern)."""
+ # Check if metadata is not None and metadata is a non-empty string
+ if not metadata:
+ return False
+ if not isinstance(metadata, str):
+ return False
+ if metadata.strip().lower() == "none":
+ return False
+ return True
+
+ def _should_handle_hitl(
+ self,
+ file_name: str,
+ file_hash: FileHashData,
+ workflow: dict[str, Any],
+ api_client: Optional["InternalAPIClient"] = None,
+ tool_execution_result: dict | str | None = None,
+ error: str | None = None,
+ ) -> bool:
+ """Determines if HITL processing should be performed, returning True if data was pushed to the queue.
+
+ This method replicates the backend DestinationConnector._should_handle_hitl logic.
+ """
+ logger.info(f"{file_name}: checking if file is eligible for HITL")
+ if error:
+ logger.error(
+ f"{file_name}: file is not eligible for HITL due to error: {error}"
+ )
+ return False
+
+ # Check if API deployment requested HITL override
+ if self.hitl_queue_name:
+ logger.info(f"{file_name}: Pushing to HITL queue")
+ return True
+
+ # Skip HITL validation if we're using file_history and no execution result is available
+ if self.is_api:
+ logger.info(
+ f"{file_name}: Skipping HITL validation as it's an API deployment"
+ )
+ return False
+ if not self.use_file_history:
+ logger.info(
+ f"{file_name}: Skipping HITL validation as we're not using file_history"
+ )
+ return False
+ if not file_hash.is_manualreview_required:
+ logger.info(f"{file_name}: File is not marked for manual review")
+ return False
+
+ # Use class-level manual review service
+ manual_review_service = self._ensure_manual_review_service(api_client)
+ if not manual_review_service:
+ logger.info(f"No manual review service available for {file_name}")
+ return False
+
+ workflow_util = manual_review_service.get_workflow_util()
+ is_to_hitl = workflow_util.validate_db_rule(
+ tool_execution_result,
+ workflow,
+ file_hash.file_destination,
+ file_hash.is_manualreview_required,
+ )
+ logger.info(f"File {file_name} checked for manual review: {is_to_hitl}")
+ if is_to_hitl:
+ return True
+ return False
+
+ def _push_data_to_queue(
+ self,
+ file_name: str,
+ workflow: dict[str, Any],
+ input_file_path: str,
+ file_execution_id: str,
+ tool_execution_result: str = None,
+ api_client: Optional["InternalAPIClient"] = None,
+ ) -> None:
+ """Handle manual review queue processing (following production pattern).
+
+ This method replicates the backend DestinationConnector._push_to_queue logic.
+ """
+ if not has_manual_review_plugin():
+ logger.warning(f"No manual review service available to enqueue {file_name}")
+ return
+ logger.info(f"Pushing {file_name} to manual review queue")
+ log_file_info(
+ self.workflow_log,
+ file_execution_id,
+ f"🔄 File '{file_name}' sending to manual review queue",
+ )
+
+ try:
+ # Ensure manual review service is available and use it
+ manual_review_service = self._ensure_manual_review_service(api_client)
+
+ # Get tool execution result if not provided
+ if not tool_execution_result:
+ tool_execution_result = (
+ self.get_tool_execution_result_from_execution_context(
+ workflow_id=self.workflow_id,
+ execution_id=self.execution_id,
+ file_execution_id=file_execution_id,
+ organization_id=self.organization_id,
+ )
+ )
+
+ if not tool_execution_result:
+ logger.warning(
+ f"No tool execution result available for {file_name}, skipping queue"
+ )
+ return
+
+ # Get queue name using backend pattern
+ queue_name = self._get_review_queue_name()
+ # Use workflow util via plugin architecture (handles OSS/Enterprise automatically)
+ workflow_util = manual_review_service.get_workflow_util()
+
+ # Read file content based on deployment type (matching backend logic)
+ if self.is_api:
+ # For API deployments, read from workflow execution storage (no fallback in backend)
+ file_content_base64 = self._read_file_content_for_queue(
+ input_file_path, file_name
+ )
+ ttl_seconds = None
+ else:
+ # For ETL/TASK workflows, read from source connector (like backend)
+ file_content_base64 = self._read_file_from_source_connector(
+ input_file_path, file_name, workflow
+ )
+ ttl_seconds = workflow_util.get_hitl_ttl_seconds(str(self.workflow_id))
+
+ # Get metadata (whisper-hash, etc.)
+ metadata = self.get_metadata()
+ whisper_hash = metadata.get("whisper-hash") if metadata else None
+ extracted_text = metadata.get("extracted_text") if metadata else None
+
+ # Create queue result matching backend QueueResult structure
+ queue_result = QueueResult(
+ file=file_name,
+ status=QueueResultStatus.SUCCESS,
+ result=tool_execution_result,
+ workflow_id=str(self.workflow_id),
+ whisper_hash=whisper_hash,
+ file_execution_id=file_execution_id,
+ extracted_text=extracted_text,
+ ttl_seconds=ttl_seconds,
+ )
+
+ # Only include file_content if provided (backend API will handle it)
+ if file_content_base64 is not None:
+ queue_result.file_content = file_content_base64
+
+ workflow_util.enqueue_manual_review(
+ queue_name=queue_name,
+ message=queue_result.to_dict(),
+ organization_id=self.organization_id,
+ )
+
+ # Log successful enqueue (common for both paths)
+ log_file_info(
+ self.workflow_log,
+ file_execution_id,
+ f"✅ File '{file_name}' sent to manual review queue '{queue_name}'",
+ )
+
+ logger.info(
+ f"✅ MANUAL REVIEW: File '{file_name}' sent to manual review queue '{queue_name}' successfully"
+ )
+
+ except Exception as e:
+ logger.error(f"Failed to push {file_name} to manual review queue: {e}")
+ raise
+
+ def _get_review_queue_name(self) -> str:
+ """Generate review queue name with optional HITL override for manual review processing.
+
+ This method replicates the backend DestinationConnector._get_review_queue_name logic.
+ """
+ logger.debug(f"Queue naming - hitl_queue_name={self.hitl_queue_name}")
+
+ # Base queue format: review_queue_{org}_{workflow_id}
+ base_queue_name = f"review_queue_{self.organization_id}_{str(self.workflow_id)}"
+
+ if self.hitl_queue_name:
+ # Custom HITL queue with user-specified name
+ q_name = f"{base_queue_name}:{self.hitl_queue_name}"
+ logger.debug(f"Using custom HITL queue: {q_name}")
+ else:
+ # Standard queue format for workflow-based processing
+ q_name = base_queue_name
+ logger.debug(f"Using standard queue name: {q_name}")
+
+ return q_name
+
+ def _read_file_content_for_queue(self, input_file_path: str, file_name: str) -> str:
+ """Read and encode file content for queue message from execution storage.
+
+ This method replicates the backend DestinationConnector._read_file_content_for_queue logic.
+ """
+ try:
+ file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ file_storage = file_system.get_file_storage()
+
+ if not file_storage.exists(input_file_path):
+ raise FileNotFoundError(f"File not found: {input_file_path}")
+
+ file_bytes = file_storage.read(input_file_path, mode="rb")
+ if isinstance(file_bytes, str):
+ file_bytes = file_bytes.encode("utf-8")
+ return base64.b64encode(file_bytes).decode("utf-8")
+ except Exception as e:
+ logger.error(f"Failed to read file content for {file_name}: {e}")
+ raise OSError(f"Failed to read file content for queue: {e}")
+
+ def _read_file_from_source_connector(
+ self, input_file_path: str, file_name: str, workflow: dict[str, Any]
+ ) -> str:
+ """Read and encode file content from source connector for ETL/TASK workflows.
+
+ This method replicates the backend logic: source_fs.open(input_file_path, "rb")
+ """
+ try:
+ # Use source connector configuration (not destination connector!)
+ if not self.source_connector_id or not self.source_connector_settings:
+ # Try to get source connector info from workflow data as fallback
+ source_connector_id = (
+ workflow.get("source_connector_id") if workflow else None
+ )
+ source_connector_settings = (
+ workflow.get("source_connector_settings") if workflow else None
+ )
+
+ if not source_connector_id or not source_connector_settings:
+ raise ValueError(
+ f"Source connector configuration not available for {file_name}"
+ )
+ else:
+ source_connector_id = self.source_connector_id
+ source_connector_settings = self.source_connector_settings
+
+ logger.debug(
+ f"Using source connector {source_connector_id} to read {file_name}"
+ )
+
+ # Import connector operations
+
+ # Get the source connector instance (not destination!)
+ connectorkit = Connectorkit()
+ connector_class = connectorkit.get_connector_class_by_connector_id(
+ source_connector_id
+ )
+ connector_instance = connector_class(source_connector_settings)
+
+ # Get fsspec filesystem (like backend: self.get_fsspec())
+ source_fs = connector_instance.get_fsspec_fs()
+
+ # Read file content (like backend: source_fs.open(input_file_path, "rb"))
+ with source_fs.open(input_file_path, "rb") as remote_file:
+ file_content = remote_file.read()
+ file_content_base64 = base64.b64encode(file_content).decode("utf-8")
+
+ logger.info(
+ f"Successfully read {len(file_content)} bytes from source connector for {file_name}"
+ )
+ return file_content_base64
+
+ except Exception as e:
+ logger.error(
+ f"Failed to read file from source connector for {file_name}: {e}"
+ )
+ raise OSError(f"Failed to read file from source connector: {e}")
+
+
+# Alias for backward compatibility
+DestinationConnector = WorkerDestinationConnector
diff --git a/workers/shared/workflow/execution/__init__.py b/workers/shared/workflow/execution/__init__.py
new file mode 100644
index 000000000..62c0e91a4
--- /dev/null
+++ b/workers/shared/workflow/execution/__init__.py
@@ -0,0 +1,19 @@
+"""Workflow execution components.
+
+This package provides the core workflow execution functionality including
+services, orchestrators, and execution context management.
+"""
+
+from .active_file_manager import ActiveFileManager
+from .context import WorkerExecutionContext
+from .file_management_utils import FileManagementUtils
+from .orchestration_utils import WorkflowOrchestrationUtils
+from .service import WorkerWorkflowExecutionService
+
+__all__ = [
+ "WorkerExecutionContext",
+ "WorkflowOrchestrationUtils",
+ "WorkerWorkflowExecutionService",
+ "ActiveFileManager",
+ "FileManagementUtils",
+]
diff --git a/workers/shared/workflow/execution/active_file_manager.py b/workers/shared/workflow/execution/active_file_manager.py
new file mode 100644
index 000000000..3ff806528
--- /dev/null
+++ b/workers/shared/workflow/execution/active_file_manager.py
@@ -0,0 +1,884 @@
+"""Active File Manager Utility
+
+This module provides utilities for managing active file processing state and preventing
+race conditions in concurrent workflow executions.
+
+Key Features:
+- Filter files that are already being processed by other executions
+- Create cache entries to prevent race conditions
+- Provide detailed statistics for monitoring and debugging
+- Graceful error handling that never fails the entire execution
+"""
+
+import hashlib
+import os
+import time
+from typing import Any, Protocol
+
+from ...api.internal_client import InternalAPIClient
+from ...cache.cache_backends import RedisCacheBackend
+from ...infrastructure.logging import WorkerLogger
+
+# Constants for cache configuration
+DEFAULT_ACTIVE_FILE_CACHE_TTL = 300 # 5 minutes
+MAX_ACTIVE_FILE_CACHE_TTL = 3600 # 1 hour maximum
+
+
+def get_active_file_cache_ttl() -> int:
+ """Get the configurable TTL for active file cache entries.
+
+ Returns:
+ TTL in seconds, with sensible defaults and bounds checking
+ """
+ try:
+ ttl = int(os.environ.get("ACTIVE_FILE_CACHE_TTL", DEFAULT_ACTIVE_FILE_CACHE_TTL))
+ # Ensure TTL is within reasonable bounds
+ return min(max(ttl, 60), MAX_ACTIVE_FILE_CACHE_TTL) # Between 1 minute and 1 hour
+ except (ValueError, TypeError):
+ return DEFAULT_ACTIVE_FILE_CACHE_TTL
+
+
+class LoggerProtocol(Protocol):
+ """Protocol for logger objects to provide proper type hints."""
+
+ def debug(self, msg: str) -> None: ...
+ def info(self, msg: str) -> None: ...
+ def warning(self, msg: str) -> None: ...
+ def error(self, msg: str) -> None: ...
+
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class ActiveFileManager:
+ """Utility class for managing active file processing state and race condition prevention.
+
+ **USAGE SCOPE**:
+ - ✅ USE: ETL/TASK workflows in @workers/general/
+ - ❌ DON'T USE: API deployments in @workers/api-deployment/
+
+ API deployments have different concurrency patterns and should not use the file_active
+ cache pattern. They handle duplicate processing through their own mechanisms.
+ """
+
+ @staticmethod
+ def filter_and_cache_files(
+ source_files: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ api_client: Any,
+ logger_instance: LoggerProtocol | None = None,
+ final_files_to_process: dict[str, Any] | None = None,
+ ) -> tuple[dict[str, Any], int, dict[str, Any]]:
+ """Filter out active files and create cache entries for files to be processed.
+
+ This method performs three key operations:
+ 1. Checks cache and database for files already being processed
+ 2. Creates cache entries ONLY for files that will actually be processed (race condition prevention)
+ 3. Filters the source_files dict to remove active files
+
+ Args:
+ source_files: Dictionary of source files to process
+ workflow_id: Workflow identifier
+ execution_id: Current execution identifier
+ api_client: API client for database checks
+ logger_instance: Optional logger override (uses module logger if None)
+ final_files_to_process: Optional dict of files that will actually be processed (after limits)
+ If provided, cache entries are created only for these files
+
+ Returns:
+ Tuple of (filtered_source_files, new_file_count, filtering_stats)
+
+ Example:
+ >>> files = {"file1": {"provider_file_uuid": "uuid1"}}
+ >>> filtered, count, stats = ActiveFileManager.filter_and_cache_files(
+ ... source_files=files,
+ ... workflow_id="workflow-123",
+ ... execution_id="exec-456",
+ ... api_client=client,
+ ... )
+ >>> print(f"Processing {count} files, stats: {stats}")
+ """
+ log = logger_instance or logger
+
+ if not source_files:
+ return (
+ source_files,
+ 0,
+ {"original_count": 0, "filtered_count": 0, "skipped_files": []},
+ )
+
+ original_count = len(source_files)
+ filtering_stats = {
+ "original_count": original_count,
+ "cache_active": [], # Files found active in cache
+ "db_active": [], # Files found active in database
+ "processing_files": [], # Files that will be processed
+ "cache_created": 0, # Successfully created cache entries
+ "cache_errors": 0, # Failed cache operations
+ "filtered_count": original_count, # Will be updated if filtering occurs
+ }
+
+ try:
+ # Extract provider_file_uuids and file paths from source files for checking
+ provider_file_map = {} # provider_uuid -> file_key mapping (for backward compatibility)
+ file_tracking_data = {} # file_key -> {provider_uuid, file_path, file_data} mapping
+
+ for file_key, file_data in source_files.items():
+ provider_uuid = ActiveFileManager._extract_provider_uuid(file_data)
+ file_path = ActiveFileManager._extract_file_path(file_data)
+
+ if provider_uuid:
+ # For backward compatibility with database checks
+ provider_file_map[provider_uuid] = file_key
+ # New tracking structure includes both provider_uuid and file_path
+ file_tracking_data[file_key] = {
+ "provider_uuid": provider_uuid,
+ "file_path": file_path
+ or file_key, # fallback to file_key if no file_path
+ "file_data": file_data,
+ }
+
+ if not provider_file_map:
+ log.warning(
+ "No provider_file_uuid found in source files, proceeding without filtering"
+ )
+ return source_files, original_count, filtering_stats
+
+ log.info(
+ f"Checking {len(provider_file_map)} files for active processing conflicts"
+ )
+ log.debug(f"Current execution_id: {execution_id}, workflow_id: {workflow_id}")
+
+ active_files_to_skip = set()
+
+ # STEP 1: Check active_file cache for OTHER executions
+ try:
+ cache_stats = ActiveFileManager._handle_cache_check(
+ file_tracking_data=file_tracking_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ log=log,
+ )
+ active_files_to_skip.update(cache_stats["active_files"])
+ filtering_stats.update(cache_stats["stats"])
+
+ except Exception as cache_error:
+ log.warning(f"Active file cache operations failed: {cache_error}")
+
+ # STEP 2: Database check for files in PENDING/EXECUTING state (backend only reads cache, doesn't create)
+ try:
+ db_active_provider_uuids = ActiveFileManager._check_database_active_files(
+ api_client=api_client,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ provider_file_map=provider_file_map,
+ log=log,
+ )
+
+ if db_active_provider_uuids:
+ # Convert provider UUIDs back to file keys for filtering
+ db_active_file_keys = {
+ provider_file_map[provider_uuid]
+ for provider_uuid in db_active_provider_uuids
+ if provider_uuid in provider_file_map
+ }
+
+ new_db_active = db_active_file_keys - active_files_to_skip
+ active_files_to_skip.update(db_active_file_keys)
+ filtering_stats["db_active"].extend(list(new_db_active))
+ log.info(
+ f"📊 Found {len(new_db_active)} additional files active in database"
+ )
+
+ except Exception as db_error:
+ log.warning(f"Database file check failed: {db_error}")
+
+ # STEP 3: Filter source_files to remove active ones (now using file_keys directly)
+ if active_files_to_skip:
+ filtered_files, new_count = (
+ ActiveFileManager._filter_source_files_by_keys(
+ source_files=source_files,
+ active_file_keys_to_skip=active_files_to_skip,
+ log=log,
+ )
+ )
+
+ filtering_stats["filtered_count"] = new_count
+ filtering_stats["skipped_files"] = list(active_files_to_skip)
+
+ log.info(
+ f"🔄 Filtered files: {original_count} → {new_count} "
+ f"(removed {len(active_files_to_skip)} active files)"
+ )
+
+ # STEP 4: Create cache entries only for files that will actually be processed
+ if final_files_to_process:
+ ActiveFileManager._create_cache_entries_for_selected_files(
+ final_files_to_process=final_files_to_process,
+ file_tracking_data=file_tracking_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ log=log,
+ filtering_stats=filtering_stats,
+ )
+
+ return filtered_files, new_count, filtering_stats
+ else:
+ log.info("✅ No active files found - processing all files")
+
+ # Create cache entries for files that will actually be processed
+ if final_files_to_process:
+ ActiveFileManager._create_cache_entries_for_selected_files(
+ final_files_to_process=final_files_to_process,
+ file_tracking_data=file_tracking_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ log=log,
+ filtering_stats=filtering_stats,
+ )
+
+ return source_files, original_count, filtering_stats
+
+ except Exception as filter_error:
+ log.warning(f"File filtering failed: {filter_error}")
+ filtering_stats["error"] = str(filter_error)
+ return source_files, original_count, filtering_stats
+
+ @staticmethod
+ def create_cache_entries(
+ source_files: dict[str, Any],
+ files_to_cache: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> dict[str, Any]:
+ """Create cache entries for files to prevent race conditions (cache-only, no filtering).
+
+ This method ONLY creates cache entries for race condition prevention. It does NOT
+ filter files or modify the source_files dictionary. Use this after FilterPipeline
+ has already applied all necessary filtering including ActiveFileFilter.
+
+ Args:
+ source_files: Dictionary of all source files (used for file_tracking_data)
+ files_to_cache: Dictionary of specific files to create cache entries for
+ workflow_id: Workflow identifier
+ execution_id: Current execution identifier
+ logger_instance: Optional logger override (uses module logger if None)
+
+ Returns:
+ Cache statistics dictionary with creation results
+
+ Example:
+ >>> # After FilterPipeline has filtered files
+ >>> cache_stats = ActiveFileManager.create_cache_entries(
+ ... source_files=all_files, # Original files for tracking data
+ ... files_to_cache=filtered_files, # Only cache these specific files
+ ... workflow_id="workflow-123",
+ ... execution_id="exec-456",
+ ... )
+ >>> print(f"Created {cache_stats['cache_created']} cache entries")
+ """
+ log = logger_instance or logger
+
+ if not files_to_cache:
+ return {
+ "cache_created": 0,
+ "cache_errors": 0,
+ "processing_files": [],
+ }
+
+ cache_stats = {
+ "cache_created": 0,
+ "cache_errors": 0,
+ "processing_files": [],
+ }
+
+ try:
+ # Extract provider_file_uuids and file paths from source files for tracking data
+ file_tracking_data = {} # file_key -> {provider_uuid, file_path, file_data} mapping
+
+ for file_key, file_data in source_files.items():
+ provider_uuid = ActiveFileManager._extract_provider_uuid(file_data)
+ file_path = ActiveFileManager._extract_file_path(file_data)
+
+ if provider_uuid:
+ file_tracking_data[file_key] = {
+ "provider_uuid": provider_uuid,
+ "file_path": file_path
+ or file_key, # fallback to file_key if no file_path
+ "file_data": file_data,
+ }
+
+ if not file_tracking_data:
+ log.warning(
+ "No provider_file_uuid found in source files, skipping cache creation"
+ )
+ return cache_stats
+
+ log.info(
+ f"🔒 Creating cache entries for {len(files_to_cache)} files to prevent race conditions"
+ )
+
+ # Create cache entries only for the specified files
+ ActiveFileManager._create_cache_entries_for_selected_files(
+ final_files_to_process=files_to_cache,
+ file_tracking_data=file_tracking_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ log=log,
+ filtering_stats=cache_stats,
+ )
+
+ log.info(
+ f"✅ Cache creation complete: {cache_stats['cache_created']} entries created, "
+ f"{cache_stats['cache_errors']} errors"
+ )
+
+ except Exception as cache_error:
+ log.warning(f"Cache entry creation failed: {cache_error}")
+ cache_stats["error"] = str(cache_error)
+
+ return cache_stats
+
+ @staticmethod
+ def create_cache_entries_simple(
+ files_to_cache: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> dict[str, Any]:
+ """Create cache entries for files to prevent race conditions (simplified API).
+
+ This is a simplified version of create_cache_entries() for cases where you only
+ have the final filtered files to cache (e.g., in discovery methods after FilterPipeline).
+ Use this when source_files and files_to_cache would be the same dictionary.
+
+ Args:
+ files_to_cache: Dictionary of files to create cache entries for
+ workflow_id: Workflow identifier
+ execution_id: Current execution identifier
+ logger_instance: Optional logger override (uses module logger if None)
+
+ Returns:
+ Cache statistics dictionary with creation results
+
+ Example:
+ >>> # After FilterPipeline in discovery methods
+ >>> cache_stats = ActiveFileManager.create_cache_entries_simple(
+ ... files_to_cache=final_filtered_files,
+ ... workflow_id="workflow-123",
+ ... execution_id="exec-456",
+ ... )
+ >>> print(f"Created {cache_stats['cache_created']} cache entries")
+ """
+ # Delegate to the full method with same dict for both parameters
+ return ActiveFileManager.create_cache_entries(
+ source_files=files_to_cache,
+ files_to_cache=files_to_cache,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ logger_instance=logger_instance,
+ )
+
+ @staticmethod
+ def _extract_provider_uuid(file_data: Any) -> str | None:
+ """Extract provider_file_uuid from file data, handling different formats."""
+ if hasattr(file_data, "provider_file_uuid") and file_data.provider_file_uuid:
+ return file_data.provider_file_uuid
+ elif isinstance(file_data, dict) and file_data.get("provider_file_uuid"):
+ return file_data["provider_file_uuid"]
+ return None
+
+ @staticmethod
+ def _extract_file_path(file_data: Any) -> str | None:
+ """Extract file_path from file data, handling different formats."""
+ if hasattr(file_data, "file_path") and file_data.file_path:
+ return file_data.file_path
+ elif isinstance(file_data, dict) and file_data.get("file_path"):
+ return file_data["file_path"]
+ return None
+
+ @staticmethod
+ def _generate_file_path_hash(file_path: str) -> str:
+ """Generate a short hash for file path to differentiate files with same provider_uuid.
+
+ Uses SHA256 with 12 characters for better collision resistance while keeping
+ cache keys reasonably short.
+ """
+ return hashlib.sha256(file_path.encode("utf-8")).hexdigest()[:12]
+
+ @staticmethod
+ def _create_cache_key(workflow_id: str, provider_uuid: str, file_path: str) -> str:
+ """Create cache key that uniquely identifies a file by provider_uuid AND file_path.
+
+ This prevents conflicts when multiple files with same content (same provider_uuid)
+ but different paths exist.
+ """
+ file_path_hash = ActiveFileManager._generate_file_path_hash(file_path)
+ return f"file_active:{workflow_id}:{provider_uuid}:{file_path_hash}"
+
+ @staticmethod
+ def _handle_cache_check(
+ file_tracking_data: dict[str, dict],
+ workflow_id: str,
+ execution_id: str,
+ log: LoggerProtocol,
+ ) -> dict[str, Any]:
+ """Handle cache checking operations using batch Redis operations for performance."""
+ cache = RedisCacheBackend()
+ active_files_to_skip = set() # Set of file_keys to skip
+ stats = {
+ "cache_active": [],
+ "processing_files": [],
+ "cache_created": 0,
+ "cache_errors": 0,
+ }
+
+ if not file_tracking_data:
+ return {"active_files": active_files_to_skip, "stats": stats}
+
+ try:
+ # BATCH OPTIMIZATION: Pre-compute all cache keys and fetch in single operation
+ cache_key_to_file_key = {} # cache_key -> file_key mapping
+ file_key_to_tracking = {} # file_key -> tracking_info mapping
+
+ # Pre-compute all cache keys
+ for file_key, tracking_info in file_tracking_data.items():
+ provider_uuid = tracking_info["provider_uuid"]
+ file_path = tracking_info["file_path"]
+
+ cache_key = ActiveFileManager._create_cache_key(
+ workflow_id, provider_uuid, file_path
+ )
+ cache_key_to_file_key[cache_key] = file_key
+ file_key_to_tracking[file_key] = tracking_info
+
+ # Single batch Redis call instead of N individual calls
+ cache_keys = list(cache_key_to_file_key.keys())
+ log.debug(f"Batch checking {len(cache_keys)} cache keys for active files")
+
+ cached_results = cache.mget(cache_keys)
+
+ # Process batch results
+ for cache_key, cached_data in cached_results.items():
+ file_key = cache_key_to_file_key[cache_key]
+ tracking_info = file_key_to_tracking[file_key]
+
+ if cached_data and isinstance(cached_data, dict):
+ # Extract data from cache wrapper
+ cached_active = cached_data.get("data", {})
+
+ if isinstance(cached_active, dict):
+ cached_execution_id = cached_active.get("execution_id")
+ cached_file_path = cached_active.get("file_path", "unknown")
+ current_file_path = tracking_info["file_path"]
+
+ log.debug(
+ f"File {file_key}: cached_execution_id={cached_execution_id}, current_execution_id={execution_id}"
+ )
+ log.debug(
+ f" Cache path: {cached_file_path}, Current path: {current_file_path}"
+ )
+
+ if cached_execution_id != execution_id:
+ active_files_to_skip.add(file_key)
+ stats["cache_active"].append(file_key)
+ log.debug(
+ f"File {file_key} already active by execution {cached_execution_id}, will skip"
+ )
+ else:
+ log.debug(
+ f"File {file_key} cached by same execution {execution_id}, will process"
+ )
+
+ if active_files_to_skip:
+ log.info(
+ f"⚡ Found {len(active_files_to_skip)} files already active in cache (batch check)"
+ )
+
+ except Exception as batch_error:
+ log.warning(
+ f"Batch cache check failed, falling back to individual checks: {batch_error}"
+ )
+ # Fallback to individual checks if batch fails
+ return ActiveFileManager._handle_cache_check_fallback(
+ file_tracking_data, workflow_id, execution_id, log
+ )
+
+ return {"active_files": active_files_to_skip, "stats": stats}
+
+ @staticmethod
+ def _handle_cache_check_fallback(
+ file_tracking_data: dict[str, dict],
+ workflow_id: str,
+ execution_id: str,
+ log: LoggerProtocol,
+ ) -> dict[str, Any]:
+ """Fallback method using individual Redis operations if batch fails."""
+ cache = RedisCacheBackend()
+ active_files_to_skip = set()
+ stats = {
+ "cache_active": [],
+ "processing_files": [],
+ "cache_created": 0,
+ "cache_errors": 0,
+ }
+
+ # Fallback to individual cache checks
+ for file_key, tracking_info in file_tracking_data.items():
+ provider_uuid = tracking_info["provider_uuid"]
+ file_path = tracking_info["file_path"]
+
+ try:
+ cache_key = ActiveFileManager._create_cache_key(
+ workflow_id, provider_uuid, file_path
+ )
+ cached_active = cache.get(cache_key)
+
+ if cached_active and isinstance(cached_active, dict):
+ cached_execution_id = cached_active.get("execution_id")
+ if cached_execution_id != execution_id:
+ active_files_to_skip.add(file_key)
+ stats["cache_active"].append(file_key)
+
+ except Exception as key_error:
+ log.debug(f"Individual cache check failed for {file_key}: {key_error}")
+
+ return {"active_files": active_files_to_skip, "stats": stats}
+
+ @staticmethod
+ def _create_cache_entries_for_selected_files(
+ final_files_to_process: dict[str, Any],
+ file_tracking_data: dict[str, dict],
+ workflow_id: str,
+ execution_id: str,
+ log: LoggerProtocol,
+ filtering_stats: dict[str, Any],
+ ) -> None:
+ """Create cache entries only for files that will actually be processed.
+
+ OPTIMIZED: Uses batch Redis operations for better performance with large file sets.
+ Uses file-path-aware cache keys to differentiate files with the same content
+ but different paths.
+ """
+ if not final_files_to_process:
+ return
+
+ cache = RedisCacheBackend()
+ ttl = get_active_file_cache_ttl() # Use configurable TTL
+
+ log.info(
+ f"Creating cache entries for {len(final_files_to_process)} final selected files (TTL: {ttl}s)"
+ )
+
+ try:
+ # BATCH OPTIMIZATION: Prepare all cache entries for batch creation
+ batch_cache_data = {} # cache_key -> (cache_data, ttl)
+ processing_files = []
+ cache_errors = 0
+
+ for file_key, file_data in final_files_to_process.items():
+ # Get tracking info for this file
+ tracking_info = file_tracking_data.get(file_key)
+ if not tracking_info:
+ log.warning(f"No tracking info found for file: {file_key}")
+ cache_errors += 1
+ continue
+
+ provider_uuid = tracking_info["provider_uuid"]
+ file_path = tracking_info["file_path"]
+
+ if not provider_uuid:
+ cache_errors += 1
+ continue
+
+ try:
+ # Prepare cache entry data
+ cache_key = ActiveFileManager._create_cache_key(
+ workflow_id, provider_uuid, file_path
+ )
+ cache_data = {
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "provider_file_uuid": provider_uuid,
+ "file_path": file_path,
+ "status": "EXECUTING",
+ "created_at": time.time(),
+ }
+
+ batch_cache_data[cache_key] = (cache_data, ttl)
+ processing_files.append(file_key)
+ log.debug(f"Prepared cache entry for: {file_key} ({provider_uuid})")
+
+ except Exception as prep_error:
+ log.warning(
+ f"Failed to prepare cache entry for {file_key}: {prep_error}"
+ )
+ cache_errors += 1
+
+ # Single batch Redis operation instead of N individual operations
+ if batch_cache_data:
+ cache_created = cache.mset(batch_cache_data)
+ log.info(
+ f"🔒 Batch created {cache_created}/{len(batch_cache_data)} cache entries "
+ f"for race condition prevention"
+ )
+ else:
+ cache_created = 0
+ log.warning("No valid cache entries prepared for batch creation")
+
+ except Exception as batch_error:
+ log.warning(
+ f"Batch cache creation failed, falling back to individual operations: {batch_error}"
+ )
+ # Fallback to individual cache creation
+ cache_created, cache_errors, processing_files = (
+ ActiveFileManager._create_cache_entries_fallback(
+ final_files_to_process=final_files_to_process,
+ file_tracking_data=file_tracking_data,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ log=log,
+ ttl=ttl,
+ )
+ )
+
+ # Update statistics with the actual cache creation results
+ filtering_stats["cache_created"] = cache_created
+ filtering_stats["cache_errors"] = cache_errors
+ filtering_stats["processing_files"] = processing_files
+
+ @staticmethod
+ def _create_cache_entries_fallback(
+ final_files_to_process: dict[str, Any],
+ file_tracking_data: dict[str, dict],
+ workflow_id: str,
+ execution_id: str,
+ log: LoggerProtocol,
+ ttl: int,
+ ) -> tuple[int, int, list[str]]:
+ """Fallback method for individual cache creation if batch fails."""
+ cache = RedisCacheBackend()
+ cache_created = 0
+ cache_errors = 0
+ processing_files = []
+
+ for file_key, file_data in final_files_to_process.items():
+ tracking_info = file_tracking_data.get(file_key)
+ if not tracking_info:
+ cache_errors += 1
+ continue
+
+ provider_uuid = tracking_info["provider_uuid"]
+ file_path = tracking_info["file_path"]
+
+ if not provider_uuid:
+ cache_errors += 1
+ continue
+
+ success = ActiveFileManager._create_cache_entry(
+ cache=cache,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ provider_uuid=provider_uuid,
+ file_path=file_path,
+ log=log,
+ ttl=ttl,
+ )
+
+ if success:
+ cache_created += 1
+ processing_files.append(file_key)
+ else:
+ cache_errors += 1
+
+ return cache_created, cache_errors, processing_files
+
+ @staticmethod
+ def _create_cache_entry(
+ cache: RedisCacheBackend,
+ workflow_id: str,
+ execution_id: str,
+ provider_uuid: str,
+ file_path: str,
+ log: LoggerProtocol,
+ ttl: int | None = None,
+ ) -> bool:
+ """Create a cache entry for an active file using file-path-aware key."""
+ try:
+ # Use configurable TTL if not provided
+ if ttl is None:
+ ttl = get_active_file_cache_ttl()
+
+ cache_key = ActiveFileManager._create_cache_key(
+ workflow_id, provider_uuid, file_path
+ )
+ cache_data = {
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "provider_file_uuid": provider_uuid,
+ "file_path": file_path, # Include file path in cache data
+ "status": "EXECUTING",
+ "created_at": time.time(),
+ }
+
+ cache.set(cache_key, cache_data, ttl=ttl)
+ log.debug(f"Created cache entry for {provider_uuid} at {file_path}")
+ return True
+
+ except Exception as cache_set_error:
+ log.warning(
+ f"Failed to create cache entry for {provider_uuid}: {cache_set_error}"
+ )
+ return False
+
+ @staticmethod
+ def _check_database_active_files(
+ api_client: InternalAPIClient,
+ workflow_id: str,
+ execution_id: str,
+ provider_file_map: dict[str, str],
+ log: LoggerProtocol,
+ ) -> set[str]:
+ """Check database for active files and return set of active provider UUIDs."""
+ active_files_response = api_client.check_files_active_processing(
+ workflow_id=workflow_id,
+ provider_file_uuids=list(provider_file_map.keys()),
+ current_execution_id=execution_id,
+ )
+
+ if active_files_response.success:
+ active_files_data = active_files_response.data
+ return {uuid for uuid, is_active in active_files_data.items() if is_active}
+ else:
+ log.warning(
+ f"Database active file check failed: {active_files_response.error}"
+ )
+ return set()
+
+ @staticmethod
+ def _filter_source_files_by_keys(
+ source_files: dict[str, Any],
+ active_file_keys_to_skip: set[str],
+ log: LoggerProtocol,
+ ) -> tuple[dict[str, Any], int]:
+ """Filter source_files dict to remove active files by file keys."""
+ for file_key in active_file_keys_to_skip:
+ if file_key in source_files:
+ del source_files[file_key]
+ log.debug(f"Removed active file: {file_key}")
+
+ new_count = len(source_files)
+ return source_files, new_count
+
+ @staticmethod
+ def _filter_source_files(
+ source_files: dict[str, Any],
+ active_files_to_skip: set[str],
+ provider_file_map: dict[str, str],
+ log: LoggerProtocol,
+ ) -> tuple[dict[str, Any], int]:
+ """Filter source_files dict to remove active files (legacy method)."""
+ files_to_remove = [
+ provider_file_map[provider_uuid]
+ for provider_uuid in active_files_to_skip
+ if provider_uuid in provider_file_map
+ ]
+
+ for file_key in files_to_remove:
+ del source_files[file_key]
+
+ new_count = len(source_files)
+ return source_files, new_count
+
+ @staticmethod
+ def cleanup_cache_entries(
+ provider_file_uuids: list[str],
+ workflow_id: str,
+ log: LoggerProtocol | None = None,
+ ) -> int:
+ """Clean up file-path-aware cache entries for completed file processing.
+
+ OPTIMIZED: Uses non-blocking SCAN instead of blocking KEYS for production safety.
+ Uses pattern matching to find all cache entries for the given provider UUIDs
+ since we don't have the file paths available during cleanup.
+
+ Args:
+ provider_file_uuids: List of provider file UUIDs to clean up
+ workflow_id: Workflow ID
+ log: Optional logger instance
+
+ Returns:
+ Number of cache entries cleaned up
+ """
+ logger_instance = log or logger
+
+ if not provider_file_uuids:
+ return 0
+
+ try:
+ cache = RedisCacheBackend()
+ cleaned_count = 0
+
+ for provider_uuid in provider_file_uuids:
+ # Find all file-path-aware cache entries for this provider_uuid
+ pattern = f"file_active:{workflow_id}:{provider_uuid}:*"
+ try:
+ # Use non-blocking SCAN instead of blocking KEYS
+ matching_keys = cache.scan_keys(
+ pattern, count=50
+ ) # Small batches for safety
+
+ if matching_keys:
+ # Delete in batches to avoid large delete operations
+ batch_size = 100
+ for i in range(0, len(matching_keys), batch_size):
+ batch_keys = matching_keys[i : i + batch_size]
+ try:
+ # Batch delete for efficiency
+ deleted_count = cache.redis_client.delete(*batch_keys)
+ cleaned_count += deleted_count
+ logger_instance.debug(
+ f"Cleaned up {deleted_count} cache entries for {provider_uuid} (batch {i//batch_size + 1})"
+ )
+ except Exception as batch_error:
+ logger_instance.warning(
+ f"Failed to delete batch for {provider_uuid}: {batch_error}"
+ )
+ # Fallback to individual deletion
+ for key in batch_keys:
+ try:
+ if cache.delete(key):
+ cleaned_count += 1
+ except Exception:
+ pass # Continue with other keys
+
+ except Exception as pattern_error:
+ logger_instance.warning(
+ f"Failed to cleanup entries for {provider_uuid}: {pattern_error}"
+ )
+
+ if cleaned_count > 0:
+ logger_instance.info(
+ f"🧹 Cleaned up {cleaned_count} active file cache entries (non-blocking SCAN)"
+ )
+
+ return cleaned_count
+
+ except Exception as cleanup_error:
+ logger_instance.warning(f"Failed to cleanup cache entries: {cleanup_error}")
+ return 0
+
+
+def cleanup_active_file_cache(
+ provider_file_uuids: list[str],
+ workflow_id: str,
+ logger_instance: LoggerProtocol | None = None,
+) -> int:
+ """Convenience function that delegates to ActiveFileManager.cleanup_cache_entries()."""
+ return ActiveFileManager.cleanup_cache_entries(
+ provider_file_uuids=provider_file_uuids,
+ workflow_id=workflow_id,
+ log=logger_instance,
+ )
diff --git a/workers/shared/workflow/execution/context.py b/workers/shared/workflow/execution/context.py
new file mode 100644
index 000000000..5fbdcd7f6
--- /dev/null
+++ b/workers/shared/workflow/execution/context.py
@@ -0,0 +1,240 @@
+"""Execution Context Management for Worker Tasks
+
+This module provides standardized execution context setup, error handling,
+and resource management patterns used across all worker task implementations.
+"""
+
+import logging
+from contextlib import contextmanager
+from typing import Any
+
+from unstract.core.data_models import ExecutionStatus
+
+from ...api.internal_client import InternalAPIClient
+from ...constants.account import Account
+from ...core.exceptions import WorkflowExecutionError as WorkerExecutionError
+from ...infrastructure.config import WorkerConfig
+from ...infrastructure.logging import WorkerLogger
+from ...utils.local_context import StateStore
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WorkerExecutionContext:
+ """Manages common worker execution setup and teardown patterns."""
+
+ @staticmethod
+ def setup_execution_context(
+ organization_id: str, execution_id: str, workflow_id: str
+ ) -> tuple[WorkerConfig, InternalAPIClient]:
+ """Set up common execution context for worker tasks.
+
+ Args:
+ organization_id: Organization context ID
+ execution_id: Workflow execution ID
+ workflow_id: Workflow ID
+
+ Returns:
+ Tuple of (WorkerConfig, InternalAPIClient) configured for the context
+
+ Raises:
+ WorkerExecutionError: If context setup fails
+ """
+ try:
+ # Set up organization context in state store
+ StateStore.set(Account.ORGANIZATION_ID, organization_id)
+
+ # Initialize API client with configuration
+ config = WorkerConfig()
+ api_client = InternalAPIClient(config)
+ api_client.set_organization_context(organization_id)
+
+ logger.info(
+ f"Execution context setup complete - "
+ f"org_id={organization_id}, exec_id={execution_id}, workflow_id={workflow_id}"
+ )
+
+ return config, api_client
+
+ except Exception as e:
+ logger.error(f"Failed to setup execution context: {e}")
+ raise WorkerExecutionError(f"Context setup failed: {e}") from e
+
+ @staticmethod
+ def handle_execution_error(
+ api_client: InternalAPIClient,
+ execution_id: str,
+ error: Exception,
+ logger: logging.Logger,
+ context: str = "execution",
+ ) -> None:
+ """Standardized error handling for execution failures.
+
+ Args:
+ api_client: API client for status updates
+ execution_id: Execution ID to update
+ error: The error that occurred
+ logger: Logger instance for error reporting
+ context: Context description for logging
+ """
+ error_message = str(error)
+ logger.error(f"Error in {context}: {error_message}")
+
+ try:
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=error_message,
+ )
+ logger.info(
+ f"Execution status updated to ERROR for execution_id={execution_id}"
+ )
+
+ except Exception as update_error:
+ logger.error(
+ f"Failed to update execution status to ERROR: {update_error}. "
+ f"Original error: {error_message}"
+ )
+
+ @staticmethod
+ @contextmanager
+ def managed_execution_context(
+ organization_id: str, execution_id: str, workflow_id: str
+ ):
+ """Context manager for automatic execution context setup and cleanup.
+
+ Args:
+ organization_id: Organization context ID
+ execution_id: Workflow execution ID
+ workflow_id: Workflow ID
+
+ Yields:
+ Tuple of (WorkerConfig, InternalAPIClient)
+
+ Usage:
+ with WorkerExecutionContext.managed_execution_context(
+ org_id, exec_id, workflow_id
+ ) as (config, api_client):
+ # Worker task logic here
+ pass
+ """
+ config = None
+ api_client = None
+
+ try:
+ config, api_client = WorkerExecutionContext.setup_execution_context(
+ organization_id, execution_id, workflow_id
+ )
+ yield config, api_client
+
+ except Exception as e:
+ if api_client:
+ WorkerExecutionContext.handle_execution_error(
+ api_client, execution_id, e, logger, "managed_context"
+ )
+ raise
+
+ finally:
+ # Cleanup resources if needed
+ try:
+ if api_client:
+ api_client.close()
+ except Exception as cleanup_error:
+ logger.warning(f"Error during context cleanup: {cleanup_error}")
+
+ @staticmethod
+ def log_task_start(
+ task_name: str,
+ execution_id: str,
+ workflow_id: str,
+ additional_params: dict[str, Any] | None = None,
+ ) -> None:
+ """Standardized task start logging.
+
+ Args:
+ task_name: Name of the task being executed
+ execution_id: Workflow execution ID
+ workflow_id: Workflow ID
+ additional_params: Optional additional parameters to log
+ """
+ log_parts = [
+ f"Starting {task_name}",
+ f"execution_id={execution_id}",
+ f"workflow_id={workflow_id}",
+ ]
+
+ if additional_params:
+ for key, value in additional_params.items():
+ # Sanitize sensitive information
+ if (
+ "password" in key.lower()
+ or "secret" in key.lower()
+ or "token" in key.lower()
+ ):
+ value = "***REDACTED***"
+ log_parts.append(f"{key}={value}")
+
+ logger.info(" - ".join(log_parts))
+
+ @staticmethod
+ def log_task_completion(
+ task_name: str,
+ execution_id: str,
+ success: bool,
+ result_summary: str | None = None,
+ duration_seconds: float | None = None,
+ ) -> None:
+ """Standardized task completion logging.
+
+ Args:
+ task_name: Name of the task that completed
+ execution_id: Workflow execution ID
+ success: Whether the task completed successfully
+ result_summary: Optional summary of results
+ duration_seconds: Optional task duration
+ """
+ status = "SUCCESS" if success else "FAILED"
+ log_parts = [f"{task_name} {status}", f"execution_id={execution_id}"]
+
+ if duration_seconds is not None:
+ log_parts.append(f"duration={duration_seconds:.2f}s")
+
+ if result_summary:
+ log_parts.append(f"result={result_summary}")
+
+ if success:
+ logger.info(" - ".join(log_parts))
+ else:
+ logger.error(" - ".join(log_parts))
+
+
+class WorkerTaskMixin:
+ """Mixin class to add common execution context methods to worker tasks."""
+
+ def setup_context(self, organization_id: str, execution_id: str, workflow_id: str):
+ """Set up execution context for this task."""
+ return WorkerExecutionContext.setup_execution_context(
+ organization_id, execution_id, workflow_id
+ )
+
+ def handle_error(
+ self, api_client: InternalAPIClient, execution_id: str, error: Exception
+ ):
+ """Handle execution error for this task."""
+ # Get logger from the task instance if available
+ task_logger = getattr(self, "logger", logger)
+ WorkerExecutionContext.handle_execution_error(
+ api_client, execution_id, error, task_logger, self.__class__.__name__
+ )
+
+ def log_start(self, execution_id: str, workflow_id: str, **params):
+ """Log task start with standard format."""
+ WorkerExecutionContext.log_task_start(
+ self.__class__.__name__, execution_id, workflow_id, params
+ )
+
+ def log_completion(self, execution_id: str, success: bool, **kwargs):
+ """Log task completion with standard format."""
+ WorkerExecutionContext.log_task_completion(
+ self.__class__.__name__, execution_id, success, **kwargs
+ )
diff --git a/workers/shared/workflow/execution/file_management_utils.py b/workers/shared/workflow/execution/file_management_utils.py
new file mode 100644
index 000000000..3dc0ba17a
--- /dev/null
+++ b/workers/shared/workflow/execution/file_management_utils.py
@@ -0,0 +1,426 @@
+"""File Management Utilities
+
+This module provides utility methods for file processing, filtering, and management
+that can be used across different worker types (general, api-deployment, etc.).
+
+Each utility method has a single responsibility and can be composed as needed.
+"""
+
+from typing import Any, Protocol
+
+from ...infrastructure.logging import WorkerLogger
+from .active_file_manager import ActiveFileManager
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class LoggerProtocol(Protocol):
+ """Protocol for logger objects to provide proper type hints."""
+
+ def debug(self, msg: str) -> None: ...
+ def info(self, msg: str) -> None: ...
+ def warning(self, msg: str) -> None: ...
+ def error(self, msg: str) -> None: ...
+
+
+class FileFilterResult:
+ """Result of file filtering operations."""
+
+ def __init__(
+ self,
+ filtered_files: dict[str, Any],
+ filtered_count: int,
+ filtering_stats: dict[str, Any],
+ ):
+ self.filtered_files = filtered_files
+ self.filtered_count = filtered_count
+ self.filtering_stats = filtering_stats
+ self.original_count = filtering_stats.get("original_count", 0)
+ self.skipped_files = filtering_stats.get("skipped_files", [])
+ self.cache_active_count = len(filtering_stats.get("cache_active", []))
+ self.db_active_count = len(filtering_stats.get("db_active", []))
+
+ def has_files(self) -> bool:
+ """Check if any files remain after filtering."""
+ return self.filtered_count > 0
+
+ def all_files_active(self) -> bool:
+ """Check if all files were filtered out due to being active."""
+ return self.original_count > 0 and self.filtered_count == 0
+
+
+class FileLimitResult:
+ """Result of applying file limits."""
+
+ def __init__(
+ self, limited_files: dict[str, Any], final_count: int, limit_applied: bool
+ ):
+ self.limited_files = limited_files
+ self.final_count = final_count
+ self.limit_applied = limit_applied
+
+
+class FileManagementUtils:
+ """Utility methods for file processing and management across workers."""
+
+ @staticmethod
+ def apply_active_file_filtering(
+ source_files: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ api_client: Any,
+ logger_instance: LoggerProtocol | None = None,
+ final_files_to_process: dict[str, Any] | None = None,
+ ) -> FileFilterResult:
+ """Apply active file filtering to remove files being processed by other executions.
+
+ Use this for ETL/TASK workflows that need to avoid duplicate processing.
+ API workflows typically skip this filtering.
+
+ Args:
+ source_files: Dictionary of source files to filter
+ workflow_id: Workflow ID
+ execution_id: Current execution ID
+ api_client: API client for database checks
+ logger_instance: Optional logger instance
+ final_files_to_process: Optional dict of files that will actually be processed
+ If provided, cache entries are created only for these files
+
+ Returns:
+ FileFilterResult with filtered files and statistics
+ """
+ log = logger_instance or logger
+
+ if not source_files:
+ return FileFilterResult(
+ filtered_files={},
+ filtered_count=0,
+ filtering_stats={
+ "original_count": 0,
+ "filtered_count": 0,
+ "skipped_files": [],
+ },
+ )
+
+ log.info(f"🔍 Applying active file filtering for {len(source_files)} files")
+
+ filtered_files, filtered_count, filtering_stats = (
+ ActiveFileManager.filter_and_cache_files(
+ source_files=source_files,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ api_client=api_client,
+ logger_instance=log,
+ final_files_to_process=final_files_to_process,
+ )
+ )
+
+ result = FileFilterResult(filtered_files, filtered_count, filtering_stats)
+
+ if result.all_files_active():
+ log.warning(
+ "⚠️ All discovered files are currently being processed by other executions"
+ )
+ log.info(
+ "💡 Tip: Wait for current executions to complete or discover more files"
+ )
+ elif result.has_files():
+ log.info(
+ f"✅ {result.filtered_count} files available for processing after filtering"
+ )
+
+ return result
+
+ @staticmethod
+ def apply_file_limit(
+ files: dict[str, Any],
+ max_limit: int,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> FileLimitResult:
+ """Apply maximum file limit to a collection of files.
+
+ Args:
+ files: Dictionary of files to limit
+ max_limit: Maximum number of files to allow
+ logger_instance: Optional logger instance
+
+ Returns:
+ FileLimitResult with limited files
+ """
+ log = logger_instance or logger
+
+ if len(files) <= max_limit:
+ return FileLimitResult(
+ limited_files=files, final_count=len(files), limit_applied=False
+ )
+
+ log.info(
+ f"📏 Applying max files limit: taking {max_limit} files from {len(files)} available"
+ )
+
+ # Convert to list, take first N files, convert back to dict
+ limited_files = dict(list(files.items())[:max_limit])
+
+ return FileLimitResult(
+ limited_files=limited_files, final_count=max_limit, limit_applied=True
+ )
+
+ @staticmethod
+ def cleanup_active_file_cache(
+ provider_file_uuids: list[str],
+ workflow_id: str,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> int:
+ """Clean up active file cache entries for completed/failed processing.
+
+ Args:
+ provider_file_uuids: List of provider file UUIDs to clean up
+ workflow_id: Workflow ID
+ logger_instance: Optional logger instance
+
+ Returns:
+ Number of cache entries cleaned up
+ """
+ log = logger_instance or logger
+
+ if not provider_file_uuids:
+ return 0
+
+ log.debug(f"🧹 Cleaning up cache entries for {len(provider_file_uuids)} files")
+
+ return ActiveFileManager.cleanup_cache_entries(
+ provider_file_uuids=provider_file_uuids, workflow_id=workflow_id, log=log
+ )
+
+ @staticmethod
+ def create_file_cache_entries(
+ source_files: dict[str, Any],
+ files_to_cache: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> dict[str, Any]:
+ """Create cache entries for files to prevent race conditions (cache-only, no filtering).
+
+ This is a utility wrapper around ActiveFileManager.create_cache_entries() that provides
+ a consistent interface for cache creation across different workflow types. Use this
+ after FilterPipeline has already applied all necessary filtering.
+
+ Args:
+ source_files: Dictionary of all source files (used for tracking data)
+ files_to_cache: Dictionary of specific files to create cache entries for
+ workflow_id: Workflow ID
+ execution_id: Current execution ID
+ logger_instance: Optional logger instance
+
+ Returns:
+ Cache statistics dictionary with creation results
+
+ Example:
+ >>> # After FilterPipeline has processed files
+ >>> cache_stats = FileManagementUtils.create_file_cache_entries(
+ ... source_files=all_discovered_files,
+ ... files_to_cache=final_filtered_files,
+ ... workflow_id="workflow-123",
+ ... execution_id="exec-456",
+ ... )
+ >>> print(f"Created {cache_stats['cache_created']} cache entries")
+ """
+ log = logger_instance or logger
+
+ if not files_to_cache:
+ log.debug("No files provided for cache creation")
+ return {"cache_created": 0, "cache_errors": 0, "processing_files": []}
+
+ log.debug(f"Creating cache entries for {len(files_to_cache)} files")
+
+ return ActiveFileManager.create_cache_entries(
+ source_files=source_files,
+ files_to_cache=files_to_cache,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ logger_instance=log,
+ )
+
+ @staticmethod
+ def extract_provider_uuids(hash_values_of_files: dict[str, Any]) -> list[str]:
+ """Extract provider file UUIDs from file hash data.
+
+ Args:
+ hash_values_of_files: Dictionary of file hash data
+
+ Returns:
+ List of provider file UUIDs
+ """
+ provider_uuids = []
+ for hash_data in hash_values_of_files.values():
+ if hasattr(hash_data, "provider_file_uuid") and hash_data.provider_file_uuid:
+ provider_uuids.append(hash_data.provider_file_uuid)
+ return provider_uuids
+
+ @staticmethod
+ def log_filtering_stats(
+ filtering_stats: dict[str, Any], logger_instance: LoggerProtocol | None = None
+ ) -> None:
+ """Log detailed file filtering statistics.
+
+ Args:
+ filtering_stats: Statistics from file filtering operations
+ logger_instance: Optional logger instance
+ """
+ log = logger_instance or logger
+
+ original_count = filtering_stats.get("original_count", 0)
+ filtered_count = filtering_stats.get("filtered_count", 0)
+
+ if original_count > 0:
+ log.info(
+ f"📊 File filtering results: {original_count} → {filtered_count} files"
+ )
+
+ cache_created = filtering_stats.get("cache_created", 0)
+ if cache_created > 0:
+ log.info(f"🔒 Created {cache_created} active_file cache entries")
+
+ cache_active = filtering_stats.get("cache_active", [])
+ db_active = filtering_stats.get("db_active", [])
+ if cache_active or db_active:
+ cache_count = len(cache_active)
+ db_count = len(db_active)
+ log.info(
+ f"⚡ Skipped {cache_count} cache-active + {db_count} db-active files"
+ )
+
+ @staticmethod
+ def process_files_with_active_filtering(
+ source_files: dict[str, Any],
+ workflow_id: str,
+ execution_id: str,
+ max_limit: int,
+ api_client: Any,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> tuple[dict[str, Any], int]:
+ """Complete file processing pipeline with active filtering and limit.
+
+ Processing order:
+ 1. Apply all filters (file history is already done, now cache + database)
+ 2. Take up to max_limit files from the filtered results
+ 3. Create cache entries ONLY for the final selected files
+
+ **IMPORTANT**: Use ONLY for ETL/TASK workflows in @workers/general/
+ Do NOT use for API deployments (@workers/api-deployment/) - they have their own logic.
+
+ Args:
+ source_files: Dictionary of source files (already filtered by file history)
+ workflow_id: Workflow ID
+ execution_id: Current execution ID
+ max_limit: Maximum number of files to process after all filtering
+ api_client: API client for database checks
+ logger_instance: Optional logger instance
+
+ Returns:
+ Tuple of (final_files, final_count)
+ """
+ log = logger_instance or logger
+
+ # Step 1: Filter out active files (no cache creation yet)
+ filter_result = FileManagementUtils.apply_active_file_filtering(
+ source_files=source_files,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ api_client=api_client,
+ logger_instance=log,
+ final_files_to_process=None, # No cache creation at this step
+ )
+
+ # Step 2: Apply limit to the filtered results (max files after all filtering)
+ limit_result = FileManagementUtils.apply_file_limit(
+ files=filter_result.filtered_files, max_limit=max_limit, logger_instance=log
+ )
+
+ # Step 3: Create cache entries ONLY for the final selected files
+ if limit_result.limited_files:
+ log.info(
+ f"Creating cache entries for {limit_result.final_count} final selected files"
+ )
+ # Use cache-only method for race condition prevention
+ FileManagementUtils.create_file_cache_entries(
+ source_files=source_files, # Need original for file_tracking_data
+ files_to_cache=limit_result.limited_files, # Create cache for these files only
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ logger_instance=log,
+ )
+
+ # Step 4: Log statistics
+ FileManagementUtils.log_filtering_stats(
+ filtering_stats=filter_result.filtering_stats, logger_instance=log
+ )
+
+ return limit_result.limited_files, limit_result.final_count
+
+ # IMPORTANT: Maximum file limit behavior
+ # The max_limit parameter specifies the maximum number of files to process
+ # AFTER all filtering has been applied. For example:
+ #
+ # Source: 10 files → File History: 7 files → Cache Filter: 5 files → DB Filter: 3 files
+ # If max_limit=4: Process 3 files (less than limit)
+ # If max_limit=2: Process 2 files (limited by max_limit)
+ #
+ # Example usage for different worker types:
+ #
+ # # ✅ ETL/TASK workflows (@workers/general/):
+ # final_files, count = FileManagementUtils.process_files_with_active_filtering(
+ # source_files=files, workflow_id=wf_id, execution_id=exec_id,
+ # max_limit=10, api_client=client
+ # )
+ #
+ # # ✅ API deployments (@workers/api-deployment/):
+ # final_files, count = FileManagementUtils.process_files_without_active_filtering(
+ # source_files=files, max_limit=10
+ # )
+ #
+ # # ✅ Cleanup (ONLY for ETL/TASK workflows - API deployments don't use cache):
+ # uuids = FileManagementUtils.extract_provider_uuids(hash_values_of_files)
+ # cleaned = FileManagementUtils.cleanup_active_file_cache(uuids, workflow_id)
+ #
+ # # Custom filtering only:
+ # filter_result = FileManagementUtils.apply_active_file_filtering(
+ # source_files=files, workflow_id=wf_id, execution_id=exec_id, api_client=client
+ # )
+ # if not filter_result.has_files():
+ # # Handle case where all files are active
+ #
+ # limit_result = FileManagementUtils.apply_file_limit(filter_result.filtered_files, 5)
+ # final_files = limit_result.limited_files
+
+ @staticmethod
+ def process_files_without_active_filtering(
+ source_files: dict[str, Any],
+ max_limit: int,
+ logger_instance: LoggerProtocol | None = None,
+ ) -> tuple[dict[str, Any], int]:
+ """Process files with only limit application, no active filtering.
+
+ **IMPORTANT**: Use for API workflows (@workers/api-deployment/) that don't need
+ duplicate processing prevention. API deployments handle concurrency differently
+ and should NOT use the file_active cache pattern.
+
+ Args:
+ source_files: Dictionary of source files
+ max_limit: Maximum number of files to process
+ logger_instance: Optional logger instance
+
+ Returns:
+ Tuple of (final_files, final_count)
+ """
+ log = logger_instance or logger
+
+ log.info(f"📋 Processing {len(source_files)} files without active filtering")
+
+ # Apply file limit only
+ limit_result = FileManagementUtils.apply_file_limit(
+ files=source_files, max_limit=max_limit, logger_instance=log
+ )
+
+ return limit_result.limited_files, limit_result.final_count
diff --git a/workers/shared/workflow/execution/orchestration_utils.py b/workers/shared/workflow/execution/orchestration_utils.py
new file mode 100644
index 000000000..e70930a1d
--- /dev/null
+++ b/workers/shared/workflow/execution/orchestration_utils.py
@@ -0,0 +1,378 @@
+"""Workflow Orchestration Utilities for Worker Tasks
+
+This module provides standardized workflow orchestration patterns,
+chord execution, batch processing, and task coordination utilities.
+"""
+
+import os
+from typing import Any
+
+from celery import chord
+
+from ...enums import FileDestinationType, PipelineType
+from ...enums.worker_enums import QueueName
+from ...infrastructure.logging import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WorkflowOrchestrationUtils:
+ """Centralized workflow orchestration patterns and utilities."""
+
+ @staticmethod
+ def create_chord_execution(
+ batch_tasks: list[Any],
+ callback_task_name: str,
+ callback_kwargs: dict[str, Any],
+ callback_queue: str,
+ app_instance: Any,
+ ) -> Any:
+ """Standardized chord creation and execution pattern.
+
+ Args:
+ batch_tasks: List of batch task signatures
+ callback_task_name: Name of callback task
+ callback_kwargs: Keyword arguments for callback
+ callback_queue: Queue name for callback task
+ app_instance: Celery app instance
+
+ Returns:
+ Chord result object or None if no batch tasks
+
+ Note:
+ This consolidates the identical chord creation pattern found in
+ api-deployment and general workers.
+
+ CRITICAL: Returns None for zero batch tasks, signaling to parent
+ that direct pipeline status updates should be handled instead.
+ """
+ try:
+ callback_signature = app_instance.signature(
+ callback_task_name,
+ kwargs=callback_kwargs,
+ queue=callback_queue,
+ )
+ # For zero files, skip chord entirely - parent should handle status updates directly
+ if not batch_tasks:
+ # Extract execution_id from callback kwargs for logging
+ execution_id = callback_kwargs.get("execution_id")
+ pipeline_id = callback_kwargs.get("pipeline_id")
+ logger.info(
+ f"[exec:{execution_id}] [pipeline:{pipeline_id}] Zero batch tasks detected - skipping chord execution "
+ f"(parent should handle pipeline status updates directly)"
+ )
+ return None # Signal to parent that no chord was created
+
+ # Normal chord execution for non-empty batch tasks
+ result = chord(batch_tasks)(callback_signature)
+
+ logger.info(
+ f"Chord execution started - "
+ f"batch_tasks={len(batch_tasks)}, "
+ f"callback={callback_task_name}, "
+ f"queue={callback_queue}"
+ )
+
+ return result
+
+ except Exception as e:
+ logger.error(f"Failed to create chord execution: {e}")
+ raise
+
+ @staticmethod
+ def determine_manual_review_routing(
+ files: dict[str, Any],
+ manual_review_config: dict[str, Any] | None = None,
+ default_destination: str = FileDestinationType.DESTINATION.value,
+ ) -> dict[str, str]:
+ """Determine manual review routing for files based on configuration.
+
+ Args:
+ files: Dictionary of files to route
+ manual_review_config: Manual review configuration
+ default_destination: Default destination if no manual review
+
+ Returns:
+ Dictionary mapping file keys to destinations
+
+ Note:
+ This consolidates the complex manual review decision logic found
+ across multiple workers.
+ """
+ routing = {}
+ manual_review_required = False
+
+ # Check if manual review is globally enabled
+ if manual_review_config:
+ manual_review_required = manual_review_config.get("enabled", False)
+
+ for file_key, file_data in files.items():
+ if manual_review_required:
+ # Additional per-file checks could go here
+ routing[file_key] = FileDestinationType.MANUALREVIEW.value
+ logger.debug(f"File {file_key} routed to manual review")
+ else:
+ routing[file_key] = default_destination
+ logger.debug(f"File {file_key} routed to {default_destination}")
+
+ if manual_review_required:
+ logger.info(f"Manual review routing: {len(files)} files routed for review")
+
+ return routing
+
+ @staticmethod
+ def create_batch_task_signatures(
+ batch_files: list[Any],
+ task_name: str,
+ base_kwargs: dict[str, Any],
+ queue_name: str,
+ app_instance: Any,
+ ) -> list[Any]:
+ """Create standardized batch task signatures.
+
+ Args:
+ batch_files: List of file batches
+ task_name: Name of task to execute
+ base_kwargs: Base keyword arguments for all tasks
+ queue_name: Queue name for task execution
+ app_instance: Celery app instance
+
+ Returns:
+ List of task signatures
+
+ Note:
+ This standardizes batch task signature creation across workers.
+ """
+ signatures = []
+
+ for batch_index, batch in enumerate(batch_files):
+ batch_kwargs = base_kwargs.copy()
+ batch_kwargs.update(
+ {
+ "batch_files": batch,
+ "batch_index": batch_index,
+ "total_batches": len(batch_files),
+ }
+ )
+
+ signature = app_instance.signature(
+ task_name, kwargs=batch_kwargs, queue=queue_name
+ )
+ signatures.append(signature)
+
+ logger.info(
+ f"Created {len(signatures)} batch task signatures for {task_name} "
+ f"on queue {queue_name}"
+ )
+
+ return signatures
+
+ @staticmethod
+ def calculate_batch_processing_metrics(
+ total_files: int, batch_size: int, processing_time_seconds: float | None = None
+ ) -> dict[str, int | float]:
+ """Calculate batch processing metrics for monitoring and optimization.
+
+ Args:
+ total_files: Total number of files processed
+ batch_size: Size of each batch
+ processing_time_seconds: Total processing time
+
+ Returns:
+ Dictionary of metrics
+
+ Note:
+ This provides consistent metrics calculation across orchestration.
+ """
+ num_batches = (total_files + batch_size - 1) // batch_size # Ceiling division
+ avg_files_per_batch = total_files / num_batches if num_batches > 0 else 0
+
+ metrics = {
+ "total_files": total_files,
+ "batch_size": batch_size,
+ "num_batches": num_batches,
+ "avg_files_per_batch": avg_files_per_batch,
+ }
+
+ if processing_time_seconds is not None:
+ metrics.update(
+ {
+ "processing_time_seconds": processing_time_seconds,
+ "avg_time_per_batch": processing_time_seconds / num_batches
+ if num_batches > 0
+ else 0,
+ "avg_time_per_file": processing_time_seconds / total_files
+ if total_files > 0
+ else 0,
+ }
+ )
+
+ return metrics
+
+ @staticmethod
+ def determine_callback_queue(
+ workflow_type: str, default_queue: str = "celery"
+ ) -> str:
+ """Determine appropriate callback queue based on workflow type.
+
+ Args:
+ workflow_type: Type of workflow being processed
+ default_queue: Default queue if no specific mapping
+
+ Returns:
+ Queue name for callback processing
+
+ Note:
+ This centralizes queue determination logic found across workers.
+ """
+ # Map workflow types to specific queues using enums
+ queue_mapping = {
+ PipelineType.API.value: QueueName.API_DEPLOYMENTS.value,
+ PipelineType.ETL.value: QueueName.GENERAL.value,
+ PipelineType.TASK.value: QueueName.GENERAL.value,
+ PipelineType.APP.value: QueueName.GENERAL.value,
+ }
+
+ # Check for environment-specific overrides
+ env_queue = os.getenv(f"CALLBACK_QUEUE_{workflow_type}")
+ if env_queue:
+ logger.info(
+ f"Using environment-specified queue for {workflow_type}: {env_queue}"
+ )
+ return env_queue
+
+ queue = queue_mapping.get(workflow_type.upper(), default_queue)
+ logger.debug(f"Determined callback queue for {workflow_type}: {queue}")
+
+ return queue
+
+ @staticmethod
+ def create_callback_signature_data(
+ execution_id: str,
+ workflow_id: str,
+ organization_id: str,
+ additional_context: dict[str, Any] | None = None,
+ ) -> dict[str, Any]:
+ """Create standardized callback signature data.
+
+ Args:
+ execution_id: Workflow execution ID
+ workflow_id: Workflow ID
+ organization_id: Organization ID
+ additional_context: Additional context data
+
+ Returns:
+ Dictionary of callback signature data
+
+ Note:
+ This standardizes callback signature creation across workers.
+ """
+ callback_data = {
+ "execution_id": execution_id,
+ "workflow_id": workflow_id,
+ "organization_id": organization_id,
+ "callback_metadata": {
+ "created_at": None, # Will be set by callback handler
+ "orchestrator": "WorkflowOrchestrationUtils",
+ },
+ }
+
+ if additional_context:
+ callback_data.update(additional_context)
+
+ return callback_data
+
+ @staticmethod
+ def validate_orchestration_parameters(
+ execution_id: str,
+ workflow_id: str,
+ organization_id: str,
+ files: dict[str, Any] | None = None,
+ ) -> None:
+ """Validate common orchestration parameters.
+
+ Args:
+ execution_id: Workflow execution ID
+ workflow_id: Workflow ID
+ organization_id: Organization ID
+ files: Optional files dictionary
+
+ Raises:
+ ValueError: If validation fails
+
+ Note:
+ This provides consistent parameter validation across orchestration.
+ """
+ if not execution_id:
+ raise ValueError("execution_id is required for workflow orchestration")
+
+ if not workflow_id:
+ raise ValueError("workflow_id is required for workflow orchestration")
+
+ if not organization_id:
+ raise ValueError("organization_id is required for workflow orchestration")
+
+ if files is not None and not isinstance(files, dict):
+ raise ValueError("files must be a dictionary when provided")
+
+ logger.debug(
+ f"Orchestration parameters validated - "
+ f"exec_id={execution_id}, workflow_id={workflow_id}, org_id={organization_id}"
+ )
+
+
+class WorkflowOrchestrationMixin:
+ """Mixin class to add orchestration utilities to worker tasks."""
+
+ def create_chord(
+ self, batch_tasks, callback_task_name, callback_kwargs, callback_queue
+ ):
+ """Create chord using standardized pattern."""
+ # Get app instance from task context
+ app_instance = getattr(self, "app", None)
+ if not app_instance:
+ raise RuntimeError("Celery app instance not available in task context")
+
+ return WorkflowOrchestrationUtils.create_chord_execution(
+ batch_tasks, callback_task_name, callback_kwargs, callback_queue, app_instance
+ )
+
+ def determine_manual_review_routing(self, files, manual_review_config=None):
+ """Determine manual review routing using standardized logic."""
+ return WorkflowOrchestrationUtils.determine_manual_review_routing(
+ files, manual_review_config
+ )
+
+ def create_batch_signatures(self, batch_files, task_name, base_kwargs, queue_name):
+ """Create batch task signatures using standardized pattern."""
+ app_instance = getattr(self, "app", None)
+ if not app_instance:
+ raise RuntimeError("Celery app instance not available in task context")
+
+ return WorkflowOrchestrationUtils.create_batch_task_signatures(
+ batch_files, task_name, base_kwargs, queue_name, app_instance
+ )
+
+ def calculate_metrics(self, total_files, batch_size, processing_time=None):
+ """Calculate processing metrics using standardized calculation."""
+ return WorkflowOrchestrationUtils.calculate_batch_processing_metrics(
+ total_files, batch_size, processing_time
+ )
+
+ def determine_callback_queue(self, workflow_type, default_queue="celery"):
+ """Determine callback queue using standardized logic."""
+ return WorkflowOrchestrationUtils.determine_callback_queue(
+ workflow_type, default_queue
+ )
+
+ def create_callback_data(self, execution_id, workflow_id, organization_id, **kwargs):
+ """Create callback signature data using standardized format."""
+ return WorkflowOrchestrationUtils.create_callback_signature_data(
+ execution_id, workflow_id, organization_id, kwargs
+ )
+
+ def validate_parameters(self, execution_id, workflow_id, organization_id, files=None):
+ """Validate orchestration parameters using standardized validation."""
+ WorkflowOrchestrationUtils.validate_orchestration_parameters(
+ execution_id, workflow_id, organization_id, files
+ )
diff --git a/workers/shared/workflow/execution/service.py b/workers/shared/workflow/execution/service.py
new file mode 100644
index 000000000..f2f93e89f
--- /dev/null
+++ b/workers/shared/workflow/execution/service.py
@@ -0,0 +1,1410 @@
+"""WorkflowExecutionService Integration for Workers
+
+This module provides direct integration with the WorkflowExecutionService
+from unstract/workflow-execution, enabling workers to execute workflows
+directly using the ToolSandbox and runner services.
+"""
+
+import time
+from typing import Any
+
+import magic
+from shared.enums.file_types import AllowedFileTypes
+from shared.exceptions.execution_exceptions import (
+ NotFoundDestinationConfiguration,
+ NotFoundSourceConfiguration,
+)
+from shared.exceptions.file_exceptions import EmptyFileError, UnsupportedMimeTypeError
+from shared.models.file_processing import FileProcessingContext
+
+# Import shared dataclasses for type safety and consistency
+from unstract.core.data_models import (
+ # DestinationConfig, # remove once verified
+ FileHashData,
+ FileOperationConstants,
+ WorkflowDefinitionResponseData,
+ WorkflowEndpointConfigData,
+)
+
+# Import file execution tracking for proper recovery mechanism
+from unstract.core.file_execution_tracker import (
+ FileExecutionData,
+ FileExecutionStage,
+ FileExecutionStageData,
+ FileExecutionStageStatus,
+ FileExecutionStatusTracker,
+)
+from unstract.core.tool_execution_status import (
+ ToolExecutionData,
+ ToolExecutionTracker,
+)
+from unstract.core.worker_models import (
+ FinalOutputResult,
+ WorkflowExecutionMetadata,
+ WorkflowExecutionResult,
+)
+from unstract.workflow_execution.dto import ToolInstance, WorkflowDto
+from unstract.workflow_execution.execution_file_handler import ExecutionFileHandler
+
+# Direct imports now that dependencies are properly configured
+from unstract.workflow_execution.workflow_execution import WorkflowExecutionService
+
+from ...api.internal_client import InternalAPIClient
+from ...infrastructure.logging import WorkerLogger
+from ..destination_connector import (
+ DestinationConfig,
+ WorkerDestinationConnector,
+)
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+class WorkerWorkflowExecutionService:
+ """Worker-compatible workflow execution service."""
+
+ READ_CHUNK_SIZE = FileOperationConstants.READ_CHUNK_SIZE
+
+ def __init__(self, api_client: InternalAPIClient = None):
+ self.api_client = api_client
+ self.logger = logger
+ self._last_execution_error = None
+
+ def execute_workflow_for_file(
+ self,
+ file_processing_context: FileProcessingContext,
+ organization_id: str,
+ workflow_id: str,
+ execution_id: str,
+ is_api: bool = False,
+ use_file_history: bool = False,
+ workflow_file_execution_id: str = None,
+ workflow_logger=None,
+ ) -> WorkflowExecutionResult:
+ """Execute workflow with clean, linear flow and comprehensive result propagation."""
+ start_time = time.time()
+ file_hash = file_processing_context.file_hash
+ file_name = file_hash.file_name
+
+ # Initialize result tracking variables
+ workflow_success = False
+ execution_error = None
+ tool_instances_data = []
+ context_setup_time = start_time
+ destination_start_time = start_time
+ destination_end_time = start_time
+
+ try:
+ logger.info(f"Executing workflow {workflow_id} for file {file_name}")
+
+ # Step 0: Check if file execution is already completed (resume capability)
+ if workflow_file_execution_id:
+ try:
+ tracker = FileExecutionStatusTracker()
+ existing_data = tracker.get_data(
+ execution_id, workflow_file_execution_id
+ )
+
+ if (
+ existing_data
+ and existing_data.stage_status.stage
+ == FileExecutionStage.COMPLETED
+ ):
+ if (
+ existing_data.stage_status.status
+ == FileExecutionStageStatus.SUCCESS
+ ):
+ logger.info(
+ f"File {file_name} already completed successfully, skipping processing"
+ )
+ # Return existing successful result
+ return WorkflowExecutionResult(
+ file_name=file_name,
+ file_execution_id=workflow_file_execution_id,
+ success=True,
+ error=None,
+ result="Already completed",
+ metadata=WorkflowExecutionMetadata(
+ total_execution_time=0,
+ workflow_success=True,
+ execution_error=None,
+ tool_instances_data=[],
+ destination_result=FinalOutputResult(
+ output="Already completed",
+ metadata={},
+ error=None,
+ processed=True,
+ ),
+ ),
+ execution_time=0,
+ )
+ except Exception as tracker_error:
+ logger.warning(
+ f"Failed to check execution tracker for {file_name}: {tracker_error}"
+ )
+ # Continue with normal execution if tracker check fails
+
+ # Step 1: Setup & Validation
+ if not self.api_client:
+ raise ValueError("API client required for workflow execution")
+
+ execution_context, tool_instances_data = self._get_workflow_execution_context(
+ execution_id, workflow_id, organization_id
+ )
+
+ workflow_context = self._get_workflow(workflow_id, organization_id)
+
+ context_setup_time = time.time()
+ logger.info(
+ f"TIMING: Workflow context setup COMPLETED for {file_name} at {context_setup_time:.6f} (took {context_setup_time - start_time:.3f}s)"
+ )
+
+ if not tool_instances_data:
+ raise ValueError(f"No tool instances found for workflow {workflow_id}")
+
+ # Initialize file execution tracker with complete metadata
+ if workflow_file_execution_id:
+ self._initialize_file_execution_tracker(
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ organization_id=organization_id,
+ file_hash=file_hash,
+ )
+ pipeline_id = execution_context.get("execution", {}).get("pipeline_id")
+ # Step 2: Execute Workflow
+ execution_service = self._create_worker_execution_service(
+ organization_id=organization_id,
+ workflow_id=workflow_id,
+ tool_instances_data=tool_instances_data,
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ is_api=is_api,
+ workflow_logger=workflow_logger,
+ pipeline_id=pipeline_id,
+ )
+
+ workflow_success = self._execute_workflow_with_service(
+ execution_service=execution_service,
+ file_processing_context=file_processing_context,
+ file_name=file_name,
+ workflow_file_execution_id=workflow_file_execution_id,
+ execution_id=execution_id,
+ workflow_id=workflow_id,
+ )
+
+ if not workflow_success:
+ execution_error = (
+ self._last_execution_error or "Workflow execution failed"
+ )
+ except Exception as e:
+ logger.error(f"Workflow setup failed for {file_name}: {e}", exc_info=True)
+ execution_error = str(e)
+ workflow_success = False
+
+ # Step 3: Process Output - Let destination handle EVERYTHING
+ # This includes:
+ # - Extracting tool results via get_tool_execution_result_from_execution_context
+ # - Caching API results
+ # - Writing to filesystem/database
+ # - Routing to manual review
+ # - Creating file history
+ # Track finalization stage before destination processing
+ if workflow_file_execution_id:
+ try:
+ tracker = FileExecutionStatusTracker()
+ tracker.update_stage_status(
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ stage_status=FileExecutionStageData(
+ stage=FileExecutionStage.FINALIZATION,
+ status=FileExecutionStageStatus.IN_PROGRESS,
+ ),
+ )
+ logger.info(f"Tracked finalization stage for {file_name}")
+ except Exception as tracker_error:
+ logger.warning(f"Failed to track finalization stage: {tracker_error}")
+
+ destination_result = None
+ destination_start_time = time.time()
+ logger.info(
+ f"TIMING: Destination processing START for {file_name} at {destination_start_time:.6f}"
+ )
+
+ try:
+ destination_result = self._handle_destination_processing(
+ file_processing_context=file_processing_context,
+ workflow=workflow_context,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ is_success=workflow_success,
+ workflow_file_execution_id=workflow_file_execution_id,
+ organization_id=organization_id,
+ workflow_logger=workflow_logger,
+ use_file_history=use_file_history,
+ is_api=is_api,
+ execution_error=execution_error,
+ )
+ logger.info(f"Destination processing completed for {file_name}")
+
+ except Exception as dest_error:
+ logger.error(
+ f"Destination processing failed for {file_name}: {dest_error}",
+ exc_info=True,
+ )
+ destination_result = FinalOutputResult(
+ output=None, metadata=None, error=str(dest_error)
+ )
+ finally:
+ destination_end_time = time.time()
+ logger.info(
+ f"TIMING: Destination processing END for {file_name} at {destination_end_time:.6f} (took {destination_end_time - destination_start_time:.3f}s)"
+ )
+
+ # Step 4: Build Final Result
+ final_time = time.time()
+ execution_time = final_time - start_time
+
+ # Build result first
+ result = self._build_final_result(
+ workflow_file_execution_id=workflow_file_execution_id,
+ file_name=file_name,
+ file_hash=file_hash,
+ workflow_success=workflow_success,
+ destination_result=destination_result,
+ execution_error=execution_error,
+ execution_time=execution_time,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ tool_count=len(tool_instances_data),
+ )
+
+ # FINAL STEP: Update METADATA.json with correct execution timing
+ # This must be done AFTER all tool execution and destination processing
+ # to ensure our timing is not overwritten by tool metadata updates
+ try:
+ file_handler = ExecutionFileHandler(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=organization_id,
+ file_execution_id=workflow_file_execution_id,
+ )
+ logger.info(
+ f"TIMING: Applying FINAL metadata update with execution time: {execution_time:.3f}s"
+ )
+ file_handler.update_execution_timing(execution_time)
+
+ except Exception as timing_error:
+ logger.warning(
+ f"Failed to update execution timing in metadata: {timing_error}"
+ )
+ # Continue - timing update failure shouldn't stop execution
+
+ # Track final completion stage
+ if workflow_file_execution_id:
+ try:
+ tracker = FileExecutionStatusTracker()
+ overall_success = workflow_success and (
+ destination_result and not destination_result.error
+ )
+
+ if overall_success:
+ tracker.update_stage_status(
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ stage_status=FileExecutionStageData(
+ stage=FileExecutionStage.COMPLETED,
+ status=FileExecutionStageStatus.SUCCESS,
+ ),
+ )
+ logger.info(f"Tracked successful completion for {file_name}")
+ else:
+ # Track failure on finalization stage
+ error_msg = execution_error or (
+ destination_result.error
+ if destination_result
+ else "Unknown error"
+ )
+ tracker.update_stage_status(
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ stage_status=FileExecutionStageData(
+ stage=FileExecutionStage.FINALIZATION,
+ status=FileExecutionStageStatus.FAILED,
+ error=error_msg,
+ ),
+ )
+ logger.info(f"Tracked failed execution for {file_name}: {error_msg}")
+
+ # Clean up tool execution tracker (even on failure)
+ self._cleanup_tool_execution_tracker(
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ )
+
+ # Clean up file execution tracker (log data then delete)
+ self._cleanup_file_execution_tracker(
+ execution_id=execution_id,
+ file_execution_id=workflow_file_execution_id,
+ )
+
+ except Exception as tracker_error:
+ logger.warning(f"Failed to track final completion stage: {tracker_error}")
+
+ return result
+
+ def _initialize_file_execution_tracker(
+ self,
+ execution_id: str,
+ file_execution_id: str,
+ organization_id: str,
+ file_hash: FileHashData,
+ ) -> None:
+ """Initialize file execution tracker with complete metadata.
+
+ Matches Django backend initialization pattern with full FileExecutionData.
+ """
+ try:
+ tracker = FileExecutionStatusTracker()
+
+ # Check if tracker already exists (resume scenario)
+ if tracker.exists(execution_id, file_execution_id):
+ logger.info(
+ f"File execution tracker already exists for execution_id: {execution_id}, "
+ f"file_execution_id: {file_execution_id}"
+ )
+ return
+
+ # Create initial stage data
+ file_execution_stage_data = FileExecutionStageData(
+ stage=FileExecutionStage.INITIALIZATION,
+ status=FileExecutionStageStatus.IN_PROGRESS,
+ )
+
+ # Create complete FileExecutionData with metadata
+ file_execution_data = FileExecutionData(
+ execution_id=str(execution_id),
+ file_execution_id=str(file_execution_id),
+ organization_id=str(organization_id),
+ stage_status=file_execution_stage_data,
+ status_history=[],
+ file_hash=file_hash.to_serialized_json(), # Match Django backend serialization format
+ )
+
+ # Initialize tracker with complete data
+ tracker.set_data(file_execution_data)
+ logger.info(
+ f"Initialized file execution tracker for execution_id: {execution_id}, "
+ f"file_execution_id: {file_execution_id}"
+ )
+
+ except Exception as e:
+ # Non-critical - log and continue
+ logger.warning(
+ f"Failed to initialize file execution tracker for {execution_id}/{file_execution_id}: {e}"
+ )
+
+ def _cleanup_file_execution_tracker(
+ self,
+ execution_id: str,
+ file_execution_id: str,
+ ) -> None:
+ """Clean up file execution tracker after processing completes.
+
+ Logs file execution data for debugging purposes before cleanup.
+ """
+ try:
+ tracker = FileExecutionStatusTracker()
+
+ # Get current file execution data for logging before cleanup
+ file_execution_data = tracker.get_data(execution_id, file_execution_id)
+
+ if file_execution_data:
+ # Log file execution data for debugging purposes
+ logger.info(
+ f"File execution tracker data before cleanup - "
+ f"execution_id: {execution_id}, file_execution_id: {file_execution_id}, "
+ f"stage: {file_execution_data.stage_status.stage.value}, "
+ f"status: {file_execution_data.stage_status.status.value}, "
+ f"organization_id: {file_execution_data.organization_id}, "
+ f"error: {file_execution_data.stage_status.error or 'None'}"
+ )
+
+ # Actually delete file execution tracker data from Redis
+ tracker.delete_data(execution_id, file_execution_id)
+ logger.info(
+ f"Deleted file execution tracker for execution_id: {execution_id}, "
+ f"file_execution_id: {file_execution_id}"
+ )
+ else:
+ logger.debug(
+ f"No file execution tracker data found for execution_id: {execution_id}, "
+ f"file_execution_id: {file_execution_id}"
+ )
+
+ except Exception as e:
+ # Non-critical - log and continue
+ logger.warning(
+ f"Failed to cleanup file execution tracker for {execution_id}/{file_execution_id}: {e}"
+ )
+
+ def _cleanup_tool_execution_tracker(
+ self,
+ execution_id: str,
+ file_execution_id: str,
+ ) -> None:
+ """Clean up tool execution tracker after file processing completes.
+
+ Matches Django backend cleanup pattern to prevent Redis memory leaks.
+ """
+ try:
+ tracker = ToolExecutionTracker()
+ tool_execution_data = ToolExecutionData(
+ execution_id=execution_id,
+ file_execution_id=file_execution_id,
+ )
+ tracker.delete_status(tool_execution_data=tool_execution_data)
+ logger.info(
+ f"Deleted tool execution tracker for execution_id: {execution_id}, "
+ f"file_execution_id: {file_execution_id}"
+ )
+ except Exception as e:
+ # Non-critical - log and continue
+ logger.warning(
+ f"Failed to cleanup tool execution tracker for {execution_id}/{file_execution_id}: {e}"
+ )
+
+ def _get_workflow_execution_context(
+ self, execution_id: str, workflow_id: str, organization_id: str
+ ) -> tuple[dict, list]:
+ """Get workflow execution context and tool instances."""
+ execution_response = self.api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(
+ f"Failed to get workflow execution: {execution_response.error}"
+ )
+
+ tool_instances_response = self.api_client.get_tool_instances_by_workflow(
+ workflow_id=workflow_id,
+ organization_id=organization_id,
+ )
+
+ return execution_response.data, tool_instances_response.tool_instances
+
+ def _get_workflow(
+ self, workflow_id: str, organization_id: str
+ ) -> WorkflowDefinitionResponseData:
+ """Get workflow definition including workflow_type."""
+ return self.api_client.get_workflow(workflow_id, organization_id)
+
+ def _build_final_result(
+ self,
+ workflow_file_execution_id: str,
+ file_name: str,
+ file_hash: FileHashData,
+ workflow_success: bool,
+ destination_result: FinalOutputResult,
+ execution_error: str,
+ execution_time: float,
+ workflow_id: str,
+ execution_id: str,
+ tool_count: int,
+ ) -> WorkflowExecutionResult:
+ """Build standardized result using DTO."""
+ # Determine overall success
+ overall_success = workflow_success and (
+ destination_result and not destination_result.error
+ )
+
+ # Consolidate errors
+ final_error = None
+ if execution_error and destination_result and destination_result.error:
+ final_error = (
+ f"Execution: {execution_error}; Destination: {destination_result.error}"
+ )
+ elif execution_error:
+ final_error = execution_error
+ elif destination_result and destination_result.error:
+ final_error = destination_result.error
+
+ # Build metadata
+ metadata = WorkflowExecutionMetadata(
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ execution_time=execution_time,
+ tool_count=tool_count,
+ workflow_executed=workflow_success,
+ destination_processed=destination_result is not None,
+ destination_error=destination_result.error if destination_result else None,
+ )
+
+ # Return structured result
+ return WorkflowExecutionResult(
+ file_execution_id=workflow_file_execution_id,
+ file_name=file_name,
+ success=overall_success,
+ error=final_error,
+ result=destination_result.output if destination_result else None,
+ source_hash=file_hash.file_hash,
+ metadata=metadata,
+ destination_output=destination_result.output if destination_result else None,
+ )
+
+ def _create_execution_result(
+ self,
+ workflow_file_execution_id: str,
+ file_name: str,
+ file_data: dict[str, Any],
+ success: bool,
+ result: Any = None,
+ error: str = None,
+ metadata: dict[str, Any] = None,
+ ) -> dict[str, Any]:
+ """Create standardized execution result structure for both success and error cases."""
+ return {
+ "file_execution_id": workflow_file_execution_id,
+ "file": file_name,
+ "result": result,
+ "success": success,
+ "error": error,
+ "metadata": metadata,
+ "source_hash": file_data.get("file_hash"),
+ }
+
+ def _create_worker_execution_service(
+ self,
+ organization_id: str,
+ workflow_id: str,
+ tool_instances_data: list[dict[str, Any]],
+ execution_id: str,
+ file_execution_id: str,
+ is_api: bool = False,
+ workflow_logger: Any | None = None,
+ pipeline_id: str | None = None,
+ ) -> WorkflowExecutionService:
+ """Create WorkflowExecutionService following backend pattern."""
+ # Convert tool instances data to ToolInstance DTOs
+ tool_instances = []
+ for tool_data in tool_instances_data:
+ try:
+ # Get tool information from the backend via API
+ # This is necessary because workers can't access Django models for Prompt Studio tools
+ tool_info = None
+ tool_id = tool_data.get("tool_id")
+ if tool_id and self.api_client:
+ try:
+ tool_info_response = self.api_client.get_tool_by_id(tool_id)
+ tool_info = tool_info_response.get("tool", {})
+ logger.info(f"Successfully fetched tool info for {tool_id}")
+ except Exception as tool_fetch_error:
+ logger.warning(
+ f"Could not fetch tool info for {tool_id}: {tool_fetch_error}"
+ )
+
+ # Use tool info if available, otherwise fail execution
+ if (
+ tool_info
+ and tool_info.get("properties")
+ and tool_info.get("image_name")
+ ):
+ properties = tool_info.get("properties", {})
+ image_name = tool_info.get("image_name")
+ image_tag = tool_info.get("image_tag", "latest")
+ logger.info(f"Successfully loaded tool properties for {tool_id}")
+ else:
+ # If we can't get valid tool data, fail the execution
+ error_msg = f"Cannot execute workflow: Invalid or missing tool data for {tool_id}. Tool registry may be unavailable or tool not found."
+ logger.error(error_msg)
+ raise ValueError(error_msg)
+
+ tool_instance = ToolInstance(
+ id=tool_data.get("id"),
+ tool_id=tool_data.get("tool_id"),
+ step=tool_data.get("step", 1),
+ workflow=workflow_id,
+ metadata=tool_data.get("metadata", {}),
+ properties=properties,
+ image_name=image_name,
+ image_tag=image_tag,
+ )
+ tool_instances.append(tool_instance)
+ except Exception as tool_error:
+ logger.warning(
+ f"Failed to create tool instance from data {tool_data}: {tool_error}"
+ )
+ continue
+
+ if not tool_instances:
+ raise ValueError("Failed to create any valid tool instances")
+
+ # Create WorkflowDto
+ workflow_dto = WorkflowDto(id=workflow_id)
+
+ # Get platform service API key from backend API
+ platform_service_api_key = self._get_platform_service_api_key(organization_id)
+
+ # Initialize WorkflowExecutionService
+ execution_service = WorkflowExecutionService(
+ organization_id=organization_id,
+ workflow_id=workflow_id,
+ workflow=workflow_dto,
+ tool_instances=tool_instances,
+ platform_service_api_key=platform_service_api_key,
+ ignore_processed_entities=False,
+ file_execution_id=file_execution_id,
+ )
+
+ # Set up messaging channel for logs
+ # Get messaging channel from workflow_logger if available
+ # This ensures consistency with WorkflowLogger which uses:
+ # log_events_id (session) for UI workflows or pipeline_id for scheduled/API
+ if workflow_logger and hasattr(workflow_logger, "messaging_channel"):
+ messaging_channel = workflow_logger.messaging_channel
+ logger.info(
+ f"Using workflow_logger messaging channel: {messaging_channel} "
+ f"for execution {execution_id}, file {file_execution_id}"
+ )
+ else:
+ # Fallback: use execution_id if no workflow_logger available
+ # This shouldn't normally happen but provides safety
+ messaging_channel = str(pipeline_id) if pipeline_id else str(execution_id)
+ logger.warning(
+ f"No workflow_logger available, using pipeline_id or execution_id as messaging channel: {messaging_channel} "
+ f"for file {file_execution_id}"
+ )
+
+ execution_service.set_messaging_channel(messaging_channel)
+
+ return execution_service
+
+ def _execute_workflow_with_service(
+ self,
+ execution_service: WorkflowExecutionService,
+ file_processing_context: FileProcessingContext,
+ file_name: str,
+ workflow_file_execution_id: str,
+ execution_id: str,
+ workflow_id: str,
+ ) -> bool:
+ """Execute workflow using WorkflowExecutionService following backend pattern."""
+ try:
+ # Step 1: Compile workflow
+ if not self._compile_workflow(execution_service, execution_id, file_name):
+ return False
+
+ # Step 2: Prepare input file and metadata
+ self._prepare_workflow_input_file(
+ execution_service=execution_service,
+ file_processing_context=file_processing_context,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ workflow_file_execution_id=workflow_file_execution_id,
+ )
+
+ # Step 3: Build and execute workflow
+ self._build_and_execute_workflow(execution_service, file_name)
+
+ return True
+
+ except Exception as e:
+ logger.error(
+ f"Tool execution failed for file {file_name}: {str(e)}", exc_info=True
+ )
+ self._last_execution_error = str(e)
+ return False
+
+ def _compile_workflow(
+ self,
+ execution_service: WorkflowExecutionService,
+ execution_id: str,
+ file_name: str,
+ ) -> bool:
+ """Compile the workflow and check for errors."""
+ compilation_result = execution_service.compile_workflow(execution_id)
+ if not compilation_result.get("success"):
+ error_msg = f"Workflow compilation failed: {compilation_result.get('problems', ['Unknown error'])}"
+ logger.error(error_msg)
+ self._last_execution_error = error_msg
+ return False
+
+ logger.info(f"Workflow compiled successfully for file {file_name}")
+ return True
+
+ def _prepare_workflow_input_file(
+ self,
+ execution_service: WorkflowExecutionService,
+ file_processing_context: FileProcessingContext,
+ workflow_id: str,
+ execution_id: str,
+ workflow_file_execution_id: str,
+ ) -> str:
+ """Prepare input file for workflow execution and return computed hash."""
+ file_handler = execution_service.file_handler
+
+ try:
+ # Get file information from file_data parameter
+ file_path = file_processing_context.file_hash.file_path
+ source_connection_type = (
+ file_processing_context.file_hash.source_connection_type
+ )
+ connector_metadata = file_processing_context.file_hash.connector_metadata
+ file_data = file_processing_context.file_data
+ # Get source configuration
+ source_config = self._get_source_config(workflow_id, execution_id)
+ source_connector_id, source_config_connector_settings = (
+ self._extract_source_connector_details(source_config)
+ )
+
+ # Get target paths
+ infile_path = file_handler.infile
+ source_file_path = file_handler.source_file
+
+ if not self._validate_file_paths(infile_path, source_file_path, file_path):
+ raise ValueError(
+ f"Missing required file paths: infile_path={infile_path}, "
+ f"source_file_path={source_file_path}, file_path={file_path}"
+ )
+
+ logger.info(f"Copying source file {file_path} to execution directory")
+
+ # Determine connection type and copy file
+ connection_type = self._determine_connection_type(source_connection_type)
+
+ if connection_type.is_api:
+ computed_hash = self._copy_api_file(
+ file_path=file_path,
+ infile_path=infile_path,
+ source_file_path=source_file_path,
+ file_processing_context=file_processing_context,
+ )
+
+ else:
+ computed_hash = self._copy_filesystem_file(
+ file_path=file_path,
+ infile_path=infile_path,
+ source_file_path=source_file_path,
+ file_processing_context=file_processing_context,
+ source_connector_id=source_connector_id,
+ source_config_connector_settings=source_config_connector_settings,
+ connector_metadata=connector_metadata,
+ )
+
+ # Create initial METADATA.json file
+ # Extract tag names from workflow execution context
+ tag_names = []
+ workflow_execution = file_processing_context.workflow_execution
+ if workflow_execution and workflow_execution.get("tags"):
+ tag_names = [tag["name"] for tag in workflow_execution["tags"]]
+
+ file_handler.add_metadata_to_volume(
+ input_file_path=file_path,
+ file_execution_id=workflow_file_execution_id,
+ source_hash=computed_hash,
+ tags=tag_names, # Pass actual tag names from execution
+ llm_profile_id=file_data.llm_profile_id,
+ custom_data=file_data.custom_data,
+ )
+ logger.info(f"Initial metadata file created for {file_path}")
+
+ return computed_hash
+
+ except Exception as file_prep_error:
+ logger.error(f"Failed to prepare input file and metadata: {file_prep_error}")
+ raise file_prep_error
+
+ def _build_and_execute_workflow(
+ self, execution_service: WorkflowExecutionService, file_name: str
+ ) -> None:
+ """Build and execute the workflow."""
+ # Build workflow
+ execution_service.build_workflow()
+ logger.info(f"Workflow built successfully for file {file_name}")
+
+ # Execute workflow
+ from unstract.workflow_execution.enums import ExecutionType
+
+ execution_service.execute_workflow(ExecutionType.COMPLETE)
+ logger.info(f"Workflow executed successfully for file {file_name}")
+
+ def _extract_source_connector_details(
+ self, source_config: dict[str, Any] | None
+ ) -> tuple[str | None, dict[str, Any]]:
+ """Extract source connector ID and settings from config."""
+ if source_config:
+ source_connector_id = source_config.get("connector_id")
+ source_config_connector_settings = source_config.get("connector_settings", {})
+ logger.info(f"Retrieved source config - connector_id: {source_connector_id}")
+ return source_connector_id, source_config_connector_settings
+ return None, {}
+
+ def _validate_file_paths(
+ self, infile_path: str | None, source_file_path: str | None, file_path: str | None
+ ) -> bool:
+ """Validate that all required file paths are present."""
+ return bool(infile_path and source_file_path and file_path)
+
+ def _determine_connection_type(self, source_connection_type: str):
+ """Determine the connection type from string."""
+ from unstract.connectors import ConnectionType
+
+ try:
+ return ConnectionType.from_string(source_connection_type)
+ except ValueError:
+ logger.warning(
+ f"Invalid source_connection_type: {source_connection_type}, defaulting to FILESYSTEM"
+ )
+ return ConnectionType.FILESYSTEM
+
+ def _copy_api_file(
+ self,
+ file_path: str,
+ infile_path: str,
+ source_file_path: str,
+ file_processing_context: FileProcessingContext,
+ ) -> str:
+ """Copy file from API storage to workflow execution directory using chunked reading."""
+ import hashlib
+
+ from unstract.filesystem import FileStorageType, FileSystem
+
+ logger.info(f"Handling API file copy from {file_path} to execution directory")
+
+ # Get file systems
+ api_file_system = FileSystem(FileStorageType.API_EXECUTION)
+ api_file_storage = api_file_system.get_file_storage()
+
+ workflow_file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ workflow_file_storage = workflow_file_system.get_file_storage()
+
+ # Copy file in chunks
+ file_content_hash = hashlib.sha256()
+ total_bytes_copied = 0
+ seek_position = 0 # Track position for sequential reads
+
+ logger.info(f"Starting chunked file copy from API storage for {file_path}")
+
+ # Read and write in chunks
+ while chunk := api_file_storage.read(
+ path=file_path,
+ mode="rb",
+ seek_position=seek_position,
+ length=self.READ_CHUNK_SIZE,
+ ):
+ file_content_hash.update(chunk)
+ total_bytes_copied += len(chunk)
+ seek_position += len(chunk)
+
+ # Write chunk to both INFILE and SOURCE
+ workflow_file_storage.write(path=infile_path, mode="ab", data=chunk)
+ workflow_file_storage.write(path=source_file_path, mode="ab", data=chunk)
+
+ # Handle empty files - raise exception instead of creating placeholders
+ if total_bytes_copied == 0:
+ raise EmptyFileError(file_path)
+ else:
+ computed_hash = file_content_hash.hexdigest()
+ logger.info(
+ f"Successfully copied {total_bytes_copied} bytes from API storage with hash: {computed_hash}"
+ )
+
+ # Store computed hash in file_data for file history
+ file_processing_context.file_hash.file_hash = computed_hash
+ return computed_hash
+
+ def _copy_filesystem_file(
+ self,
+ file_path: str,
+ infile_path: str,
+ source_file_path: str,
+ file_processing_context: FileProcessingContext,
+ source_connector_id: str | None,
+ source_config_connector_settings: dict[str, Any],
+ connector_metadata: dict[str, Any],
+ ) -> str:
+ """Copy file from filesystem connector to workflow execution directory."""
+ import hashlib
+
+ from unstract.connectors.constants import Common
+ from unstract.connectors.filesystems import connectors
+ from unstract.filesystem import FileStorageType, FileSystem
+
+ # Get workflow file storage
+ workflow_file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ workflow_file_storage = workflow_file_system.get_file_storage()
+
+ # Determine which connector to use
+ connector_id_to_use, connector_settings_to_use = self._resolve_connector_config(
+ source_connector_id=source_connector_id,
+ source_config_connector_settings=source_config_connector_settings,
+ connector_metadata=connector_metadata,
+ file_processing_context=file_processing_context,
+ )
+
+ if not connector_id_to_use:
+ available_connectors = list(connectors.keys())
+ raise ValueError(
+ f"No connector_id provided for filesystem connection type. "
+ f"Available connectors: {available_connectors}"
+ )
+
+ if connector_id_to_use not in connectors:
+ available_connectors = list(connectors.keys())
+ raise ValueError(
+ f"Connector not found in registry: {connector_id_to_use}. "
+ f"Available connectors: {available_connectors}"
+ )
+
+ logger.info(f"Using connector: {connector_id_to_use}")
+
+ # Get source filesystem
+ connector_class = connectors[connector_id_to_use][Common.METADATA][
+ Common.CONNECTOR
+ ]
+ source_connector = connector_class(connector_settings_to_use)
+ source_fs = source_connector.get_fsspec_fs()
+
+ # Copy file in chunks
+ file_content_hash = hashlib.sha256()
+ total_bytes_copied = 0
+ first_chunk = True
+
+ logger.info(f"Starting chunked file copy from {file_path} to execution directory")
+
+ with source_fs.open(file_path, "rb") as source_file:
+ while chunk := source_file.read(self.READ_CHUNK_SIZE):
+ # MIME type detection and validation on first chunk
+ if first_chunk:
+ mime_type = magic.from_buffer(chunk, mime=True)
+ logger.info(f"Detected MIME type: {mime_type} for file {file_path}")
+
+ if not AllowedFileTypes.is_allowed(mime_type):
+ raise UnsupportedMimeTypeError(
+ f"Unsupported MIME type '{mime_type}' for file '{file_path}'"
+ )
+ first_chunk = False
+
+ file_content_hash.update(chunk)
+ total_bytes_copied += len(chunk)
+
+ # Write chunk to both INFILE and SOURCE
+ workflow_file_storage.write(path=infile_path, mode="ab", data=chunk)
+ workflow_file_storage.write(path=source_file_path, mode="ab", data=chunk)
+
+ # Handle empty files - raise exception instead of using _handle_empty_file
+ if total_bytes_copied == 0:
+ raise EmptyFileError(file_path)
+ else:
+ computed_hash = file_content_hash.hexdigest()
+ logger.info(
+ f"Successfully copied {total_bytes_copied} bytes with hash: {computed_hash}"
+ )
+
+ # Store computed hash in file_data for file history
+ file_processing_context.file_hash.file_hash = computed_hash
+ return computed_hash
+
+ def _resolve_connector_config(
+ self,
+ source_connector_id: str | None,
+ source_config_connector_settings: dict[str, Any],
+ connector_metadata: dict[str, Any],
+ file_processing_context: FileProcessingContext,
+ ) -> tuple[str | None, dict[str, Any]]:
+ """Resolve which connector configuration to use."""
+ # Prefer source config (has auth tokens)
+ if source_connector_id and source_config_connector_settings:
+ logger.info(f"Using connector from source config: {source_connector_id}")
+ return source_connector_id, source_config_connector_settings
+
+ # Fall back to file metadata
+ if connector_metadata and "connector_id" in connector_metadata:
+ connector_id = connector_metadata["connector_id"]
+ logger.warning(
+ f"Using connector_id from file metadata (may lack auth): {connector_id}"
+ )
+ return connector_id, connector_metadata
+
+ # Fall back to file_data
+ if file_processing_context.file_hash.connector_id:
+ connector_id = file_processing_context.file_hash.connector_id
+ connector_settings = file_processing_context.file_hash.connector_settings
+ logger.warning(
+ f"Using connector_id from file_data (may lack auth): {connector_id}"
+ )
+ return connector_id, connector_settings
+
+ logger.error("No connector_id found in any configuration source")
+ return None, {}
+
+ def _handle_destination_processing(
+ self,
+ file_processing_context: FileProcessingContext,
+ workflow: WorkflowDefinitionResponseData,
+ workflow_id: str,
+ execution_id: str,
+ is_success: bool,
+ workflow_file_execution_id: str,
+ organization_id: str,
+ workflow_logger=None,
+ use_file_history: bool = False,
+ is_api: bool = False,
+ execution_error: str | None = None,
+ ) -> FinalOutputResult:
+ """Handle destination processing for ETL/TASK workflows following backend pattern.
+
+ This matches the exact pattern from backend/workflow_manager/workflow_v2/file_execution_tasks.py
+ _process_final_output method.
+ """
+ try:
+ file_hash = file_processing_context.file_hash
+ file_data = file_processing_context.file_data
+ logger.info(
+ f"Starting destination processing for file {file_hash.file_name} in workflow {workflow_id}"
+ )
+ if not workflow.destination_config:
+ logger.warning(
+ f"No destination configuration found for workflow {workflow_id}"
+ )
+ raise NotFoundDestinationConfiguration(
+ "No destination configuration found"
+ )
+
+ # Get source configuration to populate source connector settings
+ if not workflow.source_config:
+ logger.warning(
+ f"No source configuration found for workflow {workflow_id}"
+ )
+ raise NotFoundSourceConfiguration("No source configuration found")
+
+ # Get destination configuration via API
+ destination_config = workflow.destination_config.to_dict()
+
+ # Add source connector information to destination config for manual review
+ source_connector_info = (
+ self._extract_source_connector_info_to_update_destination(
+ source_config=workflow.source_config
+ )
+ )
+ if source_connector_info:
+ destination_config.update(source_connector_info)
+ logger.info(
+ f"Added source connector info to destination config: {source_connector_info.get('source_connector_id', 'none')}"
+ )
+ source_data = {
+ "source_connection_type": workflow.source_config.connection_type,
+ }
+ destination_config.update(source_data)
+
+ source_connection_type = workflow.source_config.connection_type
+
+ # Add HITL queue name from file_data if present (for API deployments)
+ hitl_queue_name = file_data.hitl_queue_name
+ destination_config["use_file_history"] = use_file_history
+ destination_config["file_execution_id"] = workflow_file_execution_id
+ if hitl_queue_name:
+ destination_config["hitl_queue_name"] = hitl_queue_name
+ logger.info(
+ f"Added HITL queue name to destination config: {hitl_queue_name}"
+ )
+ else:
+ logger.info(
+ "No hitl_queue_name found in file_data, proceeding with normal processing"
+ )
+
+ # Import destination connector
+
+ # Create destination config object (matching backend DestinationConnector.from_config)
+ dest_config = DestinationConfig.from_dict(destination_config)
+ logger.info(
+ f"Created destination config: {dest_config.connection_type} with source connector: {dest_config.source_connector_id}"
+ )
+ # Create destination connector (matching backend pattern)
+ destination = WorkerDestinationConnector.from_config(
+ workflow_logger, dest_config
+ )
+
+ # Process final output through destination (matching backend exactly)
+ output_result = None
+ processing_error = None # No processing error since workflow succeeded
+
+ try:
+ # CRITICAL: Log file destination routing decision
+ if file_hash.is_manualreview_required:
+ logger.info(
+ f"🔄 File {file_hash.file_name} marked for MANUAL REVIEW - sending to queue"
+ )
+ else:
+ destination_display = destination._get_destination_display_name()
+ logger.info(
+ f"📤 File {file_hash.file_name} marked for DESTINATION processing - sending to {destination_display}"
+ )
+
+ # Process final output through destination (exact backend signature + workers-specific params)
+ handle_output_result = destination.handle_output(
+ is_success=is_success,
+ file_hash=file_hash,
+ # file_history=file_history,
+ workflow={"id": workflow_id}, # Minimal workflow object like backend
+ file_execution_id=workflow_file_execution_id,
+ # Workers-specific parameters (needed for API-based operation)
+ api_client=self.api_client,
+ workflow_id=workflow_id,
+ execution_id=execution_id,
+ organization_id=organization_id,
+ execution_error=execution_error,
+ )
+ output_result = handle_output_result.output
+ metadata = handle_output_result.metadata
+ source_connection_type = workflow.source_config.connection_type
+ except Exception as dest_error:
+ logger.error(
+ f"Destination processing failed in _handle_destination_processing: {dest_error}",
+ exc_info=True,
+ )
+ processing_error = str(dest_error)
+ output_result = None
+
+ # Handle metadata for API workflows (matching backend pattern)
+ execution_metadata = None
+ if self._should_create_file_history(
+ destination=destination,
+ # file_history=file_history,
+ output_result=output_result,
+ processing_error=processing_error,
+ ):
+ # Create file history entry via API client
+ logger.info(f"Creating file history entry for {file_hash.file_name}")
+
+ # Serialize result and metadata for API
+ import json
+
+ result_json = ""
+ if output_result and destination.is_api:
+ try:
+ result_json = (
+ json.dumps(output_result)
+ if isinstance(output_result, (dict, list))
+ else str(output_result)
+ )
+ except Exception as e:
+ logger.warning(f"Failed to serialize result: {e}")
+ result_json = str(output_result)
+
+ # Create file history via API
+ file_history_response = self.api_client.create_file_history(
+ file_path=file_hash.file_path if not destination.is_api else None,
+ file_name=file_hash.file_name,
+ source_connection_type=str(source_connection_type),
+ workflow_id=workflow_id,
+ file_hash=file_hash.file_hash,
+ file_size=getattr(file_hash, "file_size", 0),
+ mime_type=getattr(file_hash, "mime_type", ""),
+ result=result_json,
+ metadata=metadata,
+ status="COMPLETED",
+ provider_file_uuid=getattr(file_hash, "provider_file_uuid", None),
+ is_api=destination.is_api,
+ )
+
+ if file_history_response.success:
+ logger.info(f"Created file history entry for {file_hash.file_name}")
+ else:
+ logger.warning(
+ f"Failed to create file history: {file_history_response.error}"
+ )
+
+ if processing_error:
+ logger.error(
+ f"Destination processing failed for file {file_hash.file_name}: {processing_error}"
+ )
+ # Return error information so the main method can handle it
+ return FinalOutputResult(
+ output=None, metadata=None, error=processing_error
+ )
+ else:
+ logger.info(
+ f"Destination processing completed for file {file_hash.file_name}"
+ )
+ return FinalOutputResult(
+ output=output_result,
+ metadata=execution_metadata,
+ error=self._last_execution_error,
+ )
+
+ except Exception as e:
+ error_msg = f"Failed to process destination for workflow {workflow_id}: {e}"
+ logger.error(error_msg, exc_info=True)
+ return FinalOutputResult(output=None, metadata=None, error=error_msg)
+
+ def _should_create_file_history(
+ self,
+ destination,
+ output_result,
+ processing_error,
+ ) -> bool:
+ """Determine if file history should be created.
+
+ File history creation rules:
+ - API workflows: Create WITH results only when use_file_history=True
+ - ETL/TASK/MANUAL_REVIEW workflows: Always create WITHOUT results (for tracking)
+ """
+ # Don't create if there is a tool execution error
+ if self._last_execution_error:
+ return False
+
+ # Don't create if there's a processing error
+ if processing_error:
+ return False
+
+ # For API workflows, only create if use_file_history is enabled
+ if destination.is_api and not destination.use_file_history:
+ return False
+
+ # For API workflows, only create if there's a valid output result
+ if destination.is_api and not output_result:
+ return False
+
+ return True
+
+ def _get_destination_config(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any] | None:
+ """Get destination configuration for the workflow via API."""
+ try:
+ # Get workflow execution context which includes destination config
+ execution_response = self.api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(
+ f"Failed to get execution context: {execution_response.error}"
+ )
+ execution_context = execution_response.data
+ destination_config = execution_context.get("destination_config", {})
+
+ if not destination_config:
+ logger.warning(
+ f"No destination config found in execution context for workflow {workflow_id}"
+ )
+ return None
+
+ logger.info(
+ f"Retrieved destination config for workflow {workflow_id}: {destination_config.get('connection_type')}"
+ )
+ return destination_config
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get destination config for workflow {workflow_id}: {e}"
+ )
+ return None
+
+ def _get_source_config(
+ self, workflow_id: str, execution_id: str
+ ) -> dict[str, Any] | None:
+ """Get source configuration for the workflow via API."""
+ try:
+ # Get workflow execution context which includes source config
+ execution_response = self.api_client.get_workflow_execution(execution_id)
+ if not execution_response.success:
+ raise Exception(
+ f"Failed to get execution context: {execution_response.error}"
+ )
+ execution_context = execution_response.data
+ source_config = execution_context.get("source_config", {})
+
+ if not source_config:
+ logger.warning(
+ f"No source config found in execution context for workflow {workflow_id}"
+ )
+ return None
+
+ logger.info(
+ f"Retrieved source config for workflow {workflow_id}: {source_config.get('type', 'unknown')}"
+ )
+ return source_config
+
+ except Exception as e:
+ logger.error(f"Failed to get source config for workflow {workflow_id}: {e}")
+ return None
+
+ def _extract_source_connector_info_to_update_destination(
+ self, source_config: WorkflowEndpointConfigData
+ ) -> dict[str, Any] | None:
+ """Extract source connector information from source config for destination connector use."""
+ try:
+ # With updated backend, source config now includes connector instance details directly
+ connector_instance = source_config.connector_instance
+ if not connector_instance:
+ logger.warning(
+ f"No connector instance found in source config: {source_config}"
+ )
+ return None
+ connector_id = connector_instance.connector_id
+ connector_settings = connector_instance.connector_metadata
+
+ # if connector_id and connector_settings:
+ # logger.info(f"Extracted source connector info: {connector_id}")
+ # return {
+ # "source_connector_id": connector_id,
+ # "source_connector_settings": connector_settings,
+ # }
+ # else:
+ # Fallback: check in source_settings for older format
+ # source_settings = source_config.configuration
+ # connector_id = source_settings.get("connector_id")
+ # connector_settings = source_settings.get(
+ # "connector_settings"
+ # ) or source_settings.get("metadata")
+
+ if connector_id and connector_settings:
+ logger.info(
+ f"Extracted source connector info from source_settings: {connector_id}"
+ )
+ return {
+ "source_connector_id": connector_id,
+ "source_connector_settings": connector_settings,
+ }
+
+ logger.debug(
+ f"No source connector info found in source config. Available keys: {list(source_config.keys())}"
+ )
+ return None
+
+ except Exception as e:
+ logger.error(f"Failed to extract source connector info: {e}")
+ return None
+
+ def _get_platform_service_api_key(self, organization_id: str) -> str:
+ """Get platform service API key from backend API.
+
+ Args:
+ organization_id: Organization ID
+
+ Returns:
+ Platform service API key
+ """
+ try:
+ # Call the internal API to get the platform key using X-Organization-ID header
+ response = self.api_client._make_request(
+ method="GET",
+ endpoint="v1/platform-settings/platform-key/",
+ organization_id=organization_id, # This will be passed as X-Organization-ID header
+ )
+
+ if response and "platform_key" in response:
+ logger.info(
+ f"Successfully retrieved platform key for org {organization_id}"
+ )
+ return response["platform_key"]
+ else:
+ logger.error(
+ f"No platform key found for org {organization_id} in API response"
+ )
+ raise Exception(
+ f"No active platform key found for organization {organization_id}"
+ )
+
+ except Exception as e:
+ logger.error(
+ f"Failed to get platform key from API for org {organization_id}: {e}"
+ )
+ raise Exception(
+ f"Unable to retrieve platform service API key for organization {organization_id}: {e}"
+ )
diff --git a/workers/shared/workflow/execution/tool_validation.py b/workers/shared/workflow/execution/tool_validation.py
new file mode 100644
index 000000000..ed40b6554
--- /dev/null
+++ b/workers/shared/workflow/execution/tool_validation.py
@@ -0,0 +1,188 @@
+"""Tool Validation Utilities
+
+Shared validation logic for tool instances before workflow execution.
+This module provides common validation functionality used by both general
+and API deployment workers to eliminate code duplication.
+"""
+
+import logging
+
+from shared.api.internal_client import InternalAPIClient
+from shared.infrastructure.logging.workflow_logger import WorkerWorkflowLogger
+
+from unstract.core.data_models import ExecutionStatus
+
+logger = logging.getLogger(__name__)
+
+
+def validate_workflow_tool_instances(
+ api_client: InternalAPIClient,
+ workflow_id: str,
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None = None,
+ workflow_type: str = "general",
+) -> None:
+ """Validate tool instances for a workflow before execution begins.
+
+ This function performs comprehensive validation of tool instances including:
+ 1. Adapter name to ID migration
+ 2. User permissions validation
+ 3. Tool settings JSON schema validation
+
+ Args:
+ api_client: Internal API client instance
+ workflow_id: Workflow ID to validate tools for
+ execution_id: Execution ID for logging and status updates
+ organization_id: Organization ID for scoped operations
+ pipeline_id: Pipeline ID (optional, for logging context)
+ workflow_type: Type of workflow for logging context ("general" or "api")
+
+ Raises:
+ Exception: If tool validation fails or API calls fail
+
+ Note:
+ This function updates workflow execution status to ERROR on validation failures
+ and provides comprehensive logging to both application logs and UI via WorkerWorkflowLogger.
+ """
+ # Get tool instances via separate API call (execution context doesn't include them)
+ tool_instances_response = api_client.get_tool_instances_by_workflow(
+ workflow_id=workflow_id, organization_id=organization_id
+ )
+ tool_instances_data = tool_instances_response.tool_instances
+
+ if not tool_instances_data:
+ logger.info(
+ f"No tool instances data available for validation in {workflow_type} workflow {workflow_id}"
+ )
+ return
+
+ logger.info(
+ f"Validating {len(tool_instances_data)} tool instances for {workflow_type} workflow {workflow_id}"
+ )
+
+ # Extract tool instance IDs for validation
+ tool_instance_ids = [
+ tool_data.get("id") for tool_data in tool_instances_data if tool_data.get("id")
+ ]
+
+ if not tool_instance_ids:
+ logger.info(
+ f"No tool instances found to validate for {workflow_type} workflow {workflow_id}"
+ )
+ return
+
+ # Create workflow-specific logger for UI feedback
+ workflow_logger = _create_workflow_logger(
+ workflow_type=workflow_type,
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+
+ try:
+ # Call backend validation API
+ validation_response = api_client.validate_tool_instances(
+ workflow_id=workflow_id,
+ tool_instance_ids=tool_instance_ids,
+ organization_id=organization_id,
+ )
+
+ if not validation_response.get("success", False):
+ # Validation failed - extract error details
+ errors = validation_response.get("errors", [])
+ error_details = "; ".join(
+ [
+ f"{err.get('tool_id', 'unknown')}: {err.get('error', 'unknown error')}"
+ for err in errors
+ ]
+ )
+ error_msg = f"Tool instance validation failed: {error_details}"
+
+ logger.error(
+ f"{workflow_type.title()} workflow validation failed for {execution_id}: {error_msg}"
+ )
+
+ # Log validation failure to UI
+ if workflow_logger:
+ workflow_logger.log_error(
+ logger, f"❌ Tool validation failed: {error_details}"
+ )
+
+ # Update execution status to ERROR and exit early
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=error_msg,
+ )
+
+ raise Exception(error_msg)
+
+ else:
+ # Validation succeeded
+ context_suffix = "API workflow" if workflow_type == "api" else "workflow"
+ logger.info(
+ f"Successfully validated {len(tool_instance_ids)} tool instances for {context_suffix}"
+ )
+
+ # Log validation success to UI
+ if workflow_logger:
+ workflow_logger.log_info(
+ logger,
+ f"✅ Validated {len(tool_instance_ids)} tool instances successfully",
+ )
+
+ except Exception as validation_error:
+ # Handle API call failures or other exceptions
+ logger.error(
+ f"Tool validation API call failed for {workflow_type} workflow {execution_id}: {validation_error}"
+ )
+
+ # Log API failure to UI
+ if workflow_logger:
+ workflow_logger.log_error(
+ logger, f"❌ Tool validation API call failed: {str(validation_error)}"
+ )
+
+ # Update execution status and re-raise
+ api_client.update_workflow_execution_status(
+ execution_id=execution_id,
+ status=ExecutionStatus.ERROR.value,
+ error_message=f"Tool validation failed: {str(validation_error)}",
+ )
+ raise
+
+
+def _create_workflow_logger(
+ workflow_type: str,
+ execution_id: str,
+ organization_id: str,
+ pipeline_id: str | None = None,
+) -> WorkerWorkflowLogger | None:
+ """Create appropriate workflow logger based on workflow type.
+
+ Args:
+ workflow_type: Type of workflow ("general" or "api")
+ execution_id: Execution ID for logger context
+ organization_id: Organization ID for logger context
+ pipeline_id: Pipeline ID for logger context (optional)
+
+ Returns:
+ WorkerWorkflowLogger instance or None if creation fails
+ """
+ try:
+ if workflow_type == "api":
+ return WorkerWorkflowLogger.create_for_api_workflow(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+ else:
+ return WorkerWorkflowLogger.create_for_general_workflow(
+ execution_id=execution_id,
+ organization_id=organization_id,
+ pipeline_id=pipeline_id,
+ )
+ except Exception as logger_error:
+ logger.warning(f"Failed to create workflow logger: {logger_error}")
+ return None
diff --git a/workers/shared/workflow/source_connector.py b/workers/shared/workflow/source_connector.py
new file mode 100644
index 000000000..49941bfc0
--- /dev/null
+++ b/workers/shared/workflow/source_connector.py
@@ -0,0 +1,213 @@
+"""Source Connector for Workflow Input Handling
+
+This module provides specialized source connector for handling workflow inputs,
+extracted from the backend workflow_manager/endpoint_v2/source.py to work without Django.
+
+Handles:
+- Filesystem source input
+- API source input
+- Source validation
+- File listing and processing
+"""
+
+from dataclasses import dataclass
+from typing import Any
+
+from unstract.core.data_models import ConnectionType as CoreConnectionType
+
+from ..infrastructure.logging.logger import WorkerLogger
+
+logger = WorkerLogger.get_logger(__name__)
+
+
+@dataclass
+class SourceConfig:
+ """Worker-compatible SourceConfig implementation."""
+
+ connection_type: str
+ settings: dict[str, Any] = None
+ # Connector instance fields from backend API
+ connector_id: str | None = None
+ connector_settings: dict[str, Any] = None
+ connector_name: str | None = None
+
+ def __post_init__(self):
+ if self.settings is None:
+ self.settings = {}
+ if self.connector_settings is None:
+ self.connector_settings = {}
+
+ def get_core_connection_type(self) -> CoreConnectionType:
+ """Convert string connection_type to CoreConnectionType enum."""
+ try:
+ # Use the enum directly for consistent mapping
+ connection_type_upper = self.connection_type.upper()
+
+ # Try to get enum member by value
+ for connection_type_enum in CoreConnectionType:
+ if connection_type_enum.value == connection_type_upper:
+ return connection_type_enum
+
+ # Fallback: handle legacy/unknown types
+ logger.warning(
+ f"Unknown connection type '{self.connection_type}', defaulting to FILESYSTEM"
+ )
+ return CoreConnectionType.FILESYSTEM
+
+ except Exception as e:
+ logger.error(
+ f"Failed to convert connection type '{self.connection_type}' to enum: {e}"
+ )
+ return CoreConnectionType.FILESYSTEM
+
+ @classmethod
+ def from_dict(cls, data: dict[str, Any]) -> "SourceConfig":
+ """Create SourceConfig from dictionary data."""
+ return cls(
+ connection_type=data.get("connection_type", ""),
+ settings=data.get("settings", {}),
+ connector_id=data.get("connector_id"),
+ connector_settings=data.get("connector_settings", {}),
+ connector_name=data.get("connector_name"),
+ )
+
+
+class WorkerSourceConnector:
+ """Worker-compatible source connector following production patterns.
+
+ This class replicates the functionality of backend SourceConnector
+ from workflow_manager/endpoint_v2/source.py without Django dependencies.
+ """
+
+ # Local connection types for workflow source handling
+ class ConnectionType:
+ # Standard connection types from CoreConnectionType
+ FILESYSTEM = CoreConnectionType.FILESYSTEM.value
+ API = CoreConnectionType.API.value
+ DATABASE = CoreConnectionType.DATABASE.value
+
+ # Workflow-specific connection type for API execution storage
+ API_STORAGE = "API_STORAGE"
+
+ def __init__(self, config: SourceConfig, workflow_log=None):
+ self.config = config
+ self.connection_type = config.connection_type
+ self.settings = config.settings
+ self.workflow_log = workflow_log
+
+ # Store connector instance details
+ self.connector_id = config.connector_id
+ self.connector_settings = config.connector_settings
+ self.connector_name = config.connector_name
+
+ @classmethod
+ def from_config(cls, workflow_log, config: SourceConfig):
+ """Create source connector from config (matching Django backend interface)."""
+ return cls(config, workflow_log)
+
+ def get_fsspec_fs(self):
+ """Get fsspec filesystem for the source connector.
+
+ This method replicates backend logic for getting filesystem access.
+ """
+ if self.connection_type == self.ConnectionType.API_STORAGE:
+ # API storage uses workflow execution storage
+ from unstract.filesystem import FileStorageType, FileSystem
+
+ file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
+ return file_system.get_file_storage()
+
+ if not self.connector_id or not self.connector_settings:
+ raise Exception("Source connector not configured")
+
+ # Get the connector instance using connectorkit
+ from unstract.connectors.connectorkit import Connectorkit
+
+ connectorkit = Connectorkit()
+ connector_class = connectorkit.get_connector_class_by_connector_id(
+ self.connector_id
+ )
+ connector_instance = connector_class(self.connector_settings)
+
+ # Get fsspec filesystem
+ return connector_instance.get_fsspec_fs()
+
+ def read_file_content(self, file_path: str) -> bytes:
+ """Read file content from source connector.
+
+ Args:
+ file_path: Path to the file in source storage
+
+ Returns:
+ File content as bytes
+ """
+ fs = self.get_fsspec_fs()
+
+ if self.connection_type == self.ConnectionType.API_STORAGE:
+ # For API storage, use the filesystem's read method
+ return fs.read(file_path, mode="rb")
+ else:
+ # For other connectors, use fsspec open
+ with fs.open(file_path, "rb") as f:
+ return f.read()
+
+ def list_files(
+ self, input_directory: str, file_pattern: str = None
+ ) -> list[dict[str, Any]]:
+ """List files from source connector.
+
+ Args:
+ input_directory: Directory to list files from
+ file_pattern: Optional glob pattern to filter files
+
+ Returns:
+ List of file information dictionaries
+ """
+ fs = self.get_fsspec_fs()
+
+ # Implementation would list files using fsspec
+ # This is a simplified version
+ try:
+ files = []
+ if self.connection_type == self.ConnectionType.API_STORAGE:
+ # Use filesystem listing
+ file_paths = fs.list(input_directory)
+ else:
+ # Use fsspec listing
+ file_paths = fs.ls(input_directory, detail=False)
+
+ for file_path in file_paths:
+ files.append(
+ {
+ "name": file_path.split("/")[-1],
+ "path": file_path,
+ }
+ )
+
+ return files
+ except Exception as e:
+ logger.error(f"Failed to list files from source: {e}")
+ return []
+
+ def validate(self) -> None:
+ """Validate source connector configuration."""
+ connection_type = self.connection_type
+
+ if connection_type not in [
+ self.ConnectionType.FILESYSTEM,
+ self.ConnectionType.API,
+ self.ConnectionType.API_STORAGE,
+ ]:
+ raise Exception(f"Invalid source connection type: {connection_type}")
+
+ if connection_type == self.ConnectionType.FILESYSTEM:
+ if not self.connector_id or not self.connector_settings:
+ raise Exception("Filesystem source requires connector configuration")
+
+ def get_config(self) -> SourceConfig:
+ """Get serializable configuration for the source connector."""
+ return self.config
+
+
+# Alias for backward compatibility
+SourceConnector = WorkerSourceConnector
diff --git a/workers/uv.lock b/workers/uv.lock
new file mode 100644
index 000000000..08892ec32
--- /dev/null
+++ b/workers/uv.lock
@@ -0,0 +1,4827 @@
+version = 1
+revision = 2
+requires-python = ">=3.12"
+resolution-markers = [
+ "python_full_version >= '3.13'",
+ "python_full_version < '3.13'",
+]
+
+[[package]]
+name = "adlfs"
+version = "2024.7.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiohttp" },
+ { name = "azure-core" },
+ { name = "azure-datalake-store" },
+ { name = "azure-identity" },
+ { name = "azure-storage-blob" },
+ { name = "fsspec" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b4/1e/6d5146676044247af566fa5843b335b1a647e6446070cec9c8b61c31b369/adlfs-2024.7.0.tar.gz", hash = "sha256:106995b91f0eb5e775bcd5957d180d9a14faef3271a063b1f65c66fd5ab05ddf", size = 48588, upload-time = "2024-07-22T12:10:33.849Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6f/51/a71c457bd0bc8af3e522b6999ff300852c7c446e384fd9904b0794f875df/adlfs-2024.7.0-py3-none-any.whl", hash = "sha256:2005c8e124fda3948f2a6abb2dbebb2c936d2d821acaca6afd61932edfa9bc07", size = 41349, upload-time = "2024-07-22T12:10:32.226Z" },
+]
+
+[[package]]
+name = "aioboto3"
+version = "13.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiobotocore", extra = ["boto3"] },
+ { name = "aiofiles" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/3f/5a/110bb213df3ec5f977995b45acfdec6c2a7b829bc33960484a9c51433f65/aioboto3-13.4.0.tar.gz", hash = "sha256:3105f9e5618c686c90050e60eb5ebf9e28f7f8c4e0fa162d4481aaa402008aab", size = 32002, upload-time = "2025-01-19T18:51:27.202Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/84/f4/645f113df15849685de0b36985a8e77afa5ae40983278f45ca38c8b58666/aioboto3-13.4.0-py3-none-any.whl", hash = "sha256:d78f3400ef3a01b4d5515108ef244941894a0bc39c4716321a00e15898d7e002", size = 34758, upload-time = "2025-01-19T18:51:25.231Z" },
+]
+
+[[package]]
+name = "aiobotocore"
+version = "2.18.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiohttp" },
+ { name = "aioitertools" },
+ { name = "botocore" },
+ { name = "jmespath" },
+ { name = "multidict" },
+ { name = "python-dateutil" },
+ { name = "urllib3" },
+ { name = "wrapt" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/5f/38/a71d13726568ba0189978a5a66c08b5d0359d446513ebdba53056763f4cb/aiobotocore-2.18.0.tar.gz", hash = "sha256:c54db752c5a742bf1a05c8359a93f508b4bf702b0e6be253a4c9ef1f9c9b6706", size = 107682, upload-time = "2025-01-17T07:53:55.194Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/40/fa/5c971881f662ef083e5dd9d8995237e919ec759246f4134bad9c9d92c525/aiobotocore-2.18.0-py3-none-any.whl", hash = "sha256:89634470946944baf0a72fe2939cdd5f98b61335d400ca55f3032aca92989ec1", size = 77615, upload-time = "2025-01-17T07:53:52.189Z" },
+]
+
+[package.optional-dependencies]
+boto3 = [
+ { name = "boto3" },
+]
+
+[[package]]
+name = "aiofiles"
+version = "24.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0b/03/a88171e277e8caa88a4c77808c20ebb04ba74cc4681bf1e9416c862de237/aiofiles-24.1.0.tar.gz", hash = "sha256:22a075c9e5a3810f0c2e48f3008c94d68c65d763b9b03857924c99e57355166c", size = 30247, upload-time = "2024-06-24T11:02:03.584Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a5/45/30bb92d442636f570cb5651bc661f52b610e2eec3f891a5dc3a4c3667db0/aiofiles-24.1.0-py3-none-any.whl", hash = "sha256:b4ec55f4195e3eb5d7abd1bf7e061763e864dd4954231fb8539a0ef8bb8260e5", size = 15896, upload-time = "2024-06-24T11:02:01.529Z" },
+]
+
+[[package]]
+name = "aiohappyeyeballs"
+version = "2.6.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/26/30/f84a107a9c4331c14b2b586036f40965c128aa4fee4dda5d3d51cb14ad54/aiohappyeyeballs-2.6.1.tar.gz", hash = "sha256:c3f9d0113123803ccadfdf3f0faa505bc78e6a72d1cc4806cbd719826e943558", size = 22760, upload-time = "2025-03-12T01:42:48.764Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/0f/15/5bf3b99495fb160b63f95972b81750f18f7f4e02ad051373b669d17d44f2/aiohappyeyeballs-2.6.1-py3-none-any.whl", hash = "sha256:f349ba8f4b75cb25c99c5c2d84e997e485204d2902a9597802b0371f09331fb8", size = 15265, upload-time = "2025-03-12T01:42:47.083Z" },
+]
+
+[[package]]
+name = "aiohttp"
+version = "3.12.15"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiohappyeyeballs" },
+ { name = "aiosignal" },
+ { name = "attrs" },
+ { name = "frozenlist" },
+ { name = "multidict" },
+ { name = "propcache" },
+ { name = "yarl" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/9b/e7/d92a237d8802ca88483906c388f7c201bbe96cd80a165ffd0ac2f6a8d59f/aiohttp-3.12.15.tar.gz", hash = "sha256:4fc61385e9c98d72fcdf47e6dd81833f47b2f77c114c29cd64a361be57a763a2", size = 7823716, upload-time = "2025-07-29T05:52:32.215Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/63/97/77cb2450d9b35f517d6cf506256bf4f5bda3f93a66b4ad64ba7fc917899c/aiohttp-3.12.15-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:802d3868f5776e28f7bf69d349c26fc0efadb81676d0afa88ed00d98a26340b7", size = 702333, upload-time = "2025-07-29T05:50:46.507Z" },
+ { url = "https://files.pythonhosted.org/packages/83/6d/0544e6b08b748682c30b9f65640d006e51f90763b41d7c546693bc22900d/aiohttp-3.12.15-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:f2800614cd560287be05e33a679638e586a2d7401f4ddf99e304d98878c29444", size = 476948, upload-time = "2025-07-29T05:50:48.067Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/1d/c8c40e611e5094330284b1aea8a4b02ca0858f8458614fa35754cab42b9c/aiohttp-3.12.15-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8466151554b593909d30a0a125d638b4e5f3836e5aecde85b66b80ded1cb5b0d", size = 469787, upload-time = "2025-07-29T05:50:49.669Z" },
+ { url = "https://files.pythonhosted.org/packages/38/7d/b76438e70319796bfff717f325d97ce2e9310f752a267bfdf5192ac6082b/aiohttp-3.12.15-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2e5a495cb1be69dae4b08f35a6c4579c539e9b5706f606632102c0f855bcba7c", size = 1716590, upload-time = "2025-07-29T05:50:51.368Z" },
+ { url = "https://files.pythonhosted.org/packages/79/b1/60370d70cdf8b269ee1444b390cbd72ce514f0d1cd1a715821c784d272c9/aiohttp-3.12.15-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:6404dfc8cdde35c69aaa489bb3542fb86ef215fc70277c892be8af540e5e21c0", size = 1699241, upload-time = "2025-07-29T05:50:53.628Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/2b/4968a7b8792437ebc12186db31523f541943e99bda8f30335c482bea6879/aiohttp-3.12.15-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3ead1c00f8521a5c9070fcb88f02967b1d8a0544e6d85c253f6968b785e1a2ab", size = 1754335, upload-time = "2025-07-29T05:50:55.394Z" },
+ { url = "https://files.pythonhosted.org/packages/fb/c1/49524ed553f9a0bec1a11fac09e790f49ff669bcd14164f9fab608831c4d/aiohttp-3.12.15-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6990ef617f14450bc6b34941dba4f12d5613cbf4e33805932f853fbd1cf18bfb", size = 1800491, upload-time = "2025-07-29T05:50:57.202Z" },
+ { url = "https://files.pythonhosted.org/packages/de/5e/3bf5acea47a96a28c121b167f5ef659cf71208b19e52a88cdfa5c37f1fcc/aiohttp-3.12.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fd736ed420f4db2b8148b52b46b88ed038d0354255f9a73196b7bbce3ea97545", size = 1719929, upload-time = "2025-07-29T05:50:59.192Z" },
+ { url = "https://files.pythonhosted.org/packages/39/94/8ae30b806835bcd1cba799ba35347dee6961a11bd507db634516210e91d8/aiohttp-3.12.15-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3c5092ce14361a73086b90c6efb3948ffa5be2f5b6fbcf52e8d8c8b8848bb97c", size = 1635733, upload-time = "2025-07-29T05:51:01.394Z" },
+ { url = "https://files.pythonhosted.org/packages/7a/46/06cdef71dd03acd9da7f51ab3a9107318aee12ad38d273f654e4f981583a/aiohttp-3.12.15-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:aaa2234bb60c4dbf82893e934d8ee8dea30446f0647e024074237a56a08c01bd", size = 1696790, upload-time = "2025-07-29T05:51:03.657Z" },
+ { url = "https://files.pythonhosted.org/packages/02/90/6b4cfaaf92ed98d0ec4d173e78b99b4b1a7551250be8937d9d67ecb356b4/aiohttp-3.12.15-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:6d86a2fbdd14192e2f234a92d3b494dd4457e683ba07e5905a0b3ee25389ac9f", size = 1718245, upload-time = "2025-07-29T05:51:05.911Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/e6/2593751670fa06f080a846f37f112cbe6f873ba510d070136a6ed46117c6/aiohttp-3.12.15-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:a041e7e2612041a6ddf1c6a33b883be6a421247c7afd47e885969ee4cc58bd8d", size = 1658899, upload-time = "2025-07-29T05:51:07.753Z" },
+ { url = "https://files.pythonhosted.org/packages/8f/28/c15bacbdb8b8eb5bf39b10680d129ea7410b859e379b03190f02fa104ffd/aiohttp-3.12.15-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:5015082477abeafad7203757ae44299a610e89ee82a1503e3d4184e6bafdd519", size = 1738459, upload-time = "2025-07-29T05:51:09.56Z" },
+ { url = "https://files.pythonhosted.org/packages/00/de/c269cbc4faa01fb10f143b1670633a8ddd5b2e1ffd0548f7aa49cb5c70e2/aiohttp-3.12.15-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:56822ff5ddfd1b745534e658faba944012346184fbfe732e0d6134b744516eea", size = 1766434, upload-time = "2025-07-29T05:51:11.423Z" },
+ { url = "https://files.pythonhosted.org/packages/52/b0/4ff3abd81aa7d929b27d2e1403722a65fc87b763e3a97b3a2a494bfc63bc/aiohttp-3.12.15-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b2acbbfff69019d9014508c4ba0401822e8bae5a5fdc3b6814285b71231b60f3", size = 1726045, upload-time = "2025-07-29T05:51:13.689Z" },
+ { url = "https://files.pythonhosted.org/packages/71/16/949225a6a2dd6efcbd855fbd90cf476052e648fb011aa538e3b15b89a57a/aiohttp-3.12.15-cp312-cp312-win32.whl", hash = "sha256:d849b0901b50f2185874b9a232f38e26b9b3d4810095a7572eacea939132d4e1", size = 423591, upload-time = "2025-07-29T05:51:15.452Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/d8/fa65d2a349fe938b76d309db1a56a75c4fb8cc7b17a398b698488a939903/aiohttp-3.12.15-cp312-cp312-win_amd64.whl", hash = "sha256:b390ef5f62bb508a9d67cb3bba9b8356e23b3996da7062f1a57ce1a79d2b3d34", size = 450266, upload-time = "2025-07-29T05:51:17.239Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/33/918091abcf102e39d15aba2476ad9e7bd35ddb190dcdd43a854000d3da0d/aiohttp-3.12.15-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:9f922ffd05034d439dde1c77a20461cf4a1b0831e6caa26151fe7aa8aaebc315", size = 696741, upload-time = "2025-07-29T05:51:19.021Z" },
+ { url = "https://files.pythonhosted.org/packages/b5/2a/7495a81e39a998e400f3ecdd44a62107254803d1681d9189be5c2e4530cd/aiohttp-3.12.15-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:2ee8a8ac39ce45f3e55663891d4b1d15598c157b4d494a4613e704c8b43112cd", size = 474407, upload-time = "2025-07-29T05:51:21.165Z" },
+ { url = "https://files.pythonhosted.org/packages/49/fc/a9576ab4be2dcbd0f73ee8675d16c707cfc12d5ee80ccf4015ba543480c9/aiohttp-3.12.15-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3eae49032c29d356b94eee45a3f39fdf4b0814b397638c2f718e96cfadf4c4e4", size = 466703, upload-time = "2025-07-29T05:51:22.948Z" },
+ { url = "https://files.pythonhosted.org/packages/09/2f/d4bcc8448cf536b2b54eed48f19682031ad182faa3a3fee54ebe5b156387/aiohttp-3.12.15-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b97752ff12cc12f46a9b20327104448042fce5c33a624f88c18f66f9368091c7", size = 1705532, upload-time = "2025-07-29T05:51:25.211Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/f3/59406396083f8b489261e3c011aa8aee9df360a96ac8fa5c2e7e1b8f0466/aiohttp-3.12.15-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:894261472691d6fe76ebb7fcf2e5870a2ac284c7406ddc95823c8598a1390f0d", size = 1686794, upload-time = "2025-07-29T05:51:27.145Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/71/164d194993a8d114ee5656c3b7ae9c12ceee7040d076bf7b32fb98a8c5c6/aiohttp-3.12.15-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5fa5d9eb82ce98959fc1031c28198b431b4d9396894f385cb63f1e2f3f20ca6b", size = 1738865, upload-time = "2025-07-29T05:51:29.366Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/00/d198461b699188a93ead39cb458554d9f0f69879b95078dce416d3209b54/aiohttp-3.12.15-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f0fa751efb11a541f57db59c1dd821bec09031e01452b2b6217319b3a1f34f3d", size = 1788238, upload-time = "2025-07-29T05:51:31.285Z" },
+ { url = "https://files.pythonhosted.org/packages/85/b8/9e7175e1fa0ac8e56baa83bf3c214823ce250d0028955dfb23f43d5e61fd/aiohttp-3.12.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5346b93e62ab51ee2a9d68e8f73c7cf96ffb73568a23e683f931e52450e4148d", size = 1710566, upload-time = "2025-07-29T05:51:33.219Z" },
+ { url = "https://files.pythonhosted.org/packages/59/e4/16a8eac9df39b48ae102ec030fa9f726d3570732e46ba0c592aeeb507b93/aiohttp-3.12.15-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:049ec0360f939cd164ecbfd2873eaa432613d5e77d6b04535e3d1fbae5a9e645", size = 1624270, upload-time = "2025-07-29T05:51:35.195Z" },
+ { url = "https://files.pythonhosted.org/packages/1f/f8/cd84dee7b6ace0740908fd0af170f9fab50c2a41ccbc3806aabcb1050141/aiohttp-3.12.15-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:b52dcf013b57464b6d1e51b627adfd69a8053e84b7103a7cd49c030f9ca44461", size = 1677294, upload-time = "2025-07-29T05:51:37.215Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/42/d0f1f85e50d401eccd12bf85c46ba84f947a84839c8a1c2c5f6e8ab1eb50/aiohttp-3.12.15-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:9b2af240143dd2765e0fb661fd0361a1b469cab235039ea57663cda087250ea9", size = 1708958, upload-time = "2025-07-29T05:51:39.328Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/6b/f6fa6c5790fb602538483aa5a1b86fcbad66244997e5230d88f9412ef24c/aiohttp-3.12.15-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:ac77f709a2cde2cc71257ab2d8c74dd157c67a0558a0d2799d5d571b4c63d44d", size = 1651553, upload-time = "2025-07-29T05:51:41.356Z" },
+ { url = "https://files.pythonhosted.org/packages/04/36/a6d36ad545fa12e61d11d1932eef273928b0495e6a576eb2af04297fdd3c/aiohttp-3.12.15-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:47f6b962246f0a774fbd3b6b7be25d59b06fdb2f164cf2513097998fc6a29693", size = 1727688, upload-time = "2025-07-29T05:51:43.452Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/c8/f195e5e06608a97a4e52c5d41c7927301bf757a8e8bb5bbf8cef6c314961/aiohttp-3.12.15-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:760fb7db442f284996e39cf9915a94492e1896baac44f06ae551974907922b64", size = 1761157, upload-time = "2025-07-29T05:51:45.643Z" },
+ { url = "https://files.pythonhosted.org/packages/05/6a/ea199e61b67f25ba688d3ce93f63b49b0a4e3b3d380f03971b4646412fc6/aiohttp-3.12.15-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:ad702e57dc385cae679c39d318def49aef754455f237499d5b99bea4ef582e51", size = 1710050, upload-time = "2025-07-29T05:51:48.203Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/2e/ffeb7f6256b33635c29dbed29a22a723ff2dd7401fff42ea60cf2060abfb/aiohttp-3.12.15-cp313-cp313-win32.whl", hash = "sha256:f813c3e9032331024de2eb2e32a88d86afb69291fbc37a3a3ae81cc9917fb3d0", size = 422647, upload-time = "2025-07-29T05:51:50.718Z" },
+ { url = "https://files.pythonhosted.org/packages/1b/8e/78ee35774201f38d5e1ba079c9958f7629b1fd079459aea9467441dbfbf5/aiohttp-3.12.15-cp313-cp313-win_amd64.whl", hash = "sha256:1a649001580bdb37c6fdb1bebbd7e3bc688e8ec2b5c6f52edbb664662b17dc84", size = 449067, upload-time = "2025-07-29T05:51:52.549Z" },
+]
+
+[[package]]
+name = "aioitertools"
+version = "0.12.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/06/de/38491a84ab323b47c7f86e94d2830e748780525f7a10c8600b67ead7e9ea/aioitertools-0.12.0.tar.gz", hash = "sha256:c2a9055b4fbb7705f561b9d86053e8af5d10cc845d22c32008c43490b2d8dd6b", size = 19369, upload-time = "2024-09-02T03:33:40.349Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/85/13/58b70a580de00893223d61de8fea167877a3aed97d4a5e1405c9159ef925/aioitertools-0.12.0-py3-none-any.whl", hash = "sha256:fc1f5fac3d737354de8831cbba3eb04f79dd649d8f3afb4c5b114925e662a796", size = 24345, upload-time = "2024-09-02T03:34:59.454Z" },
+]
+
+[[package]]
+name = "aiosignal"
+version = "1.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "frozenlist" },
+ { name = "typing-extensions", marker = "python_full_version < '3.13'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/61/62/06741b579156360248d1ec624842ad0edf697050bbaf7c3e46394e106ad1/aiosignal-1.4.0.tar.gz", hash = "sha256:f47eecd9468083c2029cc99945502cb7708b082c232f9aca65da147157b251c7", size = 25007, upload-time = "2025-07-03T22:54:43.528Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/fb/76/641ae371508676492379f16e2fa48f4e2c11741bd63c48be4b12a6b09cba/aiosignal-1.4.0-py3-none-any.whl", hash = "sha256:053243f8b92b990551949e63930a839ff0cf0b0ebbe0597b0f3fb19e1a0fe82e", size = 7490, upload-time = "2025-07-03T22:54:42.156Z" },
+]
+
+[[package]]
+name = "aiosqlite"
+version = "0.21.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/13/7d/8bca2bf9a247c2c5dfeec1d7a5f40db6518f88d314b8bca9da29670d2671/aiosqlite-0.21.0.tar.gz", hash = "sha256:131bb8056daa3bc875608c631c678cda73922a2d4ba8aec373b19f18c17e7aa3", size = 13454, upload-time = "2025-02-03T07:30:16.235Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/f5/10/6c25ed6de94c49f88a91fa5018cb4c0f3625f31d5be9f771ebe5cc7cd506/aiosqlite-0.21.0-py3-none-any.whl", hash = "sha256:2549cf4057f95f53dcba16f2b64e8e2791d7e1adedb13197dd8ed77bb226d7d0", size = 15792, upload-time = "2025-02-03T07:30:13.6Z" },
+]
+
+[[package]]
+name = "amqp"
+version = "5.3.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "vine" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/79/fc/ec94a357dfc6683d8c86f8b4cfa5416a4c36b28052ec8260c77aca96a443/amqp-5.3.1.tar.gz", hash = "sha256:cddc00c725449522023bad949f70fff7b48f0b1ade74d170a6f10ab044739432", size = 129013, upload-time = "2024-11-12T19:55:44.051Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/26/99/fc813cd978842c26c82534010ea849eee9ab3a13ea2b74e95cb9c99e747b/amqp-5.3.1-py3-none-any.whl", hash = "sha256:43b3319e1b4e7d1251833a93d672b4af1e40f3d632d479b98661a95f117880a2", size = 50944, upload-time = "2024-11-12T19:55:41.782Z" },
+]
+
+[[package]]
+name = "annotated-types"
+version = "0.7.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ee/67/531ea369ba64dcff5ec9c3402f9f51bf748cec26dde048a2f973a4eea7f5/annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89", size = 16081, upload-time = "2024-05-20T21:33:25.928Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" },
+]
+
+[[package]]
+name = "anthropic"
+version = "0.62.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "anyio" },
+ { name = "distro" },
+ { name = "httpx" },
+ { name = "jiter" },
+ { name = "pydantic" },
+ { name = "sniffio" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/cb/89/d41aa785f724275ff2a3135d4a656ba42c786e7a140973cbd7315dd2d5d2/anthropic-0.62.0.tar.gz", hash = "sha256:d45389229db9e443ea1a877f8d63309947f134991473cf8e88efee322840d084", size = 427073, upload-time = "2025-08-08T13:28:54.411Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a1/2f/53d41ff5d8fee7c77030a7fbf3432d0c7db5b799596b7d8e581bcb9a377d/anthropic-0.62.0-py3-none-any.whl", hash = "sha256:adcf2af98aa2b11e3b7c71afb2e0cb0613f679ad4a18ef58c38f17784b3df72e", size = 296625, upload-time = "2025-08-08T13:28:53.042Z" },
+]
+
+[package.optional-dependencies]
+bedrock = [
+ { name = "boto3" },
+ { name = "botocore" },
+]
+vertex = [
+ { name = "google-auth", extra = ["requests"] },
+]
+
+[[package]]
+name = "anyio"
+version = "4.10.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "idna" },
+ { name = "sniffio" },
+ { name = "typing-extensions", marker = "python_full_version < '3.13'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f1/b4/636b3b65173d3ce9a38ef5f0522789614e590dab6a8d505340a4efe4c567/anyio-4.10.0.tar.gz", hash = "sha256:3f3fae35c96039744587aa5b8371e7e8e603c0702999535961dd336026973ba6", size = 213252, upload-time = "2025-08-04T08:54:26.451Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6f/12/e5e0282d673bb9746bacfb6e2dba8719989d3660cdb2ea79aee9a9651afb/anyio-4.10.0-py3-none-any.whl", hash = "sha256:60e474ac86736bbfd6f210f7a61218939c318f43f9972497381f1c5e930ed3d1", size = 107213, upload-time = "2025-08-04T08:54:24.882Z" },
+]
+
+[[package]]
+name = "appdirs"
+version = "1.4.4"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/d7/d8/05696357e0311f5b5c316d7b95f46c669dd9c15aaeecbb48c7d0aeb88c40/appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41", size = 13470, upload-time = "2020-05-11T07:59:51.037Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3b/00/2344469e2084fb287c2e0b57b72910309874c3245463acd6cf5e3db69324/appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128", size = 9566, upload-time = "2020-05-11T07:59:49.499Z" },
+]
+
+[[package]]
+name = "asn1crypto"
+version = "1.5.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/de/cf/d547feed25b5244fcb9392e288ff9fdc3280b10260362fc45d37a798a6ee/asn1crypto-1.5.1.tar.gz", hash = "sha256:13ae38502be632115abf8a24cbe5f4da52e3b5231990aff31123c805306ccb9c", size = 121080, upload-time = "2022-03-15T14:46:52.889Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c9/7f/09065fd9e27da0eda08b4d6897f1c13535066174cc023af248fc2a8d5e5a/asn1crypto-1.5.1-py2.py3-none-any.whl", hash = "sha256:db4e40728b728508912cbb3d44f19ce188f218e9eba635821bb4b68564f8fd67", size = 105045, upload-time = "2022-03-15T14:46:51.055Z" },
+]
+
+[[package]]
+name = "asyncpg"
+version = "0.30.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/2f/4c/7c991e080e106d854809030d8584e15b2e996e26f16aee6d757e387bc17d/asyncpg-0.30.0.tar.gz", hash = "sha256:c551e9928ab6707602f44811817f82ba3c446e018bfe1d3abecc8ba5f3eac851", size = 957746, upload-time = "2024-10-20T00:30:41.127Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4b/64/9d3e887bb7b01535fdbc45fbd5f0a8447539833b97ee69ecdbb7a79d0cb4/asyncpg-0.30.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c902a60b52e506d38d7e80e0dd5399f657220f24635fee368117b8b5fce1142e", size = 673162, upload-time = "2024-10-20T00:29:41.88Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/eb/8b236663f06984f212a087b3e849731f917ab80f84450e943900e8ca4052/asyncpg-0.30.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:aca1548e43bbb9f0f627a04666fedaca23db0a31a84136ad1f868cb15deb6e3a", size = 637025, upload-time = "2024-10-20T00:29:43.352Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/57/2dc240bb263d58786cfaa60920779af6e8d32da63ab9ffc09f8312bd7a14/asyncpg-0.30.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6c2a2ef565400234a633da0eafdce27e843836256d40705d83ab7ec42074efb3", size = 3496243, upload-time = "2024-10-20T00:29:44.922Z" },
+ { url = "https://files.pythonhosted.org/packages/f4/40/0ae9d061d278b10713ea9021ef6b703ec44698fe32178715a501ac696c6b/asyncpg-0.30.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1292b84ee06ac8a2ad8e51c7475aa309245874b61333d97411aab835c4a2f737", size = 3575059, upload-time = "2024-10-20T00:29:46.891Z" },
+ { url = "https://files.pythonhosted.org/packages/c3/75/d6b895a35a2c6506952247640178e5f768eeb28b2e20299b6a6f1d743ba0/asyncpg-0.30.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:0f5712350388d0cd0615caec629ad53c81e506b1abaaf8d14c93f54b35e3595a", size = 3473596, upload-time = "2024-10-20T00:29:49.201Z" },
+ { url = "https://files.pythonhosted.org/packages/c8/e7/3693392d3e168ab0aebb2d361431375bd22ffc7b4a586a0fc060d519fae7/asyncpg-0.30.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:db9891e2d76e6f425746c5d2da01921e9a16b5a71a1c905b13f30e12a257c4af", size = 3641632, upload-time = "2024-10-20T00:29:50.768Z" },
+ { url = "https://files.pythonhosted.org/packages/32/ea/15670cea95745bba3f0352341db55f506a820b21c619ee66b7d12ea7867d/asyncpg-0.30.0-cp312-cp312-win32.whl", hash = "sha256:68d71a1be3d83d0570049cd1654a9bdfe506e794ecc98ad0873304a9f35e411e", size = 560186, upload-time = "2024-10-20T00:29:52.394Z" },
+ { url = "https://files.pythonhosted.org/packages/7e/6b/fe1fad5cee79ca5f5c27aed7bd95baee529c1bf8a387435c8ba4fe53d5c1/asyncpg-0.30.0-cp312-cp312-win_amd64.whl", hash = "sha256:9a0292c6af5c500523949155ec17b7fe01a00ace33b68a476d6b5059f9630305", size = 621064, upload-time = "2024-10-20T00:29:53.757Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/22/e20602e1218dc07692acf70d5b902be820168d6282e69ef0d3cb920dc36f/asyncpg-0.30.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:05b185ebb8083c8568ea8a40e896d5f7af4b8554b64d7719c0eaa1eb5a5c3a70", size = 670373, upload-time = "2024-10-20T00:29:55.165Z" },
+ { url = "https://files.pythonhosted.org/packages/3d/b3/0cf269a9d647852a95c06eb00b815d0b95a4eb4b55aa2d6ba680971733b9/asyncpg-0.30.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:c47806b1a8cbb0a0db896f4cd34d89942effe353a5035c62734ab13b9f938da3", size = 634745, upload-time = "2024-10-20T00:29:57.14Z" },
+ { url = "https://files.pythonhosted.org/packages/8e/6d/a4f31bf358ce8491d2a31bfe0d7bcf25269e80481e49de4d8616c4295a34/asyncpg-0.30.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9b6fde867a74e8c76c71e2f64f80c64c0f3163e687f1763cfaf21633ec24ec33", size = 3512103, upload-time = "2024-10-20T00:29:58.499Z" },
+ { url = "https://files.pythonhosted.org/packages/96/19/139227a6e67f407b9c386cb594d9628c6c78c9024f26df87c912fabd4368/asyncpg-0.30.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:46973045b567972128a27d40001124fbc821c87a6cade040cfcd4fa8a30bcdc4", size = 3592471, upload-time = "2024-10-20T00:30:00.354Z" },
+ { url = "https://files.pythonhosted.org/packages/67/e4/ab3ca38f628f53f0fd28d3ff20edff1c975dd1cb22482e0061916b4b9a74/asyncpg-0.30.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:9110df111cabc2ed81aad2f35394a00cadf4f2e0635603db6ebbd0fc896f46a4", size = 3496253, upload-time = "2024-10-20T00:30:02.794Z" },
+ { url = "https://files.pythonhosted.org/packages/ef/5f/0bf65511d4eeac3a1f41c54034a492515a707c6edbc642174ae79034d3ba/asyncpg-0.30.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:04ff0785ae7eed6cc138e73fc67b8e51d54ee7a3ce9b63666ce55a0bf095f7ba", size = 3662720, upload-time = "2024-10-20T00:30:04.501Z" },
+ { url = "https://files.pythonhosted.org/packages/e7/31/1513d5a6412b98052c3ed9158d783b1e09d0910f51fbe0e05f56cc370bc4/asyncpg-0.30.0-cp313-cp313-win32.whl", hash = "sha256:ae374585f51c2b444510cdf3595b97ece4f233fde739aa14b50e0d64e8a7a590", size = 560404, upload-time = "2024-10-20T00:30:06.537Z" },
+ { url = "https://files.pythonhosted.org/packages/c8/a4/cec76b3389c4c5ff66301cd100fe88c318563ec8a520e0b2e792b5b84972/asyncpg-0.30.0-cp313-cp313-win_amd64.whl", hash = "sha256:f59b430b8e27557c3fb9869222559f7417ced18688375825f8f12302c34e915e", size = 621623, upload-time = "2024-10-20T00:30:09.024Z" },
+]
+
+[[package]]
+name = "attrs"
+version = "25.3.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/5a/b0/1367933a8532ee6ff8d63537de4f1177af4bff9f3e829baf7331f595bb24/attrs-25.3.0.tar.gz", hash = "sha256:75d7cefc7fb576747b2c81b4442d4d4a1ce0900973527c011d1030fd3bf4af1b", size = 812032, upload-time = "2025-03-13T11:10:22.779Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", size = 63815, upload-time = "2025-03-13T11:10:21.14Z" },
+]
+
+[[package]]
+name = "authlib"
+version = "1.6.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cryptography" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/8e/a1/d8d1c6f8bc922c0b87ae0d933a8ed57be1bef6970894ed79c2852a153cd3/authlib-1.6.1.tar.gz", hash = "sha256:4dffdbb1460ba6ec8c17981a4c67af7d8af131231b5a36a88a1e8c80c111cdfd", size = 159988, upload-time = "2025-07-20T07:38:42.834Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/f9/58/cc6a08053f822f98f334d38a27687b69c6655fb05cd74a7a5e70a2aeed95/authlib-1.6.1-py2.py3-none-any.whl", hash = "sha256:e9d2031c34c6309373ab845afc24168fe9e93dc52d252631f52642f21f5ed06e", size = 239299, upload-time = "2025-07-20T07:38:39.259Z" },
+]
+
+[[package]]
+name = "azure-core"
+version = "1.35.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "requests" },
+ { name = "six" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ce/89/f53968635b1b2e53e4aad2dd641488929fef4ca9dfb0b97927fa7697ddf3/azure_core-1.35.0.tar.gz", hash = "sha256:c0be528489485e9ede59b6971eb63c1eaacf83ef53001bfe3904e475e972be5c", size = 339689, upload-time = "2025-07-03T00:55:23.496Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d4/78/bf94897361fdd650850f0f2e405b2293e2f12808239046232bdedf554301/azure_core-1.35.0-py3-none-any.whl", hash = "sha256:8db78c72868a58f3de8991eb4d22c4d368fae226dac1002998d6c50437e7dad1", size = 210708, upload-time = "2025-07-03T00:55:25.238Z" },
+]
+
+[[package]]
+name = "azure-datalake-store"
+version = "0.0.53"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cffi" },
+ { name = "msal" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/22/ff/61369d06422b5ac48067215ff404841342651b14a89b46c8d8e1507c8f17/azure-datalake-store-0.0.53.tar.gz", hash = "sha256:05b6de62ee3f2a0a6e6941e6933b792b800c3e7f6ffce2fc324bc19875757393", size = 71430, upload-time = "2023-05-10T21:17:05.665Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/88/2a/75f56b14f115189155cf12e46b366ad1fe3357af5a1a7c09f7446662d617/azure_datalake_store-0.0.53-py2.py3-none-any.whl", hash = "sha256:a30c902a6e360aa47d7f69f086b426729784e71c536f330b691647a51dc42b2b", size = 55308, upload-time = "2023-05-10T21:17:02.629Z" },
+]
+
+[[package]]
+name = "azure-identity"
+version = "1.24.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "azure-core" },
+ { name = "cryptography" },
+ { name = "msal" },
+ { name = "msal-extensions" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b5/44/f3ee20bacb220b6b4a2b0a6cf7e742eecb383a5ccf604dd79ec27c286b7e/azure_identity-1.24.0.tar.gz", hash = "sha256:6c3a40b2a70af831e920b89e6421e8dcd4af78a0cb38b9642d86c67643d4930c", size = 271630, upload-time = "2025-08-07T22:27:36.258Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a9/74/17428cb429e8d52f6d0d69ed685f4760a545cb0156594963a9337b53b6c9/azure_identity-1.24.0-py3-none-any.whl", hash = "sha256:9e04997cde0ab02ed66422c74748548e620b7b29361c72ce622acab0267ff7c4", size = 187890, upload-time = "2025-08-07T22:27:38.033Z" },
+]
+
+[[package]]
+name = "azure-storage-blob"
+version = "12.26.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "azure-core" },
+ { name = "cryptography" },
+ { name = "isodate" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/96/95/3e3414491ce45025a1cde107b6ae72bf72049e6021597c201cd6a3029b9a/azure_storage_blob-12.26.0.tar.gz", hash = "sha256:5dd7d7824224f7de00bfeb032753601c982655173061e242f13be6e26d78d71f", size = 583332, upload-time = "2025-07-16T21:34:07.644Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5b/64/63dbfdd83b31200ac58820a7951ddfdeed1fbee9285b0f3eae12d1357155/azure_storage_blob-12.26.0-py3-none-any.whl", hash = "sha256:8c5631b8b22b4f53ec5fff2f3bededf34cfef111e2af613ad42c9e6de00a77fe", size = 412907, upload-time = "2025-07-16T21:34:09.367Z" },
+]
+
+[[package]]
+name = "backoff"
+version = "2.2.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/47/d7/5bbeb12c44d7c4f2fb5b56abce497eb5ed9f34d85701de869acedd602619/backoff-2.2.1.tar.gz", hash = "sha256:03f829f5bb1923180821643f8753b0502c3b682293992485b0eef2807afa5cba", size = 17001, upload-time = "2022-10-05T19:19:32.061Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/df/73/b6e24bd22e6720ca8ee9a85a0c4a2971af8497d8f3193fa05390cbd46e09/backoff-2.2.1-py3-none-any.whl", hash = "sha256:63579f9a0628e06278f7e47b7d7d5b6ce20dc65c5e96a6f3ca99a6adca0396e8", size = 15148, upload-time = "2022-10-05T19:19:30.546Z" },
+]
+
+[[package]]
+name = "banks"
+version = "2.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "deprecated" },
+ { name = "griffe" },
+ { name = "jinja2" },
+ { name = "platformdirs" },
+ { name = "pydantic" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/7d/f8/25ef24814f77f3fd7f0fd3bd1ef3749e38a9dbd23502fbb53034de49900c/banks-2.2.0.tar.gz", hash = "sha256:d1446280ce6e00301e3e952dd754fd8cee23ff277d29ed160994a84d0d7ffe62", size = 179052, upload-time = "2025-07-18T16:28:26.892Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b4/d6/f9168956276934162ec8d48232f9920f2985ee45aa7602e3c6b4bc203613/banks-2.2.0-py3-none-any.whl", hash = "sha256:963cd5c85a587b122abde4f4064078def35c50c688c1b9d36f43c92503854e7d", size = 29244, upload-time = "2025-07-18T16:28:27.835Z" },
+]
+
+[[package]]
+name = "bcrypt"
+version = "4.3.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/bb/5d/6d7433e0f3cd46ce0b43cd65e1db465ea024dbb8216fb2404e919c2ad77b/bcrypt-4.3.0.tar.gz", hash = "sha256:3a3fd2204178b6d2adcf09cb4f6426ffef54762577a7c9b54c159008cb288c18", size = 25697, upload-time = "2025-02-28T01:24:09.174Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bf/2c/3d44e853d1fe969d229bd58d39ae6902b3d924af0e2b5a60d17d4b809ded/bcrypt-4.3.0-cp313-cp313t-macosx_10_12_universal2.whl", hash = "sha256:f01e060f14b6b57bbb72fc5b4a83ac21c443c9a2ee708e04a10e9192f90a6281", size = 483719, upload-time = "2025-02-28T01:22:34.539Z" },
+ { url = "https://files.pythonhosted.org/packages/a1/e2/58ff6e2a22eca2e2cff5370ae56dba29d70b1ea6fc08ee9115c3ae367795/bcrypt-4.3.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c5eeac541cefd0bb887a371ef73c62c3cd78535e4887b310626036a7c0a817bb", size = 272001, upload-time = "2025-02-28T01:22:38.078Z" },
+ { url = "https://files.pythonhosted.org/packages/37/1f/c55ed8dbe994b1d088309e366749633c9eb90d139af3c0a50c102ba68a1a/bcrypt-4.3.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:59e1aa0e2cd871b08ca146ed08445038f42ff75968c7ae50d2fdd7860ade2180", size = 277451, upload-time = "2025-02-28T01:22:40.787Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/1c/794feb2ecf22fe73dcfb697ea7057f632061faceb7dcf0f155f3443b4d79/bcrypt-4.3.0-cp313-cp313t-manylinux_2_28_aarch64.whl", hash = "sha256:0042b2e342e9ae3d2ed22727c1262f76cc4f345683b5c1715f0250cf4277294f", size = 272792, upload-time = "2025-02-28T01:22:43.144Z" },
+ { url = "https://files.pythonhosted.org/packages/13/b7/0b289506a3f3598c2ae2bdfa0ea66969812ed200264e3f61df77753eee6d/bcrypt-4.3.0-cp313-cp313t-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:74a8d21a09f5e025a9a23e7c0fd2c7fe8e7503e4d356c0a2c1486ba010619f09", size = 289752, upload-time = "2025-02-28T01:22:45.56Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/24/d0fb023788afe9e83cc118895a9f6c57e1044e7e1672f045e46733421fe6/bcrypt-4.3.0-cp313-cp313t-manylinux_2_28_x86_64.whl", hash = "sha256:0142b2cb84a009f8452c8c5a33ace5e3dfec4159e7735f5afe9a4d50a8ea722d", size = 277762, upload-time = "2025-02-28T01:22:47.023Z" },
+ { url = "https://files.pythonhosted.org/packages/e4/38/cde58089492e55ac4ef6c49fea7027600c84fd23f7520c62118c03b4625e/bcrypt-4.3.0-cp313-cp313t-manylinux_2_34_aarch64.whl", hash = "sha256:12fa6ce40cde3f0b899729dbd7d5e8811cb892d31b6f7d0334a1f37748b789fd", size = 272384, upload-time = "2025-02-28T01:22:49.221Z" },
+ { url = "https://files.pythonhosted.org/packages/de/6a/d5026520843490cfc8135d03012a413e4532a400e471e6188b01b2de853f/bcrypt-4.3.0-cp313-cp313t-manylinux_2_34_x86_64.whl", hash = "sha256:5bd3cca1f2aa5dbcf39e2aa13dd094ea181f48959e1071265de49cc2b82525af", size = 277329, upload-time = "2025-02-28T01:22:51.603Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/a3/4fc5255e60486466c389e28c12579d2829b28a527360e9430b4041df4cf9/bcrypt-4.3.0-cp313-cp313t-musllinux_1_1_aarch64.whl", hash = "sha256:335a420cfd63fc5bc27308e929bee231c15c85cc4c496610ffb17923abf7f231", size = 305241, upload-time = "2025-02-28T01:22:53.283Z" },
+ { url = "https://files.pythonhosted.org/packages/c7/15/2b37bc07d6ce27cc94e5b10fd5058900eb8fb11642300e932c8c82e25c4a/bcrypt-4.3.0-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:0e30e5e67aed0187a1764911af023043b4542e70a7461ad20e837e94d23e1d6c", size = 309617, upload-time = "2025-02-28T01:22:55.461Z" },
+ { url = "https://files.pythonhosted.org/packages/5f/1f/99f65edb09e6c935232ba0430c8c13bb98cb3194b6d636e61d93fe60ac59/bcrypt-4.3.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:3b8d62290ebefd49ee0b3ce7500f5dbdcf13b81402c05f6dafab9a1e1b27212f", size = 335751, upload-time = "2025-02-28T01:22:57.81Z" },
+ { url = "https://files.pythonhosted.org/packages/00/1b/b324030c706711c99769988fcb694b3cb23f247ad39a7823a78e361bdbb8/bcrypt-4.3.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:2ef6630e0ec01376f59a006dc72918b1bf436c3b571b80fa1968d775fa02fe7d", size = 355965, upload-time = "2025-02-28T01:22:59.181Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/dd/20372a0579dd915dfc3b1cd4943b3bca431866fcb1dfdfd7518c3caddea6/bcrypt-4.3.0-cp313-cp313t-win32.whl", hash = "sha256:7a4be4cbf241afee43f1c3969b9103a41b40bcb3a3f467ab19f891d9bc4642e4", size = 155316, upload-time = "2025-02-28T01:23:00.763Z" },
+ { url = "https://files.pythonhosted.org/packages/6d/52/45d969fcff6b5577c2bf17098dc36269b4c02197d551371c023130c0f890/bcrypt-4.3.0-cp313-cp313t-win_amd64.whl", hash = "sha256:5c1949bf259a388863ced887c7861da1df681cb2388645766c89fdfd9004c669", size = 147752, upload-time = "2025-02-28T01:23:02.908Z" },
+ { url = "https://files.pythonhosted.org/packages/11/22/5ada0b9af72b60cbc4c9a399fdde4af0feaa609d27eb0adc61607997a3fa/bcrypt-4.3.0-cp38-abi3-macosx_10_12_universal2.whl", hash = "sha256:f81b0ed2639568bf14749112298f9e4e2b28853dab50a8b357e31798686a036d", size = 498019, upload-time = "2025-02-28T01:23:05.838Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/8c/252a1edc598dc1ce57905be173328eda073083826955ee3c97c7ff5ba584/bcrypt-4.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:864f8f19adbe13b7de11ba15d85d4a428c7e2f344bac110f667676a0ff84924b", size = 279174, upload-time = "2025-02-28T01:23:07.274Z" },
+ { url = "https://files.pythonhosted.org/packages/29/5b/4547d5c49b85f0337c13929f2ccbe08b7283069eea3550a457914fc078aa/bcrypt-4.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3e36506d001e93bffe59754397572f21bb5dc7c83f54454c990c74a468cd589e", size = 283870, upload-time = "2025-02-28T01:23:09.151Z" },
+ { url = "https://files.pythonhosted.org/packages/be/21/7dbaf3fa1745cb63f776bb046e481fbababd7d344c5324eab47f5ca92dd2/bcrypt-4.3.0-cp38-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:842d08d75d9fe9fb94b18b071090220697f9f184d4547179b60734846461ed59", size = 279601, upload-time = "2025-02-28T01:23:11.461Z" },
+ { url = "https://files.pythonhosted.org/packages/6d/64/e042fc8262e971347d9230d9abbe70d68b0a549acd8611c83cebd3eaec67/bcrypt-4.3.0-cp38-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:7c03296b85cb87db865d91da79bf63d5609284fc0cab9472fdd8367bbd830753", size = 297660, upload-time = "2025-02-28T01:23:12.989Z" },
+ { url = "https://files.pythonhosted.org/packages/50/b8/6294eb84a3fef3b67c69b4470fcdd5326676806bf2519cda79331ab3c3a9/bcrypt-4.3.0-cp38-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:62f26585e8b219cdc909b6a0069efc5e4267e25d4a3770a364ac58024f62a761", size = 284083, upload-time = "2025-02-28T01:23:14.5Z" },
+ { url = "https://files.pythonhosted.org/packages/62/e6/baff635a4f2c42e8788fe1b1633911c38551ecca9a749d1052d296329da6/bcrypt-4.3.0-cp38-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:beeefe437218a65322fbd0069eb437e7c98137e08f22c4660ac2dc795c31f8bb", size = 279237, upload-time = "2025-02-28T01:23:16.686Z" },
+ { url = "https://files.pythonhosted.org/packages/39/48/46f623f1b0c7dc2e5de0b8af5e6f5ac4cc26408ac33f3d424e5ad8da4a90/bcrypt-4.3.0-cp38-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:97eea7408db3a5bcce4a55d13245ab3fa566e23b4c67cd227062bb49e26c585d", size = 283737, upload-time = "2025-02-28T01:23:18.897Z" },
+ { url = "https://files.pythonhosted.org/packages/49/8b/70671c3ce9c0fca4a6cc3cc6ccbaa7e948875a2e62cbd146e04a4011899c/bcrypt-4.3.0-cp38-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:191354ebfe305e84f344c5964c7cd5f924a3bfc5d405c75ad07f232b6dffb49f", size = 312741, upload-time = "2025-02-28T01:23:21.041Z" },
+ { url = "https://files.pythonhosted.org/packages/27/fb/910d3a1caa2d249b6040a5caf9f9866c52114d51523ac2fb47578a27faee/bcrypt-4.3.0-cp38-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:41261d64150858eeb5ff43c753c4b216991e0ae16614a308a15d909503617732", size = 316472, upload-time = "2025-02-28T01:23:23.183Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/cf/7cf3a05b66ce466cfb575dbbda39718d45a609daa78500f57fa9f36fa3c0/bcrypt-4.3.0-cp38-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:33752b1ba962ee793fa2b6321404bf20011fe45b9afd2a842139de3011898fef", size = 343606, upload-time = "2025-02-28T01:23:25.361Z" },
+ { url = "https://files.pythonhosted.org/packages/e3/b8/e970ecc6d7e355c0d892b7f733480f4aa8509f99b33e71550242cf0b7e63/bcrypt-4.3.0-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:50e6e80a4bfd23a25f5c05b90167c19030cf9f87930f7cb2eacb99f45d1c3304", size = 362867, upload-time = "2025-02-28T01:23:26.875Z" },
+ { url = "https://files.pythonhosted.org/packages/a9/97/8d3118efd8354c555a3422d544163f40d9f236be5b96c714086463f11699/bcrypt-4.3.0-cp38-abi3-win32.whl", hash = "sha256:67a561c4d9fb9465ec866177e7aebcad08fe23aaf6fbd692a6fab69088abfc51", size = 160589, upload-time = "2025-02-28T01:23:28.381Z" },
+ { url = "https://files.pythonhosted.org/packages/29/07/416f0b99f7f3997c69815365babbc2e8754181a4b1899d921b3c7d5b6f12/bcrypt-4.3.0-cp38-abi3-win_amd64.whl", hash = "sha256:584027857bc2843772114717a7490a37f68da563b3620f78a849bcb54dc11e62", size = 152794, upload-time = "2025-02-28T01:23:30.187Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/c1/3fa0e9e4e0bfd3fd77eb8b52ec198fd6e1fd7e9402052e43f23483f956dd/bcrypt-4.3.0-cp39-abi3-macosx_10_12_universal2.whl", hash = "sha256:0d3efb1157edebfd9128e4e46e2ac1a64e0c1fe46fb023158a407c7892b0f8c3", size = 498969, upload-time = "2025-02-28T01:23:31.945Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/d4/755ce19b6743394787fbd7dff6bf271b27ee9b5912a97242e3caf125885b/bcrypt-4.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:08bacc884fd302b611226c01014eca277d48f0a05187666bca23aac0dad6fe24", size = 279158, upload-time = "2025-02-28T01:23:34.161Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/5d/805ef1a749c965c46b28285dfb5cd272a7ed9fa971f970435a5133250182/bcrypt-4.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f6746e6fec103fcd509b96bacdfdaa2fbde9a553245dbada284435173a6f1aef", size = 284285, upload-time = "2025-02-28T01:23:35.765Z" },
+ { url = "https://files.pythonhosted.org/packages/ab/2b/698580547a4a4988e415721b71eb45e80c879f0fb04a62da131f45987b96/bcrypt-4.3.0-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:afe327968aaf13fc143a56a3360cb27d4ad0345e34da12c7290f1b00b8fe9a8b", size = 279583, upload-time = "2025-02-28T01:23:38.021Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/87/62e1e426418204db520f955ffd06f1efd389feca893dad7095bf35612eec/bcrypt-4.3.0-cp39-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:d9af79d322e735b1fc33404b5765108ae0ff232d4b54666d46730f8ac1a43676", size = 297896, upload-time = "2025-02-28T01:23:39.575Z" },
+ { url = "https://files.pythonhosted.org/packages/cb/c6/8fedca4c2ada1b6e889c52d2943b2f968d3427e5d65f595620ec4c06fa2f/bcrypt-4.3.0-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f1e3ffa1365e8702dc48c8b360fef8d7afeca482809c5e45e653af82ccd088c1", size = 284492, upload-time = "2025-02-28T01:23:40.901Z" },
+ { url = "https://files.pythonhosted.org/packages/4d/4d/c43332dcaaddb7710a8ff5269fcccba97ed3c85987ddaa808db084267b9a/bcrypt-4.3.0-cp39-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:3004df1b323d10021fda07a813fd33e0fd57bef0e9a480bb143877f6cba996fe", size = 279213, upload-time = "2025-02-28T01:23:42.653Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/7f/1e36379e169a7df3a14a1c160a49b7b918600a6008de43ff20d479e6f4b5/bcrypt-4.3.0-cp39-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:531457e5c839d8caea9b589a1bcfe3756b0547d7814e9ce3d437f17da75c32b0", size = 284162, upload-time = "2025-02-28T01:23:43.964Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/0a/644b2731194b0d7646f3210dc4d80c7fee3ecb3a1f791a6e0ae6bb8684e3/bcrypt-4.3.0-cp39-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:17a854d9a7a476a89dcef6c8bd119ad23e0f82557afbd2c442777a16408e614f", size = 312856, upload-time = "2025-02-28T01:23:46.011Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/62/2a871837c0bb6ab0c9a88bf54de0fc021a6a08832d4ea313ed92a669d437/bcrypt-4.3.0-cp39-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:6fb1fd3ab08c0cbc6826a2e0447610c6f09e983a281b919ed721ad32236b8b23", size = 316726, upload-time = "2025-02-28T01:23:47.575Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/a1/9898ea3faac0b156d457fd73a3cb9c2855c6fd063e44b8522925cdd8ce46/bcrypt-4.3.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:e965a9c1e9a393b8005031ff52583cedc15b7884fce7deb8b0346388837d6cfe", size = 343664, upload-time = "2025-02-28T01:23:49.059Z" },
+ { url = "https://files.pythonhosted.org/packages/40/f2/71b4ed65ce38982ecdda0ff20c3ad1b15e71949c78b2c053df53629ce940/bcrypt-4.3.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:79e70b8342a33b52b55d93b3a59223a844962bef479f6a0ea318ebbcadf71505", size = 363128, upload-time = "2025-02-28T01:23:50.399Z" },
+ { url = "https://files.pythonhosted.org/packages/11/99/12f6a58eca6dea4be992d6c681b7ec9410a1d9f5cf368c61437e31daa879/bcrypt-4.3.0-cp39-abi3-win32.whl", hash = "sha256:b4d4e57f0a63fd0b358eb765063ff661328f69a04494427265950c71b992a39a", size = 160598, upload-time = "2025-02-28T01:23:51.775Z" },
+ { url = "https://files.pythonhosted.org/packages/a9/cf/45fb5261ece3e6b9817d3d82b2f343a505fd58674a92577923bc500bd1aa/bcrypt-4.3.0-cp39-abi3-win_amd64.whl", hash = "sha256:e53e074b120f2877a35cc6c736b8eb161377caae8925c17688bd46ba56daaa5b", size = 152799, upload-time = "2025-02-28T01:23:53.139Z" },
+]
+
+[[package]]
+name = "beautifulsoup4"
+version = "4.13.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "soupsieve" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d8/e4/0c4c39e18fd76d6a628d4dd8da40543d136ce2d1752bd6eeeab0791f4d6b/beautifulsoup4-4.13.4.tar.gz", hash = "sha256:dbb3c4e1ceae6aefebdaf2423247260cd062430a410e38c66f2baa50a8437195", size = 621067, upload-time = "2025-04-15T17:05:13.836Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/50/cd/30110dc0ffcf3b131156077b90e9f60ed75711223f306da4db08eff8403b/beautifulsoup4-4.13.4-py3-none-any.whl", hash = "sha256:9bbbb14bfde9d79f38b8cd5f8c7c85f4b8f2523190ebed90e950a8dea4cb1c4b", size = 187285, upload-time = "2025-04-15T17:05:12.221Z" },
+]
+
+[[package]]
+name = "bidict"
+version = "0.23.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/9a/6e/026678aa5a830e07cd9498a05d3e7e650a4f56a42f267a53d22bcda1bdc9/bidict-0.23.1.tar.gz", hash = "sha256:03069d763bc387bbd20e7d49914e75fc4132a41937fa3405417e1a5a2d006d71", size = 29093, upload-time = "2024-02-18T19:09:05.748Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/99/37/e8730c3587a65eb5645d4aba2d27aae48e8003614d6aaf15dda67f702f1f/bidict-0.23.1-py3-none-any.whl", hash = "sha256:5dae8d4d79b552a71cbabc7deb25dfe8ce710b17ff41711e13010ead2abfc3e5", size = 32764, upload-time = "2024-02-18T19:09:04.156Z" },
+]
+
+[[package]]
+name = "billiard"
+version = "4.2.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/7c/58/1546c970afcd2a2428b1bfafecf2371d8951cc34b46701bea73f4280989e/billiard-4.2.1.tar.gz", hash = "sha256:12b641b0c539073fc8d3f5b8b7be998956665c4233c7c1fcd66a7e677c4fb36f", size = 155031, upload-time = "2024-09-21T13:40:22.491Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/30/da/43b15f28fe5f9e027b41c539abc5469052e9d48fd75f8ff094ba2a0ae767/billiard-4.2.1-py3-none-any.whl", hash = "sha256:40b59a4ac8806ba2c2369ea98d876bc6108b051c227baffd928c644d15d8f3cb", size = 86766, upload-time = "2024-09-21T13:40:20.188Z" },
+]
+
+[[package]]
+name = "black"
+version = "25.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "click" },
+ { name = "mypy-extensions" },
+ { name = "packaging" },
+ { name = "pathspec" },
+ { name = "platformdirs" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/94/49/26a7b0f3f35da4b5a65f081943b7bcd22d7002f5f0fb8098ec1ff21cb6ef/black-25.1.0.tar.gz", hash = "sha256:33496d5cd1222ad73391352b4ae8da15253c5de89b93a80b3e2c8d9a19ec2666", size = 649449, upload-time = "2025-01-29T04:15:40.373Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/83/71/3fe4741df7adf015ad8dfa082dd36c94ca86bb21f25608eb247b4afb15b2/black-25.1.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4b60580e829091e6f9238c848ea6750efed72140b91b048770b64e74fe04908b", size = 1650988, upload-time = "2025-01-29T05:37:16.707Z" },
+ { url = "https://files.pythonhosted.org/packages/13/f3/89aac8a83d73937ccd39bbe8fc6ac8860c11cfa0af5b1c96d081facac844/black-25.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1e2978f6df243b155ef5fa7e558a43037c3079093ed5d10fd84c43900f2d8ecc", size = 1453985, upload-time = "2025-01-29T05:37:18.273Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/22/b99efca33f1f3a1d2552c714b1e1b5ae92efac6c43e790ad539a163d1754/black-25.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3b48735872ec535027d979e8dcb20bf4f70b5ac75a8ea99f127c106a7d7aba9f", size = 1783816, upload-time = "2025-01-29T04:18:33.823Z" },
+ { url = "https://files.pythonhosted.org/packages/18/7e/a27c3ad3822b6f2e0e00d63d58ff6299a99a5b3aee69fa77cd4b0076b261/black-25.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:ea0213189960bda9cf99be5b8c8ce66bb054af5e9e861249cd23471bd7b0b3ba", size = 1440860, upload-time = "2025-01-29T04:19:12.944Z" },
+ { url = "https://files.pythonhosted.org/packages/98/87/0edf98916640efa5d0696e1abb0a8357b52e69e82322628f25bf14d263d1/black-25.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8f0b18a02996a836cc9c9c78e5babec10930862827b1b724ddfe98ccf2f2fe4f", size = 1650673, upload-time = "2025-01-29T05:37:20.574Z" },
+ { url = "https://files.pythonhosted.org/packages/52/e5/f7bf17207cf87fa6e9b676576749c6b6ed0d70f179a3d812c997870291c3/black-25.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:afebb7098bfbc70037a053b91ae8437c3857482d3a690fefc03e9ff7aa9a5fd3", size = 1453190, upload-time = "2025-01-29T05:37:22.106Z" },
+ { url = "https://files.pythonhosted.org/packages/e3/ee/adda3d46d4a9120772fae6de454c8495603c37c4c3b9c60f25b1ab6401fe/black-25.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:030b9759066a4ee5e5aca28c3c77f9c64789cdd4de8ac1df642c40b708be6171", size = 1782926, upload-time = "2025-01-29T04:18:58.564Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/64/94eb5f45dcb997d2082f097a3944cfc7fe87e071907f677e80788a2d7b7a/black-25.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:a22f402b410566e2d1c950708c77ebf5ebd5d0d88a6a2e87c86d9fb48afa0d18", size = 1442613, upload-time = "2025-01-29T04:19:27.63Z" },
+ { url = "https://files.pythonhosted.org/packages/09/71/54e999902aed72baf26bca0d50781b01838251a462612966e9fc4891eadd/black-25.1.0-py3-none-any.whl", hash = "sha256:95e8176dae143ba9097f351d174fdaf0ccd29efb414b362ae3fd72bf0f710717", size = 207646, upload-time = "2025-01-29T04:15:38.082Z" },
+]
+
+[[package]]
+name = "boto3"
+version = "1.36.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+ { name = "jmespath" },
+ { name = "s3transfer" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bf/04/0c6cea060653eee75f4348152dfc0aa0b241f7d1f99a530079ee44d61e4b/boto3-1.36.1.tar.gz", hash = "sha256:258ab77225a81d3cf3029c9afe9920cd9dec317689dfadec6f6f0a23130bb60a", size = 110959, upload-time = "2025-01-16T20:33:00.196Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2b/ed/464e1df3901fbfedd5a0786e551240216f0c867440fa6156595178227b3f/boto3-1.36.1-py3-none-any.whl", hash = "sha256:eb21380d73fec6645439c0d802210f72a0cdb3295b02953f246ff53f512faa8f", size = 139163, upload-time = "2025-01-16T20:32:57.462Z" },
+]
+
+[[package]]
+name = "botocore"
+version = "1.36.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "jmespath" },
+ { name = "python-dateutil" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/39/aa/556720b3ee9629b7c4366b5a0d9797a84e83a97f78435904cbb9bdc41939/botocore-1.36.1.tar.gz", hash = "sha256:f789a6f272b5b3d8f8756495019785e33868e5e00dd9662a3ee7959ac939bb12", size = 13498150, upload-time = "2025-01-16T20:32:35.989Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/be/bb/5431f12e2dadd881fd023fb57e7e3ab82f7b697c38dc837fc8d70cca51bd/botocore-1.36.1-py3-none-any.whl", hash = "sha256:dec513b4eb8a847d79bbefdcdd07040ed9d44c20b0001136f0890a03d595705a", size = 13297686, upload-time = "2025-01-16T20:32:31.584Z" },
+]
+
+[[package]]
+name = "boxfs"
+version = "0.2.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "boxsdk", extra = ["jwt"] },
+ { name = "fsspec" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/be/de/1c5e0faec600538f6a1d41c7ce7834cacddb2237923e30ddb225254b74b9/boxfs-0.2.1.tar.gz", hash = "sha256:c1889e12f53be3216b44f088237ac0f367a7a759a53b01b0c0edf2b3d694e50f", size = 9523, upload-time = "2023-08-23T19:24:35.233Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/86/bb/243d10169c8397051bad6bdd10beb2407fa490bfe01216f5fad09e066191/boxfs-0.2.1-py3-none-any.whl", hash = "sha256:ae796c30309bd5a02654fff9eddf1ed320356225568fad0e109e1942beaef72a", size = 9358, upload-time = "2023-08-23T19:24:34.066Z" },
+]
+
+[[package]]
+name = "boxsdk"
+version = "3.14.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "attrs" },
+ { name = "python-dateutil" },
+ { name = "requests" },
+ { name = "requests-toolbelt" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bf/d7/c1a95bb602d7f90a85a68d8e6f11954e50c255110d39e2167c7796252622/boxsdk-3.14.0.tar.gz", hash = "sha256:7918b1929368724662474fffa417fa0457a523d089b8185260efbedd28c4f9b1", size = 232630, upload-time = "2025-04-09T15:07:15.181Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4d/5d/4e15511e0f4f2f9fbbf4646a8d0e138e5c53a3d428f1724e7dc3c8acf556/boxsdk-3.14.0-py2.py3-none-any.whl", hash = "sha256:0314e2f172b050e98489955f2e9001263de79c3dd751e6feee19f2195fdf7c01", size = 141329, upload-time = "2025-04-09T15:07:13.295Z" },
+]
+
+[package.optional-dependencies]
+jwt = [
+ { name = "cryptography" },
+ { name = "pyjwt" },
+]
+
+[[package]]
+name = "cachetools"
+version = "5.5.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/6c/81/3747dad6b14fa2cf53fcf10548cf5aea6913e96fab41a3c198676f8948a5/cachetools-5.5.2.tar.gz", hash = "sha256:1a661caa9175d26759571b2e19580f9d6393969e5dfca11fdb1f947a23e640d4", size = 28380, upload-time = "2025-02-20T21:01:19.524Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/72/76/20fa66124dbe6be5cafeb312ece67de6b61dd91a0247d1ea13db4ebb33c2/cachetools-5.5.2-py3-none-any.whl", hash = "sha256:d26a22bcc62eb95c3beabd9f1ee5e820d3d2704fe2967cbe350e20c8ffcd3f0a", size = 10080, upload-time = "2025-02-20T21:01:16.647Z" },
+]
+
+[[package]]
+name = "celery"
+version = "5.5.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "billiard" },
+ { name = "click" },
+ { name = "click-didyoumean" },
+ { name = "click-plugins" },
+ { name = "click-repl" },
+ { name = "kombu" },
+ { name = "python-dateutil" },
+ { name = "vine" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bb/7d/6c289f407d219ba36d8b384b42489ebdd0c84ce9c413875a8aae0c85f35b/celery-5.5.3.tar.gz", hash = "sha256:6c972ae7968c2b5281227f01c3a3f984037d21c5129d07bf3550cc2afc6b10a5", size = 1667144, upload-time = "2025-06-01T11:08:12.563Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c9/af/0dcccc7fdcdf170f9a1585e5e96b6fb0ba1749ef6be8c89a6202284759bd/celery-5.5.3-py3-none-any.whl", hash = "sha256:0b5761a07057acee94694464ca482416b959568904c9dfa41ce8413a7d65d525", size = 438775, upload-time = "2025-06-01T11:08:09.94Z" },
+]
+
+[[package]]
+name = "certifi"
+version = "2025.8.3"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/dc/67/960ebe6bf230a96cda2e0abcf73af550ec4f090005363542f0765df162e0/certifi-2025.8.3.tar.gz", hash = "sha256:e564105f78ded564e3ae7c923924435e1daa7463faeab5bb932bc53ffae63407", size = 162386, upload-time = "2025-08-03T03:07:47.08Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl", hash = "sha256:f6c12493cfb1b06ba2ff328595af9350c65d6644968e5d3a2ffd78699af217a5", size = 161216, upload-time = "2025-08-03T03:07:45.777Z" },
+]
+
+[[package]]
+name = "cffi"
+version = "1.17.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pycparser" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/fc/97/c783634659c2920c3fc70419e3af40972dbaf758daa229a7d6ea6135c90d/cffi-1.17.1.tar.gz", hash = "sha256:1c39c6016c32bc48dd54561950ebd6836e1670f2ae46128f67cf49e789c52824", size = 516621, upload-time = "2024-09-04T20:45:21.852Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5a/84/e94227139ee5fb4d600a7a4927f322e1d4aea6fdc50bd3fca8493caba23f/cffi-1.17.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:805b4371bf7197c329fcb3ead37e710d1bca9da5d583f5073b799d5c5bd1eee4", size = 183178, upload-time = "2024-09-04T20:44:12.232Z" },
+ { url = "https://files.pythonhosted.org/packages/da/ee/fb72c2b48656111c4ef27f0f91da355e130a923473bf5ee75c5643d00cca/cffi-1.17.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:733e99bc2df47476e3848417c5a4540522f234dfd4ef3ab7fafdf555b082ec0c", size = 178840, upload-time = "2024-09-04T20:44:13.739Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/b6/db007700f67d151abadf508cbfd6a1884f57eab90b1bb985c4c8c02b0f28/cffi-1.17.1-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1257bdabf294dceb59f5e70c64a3e2f462c30c7ad68092d01bbbfb1c16b1ba36", size = 454803, upload-time = "2024-09-04T20:44:15.231Z" },
+ { url = "https://files.pythonhosted.org/packages/1a/df/f8d151540d8c200eb1c6fba8cd0dfd40904f1b0682ea705c36e6c2e97ab3/cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da95af8214998d77a98cc14e3a3bd00aa191526343078b530ceb0bd710fb48a5", size = 478850, upload-time = "2024-09-04T20:44:17.188Z" },
+ { url = "https://files.pythonhosted.org/packages/28/c0/b31116332a547fd2677ae5b78a2ef662dfc8023d67f41b2a83f7c2aa78b1/cffi-1.17.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d63afe322132c194cf832bfec0dc69a99fb9bb6bbd550f161a49e9e855cc78ff", size = 485729, upload-time = "2024-09-04T20:44:18.688Z" },
+ { url = "https://files.pythonhosted.org/packages/91/2b/9a1ddfa5c7f13cab007a2c9cc295b70fbbda7cb10a286aa6810338e60ea1/cffi-1.17.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f79fc4fc25f1c8698ff97788206bb3c2598949bfe0fef03d299eb1b5356ada99", size = 471256, upload-time = "2024-09-04T20:44:20.248Z" },
+ { url = "https://files.pythonhosted.org/packages/b2/d5/da47df7004cb17e4955df6a43d14b3b4ae77737dff8bf7f8f333196717bf/cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b62ce867176a75d03a665bad002af8e6d54644fad99a3c70905c543130e39d93", size = 479424, upload-time = "2024-09-04T20:44:21.673Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/ac/2a28bcf513e93a219c8a4e8e125534f4f6db03e3179ba1c45e949b76212c/cffi-1.17.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:386c8bf53c502fff58903061338ce4f4950cbdcb23e2902d86c0f722b786bbe3", size = 484568, upload-time = "2024-09-04T20:44:23.245Z" },
+ { url = "https://files.pythonhosted.org/packages/d4/38/ca8a4f639065f14ae0f1d9751e70447a261f1a30fa7547a828ae08142465/cffi-1.17.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4ceb10419a9adf4460ea14cfd6bc43d08701f0835e979bf821052f1805850fe8", size = 488736, upload-time = "2024-09-04T20:44:24.757Z" },
+ { url = "https://files.pythonhosted.org/packages/86/c5/28b2d6f799ec0bdecf44dced2ec5ed43e0eb63097b0f58c293583b406582/cffi-1.17.1-cp312-cp312-win32.whl", hash = "sha256:a08d7e755f8ed21095a310a693525137cfe756ce62d066e53f502a83dc550f65", size = 172448, upload-time = "2024-09-04T20:44:26.208Z" },
+ { url = "https://files.pythonhosted.org/packages/50/b9/db34c4755a7bd1cb2d1603ac3863f22bcecbd1ba29e5ee841a4bc510b294/cffi-1.17.1-cp312-cp312-win_amd64.whl", hash = "sha256:51392eae71afec0d0c8fb1a53b204dbb3bcabcb3c9b807eedf3e1e6ccf2de903", size = 181976, upload-time = "2024-09-04T20:44:27.578Z" },
+ { url = "https://files.pythonhosted.org/packages/8d/f8/dd6c246b148639254dad4d6803eb6a54e8c85c6e11ec9df2cffa87571dbe/cffi-1.17.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f3a2b4222ce6b60e2e8b337bb9596923045681d71e5a082783484d845390938e", size = 182989, upload-time = "2024-09-04T20:44:28.956Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/f1/672d303ddf17c24fc83afd712316fda78dc6fce1cd53011b839483e1ecc8/cffi-1.17.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0984a4925a435b1da406122d4d7968dd861c1385afe3b45ba82b750f229811e2", size = 178802, upload-time = "2024-09-04T20:44:30.289Z" },
+ { url = "https://files.pythonhosted.org/packages/0e/2d/eab2e858a91fdff70533cab61dcff4a1f55ec60425832ddfdc9cd36bc8af/cffi-1.17.1-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d01b12eeeb4427d3110de311e1774046ad344f5b1a7403101878976ecd7a10f3", size = 454792, upload-time = "2024-09-04T20:44:32.01Z" },
+ { url = "https://files.pythonhosted.org/packages/75/b2/fbaec7c4455c604e29388d55599b99ebcc250a60050610fadde58932b7ee/cffi-1.17.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:706510fe141c86a69c8ddc029c7910003a17353970cff3b904ff0686a5927683", size = 478893, upload-time = "2024-09-04T20:44:33.606Z" },
+ { url = "https://files.pythonhosted.org/packages/4f/b7/6e4a2162178bf1935c336d4da8a9352cccab4d3a5d7914065490f08c0690/cffi-1.17.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:de55b766c7aa2e2a3092c51e0483d700341182f08e67c63630d5b6f200bb28e5", size = 485810, upload-time = "2024-09-04T20:44:35.191Z" },
+ { url = "https://files.pythonhosted.org/packages/c7/8a/1d0e4a9c26e54746dc08c2c6c037889124d4f59dffd853a659fa545f1b40/cffi-1.17.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c59d6e989d07460165cc5ad3c61f9fd8f1b4796eacbd81cee78957842b834af4", size = 471200, upload-time = "2024-09-04T20:44:36.743Z" },
+ { url = "https://files.pythonhosted.org/packages/26/9f/1aab65a6c0db35f43c4d1b4f580e8df53914310afc10ae0397d29d697af4/cffi-1.17.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd398dbc6773384a17fe0d3e7eeb8d1a21c2200473ee6806bb5e6a8e62bb73dd", size = 479447, upload-time = "2024-09-04T20:44:38.492Z" },
+ { url = "https://files.pythonhosted.org/packages/5f/e4/fb8b3dd8dc0e98edf1135ff067ae070bb32ef9d509d6cb0f538cd6f7483f/cffi-1.17.1-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:3edc8d958eb099c634dace3c7e16560ae474aa3803a5df240542b305d14e14ed", size = 484358, upload-time = "2024-09-04T20:44:40.046Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/47/d7145bf2dc04684935d57d67dff9d6d795b2ba2796806bb109864be3a151/cffi-1.17.1-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:72e72408cad3d5419375fc87d289076ee319835bdfa2caad331e377589aebba9", size = 488469, upload-time = "2024-09-04T20:44:41.616Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/ee/f94057fa6426481d663b88637a9a10e859e492c73d0384514a17d78ee205/cffi-1.17.1-cp313-cp313-win32.whl", hash = "sha256:e03eab0a8677fa80d646b5ddece1cbeaf556c313dcfac435ba11f107ba117b5d", size = 172475, upload-time = "2024-09-04T20:44:43.733Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/fc/6a8cb64e5f0324877d503c854da15d76c1e50eb722e320b15345c4d0c6de/cffi-1.17.1-cp313-cp313-win_amd64.whl", hash = "sha256:f6a16c31041f09ead72d69f583767292f750d24913dadacf5756b966aacb3f1a", size = 182009, upload-time = "2024-09-04T20:44:45.309Z" },
+]
+
+[[package]]
+name = "charset-normalizer"
+version = "3.4.3"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/83/2d/5fd176ceb9b2fc619e63405525573493ca23441330fcdaee6bef9460e924/charset_normalizer-3.4.3.tar.gz", hash = "sha256:6fce4b8500244f6fcb71465d4a4930d132ba9ab8e71a7859e6a5d59851068d14", size = 122371, upload-time = "2025-08-09T07:57:28.46Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e9/5e/14c94999e418d9b87682734589404a25854d5f5d0408df68bc15b6ff54bb/charset_normalizer-3.4.3-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:e28e334d3ff134e88989d90ba04b47d84382a828c061d0d1027b1b12a62b39b1", size = 205655, upload-time = "2025-08-09T07:56:08.475Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/a8/c6ec5d389672521f644505a257f50544c074cf5fc292d5390331cd6fc9c3/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0cacf8f7297b0c4fcb74227692ca46b4a5852f8f4f24b3c766dd94a1075c4884", size = 146223, upload-time = "2025-08-09T07:56:09.708Z" },
+ { url = "https://files.pythonhosted.org/packages/fc/eb/a2ffb08547f4e1e5415fb69eb7db25932c52a52bed371429648db4d84fb1/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c6fd51128a41297f5409deab284fecbe5305ebd7e5a1f959bee1c054622b7018", size = 159366, upload-time = "2025-08-09T07:56:11.326Z" },
+ { url = "https://files.pythonhosted.org/packages/82/10/0fd19f20c624b278dddaf83b8464dcddc2456cb4b02bb902a6da126b87a1/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:3cfb2aad70f2c6debfbcb717f23b7eb55febc0bb23dcffc0f076009da10c6392", size = 157104, upload-time = "2025-08-09T07:56:13.014Z" },
+ { url = "https://files.pythonhosted.org/packages/16/ab/0233c3231af734f5dfcf0844aa9582d5a1466c985bbed6cedab85af9bfe3/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1606f4a55c0fd363d754049cdf400175ee96c992b1f8018b993941f221221c5f", size = 151830, upload-time = "2025-08-09T07:56:14.428Z" },
+ { url = "https://files.pythonhosted.org/packages/ae/02/e29e22b4e02839a0e4a06557b1999d0a47db3567e82989b5bb21f3fbbd9f/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:027b776c26d38b7f15b26a5da1044f376455fb3766df8fc38563b4efbc515154", size = 148854, upload-time = "2025-08-09T07:56:16.051Z" },
+ { url = "https://files.pythonhosted.org/packages/05/6b/e2539a0a4be302b481e8cafb5af8792da8093b486885a1ae4d15d452bcec/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:42e5088973e56e31e4fa58eb6bd709e42fc03799c11c42929592889a2e54c491", size = 160670, upload-time = "2025-08-09T07:56:17.314Z" },
+ { url = "https://files.pythonhosted.org/packages/31/e7/883ee5676a2ef217a40ce0bffcc3d0dfbf9e64cbcfbdf822c52981c3304b/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:cc34f233c9e71701040d772aa7490318673aa7164a0efe3172b2981218c26d93", size = 158501, upload-time = "2025-08-09T07:56:18.641Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/35/6525b21aa0db614cf8b5792d232021dca3df7f90a1944db934efa5d20bb1/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:320e8e66157cc4e247d9ddca8e21f427efc7a04bbd0ac8a9faf56583fa543f9f", size = 153173, upload-time = "2025-08-09T07:56:20.289Z" },
+ { url = "https://files.pythonhosted.org/packages/50/ee/f4704bad8201de513fdc8aac1cabc87e38c5818c93857140e06e772b5892/charset_normalizer-3.4.3-cp312-cp312-win32.whl", hash = "sha256:fb6fecfd65564f208cbf0fba07f107fb661bcd1a7c389edbced3f7a493f70e37", size = 99822, upload-time = "2025-08-09T07:56:21.551Z" },
+ { url = "https://files.pythonhosted.org/packages/39/f5/3b3836ca6064d0992c58c7561c6b6eee1b3892e9665d650c803bd5614522/charset_normalizer-3.4.3-cp312-cp312-win_amd64.whl", hash = "sha256:86df271bf921c2ee3818f0522e9a5b8092ca2ad8b065ece5d7d9d0e9f4849bcc", size = 107543, upload-time = "2025-08-09T07:56:23.115Z" },
+ { url = "https://files.pythonhosted.org/packages/65/ca/2135ac97709b400c7654b4b764daf5c5567c2da45a30cdd20f9eefe2d658/charset_normalizer-3.4.3-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:14c2a87c65b351109f6abfc424cab3927b3bdece6f706e4d12faaf3d52ee5efe", size = 205326, upload-time = "2025-08-09T07:56:24.721Z" },
+ { url = "https://files.pythonhosted.org/packages/71/11/98a04c3c97dd34e49c7d247083af03645ca3730809a5509443f3c37f7c99/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:41d1fc408ff5fdfb910200ec0e74abc40387bccb3252f3f27c0676731df2b2c8", size = 146008, upload-time = "2025-08-09T07:56:26.004Z" },
+ { url = "https://files.pythonhosted.org/packages/60/f5/4659a4cb3c4ec146bec80c32d8bb16033752574c20b1252ee842a95d1a1e/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:1bb60174149316da1c35fa5233681f7c0f9f514509b8e399ab70fea5f17e45c9", size = 159196, upload-time = "2025-08-09T07:56:27.25Z" },
+ { url = "https://files.pythonhosted.org/packages/86/9e/f552f7a00611f168b9a5865a1414179b2c6de8235a4fa40189f6f79a1753/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:30d006f98569de3459c2fc1f2acde170b7b2bd265dc1943e87e1a4efe1b67c31", size = 156819, upload-time = "2025-08-09T07:56:28.515Z" },
+ { url = "https://files.pythonhosted.org/packages/7e/95/42aa2156235cbc8fa61208aded06ef46111c4d3f0de233107b3f38631803/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:416175faf02e4b0810f1f38bcb54682878a4af94059a1cd63b8747244420801f", size = 151350, upload-time = "2025-08-09T07:56:29.716Z" },
+ { url = "https://files.pythonhosted.org/packages/c2/a9/3865b02c56f300a6f94fc631ef54f0a8a29da74fb45a773dfd3dcd380af7/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:6aab0f181c486f973bc7262a97f5aca3ee7e1437011ef0c2ec04b5a11d16c927", size = 148644, upload-time = "2025-08-09T07:56:30.984Z" },
+ { url = "https://files.pythonhosted.org/packages/77/d9/cbcf1a2a5c7d7856f11e7ac2d782aec12bdfea60d104e60e0aa1c97849dc/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:fdabf8315679312cfa71302f9bd509ded4f2f263fb5b765cf1433b39106c3cc9", size = 160468, upload-time = "2025-08-09T07:56:32.252Z" },
+ { url = "https://files.pythonhosted.org/packages/f6/42/6f45efee8697b89fda4d50580f292b8f7f9306cb2971d4b53f8914e4d890/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:bd28b817ea8c70215401f657edef3a8aa83c29d447fb0b622c35403780ba11d5", size = 158187, upload-time = "2025-08-09T07:56:33.481Z" },
+ { url = "https://files.pythonhosted.org/packages/70/99/f1c3bdcfaa9c45b3ce96f70b14f070411366fa19549c1d4832c935d8e2c3/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:18343b2d246dc6761a249ba1fb13f9ee9a2bcd95decc767319506056ea4ad4dc", size = 152699, upload-time = "2025-08-09T07:56:34.739Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/ad/b0081f2f99a4b194bcbb1934ef3b12aa4d9702ced80a37026b7607c72e58/charset_normalizer-3.4.3-cp313-cp313-win32.whl", hash = "sha256:6fb70de56f1859a3f71261cbe41005f56a7842cc348d3aeb26237560bfa5e0ce", size = 99580, upload-time = "2025-08-09T07:56:35.981Z" },
+ { url = "https://files.pythonhosted.org/packages/9a/8f/ae790790c7b64f925e5c953b924aaa42a243fb778fed9e41f147b2a5715a/charset_normalizer-3.4.3-cp313-cp313-win_amd64.whl", hash = "sha256:cf1ebb7d78e1ad8ec2a8c4732c7be2e736f6e5123a4146c5b89c9d1f585f8cef", size = 107366, upload-time = "2025-08-09T07:56:37.339Z" },
+ { url = "https://files.pythonhosted.org/packages/8e/91/b5a06ad970ddc7a0e513112d40113e834638f4ca1120eb727a249fb2715e/charset_normalizer-3.4.3-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:3cd35b7e8aedeb9e34c41385fda4f73ba609e561faedfae0a9e75e44ac558a15", size = 204342, upload-time = "2025-08-09T07:56:38.687Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/ec/1edc30a377f0a02689342f214455c3f6c2fbedd896a1d2f856c002fc3062/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b89bc04de1d83006373429975f8ef9e7932534b8cc9ca582e4db7d20d91816db", size = 145995, upload-time = "2025-08-09T07:56:40.048Z" },
+ { url = "https://files.pythonhosted.org/packages/17/e5/5e67ab85e6d22b04641acb5399c8684f4d37caf7558a53859f0283a650e9/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:2001a39612b241dae17b4687898843f254f8748b796a2e16f1051a17078d991d", size = 158640, upload-time = "2025-08-09T07:56:41.311Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/e5/38421987f6c697ee3722981289d554957c4be652f963d71c5e46a262e135/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:8dcfc373f888e4fb39a7bc57e93e3b845e7f462dacc008d9749568b1c4ece096", size = 156636, upload-time = "2025-08-09T07:56:43.195Z" },
+ { url = "https://files.pythonhosted.org/packages/a0/e4/5a075de8daa3ec0745a9a3b54467e0c2967daaaf2cec04c845f73493e9a1/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:18b97b8404387b96cdbd30ad660f6407799126d26a39ca65729162fd810a99aa", size = 150939, upload-time = "2025-08-09T07:56:44.819Z" },
+ { url = "https://files.pythonhosted.org/packages/02/f7/3611b32318b30974131db62b4043f335861d4d9b49adc6d57c1149cc49d4/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ccf600859c183d70eb47e05a44cd80a4ce77394d1ac0f79dbd2dd90a69a3a049", size = 148580, upload-time = "2025-08-09T07:56:46.684Z" },
+ { url = "https://files.pythonhosted.org/packages/7e/61/19b36f4bd67f2793ab6a99b979b4e4f3d8fc754cbdffb805335df4337126/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:53cd68b185d98dde4ad8990e56a58dea83a4162161b1ea9272e5c9182ce415e0", size = 159870, upload-time = "2025-08-09T07:56:47.941Z" },
+ { url = "https://files.pythonhosted.org/packages/06/57/84722eefdd338c04cf3030ada66889298eaedf3e7a30a624201e0cbe424a/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:30a96e1e1f865f78b030d65241c1ee850cdf422d869e9028e2fc1d5e4db73b92", size = 157797, upload-time = "2025-08-09T07:56:49.756Z" },
+ { url = "https://files.pythonhosted.org/packages/72/2a/aff5dd112b2f14bcc3462c312dce5445806bfc8ab3a7328555da95330e4b/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d716a916938e03231e86e43782ca7878fb602a125a91e7acb8b5112e2e96ac16", size = 152224, upload-time = "2025-08-09T07:56:51.369Z" },
+ { url = "https://files.pythonhosted.org/packages/b7/8c/9839225320046ed279c6e839d51f028342eb77c91c89b8ef2549f951f3ec/charset_normalizer-3.4.3-cp314-cp314-win32.whl", hash = "sha256:c6dbd0ccdda3a2ba7c2ecd9d77b37f3b5831687d8dc1b6ca5f56a4880cc7b7ce", size = 100086, upload-time = "2025-08-09T07:56:52.722Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/7a/36fbcf646e41f710ce0a563c1c9a343c6edf9be80786edeb15b6f62e17db/charset_normalizer-3.4.3-cp314-cp314-win_amd64.whl", hash = "sha256:73dc19b562516fc9bcf6e5d6e596df0b4eb98d87e4f79f3ae71840e6ed21361c", size = 107400, upload-time = "2025-08-09T07:56:55.172Z" },
+ { url = "https://files.pythonhosted.org/packages/8a/1f/f041989e93b001bc4e44bb1669ccdcf54d3f00e628229a85b08d330615c5/charset_normalizer-3.4.3-py3-none-any.whl", hash = "sha256:ce571ab16d890d23b5c278547ba694193a45011ff86a9162a71307ed9f86759a", size = 53175, upload-time = "2025-08-09T07:57:26.864Z" },
+]
+
+[[package]]
+name = "click"
+version = "8.2.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "colorama", marker = "sys_platform == 'win32'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/60/6c/8ca2efa64cf75a977a0d7fac081354553ebe483345c734fb6b6515d96bbc/click-8.2.1.tar.gz", hash = "sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202", size = 286342, upload-time = "2025-05-20T23:19:49.832Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl", hash = "sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b", size = 102215, upload-time = "2025-05-20T23:19:47.796Z" },
+]
+
+[[package]]
+name = "click-didyoumean"
+version = "0.3.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "click" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/30/ce/217289b77c590ea1e7c24242d9ddd6e249e52c795ff10fac2c50062c48cb/click_didyoumean-0.3.1.tar.gz", hash = "sha256:4f82fdff0dbe64ef8ab2279bd6aa3f6a99c3b28c05aa09cbfc07c9d7fbb5a463", size = 3089, upload-time = "2024-03-24T08:22:07.499Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/1b/5b/974430b5ffdb7a4f1941d13d83c64a0395114503cc357c6b9ae4ce5047ed/click_didyoumean-0.3.1-py3-none-any.whl", hash = "sha256:5c4bb6007cfea5f2fd6583a2fb6701a22a41eb98957e63d0fac41c10e7c3117c", size = 3631, upload-time = "2024-03-24T08:22:06.356Z" },
+]
+
+[[package]]
+name = "click-plugins"
+version = "1.1.1.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "click" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c3/a4/34847b59150da33690a36da3681d6bbc2ec14ee9a846bc30a6746e5984e4/click_plugins-1.1.1.2.tar.gz", hash = "sha256:d7af3984a99d243c131aa1a828331e7630f4a88a9741fd05c927b204bcf92261", size = 8343, upload-time = "2025-06-25T00:47:37.555Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3d/9a/2abecb28ae875e39c8cad711eb1186d8d14eab564705325e77e4e6ab9ae5/click_plugins-1.1.1.2-py2.py3-none-any.whl", hash = "sha256:008d65743833ffc1f5417bf0e78e8d2c23aab04d9745ba817bd3e71b0feb6aa6", size = 11051, upload-time = "2025-06-25T00:47:36.731Z" },
+]
+
+[[package]]
+name = "click-repl"
+version = "0.3.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "click" },
+ { name = "prompt-toolkit" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/cb/a2/57f4ac79838cfae6912f997b4d1a64a858fb0c86d7fcaae6f7b58d267fca/click-repl-0.3.0.tar.gz", hash = "sha256:17849c23dba3d667247dc4defe1757fff98694e90fe37474f3feebb69ced26a9", size = 10449, upload-time = "2023-06-15T12:43:51.141Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/52/40/9d857001228658f0d59e97ebd4c346fe73e138c6de1bce61dc568a57c7f8/click_repl-0.3.0-py3-none-any.whl", hash = "sha256:fb7e06deb8da8de86180a33a9da97ac316751c094c6899382da7feeeeb51b812", size = 10289, upload-time = "2023-06-15T12:43:48.626Z" },
+]
+
+[[package]]
+name = "colorama"
+version = "0.4.6"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
+]
+
+[[package]]
+name = "coverage"
+version = "7.10.3"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f4/2c/253cc41cd0f40b84c1c34c5363e0407d73d4a1cae005fed6db3b823175bd/coverage-7.10.3.tar.gz", hash = "sha256:812ba9250532e4a823b070b0420a36499859542335af3dca8f47fc6aa1a05619", size = 822936, upload-time = "2025-08-10T21:27:39.968Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b8/62/13c0b66e966c43d7aa64dadc8cd2afa1f5a2bf9bb863bdabc21fb94e8b63/coverage-7.10.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:449c1e2d3a84d18bd204258a897a87bc57380072eb2aded6a5b5226046207b42", size = 216262, upload-time = "2025-08-10T21:25:55.367Z" },
+ { url = "https://files.pythonhosted.org/packages/b5/f0/59fdf79be7ac2f0206fc739032f482cfd3f66b18f5248108ff192741beae/coverage-7.10.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1d4f9ce50b9261ad196dc2b2e9f1fbbee21651b54c3097a25ad783679fd18294", size = 216496, upload-time = "2025-08-10T21:25:56.759Z" },
+ { url = "https://files.pythonhosted.org/packages/34/b1/bc83788ba31bde6a0c02eb96bbc14b2d1eb083ee073beda18753fa2c4c66/coverage-7.10.3-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:4dd4564207b160d0d45c36a10bc0a3d12563028e8b48cd6459ea322302a156d7", size = 247989, upload-time = "2025-08-10T21:25:58.067Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/29/f8bdf88357956c844bd872e87cb16748a37234f7f48c721dc7e981145eb7/coverage-7.10.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:5ca3c9530ee072b7cb6a6ea7b640bcdff0ad3b334ae9687e521e59f79b1d0437", size = 250738, upload-time = "2025-08-10T21:25:59.406Z" },
+ { url = "https://files.pythonhosted.org/packages/ae/df/6396301d332b71e42bbe624670af9376f63f73a455cc24723656afa95796/coverage-7.10.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b6df359e59fa243c9925ae6507e27f29c46698359f45e568fd51b9315dbbe587", size = 251868, upload-time = "2025-08-10T21:26:00.65Z" },
+ { url = "https://files.pythonhosted.org/packages/91/21/d760b2df6139b6ef62c9cc03afb9bcdf7d6e36ed4d078baacffa618b4c1c/coverage-7.10.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:a181e4c2c896c2ff64c6312db3bda38e9ade2e1aa67f86a5628ae85873786cea", size = 249790, upload-time = "2025-08-10T21:26:02.009Z" },
+ { url = "https://files.pythonhosted.org/packages/69/91/5dcaa134568202397fa4023d7066d4318dc852b53b428052cd914faa05e1/coverage-7.10.3-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:a374d4e923814e8b72b205ef6b3d3a647bb50e66f3558582eda074c976923613", size = 247907, upload-time = "2025-08-10T21:26:03.757Z" },
+ { url = "https://files.pythonhosted.org/packages/38/ed/70c0e871cdfef75f27faceada461206c1cc2510c151e1ef8d60a6fedda39/coverage-7.10.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:daeefff05993e5e8c6e7499a8508e7bd94502b6b9a9159c84fd1fe6bce3151cb", size = 249344, upload-time = "2025-08-10T21:26:05.11Z" },
+ { url = "https://files.pythonhosted.org/packages/5f/55/c8a273ed503cedc07f8a00dcd843daf28e849f0972e4c6be4c027f418ad6/coverage-7.10.3-cp312-cp312-win32.whl", hash = "sha256:187ecdcac21f9636d570e419773df7bd2fda2e7fa040f812e7f95d0bddf5f79a", size = 218693, upload-time = "2025-08-10T21:26:06.534Z" },
+ { url = "https://files.pythonhosted.org/packages/94/58/dd3cfb2473b85be0b6eb8c5b6d80b6fc3f8f23611e69ef745cef8cf8bad5/coverage-7.10.3-cp312-cp312-win_amd64.whl", hash = "sha256:4a50ad2524ee7e4c2a95e60d2b0b83283bdfc745fe82359d567e4f15d3823eb5", size = 219501, upload-time = "2025-08-10T21:26:08.195Z" },
+ { url = "https://files.pythonhosted.org/packages/56/af/7cbcbf23d46de6f24246e3f76b30df099d05636b30c53c158a196f7da3ad/coverage-7.10.3-cp312-cp312-win_arm64.whl", hash = "sha256:c112f04e075d3495fa3ed2200f71317da99608cbb2e9345bdb6de8819fc30571", size = 218135, upload-time = "2025-08-10T21:26:09.584Z" },
+ { url = "https://files.pythonhosted.org/packages/0a/ff/239e4de9cc149c80e9cc359fab60592365b8c4cbfcad58b8a939d18c6898/coverage-7.10.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:b99e87304ffe0eb97c5308447328a584258951853807afdc58b16143a530518a", size = 216298, upload-time = "2025-08-10T21:26:10.973Z" },
+ { url = "https://files.pythonhosted.org/packages/56/da/28717da68f8ba68f14b9f558aaa8f3e39ada8b9a1ae4f4977c8f98b286d5/coverage-7.10.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:4af09c7574d09afbc1ea7da9dcea23665c01f3bc1b1feb061dac135f98ffc53a", size = 216546, upload-time = "2025-08-10T21:26:12.616Z" },
+ { url = "https://files.pythonhosted.org/packages/de/bb/e1ade16b9e3f2d6c323faeb6bee8e6c23f3a72760a5d9af102ef56a656cb/coverage-7.10.3-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:488e9b50dc5d2aa9521053cfa706209e5acf5289e81edc28291a24f4e4488f46", size = 247538, upload-time = "2025-08-10T21:26:14.455Z" },
+ { url = "https://files.pythonhosted.org/packages/ea/2f/6ae1db51dc34db499bfe340e89f79a63bd115fc32513a7bacdf17d33cd86/coverage-7.10.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:913ceddb4289cbba3a310704a424e3fb7aac2bc0c3a23ea473193cb290cf17d4", size = 250141, upload-time = "2025-08-10T21:26:15.787Z" },
+ { url = "https://files.pythonhosted.org/packages/4f/ed/33efd8819895b10c66348bf26f011dd621e804866c996ea6893d682218df/coverage-7.10.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b1f91cbc78c7112ab84ed2a8defbccd90f888fcae40a97ddd6466b0bec6ae8a", size = 251415, upload-time = "2025-08-10T21:26:17.535Z" },
+ { url = "https://files.pythonhosted.org/packages/26/04/cb83826f313d07dc743359c9914d9bc460e0798da9a0e38b4f4fabc207ed/coverage-7.10.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:b0bac054d45af7cd938834b43a9878b36ea92781bcb009eab040a5b09e9927e3", size = 249575, upload-time = "2025-08-10T21:26:18.921Z" },
+ { url = "https://files.pythonhosted.org/packages/2d/fd/ae963c7a8e9581c20fa4355ab8940ca272554d8102e872dbb932a644e410/coverage-7.10.3-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:fe72cbdd12d9e0f4aca873fa6d755e103888a7f9085e4a62d282d9d5b9f7928c", size = 247466, upload-time = "2025-08-10T21:26:20.263Z" },
+ { url = "https://files.pythonhosted.org/packages/99/e8/b68d1487c6af370b8d5ef223c6d7e250d952c3acfbfcdbf1a773aa0da9d2/coverage-7.10.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:c1e2e927ab3eadd7c244023927d646e4c15c65bb2ac7ae3c3e9537c013700d21", size = 249084, upload-time = "2025-08-10T21:26:21.638Z" },
+ { url = "https://files.pythonhosted.org/packages/66/4d/a0bcb561645c2c1e21758d8200443669d6560d2a2fb03955291110212ec4/coverage-7.10.3-cp313-cp313-win32.whl", hash = "sha256:24d0c13de473b04920ddd6e5da3c08831b1170b8f3b17461d7429b61cad59ae0", size = 218735, upload-time = "2025-08-10T21:26:23.009Z" },
+ { url = "https://files.pythonhosted.org/packages/6a/c3/78b4adddbc0feb3b223f62761e5f9b4c5a758037aaf76e0a5845e9e35e48/coverage-7.10.3-cp313-cp313-win_amd64.whl", hash = "sha256:3564aae76bce4b96e2345cf53b4c87e938c4985424a9be6a66ee902626edec4c", size = 219531, upload-time = "2025-08-10T21:26:24.474Z" },
+ { url = "https://files.pythonhosted.org/packages/70/1b/1229c0b2a527fa5390db58d164aa896d513a1fbb85a1b6b6676846f00552/coverage-7.10.3-cp313-cp313-win_arm64.whl", hash = "sha256:f35580f19f297455f44afcd773c9c7a058e52eb6eb170aa31222e635f2e38b87", size = 218162, upload-time = "2025-08-10T21:26:25.847Z" },
+ { url = "https://files.pythonhosted.org/packages/fc/26/1c1f450e15a3bf3eaecf053ff64538a2612a23f05b21d79ce03be9ff5903/coverage-7.10.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:07009152f497a0464ffdf2634586787aea0e69ddd023eafb23fc38267db94b84", size = 217003, upload-time = "2025-08-10T21:26:27.231Z" },
+ { url = "https://files.pythonhosted.org/packages/29/96/4b40036181d8c2948454b458750960956a3c4785f26a3c29418bbbee1666/coverage-7.10.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:8dd2ba5f0c7e7e8cc418be2f0c14c4d9e3f08b8fb8e4c0f83c2fe87d03eb655e", size = 217238, upload-time = "2025-08-10T21:26:28.83Z" },
+ { url = "https://files.pythonhosted.org/packages/62/23/8dfc52e95da20957293fb94d97397a100e63095ec1e0ef5c09dd8c6f591a/coverage-7.10.3-cp313-cp313t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:1ae22b97003c74186e034a93e4f946c75fad8c0ce8d92fbbc168b5e15ee2841f", size = 258561, upload-time = "2025-08-10T21:26:30.475Z" },
+ { url = "https://files.pythonhosted.org/packages/59/95/00e7fcbeda3f632232f4c07dde226afe3511a7781a000aa67798feadc535/coverage-7.10.3-cp313-cp313t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:eb329f1046888a36b1dc35504d3029e1dd5afe2196d94315d18c45ee380f67d5", size = 260735, upload-time = "2025-08-10T21:26:32.333Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/4c/f4666cbc4571804ba2a65b078ff0de600b0b577dc245389e0bc9b69ae7ca/coverage-7.10.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ce01048199a91f07f96ca3074b0c14021f4fe7ffd29a3e6a188ac60a5c3a4af8", size = 262960, upload-time = "2025-08-10T21:26:33.701Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/a5/8a9e8a7b12a290ed98b60f73d1d3e5e9ced75a4c94a0d1a671ce3ddfff2a/coverage-7.10.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:08b989a06eb9dfacf96d42b7fb4c9a22bafa370d245dc22fa839f2168c6f9fa1", size = 260515, upload-time = "2025-08-10T21:26:35.16Z" },
+ { url = "https://files.pythonhosted.org/packages/86/11/bb59f7f33b2cac0c5b17db0d9d0abba9c90d9eda51a6e727b43bd5fce4ae/coverage-7.10.3-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:669fe0d4e69c575c52148511029b722ba8d26e8a3129840c2ce0522e1452b256", size = 258278, upload-time = "2025-08-10T21:26:36.539Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/22/3646f8903743c07b3e53fded0700fed06c580a980482f04bf9536657ac17/coverage-7.10.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:3262d19092771c83f3413831d9904b1ccc5f98da5de4ffa4ad67f5b20c7aaf7b", size = 259408, upload-time = "2025-08-10T21:26:37.954Z" },
+ { url = "https://files.pythonhosted.org/packages/d2/5c/6375e9d905da22ddea41cd85c30994b8b6f6c02e44e4c5744b76d16b026f/coverage-7.10.3-cp313-cp313t-win32.whl", hash = "sha256:cc0ee4b2ccd42cab7ee6be46d8a67d230cb33a0a7cd47a58b587a7063b6c6b0e", size = 219396, upload-time = "2025-08-10T21:26:39.426Z" },
+ { url = "https://files.pythonhosted.org/packages/33/3b/7da37fd14412b8c8b6e73c3e7458fef6b1b05a37f990a9776f88e7740c89/coverage-7.10.3-cp313-cp313t-win_amd64.whl", hash = "sha256:03db599f213341e2960430984e04cf35fb179724e052a3ee627a068653cf4a7c", size = 220458, upload-time = "2025-08-10T21:26:40.905Z" },
+ { url = "https://files.pythonhosted.org/packages/28/cc/59a9a70f17edab513c844ee7a5c63cf1057041a84cc725b46a51c6f8301b/coverage-7.10.3-cp313-cp313t-win_arm64.whl", hash = "sha256:46eae7893ba65f53c71284585a262f083ef71594f05ec5c85baf79c402369098", size = 218722, upload-time = "2025-08-10T21:26:42.362Z" },
+ { url = "https://files.pythonhosted.org/packages/2d/84/bb773b51a06edbf1231b47dc810a23851f2796e913b335a0fa364773b842/coverage-7.10.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:bce8b8180912914032785850d8f3aacb25ec1810f5f54afc4a8b114e7a9b55de", size = 216280, upload-time = "2025-08-10T21:26:44.132Z" },
+ { url = "https://files.pythonhosted.org/packages/92/a8/4d8ca9c111d09865f18d56facff64d5fa076a5593c290bd1cfc5dceb8dba/coverage-7.10.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:07790b4b37d56608536f7c1079bd1aa511567ac2966d33d5cec9cf520c50a7c8", size = 216557, upload-time = "2025-08-10T21:26:45.598Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/b2/eb668bfc5060194bc5e1ccd6f664e8e045881cfee66c42a2aa6e6c5b26e8/coverage-7.10.3-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:e79367ef2cd9166acedcbf136a458dfe9a4a2dd4d1ee95738fb2ee581c56f667", size = 247598, upload-time = "2025-08-10T21:26:47.081Z" },
+ { url = "https://files.pythonhosted.org/packages/fd/b0/9faa4ac62c8822219dd83e5d0e73876398af17d7305968aed8d1606d1830/coverage-7.10.3-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:419d2a0f769f26cb1d05e9ccbc5eab4cb5d70231604d47150867c07822acbdf4", size = 250131, upload-time = "2025-08-10T21:26:48.65Z" },
+ { url = "https://files.pythonhosted.org/packages/4e/90/203537e310844d4bf1bdcfab89c1e05c25025c06d8489b9e6f937ad1a9e2/coverage-7.10.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ee221cf244757cdc2ac882e3062ab414b8464ad9c884c21e878517ea64b3fa26", size = 251485, upload-time = "2025-08-10T21:26:50.368Z" },
+ { url = "https://files.pythonhosted.org/packages/b9/b2/9d894b26bc53c70a1fe503d62240ce6564256d6d35600bdb86b80e516e7d/coverage-7.10.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c2079d8cdd6f7373d628e14b3357f24d1db02c9dc22e6a007418ca7a2be0435a", size = 249488, upload-time = "2025-08-10T21:26:52.045Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/28/af167dbac5281ba6c55c933a0ca6675d68347d5aee39cacc14d44150b922/coverage-7.10.3-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:bd8df1f83c0703fa3ca781b02d36f9ec67ad9cb725b18d486405924f5e4270bd", size = 247419, upload-time = "2025-08-10T21:26:53.533Z" },
+ { url = "https://files.pythonhosted.org/packages/f4/1c/9a4ddc9f0dcb150d4cd619e1c4bb39bcf694c6129220bdd1e5895d694dda/coverage-7.10.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:6b4e25e0fa335c8aa26e42a52053f3786a61cc7622b4d54ae2dad994aa754fec", size = 248917, upload-time = "2025-08-10T21:26:55.11Z" },
+ { url = "https://files.pythonhosted.org/packages/92/27/c6a60c7cbe10dbcdcd7fc9ee89d531dc04ea4c073800279bb269954c5a9f/coverage-7.10.3-cp314-cp314-win32.whl", hash = "sha256:d7c3d02c2866deb217dce664c71787f4b25420ea3eaf87056f44fb364a3528f5", size = 218999, upload-time = "2025-08-10T21:26:56.637Z" },
+ { url = "https://files.pythonhosted.org/packages/36/09/a94c1369964ab31273576615d55e7d14619a1c47a662ed3e2a2fe4dee7d4/coverage-7.10.3-cp314-cp314-win_amd64.whl", hash = "sha256:9c8916d44d9e0fe6cdb2227dc6b0edd8bc6c8ef13438bbbf69af7482d9bb9833", size = 219801, upload-time = "2025-08-10T21:26:58.207Z" },
+ { url = "https://files.pythonhosted.org/packages/23/59/f5cd2a80f401c01cf0f3add64a7b791b7d53fd6090a4e3e9ea52691cf3c4/coverage-7.10.3-cp314-cp314-win_arm64.whl", hash = "sha256:1007d6a2b3cf197c57105cc1ba390d9ff7f0bee215ced4dea530181e49c65ab4", size = 218381, upload-time = "2025-08-10T21:26:59.707Z" },
+ { url = "https://files.pythonhosted.org/packages/73/3d/89d65baf1ea39e148ee989de6da601469ba93c1d905b17dfb0b83bd39c96/coverage-7.10.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:ebc8791d346410d096818788877d675ca55c91db87d60e8f477bd41c6970ffc6", size = 217019, upload-time = "2025-08-10T21:27:01.242Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/7d/d9850230cd9c999ce3a1e600f85c2fff61a81c301334d7a1faa1a5ba19c8/coverage-7.10.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1f4e4d8e75f6fd3c6940ebeed29e3d9d632e1f18f6fb65d33086d99d4d073241", size = 217237, upload-time = "2025-08-10T21:27:03.442Z" },
+ { url = "https://files.pythonhosted.org/packages/36/51/b87002d417202ab27f4a1cd6bd34ee3b78f51b3ddbef51639099661da991/coverage-7.10.3-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:24581ed69f132b6225a31b0228ae4885731cddc966f8a33fe5987288bdbbbd5e", size = 258735, upload-time = "2025-08-10T21:27:05.124Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/02/1f8612bfcb46fc7ca64a353fff1cd4ed932bb6e0b4e0bb88b699c16794b8/coverage-7.10.3-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:ec151569ddfccbf71bac8c422dce15e176167385a00cd86e887f9a80035ce8a5", size = 260901, upload-time = "2025-08-10T21:27:06.68Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/3a/fe39e624ddcb2373908bd922756384bb70ac1c5009b0d1674eb326a3e428/coverage-7.10.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:2ae8e7c56290b908ee817200c0b65929b8050bc28530b131fe7c6dfee3e7d86b", size = 263157, upload-time = "2025-08-10T21:27:08.398Z" },
+ { url = "https://files.pythonhosted.org/packages/5e/89/496b6d5a10fa0d0691a633bb2b2bcf4f38f0bdfcbde21ad9e32d1af328ed/coverage-7.10.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5fb742309766d7e48e9eb4dc34bc95a424707bc6140c0e7d9726e794f11b92a0", size = 260597, upload-time = "2025-08-10T21:27:10.237Z" },
+ { url = "https://files.pythonhosted.org/packages/b6/a6/8b5bf6a9e8c6aaeb47d5fe9687014148efc05c3588110246d5fdeef9b492/coverage-7.10.3-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:c65e2a5b32fbe1e499f1036efa6eb9cb4ea2bf6f7168d0e7a5852f3024f471b1", size = 258353, upload-time = "2025-08-10T21:27:11.773Z" },
+ { url = "https://files.pythonhosted.org/packages/c3/6d/ad131be74f8afd28150a07565dfbdc86592fd61d97e2dc83383d9af219f0/coverage-7.10.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:d48d2cb07d50f12f4f18d2bb75d9d19e3506c26d96fffabf56d22936e5ed8f7c", size = 259504, upload-time = "2025-08-10T21:27:13.254Z" },
+ { url = "https://files.pythonhosted.org/packages/ec/30/fc9b5097092758cba3375a8cc4ff61774f8cd733bcfb6c9d21a60077a8d8/coverage-7.10.3-cp314-cp314t-win32.whl", hash = "sha256:dec0d9bc15ee305e09fe2cd1911d3f0371262d3cfdae05d79515d8cb712b4869", size = 219782, upload-time = "2025-08-10T21:27:14.736Z" },
+ { url = "https://files.pythonhosted.org/packages/72/9b/27fbf79451b1fac15c4bda6ec6e9deae27cf7c0648c1305aa21a3454f5c4/coverage-7.10.3-cp314-cp314t-win_amd64.whl", hash = "sha256:424ea93a323aa0f7f01174308ea78bde885c3089ec1bef7143a6d93c3e24ef64", size = 220898, upload-time = "2025-08-10T21:27:16.297Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/cf/a32bbf92869cbf0b7c8b84325327bfc718ad4b6d2c63374fef3d58e39306/coverage-7.10.3-cp314-cp314t-win_arm64.whl", hash = "sha256:f5983c132a62d93d71c9ef896a0b9bf6e6828d8d2ea32611f58684fba60bba35", size = 218922, upload-time = "2025-08-10T21:27:18.22Z" },
+ { url = "https://files.pythonhosted.org/packages/84/19/e67f4ae24e232c7f713337f3f4f7c9c58afd0c02866fb07c7b9255a19ed7/coverage-7.10.3-py3-none-any.whl", hash = "sha256:416a8d74dc0adfd33944ba2f405897bab87b7e9e84a391e09d241956bd953ce1", size = 207921, upload-time = "2025-08-10T21:27:38.254Z" },
+]
+
+[[package]]
+name = "cryptography"
+version = "45.0.6"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cffi", marker = "platform_python_implementation != 'PyPy'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d6/0d/d13399c94234ee8f3df384819dc67e0c5ce215fb751d567a55a1f4b028c7/cryptography-45.0.6.tar.gz", hash = "sha256:5c966c732cf6e4a276ce83b6e4c729edda2df6929083a952cc7da973c539c719", size = 744949, upload-time = "2025-08-05T23:59:27.93Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/8c/29/2793d178d0eda1ca4a09a7c4e09a5185e75738cc6d526433e8663b460ea6/cryptography-45.0.6-cp311-abi3-macosx_10_9_universal2.whl", hash = "sha256:048e7ad9e08cf4c0ab07ff7f36cc3115924e22e2266e034450a890d9e312dd74", size = 7042702, upload-time = "2025-08-05T23:58:23.464Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/b6/cabd07410f222f32c8d55486c464f432808abaa1f12af9afcbe8f2f19030/cryptography-45.0.6-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:44647c5d796f5fc042bbc6d61307d04bf29bccb74d188f18051b635f20a9c75f", size = 4206483, upload-time = "2025-08-05T23:58:27.132Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/9e/f9c7d36a38b1cfeb1cc74849aabe9bf817990f7603ff6eb485e0d70e0b27/cryptography-45.0.6-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:e40b80ecf35ec265c452eea0ba94c9587ca763e739b8e559c128d23bff7ebbbf", size = 4429679, upload-time = "2025-08-05T23:58:29.152Z" },
+ { url = "https://files.pythonhosted.org/packages/9c/2a/4434c17eb32ef30b254b9e8b9830cee4e516f08b47fdd291c5b1255b8101/cryptography-45.0.6-cp311-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:00e8724bdad672d75e6f069b27970883179bd472cd24a63f6e620ca7e41cc0c5", size = 4210553, upload-time = "2025-08-05T23:58:30.596Z" },
+ { url = "https://files.pythonhosted.org/packages/ef/1d/09a5df8e0c4b7970f5d1f3aff1b640df6d4be28a64cae970d56c6cf1c772/cryptography-45.0.6-cp311-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:7a3085d1b319d35296176af31c90338eeb2ddac8104661df79f80e1d9787b8b2", size = 3894499, upload-time = "2025-08-05T23:58:32.03Z" },
+ { url = "https://files.pythonhosted.org/packages/79/62/120842ab20d9150a9d3a6bdc07fe2870384e82f5266d41c53b08a3a96b34/cryptography-45.0.6-cp311-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:1b7fa6a1c1188c7ee32e47590d16a5a0646270921f8020efc9a511648e1b2e08", size = 4458484, upload-time = "2025-08-05T23:58:33.526Z" },
+ { url = "https://files.pythonhosted.org/packages/fd/80/1bc3634d45ddfed0871bfba52cf8f1ad724761662a0c792b97a951fb1b30/cryptography-45.0.6-cp311-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:275ba5cc0d9e320cd70f8e7b96d9e59903c815ca579ab96c1e37278d231fc402", size = 4210281, upload-time = "2025-08-05T23:58:35.445Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/fe/ffb12c2d83d0ee625f124880a1f023b5878f79da92e64c37962bbbe35f3f/cryptography-45.0.6-cp311-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:f4028f29a9f38a2025abedb2e409973709c660d44319c61762202206ed577c42", size = 4456890, upload-time = "2025-08-05T23:58:36.923Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/8e/b3f3fe0dc82c77a0deb5f493b23311e09193f2268b77196ec0f7a36e3f3e/cryptography-45.0.6-cp311-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:ee411a1b977f40bd075392c80c10b58025ee5c6b47a822a33c1198598a7a5f05", size = 4333247, upload-time = "2025-08-05T23:58:38.781Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/a6/c3ef2ab9e334da27a1d7b56af4a2417d77e7806b2e0f90d6267ce120d2e4/cryptography-45.0.6-cp311-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:e2a21a8eda2d86bb604934b6b37691585bd095c1f788530c1fcefc53a82b3453", size = 4565045, upload-time = "2025-08-05T23:58:40.415Z" },
+ { url = "https://files.pythonhosted.org/packages/31/c3/77722446b13fa71dddd820a5faab4ce6db49e7e0bf8312ef4192a3f78e2f/cryptography-45.0.6-cp311-abi3-win32.whl", hash = "sha256:d063341378d7ee9c91f9d23b431a3502fc8bfacd54ef0a27baa72a0843b29159", size = 2928923, upload-time = "2025-08-05T23:58:41.919Z" },
+ { url = "https://files.pythonhosted.org/packages/38/63/a025c3225188a811b82932a4dcc8457a26c3729d81578ccecbcce2cb784e/cryptography-45.0.6-cp311-abi3-win_amd64.whl", hash = "sha256:833dc32dfc1e39b7376a87b9a6a4288a10aae234631268486558920029b086ec", size = 3403805, upload-time = "2025-08-05T23:58:43.792Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/af/bcfbea93a30809f126d51c074ee0fac5bd9d57d068edf56c2a73abedbea4/cryptography-45.0.6-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:3436128a60a5e5490603ab2adbabc8763613f638513ffa7d311c900a8349a2a0", size = 7020111, upload-time = "2025-08-05T23:58:45.316Z" },
+ { url = "https://files.pythonhosted.org/packages/98/c6/ea5173689e014f1a8470899cd5beeb358e22bb3cf5a876060f9d1ca78af4/cryptography-45.0.6-cp37-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0d9ef57b6768d9fa58e92f4947cea96ade1233c0e236db22ba44748ffedca394", size = 4198169, upload-time = "2025-08-05T23:58:47.121Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/73/b12995edc0c7e2311ffb57ebd3b351f6b268fed37d93bfc6f9856e01c473/cryptography-45.0.6-cp37-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ea3c42f2016a5bbf71825537c2ad753f2870191134933196bee408aac397b3d9", size = 4421273, upload-time = "2025-08-05T23:58:48.557Z" },
+ { url = "https://files.pythonhosted.org/packages/f7/6e/286894f6f71926bc0da67408c853dd9ba953f662dcb70993a59fd499f111/cryptography-45.0.6-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:20ae4906a13716139d6d762ceb3e0e7e110f7955f3bc3876e3a07f5daadec5f3", size = 4199211, upload-time = "2025-08-05T23:58:50.139Z" },
+ { url = "https://files.pythonhosted.org/packages/de/34/a7f55e39b9623c5cb571d77a6a90387fe557908ffc44f6872f26ca8ae270/cryptography-45.0.6-cp37-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:2dac5ec199038b8e131365e2324c03d20e97fe214af051d20c49db129844e8b3", size = 3883732, upload-time = "2025-08-05T23:58:52.253Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/b9/c6d32edbcba0cd9f5df90f29ed46a65c4631c4fbe11187feb9169c6ff506/cryptography-45.0.6-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:18f878a34b90d688982e43f4b700408b478102dd58b3e39de21b5ebf6509c301", size = 4450655, upload-time = "2025-08-05T23:58:53.848Z" },
+ { url = "https://files.pythonhosted.org/packages/77/2d/09b097adfdee0227cfd4c699b3375a842080f065bab9014248933497c3f9/cryptography-45.0.6-cp37-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:5bd6020c80c5b2b2242d6c48487d7b85700f5e0038e67b29d706f98440d66eb5", size = 4198956, upload-time = "2025-08-05T23:58:55.209Z" },
+ { url = "https://files.pythonhosted.org/packages/55/66/061ec6689207d54effdff535bbdf85cc380d32dd5377173085812565cf38/cryptography-45.0.6-cp37-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:eccddbd986e43014263eda489abbddfbc287af5cddfd690477993dbb31e31016", size = 4449859, upload-time = "2025-08-05T23:58:56.639Z" },
+ { url = "https://files.pythonhosted.org/packages/41/ff/e7d5a2ad2d035e5a2af116e1a3adb4d8fcd0be92a18032917a089c6e5028/cryptography-45.0.6-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:550ae02148206beb722cfe4ef0933f9352bab26b087af00e48fdfb9ade35c5b3", size = 4320254, upload-time = "2025-08-05T23:58:58.833Z" },
+ { url = "https://files.pythonhosted.org/packages/82/27/092d311af22095d288f4db89fcaebadfb2f28944f3d790a4cf51fe5ddaeb/cryptography-45.0.6-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:5b64e668fc3528e77efa51ca70fadcd6610e8ab231e3e06ae2bab3b31c2b8ed9", size = 4554815, upload-time = "2025-08-05T23:59:00.283Z" },
+ { url = "https://files.pythonhosted.org/packages/7e/01/aa2f4940262d588a8fdf4edabe4cda45854d00ebc6eaac12568b3a491a16/cryptography-45.0.6-cp37-abi3-win32.whl", hash = "sha256:780c40fb751c7d2b0c6786ceee6b6f871e86e8718a8ff4bc35073ac353c7cd02", size = 2912147, upload-time = "2025-08-05T23:59:01.716Z" },
+ { url = "https://files.pythonhosted.org/packages/0a/bc/16e0276078c2de3ceef6b5a34b965f4436215efac45313df90d55f0ba2d2/cryptography-45.0.6-cp37-abi3-win_amd64.whl", hash = "sha256:20d15aed3ee522faac1a39fbfdfee25d17b1284bafd808e1640a74846d7c4d1b", size = 3390459, upload-time = "2025-08-05T23:59:03.358Z" },
+]
+
+[[package]]
+name = "dataclasses-json"
+version = "0.6.7"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "marshmallow" },
+ { name = "typing-inspect" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/64/a4/f71d9cf3a5ac257c993b5ca3f93df5f7fb395c725e7f1e6479d2514173c3/dataclasses_json-0.6.7.tar.gz", hash = "sha256:b6b3e528266ea45b9535223bc53ca645f5208833c29229e847b3f26a1cc55fc0", size = 32227, upload-time = "2024-06-09T16:20:19.103Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c3/be/d0d44e092656fe7a06b55e6103cbce807cdbdee17884a5367c68c9860853/dataclasses_json-0.6.7-py3-none-any.whl", hash = "sha256:0dbf33f26c8d5305befd61b39d2b3414e8a407bedc2834dea9b8d642666fb40a", size = 28686, upload-time = "2024-06-09T16:20:16.715Z" },
+]
+
+[[package]]
+name = "decorator"
+version = "5.2.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/43/fa/6d96a0978d19e17b68d634497769987b16c8f4cd0a7a05048bec693caa6b/decorator-5.2.1.tar.gz", hash = "sha256:65f266143752f734b0a7cc83c46f4618af75b8c5911b00ccb61d0ac9b6da0360", size = 56711, upload-time = "2025-02-24T04:41:34.073Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4e/8c/f3147f5c4b73e7550fe5f9352eaa956ae838d5c51eb58e7a25b9f3e2643b/decorator-5.2.1-py3-none-any.whl", hash = "sha256:d316bb415a2d9e2d2b3abcc4084c6502fc09240e292cd76a76afc106a1c8e04a", size = 9190, upload-time = "2025-02-24T04:41:32.565Z" },
+]
+
+[[package]]
+name = "defusedxml"
+version = "0.7.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0f/d5/c66da9b79e5bdb124974bfe172b4daf3c984ebd9c2a06e2b8a4dc7331c72/defusedxml-0.7.1.tar.gz", hash = "sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69", size = 75520, upload-time = "2021-03-08T10:59:26.269Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/07/6c/aa3f2f849e01cb6a001cd8554a88d4c77c5c1a31c95bdf1cf9301e6d9ef4/defusedxml-0.7.1-py2.py3-none-any.whl", hash = "sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61", size = 25604, upload-time = "2021-03-08T10:59:24.45Z" },
+]
+
+[[package]]
+name = "deprecated"
+version = "1.2.18"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "wrapt" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/98/97/06afe62762c9a8a86af0cfb7bfdab22a43ad17138b07af5b1a58442690a2/deprecated-1.2.18.tar.gz", hash = "sha256:422b6f6d859da6f2ef57857761bfb392480502a64c3028ca9bbe86085d72115d", size = 2928744, upload-time = "2025-01-27T10:46:25.7Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6e/c6/ac0b6c1e2d138f1002bcf799d330bd6d85084fece321e662a14223794041/Deprecated-1.2.18-py2.py3-none-any.whl", hash = "sha256:bd5011788200372a32418f888e326a09ff80d0214bd961147cfed01b5c018eec", size = 9998, upload-time = "2025-01-27T10:46:09.186Z" },
+]
+
+[[package]]
+name = "deprecation"
+version = "2.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "packaging" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/5a/d3/8ae2869247df154b64c1884d7346d412fed0c49df84db635aab2d1c40e62/deprecation-2.1.0.tar.gz", hash = "sha256:72b3bde64e5d778694b0cf68178aed03d15e15477116add3fb773e581f9518ff", size = 173788, upload-time = "2020-04-20T14:23:38.738Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/02/c3/253a89ee03fc9b9682f1541728eb66db7db22148cd94f89ab22528cd1e1b/deprecation-2.1.0-py2.py3-none-any.whl", hash = "sha256:a10811591210e1fb0e768a8c25517cabeabcba6f0bf96564f8ff45189f90b14a", size = 11178, upload-time = "2020-04-20T14:23:36.581Z" },
+]
+
+[[package]]
+name = "dirtyjson"
+version = "1.0.8"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/db/04/d24f6e645ad82ba0ef092fa17d9ef7a21953781663648a01c9371d9e8e98/dirtyjson-1.0.8.tar.gz", hash = "sha256:90ca4a18f3ff30ce849d100dcf4a003953c79d3a2348ef056f1d9c22231a25fd", size = 30782, upload-time = "2022-11-28T23:32:33.319Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/68/69/1bcf70f81de1b4a9f21b3a62ec0c83bdff991c88d6cc2267d02408457e88/dirtyjson-1.0.8-py3-none-any.whl", hash = "sha256:125e27248435a58acace26d5c2c4c11a1c0de0a9c5124c5a94ba78e517d74f53", size = 25197, upload-time = "2022-11-28T23:32:31.219Z" },
+]
+
+[[package]]
+name = "distro"
+version = "1.9.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/fc/f8/98eea607f65de6527f8a2e8885fc8015d3e6f5775df186e443e0964a11c3/distro-1.9.0.tar.gz", hash = "sha256:2fa77c6fd8940f116ee1d6b94a2f90b13b5ea8d019b98bc8bafdcabcdd9bdbed", size = 60722, upload-time = "2023-12-24T09:54:32.31Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277, upload-time = "2023-12-24T09:54:30.421Z" },
+]
+
+[[package]]
+name = "docker"
+version = "6.1.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "packaging" },
+ { name = "pywin32", marker = "sys_platform == 'win32'" },
+ { name = "requests" },
+ { name = "urllib3" },
+ { name = "websocket-client" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f0/73/f7c9a14e88e769f38cb7fb45aa88dfd795faa8e18aea11bababf6e068d5e/docker-6.1.3.tar.gz", hash = "sha256:aa6d17830045ba5ef0168d5eaa34d37beeb113948c413affe1d5991fc11f9a20", size = 259301, upload-time = "2023-06-01T14:24:49.268Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/db/be/3032490fa33b36ddc8c4b1da3252c6f974e7133f1a50de00c6b85cca203a/docker-6.1.3-py3-none-any.whl", hash = "sha256:aecd2277b8bf8e506e484f6ab7aec39abe0038e29fa4a6d3ba86c3fe01844ed9", size = 148096, upload-time = "2023-06-01T14:24:47.769Z" },
+]
+
+[[package]]
+name = "docstring-parser"
+version = "0.17.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/b2/9d/c3b43da9515bd270df0f80548d9944e389870713cc1fe2b8fb35fe2bcefd/docstring_parser-0.17.0.tar.gz", hash = "sha256:583de4a309722b3315439bb31d64ba3eebada841f2e2cee23b99df001434c912", size = 27442, upload-time = "2025-07-21T07:35:01.868Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/55/e2/2537ebcff11c1ee1ff17d8d0b6f4db75873e3b0fb32c2d4a2ee31ecb310a/docstring_parser-0.17.0-py3-none-any.whl", hash = "sha256:cf2569abd23dce8099b300f9b4fa8191e9582dda731fd533daf54c4551658708", size = 36896, upload-time = "2025-07-21T07:35:00.684Z" },
+]
+
+[[package]]
+name = "dropbox"
+version = "12.0.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "requests" },
+ { name = "six" },
+ { name = "stone" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/9e/56/ac085f58e8e0d0bcafdf98c2605e454ac946e3d0c72679669ae112dc30be/dropbox-12.0.2.tar.gz", hash = "sha256:50057fd5ad5fcf047f542dfc6747a896e7ef982f1b5f8500daf51f3abd609962", size = 560236, upload-time = "2024-06-03T16:45:30.448Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2d/de/95d8204d9a20fbdb353c5f8e4229b0fcb90f22b96f8246ff1f47c8a45fd5/dropbox-12.0.2-py3-none-any.whl", hash = "sha256:c5b7e9c2668adb6b12dcecd84342565dc50f7d35ab6a748d155cb79040979d1c", size = 572076, upload-time = "2024-06-03T16:45:28.153Z" },
+]
+
+[[package]]
+name = "dropboxdrivefs"
+version = "1.4.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "dropbox" },
+ { name = "fsspec" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/97/15/6d8f4c3033ad2bc364b8bb613c52c96653f2268f32ecff4f3ab5f1d7c19b/dropboxdrivefs-1.4.1.tar.gz", hash = "sha256:6f3c6061d045813553ce91ed0e2b682f1d70bec74011943c92b3181faacefd34", size = 7413, upload-time = "2024-05-27T14:04:37.648Z" }
+
+[[package]]
+name = "eval-type-backport"
+version = "0.2.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/30/ea/8b0ac4469d4c347c6a385ff09dc3c048c2d021696664e26c7ee6791631b5/eval_type_backport-0.2.2.tar.gz", hash = "sha256:f0576b4cf01ebb5bd358d02314d31846af5e07678387486e2c798af0e7d849c1", size = 9079, upload-time = "2024-12-21T20:09:46.005Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ce/31/55cd413eaccd39125368be33c46de24a1f639f2e12349b0361b4678f3915/eval_type_backport-0.2.2-py3-none-any.whl", hash = "sha256:cb6ad7c393517f476f96d456d0412ea80f0a8cf96f6892834cd9340149111b0a", size = 5830, upload-time = "2024-12-21T20:09:44.175Z" },
+]
+
+[[package]]
+name = "factory-boy"
+version = "3.3.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "faker" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ba/98/75cacae9945f67cfe323829fc2ac451f64517a8a330b572a06a323997065/factory_boy-3.3.3.tar.gz", hash = "sha256:866862d226128dfac7f2b4160287e899daf54f2612778327dd03d0e2cb1e3d03", size = 164146, upload-time = "2025-02-03T09:49:04.433Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/27/8d/2bc5f5546ff2ccb3f7de06742853483ab75bf74f36a92254702f8baecc79/factory_boy-3.3.3-py2.py3-none-any.whl", hash = "sha256:1c39e3289f7e667c4285433f305f8d506efc2fe9c73aaea4151ebd5cdea394fc", size = 37036, upload-time = "2025-02-03T09:49:01.659Z" },
+]
+
+[[package]]
+name = "faker"
+version = "37.5.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "tzdata" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ce/5d/7797a74e8e31fa227f0303239802c5f09b6722bdb6638359e7b6c8f30004/faker-37.5.3.tar.gz", hash = "sha256:8315d8ff4d6f4f588bd42ffe63abd599886c785073e26a44707e10eeba5713dc", size = 1907147, upload-time = "2025-07-30T15:52:19.528Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4b/bf/d06dd96e7afa72069dbdd26ed0853b5e8bd7941e2c0819a9b21d6e6fc052/faker-37.5.3-py3-none-any.whl", hash = "sha256:386fe9d5e6132a915984bf887fcebcc72d6366a25dd5952905b31b141a17016d", size = 1949261, upload-time = "2025-07-30T15:52:17.729Z" },
+]
+
+[[package]]
+name = "filelock"
+version = "3.18.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0a/10/c23352565a6544bdc5353e0b15fc1c563352101f30e24bf500207a54df9a/filelock-3.18.0.tar.gz", hash = "sha256:adbc88eabb99d2fec8c9c1b229b171f18afa655400173ddc653d5d01501fb9f2", size = 18075, upload-time = "2025-03-14T07:11:40.47Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4d/36/2a115987e2d8c300a974597416d9de88f2444426de9571f4b59b2cca3acc/filelock-3.18.0-py3-none-any.whl", hash = "sha256:c401f4f8377c4464e6db25fff06205fd89bdd83b65eb0488ed1b160f780e21de", size = 16215, upload-time = "2025-03-14T07:11:39.145Z" },
+]
+
+[[package]]
+name = "filetype"
+version = "1.2.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/bb/29/745f7d30d47fe0f251d3ad3dc2978a23141917661998763bebb6da007eb1/filetype-1.2.0.tar.gz", hash = "sha256:66b56cd6474bf41d8c54660347d37afcc3f7d1970648de365c102ef77548aadb", size = 998020, upload-time = "2022-11-02T17:34:04.141Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/18/79/1b8fa1bb3568781e84c9200f951c735f3f157429f44be0495da55894d620/filetype-1.2.0-py2.py3-none-any.whl", hash = "sha256:7ce71b6880181241cf7ac8697a2f1eb6a8bd9b429f7ad6d27b8db9ba5f1c2d25", size = 19970, upload-time = "2022-11-02T17:34:01.425Z" },
+]
+
+[[package]]
+name = "flake8"
+version = "7.3.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "mccabe" },
+ { name = "pycodestyle" },
+ { name = "pyflakes" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/9b/af/fbfe3c4b5a657d79e5c47a2827a362f9e1b763336a52f926126aa6dc7123/flake8-7.3.0.tar.gz", hash = "sha256:fe044858146b9fc69b551a4b490d69cf960fcb78ad1edcb84e7fbb1b4a8e3872", size = 48326, upload-time = "2025-06-20T19:31:35.838Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/9f/56/13ab06b4f93ca7cac71078fbe37fcea175d3216f31f85c3168a6bbd0bb9a/flake8-7.3.0-py2.py3-none-any.whl", hash = "sha256:b9696257b9ce8beb888cdbe31cf885c90d31928fe202be0889a7cdafad32f01e", size = 57922, upload-time = "2025-06-20T19:31:34.425Z" },
+]
+
+[[package]]
+name = "frozenlist"
+version = "1.7.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/79/b1/b64018016eeb087db503b038296fd782586432b9c077fc5c7839e9cb6ef6/frozenlist-1.7.0.tar.gz", hash = "sha256:2e310d81923c2437ea8670467121cc3e9b0f76d3043cc1d2331d56c7fb7a3a8f", size = 45078, upload-time = "2025-06-09T23:02:35.538Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ef/a2/c8131383f1e66adad5f6ecfcce383d584ca94055a34d683bbb24ac5f2f1c/frozenlist-1.7.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:3dbf9952c4bb0e90e98aec1bd992b3318685005702656bc6f67c1a32b76787f2", size = 81424, upload-time = "2025-06-09T23:00:42.24Z" },
+ { url = "https://files.pythonhosted.org/packages/4c/9d/02754159955088cb52567337d1113f945b9e444c4960771ea90eb73de8db/frozenlist-1.7.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:1f5906d3359300b8a9bb194239491122e6cf1444c2efb88865426f170c262cdb", size = 47952, upload-time = "2025-06-09T23:00:43.481Z" },
+ { url = "https://files.pythonhosted.org/packages/01/7a/0046ef1bd6699b40acd2067ed6d6670b4db2f425c56980fa21c982c2a9db/frozenlist-1.7.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:3dabd5a8f84573c8d10d8859a50ea2dec01eea372031929871368c09fa103478", size = 46688, upload-time = "2025-06-09T23:00:44.793Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/a2/a910bafe29c86997363fb4c02069df4ff0b5bc39d33c5198b4e9dd42d8f8/frozenlist-1.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aa57daa5917f1738064f302bf2626281a1cb01920c32f711fbc7bc36111058a8", size = 243084, upload-time = "2025-06-09T23:00:46.125Z" },
+ { url = "https://files.pythonhosted.org/packages/64/3e/5036af9d5031374c64c387469bfcc3af537fc0f5b1187d83a1cf6fab1639/frozenlist-1.7.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c193dda2b6d49f4c4398962810fa7d7c78f032bf45572b3e04dd5249dff27e08", size = 233524, upload-time = "2025-06-09T23:00:47.73Z" },
+ { url = "https://files.pythonhosted.org/packages/06/39/6a17b7c107a2887e781a48ecf20ad20f1c39d94b2a548c83615b5b879f28/frozenlist-1.7.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:bfe2b675cf0aaa6d61bf8fbffd3c274b3c9b7b1623beb3809df8a81399a4a9c4", size = 248493, upload-time = "2025-06-09T23:00:49.742Z" },
+ { url = "https://files.pythonhosted.org/packages/be/00/711d1337c7327d88c44d91dd0f556a1c47fb99afc060ae0ef66b4d24793d/frozenlist-1.7.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8fc5d5cda37f62b262405cf9652cf0856839c4be8ee41be0afe8858f17f4c94b", size = 244116, upload-time = "2025-06-09T23:00:51.352Z" },
+ { url = "https://files.pythonhosted.org/packages/24/fe/74e6ec0639c115df13d5850e75722750adabdc7de24e37e05a40527ca539/frozenlist-1.7.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b0d5ce521d1dd7d620198829b87ea002956e4319002ef0bc8d3e6d045cb4646e", size = 224557, upload-time = "2025-06-09T23:00:52.855Z" },
+ { url = "https://files.pythonhosted.org/packages/8d/db/48421f62a6f77c553575201e89048e97198046b793f4a089c79a6e3268bd/frozenlist-1.7.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:488d0a7d6a0008ca0db273c542098a0fa9e7dfaa7e57f70acef43f32b3f69dca", size = 241820, upload-time = "2025-06-09T23:00:54.43Z" },
+ { url = "https://files.pythonhosted.org/packages/1d/fa/cb4a76bea23047c8462976ea7b7a2bf53997a0ca171302deae9d6dd12096/frozenlist-1.7.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:15a7eaba63983d22c54d255b854e8108e7e5f3e89f647fc854bd77a237e767df", size = 236542, upload-time = "2025-06-09T23:00:56.409Z" },
+ { url = "https://files.pythonhosted.org/packages/5d/32/476a4b5cfaa0ec94d3f808f193301debff2ea42288a099afe60757ef6282/frozenlist-1.7.0-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:1eaa7e9c6d15df825bf255649e05bd8a74b04a4d2baa1ae46d9c2d00b2ca2cb5", size = 249350, upload-time = "2025-06-09T23:00:58.468Z" },
+ { url = "https://files.pythonhosted.org/packages/8d/ba/9a28042f84a6bf8ea5dbc81cfff8eaef18d78b2a1ad9d51c7bc5b029ad16/frozenlist-1.7.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:e4389e06714cfa9d47ab87f784a7c5be91d3934cd6e9a7b85beef808297cc025", size = 225093, upload-time = "2025-06-09T23:01:00.015Z" },
+ { url = "https://files.pythonhosted.org/packages/bc/29/3a32959e68f9cf000b04e79ba574527c17e8842e38c91d68214a37455786/frozenlist-1.7.0-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:73bd45e1488c40b63fe5a7df892baf9e2a4d4bb6409a2b3b78ac1c6236178e01", size = 245482, upload-time = "2025-06-09T23:01:01.474Z" },
+ { url = "https://files.pythonhosted.org/packages/80/e8/edf2f9e00da553f07f5fa165325cfc302dead715cab6ac8336a5f3d0adc2/frozenlist-1.7.0-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:99886d98e1643269760e5fe0df31e5ae7050788dd288947f7f007209b8c33f08", size = 249590, upload-time = "2025-06-09T23:01:02.961Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/80/9a0eb48b944050f94cc51ee1c413eb14a39543cc4f760ed12657a5a3c45a/frozenlist-1.7.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:290a172aae5a4c278c6da8a96222e6337744cd9c77313efe33d5670b9f65fc43", size = 237785, upload-time = "2025-06-09T23:01:05.095Z" },
+ { url = "https://files.pythonhosted.org/packages/f3/74/87601e0fb0369b7a2baf404ea921769c53b7ae00dee7dcfe5162c8c6dbf0/frozenlist-1.7.0-cp312-cp312-win32.whl", hash = "sha256:426c7bc70e07cfebc178bc4c2bf2d861d720c4fff172181eeb4a4c41d4ca2ad3", size = 39487, upload-time = "2025-06-09T23:01:06.54Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/15/c026e9a9fc17585a9d461f65d8593d281fedf55fbf7eb53f16c6df2392f9/frozenlist-1.7.0-cp312-cp312-win_amd64.whl", hash = "sha256:563b72efe5da92e02eb68c59cb37205457c977aa7a449ed1b37e6939e5c47c6a", size = 43874, upload-time = "2025-06-09T23:01:07.752Z" },
+ { url = "https://files.pythonhosted.org/packages/24/90/6b2cebdabdbd50367273c20ff6b57a3dfa89bd0762de02c3a1eb42cb6462/frozenlist-1.7.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:ee80eeda5e2a4e660651370ebffd1286542b67e268aa1ac8d6dbe973120ef7ee", size = 79791, upload-time = "2025-06-09T23:01:09.368Z" },
+ { url = "https://files.pythonhosted.org/packages/83/2e/5b70b6a3325363293fe5fc3ae74cdcbc3e996c2a11dde2fd9f1fb0776d19/frozenlist-1.7.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:d1a81c85417b914139e3a9b995d4a1c84559afc839a93cf2cb7f15e6e5f6ed2d", size = 47165, upload-time = "2025-06-09T23:01:10.653Z" },
+ { url = "https://files.pythonhosted.org/packages/f4/25/a0895c99270ca6966110f4ad98e87e5662eab416a17e7fd53c364bf8b954/frozenlist-1.7.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:cbb65198a9132ebc334f237d7b0df163e4de83fb4f2bdfe46c1e654bdb0c5d43", size = 45881, upload-time = "2025-06-09T23:01:12.296Z" },
+ { url = "https://files.pythonhosted.org/packages/19/7c/71bb0bbe0832793c601fff68cd0cf6143753d0c667f9aec93d3c323f4b55/frozenlist-1.7.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:dab46c723eeb2c255a64f9dc05b8dd601fde66d6b19cdb82b2e09cc6ff8d8b5d", size = 232409, upload-time = "2025-06-09T23:01:13.641Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/45/ed2798718910fe6eb3ba574082aaceff4528e6323f9a8570be0f7028d8e9/frozenlist-1.7.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:6aeac207a759d0dedd2e40745575ae32ab30926ff4fa49b1635def65806fddee", size = 225132, upload-time = "2025-06-09T23:01:15.264Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/e2/8417ae0f8eacb1d071d4950f32f229aa6bf68ab69aab797b72a07ea68d4f/frozenlist-1.7.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:bd8c4e58ad14b4fa7802b8be49d47993182fdd4023393899632c88fd8cd994eb", size = 237638, upload-time = "2025-06-09T23:01:16.752Z" },
+ { url = "https://files.pythonhosted.org/packages/f8/b7/2ace5450ce85f2af05a871b8c8719b341294775a0a6c5585d5e6170f2ce7/frozenlist-1.7.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:04fb24d104f425da3540ed83cbfc31388a586a7696142004c577fa61c6298c3f", size = 233539, upload-time = "2025-06-09T23:01:18.202Z" },
+ { url = "https://files.pythonhosted.org/packages/46/b9/6989292c5539553dba63f3c83dc4598186ab2888f67c0dc1d917e6887db6/frozenlist-1.7.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6a5c505156368e4ea6b53b5ac23c92d7edc864537ff911d2fb24c140bb175e60", size = 215646, upload-time = "2025-06-09T23:01:19.649Z" },
+ { url = "https://files.pythonhosted.org/packages/72/31/bc8c5c99c7818293458fe745dab4fd5730ff49697ccc82b554eb69f16a24/frozenlist-1.7.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8bd7eb96a675f18aa5c553eb7ddc24a43c8c18f22e1f9925528128c052cdbe00", size = 232233, upload-time = "2025-06-09T23:01:21.175Z" },
+ { url = "https://files.pythonhosted.org/packages/59/52/460db4d7ba0811b9ccb85af996019f5d70831f2f5f255f7cc61f86199795/frozenlist-1.7.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:05579bf020096fe05a764f1f84cd104a12f78eaab68842d036772dc6d4870b4b", size = 227996, upload-time = "2025-06-09T23:01:23.098Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/c9/f4b39e904c03927b7ecf891804fd3b4df3db29b9e487c6418e37988d6e9d/frozenlist-1.7.0-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:376b6222d114e97eeec13d46c486facd41d4f43bab626b7c3f6a8b4e81a5192c", size = 242280, upload-time = "2025-06-09T23:01:24.808Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/33/3f8d6ced42f162d743e3517781566b8481322be321b486d9d262adf70bfb/frozenlist-1.7.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:0aa7e176ebe115379b5b1c95b4096fb1c17cce0847402e227e712c27bdb5a949", size = 217717, upload-time = "2025-06-09T23:01:26.28Z" },
+ { url = "https://files.pythonhosted.org/packages/3e/e8/ad683e75da6ccef50d0ab0c2b2324b32f84fc88ceee778ed79b8e2d2fe2e/frozenlist-1.7.0-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:3fbba20e662b9c2130dc771e332a99eff5da078b2b2648153a40669a6d0e36ca", size = 236644, upload-time = "2025-06-09T23:01:27.887Z" },
+ { url = "https://files.pythonhosted.org/packages/b2/14/8d19ccdd3799310722195a72ac94ddc677541fb4bef4091d8e7775752360/frozenlist-1.7.0-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:f3f4410a0a601d349dd406b5713fec59b4cee7e71678d5b17edda7f4655a940b", size = 238879, upload-time = "2025-06-09T23:01:29.524Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/13/c12bf657494c2fd1079a48b2db49fa4196325909249a52d8f09bc9123fd7/frozenlist-1.7.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e2cdfaaec6a2f9327bf43c933c0319a7c429058e8537c508964a133dffee412e", size = 232502, upload-time = "2025-06-09T23:01:31.287Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/8b/e7f9dfde869825489382bc0d512c15e96d3964180c9499efcec72e85db7e/frozenlist-1.7.0-cp313-cp313-win32.whl", hash = "sha256:5fc4df05a6591c7768459caba1b342d9ec23fa16195e744939ba5914596ae3e1", size = 39169, upload-time = "2025-06-09T23:01:35.503Z" },
+ { url = "https://files.pythonhosted.org/packages/35/89/a487a98d94205d85745080a37860ff5744b9820a2c9acbcdd9440bfddf98/frozenlist-1.7.0-cp313-cp313-win_amd64.whl", hash = "sha256:52109052b9791a3e6b5d1b65f4b909703984b770694d3eb64fad124c835d7cba", size = 43219, upload-time = "2025-06-09T23:01:36.784Z" },
+ { url = "https://files.pythonhosted.org/packages/56/d5/5c4cf2319a49eddd9dd7145e66c4866bdc6f3dbc67ca3d59685149c11e0d/frozenlist-1.7.0-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:a6f86e4193bb0e235ef6ce3dde5cbabed887e0b11f516ce8a0f4d3b33078ec2d", size = 84345, upload-time = "2025-06-09T23:01:38.295Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/7d/ec2c1e1dc16b85bc9d526009961953df9cec8481b6886debb36ec9107799/frozenlist-1.7.0-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:82d664628865abeb32d90ae497fb93df398a69bb3434463d172b80fc25b0dd7d", size = 48880, upload-time = "2025-06-09T23:01:39.887Z" },
+ { url = "https://files.pythonhosted.org/packages/69/86/f9596807b03de126e11e7d42ac91e3d0b19a6599c714a1989a4e85eeefc4/frozenlist-1.7.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:912a7e8375a1c9a68325a902f3953191b7b292aa3c3fb0d71a216221deca460b", size = 48498, upload-time = "2025-06-09T23:01:41.318Z" },
+ { url = "https://files.pythonhosted.org/packages/5e/cb/df6de220f5036001005f2d726b789b2c0b65f2363b104bbc16f5be8084f8/frozenlist-1.7.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9537c2777167488d539bc5de2ad262efc44388230e5118868e172dd4a552b146", size = 292296, upload-time = "2025-06-09T23:01:42.685Z" },
+ { url = "https://files.pythonhosted.org/packages/83/1f/de84c642f17c8f851a2905cee2dae401e5e0daca9b5ef121e120e19aa825/frozenlist-1.7.0-cp313-cp313t-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:f34560fb1b4c3e30ba35fa9a13894ba39e5acfc5f60f57d8accde65f46cc5e74", size = 273103, upload-time = "2025-06-09T23:01:44.166Z" },
+ { url = "https://files.pythonhosted.org/packages/88/3c/c840bfa474ba3fa13c772b93070893c6e9d5c0350885760376cbe3b6c1b3/frozenlist-1.7.0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:acd03d224b0175f5a850edc104ac19040d35419eddad04e7cf2d5986d98427f1", size = 292869, upload-time = "2025-06-09T23:01:45.681Z" },
+ { url = "https://files.pythonhosted.org/packages/a6/1c/3efa6e7d5a39a1d5ef0abeb51c48fb657765794a46cf124e5aca2c7a592c/frozenlist-1.7.0-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f2038310bc582f3d6a09b3816ab01737d60bf7b1ec70f5356b09e84fb7408ab1", size = 291467, upload-time = "2025-06-09T23:01:47.234Z" },
+ { url = "https://files.pythonhosted.org/packages/4f/00/d5c5e09d4922c395e2f2f6b79b9a20dab4b67daaf78ab92e7729341f61f6/frozenlist-1.7.0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b8c05e4c8e5f36e5e088caa1bf78a687528f83c043706640a92cb76cd6999384", size = 266028, upload-time = "2025-06-09T23:01:48.819Z" },
+ { url = "https://files.pythonhosted.org/packages/4e/27/72765be905619dfde25a7f33813ac0341eb6b076abede17a2e3fbfade0cb/frozenlist-1.7.0-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:765bb588c86e47d0b68f23c1bee323d4b703218037765dcf3f25c838c6fecceb", size = 284294, upload-time = "2025-06-09T23:01:50.394Z" },
+ { url = "https://files.pythonhosted.org/packages/88/67/c94103a23001b17808eb7dd1200c156bb69fb68e63fcf0693dde4cd6228c/frozenlist-1.7.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:32dc2e08c67d86d0969714dd484fd60ff08ff81d1a1e40a77dd34a387e6ebc0c", size = 281898, upload-time = "2025-06-09T23:01:52.234Z" },
+ { url = "https://files.pythonhosted.org/packages/42/34/a3e2c00c00f9e2a9db5653bca3fec306349e71aff14ae45ecc6d0951dd24/frozenlist-1.7.0-cp313-cp313t-musllinux_1_2_armv7l.whl", hash = "sha256:c0303e597eb5a5321b4de9c68e9845ac8f290d2ab3f3e2c864437d3c5a30cd65", size = 290465, upload-time = "2025-06-09T23:01:53.788Z" },
+ { url = "https://files.pythonhosted.org/packages/bb/73/f89b7fbce8b0b0c095d82b008afd0590f71ccb3dee6eee41791cf8cd25fd/frozenlist-1.7.0-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:a47f2abb4e29b3a8d0b530f7c3598badc6b134562b1a5caee867f7c62fee51e3", size = 266385, upload-time = "2025-06-09T23:01:55.769Z" },
+ { url = "https://files.pythonhosted.org/packages/cd/45/e365fdb554159462ca12df54bc59bfa7a9a273ecc21e99e72e597564d1ae/frozenlist-1.7.0-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:3d688126c242a6fabbd92e02633414d40f50bb6002fa4cf995a1d18051525657", size = 288771, upload-time = "2025-06-09T23:01:57.4Z" },
+ { url = "https://files.pythonhosted.org/packages/00/11/47b6117002a0e904f004d70ec5194fe9144f117c33c851e3d51c765962d0/frozenlist-1.7.0-cp313-cp313t-musllinux_1_2_s390x.whl", hash = "sha256:4e7e9652b3d367c7bd449a727dc79d5043f48b88d0cbfd4f9f1060cf2b414104", size = 288206, upload-time = "2025-06-09T23:01:58.936Z" },
+ { url = "https://files.pythonhosted.org/packages/40/37/5f9f3c3fd7f7746082ec67bcdc204db72dad081f4f83a503d33220a92973/frozenlist-1.7.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:1a85e345b4c43db8b842cab1feb41be5cc0b10a1830e6295b69d7310f99becaf", size = 282620, upload-time = "2025-06-09T23:02:00.493Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/31/8fbc5af2d183bff20f21aa743b4088eac4445d2bb1cdece449ae80e4e2d1/frozenlist-1.7.0-cp313-cp313t-win32.whl", hash = "sha256:3a14027124ddb70dfcee5148979998066897e79f89f64b13328595c4bdf77c81", size = 43059, upload-time = "2025-06-09T23:02:02.072Z" },
+ { url = "https://files.pythonhosted.org/packages/bb/ed/41956f52105b8dbc26e457c5705340c67c8cc2b79f394b79bffc09d0e938/frozenlist-1.7.0-cp313-cp313t-win_amd64.whl", hash = "sha256:3bf8010d71d4507775f658e9823210b7427be36625b387221642725b515dcf3e", size = 47516, upload-time = "2025-06-09T23:02:03.779Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/45/b82e3c16be2182bff01179db177fe144d58b5dc787a7d4492c6ed8b9317f/frozenlist-1.7.0-py3-none-any.whl", hash = "sha256:9a5af342e34f7e97caf8c995864c7a396418ae2859cc6fdf1b1073020d516a7e", size = 13106, upload-time = "2025-06-09T23:02:34.204Z" },
+]
+
+[[package]]
+name = "fsspec"
+version = "2024.10.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a0/52/f16a068ebadae42526484c31f4398e62962504e5724a8ba5dc3409483df2/fsspec-2024.10.0.tar.gz", hash = "sha256:eda2d8a4116d4f2429db8550f2457da57279247dd930bb12f821b58391359493", size = 286853, upload-time = "2024-10-21T01:21:16.969Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c6/b2/454d6e7f0158951d8a78c2e1eb4f69ae81beb8dca5fee9809c6c99e9d0d0/fsspec-2024.10.0-py3-none-any.whl", hash = "sha256:03b9a6785766a4de40368b88906366755e2819e758b83705c88cd7cb5fe81871", size = 179641, upload-time = "2024-10-21T01:21:14.793Z" },
+]
+
+[package.optional-dependencies]
+sftp = [
+ { name = "paramiko" },
+]
+
+[[package]]
+name = "funcy"
+version = "2.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/70/b8/c6081521ff70afdff55cd9512b2220bbf4fa88804dae51d1b57b4b58ef32/funcy-2.0.tar.gz", hash = "sha256:3963315d59d41c6f30c04bc910e10ab50a3ac4a225868bfa96feed133df075cb", size = 537931, upload-time = "2023-03-28T06:22:46.764Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d5/08/c2409cb01d5368dcfedcbaffa7d044cc8957d57a9d0855244a5eb4709d30/funcy-2.0-py2.py3-none-any.whl", hash = "sha256:53df23c8bb1651b12f095df764bfb057935d49537a56de211b098f4c79614bb0", size = 30891, upload-time = "2023-03-28T06:22:42.576Z" },
+]
+
+[[package]]
+name = "gcsfs"
+version = "2024.10.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiohttp" },
+ { name = "decorator" },
+ { name = "fsspec" },
+ { name = "google-auth" },
+ { name = "google-auth-oauthlib" },
+ { name = "google-cloud-storage" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e5/1e/1d8c4593d9e2eb04918fec43253ab152823d67ad51ad9e3ab6b3a78c431a/gcsfs-2024.10.0.tar.gz", hash = "sha256:5df54cfe568e8fdeea5aafa7fed695cdc69a9a674e991ca8c1ce634f5df1d314", size = 79588, upload-time = "2024-10-21T13:43:26.163Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/dc/96/d60e835fb7d10166c77aef0c1fa30e634153c03a0f486786977b95f88fde/gcsfs-2024.10.0-py2.py3-none-any.whl", hash = "sha256:bb2d23547e61203ea2dda5fa6c4b91a0c34b74ebe8bb6ab1926f6c33381bceb2", size = 34953, upload-time = "2024-10-21T13:43:24.951Z" },
+]
+
+[[package]]
+name = "google-ai-generativelanguage"
+version = "0.6.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core", extra = ["grpc"] },
+ { name = "google-auth" },
+ { name = "proto-plus" },
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/01/3d/d94fd449dc5dbcd7efa55c90a31509f8f1ae9b541d1032c69a15e2c1ed20/google-ai-generativelanguage-0.6.4.tar.gz", hash = "sha256:1750848c12af96cb24ae1c3dd05e4bfe24867dc4577009ed03e1042d8421e874", size = 715303, upload-time = "2024-05-16T20:56:35.669Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/38/9c/f1790d6fbd66789969eb54c119f36e7c7e1476db2afce8b6623e9e61f486/google_ai_generativelanguage-0.6.4-py3-none-any.whl", hash = "sha256:730e471aa549797118fb1c88421ba1957741433ada575cf5dd08d3aebf903ab1", size = 679102, upload-time = "2024-05-16T20:56:32.953Z" },
+]
+
+[[package]]
+name = "google-api-core"
+version = "2.25.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-auth" },
+ { name = "googleapis-common-protos" },
+ { name = "proto-plus" },
+ { name = "protobuf" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/dc/21/e9d043e88222317afdbdb567165fdbc3b0aad90064c7e0c9eb0ad9955ad8/google_api_core-2.25.1.tar.gz", hash = "sha256:d2aaa0b13c78c61cb3f4282c464c046e45fbd75755683c9c525e6e8f7ed0a5e8", size = 165443, upload-time = "2025-06-12T20:52:20.439Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/14/4b/ead00905132820b623732b175d66354e9d3e69fcf2a5dcdab780664e7896/google_api_core-2.25.1-py3-none-any.whl", hash = "sha256:8a2a56c1fef82987a524371f99f3bd0143702fecc670c72e600c1cda6bf8dbb7", size = 160807, upload-time = "2025-06-12T20:52:19.334Z" },
+]
+
+[package.optional-dependencies]
+grpc = [
+ { name = "grpcio" },
+ { name = "grpcio-status" },
+]
+
+[[package]]
+name = "google-api-python-client"
+version = "2.178.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core" },
+ { name = "google-auth" },
+ { name = "google-auth-httplib2" },
+ { name = "httplib2" },
+ { name = "uritemplate" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/99/98/916385a87d145a27661b630c480fadf9db32bb1ad9fb1b13e8dbcbe2af70/google_api_python_client-2.178.0.tar.gz", hash = "sha256:99cba921eb471bb5973b780c653ac54d96eef8a42f1b7375b7ab98f257a4414c", size = 13282628, upload-time = "2025-08-06T14:04:51.062Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/29/34/8ae31410a2d3f28b16b7135931133caf759d3aa0653f8397e344acec5a88/google_api_python_client-2.178.0-py3-none-any.whl", hash = "sha256:f420adcd050150ff1baefa817e96e1ffa16872744f53471cd34096612e580c34", size = 13809959, upload-time = "2025-08-06T14:04:47.94Z" },
+]
+
+[[package]]
+name = "google-auth"
+version = "2.20.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cachetools" },
+ { name = "pyasn1-modules" },
+ { name = "rsa" },
+ { name = "six" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/4b/e0/d2c96098280f17eb626d4da0b7e553b8e5648d57514c8cefec851c16920c/google-auth-2.20.0.tar.gz", hash = "sha256:030af34138909ccde0fbce611afc178f1d65d32fbff281f25738b1fe1c6f3eaa", size = 229669, upload-time = "2023-06-13T17:50:38.754Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/9a/1a/5866a7c6e16abc1df395e6d2b9808984d0905c747d75f5e20f1a052421d1/google_auth-2.20.0-py2.py3-none-any.whl", hash = "sha256:23b7b0950fcda519bfb6692bf0d5289d2ea49fc143717cc7188458ec620e63fa", size = 181456, upload-time = "2023-06-13T17:50:36.408Z" },
+]
+
+[package.optional-dependencies]
+requests = [
+ { name = "requests" },
+]
+
+[[package]]
+name = "google-auth-httplib2"
+version = "0.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-auth" },
+ { name = "httplib2" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/56/be/217a598a818567b28e859ff087f347475c807a5649296fb5a817c58dacef/google-auth-httplib2-0.2.0.tar.gz", hash = "sha256:38aa7badf48f974f1eb9861794e9c0cb2a0511a4ec0679b1f886d108f5640e05", size = 10842, upload-time = "2023-12-12T17:40:30.722Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/be/8a/fe34d2f3f9470a27b01c9e76226965863f153d5fbe276f83608562e49c04/google_auth_httplib2-0.2.0-py2.py3-none-any.whl", hash = "sha256:b65a0a2123300dd71281a7bf6e64d65a0759287df52729bdd1ae2e47dc311a3d", size = 9253, upload-time = "2023-12-12T17:40:13.055Z" },
+]
+
+[[package]]
+name = "google-auth-oauthlib"
+version = "1.2.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-auth" },
+ { name = "requests-oauthlib" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/fb/87/e10bf24f7bcffc1421b84d6f9c3377c30ec305d082cd737ddaa6d8f77f7c/google_auth_oauthlib-1.2.2.tar.gz", hash = "sha256:11046fb8d3348b296302dd939ace8af0a724042e8029c1b872d87fabc9f41684", size = 20955, upload-time = "2025-04-22T16:40:29.172Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ac/84/40ee070be95771acd2f4418981edb834979424565c3eec3cd88b6aa09d24/google_auth_oauthlib-1.2.2-py3-none-any.whl", hash = "sha256:fd619506f4b3908b5df17b65f39ca8d66ea56986e5472eb5978fd8f3786f00a2", size = 19072, upload-time = "2025-04-22T16:40:28.174Z" },
+]
+
+[[package]]
+name = "google-cloud-aiplatform"
+version = "1.108.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "docstring-parser" },
+ { name = "google-api-core", extra = ["grpc"] },
+ { name = "google-auth" },
+ { name = "google-cloud-bigquery" },
+ { name = "google-cloud-resource-manager" },
+ { name = "google-cloud-storage" },
+ { name = "google-genai" },
+ { name = "packaging" },
+ { name = "proto-plus" },
+ { name = "protobuf" },
+ { name = "pydantic" },
+ { name = "shapely" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/29/2f/00393f972b97b7f1505335d632db6ddd6f314b96017887a2f8400f5b24e2/google_cloud_aiplatform-1.108.0.tar.gz", hash = "sha256:ebff9931f948622ea2d34890b2ca8f8f4915c575814fdc1bcc16bc1b1beb5549", size = 9498668, upload-time = "2025-08-08T17:21:21.321Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ca/09/403d8bddacb33ec67af5a981d6166f391a9c2a2cf163c2a6742bdf958966/google_cloud_aiplatform-1.108.0-py2.py3-none-any.whl", hash = "sha256:2001c3be0d704fe4a1d5adc815172391a0e10a9009e9c3eed721a12d3d431ba6", size = 7895944, upload-time = "2025-08-08T17:21:18.933Z" },
+]
+
+[[package]]
+name = "google-cloud-bigquery"
+version = "3.11.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core", extra = ["grpc"] },
+ { name = "google-cloud-core" },
+ { name = "google-resumable-media" },
+ { name = "grpcio" },
+ { name = "packaging" },
+ { name = "proto-plus" },
+ { name = "protobuf" },
+ { name = "python-dateutil" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/62/ff/2c520952db184dec31e2ee988cfa37fa9e7776935a3f2eccc44252ecab5f/google-cloud-bigquery-3.11.4.tar.gz", hash = "sha256:697df117241a2283bcbb93b21e10badc14e51c9a90800d2a7e1a3e1c7d842974", size = 410777, upload-time = "2023-07-19T23:12:12.7Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/cc/6a/d0ef792288f2fa2cfea80899a82de302b3332dfda41984fe114e2cfbf700/google_cloud_bigquery-3.11.4-py2.py3-none-any.whl", hash = "sha256:5fa7897743a0ed949ade25a0942fc9e7557d8fce307c6f8a76d1b604cf27f1b1", size = 219607, upload-time = "2023-07-19T23:12:09.449Z" },
+]
+
+[[package]]
+name = "google-cloud-core"
+version = "2.4.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core" },
+ { name = "google-auth" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d6/b8/2b53838d2acd6ec6168fd284a990c76695e84c65deee79c9f3a4276f6b4f/google_cloud_core-2.4.3.tar.gz", hash = "sha256:1fab62d7102844b278fe6dead3af32408b1df3eb06f5c7e8634cbd40edc4da53", size = 35861, upload-time = "2025-03-10T21:05:38.948Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/40/86/bda7241a8da2d28a754aad2ba0f6776e35b67e37c36ae0c45d49370f1014/google_cloud_core-2.4.3-py2.py3-none-any.whl", hash = "sha256:5130f9f4c14b4fafdff75c79448f9495cfade0d8775facf1b09c3bf67e027f6e", size = 29348, upload-time = "2025-03-10T21:05:37.785Z" },
+]
+
+[[package]]
+name = "google-cloud-resource-manager"
+version = "1.14.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core", extra = ["grpc"] },
+ { name = "google-auth" },
+ { name = "grpc-google-iam-v1" },
+ { name = "proto-plus" },
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/6e/ca/a4648f5038cb94af4b3942815942a03aa9398f9fb0bef55b3f1585b9940d/google_cloud_resource_manager-1.14.2.tar.gz", hash = "sha256:962e2d904c550d7bac48372607904ff7bb3277e3bb4a36d80cc9a37e28e6eb74", size = 446370, upload-time = "2025-03-17T11:35:56.343Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b1/ea/a92631c358da377af34d3a9682c97af83185c2d66363d5939ab4a1169a7f/google_cloud_resource_manager-1.14.2-py3-none-any.whl", hash = "sha256:d0fa954dedd1d2b8e13feae9099c01b8aac515b648e612834f9942d2795a9900", size = 394344, upload-time = "2025-03-17T11:35:54.722Z" },
+]
+
+[[package]]
+name = "google-cloud-secret-manager"
+version = "2.16.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core", extra = ["grpc"] },
+ { name = "grpc-google-iam-v1" },
+ { name = "proto-plus" },
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/48/6b/92b705f408c1d928526b65d1259be4254ef1f45e620f01f8665156b4d781/google-cloud-secret-manager-2.16.1.tar.gz", hash = "sha256:149d11ce9be7ea81d4ac3544d3fcd4c716a9edb2cb775d9c075231570b079fbb", size = 128884, upload-time = "2023-03-27T14:51:09.684Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6c/e3/c3aade516eaf544bd7d86694178de9c2da8eff8fc40326d0265acc65991d/google_cloud_secret_manager-2.16.1-py2.py3-none-any.whl", hash = "sha256:dad28c24921fb62961aafe808be0e7935a99096f03ac29eeeefa04b85534c1f3", size = 116749, upload-time = "2023-03-27T14:51:07.661Z" },
+]
+
+[[package]]
+name = "google-cloud-storage"
+version = "2.9.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-core" },
+ { name = "google-auth" },
+ { name = "google-cloud-core" },
+ { name = "google-resumable-media" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/fc/50/c9998f84fd8ce8799d7f8020466bbc5c9e3b1126b04a09fdb02378d451b0/google-cloud-storage-2.9.0.tar.gz", hash = "sha256:9b6ae7b509fc294bdacb84d0f3ea8e20e2c54a8b4bbe39c5707635fec214eff3", size = 5498811, upload-time = "2023-05-04T17:56:46.265Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/74/fb/3770e7f44cf6133f502e1b8503b6739351b53272cf8313b47f1de6cf4960/google_cloud_storage-2.9.0-py2.py3-none-any.whl", hash = "sha256:83a90447f23d5edd045e0037982c270302e3aeb45fc1288d2c2ca713d27bad94", size = 113512, upload-time = "2023-05-04T17:56:43.929Z" },
+]
+
+[[package]]
+name = "google-crc32c"
+version = "1.7.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/19/ae/87802e6d9f9d69adfaedfcfd599266bf386a54d0be058b532d04c794f76d/google_crc32c-1.7.1.tar.gz", hash = "sha256:2bff2305f98846f3e825dbeec9ee406f89da7962accdb29356e4eadc251bd472", size = 14495, upload-time = "2025-03-26T14:29:13.32Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/dd/b7/787e2453cf8639c94b3d06c9d61f512234a82e1d12d13d18584bd3049904/google_crc32c-1.7.1-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:2d73a68a653c57281401871dd4aeebbb6af3191dcac751a76ce430df4d403194", size = 30470, upload-time = "2025-03-26T14:34:31.655Z" },
+ { url = "https://files.pythonhosted.org/packages/ed/b4/6042c2b0cbac3ec3a69bb4c49b28d2f517b7a0f4a0232603c42c58e22b44/google_crc32c-1.7.1-cp312-cp312-macosx_12_0_x86_64.whl", hash = "sha256:22beacf83baaf59f9d3ab2bbb4db0fb018da8e5aebdce07ef9f09fce8220285e", size = 30315, upload-time = "2025-03-26T15:01:54.634Z" },
+ { url = "https://files.pythonhosted.org/packages/29/ad/01e7a61a5d059bc57b702d9ff6a18b2585ad97f720bd0a0dbe215df1ab0e/google_crc32c-1.7.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:19eafa0e4af11b0a4eb3974483d55d2d77ad1911e6cf6f832e1574f6781fd337", size = 33180, upload-time = "2025-03-26T14:41:32.168Z" },
+ { url = "https://files.pythonhosted.org/packages/3b/a5/7279055cf004561894ed3a7bfdf5bf90a53f28fadd01af7cd166e88ddf16/google_crc32c-1.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b6d86616faaea68101195c6bdc40c494e4d76f41e07a37ffdef270879c15fb65", size = 32794, upload-time = "2025-03-26T14:41:33.264Z" },
+ { url = "https://files.pythonhosted.org/packages/0f/d6/77060dbd140c624e42ae3ece3df53b9d811000729a5c821b9fd671ceaac6/google_crc32c-1.7.1-cp312-cp312-win_amd64.whl", hash = "sha256:b7491bdc0c7564fcf48c0179d2048ab2f7c7ba36b84ccd3a3e1c3f7a72d3bba6", size = 33477, upload-time = "2025-03-26T14:29:10.94Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/72/b8d785e9184ba6297a8620c8a37cf6e39b81a8ca01bb0796d7cbb28b3386/google_crc32c-1.7.1-cp313-cp313-macosx_12_0_arm64.whl", hash = "sha256:df8b38bdaf1629d62d51be8bdd04888f37c451564c2042d36e5812da9eff3c35", size = 30467, upload-time = "2025-03-26T14:36:06.909Z" },
+ { url = "https://files.pythonhosted.org/packages/34/25/5f18076968212067c4e8ea95bf3b69669f9fc698476e5f5eb97d5b37999f/google_crc32c-1.7.1-cp313-cp313-macosx_12_0_x86_64.whl", hash = "sha256:e42e20a83a29aa2709a0cf271c7f8aefaa23b7ab52e53b322585297bb94d4638", size = 30309, upload-time = "2025-03-26T15:06:15.318Z" },
+ { url = "https://files.pythonhosted.org/packages/92/83/9228fe65bf70e93e419f38bdf6c5ca5083fc6d32886ee79b450ceefd1dbd/google_crc32c-1.7.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:905a385140bf492ac300026717af339790921f411c0dfd9aa5a9e69a08ed32eb", size = 33133, upload-time = "2025-03-26T14:41:34.388Z" },
+ { url = "https://files.pythonhosted.org/packages/c3/ca/1ea2fd13ff9f8955b85e7956872fdb7050c4ace8a2306a6d177edb9cf7fe/google_crc32c-1.7.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6b211ddaf20f7ebeec5c333448582c224a7c90a9d98826fbab82c0ddc11348e6", size = 32773, upload-time = "2025-03-26T14:41:35.19Z" },
+ { url = "https://files.pythonhosted.org/packages/89/32/a22a281806e3ef21b72db16f948cad22ec68e4bdd384139291e00ff82fe2/google_crc32c-1.7.1-cp313-cp313-win_amd64.whl", hash = "sha256:0f99eaa09a9a7e642a61e06742856eec8b19fc0037832e03f941fe7cf0c8e4db", size = 33475, upload-time = "2025-03-26T14:29:11.771Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/c5/002975aff514e57fc084ba155697a049b3f9b52225ec3bc0f542871dd524/google_crc32c-1.7.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:32d1da0d74ec5634a05f53ef7df18fc646666a25efaaca9fc7dcfd4caf1d98c3", size = 33243, upload-time = "2025-03-26T14:41:35.975Z" },
+ { url = "https://files.pythonhosted.org/packages/61/cb/c585282a03a0cea70fcaa1bf55d5d702d0f2351094d663ec3be1c6c67c52/google_crc32c-1.7.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e10554d4abc5238823112c2ad7e4560f96c7bf3820b202660373d769d9e6e4c9", size = 32870, upload-time = "2025-03-26T14:41:37.08Z" },
+]
+
+[[package]]
+name = "google-genai"
+version = "1.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-auth" },
+ { name = "pydantic" },
+ { name = "requests" },
+ { name = "typing-extensions" },
+ { name = "websockets" },
+]
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/0d/ed/985f2d2e2b5fbd912ab0fdb11d6dc48c22553a6c4edffabb8146d53b974a/google_genai-1.2.0-py3-none-any.whl", hash = "sha256:609d61bee73f1a6ae5b47e9c7dd4b469d50318f050c5ceacf835b0f80f79d2d9", size = 130744, upload-time = "2025-02-12T16:40:03.601Z" },
+]
+
+[[package]]
+name = "google-generativeai"
+version = "0.5.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-ai-generativelanguage" },
+ { name = "google-api-core" },
+ { name = "google-api-python-client" },
+ { name = "google-auth" },
+ { name = "protobuf" },
+ { name = "pydantic" },
+ { name = "tqdm" },
+ { name = "typing-extensions" },
+]
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6c/ae/219536da4726a1b4ababdc2988b0894037505200faa704796099254cc968/google_generativeai-0.5.4-py3-none-any.whl", hash = "sha256:036d63ee35e7c8aedceda4f81c390a5102808af09ff3a6e57e27ed0be0708f3c", size = 150712, upload-time = "2024-05-17T01:25:53.892Z" },
+]
+
+[[package]]
+name = "google-resumable-media"
+version = "2.7.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-crc32c" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/58/5a/0efdc02665dca14e0837b62c8a1a93132c264bd02054a15abb2218afe0ae/google_resumable_media-2.7.2.tar.gz", hash = "sha256:5280aed4629f2b60b847b0d42f9857fd4935c11af266744df33d8074cae92fe0", size = 2163099, upload-time = "2024-08-07T22:20:38.555Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/82/35/b8d3baf8c46695858cb9d8835a53baa1eeb9906ddaf2f728a5f5b640fd1e/google_resumable_media-2.7.2-py2.py3-none-any.whl", hash = "sha256:3ce7551e9fe6d99e9a126101d2536612bb73486721951e9562fee0f90c6ababa", size = 81251, upload-time = "2024-08-07T22:20:36.409Z" },
+]
+
+[[package]]
+name = "googleapis-common-protos"
+version = "1.70.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/39/24/33db22342cf4a2ea27c9955e6713140fedd51e8b141b5ce5260897020f1a/googleapis_common_protos-1.70.0.tar.gz", hash = "sha256:0e1b44e0ea153e6594f9f394fef15193a68aaaea2d843f83e2742717ca753257", size = 145903, upload-time = "2025-04-14T10:17:02.924Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/86/f1/62a193f0227cf15a920390abe675f386dec35f7ae3ffe6da582d3ade42c7/googleapis_common_protos-1.70.0-py3-none-any.whl", hash = "sha256:b8bfcca8c25a2bb253e0e0b0adaf8c00773e5e6af6fd92397576680b807e0fd8", size = 294530, upload-time = "2025-04-14T10:17:01.271Z" },
+]
+
+[package.optional-dependencies]
+grpc = [
+ { name = "grpcio" },
+]
+
+[[package]]
+name = "greenlet"
+version = "3.2.4"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/03/b8/704d753a5a45507a7aab61f18db9509302ed3d0a27ac7e0359ec2905b1a6/greenlet-3.2.4.tar.gz", hash = "sha256:0dca0d95ff849f9a364385f36ab49f50065d76964944638be9691e1832e9f86d", size = 188260, upload-time = "2025-08-07T13:24:33.51Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/44/69/9b804adb5fd0671f367781560eb5eb586c4d495277c93bde4307b9e28068/greenlet-3.2.4-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:3b67ca49f54cede0186854a008109d6ee71f66bd57bb36abd6d0a0267b540cdd", size = 274079, upload-time = "2025-08-07T13:15:45.033Z" },
+ { url = "https://files.pythonhosted.org/packages/46/e9/d2a80c99f19a153eff70bc451ab78615583b8dac0754cfb942223d2c1a0d/greenlet-3.2.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ddf9164e7a5b08e9d22511526865780a576f19ddd00d62f8a665949327fde8bb", size = 640997, upload-time = "2025-08-07T13:42:56.234Z" },
+ { url = "https://files.pythonhosted.org/packages/3b/16/035dcfcc48715ccd345f3a93183267167cdd162ad123cd93067d86f27ce4/greenlet-3.2.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:f28588772bb5fb869a8eb331374ec06f24a83a9c25bfa1f38b6993afe9c1e968", size = 655185, upload-time = "2025-08-07T13:45:27.624Z" },
+ { url = "https://files.pythonhosted.org/packages/31/da/0386695eef69ffae1ad726881571dfe28b41970173947e7c558d9998de0f/greenlet-3.2.4-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:5c9320971821a7cb77cfab8d956fa8e39cd07ca44b6070db358ceb7f8797c8c9", size = 649926, upload-time = "2025-08-07T13:53:15.251Z" },
+ { url = "https://files.pythonhosted.org/packages/68/88/69bf19fd4dc19981928ceacbc5fd4bb6bc2215d53199e367832e98d1d8fe/greenlet-3.2.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c60a6d84229b271d44b70fb6e5fa23781abb5d742af7b808ae3f6efd7c9c60f6", size = 651839, upload-time = "2025-08-07T13:18:30.281Z" },
+ { url = "https://files.pythonhosted.org/packages/19/0d/6660d55f7373b2ff8152401a83e02084956da23ae58cddbfb0b330978fe9/greenlet-3.2.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3b3812d8d0c9579967815af437d96623f45c0f2ae5f04e366de62a12d83a8fb0", size = 607586, upload-time = "2025-08-07T13:18:28.544Z" },
+ { url = "https://files.pythonhosted.org/packages/8e/1a/c953fdedd22d81ee4629afbb38d2f9d71e37d23caace44775a3a969147d4/greenlet-3.2.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:abbf57b5a870d30c4675928c37278493044d7c14378350b3aa5d484fa65575f0", size = 1123281, upload-time = "2025-08-07T13:42:39.858Z" },
+ { url = "https://files.pythonhosted.org/packages/3f/c7/12381b18e21aef2c6bd3a636da1088b888b97b7a0362fac2e4de92405f97/greenlet-3.2.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:20fb936b4652b6e307b8f347665e2c615540d4b42b3b4c8a321d8286da7e520f", size = 1151142, upload-time = "2025-08-07T13:18:22.981Z" },
+ { url = "https://files.pythonhosted.org/packages/e9/08/b0814846b79399e585f974bbeebf5580fbe59e258ea7be64d9dfb253c84f/greenlet-3.2.4-cp312-cp312-win_amd64.whl", hash = "sha256:a7d4e128405eea3814a12cc2605e0e6aedb4035bf32697f72deca74de4105e02", size = 299899, upload-time = "2025-08-07T13:38:53.448Z" },
+ { url = "https://files.pythonhosted.org/packages/49/e8/58c7f85958bda41dafea50497cbd59738c5c43dbbea5ee83d651234398f4/greenlet-3.2.4-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:1a921e542453fe531144e91e1feedf12e07351b1cf6c9e8a3325ea600a715a31", size = 272814, upload-time = "2025-08-07T13:15:50.011Z" },
+ { url = "https://files.pythonhosted.org/packages/62/dd/b9f59862e9e257a16e4e610480cfffd29e3fae018a68c2332090b53aac3d/greenlet-3.2.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:cd3c8e693bff0fff6ba55f140bf390fa92c994083f838fece0f63be121334945", size = 641073, upload-time = "2025-08-07T13:42:57.23Z" },
+ { url = "https://files.pythonhosted.org/packages/f7/0b/bc13f787394920b23073ca3b6c4a7a21396301ed75a655bcb47196b50e6e/greenlet-3.2.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:710638eb93b1fa52823aa91bf75326f9ecdfd5e0466f00789246a5280f4ba0fc", size = 655191, upload-time = "2025-08-07T13:45:29.752Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/d6/6adde57d1345a8d0f14d31e4ab9c23cfe8e2cd39c3baf7674b4b0338d266/greenlet-3.2.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:c5111ccdc9c88f423426df3fd1811bfc40ed66264d35aa373420a34377efc98a", size = 649516, upload-time = "2025-08-07T13:53:16.314Z" },
+ { url = "https://files.pythonhosted.org/packages/7f/3b/3a3328a788d4a473889a2d403199932be55b1b0060f4ddd96ee7cdfcad10/greenlet-3.2.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:d76383238584e9711e20ebe14db6c88ddcedc1829a9ad31a584389463b5aa504", size = 652169, upload-time = "2025-08-07T13:18:32.861Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/43/3cecdc0349359e1a527cbf2e3e28e5f8f06d3343aaf82ca13437a9aa290f/greenlet-3.2.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:23768528f2911bcd7e475210822ffb5254ed10d71f4028387e5a99b4c6699671", size = 610497, upload-time = "2025-08-07T13:18:31.636Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/19/06b6cf5d604e2c382a6f31cafafd6f33d5dea706f4db7bdab184bad2b21d/greenlet-3.2.4-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:00fadb3fedccc447f517ee0d3fd8fe49eae949e1cd0f6a611818f4f6fb7dc83b", size = 1121662, upload-time = "2025-08-07T13:42:41.117Z" },
+ { url = "https://files.pythonhosted.org/packages/a2/15/0d5e4e1a66fab130d98168fe984c509249c833c1a3c16806b90f253ce7b9/greenlet-3.2.4-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:d25c5091190f2dc0eaa3f950252122edbbadbb682aa7b1ef2f8af0f8c0afefae", size = 1149210, upload-time = "2025-08-07T13:18:24.072Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/55/2321e43595e6801e105fcfdee02b34c0f996eb71e6ddffca6b10b7e1d771/greenlet-3.2.4-cp313-cp313-win_amd64.whl", hash = "sha256:554b03b6e73aaabec3745364d6239e9e012d64c68ccd0b8430c64ccc14939a8b", size = 299685, upload-time = "2025-08-07T13:24:38.824Z" },
+ { url = "https://files.pythonhosted.org/packages/22/5c/85273fd7cc388285632b0498dbbab97596e04b154933dfe0f3e68156c68c/greenlet-3.2.4-cp314-cp314-macosx_11_0_universal2.whl", hash = "sha256:49a30d5fda2507ae77be16479bdb62a660fa51b1eb4928b524975b3bde77b3c0", size = 273586, upload-time = "2025-08-07T13:16:08.004Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/75/10aeeaa3da9332c2e761e4c50d4c3556c21113ee3f0afa2cf5769946f7a3/greenlet-3.2.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:299fd615cd8fc86267b47597123e3f43ad79c9d8a22bebdce535e53550763e2f", size = 686346, upload-time = "2025-08-07T13:42:59.944Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/aa/687d6b12ffb505a4447567d1f3abea23bd20e73a5bed63871178e0831b7a/greenlet-3.2.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:c17b6b34111ea72fc5a4e4beec9711d2226285f0386ea83477cbb97c30a3f3a5", size = 699218, upload-time = "2025-08-07T13:45:30.969Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/8b/29aae55436521f1d6f8ff4e12fb676f3400de7fcf27fccd1d4d17fd8fecd/greenlet-3.2.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:b4a1870c51720687af7fa3e7cda6d08d801dae660f75a76f3845b642b4da6ee1", size = 694659, upload-time = "2025-08-07T13:53:17.759Z" },
+ { url = "https://files.pythonhosted.org/packages/92/2e/ea25914b1ebfde93b6fc4ff46d6864564fba59024e928bdc7de475affc25/greenlet-3.2.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:061dc4cf2c34852b052a8620d40f36324554bc192be474b9e9770e8c042fd735", size = 695355, upload-time = "2025-08-07T13:18:34.517Z" },
+ { url = "https://files.pythonhosted.org/packages/72/60/fc56c62046ec17f6b0d3060564562c64c862948c9d4bc8aa807cf5bd74f4/greenlet-3.2.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:44358b9bf66c8576a9f57a590d5f5d6e72fa4228b763d0e43fee6d3b06d3a337", size = 657512, upload-time = "2025-08-07T13:18:33.969Z" },
+ { url = "https://files.pythonhosted.org/packages/e3/a5/6ddab2b4c112be95601c13428db1d8b6608a8b6039816f2ba09c346c08fc/greenlet-3.2.4-cp314-cp314-win_amd64.whl", hash = "sha256:e37ab26028f12dbb0ff65f29a8d3d44a765c61e729647bf2ddfbbed621726f01", size = 303425, upload-time = "2025-08-07T13:32:27.59Z" },
+]
+
+[[package]]
+name = "griffe"
+version = "1.11.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "colorama" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/22/01/4897bb317b347070b73a2f795e38a897ab3b022e020ff2f3ea6bc6a5994b/griffe-1.11.0.tar.gz", hash = "sha256:c153b5bc63ca521f059e9451533a67e44a9d06cf9bf1756e4298bda5bd3262e8", size = 410774, upload-time = "2025-08-07T18:23:36.784Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a7/55/588425bdbe8097b621db813e9b33f0a8a7257771683e0f5369c6c8eb66ab/griffe-1.11.0-py3-none-any.whl", hash = "sha256:dc56cc6af8d322807ecdb484b39838c7a51ca750cf21ccccf890500c4d6389d8", size = 137576, upload-time = "2025-08-07T18:23:34.859Z" },
+]
+
+[[package]]
+name = "grpc-google-iam-v1"
+version = "0.14.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "googleapis-common-protos", extra = ["grpc"] },
+ { name = "grpcio" },
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b9/4e/8d0ca3b035e41fe0b3f31ebbb638356af720335e5a11154c330169b40777/grpc_google_iam_v1-0.14.2.tar.gz", hash = "sha256:b3e1fc387a1a329e41672197d0ace9de22c78dd7d215048c4c78712073f7bd20", size = 16259, upload-time = "2025-03-17T11:40:23.586Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/66/6f/dd9b178aee7835b96c2e63715aba6516a9d50f6bebbd1cc1d32c82a2a6c3/grpc_google_iam_v1-0.14.2-py3-none-any.whl", hash = "sha256:a3171468459770907926d56a440b2bb643eec1d7ba215f48f3ecece42b4d8351", size = 19242, upload-time = "2025-03-17T11:40:22.648Z" },
+]
+
+[[package]]
+name = "grpcio"
+version = "1.60.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/61/38/c615b5c2be690fb31871f294cc08a96e598b085b8d07c5967a5018e0b90c/grpcio-1.60.0.tar.gz", hash = "sha256:2199165a1affb666aa24adf0c97436686d0a61bc5fc113c037701fb7c7fceb96", size = 24766390, upload-time = "2023-12-07T19:00:15.486Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/61/f9/e3c4b4a879096fe608d75e2a5b4b3790baa91137c5d5da259f98128d2f86/grpcio-1.60.0-cp312-cp312-linux_armv7l.whl", hash = "sha256:a7152fa6e597c20cb97923407cf0934e14224af42c2b8d915f48bc3ad2d9ac18", size = 100617931, upload-time = "2023-12-07T18:54:31.309Z" },
+ { url = "https://files.pythonhosted.org/packages/dd/7d/5005318879231a879be0d33c588400941aee08ea8b5b45d3a9061d6bf0fb/grpcio-1.60.0-cp312-cp312-macosx_10_10_universal2.whl", hash = "sha256:7db16dd4ea1b05ada504f08d0dca1cd9b926bed3770f50e715d087c6f00ad748", size = 9612074, upload-time = "2023-12-07T18:54:37.073Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/b5/93ea03649a8315fe00b11871bb7fa807e1ee22d14f5c4de2fbc288c6cd37/grpcio-1.60.0-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:b0571a5aef36ba9177e262dc88a9240c866d903a62799e44fd4aae3f9a2ec17e", size = 5061795, upload-time = "2023-12-07T18:54:41.097Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/b8/91b5b56f7812372bd51342126f0184a1a604723b0f58466ac20c2dcef63a/grpcio-1.60.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6fd9584bf1bccdfff1512719316efa77be235469e1e3295dce64538c4773840b", size = 5566289, upload-time = "2023-12-07T18:54:44.731Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/2e/3337baee24c902d9e82f1eac00bc9dca106934763c4cd0faf819ef01b96b/grpcio-1.60.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d6a478581b1a1a8fdf3318ecb5f4d0cda41cacdffe2b527c23707c9c1b8fdb55", size = 5300194, upload-time = "2023-12-07T18:54:48.259Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/ea/b1229842677f5b712f72760d1633cf36813ec121c986454d6eba6de22093/grpcio-1.60.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:77c8a317f0fd5a0a2be8ed5cbe5341537d5c00bb79b3bb27ba7c5378ba77dbca", size = 5852832, upload-time = "2023-12-07T18:54:51.118Z" },
+ { url = "https://files.pythonhosted.org/packages/05/dc/c641498f09246a61ebe7a721888edf772e2ecdfd524e25ac61e27352d9d3/grpcio-1.60.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:1c30bb23a41df95109db130a6cc1b974844300ae2e5d68dd4947aacba5985aa5", size = 5555224, upload-time = "2023-12-07T18:54:54.663Z" },
+ { url = "https://files.pythonhosted.org/packages/4d/a3/0f07d9fdb9dddce85bbcc671bf49ed3c73301dfc3108ed4ab3212d55ef13/grpcio-1.60.0-cp312-cp312-win32.whl", hash = "sha256:2aef56e85901c2397bd557c5ba514f84de1f0ae5dd132f5d5fed042858115951", size = 3111209, upload-time = "2023-12-07T18:54:57.294Z" },
+ { url = "https://files.pythonhosted.org/packages/73/99/a7b768c6a9873b6f450476bfa389eeef877f152aeb443bec2bd91d9fb5a2/grpcio-1.60.0-cp312-cp312-win_amd64.whl", hash = "sha256:e381fe0c2aa6c03b056ad8f52f8efca7be29fb4d9ae2f8873520843b6039612a", size = 3691893, upload-time = "2023-12-07T18:55:00.164Z" },
+]
+
+[[package]]
+name = "grpcio-health-checking"
+version = "1.60.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "grpcio" },
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ac/24/d58e2855bedfe4150718e03babcadb68d3dd69803cfdb45d27195bafcd20/grpcio-health-checking-1.60.0.tar.gz", hash = "sha256:478b5300778120fed9f6d134d72b157a59f9c06689789218cbff47fafca2f119", size = 16324, upload-time = "2023-12-07T19:00:25.051Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d6/d7/98a877cabb6e0e1dd514f16d77b45036a8add1b0457a6e92c695baed9ded/grpcio_health_checking-1.60.0-py3-none-any.whl", hash = "sha256:13caf28bc93795bd6bdb580b21832ebdd1aa3f5b648ea47ed17362d85bed96d3", size = 18545, upload-time = "2023-12-07T18:56:54.215Z" },
+]
+
+[[package]]
+name = "grpcio-status"
+version = "1.60.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "googleapis-common-protos" },
+ { name = "grpcio" },
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/2a/38/0cd65d29f8fe0b5efaef60a0664885b5457a566b1a531d3e6b76a8bb0f21/grpcio-status-1.60.0.tar.gz", hash = "sha256:f10e0b6db3adc0fdc244b71962814ee982996ef06186446b5695b9fa635aa1ab", size = 13546, upload-time = "2023-12-07T19:00:28.884Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d9/bd/f46d6511088f314cfedc880721fd32d387b8513b22da01cf4771d7439a2b/grpcio_status-1.60.0-py3-none-any.whl", hash = "sha256:7d383fa36e59c1e61d380d91350badd4d12ac56e4de2c2b831b050362c3c572e", size = 14448, upload-time = "2023-12-07T18:56:58.47Z" },
+]
+
+[[package]]
+name = "grpcio-tools"
+version = "1.60.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "grpcio" },
+ { name = "protobuf" },
+ { name = "setuptools" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/3f/8f/1861529938e4a27f8d9b736a4ba58846ab1ccf63b6d7610a86a0329ffc46/grpcio-tools-1.60.0.tar.gz", hash = "sha256:ed30499340228d733ff69fcf4a66590ed7921f94eb5a2bf692258b1280b9dac7", size = 4611505, upload-time = "2023-12-07T19:00:32.95Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/50/09/16b77ffe4f0e3f03c98407a82485e8c9c15bc433334965fbd31a9dfa127b/grpcio_tools-1.60.0-cp312-cp312-linux_armv7l.whl", hash = "sha256:74025fdd6d1cb7ba4b5d087995339e9a09f0c16cf15dfe56368b23e41ffeaf7a", size = 63964335, upload-time = "2023-12-07T18:58:07.71Z" },
+ { url = "https://files.pythonhosted.org/packages/21/2f/3b4f50a810bc9892ac094b29c5c66e575a56813cb4e73fc9a4c7d2dccd3c/grpcio_tools-1.60.0-cp312-cp312-macosx_10_10_universal2.whl", hash = "sha256:5a907a4f1ffba86501b2cdb8682346249ea032b922fc69a92f082ba045cca548", size = 5147864, upload-time = "2023-12-07T18:58:13.289Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/28/f3baa87c8e53b7694761ea69d5d9c3f635b54ff7c09761e3593ca59344b3/grpcio_tools-1.60.0-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:1fbb9554466d560472f07d906bfc8dcaf52f365c2a407015185993e30372a886", size = 2709526, upload-time = "2023-12-07T18:58:15.723Z" },
+ { url = "https://files.pythonhosted.org/packages/9d/07/87e5c0c70dfa0aefc130a6e9116a54866d72449706b35902fbbf3f57f37e/grpcio_tools-1.60.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f10ef47460ce3c6fd400f05fe757b90df63486c9b84d1ecad42dcc5f80c8ac14", size = 3061068, upload-time = "2023-12-07T18:58:19.318Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/cb/e8ad1dd2caac2de9e3a0e6627024ffca3bf30c9911e691f88b7dca4e5097/grpcio_tools-1.60.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:321b18f42a70813545e416ddcb8bf20defa407a8114906711c9710a69596ceda", size = 2797033, upload-time = "2023-12-07T18:58:22.981Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/1d/8c8048c00c194aa8d5648aba853df4076be6d70e9a00a1f25d4830b6dee8/grpcio_tools-1.60.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:081336d8258f1a56542aa8a7a5dec99a2b38d902e19fbdd744594783301b0210", size = 3674987, upload-time = "2023-12-07T18:58:25.715Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/48/dae5740b16b9fdd937fa3bf4f29b6c95b8e0d2dc06a5e82a59e2aa67f07b/grpcio_tools-1.60.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:addc9b23d6ff729d9f83d4a2846292d4c84f5eb2ec38f08489a6a0d66ac2b91e", size = 3283144, upload-time = "2023-12-07T18:58:28.851Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/b6/87d859bf481a2e5629c1ea14a741faa90d533b756af0c514cbff06b00c71/grpcio_tools-1.60.0-cp312-cp312-win32.whl", hash = "sha256:e87cabac7969bdde309575edc2456357667a1b28262b2c1f12580ef48315b19d", size = 922614, upload-time = "2023-12-07T18:58:31.449Z" },
+ { url = "https://files.pythonhosted.org/packages/a8/0a/d6fea138f949f307f2e6958fbf6a3cd94a2d6a51ba3a6333a36b02e24459/grpcio_tools-1.60.0-cp312-cp312-win_amd64.whl", hash = "sha256:e70d867c120d9849093b0ac24d861e378bc88af2552e743d83b9f642d2caa7c2", size = 1068418, upload-time = "2023-12-07T18:58:34.353Z" },
+]
+
+[[package]]
+name = "h11"
+version = "0.16.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" },
+]
+
+[[package]]
+name = "h2"
+version = "4.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "hpack" },
+ { name = "hyperframe" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/1b/38/d7f80fd13e6582fb8e0df8c9a653dcc02b03ca34f4d72f34869298c5baf8/h2-4.2.0.tar.gz", hash = "sha256:c8a52129695e88b1a0578d8d2cc6842bbd79128ac685463b887ee278126ad01f", size = 2150682, upload-time = "2025-02-02T07:43:51.815Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d0/9e/984486f2d0a0bd2b024bf4bc1c62688fcafa9e61991f041fb0e2def4a982/h2-4.2.0-py3-none-any.whl", hash = "sha256:479a53ad425bb29af087f3458a61d30780bc818e4ebcf01f0b536ba916462ed0", size = 60957, upload-time = "2025-02-01T11:02:26.481Z" },
+]
+
+[[package]]
+name = "hf-xet"
+version = "1.1.7"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/b2/0a/a0f56735940fde6dd627602fec9ab3bad23f66a272397560abd65aba416e/hf_xet-1.1.7.tar.gz", hash = "sha256:20cec8db4561338824a3b5f8c19774055b04a8df7fff0cb1ff2cb1a0c1607b80", size = 477719, upload-time = "2025-08-06T00:30:55.741Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b1/7c/8d7803995caf14e7d19a392a486a040f923e2cfeff824e9b800b92072f76/hf_xet-1.1.7-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:60dae4b44d520819e54e216a2505685248ec0adbdb2dd4848b17aa85a0375cde", size = 2761743, upload-time = "2025-08-06T00:30:50.634Z" },
+ { url = "https://files.pythonhosted.org/packages/51/a3/fa5897099454aa287022a34a30e68dbff0e617760f774f8bd1db17f06bd4/hf_xet-1.1.7-cp37-abi3-macosx_11_0_arm64.whl", hash = "sha256:b109f4c11e01c057fc82004c9e51e6cdfe2cb230637644ade40c599739067b2e", size = 2624331, upload-time = "2025-08-06T00:30:49.212Z" },
+ { url = "https://files.pythonhosted.org/packages/86/50/2446a132267e60b8a48b2e5835d6e24fd988000d0f5b9b15ebd6d64ef769/hf_xet-1.1.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6efaaf1a5a9fc3a501d3e71e88a6bfebc69ee3a716d0e713a931c8b8d920038f", size = 3183844, upload-time = "2025-08-06T00:30:47.582Z" },
+ { url = "https://files.pythonhosted.org/packages/20/8f/ccc670616bb9beee867c6bb7139f7eab2b1370fe426503c25f5cbb27b148/hf_xet-1.1.7-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:751571540f9c1fbad9afcf222a5fb96daf2384bf821317b8bfb0c59d86078513", size = 3074209, upload-time = "2025-08-06T00:30:45.509Z" },
+ { url = "https://files.pythonhosted.org/packages/21/0a/4c30e1eb77205565b854f5e4a82cf1f056214e4dc87f2918ebf83d47ae14/hf_xet-1.1.7-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:18b61bbae92d56ae731b92087c44efcac216071182c603fc535f8e29ec4b09b8", size = 3239602, upload-time = "2025-08-06T00:30:52.41Z" },
+ { url = "https://files.pythonhosted.org/packages/f5/1e/fc7e9baf14152662ef0b35fa52a6e889f770a7ed14ac239de3c829ecb47e/hf_xet-1.1.7-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:713f2bff61b252f8523739969f247aa354ad8e6d869b8281e174e2ea1bb8d604", size = 3348184, upload-time = "2025-08-06T00:30:54.105Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/73/e354eae84ceff117ec3560141224724794828927fcc013c5b449bf0b8745/hf_xet-1.1.7-cp37-abi3-win_amd64.whl", hash = "sha256:2e356da7d284479ae0f1dea3cf5a2f74fdf925d6dca84ac4341930d892c7cb34", size = 2820008, upload-time = "2025-08-06T00:30:57.056Z" },
+]
+
+[[package]]
+name = "hpack"
+version = "4.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/2c/48/71de9ed269fdae9c8057e5a4c0aa7402e8bb16f2c6e90b3aa53327b113f8/hpack-4.1.0.tar.gz", hash = "sha256:ec5eca154f7056aa06f196a557655c5b009b382873ac8d1e66e79e87535f1dca", size = 51276, upload-time = "2025-01-22T21:44:58.347Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/07/c6/80c95b1b2b94682a72cbdbfb85b81ae2daffa4291fbfa1b1464502ede10d/hpack-4.1.0-py3-none-any.whl", hash = "sha256:157ac792668d995c657d93111f46b4535ed114f0c9c8d672271bbec7eae1b496", size = 34357, upload-time = "2025-01-22T21:44:56.92Z" },
+]
+
+[[package]]
+name = "httpcore"
+version = "1.0.9"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "certifi" },
+ { name = "h11" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/06/94/82699a10bca87a5556c9c59b5963f2d039dbd239f25bc2a63907a05a14cb/httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8", size = 85484, upload-time = "2025-04-24T22:06:22.219Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" },
+]
+
+[[package]]
+name = "httplib2"
+version = "0.22.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pyparsing" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/3d/ad/2371116b22d616c194aa25ec410c9c6c37f23599dcd590502b74db197584/httplib2-0.22.0.tar.gz", hash = "sha256:d7a10bc5ef5ab08322488bde8c726eeee5c8618723fdb399597ec58f3d82df81", size = 351116, upload-time = "2023-03-21T22:29:37.214Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a8/6c/d2fbdaaa5959339d53ba38e94c123e4e84b8fbc4b84beb0e70d7c1608486/httplib2-0.22.0-py3-none-any.whl", hash = "sha256:14ae0a53c1ba8f3d37e9e27cf37eabb0fb9980f435ba405d546948b009dd64dc", size = 96854, upload-time = "2023-03-21T22:29:35.683Z" },
+]
+
+[[package]]
+name = "httpx"
+version = "0.28.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "anyio" },
+ { name = "certifi" },
+ { name = "httpcore" },
+ { name = "idna" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406, upload-time = "2024-12-06T15:37:23.222Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" },
+]
+
+[package.optional-dependencies]
+http2 = [
+ { name = "h2" },
+]
+
+[[package]]
+name = "huggingface-hub"
+version = "0.34.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "filelock" },
+ { name = "fsspec" },
+ { name = "hf-xet", marker = "platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'" },
+ { name = "packaging" },
+ { name = "pyyaml" },
+ { name = "requests" },
+ { name = "tqdm" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/45/c9/bdbe19339f76d12985bc03572f330a01a93c04dffecaaea3061bdd7fb892/huggingface_hub-0.34.4.tar.gz", hash = "sha256:a4228daa6fb001be3f4f4bdaf9a0db00e1739235702848df00885c9b5742c85c", size = 459768, upload-time = "2025-08-08T09:14:52.365Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/39/7b/bb06b061991107cd8783f300adff3e7b7f284e330fd82f507f2a1417b11d/huggingface_hub-0.34.4-py3-none-any.whl", hash = "sha256:9b365d781739c93ff90c359844221beef048403f1bc1f1c123c191257c3c890a", size = 561452, upload-time = "2025-08-08T09:14:50.159Z" },
+]
+
+[[package]]
+name = "hyperframe"
+version = "6.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/02/e7/94f8232d4a74cc99514c13a9f995811485a6903d48e5d952771ef6322e30/hyperframe-6.1.0.tar.gz", hash = "sha256:f630908a00854a7adeabd6382b43923a4c4cd4b821fcb527e6ab9e15382a3b08", size = 26566, upload-time = "2025-01-22T21:41:49.302Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/48/30/47d0bf6072f7252e6521f3447ccfa40b421b6824517f82854703d0f5a98b/hyperframe-6.1.0-py3-none-any.whl", hash = "sha256:b03380493a519fce58ea5af42e4a42317bf9bd425596f7a0835ffce80f1a42e5", size = 13007, upload-time = "2025-01-22T21:41:47.295Z" },
+]
+
+[[package]]
+name = "idna"
+version = "3.10"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f1/70/7703c29685631f5a7590aa73f1f1d3fa9a380e654b86af429e0934a32f7d/idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", size = 190490, upload-time = "2024-09-15T18:07:39.745Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442, upload-time = "2024-09-15T18:07:37.964Z" },
+]
+
+[[package]]
+name = "importlib-metadata"
+version = "8.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "zipp" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c0/bd/fa8ce65b0a7d4b6d143ec23b0f5fd3f7ab80121078c465bc02baeaab22dc/importlib_metadata-8.4.0.tar.gz", hash = "sha256:9a547d3bc3608b025f93d403fdd1aae741c24fbb8314df4b155675742ce303c5", size = 54320, upload-time = "2024-08-20T17:11:42.348Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c0/14/362d31bf1076b21e1bcdcb0dc61944822ff263937b804a79231df2774d28/importlib_metadata-8.4.0-py3-none-any.whl", hash = "sha256:66f342cc6ac9818fc6ff340576acd24d65ba0b3efabb2b4ac08b598965a4a2f1", size = 26269, upload-time = "2024-08-20T17:11:41.102Z" },
+]
+
+[[package]]
+name = "iniconfig"
+version = "2.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f2/97/ebf4da567aa6827c909642694d71c9fcf53e5b504f2d96afea02718862f3/iniconfig-2.1.0.tar.gz", hash = "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7", size = 4793, upload-time = "2025-03-19T20:09:59.721Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2c/e1/e6716421ea10d38022b952c159d5161ca1193197fb744506875fbb87ea7b/iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760", size = 6050, upload-time = "2025-03-19T20:10:01.071Z" },
+]
+
+[[package]]
+name = "invoke"
+version = "2.2.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f9/42/127e6d792884ab860defc3f4d80a8f9812e48ace584ffc5a346de58cdc6c/invoke-2.2.0.tar.gz", hash = "sha256:ee6cbb101af1a859c7fe84f2a264c059020b0cb7fe3535f9424300ab568f6bd5", size = 299835, upload-time = "2023-07-12T18:05:17.998Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/0a/66/7f8c48009c72d73bc6bbe6eb87ac838d6a526146f7dab14af671121eb379/invoke-2.2.0-py3-none-any.whl", hash = "sha256:6ea924cc53d4f78e3d98bc436b08069a03077e6f85ad1ddaa8a116d7dad15820", size = 160274, upload-time = "2023-07-12T18:05:16.294Z" },
+]
+
+[[package]]
+name = "isodate"
+version = "0.7.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/54/4d/e940025e2ce31a8ce1202635910747e5a87cc3a6a6bb2d00973375014749/isodate-0.7.2.tar.gz", hash = "sha256:4cd1aa0f43ca76f4a6c6c0292a85f40b35ec2e43e315b59f06e6d32171a953e6", size = 29705, upload-time = "2024-10-08T23:04:11.5Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/15/aa/0aca39a37d3c7eb941ba736ede56d689e7be91cab5d9ca846bde3999eba6/isodate-0.7.2-py3-none-any.whl", hash = "sha256:28009937d8031054830160fce6d409ed342816b543597cece116d966c6d99e15", size = 22320, upload-time = "2024-10-08T23:04:09.501Z" },
+]
+
+[[package]]
+name = "isort"
+version = "6.0.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/b8/21/1e2a441f74a653a144224d7d21afe8f4169e6c7c20bb13aec3a2dc3815e0/isort-6.0.1.tar.gz", hash = "sha256:1cb5df28dfbc742e490c5e41bad6da41b805b0a8be7bc93cd0fb2a8a890ac450", size = 821955, upload-time = "2025-02-26T21:13:16.955Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c1/11/114d0a5f4dabbdcedc1125dee0888514c3c3b16d3e9facad87ed96fad97c/isort-6.0.1-py3-none-any.whl", hash = "sha256:2dc5d7f65c9678d94c88dfc29161a320eec67328bc97aad576874cb4be1e9615", size = 94186, upload-time = "2025-02-26T21:13:14.911Z" },
+]
+
+[[package]]
+name = "jinja2"
+version = "3.1.6"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "markupsafe" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" },
+]
+
+[[package]]
+name = "jiter"
+version = "0.10.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ee/9d/ae7ddb4b8ab3fb1b51faf4deb36cb48a4fbbd7cb36bad6a5fca4741306f7/jiter-0.10.0.tar.gz", hash = "sha256:07a7142c38aacc85194391108dc91b5b57093c978a9932bd86a36862759d9500", size = 162759, upload-time = "2025-05-18T19:04:59.73Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6d/b5/348b3313c58f5fbfb2194eb4d07e46a35748ba6e5b3b3046143f3040bafa/jiter-0.10.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:1e274728e4a5345a6dde2d343c8da018b9d4bd4350f5a472fa91f66fda44911b", size = 312262, upload-time = "2025-05-18T19:03:44.637Z" },
+ { url = "https://files.pythonhosted.org/packages/9c/4a/6a2397096162b21645162825f058d1709a02965606e537e3304b02742e9b/jiter-0.10.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7202ae396446c988cb2a5feb33a543ab2165b786ac97f53b59aafb803fef0744", size = 320124, upload-time = "2025-05-18T19:03:46.341Z" },
+ { url = "https://files.pythonhosted.org/packages/2a/85/1ce02cade7516b726dd88f59a4ee46914bf79d1676d1228ef2002ed2f1c9/jiter-0.10.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:23ba7722d6748b6920ed02a8f1726fb4b33e0fd2f3f621816a8b486c66410ab2", size = 345330, upload-time = "2025-05-18T19:03:47.596Z" },
+ { url = "https://files.pythonhosted.org/packages/75/d0/bb6b4f209a77190ce10ea8d7e50bf3725fc16d3372d0a9f11985a2b23eff/jiter-0.10.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:371eab43c0a288537d30e1f0b193bc4eca90439fc08a022dd83e5e07500ed026", size = 369670, upload-time = "2025-05-18T19:03:49.334Z" },
+ { url = "https://files.pythonhosted.org/packages/a0/f5/a61787da9b8847a601e6827fbc42ecb12be2c925ced3252c8ffcb56afcaf/jiter-0.10.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6c675736059020365cebc845a820214765162728b51ab1e03a1b7b3abb70f74c", size = 489057, upload-time = "2025-05-18T19:03:50.66Z" },
+ { url = "https://files.pythonhosted.org/packages/12/e4/6f906272810a7b21406c760a53aadbe52e99ee070fc5c0cb191e316de30b/jiter-0.10.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0c5867d40ab716e4684858e4887489685968a47e3ba222e44cde6e4a2154f959", size = 389372, upload-time = "2025-05-18T19:03:51.98Z" },
+ { url = "https://files.pythonhosted.org/packages/e2/ba/77013b0b8ba904bf3762f11e0129b8928bff7f978a81838dfcc958ad5728/jiter-0.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:395bb9a26111b60141757d874d27fdea01b17e8fac958b91c20128ba8f4acc8a", size = 352038, upload-time = "2025-05-18T19:03:53.703Z" },
+ { url = "https://files.pythonhosted.org/packages/67/27/c62568e3ccb03368dbcc44a1ef3a423cb86778a4389e995125d3d1aaa0a4/jiter-0.10.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:6842184aed5cdb07e0c7e20e5bdcfafe33515ee1741a6835353bb45fe5d1bd95", size = 391538, upload-time = "2025-05-18T19:03:55.046Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/72/0d6b7e31fc17a8fdce76164884edef0698ba556b8eb0af9546ae1a06b91d/jiter-0.10.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:62755d1bcea9876770d4df713d82606c8c1a3dca88ff39046b85a048566d56ea", size = 523557, upload-time = "2025-05-18T19:03:56.386Z" },
+ { url = "https://files.pythonhosted.org/packages/2f/09/bc1661fbbcbeb6244bd2904ff3a06f340aa77a2b94e5a7373fd165960ea3/jiter-0.10.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:533efbce2cacec78d5ba73a41756beff8431dfa1694b6346ce7af3a12c42202b", size = 514202, upload-time = "2025-05-18T19:03:57.675Z" },
+ { url = "https://files.pythonhosted.org/packages/1b/84/5a5d5400e9d4d54b8004c9673bbe4403928a00d28529ff35b19e9d176b19/jiter-0.10.0-cp312-cp312-win32.whl", hash = "sha256:8be921f0cadd245e981b964dfbcd6fd4bc4e254cdc069490416dd7a2632ecc01", size = 211781, upload-time = "2025-05-18T19:03:59.025Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/52/7ec47455e26f2d6e5f2ea4951a0652c06e5b995c291f723973ae9e724a65/jiter-0.10.0-cp312-cp312-win_amd64.whl", hash = "sha256:a7c7d785ae9dda68c2678532a5a1581347e9c15362ae9f6e68f3fdbfb64f2e49", size = 206176, upload-time = "2025-05-18T19:04:00.305Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/b0/279597e7a270e8d22623fea6c5d4eeac328e7d95c236ed51a2b884c54f70/jiter-0.10.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:e0588107ec8e11b6f5ef0e0d656fb2803ac6cf94a96b2b9fc675c0e3ab5e8644", size = 311617, upload-time = "2025-05-18T19:04:02.078Z" },
+ { url = "https://files.pythonhosted.org/packages/91/e3/0916334936f356d605f54cc164af4060e3e7094364add445a3bc79335d46/jiter-0.10.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:cafc4628b616dc32530c20ee53d71589816cf385dd9449633e910d596b1f5c8a", size = 318947, upload-time = "2025-05-18T19:04:03.347Z" },
+ { url = "https://files.pythonhosted.org/packages/6a/8e/fd94e8c02d0e94539b7d669a7ebbd2776e51f329bb2c84d4385e8063a2ad/jiter-0.10.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:520ef6d981172693786a49ff5b09eda72a42e539f14788124a07530f785c3ad6", size = 344618, upload-time = "2025-05-18T19:04:04.709Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/b0/f9f0a2ec42c6e9c2e61c327824687f1e2415b767e1089c1d9135f43816bd/jiter-0.10.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:554dedfd05937f8fc45d17ebdf298fe7e0c77458232bcb73d9fbbf4c6455f5b3", size = 368829, upload-time = "2025-05-18T19:04:06.912Z" },
+ { url = "https://files.pythonhosted.org/packages/e8/57/5bbcd5331910595ad53b9fd0c610392ac68692176f05ae48d6ce5c852967/jiter-0.10.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5bc299da7789deacf95f64052d97f75c16d4fc8c4c214a22bf8d859a4288a1c2", size = 491034, upload-time = "2025-05-18T19:04:08.222Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/be/c393df00e6e6e9e623a73551774449f2f23b6ec6a502a3297aeeece2c65a/jiter-0.10.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5161e201172de298a8a1baad95eb85db4fb90e902353b1f6a41d64ea64644e25", size = 388529, upload-time = "2025-05-18T19:04:09.566Z" },
+ { url = "https://files.pythonhosted.org/packages/42/3e/df2235c54d365434c7f150b986a6e35f41ebdc2f95acea3036d99613025d/jiter-0.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2e2227db6ba93cb3e2bf67c87e594adde0609f146344e8207e8730364db27041", size = 350671, upload-time = "2025-05-18T19:04:10.98Z" },
+ { url = "https://files.pythonhosted.org/packages/c6/77/71b0b24cbcc28f55ab4dbfe029f9a5b73aeadaba677843fc6dc9ed2b1d0a/jiter-0.10.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:15acb267ea5e2c64515574b06a8bf393fbfee6a50eb1673614aa45f4613c0cca", size = 390864, upload-time = "2025-05-18T19:04:12.722Z" },
+ { url = "https://files.pythonhosted.org/packages/6a/d3/ef774b6969b9b6178e1d1e7a89a3bd37d241f3d3ec5f8deb37bbd203714a/jiter-0.10.0-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:901b92f2e2947dc6dfcb52fd624453862e16665ea909a08398dde19c0731b7f4", size = 522989, upload-time = "2025-05-18T19:04:14.261Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/41/9becdb1d8dd5d854142f45a9d71949ed7e87a8e312b0bede2de849388cb9/jiter-0.10.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:d0cb9a125d5a3ec971a094a845eadde2db0de85b33c9f13eb94a0c63d463879e", size = 513495, upload-time = "2025-05-18T19:04:15.603Z" },
+ { url = "https://files.pythonhosted.org/packages/9c/36/3468e5a18238bdedae7c4d19461265b5e9b8e288d3f86cd89d00cbb48686/jiter-0.10.0-cp313-cp313-win32.whl", hash = "sha256:48a403277ad1ee208fb930bdf91745e4d2d6e47253eedc96e2559d1e6527006d", size = 211289, upload-time = "2025-05-18T19:04:17.541Z" },
+ { url = "https://files.pythonhosted.org/packages/7e/07/1c96b623128bcb913706e294adb5f768fb7baf8db5e1338ce7b4ee8c78ef/jiter-0.10.0-cp313-cp313-win_amd64.whl", hash = "sha256:75f9eb72ecb640619c29bf714e78c9c46c9c4eaafd644bf78577ede459f330d4", size = 205074, upload-time = "2025-05-18T19:04:19.21Z" },
+ { url = "https://files.pythonhosted.org/packages/54/46/caa2c1342655f57d8f0f2519774c6d67132205909c65e9aa8255e1d7b4f4/jiter-0.10.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:28ed2a4c05a1f32ef0e1d24c2611330219fed727dae01789f4a335617634b1ca", size = 318225, upload-time = "2025-05-18T19:04:20.583Z" },
+ { url = "https://files.pythonhosted.org/packages/43/84/c7d44c75767e18946219ba2d703a5a32ab37b0bc21886a97bc6062e4da42/jiter-0.10.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:14a4c418b1ec86a195f1ca69da8b23e8926c752b685af665ce30777233dfe070", size = 350235, upload-time = "2025-05-18T19:04:22.363Z" },
+ { url = "https://files.pythonhosted.org/packages/01/16/f5a0135ccd968b480daad0e6ab34b0c7c5ba3bc447e5088152696140dcb3/jiter-0.10.0-cp313-cp313t-win_amd64.whl", hash = "sha256:d7bfed2fe1fe0e4dda6ef682cee888ba444b21e7a6553e03252e4feb6cf0adca", size = 207278, upload-time = "2025-05-18T19:04:23.627Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/9b/1d646da42c3de6c2188fdaa15bce8ecb22b635904fc68be025e21249ba44/jiter-0.10.0-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:5e9251a5e83fab8d87799d3e1a46cb4b7f2919b895c6f4483629ed2446f66522", size = 310866, upload-time = "2025-05-18T19:04:24.891Z" },
+ { url = "https://files.pythonhosted.org/packages/ad/0e/26538b158e8a7c7987e94e7aeb2999e2e82b1f9d2e1f6e9874ddf71ebda0/jiter-0.10.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:023aa0204126fe5b87ccbcd75c8a0d0261b9abdbbf46d55e7ae9f8e22424eeb8", size = 318772, upload-time = "2025-05-18T19:04:26.161Z" },
+ { url = "https://files.pythonhosted.org/packages/7b/fb/d302893151caa1c2636d6574d213e4b34e31fd077af6050a9c5cbb42f6fb/jiter-0.10.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3c189c4f1779c05f75fc17c0c1267594ed918996a231593a21a5ca5438445216", size = 344534, upload-time = "2025-05-18T19:04:27.495Z" },
+ { url = "https://files.pythonhosted.org/packages/01/d8/5780b64a149d74e347c5128d82176eb1e3241b1391ac07935693466d6219/jiter-0.10.0-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:15720084d90d1098ca0229352607cd68256c76991f6b374af96f36920eae13c4", size = 369087, upload-time = "2025-05-18T19:04:28.896Z" },
+ { url = "https://files.pythonhosted.org/packages/e8/5b/f235a1437445160e777544f3ade57544daf96ba7e96c1a5b24a6f7ac7004/jiter-0.10.0-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e4f2fb68e5f1cfee30e2b2a09549a00683e0fde4c6a2ab88c94072fc33cb7426", size = 490694, upload-time = "2025-05-18T19:04:30.183Z" },
+ { url = "https://files.pythonhosted.org/packages/85/a9/9c3d4617caa2ff89cf61b41e83820c27ebb3f7b5fae8a72901e8cd6ff9be/jiter-0.10.0-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ce541693355fc6da424c08b7edf39a2895f58d6ea17d92cc2b168d20907dee12", size = 388992, upload-time = "2025-05-18T19:04:32.028Z" },
+ { url = "https://files.pythonhosted.org/packages/68/b1/344fd14049ba5c94526540af7eb661871f9c54d5f5601ff41a959b9a0bbd/jiter-0.10.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:31c50c40272e189d50006ad5c73883caabb73d4e9748a688b216e85a9a9ca3b9", size = 351723, upload-time = "2025-05-18T19:04:33.467Z" },
+ { url = "https://files.pythonhosted.org/packages/41/89/4c0e345041186f82a31aee7b9d4219a910df672b9fef26f129f0cda07a29/jiter-0.10.0-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:fa3402a2ff9815960e0372a47b75c76979d74402448509ccd49a275fa983ef8a", size = 392215, upload-time = "2025-05-18T19:04:34.827Z" },
+ { url = "https://files.pythonhosted.org/packages/55/58/ee607863e18d3f895feb802154a2177d7e823a7103f000df182e0f718b38/jiter-0.10.0-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:1956f934dca32d7bb647ea21d06d93ca40868b505c228556d3373cbd255ce853", size = 522762, upload-time = "2025-05-18T19:04:36.19Z" },
+ { url = "https://files.pythonhosted.org/packages/15/d0/9123fb41825490d16929e73c212de9a42913d68324a8ce3c8476cae7ac9d/jiter-0.10.0-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:fcedb049bdfc555e261d6f65a6abe1d5ad68825b7202ccb9692636c70fcced86", size = 513427, upload-time = "2025-05-18T19:04:37.544Z" },
+ { url = "https://files.pythonhosted.org/packages/d8/b3/2bd02071c5a2430d0b70403a34411fc519c2f227da7b03da9ba6a956f931/jiter-0.10.0-cp314-cp314-win32.whl", hash = "sha256:ac509f7eccca54b2a29daeb516fb95b6f0bd0d0d8084efaf8ed5dfc7b9f0b357", size = 210127, upload-time = "2025-05-18T19:04:38.837Z" },
+ { url = "https://files.pythonhosted.org/packages/03/0c/5fe86614ea050c3ecd728ab4035534387cd41e7c1855ef6c031f1ca93e3f/jiter-0.10.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:5ed975b83a2b8639356151cef5c0d597c68376fc4922b45d0eb384ac058cfa00", size = 318527, upload-time = "2025-05-18T19:04:40.612Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/4a/4175a563579e884192ba6e81725fc0448b042024419be8d83aa8a80a3f44/jiter-0.10.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3aa96f2abba33dc77f79b4cf791840230375f9534e5fac927ccceb58c5e604a5", size = 354213, upload-time = "2025-05-18T19:04:41.894Z" },
+]
+
+[[package]]
+name = "jmespath"
+version = "1.0.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/00/2a/e867e8531cf3e36b41201936b7fa7ba7b5702dbef42922193f05c8976cd6/jmespath-1.0.1.tar.gz", hash = "sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe", size = 25843, upload-time = "2022-06-17T18:00:12.224Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/31/b4/b9b800c45527aadd64d5b442f9b932b00648617eb5d63d2c7a6587b7cafc/jmespath-1.0.1-py3-none-any.whl", hash = "sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980", size = 20256, upload-time = "2022-06-17T18:00:10.251Z" },
+]
+
+[[package]]
+name = "joblib"
+version = "1.5.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/dc/fe/0f5a938c54105553436dbff7a61dc4fed4b1b2c98852f8833beaf4d5968f/joblib-1.5.1.tar.gz", hash = "sha256:f4f86e351f39fe3d0d32a9f2c3d8af1ee4cec285aafcb27003dda5205576b444", size = 330475, upload-time = "2025-05-23T12:04:37.097Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/7d/4f/1195bbac8e0c2acc5f740661631d8d750dc38d4a32b23ee5df3cde6f4e0d/joblib-1.5.1-py3-none-any.whl", hash = "sha256:4719a31f054c7d766948dcd83e9613686b27114f190f717cec7eaa2084f8a74a", size = 307746, upload-time = "2025-05-23T12:04:35.124Z" },
+]
+
+[[package]]
+name = "jsonschema"
+version = "4.25.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "attrs" },
+ { name = "jsonschema-specifications" },
+ { name = "referencing" },
+ { name = "rpds-py" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d5/00/a297a868e9d0784450faa7365c2172a7d6110c763e30ba861867c32ae6a9/jsonschema-4.25.0.tar.gz", hash = "sha256:e63acf5c11762c0e6672ffb61482bdf57f0876684d8d249c0fe2d730d48bc55f", size = 356830, upload-time = "2025-07-18T15:39:45.11Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/fe/54/c86cd8e011fe98803d7e382fd67c0df5ceab8d2b7ad8c5a81524f791551c/jsonschema-4.25.0-py3-none-any.whl", hash = "sha256:24c2e8da302de79c8b9382fee3e76b355e44d2a4364bb207159ce10b517bd716", size = 89184, upload-time = "2025-07-18T15:39:42.956Z" },
+]
+
+[[package]]
+name = "jsonschema-specifications"
+version = "2025.4.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "referencing" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bf/ce/46fbd9c8119cfc3581ee5643ea49464d168028cfb5caff5fc0596d0cf914/jsonschema_specifications-2025.4.1.tar.gz", hash = "sha256:630159c9f4dbea161a6a2205c3011cc4f18ff381b189fff48bb39b9bf26ae608", size = 15513, upload-time = "2025-04-23T12:34:07.418Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/01/0e/b27cdbaccf30b890c40ed1da9fd4a3593a5cf94dae54fb34f8a4b74fcd3f/jsonschema_specifications-2025.4.1-py3-none-any.whl", hash = "sha256:4653bffbd6584f7de83a67e0d620ef16900b390ddc7939d56684d6c81e33f1af", size = 18437, upload-time = "2025-04-23T12:34:05.422Z" },
+]
+
+[[package]]
+name = "kombu"
+version = "5.5.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "amqp" },
+ { name = "packaging" },
+ { name = "tzdata" },
+ { name = "vine" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/0f/d3/5ff936d8319ac86b9c409f1501b07c426e6ad41966fedace9ef1b966e23f/kombu-5.5.4.tar.gz", hash = "sha256:886600168275ebeada93b888e831352fe578168342f0d1d5833d88ba0d847363", size = 461992, upload-time = "2025-06-01T10:19:22.281Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ef/70/a07dcf4f62598c8ad579df241af55ced65bed76e42e45d3c368a6d82dbc1/kombu-5.5.4-py3-none-any.whl", hash = "sha256:a12ed0557c238897d8e518f1d1fdf84bd1516c5e305af2dacd85c2015115feb8", size = 210034, upload-time = "2025-06-01T10:19:20.436Z" },
+]
+
+[[package]]
+name = "llama-cloud"
+version = "0.1.35"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "certifi" },
+ { name = "httpx" },
+ { name = "pydantic" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/9b/72/816e6e900448e1b4a8137d90e65876b296c5264a23db6ae888bd3e6660ba/llama_cloud-0.1.35.tar.gz", hash = "sha256:200349d5d57424d7461f304cdb1355a58eea3e6ca1e6b0d75c66b2e937216983", size = 106403, upload-time = "2025-07-28T17:22:06.41Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/1d/d2/8d18a021ab757cea231428404f21fe3186bf1ebaac3f57a73c379483fd3f/llama_cloud-0.1.35-py3-none-any.whl", hash = "sha256:b7abab4423118e6f638d2f326749e7a07c6426543bea6da99b623c715b22af71", size = 303280, upload-time = "2025-07-28T17:22:04.946Z" },
+]
+
+[[package]]
+name = "llama-index"
+version = "0.13.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-cli" },
+ { name = "llama-index-core" },
+ { name = "llama-index-embeddings-openai" },
+ { name = "llama-index-indices-managed-llama-cloud" },
+ { name = "llama-index-llms-openai" },
+ { name = "llama-index-readers-file" },
+ { name = "llama-index-readers-llama-parse" },
+ { name = "nltk" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/40/27/5fffc57b98e753eff580184b6260b47d8d2fff4fc91edf75352402f33881/llama_index-0.13.2.tar.gz", hash = "sha256:110e5e8e077aab7643eecb0962bcdb927bdea6a2c9897606b4b26e498d93dd5b", size = 8029, upload-time = "2025-08-14T22:04:03.732Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5c/3a/de1a7d6cf24c41082464fa4bda82dba014acee0f438ef0cec606ba43ed28/llama_index-0.13.2-py3-none-any.whl", hash = "sha256:8de8eefffcfa64a9225267d7813fcb55b8ea12181d4044efe5b22642d91d2294", size = 7027, upload-time = "2025-08-14T22:04:02.408Z" },
+]
+
+[[package]]
+name = "llama-index-cli"
+version = "0.5.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "llama-index-embeddings-openai" },
+ { name = "llama-index-llms-openai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d2/e3/ac6928586e20cfd327a2a38a00781cbc8fae923edcd0316c23e38aae1537/llama_index_cli-0.5.1.tar.gz", hash = "sha256:0446159d85c56c29022c1c830c9886f670d5f59d69343c3c029a3b20eda1a9d8", size = 24821, upload-time = "2025-09-12T15:22:44.064Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b3/16/b53af5b23921d1e18f57b7a79d557b34554df295c63f5c59d5bee1f5fb47/llama_index_cli-0.5.1-py3-none-any.whl", hash = "sha256:5429b2fd7960df7724c2955b6e6901f6fa910b7b5ecef411c979a8b545a6b7e2", size = 28179, upload-time = "2025-09-12T15:22:43.169Z" },
+]
+
+[[package]]
+name = "llama-index-core"
+version = "0.13.6"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiohttp" },
+ { name = "aiosqlite" },
+ { name = "banks" },
+ { name = "dataclasses-json" },
+ { name = "deprecated" },
+ { name = "dirtyjson" },
+ { name = "filetype" },
+ { name = "fsspec" },
+ { name = "httpx" },
+ { name = "llama-index-workflows" },
+ { name = "nest-asyncio" },
+ { name = "networkx" },
+ { name = "nltk" },
+ { name = "numpy" },
+ { name = "pillow" },
+ { name = "platformdirs" },
+ { name = "pydantic" },
+ { name = "pyyaml" },
+ { name = "requests" },
+ { name = "setuptools" },
+ { name = "sqlalchemy", extra = ["asyncio"] },
+ { name = "tenacity" },
+ { name = "tiktoken" },
+ { name = "tqdm" },
+ { name = "typing-extensions" },
+ { name = "typing-inspect" },
+ { name = "wrapt" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/2d/f8/4f6e2bbc34ec6586456727a644960a1ff2d9db60b92071e213ad9d160456/llama_index_core-0.13.6.tar.gz", hash = "sha256:80315a6bd1f9804f48c1870eff1a0315bf9fe5a413747d53eb88a8ebb2602b97", size = 7232179, upload-time = "2025-09-07T03:27:26.544Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/35/23/7e497216ece6e041c6a271f2b7952e5609729da0dcdf09dd3f25a4efc1b9/llama_index_core-0.13.6-py3-none-any.whl", hash = "sha256:67bec3c06a8105cd82d83db0f8c3122f4e4d8a4b9c7a2768cced6a2686ddb331", size = 7575324, upload-time = "2025-09-07T03:27:19.243Z" },
+]
+
+[[package]]
+name = "llama-index-embeddings-azure-openai"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "llama-index-embeddings-openai" },
+ { name = "llama-index-llms-azure-openai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/36/c8/9b0eb78531ec2b42ca06750e5b256b122c0449d9f4e4ce3be5f4b1601a3e/llama_index_embeddings_azure_openai-0.4.0.tar.gz", hash = "sha256:092e48e79e47d9c552792dc17fd527ec2ebdc657781ccadeb43cfcbc0b5d354a", size = 4785, upload-time = "2025-07-31T00:31:02.584Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3a/e3/f030182f1c9268b1d59ae7d2e73e2782ab8a152ec1dd04ed1946532825b1/llama_index_embeddings_azure_openai-0.4.0-py3-none-any.whl", hash = "sha256:4a570fb4478493baf6eeb07f584880d7369728eaf6beff6e250ce46244e37cac", size = 4419, upload-time = "2025-07-31T00:31:01.661Z" },
+]
+
+[[package]]
+name = "llama-index-embeddings-bedrock"
+version = "0.6.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aioboto3" },
+ { name = "boto3" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/1f/0f/2b8a06719289717254c5835475341996b015298115d3dab42d1a1ea36868/llama_index_embeddings_bedrock-0.6.1.tar.gz", hash = "sha256:9efce880d1c48473d1eb21d17f4e766a1ae4d0f1b7e9995c91aa50cab8ee79f2", size = 6844, upload-time = "2025-08-08T20:34:13.204Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/83/87/80fe257184c47176537ce6957d888f18da36930ace0f9f92e57ca25c47a3/llama_index_embeddings_bedrock-0.6.1-py3-none-any.whl", hash = "sha256:cd3f003810e359f9101b1e4740fc4794bd0091753dee0ed45998881d1de8eeab", size = 6515, upload-time = "2025-08-08T20:34:12.21Z" },
+]
+
+[[package]]
+name = "llama-index-embeddings-google"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-generativeai" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bd/69/802218bbacb5d602b8368dccb2d8c39e91d2f178d175827ca3701122925e/llama_index_embeddings_google-0.4.0.tar.gz", hash = "sha256:c15b49f81017e3dfc88e06bd7145c1eb170eacaf8890ece38fe5a077471145bd", size = 4722, upload-time = "2025-07-30T21:02:10.326Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ac/cf/1f9e3b0e764a92cd2e6fc0452e1ecf7471c22a4798d7556a16cbc7a15308/llama_index_embeddings_google-0.4.0-py3-none-any.whl", hash = "sha256:df2243587eeadf6ae386f19ff7026a92f3d2abffd4e46a5be6c0262e75986b08", size = 5921, upload-time = "2025-07-30T21:02:09.575Z" },
+]
+
+[[package]]
+name = "llama-index-embeddings-ollama"
+version = "0.8.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "ollama" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/19/d9/589db89f1ff92e247688feee7d027b0aefab787ff6c5d1da2bc4d31cd97f/llama_index_embeddings_ollama-0.8.1.tar.gz", hash = "sha256:c5692899bdab2508a1122e16eeffe8d5e3349ab8c3addad0784d787ff32e178a", size = 3841, upload-time = "2025-08-10T22:47:05.775Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5f/6d/3ba2ee2ea0f3812f33cacd44cbfe3ec3fdd4d840387db7327c2cdc9255a5/llama_index_embeddings_ollama-0.8.1-py3-none-any.whl", hash = "sha256:480f94809426de3a6e17f2ef84873ae0f164bf43c317ba9d709d44ee62a1dae5", size = 3420, upload-time = "2025-08-10T22:47:04.752Z" },
+]
+
+[[package]]
+name = "llama-index-embeddings-openai"
+version = "0.5.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "openai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/26/6a/80ed46993c6827786cdec4f6b553f3f4e5fc8741c31e8903c694833d24bf/llama_index_embeddings_openai-0.5.0.tar.gz", hash = "sha256:ac587839a111089ea8a6255f9214016d7a813b383bbbbf9207799be1100758eb", size = 7019, upload-time = "2025-07-30T19:55:05.699Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/01/21/65f13a385292d7d573dfde472da7daff5f779345d60c5c3e274142ec8ba2/llama_index_embeddings_openai-0.5.0-py3-none-any.whl", hash = "sha256:d817edb22e3ff475e8cd1833faf1147028986bc1d688f7894ef947558864b728", size = 7009, upload-time = "2025-07-30T19:55:04.86Z" },
+]
+
+[[package]]
+name = "llama-index-embeddings-vertex"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-cloud-aiplatform" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/7b/df/3dbcf17f8b53954bbbf8d97b2910bca35c77e9922c11c28f6b669e0a0e68/llama_index_embeddings_vertex-0.4.0.tar.gz", hash = "sha256:0e7f41bc9e6307b95aabc7dba21537581345806e55098bc0e7b897c7eb83e6ec", size = 5988, upload-time = "2025-07-30T20:56:50.727Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/98/a4/ed32059e80a00b2780a78cc013874de9a92f001a29cf090c39d8ffdcbc8d/llama_index_embeddings_vertex-0.4.0-py3-none-any.whl", hash = "sha256:97f33cb84927ab718c822a8953cee999f27082fd764b5e4f160d324daea117be", size = 5635, upload-time = "2025-07-30T20:56:49.945Z" },
+]
+
+[[package]]
+name = "llama-index-indices-managed-llama-cloud"
+version = "0.9.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "deprecated" },
+ { name = "llama-cloud" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/61/4a/79044fcb3209583d1ffe0c2a7c19dddfb657a03faeb9fe0cf5a74027e646/llama_index_indices_managed_llama_cloud-0.9.4.tar.gz", hash = "sha256:b5e00752ab30564abf19c57595a2107f5697c3b03b085817b4fca84a38ebbd59", size = 15146, upload-time = "2025-09-08T20:29:58.673Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a6/6a/0e33245df06afc9766c46a1fe92687be8a09da5d0d0128bc08d84a9f5efa/llama_index_indices_managed_llama_cloud-0.9.4-py3-none-any.whl", hash = "sha256:535a08811046803ca6ab7f8e9d510e926aa5306608b02201ad3d9d21701383bc", size = 17005, upload-time = "2025-09-08T20:29:57.876Z" },
+]
+
+[[package]]
+name = "llama-index-instrumentation"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "deprecated" },
+ { name = "pydantic" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/8e/ad/8be7010038c12ec9c0ed41a070527fd880e6181d87ae00d00790aefa50ee/llama_index_instrumentation-0.4.0.tar.gz", hash = "sha256:f38ecc1f02b6c1f7ab84263baa6467fac9f86538c0ee25542853de46278abea7", size = 44948, upload-time = "2025-07-30T21:02:26.86Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/78/36/b85d699d2827464f9ba1c5adb1069cf18af0e3c3e45cfe017142dd85eb7c/llama_index_instrumentation-0.4.0-py3-none-any.whl", hash = "sha256:83f73156be34dd0121dfe9e259883620e19f0162f152ac483e179ad5ad0396ac", size = 14950, upload-time = "2025-07-30T21:02:25.956Z" },
+]
+
+[[package]]
+name = "llama-index-llms-anthropic"
+version = "0.8.5"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "anthropic", extra = ["bedrock", "vertex"] },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e8/d2/19bdc50027c5a60d4d8567a7dc66c78946aa2be6e65688d11abb70e1ceb1/llama_index_llms_anthropic-0.8.5.tar.gz", hash = "sha256:e85194104eb1df66ee9e0b234fb37f3e12b368bb51888d772bd5ee6b1fb57d22", size = 12728, upload-time = "2025-08-21T16:47:22.383Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bd/53/0a13d516be051d042f3b367a4fb1e8cde900095334865f532f924e360763/llama_index_llms_anthropic-0.8.5-py3-none-any.whl", hash = "sha256:5a403b13733a5b18595b584a84d39bcffe51c9dfb7d79323d38efd45fd983b43", size = 12907, upload-time = "2025-08-21T16:47:21.192Z" },
+]
+
+[[package]]
+name = "llama-index-llms-anyscale"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "llama-index-llms-openai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/84/dd/5f21180ad36bb7193436f3bbc8e91549700635a6ef90080c99826e034bc2/llama_index_llms_anyscale-0.4.0.tar.gz", hash = "sha256:e59927075f7628117971668b286ada3a453aba4a604f90aaad533275903b7a2e", size = 5809, upload-time = "2025-07-30T21:35:09.894Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c5/4e/ac554396b4b25d7226961ae03c50b0999c8302ee775c238e7e27fc874f05/llama_index_llms_anyscale-0.4.0-py3-none-any.whl", hash = "sha256:37e249b439c86d11e1dba21ee9a0685bf5c57435429899b229564ee5bfb1cfff", size = 5916, upload-time = "2025-07-30T21:35:08.984Z" },
+]
+
+[[package]]
+name = "llama-index-llms-azure-openai"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "azure-identity" },
+ { name = "httpx" },
+ { name = "llama-index-core" },
+ { name = "llama-index-llms-openai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/25/3e/70c189502d1ee84dd73db66f3c4978dc5ce975e233954dc2724c9374d659/llama_index_llms_azure_openai-0.4.0.tar.gz", hash = "sha256:bba297fd7d0e85e9cf17ac03f7617ff9812719b6312e0f56ee4242ae11fa5d9b", size = 7054, upload-time = "2025-07-30T21:36:39.408Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5f/1a/3992ac83c237eba455411dbd5ab2ec65dbefa8670aecd8a3f809b30cbcbc/llama_index_llms_azure_openai-0.4.0-py3-none-any.whl", hash = "sha256:f7f69cad12d7e6da75a58f6ec49f719dee3f03d30bbafc7ec29b2bf9087b0d51", size = 7257, upload-time = "2025-07-30T21:36:38.398Z" },
+]
+
+[[package]]
+name = "llama-index-llms-bedrock-converse"
+version = "0.8.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aioboto3" },
+ { name = "boto3" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/7d/21/6fac92ca12bb4cd49c1082300917c93caab7bcfacf95a22a17e1fc4438bd/llama_index_llms_bedrock_converse-0.8.2.tar.gz", hash = "sha256:1886a0e66326cd4515417e90234827ed5e7ae3f2940ae3bee324ab4f51fc0ef0", size = 14941, upload-time = "2025-08-12T23:54:04.519Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/f4/be/f93bc60dc46f4ecef2ab64adbbd53a8874073a2b7d9125394e2bb51fc70b/llama_index_llms_bedrock_converse-0.8.2-py3-none-any.whl", hash = "sha256:68d86f187f9715aa0b09b4da3b70a7d4120a87f40bd029362632ad67d1cc9152", size = 15427, upload-time = "2025-08-12T23:54:03.289Z" },
+]
+
+[[package]]
+name = "llama-index-llms-mistralai"
+version = "0.7.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "mistralai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/20/28/c9be8c068e67a34701661a64dacc1be06f519b5701caf6ad61101217391e/llama_index_llms_mistralai-0.7.0.tar.gz", hash = "sha256:85386978996e2b7acbb398313bfed2e930518ade8f1b75ebffc609e8fe03550b", size = 8485, upload-time = "2025-07-30T21:07:43.776Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b3/46/20bf59de219a849a3e3126d4412beae7fc550509426ab9651d789c4d5f64/llama_index_llms_mistralai-0.7.0-py3-none-any.whl", hash = "sha256:030e4e57bfa3764cb8cc8cd72ed35e785c8bbd59fce183958922d6563289072a", size = 8576, upload-time = "2025-07-30T21:07:42.712Z" },
+]
+
+[[package]]
+name = "llama-index-llms-ollama"
+version = "0.7.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "ollama" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c3/ea/e7d0cbf14be11352312c8713de9591a2d9c8da9a4b6d507ae821d7dca6e9/llama_index_llms_ollama-0.7.1.tar.gz", hash = "sha256:189b65ea25c03c660c105b80dbb5109c4fea8da68f1e90592aebfdfdde708928", size = 8472, upload-time = "2025-08-14T20:17:32.271Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/8c/0d/1ceba6f1dda184de5b5b686a06eaf48ecdf8437d7127353500d01c7ccf62/llama_index_llms_ollama-0.7.1-py3-none-any.whl", hash = "sha256:5e5d04d7ad3446059057821aade0fe20b04f3cb56651792e1f6b8732cbacf466", size = 8152, upload-time = "2025-08-14T20:17:31.519Z" },
+]
+
+[[package]]
+name = "llama-index-llms-openai"
+version = "0.5.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "openai" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/20/59/4c414d79a21189d9db6de58ecbc297cd0f5ea121803b836bd134c67dd7a3/llama_index_llms_openai-0.5.4.tar.gz", hash = "sha256:9e36b6d2fc5f056b00ee655901b3bb7e7060b23f7b19439889fb78d696340f54", size = 24230, upload-time = "2025-08-16T22:41:17.408Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ad/62/aec65450b8d7ba723fa557884ac34d94b2b8f3876a54249c05d240a2be6c/llama_index_llms_openai-0.5.4-py3-none-any.whl", hash = "sha256:8d42fbfa56b5f281ad0dfcb2915916c188b5876625f9f8d27016b7dc4366cc24", size = 25357, upload-time = "2025-08-16T22:41:16.472Z" },
+]
+
+[[package]]
+name = "llama-index-llms-palm"
+version = "0.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-generativeai" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/21/11/81f0ba7d6fa170278e1a55a6f330fabe59b10e9abfb8941619414357edeb/llama_index_llms_palm-0.4.0.tar.gz", hash = "sha256:5a5b1981bb20c0563fea0fecf1b743970cb34048455f0df740934753850a5fab", size = 5066, upload-time = "2025-07-30T21:12:47.667Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2e/25/ab9e3eb09311c5daf4e7d048f4b9530012482b7e3032bff44e6c5428808f/llama_index_llms_palm-0.4.0-py3-none-any.whl", hash = "sha256:0c1dfa02302d0d4bf97a9434d7edae0b93bf7aa50b37ff807f6860ba4e5bbc46", size = 4719, upload-time = "2025-07-30T21:12:46.625Z" },
+]
+
+[[package]]
+name = "llama-index-llms-replicate"
+version = "0.5.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/6a/83/c6594c464bded3afdd04e893595a1374c646a74d3e1a9c48160ef1c3d33b/llama_index_llms_replicate-0.5.0.tar.gz", hash = "sha256:ebde891f5669219ddb0bdb4f7e6aff075404f27c78bbe423686e1c0cf82ec0c6", size = 4440, upload-time = "2025-07-30T21:04:36.577Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d4/1c/fb26d8c03b157fac04cc0d6d597c01ddffae01a420c9480d11325f56402d/llama_index_llms_replicate-0.5.0-py3-none-any.whl", hash = "sha256:57824613a0732f2bd6e24574d86ea360fd4a36765b55a771f4a1c6b9f3b0f782", size = 3999, upload-time = "2025-07-30T21:04:35.681Z" },
+]
+
+[[package]]
+name = "llama-index-llms-vertex"
+version = "0.6.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-cloud-aiplatform" },
+ { name = "llama-index-core" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b1/d6/05d5dbc10ad757c5ebb01d696f4966a590cacb1cbc95ac16ef69b0630620/llama_index_llms_vertex-0.6.0.tar.gz", hash = "sha256:8377701657eeb6256a116ab11b62d3e4ed8f6802b9500fbae10eb69676214573", size = 9394, upload-time = "2025-07-30T20:56:25.67Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a5/7b/ed902c5f5622c8d463a4e9bb79d9072bd9224de7537a89f27080351ff3b9/llama_index_llms_vertex-0.6.0-py3-none-any.whl", hash = "sha256:48f3702f92b48485dfb5b3c08d1dbc45139ea797ec5d6c7f5901b0bf8cbf4e11", size = 9956, upload-time = "2025-07-30T20:56:24.604Z" },
+]
+
+[[package]]
+name = "llama-index-readers-file"
+version = "0.5.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "beautifulsoup4" },
+ { name = "defusedxml" },
+ { name = "llama-index-core" },
+ { name = "pandas" },
+ { name = "pypdf" },
+ { name = "striprtf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/01/d9/c67ad2b9cba8dacf1d4a55fe5432357b6eceaecfb096a0de5c1cbd959b98/llama_index_readers_file-0.5.4.tar.gz", hash = "sha256:5e766f32597622e66529464101914548ad683770a0a5d2bdc9ee84eb3a110332", size = 32565, upload-time = "2025-09-08T20:39:40.287Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ea/e3/76d72a7281b9c88d488908731c9034e1ee1a2cad5aa1dead76b051eca989/llama_index_readers_file-0.5.4-py3-none-any.whl", hash = "sha256:135be5ddda66c5b35883911918b2d99f67a2ab010d180af5630c872ea9509d45", size = 51827, upload-time = "2025-09-08T20:39:39.408Z" },
+]
+
+[[package]]
+name = "llama-index-readers-llama-parse"
+version = "0.5.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "llama-parse" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b3/77/5bfaab20e6ec8428dbf2352e18be550c957602723d69383908176b5686cd/llama_index_readers_llama_parse-0.5.1.tar.gz", hash = "sha256:2b78b73faa933e30e6c69df351e4e9f36dfe2ae142e2ab3969ddd2ac48930e37", size = 3858, upload-time = "2025-09-08T20:41:29.201Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/68/81/52410c7245dcbf1a54756a9ce3892cdd167ec0b884d696de1304ca3f452e/llama_index_readers_llama_parse-0.5.1-py3-none-any.whl", hash = "sha256:0d41450ed29b0c49c024e206ef6c8e662b1854e77a1c5faefed3b958be54f880", size = 3203, upload-time = "2025-09-08T20:41:28.438Z" },
+]
+
+[[package]]
+name = "llama-index-vector-stores-milvus"
+version = "0.9.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "pymilvus" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/92/50/428b4af2d65b3f0ec0b41638579a5d67c027d64f46c2e11769975737f0ef/llama_index_vector_stores_milvus-0.9.0.tar.gz", hash = "sha256:938f002aa0817c3afc85f233791fdeefd87093e806c5108411f07d8d616b3d30", size = 15284, upload-time = "2025-07-30T21:12:38.4Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ac/fa/56b1d6626a4fcd968a940b13683b181cfd14bdb8b348772bedfa82b7e71d/llama_index_vector_stores_milvus-0.9.0-py3-none-any.whl", hash = "sha256:a08e20e72816c7b81cb82d27211e63ca175e4683b07e954adef1bae7a2c844f7", size = 15563, upload-time = "2025-07-30T21:12:37.465Z" },
+]
+
+[[package]]
+name = "llama-index-vector-stores-pinecone"
+version = "0.7.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "pinecone" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/13/31/9be27780523a4784bea5cf7910004b0e805b9fef09a4a5ed3af38757cb2b/llama_index_vector_stores_pinecone-0.7.0.tar.gz", hash = "sha256:72f4828115d5857249fc7d7a0753a6b1c2644c929687d86f5bed41274e5b7e76", size = 7852, upload-time = "2025-07-30T20:54:28.213Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/54/de/901d76d42474cce0aa8c054ee76e4dc9967d8df84907797ab99b3423d988/llama_index_vector_stores_pinecone-0.7.0-py3-none-any.whl", hash = "sha256:023ac4cde067f7154cc90534b72388c0b6905eaa41f30c7ef1446f67e3549b25", size = 8039, upload-time = "2025-07-30T20:54:27.487Z" },
+]
+
+[[package]]
+name = "llama-index-vector-stores-postgres"
+version = "0.6.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "asyncpg" },
+ { name = "llama-index-core" },
+ { name = "pgvector" },
+ { name = "psycopg2-binary" },
+ { name = "sqlalchemy", extra = ["asyncio"] },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/a3/2e/ddd8accef30a39f8ffb7bae9f5a5c91ba5f1f45ede1d55c73ba78e61e23a/llama_index_vector_stores_postgres-0.6.3.tar.gz", hash = "sha256:b15d2e7c3bf2a0b18754934a84cf5324403b9401e2b31bcdb00418ed2d03770c", size = 11316, upload-time = "2025-08-12T12:36:35.281Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a0/cd/0aa5189615f33e805d8bc306d8a0f646892b55245e88fe6fb8df61059f66/llama_index_vector_stores_postgres-0.6.3-py3-none-any.whl", hash = "sha256:6086b7d450bf1204eb5523cd924c8395fc9cbd212f337d1caef18ce41cefc198", size = 11042, upload-time = "2025-08-12T12:36:33.019Z" },
+]
+
+[[package]]
+name = "llama-index-vector-stores-qdrant"
+version = "0.7.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "grpcio" },
+ { name = "llama-index-core" },
+ { name = "qdrant-client" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/88/84/441a41a34dea214c89e3cabc177f07615ba4b434d46a70ba810c8c3c5bcd/llama_index_vector_stores_qdrant-0.7.1.tar.gz", hash = "sha256:d51a561dc5aad270c4bbed72370cea9002e4b72d0038ec5b465f6bcdb67b1213", size = 13013, upload-time = "2025-07-31T18:18:55.931Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/44/b3/623615e44ff4c19ca593a620eef670cad9bed78fe6e4d364753415b71aa0/llama_index_vector_stores_qdrant-0.7.1-py3-none-any.whl", hash = "sha256:f48eeb9228f7dc7e4d41a55d76dcf6d93b8bfbea1c943c09140a09252018f577", size = 13204, upload-time = "2025-07-31T18:18:54.364Z" },
+]
+
+[[package]]
+name = "llama-index-vector-stores-weaviate"
+version = "1.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-core" },
+ { name = "weaviate-client" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/5e/ab/6da9ec13e8c1a6dc2a00eb17074388a4720d66252f9b784b725f2282ca5e/llama_index_vector_stores_weaviate-1.4.0.tar.gz", hash = "sha256:c5374406b90b4f27455c623a84f56c6df3d71408ffac8984cab39edc8f6a748e", size = 8535, upload-time = "2025-07-30T20:57:22.275Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e6/70/aef7524a6ed14f79dca84685559045b303cb43f11a38b9f790e6274115e2/llama_index_vector_stores_weaviate-1.4.0-py3-none-any.whl", hash = "sha256:5e3ac7e499e20988f8165c7dfa223b64714572164114e5818c3d51ff273a0c53", size = 9326, upload-time = "2025-07-30T20:57:21.207Z" },
+]
+
+[[package]]
+name = "llama-index-workflows"
+version = "1.3.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "llama-index-instrumentation" },
+ { name = "pydantic" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/00/dc/54fd5dec0ad3c65f3e8a520db7a3024141b71cd41660d0baca3cd6b18707/llama_index_workflows-1.3.0.tar.gz", hash = "sha256:9c1688e237efad384f16485af71c6f9456a2eb6d85bf61ff49e5717f10ff286d", size = 1040839, upload-time = "2025-08-07T09:11:00.307Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3b/cf/0c50bc6e5c4fb7913f5682a0d26a60b976533dd8a87a5dbd84f617c6f1ab/llama_index_workflows-1.3.0-py3-none-any.whl", hash = "sha256:328cc25d92b014ef527f105a2f2088c0924fff0494e53d93decb951f14fbfe47", size = 42527, upload-time = "2025-08-07T09:10:59.155Z" },
+]
+
+[[package]]
+name = "llama-parse"
+version = "0.5.19"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "click" },
+ { name = "llama-index-core" },
+ { name = "pydantic" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/3b/02/63839a55f6f207110400c4f394152fd0290e9f8e450226b02a87cfdbd835/llama_parse-0.5.19.tar.gz", hash = "sha256:db69da70e199a2664705eb983a70fa92b7cee19dd6cff175af7692a0b8a4dd53", size = 16100, upload-time = "2024-12-27T19:08:43.051Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/38/b7/3ff106e8199992bb62e72f195c8f6f2f2fe4a185f5f92746f0ed9db5c5d2/llama_parse-0.5.19-py3-none-any.whl", hash = "sha256:715cc895d183531b4299359d4f4004089b2e522f5f137f316084e7aa04035b62", size = 15421, upload-time = "2024-12-27T19:08:41.974Z" },
+]
+
+[[package]]
+name = "llmwhisperer-client"
+version = "2.4.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/6c/9c/ebd684cfbcf5a76d42711a1ef314145a680cd5ae5c07168ede7fdac3bb72/llmwhisperer_client-2.4.2.tar.gz", hash = "sha256:085ed27108f9ae7cf042af58c5a3022ef51051db395774b5771ed4ed9b4be154", size = 3261138, upload-time = "2025-07-21T11:12:57.897Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b6/21/7cab42f479f7dba81f53e77d2b6fdce5f707cb1b50d50fde707671be7211/llmwhisperer_client-2.4.2-py3-none-any.whl", hash = "sha256:15dba4dd86aec521b6a296460031b19281847876cd6378e24a980b3d5c681c50", size = 9663, upload-time = "2025-07-21T11:12:56.725Z" },
+]
+
+[[package]]
+name = "markupsafe"
+version = "3.0.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/b2/97/5d42485e71dfc078108a86d6de8fa46db44a1a9295e89c5d6d4a06e23a62/markupsafe-3.0.2.tar.gz", hash = "sha256:ee55d3edf80167e48ea11a923c7386f4669df67d7994554387f84e7d8b0a2bf0", size = 20537, upload-time = "2024-10-18T15:21:54.129Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/22/09/d1f21434c97fc42f09d290cbb6350d44eb12f09cc62c9476effdb33a18aa/MarkupSafe-3.0.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:9778bd8ab0a994ebf6f84c2b949e65736d5575320a17ae8984a77fab08db94cf", size = 14274, upload-time = "2024-10-18T15:21:13.777Z" },
+ { url = "https://files.pythonhosted.org/packages/6b/b0/18f76bba336fa5aecf79d45dcd6c806c280ec44538b3c13671d49099fdd0/MarkupSafe-3.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846ade7b71e3536c4e56b386c2a47adf5741d2d8b94ec9dc3e92e5e1ee1e2225", size = 12348, upload-time = "2024-10-18T15:21:14.822Z" },
+ { url = "https://files.pythonhosted.org/packages/e0/25/dd5c0f6ac1311e9b40f4af06c78efde0f3b5cbf02502f8ef9501294c425b/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1c99d261bd2d5f6b59325c92c73df481e05e57f19837bdca8413b9eac4bd8028", size = 24149, upload-time = "2024-10-18T15:21:15.642Z" },
+ { url = "https://files.pythonhosted.org/packages/f3/f0/89e7aadfb3749d0f52234a0c8c7867877876e0a20b60e2188e9850794c17/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e17c96c14e19278594aa4841ec148115f9c7615a47382ecb6b82bd8fea3ab0c8", size = 23118, upload-time = "2024-10-18T15:21:17.133Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/da/f2eeb64c723f5e3777bc081da884b414671982008c47dcc1873d81f625b6/MarkupSafe-3.0.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:88416bd1e65dcea10bc7569faacb2c20ce071dd1f87539ca2ab364bf6231393c", size = 22993, upload-time = "2024-10-18T15:21:18.064Z" },
+ { url = "https://files.pythonhosted.org/packages/da/0e/1f32af846df486dce7c227fe0f2398dc7e2e51d4a370508281f3c1c5cddc/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:2181e67807fc2fa785d0592dc2d6206c019b9502410671cc905d132a92866557", size = 24178, upload-time = "2024-10-18T15:21:18.859Z" },
+ { url = "https://files.pythonhosted.org/packages/c4/f6/bb3ca0532de8086cbff5f06d137064c8410d10779c4c127e0e47d17c0b71/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:52305740fe773d09cffb16f8ed0427942901f00adedac82ec8b67752f58a1b22", size = 23319, upload-time = "2024-10-18T15:21:19.671Z" },
+ { url = "https://files.pythonhosted.org/packages/a2/82/8be4c96ffee03c5b4a034e60a31294daf481e12c7c43ab8e34a1453ee48b/MarkupSafe-3.0.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ad10d3ded218f1039f11a75f8091880239651b52e9bb592ca27de44eed242a48", size = 23352, upload-time = "2024-10-18T15:21:20.971Z" },
+ { url = "https://files.pythonhosted.org/packages/51/ae/97827349d3fcffee7e184bdf7f41cd6b88d9919c80f0263ba7acd1bbcb18/MarkupSafe-3.0.2-cp312-cp312-win32.whl", hash = "sha256:0f4ca02bea9a23221c0182836703cbf8930c5e9454bacce27e767509fa286a30", size = 15097, upload-time = "2024-10-18T15:21:22.646Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/80/a61f99dc3a936413c3ee4e1eecac96c0da5ed07ad56fd975f1a9da5bc630/MarkupSafe-3.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:8e06879fc22a25ca47312fbe7c8264eb0b662f6db27cb2d3bbbc74b1df4b9b87", size = 15601, upload-time = "2024-10-18T15:21:23.499Z" },
+ { url = "https://files.pythonhosted.org/packages/83/0e/67eb10a7ecc77a0c2bbe2b0235765b98d164d81600746914bebada795e97/MarkupSafe-3.0.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:ba9527cdd4c926ed0760bc301f6728ef34d841f405abf9d4f959c478421e4efd", size = 14274, upload-time = "2024-10-18T15:21:24.577Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/6d/9409f3684d3335375d04e5f05744dfe7e9f120062c9857df4ab490a1031a/MarkupSafe-3.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f8b3d067f2e40fe93e1ccdd6b2e1d16c43140e76f02fb1319a05cf2b79d99430", size = 12352, upload-time = "2024-10-18T15:21:25.382Z" },
+ { url = "https://files.pythonhosted.org/packages/d2/f5/6eadfcd3885ea85fe2a7c128315cc1bb7241e1987443d78c8fe712d03091/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:569511d3b58c8791ab4c2e1285575265991e6d8f8700c7be0e88f86cb0672094", size = 24122, upload-time = "2024-10-18T15:21:26.199Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/91/96cf928db8236f1bfab6ce15ad070dfdd02ed88261c2afafd4b43575e9e9/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:15ab75ef81add55874e7ab7055e9c397312385bd9ced94920f2802310c930396", size = 23085, upload-time = "2024-10-18T15:21:27.029Z" },
+ { url = "https://files.pythonhosted.org/packages/c2/cf/c9d56af24d56ea04daae7ac0940232d31d5a8354f2b457c6d856b2057d69/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f3818cb119498c0678015754eba762e0d61e5b52d34c8b13d770f0719f7b1d79", size = 22978, upload-time = "2024-10-18T15:21:27.846Z" },
+ { url = "https://files.pythonhosted.org/packages/2a/9f/8619835cd6a711d6272d62abb78c033bda638fdc54c4e7f4272cf1c0962b/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:cdb82a876c47801bb54a690c5ae105a46b392ac6099881cdfb9f6e95e4014c6a", size = 24208, upload-time = "2024-10-18T15:21:28.744Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/bf/176950a1792b2cd2102b8ffeb5133e1ed984547b75db47c25a67d3359f77/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:cabc348d87e913db6ab4aa100f01b08f481097838bdddf7c7a84b7575b7309ca", size = 23357, upload-time = "2024-10-18T15:21:29.545Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/4f/9a02c1d335caabe5c4efb90e1b6e8ee944aa245c1aaaab8e8a618987d816/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:444dcda765c8a838eaae23112db52f1efaf750daddb2d9ca300bcae1039adc5c", size = 23344, upload-time = "2024-10-18T15:21:30.366Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/55/c271b57db36f748f0e04a759ace9f8f759ccf22b4960c270c78a394f58be/MarkupSafe-3.0.2-cp313-cp313-win32.whl", hash = "sha256:bcf3e58998965654fdaff38e58584d8937aa3096ab5354d493c77d1fdd66d7a1", size = 15101, upload-time = "2024-10-18T15:21:31.207Z" },
+ { url = "https://files.pythonhosted.org/packages/29/88/07df22d2dd4df40aba9f3e402e6dc1b8ee86297dddbad4872bd5e7b0094f/MarkupSafe-3.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:e6a2a455bd412959b57a172ce6328d2dd1f01cb2135efda2e4576e8a23fa3b0f", size = 15603, upload-time = "2024-10-18T15:21:32.032Z" },
+ { url = "https://files.pythonhosted.org/packages/62/6a/8b89d24db2d32d433dffcd6a8779159da109842434f1dd2f6e71f32f738c/MarkupSafe-3.0.2-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:b5a6b3ada725cea8a5e634536b1b01c30bcdcd7f9c6fff4151548d5bf6b3a36c", size = 14510, upload-time = "2024-10-18T15:21:33.625Z" },
+ { url = "https://files.pythonhosted.org/packages/7a/06/a10f955f70a2e5a9bf78d11a161029d278eeacbd35ef806c3fd17b13060d/MarkupSafe-3.0.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:a904af0a6162c73e3edcb969eeeb53a63ceeb5d8cf642fade7d39e7963a22ddb", size = 12486, upload-time = "2024-10-18T15:21:34.611Z" },
+ { url = "https://files.pythonhosted.org/packages/34/cf/65d4a571869a1a9078198ca28f39fba5fbb910f952f9dbc5220afff9f5e6/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4aa4e5faecf353ed117801a068ebab7b7e09ffb6e1d5e412dc852e0da018126c", size = 25480, upload-time = "2024-10-18T15:21:35.398Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/e3/90e9651924c430b885468b56b3d597cabf6d72be4b24a0acd1fa0e12af67/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c0ef13eaeee5b615fb07c9a7dadb38eac06a0608b41570d8ade51c56539e509d", size = 23914, upload-time = "2024-10-18T15:21:36.231Z" },
+ { url = "https://files.pythonhosted.org/packages/66/8c/6c7cf61f95d63bb866db39085150df1f2a5bd3335298f14a66b48e92659c/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d16a81a06776313e817c951135cf7340a3e91e8c1ff2fac444cfd75fffa04afe", size = 23796, upload-time = "2024-10-18T15:21:37.073Z" },
+ { url = "https://files.pythonhosted.org/packages/bb/35/cbe9238ec3f47ac9a7c8b3df7a808e7cb50fe149dc7039f5f454b3fba218/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:6381026f158fdb7c72a168278597a5e3a5222e83ea18f543112b2662a9b699c5", size = 25473, upload-time = "2024-10-18T15:21:37.932Z" },
+ { url = "https://files.pythonhosted.org/packages/e6/32/7621a4382488aa283cc05e8984a9c219abad3bca087be9ec77e89939ded9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:3d79d162e7be8f996986c064d1c7c817f6df3a77fe3d6859f6f9e7be4b8c213a", size = 24114, upload-time = "2024-10-18T15:21:39.799Z" },
+ { url = "https://files.pythonhosted.org/packages/0d/80/0985960e4b89922cb5a0bac0ed39c5b96cbc1a536a99f30e8c220a996ed9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:131a3c7689c85f5ad20f9f6fb1b866f402c445b220c19fe4308c0b147ccd2ad9", size = 24098, upload-time = "2024-10-18T15:21:40.813Z" },
+ { url = "https://files.pythonhosted.org/packages/82/78/fedb03c7d5380df2427038ec8d973587e90561b2d90cd472ce9254cf348b/MarkupSafe-3.0.2-cp313-cp313t-win32.whl", hash = "sha256:ba8062ed2cf21c07a9e295d5b8a2a5ce678b913b45fdf68c32d95d6c1291e0b6", size = 15208, upload-time = "2024-10-18T15:21:41.814Z" },
+ { url = "https://files.pythonhosted.org/packages/4f/65/6079a46068dfceaeabb5dcad6d674f5f5c61a6fa5673746f42a9f4c233b3/MarkupSafe-3.0.2-cp313-cp313t-win_amd64.whl", hash = "sha256:e444a31f8db13eb18ada366ab3cf45fd4b31e4db1236a4448f68778c1d1a5a2f", size = 15739, upload-time = "2024-10-18T15:21:42.784Z" },
+]
+
+[[package]]
+name = "marshmallow"
+version = "3.26.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "packaging" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ab/5e/5e53d26b42ab75491cda89b871dab9e97c840bf12c63ec58a1919710cd06/marshmallow-3.26.1.tar.gz", hash = "sha256:e6d8affb6cb61d39d26402096dc0aee12d5a26d490a121f118d2e81dc0719dc6", size = 221825, upload-time = "2025-02-03T15:32:25.093Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/34/75/51952c7b2d3873b44a0028b1bd26a25078c18f92f256608e8d1dc61b39fd/marshmallow-3.26.1-py3-none-any.whl", hash = "sha256:3350409f20a70a7e4e11a27661187b77cdcaeb20abca41c1454fe33636bea09c", size = 50878, upload-time = "2025-02-03T15:32:22.295Z" },
+]
+
+[[package]]
+name = "mccabe"
+version = "0.7.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e7/ff/0ffefdcac38932a54d2b5eed4e0ba8a408f215002cd178ad1df0f2806ff8/mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", size = 9658, upload-time = "2022-01-24T01:14:51.113Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/27/1a/1f68f9ba0c207934b35b86a8ca3aad8395a3d6dd7921c0686e23853ff5a9/mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e", size = 7350, upload-time = "2022-01-24T01:14:49.62Z" },
+]
+
+[[package]]
+name = "milvus-lite"
+version = "2.4.12"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "tqdm" },
+]
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/64/3a/110e46db650ced604f97307e48e353726cfa6d26b1bf72acb81bbf07ecbd/milvus_lite-2.4.12-py3-none-macosx_10_9_x86_64.whl", hash = "sha256:e8d4f7cdd5f731efd6faeee3715d280fd91a5f9b4d89312664d56401f65b1473", size = 19843871, upload-time = "2025-03-21T06:20:26.141Z" },
+ { url = "https://files.pythonhosted.org/packages/a5/a7/11c21f2d6f3299ad07af8142b007e4297ff12d4bdc53e1e1ba48f661954b/milvus_lite-2.4.12-py3-none-macosx_11_0_arm64.whl", hash = "sha256:20087663e7b4385050b7ad08f1f03404426d4c87b1ff91d5a8723eee7fd49e88", size = 17411635, upload-time = "2025-03-21T06:20:43.548Z" },
+ { url = "https://files.pythonhosted.org/packages/a8/cc/b6f465e984439adf24da0a8ff3035d5c9ece30b6ff19f9a53f73f9ef901a/milvus_lite-2.4.12-py3-none-manylinux2014_aarch64.whl", hash = "sha256:a0f3a5ddbfd19f4a6b842b2fd3445693c796cde272b701a1646a94c1ac45d3d7", size = 35693118, upload-time = "2025-03-21T06:21:14.921Z" },
+ { url = "https://files.pythonhosted.org/packages/44/43/b3f6e9defd1f3927b972beac7abe3d5b4a3bdb287e3bad69618e2e76cf0a/milvus_lite-2.4.12-py3-none-manylinux2014_x86_64.whl", hash = "sha256:334037ebbab60243b5d8b43d54ca2f835d81d48c3cda0c6a462605e588deb05d", size = 45182549, upload-time = "2025-03-21T06:21:45.425Z" },
+]
+
+[[package]]
+name = "mistralai"
+version = "1.9.7"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "eval-type-backport" },
+ { name = "httpx" },
+ { name = "invoke" },
+ { name = "pydantic" },
+ { name = "python-dateutil" },
+ { name = "pyyaml" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ec/0b/3f9132f4b49178eafdc00f4def719433ec6e85da5df3a96b283ed5f4df3c/mistralai-1.9.7.tar.gz", hash = "sha256:ec5d32caa2da8d31637841d9be74ef8246d3e3281007fafacaea51145e2d4e15", size = 197398, upload-time = "2025-08-20T09:04:32.831Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/80/d3/f7b73c4a6d621a13b0b06bb2a23ef3e8c775ef01f0daefd0ae91ead0f2af/mistralai-1.9.7-py3-none-any.whl", hash = "sha256:abbd32c0c21a870681bca72d4e667a59c02cc87f8d2def788c81b7dc361e8c0f", size = 425764, upload-time = "2025-08-20T09:04:31.666Z" },
+]
+
+[[package]]
+name = "msal"
+version = "1.33.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cryptography" },
+ { name = "pyjwt", extra = ["crypto"] },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d5/da/81acbe0c1fd7e9e4ec35f55dadeba9833a847b9a6ba2e2d1e4432da901dd/msal-1.33.0.tar.gz", hash = "sha256:836ad80faa3e25a7d71015c990ce61f704a87328b1e73bcbb0623a18cbf17510", size = 153801, upload-time = "2025-07-22T19:36:33.693Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/86/5b/fbc73e91f7727ae1e79b21ed833308e99dc11cc1cd3d4717f579775de5e9/msal-1.33.0-py3-none-any.whl", hash = "sha256:c0cd41cecf8eaed733ee7e3be9e040291eba53b0f262d3ae9c58f38b04244273", size = 116853, upload-time = "2025-07-22T19:36:32.403Z" },
+]
+
+[[package]]
+name = "msal-extensions"
+version = "1.3.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "msal" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/01/99/5d239b6156eddf761a636bded1118414d161bd6b7b37a9335549ed159396/msal_extensions-1.3.1.tar.gz", hash = "sha256:c5b0fd10f65ef62b5f1d62f4251d51cbcaf003fcedae8c91b040a488614be1a4", size = 23315, upload-time = "2025-03-14T23:51:03.902Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5e/75/bd9b7bb966668920f06b200e84454c8f3566b102183bc55c5473d96cb2b9/msal_extensions-1.3.1-py3-none-any.whl", hash = "sha256:96d3de4d034504e969ac5e85bae8106c8373b5c6568e4c8fa7af2eca9dbe6bca", size = 20583, upload-time = "2025-03-14T23:51:03.016Z" },
+]
+
+[[package]]
+name = "multidict"
+version = "6.6.3"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/3d/2c/5dad12e82fbdf7470f29bff2171484bf07cb3b16ada60a6589af8f376440/multidict-6.6.3.tar.gz", hash = "sha256:798a9eb12dab0a6c2e29c1de6f3468af5cb2da6053a20dfa3344907eed0937cc", size = 101006, upload-time = "2025-06-30T15:53:46.929Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/0e/a0/6b57988ea102da0623ea814160ed78d45a2645e4bbb499c2896d12833a70/multidict-6.6.3-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:056bebbeda16b2e38642d75e9e5310c484b7c24e3841dc0fb943206a72ec89d6", size = 76514, upload-time = "2025-06-30T15:51:48.728Z" },
+ { url = "https://files.pythonhosted.org/packages/07/7a/d1e92665b0850c6c0508f101f9cf0410c1afa24973e1115fe9c6a185ebf7/multidict-6.6.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:e5f481cccb3c5c5e5de5d00b5141dc589c1047e60d07e85bbd7dea3d4580d63f", size = 45394, upload-time = "2025-06-30T15:51:49.986Z" },
+ { url = "https://files.pythonhosted.org/packages/52/6f/dd104490e01be6ef8bf9573705d8572f8c2d2c561f06e3826b081d9e6591/multidict-6.6.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:10bea2ee839a759ee368b5a6e47787f399b41e70cf0c20d90dfaf4158dfb4e55", size = 43590, upload-time = "2025-06-30T15:51:51.331Z" },
+ { url = "https://files.pythonhosted.org/packages/44/fe/06e0e01b1b0611e6581b7fd5a85b43dacc08b6cea3034f902f383b0873e5/multidict-6.6.3-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:2334cfb0fa9549d6ce2c21af2bfbcd3ac4ec3646b1b1581c88e3e2b1779ec92b", size = 237292, upload-time = "2025-06-30T15:51:52.584Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/71/4f0e558fb77696b89c233c1ee2d92f3e1d5459070a0e89153c9e9e804186/multidict-6.6.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b8fee016722550a2276ca2cb5bb624480e0ed2bd49125b2b73b7010b9090e888", size = 258385, upload-time = "2025-06-30T15:51:53.913Z" },
+ { url = "https://files.pythonhosted.org/packages/e3/25/cca0e68228addad24903801ed1ab42e21307a1b4b6dd2cf63da5d3ae082a/multidict-6.6.3-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:e5511cb35f5c50a2db21047c875eb42f308c5583edf96bd8ebf7d770a9d68f6d", size = 242328, upload-time = "2025-06-30T15:51:55.672Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/a3/46f2d420d86bbcb8fe660b26a10a219871a0fbf4d43cb846a4031533f3e0/multidict-6.6.3-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:712b348f7f449948e0a6c4564a21c7db965af900973a67db432d724619b3c680", size = 268057, upload-time = "2025-06-30T15:51:57.037Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/73/1c743542fe00794a2ec7466abd3f312ccb8fad8dff9f36d42e18fb1ec33e/multidict-6.6.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:e4e15d2138ee2694e038e33b7c3da70e6b0ad8868b9f8094a72e1414aeda9c1a", size = 269341, upload-time = "2025-06-30T15:51:59.111Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/11/6ec9dcbe2264b92778eeb85407d1df18812248bf3506a5a1754bc035db0c/multidict-6.6.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8df25594989aebff8a130f7899fa03cbfcc5d2b5f4a461cf2518236fe6f15961", size = 256081, upload-time = "2025-06-30T15:52:00.533Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/2b/631b1e2afeb5f1696846d747d36cda075bfdc0bc7245d6ba5c319278d6c4/multidict-6.6.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:159ca68bfd284a8860f8d8112cf0521113bffd9c17568579e4d13d1f1dc76b65", size = 253581, upload-time = "2025-06-30T15:52:02.43Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/0e/7e3b93f79efeb6111d3bf9a1a69e555ba1d07ad1c11bceb56b7310d0d7ee/multidict-6.6.3-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:e098c17856a8c9ade81b4810888c5ad1914099657226283cab3062c0540b0643", size = 250750, upload-time = "2025-06-30T15:52:04.26Z" },
+ { url = "https://files.pythonhosted.org/packages/ad/9e/086846c1d6601948e7de556ee464a2d4c85e33883e749f46b9547d7b0704/multidict-6.6.3-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:67c92ed673049dec52d7ed39f8cf9ebbadf5032c774058b4406d18c8f8fe7063", size = 251548, upload-time = "2025-06-30T15:52:06.002Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/7b/86ec260118e522f1a31550e87b23542294880c97cfbf6fb18cc67b044c66/multidict-6.6.3-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:bd0578596e3a835ef451784053cfd327d607fc39ea1a14812139339a18a0dbc3", size = 262718, upload-time = "2025-06-30T15:52:07.707Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/bd/22ce8f47abb0be04692c9fc4638508b8340987b18691aa7775d927b73f72/multidict-6.6.3-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:346055630a2df2115cd23ae271910b4cae40f4e336773550dca4889b12916e75", size = 259603, upload-time = "2025-06-30T15:52:09.58Z" },
+ { url = "https://files.pythonhosted.org/packages/07/9c/91b7ac1691be95cd1f4a26e36a74b97cda6aa9820632d31aab4410f46ebd/multidict-6.6.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:555ff55a359302b79de97e0468e9ee80637b0de1fce77721639f7cd9440b3a10", size = 251351, upload-time = "2025-06-30T15:52:10.947Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/5c/4d7adc739884f7a9fbe00d1eac8c034023ef8bad71f2ebe12823ca2e3649/multidict-6.6.3-cp312-cp312-win32.whl", hash = "sha256:73ab034fb8d58ff85c2bcbadc470efc3fafeea8affcf8722855fb94557f14cc5", size = 41860, upload-time = "2025-06-30T15:52:12.334Z" },
+ { url = "https://files.pythonhosted.org/packages/6a/a3/0fbc7afdf7cb1aa12a086b02959307848eb6bcc8f66fcb66c0cb57e2a2c1/multidict-6.6.3-cp312-cp312-win_amd64.whl", hash = "sha256:04cbcce84f63b9af41bad04a54d4cc4e60e90c35b9e6ccb130be2d75b71f8c17", size = 45982, upload-time = "2025-06-30T15:52:13.6Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/95/8c825bd70ff9b02462dc18d1295dd08d3e9e4eb66856d292ffa62cfe1920/multidict-6.6.3-cp312-cp312-win_arm64.whl", hash = "sha256:0f1130b896ecb52d2a1e615260f3ea2af55fa7dc3d7c3003ba0c3121a759b18b", size = 43210, upload-time = "2025-06-30T15:52:14.893Z" },
+ { url = "https://files.pythonhosted.org/packages/52/1d/0bebcbbb4f000751fbd09957257903d6e002943fc668d841a4cf2fb7f872/multidict-6.6.3-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:540d3c06d48507357a7d57721e5094b4f7093399a0106c211f33540fdc374d55", size = 75843, upload-time = "2025-06-30T15:52:16.155Z" },
+ { url = "https://files.pythonhosted.org/packages/07/8f/cbe241b0434cfe257f65c2b1bcf9e8d5fb52bc708c5061fb29b0fed22bdf/multidict-6.6.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:9c19cea2a690f04247d43f366d03e4eb110a0dc4cd1bbeee4d445435428ed35b", size = 45053, upload-time = "2025-06-30T15:52:17.429Z" },
+ { url = "https://files.pythonhosted.org/packages/32/d2/0b3b23f9dbad5b270b22a3ac3ea73ed0a50ef2d9a390447061178ed6bdb8/multidict-6.6.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:7af039820cfd00effec86bda5d8debef711a3e86a1d3772e85bea0f243a4bd65", size = 43273, upload-time = "2025-06-30T15:52:19.346Z" },
+ { url = "https://files.pythonhosted.org/packages/fd/fe/6eb68927e823999e3683bc49678eb20374ba9615097d085298fd5b386564/multidict-6.6.3-cp313-cp313-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:500b84f51654fdc3944e936f2922114349bf8fdcac77c3092b03449f0e5bc2b3", size = 237124, upload-time = "2025-06-30T15:52:20.773Z" },
+ { url = "https://files.pythonhosted.org/packages/e7/ab/320d8507e7726c460cb77117848b3834ea0d59e769f36fdae495f7669929/multidict-6.6.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f3fc723ab8a5c5ed6c50418e9bfcd8e6dceba6c271cee6728a10a4ed8561520c", size = 256892, upload-time = "2025-06-30T15:52:22.242Z" },
+ { url = "https://files.pythonhosted.org/packages/76/60/38ee422db515ac69834e60142a1a69111ac96026e76e8e9aa347fd2e4591/multidict-6.6.3-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:94c47ea3ade005b5976789baaed66d4de4480d0a0bf31cef6edaa41c1e7b56a6", size = 240547, upload-time = "2025-06-30T15:52:23.736Z" },
+ { url = "https://files.pythonhosted.org/packages/27/fb/905224fde2dff042b030c27ad95a7ae744325cf54b890b443d30a789b80e/multidict-6.6.3-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:dbc7cf464cc6d67e83e136c9f55726da3a30176f020a36ead246eceed87f1cd8", size = 266223, upload-time = "2025-06-30T15:52:25.185Z" },
+ { url = "https://files.pythonhosted.org/packages/76/35/dc38ab361051beae08d1a53965e3e1a418752fc5be4d3fb983c5582d8784/multidict-6.6.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:900eb9f9da25ada070f8ee4a23f884e0ee66fe4e1a38c3af644256a508ad81ca", size = 267262, upload-time = "2025-06-30T15:52:26.969Z" },
+ { url = "https://files.pythonhosted.org/packages/1f/a3/0a485b7f36e422421b17e2bbb5a81c1af10eac1d4476f2ff92927c730479/multidict-6.6.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7c6df517cf177da5d47ab15407143a89cd1a23f8b335f3a28d57e8b0a3dbb884", size = 254345, upload-time = "2025-06-30T15:52:28.467Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/59/bcdd52c1dab7c0e0d75ff19cac751fbd5f850d1fc39172ce809a74aa9ea4/multidict-6.6.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:4ef421045f13879e21c994b36e728d8e7d126c91a64b9185810ab51d474f27e7", size = 252248, upload-time = "2025-06-30T15:52:29.938Z" },
+ { url = "https://files.pythonhosted.org/packages/bb/a4/2d96aaa6eae8067ce108d4acee6f45ced5728beda55c0f02ae1072c730d1/multidict-6.6.3-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:6c1e61bb4f80895c081790b6b09fa49e13566df8fbff817da3f85b3a8192e36b", size = 250115, upload-time = "2025-06-30T15:52:31.416Z" },
+ { url = "https://files.pythonhosted.org/packages/25/d2/ed9f847fa5c7d0677d4f02ea2c163d5e48573de3f57bacf5670e43a5ffaa/multidict-6.6.3-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:e5e8523bb12d7623cd8300dbd91b9e439a46a028cd078ca695eb66ba31adee3c", size = 249649, upload-time = "2025-06-30T15:52:32.996Z" },
+ { url = "https://files.pythonhosted.org/packages/1f/af/9155850372563fc550803d3f25373308aa70f59b52cff25854086ecb4a79/multidict-6.6.3-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:ef58340cc896219e4e653dade08fea5c55c6df41bcc68122e3be3e9d873d9a7b", size = 261203, upload-time = "2025-06-30T15:52:34.521Z" },
+ { url = "https://files.pythonhosted.org/packages/36/2f/c6a728f699896252cf309769089568a33c6439626648843f78743660709d/multidict-6.6.3-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:fc9dc435ec8699e7b602b94fe0cd4703e69273a01cbc34409af29e7820f777f1", size = 258051, upload-time = "2025-06-30T15:52:35.999Z" },
+ { url = "https://files.pythonhosted.org/packages/d0/60/689880776d6b18fa2b70f6cc74ff87dd6c6b9b47bd9cf74c16fecfaa6ad9/multidict-6.6.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9e864486ef4ab07db5e9cb997bad2b681514158d6954dd1958dfb163b83d53e6", size = 249601, upload-time = "2025-06-30T15:52:37.473Z" },
+ { url = "https://files.pythonhosted.org/packages/75/5e/325b11f2222a549019cf2ef879c1f81f94a0d40ace3ef55cf529915ba6cc/multidict-6.6.3-cp313-cp313-win32.whl", hash = "sha256:5633a82fba8e841bc5c5c06b16e21529573cd654f67fd833650a215520a6210e", size = 41683, upload-time = "2025-06-30T15:52:38.927Z" },
+ { url = "https://files.pythonhosted.org/packages/b1/ad/cf46e73f5d6e3c775cabd2a05976547f3f18b39bee06260369a42501f053/multidict-6.6.3-cp313-cp313-win_amd64.whl", hash = "sha256:e93089c1570a4ad54c3714a12c2cef549dc9d58e97bcded193d928649cab78e9", size = 45811, upload-time = "2025-06-30T15:52:40.207Z" },
+ { url = "https://files.pythonhosted.org/packages/c5/c9/2e3fe950db28fb7c62e1a5f46e1e38759b072e2089209bc033c2798bb5ec/multidict-6.6.3-cp313-cp313-win_arm64.whl", hash = "sha256:c60b401f192e79caec61f166da9c924e9f8bc65548d4246842df91651e83d600", size = 43056, upload-time = "2025-06-30T15:52:41.575Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/58/aaf8114cf34966e084a8cc9517771288adb53465188843d5a19862cb6dc3/multidict-6.6.3-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:02fd8f32d403a6ff13864b0851f1f523d4c988051eea0471d4f1fd8010f11134", size = 82811, upload-time = "2025-06-30T15:52:43.281Z" },
+ { url = "https://files.pythonhosted.org/packages/71/af/5402e7b58a1f5b987a07ad98f2501fdba2a4f4b4c30cf114e3ce8db64c87/multidict-6.6.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:f3aa090106b1543f3f87b2041eef3c156c8da2aed90c63a2fbed62d875c49c37", size = 48304, upload-time = "2025-06-30T15:52:45.026Z" },
+ { url = "https://files.pythonhosted.org/packages/39/65/ab3c8cafe21adb45b24a50266fd747147dec7847425bc2a0f6934b3ae9ce/multidict-6.6.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:e924fb978615a5e33ff644cc42e6aa241effcf4f3322c09d4f8cebde95aff5f8", size = 46775, upload-time = "2025-06-30T15:52:46.459Z" },
+ { url = "https://files.pythonhosted.org/packages/49/ba/9fcc1b332f67cc0c0c8079e263bfab6660f87fe4e28a35921771ff3eea0d/multidict-6.6.3-cp313-cp313t-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:b9fe5a0e57c6dbd0e2ce81ca66272282c32cd11d31658ee9553849d91289e1c1", size = 229773, upload-time = "2025-06-30T15:52:47.88Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/14/0145a251f555f7c754ce2dcbcd012939bbd1f34f066fa5d28a50e722a054/multidict-6.6.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b24576f208793ebae00280c59927c3b7c2a3b1655e443a25f753c4611bc1c373", size = 250083, upload-time = "2025-06-30T15:52:49.366Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/d4/d5c0bd2bbb173b586c249a151a26d2fb3ec7d53c96e42091c9fef4e1f10c/multidict-6.6.3-cp313-cp313t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:135631cb6c58eac37d7ac0df380294fecdc026b28837fa07c02e459c7fb9c54e", size = 228980, upload-time = "2025-06-30T15:52:50.903Z" },
+ { url = "https://files.pythonhosted.org/packages/21/32/c9a2d8444a50ec48c4733ccc67254100c10e1c8ae8e40c7a2d2183b59b97/multidict-6.6.3-cp313-cp313t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:274d416b0df887aef98f19f21578653982cfb8a05b4e187d4a17103322eeaf8f", size = 257776, upload-time = "2025-06-30T15:52:52.764Z" },
+ { url = "https://files.pythonhosted.org/packages/68/d0/14fa1699f4ef629eae08ad6201c6b476098f5efb051b296f4c26be7a9fdf/multidict-6.6.3-cp313-cp313t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:e252017a817fad7ce05cafbe5711ed40faeb580e63b16755a3a24e66fa1d87c0", size = 256882, upload-time = "2025-06-30T15:52:54.596Z" },
+ { url = "https://files.pythonhosted.org/packages/da/88/84a27570fbe303c65607d517a5f147cd2fc046c2d1da02b84b17b9bdc2aa/multidict-6.6.3-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2e4cc8d848cd4fe1cdee28c13ea79ab0ed37fc2e89dd77bac86a2e7959a8c3bc", size = 247816, upload-time = "2025-06-30T15:52:56.175Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/60/dca352a0c999ce96a5d8b8ee0b2b9f729dcad2e0b0c195f8286269a2074c/multidict-6.6.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:9e236a7094b9c4c1b7585f6b9cca34b9d833cf079f7e4c49e6a4a6ec9bfdc68f", size = 245341, upload-time = "2025-06-30T15:52:57.752Z" },
+ { url = "https://files.pythonhosted.org/packages/50/ef/433fa3ed06028f03946f3993223dada70fb700f763f70c00079533c34578/multidict-6.6.3-cp313-cp313t-musllinux_1_2_armv7l.whl", hash = "sha256:e0cb0ab69915c55627c933f0b555a943d98ba71b4d1c57bc0d0a66e2567c7471", size = 235854, upload-time = "2025-06-30T15:52:59.74Z" },
+ { url = "https://files.pythonhosted.org/packages/1b/1f/487612ab56fbe35715320905215a57fede20de7db40a261759690dc80471/multidict-6.6.3-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:81ef2f64593aba09c5212a3d0f8c906a0d38d710a011f2f42759704d4557d3f2", size = 243432, upload-time = "2025-06-30T15:53:01.602Z" },
+ { url = "https://files.pythonhosted.org/packages/da/6f/ce8b79de16cd885c6f9052c96a3671373d00c59b3ee635ea93e6e81b8ccf/multidict-6.6.3-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:b9cbc60010de3562545fa198bfc6d3825df430ea96d2cc509c39bd71e2e7d648", size = 252731, upload-time = "2025-06-30T15:53:03.517Z" },
+ { url = "https://files.pythonhosted.org/packages/bb/fe/a2514a6aba78e5abefa1624ca85ae18f542d95ac5cde2e3815a9fbf369aa/multidict-6.6.3-cp313-cp313t-musllinux_1_2_s390x.whl", hash = "sha256:70d974eaaa37211390cd02ef93b7e938de564bbffa866f0b08d07e5e65da783d", size = 247086, upload-time = "2025-06-30T15:53:05.48Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/22/b788718d63bb3cce752d107a57c85fcd1a212c6c778628567c9713f9345a/multidict-6.6.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:3713303e4a6663c6d01d648a68f2848701001f3390a030edaaf3fc949c90bf7c", size = 243338, upload-time = "2025-06-30T15:53:07.522Z" },
+ { url = "https://files.pythonhosted.org/packages/22/d6/fdb3d0670819f2228f3f7d9af613d5e652c15d170c83e5f1c94fbc55a25b/multidict-6.6.3-cp313-cp313t-win32.whl", hash = "sha256:639ecc9fe7cd73f2495f62c213e964843826f44505a3e5d82805aa85cac6f89e", size = 47812, upload-time = "2025-06-30T15:53:09.263Z" },
+ { url = "https://files.pythonhosted.org/packages/b6/d6/a9d2c808f2c489ad199723197419207ecbfbc1776f6e155e1ecea9c883aa/multidict-6.6.3-cp313-cp313t-win_amd64.whl", hash = "sha256:9f97e181f344a0ef3881b573d31de8542cc0dbc559ec68c8f8b5ce2c2e91646d", size = 53011, upload-time = "2025-06-30T15:53:11.038Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/40/b68001cba8188dd267590a111f9661b6256debc327137667e832bf5d66e8/multidict-6.6.3-cp313-cp313t-win_arm64.whl", hash = "sha256:ce8b7693da41a3c4fde5871c738a81490cea5496c671d74374c8ab889e1834fb", size = 45254, upload-time = "2025-06-30T15:53:12.421Z" },
+ { url = "https://files.pythonhosted.org/packages/d8/30/9aec301e9772b098c1f5c0ca0279237c9766d94b97802e9888010c64b0ed/multidict-6.6.3-py3-none-any.whl", hash = "sha256:8db10f29c7541fc5da4defd8cd697e1ca429db743fa716325f236079b96f775a", size = 12313, upload-time = "2025-06-30T15:53:45.437Z" },
+]
+
+[[package]]
+name = "mypy"
+version = "1.17.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "mypy-extensions" },
+ { name = "pathspec" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/8e/22/ea637422dedf0bf36f3ef238eab4e455e2a0dcc3082b5cc067615347ab8e/mypy-1.17.1.tar.gz", hash = "sha256:25e01ec741ab5bb3eec8ba9cdb0f769230368a22c959c4937360efb89b7e9f01", size = 3352570, upload-time = "2025-07-31T07:54:19.204Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/17/a2/7034d0d61af8098ec47902108553122baa0f438df8a713be860f7407c9e6/mypy-1.17.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:69e83ea6553a3ba79c08c6e15dbd9bfa912ec1e493bf75489ef93beb65209aeb", size = 11086295, upload-time = "2025-07-31T07:53:28.124Z" },
+ { url = "https://files.pythonhosted.org/packages/14/1f/19e7e44b594d4b12f6ba8064dbe136505cec813549ca3e5191e40b1d3cc2/mypy-1.17.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1b16708a66d38abb1e6b5702f5c2c87e133289da36f6a1d15f6a5221085c6403", size = 10112355, upload-time = "2025-07-31T07:53:21.121Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/69/baa33927e29e6b4c55d798a9d44db5d394072eef2bdc18c3e2048c9ed1e9/mypy-1.17.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:89e972c0035e9e05823907ad5398c5a73b9f47a002b22359b177d40bdaee7056", size = 11875285, upload-time = "2025-07-31T07:53:55.293Z" },
+ { url = "https://files.pythonhosted.org/packages/90/13/f3a89c76b0a41e19490b01e7069713a30949d9a6c147289ee1521bcea245/mypy-1.17.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:03b6d0ed2b188e35ee6d5c36b5580cffd6da23319991c49ab5556c023ccf1341", size = 12737895, upload-time = "2025-07-31T07:53:43.623Z" },
+ { url = "https://files.pythonhosted.org/packages/23/a1/c4ee79ac484241301564072e6476c5a5be2590bc2e7bfd28220033d2ef8f/mypy-1.17.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c837b896b37cd103570d776bda106eabb8737aa6dd4f248451aecf53030cdbeb", size = 12931025, upload-time = "2025-07-31T07:54:17.125Z" },
+ { url = "https://files.pythonhosted.org/packages/89/b8/7409477be7919a0608900e6320b155c72caab4fef46427c5cc75f85edadd/mypy-1.17.1-cp312-cp312-win_amd64.whl", hash = "sha256:665afab0963a4b39dff7c1fa563cc8b11ecff7910206db4b2e64dd1ba25aed19", size = 9584664, upload-time = "2025-07-31T07:54:12.842Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/82/aec2fc9b9b149f372850291827537a508d6c4d3664b1750a324b91f71355/mypy-1.17.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:93378d3203a5c0800c6b6d850ad2f19f7a3cdf1a3701d3416dbf128805c6a6a7", size = 11075338, upload-time = "2025-07-31T07:53:38.873Z" },
+ { url = "https://files.pythonhosted.org/packages/07/ac/ee93fbde9d2242657128af8c86f5d917cd2887584cf948a8e3663d0cd737/mypy-1.17.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:15d54056f7fe7a826d897789f53dd6377ec2ea8ba6f776dc83c2902b899fee81", size = 10113066, upload-time = "2025-07-31T07:54:14.707Z" },
+ { url = "https://files.pythonhosted.org/packages/5a/68/946a1e0be93f17f7caa56c45844ec691ca153ee8b62f21eddda336a2d203/mypy-1.17.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:209a58fed9987eccc20f2ca94afe7257a8f46eb5df1fb69958650973230f91e6", size = 11875473, upload-time = "2025-07-31T07:53:14.504Z" },
+ { url = "https://files.pythonhosted.org/packages/9f/0f/478b4dce1cb4f43cf0f0d00fba3030b21ca04a01b74d1cd272a528cf446f/mypy-1.17.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:099b9a5da47de9e2cb5165e581f158e854d9e19d2e96b6698c0d64de911dd849", size = 12744296, upload-time = "2025-07-31T07:53:03.896Z" },
+ { url = "https://files.pythonhosted.org/packages/ca/70/afa5850176379d1b303f992a828de95fc14487429a7139a4e0bdd17a8279/mypy-1.17.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:fa6ffadfbe6994d724c5a1bb6123a7d27dd68fc9c059561cd33b664a79578e14", size = 12914657, upload-time = "2025-07-31T07:54:08.576Z" },
+ { url = "https://files.pythonhosted.org/packages/53/f9/4a83e1c856a3d9c8f6edaa4749a4864ee98486e9b9dbfbc93842891029c2/mypy-1.17.1-cp313-cp313-win_amd64.whl", hash = "sha256:9a2b7d9180aed171f033c9f2fc6c204c1245cf60b0cb61cf2e7acc24eea78e0a", size = 9593320, upload-time = "2025-07-31T07:53:01.341Z" },
+ { url = "https://files.pythonhosted.org/packages/38/56/79c2fac86da57c7d8c48622a05873eaab40b905096c33597462713f5af90/mypy-1.17.1-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:15a83369400454c41ed3a118e0cc58bd8123921a602f385cb6d6ea5df050c733", size = 11040037, upload-time = "2025-07-31T07:54:10.942Z" },
+ { url = "https://files.pythonhosted.org/packages/4d/c3/adabe6ff53638e3cad19e3547268482408323b1e68bf082c9119000cd049/mypy-1.17.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:55b918670f692fc9fba55c3298d8a3beae295c5cded0a55dccdc5bbead814acd", size = 10131550, upload-time = "2025-07-31T07:53:41.307Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/c5/2e234c22c3bdeb23a7817af57a58865a39753bde52c74e2c661ee0cfc640/mypy-1.17.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:62761474061feef6f720149d7ba876122007ddc64adff5ba6f374fda35a018a0", size = 11872963, upload-time = "2025-07-31T07:53:16.878Z" },
+ { url = "https://files.pythonhosted.org/packages/ab/26/c13c130f35ca8caa5f2ceab68a247775648fdcd6c9a18f158825f2bc2410/mypy-1.17.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c49562d3d908fd49ed0938e5423daed8d407774a479b595b143a3d7f87cdae6a", size = 12710189, upload-time = "2025-07-31T07:54:01.962Z" },
+ { url = "https://files.pythonhosted.org/packages/82/df/c7d79d09f6de8383fe800521d066d877e54d30b4fb94281c262be2df84ef/mypy-1.17.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:397fba5d7616a5bc60b45c7ed204717eaddc38f826e3645402c426057ead9a91", size = 12900322, upload-time = "2025-07-31T07:53:10.551Z" },
+ { url = "https://files.pythonhosted.org/packages/b8/98/3d5a48978b4f708c55ae832619addc66d677f6dc59f3ebad71bae8285ca6/mypy-1.17.1-cp314-cp314-win_amd64.whl", hash = "sha256:9d6b20b97d373f41617bd0708fd46aa656059af57f2ef72aa8c7d6a2b73b74ed", size = 9751879, upload-time = "2025-07-31T07:52:56.683Z" },
+ { url = "https://files.pythonhosted.org/packages/1d/f3/8fcd2af0f5b806f6cf463efaffd3c9548a28f84220493ecd38d127b6b66d/mypy-1.17.1-py3-none-any.whl", hash = "sha256:a9f52c0351c21fe24c21d8c0eb1f62967b262d6729393397b6f443c3b773c3b9", size = 2283411, upload-time = "2025-07-31T07:53:24.664Z" },
+]
+
+[[package]]
+name = "mypy-extensions"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a2/6e/371856a3fb9d31ca8dac321cda606860fa4548858c0cc45d9d1d4ca2628b/mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558", size = 6343, upload-time = "2025-04-22T14:54:24.164Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/79/7b/2c79738432f5c924bef5071f933bcc9efd0473bac3b4aa584a6f7c1c8df8/mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505", size = 4963, upload-time = "2025-04-22T14:54:22.983Z" },
+]
+
+[[package]]
+name = "nest-asyncio"
+version = "1.6.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/83/f8/51569ac65d696c8ecbee95938f89d4abf00f47d58d48f6fbabfe8f0baefe/nest_asyncio-1.6.0.tar.gz", hash = "sha256:6f172d5449aca15afd6c646851f4e31e02c598d553a667e38cafa997cfec55fe", size = 7418, upload-time = "2024-01-21T14:25:19.227Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a0/c4/c2971a3ba4c6103a3d10c4b0f24f461ddc027f0f09763220cf35ca1401b3/nest_asyncio-1.6.0-py3-none-any.whl", hash = "sha256:87af6efd6b5e897c81050477ef65c62e2b2f35d51703cae01aff2905b1852e1c", size = 5195, upload-time = "2024-01-21T14:25:17.223Z" },
+]
+
+[[package]]
+name = "networkx"
+version = "3.5"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/6c/4f/ccdb8ad3a38e583f214547fd2f7ff1fc160c43a75af88e6aec213404b96a/networkx-3.5.tar.gz", hash = "sha256:d4c6f9cf81f52d69230866796b82afbccdec3db7ae4fbd1b65ea750feed50037", size = 2471065, upload-time = "2025-05-29T11:35:07.804Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/eb/8d/776adee7bbf76365fdd7f2552710282c79a4ead5d2a46408c9043a2b70ba/networkx-3.5-py3-none-any.whl", hash = "sha256:0030d386a9a06dee3565298b4a734b68589749a544acbb6c412dc9e2489ec6ec", size = 2034406, upload-time = "2025-05-29T11:35:04.961Z" },
+]
+
+[[package]]
+name = "nltk"
+version = "3.9.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "click" },
+ { name = "joblib" },
+ { name = "regex" },
+ { name = "tqdm" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/3c/87/db8be88ad32c2d042420b6fd9ffd4a149f9a0d7f0e86b3f543be2eeeedd2/nltk-3.9.1.tar.gz", hash = "sha256:87d127bd3de4bd89a4f81265e5fa59cb1b199b27440175370f7417d2bc7ae868", size = 2904691, upload-time = "2024-08-18T19:48:37.769Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4d/66/7d9e26593edda06e8cb531874633f7c2372279c3b0f46235539fe546df8b/nltk-3.9.1-py3-none-any.whl", hash = "sha256:4fa26829c5b00715afe3061398a8989dc643b92ce7dd93fb4585a70930d168a1", size = 1505442, upload-time = "2024-08-18T19:48:21.909Z" },
+]
+
+[[package]]
+name = "numpy"
+version = "2.3.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/37/7d/3fec4199c5ffb892bed55cff901e4f39a58c81df9c44c280499e92cad264/numpy-2.3.2.tar.gz", hash = "sha256:e0486a11ec30cdecb53f184d496d1c6a20786c81e55e41640270130056f8ee48", size = 20489306, upload-time = "2025-07-24T21:32:07.553Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/00/6d/745dd1c1c5c284d17725e5c802ca4d45cfc6803519d777f087b71c9f4069/numpy-2.3.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:bc3186bea41fae9d8e90c2b4fb5f0a1f5a690682da79b92574d63f56b529080b", size = 20956420, upload-time = "2025-07-24T20:28:18.002Z" },
+ { url = "https://files.pythonhosted.org/packages/bc/96/e7b533ea5740641dd62b07a790af5d9d8fec36000b8e2d0472bd7574105f/numpy-2.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2f4f0215edb189048a3c03bd5b19345bdfa7b45a7a6f72ae5945d2a28272727f", size = 14184660, upload-time = "2025-07-24T20:28:39.522Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/53/102c6122db45a62aa20d1b18c9986f67e6b97e0d6fbc1ae13e3e4c84430c/numpy-2.3.2-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:8b1224a734cd509f70816455c3cffe13a4f599b1bf7130f913ba0e2c0b2006c0", size = 5113382, upload-time = "2025-07-24T20:28:48.544Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/21/376257efcbf63e624250717e82b4fae93d60178f09eb03ed766dbb48ec9c/numpy-2.3.2-cp312-cp312-macosx_14_0_x86_64.whl", hash = "sha256:3dcf02866b977a38ba3ec10215220609ab9667378a9e2150615673f3ffd6c73b", size = 6647258, upload-time = "2025-07-24T20:28:59.104Z" },
+ { url = "https://files.pythonhosted.org/packages/91/ba/f4ebf257f08affa464fe6036e13f2bf9d4642a40228781dc1235da81be9f/numpy-2.3.2-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:572d5512df5470f50ada8d1972c5f1082d9a0b7aa5944db8084077570cf98370", size = 14281409, upload-time = "2025-07-24T20:40:30.298Z" },
+ { url = "https://files.pythonhosted.org/packages/59/ef/f96536f1df42c668cbacb727a8c6da7afc9c05ece6d558927fb1722693e1/numpy-2.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8145dd6d10df13c559d1e4314df29695613575183fa2e2d11fac4c208c8a1f73", size = 16641317, upload-time = "2025-07-24T20:40:56.625Z" },
+ { url = "https://files.pythonhosted.org/packages/f6/a7/af813a7b4f9a42f498dde8a4c6fcbff8100eed00182cc91dbaf095645f38/numpy-2.3.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:103ea7063fa624af04a791c39f97070bf93b96d7af7eb23530cd087dc8dbe9dc", size = 16056262, upload-time = "2025-07-24T20:41:20.797Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/5d/41c4ef8404caaa7f05ed1cfb06afe16a25895260eacbd29b4d84dff2920b/numpy-2.3.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:fc927d7f289d14f5e037be917539620603294454130b6de200091e23d27dc9be", size = 18579342, upload-time = "2025-07-24T20:41:50.753Z" },
+ { url = "https://files.pythonhosted.org/packages/a1/4f/9950e44c5a11636f4a3af6e825ec23003475cc9a466edb7a759ed3ea63bd/numpy-2.3.2-cp312-cp312-win32.whl", hash = "sha256:d95f59afe7f808c103be692175008bab926b59309ade3e6d25009e9a171f7036", size = 6320610, upload-time = "2025-07-24T20:42:01.551Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/2f/244643a5ce54a94f0a9a2ab578189c061e4a87c002e037b0829dd77293b6/numpy-2.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:9e196ade2400c0c737d93465327d1ae7c06c7cb8a1756121ebf54b06ca183c7f", size = 12786292, upload-time = "2025-07-24T20:42:20.738Z" },
+ { url = "https://files.pythonhosted.org/packages/54/cd/7b5f49d5d78db7badab22d8323c1b6ae458fbf86c4fdfa194ab3cd4eb39b/numpy-2.3.2-cp312-cp312-win_arm64.whl", hash = "sha256:ee807923782faaf60d0d7331f5e86da7d5e3079e28b291973c545476c2b00d07", size = 10194071, upload-time = "2025-07-24T20:42:36.657Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/c0/c6bb172c916b00700ed3bf71cb56175fd1f7dbecebf8353545d0b5519f6c/numpy-2.3.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:c8d9727f5316a256425892b043736d63e89ed15bbfe6556c5ff4d9d4448ff3b3", size = 20949074, upload-time = "2025-07-24T20:43:07.813Z" },
+ { url = "https://files.pythonhosted.org/packages/20/4e/c116466d22acaf4573e58421c956c6076dc526e24a6be0903219775d862e/numpy-2.3.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:efc81393f25f14d11c9d161e46e6ee348637c0a1e8a54bf9dedc472a3fae993b", size = 14177311, upload-time = "2025-07-24T20:43:29.335Z" },
+ { url = "https://files.pythonhosted.org/packages/78/45/d4698c182895af189c463fc91d70805d455a227261d950e4e0f1310c2550/numpy-2.3.2-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:dd937f088a2df683cbb79dda9a772b62a3e5a8a7e76690612c2737f38c6ef1b6", size = 5106022, upload-time = "2025-07-24T20:43:37.999Z" },
+ { url = "https://files.pythonhosted.org/packages/9f/76/3e6880fef4420179309dba72a8c11f6166c431cf6dee54c577af8906f914/numpy-2.3.2-cp313-cp313-macosx_14_0_x86_64.whl", hash = "sha256:11e58218c0c46c80509186e460d79fbdc9ca1eb8d8aee39d8f2dc768eb781089", size = 6640135, upload-time = "2025-07-24T20:43:49.28Z" },
+ { url = "https://files.pythonhosted.org/packages/34/fa/87ff7f25b3c4ce9085a62554460b7db686fef1e0207e8977795c7b7d7ba1/numpy-2.3.2-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5ad4ebcb683a1f99f4f392cc522ee20a18b2bb12a2c1c42c3d48d5a1adc9d3d2", size = 14278147, upload-time = "2025-07-24T20:44:10.328Z" },
+ { url = "https://files.pythonhosted.org/packages/1d/0f/571b2c7a3833ae419fe69ff7b479a78d313581785203cc70a8db90121b9a/numpy-2.3.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:938065908d1d869c7d75d8ec45f735a034771c6ea07088867f713d1cd3bbbe4f", size = 16635989, upload-time = "2025-07-24T20:44:34.88Z" },
+ { url = "https://files.pythonhosted.org/packages/24/5a/84ae8dca9c9a4c592fe11340b36a86ffa9fd3e40513198daf8a97839345c/numpy-2.3.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:66459dccc65d8ec98cc7df61307b64bf9e08101f9598755d42d8ae65d9a7a6ee", size = 16053052, upload-time = "2025-07-24T20:44:58.872Z" },
+ { url = "https://files.pythonhosted.org/packages/57/7c/e5725d99a9133b9813fcf148d3f858df98511686e853169dbaf63aec6097/numpy-2.3.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a7af9ed2aa9ec5950daf05bb11abc4076a108bd3c7db9aa7251d5f107079b6a6", size = 18577955, upload-time = "2025-07-24T20:45:26.714Z" },
+ { url = "https://files.pythonhosted.org/packages/ae/11/7c546fcf42145f29b71e4d6f429e96d8d68e5a7ba1830b2e68d7418f0bbd/numpy-2.3.2-cp313-cp313-win32.whl", hash = "sha256:906a30249315f9c8e17b085cc5f87d3f369b35fedd0051d4a84686967bdbbd0b", size = 6311843, upload-time = "2025-07-24T20:49:24.444Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/6f/a428fd1cb7ed39b4280d057720fed5121b0d7754fd2a9768640160f5517b/numpy-2.3.2-cp313-cp313-win_amd64.whl", hash = "sha256:c63d95dc9d67b676e9108fe0d2182987ccb0f11933c1e8959f42fa0da8d4fa56", size = 12782876, upload-time = "2025-07-24T20:49:43.227Z" },
+ { url = "https://files.pythonhosted.org/packages/65/85/4ea455c9040a12595fb6c43f2c217257c7b52dd0ba332c6a6c1d28b289fe/numpy-2.3.2-cp313-cp313-win_arm64.whl", hash = "sha256:b05a89f2fb84d21235f93de47129dd4f11c16f64c87c33f5e284e6a3a54e43f2", size = 10192786, upload-time = "2025-07-24T20:49:59.443Z" },
+ { url = "https://files.pythonhosted.org/packages/80/23/8278f40282d10c3f258ec3ff1b103d4994bcad78b0cba9208317f6bb73da/numpy-2.3.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:4e6ecfeddfa83b02318f4d84acf15fbdbf9ded18e46989a15a8b6995dfbf85ab", size = 21047395, upload-time = "2025-07-24T20:45:58.821Z" },
+ { url = "https://files.pythonhosted.org/packages/1f/2d/624f2ce4a5df52628b4ccd16a4f9437b37c35f4f8a50d00e962aae6efd7a/numpy-2.3.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:508b0eada3eded10a3b55725b40806a4b855961040180028f52580c4729916a2", size = 14300374, upload-time = "2025-07-24T20:46:20.207Z" },
+ { url = "https://files.pythonhosted.org/packages/f6/62/ff1e512cdbb829b80a6bd08318a58698867bca0ca2499d101b4af063ee97/numpy-2.3.2-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:754d6755d9a7588bdc6ac47dc4ee97867271b17cee39cb87aef079574366db0a", size = 5228864, upload-time = "2025-07-24T20:46:30.58Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/8e/74bc18078fff03192d4032cfa99d5a5ca937807136d6f5790ce07ca53515/numpy-2.3.2-cp313-cp313t-macosx_14_0_x86_64.whl", hash = "sha256:a9f66e7d2b2d7712410d3bc5684149040ef5f19856f20277cd17ea83e5006286", size = 6737533, upload-time = "2025-07-24T20:46:46.111Z" },
+ { url = "https://files.pythonhosted.org/packages/19/ea/0731efe2c9073ccca5698ef6a8c3667c4cf4eea53fcdcd0b50140aba03bc/numpy-2.3.2-cp313-cp313t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:de6ea4e5a65d5a90c7d286ddff2b87f3f4ad61faa3db8dabe936b34c2275b6f8", size = 14352007, upload-time = "2025-07-24T20:47:07.1Z" },
+ { url = "https://files.pythonhosted.org/packages/cf/90/36be0865f16dfed20f4bc7f75235b963d5939707d4b591f086777412ff7b/numpy-2.3.2-cp313-cp313t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a3ef07ec8cbc8fc9e369c8dcd52019510c12da4de81367d8b20bc692aa07573a", size = 16701914, upload-time = "2025-07-24T20:47:32.459Z" },
+ { url = "https://files.pythonhosted.org/packages/94/30/06cd055e24cb6c38e5989a9e747042b4e723535758e6153f11afea88c01b/numpy-2.3.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:27c9f90e7481275c7800dc9c24b7cc40ace3fdb970ae4d21eaff983a32f70c91", size = 16132708, upload-time = "2025-07-24T20:47:58.129Z" },
+ { url = "https://files.pythonhosted.org/packages/9a/14/ecede608ea73e58267fd7cb78f42341b3b37ba576e778a1a06baffbe585c/numpy-2.3.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:07b62978075b67eee4065b166d000d457c82a1efe726cce608b9db9dd66a73a5", size = 18651678, upload-time = "2025-07-24T20:48:25.402Z" },
+ { url = "https://files.pythonhosted.org/packages/40/f3/2fe6066b8d07c3685509bc24d56386534c008b462a488b7f503ba82b8923/numpy-2.3.2-cp313-cp313t-win32.whl", hash = "sha256:c771cfac34a4f2c0de8e8c97312d07d64fd8f8ed45bc9f5726a7e947270152b5", size = 6441832, upload-time = "2025-07-24T20:48:37.181Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/ba/0937d66d05204d8f28630c9c60bc3eda68824abde4cf756c4d6aad03b0c6/numpy-2.3.2-cp313-cp313t-win_amd64.whl", hash = "sha256:72dbebb2dcc8305c431b2836bcc66af967df91be793d63a24e3d9b741374c450", size = 12927049, upload-time = "2025-07-24T20:48:56.24Z" },
+ { url = "https://files.pythonhosted.org/packages/e9/ed/13542dd59c104d5e654dfa2ac282c199ba64846a74c2c4bcdbc3a0f75df1/numpy-2.3.2-cp313-cp313t-win_arm64.whl", hash = "sha256:72c6df2267e926a6d5286b0a6d556ebe49eae261062059317837fda12ddf0c1a", size = 10262935, upload-time = "2025-07-24T20:49:13.136Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/7c/7659048aaf498f7611b783e000c7268fcc4dcf0ce21cd10aad7b2e8f9591/numpy-2.3.2-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:448a66d052d0cf14ce9865d159bfc403282c9bc7bb2a31b03cc18b651eca8b1a", size = 20950906, upload-time = "2025-07-24T20:50:30.346Z" },
+ { url = "https://files.pythonhosted.org/packages/80/db/984bea9d4ddf7112a04cfdfb22b1050af5757864cfffe8e09e44b7f11a10/numpy-2.3.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:546aaf78e81b4081b2eba1d105c3b34064783027a06b3ab20b6eba21fb64132b", size = 14185607, upload-time = "2025-07-24T20:50:51.923Z" },
+ { url = "https://files.pythonhosted.org/packages/e4/76/b3d6f414f4eca568f469ac112a3b510938d892bc5a6c190cb883af080b77/numpy-2.3.2-cp314-cp314-macosx_14_0_arm64.whl", hash = "sha256:87c930d52f45df092f7578889711a0768094debf73cfcde105e2d66954358125", size = 5114110, upload-time = "2025-07-24T20:51:01.041Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/d2/6f5e6826abd6bca52392ed88fe44a4b52aacb60567ac3bc86c67834c3a56/numpy-2.3.2-cp314-cp314-macosx_14_0_x86_64.whl", hash = "sha256:8dc082ea901a62edb8f59713c6a7e28a85daddcb67454c839de57656478f5b19", size = 6642050, upload-time = "2025-07-24T20:51:11.64Z" },
+ { url = "https://files.pythonhosted.org/packages/c4/43/f12b2ade99199e39c73ad182f103f9d9791f48d885c600c8e05927865baf/numpy-2.3.2-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:af58de8745f7fa9ca1c0c7c943616c6fe28e75d0c81f5c295810e3c83b5be92f", size = 14296292, upload-time = "2025-07-24T20:51:33.488Z" },
+ { url = "https://files.pythonhosted.org/packages/5d/f9/77c07d94bf110a916b17210fac38680ed8734c236bfed9982fd8524a7b47/numpy-2.3.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fed5527c4cf10f16c6d0b6bee1f89958bccb0ad2522c8cadc2efd318bcd545f5", size = 16638913, upload-time = "2025-07-24T20:51:58.517Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/d1/9d9f2c8ea399cc05cfff8a7437453bd4e7d894373a93cdc46361bbb49a7d/numpy-2.3.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:095737ed986e00393ec18ec0b21b47c22889ae4b0cd2d5e88342e08b01141f58", size = 16071180, upload-time = "2025-07-24T20:52:22.827Z" },
+ { url = "https://files.pythonhosted.org/packages/4c/41/82e2c68aff2a0c9bf315e47d61951099fed65d8cb2c8d9dc388cb87e947e/numpy-2.3.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:b5e40e80299607f597e1a8a247ff8d71d79c5b52baa11cc1cce30aa92d2da6e0", size = 18576809, upload-time = "2025-07-24T20:52:51.015Z" },
+ { url = "https://files.pythonhosted.org/packages/14/14/4b4fd3efb0837ed252d0f583c5c35a75121038a8c4e065f2c259be06d2d8/numpy-2.3.2-cp314-cp314-win32.whl", hash = "sha256:7d6e390423cc1f76e1b8108c9b6889d20a7a1f59d9a60cac4a050fa734d6c1e2", size = 6366410, upload-time = "2025-07-24T20:56:44.949Z" },
+ { url = "https://files.pythonhosted.org/packages/11/9e/b4c24a6b8467b61aced5c8dc7dcfce23621baa2e17f661edb2444a418040/numpy-2.3.2-cp314-cp314-win_amd64.whl", hash = "sha256:b9d0878b21e3918d76d2209c924ebb272340da1fb51abc00f986c258cd5e957b", size = 12918821, upload-time = "2025-07-24T20:57:06.479Z" },
+ { url = "https://files.pythonhosted.org/packages/0e/0f/0dc44007c70b1007c1cef86b06986a3812dd7106d8f946c09cfa75782556/numpy-2.3.2-cp314-cp314-win_arm64.whl", hash = "sha256:2738534837c6a1d0c39340a190177d7d66fdf432894f469728da901f8f6dc910", size = 10477303, upload-time = "2025-07-24T20:57:22.879Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/3e/075752b79140b78ddfc9c0a1634d234cfdbc6f9bbbfa6b7504e445ad7d19/numpy-2.3.2-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:4d002ecf7c9b53240be3bb69d80f86ddbd34078bae04d87be81c1f58466f264e", size = 21047524, upload-time = "2025-07-24T20:53:22.086Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/6d/60e8247564a72426570d0e0ea1151b95ce5bd2f1597bb878a18d32aec855/numpy-2.3.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:293b2192c6bcce487dbc6326de5853787f870aeb6c43f8f9c6496db5b1781e45", size = 14300519, upload-time = "2025-07-24T20:53:44.053Z" },
+ { url = "https://files.pythonhosted.org/packages/4d/73/d8326c442cd428d47a067070c3ac6cc3b651a6e53613a1668342a12d4479/numpy-2.3.2-cp314-cp314t-macosx_14_0_arm64.whl", hash = "sha256:0a4f2021a6da53a0d580d6ef5db29947025ae8b35b3250141805ea9a32bbe86b", size = 5228972, upload-time = "2025-07-24T20:53:53.81Z" },
+ { url = "https://files.pythonhosted.org/packages/34/2e/e71b2d6dad075271e7079db776196829019b90ce3ece5c69639e4f6fdc44/numpy-2.3.2-cp314-cp314t-macosx_14_0_x86_64.whl", hash = "sha256:9c144440db4bf3bb6372d2c3e49834cc0ff7bb4c24975ab33e01199e645416f2", size = 6737439, upload-time = "2025-07-24T20:54:04.742Z" },
+ { url = "https://files.pythonhosted.org/packages/15/b0/d004bcd56c2c5e0500ffc65385eb6d569ffd3363cb5e593ae742749b2daa/numpy-2.3.2-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f92d6c2a8535dc4fe4419562294ff957f83a16ebdec66df0805e473ffaad8bd0", size = 14352479, upload-time = "2025-07-24T20:54:25.819Z" },
+ { url = "https://files.pythonhosted.org/packages/11/e3/285142fcff8721e0c99b51686426165059874c150ea9ab898e12a492e291/numpy-2.3.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:cefc2219baa48e468e3db7e706305fcd0c095534a192a08f31e98d83a7d45fb0", size = 16702805, upload-time = "2025-07-24T20:54:50.814Z" },
+ { url = "https://files.pythonhosted.org/packages/33/c3/33b56b0e47e604af2c7cd065edca892d180f5899599b76830652875249a3/numpy-2.3.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:76c3e9501ceb50b2ff3824c3589d5d1ab4ac857b0ee3f8f49629d0de55ecf7c2", size = 16133830, upload-time = "2025-07-24T20:55:17.306Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/ae/7b1476a1f4d6a48bc669b8deb09939c56dd2a439db1ab03017844374fb67/numpy-2.3.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:122bf5ed9a0221b3419672493878ba4967121514b1d7d4656a7580cd11dddcbf", size = 18652665, upload-time = "2025-07-24T20:55:46.665Z" },
+ { url = "https://files.pythonhosted.org/packages/14/ba/5b5c9978c4bb161034148ade2de9db44ec316fab89ce8c400db0e0c81f86/numpy-2.3.2-cp314-cp314t-win32.whl", hash = "sha256:6f1ae3dcb840edccc45af496f312528c15b1f79ac318169d094e85e4bb35fdf1", size = 6514777, upload-time = "2025-07-24T20:55:57.66Z" },
+ { url = "https://files.pythonhosted.org/packages/eb/46/3dbaf0ae7c17cdc46b9f662c56da2054887b8d9e737c1476f335c83d33db/numpy-2.3.2-cp314-cp314t-win_amd64.whl", hash = "sha256:087ffc25890d89a43536f75c5fe8770922008758e8eeeef61733957041ed2f9b", size = 13111856, upload-time = "2025-07-24T20:56:17.318Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/9e/1652778bce745a67b5fe05adde60ed362d38eb17d919a540e813d30f6874/numpy-2.3.2-cp314-cp314t-win_arm64.whl", hash = "sha256:092aeb3449833ea9c0bf0089d70c29ae480685dd2377ec9cdbbb620257f84631", size = 10544226, upload-time = "2025-07-24T20:56:34.509Z" },
+]
+
+[[package]]
+name = "oauth2client"
+version = "4.1.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "httplib2" },
+ { name = "pyasn1" },
+ { name = "pyasn1-modules" },
+ { name = "rsa" },
+ { name = "six" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/a6/7b/17244b1083e8e604bf154cf9b716aecd6388acd656dd01893d0d244c94d9/oauth2client-4.1.3.tar.gz", hash = "sha256:d486741e451287f69568a4d26d70d9acd73a2bbfa275746c535b4209891cccc6", size = 155910, upload-time = "2018-09-07T21:38:18.036Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/95/a9/4f25a14d23f0786b64875b91784607c2277eff25d48f915e39ff0cff505a/oauth2client-4.1.3-py2.py3-none-any.whl", hash = "sha256:b8a81cc5d60e2d364f0b1b98f958dbd472887acaf1a5b05e21c28c31a2d6d3ac", size = 98206, upload-time = "2018-09-07T21:38:16.742Z" },
+]
+
+[[package]]
+name = "oauthlib"
+version = "3.3.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0b/5f/19930f824ffeb0ad4372da4812c50edbd1434f678c90c2733e1188edfc63/oauthlib-3.3.1.tar.gz", hash = "sha256:0f0f8aa759826a193cf66c12ea1af1637f87b9b4622d46e866952bb022e538c9", size = 185918, upload-time = "2025-06-19T22:48:08.269Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/be/9c/92789c596b8df838baa98fa71844d84283302f7604ed565dafe5a6b5041a/oauthlib-3.3.1-py3-none-any.whl", hash = "sha256:88119c938d2b8fb88561af5f6ee0eec8cc8d552b7bb1f712743136eb7523b7a1", size = 160065, upload-time = "2025-06-19T22:48:06.508Z" },
+]
+
+[[package]]
+name = "ollama"
+version = "0.5.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "httpx" },
+ { name = "pydantic" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/91/6d/ae96027416dcc2e98c944c050c492789502d7d7c0b95a740f0bb39268632/ollama-0.5.3.tar.gz", hash = "sha256:40b6dff729df3b24e56d4042fd9d37e231cee8e528677e0d085413a1d6692394", size = 43331, upload-time = "2025-08-07T21:44:10.422Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/be/f6/2091e50b8b6c3e6901f6eab283d5efd66fb71c86ddb1b4d68766c3eeba0f/ollama-0.5.3-py3-none-any.whl", hash = "sha256:a8303b413d99a9043dbf77ebf11ced672396b59bec27e6d5db67c88f01b279d2", size = 13490, upload-time = "2025-08-07T21:44:09.353Z" },
+]
+
+[[package]]
+name = "openai"
+version = "1.99.6"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "anyio" },
+ { name = "distro" },
+ { name = "httpx" },
+ { name = "jiter" },
+ { name = "pydantic" },
+ { name = "sniffio" },
+ { name = "tqdm" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/11/45/38a87bd6949236db5ae3132f41d5861824702b149f86d2627d6900919103/openai-1.99.6.tar.gz", hash = "sha256:f48f4239b938ef187062f3d5199a05b69711d8b600b9a9b6a3853cd271799183", size = 505364, upload-time = "2025-08-09T15:20:54.438Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d6/dd/9aa956485c2856346b3181542fbb0aea4e5b457fa7a523944726746da8da/openai-1.99.6-py3-none-any.whl", hash = "sha256:e40d44b2989588c45ce13819598788b77b8fb80ba2f7ae95ce90d14e46f1bd26", size = 786296, upload-time = "2025-08-09T15:20:51.95Z" },
+]
+
+[[package]]
+name = "opentelemetry-api"
+version = "1.37.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "importlib-metadata" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/63/04/05040d7ce33a907a2a02257e601992f0cdf11c73b33f13c4492bf6c3d6d5/opentelemetry_api-1.37.0.tar.gz", hash = "sha256:540735b120355bd5112738ea53621f8d5edb35ebcd6fe21ada3ab1c61d1cd9a7", size = 64923, upload-time = "2025-09-11T10:29:01.662Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/91/48/28ed9e55dcf2f453128df738210a980e09f4e468a456fa3c763dbc8be70a/opentelemetry_api-1.37.0-py3-none-any.whl", hash = "sha256:accf2024d3e89faec14302213bc39550ec0f4095d1cf5ca688e1bfb1c8612f47", size = 65732, upload-time = "2025-09-11T10:28:41.826Z" },
+]
+
+[[package]]
+name = "opentelemetry-distro"
+version = "0.58b0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "opentelemetry-api" },
+ { name = "opentelemetry-instrumentation" },
+ { name = "opentelemetry-sdk" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c3/20/597f387b42c649bac39af9ff8ad5bfdc163ce1a30cdecb16474ab8e57905/opentelemetry_distro-0.58b0.tar.gz", hash = "sha256:ef993c845c11fd156046a96e5ffe1ecfe33f7282fa6149cf9decb26ff8716666", size = 2583, upload-time = "2025-09-11T11:42:12.034Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/84/34/53016553489592262408b72e94466403da3c84ebe044b073bbcc1a6b228b/opentelemetry_distro-0.58b0-py3-none-any.whl", hash = "sha256:d90dddc3ae93d60d917a267a0099bd72f87fa3454b49ca8799f97cb58c777ef4", size = 3346, upload-time = "2025-09-11T11:40:56.853Z" },
+]
+
+[[package]]
+name = "opentelemetry-exporter-otlp"
+version = "1.15.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "opentelemetry-exporter-otlp-proto-grpc" },
+ { name = "opentelemetry-exporter-otlp-proto-http" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d9/bd/abafe13a0d77145270a39de7442d12d71b51a9f9d103d15d636110ae8a21/opentelemetry_exporter_otlp-1.15.0.tar.gz", hash = "sha256:4f7c49751d9720e2e726e13b0bb958ccade4e29122c305d92c033da432c8d2c5", size = 6126, upload-time = "2022-12-09T22:28:43.353Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/64/a2/4956610bd5348977fea8818d488793a46d1359337c0226164f093a17c61c/opentelemetry_exporter_otlp-1.15.0-py3-none-any.whl", hash = "sha256:79f22748b6a54808a0448093dfa189c8490e729f67c134d4c992533d9393b33e", size = 6976, upload-time = "2022-12-09T22:28:12.944Z" },
+]
+
+[[package]]
+name = "opentelemetry-exporter-otlp-proto-grpc"
+version = "1.15.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "backoff" },
+ { name = "googleapis-common-protos" },
+ { name = "grpcio" },
+ { name = "opentelemetry-api" },
+ { name = "opentelemetry-proto" },
+ { name = "opentelemetry-sdk" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e4/ab/1be294b194af410f350f867a54621b4f33b7551adce2ae795e907148fc1e/opentelemetry_exporter_otlp_proto_grpc-1.15.0.tar.gz", hash = "sha256:844f2a4bb9bcda34e4eb6fe36765e5031aacb36dc60ed88c90fc246942ea26e7", size = 27262, upload-time = "2022-12-09T22:28:44.359Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/dd/8f/73ad108bcfd61b4169be5ad8b76acaf9158f224740da10ab9ea3469d551a/opentelemetry_exporter_otlp_proto_grpc-1.15.0-py3-none-any.whl", hash = "sha256:c2a5492ba7d140109968135d641d06ce3c5bd73c50665f787526065d57d7fd1d", size = 20378, upload-time = "2022-12-09T22:28:14.623Z" },
+]
+
+[[package]]
+name = "opentelemetry-exporter-otlp-proto-http"
+version = "1.15.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "backoff" },
+ { name = "googleapis-common-protos" },
+ { name = "opentelemetry-api" },
+ { name = "opentelemetry-proto" },
+ { name = "opentelemetry-sdk" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ad/ee/14baa8edbf6b0c8e23a93ee0807fb637d4689959a0b166e2821032fade34/opentelemetry_exporter_otlp_proto_http-1.15.0.tar.gz", hash = "sha256:11b2c814249a49b22f6cca7a06b05701f561d577b747f3660dfd67b6eb9daf9c", size = 18930, upload-time = "2022-12-09T22:28:45.366Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b0/12/77af459682a4f41eb9f13801af6a12420a86f5673dc568585ee49112e969/opentelemetry_exporter_otlp_proto_http-1.15.0-py3-none-any.whl", hash = "sha256:3ec2a02196c8a54bf5cbf7fe623a5238625638e83b6047a983bdf96e2bbb74c0", size = 21588, upload-time = "2022-12-09T22:28:15.776Z" },
+]
+
+[[package]]
+name = "opentelemetry-instrumentation"
+version = "0.58b0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "opentelemetry-api" },
+ { name = "opentelemetry-semantic-conventions" },
+ { name = "packaging" },
+ { name = "wrapt" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f6/36/7c307d9be8ce4ee7beb86d7f1d31027f2a6a89228240405a858d6e4d64f9/opentelemetry_instrumentation-0.58b0.tar.gz", hash = "sha256:df640f3ac715a3e05af145c18f527f4422c6ab6c467e40bd24d2ad75a00cb705", size = 31549, upload-time = "2025-09-11T11:42:14.084Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d4/db/5ff1cd6c5ca1d12ecf1b73be16fbb2a8af2114ee46d4b0e6d4b23f4f4db7/opentelemetry_instrumentation-0.58b0-py3-none-any.whl", hash = "sha256:50f97ac03100676c9f7fc28197f8240c7290ca1baa12da8bfbb9a1de4f34cc45", size = 33019, upload-time = "2025-09-11T11:41:00.624Z" },
+]
+
+[[package]]
+name = "opentelemetry-proto"
+version = "1.15.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/1e/80/b3b2a98039574e57b6b15982219ae025d55f8c46d50dde258865ce5601b4/opentelemetry_proto-1.15.0.tar.gz", hash = "sha256:9c4008e40ac8cab359daac283fbe7002c5c29c77ea2674ad5626a249e64e0101", size = 35713, upload-time = "2022-12-09T22:28:55.409Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3a/56/8343d94af8f32594f6b0bd273f72a40e430fb5970a353237af53af5d3031/opentelemetry_proto-1.15.0-py3-none-any.whl", hash = "sha256:044b6d044b4d10530f250856f933442b8753a17f94ae37c207607f733fb9a844", size = 52616, upload-time = "2022-12-09T22:28:30.03Z" },
+]
+
+[[package]]
+name = "opentelemetry-sdk"
+version = "1.37.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "opentelemetry-api" },
+ { name = "opentelemetry-semantic-conventions" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f4/62/2e0ca80d7fe94f0b193135375da92c640d15fe81f636658d2acf373086bc/opentelemetry_sdk-1.37.0.tar.gz", hash = "sha256:cc8e089c10953ded765b5ab5669b198bbe0af1b3f89f1007d19acd32dc46dda5", size = 170404, upload-time = "2025-09-11T10:29:11.779Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/9f/62/9f4ad6a54126fb00f7ed4bb5034964c6e4f00fcd5a905e115bd22707e20d/opentelemetry_sdk-1.37.0-py3-none-any.whl", hash = "sha256:8f3c3c22063e52475c5dbced7209495c2c16723d016d39287dfc215d1771257c", size = 131941, upload-time = "2025-09-11T10:28:57.83Z" },
+]
+
+[[package]]
+name = "opentelemetry-semantic-conventions"
+version = "0.58b0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "opentelemetry-api" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/aa/1b/90701d91e6300d9f2fb352153fb1721ed99ed1f6ea14fa992c756016e63a/opentelemetry_semantic_conventions-0.58b0.tar.gz", hash = "sha256:6bd46f51264279c433755767bb44ad00f1c9e2367e1b42af563372c5a6fa0c25", size = 129867, upload-time = "2025-09-11T10:29:12.597Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/07/90/68152b7465f50285d3ce2481b3aec2f82822e3f52e5152eeeaf516bab841/opentelemetry_semantic_conventions-0.58b0-py3-none-any.whl", hash = "sha256:5564905ab1458b96684db1340232729fce3b5375a06e140e8904c78e4f815b28", size = 207954, upload-time = "2025-09-11T10:28:59.218Z" },
+]
+
+[[package]]
+name = "oracledb"
+version = "2.4.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cryptography" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ed/c7/12632c03022aa5059ce9b6738397cda682dfda9d9afe7008b8a4f98c6ee5/oracledb-2.4.0.tar.gz", hash = "sha256:bdd61a9d5077448b5f1c58af6a14accc287bf8032846c351a3cdde5cf64fe95b", size = 614809, upload-time = "2024-08-20T21:02:35.362Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/9e/5b/5125e0a74a58717ac094d953ddaa4c61cfefcd926850c0ecc081e0c209f3/oracledb-2.4.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:03d1072db83e3f95a8792b8452c78940141902ef97f31223f1d96bfeb8ff830b", size = 3769983, upload-time = "2024-08-20T21:03:08.186Z" },
+ { url = "https://files.pythonhosted.org/packages/17/22/81eb81e15a86989acd21220480a87a3891a27b3f2d64b249098e09e002eb/oracledb-2.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2fda77ace54379ad70187627ed02329f9ef4f35c1cc1052e4d27fe4ec68d38fc", size = 2081340, upload-time = "2024-08-20T21:03:10.988Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/56/9cd84f67a573cc6066589d8264ab13f710a128197977205b9c4b177ee85e/oracledb-2.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bed34cdd5037277424bb5a38987e00cbb6eea3670ce9c4fcc3cab5971fab5348", size = 2234827, upload-time = "2024-08-20T21:03:13.716Z" },
+ { url = "https://files.pythonhosted.org/packages/f5/ca/4406cfe3400735bf4a1eee951eb174c6cd8573e74d43c1aba9448066a3d2/oracledb-2.4.0-cp312-cp312-win32.whl", hash = "sha256:02e1eea36de371d7719ca02d20a8900fab767e5db71aa59be101405060cf2cfa", size = 1373933, upload-time = "2024-08-20T21:03:15.514Z" },
+ { url = "https://files.pythonhosted.org/packages/a8/e9/1a8afdbe4aaba030476c91284d7599f54fce2879232d28797a4a71d5cfe2/oracledb-2.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:0b81ec1e20d4d20b0f95a673bb73923d24673e8739d3a25a746113519612c057", size = 1681666, upload-time = "2024-08-20T21:03:17.366Z" },
+ { url = "https://files.pythonhosted.org/packages/88/ae/603c592fc7054ccad523ba06f3d186cae5fb0f18ce477552be2178d6668b/oracledb-2.4.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:b2933b4fd324da089a15567830d81d4ff1b3e7ecc24a615f9e61b0f7fcacf32d", size = 3730093, upload-time = "2024-08-20T21:03:20.23Z" },
+ { url = "https://files.pythonhosted.org/packages/af/70/744ab12e334375808678fbce494be560269f59dbda03613f02d4c22cadeb/oracledb-2.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6d721d5fd0d45bd901bc76247172eb2e00f9feb67283dbb38e763e3e50308cb0", size = 2079861, upload-time = "2024-08-20T21:03:22.954Z" },
+ { url = "https://files.pythonhosted.org/packages/eb/5d/f1606491f05337d95e92ba8d474852d9616cc43bf24d60a64cc33a5f5517/oracledb-2.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e23661da50934439b88fcedd9be3c8abecb313335abde9cf9faee3162c814744", size = 2235137, upload-time = "2024-08-20T21:03:25.061Z" },
+ { url = "https://files.pythonhosted.org/packages/ca/b0/cc05876b2a0b50a528dc5f01a81eb18386beeb0aba8993b796d1d381399e/oracledb-2.4.0-cp313-cp313-win32.whl", hash = "sha256:b10998a89fc93a31a968fd34d36547f7878f3efb3491e61493c78ddd5724283f", size = 1370670, upload-time = "2024-08-20T21:03:26.819Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/09/bea4244b8e040f9a31178196082ffbde34404f8bb42c780a192b28a113b2/oracledb-2.4.0-cp313-cp313-win_amd64.whl", hash = "sha256:e39779713558bc6f2e1ec78b71378536ec9da05dc5f95fe3ca41bfb6b878e81a", size = 1678689, upload-time = "2024-08-20T21:03:29.108Z" },
+]
+
+[[package]]
+name = "packaging"
+version = "25.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a1/d4/1fc4078c65507b51b96ca8f8c3ba19e6a61c8253c72794544580a7b6c24d/packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f", size = 165727, upload-time = "2025-04-19T11:48:59.673Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", size = 66469, upload-time = "2025-04-19T11:48:57.875Z" },
+]
+
+[[package]]
+name = "pandas"
+version = "2.2.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "numpy" },
+ { name = "python-dateutil" },
+ { name = "pytz" },
+ { name = "tzdata" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/9c/d6/9f8431bacc2e19dca897724cd097b1bb224a6ad5433784a44b587c7c13af/pandas-2.2.3.tar.gz", hash = "sha256:4f18ba62b61d7e192368b84517265a99b4d7ee8912f8708660fb4a366cc82667", size = 4399213, upload-time = "2024-09-20T13:10:04.827Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/17/a3/fb2734118db0af37ea7433f57f722c0a56687e14b14690edff0cdb4b7e58/pandas-2.2.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:b1d432e8d08679a40e2a6d8b2f9770a5c21793a6f9f47fdd52c5ce1948a5a8a9", size = 12529893, upload-time = "2024-09-20T13:09:09.655Z" },
+ { url = "https://files.pythonhosted.org/packages/e1/0c/ad295fd74bfac85358fd579e271cded3ac969de81f62dd0142c426b9da91/pandas-2.2.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a5a1595fe639f5988ba6a8e5bc9649af3baf26df3998a0abe56c02609392e0a4", size = 11363475, upload-time = "2024-09-20T13:09:14.718Z" },
+ { url = "https://files.pythonhosted.org/packages/c6/2a/4bba3f03f7d07207481fed47f5b35f556c7441acddc368ec43d6643c5777/pandas-2.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:5de54125a92bb4d1c051c0659e6fcb75256bf799a732a87184e5ea503965bce3", size = 15188645, upload-time = "2024-09-20T19:02:03.88Z" },
+ { url = "https://files.pythonhosted.org/packages/38/f8/d8fddee9ed0d0c0f4a2132c1dfcf0e3e53265055da8df952a53e7eaf178c/pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fffb8ae78d8af97f849404f21411c95062db1496aeb3e56f146f0355c9989319", size = 12739445, upload-time = "2024-09-20T13:09:17.621Z" },
+ { url = "https://files.pythonhosted.org/packages/20/e8/45a05d9c39d2cea61ab175dbe6a2de1d05b679e8de2011da4ee190d7e748/pandas-2.2.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6dfcb5ee8d4d50c06a51c2fffa6cff6272098ad6540aed1a76d15fb9318194d8", size = 16359235, upload-time = "2024-09-20T19:02:07.094Z" },
+ { url = "https://files.pythonhosted.org/packages/1d/99/617d07a6a5e429ff90c90da64d428516605a1ec7d7bea494235e1c3882de/pandas-2.2.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:062309c1b9ea12a50e8ce661145c6aab431b1e99530d3cd60640e255778bd43a", size = 14056756, upload-time = "2024-09-20T13:09:20.474Z" },
+ { url = "https://files.pythonhosted.org/packages/29/d4/1244ab8edf173a10fd601f7e13b9566c1b525c4f365d6bee918e68381889/pandas-2.2.3-cp312-cp312-win_amd64.whl", hash = "sha256:59ef3764d0fe818125a5097d2ae867ca3fa64df032331b7e0917cf5d7bf66b13", size = 11504248, upload-time = "2024-09-20T13:09:23.137Z" },
+ { url = "https://files.pythonhosted.org/packages/64/22/3b8f4e0ed70644e85cfdcd57454686b9057c6c38d2f74fe4b8bc2527214a/pandas-2.2.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f00d1345d84d8c86a63e476bb4955e46458b304b9575dcf71102b5c705320015", size = 12477643, upload-time = "2024-09-20T13:09:25.522Z" },
+ { url = "https://files.pythonhosted.org/packages/e4/93/b3f5d1838500e22c8d793625da672f3eec046b1a99257666c94446969282/pandas-2.2.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3508d914817e153ad359d7e069d752cdd736a247c322d932eb89e6bc84217f28", size = 11281573, upload-time = "2024-09-20T13:09:28.012Z" },
+ { url = "https://files.pythonhosted.org/packages/f5/94/6c79b07f0e5aab1dcfa35a75f4817f5c4f677931d4234afcd75f0e6a66ca/pandas-2.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:22a9d949bfc9a502d320aa04e5d02feab689d61da4e7764b62c30b991c42c5f0", size = 15196085, upload-time = "2024-09-20T19:02:10.451Z" },
+ { url = "https://files.pythonhosted.org/packages/e8/31/aa8da88ca0eadbabd0a639788a6da13bb2ff6edbbb9f29aa786450a30a91/pandas-2.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3a255b2c19987fbbe62a9dfd6cff7ff2aa9ccab3fc75218fd4b7530f01efa24", size = 12711809, upload-time = "2024-09-20T13:09:30.814Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/7c/c6dbdb0cb2a4344cacfb8de1c5808ca885b2e4dcfde8008266608f9372af/pandas-2.2.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:800250ecdadb6d9c78eae4990da62743b857b470883fa27f652db8bdde7f6659", size = 16356316, upload-time = "2024-09-20T19:02:13.825Z" },
+ { url = "https://files.pythonhosted.org/packages/57/b7/8b757e7d92023b832869fa8881a992696a0bfe2e26f72c9ae9f255988d42/pandas-2.2.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6374c452ff3ec675a8f46fd9ab25c4ad0ba590b71cf0656f8b6daa5202bca3fb", size = 14022055, upload-time = "2024-09-20T13:09:33.462Z" },
+ { url = "https://files.pythonhosted.org/packages/3b/bc/4b18e2b8c002572c5a441a64826252ce5da2aa738855747247a971988043/pandas-2.2.3-cp313-cp313-win_amd64.whl", hash = "sha256:61c5ad4043f791b61dd4752191d9f07f0ae412515d59ba8f005832a532f8736d", size = 11481175, upload-time = "2024-09-20T13:09:35.871Z" },
+ { url = "https://files.pythonhosted.org/packages/76/a3/a5d88146815e972d40d19247b2c162e88213ef51c7c25993942c39dbf41d/pandas-2.2.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:3b71f27954685ee685317063bf13c7709a7ba74fc996b84fc6821c59b0f06468", size = 12615650, upload-time = "2024-09-20T13:09:38.685Z" },
+ { url = "https://files.pythonhosted.org/packages/9c/8c/f0fd18f6140ddafc0c24122c8a964e48294acc579d47def376fef12bcb4a/pandas-2.2.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:38cf8125c40dae9d5acc10fa66af8ea6fdf760b2714ee482ca691fc66e6fcb18", size = 11290177, upload-time = "2024-09-20T13:09:41.141Z" },
+ { url = "https://files.pythonhosted.org/packages/ed/f9/e995754eab9c0f14c6777401f7eece0943840b7a9fc932221c19d1abee9f/pandas-2.2.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ba96630bc17c875161df3818780af30e43be9b166ce51c9a18c1feae342906c2", size = 14651526, upload-time = "2024-09-20T19:02:16.905Z" },
+ { url = "https://files.pythonhosted.org/packages/25/b0/98d6ae2e1abac4f35230aa756005e8654649d305df9a28b16b9ae4353bff/pandas-2.2.3-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1db71525a1538b30142094edb9adc10be3f3e176748cd7acc2240c2f2e5aa3a4", size = 11871013, upload-time = "2024-09-20T13:09:44.39Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/57/0f72a10f9db6a4628744c8e8f0df4e6e21de01212c7c981d31e50ffc8328/pandas-2.2.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:15c0e1e02e93116177d29ff83e8b1619c93ddc9c49083f237d4312337a61165d", size = 15711620, upload-time = "2024-09-20T19:02:20.639Z" },
+ { url = "https://files.pythonhosted.org/packages/ab/5f/b38085618b950b79d2d9164a711c52b10aefc0ae6833b96f626b7021b2ed/pandas-2.2.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:ad5b65698ab28ed8d7f18790a0dc58005c7629f227be9ecc1072aa74c0c1d43a", size = 13098436, upload-time = "2024-09-20T13:09:48.112Z" },
+]
+
+[[package]]
+name = "paramiko"
+version = "4.0.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "bcrypt" },
+ { name = "cryptography" },
+ { name = "invoke" },
+ { name = "pynacl" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/1f/e7/81fdcbc7f190cdb058cffc9431587eb289833bdd633e2002455ca9bb13d4/paramiko-4.0.0.tar.gz", hash = "sha256:6a25f07b380cc9c9a88d2b920ad37167ac4667f8d9886ccebd8f90f654b5d69f", size = 1630743, upload-time = "2025-08-04T01:02:03.711Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a9/90/a744336f5af32c433bd09af7854599682a383b37cfd78f7de263de6ad6cb/paramiko-4.0.0-py3-none-any.whl", hash = "sha256:0e20e00ac666503bf0b4eda3b6d833465a2b7aff2e2b3d79a8bba5ef144ee3b9", size = 223932, upload-time = "2025-08-04T01:02:02.029Z" },
+]
+
+[[package]]
+name = "pathspec"
+version = "0.12.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ca/bc/f35b8446f4531a7cb215605d100cd88b7ac6f44ab3fc94870c120ab3adbf/pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712", size = 51043, upload-time = "2023-12-10T22:30:45Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191, upload-time = "2023-12-10T22:30:43.14Z" },
+]
+
+[[package]]
+name = "pdfminer-six"
+version = "20250506"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "charset-normalizer" },
+ { name = "cryptography" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/78/46/5223d613ac4963e1f7c07b2660fe0e9e770102ec6bda8c038400113fb215/pdfminer_six-20250506.tar.gz", hash = "sha256:b03cc8df09cf3c7aba8246deae52e0bca7ebb112a38895b5e1d4f5dd2b8ca2e7", size = 7387678, upload-time = "2025-05-06T16:17:00.787Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/73/16/7a432c0101fa87457e75cb12c879e1749c5870a786525e2e0f42871d6462/pdfminer_six-20250506-py3-none-any.whl", hash = "sha256:d81ad173f62e5f841b53a8ba63af1a4a355933cfc0ffabd608e568b9193909e3", size = 5620187, upload-time = "2025-05-06T16:16:58.669Z" },
+]
+
+[[package]]
+name = "pdfplumber"
+version = "0.11.7"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pdfminer-six" },
+ { name = "pillow" },
+ { name = "pypdfium2" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/6d/0d/4135821aa7b1a0b77a29fac881ef0890b46b0b002290d04915ed7acc0043/pdfplumber-0.11.7.tar.gz", hash = "sha256:fa67773e5e599de1624255e9b75d1409297c5e1d7493b386ce63648637c67368", size = 115518, upload-time = "2025-06-12T11:30:49.864Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/db/e0/52b67d4f00e09e497aec4f71bc44d395605e8ebcea52543242ed34c25ef9/pdfplumber-0.11.7-py3-none-any.whl", hash = "sha256:edd2195cca68bd770da479cf528a737e362968ec2351e62a6c0b71ff612ac25e", size = 60029, upload-time = "2025-06-12T11:30:48.89Z" },
+]
+
+[[package]]
+name = "pgvector"
+version = "0.4.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "numpy" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/44/43/9a0fb552ab4fd980680c2037962e331820f67585df740bedc4a2b50faf20/pgvector-0.4.1.tar.gz", hash = "sha256:83d3a1c044ff0c2f1e95d13dfb625beb0b65506cfec0941bfe81fd0ad44f4003", size = 30646, upload-time = "2025-04-26T18:56:37.151Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bf/21/b5735d5982892c878ff3d01bb06e018c43fc204428361ee9fc25a1b2125c/pgvector-0.4.1-py3-none-any.whl", hash = "sha256:34bb4e99e1b13d08a2fe82dda9f860f15ddcd0166fbb25bffe15821cbfeb7362", size = 27086, upload-time = "2025-04-26T18:56:35.956Z" },
+]
+
+[[package]]
+name = "pillow"
+version = "11.3.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f3/0d/d0d6dea55cd152ce3d6767bb38a8fc10e33796ba4ba210cbab9354b6d238/pillow-11.3.0.tar.gz", hash = "sha256:3828ee7586cd0b2091b6209e5ad53e20d0649bbe87164a459d0676e035e8f523", size = 47113069, upload-time = "2025-07-01T09:16:30.666Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/40/fe/1bc9b3ee13f68487a99ac9529968035cca2f0a51ec36892060edcc51d06a/pillow-11.3.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:fdae223722da47b024b867c1ea0be64e0df702c5e0a60e27daad39bf960dd1e4", size = 5278800, upload-time = "2025-07-01T09:14:17.648Z" },
+ { url = "https://files.pythonhosted.org/packages/2c/32/7e2ac19b5713657384cec55f89065fb306b06af008cfd87e572035b27119/pillow-11.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:921bd305b10e82b4d1f5e802b6850677f965d8394203d182f078873851dada69", size = 4686296, upload-time = "2025-07-01T09:14:19.828Z" },
+ { url = "https://files.pythonhosted.org/packages/8e/1e/b9e12bbe6e4c2220effebc09ea0923a07a6da1e1f1bfbc8d7d29a01ce32b/pillow-11.3.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:eb76541cba2f958032d79d143b98a3a6b3ea87f0959bbe256c0b5e416599fd5d", size = 5871726, upload-time = "2025-07-03T13:10:04.448Z" },
+ { url = "https://files.pythonhosted.org/packages/8d/33/e9200d2bd7ba00dc3ddb78df1198a6e80d7669cce6c2bdbeb2530a74ec58/pillow-11.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:67172f2944ebba3d4a7b54f2e95c786a3a50c21b88456329314caaa28cda70f6", size = 7644652, upload-time = "2025-07-03T13:10:10.391Z" },
+ { url = "https://files.pythonhosted.org/packages/41/f1/6f2427a26fc683e00d985bc391bdd76d8dd4e92fac33d841127eb8fb2313/pillow-11.3.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:97f07ed9f56a3b9b5f49d3661dc9607484e85c67e27f3e8be2c7d28ca032fec7", size = 5977787, upload-time = "2025-07-01T09:14:21.63Z" },
+ { url = "https://files.pythonhosted.org/packages/e4/c9/06dd4a38974e24f932ff5f98ea3c546ce3f8c995d3f0985f8e5ba48bba19/pillow-11.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:676b2815362456b5b3216b4fd5bd89d362100dc6f4945154ff172e206a22c024", size = 6645236, upload-time = "2025-07-01T09:14:23.321Z" },
+ { url = "https://files.pythonhosted.org/packages/40/e7/848f69fb79843b3d91241bad658e9c14f39a32f71a301bcd1d139416d1be/pillow-11.3.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:3e184b2f26ff146363dd07bde8b711833d7b0202e27d13540bfe2e35a323a809", size = 6086950, upload-time = "2025-07-01T09:14:25.237Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/1a/7cff92e695a2a29ac1958c2a0fe4c0b2393b60aac13b04a4fe2735cad52d/pillow-11.3.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:6be31e3fc9a621e071bc17bb7de63b85cbe0bfae91bb0363c893cbe67247780d", size = 6723358, upload-time = "2025-07-01T09:14:27.053Z" },
+ { url = "https://files.pythonhosted.org/packages/26/7d/73699ad77895f69edff76b0f332acc3d497f22f5d75e5360f78cbcaff248/pillow-11.3.0-cp312-cp312-win32.whl", hash = "sha256:7b161756381f0918e05e7cb8a371fff367e807770f8fe92ecb20d905d0e1c149", size = 6275079, upload-time = "2025-07-01T09:14:30.104Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/ce/e7dfc873bdd9828f3b6e5c2bbb74e47a98ec23cc5c74fc4e54462f0d9204/pillow-11.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:a6444696fce635783440b7f7a9fc24b3ad10a9ea3f0ab66c5905be1c19ccf17d", size = 6986324, upload-time = "2025-07-01T09:14:31.899Z" },
+ { url = "https://files.pythonhosted.org/packages/16/8f/b13447d1bf0b1f7467ce7d86f6e6edf66c0ad7cf44cf5c87a37f9bed9936/pillow-11.3.0-cp312-cp312-win_arm64.whl", hash = "sha256:2aceea54f957dd4448264f9bf40875da0415c83eb85f55069d89c0ed436e3542", size = 2423067, upload-time = "2025-07-01T09:14:33.709Z" },
+ { url = "https://files.pythonhosted.org/packages/1e/93/0952f2ed8db3a5a4c7a11f91965d6184ebc8cd7cbb7941a260d5f018cd2d/pillow-11.3.0-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:1c627742b539bba4309df89171356fcb3cc5a9178355b2727d1b74a6cf155fbd", size = 2128328, upload-time = "2025-07-01T09:14:35.276Z" },
+ { url = "https://files.pythonhosted.org/packages/4b/e8/100c3d114b1a0bf4042f27e0f87d2f25e857e838034e98ca98fe7b8c0a9c/pillow-11.3.0-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:30b7c02f3899d10f13d7a48163c8969e4e653f8b43416d23d13d1bbfdc93b9f8", size = 2170652, upload-time = "2025-07-01T09:14:37.203Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/86/3f758a28a6e381758545f7cdb4942e1cb79abd271bea932998fc0db93cb6/pillow-11.3.0-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:7859a4cc7c9295f5838015d8cc0a9c215b77e43d07a25e460f35cf516df8626f", size = 2227443, upload-time = "2025-07-01T09:14:39.344Z" },
+ { url = "https://files.pythonhosted.org/packages/01/f4/91d5b3ffa718df2f53b0dc109877993e511f4fd055d7e9508682e8aba092/pillow-11.3.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:ec1ee50470b0d050984394423d96325b744d55c701a439d2bd66089bff963d3c", size = 5278474, upload-time = "2025-07-01T09:14:41.843Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/0e/37d7d3eca6c879fbd9dba21268427dffda1ab00d4eb05b32923d4fbe3b12/pillow-11.3.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:7db51d222548ccfd274e4572fdbf3e810a5e66b00608862f947b163e613b67dd", size = 4686038, upload-time = "2025-07-01T09:14:44.008Z" },
+ { url = "https://files.pythonhosted.org/packages/ff/b0/3426e5c7f6565e752d81221af9d3676fdbb4f352317ceafd42899aaf5d8a/pillow-11.3.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:2d6fcc902a24ac74495df63faad1884282239265c6839a0a6416d33faedfae7e", size = 5864407, upload-time = "2025-07-03T13:10:15.628Z" },
+ { url = "https://files.pythonhosted.org/packages/fc/c1/c6c423134229f2a221ee53f838d4be9d82bab86f7e2f8e75e47b6bf6cd77/pillow-11.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f0f5d8f4a08090c6d6d578351a2b91acf519a54986c055af27e7a93feae6d3f1", size = 7639094, upload-time = "2025-07-03T13:10:21.857Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/c9/09e6746630fe6372c67c648ff9deae52a2bc20897d51fa293571977ceb5d/pillow-11.3.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c37d8ba9411d6003bba9e518db0db0c58a680ab9fe5179f040b0463644bc9805", size = 5973503, upload-time = "2025-07-01T09:14:45.698Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/1c/a2a29649c0b1983d3ef57ee87a66487fdeb45132df66ab30dd37f7dbe162/pillow-11.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:13f87d581e71d9189ab21fe0efb5a23e9f28552d5be6979e84001d3b8505abe8", size = 6642574, upload-time = "2025-07-01T09:14:47.415Z" },
+ { url = "https://files.pythonhosted.org/packages/36/de/d5cc31cc4b055b6c6fd990e3e7f0f8aaf36229a2698501bcb0cdf67c7146/pillow-11.3.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:023f6d2d11784a465f09fd09a34b150ea4672e85fb3d05931d89f373ab14abb2", size = 6084060, upload-time = "2025-07-01T09:14:49.636Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/ea/502d938cbaeec836ac28a9b730193716f0114c41325db428e6b280513f09/pillow-11.3.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:45dfc51ac5975b938e9809451c51734124e73b04d0f0ac621649821a63852e7b", size = 6721407, upload-time = "2025-07-01T09:14:51.962Z" },
+ { url = "https://files.pythonhosted.org/packages/45/9c/9c5e2a73f125f6cbc59cc7087c8f2d649a7ae453f83bd0362ff7c9e2aee2/pillow-11.3.0-cp313-cp313-win32.whl", hash = "sha256:a4d336baed65d50d37b88ca5b60c0fa9d81e3a87d4a7930d3880d1624d5b31f3", size = 6273841, upload-time = "2025-07-01T09:14:54.142Z" },
+ { url = "https://files.pythonhosted.org/packages/23/85/397c73524e0cd212067e0c969aa245b01d50183439550d24d9f55781b776/pillow-11.3.0-cp313-cp313-win_amd64.whl", hash = "sha256:0bce5c4fd0921f99d2e858dc4d4d64193407e1b99478bc5cacecba2311abde51", size = 6978450, upload-time = "2025-07-01T09:14:56.436Z" },
+ { url = "https://files.pythonhosted.org/packages/17/d2/622f4547f69cd173955194b78e4d19ca4935a1b0f03a302d655c9f6aae65/pillow-11.3.0-cp313-cp313-win_arm64.whl", hash = "sha256:1904e1264881f682f02b7f8167935cce37bc97db457f8e7849dc3a6a52b99580", size = 2423055, upload-time = "2025-07-01T09:14:58.072Z" },
+ { url = "https://files.pythonhosted.org/packages/dd/80/a8a2ac21dda2e82480852978416cfacd439a4b490a501a288ecf4fe2532d/pillow-11.3.0-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:4c834a3921375c48ee6b9624061076bc0a32a60b5532b322cc0ea64e639dd50e", size = 5281110, upload-time = "2025-07-01T09:14:59.79Z" },
+ { url = "https://files.pythonhosted.org/packages/44/d6/b79754ca790f315918732e18f82a8146d33bcd7f4494380457ea89eb883d/pillow-11.3.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:5e05688ccef30ea69b9317a9ead994b93975104a677a36a8ed8106be9260aa6d", size = 4689547, upload-time = "2025-07-01T09:15:01.648Z" },
+ { url = "https://files.pythonhosted.org/packages/49/20/716b8717d331150cb00f7fdd78169c01e8e0c219732a78b0e59b6bdb2fd6/pillow-11.3.0-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:1019b04af07fc0163e2810167918cb5add8d74674b6267616021ab558dc98ced", size = 5901554, upload-time = "2025-07-03T13:10:27.018Z" },
+ { url = "https://files.pythonhosted.org/packages/74/cf/a9f3a2514a65bb071075063a96f0a5cf949c2f2fce683c15ccc83b1c1cab/pillow-11.3.0-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f944255db153ebb2b19c51fe85dd99ef0ce494123f21b9db4877ffdfc5590c7c", size = 7669132, upload-time = "2025-07-03T13:10:33.01Z" },
+ { url = "https://files.pythonhosted.org/packages/98/3c/da78805cbdbee9cb43efe8261dd7cc0b4b93f2ac79b676c03159e9db2187/pillow-11.3.0-cp313-cp313t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1f85acb69adf2aaee8b7da124efebbdb959a104db34d3a2cb0f3793dbae422a8", size = 6005001, upload-time = "2025-07-01T09:15:03.365Z" },
+ { url = "https://files.pythonhosted.org/packages/6c/fa/ce044b91faecf30e635321351bba32bab5a7e034c60187fe9698191aef4f/pillow-11.3.0-cp313-cp313t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:05f6ecbeff5005399bb48d198f098a9b4b6bdf27b8487c7f38ca16eeb070cd59", size = 6668814, upload-time = "2025-07-01T09:15:05.655Z" },
+ { url = "https://files.pythonhosted.org/packages/7b/51/90f9291406d09bf93686434f9183aba27b831c10c87746ff49f127ee80cb/pillow-11.3.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:a7bc6e6fd0395bc052f16b1a8670859964dbd7003bd0af2ff08342eb6e442cfe", size = 6113124, upload-time = "2025-07-01T09:15:07.358Z" },
+ { url = "https://files.pythonhosted.org/packages/cd/5a/6fec59b1dfb619234f7636d4157d11fb4e196caeee220232a8d2ec48488d/pillow-11.3.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:83e1b0161c9d148125083a35c1c5a89db5b7054834fd4387499e06552035236c", size = 6747186, upload-time = "2025-07-01T09:15:09.317Z" },
+ { url = "https://files.pythonhosted.org/packages/49/6b/00187a044f98255225f172de653941e61da37104a9ea60e4f6887717e2b5/pillow-11.3.0-cp313-cp313t-win32.whl", hash = "sha256:2a3117c06b8fb646639dce83694f2f9eac405472713fcb1ae887469c0d4f6788", size = 6277546, upload-time = "2025-07-01T09:15:11.311Z" },
+ { url = "https://files.pythonhosted.org/packages/e8/5c/6caaba7e261c0d75bab23be79f1d06b5ad2a2ae49f028ccec801b0e853d6/pillow-11.3.0-cp313-cp313t-win_amd64.whl", hash = "sha256:857844335c95bea93fb39e0fa2726b4d9d758850b34075a7e3ff4f4fa3aa3b31", size = 6985102, upload-time = "2025-07-01T09:15:13.164Z" },
+ { url = "https://files.pythonhosted.org/packages/f3/7e/b623008460c09a0cb38263c93b828c666493caee2eb34ff67f778b87e58c/pillow-11.3.0-cp313-cp313t-win_arm64.whl", hash = "sha256:8797edc41f3e8536ae4b10897ee2f637235c94f27404cac7297f7b607dd0716e", size = 2424803, upload-time = "2025-07-01T09:15:15.695Z" },
+ { url = "https://files.pythonhosted.org/packages/73/f4/04905af42837292ed86cb1b1dabe03dce1edc008ef14c473c5c7e1443c5d/pillow-11.3.0-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:d9da3df5f9ea2a89b81bb6087177fb1f4d1c7146d583a3fe5c672c0d94e55e12", size = 5278520, upload-time = "2025-07-01T09:15:17.429Z" },
+ { url = "https://files.pythonhosted.org/packages/41/b0/33d79e377a336247df6348a54e6d2a2b85d644ca202555e3faa0cf811ecc/pillow-11.3.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:0b275ff9b04df7b640c59ec5a3cb113eefd3795a8df80bac69646ef699c6981a", size = 4686116, upload-time = "2025-07-01T09:15:19.423Z" },
+ { url = "https://files.pythonhosted.org/packages/49/2d/ed8bc0ab219ae8768f529597d9509d184fe8a6c4741a6864fea334d25f3f/pillow-11.3.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0743841cabd3dba6a83f38a92672cccbd69af56e3e91777b0ee7f4dba4385632", size = 5864597, upload-time = "2025-07-03T13:10:38.404Z" },
+ { url = "https://files.pythonhosted.org/packages/b5/3d/b932bb4225c80b58dfadaca9d42d08d0b7064d2d1791b6a237f87f661834/pillow-11.3.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:2465a69cf967b8b49ee1b96d76718cd98c4e925414ead59fdf75cf0fd07df673", size = 7638246, upload-time = "2025-07-03T13:10:44.987Z" },
+ { url = "https://files.pythonhosted.org/packages/09/b5/0487044b7c096f1b48f0d7ad416472c02e0e4bf6919541b111efd3cae690/pillow-11.3.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:41742638139424703b4d01665b807c6468e23e699e8e90cffefe291c5832b027", size = 5973336, upload-time = "2025-07-01T09:15:21.237Z" },
+ { url = "https://files.pythonhosted.org/packages/a8/2d/524f9318f6cbfcc79fbc004801ea6b607ec3f843977652fdee4857a7568b/pillow-11.3.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:93efb0b4de7e340d99057415c749175e24c8864302369e05914682ba642e5d77", size = 6642699, upload-time = "2025-07-01T09:15:23.186Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/d2/a9a4f280c6aefedce1e8f615baaa5474e0701d86dd6f1dede66726462bbd/pillow-11.3.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7966e38dcd0fa11ca390aed7c6f20454443581d758242023cf36fcb319b1a874", size = 6083789, upload-time = "2025-07-01T09:15:25.1Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/54/86b0cd9dbb683a9d5e960b66c7379e821a19be4ac5810e2e5a715c09a0c0/pillow-11.3.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:98a9afa7b9007c67ed84c57c9e0ad86a6000da96eaa638e4f8abe5b65ff83f0a", size = 6720386, upload-time = "2025-07-01T09:15:27.378Z" },
+ { url = "https://files.pythonhosted.org/packages/e7/95/88efcaf384c3588e24259c4203b909cbe3e3c2d887af9e938c2022c9dd48/pillow-11.3.0-cp314-cp314-win32.whl", hash = "sha256:02a723e6bf909e7cea0dac1b0e0310be9d7650cd66222a5f1c571455c0a45214", size = 6370911, upload-time = "2025-07-01T09:15:29.294Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/cc/934e5820850ec5eb107e7b1a72dd278140731c669f396110ebc326f2a503/pillow-11.3.0-cp314-cp314-win_amd64.whl", hash = "sha256:a418486160228f64dd9e9efcd132679b7a02a5f22c982c78b6fc7dab3fefb635", size = 7117383, upload-time = "2025-07-01T09:15:31.128Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/e9/9c0a616a71da2a5d163aa37405e8aced9a906d574b4a214bede134e731bc/pillow-11.3.0-cp314-cp314-win_arm64.whl", hash = "sha256:155658efb5e044669c08896c0c44231c5e9abcaadbc5cd3648df2f7c0b96b9a6", size = 2511385, upload-time = "2025-07-01T09:15:33.328Z" },
+ { url = "https://files.pythonhosted.org/packages/1a/33/c88376898aff369658b225262cd4f2659b13e8178e7534df9e6e1fa289f6/pillow-11.3.0-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:59a03cdf019efbfeeed910bf79c7c93255c3d54bc45898ac2a4140071b02b4ae", size = 5281129, upload-time = "2025-07-01T09:15:35.194Z" },
+ { url = "https://files.pythonhosted.org/packages/1f/70/d376247fb36f1844b42910911c83a02d5544ebd2a8bad9efcc0f707ea774/pillow-11.3.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:f8a5827f84d973d8636e9dc5764af4f0cf2318d26744b3d902931701b0d46653", size = 4689580, upload-time = "2025-07-01T09:15:37.114Z" },
+ { url = "https://files.pythonhosted.org/packages/eb/1c/537e930496149fbac69efd2fc4329035bbe2e5475b4165439e3be9cb183b/pillow-11.3.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ee92f2fd10f4adc4b43d07ec5e779932b4eb3dbfbc34790ada5a6669bc095aa6", size = 5902860, upload-time = "2025-07-03T13:10:50.248Z" },
+ { url = "https://files.pythonhosted.org/packages/bd/57/80f53264954dcefeebcf9dae6e3eb1daea1b488f0be8b8fef12f79a3eb10/pillow-11.3.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c96d333dcf42d01f47b37e0979b6bd73ec91eae18614864622d9b87bbd5bbf36", size = 7670694, upload-time = "2025-07-03T13:10:56.432Z" },
+ { url = "https://files.pythonhosted.org/packages/70/ff/4727d3b71a8578b4587d9c276e90efad2d6fe0335fd76742a6da08132e8c/pillow-11.3.0-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4c96f993ab8c98460cd0c001447bff6194403e8b1d7e149ade5f00594918128b", size = 6005888, upload-time = "2025-07-01T09:15:39.436Z" },
+ { url = "https://files.pythonhosted.org/packages/05/ae/716592277934f85d3be51d7256f3636672d7b1abfafdc42cf3f8cbd4b4c8/pillow-11.3.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:41342b64afeba938edb034d122b2dda5db2139b9a4af999729ba8818e0056477", size = 6670330, upload-time = "2025-07-01T09:15:41.269Z" },
+ { url = "https://files.pythonhosted.org/packages/e7/bb/7fe6cddcc8827b01b1a9766f5fdeb7418680744f9082035bdbabecf1d57f/pillow-11.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:068d9c39a2d1b358eb9f245ce7ab1b5c3246c7c8c7d9ba58cfa5b43146c06e50", size = 6114089, upload-time = "2025-07-01T09:15:43.13Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/f5/06bfaa444c8e80f1a8e4bff98da9c83b37b5be3b1deaa43d27a0db37ef84/pillow-11.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:a1bc6ba083b145187f648b667e05a2534ecc4b9f2784c2cbe3089e44868f2b9b", size = 6748206, upload-time = "2025-07-01T09:15:44.937Z" },
+ { url = "https://files.pythonhosted.org/packages/f0/77/bc6f92a3e8e6e46c0ca78abfffec0037845800ea38c73483760362804c41/pillow-11.3.0-cp314-cp314t-win32.whl", hash = "sha256:118ca10c0d60b06d006be10a501fd6bbdfef559251ed31b794668ed569c87e12", size = 6377370, upload-time = "2025-07-01T09:15:46.673Z" },
+ { url = "https://files.pythonhosted.org/packages/4a/82/3a721f7d69dca802befb8af08b7c79ebcab461007ce1c18bd91a5d5896f9/pillow-11.3.0-cp314-cp314t-win_amd64.whl", hash = "sha256:8924748b688aa210d79883357d102cd64690e56b923a186f35a82cbc10f997db", size = 7121500, upload-time = "2025-07-01T09:15:48.512Z" },
+ { url = "https://files.pythonhosted.org/packages/89/c7/5572fa4a3f45740eaab6ae86fcdf7195b55beac1371ac8c619d880cfe948/pillow-11.3.0-cp314-cp314t-win_arm64.whl", hash = "sha256:79ea0d14d3ebad43ec77ad5272e6ff9bba5b679ef73375ea760261207fa8e0aa", size = 2512835, upload-time = "2025-07-01T09:15:50.399Z" },
+]
+
+[[package]]
+name = "pinecone"
+version = "7.0.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "certifi" },
+ { name = "pinecone-plugin-interface" },
+ { name = "python-dateutil" },
+ { name = "typing-extensions" },
+ { name = "urllib3", marker = "python_full_version < '4.0'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bc/9d/07a7f2136ce04cabd21d69c057dc2915867082b0047e6873e424388d4475/pinecone-7.0.1.tar.gz", hash = "sha256:49ff7b0f5be4a2ddec5aaa709758a9f2df56baa58ad46507d081409e246a81ec", size = 207930, upload-time = "2025-05-21T19:39:01.218Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/81/88/896221e991077d353e61991b759f46d75f3b4298eb5a4aa6534c1371f4b0/pinecone-7.0.1-py3-none-any.whl", hash = "sha256:ce7b0dab3c9f7d81e75b24c13fcbca4a51371e08021faaecaf0cd9a45ca1be6c", size = 516590, upload-time = "2025-05-21T19:38:59.117Z" },
+]
+
+[[package]]
+name = "pinecone-plugin-interface"
+version = "0.0.7"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f4/fb/e8a4063264953ead9e2b24d9b390152c60f042c951c47f4592e9996e57ff/pinecone_plugin_interface-0.0.7.tar.gz", hash = "sha256:b8e6675e41847333aa13923cc44daa3f85676d7157324682dc1640588a982846", size = 3370, upload-time = "2024-06-05T01:57:52.093Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3b/1d/a21fdfcd6d022cb64cef5c2a29ee6691c6c103c4566b41646b080b7536a5/pinecone_plugin_interface-0.0.7-py3-none-any.whl", hash = "sha256:875857ad9c9fc8bbc074dbe780d187a2afd21f5bfe0f3b08601924a61ef1bba8", size = 6249, upload-time = "2024-06-05T01:57:50.583Z" },
+]
+
+[[package]]
+name = "platformdirs"
+version = "4.3.8"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/fe/8b/3c73abc9c759ecd3f1f7ceff6685840859e8070c4d947c93fae71f6a0bf2/platformdirs-4.3.8.tar.gz", hash = "sha256:3d512d96e16bcb959a814c9f348431070822a6496326a4be0911c40b5a74c2bc", size = 21362, upload-time = "2025-05-07T22:47:42.121Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/fe/39/979e8e21520d4e47a0bbe349e2713c0aac6f3d853d0e5b34d76206c439aa/platformdirs-4.3.8-py3-none-any.whl", hash = "sha256:ff7059bb7eb1179e2685604f4aaf157cfd9535242bd23742eadc3c13542139b4", size = 18567, upload-time = "2025-05-07T22:47:40.376Z" },
+]
+
+[[package]]
+name = "pluggy"
+version = "1.6.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
+]
+
+[[package]]
+name = "ply"
+version = "3.11"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e5/69/882ee5c9d017149285cab114ebeab373308ef0f874fcdac9beb90e0ac4da/ply-3.11.tar.gz", hash = "sha256:00c7c1aaa88358b9c765b6d3000c6eec0ba42abca5351b095321aef446081da3", size = 159130, upload-time = "2018-02-15T19:01:31.097Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a3/58/35da89ee790598a0700ea49b2a66594140f44dec458c07e8e3d4979137fc/ply-3.11-py2.py3-none-any.whl", hash = "sha256:096f9b8350b65ebd2fd1346b12452efe5b9607f7482813ffca50c22722a807ce", size = 49567, upload-time = "2018-02-15T19:01:27.172Z" },
+]
+
+[[package]]
+name = "portalocker"
+version = "3.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pywin32", marker = "sys_platform == 'win32'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/5e/77/65b857a69ed876e1951e88aaba60f5ce6120c33703f7cb61a3c894b8c1b6/portalocker-3.2.0.tar.gz", hash = "sha256:1f3002956a54a8c3730586c5c77bf18fae4149e07eaf1c29fc3faf4d5a3f89ac", size = 95644, upload-time = "2025-06-14T13:20:40.03Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4b/a6/38c8e2f318bf67d338f4d629e93b0b4b9af331f455f0390ea8ce4a099b26/portalocker-3.2.0-py3-none-any.whl", hash = "sha256:3cdc5f565312224bc570c49337bd21428bba0ef363bbcf58b9ef4a9f11779968", size = 22424, upload-time = "2025-06-14T13:20:38.083Z" },
+]
+
+[[package]]
+name = "prometheus-client"
+version = "0.22.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/5e/cf/40dde0a2be27cc1eb41e333d1a674a74ce8b8b0457269cc640fd42b07cf7/prometheus_client-0.22.1.tar.gz", hash = "sha256:190f1331e783cf21eb60bca559354e0a4d4378facecf78f5428c39b675d20d28", size = 69746, upload-time = "2025-06-02T14:29:01.152Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/32/ae/ec06af4fe3ee72d16973474f122541746196aaa16cea6f66d18b963c6177/prometheus_client-0.22.1-py3-none-any.whl", hash = "sha256:cca895342e308174341b2cbf99a56bef291fbc0ef7b9e5412a0f26d653ba7094", size = 58694, upload-time = "2025-06-02T14:29:00.068Z" },
+]
+
+[[package]]
+name = "prompt-toolkit"
+version = "3.0.51"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "wcwidth" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/bb/6e/9d084c929dfe9e3bfe0c6a47e31f78a25c54627d64a66e884a8bf5474f1c/prompt_toolkit-3.0.51.tar.gz", hash = "sha256:931a162e3b27fc90c86f1b48bb1fb2c528c2761475e57c9c06de13311c7b54ed", size = 428940, upload-time = "2025-04-15T09:18:47.731Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ce/4f/5249960887b1fbe561d9ff265496d170b55a735b76724f10ef19f9e40716/prompt_toolkit-3.0.51-py3-none-any.whl", hash = "sha256:52742911fde84e2d423e2f9a4cf1de7d7ac4e51958f648d9540e0fb8db077b07", size = 387810, upload-time = "2025-04-15T09:18:44.753Z" },
+]
+
+[[package]]
+name = "propcache"
+version = "0.3.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a6/16/43264e4a779dd8588c21a70f0709665ee8f611211bdd2c87d952cfa7c776/propcache-0.3.2.tar.gz", hash = "sha256:20d7d62e4e7ef05f221e0db2856b979540686342e7dd9973b815599c7057e168", size = 44139, upload-time = "2025-06-09T22:56:06.081Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a8/42/9ca01b0a6f48e81615dca4765a8f1dd2c057e0540f6116a27dc5ee01dfb6/propcache-0.3.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:8de106b6c84506b31c27168582cd3cb3000a6412c16df14a8628e5871ff83c10", size = 73674, upload-time = "2025-06-09T22:54:30.551Z" },
+ { url = "https://files.pythonhosted.org/packages/af/6e/21293133beb550f9c901bbece755d582bfaf2176bee4774000bd4dd41884/propcache-0.3.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:28710b0d3975117239c76600ea351934ac7b5ff56e60953474342608dbbb6154", size = 43570, upload-time = "2025-06-09T22:54:32.296Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/c8/0393a0a3a2b8760eb3bde3c147f62b20044f0ddac81e9d6ed7318ec0d852/propcache-0.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce26862344bdf836650ed2487c3d724b00fbfec4233a1013f597b78c1cb73615", size = 43094, upload-time = "2025-06-09T22:54:33.929Z" },
+ { url = "https://files.pythonhosted.org/packages/37/2c/489afe311a690399d04a3e03b069225670c1d489eb7b044a566511c1c498/propcache-0.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bca54bd347a253af2cf4544bbec232ab982f4868de0dd684246b67a51bc6b1db", size = 226958, upload-time = "2025-06-09T22:54:35.186Z" },
+ { url = "https://files.pythonhosted.org/packages/9d/ca/63b520d2f3d418c968bf596839ae26cf7f87bead026b6192d4da6a08c467/propcache-0.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:55780d5e9a2ddc59711d727226bb1ba83a22dd32f64ee15594b9392b1f544eb1", size = 234894, upload-time = "2025-06-09T22:54:36.708Z" },
+ { url = "https://files.pythonhosted.org/packages/11/60/1d0ed6fff455a028d678df30cc28dcee7af77fa2b0e6962ce1df95c9a2a9/propcache-0.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:035e631be25d6975ed87ab23153db6a73426a48db688070d925aa27e996fe93c", size = 233672, upload-time = "2025-06-09T22:54:38.062Z" },
+ { url = "https://files.pythonhosted.org/packages/37/7c/54fd5301ef38505ab235d98827207176a5c9b2aa61939b10a460ca53e123/propcache-0.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ee6f22b6eaa39297c751d0e80c0d3a454f112f5c6481214fcf4c092074cecd67", size = 224395, upload-time = "2025-06-09T22:54:39.634Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/1a/89a40e0846f5de05fdc6779883bf46ba980e6df4d2ff8fb02643de126592/propcache-0.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7ca3aee1aa955438c4dba34fc20a9f390e4c79967257d830f137bd5a8a32ed3b", size = 212510, upload-time = "2025-06-09T22:54:41.565Z" },
+ { url = "https://files.pythonhosted.org/packages/5e/33/ca98368586c9566a6b8d5ef66e30484f8da84c0aac3f2d9aec6d31a11bd5/propcache-0.3.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:7a4f30862869fa2b68380d677cc1c5fcf1e0f2b9ea0cf665812895c75d0ca3b8", size = 222949, upload-time = "2025-06-09T22:54:43.038Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/11/ace870d0aafe443b33b2f0b7efdb872b7c3abd505bfb4890716ad7865e9d/propcache-0.3.2-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:b77ec3c257d7816d9f3700013639db7491a434644c906a2578a11daf13176251", size = 217258, upload-time = "2025-06-09T22:54:44.376Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/d2/86fd6f7adffcfc74b42c10a6b7db721d1d9ca1055c45d39a1a8f2a740a21/propcache-0.3.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:cab90ac9d3f14b2d5050928483d3d3b8fb6b4018893fc75710e6aa361ecb2474", size = 213036, upload-time = "2025-06-09T22:54:46.243Z" },
+ { url = "https://files.pythonhosted.org/packages/07/94/2d7d1e328f45ff34a0a284cf5a2847013701e24c2a53117e7c280a4316b3/propcache-0.3.2-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:0b504d29f3c47cf6b9e936c1852246c83d450e8e063d50562115a6be6d3a2535", size = 227684, upload-time = "2025-06-09T22:54:47.63Z" },
+ { url = "https://files.pythonhosted.org/packages/b7/05/37ae63a0087677e90b1d14710e532ff104d44bc1efa3b3970fff99b891dc/propcache-0.3.2-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:ce2ac2675a6aa41ddb2a0c9cbff53780a617ac3d43e620f8fd77ba1c84dcfc06", size = 234562, upload-time = "2025-06-09T22:54:48.982Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/7c/3f539fcae630408d0bd8bf3208b9a647ccad10976eda62402a80adf8fc34/propcache-0.3.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:62b4239611205294cc433845b914131b2a1f03500ff3c1ed093ed216b82621e1", size = 222142, upload-time = "2025-06-09T22:54:50.424Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/d2/34b9eac8c35f79f8a962546b3e97e9d4b990c420ee66ac8255d5d9611648/propcache-0.3.2-cp312-cp312-win32.whl", hash = "sha256:df4a81b9b53449ebc90cc4deefb052c1dd934ba85012aa912c7ea7b7e38b60c1", size = 37711, upload-time = "2025-06-09T22:54:52.072Z" },
+ { url = "https://files.pythonhosted.org/packages/19/61/d582be5d226cf79071681d1b46b848d6cb03d7b70af7063e33a2787eaa03/propcache-0.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:7046e79b989d7fe457bb755844019e10f693752d169076138abf17f31380800c", size = 41479, upload-time = "2025-06-09T22:54:53.234Z" },
+ { url = "https://files.pythonhosted.org/packages/dc/d1/8c747fafa558c603c4ca19d8e20b288aa0c7cda74e9402f50f31eb65267e/propcache-0.3.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:ca592ed634a73ca002967458187109265e980422116c0a107cf93d81f95af945", size = 71286, upload-time = "2025-06-09T22:54:54.369Z" },
+ { url = "https://files.pythonhosted.org/packages/61/99/d606cb7986b60d89c36de8a85d58764323b3a5ff07770a99d8e993b3fa73/propcache-0.3.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:9ecb0aad4020e275652ba3975740f241bd12a61f1a784df044cf7477a02bc252", size = 42425, upload-time = "2025-06-09T22:54:55.642Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/96/ef98f91bbb42b79e9bb82bdd348b255eb9d65f14dbbe3b1594644c4073f7/propcache-0.3.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:7f08f1cc28bd2eade7a8a3d2954ccc673bb02062e3e7da09bc75d843386b342f", size = 41846, upload-time = "2025-06-09T22:54:57.246Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/ad/3f0f9a705fb630d175146cd7b1d2bf5555c9beaed54e94132b21aac098a6/propcache-0.3.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d1a342c834734edb4be5ecb1e9fb48cb64b1e2320fccbd8c54bf8da8f2a84c33", size = 208871, upload-time = "2025-06-09T22:54:58.975Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/38/2085cda93d2c8b6ec3e92af2c89489a36a5886b712a34ab25de9fbca7992/propcache-0.3.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8a544caaae1ac73f1fecfae70ded3e93728831affebd017d53449e3ac052ac1e", size = 215720, upload-time = "2025-06-09T22:55:00.471Z" },
+ { url = "https://files.pythonhosted.org/packages/61/c1/d72ea2dc83ac7f2c8e182786ab0fc2c7bd123a1ff9b7975bee671866fe5f/propcache-0.3.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:310d11aa44635298397db47a3ebce7db99a4cc4b9bbdfcf6c98a60c8d5261cf1", size = 215203, upload-time = "2025-06-09T22:55:01.834Z" },
+ { url = "https://files.pythonhosted.org/packages/af/81/b324c44ae60c56ef12007105f1460d5c304b0626ab0cc6b07c8f2a9aa0b8/propcache-0.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4c1396592321ac83157ac03a2023aa6cc4a3cc3cfdecb71090054c09e5a7cce3", size = 206365, upload-time = "2025-06-09T22:55:03.199Z" },
+ { url = "https://files.pythonhosted.org/packages/09/73/88549128bb89e66d2aff242488f62869014ae092db63ccea53c1cc75a81d/propcache-0.3.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8cabf5b5902272565e78197edb682017d21cf3b550ba0460ee473753f28d23c1", size = 196016, upload-time = "2025-06-09T22:55:04.518Z" },
+ { url = "https://files.pythonhosted.org/packages/b9/3f/3bdd14e737d145114a5eb83cb172903afba7242f67c5877f9909a20d948d/propcache-0.3.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:0a2f2235ac46a7aa25bdeb03a9e7060f6ecbd213b1f9101c43b3090ffb971ef6", size = 205596, upload-time = "2025-06-09T22:55:05.942Z" },
+ { url = "https://files.pythonhosted.org/packages/0f/ca/2f4aa819c357d3107c3763d7ef42c03980f9ed5c48c82e01e25945d437c1/propcache-0.3.2-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:92b69e12e34869a6970fd2f3da91669899994b47c98f5d430b781c26f1d9f387", size = 200977, upload-time = "2025-06-09T22:55:07.792Z" },
+ { url = "https://files.pythonhosted.org/packages/cd/4a/e65276c7477533c59085251ae88505caf6831c0e85ff8b2e31ebcbb949b1/propcache-0.3.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:54e02207c79968ebbdffc169591009f4474dde3b4679e16634d34c9363ff56b4", size = 197220, upload-time = "2025-06-09T22:55:09.173Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/54/fc7152e517cf5578278b242396ce4d4b36795423988ef39bb8cd5bf274c8/propcache-0.3.2-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:4adfb44cb588001f68c5466579d3f1157ca07f7504fc91ec87862e2b8e556b88", size = 210642, upload-time = "2025-06-09T22:55:10.62Z" },
+ { url = "https://files.pythonhosted.org/packages/b9/80/abeb4a896d2767bf5f1ea7b92eb7be6a5330645bd7fb844049c0e4045d9d/propcache-0.3.2-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:fd3e6019dc1261cd0291ee8919dd91fbab7b169bb76aeef6c716833a3f65d206", size = 212789, upload-time = "2025-06-09T22:55:12.029Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/db/ea12a49aa7b2b6d68a5da8293dcf50068d48d088100ac016ad92a6a780e6/propcache-0.3.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:4c181cad81158d71c41a2bce88edce078458e2dd5ffee7eddd6b05da85079f43", size = 205880, upload-time = "2025-06-09T22:55:13.45Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/e5/9076a0bbbfb65d1198007059c65639dfd56266cf8e477a9707e4b1999ff4/propcache-0.3.2-cp313-cp313-win32.whl", hash = "sha256:8a08154613f2249519e549de2330cf8e2071c2887309a7b07fb56098f5170a02", size = 37220, upload-time = "2025-06-09T22:55:15.284Z" },
+ { url = "https://files.pythonhosted.org/packages/d3/f5/b369e026b09a26cd77aa88d8fffd69141d2ae00a2abaaf5380d2603f4b7f/propcache-0.3.2-cp313-cp313-win_amd64.whl", hash = "sha256:e41671f1594fc4ab0a6dec1351864713cb3a279910ae8b58f884a88a0a632c05", size = 40678, upload-time = "2025-06-09T22:55:16.445Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/3a/6ece377b55544941a08d03581c7bc400a3c8cd3c2865900a68d5de79e21f/propcache-0.3.2-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:9a3cf035bbaf035f109987d9d55dc90e4b0e36e04bbbb95af3055ef17194057b", size = 76560, upload-time = "2025-06-09T22:55:17.598Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/da/64a2bb16418740fa634b0e9c3d29edff1db07f56d3546ca2d86ddf0305e1/propcache-0.3.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:156c03d07dc1323d8dacaa221fbe028c5c70d16709cdd63502778e6c3ccca1b0", size = 44676, upload-time = "2025-06-09T22:55:18.922Z" },
+ { url = "https://files.pythonhosted.org/packages/36/7b/f025e06ea51cb72c52fb87e9b395cced02786610b60a3ed51da8af017170/propcache-0.3.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:74413c0ba02ba86f55cf60d18daab219f7e531620c15f1e23d95563f505efe7e", size = 44701, upload-time = "2025-06-09T22:55:20.106Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/00/faa1b1b7c3b74fc277f8642f32a4c72ba1d7b2de36d7cdfb676db7f4303e/propcache-0.3.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f066b437bb3fa39c58ff97ab2ca351db465157d68ed0440abecb21715eb24b28", size = 276934, upload-time = "2025-06-09T22:55:21.5Z" },
+ { url = "https://files.pythonhosted.org/packages/74/ab/935beb6f1756e0476a4d5938ff44bf0d13a055fed880caf93859b4f1baf4/propcache-0.3.2-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f1304b085c83067914721e7e9d9917d41ad87696bf70f0bc7dee450e9c71ad0a", size = 278316, upload-time = "2025-06-09T22:55:22.918Z" },
+ { url = "https://files.pythonhosted.org/packages/f8/9d/994a5c1ce4389610838d1caec74bdf0e98b306c70314d46dbe4fcf21a3e2/propcache-0.3.2-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ab50cef01b372763a13333b4e54021bdcb291fc9a8e2ccb9c2df98be51bcde6c", size = 282619, upload-time = "2025-06-09T22:55:24.651Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/00/a10afce3d1ed0287cef2e09506d3be9822513f2c1e96457ee369adb9a6cd/propcache-0.3.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fad3b2a085ec259ad2c2842666b2a0a49dea8463579c606426128925af1ed725", size = 265896, upload-time = "2025-06-09T22:55:26.049Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/a8/2aa6716ffa566ca57c749edb909ad27884680887d68517e4be41b02299f3/propcache-0.3.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:261fa020c1c14deafd54c76b014956e2f86991af198c51139faf41c4d5e83892", size = 252111, upload-time = "2025-06-09T22:55:27.381Z" },
+ { url = "https://files.pythonhosted.org/packages/36/4f/345ca9183b85ac29c8694b0941f7484bf419c7f0fea2d1e386b4f7893eed/propcache-0.3.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:46d7f8aa79c927e5f987ee3a80205c987717d3659f035c85cf0c3680526bdb44", size = 268334, upload-time = "2025-06-09T22:55:28.747Z" },
+ { url = "https://files.pythonhosted.org/packages/3e/ca/fcd54f78b59e3f97b3b9715501e3147f5340167733d27db423aa321e7148/propcache-0.3.2-cp313-cp313t-musllinux_1_2_armv7l.whl", hash = "sha256:6d8f3f0eebf73e3c0ff0e7853f68be638b4043c65a70517bb575eff54edd8dbe", size = 255026, upload-time = "2025-06-09T22:55:30.184Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/95/8e6a6bbbd78ac89c30c225210a5c687790e532ba4088afb8c0445b77ef37/propcache-0.3.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:03c89c1b14a5452cf15403e291c0ccd7751d5b9736ecb2c5bab977ad6c5bcd81", size = 250724, upload-time = "2025-06-09T22:55:31.646Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/b0/0dd03616142baba28e8b2d14ce5df6631b4673850a3d4f9c0f9dd714a404/propcache-0.3.2-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:0cc17efde71e12bbaad086d679ce575268d70bc123a5a71ea7ad76f70ba30bba", size = 268868, upload-time = "2025-06-09T22:55:33.209Z" },
+ { url = "https://files.pythonhosted.org/packages/c5/98/2c12407a7e4fbacd94ddd32f3b1e3d5231e77c30ef7162b12a60e2dd5ce3/propcache-0.3.2-cp313-cp313t-musllinux_1_2_s390x.whl", hash = "sha256:acdf05d00696bc0447e278bb53cb04ca72354e562cf88ea6f9107df8e7fd9770", size = 271322, upload-time = "2025-06-09T22:55:35.065Z" },
+ { url = "https://files.pythonhosted.org/packages/35/91/9cb56efbb428b006bb85db28591e40b7736847b8331d43fe335acf95f6c8/propcache-0.3.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:4445542398bd0b5d32df908031cb1b30d43ac848e20470a878b770ec2dcc6330", size = 265778, upload-time = "2025-06-09T22:55:36.45Z" },
+ { url = "https://files.pythonhosted.org/packages/9a/4c/b0fe775a2bdd01e176b14b574be679d84fc83958335790f7c9a686c1f468/propcache-0.3.2-cp313-cp313t-win32.whl", hash = "sha256:f86e5d7cd03afb3a1db8e9f9f6eff15794e79e791350ac48a8c924e6f439f394", size = 41175, upload-time = "2025-06-09T22:55:38.436Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/ff/47f08595e3d9b5e149c150f88d9714574f1a7cbd89fe2817158a952674bf/propcache-0.3.2-cp313-cp313t-win_amd64.whl", hash = "sha256:9704bedf6e7cbe3c65eca4379a9b53ee6a83749f047808cbb5044d40d7d72198", size = 44857, upload-time = "2025-06-09T22:55:39.687Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/35/cc0aaecf278bb4575b8555f2b137de5ab821595ddae9da9d3cd1da4072c7/propcache-0.3.2-py3-none-any.whl", hash = "sha256:98f1ec44fb675f5052cccc8e609c46ed23a35a1cfd18545ad4e29002d858a43f", size = 12663, upload-time = "2025-06-09T22:56:04.484Z" },
+]
+
+[[package]]
+name = "proto-plus"
+version = "1.26.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "protobuf" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f4/ac/87285f15f7cce6d4a008f33f1757fb5a13611ea8914eb58c3d0d26243468/proto_plus-1.26.1.tar.gz", hash = "sha256:21a515a4c4c0088a773899e23c7bbade3d18f9c66c73edd4c7ee3816bc96a012", size = 56142, upload-time = "2025-03-10T15:54:38.843Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4e/6d/280c4c2ce28b1593a19ad5239c8b826871fc6ec275c21afc8e1820108039/proto_plus-1.26.1-py3-none-any.whl", hash = "sha256:13285478c2dcf2abb829db158e1047e2f1e8d63a077d94263c2b88b043c75a66", size = 50163, upload-time = "2025-03-10T15:54:37.335Z" },
+]
+
+[[package]]
+name = "protobuf"
+version = "4.25.8"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/df/01/34c8d2b6354906d728703cb9d546a0e534de479e25f1b581e4094c4a85cc/protobuf-4.25.8.tar.gz", hash = "sha256:6135cf8affe1fc6f76cced2641e4ea8d3e59518d1f24ae41ba97bcad82d397cd", size = 380920, upload-time = "2025-05-28T14:22:25.153Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/45/ff/05f34305fe6b85bbfbecbc559d423a5985605cad5eda4f47eae9e9c9c5c5/protobuf-4.25.8-cp310-abi3-win32.whl", hash = "sha256:504435d831565f7cfac9f0714440028907f1975e4bed228e58e72ecfff58a1e0", size = 392745, upload-time = "2025-05-28T14:22:10.524Z" },
+ { url = "https://files.pythonhosted.org/packages/08/35/8b8a8405c564caf4ba835b1fdf554da869954712b26d8f2a98c0e434469b/protobuf-4.25.8-cp310-abi3-win_amd64.whl", hash = "sha256:bd551eb1fe1d7e92c1af1d75bdfa572eff1ab0e5bf1736716814cdccdb2360f9", size = 413736, upload-time = "2025-05-28T14:22:13.156Z" },
+ { url = "https://files.pythonhosted.org/packages/28/d7/ab27049a035b258dab43445eb6ec84a26277b16105b277cbe0a7698bdc6c/protobuf-4.25.8-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:ca809b42f4444f144f2115c4c1a747b9a404d590f18f37e9402422033e464e0f", size = 394537, upload-time = "2025-05-28T14:22:14.768Z" },
+ { url = "https://files.pythonhosted.org/packages/bd/6d/a4a198b61808dd3d1ee187082ccc21499bc949d639feb948961b48be9a7e/protobuf-4.25.8-cp37-abi3-manylinux2014_aarch64.whl", hash = "sha256:9ad7ef62d92baf5a8654fbb88dac7fa5594cfa70fd3440488a5ca3bfc6d795a7", size = 294005, upload-time = "2025-05-28T14:22:16.052Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/c6/c9deaa6e789b6fc41b88ccbdfe7a42d2b82663248b715f55aa77fbc00724/protobuf-4.25.8-cp37-abi3-manylinux2014_x86_64.whl", hash = "sha256:83e6e54e93d2b696a92cad6e6efc924f3850f82b52e1563778dfab8b355101b0", size = 294924, upload-time = "2025-05-28T14:22:17.105Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/c1/6aece0ab5209981a70cd186f164c133fdba2f51e124ff92b73de7fd24d78/protobuf-4.25.8-py3-none-any.whl", hash = "sha256:15a0af558aa3b13efef102ae6e4f3efac06f1eea11afb3a57db2901447d9fb59", size = 156757, upload-time = "2025-05-28T14:22:24.135Z" },
+]
+
+[[package]]
+name = "psutil"
+version = "5.9.8"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/90/c7/6dc0a455d111f68ee43f27793971cf03fe29b6ef972042549db29eec39a2/psutil-5.9.8.tar.gz", hash = "sha256:6be126e3225486dff286a8fb9a06246a5253f4c7c53b475ea5f5ac934e64194c", size = 503247, upload-time = "2024-01-19T20:47:09.517Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e7/e3/07ae864a636d70a8a6f58da27cb1179192f1140d5d1da10886ade9405797/psutil-5.9.8-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:aee678c8720623dc456fa20659af736241f575d79429a0e5e9cf88ae0605cc81", size = 248702, upload-time = "2024-01-19T20:47:36.303Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/bd/28c5f553667116b2598b9cc55908ec435cb7f77a34f2bff3e3ca765b0f78/psutil-5.9.8-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8cb6403ce6d8e047495a701dc7c5bd788add903f8986d523e3e20b98b733e421", size = 285242, upload-time = "2024-01-19T20:47:39.65Z" },
+ { url = "https://files.pythonhosted.org/packages/c5/4f/0e22aaa246f96d6ac87fe5ebb9c5a693fbe8877f537a1022527c47ca43c5/psutil-5.9.8-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d06016f7f8625a1825ba3732081d77c94589dca78b7a3fc072194851e88461a4", size = 288191, upload-time = "2024-01-19T20:47:43.078Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/f5/2aa3a4acdc1e5940b59d421742356f133185667dd190b166dbcfcf5d7b43/psutil-5.9.8-cp37-abi3-win32.whl", hash = "sha256:bc56c2a1b0d15aa3eaa5a60c9f3f8e3e565303b465dbf57a1b730e7a2b9844e0", size = 251252, upload-time = "2024-01-19T20:47:52.88Z" },
+ { url = "https://files.pythonhosted.org/packages/93/52/3e39d26feae7df0aa0fd510b14012c3678b36ed068f7d78b8d8784d61f0e/psutil-5.9.8-cp37-abi3-win_amd64.whl", hash = "sha256:8db4c1b57507eef143a15a6884ca10f7c73876cdf5d51e713151c1236a0e68cf", size = 255090, upload-time = "2024-01-19T20:47:56.019Z" },
+ { url = "https://files.pythonhosted.org/packages/05/33/2d74d588408caedd065c2497bdb5ef83ce6082db01289a1e1147f6639802/psutil-5.9.8-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:d16bbddf0693323b8c6123dd804100241da461e41d6e332fb0ba6058f630f8c8", size = 249898, upload-time = "2024-01-19T20:47:59.238Z" },
+]
+
+[[package]]
+name = "psycopg2-binary"
+version = "2.9.9"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/fc/07/e720e53bfab016ebcc34241695ccc06a9e3d91ba19b40ca81317afbdc440/psycopg2-binary-2.9.9.tar.gz", hash = "sha256:7f01846810177d829c7692f1f5ada8096762d9172af1b1a28d4ab5b77c923c1c", size = 384973, upload-time = "2023-10-03T12:48:55.128Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a7/d0/5f2db14e7b53552276ab613399a83f83f85b173a862d3f20580bc7231139/psycopg2_binary-2.9.9-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:8532fd6e6e2dc57bcb3bc90b079c60de896d2128c5d9d6f24a63875a95a088cf", size = 2823784, upload-time = "2023-10-03T12:47:00.404Z" },
+ { url = "https://files.pythonhosted.org/packages/18/ca/da384fd47233e300e3e485c90e7aab5d7def896d1281239f75901faf87d4/psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:b0605eaed3eb239e87df0d5e3c6489daae3f7388d455d0c0b4df899519c6a38d", size = 2553308, upload-time = "2023-11-01T10:40:33.984Z" },
+ { url = "https://files.pythonhosted.org/packages/50/66/fa53d2d3d92f6e1ef469d92afc6a4fe3f6e8a9a04b687aa28fb1f1d954ee/psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f8544b092a29a6ddd72f3556a9fcf249ec412e10ad28be6a0c0d948924f2212", size = 2851283, upload-time = "2023-10-03T12:47:02.736Z" },
+ { url = "https://files.pythonhosted.org/packages/04/37/2429360ac5547378202db14eec0dde76edbe1f6627df5a43c7e164922859/psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2d423c8d8a3c82d08fe8af900ad5b613ce3632a1249fd6a223941d0735fce493", size = 3081839, upload-time = "2023-10-03T12:47:05.027Z" },
+ { url = "https://files.pythonhosted.org/packages/62/2a/c0530b59d7e0d09824bc2102ecdcec0456b8ca4d47c0caa82e86fce3ed4c/psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e5afae772c00980525f6d6ecf7cbca55676296b580c0e6abb407f15f3706996", size = 3264488, upload-time = "2023-10-03T12:47:08.962Z" },
+ { url = "https://files.pythonhosted.org/packages/19/57/9f172b900795ea37246c78b5f52e00f4779984370855b3e161600156906d/psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6e6f98446430fdf41bd36d4faa6cb409f5140c1c2cf58ce0bbdaf16af7d3f119", size = 3020700, upload-time = "2023-10-03T12:47:12.23Z" },
+ { url = "https://files.pythonhosted.org/packages/94/68/1176fc14ea76861b7b8360be5176e87fb20d5091b137c76570eb4e237324/psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:c77e3d1862452565875eb31bdb45ac62502feabbd53429fdc39a1cc341d681ba", size = 2355968, upload-time = "2023-10-03T12:47:14.817Z" },
+ { url = "https://files.pythonhosted.org/packages/70/bb/aec2646a705a09079d008ce88073401cd61fc9b04f92af3eb282caa3a2ec/psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:cb16c65dcb648d0a43a2521f2f0a2300f40639f6f8c1ecbc662141e4e3e1ee07", size = 2536101, upload-time = "2023-10-03T12:47:17.454Z" },
+ { url = "https://files.pythonhosted.org/packages/14/33/12818c157e333cb9d9e6753d1b2463b6f60dbc1fade115f8e4dc5c52cac4/psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:911dda9c487075abd54e644ccdf5e5c16773470a6a5d3826fda76699410066fb", size = 2487064, upload-time = "2023-10-03T12:47:20.717Z" },
+ { url = "https://files.pythonhosted.org/packages/56/a2/7851c68fe8768f3c9c246198b6356ee3e4a8a7f6820cc798443faada3400/psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:57fede879f08d23c85140a360c6a77709113efd1c993923c59fde17aa27599fe", size = 2456257, upload-time = "2023-10-03T12:47:23.004Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/ee/3ba07c6dc7c3294e717e94720da1597aedc82a10b1b180203ce183d4631a/psycopg2_binary-2.9.9-cp312-cp312-win32.whl", hash = "sha256:64cf30263844fa208851ebb13b0732ce674d8ec6a0c86a4e160495d299ba3c93", size = 1024709, upload-time = "2023-10-28T09:37:24.991Z" },
+ { url = "https://files.pythonhosted.org/packages/7b/08/9c66c269b0d417a0af9fb969535f0371b8c538633535a7a6a5ca3f9231e2/psycopg2_binary-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:81ff62668af011f9a48787564ab7eded4e9fb17a4a6a74af5ffa6a457400d2ab", size = 1163864, upload-time = "2023-10-28T09:37:28.155Z" },
+]
+
+[[package]]
+name = "pyarrow"
+version = "18.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/7f/7b/640785a9062bb00314caa8a387abce547d2a420cf09bd6c715fe659ccffb/pyarrow-18.1.0.tar.gz", hash = "sha256:9386d3ca9c145b5539a1cfc75df07757dff870168c959b473a0bccbc3abc8c73", size = 1118671, upload-time = "2024-11-26T02:01:48.62Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6a/50/12829e7111b932581e51dda51d5cb39207a056c30fe31ef43f14c63c4d7e/pyarrow-18.1.0-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:9f3a76670b263dc41d0ae877f09124ab96ce10e4e48f3e3e4257273cee61ad0d", size = 29514620, upload-time = "2024-11-26T01:59:39.797Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/41/468c944eab157702e96abab3d07b48b8424927d4933541ab43788bb6964d/pyarrow-18.1.0-cp312-cp312-macosx_12_0_x86_64.whl", hash = "sha256:da31fbca07c435be88a0c321402c4e31a2ba61593ec7473630769de8346b54ee", size = 30856494, upload-time = "2024-11-26T01:59:44.725Z" },
+ { url = "https://files.pythonhosted.org/packages/68/f9/29fb659b390312a7345aeb858a9d9c157552a8852522f2c8bad437c29c0a/pyarrow-18.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:543ad8459bc438efc46d29a759e1079436290bd583141384c6f7a1068ed6f992", size = 39203624, upload-time = "2024-11-26T01:59:49.189Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/f6/19360dae44200e35753c5c2889dc478154cd78e61b1f738514c9f131734d/pyarrow-18.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0743e503c55be0fdb5c08e7d44853da27f19dc854531c0570f9f394ec9671d54", size = 40139341, upload-time = "2024-11-26T01:59:54.849Z" },
+ { url = "https://files.pythonhosted.org/packages/bb/e6/9b3afbbcf10cc724312e824af94a2e993d8ace22994d823f5c35324cebf5/pyarrow-18.1.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:d4b3d2a34780645bed6414e22dda55a92e0fcd1b8a637fba86800ad737057e33", size = 38618629, upload-time = "2024-11-26T01:59:59.966Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/2e/3b99f8a3d9e0ccae0e961978a0d0089b25fb46ebbcfb5ebae3cca179a5b3/pyarrow-18.1.0-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:c52f81aa6f6575058d8e2c782bf79d4f9fdc89887f16825ec3a66607a5dd8e30", size = 40078661, upload-time = "2024-11-26T02:00:04.55Z" },
+ { url = "https://files.pythonhosted.org/packages/76/52/f8da04195000099d394012b8d42c503d7041b79f778d854f410e5f05049a/pyarrow-18.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:0ad4892617e1a6c7a551cfc827e072a633eaff758fa09f21c4ee548c30bcaf99", size = 25092330, upload-time = "2024-11-26T02:00:09.576Z" },
+ { url = "https://files.pythonhosted.org/packages/cb/87/aa4d249732edef6ad88899399047d7e49311a55749d3c373007d034ee471/pyarrow-18.1.0-cp313-cp313-macosx_12_0_arm64.whl", hash = "sha256:84e314d22231357d473eabec709d0ba285fa706a72377f9cc8e1cb3c8013813b", size = 29497406, upload-time = "2024-11-26T02:00:14.469Z" },
+ { url = "https://files.pythonhosted.org/packages/3c/c7/ed6adb46d93a3177540e228b5ca30d99fc8ea3b13bdb88b6f8b6467e2cb7/pyarrow-18.1.0-cp313-cp313-macosx_12_0_x86_64.whl", hash = "sha256:f591704ac05dfd0477bb8f8e0bd4b5dc52c1cadf50503858dce3a15db6e46ff2", size = 30835095, upload-time = "2024-11-26T02:00:19.347Z" },
+ { url = "https://files.pythonhosted.org/packages/41/d7/ed85001edfb96200ff606943cff71d64f91926ab42828676c0fc0db98963/pyarrow-18.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:acb7564204d3c40babf93a05624fc6a8ec1ab1def295c363afc40b0c9e66c191", size = 39194527, upload-time = "2024-11-26T02:00:24.085Z" },
+ { url = "https://files.pythonhosted.org/packages/59/16/35e28eab126342fa391593415d79477e89582de411bb95232f28b131a769/pyarrow-18.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:74de649d1d2ccb778f7c3afff6085bd5092aed4c23df9feeb45dd6b16f3811aa", size = 40131443, upload-time = "2024-11-26T02:00:29.483Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/95/e855880614c8da20f4cd74fa85d7268c725cf0013dc754048593a38896a0/pyarrow-18.1.0-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:f96bd502cb11abb08efea6dab09c003305161cb6c9eafd432e35e76e7fa9b90c", size = 38608750, upload-time = "2024-11-26T02:00:34.069Z" },
+ { url = "https://files.pythonhosted.org/packages/54/9d/f253554b1457d4fdb3831b7bd5f8f00f1795585a606eabf6fec0a58a9c38/pyarrow-18.1.0-cp313-cp313-manylinux_2_28_x86_64.whl", hash = "sha256:36ac22d7782554754a3b50201b607d553a8d71b78cdf03b33c1125be4b52397c", size = 40066690, upload-time = "2024-11-26T02:00:39.603Z" },
+ { url = "https://files.pythonhosted.org/packages/2f/58/8912a2563e6b8273e8aa7b605a345bba5a06204549826f6493065575ebc0/pyarrow-18.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:25dbacab8c5952df0ca6ca0af28f50d45bd31c1ff6fcf79e2d120b4a65ee7181", size = 25081054, upload-time = "2024-11-26T02:00:43.611Z" },
+ { url = "https://files.pythonhosted.org/packages/82/f9/d06ddc06cab1ada0c2f2fd205ac8c25c2701182de1b9c4bf7a0a44844431/pyarrow-18.1.0-cp313-cp313t-macosx_12_0_arm64.whl", hash = "sha256:6a276190309aba7bc9d5bd2933230458b3521a4317acfefe69a354f2fe59f2bc", size = 29525542, upload-time = "2024-11-26T02:00:48.094Z" },
+ { url = "https://files.pythonhosted.org/packages/ab/94/8917e3b961810587ecbdaa417f8ebac0abb25105ae667b7aa11c05876976/pyarrow-18.1.0-cp313-cp313t-macosx_12_0_x86_64.whl", hash = "sha256:ad514dbfcffe30124ce655d72771ae070f30bf850b48bc4d9d3b25993ee0e386", size = 30829412, upload-time = "2024-11-26T02:00:52.458Z" },
+ { url = "https://files.pythonhosted.org/packages/5e/e3/3b16c3190f3d71d3b10f6758d2d5f7779ef008c4fd367cedab3ed178a9f7/pyarrow-18.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aebc13a11ed3032d8dd6e7171eb6e86d40d67a5639d96c35142bd568b9299324", size = 39119106, upload-time = "2024-11-26T02:00:57.219Z" },
+ { url = "https://files.pythonhosted.org/packages/1d/d6/5d704b0d25c3c79532f8c0639f253ec2803b897100f64bcb3f53ced236e5/pyarrow-18.1.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d6cf5c05f3cee251d80e98726b5c7cc9f21bab9e9783673bac58e6dfab57ecc8", size = 40090940, upload-time = "2024-11-26T02:01:02.31Z" },
+ { url = "https://files.pythonhosted.org/packages/37/29/366bc7e588220d74ec00e497ac6710c2833c9176f0372fe0286929b2d64c/pyarrow-18.1.0-cp313-cp313t-manylinux_2_28_aarch64.whl", hash = "sha256:11b676cd410cf162d3f6a70b43fb9e1e40affbc542a1e9ed3681895f2962d3d9", size = 38548177, upload-time = "2024-11-26T02:01:07.371Z" },
+ { url = "https://files.pythonhosted.org/packages/c8/11/fabf6ecabb1fe5b7d96889228ca2a9158c4c3bb732e3b8ee3f7f6d40b703/pyarrow-18.1.0-cp313-cp313t-manylinux_2_28_x86_64.whl", hash = "sha256:b76130d835261b38f14fc41fdfb39ad8d672afb84c447126b84d5472244cfaba", size = 40043567, upload-time = "2024-11-26T02:01:12.931Z" },
+]
+
+[[package]]
+name = "pyasn1"
+version = "0.6.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ba/e9/01f1a64245b89f039897cb0130016d79f77d52669aae6ee7b159a6c4c018/pyasn1-0.6.1.tar.gz", hash = "sha256:6f580d2bdd84365380830acf45550f2511469f673cb4a5ae3857a3170128b034", size = 145322, upload-time = "2024-09-10T22:41:42.55Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c8/f1/d6a797abb14f6283c0ddff96bbdd46937f64122b8c925cab503dd37f8214/pyasn1-0.6.1-py3-none-any.whl", hash = "sha256:0d632f46f2ba09143da3a8afe9e33fb6f92fa2320ab7e886e2d0f7672af84629", size = 83135, upload-time = "2024-09-11T16:00:36.122Z" },
+]
+
+[[package]]
+name = "pyasn1-modules"
+version = "0.4.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pyasn1" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e9/e6/78ebbb10a8c8e4b61a59249394a4a594c1a7af95593dc933a349c8d00964/pyasn1_modules-0.4.2.tar.gz", hash = "sha256:677091de870a80aae844b1ca6134f54652fa2c8c5a52aa396440ac3106e941e6", size = 307892, upload-time = "2025-03-28T02:41:22.17Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/47/8d/d529b5d697919ba8c11ad626e835d4039be708a35b0d22de83a269a6682c/pyasn1_modules-0.4.2-py3-none-any.whl", hash = "sha256:29253a9207ce32b64c3ac6600edc75368f98473906e8fd1043bd6b5b1de2c14a", size = 181259, upload-time = "2025-03-28T02:41:19.028Z" },
+]
+
+[[package]]
+name = "pycodestyle"
+version = "2.14.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/11/e0/abfd2a0d2efe47670df87f3e3a0e2edda42f055053c85361f19c0e2c1ca8/pycodestyle-2.14.0.tar.gz", hash = "sha256:c4b5b517d278089ff9d0abdec919cd97262a3367449ea1c8b49b91529167b783", size = 39472, upload-time = "2025-06-20T18:49:48.75Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d7/27/a58ddaf8c588a3ef080db9d0b7e0b97215cee3a45df74f3a94dbbf5c893a/pycodestyle-2.14.0-py2.py3-none-any.whl", hash = "sha256:dd6bf7cb4ee77f8e016f9c8e74a35ddd9f67e1d5fd4184d86c3b98e07099f42d", size = 31594, upload-time = "2025-06-20T18:49:47.491Z" },
+]
+
+[[package]]
+name = "pycparser"
+version = "2.22"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/1d/b2/31537cf4b1ca988837256c910a668b553fceb8f069bedc4b1c826024b52c/pycparser-2.22.tar.gz", hash = "sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6", size = 172736, upload-time = "2024-03-30T13:22:22.564Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl", hash = "sha256:c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc", size = 117552, upload-time = "2024-03-30T13:22:20.476Z" },
+]
+
+[[package]]
+name = "pydantic"
+version = "2.11.7"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "annotated-types" },
+ { name = "pydantic-core" },
+ { name = "typing-extensions" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/00/dd/4325abf92c39ba8623b5af936ddb36ffcfe0beae70405d456ab1fb2f5b8c/pydantic-2.11.7.tar.gz", hash = "sha256:d989c3c6cb79469287b1569f7447a17848c998458d49ebe294e975b9baf0f0db", size = 788350, upload-time = "2025-06-14T08:33:17.137Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6a/c0/ec2b1c8712ca690e5d61979dee872603e92b8a32f94cc1b72d53beab008a/pydantic-2.11.7-py3-none-any.whl", hash = "sha256:dde5df002701f6de26248661f6835bbe296a47bf73990135c7d07ce741b9623b", size = 444782, upload-time = "2025-06-14T08:33:14.905Z" },
+]
+
+[[package]]
+name = "pydantic-core"
+version = "2.33.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ad/88/5f2260bdfae97aabf98f1778d43f69574390ad787afb646292a638c923d4/pydantic_core-2.33.2.tar.gz", hash = "sha256:7cb8bc3605c29176e1b105350d2e6474142d7c1bd1d9327c4a9bdb46bf827acc", size = 435195, upload-time = "2025-04-23T18:33:52.104Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/18/8a/2b41c97f554ec8c71f2a8a5f85cb56a8b0956addfe8b0efb5b3d77e8bdc3/pydantic_core-2.33.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:a7ec89dc587667f22b6a0b6579c249fca9026ce7c333fc142ba42411fa243cdc", size = 2009000, upload-time = "2025-04-23T18:31:25.863Z" },
+ { url = "https://files.pythonhosted.org/packages/a1/02/6224312aacb3c8ecbaa959897af57181fb6cf3a3d7917fd44d0f2917e6f2/pydantic_core-2.33.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:3c6db6e52c6d70aa0d00d45cdb9b40f0433b96380071ea80b09277dba021ddf7", size = 1847996, upload-time = "2025-04-23T18:31:27.341Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/46/6dcdf084a523dbe0a0be59d054734b86a981726f221f4562aed313dbcb49/pydantic_core-2.33.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e61206137cbc65e6d5256e1166f88331d3b6238e082d9f74613b9b765fb9025", size = 1880957, upload-time = "2025-04-23T18:31:28.956Z" },
+ { url = "https://files.pythonhosted.org/packages/ec/6b/1ec2c03837ac00886ba8160ce041ce4e325b41d06a034adbef11339ae422/pydantic_core-2.33.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eb8c529b2819c37140eb51b914153063d27ed88e3bdc31b71198a198e921e011", size = 1964199, upload-time = "2025-04-23T18:31:31.025Z" },
+ { url = "https://files.pythonhosted.org/packages/2d/1d/6bf34d6adb9debd9136bd197ca72642203ce9aaaa85cfcbfcf20f9696e83/pydantic_core-2.33.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c52b02ad8b4e2cf14ca7b3d918f3eb0ee91e63b3167c32591e57c4317e134f8f", size = 2120296, upload-time = "2025-04-23T18:31:32.514Z" },
+ { url = "https://files.pythonhosted.org/packages/e0/94/2bd0aaf5a591e974b32a9f7123f16637776c304471a0ab33cf263cf5591a/pydantic_core-2.33.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:96081f1605125ba0855dfda83f6f3df5ec90c61195421ba72223de35ccfb2f88", size = 2676109, upload-time = "2025-04-23T18:31:33.958Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/41/4b043778cf9c4285d59742281a769eac371b9e47e35f98ad321349cc5d61/pydantic_core-2.33.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f57a69461af2a5fa6e6bbd7a5f60d3b7e6cebb687f55106933188e79ad155c1", size = 2002028, upload-time = "2025-04-23T18:31:39.095Z" },
+ { url = "https://files.pythonhosted.org/packages/cb/d5/7bb781bf2748ce3d03af04d5c969fa1308880e1dca35a9bd94e1a96a922e/pydantic_core-2.33.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:572c7e6c8bb4774d2ac88929e3d1f12bc45714ae5ee6d9a788a9fb35e60bb04b", size = 2100044, upload-time = "2025-04-23T18:31:41.034Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/36/def5e53e1eb0ad896785702a5bbfd25eed546cdcf4087ad285021a90ed53/pydantic_core-2.33.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:db4b41f9bd95fbe5acd76d89920336ba96f03e149097365afe1cb092fceb89a1", size = 2058881, upload-time = "2025-04-23T18:31:42.757Z" },
+ { url = "https://files.pythonhosted.org/packages/01/6c/57f8d70b2ee57fc3dc8b9610315949837fa8c11d86927b9bb044f8705419/pydantic_core-2.33.2-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:fa854f5cf7e33842a892e5c73f45327760bc7bc516339fda888c75ae60edaeb6", size = 2227034, upload-time = "2025-04-23T18:31:44.304Z" },
+ { url = "https://files.pythonhosted.org/packages/27/b9/9c17f0396a82b3d5cbea4c24d742083422639e7bb1d5bf600e12cb176a13/pydantic_core-2.33.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:5f483cfb75ff703095c59e365360cb73e00185e01aaea067cd19acffd2ab20ea", size = 2234187, upload-time = "2025-04-23T18:31:45.891Z" },
+ { url = "https://files.pythonhosted.org/packages/b0/6a/adf5734ffd52bf86d865093ad70b2ce543415e0e356f6cacabbc0d9ad910/pydantic_core-2.33.2-cp312-cp312-win32.whl", hash = "sha256:9cb1da0f5a471435a7bc7e439b8a728e8b61e59784b2af70d7c169f8dd8ae290", size = 1892628, upload-time = "2025-04-23T18:31:47.819Z" },
+ { url = "https://files.pythonhosted.org/packages/43/e4/5479fecb3606c1368d496a825d8411e126133c41224c1e7238be58b87d7e/pydantic_core-2.33.2-cp312-cp312-win_amd64.whl", hash = "sha256:f941635f2a3d96b2973e867144fde513665c87f13fe0e193c158ac51bfaaa7b2", size = 1955866, upload-time = "2025-04-23T18:31:49.635Z" },
+ { url = "https://files.pythonhosted.org/packages/0d/24/8b11e8b3e2be9dd82df4b11408a67c61bb4dc4f8e11b5b0fc888b38118b5/pydantic_core-2.33.2-cp312-cp312-win_arm64.whl", hash = "sha256:cca3868ddfaccfbc4bfb1d608e2ccaaebe0ae628e1416aeb9c4d88c001bb45ab", size = 1888894, upload-time = "2025-04-23T18:31:51.609Z" },
+ { url = "https://files.pythonhosted.org/packages/46/8c/99040727b41f56616573a28771b1bfa08a3d3fe74d3d513f01251f79f172/pydantic_core-2.33.2-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:1082dd3e2d7109ad8b7da48e1d4710c8d06c253cbc4a27c1cff4fbcaa97a9e3f", size = 2015688, upload-time = "2025-04-23T18:31:53.175Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/cc/5999d1eb705a6cefc31f0b4a90e9f7fc400539b1a1030529700cc1b51838/pydantic_core-2.33.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f517ca031dfc037a9c07e748cefd8d96235088b83b4f4ba8939105d20fa1dcd6", size = 1844808, upload-time = "2025-04-23T18:31:54.79Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/5e/a0a7b8885c98889a18b6e376f344da1ef323d270b44edf8174d6bce4d622/pydantic_core-2.33.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0a9f2c9dd19656823cb8250b0724ee9c60a82f3cdf68a080979d13092a3b0fef", size = 1885580, upload-time = "2025-04-23T18:31:57.393Z" },
+ { url = "https://files.pythonhosted.org/packages/3b/2a/953581f343c7d11a304581156618c3f592435523dd9d79865903272c256a/pydantic_core-2.33.2-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2b0a451c263b01acebe51895bfb0e1cc842a5c666efe06cdf13846c7418caa9a", size = 1973859, upload-time = "2025-04-23T18:31:59.065Z" },
+ { url = "https://files.pythonhosted.org/packages/e6/55/f1a813904771c03a3f97f676c62cca0c0a4138654107c1b61f19c644868b/pydantic_core-2.33.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1ea40a64d23faa25e62a70ad163571c0b342b8bf66d5fa612ac0dec4f069d916", size = 2120810, upload-time = "2025-04-23T18:32:00.78Z" },
+ { url = "https://files.pythonhosted.org/packages/aa/c3/053389835a996e18853ba107a63caae0b9deb4a276c6b472931ea9ae6e48/pydantic_core-2.33.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0fb2d542b4d66f9470e8065c5469ec676978d625a8b7a363f07d9a501a9cb36a", size = 2676498, upload-time = "2025-04-23T18:32:02.418Z" },
+ { url = "https://files.pythonhosted.org/packages/eb/3c/f4abd740877a35abade05e437245b192f9d0ffb48bbbbd708df33d3cda37/pydantic_core-2.33.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9fdac5d6ffa1b5a83bca06ffe7583f5576555e6c8b3a91fbd25ea7780f825f7d", size = 2000611, upload-time = "2025-04-23T18:32:04.152Z" },
+ { url = "https://files.pythonhosted.org/packages/59/a7/63ef2fed1837d1121a894d0ce88439fe3e3b3e48c7543b2a4479eb99c2bd/pydantic_core-2.33.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:04a1a413977ab517154eebb2d326da71638271477d6ad87a769102f7c2488c56", size = 2107924, upload-time = "2025-04-23T18:32:06.129Z" },
+ { url = "https://files.pythonhosted.org/packages/04/8f/2551964ef045669801675f1cfc3b0d74147f4901c3ffa42be2ddb1f0efc4/pydantic_core-2.33.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:c8e7af2f4e0194c22b5b37205bfb293d166a7344a5b0d0eaccebc376546d77d5", size = 2063196, upload-time = "2025-04-23T18:32:08.178Z" },
+ { url = "https://files.pythonhosted.org/packages/26/bd/d9602777e77fc6dbb0c7db9ad356e9a985825547dce5ad1d30ee04903918/pydantic_core-2.33.2-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:5c92edd15cd58b3c2d34873597a1e20f13094f59cf88068adb18947df5455b4e", size = 2236389, upload-time = "2025-04-23T18:32:10.242Z" },
+ { url = "https://files.pythonhosted.org/packages/42/db/0e950daa7e2230423ab342ae918a794964b053bec24ba8af013fc7c94846/pydantic_core-2.33.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:65132b7b4a1c0beded5e057324b7e16e10910c106d43675d9bd87d4f38dde162", size = 2239223, upload-time = "2025-04-23T18:32:12.382Z" },
+ { url = "https://files.pythonhosted.org/packages/58/4d/4f937099c545a8a17eb52cb67fe0447fd9a373b348ccfa9a87f141eeb00f/pydantic_core-2.33.2-cp313-cp313-win32.whl", hash = "sha256:52fb90784e0a242bb96ec53f42196a17278855b0f31ac7c3cc6f5c1ec4811849", size = 1900473, upload-time = "2025-04-23T18:32:14.034Z" },
+ { url = "https://files.pythonhosted.org/packages/a0/75/4a0a9bac998d78d889def5e4ef2b065acba8cae8c93696906c3a91f310ca/pydantic_core-2.33.2-cp313-cp313-win_amd64.whl", hash = "sha256:c083a3bdd5a93dfe480f1125926afcdbf2917ae714bdb80b36d34318b2bec5d9", size = 1955269, upload-time = "2025-04-23T18:32:15.783Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/86/1beda0576969592f1497b4ce8e7bc8cbdf614c352426271b1b10d5f0aa64/pydantic_core-2.33.2-cp313-cp313-win_arm64.whl", hash = "sha256:e80b087132752f6b3d714f041ccf74403799d3b23a72722ea2e6ba2e892555b9", size = 1893921, upload-time = "2025-04-23T18:32:18.473Z" },
+ { url = "https://files.pythonhosted.org/packages/a4/7d/e09391c2eebeab681df2b74bfe6c43422fffede8dc74187b2b0bf6fd7571/pydantic_core-2.33.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:61c18fba8e5e9db3ab908620af374db0ac1baa69f0f32df4f61ae23f15e586ac", size = 1806162, upload-time = "2025-04-23T18:32:20.188Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/3d/847b6b1fed9f8ed3bb95a9ad04fbd0b212e832d4f0f50ff4d9ee5a9f15cf/pydantic_core-2.33.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:95237e53bb015f67b63c91af7518a62a8660376a6a0db19b89acc77a4d6199f5", size = 1981560, upload-time = "2025-04-23T18:32:22.354Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/9a/e73262f6c6656262b5fdd723ad90f518f579b7bc8622e43a942eec53c938/pydantic_core-2.33.2-cp313-cp313t-win_amd64.whl", hash = "sha256:c2fc0a768ef76c15ab9238afa6da7f69895bb5d1ee83aeea2e3509af4472d0b9", size = 1935777, upload-time = "2025-04-23T18:32:25.088Z" },
+]
+
+[[package]]
+name = "pydrive2"
+version = "1.15.4"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "google-api-python-client" },
+ { name = "oauth2client" },
+ { name = "pyopenssl" },
+ { name = "pyyaml" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/45/74/b591079fa588351cec61861b85ba26f7deb96f3b445556c100e17db5572b/PyDrive2-1.15.4.tar.gz", hash = "sha256:0c011b74ebc24f3c6ca72820626b77f1dfe0ae88f5740c5a5cf96e83dd79ba99", size = 60514, upload-time = "2023-05-21T02:25:57.217Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/18/f4/d0b40ee1c703304e8cc737e53516f834c0fbad4fe9b27aed7680d9fdf344/PyDrive2-1.15.4-py3-none-any.whl", hash = "sha256:91fe28e5f094a6dfff834495c4aee0041cbef979467ad27cd0d4b1f91afa8869", size = 45011, upload-time = "2023-05-21T02:25:55.265Z" },
+]
+
+[package.optional-dependencies]
+fsspec = [
+ { name = "appdirs" },
+ { name = "fsspec" },
+ { name = "funcy" },
+ { name = "tqdm" },
+]
+
+[[package]]
+name = "pyflakes"
+version = "3.4.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/45/dc/fd034dc20b4b264b3d015808458391acbf9df40b1e54750ef175d39180b1/pyflakes-3.4.0.tar.gz", hash = "sha256:b24f96fafb7d2ab0ec5075b7350b3d2d2218eab42003821c06344973d3ea2f58", size = 64669, upload-time = "2025-06-20T18:45:27.834Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c2/2f/81d580a0fb83baeb066698975cb14a618bdbed7720678566f1b046a95fe8/pyflakes-3.4.0-py2.py3-none-any.whl", hash = "sha256:f742a7dbd0d9cb9ea41e9a24a918996e8170c799fa528688d40dd582c8265f4f", size = 63551, upload-time = "2025-06-20T18:45:26.937Z" },
+]
+
+[[package]]
+name = "pygments"
+version = "2.19.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/b0/77/a5b8c569bf593b0140bde72ea885a803b82086995367bf2037de0159d924/pygments-2.19.2.tar.gz", hash = "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887", size = 4968631, upload-time = "2025-06-21T13:39:12.283Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c7/21/705964c7812476f378728bdf590ca4b771ec72385c533964653c68e86bdc/pygments-2.19.2-py3-none-any.whl", hash = "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b", size = 1225217, upload-time = "2025-06-21T13:39:07.939Z" },
+]
+
+[[package]]
+name = "pyjwt"
+version = "2.10.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e7/46/bd74733ff231675599650d3e47f361794b22ef3e3770998dda30d3b63726/pyjwt-2.10.1.tar.gz", hash = "sha256:3cc5772eb20009233caf06e9d8a0577824723b44e6648ee0a2aedb6cf9381953", size = 87785, upload-time = "2024-11-28T03:43:29.933Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/61/ad/689f02752eeec26aed679477e80e632ef1b682313be70793d798c1d5fc8f/PyJWT-2.10.1-py3-none-any.whl", hash = "sha256:dcdd193e30abefd5debf142f9adfcdd2b58004e644f25406ffaebd50bd98dacb", size = 22997, upload-time = "2024-11-28T03:43:27.893Z" },
+]
+
+[package.optional-dependencies]
+crypto = [
+ { name = "cryptography" },
+]
+
+[[package]]
+name = "pymilvus"
+version = "2.5.15"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "grpcio" },
+ { name = "milvus-lite", marker = "sys_platform != 'win32'" },
+ { name = "pandas" },
+ { name = "protobuf" },
+ { name = "python-dotenv" },
+ { name = "setuptools" },
+ { name = "ujson" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/cd/f9/dee7f0d42979bf4cbe0bf23f8db9bf4c331b53c4c9f8692d2e027073c928/pymilvus-2.5.15.tar.gz", hash = "sha256:350396ef3bb40aa62c8a2ecaccb5c664bbb1569eef8593b74dd1d5125eb0deb2", size = 1278109, upload-time = "2025-08-21T11:57:58.416Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2e/af/10a620686025e5b59889d7075f5d426e45e57a0180c4465051645a88ccb0/pymilvus-2.5.15-py3-none-any.whl", hash = "sha256:a155a3b436e2e3ca4b85aac80c92733afe0bd172c497c3bc0dfaca0b804b90c9", size = 241683, upload-time = "2025-08-21T11:57:56.663Z" },
+]
+
+[[package]]
+name = "pymssql"
+version = "2.3.4"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/83/35/5a0b79369e42fffd5c04e4e74fa90ef034cc5c3f314e14f6d58cac646ccf/pymssql-2.3.4.tar.gz", hash = "sha256:117c82d7aa9021171aa9be98368475519f33d9c32073cdcf9b0d76231abc6436", size = 184604, upload-time = "2025-04-02T02:08:43.503Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bc/89/5a7a4b27ee44b2dc4708de7e897311cb17f15e7c983c299e8bf97ebf98d1/pymssql-2.3.4-cp312-cp312-macosx_13_0_universal2.whl", hash = "sha256:809b75aaeb9bcd061230bace41e275f80f464f70fcbf5dde2ba7ba8f0eea5298", size = 3075736, upload-time = "2025-04-02T02:11:44.347Z" },
+ { url = "https://files.pythonhosted.org/packages/43/f9/19bbb0026a47043fb239e821e10a75304b12ba986ce4af71cf8986af411c/pymssql-2.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:48ab1ee04754fb8ce703b6c154e54fde4f6c7f440766d397b101b748123a12df", size = 4019433, upload-time = "2025-04-02T03:07:58.222Z" },
+ { url = "https://files.pythonhosted.org/packages/a6/ac/3aca13f1f527299db4adef594fb9f14d47d68de91b93a220a67391b8ec87/pymssql-2.3.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9e22bb4d5aed85b084e3b9fb5ae3463301dd69c17703cfef72e0aed746452cc9", size = 3993550, upload-time = "2025-04-02T02:13:16.433Z" },
+ { url = "https://files.pythonhosted.org/packages/b9/93/879d92f61afb974f69b9186b16ee6a97adff2abc82777e3b66c9c9efb179/pymssql-2.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c2c1c8d3632630d52387e5b5b4483027494b5cb8f65401573715b74e7a3f16e5", size = 4381934, upload-time = "2025-04-02T02:12:45.424Z" },
+ { url = "https://files.pythonhosted.org/packages/6c/a6/923769b6dbb4e3a4c07a867e0c7fa8e4b230f675095cd7109d4e3eb9ddf0/pymssql-2.3.4-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:f7f245acbdf89b96a41513ef0214b55a3ba2824f1f3119dd1945443b6cac78d3", size = 4849674, upload-time = "2025-04-02T02:13:05.245Z" },
+ { url = "https://files.pythonhosted.org/packages/7a/2d/c787f061dcd0603905bf8085dda9cddb8c3c03b18d9239d5d18c953eebba/pymssql-2.3.4-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:9484485fb847eb67f828459b0f4857c9725b20c517c2b7f88a9788fd72b76a6a", size = 4076649, upload-time = "2025-04-02T02:15:13.053Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/a2/e55d823e3ab21cf9fc88e4e2424936899392d9d2e6569d5bcce063f84dac/pymssql-2.3.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4a0716482cd5ecce07230925593cefd9137959c18aca4c92fc24c243d3c20e38", size = 4139477, upload-time = "2025-04-02T02:13:42.91Z" },
+ { url = "https://files.pythonhosted.org/packages/c7/7c/0fec6587b38081d0d0fca4f9ad31e85ec6c5791879e57f0e559ec6be4d3d/pymssql-2.3.4-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:ba4f988674b361709821c8173a6471aa6e47ee6e45b5a8e30d4dcbde1f62fb0f", size = 4653837, upload-time = "2025-04-02T02:15:05.102Z" },
+ { url = "https://files.pythonhosted.org/packages/5f/7c/77d0251f4b5ad5690226a93547fc8279c1c48bd14e3ccc820f5c580a3b73/pymssql-2.3.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:51b8ebfbd7d14d5e7c65e76ffaf31584ffabe9fb1bfd2a85f529bd707512e39d", size = 4910914, upload-time = "2025-04-02T02:13:55.446Z" },
+ { url = "https://files.pythonhosted.org/packages/4f/22/1b2ef85804872a5940010d3c012722356af1fa24f8ba6f419c0260881032/pymssql-2.3.4-cp312-cp312-win32.whl", hash = "sha256:c8f5718f5e7d2623eaf35e025d5fa288c5789916809a89f00b42346b888673da", size = 1337991, upload-time = "2025-04-02T02:29:43.394Z" },
+ { url = "https://files.pythonhosted.org/packages/0f/43/c98f34e7b3cd45653fb233a4bee83bffca0cf5e78c290c291cec34faac21/pymssql-2.3.4-cp312-cp312-win_amd64.whl", hash = "sha256:d72b38b5ba66a4072c680447099bb63ac35d0425e9a29ff91b048e563b999be5", size = 2021760, upload-time = "2025-04-02T02:28:06.757Z" },
+ { url = "https://files.pythonhosted.org/packages/63/58/90dbe299359c547fcb037d4a12f2146916213b99a245d01efdf5ade52910/pymssql-2.3.4-cp313-cp313-macosx_13_0_universal2.whl", hash = "sha256:36ede0bc046e18cb0a5f043828bc441c80ffb2aa4606ce0cfcbf2a3d71266f0a", size = 3064581, upload-time = "2025-04-02T02:09:43.911Z" },
+ { url = "https://files.pythonhosted.org/packages/4b/7c/15e75a74de5e392ea1a9456261632cc312c873f28ac2f9ef39dfefac8cd2/pymssql-2.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d247114853ada387415df303d24d2e990596ce28b23f5b59c46d852cfea0f2ad", size = 4013283, upload-time = "2025-04-02T03:08:00.216Z" },
+ { url = "https://files.pythonhosted.org/packages/2a/29/b9f08676145c3086db11c55b40bd58dfb0d775853f7280c1b2e15fc44fc2/pymssql-2.3.4-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:79881cbe1a5826ddb959ccf8add015e5b82e6afbbf9cf5e281bd794278b2c2eb", size = 3996475, upload-time = "2025-04-02T02:13:18.212Z" },
+ { url = "https://files.pythonhosted.org/packages/ab/cb/54ca973c666e8402f3bf7feaf7e2037b7c80dbd732be67e224f95cb6a1cc/pymssql-2.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4bfcd63280b0f74124241092bdfd7889925342bcb58b4cde299e4c91cec55436", size = 4377615, upload-time = "2025-04-02T02:12:46.677Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/f2/973dfded45e0df9dcf72bc1b7254cefd5ffb1492f314822020d3c066421f/pymssql-2.3.4-cp313-cp313-manylinux_2_28_x86_64.whl", hash = "sha256:f3b784563f2b24c4d3f0e250fa9cfe59a22791539725f4d5059139c66f072a14", size = 4839647, upload-time = "2025-04-02T02:13:07.216Z" },
+ { url = "https://files.pythonhosted.org/packages/91/cb/9d9342f0936ff6d58a59446e7449f93cc1134e59f3a1ec075e7b364e82a6/pymssql-2.3.4-cp313-cp313-musllinux_1_1_i686.whl", hash = "sha256:a54a018215cf0cffbaaa6edaa02215ef19fa9c9ff6a2c172e8fa563f577e2e91", size = 4079413, upload-time = "2025-04-02T02:15:14.592Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/f1/79866247539144dcc9e44e9f8ad700bdc78c286863f37d879d71bbfd2c94/pymssql-2.3.4-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:14f2474fda3c57bc95b9ba146552463571fe77c816cbfb2e64344528d9afb755", size = 4141187, upload-time = "2025-04-02T02:13:44.711Z" },
+ { url = "https://files.pythonhosted.org/packages/9c/2d/c187ebcaeb2832cc7ac85034897eb920b361fd63bf011a5d02b31fe2f840/pymssql-2.3.4-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:145dc2b73e4fe115e6176866245921ce95a216a8d6cb0d9420c2e05ee2a911a9", size = 4661965, upload-time = "2025-04-02T02:15:06.727Z" },
+ { url = "https://files.pythonhosted.org/packages/77/59/aae5ba396d1c603325112bf7106705e1781e4604381faa45ad55161f2b0f/pymssql-2.3.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e08f1bc9e4a914c82816e3e5270b53bead13d3444435fc7bddfff9cb302b9982", size = 4903978, upload-time = "2025-04-02T02:13:57.341Z" },
+ { url = "https://files.pythonhosted.org/packages/3f/a9/25ea7056857aabbfd285c397084c571e4486f341ff8e8086b067bc2e2109/pymssql-2.3.4-cp313-cp313-win32.whl", hash = "sha256:e31b507f4669671e8bbdeecf1c1c2ed9c092953a1decfae5af656200a74195d1", size = 1337662, upload-time = "2025-04-02T02:21:12.84Z" },
+]
+
+[[package]]
+name = "pymysql"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/41/9d/ee68dee1c8821c839bb31e6e5f40e61035a5278f7c1307dde758f0c90452/PyMySQL-1.1.0.tar.gz", hash = "sha256:4f13a7df8bf36a51e81dd9f3605fede45a4878fe02f9236349fd82a3f0612f96", size = 47240, upload-time = "2023-06-26T05:34:02.058Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e5/30/20467e39523d0cfc2b6227902d3687a16364307260c75e6a1cb4422b0c62/PyMySQL-1.1.0-py3-none-any.whl", hash = "sha256:8969ec6d763c856f7073c4c64662882675702efcb114b4bcbb955aea3a069fa7", size = 44768, upload-time = "2023-06-26T05:33:59.951Z" },
+]
+
+[[package]]
+name = "pynacl"
+version = "1.5.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cffi" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/a7/22/27582568be639dfe22ddb3902225f91f2f17ceff88ce80e4db396c8986da/PyNaCl-1.5.0.tar.gz", hash = "sha256:8ac7448f09ab85811607bdd21ec2464495ac8b7c66d146bf545b0f08fb9220ba", size = 3392854, upload-time = "2022-01-07T22:05:41.134Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ce/75/0b8ede18506041c0bf23ac4d8e2971b4161cd6ce630b177d0a08eb0d8857/PyNaCl-1.5.0-cp36-abi3-macosx_10_10_universal2.whl", hash = "sha256:401002a4aaa07c9414132aaed7f6836ff98f59277a234704ff66878c2ee4a0d1", size = 349920, upload-time = "2022-01-07T22:05:49.156Z" },
+ { url = "https://files.pythonhosted.org/packages/59/bb/fddf10acd09637327a97ef89d2a9d621328850a72f1fdc8c08bdf72e385f/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl", hash = "sha256:52cb72a79269189d4e0dc537556f4740f7f0a9ec41c1322598799b0bdad4ef92", size = 601722, upload-time = "2022-01-07T22:05:50.989Z" },
+ { url = "https://files.pythonhosted.org/packages/5d/70/87a065c37cca41a75f2ce113a5a2c2aa7533be648b184ade58971b5f7ccc/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a36d4a9dda1f19ce6e03c9a784a2921a4b726b02e1c736600ca9c22029474394", size = 680087, upload-time = "2022-01-07T22:05:52.539Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/87/f1bb6a595f14a327e8285b9eb54d41fef76c585a0edef0a45f6fc95de125/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:0c84947a22519e013607c9be43706dd42513f9e6ae5d39d3613ca1e142fba44d", size = 856678, upload-time = "2022-01-07T22:05:54.251Z" },
+ { url = "https://files.pythonhosted.org/packages/66/28/ca86676b69bf9f90e710571b67450508484388bfce09acf8a46f0b8c785f/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:06b8f6fa7f5de8d5d2f7573fe8c863c051225a27b61e6860fd047b1775807858", size = 1133660, upload-time = "2022-01-07T22:05:56.056Z" },
+ { url = "https://files.pythonhosted.org/packages/3d/85/c262db650e86812585e2bc59e497a8f59948a005325a11bbbc9ecd3fe26b/PyNaCl-1.5.0-cp36-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a422368fc821589c228f4c49438a368831cb5bbc0eab5ebe1d7fac9dded6567b", size = 663824, upload-time = "2022-01-07T22:05:57.434Z" },
+ { url = "https://files.pythonhosted.org/packages/fd/1a/cc308a884bd299b651f1633acb978e8596c71c33ca85e9dc9fa33a5399b9/PyNaCl-1.5.0-cp36-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:61f642bf2378713e2c2e1de73444a3778e5f0a38be6fee0fe532fe30060282ff", size = 1117912, upload-time = "2022-01-07T22:05:58.665Z" },
+ { url = "https://files.pythonhosted.org/packages/25/2d/b7df6ddb0c2a33afdb358f8af6ea3b8c4d1196ca45497dd37a56f0c122be/PyNaCl-1.5.0-cp36-abi3-win32.whl", hash = "sha256:e46dae94e34b085175f8abb3b0aaa7da40767865ac82c928eeb9e57e1ea8a543", size = 204624, upload-time = "2022-01-07T22:06:00.085Z" },
+ { url = "https://files.pythonhosted.org/packages/5e/22/d3db169895faaf3e2eda892f005f433a62db2decbcfbc2f61e6517adfa87/PyNaCl-1.5.0-cp36-abi3-win_amd64.whl", hash = "sha256:20f42270d27e1b6a29f54032090b972d97f0a1b0948cc52392041ef7831fee93", size = 212141, upload-time = "2022-01-07T22:06:01.861Z" },
+]
+
+[[package]]
+name = "pyopenssl"
+version = "25.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cryptography" },
+ { name = "typing-extensions", marker = "python_full_version < '3.13'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/04/8c/cd89ad05804f8e3c17dea8f178c3f40eeab5694c30e0c9f5bcd49f576fc3/pyopenssl-25.1.0.tar.gz", hash = "sha256:8d031884482e0c67ee92bf9a4d8cceb08d92aba7136432ffb0703c5280fc205b", size = 179937, upload-time = "2025-05-17T16:28:31.31Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/80/28/2659c02301b9500751f8d42f9a6632e1508aa5120de5e43042b8b30f8d5d/pyopenssl-25.1.0-py3-none-any.whl", hash = "sha256:2b11f239acc47ac2e5aca04fd7fa829800aeee22a2eb30d744572a157bd8a1ab", size = 56771, upload-time = "2025-05-17T16:28:29.197Z" },
+]
+
+[[package]]
+name = "pyparsing"
+version = "3.2.3"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/bb/22/f1129e69d94ffff626bdb5c835506b3a5b4f3d070f17ea295e12c2c6f60f/pyparsing-3.2.3.tar.gz", hash = "sha256:b9c13f1ab8b3b542f72e28f634bad4de758ab3ce4546e4301970ad6fa77c38be", size = 1088608, upload-time = "2025-03-25T05:01:28.114Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/05/e7/df2285f3d08fee213f2d041540fa4fc9ca6c2d44cf36d3a035bf2a8d2bcc/pyparsing-3.2.3-py3-none-any.whl", hash = "sha256:a749938e02d6fd0b59b356ca504a24982314bb090c383e3cf201c95ef7e2bfcf", size = 111120, upload-time = "2025-03-25T05:01:24.908Z" },
+]
+
+[[package]]
+name = "pypdf"
+version = "5.9.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/89/3a/584b97a228950ed85aec97c811c68473d9b8d149e6a8c155668287cf1a28/pypdf-5.9.0.tar.gz", hash = "sha256:30f67a614d558e495e1fbb157ba58c1de91ffc1718f5e0dfeb82a029233890a1", size = 5035118, upload-time = "2025-07-27T14:04:52.364Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/48/d9/6cff57c80a6963e7dd183bf09e9f21604a77716644b1e580e97b259f7612/pypdf-5.9.0-py3-none-any.whl", hash = "sha256:be10a4c54202f46d9daceaa8788be07aa8cd5ea8c25c529c50dd509206382c35", size = 313193, upload-time = "2025-07-27T14:04:50.53Z" },
+]
+
+[[package]]
+name = "pypdfium2"
+version = "4.30.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a1/14/838b3ba247a0ba92e4df5d23f2bea9478edcfd72b78a39d6ca36ccd84ad2/pypdfium2-4.30.0.tar.gz", hash = "sha256:48b5b7e5566665bc1015b9d69c1ebabe21f6aee468b509531c3c8318eeee2e16", size = 140239, upload-time = "2024-05-09T18:33:17.552Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c7/9a/c8ff5cc352c1b60b0b97642ae734f51edbab6e28b45b4fcdfe5306ee3c83/pypdfium2-4.30.0-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:b33ceded0b6ff5b2b93bc1fe0ad4b71aa6b7e7bd5875f1ca0cdfb6ba6ac01aab", size = 2837254, upload-time = "2024-05-09T18:32:48.653Z" },
+ { url = "https://files.pythonhosted.org/packages/21/8b/27d4d5409f3c76b985f4ee4afe147b606594411e15ac4dc1c3363c9a9810/pypdfium2-4.30.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:4e55689f4b06e2d2406203e771f78789bd4f190731b5d57383d05cf611d829de", size = 2707624, upload-time = "2024-05-09T18:32:51.458Z" },
+ { url = "https://files.pythonhosted.org/packages/11/63/28a73ca17c24b41a205d658e177d68e198d7dde65a8c99c821d231b6ee3d/pypdfium2-4.30.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e6e50f5ce7f65a40a33d7c9edc39f23140c57e37144c2d6d9e9262a2a854854", size = 2793126, upload-time = "2024-05-09T18:32:53.581Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/96/53b3ebf0955edbd02ac6da16a818ecc65c939e98fdeb4e0958362bd385c8/pypdfium2-4.30.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3d0dd3ecaffd0b6dbda3da663220e705cb563918249bda26058c6036752ba3a2", size = 2591077, upload-time = "2024-05-09T18:32:55.99Z" },
+ { url = "https://files.pythonhosted.org/packages/ec/ee/0394e56e7cab8b5b21f744d988400948ef71a9a892cbeb0b200d324ab2c7/pypdfium2-4.30.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cc3bf29b0db8c76cdfaac1ec1cde8edf211a7de7390fbf8934ad2aa9b4d6dfad", size = 2864431, upload-time = "2024-05-09T18:32:57.911Z" },
+ { url = "https://files.pythonhosted.org/packages/65/cd/3f1edf20a0ef4a212a5e20a5900e64942c5a374473671ac0780eaa08ea80/pypdfium2-4.30.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f1f78d2189e0ddf9ac2b7a9b9bd4f0c66f54d1389ff6c17e9fd9dc034d06eb3f", size = 2812008, upload-time = "2024-05-09T18:32:59.886Z" },
+ { url = "https://files.pythonhosted.org/packages/c8/91/2d517db61845698f41a2a974de90762e50faeb529201c6b3574935969045/pypdfium2-4.30.0-py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:5eda3641a2da7a7a0b2f4dbd71d706401a656fea521b6b6faa0675b15d31a163", size = 6181543, upload-time = "2024-05-09T18:33:02.597Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/c4/ed1315143a7a84b2c7616569dfb472473968d628f17c231c39e29ae9d780/pypdfium2-4.30.0-py3-none-musllinux_1_1_i686.whl", hash = "sha256:0dfa61421b5eb68e1188b0b2231e7ba35735aef2d867d86e48ee6cab6975195e", size = 6175911, upload-time = "2024-05-09T18:33:05.376Z" },
+ { url = "https://files.pythonhosted.org/packages/7a/c4/9e62d03f414e0e3051c56d5943c3bf42aa9608ede4e19dc96438364e9e03/pypdfium2-4.30.0-py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:f33bd79e7a09d5f7acca3b0b69ff6c8a488869a7fab48fdf400fec6e20b9c8be", size = 6267430, upload-time = "2024-05-09T18:33:08.067Z" },
+ { url = "https://files.pythonhosted.org/packages/90/47/eda4904f715fb98561e34012826e883816945934a851745570521ec89520/pypdfium2-4.30.0-py3-none-win32.whl", hash = "sha256:ee2410f15d576d976c2ab2558c93d392a25fb9f6635e8dd0a8a3a5241b275e0e", size = 2775951, upload-time = "2024-05-09T18:33:10.567Z" },
+ { url = "https://files.pythonhosted.org/packages/25/bd/56d9ec6b9f0fc4e0d95288759f3179f0fcd34b1a1526b75673d2f6d5196f/pypdfium2-4.30.0-py3-none-win_amd64.whl", hash = "sha256:90dbb2ac07be53219f56be09961eb95cf2473f834d01a42d901d13ccfad64b4c", size = 2892098, upload-time = "2024-05-09T18:33:13.107Z" },
+ { url = "https://files.pythonhosted.org/packages/be/7a/097801205b991bc3115e8af1edb850d30aeaf0118520b016354cf5ccd3f6/pypdfium2-4.30.0-py3-none-win_arm64.whl", hash = "sha256:119b2969a6d6b1e8d55e99caaf05290294f2d0fe49c12a3f17102d01c441bd29", size = 2752118, upload-time = "2024-05-09T18:33:15.489Z" },
+]
+
+[[package]]
+name = "pytest"
+version = "8.4.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "colorama", marker = "sys_platform == 'win32'" },
+ { name = "iniconfig" },
+ { name = "packaging" },
+ { name = "pluggy" },
+ { name = "pygments" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/08/ba/45911d754e8eba3d5a841a5ce61a65a685ff1798421ac054f85aa8747dfb/pytest-8.4.1.tar.gz", hash = "sha256:7c67fd69174877359ed9371ec3af8a3d2b04741818c51e5e99cc1742251fa93c", size = 1517714, upload-time = "2025-06-18T05:48:06.109Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/29/16/c8a903f4c4dffe7a12843191437d7cd8e32751d5de349d45d3fe69544e87/pytest-8.4.1-py3-none-any.whl", hash = "sha256:539c70ba6fcead8e78eebbf1115e8b589e7565830d7d006a8723f19ac8a0afb7", size = 365474, upload-time = "2025-06-18T05:48:03.955Z" },
+]
+
+[[package]]
+name = "pytest-asyncio"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pytest" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/4e/51/f8794af39eeb870e87a8c8068642fc07bce0c854d6865d7dd0f2a9d338c2/pytest_asyncio-1.1.0.tar.gz", hash = "sha256:796aa822981e01b68c12e4827b8697108f7205020f24b5793b3c41555dab68ea", size = 46652, upload-time = "2025-07-16T04:29:26.393Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c7/9d/bf86eddabf8c6c9cb1ea9a869d6873b46f105a5d292d3a6f7071f5b07935/pytest_asyncio-1.1.0-py3-none-any.whl", hash = "sha256:5fe2d69607b0bd75c656d1211f969cadba035030156745ee09e7d71740e58ecf", size = 15157, upload-time = "2025-07-16T04:29:24.929Z" },
+]
+
+[[package]]
+name = "pytest-cov"
+version = "6.2.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "coverage" },
+ { name = "pluggy" },
+ { name = "pytest" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/18/99/668cade231f434aaa59bbfbf49469068d2ddd945000621d3d165d2e7dd7b/pytest_cov-6.2.1.tar.gz", hash = "sha256:25cc6cc0a5358204b8108ecedc51a9b57b34cc6b8c967cc2c01a4e00d8a67da2", size = 69432, upload-time = "2025-06-12T10:47:47.684Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bc/16/4ea354101abb1287856baa4af2732be351c7bee728065aed451b678153fd/pytest_cov-6.2.1-py3-none-any.whl", hash = "sha256:f5bc4c23f42f1cdd23c70b1dab1bbaef4fc505ba950d53e0081d0730dd7e86d5", size = 24644, upload-time = "2025-06-12T10:47:45.932Z" },
+]
+
+[[package]]
+name = "pytest-mock"
+version = "3.14.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pytest" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/71/28/67172c96ba684058a4d24ffe144d64783d2a270d0af0d9e792737bddc75c/pytest_mock-3.14.1.tar.gz", hash = "sha256:159e9edac4c451ce77a5cdb9fc5d1100708d2dd4ba3c3df572f14097351af80e", size = 33241, upload-time = "2025-05-26T13:58:45.167Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b2/05/77b60e520511c53d1c1ca75f1930c7dd8e971d0c4379b7f4b3f9644685ba/pytest_mock-3.14.1-py3-none-any.whl", hash = "sha256:178aefcd11307d874b4cd3100344e7e2d888d9791a6a1d9bfe90fbc1b74fd1d0", size = 9923, upload-time = "2025-05-26T13:58:43.487Z" },
+]
+
+[[package]]
+name = "python-dateutil"
+version = "2.9.0.post0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "six" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" },
+]
+
+[[package]]
+name = "python-dotenv"
+version = "1.0.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/bc/57/e84d88dfe0aec03b7a2d4327012c1627ab5f03652216c63d49846d7a6c58/python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca", size = 39115, upload-time = "2024-01-23T06:33:00.505Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6a/3e/b68c118422ec867fa7ab88444e1274aa40681c606d59ac27de5a5588f082/python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a", size = 19863, upload-time = "2024-01-23T06:32:58.246Z" },
+]
+
+[[package]]
+name = "python-engineio"
+version = "4.12.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "simple-websocket" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ba/0b/67295279b66835f9fa7a491650efcd78b20321c127036eef62c11a31e028/python_engineio-4.12.2.tar.gz", hash = "sha256:e7e712ffe1be1f6a05ee5f951e72d434854a32fcfc7f6e4d9d3cae24ec70defa", size = 91677, upload-time = "2025-06-04T19:22:18.789Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/0c/fa/df59acedf7bbb937f69174d00f921a7b93aa5a5f5c17d05296c814fff6fc/python_engineio-4.12.2-py3-none-any.whl", hash = "sha256:8218ab66950e179dfec4b4bbb30aecf3f5d86f5e58e6fc1aa7fde2c698b2804f", size = 59536, upload-time = "2025-06-04T19:22:16.916Z" },
+]
+
+[[package]]
+name = "python-magic"
+version = "0.4.27"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/da/db/0b3e28ac047452d079d375ec6798bf76a036a08182dbb39ed38116a49130/python-magic-0.4.27.tar.gz", hash = "sha256:c1ba14b08e4a5f5c31a302b7721239695b2f0f058d125bd5ce1ee36b9d9d3c3b", size = 14677, upload-time = "2022-06-07T20:16:59.508Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/6c/73/9f872cb81fc5c3bb48f7227872c28975f998f3e7c2b1c16e95e6432bbb90/python_magic-0.4.27-py2.py3-none-any.whl", hash = "sha256:c212960ad306f700aa0d01e5d7a325d20548ff97eb9920dcd29513174f0294d3", size = 13840, upload-time = "2022-06-07T20:16:57.763Z" },
+]
+
+[[package]]
+name = "python-socketio"
+version = "5.13.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "bidict" },
+ { name = "python-engineio" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/21/1a/396d50ccf06ee539fa758ce5623b59a9cb27637fc4b2dc07ed08bf495e77/python_socketio-5.13.0.tar.gz", hash = "sha256:ac4e19a0302ae812e23b712ec8b6427ca0521f7c582d6abb096e36e24a263029", size = 121125, upload-time = "2025-04-12T15:46:59.933Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3c/32/b4fb8585d1be0f68bde7e110dffbcf354915f77ad8c778563f0ad9655c02/python_socketio-5.13.0-py3-none-any.whl", hash = "sha256:51f68d6499f2df8524668c24bcec13ba1414117cfb3a90115c559b601ab10caf", size = 77800, upload-time = "2025-04-12T15:46:58.412Z" },
+]
+
+[[package]]
+name = "pytz"
+version = "2025.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f8/bf/abbd3cdfb8fbc7fb3d4d38d320f2441b1e7cbe29be4f23797b4a2b5d8aac/pytz-2025.2.tar.gz", hash = "sha256:360b9e3dbb49a209c21ad61809c7fb453643e048b38924c765813546746e81c3", size = 320884, upload-time = "2025-03-25T02:25:00.538Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/81/c4/34e93fe5f5429d7570ec1fa436f1986fb1f00c3e0f43a589fe2bbcd22c3f/pytz-2025.2-py2.py3-none-any.whl", hash = "sha256:5ddf76296dd8c44c26eb8f4b6f35488f3ccbf6fbbd7adee0b7262d43f0ec2f00", size = 509225, upload-time = "2025-03-25T02:24:58.468Z" },
+]
+
+[[package]]
+name = "pywin32"
+version = "311"
+source = { registry = "https://pypi.org/simple" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e7/ab/01ea1943d4eba0f850c3c61e78e8dd59757ff815ff3ccd0a84de5f541f42/pywin32-311-cp312-cp312-win32.whl", hash = "sha256:750ec6e621af2b948540032557b10a2d43b0cee2ae9758c54154d711cc852d31", size = 8706543, upload-time = "2025-07-14T20:13:20.765Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/a8/a0e8d07d4d051ec7502cd58b291ec98dcc0c3fff027caad0470b72cfcc2f/pywin32-311-cp312-cp312-win_amd64.whl", hash = "sha256:b8c095edad5c211ff31c05223658e71bf7116daa0ecf3ad85f3201ea3190d067", size = 9495040, upload-time = "2025-07-14T20:13:22.543Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/3a/2ae996277b4b50f17d61f0603efd8253cb2d79cc7ae159468007b586396d/pywin32-311-cp312-cp312-win_arm64.whl", hash = "sha256:e286f46a9a39c4a18b319c28f59b61de793654af2f395c102b4f819e584b5852", size = 8710102, upload-time = "2025-07-14T20:13:24.682Z" },
+ { url = "https://files.pythonhosted.org/packages/a5/be/3fd5de0979fcb3994bfee0d65ed8ca9506a8a1260651b86174f6a86f52b3/pywin32-311-cp313-cp313-win32.whl", hash = "sha256:f95ba5a847cba10dd8c4d8fefa9f2a6cf283b8b88ed6178fa8a6c1ab16054d0d", size = 8705700, upload-time = "2025-07-14T20:13:26.471Z" },
+ { url = "https://files.pythonhosted.org/packages/e3/28/e0a1909523c6890208295a29e05c2adb2126364e289826c0a8bc7297bd5c/pywin32-311-cp313-cp313-win_amd64.whl", hash = "sha256:718a38f7e5b058e76aee1c56ddd06908116d35147e133427e59a3983f703a20d", size = 9494700, upload-time = "2025-07-14T20:13:28.243Z" },
+ { url = "https://files.pythonhosted.org/packages/04/bf/90339ac0f55726dce7d794e6d79a18a91265bdf3aa70b6b9ca52f35e022a/pywin32-311-cp313-cp313-win_arm64.whl", hash = "sha256:7b4075d959648406202d92a2310cb990fea19b535c7f4a78d3f5e10b926eeb8a", size = 8709318, upload-time = "2025-07-14T20:13:30.348Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/31/097f2e132c4f16d99a22bfb777e0fd88bd8e1c634304e102f313af69ace5/pywin32-311-cp314-cp314-win32.whl", hash = "sha256:b7a2c10b93f8986666d0c803ee19b5990885872a7de910fc460f9b0c2fbf92ee", size = 8840714, upload-time = "2025-07-14T20:13:32.449Z" },
+ { url = "https://files.pythonhosted.org/packages/90/4b/07c77d8ba0e01349358082713400435347df8426208171ce297da32c313d/pywin32-311-cp314-cp314-win_amd64.whl", hash = "sha256:3aca44c046bd2ed8c90de9cb8427f581c479e594e99b5c0bb19b29c10fd6cb87", size = 9656800, upload-time = "2025-07-14T20:13:34.312Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/d2/21af5c535501a7233e734b8af901574572da66fcc254cb35d0609c9080dd/pywin32-311-cp314-cp314-win_arm64.whl", hash = "sha256:a508e2d9025764a8270f93111a970e1d0fbfc33f4153b388bb649b7eec4f9b42", size = 8932540, upload-time = "2025-07-14T20:13:36.379Z" },
+]
+
+[[package]]
+name = "pyyaml"
+version = "6.0.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e", size = 130631, upload-time = "2024-08-06T20:33:50.674Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/86/0c/c581167fc46d6d6d7ddcfb8c843a4de25bdd27e4466938109ca68492292c/PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab", size = 183873, upload-time = "2024-08-06T20:32:25.131Z" },
+ { url = "https://files.pythonhosted.org/packages/a8/0c/38374f5bb272c051e2a69281d71cba6fdb983413e6758b84482905e29a5d/PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725", size = 173302, upload-time = "2024-08-06T20:32:26.511Z" },
+ { url = "https://files.pythonhosted.org/packages/c3/93/9916574aa8c00aa06bbac729972eb1071d002b8e158bd0e83a3b9a20a1f7/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5", size = 739154, upload-time = "2024-08-06T20:32:28.363Z" },
+ { url = "https://files.pythonhosted.org/packages/95/0f/b8938f1cbd09739c6da569d172531567dbcc9789e0029aa070856f123984/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425", size = 766223, upload-time = "2024-08-06T20:32:30.058Z" },
+ { url = "https://files.pythonhosted.org/packages/b9/2b/614b4752f2e127db5cc206abc23a8c19678e92b23c3db30fc86ab731d3bd/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476", size = 767542, upload-time = "2024-08-06T20:32:31.881Z" },
+ { url = "https://files.pythonhosted.org/packages/d4/00/dd137d5bcc7efea1836d6264f049359861cf548469d18da90cd8216cf05f/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48", size = 731164, upload-time = "2024-08-06T20:32:37.083Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/1f/4f998c900485e5c0ef43838363ba4a9723ac0ad73a9dc42068b12aaba4e4/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b", size = 756611, upload-time = "2024-08-06T20:32:38.898Z" },
+ { url = "https://files.pythonhosted.org/packages/df/d1/f5a275fdb252768b7a11ec63585bc38d0e87c9e05668a139fea92b80634c/PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4", size = 140591, upload-time = "2024-08-06T20:32:40.241Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/e8/4f648c598b17c3d06e8753d7d13d57542b30d56e6c2dedf9c331ae56312e/PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8", size = 156338, upload-time = "2024-08-06T20:32:41.93Z" },
+ { url = "https://files.pythonhosted.org/packages/ef/e3/3af305b830494fa85d95f6d95ef7fa73f2ee1cc8ef5b495c7c3269fb835f/PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba", size = 181309, upload-time = "2024-08-06T20:32:43.4Z" },
+ { url = "https://files.pythonhosted.org/packages/45/9f/3b1c20a0b7a3200524eb0076cc027a970d320bd3a6592873c85c92a08731/PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1", size = 171679, upload-time = "2024-08-06T20:32:44.801Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/9a/337322f27005c33bcb656c655fa78325b730324c78620e8328ae28b64d0c/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133", size = 733428, upload-time = "2024-08-06T20:32:46.432Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/69/864fbe19e6c18ea3cc196cbe5d392175b4cf3d5d0ac1403ec3f2d237ebb5/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484", size = 763361, upload-time = "2024-08-06T20:32:51.188Z" },
+ { url = "https://files.pythonhosted.org/packages/04/24/b7721e4845c2f162d26f50521b825fb061bc0a5afcf9a386840f23ea19fa/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5", size = 759523, upload-time = "2024-08-06T20:32:53.019Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/b2/e3234f59ba06559c6ff63c4e10baea10e5e7df868092bf9ab40e5b9c56b6/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc", size = 726660, upload-time = "2024-08-06T20:32:54.708Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/0f/25911a9f080464c59fab9027482f822b86bf0608957a5fcc6eaac85aa515/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652", size = 751597, upload-time = "2024-08-06T20:32:56.985Z" },
+ { url = "https://files.pythonhosted.org/packages/14/0d/e2c3b43bbce3cf6bd97c840b46088a3031085179e596d4929729d8d68270/PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183", size = 140527, upload-time = "2024-08-06T20:33:03.001Z" },
+ { url = "https://files.pythonhosted.org/packages/fa/de/02b54f42487e3d3c6efb3f89428677074ca7bf43aae402517bc7cca949f3/PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563", size = 156446, upload-time = "2024-08-06T20:33:04.33Z" },
+]
+
+[[package]]
+name = "qdrant-client"
+version = "1.15.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "grpcio" },
+ { name = "httpx", extra = ["http2"] },
+ { name = "numpy" },
+ { name = "portalocker" },
+ { name = "protobuf" },
+ { name = "pydantic" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/79/8b/76c7d325e11d97cb8eb5e261c3759e9ed6664735afbf32fdded5b580690c/qdrant_client-1.15.1.tar.gz", hash = "sha256:631f1f3caebfad0fd0c1fba98f41be81d9962b7bf3ca653bed3b727c0e0cbe0e", size = 295297, upload-time = "2025-07-31T19:35:19.627Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ef/33/d8df6a2b214ffbe4138db9a1efe3248f67dc3c671f82308bea1582ecbbb7/qdrant_client-1.15.1-py3-none-any.whl", hash = "sha256:2b975099b378382f6ca1cfb43f0d59e541be6e16a5892f282a4b8de7eff5cb63", size = 337331, upload-time = "2025-07-31T19:35:17.539Z" },
+]
+
+[[package]]
+name = "redis"
+version = "5.2.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/47/da/d283a37303a995cd36f8b92db85135153dc4f7a8e4441aa827721b442cfb/redis-5.2.1.tar.gz", hash = "sha256:16f2e22dff21d5125e8481515e386711a34cbec50f0e44413dd7d9c060a54e0f", size = 4608355, upload-time = "2024-12-06T09:50:41.956Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3c/5f/fa26b9b2672cbe30e07d9a5bdf39cf16e3b80b42916757c5f92bca88e4ba/redis-5.2.1-py3-none-any.whl", hash = "sha256:ee7e1056b9aea0f04c6c2ed59452947f34c4940ee025f5dd83e6a6418b6989e4", size = 261502, upload-time = "2024-12-06T09:50:39.656Z" },
+]
+
+[[package]]
+name = "referencing"
+version = "0.36.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "attrs" },
+ { name = "rpds-py" },
+ { name = "typing-extensions", marker = "python_full_version < '3.13'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/2f/db/98b5c277be99dd18bfd91dd04e1b759cad18d1a338188c936e92f921c7e2/referencing-0.36.2.tar.gz", hash = "sha256:df2e89862cd09deabbdba16944cc3f10feb6b3e6f18e902f7cc25609a34775aa", size = 74744, upload-time = "2025-01-25T08:48:16.138Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c1/b1/3baf80dc6d2b7bc27a95a67752d0208e410351e3feb4eb78de5f77454d8d/referencing-0.36.2-py3-none-any.whl", hash = "sha256:e8699adbbf8b5c7de96d8ffa0eb5c158b3beafce084968e2ea8bb08c6794dcd0", size = 26775, upload-time = "2025-01-25T08:48:14.241Z" },
+]
+
+[[package]]
+name = "regex"
+version = "2025.7.34"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0b/de/e13fa6dc61d78b30ba47481f99933a3b49a57779d625c392d8036770a60d/regex-2025.7.34.tar.gz", hash = "sha256:9ead9765217afd04a86822dfcd4ed2747dfe426e887da413b15ff0ac2457e21a", size = 400714, upload-time = "2025-07-31T00:21:16.262Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ff/f0/31d62596c75a33f979317658e8d261574785c6cd8672c06741ce2e2e2070/regex-2025.7.34-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:7f7211a746aced993bef487de69307a38c5ddd79257d7be83f7b202cb59ddb50", size = 485492, upload-time = "2025-07-31T00:19:35.57Z" },
+ { url = "https://files.pythonhosted.org/packages/d8/16/b818d223f1c9758c3434be89aa1a01aae798e0e0df36c1f143d1963dd1ee/regex-2025.7.34-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:fb31080f2bd0681484b275461b202b5ad182f52c9ec606052020fe13eb13a72f", size = 290000, upload-time = "2025-07-31T00:19:37.175Z" },
+ { url = "https://files.pythonhosted.org/packages/cd/70/69506d53397b4bd6954061bae75677ad34deb7f6ca3ba199660d6f728ff5/regex-2025.7.34-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0200a5150c4cf61e407038f4b4d5cdad13e86345dac29ff9dab3d75d905cf130", size = 286072, upload-time = "2025-07-31T00:19:38.612Z" },
+ { url = "https://files.pythonhosted.org/packages/b0/73/536a216d5f66084fb577bb0543b5cb7de3272eb70a157f0c3a542f1c2551/regex-2025.7.34-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:739a74970e736df0773788377969c9fea3876c2fc13d0563f98e5503e5185f46", size = 797341, upload-time = "2025-07-31T00:19:40.119Z" },
+ { url = "https://files.pythonhosted.org/packages/26/af/733f8168449e56e8f404bb807ea7189f59507cbea1b67a7bbcd92f8bf844/regex-2025.7.34-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:4fef81b2f7ea6a2029161ed6dea9ae13834c28eb5a95b8771828194a026621e4", size = 862556, upload-time = "2025-07-31T00:19:41.556Z" },
+ { url = "https://files.pythonhosted.org/packages/19/dd/59c464d58c06c4f7d87de4ab1f590e430821345a40c5d345d449a636d15f/regex-2025.7.34-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:ea74cf81fe61a7e9d77989050d0089a927ab758c29dac4e8e1b6c06fccf3ebf0", size = 910762, upload-time = "2025-07-31T00:19:43Z" },
+ { url = "https://files.pythonhosted.org/packages/37/a8/b05ccf33ceca0815a1e253693b2c86544932ebcc0049c16b0fbdf18b688b/regex-2025.7.34-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e4636a7f3b65a5f340ed9ddf53585c42e3ff37101d383ed321bfe5660481744b", size = 801892, upload-time = "2025-07-31T00:19:44.645Z" },
+ { url = "https://files.pythonhosted.org/packages/5f/9a/b993cb2e634cc22810afd1652dba0cae156c40d4864285ff486c73cd1996/regex-2025.7.34-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6cef962d7834437fe8d3da6f9bfc6f93f20f218266dcefec0560ed7765f5fe01", size = 786551, upload-time = "2025-07-31T00:19:46.127Z" },
+ { url = "https://files.pythonhosted.org/packages/2d/79/7849d67910a0de4e26834b5bb816e028e35473f3d7ae563552ea04f58ca2/regex-2025.7.34-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:cbe1698e5b80298dbce8df4d8d1182279fbdaf1044e864cbc9d53c20e4a2be77", size = 856457, upload-time = "2025-07-31T00:19:47.562Z" },
+ { url = "https://files.pythonhosted.org/packages/91/c6/de516bc082524b27e45cb4f54e28bd800c01efb26d15646a65b87b13a91e/regex-2025.7.34-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:32b9f9bcf0f605eb094b08e8da72e44badabb63dde6b83bd530580b488d1c6da", size = 848902, upload-time = "2025-07-31T00:19:49.312Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/22/519ff8ba15f732db099b126f039586bd372da6cd4efb810d5d66a5daeda1/regex-2025.7.34-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:524c868ba527eab4e8744a9287809579f54ae8c62fbf07d62aacd89f6026b282", size = 788038, upload-time = "2025-07-31T00:19:50.794Z" },
+ { url = "https://files.pythonhosted.org/packages/3f/7d/aabb467d8f57d8149895d133c88eb809a1a6a0fe262c1d508eb9dfabb6f9/regex-2025.7.34-cp312-cp312-win32.whl", hash = "sha256:d600e58ee6d036081c89696d2bdd55d507498a7180df2e19945c6642fac59588", size = 264417, upload-time = "2025-07-31T00:19:52.292Z" },
+ { url = "https://files.pythonhosted.org/packages/3b/39/bd922b55a4fc5ad5c13753274e5b536f5b06ec8eb9747675668491c7ab7a/regex-2025.7.34-cp312-cp312-win_amd64.whl", hash = "sha256:9a9ab52a466a9b4b91564437b36417b76033e8778e5af8f36be835d8cb370d62", size = 275387, upload-time = "2025-07-31T00:19:53.593Z" },
+ { url = "https://files.pythonhosted.org/packages/f7/3c/c61d2fdcecb754a40475a3d1ef9a000911d3e3fc75c096acf44b0dfb786a/regex-2025.7.34-cp312-cp312-win_arm64.whl", hash = "sha256:c83aec91af9c6fbf7c743274fd952272403ad9a9db05fe9bfc9df8d12b45f176", size = 268482, upload-time = "2025-07-31T00:19:55.183Z" },
+ { url = "https://files.pythonhosted.org/packages/15/16/b709b2119975035169a25aa8e4940ca177b1a2e25e14f8d996d09130368e/regex-2025.7.34-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:c3c9740a77aeef3f5e3aaab92403946a8d34437db930a0280e7e81ddcada61f5", size = 485334, upload-time = "2025-07-31T00:19:56.58Z" },
+ { url = "https://files.pythonhosted.org/packages/94/a6/c09136046be0595f0331bc58a0e5f89c2d324cf734e0b0ec53cf4b12a636/regex-2025.7.34-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:69ed3bc611540f2ea70a4080f853741ec698be556b1df404599f8724690edbcd", size = 289942, upload-time = "2025-07-31T00:19:57.943Z" },
+ { url = "https://files.pythonhosted.org/packages/36/91/08fc0fd0f40bdfb0e0df4134ee37cfb16e66a1044ac56d36911fd01c69d2/regex-2025.7.34-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:d03c6f9dcd562c56527c42b8530aad93193e0b3254a588be1f2ed378cdfdea1b", size = 285991, upload-time = "2025-07-31T00:19:59.837Z" },
+ { url = "https://files.pythonhosted.org/packages/be/2f/99dc8f6f756606f0c214d14c7b6c17270b6bbe26d5c1f05cde9dbb1c551f/regex-2025.7.34-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6164b1d99dee1dfad33f301f174d8139d4368a9fb50bf0a3603b2eaf579963ad", size = 797415, upload-time = "2025-07-31T00:20:01.668Z" },
+ { url = "https://files.pythonhosted.org/packages/62/cf/2fcdca1110495458ba4e95c52ce73b361cf1cafd8a53b5c31542cde9a15b/regex-2025.7.34-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:1e4f4f62599b8142362f164ce776f19d79bdd21273e86920a7b604a4275b4f59", size = 862487, upload-time = "2025-07-31T00:20:03.142Z" },
+ { url = "https://files.pythonhosted.org/packages/90/38/899105dd27fed394e3fae45607c1983e138273ec167e47882fc401f112b9/regex-2025.7.34-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:72a26dcc6a59c057b292f39d41465d8233a10fd69121fa24f8f43ec6294e5415", size = 910717, upload-time = "2025-07-31T00:20:04.727Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/f6/4716198dbd0bcc9c45625ac4c81a435d1c4d8ad662e8576dac06bab35b17/regex-2025.7.34-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d5273fddf7a3e602695c92716c420c377599ed3c853ea669c1fe26218867002f", size = 801943, upload-time = "2025-07-31T00:20:07.1Z" },
+ { url = "https://files.pythonhosted.org/packages/40/5d/cff8896d27e4e3dd11dd72ac78797c7987eb50fe4debc2c0f2f1682eb06d/regex-2025.7.34-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:c1844be23cd40135b3a5a4dd298e1e0c0cb36757364dd6cdc6025770363e06c1", size = 786664, upload-time = "2025-07-31T00:20:08.818Z" },
+ { url = "https://files.pythonhosted.org/packages/10/29/758bf83cf7b4c34f07ac3423ea03cee3eb3176941641e4ccc05620f6c0b8/regex-2025.7.34-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:dde35e2afbbe2272f8abee3b9fe6772d9b5a07d82607b5788e8508974059925c", size = 856457, upload-time = "2025-07-31T00:20:10.328Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/30/c19d212b619963c5b460bfed0ea69a092c6a43cba52a973d46c27b3e2975/regex-2025.7.34-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:f3f6e8e7af516a7549412ce57613e859c3be27d55341a894aacaa11703a4c31a", size = 849008, upload-time = "2025-07-31T00:20:11.823Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/b8/3c35da3b12c87e3cc00010ef6c3a4ae787cff0bc381aa3d251def219969a/regex-2025.7.34-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:469142fb94a869beb25b5f18ea87646d21def10fbacb0bcb749224f3509476f0", size = 788101, upload-time = "2025-07-31T00:20:13.729Z" },
+ { url = "https://files.pythonhosted.org/packages/47/80/2f46677c0b3c2b723b2c358d19f9346e714113865da0f5f736ca1a883bde/regex-2025.7.34-cp313-cp313-win32.whl", hash = "sha256:da7507d083ee33ccea1310447410c27ca11fb9ef18c95899ca57ff60a7e4d8f1", size = 264401, upload-time = "2025-07-31T00:20:15.233Z" },
+ { url = "https://files.pythonhosted.org/packages/be/fa/917d64dd074682606a003cba33585c28138c77d848ef72fc77cbb1183849/regex-2025.7.34-cp313-cp313-win_amd64.whl", hash = "sha256:9d644de5520441e5f7e2db63aec2748948cc39ed4d7a87fd5db578ea4043d997", size = 275368, upload-time = "2025-07-31T00:20:16.711Z" },
+ { url = "https://files.pythonhosted.org/packages/65/cd/f94383666704170a2154a5df7b16be28f0c27a266bffcd843e58bc84120f/regex-2025.7.34-cp313-cp313-win_arm64.whl", hash = "sha256:7bf1c5503a9f2cbd2f52d7e260acb3131b07b6273c470abb78568174fe6bde3f", size = 268482, upload-time = "2025-07-31T00:20:18.189Z" },
+ { url = "https://files.pythonhosted.org/packages/ac/23/6376f3a23cf2f3c00514b1cdd8c990afb4dfbac3cb4a68b633c6b7e2e307/regex-2025.7.34-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:8283afe7042d8270cecf27cca558873168e771183d4d593e3c5fe5f12402212a", size = 485385, upload-time = "2025-07-31T00:20:19.692Z" },
+ { url = "https://files.pythonhosted.org/packages/73/5b/6d4d3a0b4d312adbfd6d5694c8dddcf1396708976dd87e4d00af439d962b/regex-2025.7.34-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:6c053f9647e3421dd2f5dff8172eb7b4eec129df9d1d2f7133a4386319b47435", size = 289788, upload-time = "2025-07-31T00:20:21.941Z" },
+ { url = "https://files.pythonhosted.org/packages/92/71/5862ac9913746e5054d01cb9fb8125b3d0802c0706ef547cae1e7f4428fa/regex-2025.7.34-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:a16dd56bbcb7d10e62861c3cd000290ddff28ea142ffb5eb3470f183628011ac", size = 286136, upload-time = "2025-07-31T00:20:26.146Z" },
+ { url = "https://files.pythonhosted.org/packages/27/df/5b505dc447eb71278eba10d5ec940769ca89c1af70f0468bfbcb98035dc2/regex-2025.7.34-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:69c593ff5a24c0d5c1112b0df9b09eae42b33c014bdca7022d6523b210b69f72", size = 797753, upload-time = "2025-07-31T00:20:27.919Z" },
+ { url = "https://files.pythonhosted.org/packages/86/38/3e3dc953d13998fa047e9a2414b556201dbd7147034fbac129392363253b/regex-2025.7.34-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:98d0ce170fcde1a03b5df19c5650db22ab58af375aaa6ff07978a85c9f250f0e", size = 863263, upload-time = "2025-07-31T00:20:29.803Z" },
+ { url = "https://files.pythonhosted.org/packages/68/e5/3ff66b29dde12f5b874dda2d9dec7245c2051f2528d8c2a797901497f140/regex-2025.7.34-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d72765a4bff8c43711d5b0f5b452991a9947853dfa471972169b3cc0ba1d0751", size = 910103, upload-time = "2025-07-31T00:20:31.313Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/fe/14176f2182125977fba3711adea73f472a11f3f9288c1317c59cd16ad5e6/regex-2025.7.34-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4494f8fd95a77eb434039ad8460e64d57baa0434f1395b7da44015bef650d0e4", size = 801709, upload-time = "2025-07-31T00:20:33.323Z" },
+ { url = "https://files.pythonhosted.org/packages/5a/0d/80d4e66ed24f1ba876a9e8e31b709f9fd22d5c266bf5f3ab3c1afe683d7d/regex-2025.7.34-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:4f42b522259c66e918a0121a12429b2abcf696c6f967fa37bdc7b72e61469f98", size = 786726, upload-time = "2025-07-31T00:20:35.252Z" },
+ { url = "https://files.pythonhosted.org/packages/12/75/c3ebb30e04a56c046f5c85179dc173818551037daae2c0c940c7b19152cb/regex-2025.7.34-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:aaef1f056d96a0a5d53ad47d019d5b4c66fe4be2da87016e0d43b7242599ffc7", size = 857306, upload-time = "2025-07-31T00:20:37.12Z" },
+ { url = "https://files.pythonhosted.org/packages/b1/b2/a4dc5d8b14f90924f27f0ac4c4c4f5e195b723be98adecc884f6716614b6/regex-2025.7.34-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:656433e5b7dccc9bc0da6312da8eb897b81f5e560321ec413500e5367fcd5d47", size = 848494, upload-time = "2025-07-31T00:20:38.818Z" },
+ { url = "https://files.pythonhosted.org/packages/0d/21/9ac6e07a4c5e8646a90b56b61f7e9dac11ae0747c857f91d3d2bc7c241d9/regex-2025.7.34-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:e91eb2c62c39705e17b4d42d4b86c4e86c884c0d15d9c5a47d0835f8387add8e", size = 787850, upload-time = "2025-07-31T00:20:40.478Z" },
+ { url = "https://files.pythonhosted.org/packages/be/6c/d51204e28e7bc54f9a03bb799b04730d7e54ff2718862b8d4e09e7110a6a/regex-2025.7.34-cp314-cp314-win32.whl", hash = "sha256:f978ddfb6216028c8f1d6b0f7ef779949498b64117fc35a939022f67f810bdcb", size = 269730, upload-time = "2025-07-31T00:20:42.253Z" },
+ { url = "https://files.pythonhosted.org/packages/74/52/a7e92d02fa1fdef59d113098cb9f02c5d03289a0e9f9e5d4d6acccd10677/regex-2025.7.34-cp314-cp314-win_amd64.whl", hash = "sha256:4b7dc33b9b48fb37ead12ffc7bdb846ac72f99a80373c4da48f64b373a7abeae", size = 278640, upload-time = "2025-07-31T00:20:44.42Z" },
+ { url = "https://files.pythonhosted.org/packages/d1/78/a815529b559b1771080faa90c3ab401730661f99d495ab0071649f139ebd/regex-2025.7.34-cp314-cp314-win_arm64.whl", hash = "sha256:4b8c4d39f451e64809912c82392933d80fe2e4a87eeef8859fcc5380d0173c64", size = 271757, upload-time = "2025-07-31T00:20:46.355Z" },
+]
+
+[[package]]
+name = "requests"
+version = "2.31.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "certifi" },
+ { name = "charset-normalizer" },
+ { name = "idna" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/9d/be/10918a2eac4ae9f02f6cfe6414b7a155ccd8f7f9d4380d62fd5b955065c3/requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1", size = 110794, upload-time = "2023-05-22T15:12:44.175Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f", size = 62574, upload-time = "2023-05-22T15:12:42.313Z" },
+]
+
+[[package]]
+name = "requests-oauthlib"
+version = "2.0.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "oauthlib" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/42/f2/05f29bc3913aea15eb670be136045bf5c5bbf4b99ecb839da9b422bb2c85/requests-oauthlib-2.0.0.tar.gz", hash = "sha256:b3dffaebd884d8cd778494369603a9e7b58d29111bf6b41bdc2dcd87203af4e9", size = 55650, upload-time = "2024-03-22T20:32:29.939Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3b/5d/63d4ae3b9daea098d5d6f5da83984853c1bbacd5dc826764b249fe119d24/requests_oauthlib-2.0.0-py2.py3-none-any.whl", hash = "sha256:7dd8a5c40426b779b0868c404bdef9768deccf22749cde15852df527e6269b36", size = 24179, upload-time = "2024-03-22T20:32:28.055Z" },
+]
+
+[[package]]
+name = "requests-toolbelt"
+version = "1.0.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f3/61/d7545dafb7ac2230c70d38d31cbfe4cc64f7144dc41f6e4e4b78ecd9f5bb/requests-toolbelt-1.0.0.tar.gz", hash = "sha256:7681a0a3d047012b5bdc0ee37d7f8f07ebe76ab08caeccfc3921ce23c88d5bc6", size = 206888, upload-time = "2023-05-01T04:11:33.229Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3f/51/d4db610ef29373b879047326cbf6fa98b6c1969d6f6dc423279de2b1be2c/requests_toolbelt-1.0.0-py2.py3-none-any.whl", hash = "sha256:cccfdd665f0a24fcf4726e690f65639d272bb0637b9b92dfd91a5568ccf6bd06", size = 54481, upload-time = "2023-05-01T04:11:28.427Z" },
+]
+
+[[package]]
+name = "responses"
+version = "0.25.8"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pyyaml" },
+ { name = "requests" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/0e/95/89c054ad70bfef6da605338b009b2e283485835351a9935c7bfbfaca7ffc/responses-0.25.8.tar.gz", hash = "sha256:9374d047a575c8f781b94454db5cab590b6029505f488d12899ddb10a4af1cf4", size = 79320, upload-time = "2025-08-08T19:01:46.709Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/1c/4c/cc276ce57e572c102d9542d383b2cfd551276581dc60004cb94fe8774c11/responses-0.25.8-py3-none-any.whl", hash = "sha256:0c710af92def29c8352ceadff0c3fe340ace27cf5af1bbe46fb71275bcd2831c", size = 34769, upload-time = "2025-08-08T19:01:45.018Z" },
+]
+
+[[package]]
+name = "rpds-py"
+version = "0.27.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/1e/d9/991a0dee12d9fc53ed027e26a26a64b151d77252ac477e22666b9688bc16/rpds_py-0.27.0.tar.gz", hash = "sha256:8b23cf252f180cda89220b378d917180f29d313cd6a07b2431c0d3b776aae86f", size = 27420, upload-time = "2025-08-07T08:26:39.624Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/cd/17/e67309ca1ac993fa1888a0d9b2f5ccc1f67196ace32e76c9f8e1dbbbd50c/rpds_py-0.27.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:19c990fdf5acecbf0623e906ae2e09ce1c58947197f9bced6bbd7482662231c4", size = 362611, upload-time = "2025-08-07T08:23:44.773Z" },
+ { url = "https://files.pythonhosted.org/packages/93/2e/28c2fb84aa7aa5d75933d1862d0f7de6198ea22dfd9a0cca06e8a4e7509e/rpds_py-0.27.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:6c27a7054b5224710fcfb1a626ec3ff4f28bcb89b899148c72873b18210e446b", size = 347680, upload-time = "2025-08-07T08:23:46.014Z" },
+ { url = "https://files.pythonhosted.org/packages/44/3e/9834b4c8f4f5fe936b479e623832468aa4bd6beb8d014fecaee9eac6cdb1/rpds_py-0.27.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:09965b314091829b378b60607022048953e25f0b396c2b70e7c4c81bcecf932e", size = 384600, upload-time = "2025-08-07T08:23:48Z" },
+ { url = "https://files.pythonhosted.org/packages/19/78/744123c7b38865a965cd9e6f691fde7ef989a00a256fa8bf15b75240d12f/rpds_py-0.27.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:14f028eb47f59e9169bfdf9f7ceafd29dd64902141840633683d0bad5b04ff34", size = 400697, upload-time = "2025-08-07T08:23:49.407Z" },
+ { url = "https://files.pythonhosted.org/packages/32/97/3c3d32fe7daee0a1f1a678b6d4dfb8c4dcf88197fa2441f9da7cb54a8466/rpds_py-0.27.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6168af0be75bba990a39f9431cdfae5f0ad501f4af32ae62e8856307200517b8", size = 517781, upload-time = "2025-08-07T08:23:50.557Z" },
+ { url = "https://files.pythonhosted.org/packages/b2/be/28f0e3e733680aa13ecec1212fc0f585928a206292f14f89c0b8a684cad1/rpds_py-0.27.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ab47fe727c13c09d0e6f508e3a49e545008e23bf762a245b020391b621f5b726", size = 406449, upload-time = "2025-08-07T08:23:51.732Z" },
+ { url = "https://files.pythonhosted.org/packages/95/ae/5d15c83e337c082d0367053baeb40bfba683f42459f6ebff63a2fd7e5518/rpds_py-0.27.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fa01b3d5e3b7d97efab65bd3d88f164e289ec323a8c033c5c38e53ee25c007e", size = 386150, upload-time = "2025-08-07T08:23:52.822Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/65/944e95f95d5931112829e040912b25a77b2e7ed913ea5fe5746aa5c1ce75/rpds_py-0.27.0-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:6c135708e987f46053e0a1246a206f53717f9fadfba27174a9769ad4befba5c3", size = 406100, upload-time = "2025-08-07T08:23:54.339Z" },
+ { url = "https://files.pythonhosted.org/packages/21/a4/1664b83fae02894533cd11dc0b9f91d673797c2185b7be0f7496107ed6c5/rpds_py-0.27.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:fc327f4497b7087d06204235199daf208fd01c82d80465dc5efa4ec9df1c5b4e", size = 421345, upload-time = "2025-08-07T08:23:55.832Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/26/b7303941c2b0823bfb34c71378249f8beedce57301f400acb04bb345d025/rpds_py-0.27.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:7e57906e38583a2cba67046a09c2637e23297618dc1f3caddbc493f2be97c93f", size = 561891, upload-time = "2025-08-07T08:23:56.951Z" },
+ { url = "https://files.pythonhosted.org/packages/9b/c8/48623d64d4a5a028fa99576c768a6159db49ab907230edddc0b8468b998b/rpds_py-0.27.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:0f4f69d7a4300fbf91efb1fb4916421bd57804c01ab938ab50ac9c4aa2212f03", size = 591756, upload-time = "2025-08-07T08:23:58.146Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/51/18f62617e8e61cc66334c9fb44b1ad7baae3438662098efbc55fb3fda453/rpds_py-0.27.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b4c4fbbcff474e1e5f38be1bf04511c03d492d42eec0babda5d03af3b5589374", size = 557088, upload-time = "2025-08-07T08:23:59.6Z" },
+ { url = "https://files.pythonhosted.org/packages/bd/4c/e84c3a276e2496a93d245516be6b49e20499aa8ca1c94d59fada0d79addc/rpds_py-0.27.0-cp312-cp312-win32.whl", hash = "sha256:27bac29bbbf39601b2aab474daf99dbc8e7176ca3389237a23944b17f8913d97", size = 221926, upload-time = "2025-08-07T08:24:00.695Z" },
+ { url = "https://files.pythonhosted.org/packages/83/89/9d0fbcef64340db0605eb0a0044f258076f3ae0a3b108983b2c614d96212/rpds_py-0.27.0-cp312-cp312-win_amd64.whl", hash = "sha256:8a06aa1197ec0281eb1d7daf6073e199eb832fe591ffa329b88bae28f25f5fe5", size = 233235, upload-time = "2025-08-07T08:24:01.846Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/b0/e177aa9f39cbab060f96de4a09df77d494f0279604dc2f509263e21b05f9/rpds_py-0.27.0-cp312-cp312-win_arm64.whl", hash = "sha256:e14aab02258cb776a108107bd15f5b5e4a1bbaa61ef33b36693dfab6f89d54f9", size = 223315, upload-time = "2025-08-07T08:24:03.337Z" },
+ { url = "https://files.pythonhosted.org/packages/81/d2/dfdfd42565a923b9e5a29f93501664f5b984a802967d48d49200ad71be36/rpds_py-0.27.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:443d239d02d9ae55b74015234f2cd8eb09e59fbba30bf60baeb3123ad4c6d5ff", size = 362133, upload-time = "2025-08-07T08:24:04.508Z" },
+ { url = "https://files.pythonhosted.org/packages/ac/4a/0a2e2460c4b66021d349ce9f6331df1d6c75d7eea90df9785d333a49df04/rpds_py-0.27.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:b8a7acf04fda1f30f1007f3cc96d29d8cf0a53e626e4e1655fdf4eabc082d367", size = 347128, upload-time = "2025-08-07T08:24:05.695Z" },
+ { url = "https://files.pythonhosted.org/packages/35/8d/7d1e4390dfe09d4213b3175a3f5a817514355cb3524593380733204f20b9/rpds_py-0.27.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9d0f92b78cfc3b74a42239fdd8c1266f4715b573204c234d2f9fc3fc7a24f185", size = 384027, upload-time = "2025-08-07T08:24:06.841Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/65/78499d1a62172891c8cd45de737b2a4b84a414b6ad8315ab3ac4945a5b61/rpds_py-0.27.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:ce4ed8e0c7dbc5b19352b9c2c6131dd23b95fa8698b5cdd076307a33626b72dc", size = 399973, upload-time = "2025-08-07T08:24:08.143Z" },
+ { url = "https://files.pythonhosted.org/packages/10/a1/1c67c1d8cc889107b19570bb01f75cf49852068e95e6aee80d22915406fc/rpds_py-0.27.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:fde355b02934cc6b07200cc3b27ab0c15870a757d1a72fd401aa92e2ea3c6bfe", size = 515295, upload-time = "2025-08-07T08:24:09.711Z" },
+ { url = "https://files.pythonhosted.org/packages/df/27/700ec88e748436b6c7c4a2262d66e80f8c21ab585d5e98c45e02f13f21c0/rpds_py-0.27.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:13bbc4846ae4c993f07c93feb21a24d8ec637573d567a924b1001e81c8ae80f9", size = 406737, upload-time = "2025-08-07T08:24:11.182Z" },
+ { url = "https://files.pythonhosted.org/packages/33/cc/6b0ee8f0ba3f2df2daac1beda17fde5cf10897a7d466f252bd184ef20162/rpds_py-0.27.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be0744661afbc4099fef7f4e604e7f1ea1be1dd7284f357924af12a705cc7d5c", size = 385898, upload-time = "2025-08-07T08:24:12.798Z" },
+ { url = "https://files.pythonhosted.org/packages/e8/7e/c927b37d7d33c0a0ebf249cc268dc2fcec52864c1b6309ecb960497f2285/rpds_py-0.27.0-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:069e0384a54f427bd65d7fda83b68a90606a3835901aaff42185fcd94f5a9295", size = 405785, upload-time = "2025-08-07T08:24:14.906Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/d2/8ed50746d909dcf402af3fa58b83d5a590ed43e07251d6b08fad1a535ba6/rpds_py-0.27.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4bc262ace5a1a7dc3e2eac2fa97b8257ae795389f688b5adf22c5db1e2431c43", size = 419760, upload-time = "2025-08-07T08:24:16.129Z" },
+ { url = "https://files.pythonhosted.org/packages/d3/60/2b2071aee781cb3bd49f94d5d35686990b925e9b9f3e3d149235a6f5d5c1/rpds_py-0.27.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:2fe6e18e5c8581f0361b35ae575043c7029d0a92cb3429e6e596c2cdde251432", size = 561201, upload-time = "2025-08-07T08:24:17.645Z" },
+ { url = "https://files.pythonhosted.org/packages/98/1f/27b67304272521aaea02be293fecedce13fa351a4e41cdb9290576fc6d81/rpds_py-0.27.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d93ebdb82363d2e7bec64eecdc3632b59e84bd270d74fe5be1659f7787052f9b", size = 591021, upload-time = "2025-08-07T08:24:18.999Z" },
+ { url = "https://files.pythonhosted.org/packages/db/9b/a2fadf823164dd085b1f894be6443b0762a54a7af6f36e98e8fcda69ee50/rpds_py-0.27.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:0954e3a92e1d62e83a54ea7b3fdc9efa5d61acef8488a8a3d31fdafbfb00460d", size = 556368, upload-time = "2025-08-07T08:24:20.54Z" },
+ { url = "https://files.pythonhosted.org/packages/24/f3/6d135d46a129cda2e3e6d4c5e91e2cc26ea0428c6cf152763f3f10b6dd05/rpds_py-0.27.0-cp313-cp313-win32.whl", hash = "sha256:2cff9bdd6c7b906cc562a505c04a57d92e82d37200027e8d362518df427f96cd", size = 221236, upload-time = "2025-08-07T08:24:22.144Z" },
+ { url = "https://files.pythonhosted.org/packages/c5/44/65d7494f5448ecc755b545d78b188440f81da98b50ea0447ab5ebfdf9bd6/rpds_py-0.27.0-cp313-cp313-win_amd64.whl", hash = "sha256:dc79d192fb76fc0c84f2c58672c17bbbc383fd26c3cdc29daae16ce3d927e8b2", size = 232634, upload-time = "2025-08-07T08:24:23.642Z" },
+ { url = "https://files.pythonhosted.org/packages/70/d9/23852410fadab2abb611733933401de42a1964ce6600a3badae35fbd573e/rpds_py-0.27.0-cp313-cp313-win_arm64.whl", hash = "sha256:5b3a5c8089eed498a3af23ce87a80805ff98f6ef8f7bdb70bd1b7dae5105f6ac", size = 222783, upload-time = "2025-08-07T08:24:25.098Z" },
+ { url = "https://files.pythonhosted.org/packages/15/75/03447917f78512b34463f4ef11066516067099a0c466545655503bed0c77/rpds_py-0.27.0-cp313-cp313t-macosx_10_12_x86_64.whl", hash = "sha256:90fb790138c1a89a2e58c9282fe1089638401f2f3b8dddd758499041bc6e0774", size = 359154, upload-time = "2025-08-07T08:24:26.249Z" },
+ { url = "https://files.pythonhosted.org/packages/6b/fc/4dac4fa756451f2122ddaf136e2c6aeb758dc6fdbe9ccc4bc95c98451d50/rpds_py-0.27.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:010c4843a3b92b54373e3d2291a7447d6c3fc29f591772cc2ea0e9f5c1da434b", size = 343909, upload-time = "2025-08-07T08:24:27.405Z" },
+ { url = "https://files.pythonhosted.org/packages/7b/81/723c1ed8e6f57ed9d8c0c07578747a2d3d554aaefc1ab89f4e42cfeefa07/rpds_py-0.27.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c9ce7a9e967afc0a2af7caa0d15a3e9c1054815f73d6a8cb9225b61921b419bd", size = 379340, upload-time = "2025-08-07T08:24:28.714Z" },
+ { url = "https://files.pythonhosted.org/packages/98/16/7e3740413de71818ce1997df82ba5f94bae9fff90c0a578c0e24658e6201/rpds_py-0.27.0-cp313-cp313t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:aa0bf113d15e8abdfee92aa4db86761b709a09954083afcb5bf0f952d6065fdb", size = 391655, upload-time = "2025-08-07T08:24:30.223Z" },
+ { url = "https://files.pythonhosted.org/packages/e0/63/2a9f510e124d80660f60ecce07953f3f2d5f0b96192c1365443859b9c87f/rpds_py-0.27.0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:eb91d252b35004a84670dfeafadb042528b19842a0080d8b53e5ec1128e8f433", size = 513017, upload-time = "2025-08-07T08:24:31.446Z" },
+ { url = "https://files.pythonhosted.org/packages/2c/4e/cf6ff311d09776c53ea1b4f2e6700b9d43bb4e99551006817ade4bbd6f78/rpds_py-0.27.0-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:db8a6313dbac934193fc17fe7610f70cd8181c542a91382531bef5ed785e5615", size = 402058, upload-time = "2025-08-07T08:24:32.613Z" },
+ { url = "https://files.pythonhosted.org/packages/88/11/5e36096d474cb10f2a2d68b22af60a3bc4164fd8db15078769a568d9d3ac/rpds_py-0.27.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ce96ab0bdfcef1b8c371ada2100767ace6804ea35aacce0aef3aeb4f3f499ca8", size = 383474, upload-time = "2025-08-07T08:24:33.767Z" },
+ { url = "https://files.pythonhosted.org/packages/db/a2/3dff02805b06058760b5eaa6d8cb8db3eb3e46c9e452453ad5fc5b5ad9fe/rpds_py-0.27.0-cp313-cp313t-manylinux_2_31_riscv64.whl", hash = "sha256:7451ede3560086abe1aa27dcdcf55cd15c96b56f543fb12e5826eee6f721f858", size = 400067, upload-time = "2025-08-07T08:24:35.021Z" },
+ { url = "https://files.pythonhosted.org/packages/67/87/eed7369b0b265518e21ea836456a4ed4a6744c8c12422ce05bce760bb3cf/rpds_py-0.27.0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:32196b5a99821476537b3f7732432d64d93a58d680a52c5e12a190ee0135d8b5", size = 412085, upload-time = "2025-08-07T08:24:36.267Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/48/f50b2ab2fbb422fbb389fe296e70b7a6b5ea31b263ada5c61377e710a924/rpds_py-0.27.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:a029be818059870664157194e46ce0e995082ac49926f1423c1f058534d2aaa9", size = 555928, upload-time = "2025-08-07T08:24:37.573Z" },
+ { url = "https://files.pythonhosted.org/packages/98/41/b18eb51045d06887666c3560cd4bbb6819127b43d758f5adb82b5f56f7d1/rpds_py-0.27.0-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:3841f66c1ffdc6cebce8aed64e36db71466f1dc23c0d9a5592e2a782a3042c79", size = 585527, upload-time = "2025-08-07T08:24:39.391Z" },
+ { url = "https://files.pythonhosted.org/packages/be/03/a3dd6470fc76499959b00ae56295b76b4bdf7c6ffc60d62006b1217567e1/rpds_py-0.27.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:42894616da0fc0dcb2ec08a77896c3f56e9cb2f4b66acd76fc8992c3557ceb1c", size = 554211, upload-time = "2025-08-07T08:24:40.6Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/d1/ee5fd1be395a07423ac4ca0bcc05280bf95db2b155d03adefeb47d5ebf7e/rpds_py-0.27.0-cp313-cp313t-win32.whl", hash = "sha256:b1fef1f13c842a39a03409e30ca0bf87b39a1e2a305a9924deadb75a43105d23", size = 216624, upload-time = "2025-08-07T08:24:42.204Z" },
+ { url = "https://files.pythonhosted.org/packages/1c/94/4814c4c858833bf46706f87349c37ca45e154da7dbbec9ff09f1abeb08cc/rpds_py-0.27.0-cp313-cp313t-win_amd64.whl", hash = "sha256:183f5e221ba3e283cd36fdfbe311d95cd87699a083330b4f792543987167eff1", size = 230007, upload-time = "2025-08-07T08:24:43.329Z" },
+ { url = "https://files.pythonhosted.org/packages/0e/a5/8fffe1c7dc7c055aa02df310f9fb71cfc693a4d5ccc5de2d3456ea5fb022/rpds_py-0.27.0-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:f3cd110e02c5bf17d8fb562f6c9df5c20e73029d587cf8602a2da6c5ef1e32cb", size = 362595, upload-time = "2025-08-07T08:24:44.478Z" },
+ { url = "https://files.pythonhosted.org/packages/bc/c7/4e4253fd2d4bb0edbc0b0b10d9f280612ca4f0f990e3c04c599000fe7d71/rpds_py-0.27.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:8d0e09cf4863c74106b5265c2c310f36146e2b445ff7b3018a56799f28f39f6f", size = 347252, upload-time = "2025-08-07T08:24:45.678Z" },
+ { url = "https://files.pythonhosted.org/packages/f3/c8/3d1a954d30f0174dd6baf18b57c215da03cf7846a9d6e0143304e784cddc/rpds_py-0.27.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:64f689ab822f9b5eb6dfc69893b4b9366db1d2420f7db1f6a2adf2a9ca15ad64", size = 384886, upload-time = "2025-08-07T08:24:46.86Z" },
+ { url = "https://files.pythonhosted.org/packages/e0/52/3c5835f2df389832b28f9276dd5395b5a965cea34226e7c88c8fbec2093c/rpds_py-0.27.0-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e36c80c49853b3ffda7aa1831bf175c13356b210c73128c861f3aa93c3cc4015", size = 399716, upload-time = "2025-08-07T08:24:48.174Z" },
+ { url = "https://files.pythonhosted.org/packages/40/73/176e46992461a1749686a2a441e24df51ff86b99c2d34bf39f2a5273b987/rpds_py-0.27.0-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6de6a7f622860af0146cb9ee148682ff4d0cea0b8fd3ad51ce4d40efb2f061d0", size = 517030, upload-time = "2025-08-07T08:24:49.52Z" },
+ { url = "https://files.pythonhosted.org/packages/79/2a/7266c75840e8c6e70effeb0d38922a45720904f2cd695e68a0150e5407e2/rpds_py-0.27.0-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4045e2fc4b37ec4b48e8907a5819bdd3380708c139d7cc358f03a3653abedb89", size = 408448, upload-time = "2025-08-07T08:24:50.727Z" },
+ { url = "https://files.pythonhosted.org/packages/e6/5f/a7efc572b8e235093dc6cf39f4dbc8a7f08e65fdbcec7ff4daeb3585eef1/rpds_py-0.27.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9da162b718b12c4219eeeeb68a5b7552fbc7aadedf2efee440f88b9c0e54b45d", size = 387320, upload-time = "2025-08-07T08:24:52.004Z" },
+ { url = "https://files.pythonhosted.org/packages/a2/eb/9ff6bc92efe57cf5a2cb74dee20453ba444b6fdc85275d8c99e0d27239d1/rpds_py-0.27.0-cp314-cp314-manylinux_2_31_riscv64.whl", hash = "sha256:0665be515767dc727ffa5f74bd2ef60b0ff85dad6bb8f50d91eaa6b5fb226f51", size = 407414, upload-time = "2025-08-07T08:24:53.664Z" },
+ { url = "https://files.pythonhosted.org/packages/fb/bd/3b9b19b00d5c6e1bd0f418c229ab0f8d3b110ddf7ec5d9d689ef783d0268/rpds_py-0.27.0-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:203f581accef67300a942e49a37d74c12ceeef4514874c7cede21b012613ca2c", size = 420766, upload-time = "2025-08-07T08:24:55.917Z" },
+ { url = "https://files.pythonhosted.org/packages/17/6b/521a7b1079ce16258c70805166e3ac6ec4ee2139d023fe07954dc9b2d568/rpds_py-0.27.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7873b65686a6471c0037139aa000d23fe94628e0daaa27b6e40607c90e3f5ec4", size = 562409, upload-time = "2025-08-07T08:24:57.17Z" },
+ { url = "https://files.pythonhosted.org/packages/8b/bf/65db5bfb14ccc55e39de8419a659d05a2a9cd232f0a699a516bb0991da7b/rpds_py-0.27.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:249ab91ceaa6b41abc5f19513cb95b45c6f956f6b89f1fe3d99c81255a849f9e", size = 590793, upload-time = "2025-08-07T08:24:58.388Z" },
+ { url = "https://files.pythonhosted.org/packages/db/b8/82d368b378325191ba7aae8f40f009b78057b598d4394d1f2cdabaf67b3f/rpds_py-0.27.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d2f184336bc1d6abfaaa1262ed42739c3789b1e3a65a29916a615307d22ffd2e", size = 558178, upload-time = "2025-08-07T08:24:59.756Z" },
+ { url = "https://files.pythonhosted.org/packages/f6/ff/f270bddbfbc3812500f8131b1ebbd97afd014cd554b604a3f73f03133a36/rpds_py-0.27.0-cp314-cp314-win32.whl", hash = "sha256:d3c622c39f04d5751408f5b801ecb527e6e0a471b367f420a877f7a660d583f6", size = 222355, upload-time = "2025-08-07T08:25:01.027Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/20/fdab055b1460c02ed356a0e0b0a78c1dd32dc64e82a544f7b31c9ac643dc/rpds_py-0.27.0-cp314-cp314-win_amd64.whl", hash = "sha256:cf824aceaeffff029ccfba0da637d432ca71ab21f13e7f6f5179cd88ebc77a8a", size = 234007, upload-time = "2025-08-07T08:25:02.268Z" },
+ { url = "https://files.pythonhosted.org/packages/4d/a8/694c060005421797a3be4943dab8347c76c2b429a9bef68fb2c87c9e70c7/rpds_py-0.27.0-cp314-cp314-win_arm64.whl", hash = "sha256:86aca1616922b40d8ac1b3073a1ead4255a2f13405e5700c01f7c8d29a03972d", size = 223527, upload-time = "2025-08-07T08:25:03.45Z" },
+ { url = "https://files.pythonhosted.org/packages/1e/f9/77f4c90f79d2c5ca8ce6ec6a76cb4734ee247de6b3a4f337e289e1f00372/rpds_py-0.27.0-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:341d8acb6724c0c17bdf714319c393bb27f6d23d39bc74f94221b3e59fc31828", size = 359469, upload-time = "2025-08-07T08:25:04.648Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/22/b97878d2f1284286fef4172069e84b0b42b546ea7d053e5fb7adb9ac6494/rpds_py-0.27.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:6b96b0b784fe5fd03beffff2b1533dc0d85e92bab8d1b2c24ef3a5dc8fac5669", size = 343960, upload-time = "2025-08-07T08:25:05.863Z" },
+ { url = "https://files.pythonhosted.org/packages/b1/b0/dfd55b5bb480eda0578ae94ef256d3061d20b19a0f5e18c482f03e65464f/rpds_py-0.27.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0c431bfb91478d7cbe368d0a699978050d3b112d7f1d440a41e90faa325557fd", size = 380201, upload-time = "2025-08-07T08:25:07.513Z" },
+ { url = "https://files.pythonhosted.org/packages/28/22/e1fa64e50d58ad2b2053077e3ec81a979147c43428de9e6de68ddf6aff4e/rpds_py-0.27.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:20e222a44ae9f507d0f2678ee3dd0c45ec1e930f6875d99b8459631c24058aec", size = 392111, upload-time = "2025-08-07T08:25:09.149Z" },
+ { url = "https://files.pythonhosted.org/packages/49/f9/43ab7a43e97aedf6cea6af70fdcbe18abbbc41d4ae6cdec1bfc23bbad403/rpds_py-0.27.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:184f0d7b342967f6cda94a07d0e1fae177d11d0b8f17d73e06e36ac02889f303", size = 515863, upload-time = "2025-08-07T08:25:10.431Z" },
+ { url = "https://files.pythonhosted.org/packages/38/9b/9bd59dcc636cd04d86a2d20ad967770bf348f5eb5922a8f29b547c074243/rpds_py-0.27.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a00c91104c173c9043bc46f7b30ee5e6d2f6b1149f11f545580f5d6fdff42c0b", size = 402398, upload-time = "2025-08-07T08:25:11.819Z" },
+ { url = "https://files.pythonhosted.org/packages/71/bf/f099328c6c85667aba6b66fa5c35a8882db06dcd462ea214be72813a0dd2/rpds_py-0.27.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f7a37dd208f0d658e0487522078b1ed68cd6bce20ef4b5a915d2809b9094b410", size = 384665, upload-time = "2025-08-07T08:25:13.194Z" },
+ { url = "https://files.pythonhosted.org/packages/a9/c5/9c1f03121ece6634818490bd3c8be2c82a70928a19de03467fb25a3ae2a8/rpds_py-0.27.0-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:92f3b3ec3e6008a1fe00b7c0946a170f161ac00645cde35e3c9a68c2475e8156", size = 400405, upload-time = "2025-08-07T08:25:14.417Z" },
+ { url = "https://files.pythonhosted.org/packages/b5/b8/e25d54af3e63ac94f0c16d8fe143779fe71ff209445a0c00d0f6984b6b2c/rpds_py-0.27.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:a1b3db5fae5cbce2131b7420a3f83553d4d89514c03d67804ced36161fe8b6b2", size = 413179, upload-time = "2025-08-07T08:25:15.664Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/d1/406b3316433fe49c3021546293a04bc33f1478e3ec7950215a7fce1a1208/rpds_py-0.27.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5355527adaa713ab693cbce7c1e0ec71682f599f61b128cf19d07e5c13c9b1f1", size = 556895, upload-time = "2025-08-07T08:25:17.061Z" },
+ { url = "https://files.pythonhosted.org/packages/5f/bc/3697c0c21fcb9a54d46ae3b735eb2365eea0c2be076b8f770f98e07998de/rpds_py-0.27.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:fcc01c57ce6e70b728af02b2401c5bc853a9e14eb07deda30624374f0aebfe42", size = 585464, upload-time = "2025-08-07T08:25:18.406Z" },
+ { url = "https://files.pythonhosted.org/packages/63/09/ee1bb5536f99f42c839b177d552f6114aa3142d82f49cef49261ed28dbe0/rpds_py-0.27.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:3001013dae10f806380ba739d40dee11db1ecb91684febb8406a87c2ded23dae", size = 555090, upload-time = "2025-08-07T08:25:20.461Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/2c/363eada9e89f7059199d3724135a86c47082cbf72790d6ba2f336d146ddb/rpds_py-0.27.0-cp314-cp314t-win32.whl", hash = "sha256:0f401c369186a5743694dd9fc08cba66cf70908757552e1f714bfc5219c655b5", size = 218001, upload-time = "2025-08-07T08:25:21.761Z" },
+ { url = "https://files.pythonhosted.org/packages/e2/3f/d6c216ed5199c9ef79e2a33955601f454ed1e7420a93b89670133bca5ace/rpds_py-0.27.0-cp314-cp314t-win_amd64.whl", hash = "sha256:8a1dca5507fa1337f75dcd5070218b20bc68cf8844271c923c1b79dfcbc20391", size = 230993, upload-time = "2025-08-07T08:25:23.34Z" },
+]
+
+[[package]]
+name = "rsa"
+version = "4.9.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "pyasn1" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/da/8a/22b7beea3ee0d44b1916c0c1cb0ee3af23b700b6da9f04991899d0c555d4/rsa-4.9.1.tar.gz", hash = "sha256:e7bdbfdb5497da4c07dfd35530e1a902659db6ff241e39d9953cad06ebd0ae75", size = 29034, upload-time = "2025-04-16T09:51:18.218Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/64/8d/0133e4eb4beed9e425d9a98ed6e081a55d195481b7632472be1af08d2f6b/rsa-4.9.1-py3-none-any.whl", hash = "sha256:68635866661c6836b8d39430f97a996acbd61bfa49406748ea243539fe239762", size = 34696, upload-time = "2025-04-16T09:51:17.142Z" },
+]
+
+[[package]]
+name = "s3fs"
+version = "2024.10.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "aiobotocore" },
+ { name = "aiohttp" },
+ { name = "fsspec" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/75/65/4b4c868cff76c036d11dc75dd91e5696dbf16ce626514166f35d5f4a930f/s3fs-2024.10.0.tar.gz", hash = "sha256:58b8c3650f8b99dbedf361543da3533aac8707035a104db5d80b094617ad4a3f", size = 75916, upload-time = "2024-10-21T01:45:49.967Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/99/44/bb9ff095ae7b1b6908480f683b6ca6b71c2105d343a5e5cb25334b01f5fa/s3fs-2024.10.0-py3-none-any.whl", hash = "sha256:7a2025d60d5b1a6025726b3a5e292a8e5aa713abc3b16fd1f81735181f7bb282", size = 29855, upload-time = "2024-10-21T01:45:47.905Z" },
+]
+
+[package.optional-dependencies]
+boto3 = [
+ { name = "aiobotocore", extra = ["boto3"] },
+]
+
+[[package]]
+name = "s3transfer"
+version = "0.11.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/39/24/1390172471d569e281fcfd29b92f2f73774e95972c965d14b6c802ff2352/s3transfer-0.11.3.tar.gz", hash = "sha256:edae4977e3a122445660c7c114bba949f9d191bae3b34a096f18a1c8c354527a", size = 148042, upload-time = "2025-02-26T20:44:57.459Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e4/81/48c41b554a54d75d4407740abb60e3a102ae416284df04d1dbdcbe3dbf24/s3transfer-0.11.3-py3-none-any.whl", hash = "sha256:ca855bdeb885174b5ffa95b9913622459d4ad8e331fc98eb01e6d5eb6a30655d", size = 84246, upload-time = "2025-02-26T20:44:55.509Z" },
+]
+
+[[package]]
+name = "safetensors"
+version = "0.6.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ac/cc/738f3011628920e027a11754d9cae9abec1aed00f7ae860abbf843755233/safetensors-0.6.2.tar.gz", hash = "sha256:43ff2aa0e6fa2dc3ea5524ac7ad93a9839256b8703761e76e2d0b2a3fa4f15d9", size = 197968, upload-time = "2025-08-08T13:13:58.654Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/4d/b1/3f5fd73c039fc87dba3ff8b5d528bfc5a32b597fea8e7a6a4800343a17c7/safetensors-0.6.2-cp38-abi3-macosx_10_12_x86_64.whl", hash = "sha256:9c85ede8ec58f120bad982ec47746981e210492a6db876882aa021446af8ffba", size = 454797, upload-time = "2025-08-08T13:13:52.066Z" },
+ { url = "https://files.pythonhosted.org/packages/8c/c9/bb114c158540ee17907ec470d01980957fdaf87b4aa07914c24eba87b9c6/safetensors-0.6.2-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:d6675cf4b39c98dbd7d940598028f3742e0375a6b4d4277e76beb0c35f4b843b", size = 432206, upload-time = "2025-08-08T13:13:50.931Z" },
+ { url = "https://files.pythonhosted.org/packages/d3/8e/f70c34e47df3110e8e0bb268d90db8d4be8958a54ab0336c9be4fe86dac8/safetensors-0.6.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1d2d2b3ce1e2509c68932ca03ab8f20570920cd9754b05063d4368ee52833ecd", size = 473261, upload-time = "2025-08-08T13:13:41.259Z" },
+ { url = "https://files.pythonhosted.org/packages/2a/f5/be9c6a7c7ef773e1996dc214e73485286df1836dbd063e8085ee1976f9cb/safetensors-0.6.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:93de35a18f46b0f5a6a1f9e26d91b442094f2df02e9fd7acf224cfec4238821a", size = 485117, upload-time = "2025-08-08T13:13:43.506Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/55/23f2d0a2c96ed8665bf17a30ab4ce5270413f4d74b6d87dd663258b9af31/safetensors-0.6.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:89a89b505f335640f9120fac65ddeb83e40f1fd081cb8ed88b505bdccec8d0a1", size = 616154, upload-time = "2025-08-08T13:13:45.096Z" },
+ { url = "https://files.pythonhosted.org/packages/98/c6/affb0bd9ce02aa46e7acddbe087912a04d953d7a4d74b708c91b5806ef3f/safetensors-0.6.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fc4d0d0b937e04bdf2ae6f70cd3ad51328635fe0e6214aa1fc811f3b576b3bda", size = 520713, upload-time = "2025-08-08T13:13:46.25Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/5d/5a514d7b88e310c8b146e2404e0dc161282e78634d9358975fd56dfd14be/safetensors-0.6.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8045db2c872db8f4cbe3faa0495932d89c38c899c603f21e9b6486951a5ecb8f", size = 485835, upload-time = "2025-08-08T13:13:49.373Z" },
+ { url = "https://files.pythonhosted.org/packages/7a/7b/4fc3b2ba62c352b2071bea9cfbad330fadda70579f617506ae1a2f129cab/safetensors-0.6.2-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:81e67e8bab9878bb568cffbc5f5e655adb38d2418351dc0859ccac158f753e19", size = 521503, upload-time = "2025-08-08T13:13:47.651Z" },
+ { url = "https://files.pythonhosted.org/packages/5a/50/0057e11fe1f3cead9254315a6c106a16dd4b1a19cd247f7cc6414f6b7866/safetensors-0.6.2-cp38-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:b0e4d029ab0a0e0e4fdf142b194514695b1d7d3735503ba700cf36d0fc7136ce", size = 652256, upload-time = "2025-08-08T13:13:53.167Z" },
+ { url = "https://files.pythonhosted.org/packages/e9/29/473f789e4ac242593ac1656fbece6e1ecd860bb289e635e963667807afe3/safetensors-0.6.2-cp38-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:fa48268185c52bfe8771e46325a1e21d317207bcabcb72e65c6e28e9ffeb29c7", size = 747281, upload-time = "2025-08-08T13:13:54.656Z" },
+ { url = "https://files.pythonhosted.org/packages/68/52/f7324aad7f2df99e05525c84d352dc217e0fa637a4f603e9f2eedfbe2c67/safetensors-0.6.2-cp38-abi3-musllinux_1_2_i686.whl", hash = "sha256:d83c20c12c2d2f465997c51b7ecb00e407e5f94d7dec3ea0cc11d86f60d3fde5", size = 692286, upload-time = "2025-08-08T13:13:55.884Z" },
+ { url = "https://files.pythonhosted.org/packages/ad/fe/cad1d9762868c7c5dc70c8620074df28ebb1a8e4c17d4c0cb031889c457e/safetensors-0.6.2-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:d944cea65fad0ead848b6ec2c37cc0b197194bec228f8020054742190e9312ac", size = 655957, upload-time = "2025-08-08T13:13:57.029Z" },
+ { url = "https://files.pythonhosted.org/packages/59/a7/e2158e17bbe57d104f0abbd95dff60dda916cf277c9f9663b4bf9bad8b6e/safetensors-0.6.2-cp38-abi3-win32.whl", hash = "sha256:cab75ca7c064d3911411461151cb69380c9225798a20e712b102edda2542ddb1", size = 308926, upload-time = "2025-08-08T13:14:01.095Z" },
+ { url = "https://files.pythonhosted.org/packages/2c/c3/c0be1135726618dc1e28d181b8c442403d8dbb9e273fd791de2d4384bcdd/safetensors-0.6.2-cp38-abi3-win_amd64.whl", hash = "sha256:c7b214870df923cbc1593c3faee16bec59ea462758699bd3fee399d00aac072c", size = 320192, upload-time = "2025-08-08T13:13:59.467Z" },
+]
+
+[[package]]
+name = "setuptools"
+version = "80.9.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/18/5d/3bf57dcd21979b887f014ea83c24ae194cfcd12b9e0fda66b957c69d1fca/setuptools-80.9.0.tar.gz", hash = "sha256:f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c", size = 1319958, upload-time = "2025-05-27T00:56:51.443Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772/setuptools-80.9.0-py3-none-any.whl", hash = "sha256:062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922", size = 1201486, upload-time = "2025-05-27T00:56:49.664Z" },
+]
+
+[[package]]
+name = "shapely"
+version = "2.1.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "numpy" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ca/3c/2da625233f4e605155926566c0e7ea8dda361877f48e8b1655e53456f252/shapely-2.1.1.tar.gz", hash = "sha256:500621967f2ffe9642454808009044c21e5b35db89ce69f8a2042c2ffd0e2772", size = 315422, upload-time = "2025-05-19T11:04:41.265Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/fb/64/9544dc07dfe80a2d489060791300827c941c451e2910f7364b19607ea352/shapely-2.1.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:2827365b58bf98efb60affc94a8e01c56dd1995a80aabe4b701465d86dcbba43", size = 1833021, upload-time = "2025-05-19T11:04:08.022Z" },
+ { url = "https://files.pythonhosted.org/packages/07/aa/fb5f545e72e89b6a0f04a0effda144f5be956c9c312c7d4e00dfddbddbcf/shapely-2.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a9c551f7fa7f1e917af2347fe983f21f212863f1d04f08eece01e9c275903fad", size = 1643018, upload-time = "2025-05-19T11:04:09.343Z" },
+ { url = "https://files.pythonhosted.org/packages/03/46/61e03edba81de729f09d880ce7ae5c1af873a0814206bbfb4402ab5c3388/shapely-2.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:78dec4d4fbe7b1db8dc36de3031767e7ece5911fb7782bc9e95c5cdec58fb1e9", size = 2986417, upload-time = "2025-05-19T11:04:10.56Z" },
+ { url = "https://files.pythonhosted.org/packages/1f/1e/83ec268ab8254a446b4178b45616ab5822d7b9d2b7eb6e27cf0b82f45601/shapely-2.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:872d3c0a7b8b37da0e23d80496ec5973c4692920b90de9f502b5beb994bbaaef", size = 3098224, upload-time = "2025-05-19T11:04:11.903Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/44/0c21e7717c243e067c9ef8fa9126de24239f8345a5bba9280f7bb9935959/shapely-2.1.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:2e2b9125ebfbc28ecf5353511de62f75a8515ae9470521c9a693e4bb9fbe0cf1", size = 3925982, upload-time = "2025-05-19T11:04:13.224Z" },
+ { url = "https://files.pythonhosted.org/packages/15/50/d3b4e15fefc103a0eb13d83bad5f65cd6e07a5d8b2ae920e767932a247d1/shapely-2.1.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:4b96cea171b3d7f6786976a0520f178c42792897653ecca0c5422fb1e6946e6d", size = 4089122, upload-time = "2025-05-19T11:04:14.477Z" },
+ { url = "https://files.pythonhosted.org/packages/bd/05/9a68f27fc6110baeedeeebc14fd86e73fa38738c5b741302408fb6355577/shapely-2.1.1-cp312-cp312-win32.whl", hash = "sha256:39dca52201e02996df02e447f729da97cfb6ff41a03cb50f5547f19d02905af8", size = 1522437, upload-time = "2025-05-19T11:04:16.203Z" },
+ { url = "https://files.pythonhosted.org/packages/bc/e9/a4560e12b9338842a1f82c9016d2543eaa084fce30a1ca11991143086b57/shapely-2.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:13d643256f81d55a50013eff6321142781cf777eb6a9e207c2c9e6315ba6044a", size = 1703479, upload-time = "2025-05-19T11:04:18.497Z" },
+ { url = "https://files.pythonhosted.org/packages/71/8e/2bc836437f4b84d62efc1faddce0d4e023a5d990bbddd3c78b2004ebc246/shapely-2.1.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:3004a644d9e89e26c20286d5fdc10f41b1744c48ce910bd1867fdff963fe6c48", size = 1832107, upload-time = "2025-05-19T11:04:19.736Z" },
+ { url = "https://files.pythonhosted.org/packages/12/a2/12c7cae5b62d5d851c2db836eadd0986f63918a91976495861f7c492f4a9/shapely-2.1.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:1415146fa12d80a47d13cfad5310b3c8b9c2aa8c14a0c845c9d3d75e77cb54f6", size = 1642355, upload-time = "2025-05-19T11:04:21.035Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/7e/6d28b43d53fea56de69c744e34c2b999ed4042f7a811dc1bceb876071c95/shapely-2.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:21fcab88b7520820ec16d09d6bea68652ca13993c84dffc6129dc3607c95594c", size = 2968871, upload-time = "2025-05-19T11:04:22.167Z" },
+ { url = "https://files.pythonhosted.org/packages/dd/87/1017c31e52370b2b79e4d29e07cbb590ab9e5e58cf7e2bdfe363765d6251/shapely-2.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e5ce6a5cc52c974b291237a96c08c5592e50f066871704fb5b12be2639d9026a", size = 3080830, upload-time = "2025-05-19T11:04:23.997Z" },
+ { url = "https://files.pythonhosted.org/packages/1d/fe/f4a03d81abd96a6ce31c49cd8aaba970eaaa98e191bd1e4d43041e57ae5a/shapely-2.1.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:04e4c12a45a1d70aeb266618d8cf81a2de9c4df511b63e105b90bfdfb52146de", size = 3908961, upload-time = "2025-05-19T11:04:25.702Z" },
+ { url = "https://files.pythonhosted.org/packages/ef/59/7605289a95a6844056a2017ab36d9b0cb9d6a3c3b5317c1f968c193031c9/shapely-2.1.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6ca74d851ca5264aae16c2b47e96735579686cb69fa93c4078070a0ec845b8d8", size = 4079623, upload-time = "2025-05-19T11:04:27.171Z" },
+ { url = "https://files.pythonhosted.org/packages/bc/4d/9fea036eff2ef4059d30247128b2d67aaa5f0b25e9fc27e1d15cc1b84704/shapely-2.1.1-cp313-cp313-win32.whl", hash = "sha256:fd9130501bf42ffb7e0695b9ea17a27ae8ce68d50b56b6941c7f9b3d3453bc52", size = 1521916, upload-time = "2025-05-19T11:04:28.405Z" },
+ { url = "https://files.pythonhosted.org/packages/12/d9/6d13b8957a17c95794f0c4dfb65ecd0957e6c7131a56ce18d135c1107a52/shapely-2.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:ab8d878687b438a2f4c138ed1a80941c6ab0029e0f4c785ecfe114413b498a97", size = 1702746, upload-time = "2025-05-19T11:04:29.643Z" },
+ { url = "https://files.pythonhosted.org/packages/60/36/b1452e3e7f35f5f6454d96f3be6e2bb87082720ff6c9437ecc215fa79be0/shapely-2.1.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:0c062384316a47f776305ed2fa22182717508ffdeb4a56d0ff4087a77b2a0f6d", size = 1833482, upload-time = "2025-05-19T11:04:30.852Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/ca/8e6f59be0718893eb3e478141285796a923636dc8f086f83e5b0ec0036d0/shapely-2.1.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:4ecf6c196b896e8f1360cc219ed4eee1c1e5f5883e505d449f263bd053fb8c05", size = 1642256, upload-time = "2025-05-19T11:04:32.068Z" },
+ { url = "https://files.pythonhosted.org/packages/ab/78/0053aea449bb1d4503999525fec6232f049abcdc8df60d290416110de943/shapely-2.1.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fb00070b4c4860f6743c600285109c273cca5241e970ad56bb87bef0be1ea3a0", size = 3016614, upload-time = "2025-05-19T11:04:33.7Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/53/36f1b1de1dfafd1b457dcbafa785b298ce1b8a3e7026b79619e708a245d5/shapely-2.1.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d14a9afa5fa980fbe7bf63706fdfb8ff588f638f145a1d9dbc18374b5b7de913", size = 3093542, upload-time = "2025-05-19T11:04:34.952Z" },
+ { url = "https://files.pythonhosted.org/packages/b9/bf/0619f37ceec6b924d84427c88835b61f27f43560239936ff88915c37da19/shapely-2.1.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:b640e390dabde790e3fb947198b466e63223e0a9ccd787da5f07bcb14756c28d", size = 3945961, upload-time = "2025-05-19T11:04:36.32Z" },
+ { url = "https://files.pythonhosted.org/packages/93/c9/20ca4afeb572763b07a7997f00854cb9499df6af85929e93012b189d8917/shapely-2.1.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:69e08bf9697c1b73ec6aa70437db922bafcea7baca131c90c26d59491a9760f9", size = 4089514, upload-time = "2025-05-19T11:04:37.683Z" },
+ { url = "https://files.pythonhosted.org/packages/33/6a/27036a5a560b80012a544366bceafd491e8abb94a8db14047b5346b5a749/shapely-2.1.1-cp313-cp313t-win32.whl", hash = "sha256:ef2d09d5a964cc90c2c18b03566cf918a61c248596998a0301d5b632beadb9db", size = 1540607, upload-time = "2025-05-19T11:04:38.925Z" },
+ { url = "https://files.pythonhosted.org/packages/ea/f1/5e9b3ba5c7aa7ebfaf269657e728067d16a7c99401c7973ddf5f0cf121bd/shapely-2.1.1-cp313-cp313t-win_amd64.whl", hash = "sha256:8cb8f17c377260452e9d7720eeaf59082c5f8ea48cf104524d953e5d36d4bdb7", size = 1723061, upload-time = "2025-05-19T11:04:40.082Z" },
+]
+
+[[package]]
+name = "simple-websocket"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "wsproto" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/b0/d4/bfa032f961103eba93de583b161f0e6a5b63cebb8f2c7d0c6e6efe1e3d2e/simple_websocket-1.1.0.tar.gz", hash = "sha256:7939234e7aa067c534abdab3a9ed933ec9ce4691b0713c78acb195560aa52ae4", size = 17300, upload-time = "2024-10-10T22:39:31.412Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/52/59/0782e51887ac6b07ffd1570e0364cf901ebc36345fea669969d2084baebb/simple_websocket-1.1.0-py3-none-any.whl", hash = "sha256:4af6069630a38ed6c561010f0e11a5bc0d4ca569b36306eb257cd9a192497c8c", size = 13842, upload-time = "2024-10-10T22:39:29.645Z" },
+]
+
+[[package]]
+name = "singleton-decorator"
+version = "1.0.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/33/98/a8b5c919bee1152a9a1afd82014431f8db5882699754de50d1b3aba4d136/singleton-decorator-1.0.0.tar.gz", hash = "sha256:1a90ad8a8a738be591c9c167fdd677c5d4a43d1bc6b1c128227be1c5e03bee07", size = 2791, upload-time = "2017-08-10T19:52:45.903Z" }
+
+[[package]]
+name = "six"
+version = "1.17.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },
+]
+
+[[package]]
+name = "sniffio"
+version = "1.3.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372, upload-time = "2024-02-25T23:20:04.057Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235, upload-time = "2024-02-25T23:20:01.196Z" },
+]
+
+[[package]]
+name = "snowflake-connector-python"
+version = "3.14.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "asn1crypto" },
+ { name = "boto3" },
+ { name = "botocore" },
+ { name = "certifi" },
+ { name = "cffi" },
+ { name = "charset-normalizer" },
+ { name = "cryptography" },
+ { name = "filelock" },
+ { name = "idna" },
+ { name = "packaging" },
+ { name = "platformdirs" },
+ { name = "pyjwt" },
+ { name = "pyopenssl" },
+ { name = "pytz" },
+ { name = "requests" },
+ { name = "sortedcontainers" },
+ { name = "tomlkit" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/13/bf/7c765991c79d40bde324961ec75b67ba6c00c2491ec894e89c199de5bd20/snowflake_connector_python-3.14.1.tar.gz", hash = "sha256:5ff7a9f1582d1583f86e1c181d29b3ee56e7e6163d14209fc8bf34ae2e234986", size = 772678, upload-time = "2025-04-21T22:06:11.825Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/48/13/126b2c1825f4149d2b9ae39c6a4700224158490725845fbde1d397c59c1c/snowflake_connector_python-3.14.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7f0505a9ff3b00bb476078b8f642da6fea303022b997331c522eb02b80ad129f", size = 987827, upload-time = "2025-04-21T22:06:20.927Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/22/bababb1c5b7a98b604d2b0899274cf6803427409fe62d609e58b1a9ef741/snowflake_connector_python-3.14.1-cp312-cp312-macosx_11_0_x86_64.whl", hash = "sha256:bf3ca3c1403f4d8cad92f597571c334015fc7be2a917b4e6eb75a66517404577", size = 999123, upload-time = "2025-04-21T22:06:22.319Z" },
+ { url = "https://files.pythonhosted.org/packages/48/83/aae4f574024c81be41e8b3afe65403ab1e4581044d90e8942b2cc02dee19/snowflake_connector_python-3.14.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2cc908f9fd4abf354fad7c5b69557a1da229196f7554126e7aef0441db56c75f", size = 2601753, upload-time = "2025-04-21T22:05:59.668Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/63/e000afe88b217413a84bef6123d49a5931e9073ba2efb215b29dffdd5692/snowflake_connector_python-3.14.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:40dab3a11cee219073e5a5bda2aa2d6b2b4fc1a7267d934466e20ea6cfa4db6b", size = 2625995, upload-time = "2025-04-21T22:06:01.624Z" },
+ { url = "https://files.pythonhosted.org/packages/30/9f/aefda344599d45ee5bafdf9bcc2279dbc7e21c2cfcc0fb574a41840613a9/snowflake_connector_python-3.14.1-cp312-cp312-win_amd64.whl", hash = "sha256:079bd59de5702fdce9a3d0fc67061f7fbb959599d5887ebaf9f0828c172f47de", size = 946534, upload-time = "2025-04-21T22:06:33.601Z" },
+ { url = "https://files.pythonhosted.org/packages/b5/3e/1fbaa991ae860c24efb8fd55655d147d597917f8bfcc807431fee3bb00d8/snowflake_connector_python-3.14.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:003f87241b95c647d2ddf42d0025ee4a140afe09454d5167c58cf23b18bacf79", size = 988181, upload-time = "2025-04-21T22:06:23.681Z" },
+ { url = "https://files.pythonhosted.org/packages/55/fa/9e9a82987bb1aaf5d635a3a78e7b78b8de97d0aaeff7fc9dbf71a1cc57d1/snowflake_connector_python-3.14.1-cp313-cp313-macosx_11_0_x86_64.whl", hash = "sha256:5724e1874f22a880f28941ae84aec524a210038817971b3080a010fe555fcb47", size = 999537, upload-time = "2025-04-21T22:06:25.576Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/c0/40858301bdf40a7bcbe73e65e8de5f312e6a365d018fe7eebbaf3e9b58da/snowflake_connector_python-3.14.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:39856da1f790f2c4905f69b5ede4f20edc696821e0e5cd6397276ec48b40f3fe", size = 2606746, upload-time = "2025-04-21T22:06:03.537Z" },
+ { url = "https://files.pythonhosted.org/packages/35/e3/bd9e8e2b21b0b4ed16f64ff9ffc1b6380ee06d2674f81e644add0a773b47/snowflake_connector_python-3.14.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62e4b17de6b78b9af831962baf2bae802cc82c6cbd7f3b1302eac983db2411bf", size = 2631293, upload-time = "2025-04-21T22:06:04.95Z" },
+]
+
+[package.optional-dependencies]
+pandas = [
+ { name = "pandas" },
+ { name = "pyarrow" },
+]
+
+[[package]]
+name = "sortedcontainers"
+version = "2.4.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e8/c4/ba2f8066cceb6f23394729afe52f3bf7adec04bf9ed2c820b39e19299111/sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88", size = 30594, upload-time = "2021-05-16T22:03:42.897Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/32/46/9cb0e58b2deb7f82b84065f37f3bffeb12413f947f9388e4cac22c4621ce/sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0", size = 29575, upload-time = "2021-05-16T22:03:41.177Z" },
+]
+
+[[package]]
+name = "soupsieve"
+version = "2.7"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/3f/f4/4a80cd6ef364b2e8b65b15816a843c0980f7a5a2b4dc701fc574952aa19f/soupsieve-2.7.tar.gz", hash = "sha256:ad282f9b6926286d2ead4750552c8a6142bc4c783fd66b0293547c8fe6ae126a", size = 103418, upload-time = "2025-04-20T18:50:08.518Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e7/9c/0e6afc12c269578be5c0c1c9f4b49a8d32770a080260c333ac04cc1c832d/soupsieve-2.7-py3-none-any.whl", hash = "sha256:6e60cc5c1ffaf1cebcc12e8188320b72071e922c2e897f737cadce79ad5d30c4", size = 36677, upload-time = "2025-04-20T18:50:07.196Z" },
+]
+
+[[package]]
+name = "sqlalchemy"
+version = "2.0.42"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "greenlet", marker = "(python_full_version < '3.14' and platform_machine == 'AMD64') or (python_full_version < '3.14' and platform_machine == 'WIN32') or (python_full_version < '3.14' and platform_machine == 'aarch64') or (python_full_version < '3.14' and platform_machine == 'amd64') or (python_full_version < '3.14' and platform_machine == 'ppc64le') or (python_full_version < '3.14' and platform_machine == 'win32') or (python_full_version < '3.14' and platform_machine == 'x86_64')" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/5a/03/a0af991e3a43174d6b83fca4fb399745abceddd1171bdabae48ce877ff47/sqlalchemy-2.0.42.tar.gz", hash = "sha256:160bedd8a5c28765bd5be4dec2d881e109e33b34922e50a3b881a7681773ac5f", size = 9749972, upload-time = "2025-07-29T12:48:09.323Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/61/66/ac31a9821fc70a7376321fb2c70fdd7eadbc06dadf66ee216a22a41d6058/sqlalchemy-2.0.42-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:09637a0872689d3eb71c41e249c6f422e3e18bbd05b4cd258193cfc7a9a50da2", size = 2132203, upload-time = "2025-07-29T13:29:19.291Z" },
+ { url = "https://files.pythonhosted.org/packages/fc/ba/fd943172e017f955d7a8b3a94695265b7114efe4854feaa01f057e8f5293/sqlalchemy-2.0.42-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a3cb3ec67cc08bea54e06b569398ae21623534a7b1b23c258883a7c696ae10df", size = 2120373, upload-time = "2025-07-29T13:29:21.049Z" },
+ { url = "https://files.pythonhosted.org/packages/ea/a2/b5f7d233d063ffadf7e9fff3898b42657ba154a5bec95a96f44cba7f818b/sqlalchemy-2.0.42-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e87e6a5ef6f9d8daeb2ce5918bf5fddecc11cae6a7d7a671fcc4616c47635e01", size = 3317685, upload-time = "2025-07-29T13:26:40.837Z" },
+ { url = "https://files.pythonhosted.org/packages/86/00/fcd8daab13a9119d41f3e485a101c29f5d2085bda459154ba354c616bf4e/sqlalchemy-2.0.42-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0b718011a9d66c0d2f78e1997755cd965f3414563b31867475e9bc6efdc2281d", size = 3326967, upload-time = "2025-07-29T13:22:31.009Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/85/e622a273d648d39d6771157961956991a6d760e323e273d15e9704c30ccc/sqlalchemy-2.0.42-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:16d9b544873fe6486dddbb859501a07d89f77c61d29060bb87d0faf7519b6a4d", size = 3255331, upload-time = "2025-07-29T13:26:42.579Z" },
+ { url = "https://files.pythonhosted.org/packages/3a/a0/2c2338b592c7b0a61feffd005378c084b4c01fabaf1ed5f655ab7bd446f0/sqlalchemy-2.0.42-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:21bfdf57abf72fa89b97dd74d3187caa3172a78c125f2144764a73970810c4ee", size = 3291791, upload-time = "2025-07-29T13:22:32.454Z" },
+ { url = "https://files.pythonhosted.org/packages/41/19/b8a2907972a78285fdce4c880ecaab3c5067eb726882ca6347f7a4bf64f6/sqlalchemy-2.0.42-cp312-cp312-win32.whl", hash = "sha256:78b46555b730a24901ceb4cb901c6b45c9407f8875209ed3c5d6bcd0390a6ed1", size = 2096180, upload-time = "2025-07-29T13:16:08.952Z" },
+ { url = "https://files.pythonhosted.org/packages/48/1f/67a78f3dfd08a2ed1c7be820fe7775944f5126080b5027cc859084f8e223/sqlalchemy-2.0.42-cp312-cp312-win_amd64.whl", hash = "sha256:4c94447a016f36c4da80072e6c6964713b0af3c8019e9c4daadf21f61b81ab53", size = 2123533, upload-time = "2025-07-29T13:16:11.705Z" },
+ { url = "https://files.pythonhosted.org/packages/e9/7e/25d8c28b86730c9fb0e09156f601d7a96d1c634043bf8ba36513eb78887b/sqlalchemy-2.0.42-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:941804f55c7d507334da38133268e3f6e5b0340d584ba0f277dd884197f4ae8c", size = 2127905, upload-time = "2025-07-29T13:29:22.249Z" },
+ { url = "https://files.pythonhosted.org/packages/e5/a1/9d8c93434d1d983880d976400fcb7895a79576bd94dca61c3b7b90b1ed0d/sqlalchemy-2.0.42-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:95d3d06a968a760ce2aa6a5889fefcbdd53ca935735e0768e1db046ec08cbf01", size = 2115726, upload-time = "2025-07-29T13:29:23.496Z" },
+ { url = "https://files.pythonhosted.org/packages/a2/cc/d33646fcc24c87cc4e30a03556b611a4e7bcfa69a4c935bffb923e3c89f4/sqlalchemy-2.0.42-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4cf10396a8a700a0f38ccd220d940be529c8f64435c5d5b29375acab9267a6c9", size = 3246007, upload-time = "2025-07-29T13:26:44.166Z" },
+ { url = "https://files.pythonhosted.org/packages/67/08/4e6c533d4c7f5e7c4cbb6fe8a2c4e813202a40f05700d4009a44ec6e236d/sqlalchemy-2.0.42-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9cae6c2b05326d7c2c7c0519f323f90e0fb9e8afa783c6a05bb9ee92a90d0f04", size = 3250919, upload-time = "2025-07-29T13:22:33.74Z" },
+ { url = "https://files.pythonhosted.org/packages/5c/82/f680e9a636d217aece1b9a8030d18ad2b59b5e216e0c94e03ad86b344af3/sqlalchemy-2.0.42-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f50f7b20677b23cfb35b6afcd8372b2feb348a38e3033f6447ee0704540be894", size = 3180546, upload-time = "2025-07-29T13:26:45.648Z" },
+ { url = "https://files.pythonhosted.org/packages/7d/a2/8c8f6325f153894afa3775584c429cc936353fb1db26eddb60a549d0ff4b/sqlalchemy-2.0.42-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9d88a1c0d66d24e229e3938e1ef16ebdbd2bf4ced93af6eff55225f7465cf350", size = 3216683, upload-time = "2025-07-29T13:22:34.977Z" },
+ { url = "https://files.pythonhosted.org/packages/39/44/3a451d7fa4482a8ffdf364e803ddc2cfcafc1c4635fb366f169ecc2c3b11/sqlalchemy-2.0.42-cp313-cp313-win32.whl", hash = "sha256:45c842c94c9ad546c72225a0c0d1ae8ef3f7c212484be3d429715a062970e87f", size = 2093990, upload-time = "2025-07-29T13:16:13.036Z" },
+ { url = "https://files.pythonhosted.org/packages/4b/9e/9bce34f67aea0251c8ac104f7bdb2229d58fb2e86a4ad8807999c4bee34b/sqlalchemy-2.0.42-cp313-cp313-win_amd64.whl", hash = "sha256:eb9905f7f1e49fd57a7ed6269bc567fcbbdac9feadff20ad6bd7707266a91577", size = 2120473, upload-time = "2025-07-29T13:16:14.502Z" },
+ { url = "https://files.pythonhosted.org/packages/ee/55/ba2546ab09a6adebc521bf3974440dc1d8c06ed342cceb30ed62a8858835/sqlalchemy-2.0.42-py3-none-any.whl", hash = "sha256:defcdff7e661f0043daa381832af65d616e060ddb54d3fe4476f51df7eaa1835", size = 1922072, upload-time = "2025-07-29T13:09:17.061Z" },
+]
+
+[package.optional-dependencies]
+asyncio = [
+ { name = "greenlet" },
+]
+
+[[package]]
+name = "stone"
+version = "3.3.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "ply" },
+ { name = "six" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/99/6f/ef25bbc1aefeb9c905d527f1d3cd3f41f22f40566d33001b8bb14ae0cdaf/stone-3.3.1.tar.gz", hash = "sha256:4ef0397512f609757975f7ec09b35639d72ba7e3e17ce4ddf399578346b4cb50", size = 190888, upload-time = "2022-01-25T21:32:16.729Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5c/92/d0c83f63d3518e5f0b8a311937c31347349ec9a47b209ddc17f7566f58fc/stone-3.3.1-py3-none-any.whl", hash = "sha256:e15866fad249c11a963cce3bdbed37758f2e88c8ff4898616bc0caeb1e216047", size = 162257, upload-time = "2022-01-25T21:32:15.155Z" },
+]
+
+[[package]]
+name = "striprtf"
+version = "0.0.26"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/25/20/3d419008265346452d09e5dadfd5d045b64b40d8fc31af40588e6c76997a/striprtf-0.0.26.tar.gz", hash = "sha256:fdb2bba7ac440072d1c41eab50d8d74ae88f60a8b6575c6e2c7805dc462093aa", size = 6258, upload-time = "2023-07-20T14:30:36.29Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a3/cf/0fea4f4ba3fc2772ac2419278aa9f6964124d4302117d61bc055758e000c/striprtf-0.0.26-py3-none-any.whl", hash = "sha256:8c8f9d32083cdc2e8bfb149455aa1cc5a4e0a035893bedc75db8b73becb3a1bb", size = 6914, upload-time = "2023-07-20T14:30:35.338Z" },
+]
+
+[[package]]
+name = "tenacity"
+version = "9.1.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0a/d4/2b0cd0fe285e14b36db076e78c93766ff1d529d70408bd1d2a5a84f1d929/tenacity-9.1.2.tar.gz", hash = "sha256:1169d376c297e7de388d18b4481760d478b0e99a777cad3a9c86e556f4b697cb", size = 48036, upload-time = "2025-04-02T08:25:09.966Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e5/30/643397144bfbfec6f6ef821f36f33e57d35946c44a2352d3c9f0ae847619/tenacity-9.1.2-py3-none-any.whl", hash = "sha256:f77bf36710d8b73a50b2dd155c97b870017ad21afe6ab300326b0371b3b05138", size = 28248, upload-time = "2025-04-02T08:25:07.678Z" },
+]
+
+[[package]]
+name = "tiktoken"
+version = "0.9.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "regex" },
+ { name = "requests" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/ea/cf/756fedf6981e82897f2d570dd25fa597eb3f4459068ae0572d7e888cfd6f/tiktoken-0.9.0.tar.gz", hash = "sha256:d02a5ca6a938e0490e1ff957bc48c8b078c88cb83977be1625b1fd8aac792c5d", size = 35991, upload-time = "2025-02-14T06:03:01.003Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/cf/e5/21ff33ecfa2101c1bb0f9b6df750553bd873b7fb532ce2cb276ff40b197f/tiktoken-0.9.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:e88f121c1c22b726649ce67c089b90ddda8b9662545a8aeb03cfef15967ddd03", size = 1065073, upload-time = "2025-02-14T06:02:24.768Z" },
+ { url = "https://files.pythonhosted.org/packages/8e/03/a95e7b4863ee9ceec1c55983e4cc9558bcfd8f4f80e19c4f8a99642f697d/tiktoken-0.9.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a6600660f2f72369acb13a57fb3e212434ed38b045fd8cc6cdd74947b4b5d210", size = 1008075, upload-time = "2025-02-14T06:02:26.92Z" },
+ { url = "https://files.pythonhosted.org/packages/40/10/1305bb02a561595088235a513ec73e50b32e74364fef4de519da69bc8010/tiktoken-0.9.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:95e811743b5dfa74f4b227927ed86cbc57cad4df859cb3b643be797914e41794", size = 1140754, upload-time = "2025-02-14T06:02:28.124Z" },
+ { url = "https://files.pythonhosted.org/packages/1b/40/da42522018ca496432ffd02793c3a72a739ac04c3794a4914570c9bb2925/tiktoken-0.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99376e1370d59bcf6935c933cb9ba64adc29033b7e73f5f7569f3aad86552b22", size = 1196678, upload-time = "2025-02-14T06:02:29.845Z" },
+ { url = "https://files.pythonhosted.org/packages/5c/41/1e59dddaae270ba20187ceb8aa52c75b24ffc09f547233991d5fd822838b/tiktoken-0.9.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:badb947c32739fb6ddde173e14885fb3de4d32ab9d8c591cbd013c22b4c31dd2", size = 1259283, upload-time = "2025-02-14T06:02:33.838Z" },
+ { url = "https://files.pythonhosted.org/packages/5b/64/b16003419a1d7728d0d8c0d56a4c24325e7b10a21a9dd1fc0f7115c02f0a/tiktoken-0.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:5a62d7a25225bafed786a524c1b9f0910a1128f4232615bf3f8257a73aaa3b16", size = 894897, upload-time = "2025-02-14T06:02:36.265Z" },
+ { url = "https://files.pythonhosted.org/packages/7a/11/09d936d37f49f4f494ffe660af44acd2d99eb2429d60a57c71318af214e0/tiktoken-0.9.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:2b0e8e05a26eda1249e824156d537015480af7ae222ccb798e5234ae0285dbdb", size = 1064919, upload-time = "2025-02-14T06:02:37.494Z" },
+ { url = "https://files.pythonhosted.org/packages/80/0e/f38ba35713edb8d4197ae602e80837d574244ced7fb1b6070b31c29816e0/tiktoken-0.9.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:27d457f096f87685195eea0165a1807fae87b97b2161fe8c9b1df5bd74ca6f63", size = 1007877, upload-time = "2025-02-14T06:02:39.516Z" },
+ { url = "https://files.pythonhosted.org/packages/fe/82/9197f77421e2a01373e27a79dd36efdd99e6b4115746ecc553318ecafbf0/tiktoken-0.9.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2cf8ded49cddf825390e36dd1ad35cd49589e8161fdcb52aa25f0583e90a3e01", size = 1140095, upload-time = "2025-02-14T06:02:41.791Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/bb/4513da71cac187383541facd0291c4572b03ec23c561de5811781bbd988f/tiktoken-0.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cc156cb314119a8bb9748257a2eaebd5cc0753b6cb491d26694ed42fc7cb3139", size = 1195649, upload-time = "2025-02-14T06:02:43Z" },
+ { url = "https://files.pythonhosted.org/packages/fa/5c/74e4c137530dd8504e97e3a41729b1103a4ac29036cbfd3250b11fd29451/tiktoken-0.9.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:cd69372e8c9dd761f0ab873112aba55a0e3e506332dd9f7522ca466e817b1b7a", size = 1258465, upload-time = "2025-02-14T06:02:45.046Z" },
+ { url = "https://files.pythonhosted.org/packages/de/a8/8f499c179ec900783ffe133e9aab10044481679bb9aad78436d239eee716/tiktoken-0.9.0-cp313-cp313-win_amd64.whl", hash = "sha256:5ea0edb6f83dc56d794723286215918c1cde03712cbbafa0348b33448faf5b95", size = 894669, upload-time = "2025-02-14T06:02:47.341Z" },
+]
+
+[[package]]
+name = "tokenizers"
+version = "0.15.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "huggingface-hub" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c0/44/625db94e91c6196b6574359fa70bfe28e8eabf57a1b894f8f0ec69727fd1/tokenizers-0.15.2.tar.gz", hash = "sha256:e6e9c6e019dd5484be5beafc775ae6c925f4c69a3487040ed09b45e13df2cb91", size = 320256, upload-time = "2024-02-12T02:28:50.62Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ae/ca/ea4b5aa70d4d26f2d05620c265b07b5a249157767c1673f5753b8bfc7db1/tokenizers-0.15.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:f86593c18d2e6248e72fb91c77d413a815153b8ea4e31f7cd443bdf28e467670", size = 2574444, upload-time = "2024-02-12T02:25:27.417Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/99/5a55a9b6e2db274c0969ad57d989d02efae90f9e558983a561c9b2b7ea1a/tokenizers-0.15.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0774bccc6608eca23eb9d620196687c8b2360624619623cf4ba9dc9bd53e8b51", size = 2411608, upload-time = "2024-02-12T02:25:29.74Z" },
+ { url = "https://files.pythonhosted.org/packages/82/cc/29bb3a25c06b90ce82bb20ef074011481de5c44413a1e1eb10cfd93080fb/tokenizers-0.15.2-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:d0222c5b7c9b26c0b4822a82f6a7011de0a9d3060e1da176f66274b70f846b98", size = 3652367, upload-time = "2024-02-12T02:25:32.079Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/ae/f6a974be9b2e1615f3de3cc9e4fc2897a86357400801c58143c67cbbad2e/tokenizers-0.15.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3835738be1de66624fff2f4f6f6684775da4e9c00bde053be7564cbf3545cc66", size = 3529509, upload-time = "2024-02-12T02:25:34.042Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/42/340b91f675b494c4ecc0a256c5dd88b4003dbfde05afff90b970738fdfb4/tokenizers-0.15.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:0143e7d9dcd811855c1ce1ab9bf5d96d29bf5e528fd6c7824d0465741e8c10fd", size = 3396516, upload-time = "2024-02-12T02:25:35.884Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/b2/8a965abc17fff309eb06e98ce429a19a5e04f731a669a6113b9e182f8a79/tokenizers-0.15.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:db35825f6d54215f6b6009a7ff3eedee0848c99a6271c870d2826fbbedf31a38", size = 3918811, upload-time = "2024-02-12T02:25:37.85Z" },
+ { url = "https://files.pythonhosted.org/packages/6c/16/dad7b4aa6e34a395aef7ae7b010d8b5ebefdf3df81510de53d7f17d2f0fc/tokenizers-0.15.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3f5e64b0389a2be47091d8cc53c87859783b837ea1a06edd9d8e04004df55a5c", size = 4025494, upload-time = "2024-02-12T02:25:40.247Z" },
+ { url = "https://files.pythonhosted.org/packages/f6/de/3707df0c1d7bf55e6a4dba724700353bfee8e292fdd8ccfe93416549124d/tokenizers-0.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e0480c452217edd35eca56fafe2029fb4d368b7c0475f8dfa3c5c9c400a7456", size = 3575314, upload-time = "2024-02-12T02:25:42.212Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/dd/7b8da304d152bb46f13bc2ba5bd545480ab6ce39d94a53eef07f7624d235/tokenizers-0.15.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:a33ab881c8fe70474980577e033d0bc9a27b7ab8272896e500708b212995d834", size = 9682779, upload-time = "2024-02-12T02:25:44.027Z" },
+ { url = "https://files.pythonhosted.org/packages/07/aa/66e8a81e07a791ca6ee9d74ee6de1ffbcd3985149f13aeb530bd409baba0/tokenizers-0.15.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a308a607ca9de2c64c1b9ba79ec9a403969715a1b8ba5f998a676826f1a7039d", size = 9995614, upload-time = "2024-02-12T02:25:46.804Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/e1/aed3bc98785c54bd26bf6dd3d2f54cc00de33e8b1f922a23131372eedec8/tokenizers-0.15.2-cp312-none-win32.whl", hash = "sha256:b8fcfa81bcb9447df582c5bc96a031e6df4da2a774b8080d4f02c0c16b42be0b", size = 2011030, upload-time = "2024-02-12T02:25:49.829Z" },
+ { url = "https://files.pythonhosted.org/packages/c9/ea/5800f4941a713b2feed955b6a256aacc1ca68a6699916d2668622c075d38/tokenizers-0.15.2-cp312-none-win_amd64.whl", hash = "sha256:38d7ab43c6825abfc0b661d95f39c7f8af2449364f01d331f3b51c94dcff7221", size = 2180523, upload-time = "2024-02-12T02:25:51.542Z" },
+ { url = "https://files.pythonhosted.org/packages/6d/04/406f35822d785ccdcd740f95ba58515c739b6d57c05dd278ee64c70d1565/tokenizers-0.15.2-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:38bfb0204ff3246ca4d5e726e8cc8403bfc931090151e6eede54d0e0cf162ef0", size = 2574496, upload-time = "2024-02-12T02:25:53.421Z" },
+ { url = "https://files.pythonhosted.org/packages/6c/b4/6cc305767c9b1b97b8f5bc61fc472abf42b24ad39388e8f0c57250a7c145/tokenizers-0.15.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:9c861d35e8286a53e06e9e28d030b5a05bcbf5ac9d7229e561e53c352a85b1fc", size = 2411609, upload-time = "2024-02-12T02:25:55.102Z" },
+ { url = "https://files.pythonhosted.org/packages/6b/6c/ae2437a3e233298a962053c62b943ffabb38627fd6787ff8da62352333fa/tokenizers-0.15.2-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:936bf3842db5b2048eaa53dade907b1160f318e7c90c74bfab86f1e47720bdd6", size = 3652369, upload-time = "2024-02-12T02:25:57.566Z" },
+ { url = "https://files.pythonhosted.org/packages/00/8b/21600349146d9fa4d341c507faf8d11b7292b7f29f8def440b81e65ad1ee/tokenizers-0.15.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:620beacc3373277700d0e27718aa8b25f7b383eb8001fba94ee00aeea1459d89", size = 3529510, upload-time = "2024-02-12T02:25:59.419Z" },
+ { url = "https://files.pythonhosted.org/packages/53/cd/6ffc60fbc5eae02629d736d578a7c5ca5c20b2b84e9866d61a0c6395684a/tokenizers-0.15.2-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2735ecbbf37e52db4ea970e539fd2d450d213517b77745114f92867f3fc246eb", size = 3396516, upload-time = "2024-02-12T02:26:01.263Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/4c/15b66eb6a47dc9345192aa77988655830c1ebd1306d2b894ecd28fbfbbca/tokenizers-0.15.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:473c83c5e2359bb81b0b6fde870b41b2764fcdd36d997485e07e72cc3a62264a", size = 3918812, upload-time = "2024-02-12T02:26:03.628Z" },
+ { url = "https://files.pythonhosted.org/packages/ed/3b/f9df83311475e456473958cce65a3709f07a1d1dd8ed046d4779ec4336c8/tokenizers-0.15.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:968fa1fb3c27398b28a4eca1cbd1e19355c4d3a6007f7398d48826bbe3a0f728", size = 4025495, upload-time = "2024-02-12T02:26:05.707Z" },
+ { url = "https://files.pythonhosted.org/packages/36/ee/2055fbeb590719393d29cea3016491fd3a6da10598541bff256cc3750349/tokenizers-0.15.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:865c60ae6eaebdde7da66191ee9b7db52e542ed8ee9d2c653b6d190a9351b980", size = 3575316, upload-time = "2024-02-12T02:26:08.379Z" },
+ { url = "https://files.pythonhosted.org/packages/93/53/ae4e5e49bdc61849b668263a1a4c398b4e33aea1bb9b0a59c9677bb5266b/tokenizers-0.15.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:7c0d8b52664ab2d4a8d6686eb5effc68b78608a9008f086a122a7b2996befbab", size = 9682779, upload-time = "2024-02-12T02:26:10.808Z" },
+ { url = "https://files.pythonhosted.org/packages/04/c6/8818b867611734889cd8faca1153ec5dbdd59c98e85e5f6980e7be338839/tokenizers-0.15.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:f33dfbdec3784093a9aebb3680d1f91336c56d86cc70ddf88708251da1fe9064", size = 9995614, upload-time = "2024-02-12T02:26:13.907Z" },
+]
+
+[[package]]
+name = "tomlkit"
+version = "0.13.3"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/cc/18/0bbf3884e9eaa38819ebe46a7bd25dcd56b67434402b66a58c4b8e552575/tomlkit-0.13.3.tar.gz", hash = "sha256:430cf247ee57df2b94ee3fbe588e71d362a941ebb545dec29b53961d61add2a1", size = 185207, upload-time = "2025-06-05T07:13:44.947Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bd/75/8539d011f6be8e29f339c42e633aae3cb73bffa95dd0f9adec09b9c58e85/tomlkit-0.13.3-py3-none-any.whl", hash = "sha256:c89c649d79ee40629a9fda55f8ace8c6a1b42deb912b2a8fd8d942ddadb606b0", size = 38901, upload-time = "2025-06-05T07:13:43.546Z" },
+]
+
+[[package]]
+name = "tqdm"
+version = "4.67.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "colorama", marker = "sys_platform == 'win32'" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/a8/4b/29b4ef32e036bb34e4ab51796dd745cdba7ed47ad142a9f4a1eb8e0c744d/tqdm-4.67.1.tar.gz", hash = "sha256:f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2", size = 169737, upload-time = "2024-11-24T20:12:22.481Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d0/30/dc54f88dd4a2b5dc8a0279bdd7270e735851848b762aeb1c1184ed1f6b14/tqdm-4.67.1-py3-none-any.whl", hash = "sha256:26445eca388f82e72884e0d580d5464cd801a3ea01e63e5601bdff9ba6a48de2", size = 78540, upload-time = "2024-11-24T20:12:19.698Z" },
+]
+
+[[package]]
+name = "transformers"
+version = "4.37.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "filelock" },
+ { name = "huggingface-hub" },
+ { name = "numpy" },
+ { name = "packaging" },
+ { name = "pyyaml" },
+ { name = "regex" },
+ { name = "requests" },
+ { name = "safetensors" },
+ { name = "tokenizers" },
+ { name = "tqdm" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d0/78/61795d3a08e17535eee1d91ce448c048e072ac495946b04f49a9caf67f63/transformers-4.37.0.tar.gz", hash = "sha256:5a0fdee36168f751770f7036ce7a8787be14f8b0d8f29806c493b6cb819c6c83", size = 7140982, upload-time = "2024-01-22T11:13:47.192Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3c/45/52133ce6bce49a099cc865599803bf1fad93de887276f728e56848d77a70/transformers-4.37.0-py3-none-any.whl", hash = "sha256:669d4e2c12661e71c464eb18d6a9b9a2c74d4cba0f4648bb9323896bdd046826", size = 8402157, upload-time = "2024-01-22T11:13:41.587Z" },
+]
+
+[[package]]
+name = "typing-extensions"
+version = "4.14.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/98/5a/da40306b885cc8c09109dc2e1abd358d5684b1425678151cdaed4731c822/typing_extensions-4.14.1.tar.gz", hash = "sha256:38b39f4aeeab64884ce9f74c94263ef78f3c22467c8724005483154c26648d36", size = 107673, upload-time = "2025-07-04T13:28:34.16Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b5/00/d631e67a838026495268c2f6884f3711a15a9a2a96cd244fdaea53b823fb/typing_extensions-4.14.1-py3-none-any.whl", hash = "sha256:d1e1e3b58374dc93031d6eda2420a48ea44a36c2b4766a4fdeb3710755731d76", size = 43906, upload-time = "2025-07-04T13:28:32.743Z" },
+]
+
+[[package]]
+name = "typing-inspect"
+version = "0.9.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "mypy-extensions" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/dc/74/1789779d91f1961fa9438e9a8710cdae6bd138c80d7303996933d117264a/typing_inspect-0.9.0.tar.gz", hash = "sha256:b23fc42ff6f6ef6954e4852c1fb512cdd18dbea03134f91f856a95ccc9461f78", size = 13825, upload-time = "2023-05-24T20:25:47.612Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/65/f3/107a22063bf27bdccf2024833d3445f4eea42b2e598abfbd46f6a63b6cb0/typing_inspect-0.9.0-py3-none-any.whl", hash = "sha256:9ee6fc59062311ef8547596ab6b955e1b8aa46242d854bfc78f4f6b0eff35f9f", size = 8827, upload-time = "2023-05-24T20:25:45.287Z" },
+]
+
+[[package]]
+name = "typing-inspection"
+version = "0.4.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/f8/b1/0c11f5058406b3af7609f121aaa6b609744687f1d158b3c3a5bf4cc94238/typing_inspection-0.4.1.tar.gz", hash = "sha256:6ae134cc0203c33377d43188d4064e9b357dba58cff3185f22924610e70a9d28", size = 75726, upload-time = "2025-05-21T18:55:23.885Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/17/69/cd203477f944c353c31bade965f880aa1061fd6bf05ded0726ca845b6ff7/typing_inspection-0.4.1-py3-none-any.whl", hash = "sha256:389055682238f53b04f7badcb49b989835495a96700ced5dab2d8feae4b26f51", size = 14552, upload-time = "2025-05-21T18:55:22.152Z" },
+]
+
+[[package]]
+name = "tzdata"
+version = "2025.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/95/32/1a225d6164441be760d75c2c42e2780dc0873fe382da3e98a2e1e48361e5/tzdata-2025.2.tar.gz", hash = "sha256:b60a638fcc0daffadf82fe0f57e53d06bdec2f36c4df66280ae79bce6bd6f2b9", size = 196380, upload-time = "2025-03-23T13:54:43.652Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl", hash = "sha256:1a403fada01ff9221ca8044d701868fa132215d84beb92242d9acd2147f667a8", size = 347839, upload-time = "2025-03-23T13:54:41.845Z" },
+]
+
+[[package]]
+name = "ujson"
+version = "5.10.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f0/00/3110fd566786bfa542adb7932d62035e0c0ef662a8ff6544b6643b3d6fd7/ujson-5.10.0.tar.gz", hash = "sha256:b3cd8f3c5d8c7738257f1018880444f7b7d9b66232c64649f562d7ba86ad4bc1", size = 7154885, upload-time = "2024-05-14T02:02:34.233Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e8/a6/fd3f8bbd80842267e2d06c3583279555e8354c5986c952385199d57a5b6c/ujson-5.10.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:98ba15d8cbc481ce55695beee9f063189dce91a4b08bc1d03e7f0152cd4bbdd5", size = 55642, upload-time = "2024-05-14T02:01:04.055Z" },
+ { url = "https://files.pythonhosted.org/packages/a8/47/dd03fd2b5ae727e16d5d18919b383959c6d269c7b948a380fdd879518640/ujson-5.10.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a9d2edbf1556e4f56e50fab7d8ff993dbad7f54bac68eacdd27a8f55f433578e", size = 51807, upload-time = "2024-05-14T02:01:05.25Z" },
+ { url = "https://files.pythonhosted.org/packages/25/23/079a4cc6fd7e2655a473ed9e776ddbb7144e27f04e8fc484a0fb45fe6f71/ujson-5.10.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6627029ae4f52d0e1a2451768c2c37c0c814ffc04f796eb36244cf16b8e57043", size = 51972, upload-time = "2024-05-14T02:01:06.458Z" },
+ { url = "https://files.pythonhosted.org/packages/04/81/668707e5f2177791869b624be4c06fb2473bf97ee33296b18d1cf3092af7/ujson-5.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f8ccb77b3e40b151e20519c6ae6d89bfe3f4c14e8e210d910287f778368bb3d1", size = 53686, upload-time = "2024-05-14T02:01:07.618Z" },
+ { url = "https://files.pythonhosted.org/packages/bd/50/056d518a386d80aaf4505ccf3cee1c40d312a46901ed494d5711dd939bc3/ujson-5.10.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f3caf9cd64abfeb11a3b661329085c5e167abbe15256b3b68cb5d914ba7396f3", size = 58591, upload-time = "2024-05-14T02:01:08.901Z" },
+ { url = "https://files.pythonhosted.org/packages/fc/d6/aeaf3e2d6fb1f4cfb6bf25f454d60490ed8146ddc0600fae44bfe7eb5a72/ujson-5.10.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6e32abdce572e3a8c3d02c886c704a38a1b015a1fb858004e03d20ca7cecbb21", size = 997853, upload-time = "2024-05-14T02:01:10.772Z" },
+ { url = "https://files.pythonhosted.org/packages/f8/d5/1f2a5d2699f447f7d990334ca96e90065ea7f99b142ce96e85f26d7e78e2/ujson-5.10.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:a65b6af4d903103ee7b6f4f5b85f1bfd0c90ba4eeac6421aae436c9988aa64a2", size = 1140689, upload-time = "2024-05-14T02:01:12.214Z" },
+ { url = "https://files.pythonhosted.org/packages/f2/2c/6990f4ccb41ed93744aaaa3786394bca0875503f97690622f3cafc0adfde/ujson-5.10.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:604a046d966457b6cdcacc5aa2ec5314f0e8c42bae52842c1e6fa02ea4bda42e", size = 1043576, upload-time = "2024-05-14T02:01:14.39Z" },
+ { url = "https://files.pythonhosted.org/packages/14/f5/a2368463dbb09fbdbf6a696062d0c0f62e4ae6fa65f38f829611da2e8fdd/ujson-5.10.0-cp312-cp312-win32.whl", hash = "sha256:6dea1c8b4fc921bf78a8ff00bbd2bfe166345f5536c510671bccececb187c80e", size = 38764, upload-time = "2024-05-14T02:01:15.83Z" },
+ { url = "https://files.pythonhosted.org/packages/59/2d/691f741ffd72b6c84438a93749ac57bf1a3f217ac4b0ea4fd0e96119e118/ujson-5.10.0-cp312-cp312-win_amd64.whl", hash = "sha256:38665e7d8290188b1e0d57d584eb8110951a9591363316dd41cf8686ab1d0abc", size = 42211, upload-time = "2024-05-14T02:01:17.567Z" },
+ { url = "https://files.pythonhosted.org/packages/0d/69/b3e3f924bb0e8820bb46671979770c5be6a7d51c77a66324cdb09f1acddb/ujson-5.10.0-cp313-cp313-macosx_10_9_x86_64.whl", hash = "sha256:618efd84dc1acbd6bff8eaa736bb6c074bfa8b8a98f55b61c38d4ca2c1f7f287", size = 55646, upload-time = "2024-05-14T02:01:19.26Z" },
+ { url = "https://files.pythonhosted.org/packages/32/8a/9b748eb543c6cabc54ebeaa1f28035b1bd09c0800235b08e85990734c41e/ujson-5.10.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:38d5d36b4aedfe81dfe251f76c0467399d575d1395a1755de391e58985ab1c2e", size = 51806, upload-time = "2024-05-14T02:01:20.593Z" },
+ { url = "https://files.pythonhosted.org/packages/39/50/4b53ea234413b710a18b305f465b328e306ba9592e13a791a6a6b378869b/ujson-5.10.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:67079b1f9fb29ed9a2914acf4ef6c02844b3153913eb735d4bf287ee1db6e557", size = 51975, upload-time = "2024-05-14T02:01:21.904Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/9d/8061934f960cdb6dd55f0b3ceeff207fcc48c64f58b43403777ad5623d9e/ujson-5.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7d0e0ceeb8fe2468c70ec0c37b439dd554e2aa539a8a56365fd761edb418988", size = 53693, upload-time = "2024-05-14T02:01:23.742Z" },
+ { url = "https://files.pythonhosted.org/packages/f5/be/7bfa84b28519ddbb67efc8410765ca7da55e6b93aba84d97764cd5794dbc/ujson-5.10.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:59e02cd37bc7c44d587a0ba45347cc815fb7a5fe48de16bf05caa5f7d0d2e816", size = 58594, upload-time = "2024-05-14T02:01:25.554Z" },
+ { url = "https://files.pythonhosted.org/packages/48/eb/85d465abafb2c69d9699cfa5520e6e96561db787d36c677370e066c7e2e7/ujson-5.10.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:2a890b706b64e0065f02577bf6d8ca3b66c11a5e81fb75d757233a38c07a1f20", size = 997853, upload-time = "2024-05-14T02:01:27.151Z" },
+ { url = "https://files.pythonhosted.org/packages/9f/76/2a63409fc05d34dd7d929357b7a45e3a2c96f22b4225cd74becd2ba6c4cb/ujson-5.10.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:621e34b4632c740ecb491efc7f1fcb4f74b48ddb55e65221995e74e2d00bbff0", size = 1140694, upload-time = "2024-05-14T02:01:29.113Z" },
+ { url = "https://files.pythonhosted.org/packages/45/ed/582c4daba0f3e1688d923b5cb914ada1f9defa702df38a1916c899f7c4d1/ujson-5.10.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:b9500e61fce0cfc86168b248104e954fead61f9be213087153d272e817ec7b4f", size = 1043580, upload-time = "2024-05-14T02:01:31.447Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/0c/9837fece153051e19c7bade9f88f9b409e026b9525927824cdf16293b43b/ujson-5.10.0-cp313-cp313-win32.whl", hash = "sha256:4c4fc16f11ac1612f05b6f5781b384716719547e142cfd67b65d035bd85af165", size = 38766, upload-time = "2024-05-14T02:01:32.856Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/72/6cb6728e2738c05bbe9bd522d6fc79f86b9a28402f38663e85a28fddd4a0/ujson-5.10.0-cp313-cp313-win_amd64.whl", hash = "sha256:4573fd1695932d4f619928fd09d5d03d917274381649ade4328091ceca175539", size = 42212, upload-time = "2024-05-14T02:01:33.97Z" },
+]
+
+[[package]]
+name = "unstract-connectors"
+version = "0.0.3"
+source = { editable = "../unstract/connectors" }
+dependencies = [
+ { name = "adlfs" },
+ { name = "boxfs" },
+ { name = "dropboxdrivefs" },
+ { name = "fsspec", extra = ["sftp"] },
+ { name = "gcsfs" },
+ { name = "google-auth" },
+ { name = "google-cloud-bigquery" },
+ { name = "google-cloud-secret-manager" },
+ { name = "google-cloud-storage" },
+ { name = "oauth2client" },
+ { name = "oracledb" },
+ { name = "psycopg2-binary" },
+ { name = "pydrive2", extra = ["fsspec"] },
+ { name = "pymssql" },
+ { name = "pymysql" },
+ { name = "s3fs", extra = ["boto3"] },
+ { name = "singleton-decorator" },
+ { name = "snowflake-connector-python", extra = ["pandas"] },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "adlfs", specifier = "~=2024.7.0" },
+ { name = "boxfs", specifier = "==0.2.1" },
+ { name = "dropboxdrivefs", specifier = "==1.4.1" },
+ { name = "fsspec", extras = ["sftp"], specifier = "~=2024.10.0" },
+ { name = "gcsfs", specifier = "==2024.10.0" },
+ { name = "google-auth", specifier = "==2.20.0" },
+ { name = "google-cloud-bigquery", specifier = "==3.11.4" },
+ { name = "google-cloud-secret-manager", specifier = "==2.16.1" },
+ { name = "google-cloud-storage", specifier = "==2.9.0" },
+ { name = "oauth2client", specifier = "==4.1.3" },
+ { name = "oracledb", specifier = "==2.4.0" },
+ { name = "psycopg2-binary", specifier = "==2.9.9" },
+ { name = "pydrive2", extras = ["fsspec"], specifier = "==1.15.4" },
+ { name = "pymssql", specifier = "==2.3.4" },
+ { name = "pymysql", specifier = "==1.1.0" },
+ { name = "s3fs", extras = ["boto3"], specifier = "==2024.10.0" },
+ { name = "singleton-decorator", specifier = "~=1.0.0" },
+ { name = "snowflake-connector-python", extras = ["pandas"], specifier = "~=3.14.0" },
+]
+
+[[package]]
+name = "unstract-core"
+version = "0.0.1"
+source = { editable = "../unstract/core" }
+dependencies = [
+ { name = "httpx" },
+ { name = "kombu" },
+ { name = "redis" },
+ { name = "requests" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "flask", marker = "extra == 'flask'", specifier = "~=3.1.0" },
+ { name = "httpx", specifier = ">=0.27.0" },
+ { name = "kombu", specifier = "~=5.5.3" },
+ { name = "redis", specifier = "~=5.2.1" },
+ { name = "requests", specifier = "==2.31.0" },
+]
+provides-extras = ["flask"]
+
+[[package]]
+name = "unstract-filesystem"
+version = "0.0.1"
+source = { editable = "../unstract/filesystem" }
+dependencies = [
+ { name = "unstract-sdk" },
+]
+
+[package.metadata]
+requires-dist = [{ name = "unstract-sdk", specifier = "~=0.77.1" }]
+
+[[package]]
+name = "unstract-flags"
+version = "0.0.1"
+source = { editable = "../unstract/flags" }
+dependencies = [
+ { name = "grpcio" },
+ { name = "grpcio-tools" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "grpcio", specifier = "<=1.60.0" },
+ { name = "grpcio-tools", specifier = "<=1.60.0" },
+]
+
+[[package]]
+name = "unstract-sdk"
+version = "0.77.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "filetype" },
+ { name = "httpx" },
+ { name = "jsonschema" },
+ { name = "llama-index" },
+ { name = "llama-index-embeddings-azure-openai" },
+ { name = "llama-index-embeddings-bedrock" },
+ { name = "llama-index-embeddings-google" },
+ { name = "llama-index-embeddings-ollama" },
+ { name = "llama-index-embeddings-openai" },
+ { name = "llama-index-embeddings-vertex" },
+ { name = "llama-index-llms-anthropic" },
+ { name = "llama-index-llms-anyscale" },
+ { name = "llama-index-llms-azure-openai" },
+ { name = "llama-index-llms-bedrock-converse" },
+ { name = "llama-index-llms-mistralai" },
+ { name = "llama-index-llms-ollama" },
+ { name = "llama-index-llms-openai" },
+ { name = "llama-index-llms-palm" },
+ { name = "llama-index-llms-replicate" },
+ { name = "llama-index-llms-vertex" },
+ { name = "llama-index-vector-stores-milvus" },
+ { name = "llama-index-vector-stores-pinecone" },
+ { name = "llama-index-vector-stores-postgres" },
+ { name = "llama-index-vector-stores-qdrant" },
+ { name = "llama-index-vector-stores-weaviate" },
+ { name = "llama-parse" },
+ { name = "llmwhisperer-client" },
+ { name = "mistralai" },
+ { name = "pdfplumber" },
+ { name = "python-dotenv" },
+ { name = "python-magic" },
+ { name = "redis" },
+ { name = "singleton-decorator" },
+ { name = "tiktoken" },
+ { name = "transformers" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c5/e8/f7e1045fee076c75c42bb27b4fa5a077836cfa8fd3fd580f6c6193fa19dc/unstract_sdk-0.77.3.tar.gz", hash = "sha256:378c19129a91e861b7235e92411ef72792c6c851320cb7897b380d08d3489c9d", size = 2375843, upload-time = "2025-09-22T13:07:35.809Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d5/84/d596295fce3a713b1953a4fd7be3be1d788920e5633e28fbea7c7331b68a/unstract_sdk-0.77.3-py3-none-any.whl", hash = "sha256:74e83cbb68eef98fbaecfc83e0cfd2228e5958506e1b51a65fae0d891027aaee", size = 266640, upload-time = "2025-09-22T13:07:34.351Z" },
+]
+
+[package.optional-dependencies]
+azure = [
+ { name = "adlfs" },
+]
+
+[[package]]
+name = "unstract-tool-registry"
+version = "0.0.1"
+source = { editable = "../unstract/tool-registry" }
+dependencies = [
+ { name = "docker" },
+ { name = "jsonschema" },
+ { name = "pyyaml" },
+ { name = "unstract-flags" },
+ { name = "unstract-sdk" },
+ { name = "unstract-tool-sandbox" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "docker", specifier = "~=6.1.3" },
+ { name = "jsonschema", specifier = ">=4.18.6,<5.0" },
+ { name = "pyyaml", specifier = "~=6.0.1" },
+ { name = "unstract-flags", editable = "../unstract/flags" },
+ { name = "unstract-sdk", specifier = "~=0.77.1" },
+ { name = "unstract-tool-sandbox", editable = "../unstract/tool-sandbox" },
+]
+
+[[package]]
+name = "unstract-tool-sandbox"
+version = "0.0.1"
+source = { editable = "../unstract/tool-sandbox" }
+dependencies = [
+ { name = "requests" },
+ { name = "unstract-core" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "requests", specifier = "==2.31.0" },
+ { name = "unstract-core", editable = "../unstract/core" },
+]
+
+[[package]]
+name = "unstract-workers"
+version = "1.0.0"
+source = { editable = "." }
+dependencies = [
+ { name = "celery" },
+ { name = "httpx" },
+ { name = "prometheus-client" },
+ { name = "psutil" },
+ { name = "python-dotenv" },
+ { name = "python-socketio" },
+ { name = "redis" },
+ { name = "requests" },
+ { name = "unstract-connectors" },
+ { name = "unstract-core" },
+ { name = "unstract-filesystem" },
+ { name = "unstract-flags" },
+ { name = "unstract-sdk", extra = ["azure"] },
+ { name = "unstract-tool-registry" },
+ { name = "unstract-tool-sandbox" },
+ { name = "unstract-workflow-execution" },
+ { name = "urllib3" },
+]
+
+[package.dev-dependencies]
+deploy = [
+ { name = "opentelemetry-distro" },
+ { name = "opentelemetry-exporter-otlp" },
+]
+dev = [
+ { name = "black" },
+ { name = "flake8" },
+ { name = "isort" },
+ { name = "mypy" },
+ { name = "pytest" },
+ { name = "pytest-asyncio" },
+ { name = "pytest-cov" },
+ { name = "pytest-mock" },
+]
+test = [
+ { name = "factory-boy" },
+ { name = "pytest" },
+ { name = "pytest-asyncio" },
+ { name = "pytest-cov" },
+ { name = "pytest-mock" },
+ { name = "responses" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "celery", specifier = ">=5.5.3" },
+ { name = "httpx", specifier = ">=0.27.0" },
+ { name = "prometheus-client", specifier = ">=0.17.0,<1.0.0" },
+ { name = "psutil", specifier = ">=5.9.0,<6.0.0" },
+ { name = "python-dotenv", specifier = ">=1.0.0,<2.0.0" },
+ { name = "python-socketio", specifier = ">=5.9.0" },
+ { name = "redis", specifier = ">=4.5.0,<6.0.0" },
+ { name = "requests", specifier = ">=2.31.0,<3.0.0" },
+ { name = "unstract-connectors", editable = "../unstract/connectors" },
+ { name = "unstract-core", editable = "../unstract/core" },
+ { name = "unstract-filesystem", editable = "../unstract/filesystem" },
+ { name = "unstract-flags", editable = "../unstract/flags" },
+ { name = "unstract-sdk", extras = ["azure"], specifier = "~=0.77.3" },
+ { name = "unstract-tool-registry", editable = "../unstract/tool-registry" },
+ { name = "unstract-tool-sandbox", editable = "../unstract/tool-sandbox" },
+ { name = "unstract-workflow-execution", editable = "../unstract/workflow-execution" },
+ { name = "urllib3", specifier = ">=1.26.0" },
+]
+
+[package.metadata.requires-dev]
+deploy = [
+ { name = "opentelemetry-distro" },
+ { name = "opentelemetry-exporter-otlp" },
+]
+dev = [
+ { name = "black", specifier = ">=23.7.0" },
+ { name = "flake8", specifier = ">=6.0.0" },
+ { name = "isort", specifier = ">=5.12.0" },
+ { name = "mypy", specifier = ">=1.5.0" },
+ { name = "pytest", specifier = ">=7.4.0" },
+ { name = "pytest-asyncio", specifier = ">=0.21.0" },
+ { name = "pytest-cov", specifier = ">=4.1.0" },
+ { name = "pytest-mock", specifier = ">=3.11.0" },
+]
+test = [
+ { name = "factory-boy", specifier = ">=3.3.0" },
+ { name = "pytest", specifier = ">=7.4.0" },
+ { name = "pytest-asyncio", specifier = ">=0.21.0" },
+ { name = "pytest-cov", specifier = ">=4.1.0" },
+ { name = "pytest-mock", specifier = ">=3.11.0" },
+ { name = "responses", specifier = ">=0.23.0" },
+]
+
+[[package]]
+name = "unstract-workflow-execution"
+version = "0.0.1"
+source = { editable = "../unstract/workflow-execution" }
+dependencies = [
+ { name = "unstract-core" },
+ { name = "unstract-filesystem" },
+ { name = "unstract-flags" },
+ { name = "unstract-tool-registry" },
+ { name = "unstract-tool-sandbox" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "unstract-core", editable = "../unstract/core" },
+ { name = "unstract-filesystem", editable = "../unstract/filesystem" },
+ { name = "unstract-flags", editable = "../unstract/flags" },
+ { name = "unstract-tool-registry", editable = "../unstract/tool-registry" },
+ { name = "unstract-tool-sandbox", editable = "../unstract/tool-sandbox" },
+]
+
+[[package]]
+name = "uritemplate"
+version = "4.2.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/98/60/f174043244c5306c9988380d2cb10009f91563fc4b31293d27e17201af56/uritemplate-4.2.0.tar.gz", hash = "sha256:480c2ed180878955863323eea31b0ede668795de182617fef9c6ca09e6ec9d0e", size = 33267, upload-time = "2025-06-02T15:12:06.318Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a9/99/3ae339466c9183ea5b8ae87b34c0b897eda475d2aec2307cae60e5cd4f29/uritemplate-4.2.0-py3-none-any.whl", hash = "sha256:962201ba1c4edcab02e60f9a0d3821e82dfc5d2d6662a21abd533879bdb8a686", size = 11488, upload-time = "2025-06-02T15:12:03.405Z" },
+]
+
+[[package]]
+name = "urllib3"
+version = "1.26.20"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e4/e8/6ff5e6bc22095cfc59b6ea711b687e2b7ed4bdb373f7eeec370a97d7392f/urllib3-1.26.20.tar.gz", hash = "sha256:40c2dc0c681e47eb8f90e7e27bf6ff7df2e677421fd46756da1161c39ca70d32", size = 307380, upload-time = "2024-08-29T15:43:11.37Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/33/cf/8435d5a7159e2a9c83a95896ed596f68cf798005fe107cc655b5c5c14704/urllib3-1.26.20-py2.py3-none-any.whl", hash = "sha256:0ed14ccfbf1c30a9072c7ca157e4319b70d65f623e91e7b32fadb2853431016e", size = 144225, upload-time = "2024-08-29T15:43:08.921Z" },
+]
+
+[[package]]
+name = "validators"
+version = "0.35.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/53/66/a435d9ae49850b2f071f7ebd8119dd4e84872b01630d6736761e6e7fd847/validators-0.35.0.tar.gz", hash = "sha256:992d6c48a4e77c81f1b4daba10d16c3a9bb0dbb79b3a19ea847ff0928e70497a", size = 73399, upload-time = "2025-05-01T05:42:06.7Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/fa/6e/3e955517e22cbdd565f2f8b2e73d52528b14b8bcfdb04f62466b071de847/validators-0.35.0-py3-none-any.whl", hash = "sha256:e8c947097eae7892cb3d26868d637f79f47b4a0554bc6b80065dfe5aac3705dd", size = 44712, upload-time = "2025-05-01T05:42:04.203Z" },
+]
+
+[[package]]
+name = "vine"
+version = "5.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/bd/e4/d07b5f29d283596b9727dd5275ccbceb63c44a1a82aa9e4bfd20426762ac/vine-5.1.0.tar.gz", hash = "sha256:8b62e981d35c41049211cf62a0a1242d8c1ee9bd15bb196ce38aefd6799e61e0", size = 48980, upload-time = "2023-11-05T08:46:53.857Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/03/ff/7c0c86c43b3cbb927e0ccc0255cb4057ceba4799cd44ae95174ce8e8b5b2/vine-5.1.0-py3-none-any.whl", hash = "sha256:40fdf3c48b2cfe1c38a49e9ae2da6fda88e4794c810050a728bd7413811fb1dc", size = 9636, upload-time = "2023-11-05T08:46:51.205Z" },
+]
+
+[[package]]
+name = "wcwidth"
+version = "0.2.13"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/6c/63/53559446a878410fc5a5974feb13d31d78d752eb18aeba59c7fef1af7598/wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5", size = 101301, upload-time = "2024-01-06T02:10:57.829Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/fd/84/fd2ba7aafacbad3c4201d395674fc6348826569da3c0937e75505ead3528/wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859", size = 34166, upload-time = "2024-01-06T02:10:55.763Z" },
+]
+
+[[package]]
+name = "weaviate-client"
+version = "4.16.6"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "authlib" },
+ { name = "deprecation" },
+ { name = "grpcio" },
+ { name = "grpcio-health-checking" },
+ { name = "httpx" },
+ { name = "pydantic" },
+ { name = "validators" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/8f/1e/b44262cd9edff939f7a6e40b6134d737a28bcdb0445cbdf2af9544953658/weaviate_client-4.16.6.tar.gz", hash = "sha256:79064bd976b0ec6bee09507f74481711bcbc861bcc097ca37db22bcf948771e6", size = 779904, upload-time = "2025-08-06T10:18:58.593Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5c/d2/7cf098b1d14dd237a81b84012f0c4cdea355d2312b10410148384fa8b39a/weaviate_client-4.16.6-py3-none-any.whl", hash = "sha256:8eafcac785876bc731b7dedd7272a93b530fc5ed807ab54b6d74f9493a014dec", size = 597469, upload-time = "2025-08-06T10:18:56.79Z" },
+]
+
+[[package]]
+name = "websocket-client"
+version = "1.8.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e6/30/fba0d96b4b5fbf5948ed3f4681f7da2f9f64512e1d303f94b4cc174c24a5/websocket_client-1.8.0.tar.gz", hash = "sha256:3239df9f44da632f96012472805d40a23281a991027ce11d2f45a6f24ac4c3da", size = 54648, upload-time = "2024-04-23T22:16:16.976Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5a/84/44687a29792a70e111c5c477230a72c4b957d88d16141199bf9acb7537a3/websocket_client-1.8.0-py3-none-any.whl", hash = "sha256:17b44cc997f5c498e809b22cdf2d9c7a9e71c02c8cc2b6c56e7c2d1239bfa526", size = 58826, upload-time = "2024-04-23T22:16:14.422Z" },
+]
+
+[[package]]
+name = "websockets"
+version = "14.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/94/54/8359678c726243d19fae38ca14a334e740782336c9f19700858c4eb64a1e/websockets-14.2.tar.gz", hash = "sha256:5059ed9c54945efb321f097084b4c7e52c246f2c869815876a69d1efc4ad6eb5", size = 164394, upload-time = "2025-01-19T21:00:56.431Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/c1/81/04f7a397653dc8bec94ddc071f34833e8b99b13ef1a3804c149d59f92c18/websockets-14.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:1f20522e624d7ffbdbe259c6b6a65d73c895045f76a93719aa10cd93b3de100c", size = 163096, upload-time = "2025-01-19T20:59:29.763Z" },
+ { url = "https://files.pythonhosted.org/packages/ec/c5/de30e88557e4d70988ed4d2eabd73fd3e1e52456b9f3a4e9564d86353b6d/websockets-14.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:647b573f7d3ada919fd60e64d533409a79dcf1ea21daeb4542d1d996519ca967", size = 160758, upload-time = "2025-01-19T20:59:32.095Z" },
+ { url = "https://files.pythonhosted.org/packages/e5/8c/d130d668781f2c77d106c007b6c6c1d9db68239107c41ba109f09e6c218a/websockets-14.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:6af99a38e49f66be5a64b1e890208ad026cda49355661549c507152113049990", size = 160995, upload-time = "2025-01-19T20:59:33.527Z" },
+ { url = "https://files.pythonhosted.org/packages/a6/bc/f6678a0ff17246df4f06765e22fc9d98d1b11a258cc50c5968b33d6742a1/websockets-14.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:091ab63dfc8cea748cc22c1db2814eadb77ccbf82829bac6b2fbe3401d548eda", size = 170815, upload-time = "2025-01-19T20:59:35.837Z" },
+ { url = "https://files.pythonhosted.org/packages/d8/b2/8070cb970c2e4122a6ef38bc5b203415fd46460e025652e1ee3f2f43a9a3/websockets-14.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b374e8953ad477d17e4851cdc66d83fdc2db88d9e73abf755c94510ebddceb95", size = 169759, upload-time = "2025-01-19T20:59:38.216Z" },
+ { url = "https://files.pythonhosted.org/packages/81/da/72f7caabd94652e6eb7e92ed2d3da818626e70b4f2b15a854ef60bf501ec/websockets-14.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a39d7eceeea35db85b85e1169011bb4321c32e673920ae9c1b6e0978590012a3", size = 170178, upload-time = "2025-01-19T20:59:40.423Z" },
+ { url = "https://files.pythonhosted.org/packages/31/e0/812725b6deca8afd3a08a2e81b3c4c120c17f68c9b84522a520b816cda58/websockets-14.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:0a6f3efd47ffd0d12080594f434faf1cd2549b31e54870b8470b28cc1d3817d9", size = 170453, upload-time = "2025-01-19T20:59:41.996Z" },
+ { url = "https://files.pythonhosted.org/packages/66/d3/8275dbc231e5ba9bb0c4f93144394b4194402a7a0c8ffaca5307a58ab5e3/websockets-14.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:065ce275e7c4ffb42cb738dd6b20726ac26ac9ad0a2a48e33ca632351a737267", size = 169830, upload-time = "2025-01-19T20:59:44.669Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/ae/e7d1a56755ae15ad5a94e80dd490ad09e345365199600b2629b18ee37bc7/websockets-14.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e9d0e53530ba7b8b5e389c02282f9d2aa47581514bd6049d3a7cffe1385cf5fe", size = 169824, upload-time = "2025-01-19T20:59:46.932Z" },
+ { url = "https://files.pythonhosted.org/packages/b6/32/88ccdd63cb261e77b882e706108d072e4f1c839ed723bf91a3e1f216bf60/websockets-14.2-cp312-cp312-win32.whl", hash = "sha256:20e6dd0984d7ca3037afcb4494e48c74ffb51e8013cac71cf607fffe11df7205", size = 163981, upload-time = "2025-01-19T20:59:49.228Z" },
+ { url = "https://files.pythonhosted.org/packages/b3/7d/32cdb77990b3bdc34a306e0a0f73a1275221e9a66d869f6ff833c95b56ef/websockets-14.2-cp312-cp312-win_amd64.whl", hash = "sha256:44bba1a956c2c9d268bdcdf234d5e5ff4c9b6dc3e300545cbe99af59dda9dcce", size = 164421, upload-time = "2025-01-19T20:59:50.674Z" },
+ { url = "https://files.pythonhosted.org/packages/82/94/4f9b55099a4603ac53c2912e1f043d6c49d23e94dd82a9ce1eb554a90215/websockets-14.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:6f1372e511c7409a542291bce92d6c83320e02c9cf392223272287ce55bc224e", size = 163102, upload-time = "2025-01-19T20:59:52.177Z" },
+ { url = "https://files.pythonhosted.org/packages/8e/b7/7484905215627909d9a79ae07070057afe477433fdacb59bf608ce86365a/websockets-14.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:4da98b72009836179bb596a92297b1a61bb5a830c0e483a7d0766d45070a08ad", size = 160766, upload-time = "2025-01-19T20:59:54.368Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/a4/edb62efc84adb61883c7d2c6ad65181cb087c64252138e12d655989eec05/websockets-14.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f8a86a269759026d2bde227652b87be79f8a734e582debf64c9d302faa1e9f03", size = 160998, upload-time = "2025-01-19T20:59:56.671Z" },
+ { url = "https://files.pythonhosted.org/packages/f5/79/036d320dc894b96af14eac2529967a6fc8b74f03b83c487e7a0e9043d842/websockets-14.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:86cf1aaeca909bf6815ea714d5c5736c8d6dd3a13770e885aafe062ecbd04f1f", size = 170780, upload-time = "2025-01-19T20:59:58.085Z" },
+ { url = "https://files.pythonhosted.org/packages/63/75/5737d21ee4dd7e4b9d487ee044af24a935e36a9ff1e1419d684feedcba71/websockets-14.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9b0f6c3ba3b1240f602ebb3971d45b02cc12bd1845466dd783496b3b05783a5", size = 169717, upload-time = "2025-01-19T20:59:59.545Z" },
+ { url = "https://files.pythonhosted.org/packages/2c/3c/bf9b2c396ed86a0b4a92ff4cdaee09753d3ee389be738e92b9bbd0330b64/websockets-14.2-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:669c3e101c246aa85bc8534e495952e2ca208bd87994650b90a23d745902db9a", size = 170155, upload-time = "2025-01-19T21:00:01.887Z" },
+ { url = "https://files.pythonhosted.org/packages/75/2d/83a5aca7247a655b1da5eb0ee73413abd5c3a57fc8b92915805e6033359d/websockets-14.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:eabdb28b972f3729348e632ab08f2a7b616c7e53d5414c12108c29972e655b20", size = 170495, upload-time = "2025-01-19T21:00:04.064Z" },
+ { url = "https://files.pythonhosted.org/packages/79/dd/699238a92761e2f943885e091486378813ac8f43e3c84990bc394c2be93e/websockets-14.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:2066dc4cbcc19f32c12a5a0e8cc1b7ac734e5b64ac0a325ff8353451c4b15ef2", size = 169880, upload-time = "2025-01-19T21:00:05.695Z" },
+ { url = "https://files.pythonhosted.org/packages/c8/c9/67a8f08923cf55ce61aadda72089e3ed4353a95a3a4bc8bf42082810e580/websockets-14.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:ab95d357cd471df61873dadf66dd05dd4709cae001dd6342edafc8dc6382f307", size = 169856, upload-time = "2025-01-19T21:00:07.192Z" },
+ { url = "https://files.pythonhosted.org/packages/17/b1/1ffdb2680c64e9c3921d99db460546194c40d4acbef999a18c37aa4d58a3/websockets-14.2-cp313-cp313-win32.whl", hash = "sha256:a9e72fb63e5f3feacdcf5b4ff53199ec8c18d66e325c34ee4c551ca748623bbc", size = 163974, upload-time = "2025-01-19T21:00:08.698Z" },
+ { url = "https://files.pythonhosted.org/packages/14/13/8b7fc4cb551b9cfd9890f0fd66e53c18a06240319915533b033a56a3d520/websockets-14.2-cp313-cp313-win_amd64.whl", hash = "sha256:b439ea828c4ba99bb3176dc8d9b933392a2413c0f6b149fdcba48393f573377f", size = 164420, upload-time = "2025-01-19T21:00:10.182Z" },
+ { url = "https://files.pythonhosted.org/packages/7b/c8/d529f8a32ce40d98309f4470780631e971a5a842b60aec864833b3615786/websockets-14.2-py3-none-any.whl", hash = "sha256:7a6ceec4ea84469f15cf15807a747e9efe57e369c384fa86e022b3bea679b79b", size = 157416, upload-time = "2025-01-19T21:00:54.843Z" },
+]
+
+[[package]]
+name = "wrapt"
+version = "1.17.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/c3/fc/e91cc220803d7bc4db93fb02facd8461c37364151b8494762cc88b0fbcef/wrapt-1.17.2.tar.gz", hash = "sha256:41388e9d4d1522446fe79d3213196bd9e3b301a336965b9e27ca2788ebd122f3", size = 55531, upload-time = "2025-01-14T10:35:45.465Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a1/bd/ab55f849fd1f9a58ed7ea47f5559ff09741b25f00c191231f9f059c83949/wrapt-1.17.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:d5e2439eecc762cd85e7bd37161d4714aa03a33c5ba884e26c81559817ca0925", size = 53799, upload-time = "2025-01-14T10:33:57.4Z" },
+ { url = "https://files.pythonhosted.org/packages/53/18/75ddc64c3f63988f5a1d7e10fb204ffe5762bc663f8023f18ecaf31a332e/wrapt-1.17.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:3fc7cb4c1c744f8c05cd5f9438a3caa6ab94ce8344e952d7c45a8ed59dd88392", size = 38821, upload-time = "2025-01-14T10:33:59.334Z" },
+ { url = "https://files.pythonhosted.org/packages/48/2a/97928387d6ed1c1ebbfd4efc4133a0633546bec8481a2dd5ec961313a1c7/wrapt-1.17.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8fdbdb757d5390f7c675e558fd3186d590973244fab0c5fe63d373ade3e99d40", size = 38919, upload-time = "2025-01-14T10:34:04.093Z" },
+ { url = "https://files.pythonhosted.org/packages/73/54/3bfe5a1febbbccb7a2f77de47b989c0b85ed3a6a41614b104204a788c20e/wrapt-1.17.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5bb1d0dbf99411f3d871deb6faa9aabb9d4e744d67dcaaa05399af89d847a91d", size = 88721, upload-time = "2025-01-14T10:34:07.163Z" },
+ { url = "https://files.pythonhosted.org/packages/25/cb/7262bc1b0300b4b64af50c2720ef958c2c1917525238d661c3e9a2b71b7b/wrapt-1.17.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d18a4865f46b8579d44e4fe1e2bcbc6472ad83d98e22a26c963d46e4c125ef0b", size = 80899, upload-time = "2025-01-14T10:34:09.82Z" },
+ { url = "https://files.pythonhosted.org/packages/2a/5a/04cde32b07a7431d4ed0553a76fdb7a61270e78c5fd5a603e190ac389f14/wrapt-1.17.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc570b5f14a79734437cb7b0500376b6b791153314986074486e0b0fa8d71d98", size = 89222, upload-time = "2025-01-14T10:34:11.258Z" },
+ { url = "https://files.pythonhosted.org/packages/09/28/2e45a4f4771fcfb109e244d5dbe54259e970362a311b67a965555ba65026/wrapt-1.17.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6d9187b01bebc3875bac9b087948a2bccefe464a7d8f627cf6e48b1bbae30f82", size = 86707, upload-time = "2025-01-14T10:34:12.49Z" },
+ { url = "https://files.pythonhosted.org/packages/c6/d2/dcb56bf5f32fcd4bd9aacc77b50a539abdd5b6536872413fd3f428b21bed/wrapt-1.17.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:9e8659775f1adf02eb1e6f109751268e493c73716ca5761f8acb695e52a756ae", size = 79685, upload-time = "2025-01-14T10:34:15.043Z" },
+ { url = "https://files.pythonhosted.org/packages/80/4e/eb8b353e36711347893f502ce91c770b0b0929f8f0bed2670a6856e667a9/wrapt-1.17.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e8b2816ebef96d83657b56306152a93909a83f23994f4b30ad4573b00bd11bb9", size = 87567, upload-time = "2025-01-14T10:34:16.563Z" },
+ { url = "https://files.pythonhosted.org/packages/17/27/4fe749a54e7fae6e7146f1c7d914d28ef599dacd4416566c055564080fe2/wrapt-1.17.2-cp312-cp312-win32.whl", hash = "sha256:468090021f391fe0056ad3e807e3d9034e0fd01adcd3bdfba977b6fdf4213ea9", size = 36672, upload-time = "2025-01-14T10:34:17.727Z" },
+ { url = "https://files.pythonhosted.org/packages/15/06/1dbf478ea45c03e78a6a8c4be4fdc3c3bddea5c8de8a93bc971415e47f0f/wrapt-1.17.2-cp312-cp312-win_amd64.whl", hash = "sha256:ec89ed91f2fa8e3f52ae53cd3cf640d6feff92ba90d62236a81e4e563ac0e991", size = 38865, upload-time = "2025-01-14T10:34:19.577Z" },
+ { url = "https://files.pythonhosted.org/packages/ce/b9/0ffd557a92f3b11d4c5d5e0c5e4ad057bd9eb8586615cdaf901409920b14/wrapt-1.17.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:6ed6ffac43aecfe6d86ec5b74b06a5be33d5bb9243d055141e8cabb12aa08125", size = 53800, upload-time = "2025-01-14T10:34:21.571Z" },
+ { url = "https://files.pythonhosted.org/packages/c0/ef/8be90a0b7e73c32e550c73cfb2fa09db62234227ece47b0e80a05073b375/wrapt-1.17.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:35621ae4c00e056adb0009f8e86e28eb4a41a4bfa8f9bfa9fca7d343fe94f998", size = 38824, upload-time = "2025-01-14T10:34:22.999Z" },
+ { url = "https://files.pythonhosted.org/packages/36/89/0aae34c10fe524cce30fe5fc433210376bce94cf74d05b0d68344c8ba46e/wrapt-1.17.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a604bf7a053f8362d27eb9fefd2097f82600b856d5abe996d623babd067b1ab5", size = 38920, upload-time = "2025-01-14T10:34:25.386Z" },
+ { url = "https://files.pythonhosted.org/packages/3b/24/11c4510de906d77e0cfb5197f1b1445d4fec42c9a39ea853d482698ac681/wrapt-1.17.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5cbabee4f083b6b4cd282f5b817a867cf0b1028c54d445b7ec7cfe6505057cf8", size = 88690, upload-time = "2025-01-14T10:34:28.058Z" },
+ { url = "https://files.pythonhosted.org/packages/71/d7/cfcf842291267bf455b3e266c0c29dcb675b5540ee8b50ba1699abf3af45/wrapt-1.17.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:49703ce2ddc220df165bd2962f8e03b84c89fee2d65e1c24a7defff6f988f4d6", size = 80861, upload-time = "2025-01-14T10:34:29.167Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/66/5d973e9f3e7370fd686fb47a9af3319418ed925c27d72ce16b791231576d/wrapt-1.17.2-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8112e52c5822fc4253f3901b676c55ddf288614dc7011634e2719718eaa187dc", size = 89174, upload-time = "2025-01-14T10:34:31.702Z" },
+ { url = "https://files.pythonhosted.org/packages/a7/d3/8e17bb70f6ae25dabc1aaf990f86824e4fd98ee9cadf197054e068500d27/wrapt-1.17.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:9fee687dce376205d9a494e9c121e27183b2a3df18037f89d69bd7b35bcf59e2", size = 86721, upload-time = "2025-01-14T10:34:32.91Z" },
+ { url = "https://files.pythonhosted.org/packages/6f/54/f170dfb278fe1c30d0ff864513cff526d624ab8de3254b20abb9cffedc24/wrapt-1.17.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:18983c537e04d11cf027fbb60a1e8dfd5190e2b60cc27bc0808e653e7b218d1b", size = 79763, upload-time = "2025-01-14T10:34:34.903Z" },
+ { url = "https://files.pythonhosted.org/packages/4a/98/de07243751f1c4a9b15c76019250210dd3486ce098c3d80d5f729cba029c/wrapt-1.17.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:703919b1633412ab54bcf920ab388735832fdcb9f9a00ae49387f0fe67dad504", size = 87585, upload-time = "2025-01-14T10:34:36.13Z" },
+ { url = "https://files.pythonhosted.org/packages/f9/f0/13925f4bd6548013038cdeb11ee2cbd4e37c30f8bfd5db9e5a2a370d6e20/wrapt-1.17.2-cp313-cp313-win32.whl", hash = "sha256:abbb9e76177c35d4e8568e58650aa6926040d6a9f6f03435b7a522bf1c487f9a", size = 36676, upload-time = "2025-01-14T10:34:37.962Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/ae/743f16ef8c2e3628df3ddfd652b7d4c555d12c84b53f3d8218498f4ade9b/wrapt-1.17.2-cp313-cp313-win_amd64.whl", hash = "sha256:69606d7bb691b50a4240ce6b22ebb319c1cfb164e5f6569835058196e0f3a845", size = 38871, upload-time = "2025-01-14T10:34:39.13Z" },
+ { url = "https://files.pythonhosted.org/packages/3d/bc/30f903f891a82d402ffb5fda27ec1d621cc97cb74c16fea0b6141f1d4e87/wrapt-1.17.2-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:4a721d3c943dae44f8e243b380cb645a709ba5bd35d3ad27bc2ed947e9c68192", size = 56312, upload-time = "2025-01-14T10:34:40.604Z" },
+ { url = "https://files.pythonhosted.org/packages/8a/04/c97273eb491b5f1c918857cd26f314b74fc9b29224521f5b83f872253725/wrapt-1.17.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:766d8bbefcb9e00c3ac3b000d9acc51f1b399513f44d77dfe0eb026ad7c9a19b", size = 40062, upload-time = "2025-01-14T10:34:45.011Z" },
+ { url = "https://files.pythonhosted.org/packages/4e/ca/3b7afa1eae3a9e7fefe499db9b96813f41828b9fdb016ee836c4c379dadb/wrapt-1.17.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:e496a8ce2c256da1eb98bd15803a79bee00fc351f5dfb9ea82594a3f058309e0", size = 40155, upload-time = "2025-01-14T10:34:47.25Z" },
+ { url = "https://files.pythonhosted.org/packages/89/be/7c1baed43290775cb9030c774bc53c860db140397047cc49aedaf0a15477/wrapt-1.17.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:40d615e4fe22f4ad3528448c193b218e077656ca9ccb22ce2cb20db730f8d306", size = 113471, upload-time = "2025-01-14T10:34:50.934Z" },
+ { url = "https://files.pythonhosted.org/packages/32/98/4ed894cf012b6d6aae5f5cc974006bdeb92f0241775addad3f8cd6ab71c8/wrapt-1.17.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a5aaeff38654462bc4b09023918b7f21790efb807f54c000a39d41d69cf552cb", size = 101208, upload-time = "2025-01-14T10:34:52.297Z" },
+ { url = "https://files.pythonhosted.org/packages/ea/fd/0c30f2301ca94e655e5e057012e83284ce8c545df7661a78d8bfca2fac7a/wrapt-1.17.2-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9a7d15bbd2bc99e92e39f49a04653062ee6085c0e18b3b7512a4f2fe91f2d681", size = 109339, upload-time = "2025-01-14T10:34:53.489Z" },
+ { url = "https://files.pythonhosted.org/packages/75/56/05d000de894c4cfcb84bcd6b1df6214297b8089a7bd324c21a4765e49b14/wrapt-1.17.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:e3890b508a23299083e065f435a492b5435eba6e304a7114d2f919d400888cc6", size = 110232, upload-time = "2025-01-14T10:34:55.327Z" },
+ { url = "https://files.pythonhosted.org/packages/53/f8/c3f6b2cf9b9277fb0813418e1503e68414cd036b3b099c823379c9575e6d/wrapt-1.17.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:8c8b293cd65ad716d13d8dd3624e42e5a19cc2a2f1acc74b30c2c13f15cb61a6", size = 100476, upload-time = "2025-01-14T10:34:58.055Z" },
+ { url = "https://files.pythonhosted.org/packages/a7/b1/0bb11e29aa5139d90b770ebbfa167267b1fc548d2302c30c8f7572851738/wrapt-1.17.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:4c82b8785d98cdd9fed4cac84d765d234ed3251bd6afe34cb7ac523cb93e8b4f", size = 106377, upload-time = "2025-01-14T10:34:59.3Z" },
+ { url = "https://files.pythonhosted.org/packages/6a/e1/0122853035b40b3f333bbb25f1939fc1045e21dd518f7f0922b60c156f7c/wrapt-1.17.2-cp313-cp313t-win32.whl", hash = "sha256:13e6afb7fe71fe7485a4550a8844cc9ffbe263c0f1a1eea569bc7091d4898555", size = 37986, upload-time = "2025-01-14T10:35:00.498Z" },
+ { url = "https://files.pythonhosted.org/packages/09/5e/1655cf481e079c1f22d0cabdd4e51733679932718dc23bf2db175f329b76/wrapt-1.17.2-cp313-cp313t-win_amd64.whl", hash = "sha256:eaf675418ed6b3b31c7a989fd007fa7c3be66ce14e5c3b27336383604c9da85c", size = 40750, upload-time = "2025-01-14T10:35:03.378Z" },
+ { url = "https://files.pythonhosted.org/packages/2d/82/f56956041adef78f849db6b289b282e72b55ab8045a75abad81898c28d19/wrapt-1.17.2-py3-none-any.whl", hash = "sha256:b18f2d1533a71f069c7f82d524a52599053d4c7166e9dd374ae2136b7f40f7c8", size = 23594, upload-time = "2025-01-14T10:35:44.018Z" },
+]
+
+[[package]]
+name = "wsproto"
+version = "1.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "h11" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/c9/4a/44d3c295350d776427904d73c189e10aeae66d7f555bb2feee16d1e4ba5a/wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065", size = 53425, upload-time = "2022-08-23T19:58:21.447Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736", size = 24226, upload-time = "2022-08-23T19:58:19.96Z" },
+]
+
+[[package]]
+name = "yarl"
+version = "1.20.1"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "idna" },
+ { name = "multidict" },
+ { name = "propcache" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/3c/fb/efaa23fa4e45537b827620f04cf8f3cd658b76642205162e072703a5b963/yarl-1.20.1.tar.gz", hash = "sha256:d017a4997ee50c91fd5466cef416231bb82177b93b029906cefc542ce14c35ac", size = 186428, upload-time = "2025-06-10T00:46:09.923Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/5f/9a/cb7fad7d73c69f296eda6815e4a2c7ed53fc70c2f136479a91c8e5fbdb6d/yarl-1.20.1-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:bdcc4cd244e58593a4379fe60fdee5ac0331f8eb70320a24d591a3be197b94a9", size = 133667, upload-time = "2025-06-10T00:43:44.369Z" },
+ { url = "https://files.pythonhosted.org/packages/67/38/688577a1cb1e656e3971fb66a3492501c5a5df56d99722e57c98249e5b8a/yarl-1.20.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:b29a2c385a5f5b9c7d9347e5812b6f7ab267193c62d282a540b4fc528c8a9d2a", size = 91025, upload-time = "2025-06-10T00:43:46.295Z" },
+ { url = "https://files.pythonhosted.org/packages/50/ec/72991ae51febeb11a42813fc259f0d4c8e0507f2b74b5514618d8b640365/yarl-1.20.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1112ae8154186dfe2de4732197f59c05a83dc814849a5ced892b708033f40dc2", size = 89709, upload-time = "2025-06-10T00:43:48.22Z" },
+ { url = "https://files.pythonhosted.org/packages/99/da/4d798025490e89426e9f976702e5f9482005c548c579bdae792a4c37769e/yarl-1.20.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:90bbd29c4fe234233f7fa2b9b121fb63c321830e5d05b45153a2ca68f7d310ee", size = 352287, upload-time = "2025-06-10T00:43:49.924Z" },
+ { url = "https://files.pythonhosted.org/packages/1a/26/54a15c6a567aac1c61b18aa0f4b8aa2e285a52d547d1be8bf48abe2b3991/yarl-1.20.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:680e19c7ce3710ac4cd964e90dad99bf9b5029372ba0c7cbfcd55e54d90ea819", size = 345429, upload-time = "2025-06-10T00:43:51.7Z" },
+ { url = "https://files.pythonhosted.org/packages/d6/95/9dcf2386cb875b234353b93ec43e40219e14900e046bf6ac118f94b1e353/yarl-1.20.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4a979218c1fdb4246a05efc2cc23859d47c89af463a90b99b7c56094daf25a16", size = 365429, upload-time = "2025-06-10T00:43:53.494Z" },
+ { url = "https://files.pythonhosted.org/packages/91/b2/33a8750f6a4bc224242a635f5f2cff6d6ad5ba651f6edcccf721992c21a0/yarl-1.20.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:255b468adf57b4a7b65d8aad5b5138dce6a0752c139965711bdcb81bc370e1b6", size = 363862, upload-time = "2025-06-10T00:43:55.766Z" },
+ { url = "https://files.pythonhosted.org/packages/98/28/3ab7acc5b51f4434b181b0cee8f1f4b77a65919700a355fb3617f9488874/yarl-1.20.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a97d67108e79cfe22e2b430d80d7571ae57d19f17cda8bb967057ca8a7bf5bfd", size = 355616, upload-time = "2025-06-10T00:43:58.056Z" },
+ { url = "https://files.pythonhosted.org/packages/36/a3/f666894aa947a371724ec7cd2e5daa78ee8a777b21509b4252dd7bd15e29/yarl-1.20.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8570d998db4ddbfb9a590b185a0a33dbf8aafb831d07a5257b4ec9948df9cb0a", size = 339954, upload-time = "2025-06-10T00:43:59.773Z" },
+ { url = "https://files.pythonhosted.org/packages/f1/81/5f466427e09773c04219d3450d7a1256138a010b6c9f0af2d48565e9ad13/yarl-1.20.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:97c75596019baae7c71ccf1d8cc4738bc08134060d0adfcbe5642f778d1dca38", size = 365575, upload-time = "2025-06-10T00:44:02.051Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/e3/e4b0ad8403e97e6c9972dd587388940a032f030ebec196ab81a3b8e94d31/yarl-1.20.1-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:1c48912653e63aef91ff988c5432832692ac5a1d8f0fb8a33091520b5bbe19ef", size = 365061, upload-time = "2025-06-10T00:44:04.196Z" },
+ { url = "https://files.pythonhosted.org/packages/ac/99/b8a142e79eb86c926f9f06452eb13ecb1bb5713bd01dc0038faf5452e544/yarl-1.20.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:4c3ae28f3ae1563c50f3d37f064ddb1511ecc1d5584e88c6b7c63cf7702a6d5f", size = 364142, upload-time = "2025-06-10T00:44:06.527Z" },
+ { url = "https://files.pythonhosted.org/packages/34/f2/08ed34a4a506d82a1a3e5bab99ccd930a040f9b6449e9fd050320e45845c/yarl-1.20.1-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:c5e9642f27036283550f5f57dc6156c51084b458570b9d0d96100c8bebb186a8", size = 381894, upload-time = "2025-06-10T00:44:08.379Z" },
+ { url = "https://files.pythonhosted.org/packages/92/f8/9a3fbf0968eac704f681726eff595dce9b49c8a25cd92bf83df209668285/yarl-1.20.1-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:2c26b0c49220d5799f7b22c6838409ee9bc58ee5c95361a4d7831f03cc225b5a", size = 383378, upload-time = "2025-06-10T00:44:10.51Z" },
+ { url = "https://files.pythonhosted.org/packages/af/85/9363f77bdfa1e4d690957cd39d192c4cacd1c58965df0470a4905253b54f/yarl-1.20.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:564ab3d517e3d01c408c67f2e5247aad4019dcf1969982aba3974b4093279004", size = 374069, upload-time = "2025-06-10T00:44:12.834Z" },
+ { url = "https://files.pythonhosted.org/packages/35/99/9918c8739ba271dcd935400cff8b32e3cd319eaf02fcd023d5dcd487a7c8/yarl-1.20.1-cp312-cp312-win32.whl", hash = "sha256:daea0d313868da1cf2fac6b2d3a25c6e3a9e879483244be38c8e6a41f1d876a5", size = 81249, upload-time = "2025-06-10T00:44:14.731Z" },
+ { url = "https://files.pythonhosted.org/packages/eb/83/5d9092950565481b413b31a23e75dd3418ff0a277d6e0abf3729d4d1ce25/yarl-1.20.1-cp312-cp312-win_amd64.whl", hash = "sha256:48ea7d7f9be0487339828a4de0360d7ce0efc06524a48e1810f945c45b813698", size = 86710, upload-time = "2025-06-10T00:44:16.716Z" },
+ { url = "https://files.pythonhosted.org/packages/8a/e1/2411b6d7f769a07687acee88a062af5833cf1966b7266f3d8dfb3d3dc7d3/yarl-1.20.1-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:0b5ff0fbb7c9f1b1b5ab53330acbfc5247893069e7716840c8e7d5bb7355038a", size = 131811, upload-time = "2025-06-10T00:44:18.933Z" },
+ { url = "https://files.pythonhosted.org/packages/b2/27/584394e1cb76fb771371770eccad35de400e7b434ce3142c2dd27392c968/yarl-1.20.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:14f326acd845c2b2e2eb38fb1346c94f7f3b01a4f5c788f8144f9b630bfff9a3", size = 90078, upload-time = "2025-06-10T00:44:20.635Z" },
+ { url = "https://files.pythonhosted.org/packages/bf/9a/3246ae92d4049099f52d9b0fe3486e3b500e29b7ea872d0f152966fc209d/yarl-1.20.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f60e4ad5db23f0b96e49c018596707c3ae89f5d0bd97f0ad3684bcbad899f1e7", size = 88748, upload-time = "2025-06-10T00:44:22.34Z" },
+ { url = "https://files.pythonhosted.org/packages/a3/25/35afe384e31115a1a801fbcf84012d7a066d89035befae7c5d4284df1e03/yarl-1.20.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:49bdd1b8e00ce57e68ba51916e4bb04461746e794e7c4d4bbc42ba2f18297691", size = 349595, upload-time = "2025-06-10T00:44:24.314Z" },
+ { url = "https://files.pythonhosted.org/packages/28/2d/8aca6cb2cabc8f12efcb82749b9cefecbccfc7b0384e56cd71058ccee433/yarl-1.20.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:66252d780b45189975abfed839616e8fd2dbacbdc262105ad7742c6ae58f3e31", size = 342616, upload-time = "2025-06-10T00:44:26.167Z" },
+ { url = "https://files.pythonhosted.org/packages/0b/e9/1312633d16b31acf0098d30440ca855e3492d66623dafb8e25b03d00c3da/yarl-1.20.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:59174e7332f5d153d8f7452a102b103e2e74035ad085f404df2e40e663a22b28", size = 361324, upload-time = "2025-06-10T00:44:27.915Z" },
+ { url = "https://files.pythonhosted.org/packages/bc/a0/688cc99463f12f7669eec7c8acc71ef56a1521b99eab7cd3abb75af887b0/yarl-1.20.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e3968ec7d92a0c0f9ac34d5ecfd03869ec0cab0697c91a45db3fbbd95fe1b653", size = 359676, upload-time = "2025-06-10T00:44:30.041Z" },
+ { url = "https://files.pythonhosted.org/packages/af/44/46407d7f7a56e9a85a4c207724c9f2c545c060380718eea9088f222ba697/yarl-1.20.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d1a4fbb50e14396ba3d375f68bfe02215d8e7bc3ec49da8341fe3157f59d2ff5", size = 352614, upload-time = "2025-06-10T00:44:32.171Z" },
+ { url = "https://files.pythonhosted.org/packages/b1/91/31163295e82b8d5485d31d9cf7754d973d41915cadce070491778d9c9825/yarl-1.20.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:11a62c839c3a8eac2410e951301309426f368388ff2f33799052787035793b02", size = 336766, upload-time = "2025-06-10T00:44:34.494Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/8e/c41a5bc482121f51c083c4c2bcd16b9e01e1cf8729e380273a952513a21f/yarl-1.20.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:041eaa14f73ff5a8986b4388ac6bb43a77f2ea09bf1913df7a35d4646db69e53", size = 364615, upload-time = "2025-06-10T00:44:36.856Z" },
+ { url = "https://files.pythonhosted.org/packages/e3/5b/61a3b054238d33d70ea06ebba7e58597891b71c699e247df35cc984ab393/yarl-1.20.1-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:377fae2fef158e8fd9d60b4c8751387b8d1fb121d3d0b8e9b0be07d1b41e83dc", size = 360982, upload-time = "2025-06-10T00:44:39.141Z" },
+ { url = "https://files.pythonhosted.org/packages/df/a3/6a72fb83f8d478cb201d14927bc8040af901811a88e0ff2da7842dd0ed19/yarl-1.20.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:1c92f4390e407513f619d49319023664643d3339bd5e5a56a3bebe01bc67ec04", size = 369792, upload-time = "2025-06-10T00:44:40.934Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/af/4cc3c36dfc7c077f8dedb561eb21f69e1e9f2456b91b593882b0b18c19dc/yarl-1.20.1-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:d25ddcf954df1754ab0f86bb696af765c5bfaba39b74095f27eececa049ef9a4", size = 382049, upload-time = "2025-06-10T00:44:42.854Z" },
+ { url = "https://files.pythonhosted.org/packages/19/3a/e54e2c4752160115183a66dc9ee75a153f81f3ab2ba4bf79c3c53b33de34/yarl-1.20.1-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:909313577e9619dcff8c31a0ea2aa0a2a828341d92673015456b3ae492e7317b", size = 384774, upload-time = "2025-06-10T00:44:45.275Z" },
+ { url = "https://files.pythonhosted.org/packages/9c/20/200ae86dabfca89060ec6447649f219b4cbd94531e425e50d57e5f5ac330/yarl-1.20.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:793fd0580cb9664548c6b83c63b43c477212c0260891ddf86809e1c06c8b08f1", size = 374252, upload-time = "2025-06-10T00:44:47.31Z" },
+ { url = "https://files.pythonhosted.org/packages/83/75/11ee332f2f516b3d094e89448da73d557687f7d137d5a0f48c40ff211487/yarl-1.20.1-cp313-cp313-win32.whl", hash = "sha256:468f6e40285de5a5b3c44981ca3a319a4b208ccc07d526b20b12aeedcfa654b7", size = 81198, upload-time = "2025-06-10T00:44:49.164Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/ba/39b1ecbf51620b40ab402b0fc817f0ff750f6d92712b44689c2c215be89d/yarl-1.20.1-cp313-cp313-win_amd64.whl", hash = "sha256:495b4ef2fea40596bfc0affe3837411d6aa3371abcf31aac0ccc4bdd64d4ef5c", size = 86346, upload-time = "2025-06-10T00:44:51.182Z" },
+ { url = "https://files.pythonhosted.org/packages/43/c7/669c52519dca4c95153c8ad96dd123c79f354a376346b198f438e56ffeb4/yarl-1.20.1-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:f60233b98423aab21d249a30eb27c389c14929f47be8430efa7dbd91493a729d", size = 138826, upload-time = "2025-06-10T00:44:52.883Z" },
+ { url = "https://files.pythonhosted.org/packages/6a/42/fc0053719b44f6ad04a75d7f05e0e9674d45ef62f2d9ad2c1163e5c05827/yarl-1.20.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:6f3eff4cc3f03d650d8755c6eefc844edde99d641d0dcf4da3ab27141a5f8ddf", size = 93217, upload-time = "2025-06-10T00:44:54.658Z" },
+ { url = "https://files.pythonhosted.org/packages/4f/7f/fa59c4c27e2a076bba0d959386e26eba77eb52ea4a0aac48e3515c186b4c/yarl-1.20.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:69ff8439d8ba832d6bed88af2c2b3445977eba9a4588b787b32945871c2444e3", size = 92700, upload-time = "2025-06-10T00:44:56.784Z" },
+ { url = "https://files.pythonhosted.org/packages/2f/d4/062b2f48e7c93481e88eff97a6312dca15ea200e959f23e96d8ab898c5b8/yarl-1.20.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3cf34efa60eb81dd2645a2e13e00bb98b76c35ab5061a3989c7a70f78c85006d", size = 347644, upload-time = "2025-06-10T00:44:59.071Z" },
+ { url = "https://files.pythonhosted.org/packages/89/47/78b7f40d13c8f62b499cc702fdf69e090455518ae544c00a3bf4afc9fc77/yarl-1.20.1-cp313-cp313t-manylinux_2_17_armv7l.manylinux2014_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:8e0fe9364ad0fddab2688ce72cb7a8e61ea42eff3c7caeeb83874a5d479c896c", size = 323452, upload-time = "2025-06-10T00:45:01.605Z" },
+ { url = "https://files.pythonhosted.org/packages/eb/2b/490d3b2dc66f52987d4ee0d3090a147ea67732ce6b4d61e362c1846d0d32/yarl-1.20.1-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8f64fbf81878ba914562c672024089e3401974a39767747691c65080a67b18c1", size = 346378, upload-time = "2025-06-10T00:45:03.946Z" },
+ { url = "https://files.pythonhosted.org/packages/66/ad/775da9c8a94ce925d1537f939a4f17d782efef1f973039d821cbe4bcc211/yarl-1.20.1-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f6342d643bf9a1de97e512e45e4b9560a043347e779a173250824f8b254bd5ce", size = 353261, upload-time = "2025-06-10T00:45:05.992Z" },
+ { url = "https://files.pythonhosted.org/packages/4b/23/0ed0922b47a4f5c6eb9065d5ff1e459747226ddce5c6a4c111e728c9f701/yarl-1.20.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:56dac5f452ed25eef0f6e3c6a066c6ab68971d96a9fb441791cad0efba6140d3", size = 335987, upload-time = "2025-06-10T00:45:08.227Z" },
+ { url = "https://files.pythonhosted.org/packages/3e/49/bc728a7fe7d0e9336e2b78f0958a2d6b288ba89f25a1762407a222bf53c3/yarl-1.20.1-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c7d7f497126d65e2cad8dc5f97d34c27b19199b6414a40cb36b52f41b79014be", size = 329361, upload-time = "2025-06-10T00:45:10.11Z" },
+ { url = "https://files.pythonhosted.org/packages/93/8f/b811b9d1f617c83c907e7082a76e2b92b655400e61730cd61a1f67178393/yarl-1.20.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:67e708dfb8e78d8a19169818eeb5c7a80717562de9051bf2413aca8e3696bf16", size = 346460, upload-time = "2025-06-10T00:45:12.055Z" },
+ { url = "https://files.pythonhosted.org/packages/70/fd/af94f04f275f95da2c3b8b5e1d49e3e79f1ed8b6ceb0f1664cbd902773ff/yarl-1.20.1-cp313-cp313t-musllinux_1_2_armv7l.whl", hash = "sha256:595c07bc79af2494365cc96ddeb772f76272364ef7c80fb892ef9d0649586513", size = 334486, upload-time = "2025-06-10T00:45:13.995Z" },
+ { url = "https://files.pythonhosted.org/packages/84/65/04c62e82704e7dd0a9b3f61dbaa8447f8507655fd16c51da0637b39b2910/yarl-1.20.1-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:7bdd2f80f4a7df852ab9ab49484a4dee8030023aa536df41f2d922fd57bf023f", size = 342219, upload-time = "2025-06-10T00:45:16.479Z" },
+ { url = "https://files.pythonhosted.org/packages/91/95/459ca62eb958381b342d94ab9a4b6aec1ddec1f7057c487e926f03c06d30/yarl-1.20.1-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:c03bfebc4ae8d862f853a9757199677ab74ec25424d0ebd68a0027e9c639a390", size = 350693, upload-time = "2025-06-10T00:45:18.399Z" },
+ { url = "https://files.pythonhosted.org/packages/a6/00/d393e82dd955ad20617abc546a8f1aee40534d599ff555ea053d0ec9bf03/yarl-1.20.1-cp313-cp313t-musllinux_1_2_s390x.whl", hash = "sha256:344d1103e9c1523f32a5ed704d576172d2cabed3122ea90b1d4e11fe17c66458", size = 355803, upload-time = "2025-06-10T00:45:20.677Z" },
+ { url = "https://files.pythonhosted.org/packages/9e/ed/c5fb04869b99b717985e244fd93029c7a8e8febdfcffa06093e32d7d44e7/yarl-1.20.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:88cab98aa4e13e1ade8c141daeedd300a4603b7132819c484841bb7af3edce9e", size = 341709, upload-time = "2025-06-10T00:45:23.221Z" },
+ { url = "https://files.pythonhosted.org/packages/24/fd/725b8e73ac2a50e78a4534ac43c6addf5c1c2d65380dd48a9169cc6739a9/yarl-1.20.1-cp313-cp313t-win32.whl", hash = "sha256:b121ff6a7cbd4abc28985b6028235491941b9fe8fe226e6fdc539c977ea1739d", size = 86591, upload-time = "2025-06-10T00:45:25.793Z" },
+ { url = "https://files.pythonhosted.org/packages/94/c3/b2e9f38bc3e11191981d57ea08cab2166e74ea770024a646617c9cddd9f6/yarl-1.20.1-cp313-cp313t-win_amd64.whl", hash = "sha256:541d050a355bbbc27e55d906bc91cb6fe42f96c01413dd0f4ed5a5240513874f", size = 93003, upload-time = "2025-06-10T00:45:27.752Z" },
+ { url = "https://files.pythonhosted.org/packages/b4/2d/2345fce04cfd4bee161bf1e7d9cdc702e3e16109021035dbb24db654a622/yarl-1.20.1-py3-none-any.whl", hash = "sha256:83b8eb083fe4683c6115795d9fc1cfaf2cbbefb19b3a1cb68f6527460f483a77", size = 46542, upload-time = "2025-06-10T00:46:07.521Z" },
+]
+
+[[package]]
+name = "zipp"
+version = "3.23.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/e3/02/0f2892c661036d50ede074e376733dca2ae7c6eb617489437771209d4180/zipp-3.23.0.tar.gz", hash = "sha256:a07157588a12518c9d4034df3fbbee09c814741a33ff63c05fa29d26a2404166", size = 25547, upload-time = "2025-06-08T17:06:39.4Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/2e/54/647ade08bf0db230bfea292f893923872fd20be6ac6f53b2b936ba839d75/zipp-3.23.0-py3-none-any.whl", hash = "sha256:071652d6115ed432f5ce1d34c336c0adfd6a884660d1e9712a256d3d3bd4b14e", size = 10276, upload-time = "2025-06-08T17:06:38.034Z" },
+]
diff --git a/workers/worker.py b/workers/worker.py
new file mode 100755
index 000000000..9e3faff7f
--- /dev/null
+++ b/workers/worker.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+"""Unified Celery Worker Entry Point
+
+This module serves as the main entry point for all Celery workers.
+It uses WorkerBuilder to ensure proper configuration including chord retry settings.
+"""
+
+import logging
+import os
+import sys
+
+# Add the workers directory to Python path
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+
+# Import the WorkerBuilder and WorkerType
+from shared.enums.worker_enums import WorkerType
+from shared.infrastructure import initialize_worker_infrastructure
+from shared.infrastructure.config.builder import WorkerBuilder
+
+# Determine worker type from environment FIRST
+WORKER_TYPE = os.environ.get("WORKER_TYPE", "general")
+
+# Convert WORKER_TYPE string to WorkerType enum
+# Handle directory name mapping: directories use hyphens, enums use underscores
+worker_type_mapping = {
+ "api-deployment": WorkerType.API_DEPLOYMENT,
+ "api_deployment": WorkerType.API_DEPLOYMENT,
+ "file_processing": WorkerType.FILE_PROCESSING,
+ "file-processing": WorkerType.FILE_PROCESSING,
+ "log_consumer": WorkerType.LOG_CONSUMER,
+ "log-consumer": WorkerType.LOG_CONSUMER,
+ "general": WorkerType.GENERAL,
+ "callback": WorkerType.CALLBACK,
+ "notification": WorkerType.NOTIFICATION,
+ "scheduler": WorkerType.SCHEDULER,
+}
+
+# Get the WorkerType enum
+worker_type = worker_type_mapping.get(WORKER_TYPE, WorkerType.GENERAL)
+
+# CRITICAL: Setup logging IMMEDIATELY before any logging calls
+# This ensures ALL subsequent logs use Django format
+WorkerBuilder.setup_logging(worker_type)
+
+# Now get logger after setup is complete
+logger = logging.getLogger(__name__)
+
+logger.info("🚀 Unified Worker Entry Point - Using WorkerBuilder System")
+logger.info(f"📋 Worker Type: {WORKER_TYPE}")
+logger.info(f"🐳 Running from: {os.getcwd()}")
+logger.info(f"📦 Converted '{WORKER_TYPE}' to {worker_type}")
+
+# Use WorkerBuilder to create the Celery app with proper configuration
+# This ensures chord retry configuration is applied correctly
+logger.info(f"🔧 Building Celery app using WorkerBuilder for {worker_type}")
+app, config = WorkerBuilder.build_celery_app(worker_type)
+
+# Initialize worker infrastructure (singleton API clients, cache managers, etc.)
+# This must happen BEFORE task imports so tasks can use shared infrastructure
+logger.info("🏗️ Initializing worker infrastructure (singleton pattern)...")
+
+initialize_worker_infrastructure()
+logger.info("✅ Worker infrastructure initialized successfully")
+
+# Import tasks from the worker-specific directory
+# Handle directory name mapping for task imports
+worker_dir_mapping = {
+ WorkerType.API_DEPLOYMENT: "api-deployment",
+ WorkerType.FILE_PROCESSING: "file_processing",
+ WorkerType.LOG_CONSUMER: "log_consumer",
+ WorkerType.GENERAL: "general",
+ WorkerType.CALLBACK: "callback",
+ WorkerType.NOTIFICATION: "notification",
+ WorkerType.SCHEDULER: "scheduler",
+}
+
+worker_directory = worker_dir_mapping.get(worker_type, WORKER_TYPE)
+worker_path = os.path.join(os.path.dirname(__file__), worker_directory)
+
+# Add worker directory to path for task imports
+if os.path.exists(worker_path):
+ sys.path.append(worker_path)
+ logger.info(f"✅ Added {worker_directory} to Python path for task imports")
+
+ # Import tasks module to register tasks
+ tasks_file = os.path.join(worker_path, "tasks.py")
+ if os.path.exists(tasks_file):
+ logger.info(f"📋 Loading tasks from: {tasks_file}")
+ # Import the tasks module to register tasks with the app
+ import importlib.util
+
+ spec = importlib.util.spec_from_file_location("tasks", tasks_file)
+ tasks_module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(tasks_module)
+ logger.info(f"✅ Tasks loaded successfully from {worker_directory}")
+ else:
+ logger.warning(f"⚠️ No tasks.py found at: {tasks_file}")
+else:
+ logger.error(f"❌ Worker directory not found: {worker_path}")
+
+# Log successful configuration
+logger.info(f"✅ Successfully loaded {worker_type} worker using WorkerBuilder")
+logger.info(
+ f"📊 Chord retry interval: {getattr(app.conf, 'result_chord_retry_interval', 'NOT SET')}"
+)
+logger.info(f"🎯 Worker '{config.worker_name}' ready for Celery")
+
+# Export for Celery to use
+__all__ = ["app", "config"]