1use std::vec;
2
3use agent_stream_kit::{
4 ASKit, Agent, AgentContext, AgentData, AgentError, AgentOutput, AgentSpec, AgentStatus,
5 AgentValue, AsAgent, askit_agent, async_trait,
6};
7
8const CATEGORY: &str = "Std/Input";
9
10const UNIT: &str = "unit";
11const BOOLEAN: &str = "boolean";
12const INTEGER: &str = "integer";
13const NUMBER: &str = "number";
14const STRING: &str = "string";
15const TEXT: &str = "text";
16const OBJECT: &str = "object";
17
18#[askit_agent(
20 kind = "Input",
21 title = "Unit Input",
22 hide_title,
23 category = CATEGORY,
24 outputs = [UNIT],
25 unit_config(name = UNIT, hide_title)
26)]
27struct UnitInputAgent {
28 data: AgentData,
29}
30
31impl AsAgent for UnitInputAgent {
32 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
33 Ok(Self {
34 data: AgentData::new(askit, id, spec),
35 })
36 }
37
38 fn configs_changed(&mut self) -> Result<(), AgentError> {
39 if *self.status() == AgentStatus::Start {
42 self.try_output(AgentContext::new(), UNIT, AgentValue::unit())?;
43 }
44
45 Ok(())
46 }
47}
48
49#[askit_agent(
51 kind = "Input",
52 title = "Boolean Input",
53 category = CATEGORY,
54 inputs = [UNIT],
55 outputs = [BOOLEAN],
56 boolean_config(name = BOOLEAN, hide_title),
57)]
58struct BooleanInputAgent {
59 data: AgentData,
60}
61
62#[async_trait]
63impl AsAgent for BooleanInputAgent {
64 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
65 Ok(Self {
66 data: AgentData::new(askit, id, spec),
67 })
68 }
69
70 fn configs_changed(&mut self) -> Result<(), AgentError> {
71 if *self.status() == AgentStatus::Start {
72 let value = self.configs()?.get(BOOLEAN)?;
73 self.try_output(AgentContext::new(), BOOLEAN, value.clone())?;
74 }
75 Ok(())
76 }
77
78 async fn process(
79 &mut self,
80 ctx: AgentContext,
81 _pin: String,
82 _value: AgentValue,
83 ) -> Result<(), AgentError> {
84 let value = self.configs()?.get(BOOLEAN)?;
85 self.output(ctx, BOOLEAN, value.clone()).await
86 }
87}
88
89#[askit_agent(
91 kind = "Input",
92 title = "Integer Input",
93 category = CATEGORY,
94 inputs = [UNIT],
95 outputs = [INTEGER],
96 integer_config(name = INTEGER, hide_title)
97)]
98struct IntegerInputAgent {
99 data: AgentData,
100}
101
102#[async_trait]
103impl AsAgent for IntegerInputAgent {
104 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
105 Ok(Self {
106 data: AgentData::new(askit, id, spec),
107 })
108 }
109
110 fn configs_changed(&mut self) -> Result<(), AgentError> {
111 if *self.status() == AgentStatus::Start {
112 let value = self.configs()?.get(INTEGER)?;
113 self.try_output(AgentContext::new(), INTEGER, value.clone())?;
114 }
115 Ok(())
116 }
117
118 async fn process(
119 &mut self,
120 ctx: AgentContext,
121 _pin: String,
122 _value: AgentValue,
123 ) -> Result<(), AgentError> {
124 let value = self.configs()?.get(INTEGER)?;
125 self.output(ctx, INTEGER, value.clone()).await
126 }
127}
128
129#[askit_agent(
131 kind = "Input",
132 title = "Number Input",
133 category = CATEGORY,
134 inputs = [UNIT],
135 outputs = [NUMBER],
136 number_config(name = NUMBER, hide_title)
137)]
138struct NumberInputAgent {
139 data: AgentData,
140}
141
142#[async_trait]
143impl AsAgent for NumberInputAgent {
144 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
145 Ok(Self {
146 data: AgentData::new(askit, id, spec),
147 })
148 }
149
150 fn configs_changed(&mut self) -> Result<(), AgentError> {
151 if *self.status() == AgentStatus::Start {
152 let value = self.configs()?.get_number(NUMBER)?; self.try_output(AgentContext::new(), NUMBER, AgentValue::number(value))?;
154 }
155 Ok(())
156 }
157
158 async fn process(
159 &mut self,
160 ctx: AgentContext,
161 _pin: String,
162 _value: AgentValue,
163 ) -> Result<(), AgentError> {
164 let value = self.configs()?.get_number(NUMBER)?;
165 self.output(ctx, NUMBER, AgentValue::number(value)).await
166 }
167}
168
169#[askit_agent(
171 kind = "Input",
172 title = "String Input",
173 category = CATEGORY,
174 inputs = [UNIT],
175 outputs = [STRING],
176 string_config(name = STRING, hide_title)
177)]
178struct StringInputAgent {
179 data: AgentData,
180}
181
182#[async_trait]
183impl AsAgent for StringInputAgent {
184 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
185 Ok(Self {
186 data: AgentData::new(askit, id, spec),
187 })
188 }
189
190 fn configs_changed(&mut self) -> Result<(), AgentError> {
191 if *self.status() == AgentStatus::Start {
192 let value = self.configs()?.get(STRING)?;
193 self.try_output(AgentContext::new(), STRING, value.clone())?;
194 }
195 Ok(())
196 }
197
198 async fn process(
199 &mut self,
200 ctx: AgentContext,
201 _pin: String,
202 _value: AgentValue,
203 ) -> Result<(), AgentError> {
204 let value = self.configs()?.get(STRING)?;
205 self.output(ctx, STRING, value.clone()).await
206 }
207}
208
209#[askit_agent(
211 kind = "Input",
212 title = "Text Input",
213 category = CATEGORY,
214 inputs = [UNIT],
215 outputs = [TEXT],
216 text_config(name = TEXT, hide_title)
217)]
218struct TextInputAgent {
219 data: AgentData,
220}
221
222#[async_trait]
223impl AsAgent for TextInputAgent {
224 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
225 Ok(Self {
226 data: AgentData::new(askit, id, spec),
227 })
228 }
229
230 fn configs_changed(&mut self) -> Result<(), AgentError> {
231 if *self.status() == AgentStatus::Start {
232 let value = self.configs()?.get(TEXT)?;
233 self.try_output(AgentContext::new(), TEXT, value.clone())?;
234 }
235 Ok(())
236 }
237
238 async fn process(
239 &mut self,
240 ctx: AgentContext,
241 _pin: String,
242 _value: AgentValue,
243 ) -> Result<(), AgentError> {
244 let value = self.configs()?.get(TEXT)?;
245 self.output(ctx, TEXT, value.clone()).await
246 }
247}
248
249#[askit_agent(
251 kind = "Input",
252 title = "Object Input",
253 category = CATEGORY,
254 inputs = [UNIT],
255 outputs = [OBJECT],
256 object_config(name = OBJECT, hide_title)
257)]
258struct ObjectInputAgent {
259 data: AgentData,
260}
261
262#[async_trait]
263impl AsAgent for ObjectInputAgent {
264 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
265 Ok(Self {
266 data: AgentData::new(askit, id, spec),
267 })
268 }
269
270 fn configs_changed(&mut self) -> Result<(), AgentError> {
271 if *self.status() == AgentStatus::Start {
272 let value = self.configs()?.get(OBJECT)?;
273 self.try_output(AgentContext::new(), OBJECT, value.clone())?;
274 }
275 Ok(())
276 }
277
278 async fn process(
279 &mut self,
280 ctx: AgentContext,
281 _pin: String,
282 _value: AgentValue,
283 ) -> Result<(), AgentError> {
284 let value = self.configs()?.get(OBJECT)?;
285 self.output(ctx, OBJECT, value.clone()).await
286 }
287}