askit_std_agents/
display.rs1use std::vec;
2
3use agent_stream_kit::{
4 ASKit, AgentContext, AgentData, AgentError, AgentOutput, AgentSpec, AgentValue, AsAgent,
5 askit_agent, async_trait,
6};
7
8static CATEGORY: &str = "Std/Display";
9static DISPLAY_VALUE: &str = "value";
10
11#[askit_agent(
13 title = "Display Value",
14 category = CATEGORY,
15 inputs = ["*"],
16 custom_config(
17 name = DISPLAY_VALUE,
18 readonly,
19 type_="*",
20 default=AgentValue::unit(),
21 hide_title,
22 )
23)]
24struct DisplayValueAgent {
25 data: AgentData,
26}
27
28#[async_trait]
29impl AsAgent for DisplayValueAgent {
30 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
31 Ok(Self {
32 data: AgentData::new(askit, id, spec),
33 })
34 }
35
36 async fn start(&mut self) -> Result<(), AgentError> {
37 Ok(())
38 }
39
40 async fn process(
41 &mut self,
42 _ctx: AgentContext,
43 _pin: String,
44 value: AgentValue,
45 ) -> Result<(), AgentError> {
46 self.emit_config_updated(DISPLAY_VALUE, value);
47 Ok(())
48 }
49}
50
51#[askit_agent(
53 title = "Debug Value",
54 category = CATEGORY,
55 inputs = ["*"],
56 object_config(
57 name = DISPLAY_VALUE,
58 readonly,
59 hide_title,
60 )
61)]
62struct DebugValueAgent {
63 data: AgentData,
64}
65
66#[async_trait]
67impl AsAgent for DebugValueAgent {
68 fn new(askit: ASKit, id: String, spec: AgentSpec) -> Result<Self, AgentError> {
69 Ok(Self {
70 data: AgentData::new(askit, id, spec),
71 })
72 }
73
74 async fn process(
75 &mut self,
76 ctx: AgentContext,
77 _pin: String,
78 value: AgentValue,
79 ) -> Result<(), AgentError> {
80 let ctx_json =
81 serde_json::to_value(&ctx).map_err(|e| AgentError::InvalidValue(e.to_string()))?;
82 let ctx = AgentValue::from_json(ctx_json)?;
83 let debug_value =
84 AgentValue::object([("ctx".to_string(), ctx), ("value".to_string(), value)].into());
85 self.emit_config_updated(DISPLAY_VALUE, debug_value);
86 Ok(())
87 }
88}