agent_stream_kit/
output.rs1use crate::error::AgentError;
2
3use super::agent::Agent;
4use super::context::AgentContext;
5use super::value::AgentValue;
6
7pub trait AgentOutput {
8 fn try_output_raw(
9 &mut self,
10 ctx: AgentContext,
11 pin: String,
12 value: AgentValue,
13 ) -> Result<(), AgentError>;
14
15 fn try_output<S: Into<String>>(
16 &mut self,
17 ctx: AgentContext,
18 pin: S,
19 value: AgentValue,
20 ) -> Result<(), AgentError> {
21 self.try_output_raw(ctx, pin.into(), value)
22 }
23
24 fn emit_display_raw(&self, key: String, value: AgentValue);
25
26 fn emit_display<S: Into<String>>(&self, key: S, value: AgentValue) {
27 self.emit_display_raw(key.into(), value);
28 }
29
30 fn emit_error_raw(&self, message: String);
31
32 #[allow(unused)]
33 fn emit_error<S: Into<String>>(&self, message: S) {
34 self.emit_error_raw(message.into());
35 }
36}
37
38impl<T: Agent> AgentOutput for T {
39 fn try_output_raw(
40 &mut self,
41 ctx: AgentContext,
42 pin: String,
43 value: AgentValue,
44 ) -> Result<(), AgentError> {
45 self.set_out_pin(pin.clone(), value.clone());
46 self.askit()
47 .try_send_agent_out(self.id().into(), ctx, pin, value)
48 }
49
50 fn emit_display_raw(&self, key: String, value: AgentValue) {
51 self.askit()
52 .emit_agent_display(self.id().to_string(), key, value);
53 }
54
55 fn emit_error_raw(&self, message: String) {
56 self.askit()
57 .emit_agent_error(self.id().to_string(), message);
58 }
59}