1+ use crate :: prelude:: * ;
2+
13use crate :: base:: spec:: VectorSimilarityMetric ;
24use crate :: execution:: query;
35use crate :: get_lib_context;
@@ -7,13 +9,10 @@ use crate::ops::py_factory::PyOpArgSchema;
79use crate :: ops:: { interface:: ExecutorFactory , py_factory:: PyFunctionFactory , register_factory} ;
810use crate :: server:: { self , ServerSettings } ;
911use crate :: settings:: Settings ;
12+ use crate :: setup;
1013use crate :: LIB_CONTEXT ;
11- use crate :: { api_error, setup} ;
12- use crate :: { builder, execution} ;
13- use anyhow:: anyhow;
1414use pyo3:: { exceptions:: PyException , prelude:: * } ;
1515use std:: collections:: btree_map;
16- use std:: sync:: Arc ;
1716
1817mod convert;
1918pub use convert:: * ;
@@ -91,20 +90,20 @@ impl IndexUpdateInfo {
9190}
9291
9392#[ pyclass]
94- pub struct Flow ( pub Arc < builder :: AnalyzedFlow > ) ;
93+ pub struct Flow ( pub Arc < FlowContext > ) ;
9594
9695#[ pymethods]
9796impl Flow {
9897 pub fn __str__ ( & self ) -> String {
99- serde_json:: to_string_pretty ( & self . 0 . flow_instance ) . unwrap ( )
98+ serde_json:: to_string_pretty ( & self . 0 . flow . flow_instance ) . unwrap ( )
10099 }
101100
102101 pub fn __repr__ ( & self ) -> String {
103102 self . __str__ ( )
104103 }
105104
106105 pub fn name ( & self ) -> & str {
107- & self . 0 . flow_instance . name
106+ & self . 0 . flow . flow_instance . name
108107 }
109108
110109 pub fn update ( & self , py : Python < ' _ > ) -> PyResult < IndexUpdateInfo > {
@@ -132,10 +131,10 @@ impl Flow {
132131 lib_context
133132 . runtime
134133 . block_on ( async {
135- let exec_plan = self . 0 . get_execution_plan ( ) . await ?;
134+ let exec_plan = self . 0 . flow . get_execution_plan ( ) . await ?;
136135 execution:: dumper:: evaluate_and_dump (
137136 & exec_plan,
138- & self . 0 . data_schema ,
137+ & self . 0 . flow . data_schema ,
139138 options. into_inner ( ) ,
140139 & lib_context. pool ,
141140 )
@@ -181,7 +180,7 @@ impl SimpleSemanticsQueryHandler {
181180 let handler = lib_context
182181 . runtime
183182 . block_on ( query:: SimpleSemanticsQueryHandler :: new (
184- flow. 0 . clone ( ) ,
183+ flow. 0 . flow . clone ( ) ,
185184 target_name,
186185 query_transform_flow. 0 . clone ( ) ,
187186 default_similarity_metric. 0 ,
@@ -194,11 +193,11 @@ impl SimpleSemanticsQueryHandler {
194193 pub fn register_query_handler ( & self , name : String ) -> PyResult < ( ) > {
195194 let lib_context = get_lib_context ( )
196195 . ok_or_else ( || PyException :: new_err ( "cocoindex library not initialized" ) ) ?;
197- let mut flows = lib_context. flows . write ( ) . unwrap ( ) ;
198- let flow_ctx = flows
199- . get_mut ( & self . 0 . flow_name )
200- . ok_or_else ( || PyException :: new_err ( format ! ( "flow not found: {}" , self . 0 . flow_name ) ) ) ? ;
201- match flow_ctx . query_handlers . entry ( name) {
196+ let flow_ctx = lib_context
197+ . get_flow_context ( & self . 0 . flow_name )
198+ . into_py_result ( ) ? ;
199+ let mut query_handlers = flow_ctx . query_handlers . lock ( ) . unwrap ( ) ;
200+ match query_handlers. entry ( name) {
202201 btree_map:: Entry :: Occupied ( entry) => {
203202 return Err ( PyException :: new_err ( format ! (
204203 "query handler name already exists: {}" ,
@@ -270,8 +269,8 @@ fn check_setup_status(
270269) -> PyResult < SetupStatusCheck > {
271270 let lib_context = get_lib_context ( )
272271 . ok_or_else ( || PyException :: new_err ( "cocoindex library not initialized" ) ) ?;
272+ let flows = lib_context. flows . lock ( ) . unwrap ( ) ;
273273 let all_css = lib_context. combined_setup_states . read ( ) . unwrap ( ) ;
274- let flows = lib_context. flows . read ( ) . unwrap ( ) ;
275274 let setup_status =
276275 setup:: check_setup_status ( & flows, & all_css, options. into_inner ( ) ) . into_py_result ( ) ?;
277276 Ok ( SetupStatusCheck ( setup_status) )
0 commit comments