66
77mod private
88{
9- use std:: io;
9+ use std::
10+ {
11+ io,
12+ collections:: HashMap ,
13+ } ;
1014
1115 use former:: Former ;
1216 use serde::
1317 {
14- serialize ,
15- deserialize ,
18+ Serialize ,
19+ Deserialize ,
1620 } ;
1721
1822 /// Struct that represents user written scenarios.
@@ -45,173 +49,16 @@ mod private
4549 /// ID of the node. Must be unique, will also identify node output.
4650 pub id : String ,
4751
48- /// Type of the node.
52+ /// Type of the node. Represented as a path.
4953 pub r#type : String ,
5054
51- /// Specific type of `NodeRaw`.
52- pub kind : NodeRawKind ,
55+ /// Rest of the key-value pairs in the node that are specific to node types.
56+ #[ serde( flatten ) ]
57+ pub params : HashMap < String , String > ,
5358
54- /// ID of the next node to execute.
59+ /// ID of the next node to execute. Represented as a path.
5560 pub next : String ,
5661 }
57-
58- impl format_tools:: Fields < & ' _ str , & ' _ str > for NodeRaw
59- {
60- type Key < ' k > = & ' k str ;
61- type Val < ' v > = & ' v str ;
62-
63- fn fields ( & self ) -> impl format_tools:: IteratorTrait < Item = ( & ' _ str , & ' _ str ) >
64- {
65- let mut dst = Vec :: new ( ) ;
66-
67- dst. push ( ( "id" , self . id . as_str ( ) ) ) ;
68- dst. push ( ( "type" , self . r#type . as_str ( ) ) ) ;
69-
70- dst. extend ( self . kind . fields ( ) ) ;
71-
72- dst. push ( ( "next" , self . next . as_str ( ) ) ) ;
73-
74- dst. into_iter ( )
75- }
76- }
77-
78- /// Representation of different types of nodes. Contains parameters unique to types.
79- /// Used in `Node` struct, where you can find common parameters like `id`, `type`, and others.
80- #[ derive( Debug , Serialize , Deserialize , PartialEq ) ]
81- pub enum NodeRawKind
82- {
83- /// Read input from `stdin`.
84- TriggerStdin ( TriggerStdinRaw ) ,
85-
86- /// Get output from LLM.
87- AgentsCompletion ( AgentsCompletionRaw ) ,
88-
89- /// Print output to `stdout`.
90- EventStdout ( EventStdoutRaw ) ,
91- }
92-
93- impl format_tools:: Fields < & ' _ str , & ' _ str > for NodeRawKind
94- {
95- type Key < ' k > = & ' k str ;
96- type Val < ' v > = & ' v str ;
97-
98- fn fields ( & self ) -> impl format_tools:: IteratorTrait < Item = ( & ' _ str , & ' _ str ) >
99- {
100- match self
101- {
102- Self :: TriggerStdin ( v ) => v. fields ( ) ,
103- Self :: AgentsCompletion ( v ) => v. fields ( ) ,
104- Self :: EventStdout ( v ) => v. fields ( ) ,
105- }
106- }
107- }
108-
109- /// Read input from `stdin`.
110- #[ derive( Debug , Serialize , Deserialize , Former , PartialEq ) ]
111- pub struct TriggerStdinRaw
112- {
113- pub prompt : String ;
114- }
115-
116- impl From < TriggerStdinRaw > for NodeRawKind
117- {
118- fn from ( value : TriggerStdinRaw ) -> Self
119- {
120- Self :: TriggerStdin ( value )
121- }
122- }
123-
124- impl format_tools:: Fields < & ' _ str , & ' _ str > for TriggerStdinRaw
125- {
126- type Key < ' k > = & ' k str ;
127- type Val < ' v > = & ' v str ;
128-
129- fn fields ( & self ) -> impl format_tools:: IteratorTrait < Item = ( & ' _ str , & ' _ str ) >
130- {
131- std:: iter:: once ( ( "prompt" , prompt. as_str ( ) ) )
132- }
133- }
134-
135- /// Get output from LLM.
136- #[ derive( Debug , Serialize , Deserialize , Former , PartialEq ) ]
137- pub struct AgentsCompletionRaw
138- {
139- /// Agent's system message template.
140- pub system_message : String ,
141-
142- /// Agent's user message template.
143- pub user_message : String ,
144-
145- /// Reuse chat history of other agent.
146- pub agent_reuse : Option < String > ,
147- }
148-
149- impl From < AgentsCompletionRaw > for NodeRawKind
150- {
151- fn from ( value : AgentsCompletionRaw ) -> Self
152- {
153- Self :: AgentsCompletion ( value )
154- }
155- }
156-
157- impl format_tools:: Fields < & ' _ str , & ' _ str > for AgentsCompletionRaw
158- {
159- type Key < ' k > = & ' k str ;
160- type Val < ' v > = & ' v str ;
161-
162- fn fields ( & self ) -> impl format_tools:: IteratorTrait < Item = ( & ' _ str , & ' _ str ) >
163- {
164- let mut dst = Vec :: new ( ) ;
165-
166- dst. push ( ( "system_message" , system_message. as_str ( ) ) ) ;
167- dst. push ( ( "user_message" , user_message. as_str ( ) ) ) ;
168-
169- if let Some ( agent_reuse ) = agent_reuse
170- {
171- dst. push ( ( "agent_reuse" , agent_reuse. as_str ( ) ) ) ;
172- }
173-
174- dst. into_iter ( )
175- }
176- }
177-
178- /// Print output to `stdout`.
179- #[ derive( Debug , Serialize , Deserialize , Former , PartialEq ) ]
180- pub struct EventStdoutRaw
181- {
182- /// Prompt to display to `stdout`.
183- pub output : String ,
184- }
185-
186- impl From < EventsStdoutRaw > for NodeRawKind
187- {
188- fn from ( value : EventsStdoutRaw ) -> Self
189- {
190- Self :: EventsStdout ( value )
191- }
192- }
193-
194- impl format_tools:: Fields < & ' _ str , & ' _ str > for EventStdoutRaw
195- {
196- type Key < ' k > = & ' k str ;
197- type Val < ' v > = & ' v str ;
198-
199- fn fields ( & self ) -> impl format_tools:: IteratorTrait < Item = ( & ' _ str , & ' _ str ) >
200- {
201- let mut dst = Vec :: new ( ) ;
202-
203- dst. push ( ( "system_message" , system_message. as_str ( ) ) ) ;
204- dst. push ( ( "user_message" , user_message. as_str ( ) ) ) ;
205-
206- if let Some ( agent_reuse ) = agent_reuse
207- {
208- dst. push ( ( "agent_reuse" , agent_reuse. as_str ( ) ) ) ;
209- }
210-
211- dst. into_iter ( )
212- }
213- }
214-
21562}
21663
21764crate :: mod_interface!
@@ -220,6 +67,5 @@ crate::mod_interface!
22067 {
22168 ScenarioRaw ,
22269 NodeRaw ,
223- NodeRawKind ,
22470 } ;
22571}
0 commit comments