use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WidgetSchema {
pub name: String,
pub description: String,
pub default_role: SemanticRole,
pub properties: Vec<PropertySchema>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub actions: Vec<super::AgentAction>,
pub usage_hint: Option<String>,
pub tags: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PropertySchema {
pub name: String,
pub description: String,
pub property_type: PropertyType,
pub required: bool,
pub default_value: Option<serde_json::Value>,
pub constraints: Vec<PropertyConstraint>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum PropertyType {
String,
Integer,
Float,
Boolean,
Color,
Style,
Rect,
Size,
Position,
Enum(Vec<String>),
Array(Box<PropertyType>),
Object(Vec<PropertySchema>),
Widget,
Any,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum PropertyConstraint {
Min(f64),
Max(f64),
MinLength(usize),
MaxLength(usize),
Pattern(String),
OneOf(Vec<serde_json::Value>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SemanticRole {
Display,
Input,
Navigation,
Container,
Progress,
Selection,
DataVisualization,
Decoration,
Action,
Scrollable,
Modal,
Menu,
Toolbar,
Tab,
TreeNode,
Canvas,
Media,
System,
Diagnostic,
Configuration,
Custom,
}
impl WidgetSchema {
pub fn new(
name: impl Into<String>,
description: impl Into<String>,
role: SemanticRole,
) -> Self {
Self {
name: name.into(),
description: description.into(),
default_role: role,
properties: vec![],
actions: vec![],
usage_hint: None,
tags: vec![],
}
}
}
impl PropertySchema {
pub fn new(
name: impl Into<String>,
description: impl Into<String>,
property_type: PropertyType,
required: bool,
) -> Self {
Self {
name: name.into(),
description: description.into(),
property_type,
required,
default_value: None,
constraints: vec![],
}
}
}
impl std::fmt::Display for SemanticRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Display => "display",
Self::Input => "input",
Self::Navigation => "navigation",
Self::Container => "container",
Self::Progress => "progress",
Self::Selection => "selection",
Self::DataVisualization => "data-visualization",
Self::Decoration => "decoration",
Self::Action => "action",
Self::Scrollable => "scrollable",
Self::Modal => "modal",
Self::Menu => "menu",
Self::Toolbar => "toolbar",
Self::Tab => "tab",
Self::TreeNode => "tree-node",
Self::Canvas => "canvas",
Self::Media => "media",
Self::System => "system",
Self::Diagnostic => "diagnostic",
Self::Configuration => "configuration",
Self::Custom => "custom",
};
f.write_str(s)
}
}