use super::{
ContextAnalyzer, MenuGenerator, OptionGenerator, PersonalizationEngine, RollbackDifficulty,
UserInterventionOption,
};
use crate::planner::stall_detection::StallEvent;
use crate::planner::stall_detection::StallSeverity;
use anyhow::Result;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use uuid::Uuid;
impl MenuGenerator {
pub(crate) fn new() -> Self {
Self {
context_analyzer: Arc::new(ContextAnalyzer::new()),
option_generator: Arc::new(OptionGenerator::new()),
menu_templates: Arc::new(RwLock::new(HashMap::new())),
personalization_engine: Arc::new(PersonalizationEngine::new()),
}
}
pub(crate) async fn generate_intervention_options(
&self,
workflow_id: Uuid,
stall_event: &StallEvent,
) -> Result<Vec<UserInterventionOption>> {
let _ = workflow_id;
let mut options = Vec::new();
options.push(UserInterventionOption {
option_id: Uuid::new_v4(),
title: "Retry Operation".to_string(),
description: "Retry the failed operation with the same parameters".to_string(),
option_type: super::OptionType::Retry,
risk_level: super::RiskLevel::Low,
estimated_impact: super::EstimatedImpact {
time_impact_minutes: 5,
resource_impact: 0.1,
success_probability: 0.7,
side_effects: vec![],
rollback_difficulty: RollbackDifficulty::Easy,
},
prerequisites: vec![],
consequences: vec!["May fail again if root cause not addressed".to_string()],
recommended: true,
metadata: HashMap::new(),
});
options.push(UserInterventionOption {
option_id: Uuid::new_v4(),
title: "Skip Operation".to_string(),
description: "Skip the failed operation and continue with the workflow".to_string(),
option_type: super::OptionType::Skip,
risk_level: super::RiskLevel::Medium,
estimated_impact: super::EstimatedImpact {
time_impact_minutes: 0,
resource_impact: 0.0,
success_probability: 1.0,
side_effects: vec!["Workflow may be incomplete".to_string()],
rollback_difficulty: RollbackDifficulty::Medium,
},
prerequisites: vec!["Operation must be non-critical".to_string()],
consequences: vec!["Workflow results may be incomplete".to_string()],
recommended: false,
metadata: HashMap::new(),
});
options.push(UserInterventionOption {
option_id: Uuid::new_v4(),
title: "Escalate to Administrator".to_string(),
description: "Escalate the issue to a system administrator for manual resolution"
.to_string(),
option_type: super::OptionType::Escalate,
risk_level: super::RiskLevel::Low,
estimated_impact: super::EstimatedImpact {
time_impact_minutes: 30,
resource_impact: 0.2,
success_probability: 0.9,
side_effects: vec!["Requires human intervention".to_string()],
rollback_difficulty: RollbackDifficulty::Easy,
},
prerequisites: vec!["Administrator must be available".to_string()],
consequences: vec!["Workflow will be paused until manual resolution".to_string()],
recommended: matches!(
stall_event.severity,
StallSeverity::High | StallSeverity::Critical
),
metadata: HashMap::new(),
});
options.push(UserInterventionOption {
option_id: Uuid::new_v4(),
title: "Cancel Workflow".to_string(),
description: "Cancel the entire workflow and perform cleanup".to_string(),
option_type: super::OptionType::Cancel,
risk_level: super::RiskLevel::High,
estimated_impact: super::EstimatedImpact {
time_impact_minutes: -1,
resource_impact: -0.5,
success_probability: 1.0,
side_effects: vec!["All workflow progress will be lost".to_string()],
rollback_difficulty: RollbackDifficulty::Impossible,
},
prerequisites: vec![],
consequences: vec!["Workflow will be terminated and cannot be resumed".to_string()],
recommended: false,
metadata: HashMap::new(),
});
Ok(options)
}
}
impl ContextAnalyzer {
fn new() -> Self {
Self {
analysis_rules: Arc::new(RwLock::new(Vec::new())),
context_cache: Arc::new(RwLock::new(HashMap::new())),
}
}
}
impl OptionGenerator {
fn new() -> Self {
Self {
generation_strategies: Arc::new(RwLock::new(Vec::new())),
option_cache: Arc::new(RwLock::new(HashMap::new())),
}
}
}
impl PersonalizationEngine {
fn new() -> Self {
Self {
user_profiles: Arc::new(RwLock::new(HashMap::new())),
preference_models: Arc::new(RwLock::new(HashMap::new())),
adaptation_rules: Arc::new(RwLock::new(Vec::new())),
}
}
}