Skip to content

Commit 1b8c7cf

Browse files
authored
Merge pull request #49 from UiPath/fix/consistent-CLI-design
fix: use ConsoleLogger
2 parents e98e2d6 + e2fd03a commit 1b8c7cf

File tree

4 files changed

+41
-53
lines changed

4 files changed

+41
-53
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
22
name = "uipath-langchain"
3-
version = "0.0.95"
3+
version = "0.0.96"
44
description = "UiPath Langchain"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
77
dependencies = [
8-
"uipath>=2.0.23, <2.1.0",
8+
"uipath>=2.0.28, <2.1.0",
99
"langgraph>=0.2.70",
1010
"langchain-core>=0.3.34",
1111
"langgraph-checkpoint-sqlite>=2.0.3",

src/uipath_langchain/_cli/cli_init.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import uuid
55
from typing import Any, Dict
66

7-
import click
87
from langgraph.graph.state import CompiledStateGraph
8+
from uipath._cli._utils._console import ConsoleLogger
99
from uipath._cli._utils._parse_ast import generate_bindings_json # type: ignore
1010
from uipath._cli.middlewares import MiddlewareResult
11-
from uipath._cli.spinner import Spinner
1211

1312
from ._utils._graph import LangGraphConfig
1413

14+
console = ConsoleLogger()
15+
1516

1617
def resolve_refs(schema, root=None):
1718
"""Recursively resolves $ref references in a JSON schema."""
@@ -95,15 +96,13 @@ def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
9596

9697
async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
9798
"""Middleware to check for langgraph.json and create uipath.json with schemas"""
98-
spinner = Spinner("Initializing UiPath project...")
9999
config = LangGraphConfig()
100100
if not config.exists:
101101
return MiddlewareResult(
102102
should_continue=True
103103
) # Continue with normal flow if no langgraph.json
104104

105105
try:
106-
spinner.start()
107106
config.load_config()
108107
entrypoints = []
109108
all_bindings = {"version": "2.0", "resources": []}
@@ -134,8 +133,8 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
134133
if "resources" in file_bindings:
135134
all_bindings["resources"] = file_bindings["resources"]
136135
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)}"
139138
)
140139

141140
new_entrypoint: dict[str, Any] = {
@@ -148,21 +147,18 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
148147
entrypoints.append(new_entrypoint)
149148

150149
except Exception as e:
151-
spinner.stop()
152-
print(f"Error during graph load: {e}")
150+
console.error(f"Error during graph load: {e}")
153151
return MiddlewareResult(
154152
should_continue=False,
155-
error_message=f"❌ Failed to load graph '{graph.name}': {str(e)}",
156153
should_include_stacktrace=True,
157154
)
158155
finally:
159156
await graph.cleanup()
160157

161158
if entrypoint and not entrypoints:
162-
spinner.stop()
159+
console.error(f"Error: No graph found with name '{entrypoint}'")
163160
return MiddlewareResult(
164161
should_continue=False,
165-
error_message=f"❌ Error: No graph found with name '{entrypoint}'",
166162
)
167163

168164
uipath_config = {"entryPoints": entrypoints, "bindings": all_bindings}
@@ -177,25 +173,22 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
177173
try:
178174
with open(mermaid_file_path, "w") as f:
179175
f.write(mermaid_content)
176+
console.success(f" Created '{mermaid_file_path}' file.")
180177
except Exception as write_error:
181-
spinner.stop()
178+
console.error(
179+
f"Error writing mermaid file for '{graph_name}': {str(write_error)}"
180+
)
182181
return MiddlewareResult(
183182
should_continue=False,
184-
error_message=f"❌ Error writing mermaid file for '{graph_name}': {str(write_error)}",
185183
should_include_stacktrace=True,
186184
)
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)
193187

194188
except Exception as e:
195-
spinner.stop()
189+
console.error(f"Error processing langgraph configuration: {str(e)}")
196190
return MiddlewareResult(
197191
should_continue=False,
198-
error_message=f"❌ Error processing langgraph configuration: {str(e)}",
199192
should_include_stacktrace=True,
200193
)
201194

src/uipath_langchain/_cli/cli_new.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import shutil
33

44
import click
5+
from uipath._cli._utils._console import ConsoleLogger
56
from uipath._cli.middlewares import MiddlewareResult
6-
from uipath._cli.spinner import Spinner
7+
8+
console = ConsoleLogger()
79

810

911
def generate_script(target_directory):
@@ -41,36 +43,29 @@ def generate_pyproject(target_directory, project_name):
4143

4244
def langgraph_new_middleware(name: str) -> MiddlewareResult:
4345
"""Middleware to create demo langchain agent"""
44-
spinner = Spinner("Creating demo agent...")
46+
4547
directory = os.getcwd()
4648

4749
try:
48-
generate_script(directory)
49-
click.echo(click.style("✓ ", fg="green", bold=True) + "Created main.py file")
50-
click.echo(
51-
click.style("✓ ", fg="green", bold=True) + "Created langgraph.json file"
52-
)
53-
generate_pyproject(directory, name)
54-
click.echo(
55-
click.style("✓ ", fg="green", bold=True) + "Created pyproject.toml file"
56-
)
57-
os.system("uv sync")
58-
spinner.start()
59-
ctx = click.get_current_context()
60-
init_cmd = ctx.parent.command.get_command(ctx, "init") # type: ignore
61-
ctx.invoke(init_cmd)
62-
spinner.stop()
63-
click.echo(
64-
click.style("✓ ", fg="green", bold=True) + " Agent created successfully."
65-
)
66-
return MiddlewareResult(
67-
should_continue=False,
68-
info_message="""Usage example: ` uipath run agent '{"topic": "UiPath"}' `""",
69-
)
50+
with console.spinner(f"Creating new agent {name} in current directory ..."):
51+
generate_pyproject(directory, name)
52+
generate_script(directory)
53+
console.success("Created 'main.py' file.")
54+
console.success("Created 'langgraph.json' file.")
55+
generate_pyproject(directory, name)
56+
console.success("Created 'pyproject.toml' file.")
57+
os.system("uv sync")
58+
ctx = click.get_current_context()
59+
init_cmd = ctx.parent.command.get_command(ctx, "init") # type: ignore
60+
ctx.invoke(init_cmd)
61+
console.config(
62+
" Please ensure to define either ANTHROPIC_API_KEY or OPENAI_API_KEY in your .env file."
63+
)
64+
console.hint(""" Run agent: uipath run agent '{"topic": "UiPath"}'""")
65+
return MiddlewareResult(should_continue=False)
7066
except Exception as e:
71-
spinner.stop()
67+
console.error(f"Error creating demo agent {str(e)}")
7268
return MiddlewareResult(
7369
should_continue=False,
74-
error_message=f"❌ Error creating demo agent {str(e)}",
7570
should_include_stacktrace=True,
7671
)

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)