Skip to content

Commit 4fc08c3

Browse files
Merge pull request #110 from UiPath/feat/cli-init-infer-bindings
feat(cli): enhance init with options
2 parents 3840e8f + f0faba0 commit 4fc08c3

File tree

3 files changed

+1579
-1532
lines changed

3 files changed

+1579
-1532
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "UiPath Langchain"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
77
dependencies = [
8-
"uipath>=2.0.65, <2.1.0",
8+
"uipath>=2.0.71, <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: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import os
44
import uuid
5-
from typing import Any, Dict
5+
from typing import Any, Callable, Dict, overload
66

77
from langgraph.graph.state import CompiledStateGraph
88
from 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

Comments
 (0)