4
4
import uuid
5
5
from typing import Any , Dict
6
6
7
+ import click
7
8
from langgraph .graph .state import CompiledStateGraph
8
9
from uipath ._cli ._utils ._parse_ast import generate_bindings_json # type: ignore
9
10
from uipath ._cli .middlewares import MiddlewareResult
11
+ from uipath ._cli .spinner import Spinner
10
12
11
13
from ._utils ._graph import LangGraphConfig
12
14
@@ -93,13 +95,15 @@ def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
93
95
94
96
async def langgraph_init_middleware_async (entrypoint : str ) -> MiddlewareResult :
95
97
"""Middleware to check for langgraph.json and create uipath.json with schemas"""
98
+ spinner = Spinner ("Initializing UiPath project..." )
96
99
config = LangGraphConfig ()
97
100
if not config .exists :
98
101
return MiddlewareResult (
99
102
should_continue = True
100
103
) # Continue with normal flow if no langgraph.json
101
104
102
105
try :
106
+ spinner .start ()
103
107
config .load_config ()
104
108
entrypoints = []
105
109
all_bindings = {"version" : "2.0" , "resources" : []}
@@ -122,7 +126,6 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
122
126
mermaids [graph .name ] = compiled_graph .get_graph (xray = 1 ).draw_mermaid ()
123
127
124
128
try :
125
- print ("Generating bindings for " , graph .file_path )
126
129
# Make sure the file path exists
127
130
if os .path .exists (graph .file_path ):
128
131
file_bindings = generate_bindings_json (graph .file_path )
@@ -132,7 +135,7 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
132
135
all_bindings ["resources" ] = file_bindings ["resources" ]
133
136
except Exception as e :
134
137
print (
135
- f"Warning: Could not generate bindings for { graph .file_path } : { str (e )} "
138
+ f"⚠️ Warning: Could not generate bindings for { graph .file_path } : { str (e )} "
136
139
)
137
140
138
141
new_entrypoint : dict [str , Any ] = {
@@ -145,19 +148,21 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
145
148
entrypoints .append (new_entrypoint )
146
149
147
150
except Exception as e :
151
+ spinner .stop ()
148
152
print (f"Error during graph load: { e } " )
149
153
return MiddlewareResult (
150
154
should_continue = False ,
151
- error_message = f"Failed to load graph '{ graph .name } ': { str (e )} " ,
155
+ error_message = f"❌ Failed to load graph '{ graph .name } ': { str (e )} " ,
152
156
should_include_stacktrace = True ,
153
157
)
154
158
finally :
155
159
await graph .cleanup ()
156
160
157
161
if entrypoint and not entrypoints :
162
+ spinner .stop ()
158
163
return MiddlewareResult (
159
164
should_continue = False ,
160
- error_message = f"Error: No graph found with name '{ entrypoint } '" ,
165
+ error_message = f"❌ Error: No graph found with name '{ entrypoint } '" ,
161
166
)
162
167
163
168
uipath_config = {"entryPoints" : entrypoints , "bindings" : all_bindings }
@@ -173,21 +178,24 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
173
178
with open (mermaid_file_path , "w" ) as f :
174
179
f .write (mermaid_content )
175
180
except Exception as write_error :
181
+ spinner .stop ()
176
182
return MiddlewareResult (
177
183
should_continue = False ,
178
- error_message = f"Error writing mermaid file for '{ graph_name } ': { str (write_error )} " ,
184
+ error_message = f"❌ Error writing mermaid file for '{ graph_name } ': { str (write_error )} " ,
179
185
should_include_stacktrace = True ,
180
186
)
181
-
187
+ spinner . stop ()
182
188
return MiddlewareResult (
183
189
should_continue = False ,
184
- info_message = f"Configuration file { config_path } created successfully." ,
190
+ info_message = click .style ("✓ " , fg = "green" , bold = True )
191
+ + f" Configuration file { config_path } created successfully." ,
185
192
)
186
193
187
194
except Exception as e :
195
+ spinner .stop ()
188
196
return MiddlewareResult (
189
197
should_continue = False ,
190
- error_message = f"Error processing langgraph configuration: { str (e )} " ,
198
+ error_message = f"❌ Error processing langgraph configuration: { str (e )} " ,
191
199
should_include_stacktrace = True ,
192
200
)
193
201
0 commit comments