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