Skip to main content

mesh_llm_plugin/manifest/control_behavior/
builders.rs

1use crate::proto;
2
3use super::super::PluginConfigSettingBuilder;
4
5impl PluginConfigSettingBuilder {
6    pub fn control_behavior(
7        mut self,
8        control_behavior: proto::PluginConfigControlBehavior,
9    ) -> Self {
10        self.inner.control_behavior = Some(control_behavior);
11        self
12    }
13
14    pub fn control_numeric(mut self, numeric: proto::PluginConfigNumericControl) -> Self {
15        self.control_behavior_mut().numeric = Some(numeric);
16        self
17    }
18
19    pub fn control_numeric_min(mut self, min: f64) -> Self {
20        self.control_numeric_mut().min = Some(min);
21        self
22    }
23
24    pub fn control_numeric_max(mut self, max: f64) -> Self {
25        self.control_numeric_mut().max = Some(max);
26        self
27    }
28
29    pub fn control_numeric_step(mut self, step: f64) -> Self {
30        self.control_numeric_mut().step = Some(step);
31        self
32    }
33
34    pub fn control_numeric_soft_min(mut self, soft_min: f64) -> Self {
35        self.control_numeric_mut().soft_min = Some(soft_min);
36        self
37    }
38
39    pub fn control_numeric_soft_max(mut self, soft_max: f64) -> Self {
40        self.control_numeric_mut().soft_max = Some(soft_max);
41        self
42    }
43
44    pub fn control_numeric_unit(mut self, unit: impl Into<String>) -> Self {
45        self.control_numeric_mut().unit = Some(unit.into());
46        self
47    }
48
49    pub fn control_text_format(mut self, text_format: proto::PluginConfigTextFormat) -> Self {
50        self.control_behavior_mut().text_format = Some(text_format as i32);
51        self
52    }
53
54    pub fn control_options_source(
55        mut self,
56        options_source: proto::PluginConfigOptionsSource,
57    ) -> Self {
58        self.control_behavior_mut().options_source = Some(options_source as i32);
59        self
60    }
61
62    pub fn control_options_static(self) -> Self {
63        self.control_options_source(proto::PluginConfigOptionsSource::Static)
64    }
65
66    pub fn control_options_runtime_gpus(self) -> Self {
67        self.control_options_source(proto::PluginConfigOptionsSource::RuntimeGpus)
68    }
69
70    pub fn control_options_runtime_native_backends(self) -> Self {
71        self.control_options_source(proto::PluginConfigOptionsSource::RuntimeNativeBackends)
72    }
73
74    pub fn control_options_runtime_local_models(self) -> Self {
75        self.control_options_source(proto::PluginConfigOptionsSource::RuntimeLocalModels)
76    }
77
78    pub fn control_options_runtime_installed_plugins(self) -> Self {
79        self.control_options_source(proto::PluginConfigOptionsSource::RuntimeInstalledPlugins)
80    }
81
82    pub fn control_options_runtime_mesh_peers(self) -> Self {
83        self.control_options_source(proto::PluginConfigOptionsSource::RuntimeMeshPeers)
84    }
85
86    pub fn control_availability(
87        mut self,
88        enabled: bool,
89        source: proto::PluginConfigControlAvailabilitySource,
90    ) -> Self {
91        let availability = self.control_availability_mut();
92        availability.enabled = enabled;
93        availability.source = source as i32;
94        self
95    }
96
97    pub fn control_availability_reason(mut self, reason: impl Into<String>) -> Self {
98        self.control_availability_mut().reason = Some(reason.into());
99        self
100    }
101
102    pub fn control_availability_note(mut self, note: impl Into<String>) -> Self {
103        self.control_availability_mut().note = Some(note.into());
104        self
105    }
106
107    pub fn control_enable_when(mut self, condition: proto::PluginConfigControlCondition) -> Self {
108        self.control_behavior_mut().enable_when.push(condition);
109        self
110    }
111
112    pub fn control_disable_when(mut self, disable: proto::PluginConfigConditionalDisable) -> Self {
113        self.control_behavior_mut().disable_when.push(disable);
114        self
115    }
116
117    pub fn control_conflict(mut self, conflict: proto::PluginConfigConflictRule) -> Self {
118        self.control_behavior_mut().conflicts.push(conflict);
119        self
120    }
121
122    pub fn control_write_policy(mut self, policy: proto::PluginConfigDisabledWritePolicy) -> Self {
123        self.control_behavior_mut().write_policy = Some(policy as i32);
124        self
125    }
126
127    fn control_behavior_mut(&mut self) -> &mut proto::PluginConfigControlBehavior {
128        self.inner
129            .control_behavior
130            .get_or_insert_with(proto::PluginConfigControlBehavior::default)
131    }
132
133    fn control_numeric_mut(&mut self) -> &mut proto::PluginConfigNumericControl {
134        self.control_behavior_mut()
135            .numeric
136            .get_or_insert_with(proto::PluginConfigNumericControl::default)
137    }
138
139    fn control_availability_mut(&mut self) -> &mut proto::PluginConfigControlAvailability {
140        self.control_behavior_mut().availability.get_or_insert(
141            proto::PluginConfigControlAvailability {
142                enabled: true,
143                reason: None,
144                note: None,
145                source: proto::PluginConfigControlAvailabilitySource::Static as i32,
146            },
147        )
148    }
149}