Improve AI logic
This commit is contained in:
@@ -26,6 +26,12 @@ READ_ONLY_WHITELIST_PATTERNS = [
|
||||
r'^/api/v1/users/me/export.*$',
|
||||
r'^/api/v1/subscriptions/.*',
|
||||
r'^/api/v1/auth/.*', # Allow auth operations
|
||||
r'^/api/v1/tenants/.*/orchestrator/run-daily-workflow$', # Allow workflow testing
|
||||
r'^/api/v1/tenants/.*/inventory/ml/insights/.*', # Allow ML insights (safety stock optimization)
|
||||
r'^/api/v1/tenants/.*/production/ml/insights/.*', # Allow ML insights (yield prediction)
|
||||
r'^/api/v1/tenants/.*/procurement/ml/insights/.*', # Allow ML insights (supplier analysis, price forecasting)
|
||||
r'^/api/v1/tenants/.*/forecasting/ml/insights/.*', # Allow ML insights (rules generation)
|
||||
r'^/api/v1/tenants/.*/forecasting/operations/.*', # Allow forecasting operations
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -172,6 +172,16 @@ async def proxy_tenant_analytics(request: Request, tenant_id: str = Path(...), p
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/analytics/{path}".rstrip("/")
|
||||
return await _proxy_to_sales_service(request, target_path)
|
||||
|
||||
# ================================================================
|
||||
# TENANT-SCOPED AI INSIGHTS ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
@router.api_route("/{tenant_id}/insights{path:path}", methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_insights(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant AI insights requests to AI insights service"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/insights{path}".rstrip("/")
|
||||
return await _proxy_to_ai_insights_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@router.api_route("/{tenant_id}/onboarding/{path:path}", methods=["GET", "POST", "OPTIONS"])
|
||||
async def proxy_tenant_onboarding(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant onboarding requests to sales service"""
|
||||
@@ -354,9 +364,9 @@ async def proxy_tenant_customers(request: Request, tenant_id: str = Path(...), p
|
||||
@router.api_route("/{tenant_id}/procurement/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_procurement(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant procurement requests to procurement service"""
|
||||
# Remove the /procurement/ part from the path since procurement service doesn't have this prefix
|
||||
# The procurement service expects /api/v1/tenants/{tenant_id}/purchase-orders, not /api/v1/tenants/{tenant_id}/procurement/purchase-orders
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/{path}".rstrip("/")
|
||||
# For all procurement routes, we need to maintain the /procurement/ part in the path
|
||||
# The procurement service now uses standardized paths with RouteBuilder
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/procurement/{path}".rstrip("/")
|
||||
return await _proxy_to_procurement_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
# ================================================================
|
||||
@@ -375,11 +385,9 @@ async def proxy_tenant_suppliers_with_path(request: Request, tenant_id: str = Pa
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/suppliers/{path}".rstrip("/")
|
||||
return await _proxy_to_suppliers_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@router.api_route("/{tenant_id}/purchase-orders{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_purchase_orders(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant purchase order requests to procurement service"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/purchase-orders{path}".rstrip("/")
|
||||
return await _proxy_to_procurement_service(request, target_path, tenant_id=tenant_id)
|
||||
# NOTE: Purchase orders are now accessed via the main procurement route:
|
||||
# /api/v1/tenants/{tenant_id}/procurement/purchase-orders/*
|
||||
# Legacy route removed to enforce standardized structure
|
||||
|
||||
@router.api_route("/{tenant_id}/deliveries{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_deliveries(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
@@ -477,6 +485,10 @@ async def _proxy_to_orchestrator_service(request: Request, target_path: str, ten
|
||||
"""Proxy request to orchestrator service"""
|
||||
return await _proxy_request(request, target_path, settings.ORCHESTRATOR_SERVICE_URL, tenant_id=tenant_id)
|
||||
|
||||
async def _proxy_to_ai_insights_service(request: Request, target_path: str, tenant_id: str = None):
|
||||
"""Proxy request to AI insights service"""
|
||||
return await _proxy_request(request, target_path, settings.AI_INSIGHTS_SERVICE_URL, tenant_id=tenant_id)
|
||||
|
||||
async def _proxy_request(request: Request, target_path: str, service_url: str, tenant_id: str = None):
|
||||
"""Generic proxy function with enhanced error handling"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user