-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path_uipath.py
More file actions
176 lines (145 loc) · 5.79 KB
/
_uipath.py
File metadata and controls
176 lines (145 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from functools import cached_property
from typing import Optional
from pydantic import ValidationError
from uipath.platform.automation_tracker import AutomationTrackerService
from .action_center import TasksService
from .agenthub._agenthub_service import AgentHubService
from .agenthub._remote_a2a_service import RemoteA2aService
from .chat import ConversationsService, UiPathLlmChatService, UiPathOpenAIService
from .common import (
ApiClient,
ExternalApplicationService,
UiPathApiConfig,
UiPathExecutionContext,
)
from .common.auth import resolve_config_from_env
from .connections import ConnectionsService
from .context_grounding import ContextGroundingService
from .documents import DocumentsService
from .entities import EntitiesService
from .errors import BaseUrlMissingError, SecretMissingError
from .guardrails import GuardrailsService
from .orchestrator import (
AssetsService,
AttachmentsService,
BucketsService,
FolderService,
JobsService,
McpService,
OrchestratorSetupService,
ProcessesService,
QueuesService,
)
from .resource_catalog import ResourceCatalogService
def _has_valid_client_credentials(
client_id: Optional[str], client_secret: Optional[str]
) -> bool:
if bool(client_id) != bool(client_secret):
raise ValueError("Both client_id and client_secret must be provided together.")
return bool(client_id and client_secret)
class UiPath:
def __init__(
self,
*,
base_url: Optional[str] = None,
secret: Optional[str] = None,
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
scope: Optional[str] = None,
debug: bool = False,
) -> None:
try:
if _has_valid_client_credentials(client_id, client_secret):
assert client_id and client_secret
service = ExternalApplicationService(base_url)
token_data = service.get_token_data(client_id, client_secret, scope)
base_url, secret = service._base_url, token_data.access_token
else:
base_url, secret = resolve_config_from_env(base_url, secret)
self._config = UiPathApiConfig(
base_url=base_url,
secret=secret,
)
except ValidationError as e:
for error in e.errors():
if error["loc"][0] == "base_url":
raise BaseUrlMissingError() from e
elif error["loc"][0] == "secret":
raise SecretMissingError() from e
self._execution_context = UiPathExecutionContext()
@property
def api_client(self) -> ApiClient:
return ApiClient(self._config, self._execution_context)
@property
def assets(self) -> AssetsService:
return AssetsService(self._config, self._execution_context)
@cached_property
def attachments(self) -> AttachmentsService:
return AttachmentsService(self._config, self._execution_context)
@property
def processes(self) -> ProcessesService:
return ProcessesService(self._config, self._execution_context, self.attachments)
@property
def tasks(self) -> TasksService:
return TasksService(self._config, self._execution_context)
@cached_property
def buckets(self) -> BucketsService:
return BucketsService(self._config, self._execution_context)
@cached_property
def connections(self) -> ConnectionsService:
return ConnectionsService(self._config, self._execution_context, self.folders)
@property
def context_grounding(self) -> ContextGroundingService:
return ContextGroundingService(
self._config,
self._execution_context,
self.folders,
self.buckets,
)
@property
def documents(self) -> DocumentsService:
return DocumentsService(self._config, self._execution_context)
@property
def queues(self) -> QueuesService:
return QueuesService(self._config, self._execution_context)
@property
def jobs(self) -> JobsService:
return JobsService(self._config, self._execution_context)
@cached_property
def folders(self) -> FolderService:
return FolderService(self._config, self._execution_context)
@property
def llm_openai(self) -> UiPathOpenAIService:
return UiPathOpenAIService(self._config, self._execution_context)
@property
def llm(self) -> UiPathLlmChatService:
return UiPathLlmChatService(self._config, self._execution_context)
@property
def entities(self) -> EntitiesService:
return EntitiesService(self._config, self._execution_context)
@cached_property
def resource_catalog(self) -> ResourceCatalogService:
return ResourceCatalogService(
self._config, self._execution_context, self.folders
)
@property
def conversational(self) -> ConversationsService:
return ConversationsService(self._config, self._execution_context)
@property
def mcp(self) -> McpService:
return McpService(self._config, self._execution_context, self.folders)
@property
def guardrails(self) -> GuardrailsService:
return GuardrailsService(self._config, self._execution_context)
@property
def agenthub(self) -> AgentHubService:
return AgentHubService(self._config, self._execution_context, self.folders)
@property
def remote_a2a(self) -> RemoteA2aService:
return RemoteA2aService(self._config, self._execution_context, self.folders)
@property
def orchestrator_setup(self) -> OrchestratorSetupService:
return OrchestratorSetupService(self._config, self._execution_context)
@property
def automation_tracker(self) -> AutomationTrackerService:
return AutomationTrackerService(self._config, self._execution_context)