Skip to main content

systemprompt_models/artifacts/dashboard/
hints.rs

1//! Rendering hints for dashboard artifacts.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8use serde_json::{Value as JsonValue, json};
9
10#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
11pub struct DashboardHints {
12    pub layout: LayoutMode,
13    pub refreshable: bool,
14    pub refresh_interval_seconds: Option<u32>,
15    pub drill_down_enabled: bool,
16}
17
18#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
19#[serde(rename_all = "lowercase")]
20pub enum LayoutMode {
21    #[default]
22    Vertical,
23    Grid,
24    Tabs,
25}
26
27impl DashboardHints {
28    pub fn new() -> Self {
29        Self::default()
30    }
31
32    pub const fn with_refreshable(mut self, refreshable: bool) -> Self {
33        self.refreshable = refreshable;
34        self
35    }
36
37    pub const fn with_refresh_interval(mut self, seconds: u32) -> Self {
38        self.refresh_interval_seconds = Some(seconds);
39        self
40    }
41
42    pub const fn with_drill_down(mut self, enabled: bool) -> Self {
43        self.drill_down_enabled = enabled;
44        self
45    }
46
47    pub const fn with_layout(mut self, layout: LayoutMode) -> Self {
48        self.layout = layout;
49        self
50    }
51
52    pub fn generate_schema(&self) -> JsonValue {
53        let mut schema = json!({
54            "layout": self.layout,
55            "refreshable": self.refreshable,
56            "drill_down_enabled": self.drill_down_enabled
57        });
58
59        if let Some(interval) = self.refresh_interval_seconds {
60            schema["refresh_interval_seconds"] = json!(interval);
61        }
62
63        schema
64    }
65}