use std::sync::Arc;
use std::time::Duration;
use gadk_agent::AgentError;
use crate::error::{WorkflowErrorKind, workflow_error};
#[derive(Clone, Default)]
pub struct NodeConfig {
pub parallel_worker: bool,
pub rerun_on_resume: Option<bool>,
pub wait_for_output: Option<bool>,
pub retry_config: Option<RetryConfig>,
pub timeout: Option<Duration>,
pub emits_own_span: bool,
}
#[derive(Clone, Default)]
pub struct RetryConfig {
pub max_attempts: i32,
pub initial_delay: Duration,
pub max_delay: Duration,
pub backoff_factor: f64,
pub jitter: f64,
#[allow(clippy::type_complexity)] pub should_retry: Option<Arc<dyn Fn(&AgentError) -> bool + Send + Sync>>,
}
pub(crate) fn default_should_retry(err: &AgentError) -> bool {
!workflow_error(err).is_some_and(|w| w.is(WorkflowErrorKind::InputValidation))
}
pub fn default_retry_config() -> RetryConfig {
RetryConfig {
max_attempts: 5,
initial_delay: Duration::from_secs(1),
max_delay: Duration::from_secs(60),
backoff_factor: 2.0,
jitter: 1.0,
should_retry: Some(Arc::new(default_should_retry)),
}
}