Skip to content

Commit ead77c6

Browse files
authored
Merge pull request #194 from UiPath/akshaya/improved_is_integration
feat(IntegrationService): improved integration-service integration
2 parents 0a1bc7f + 84c9610 commit ead77c6

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
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.135"
3+
version = "0.0.136"
44
description = "UiPath Langchain"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
77
dependencies = [
8-
"uipath>=2.1.64, <2.2.0",
8+
"uipath>=2.1.65, <2.2.0",
99
"langgraph>=0.5.0, <0.7.0",
1010
"langchain-core>=0.3.34",
1111
"langgraph-checkpoint-sqlite>=2.0.3",

src/uipath_langchain/tools/preconfigured.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import logging
3-
from typing import Iterable, Optional, Type
3+
from typing import Any, Iterable, Optional, Type
44

55
import httpx
66
from jsonschema_pydantic import jsonschema_to_pydantic as create_model # type: ignore
@@ -14,11 +14,13 @@
1414
AgentDefinition,
1515
AgentEscalationChannel,
1616
AgentEscalationResourceConfig,
17+
AgentIntegrationToolParameter,
1718
AgentIntegrationToolResourceConfig,
1819
AgentProcessToolResourceConfig,
1920
AgentResourceConfig,
2021
)
2122
from uipath.models import CreateAction, InvokeProcess
23+
from uipath.models.connections import ConnectionTokenType
2224

2325
logger = logging.getLogger(__name__)
2426

@@ -91,6 +93,27 @@ def create_escalation_tool(
9193
yield create_escalation_tool_from_channel(channel)
9294

9395

96+
METHOD_MAP = {"GETBYID": "GET"}
97+
98+
99+
def build_query_params(parameters: list[AgentIntegrationToolParameter]):
100+
query_params = [
101+
x for x in parameters if x.field_location == "query" and x.value is not None
102+
]
103+
if query_params:
104+
return "?" + "&".join(f"{q.name}={q.value}" for q in query_params)
105+
return ""
106+
107+
108+
def filter_query_params(
109+
kwargs: dict[str, Any], parameters: list[AgentIntegrationToolParameter]
110+
):
111+
query_params = {x.name for x in parameters if x.field_location == "query"}
112+
non_query_params = {x.name for x in parameters if x.field_location != "query"}
113+
fields_to_ignore = query_params - non_query_params
114+
return {k: v for k, v in kwargs.items() if k not in fields_to_ignore}
115+
116+
94117
def create_integration_tool(
95118
resource: AgentIntegrationToolResourceConfig,
96119
) -> Iterable[BaseTool]:
@@ -100,15 +123,21 @@ async def integration(**kwargs) -> BaseModel:
100123
resource.properties.connection.id
101124
)
102125
token = await uipath.connections.retrieve_token_async(
103-
resource.properties.connection.id
126+
resource.properties.connection.id, ConnectionTokenType.BEARER
104127
)
105128
tool_url = f"{remote_connection.api_base_uri}/v3/element/instances/{remote_connection.element_instance_id}{resource.properties.tool_path}"
129+
tool_url = f"{tool_url}{build_query_params(resource.properties.parameters)}"
130+
tool_url = tool_url.format(**kwargs)
106131

132+
authorization = f"{token.token_type} {token.access_token}"
133+
method = METHOD_MAP.get(resource.properties.method, resource.properties.method)
107134
response = await httpx.AsyncClient().request(
108-
resource.properties.method,
135+
method,
109136
tool_url,
110-
headers={"Authorization": f"Bearer {token.access_token}"},
111-
content=json.dumps(kwargs),
137+
headers={"Authorization": authorization},
138+
content=json.dumps(
139+
filter_query_params(kwargs, resource.properties.parameters)
140+
),
112141
)
113142
return response.json()
114143

tests/tools/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def uipath_connection_mock(httpx_mock, response):
3535
@contextmanager
3636
def uipath_token_mock(httpx_mock, response):
3737
httpx_mock.add_response(
38-
url="https://example.com/api/v1/Connections/connection-id/token?tokenType=direct",
38+
url="https://example.com/api/v1/Connections/connection-id/token?tokenType=bearer",
3939
method="GET",
4040
json=response,
4141
)

uv.lock

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

0 commit comments

Comments
 (0)