greentic-flow-builder 0.4.0

Greentic Flow Builder — orchestrator that powers Adaptive Card design via the adaptive-card-mcp toolkit
Documentation
//! Shared application state for the Axum UI server.

use crate::knowledge::Knowledge;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::Mutex;

pub struct AppState {
    pub openai_api_key: String,
    pub model: String,
    pub system_prompt: String,
    pub knowledge_base: Arc<Knowledge>,
    /// Active pack jobs, keyed by job ID.
    pub pack_jobs: Mutex<HashMap<String, PackJob>>,
    /// Active wizard jobs, keyed by job ID.
    pub wizard_jobs: Mutex<HashMap<String, WizardJob>>,
}

/// State of a running or completed pack job.
#[derive(Debug, Clone)]
pub struct PackJob {
    /// Log lines captured from stderr/stdout of the subprocess.
    pub lines: Vec<PackLogLine>,
    /// 0-100 progress estimate.
    pub progress: u8,
    /// Current step label.
    pub step: String,
    /// Final status.
    pub status: PackJobStatus,
    /// Result path (set on success).
    pub pack_path: Option<String>,
    /// Workspace path (set on success).
    pub workspace_path: Option<String>,
    /// Download URL (set on success).
    pub download_url: Option<String>,
    /// Filename (set on success).
    pub filename: Option<String>,
    /// Error message (set on failure).
    pub error: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PackJobStatus {
    Running,
    Done,
    Failed,
}
impl PackJobStatus {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Running => "running",
            Self::Done => "done",
            Self::Failed => "failed",
        }
    }
}

#[derive(Debug, Clone)]
pub struct PackLogLine {
    pub text: String,
    pub kind: LogKind,
}

#[derive(Debug, Clone)]
pub enum LogKind {
    Info,
    Progress,
    Warning,
    Error,
    Done,
}
impl LogKind {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Info => "info",
            Self::Progress => "progress",
            Self::Warning => "warning",
            Self::Error => "error",
            Self::Done => "done",
        }
    }
}

/// State of a wizard build/deploy job.
#[derive(Debug, Clone)]
pub struct WizardJob {
    pub mode: WizardMode,
    pub lines: Vec<PackLogLine>,
    pub progress: u8,
    pub step: String,
    pub status: WizardJobStatus,
    pub download_url: Option<String>,
    pub filename: Option<String>,
    pub deploy_url: Option<String>,
    pub error: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WizardMode {
    Deploy,
    Develop,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WizardJobStatus {
    Building,
    Deploying,
    Done,
    Failed,
}
impl WizardJobStatus {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Building => "building",
            Self::Deploying => "deploying",
            Self::Done => "done",
            Self::Failed => "failed",
        }
    }
}