Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
π ARF Ultimate Investor Demo v3.8.0 - ENTERPRISE EDITION
|
| 3 |
MODULAR VERSION - Properly integrated with all components
|
| 4 |
ULTIMATE FIXED VERSION with all critical issues resolved
|
| 5 |
-
NOW WITH REAL ARF v3.3.7 INTEGRATION
|
| 6 |
"""
|
| 7 |
|
| 8 |
import logging
|
|
@@ -12,6 +12,7 @@ import json
|
|
| 12 |
import datetime
|
| 13 |
import asyncio
|
| 14 |
import time
|
|
|
|
| 15 |
from pathlib import Path
|
| 16 |
from typing import Dict, List, Any, Optional, Tuple
|
| 17 |
|
|
@@ -72,13 +73,78 @@ class Settings:
|
|
| 72 |
"""Simple settings class"""
|
| 73 |
def __init__(self):
|
| 74 |
self.arf_mode = "demo"
|
| 75 |
-
self.use_mock_arf =
|
| 76 |
self.default_scenario = "Cache Miss Storm"
|
| 77 |
self.max_history_items = 100
|
| 78 |
self.auto_refresh_seconds = 30
|
| 79 |
|
| 80 |
settings = Settings()
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# ===========================================
|
| 83 |
# REAL ARF ORCHESTRATOR (Replaces FixedDemoOrchestrator)
|
| 84 |
# ===========================================
|
|
@@ -113,17 +179,255 @@ class RealARFOrchestrator:
|
|
| 113 |
self._init_mock_fallback()
|
| 114 |
|
| 115 |
def _init_mock_fallback(self):
|
| 116 |
-
"""Initialize mock fallback functions"""
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
self._simulate_arf_analysis = simulate_arf_analysis
|
| 124 |
self._run_rag_similarity_search = run_rag_similarity_search
|
| 125 |
-
self._create_mock_healing_intent = create_mock_healing_intent
|
| 126 |
self._calculate_pattern_confidence = calculate_pattern_confidence
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
async def analyze_incident(self, scenario_name: str, scenario_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 129 |
"""
|
|
@@ -175,19 +479,26 @@ class RealARFOrchestrator:
|
|
| 175 |
return await self._analyze_with_mock(scenario_name, scenario_data)
|
| 176 |
|
| 177 |
async def _analyze_with_mock(self, scenario_name: str, scenario_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 178 |
-
"""Fallback mock analysis"""
|
| 179 |
-
logger.info(f"Using mock analysis for: {scenario_name}")
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# Step 1: Detection Agent
|
| 183 |
-
detection_result = self._simulate_arf_analysis(
|
| 184 |
|
| 185 |
# Step 2: Recall Agent
|
| 186 |
-
similar_incidents = self._run_rag_similarity_search(
|
| 187 |
|
| 188 |
# Step 3: Decision Agent
|
| 189 |
-
confidence = self._calculate_pattern_confidence(
|
| 190 |
-
healing_intent = self._create_mock_healing_intent(
|
| 191 |
|
| 192 |
# Simulate processing time
|
| 193 |
await asyncio.sleep(0.5)
|
|
@@ -209,7 +520,7 @@ class RealARFOrchestrator:
|
|
| 209 |
}
|
| 210 |
}
|
| 211 |
|
| 212 |
-
logger.info(f"
|
| 213 |
return result
|
| 214 |
|
| 215 |
except Exception as e:
|
|
@@ -334,37 +645,16 @@ def import_components() -> Dict[str, Any]:
|
|
| 334 |
logger.warning(f"EnhancedVisualizationEngine not available: {e}")
|
| 335 |
class MockVisualizationEngine:
|
| 336 |
def create_executive_dashboard(self, data=None):
|
| 337 |
-
|
| 338 |
-
fig = go.Figure()
|
| 339 |
-
fig.update_layout(height=400, title="Executive Dashboard")
|
| 340 |
-
return fig
|
| 341 |
|
| 342 |
def create_telemetry_plot(self, scenario_name, anomaly_detected=True):
|
| 343 |
-
|
| 344 |
-
import numpy as np
|
| 345 |
-
fig = go.Figure()
|
| 346 |
-
fig.add_trace(go.Scatter(x=[0, 1, 2], y=[0, 1, 0]))
|
| 347 |
-
fig.update_layout(height=300, title=f"Telemetry: {scenario_name}")
|
| 348 |
-
return fig
|
| 349 |
|
| 350 |
def create_impact_gauge(self, scenario_name):
|
| 351 |
-
|
| 352 |
-
fig = go.Figure(go.Indicator(
|
| 353 |
-
mode="gauge+number",
|
| 354 |
-
value=8500,
|
| 355 |
-
title={'text': "π° Hourly Revenue Risk"},
|
| 356 |
-
gauge={'axis': {'range': [0, 15000]}}
|
| 357 |
-
))
|
| 358 |
-
fig.update_layout(height=300)
|
| 359 |
-
return fig
|
| 360 |
|
| 361 |
def create_timeline_comparison(self):
|
| 362 |
-
|
| 363 |
-
fig = go.Figure()
|
| 364 |
-
fig.add_trace(go.Bar(name='Manual', x=['Detection', 'Resolution'], y=[300, 2700]))
|
| 365 |
-
fig.add_trace(go.Bar(name='ARF', x=['Detection', 'Resolution'], y=[45, 720]))
|
| 366 |
-
fig.update_layout(height=400, title="Timeline Comparison")
|
| 367 |
-
return fig
|
| 368 |
components["EnhancedVisualizationEngine"] = MockVisualizationEngine()
|
| 369 |
|
| 370 |
# Import UI components
|
|
@@ -549,12 +839,7 @@ def create_telemetry_plot(scenario_name: str):
|
|
| 549 |
return viz_engine.create_telemetry_plot(scenario_name, anomaly_detected=True)
|
| 550 |
except Exception as e:
|
| 551 |
logger.error(f"Failed to create telemetry plot: {e}")
|
| 552 |
-
|
| 553 |
-
import plotly.graph_objects as go
|
| 554 |
-
fig = go.Figure()
|
| 555 |
-
fig.add_trace(go.Scatter(x=[0, 1, 2], y=[0, 1, 0]))
|
| 556 |
-
fig.update_layout(height=300, title=f"Telemetry: {scenario_name}")
|
| 557 |
-
return fig
|
| 558 |
|
| 559 |
def create_impact_plot(scenario_name: str):
|
| 560 |
"""Create a business impact visualization"""
|
|
@@ -563,16 +848,7 @@ def create_impact_plot(scenario_name: str):
|
|
| 563 |
return viz_engine.create_impact_gauge(scenario_name)
|
| 564 |
except Exception as e:
|
| 565 |
logger.error(f"Failed to create impact plot: {e}")
|
| 566 |
-
|
| 567 |
-
import plotly.graph_objects as go
|
| 568 |
-
fig = go.Figure(go.Indicator(
|
| 569 |
-
mode="gauge+number",
|
| 570 |
-
value=8500,
|
| 571 |
-
title={'text': "π° Hourly Revenue Risk"},
|
| 572 |
-
gauge={'axis': {'range': [0, 15000]}}
|
| 573 |
-
))
|
| 574 |
-
fig.update_layout(height=300)
|
| 575 |
-
return fig
|
| 576 |
|
| 577 |
def create_timeline_plot(scenario_name: str):
|
| 578 |
"""Create an incident timeline visualization"""
|
|
@@ -581,19 +857,13 @@ def create_timeline_plot(scenario_name: str):
|
|
| 581 |
return viz_engine.create_timeline_comparison()
|
| 582 |
except Exception as e:
|
| 583 |
logger.error(f"Failed to create timeline plot: {e}")
|
| 584 |
-
|
| 585 |
-
import plotly.graph_objects as go
|
| 586 |
-
fig = go.Figure()
|
| 587 |
-
fig.add_trace(go.Bar(name='Manual', x=['Detection', 'Resolution'], y=[300, 2700]))
|
| 588 |
-
fig.add_trace(go.Bar(name='ARF', x=['Detection', 'Resolution'], y=[45, 720]))
|
| 589 |
-
fig.update_layout(height=400, title="Timeline Comparison")
|
| 590 |
-
return fig
|
| 591 |
|
| 592 |
# ===========================================
|
| 593 |
# SCENARIO UPDATE HANDLER
|
| 594 |
# ===========================================
|
| 595 |
def update_scenario_display(scenario_name: str) -> tuple:
|
| 596 |
-
"""Update all scenario-related displays"""
|
| 597 |
scenario = get_components()["INCIDENT_SCENARIOS"].get(scenario_name, {})
|
| 598 |
impact = scenario.get("business_impact", {})
|
| 599 |
metrics = scenario.get("metrics", {})
|
|
@@ -645,11 +915,11 @@ def update_scenario_display(scenario_name: str) -> tuple:
|
|
| 645 |
)
|
| 646 |
|
| 647 |
# ===========================================
|
| 648 |
-
# REAL ARF ANALYSIS HANDLER - UPDATED VERSION
|
| 649 |
# ===========================================
|
| 650 |
@AsyncRunner.async_to_sync
|
| 651 |
async def run_oss_analysis(scenario_name: str):
|
| 652 |
-
"""Run OSS analysis with real ARF v3.3.7"""
|
| 653 |
try:
|
| 654 |
logger.info(f"Running REAL ARF analysis for: {scenario_name}")
|
| 655 |
|
|
@@ -673,17 +943,27 @@ async def run_oss_analysis(scenario_name: str):
|
|
| 673 |
# Update incident table
|
| 674 |
incident_table_data = get_audit_manager().get_incident_table()
|
| 675 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
# Enhanced results with real ARF data
|
| 677 |
demo_display = analysis.get("demo_display", {})
|
| 678 |
real_arf_version = demo_display.get("real_arf_version", "mock")
|
| 679 |
|
| 680 |
-
# Extract confidence values
|
| 681 |
if real_arf_version == "3.3.7":
|
| 682 |
oss_analysis = analysis.get("oss_analysis", {})
|
| 683 |
-
detection_confidence = oss_analysis.get("confidence", 0.85)
|
| 684 |
-
similar_count = len(oss_analysis.get("recall", []))
|
| 685 |
-
decision_data = oss_analysis.get("decision", {})
|
| 686 |
-
decision_confidence = decision_data.get("confidence", 0.85)
|
| 687 |
|
| 688 |
# Check for enterprise enhancements
|
| 689 |
enterprise_enhancements = analysis.get("enterprise_enhancements")
|
|
@@ -702,7 +982,7 @@ async def run_oss_analysis(scenario_name: str):
|
|
| 702 |
"findings": [
|
| 703 |
f"Anomaly detected with {detection_confidence:.1%} confidence",
|
| 704 |
f"{similar_count} similar incidents found in RAG memory",
|
| 705 |
-
f"Historical success rate for similar actions:
|
| 706 |
f"Novel execution protocols: {'β
Available' if novel_execution else 'β OSS Only'}"
|
| 707 |
],
|
| 708 |
"recommendations": [
|
|
@@ -711,139 +991,77 @@ async def run_oss_analysis(scenario_name: str):
|
|
| 711 |
"Add enhanced monitoring for key metrics",
|
| 712 |
f"Rollback guarantee: {rollback_guarantee}"
|
| 713 |
],
|
| 714 |
-
"healing_intent":
|
| 715 |
}
|
| 716 |
else:
|
| 717 |
-
# Mock fallback
|
| 718 |
-
detection_confidence = analysis.get("detection", {}).get("confidence", 99.8)
|
| 719 |
-
similar_count = len(analysis.get("recall", []))
|
| 720 |
-
decision_confidence = analysis.get("confidence", 94.0)
|
| 721 |
-
|
| 722 |
oss_results = {
|
| 723 |
-
"status": "β
OSS Analysis Complete (
|
| 724 |
"arf_version": "mock",
|
| 725 |
"scenario": scenario_name,
|
| 726 |
"confidence": decision_confidence,
|
| 727 |
"agents_executed": ["Detection", "Recall", "Decision"],
|
| 728 |
"findings": [
|
| 729 |
-
f"Anomaly detected with {detection_confidence
|
| 730 |
f"{similar_count} similar incidents found in RAG memory",
|
| 731 |
-
f"Historical success rate for similar actions:
|
|
|
|
|
|
|
| 732 |
],
|
| 733 |
"recommendations": [
|
| 734 |
"Scale resources based on historical patterns",
|
| 735 |
"Implement circuit breaker pattern",
|
| 736 |
"Add enhanced monitoring for key metrics"
|
| 737 |
],
|
| 738 |
-
"healing_intent":
|
| 739 |
-
|
| 740 |
-
"component": scenario.get("component", "unknown"),
|
| 741 |
-
"parameters": {"nodes": "3β5", "region": "auto-select"},
|
| 742 |
-
"confidence": decision_confidence,
|
| 743 |
-
"requires_enterprise": True,
|
| 744 |
-
"advisory_only": True,
|
| 745 |
-
"safety_check": "β
Passed (blast radius: 2 services)"
|
| 746 |
-
})
|
| 747 |
}
|
| 748 |
|
| 749 |
-
# Update agent status HTML -
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
<div style="
|
| 753 |
-
|
| 754 |
-
<
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
<
|
| 758 |
-
|
| 759 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Accuracy: 98.7%</span>
|
| 760 |
-
<span style="font-size: 11px; padding: 3px 8px; background: #10b981; color: white; border-radius: 6px; font-weight: 500;">REAL</span>
|
| 761 |
-
</div>
|
| 762 |
-
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">COMPLETE</div>
|
| 763 |
-
</div>
|
| 764 |
-
</div>
|
| 765 |
-
"""
|
| 766 |
-
|
| 767 |
-
recall_html = f"""
|
| 768 |
-
<div style="border: 2px solid #8b5cf6; border-radius: 14px; padding: 18px; background: #f5f3ff; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
| 769 |
-
<div style="font-size: 32px; margin-bottom: 10px;">π§ </div>
|
| 770 |
-
<div style="width: 100%;">
|
| 771 |
-
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Recall Agent v3.3.7</h4>
|
| 772 |
-
<p style="font-size: 13px; color: #475569; margin-bottom: 12px; line-height: 1.4;"><strong>{similar_count} similar incidents</strong> retrieved from memory</p>
|
| 773 |
-
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 774 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Recall: 92%</span>
|
| 775 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Patterns: 5</span>
|
| 776 |
-
<span style="font-size: 11px; padding: 3px 8px; background: #10b981; color: white; border-radius: 6px; font-weight: 500;">REAL</span>
|
| 777 |
-
</div>
|
| 778 |
-
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">COMPLETE</div>
|
| 779 |
-
</div>
|
| 780 |
-
</div>
|
| 781 |
-
"""
|
| 782 |
-
|
| 783 |
-
decision_html = f"""
|
| 784 |
-
<div style="border: 2px solid #10b981; border-radius: 14px; padding: 18px; background: #f0fdf4; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
| 785 |
-
<div style="font-size: 32px; margin-bottom: 10px;">π―</div>
|
| 786 |
-
<div style="width: 100%;">
|
| 787 |
-
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Decision Agent v3.3.7</h4>
|
| 788 |
-
<p style="font-size: 13px; color: #475569; margin-bottom: 12px; line-height: 1.4;">HealingIntent created with <strong>{decision_confidence:.1%} confidence</strong></p>
|
| 789 |
-
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 790 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Success Rate: 87%</span>
|
| 791 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Safety: 100%</span>
|
| 792 |
-
<span style="font-size: 11px; padding: 3px 8px; background: #10b981; color: white; border-radius: 6px; font-weight: 500;">REAL</span>
|
| 793 |
-
</div>
|
| 794 |
-
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">COMPLETE</div>
|
| 795 |
-
</div>
|
| 796 |
-
</div>
|
| 797 |
-
"""
|
| 798 |
-
else:
|
| 799 |
-
# Mock fallback HTML
|
| 800 |
-
detection_html = f"""
|
| 801 |
-
<div style="border: 2px solid #3b82f6; border-radius: 14px; padding: 18px; background: #eff6ff; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
| 802 |
-
<div style="font-size: 32px; margin-bottom: 10px;">π΅οΈββοΈ</div>
|
| 803 |
-
<div style="width: 100%;">
|
| 804 |
-
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Detection Agent (Mock)</h4>
|
| 805 |
-
<p style="font-size: 13px; color: #475569; margin-bottom: 12px; line-height: 1.4;">Mock analysis: <strong>{detection_confidence}% confidence</strong></p>
|
| 806 |
-
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 807 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Time: 45s</span>
|
| 808 |
-
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Accuracy: 98.7%</span>
|
| 809 |
-
<span style="font-size: 11px; padding: 3px 8px; background: #f59e0b; color: white; border-radius: 6px; font-weight: 500;">MOCK</span>
|
| 810 |
-
</div>
|
| 811 |
-
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">COMPLETE</div>
|
| 812 |
</div>
|
|
|
|
| 813 |
</div>
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
</div>
|
| 827 |
-
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">COMPLETE</div>
|
| 828 |
</div>
|
|
|
|
| 829 |
</div>
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
</div>
|
| 843 |
-
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">COMPLETE</div>
|
| 844 |
</div>
|
|
|
|
| 845 |
</div>
|
| 846 |
-
|
|
|
|
| 847 |
|
| 848 |
logger.info(f"Analysis completed successfully for {scenario_name} (Real ARF: {real_arf_version})")
|
| 849 |
return (
|
|
@@ -890,9 +1108,9 @@ def execute_enterprise_healing(scenario_name, approval_required, mcp_mode_value)
|
|
| 890 |
if "Advisory" in mcp_mode_value:
|
| 891 |
return gr.HTML.update(value="<div style='padding: 20px; background: #fef2f2; border-radius: 14px;'><p>β Cannot execute in Advisory mode. Switch to Approval or Autonomous mode.</p></div>"), {}, []
|
| 892 |
|
| 893 |
-
# Calculate savings
|
| 894 |
impact = scenario.get("business_impact", {})
|
| 895 |
-
revenue_loss = impact.get("revenue_loss_per_hour",
|
| 896 |
savings = int(revenue_loss * 0.85)
|
| 897 |
|
| 898 |
# Add to audit trail
|
|
@@ -1119,7 +1337,7 @@ def create_demo_interface():
|
|
| 1119 |
outputs=[scenario_card, telemetry_viz, impact_viz, timeline_viz]
|
| 1120 |
)
|
| 1121 |
|
| 1122 |
-
# Run OSS Analysis - Now uses REAL ARF
|
| 1123 |
oss_btn.click(
|
| 1124 |
fn=run_oss_analysis,
|
| 1125 |
inputs=[scenario_dropdown],
|
|
@@ -1151,7 +1369,7 @@ def create_demo_interface():
|
|
| 1151 |
|
| 1152 |
scenario = get_components()["INCIDENT_SCENARIOS"].get(scenario_name, {})
|
| 1153 |
impact = scenario.get("business_impact", {})
|
| 1154 |
-
revenue_loss = impact.get("revenue_loss_per_hour",
|
| 1155 |
savings = int(revenue_loss * 0.85)
|
| 1156 |
|
| 1157 |
# Get orchestrator for execution
|
|
@@ -1163,9 +1381,9 @@ def create_demo_interface():
|
|
| 1163 |
"scenario": scenario_name,
|
| 1164 |
"arf_version": "3.3.7",
|
| 1165 |
"steps_completed": [
|
| 1166 |
-
"1. Incident detected (
|
| 1167 |
"2. OSS analysis completed - REAL ARF",
|
| 1168 |
-
"3. HealingIntent created (
|
| 1169 |
"4. Enterprise license validated",
|
| 1170 |
"5. Autonomous execution simulated",
|
| 1171 |
"6. Outcome recorded in RAG memory"
|
|
@@ -1383,34 +1601,36 @@ def create_demo_interface():
|
|
| 1383 |
clear_btn.click(fn=clear_audit_trail, outputs=[execution_table, incident_table])
|
| 1384 |
export_btn.click(fn=export_audit_trail, outputs=[export_text])
|
| 1385 |
|
| 1386 |
-
# ============ INITIALIZATION ============
|
| 1387 |
|
| 1388 |
-
# Initialize scenario display
|
| 1389 |
demo.load(
|
| 1390 |
-
fn=lambda:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1391 |
outputs=[scenario_card, telemetry_viz, impact_viz, timeline_viz]
|
| 1392 |
)
|
| 1393 |
|
| 1394 |
-
# Initialize dashboard
|
| 1395 |
-
|
| 1396 |
-
|
| 1397 |
-
|
| 1398 |
-
|
| 1399 |
-
return chart
|
| 1400 |
-
except Exception as e:
|
| 1401 |
-
logger.error(f"Dashboard initialization failed: {e}")
|
| 1402 |
-
import plotly.graph_objects as go
|
| 1403 |
-
fig = go.Figure(go.Indicator(
|
| 1404 |
-
mode="number+gauge",
|
| 1405 |
-
value=5.2,
|
| 1406 |
-
title={"text": "<b>Executive Dashboard</b><br>ROI Multiplier"},
|
| 1407 |
-
domain={'x': [0, 1], 'y': [0, 1]},
|
| 1408 |
-
gauge={'axis': {'range': [0, 10]}}
|
| 1409 |
-
))
|
| 1410 |
-
fig.update_layout(height=700, paper_bgcolor="rgba(0,0,0,0)")
|
| 1411 |
-
return fig
|
| 1412 |
-
|
| 1413 |
-
demo.load(fn=initialize_dashboard, outputs=[dashboard_output])
|
| 1414 |
|
| 1415 |
return demo
|
| 1416 |
|
|
@@ -1425,7 +1645,7 @@ def main():
|
|
| 1425 |
print(f"π Mode: {settings.arf_mode.upper()}")
|
| 1426 |
print(f"π€ Using REAL ARF: {not settings.use_mock_arf}")
|
| 1427 |
print(f"π― Default Scenario: {settings.default_scenario}")
|
| 1428 |
-
print(f"π’ ARF Version: 3.3.7 with
|
| 1429 |
print("=" * 70)
|
| 1430 |
|
| 1431 |
import gradio as gr
|
|
|
|
| 2 |
π ARF Ultimate Investor Demo v3.8.0 - ENTERPRISE EDITION
|
| 3 |
MODULAR VERSION - Properly integrated with all components
|
| 4 |
ULTIMATE FIXED VERSION with all critical issues resolved
|
| 5 |
+
NOW WITH REAL ARF v3.3.7 INTEGRATION AND DYNAMIC SCENARIO METRICS
|
| 6 |
"""
|
| 7 |
|
| 8 |
import logging
|
|
|
|
| 12 |
import datetime
|
| 13 |
import asyncio
|
| 14 |
import time
|
| 15 |
+
import random
|
| 16 |
from pathlib import Path
|
| 17 |
from typing import Dict, List, Any, Optional, Tuple
|
| 18 |
|
|
|
|
| 73 |
"""Simple settings class"""
|
| 74 |
def __init__(self):
|
| 75 |
self.arf_mode = "demo"
|
| 76 |
+
self.use_mock_arf = True # Start with mock to prevent auto-analysis
|
| 77 |
self.default_scenario = "Cache Miss Storm"
|
| 78 |
self.max_history_items = 100
|
| 79 |
self.auto_refresh_seconds = 30
|
| 80 |
|
| 81 |
settings = Settings()
|
| 82 |
|
| 83 |
+
# ===========================================
|
| 84 |
+
# HELPER FUNCTIONS FOR EMPTY STATES
|
| 85 |
+
# ===========================================
|
| 86 |
+
def create_empty_plot(title: str):
|
| 87 |
+
"""Create an empty placeholder plot"""
|
| 88 |
+
import plotly.graph_objects as go
|
| 89 |
+
fig = go.Figure()
|
| 90 |
+
fig.add_annotation(
|
| 91 |
+
text="π Select a scenario<br>to view data",
|
| 92 |
+
xref="paper", yref="paper",
|
| 93 |
+
x=0.5, y=0.5, showarrow=False,
|
| 94 |
+
font=dict(size=14, color="#64748b")
|
| 95 |
+
)
|
| 96 |
+
fig.update_layout(
|
| 97 |
+
height=300,
|
| 98 |
+
title=title,
|
| 99 |
+
paper_bgcolor="rgba(0,0,0,0)",
|
| 100 |
+
plot_bgcolor="rgba(0,0,0,0)",
|
| 101 |
+
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 102 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)
|
| 103 |
+
)
|
| 104 |
+
return fig
|
| 105 |
+
|
| 106 |
+
def create_empty_dashboard():
|
| 107 |
+
"""Create empty dashboard"""
|
| 108 |
+
import plotly.graph_objects as go
|
| 109 |
+
fig = go.Figure()
|
| 110 |
+
fig.add_annotation(
|
| 111 |
+
text="π Dashboard will populate<br>after ROI calculation",
|
| 112 |
+
xref="paper", yref="paper",
|
| 113 |
+
x=0.5, y=0.5, showarrow=False,
|
| 114 |
+
font=dict(size=16, color="#64748b")
|
| 115 |
+
)
|
| 116 |
+
fig.update_layout(
|
| 117 |
+
height=700,
|
| 118 |
+
paper_bgcolor="rgba(0,0,0,0)",
|
| 119 |
+
plot_bgcolor="rgba(0,0,0,0)",
|
| 120 |
+
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 121 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 122 |
+
title=""
|
| 123 |
+
)
|
| 124 |
+
return fig
|
| 125 |
+
|
| 126 |
+
def get_inactive_agent_html(agent_name: str, description: str):
|
| 127 |
+
"""Get HTML for inactive agent state"""
|
| 128 |
+
icons = {
|
| 129 |
+
"Detection": "π΅οΈββοΈ",
|
| 130 |
+
"Recall": "π§ ",
|
| 131 |
+
"Decision": "π―"
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
return f"""
|
| 135 |
+
<div style="border: 2px solid #e2e8f0; border-radius: 14px; padding: 18px; background: #f8fafc; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0.7;">
|
| 136 |
+
<div style="font-size: 32px; margin-bottom: 10px; opacity: 0.5;">{icons.get(agent_name, 'β³')}</div>
|
| 137 |
+
<div style="width: 100%;">
|
| 138 |
+
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #94a3b8;">{agent_name} Agent</h4>
|
| 139 |
+
<p style="font-size: 13px; color: #cbd5e1; margin-bottom: 12px; line-height: 1.4;">{description}</p>
|
| 140 |
+
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 141 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.5); border-radius: 6px; color: #cbd5e1; font-weight: 500;">Status: Inactive</span>
|
| 142 |
+
</div>
|
| 143 |
+
<div style="display: inline-block; padding: 5px 14px; background: #e2e8f0; border-radius: 20px; font-size: 12px; font-weight: bold; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px;">WAITING</div>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
"""
|
| 147 |
+
|
| 148 |
# ===========================================
|
| 149 |
# REAL ARF ORCHESTRATOR (Replaces FixedDemoOrchestrator)
|
| 150 |
# ===========================================
|
|
|
|
| 179 |
self._init_mock_fallback()
|
| 180 |
|
| 181 |
def _init_mock_fallback(self):
|
| 182 |
+
"""Initialize mock fallback functions with scenario-aware metrics"""
|
| 183 |
+
# We'll use the enhanced mock ARF functions
|
| 184 |
+
# These will be loaded lazily when needed
|
| 185 |
+
self._mock_functions_loaded = False
|
| 186 |
+
self._simulate_arf_analysis = None
|
| 187 |
+
self._run_rag_similarity_search = None
|
| 188 |
+
self._create_mock_healing_intent = None
|
| 189 |
+
self._calculate_pattern_confidence = None
|
| 190 |
+
|
| 191 |
+
def _load_mock_functions(self):
|
| 192 |
+
"""Lazy load enhanced mock ARF functions with scenario-aware metrics"""
|
| 193 |
+
if not self._mock_functions_loaded:
|
| 194 |
+
try:
|
| 195 |
+
# Try to import enhanced mock ARF functions
|
| 196 |
+
from demo.mock_arf import (
|
| 197 |
+
simulate_arf_analysis,
|
| 198 |
+
run_rag_similarity_search,
|
| 199 |
+
create_mock_healing_intent,
|
| 200 |
+
calculate_pattern_confidence
|
| 201 |
+
)
|
| 202 |
+
self._simulate_arf_analysis = simulate_arf_analysis
|
| 203 |
+
self._run_rag_similarity_search = run_rag_similarity_search
|
| 204 |
+
self._create_mock_healing_intent = create_mock_healing_intent
|
| 205 |
+
self._calculate_pattern_confidence = calculate_pattern_confidence
|
| 206 |
+
self._mock_functions_loaded = True
|
| 207 |
+
logger.info("β
Enhanced scenario-aware mock ARF functions loaded")
|
| 208 |
+
except ImportError as e:
|
| 209 |
+
logger.error(f"Failed to load enhanced mock ARF functions: {e}")
|
| 210 |
+
# Create fallback functions with scenario-aware metrics
|
| 211 |
+
self._create_scenario_aware_fallback_functions()
|
| 212 |
+
|
| 213 |
+
def _create_scenario_aware_fallback_functions(self):
|
| 214 |
+
"""Create scenario-aware fallback mock functions"""
|
| 215 |
+
import random
|
| 216 |
+
import time as ttime
|
| 217 |
+
|
| 218 |
+
# Scenario-specific configurations
|
| 219 |
+
scenario_configs = {
|
| 220 |
+
"Cache Miss Storm": {
|
| 221 |
+
"detection_confidence_range": (0.97, 0.995),
|
| 222 |
+
"detection_time_range": (35, 55),
|
| 223 |
+
"accuracy_range": (0.97, 0.995),
|
| 224 |
+
"similar_incidents_range": (2, 5),
|
| 225 |
+
"similarity_score_range": (0.88, 0.96),
|
| 226 |
+
"pattern_confidence_range": (0.91, 0.97),
|
| 227 |
+
"success_rate_range": (0.82, 0.93),
|
| 228 |
+
"cost_savings_range": (5000, 9000)
|
| 229 |
+
},
|
| 230 |
+
"Database Connection Pool Exhaustion": {
|
| 231 |
+
"detection_confidence_range": (0.92, 0.98),
|
| 232 |
+
"detection_time_range": (40, 65),
|
| 233 |
+
"accuracy_range": (0.95, 0.985),
|
| 234 |
+
"similar_incidents_range": (1, 4),
|
| 235 |
+
"similarity_score_range": (0.85, 0.94),
|
| 236 |
+
"pattern_confidence_range": (0.88, 0.95),
|
| 237 |
+
"success_rate_range": (0.78, 0.88),
|
| 238 |
+
"cost_savings_range": (3500, 5500)
|
| 239 |
+
},
|
| 240 |
+
"Kubernetes Memory Leak": {
|
| 241 |
+
"detection_confidence_range": (0.94, 0.99),
|
| 242 |
+
"detection_time_range": (30, 50),
|
| 243 |
+
"accuracy_range": (0.96, 0.99),
|
| 244 |
+
"similar_incidents_range": (3, 6),
|
| 245 |
+
"similarity_score_range": (0.89, 0.95),
|
| 246 |
+
"pattern_confidence_range": (0.90, 0.96),
|
| 247 |
+
"success_rate_range": (0.85, 0.92),
|
| 248 |
+
"cost_savings_range": (4500, 7500)
|
| 249 |
+
},
|
| 250 |
+
"API Rate Limit Storm": {
|
| 251 |
+
"detection_confidence_range": (0.96, 0.99),
|
| 252 |
+
"detection_time_range": (25, 45),
|
| 253 |
+
"accuracy_range": (0.97, 0.99),
|
| 254 |
+
"similar_incidents_range": (2, 4),
|
| 255 |
+
"similarity_score_range": (0.87, 0.93),
|
| 256 |
+
"pattern_confidence_range": (0.89, 0.94),
|
| 257 |
+
"success_rate_range": (0.80, 0.90),
|
| 258 |
+
"cost_savings_range": (3000, 5000)
|
| 259 |
+
},
|
| 260 |
+
"Network Partition": {
|
| 261 |
+
"detection_confidence_range": (0.98, 0.999),
|
| 262 |
+
"detection_time_range": (20, 40),
|
| 263 |
+
"accuracy_range": (0.98, 0.995),
|
| 264 |
+
"similar_incidents_range": (1, 3),
|
| 265 |
+
"similarity_score_range": (0.90, 0.97),
|
| 266 |
+
"pattern_confidence_range": (0.93, 0.98),
|
| 267 |
+
"success_rate_range": (0.75, 0.85),
|
| 268 |
+
"cost_savings_range": (8000, 15000)
|
| 269 |
+
},
|
| 270 |
+
"Storage I/O Saturation": {
|
| 271 |
+
"detection_confidence_range": (0.93, 0.98),
|
| 272 |
+
"detection_time_range": (45, 70),
|
| 273 |
+
"accuracy_range": (0.94, 0.98),
|
| 274 |
+
"similar_incidents_range": (2, 5),
|
| 275 |
+
"similarity_score_range": (0.86, 0.92),
|
| 276 |
+
"pattern_confidence_range": (0.87, 0.93),
|
| 277 |
+
"success_rate_range": (0.79, 0.87),
|
| 278 |
+
"cost_savings_range": (5500, 8500)
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
def get_scenario_config(scenario_name):
|
| 283 |
+
"""Get configuration for a specific scenario"""
|
| 284 |
+
return scenario_configs.get(scenario_name, {
|
| 285 |
+
"detection_confidence_range": (0.90, 0.98),
|
| 286 |
+
"detection_time_range": (30, 60),
|
| 287 |
+
"accuracy_range": (0.92, 0.98),
|
| 288 |
+
"similar_incidents_range": (1, 3),
|
| 289 |
+
"similarity_score_range": (0.85, 0.95),
|
| 290 |
+
"pattern_confidence_range": (0.85, 0.95),
|
| 291 |
+
"success_rate_range": (0.75, 0.90),
|
| 292 |
+
"cost_savings_range": (4000, 8000)
|
| 293 |
+
})
|
| 294 |
+
|
| 295 |
+
def simulate_arf_analysis(scenario):
|
| 296 |
+
"""Scenario-aware mock analysis"""
|
| 297 |
+
scenario_name = scenario.get("name", "Unknown Scenario")
|
| 298 |
+
config = get_scenario_config(scenario_name)
|
| 299 |
+
|
| 300 |
+
# Generate scenario-specific values
|
| 301 |
+
detection_confidence = random.uniform(*config["detection_confidence_range"])
|
| 302 |
+
detection_time = random.randint(*config["detection_time_range"])
|
| 303 |
+
accuracy = random.uniform(*config["accuracy_range"])
|
| 304 |
+
|
| 305 |
+
return {
|
| 306 |
+
"analysis_complete": True,
|
| 307 |
+
"anomaly_detected": True,
|
| 308 |
+
"severity": scenario.get("severity", "HIGH"),
|
| 309 |
+
"confidence": round(detection_confidence, 3),
|
| 310 |
+
"detection_time_ms": detection_time * 1000,
|
| 311 |
+
"detection_time_seconds": detection_time,
|
| 312 |
+
"accuracy": round(accuracy, 3),
|
| 313 |
+
"component": scenario.get("component", "unknown"),
|
| 314 |
+
"scenario_specific": True,
|
| 315 |
+
"scenario_name": scenario_name
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
def run_rag_similarity_search(scenario):
|
| 319 |
+
"""Scenario-aware RAG search"""
|
| 320 |
+
scenario_name = scenario.get("name", "Unknown Scenario")
|
| 321 |
+
config = get_scenario_config(scenario_name)
|
| 322 |
+
|
| 323 |
+
similar_count = random.randint(*config["similar_incidents_range"])
|
| 324 |
+
similar_incidents = []
|
| 325 |
+
|
| 326 |
+
base_time = int(ttime.time())
|
| 327 |
+
|
| 328 |
+
for i in range(similar_count):
|
| 329 |
+
similarity_score = random.uniform(*config["similarity_score_range"])
|
| 330 |
+
cost_savings = random.randint(*config["cost_savings_range"])
|
| 331 |
+
|
| 332 |
+
similar_incidents.append({
|
| 333 |
+
"incident_id": f"inc_{base_time - random.randint(1, 90)}_00{i}",
|
| 334 |
+
"similarity_score": round(similarity_score, 3),
|
| 335 |
+
"success": random.random() > 0.15,
|
| 336 |
+
"resolution": "scale_out",
|
| 337 |
+
"cost_savings": cost_savings,
|
| 338 |
+
"detection_time": f"{random.randint(30, 60)}s",
|
| 339 |
+
"resolution_time": f"{random.randint(10, 25)}m",
|
| 340 |
+
"pattern": f"{scenario_name.lower().replace(' ', '_')}_v{random.randint(1, 3)}",
|
| 341 |
+
"affected_users": random.randint(20000, 60000),
|
| 342 |
+
"component_match": scenario.get("component", "unknown"),
|
| 343 |
+
"rag_source": "production_memory_v3"
|
| 344 |
+
})
|
| 345 |
+
|
| 346 |
+
return similar_incidents
|
| 347 |
+
|
| 348 |
+
def calculate_pattern_confidence(scenario, similar_incidents):
|
| 349 |
+
"""Calculate pattern confidence based on similar incidents"""
|
| 350 |
+
scenario_name = scenario.get("name", "Unknown Scenario")
|
| 351 |
+
config = get_scenario_config(scenario_name)
|
| 352 |
+
|
| 353 |
+
if not similar_incidents:
|
| 354 |
+
return random.uniform(*config["pattern_confidence_range"])
|
| 355 |
+
|
| 356 |
+
# Calculate average similarity and success rate
|
| 357 |
+
similarity_scores = [inc["similarity_score"] for inc in similar_incidents]
|
| 358 |
+
success_rates = [1.0 if inc["success"] else 0.0 for inc in similar_incidents]
|
| 359 |
+
|
| 360 |
+
avg_similarity = sum(similarity_scores) / len(similarity_scores)
|
| 361 |
+
avg_success = sum(success_rates) / len(success_rates)
|
| 362 |
+
|
| 363 |
+
# Weighted average: 60% similarity, 40% success rate
|
| 364 |
+
confidence = (avg_similarity * 0.6) + (avg_success * 0.4)
|
| 365 |
+
|
| 366 |
+
# Keep within scenario range
|
| 367 |
+
min_conf, max_conf = config["pattern_confidence_range"]
|
| 368 |
+
confidence = max(min_conf, min(max_conf, confidence))
|
| 369 |
+
|
| 370 |
+
return round(confidence, 3)
|
| 371 |
+
|
| 372 |
+
def create_mock_healing_intent(scenario, similar_incidents, confidence):
|
| 373 |
+
"""Create mock healing intent based on scenario"""
|
| 374 |
+
scenario_name = scenario.get("name", "Unknown Scenario")
|
| 375 |
+
config = get_scenario_config(scenario_name)
|
| 376 |
+
|
| 377 |
+
component = scenario.get("component", "unknown")
|
| 378 |
+
|
| 379 |
+
# Determine action based on component
|
| 380 |
+
if "cache" in component.lower():
|
| 381 |
+
action = "scale_out"
|
| 382 |
+
parameters = {"nodes": "3β5", "memory": "16GBβ32GB"}
|
| 383 |
+
elif "database" in component.lower():
|
| 384 |
+
action = "restart"
|
| 385 |
+
parameters = {"connections": "reset_pool", "timeout": "30s"}
|
| 386 |
+
elif "kubernetes" in component.lower():
|
| 387 |
+
action = "memory_limit_increase"
|
| 388 |
+
parameters = {"memory": "1Giβ2Gi", "strategy": "pod_restart"}
|
| 389 |
+
elif "api" in component.lower():
|
| 390 |
+
action = "circuit_breaker"
|
| 391 |
+
parameters = {"threshold": "80%", "window": "5m"}
|
| 392 |
+
else:
|
| 393 |
+
action = "investigate"
|
| 394 |
+
parameters = {"priority": "high"}
|
| 395 |
+
|
| 396 |
+
# Calculate success rate
|
| 397 |
+
if similar_incidents:
|
| 398 |
+
success_count = sum(1 for inc in similar_incidents if inc["success"])
|
| 399 |
+
success_rate = success_count / len(similar_incidents)
|
| 400 |
+
else:
|
| 401 |
+
success_rate = random.uniform(*config["success_rate_range"])
|
| 402 |
+
|
| 403 |
+
# Calculate estimated savings
|
| 404 |
+
if similar_incidents:
|
| 405 |
+
avg_savings = sum(inc["cost_savings"] for inc in similar_incidents) / len(similar_incidents)
|
| 406 |
+
else:
|
| 407 |
+
avg_savings = sum(config["cost_savings_range"]) / 2
|
| 408 |
+
|
| 409 |
+
return {
|
| 410 |
+
"action": action,
|
| 411 |
+
"component": component,
|
| 412 |
+
"confidence": confidence,
|
| 413 |
+
"parameters": parameters,
|
| 414 |
+
"success_rate": round(success_rate, 3),
|
| 415 |
+
"estimated_savings": int(avg_savings),
|
| 416 |
+
"safety_checks": {
|
| 417 |
+
"blast_radius": f"{random.randint(1, 3)} services",
|
| 418 |
+
"business_hours": "compliant",
|
| 419 |
+
"rollback_plan": "available"
|
| 420 |
+
},
|
| 421 |
+
"scenario_specific": True,
|
| 422 |
+
"scenario_name": scenario_name
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
self._simulate_arf_analysis = simulate_arf_analysis
|
| 426 |
self._run_rag_similarity_search = run_rag_similarity_search
|
|
|
|
| 427 |
self._calculate_pattern_confidence = calculate_pattern_confidence
|
| 428 |
+
self._create_mock_healing_intent = create_mock_healing_intent
|
| 429 |
+
self._mock_functions_loaded = True
|
| 430 |
+
logger.info("Scenario-aware fallback mock functions created")
|
| 431 |
|
| 432 |
async def analyze_incident(self, scenario_name: str, scenario_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 433 |
"""
|
|
|
|
| 479 |
return await self._analyze_with_mock(scenario_name, scenario_data)
|
| 480 |
|
| 481 |
async def _analyze_with_mock(self, scenario_name: str, scenario_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 482 |
+
"""Fallback mock analysis with scenario-aware metrics"""
|
| 483 |
+
logger.info(f"Using scenario-aware mock analysis for: {scenario_name}")
|
| 484 |
+
|
| 485 |
+
# Load mock functions if not loaded
|
| 486 |
+
self._load_mock_functions()
|
| 487 |
|
| 488 |
try:
|
| 489 |
+
# Add scenario name to data
|
| 490 |
+
scenario_data_with_name = scenario_data.copy()
|
| 491 |
+
scenario_data_with_name["name"] = scenario_name
|
| 492 |
+
|
| 493 |
# Step 1: Detection Agent
|
| 494 |
+
detection_result = self._simulate_arf_analysis(scenario_data_with_name)
|
| 495 |
|
| 496 |
# Step 2: Recall Agent
|
| 497 |
+
similar_incidents = self._run_rag_similarity_search(scenario_data_with_name)
|
| 498 |
|
| 499 |
# Step 3: Decision Agent
|
| 500 |
+
confidence = self._calculate_pattern_confidence(scenario_data_with_name, similar_incidents)
|
| 501 |
+
healing_intent = self._create_mock_healing_intent(scenario_data_with_name, similar_incidents, confidence)
|
| 502 |
|
| 503 |
# Simulate processing time
|
| 504 |
await asyncio.sleep(0.5)
|
|
|
|
| 520 |
}
|
| 521 |
}
|
| 522 |
|
| 523 |
+
logger.info(f"Scenario-aware mock analysis complete for {scenario_name}")
|
| 524 |
return result
|
| 525 |
|
| 526 |
except Exception as e:
|
|
|
|
| 645 |
logger.warning(f"EnhancedVisualizationEngine not available: {e}")
|
| 646 |
class MockVisualizationEngine:
|
| 647 |
def create_executive_dashboard(self, data=None):
|
| 648 |
+
return create_empty_dashboard()
|
|
|
|
|
|
|
|
|
|
| 649 |
|
| 650 |
def create_telemetry_plot(self, scenario_name, anomaly_detected=True):
|
| 651 |
+
return create_empty_plot(f"Telemetry: {scenario_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
|
| 653 |
def create_impact_gauge(self, scenario_name):
|
| 654 |
+
return create_empty_plot(f"Impact: {scenario_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
|
| 656 |
def create_timeline_comparison(self):
|
| 657 |
+
return create_empty_plot("Timeline Comparison")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
components["EnhancedVisualizationEngine"] = MockVisualizationEngine()
|
| 659 |
|
| 660 |
# Import UI components
|
|
|
|
| 839 |
return viz_engine.create_telemetry_plot(scenario_name, anomaly_detected=True)
|
| 840 |
except Exception as e:
|
| 841 |
logger.error(f"Failed to create telemetry plot: {e}")
|
| 842 |
+
return create_empty_plot(f"Telemetry: {scenario_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
|
| 844 |
def create_impact_plot(scenario_name: str):
|
| 845 |
"""Create a business impact visualization"""
|
|
|
|
| 848 |
return viz_engine.create_impact_gauge(scenario_name)
|
| 849 |
except Exception as e:
|
| 850 |
logger.error(f"Failed to create impact plot: {e}")
|
| 851 |
+
return create_empty_plot(f"Impact: {scenario_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
|
| 853 |
def create_timeline_plot(scenario_name: str):
|
| 854 |
"""Create an incident timeline visualization"""
|
|
|
|
| 857 |
return viz_engine.create_timeline_comparison()
|
| 858 |
except Exception as e:
|
| 859 |
logger.error(f"Failed to create timeline plot: {e}")
|
| 860 |
+
return create_empty_plot("Timeline Comparison")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
|
| 862 |
# ===========================================
|
| 863 |
# SCENARIO UPDATE HANDLER
|
| 864 |
# ===========================================
|
| 865 |
def update_scenario_display(scenario_name: str) -> tuple:
|
| 866 |
+
"""Update all scenario-related displays with scenario-specific data"""
|
| 867 |
scenario = get_components()["INCIDENT_SCENARIOS"].get(scenario_name, {})
|
| 868 |
impact = scenario.get("business_impact", {})
|
| 869 |
metrics = scenario.get("metrics", {})
|
|
|
|
| 915 |
)
|
| 916 |
|
| 917 |
# ===========================================
|
| 918 |
+
# REAL ARF ANALYSIS HANDLER - UPDATED VERSION WITH DYNAMIC METRICS
|
| 919 |
# ===========================================
|
| 920 |
@AsyncRunner.async_to_sync
|
| 921 |
async def run_oss_analysis(scenario_name: str):
|
| 922 |
+
"""Run OSS analysis with real ARF v3.3.7 and dynamic scenario metrics"""
|
| 923 |
try:
|
| 924 |
logger.info(f"Running REAL ARF analysis for: {scenario_name}")
|
| 925 |
|
|
|
|
| 943 |
# Update incident table
|
| 944 |
incident_table_data = get_audit_manager().get_incident_table()
|
| 945 |
|
| 946 |
+
# Extract dynamic values from analysis
|
| 947 |
+
detection_result = analysis.get("detection", {})
|
| 948 |
+
detection_confidence = detection_result.get("confidence", 0.987)
|
| 949 |
+
detection_time_seconds = detection_result.get("detection_time_seconds", 45)
|
| 950 |
+
accuracy = detection_result.get("accuracy", 0.987)
|
| 951 |
+
|
| 952 |
+
similar_incidents = analysis.get("recall", [])
|
| 953 |
+
similar_count = len(similar_incidents)
|
| 954 |
+
|
| 955 |
+
decision_confidence = analysis.get("confidence", 0.94)
|
| 956 |
+
healing_intent = analysis.get("decision", {})
|
| 957 |
+
|
| 958 |
+
# Get success rate from healing intent or calculate
|
| 959 |
+
success_rate = healing_intent.get("success_rate", 0.87)
|
| 960 |
+
|
| 961 |
# Enhanced results with real ARF data
|
| 962 |
demo_display = analysis.get("demo_display", {})
|
| 963 |
real_arf_version = demo_display.get("real_arf_version", "mock")
|
| 964 |
|
|
|
|
| 965 |
if real_arf_version == "3.3.7":
|
| 966 |
oss_analysis = analysis.get("oss_analysis", {})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 967 |
|
| 968 |
# Check for enterprise enhancements
|
| 969 |
enterprise_enhancements = analysis.get("enterprise_enhancements")
|
|
|
|
| 982 |
"findings": [
|
| 983 |
f"Anomaly detected with {detection_confidence:.1%} confidence",
|
| 984 |
f"{similar_count} similar incidents found in RAG memory",
|
| 985 |
+
f"Historical success rate for similar actions: {success_rate:.1%}",
|
| 986 |
f"Novel execution protocols: {'β
Available' if novel_execution else 'β OSS Only'}"
|
| 987 |
],
|
| 988 |
"recommendations": [
|
|
|
|
| 991 |
"Add enhanced monitoring for key metrics",
|
| 992 |
f"Rollback guarantee: {rollback_guarantee}"
|
| 993 |
],
|
| 994 |
+
"healing_intent": healing_intent
|
| 995 |
}
|
| 996 |
else:
|
| 997 |
+
# Mock fallback with scenario-aware metrics
|
|
|
|
|
|
|
|
|
|
|
|
|
| 998 |
oss_results = {
|
| 999 |
+
"status": "β
OSS Analysis Complete (Scenario-Aware Mock)",
|
| 1000 |
"arf_version": "mock",
|
| 1001 |
"scenario": scenario_name,
|
| 1002 |
"confidence": decision_confidence,
|
| 1003 |
"agents_executed": ["Detection", "Recall", "Decision"],
|
| 1004 |
"findings": [
|
| 1005 |
+
f"Anomaly detected with {detection_confidence:.1%} confidence",
|
| 1006 |
f"{similar_count} similar incidents found in RAG memory",
|
| 1007 |
+
f"Historical success rate for similar actions: {success_rate:.1%}",
|
| 1008 |
+
f"Detection time: {detection_time_seconds} seconds",
|
| 1009 |
+
f"Analysis accuracy: {accuracy:.1%}"
|
| 1010 |
],
|
| 1011 |
"recommendations": [
|
| 1012 |
"Scale resources based on historical patterns",
|
| 1013 |
"Implement circuit breaker pattern",
|
| 1014 |
"Add enhanced monitoring for key metrics"
|
| 1015 |
],
|
| 1016 |
+
"healing_intent": healing_intent,
|
| 1017 |
+
"scenario_specific": True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
}
|
| 1019 |
|
| 1020 |
+
# Update agent status HTML - Dynamic values based on scenario
|
| 1021 |
+
detection_html = f"""
|
| 1022 |
+
<div style="border: 2px solid #3b82f6; border-radius: 14px; padding: 18px; background: #eff6ff; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
| 1023 |
+
<div style="font-size: 32px; margin-bottom: 10px;">π΅οΈββοΈ</div>
|
| 1024 |
+
<div style="width: 100%;">
|
| 1025 |
+
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Detection Agent</h4>
|
| 1026 |
+
<p style="font-size: 13px; color: #475569; margin-bottom: 12px; line-height: 1.4;">Anomaly detected: <strong>{detection_confidence:.1%} confidence</strong></p>
|
| 1027 |
+
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 1028 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Response: {detection_time_seconds}s</span>
|
| 1029 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Accuracy: {accuracy:.1%}</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1030 |
</div>
|
| 1031 |
+
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">ACTIVE</div>
|
| 1032 |
</div>
|
| 1033 |
+
</div>
|
| 1034 |
+
"""
|
| 1035 |
+
|
| 1036 |
+
recall_html = f"""
|
| 1037 |
+
<div style="border: 2px solid #8b5cf6; border-radius: 14px; padding: 18px; background: #f5f3ff; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
| 1038 |
+
<div style="font-size: 32px; margin-bottom: 10px;">π§ </div>
|
| 1039 |
+
<div style="width: 100%;">
|
| 1040 |
+
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Recall Agent</h4>
|
| 1041 |
+
<p style="font-size: 13px; color: #475569; margin-bottom: 12px; line-height: 1.4;"><strong>{similar_count} similar incidents</strong> found in RAG memory</p>
|
| 1042 |
+
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 1043 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Recall: 92%</span>
|
| 1044 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Context: {similar_count} patterns</span>
|
|
|
|
|
|
|
| 1045 |
</div>
|
| 1046 |
+
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">ACTIVE</div>
|
| 1047 |
</div>
|
| 1048 |
+
</div>
|
| 1049 |
+
"""
|
| 1050 |
+
|
| 1051 |
+
decision_html = f"""
|
| 1052 |
+
<div style="border: 2px solid #10b981; border-radius: 14px; padding: 18px; background: #f0fdf4; text-align: center; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
| 1053 |
+
<div style="font-size: 32px; margin-bottom: 10px;">π―</div>
|
| 1054 |
+
<div style="width: 100%;">
|
| 1055 |
+
<h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Decision Agent</h4>
|
| 1056 |
+
<p style="font-size: 13px; color: #475569; margin-bottom: 12px; line-height: 1.4;">Generating healing intent with <strong>{decision_confidence:.1%} confidence</strong></p>
|
| 1057 |
+
<div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
|
| 1058 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Success Rate: {success_rate:.1%}</span>
|
| 1059 |
+
<span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; color: #475569; font-weight: 500;">Safety: 100%</span>
|
|
|
|
|
|
|
| 1060 |
</div>
|
| 1061 |
+
<div style="display: inline-block; padding: 5px 14px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); border-radius: 20px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; letter-spacing: 0.5px;">ACTIVE</div>
|
| 1062 |
</div>
|
| 1063 |
+
</div>
|
| 1064 |
+
"""
|
| 1065 |
|
| 1066 |
logger.info(f"Analysis completed successfully for {scenario_name} (Real ARF: {real_arf_version})")
|
| 1067 |
return (
|
|
|
|
| 1108 |
if "Advisory" in mcp_mode_value:
|
| 1109 |
return gr.HTML.update(value="<div style='padding: 20px; background: #fef2f2; border-radius: 14px;'><p>β Cannot execute in Advisory mode. Switch to Approval or Autonomous mode.</p></div>"), {}, []
|
| 1110 |
|
| 1111 |
+
# Calculate savings based on scenario
|
| 1112 |
impact = scenario.get("business_impact", {})
|
| 1113 |
+
revenue_loss = impact.get("revenue_loss_per_hour", get_scenario_impact(scenario_name))
|
| 1114 |
savings = int(revenue_loss * 0.85)
|
| 1115 |
|
| 1116 |
# Add to audit trail
|
|
|
|
| 1337 |
outputs=[scenario_card, telemetry_viz, impact_viz, timeline_viz]
|
| 1338 |
)
|
| 1339 |
|
| 1340 |
+
# Run OSS Analysis - Now uses REAL ARF with dynamic metrics
|
| 1341 |
oss_btn.click(
|
| 1342 |
fn=run_oss_analysis,
|
| 1343 |
inputs=[scenario_dropdown],
|
|
|
|
| 1369 |
|
| 1370 |
scenario = get_components()["INCIDENT_SCENARIOS"].get(scenario_name, {})
|
| 1371 |
impact = scenario.get("business_impact", {})
|
| 1372 |
+
revenue_loss = impact.get("revenue_loss_per_hour", get_scenario_impact(scenario_name))
|
| 1373 |
savings = int(revenue_loss * 0.85)
|
| 1374 |
|
| 1375 |
# Get orchestrator for execution
|
|
|
|
| 1381 |
"scenario": scenario_name,
|
| 1382 |
"arf_version": "3.3.7",
|
| 1383 |
"steps_completed": [
|
| 1384 |
+
"1. Incident detected (dynamic time) - REAL ARF",
|
| 1385 |
"2. OSS analysis completed - REAL ARF",
|
| 1386 |
+
"3. HealingIntent created (dynamic confidence) - REAL ARF",
|
| 1387 |
"4. Enterprise license validated",
|
| 1388 |
"5. Autonomous execution simulated",
|
| 1389 |
"6. Outcome recorded in RAG memory"
|
|
|
|
| 1601 |
clear_btn.click(fn=clear_audit_trail, outputs=[execution_table, incident_table])
|
| 1602 |
export_btn.click(fn=export_audit_trail, outputs=[export_text])
|
| 1603 |
|
| 1604 |
+
# ============ INITIALIZATION WITH EMPTY STATES ============
|
| 1605 |
|
| 1606 |
+
# Initialize with empty scenario display
|
| 1607 |
demo.load(
|
| 1608 |
+
fn=lambda: (
|
| 1609 |
+
# Empty scenario card
|
| 1610 |
+
"""
|
| 1611 |
+
<div style="border: 1px solid #e2e8f0; border-radius: 14px; padding: 20px; background: white; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
|
| 1612 |
+
<div style="text-align: center; padding: 40px 20px;">
|
| 1613 |
+
<div style="font-size: 48px; margin-bottom: 20px;">π</div>
|
| 1614 |
+
<h3 style="margin: 0 0 10px 0; font-size: 18px; color: #1e293b;">Select a Scenario</h3>
|
| 1615 |
+
<p style="font-size: 14px; color: #64748b; margin: 0;">Choose an incident scenario from the dropdown to begin analysis</p>
|
| 1616 |
+
</div>
|
| 1617 |
+
</div>
|
| 1618 |
+
""",
|
| 1619 |
+
# Empty telemetry plot
|
| 1620 |
+
create_empty_plot("Select a scenario to view telemetry"),
|
| 1621 |
+
# Empty impact plot
|
| 1622 |
+
create_empty_plot("Select a scenario to view impact"),
|
| 1623 |
+
# Empty timeline plot
|
| 1624 |
+
create_empty_plot("Select a scenario to view timeline")
|
| 1625 |
+
),
|
| 1626 |
outputs=[scenario_card, telemetry_viz, impact_viz, timeline_viz]
|
| 1627 |
)
|
| 1628 |
|
| 1629 |
+
# Initialize dashboard with empty state
|
| 1630 |
+
demo.load(
|
| 1631 |
+
fn=lambda: create_empty_dashboard(),
|
| 1632 |
+
outputs=[dashboard_output]
|
| 1633 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1634 |
|
| 1635 |
return demo
|
| 1636 |
|
|
|
|
| 1645 |
print(f"π Mode: {settings.arf_mode.upper()}")
|
| 1646 |
print(f"π€ Using REAL ARF: {not settings.use_mock_arf}")
|
| 1647 |
print(f"π― Default Scenario: {settings.default_scenario}")
|
| 1648 |
+
print(f"π’ ARF Version: 3.3.7 with Dynamic Scenario Metrics")
|
| 1649 |
print("=" * 70)
|
| 1650 |
|
| 1651 |
import gradio as gr
|