1- use crate :: agent_control:: run:: Environment ;
2- use crate :: agent_type:: agent_type_registry:: { AgentRegistry , AgentRepositoryError } ;
3- use crate :: agent_type:: embedded_registry:: EmbeddedRegistry ;
4- use crate :: agent_type:: variable:: constraints:: VariableConstraints ;
5- use crate :: config_migrate:: migration:: agent_value_spec:: AgentValueSpec :: AgentValueSpecEnd ;
6- use crate :: config_migrate:: migration:: agent_value_spec:: {
7- AgentValueError , AgentValueSpec , from_fqn_and_value, merge_agent_values,
8- } ;
9- use crate :: config_migrate:: migration:: config:: {
10- AgentTypeFieldFQN , DirInfo , FilePath , MigrationAgentConfig ,
11- } ;
12- use crate :: config_migrate:: migration:: config:: { FILE_SEPARATOR , FILE_SEPARATOR_REPLACE } ;
1+ use crate :: agent_type:: agent_type_registry:: AgentRepositoryError ;
2+ use crate :: config_migrate:: migration:: agent_value_spec:: AgentValueError ;
3+ use crate :: config_migrate:: migration:: config:: MigrationAgentConfig ;
134use crate :: config_migrate:: migration:: converter:: ConversionError :: * ;
145use crate :: config_migrate:: migration:: supported_config_value:: SupportedConfigValue ;
156use crate :: config_migrate:: migration:: supported_config_value:: SupportedConfigValueError ;
16- use crate :: sub_agent:: effective_agents_assembler:: { AgentTypeDefinitionError , build_agent_type } ;
7+ use crate :: sub_agent:: effective_agents_assembler:: AgentTypeDefinitionError ;
178use fs:: LocalFile ;
189use fs:: file_reader:: { FileReader , FileReaderError } ;
1910use std:: collections:: HashMap ;
@@ -40,22 +31,20 @@ pub enum ConversionError {
4031 SupportedConfigValueError ( #[ from] SupportedConfigValueError ) ,
4132}
4233
43- pub struct ConfigConverter < R : AgentRegistry , F : FileReader > {
44- agent_registry : R ,
34+ pub struct ConfigConverter < F : FileReader > {
4535 file_reader : F ,
4636}
4737
48- impl Default for ConfigConverter < EmbeddedRegistry , LocalFile > {
38+ impl Default for ConfigConverter < LocalFile > {
4939 fn default ( ) -> Self {
5040 ConfigConverter {
51- agent_registry : EmbeddedRegistry :: default ( ) ,
5241 file_reader : LocalFile ,
5342 }
5443 }
5544}
5645
5746#[ cfg_attr( test, mockall:: automock) ]
58- impl < R : AgentRegistry , F : FileReader > ConfigConverter < R , F > {
47+ impl < F : FileReader > ConfigConverter < F > {
5948 pub fn convert (
6049 & self ,
6150 migration_agent_config : & MigrationAgentConfig ,
@@ -111,40 +100,4 @@ impl<R: AgentRegistry, F: FileReader> ConfigConverter<R, F> {
111100 ]
112101 . into ( ) )
113102 }
114-
115- fn file_to_agent_value_spec (
116- & self ,
117- agent_type_field_fqn : AgentTypeFieldFQN ,
118- file_path : FilePath ,
119- ) -> Result < HashMap < String , AgentValueSpec > , ConversionError > {
120- let contents = self . file_reader . read ( file_path. as_path ( ) ) ?;
121- Ok ( from_fqn_and_value (
122- agent_type_field_fqn. clone ( ) ,
123- AgentValueSpecEnd ( contents) ,
124- ) )
125- }
126-
127- fn dir_to_agent_value_spec (
128- & self ,
129- agent_type_field_fqn : AgentTypeFieldFQN ,
130- dir_info : DirInfo ,
131- ) -> Result < HashMap < String , AgentValueSpec > , ConversionError > {
132- let files_paths = self . file_reader . dir_entries ( dir_info. path . as_path ( ) ) ?;
133- let mut res: Vec < HashMap < String , AgentValueSpec > > = Vec :: new ( ) ;
134- // refactor file_path to path
135- for path in files_paths {
136- let filename = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
137- //filter by filename
138- if !dir_info. valid_filename ( filename. as_str ( ) ) {
139- continue ;
140- }
141-
142- // replace the file separator to not be treated as a leaf
143- let escaped_filename = filename. replace ( FILE_SEPARATOR , FILE_SEPARATOR_REPLACE ) ;
144- let full_agent_type_field_fqn: AgentTypeFieldFQN =
145- format ! ( "{agent_type_field_fqn}.{escaped_filename}" ) . into ( ) ;
146- res. push ( self . file_to_agent_value_spec ( full_agent_type_field_fqn, path) ?) ;
147- }
148- Ok ( merge_agent_values ( res) ?)
149- }
150103}
0 commit comments