Skip to main content

butterflow_models/
template.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use ts_rs::TS;
5
6use crate::runtime::Runtime;
7use crate::step::Step;
8
9/// Represents a template input
10#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
11pub struct TemplateInput {
12    /// Name of the input
13    pub name: String,
14
15    /// Type of the input (string, number, boolean)
16    #[serde(default = "default_input_type")]
17    pub r#type: String,
18
19    /// Whether the input is required
20    #[serde(default)]
21    #[ts(optional, as = "Option<bool>")]
22    pub required: bool,
23
24    /// Description of the input
25    #[serde(default)]
26    pub description: Option<String>,
27
28    /// Default value for the input
29    #[serde(default)]
30    pub default: Option<String>,
31}
32
33/// Represents a template output
34#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
35pub struct TemplateOutput {
36    /// Name of the output
37    pub name: String,
38
39    /// Value of the output
40    pub value: String,
41
42    /// Description of the output
43    #[serde(default)]
44    pub description: Option<String>,
45}
46
47/// Represents a reusable template
48#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
49pub struct Template {
50    /// Unique identifier for the template
51    pub id: String,
52
53    /// Human-readable name
54    pub name: String,
55
56    /// Detailed description of what the template does
57    #[serde(default)]
58    #[ts(optional=nullable)]
59    pub description: Option<String>,
60
61    /// Container runtime configuration
62    #[serde(default)]
63    #[ts(optional=nullable)]
64    pub runtime: Option<Runtime>,
65
66    /// Inputs for the template
67    #[serde(default)]
68    pub inputs: Vec<TemplateInput>,
69
70    /// Steps to execute within the template
71    pub steps: Vec<Step>,
72
73    /// Outputs from the template
74    #[serde(default)]
75    #[ts(optional, as = "Option<Vec<TemplateOutput>>")]
76    pub outputs: Vec<TemplateOutput>,
77
78    /// Environment variables to inject into the container
79    #[serde(default)]
80    #[ts(as = "Option<HashMap<String, String>>", optional)]
81    pub env: HashMap<String, String>,
82}
83
84fn default_input_type() -> String {
85    "string".to_string()
86}