@@ -188,19 +188,7 @@ impl ConversationState {
188188 history : VecDeque :: new ( ) ,
189189 valid_history_range : Default :: default ( ) ,
190190 transcript : VecDeque :: with_capacity ( MAX_CONVERSATION_STATE_HISTORY_LEN ) ,
191- tools : tool_config
192- . into_values ( )
193- . fold ( HashMap :: < ToolOrigin , Vec < Tool > > :: new ( ) , |mut acc, v| {
194- let tool = Tool :: ToolSpecification ( ToolSpecification {
195- name : v. name ,
196- description : v. description ,
197- input_schema : v. input_schema . into ( ) ,
198- } ) ;
199- acc. entry ( v. tool_origin )
200- . and_modify ( |tools| tools. push ( tool. clone ( ) ) )
201- . or_insert ( vec ! [ tool] ) ;
202- acc
203- } ) ,
191+ tools : format_tool_spec ( tool_config) ,
204192 context_manager,
205193 tool_manager,
206194 context_message_length : None ,
@@ -854,6 +842,22 @@ Return only the JSON configuration, no additional text.",
854842 }
855843}
856844
845+ pub fn format_tool_spec ( tool_spec : HashMap < String , ToolSpec > ) -> HashMap < ToolOrigin , Vec < Tool > > {
846+ tool_spec
847+ . into_values ( )
848+ . fold ( HashMap :: < ToolOrigin , Vec < Tool > > :: new ( ) , |mut acc, v| {
849+ let tool = Tool :: ToolSpecification ( ToolSpecification {
850+ name : v. name ,
851+ description : v. description ,
852+ input_schema : v. input_schema . into ( ) ,
853+ } ) ;
854+ acc. entry ( v. tool_origin )
855+ . and_modify ( |tools| tools. push ( tool. clone ( ) ) )
856+ . or_insert ( vec ! [ tool] ) ;
857+ acc
858+ } )
859+ }
860+
857861/// Represents a conversation state that can be converted into a [FigConversationState] (the type
858862/// used by the API client). Represents borrowed data, and reflects an exact [FigConversationState]
859863/// that can be generated from [ConversationState] at any point in time.
0 commit comments