greentic-flow-builder 0.1.0

AI-powered Adaptive Card flow builder with visual graph editor and demo runner
Documentation
//! Core type definitions for the template system.
//!
//! Types here are plain data structures with no behavior.
//! Logic lives in `registry/`, `theme/`, `render/`, `discovery/`.

use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::BTreeMap;

/// Metadata about a primitive (atomic building block).
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PrimitiveInfo {
    pub name: String,
    pub description: String,
    #[serde(default)]
    pub tags: Vec<String>,
    #[serde(default)]
    pub props: BTreeMap<String, PrimitiveProp>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PrimitiveProp {
    #[serde(rename = "type")]
    pub prop_type: String,
    #[serde(default)]
    pub required: bool,
    #[serde(default)]
    pub description: String,
}

/// Top-level primitives manifest (from `_primitives.json`).
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PrimitivesManifest {
    pub version: String,
    pub primitives: Vec<PrimitiveInfo>,
}

/// Information about a preset template.
#[derive(Debug, Clone)]
pub struct PresetInfo {
    pub name: String,
    pub category: String,
    pub title: String,
    pub description: String,
    pub tags: Vec<String>,
    pub use_cases: Vec<String>,
    pub example: Value,
    pub schema: Value,
    pub template_source: String,
}

/// Category grouping for presets.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Category {
    pub name: String,
    pub display_name: String,
    pub description: String,
    pub presets: Vec<String>,
}

/// Master catalog (from `_catalog.json`).
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Catalog {
    pub categories: Vec<Category>,
}

/// Theme definition (from `_themes/*.json`).
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Theme {
    pub name: String,
    pub display_name: String,
    #[serde(default)]
    pub description: String,
    pub tokens: BTreeMap<String, Value>,
    #[serde(default)]
    pub host_config: Value,
}

/// External template pack metadata (from `pack.json`).
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PackMetadata {
    pub name: String,
    pub version: String,
    #[serde(default)]
    pub description: String,
    #[serde(default)]
    pub author: String,
}

/// Render request variants.
#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum RenderRequest {
    Preset {
        #[serde(alias = "template")]
        preset: String,
        #[serde(default)]
        theme: Option<String>,
        #[serde(default)]
        data: Value,
    },
    Compose {
        preset: String, // must be "compose"
        #[serde(default)]
        theme: Option<String>,
        sections: Vec<ComposeSection>,
    },
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ComposeSection {
    pub primitive: String,
    #[serde(flatten)]
    pub data: Value,
}

/// Render response (returned to HTTP client).
#[derive(Debug, Clone, Serialize)]
pub struct RenderResponse {
    pub card: Value,
    pub host_config: Value,
    pub preset: String,
    pub theme: String,
}