gsm_core/
provider_capabilities.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5#[serde(rename_all = "snake_case")]
6pub struct ProviderCapabilitiesV1 {
7 pub version: String,
8 pub supports_adaptive_cards: bool,
9 pub supports_markdown: bool,
10 pub supports_html: bool,
11 pub supports_images: bool,
12 pub supports_buttons: bool,
13 pub supports_threads: bool,
14 pub max_text_len: Option<u32>,
15 pub max_payload_bytes: Option<u32>,
16 pub max_actions: Option<u32>,
17 pub max_buttons_per_row: Option<u32>,
18 pub max_total_buttons: Option<u32>,
19 #[serde(default)]
20 pub limits: ProviderLimitsV1,
21}
22
23impl Default for ProviderCapabilitiesV1 {
24 fn default() -> Self {
25 Self {
26 version: "v1".to_string(),
27 supports_adaptive_cards: false,
28 supports_markdown: false,
29 supports_html: false,
30 supports_images: false,
31 supports_buttons: false,
32 supports_threads: false,
33 max_text_len: None,
34 max_payload_bytes: None,
35 max_actions: None,
36 max_buttons_per_row: None,
37 max_total_buttons: None,
38 limits: ProviderLimitsV1::default(),
39 }
40 }
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
44#[serde(rename_all = "snake_case")]
45pub struct ProviderLimitsV1 {
46 pub max_text_len: Option<u32>,
47 pub max_payload_bytes: Option<u32>,
48 pub max_actions: Option<u32>,
49 pub max_buttons_per_row: Option<u32>,
50 pub max_total_buttons: Option<u32>,
51}
52
53#[derive(Debug, thiserror::Error, PartialEq, Eq)]
54pub enum CapabilitiesError {
55 #[error("version must be \"v1\"")]
56 BadVersion,
57 #[error("max_buttons_per_row cannot exceed max_total_buttons")]
58 ButtonsRowExceedsTotal,
59}
60
61impl ProviderCapabilitiesV1 {
62 pub fn validate(&self) -> Result<(), CapabilitiesError> {
63 if self.version != "v1" {
64 return Err(CapabilitiesError::BadVersion);
65 }
66
67 let row = self.limits.max_buttons_per_row.or(self.max_buttons_per_row);
68 let total = self.limits.max_total_buttons.or(self.max_total_buttons);
69 if let (Some(r), Some(t)) = (row, total)
70 && r > t
71 {
72 return Err(CapabilitiesError::ButtonsRowExceedsTotal);
73 }
74
75 Ok(())
76 }
77}