22import json
33import os
44import uuid
5- from typing import Any , Dict
5+ from typing import Any , Callable , Dict , overload
66
77from langgraph .graph .state import CompiledStateGraph
88from uipath ._cli ._utils ._console import ConsoleLogger
@@ -94,8 +94,14 @@ def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
9494 return schema
9595
9696
97- async def langgraph_init_middleware_async (entrypoint : str ) -> MiddlewareResult :
97+ async def langgraph_init_middleware_async (
98+ entrypoint : str ,
99+ options : dict [str , Any ] | None = None ,
100+ write_config : Callable [[Any ], str ] | None = None ,
101+ ) -> MiddlewareResult :
98102 """Middleware to check for langgraph.json and create uipath.json with schemas"""
103+ options = options or {}
104+
99105 config = LangGraphConfig ()
100106 if not config .exists :
101107 return MiddlewareResult (
@@ -125,8 +131,9 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
125131 mermaids [graph .name ] = compiled_graph .get_graph (xray = 1 ).draw_mermaid ()
126132
127133 try :
134+ should_infer_bindings = options .get ("infer_bindings" , True )
128135 # Make sure the file path exists
129- if os .path .exists (graph .file_path ):
136+ if os .path .exists (graph .file_path ) and should_infer_bindings :
130137 file_bindings = generate_bindings_json (graph .file_path )
131138
132139 # Merge bindings
@@ -163,10 +170,13 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
163170
164171 uipath_config = {"entryPoints" : entrypoints , "bindings" : all_bindings }
165172
166- # Save the uipath.json file
167- config_path = "uipath.json"
168- with open (config_path , "w" ) as f :
169- json .dump (uipath_config , f , indent = 2 )
173+ if write_config :
174+ config_path = write_config (uipath_config )
175+ else :
176+ # Save the uipath.json file
177+ config_path = "uipath.json"
178+ with open (config_path , "w" ) as f :
179+ json .dump (uipath_config , f , indent = 4 )
170180
171181 for graph_name , mermaid_content in mermaids .items ():
172182 mermaid_file_path = f"{ graph_name } .mermaid"
@@ -193,6 +203,26 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
193203 )
194204
195205
196- def langgraph_init_middleware (entrypoint : str ) -> MiddlewareResult :
206+ @overload
207+ def langgraph_init_middleware (
208+ entrypoint : str ,
209+ ) -> MiddlewareResult : ...
210+
211+
212+ @overload
213+ def langgraph_init_middleware (
214+ entrypoint : str ,
215+ options : dict [str , Any ],
216+ write_config : Callable [[Any ], str ],
217+ ) -> MiddlewareResult : ...
218+
219+
220+ def langgraph_init_middleware (
221+ entrypoint : str ,
222+ options : dict [str , Any ] | None = None ,
223+ write_config : Callable [[Any ], str ] | None = None ,
224+ ) -> MiddlewareResult :
197225 """Middleware to check for langgraph.json and create uipath.json with schemas"""
198- return asyncio .run (langgraph_init_middleware_async (entrypoint ))
226+ return asyncio .run (
227+ langgraph_init_middleware_async (entrypoint , options , write_config )
228+ )
0 commit comments