uipath 2.5__0-py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uipath/_cli/README.md +11 -0
- uipath/_cli/__init__.py +161 -0
- uipath/_cli/_auth/_auth_server.py +198 -0
- uipath/_cli/_auth/_auth_service.py +153 -0
- uipath/_cli/_auth/_models.py +40 -0
- uipath/_cli/_auth/_oidc_utils.py +195 -0
- uipath/_cli/_auth/_portal_service.py +227 -0
- uipath/_cli/_auth/_url_utils.py +82 -0
- uipath/_cli/_auth/_utils.py +27 -0
- uipath/_cli/_auth/auth_config_25_10.json +6 -0
- uipath/_cli/_auth/auth_config_cloud.json +6 -0
- uipath/_cli/_auth/index.html +616 -0
- uipath/_cli/_auth/localhost.crt +25 -0
- uipath/_cli/_auth/localhost.key +27 -0
- uipath/_cli/_chat/_bridge.py +379 -0
- uipath/_cli/_debug/_bridge.py +886 -0
- uipath/_cli/_evals/__init__.py +0 -0
- uipath/_cli/_evals/_configurable_factory.py +167 -0
- uipath/_cli/_evals/_console_progress_reporter.py +248 -0
- uipath/_cli/_evals/_eval_util.py +80 -0
- uipath/_cli/_evals/_evaluate.py +25 -0
- uipath/_cli/_evals/_evaluator_factory.py +491 -0
- uipath/_cli/_evals/_helpers.py +196 -0
- uipath/_cli/_evals/_models/_evaluation_set.py +288 -0
- uipath/_cli/_evals/_models/_evaluator.py +280 -0
- uipath/_cli/_evals/_models/_evaluator_base_params.py +16 -0
- uipath/_cli/_evals/_models/_exceptions.py +6 -0
- uipath/_cli/_evals/_models/_mocks.py +3 -0
- uipath/_cli/_evals/_models/_output.py +201 -0
- uipath/_cli/_evals/_models/_sw_reporting.py +21 -0
- uipath/_cli/_evals/_progress_reporter.py +1356 -0
- uipath/_cli/_evals/_runtime.py +1048 -0
- uipath/_cli/_evals/_span_collection.py +23 -0
- uipath/_cli/_evals/_span_utils.py +280 -0
- uipath/_cli/_evals/_telemetry.py +322 -0
- uipath/_cli/_evals/mocks/__init__.py +1 -0
- uipath/_cli/_evals/mocks/cache_manager.py +94 -0
- uipath/_cli/_evals/mocks/input_mocker.py +149 -0
- uipath/_cli/_evals/mocks/llm_mocker.py +217 -0
- uipath/_cli/_evals/mocks/mocker.py +41 -0
- uipath/_cli/_evals/mocks/mocker_factory.py +25 -0
- uipath/_cli/_evals/mocks/mockito_mocker.py +125 -0
- uipath/_cli/_evals/mocks/mocks.py +116 -0
- uipath/_cli/_push/models.py +17 -0
- uipath/_cli/_push/sw_file_handler.py +630 -0
- uipath/_cli/_templates/.psmdcp.template +9 -0
- uipath/_cli/_templates/.rels.template +5 -0
- uipath/_cli/_templates/[Content_Types].xml.template +9 -0
- uipath/_cli/_templates/custom_evaluator.py.template +65 -0
- uipath/_cli/_templates/main.py.template +24 -0
- uipath/_cli/_templates/package.nuspec.template +10 -0
- uipath/_cli/_utils/_common.py +212 -0
- uipath/_cli/_utils/_console.py +337 -0
- uipath/_cli/_utils/_constants.py +63 -0
- uipath/_cli/_utils/_context.py +65 -0
- uipath/_cli/_utils/_debug.py +56 -0
- uipath/_cli/_utils/_eval_set.py +161 -0
- uipath/_cli/_utils/_folders.py +41 -0
- uipath/_cli/_utils/_formatters.py +173 -0
- uipath/_cli/_utils/_parallelization.py +60 -0
- uipath/_cli/_utils/_processes.py +54 -0
- uipath/_cli/_utils/_project_files.py +615 -0
- uipath/_cli/_utils/_resources.py +22 -0
- uipath/_cli/_utils/_service_base.py +343 -0
- uipath/_cli/_utils/_service_cli_generator.py +705 -0
- uipath/_cli/_utils/_service_metadata.py +206 -0
- uipath/_cli/_utils/_service_protocol.py +223 -0
- uipath/_cli/_utils/_studio_project.py +969 -0
- uipath/_cli/_utils/_tracing.py +52 -0
- uipath/_cli/_utils/_type_registry.py +106 -0
- uipath/_cli/_utils/_uv_helpers.py +114 -0
- uipath/_cli/_utils/_validators.py +127 -0
- uipath/_cli/cli_add.py +113 -0
- uipath/_cli/cli_auth.py +86 -0
- uipath/_cli/cli_debug.py +183 -0
- uipath/_cli/cli_deploy.py +34 -0
- uipath/_cli/cli_dev.py +96 -0
- uipath/_cli/cli_eval.py +259 -0
- uipath/_cli/cli_init.py +350 -0
- uipath/_cli/cli_invoke.py +124 -0
- uipath/_cli/cli_new.py +85 -0
- uipath/_cli/cli_pack.py +372 -0
- uipath/_cli/cli_publish.py +228 -0
- uipath/_cli/cli_pull.py +82 -0
- uipath/_cli/cli_push.py +308 -0
- uipath/_cli/cli_register.py +44 -0
- uipath/_cli/cli_run.py +225 -0
- uipath/_cli/middlewares.py +143 -0
- uipath/_cli/models/__init__.py +0 -0
- uipath/_cli/models/runtime_schema.py +43 -0
- uipath/_cli/models/uipath_json_schema.py +133 -0
- uipath/_cli/runtimes.py +11 -0
- uipath/_cli/services/__init__.py +38 -0
- uipath/_cli/services/_buckets_metadata.py +53 -0
- uipath/_cli/services/cli_buckets.py +526 -0
- uipath/_cli/spinner.py +38 -0
- uipath/_events/__init__.py +0 -0
- uipath/_events/_event_bus.py +157 -0
- uipath/_events/_events.py +73 -0
- uipath/_resources/AGENTS.md +21 -0
- uipath/_resources/CLAUDE.md +1 -0
- uipath/_resources/CLI_REFERENCE.md +229 -0
- uipath/_resources/REQUIRED_STRUCTURE.md +64 -0
- uipath/_resources/SDK_REFERENCE.md +643 -0
- uipath/_resources/eval.md +287 -0
- uipath/_resources/new-agent.md +103 -0
- uipath/_utils/__init__.py +20 -0
- uipath/_utils/_auth.py +49 -0
- uipath/_utils/_bindings.py +221 -0
- uipath/_utils/_endpoint.py +79 -0
- uipath/_utils/_logs.py +21 -0
- uipath/_utils/_request_override.py +18 -0
- uipath/_utils/_request_spec.py +23 -0
- uipath/_utils/_ssl_context.py +54 -0
- uipath/_utils/_url.py +102 -0
- uipath/_utils/_user_agent.py +19 -0
- uipath/_utils/constants.py +79 -0
- uipath/_utils/validation.py +43 -0
- uipath/agent/__init__.py +6 -0
- uipath/agent/models/agent.py +933 -0
- uipath/agent/models/evals.py +27 -0
- uipath/agent/react/__init__.py +28 -0
- uipath/agent/react/conversational_prompts.py +293 -0
- uipath/agent/react/prompts.py +57 -0
- uipath/agent/react/tools.py +74 -0
- uipath/agent/utils/__init__.py +18 -0
- uipath/agent/utils/_utils.py +139 -0
- uipath/agent/utils/text_tokens.py +136 -0
- uipath/eval/_helpers/__init__.py +3 -0
- uipath/eval/_helpers/evaluators_helpers.py +494 -0
- uipath/eval/_helpers/helpers.py +78 -0
- uipath/eval/evaluators/__init__.py +74 -0
- uipath/eval/evaluators/base_evaluator.py +610 -0
- uipath/eval/evaluators/contains_evaluator.py +80 -0
- uipath/eval/evaluators/exact_match_evaluator.py +68 -0
- uipath/eval/evaluators/json_similarity_evaluator.py +180 -0
- uipath/eval/evaluators/legacy_base_evaluator.py +114 -0
- uipath/eval/evaluators/legacy_context_precision_evaluator.py +352 -0
- uipath/eval/evaluators/legacy_deterministic_evaluator_base.py +53 -0
- uipath/eval/evaluators/legacy_evaluator_utils.py +75 -0
- uipath/eval/evaluators/legacy_exact_match_evaluator.py +63 -0
- uipath/eval/evaluators/legacy_faithfulness_evaluator.py +516 -0
- uipath/eval/evaluators/legacy_json_similarity_evaluator.py +164 -0
- uipath/eval/evaluators/legacy_llm_as_judge_evaluator.py +151 -0
- uipath/eval/evaluators/legacy_trajectory_evaluator.py +174 -0
- uipath/eval/evaluators/llm_as_judge_evaluator.py +202 -0
- uipath/eval/evaluators/llm_judge_output_evaluator.py +112 -0
- uipath/eval/evaluators/llm_judge_trajectory_evaluator.py +142 -0
- uipath/eval/evaluators/output_evaluator.py +119 -0
- uipath/eval/evaluators/tool_call_args_evaluator.py +82 -0
- uipath/eval/evaluators/tool_call_count_evaluator.py +87 -0
- uipath/eval/evaluators/tool_call_order_evaluator.py +84 -0
- uipath/eval/evaluators/tool_call_output_evaluator.py +87 -0
- uipath/eval/evaluators_types/ContainsEvaluator.json +79 -0
- uipath/eval/evaluators_types/ExactMatchEvaluator.json +95 -0
- uipath/eval/evaluators_types/JsonSimilarityEvaluator.json +87 -0
- uipath/eval/evaluators_types/LLMJudgeOutputEvaluator.json +114 -0
- uipath/eval/evaluators_types/LLMJudgeStrictJSONSimilarityOutputEvaluator.json +114 -0
- uipath/eval/evaluators_types/LLMJudgeTrajectoryEvaluator.json +92 -0
- uipath/eval/evaluators_types/LLMJudgeTrajectorySimulationEvaluator.json +92 -0
- uipath/eval/evaluators_types/ToolCallArgsEvaluator.json +137 -0
- uipath/eval/evaluators_types/ToolCallCountEvaluator.json +110 -0
- uipath/eval/evaluators_types/ToolCallOrderEvaluator.json +106 -0
- uipath/eval/evaluators_types/ToolCallOutputEvaluator.json +130 -0
- uipath/eval/evaluators_types/generate_types.py +31 -0
- uipath/eval/mocks/__init__.py +8 -0
- uipath/eval/mocks/mockable.py +105 -0
- uipath/eval/models/__init__.py +34 -0
- uipath/eval/models/llm_judge_types.py +196 -0
- uipath/eval/models/models.py +323 -0
- uipath/functions/__init__.py +25 -0
- uipath/functions/factory.py +86 -0
- uipath/functions/runtime.py +196 -0
- uipath/functions/schema_gen.py +149 -0
- uipath/functions/type_conversion.py +135 -0
- uipath/platform/__init__.py +40 -0
- uipath/platform/_uipath.py +155 -0
- uipath/platform/action_center/__init__.py +14 -0
- uipath/platform/action_center/_tasks_service.py +470 -0
- uipath/platform/action_center/task_schema.py +30 -0
- uipath/platform/action_center/tasks.py +84 -0
- uipath/platform/attachments/__init__.py +12 -0
- uipath/platform/attachments/attachments.py +41 -0
- uipath/platform/chat/__init__.py +63 -0
- uipath/platform/chat/_conversations_service.py +50 -0
- uipath/platform/chat/_llm_gateway_service.py +596 -0
- uipath/platform/chat/llm_gateway.py +128 -0
- uipath/platform/chat/llm_throttle.py +49 -0
- uipath/platform/common/__init__.py +51 -0
- uipath/platform/common/_api_client.py +59 -0
- uipath/platform/common/_base_service.py +192 -0
- uipath/platform/common/_config.py +117 -0
- uipath/platform/common/_execution_context.py +78 -0
- uipath/platform/common/_external_application_service.py +140 -0
- uipath/platform/common/_folder_context.py +53 -0
- uipath/platform/common/auth.py +16 -0
- uipath/platform/common/interrupt_models.py +136 -0
- uipath/platform/common/paging.py +63 -0
- uipath/platform/connections/__init__.py +26 -0
- uipath/platform/connections/_connections_service.py +813 -0
- uipath/platform/connections/connections.py +107 -0
- uipath/platform/context_grounding/__init__.py +65 -0
- uipath/platform/context_grounding/_context_grounding_service.py +1465 -0
- uipath/platform/context_grounding/context_grounding.py +192 -0
- uipath/platform/context_grounding/context_grounding_index.py +76 -0
- uipath/platform/context_grounding/context_grounding_payloads.py +211 -0
- uipath/platform/documents/__init__.py +46 -0
- uipath/platform/documents/_documents_service.py +2010 -0
- uipath/platform/documents/documents.py +266 -0
- uipath/platform/entities/__init__.py +36 -0
- uipath/platform/entities/_entities_service.py +902 -0
- uipath/platform/entities/entities.py +325 -0
- uipath/platform/errors/__init__.py +34 -0
- uipath/platform/errors/_base_url_missing_error.py +13 -0
- uipath/platform/errors/_batch_transform_not_complete_exception.py +13 -0
- uipath/platform/errors/_enriched_exception.py +38 -0
- uipath/platform/errors/_folder_not_found_exception.py +13 -0
- uipath/platform/errors/_ingestion_in_progress_exception.py +17 -0
- uipath/platform/errors/_ixp_extraction_not_complete_exception.py +14 -0
- uipath/platform/errors/_secret_missing_error.py +13 -0
- uipath/platform/errors/_unsupported_data_source_exception.py +17 -0
- uipath/platform/guardrails/__init__.py +36 -0
- uipath/platform/guardrails/_guardrails_service.py +85 -0
- uipath/platform/guardrails/guardrails.py +70 -0
- uipath/platform/orchestrator/__init__.py +53 -0
- uipath/platform/orchestrator/_assets_service.py +372 -0
- uipath/platform/orchestrator/_attachments_service.py +1020 -0
- uipath/platform/orchestrator/_buckets_service.py +1799 -0
- uipath/platform/orchestrator/_folder_service.py +220 -0
- uipath/platform/orchestrator/_jobs_service.py +1485 -0
- uipath/platform/orchestrator/_mcp_service.py +223 -0
- uipath/platform/orchestrator/_processes_service.py +248 -0
- uipath/platform/orchestrator/_queues_service.py +352 -0
- uipath/platform/orchestrator/assets.py +73 -0
- uipath/platform/orchestrator/attachment.py +36 -0
- uipath/platform/orchestrator/buckets.py +80 -0
- uipath/platform/orchestrator/folder.py +15 -0
- uipath/platform/orchestrator/job.py +81 -0
- uipath/platform/orchestrator/mcp.py +56 -0
- uipath/platform/orchestrator/processes.py +49 -0
- uipath/platform/orchestrator/queues.py +204 -0
- uipath/platform/resource_catalog/__init__.py +15 -0
- uipath/platform/resource_catalog/_resource_catalog_service.py +630 -0
- uipath/platform/resource_catalog/resource_catalog.py +124 -0
- uipath/platform/resume_triggers/__init__.py +16 -0
- uipath/platform/resume_triggers/_enums.py +18 -0
- uipath/platform/resume_triggers/_protocol.py +620 -0
- uipath/py.typed +0 -0
- uipath/telemetry/__init__.py +8 -0
- uipath/telemetry/_constants.py +20 -0
- uipath/telemetry/_track.py +349 -0
- uipath/tracing/__init__.py +16 -0
- uipath/tracing/_otel_exporters.py +437 -0
- uipath/tracing/_utils.py +395 -0
- uipath/utils/__init__.py +5 -0
- uipath/utils/_endpoints_manager.py +198 -0
- uipath/utils/dynamic_schema.py +128 -0
- uipath-2.5.0.dist-info/METADATA +235 -0
- uipath-2.5.0.dist-info/RECORD +262 -0
- uipath-2.5.0.dist-info/WHEEL +4 -0
- uipath-2.5.0.dist-info/entry_points.txt +2 -0
- uipath-2.5.0.dist-info/licenses/LICENSE +9 -0
uipath/_cli/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# parse
|
|
2
|
+
|
|
3
|
+
`parse-ast.py` will extract names and types of resources to prepare for bindings. currently it's hardcoded to run on `dummy-main.py`
|
|
4
|
+
|
|
5
|
+
# init
|
|
6
|
+
|
|
7
|
+
asks for project name, type (process/agent) description and target directory where to init the project. it inits a script, a requirements.txt for the user to install, and a config.json file that we'll use at packing time.
|
|
8
|
+
|
|
9
|
+
# pack
|
|
10
|
+
|
|
11
|
+
asks for target directory of the package files and the version and will create a nupkg file
|
uipath/_cli/__init__.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
|
|
8
|
+
from uipath._cli._utils._context import CliContext
|
|
9
|
+
from uipath._cli.runtimes import load_runtime_factories
|
|
10
|
+
from uipath._utils._logs import setup_logging
|
|
11
|
+
from uipath._utils.constants import DOTENV_FILE
|
|
12
|
+
from uipath.functions import register_default_runtime_factory
|
|
13
|
+
|
|
14
|
+
# DO NOT ADD HEAVY IMPORTS HERE
|
|
15
|
+
#
|
|
16
|
+
# Every import at the top of this file runs on EVERY command.
|
|
17
|
+
# Yes, even `--version`. Yes, even `--help`.
|
|
18
|
+
#
|
|
19
|
+
# We spent hours getting startup from 1.7s → 0.5s.
|
|
20
|
+
# If you add `import pandas` here, I will find you.
|
|
21
|
+
|
|
22
|
+
_LAZY_COMMANDS = {
|
|
23
|
+
"new": "cli_new",
|
|
24
|
+
"init": "cli_init",
|
|
25
|
+
"pack": "cli_pack",
|
|
26
|
+
"publish": "cli_publish",
|
|
27
|
+
"run": "cli_run",
|
|
28
|
+
"deploy": "cli_deploy",
|
|
29
|
+
"auth": "cli_auth",
|
|
30
|
+
"invoke": "cli_invoke",
|
|
31
|
+
"push": "cli_push",
|
|
32
|
+
"pull": "cli_pull",
|
|
33
|
+
"eval": "cli_eval",
|
|
34
|
+
"dev": "cli_dev",
|
|
35
|
+
"add": "cli_add",
|
|
36
|
+
"register": "cli_register",
|
|
37
|
+
"debug": "cli_debug",
|
|
38
|
+
"buckets": "services.cli_buckets",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _load_command(name: str):
|
|
43
|
+
"""Load a CLI command by name."""
|
|
44
|
+
if name not in _LAZY_COMMANDS:
|
|
45
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
46
|
+
module_name = _LAZY_COMMANDS[name]
|
|
47
|
+
mod = __import__(f"uipath._cli.{module_name}", fromlist=[name])
|
|
48
|
+
return getattr(mod, name)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def __getattr__(name: str):
|
|
52
|
+
"""Lazy load CLI commands for mkdocs-click compatibility."""
|
|
53
|
+
return _load_command(name)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def add_cwd_to_path():
|
|
57
|
+
cwd = os.getcwd()
|
|
58
|
+
if cwd not in sys.path:
|
|
59
|
+
sys.path.insert(0, cwd)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def load_environment_variables():
|
|
63
|
+
load_dotenv(dotenv_path=os.path.join(os.getcwd(), DOTENV_FILE), override=True)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
load_environment_variables()
|
|
67
|
+
add_cwd_to_path()
|
|
68
|
+
register_default_runtime_factory()
|
|
69
|
+
load_runtime_factories()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _get_safe_version() -> str:
|
|
73
|
+
"""Get the version of the uipath package."""
|
|
74
|
+
try:
|
|
75
|
+
version = importlib.metadata.version("uipath")
|
|
76
|
+
return version
|
|
77
|
+
except importlib.metadata.PackageNotFoundError:
|
|
78
|
+
return "unknown"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class LazyGroup(click.Group):
|
|
82
|
+
"""Lazy-load commands only when invoked."""
|
|
83
|
+
|
|
84
|
+
def list_commands(self, ctx):
|
|
85
|
+
return sorted(_LAZY_COMMANDS.keys())
|
|
86
|
+
|
|
87
|
+
def get_command(self, ctx, cmd_name):
|
|
88
|
+
if cmd_name in _LAZY_COMMANDS:
|
|
89
|
+
return _load_command(cmd_name)
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@click.command(cls=LazyGroup, invoke_without_command=True)
|
|
94
|
+
@click.version_option(
|
|
95
|
+
_get_safe_version(),
|
|
96
|
+
prog_name="uipath",
|
|
97
|
+
message="%(prog)s version %(version)s",
|
|
98
|
+
)
|
|
99
|
+
@click.option(
|
|
100
|
+
"-lv",
|
|
101
|
+
is_flag=True,
|
|
102
|
+
help="Display the current version of uipath-langchain.",
|
|
103
|
+
)
|
|
104
|
+
@click.option(
|
|
105
|
+
"-v",
|
|
106
|
+
is_flag=True,
|
|
107
|
+
help="Display the current version of uipath.",
|
|
108
|
+
)
|
|
109
|
+
@click.option(
|
|
110
|
+
"--format",
|
|
111
|
+
type=click.Choice(["json", "table", "csv"]),
|
|
112
|
+
default="table",
|
|
113
|
+
help="Output format for commands",
|
|
114
|
+
)
|
|
115
|
+
@click.option(
|
|
116
|
+
"--debug",
|
|
117
|
+
is_flag=True,
|
|
118
|
+
help="Enable debug logging and show stack traces",
|
|
119
|
+
)
|
|
120
|
+
@click.pass_context
|
|
121
|
+
def cli(
|
|
122
|
+
ctx: click.Context,
|
|
123
|
+
lv: bool,
|
|
124
|
+
v: bool,
|
|
125
|
+
format: str,
|
|
126
|
+
debug: bool,
|
|
127
|
+
) -> None:
|
|
128
|
+
"""UiPath CLI - Automate everything.
|
|
129
|
+
|
|
130
|
+
\b
|
|
131
|
+
Examples:
|
|
132
|
+
uipath new my-project
|
|
133
|
+
uipath dev
|
|
134
|
+
uipath deploy
|
|
135
|
+
uipath buckets list --folder-path "Shared"
|
|
136
|
+
""" # noqa: D301
|
|
137
|
+
ctx.obj = CliContext(
|
|
138
|
+
output_format=format,
|
|
139
|
+
debug=debug,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
setup_logging(should_debug=debug)
|
|
143
|
+
|
|
144
|
+
if lv:
|
|
145
|
+
try:
|
|
146
|
+
version = importlib.metadata.version("uipath-langchain")
|
|
147
|
+
click.echo(f"uipath-langchain version {version}")
|
|
148
|
+
except importlib.metadata.PackageNotFoundError:
|
|
149
|
+
click.echo("uipath-langchain is not installed", err=True)
|
|
150
|
+
sys.exit(1)
|
|
151
|
+
if v:
|
|
152
|
+
try:
|
|
153
|
+
version = importlib.metadata.version("uipath")
|
|
154
|
+
click.echo(f"uipath version {version}")
|
|
155
|
+
except importlib.metadata.PackageNotFoundError:
|
|
156
|
+
click.echo("uipath is not installed", err=True)
|
|
157
|
+
sys.exit(1)
|
|
158
|
+
|
|
159
|
+
# Show help if no command was provided (matches docker, kubectl, git behavior)
|
|
160
|
+
if ctx.invoked_subcommand is None and not lv and not v:
|
|
161
|
+
click.echo(ctx.get_help())
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import http.server
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import socketserver
|
|
6
|
+
import threading
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
# Server port
|
|
10
|
+
PORT = 6234
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Custom exception for token received
|
|
14
|
+
class TokenReceivedSignal(Exception):
|
|
15
|
+
"""Exception raised when a token is successfully received."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, token_data):
|
|
18
|
+
self.token_data = token_data
|
|
19
|
+
super().__init__("Token received successfully")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def make_request_handler_class(
|
|
23
|
+
state, code_verifier, token_callback, domain, redirect_uri, client_id
|
|
24
|
+
):
|
|
25
|
+
class SimpleHTTPSRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|
26
|
+
"""Simple HTTPS request handler that serves static files."""
|
|
27
|
+
|
|
28
|
+
def log_message(self, format, *args) -> None:
|
|
29
|
+
# do nothing
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def do_POST(self):
|
|
33
|
+
"""Handle POST requests to /set_token."""
|
|
34
|
+
if self.path == "/set_token":
|
|
35
|
+
content_length = int(self.headers["Content-Length"])
|
|
36
|
+
post_data = self.rfile.read(content_length)
|
|
37
|
+
token_data = json.loads(post_data.decode("utf-8"))
|
|
38
|
+
|
|
39
|
+
self.send_response(200)
|
|
40
|
+
self.end_headers()
|
|
41
|
+
self.wfile.write(b"Token received")
|
|
42
|
+
|
|
43
|
+
time.sleep(1)
|
|
44
|
+
|
|
45
|
+
token_callback(token_data)
|
|
46
|
+
elif self.path == "/log":
|
|
47
|
+
content_length = int(self.headers["Content-Length"])
|
|
48
|
+
post_data = self.rfile.read(content_length)
|
|
49
|
+
logs = json.loads(post_data.decode("utf-8"))
|
|
50
|
+
# Write logs to .uipath/.error_log file
|
|
51
|
+
uipath_dir = os.path.join(os.getcwd(), ".uipath")
|
|
52
|
+
os.makedirs(uipath_dir, exist_ok=True)
|
|
53
|
+
error_log_path = os.path.join(uipath_dir, ".error_log")
|
|
54
|
+
|
|
55
|
+
with open(error_log_path, "a", encoding="utf-8") as f:
|
|
56
|
+
f.write(
|
|
57
|
+
f"\n--- Authentication Error Log {time.strftime('%Y-%m-%d %H:%M:%S')} ---\n"
|
|
58
|
+
)
|
|
59
|
+
json.dump(logs, f, indent=2)
|
|
60
|
+
f.write("\n")
|
|
61
|
+
self.send_response(200)
|
|
62
|
+
self.end_headers()
|
|
63
|
+
self.wfile.write(b"Log received")
|
|
64
|
+
else:
|
|
65
|
+
self.send_error(404, "Path not found")
|
|
66
|
+
|
|
67
|
+
def do_GET(self):
|
|
68
|
+
"""Handle GET requests by serving index.html."""
|
|
69
|
+
# Always serve index.html regardless of the path
|
|
70
|
+
try:
|
|
71
|
+
index_path = os.path.join(os.path.dirname(__file__), "index.html")
|
|
72
|
+
with open(index_path, "r") as f:
|
|
73
|
+
content = f.read()
|
|
74
|
+
|
|
75
|
+
content = content.replace("__PY_REPLACE_EXPECTED_STATE__", state)
|
|
76
|
+
content = content.replace("__PY_REPLACE_CODE_VERIFIER__", code_verifier)
|
|
77
|
+
content = content.replace("__PY_REPLACE_REDIRECT_URI__", redirect_uri)
|
|
78
|
+
content = content.replace("__PY_REPLACE_CLIENT_ID__", client_id)
|
|
79
|
+
content = content.replace("__PY_REPLACE_DOMAIN__", domain)
|
|
80
|
+
|
|
81
|
+
self.send_response(200)
|
|
82
|
+
self.send_header("Content-Type", "text/html")
|
|
83
|
+
self.send_header("Content-Length", str(len(content)))
|
|
84
|
+
self.end_headers()
|
|
85
|
+
self.wfile.write(content.encode("utf-8"))
|
|
86
|
+
except FileNotFoundError:
|
|
87
|
+
self.send_error(404, "File not found")
|
|
88
|
+
|
|
89
|
+
def end_headers(self):
|
|
90
|
+
self.send_header("Access-Control-Allow-Origin", "*")
|
|
91
|
+
self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
|
92
|
+
self.send_header("Access-Control-Allow-Headers", "Content-Type")
|
|
93
|
+
super().end_headers()
|
|
94
|
+
|
|
95
|
+
def do_OPTIONS(self):
|
|
96
|
+
self.send_response(200)
|
|
97
|
+
self.end_headers()
|
|
98
|
+
|
|
99
|
+
return SimpleHTTPSRequestHandler
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class HTTPServer:
|
|
103
|
+
def __init__(self, port=6234, redirect_uri=None, client_id=None):
|
|
104
|
+
"""Initialize HTTP server with configurable parameters.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
port (int, optional): Port number to run the server on. Defaults to 6234.
|
|
108
|
+
redirect_uri (str, optional): OAuth redirect URI. Defaults to None.
|
|
109
|
+
client_id (str, optional): OAuth client ID. Defaults to None.
|
|
110
|
+
"""
|
|
111
|
+
self.current_path = os.path.dirname(os.path.abspath(__file__))
|
|
112
|
+
self.port = port
|
|
113
|
+
self.redirect_uri = redirect_uri
|
|
114
|
+
self.client_id = client_id
|
|
115
|
+
self.httpd: socketserver.TCPServer | None = None
|
|
116
|
+
self.token_data = None
|
|
117
|
+
self.should_shutdown = False
|
|
118
|
+
self.token_received_event: asyncio.Event | None = None
|
|
119
|
+
self.loop = None
|
|
120
|
+
|
|
121
|
+
def token_received_callback(self, token_data):
|
|
122
|
+
"""Callback for when a token is received.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
token_data (dict): The received token data.
|
|
126
|
+
"""
|
|
127
|
+
self.token_data = token_data
|
|
128
|
+
if self.token_received_event and self.loop:
|
|
129
|
+
self.loop.call_soon_threadsafe(self.token_received_event.set)
|
|
130
|
+
|
|
131
|
+
def create_server(self, state, code_verifier, domain):
|
|
132
|
+
"""Create and configure the HTTP server.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
state (str): The OAuth state parameter.
|
|
136
|
+
code_verifier (str): The PKCE code verifier.
|
|
137
|
+
domain (str): The domain for authentication.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
socketserver.TCPServer: The configured HTTP server.
|
|
141
|
+
"""
|
|
142
|
+
# Create server with address reuse
|
|
143
|
+
socketserver.TCPServer.allow_reuse_address = True
|
|
144
|
+
handler = make_request_handler_class(
|
|
145
|
+
state,
|
|
146
|
+
code_verifier,
|
|
147
|
+
self.token_received_callback,
|
|
148
|
+
domain,
|
|
149
|
+
self.redirect_uri,
|
|
150
|
+
self.client_id,
|
|
151
|
+
)
|
|
152
|
+
self.httpd = socketserver.TCPServer(("", self.port), handler)
|
|
153
|
+
return self.httpd
|
|
154
|
+
|
|
155
|
+
def _run_server(self):
|
|
156
|
+
"""Run server loop in thread."""
|
|
157
|
+
try:
|
|
158
|
+
while not self.should_shutdown and self.httpd:
|
|
159
|
+
self.httpd.handle_request()
|
|
160
|
+
except Exception:
|
|
161
|
+
# Server might be closed, that's fine
|
|
162
|
+
pass
|
|
163
|
+
|
|
164
|
+
async def start(self, state, code_verifier, domain):
|
|
165
|
+
"""Start the server.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
state (str): The OAuth state parameter.
|
|
169
|
+
code_verifier (str): The PKCE code verifier.
|
|
170
|
+
domain (str): The domain for authentication.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
dict: The received token data or an empty dict if no token was received.
|
|
174
|
+
"""
|
|
175
|
+
if not self.httpd:
|
|
176
|
+
self.create_server(state, code_verifier, domain)
|
|
177
|
+
|
|
178
|
+
self.token_received_event = asyncio.Event()
|
|
179
|
+
self.loop = asyncio.get_event_loop()
|
|
180
|
+
|
|
181
|
+
# Run server in daemon thread
|
|
182
|
+
server_thread = threading.Thread(target=self._run_server, daemon=True)
|
|
183
|
+
server_thread.start()
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
# Wait indefinitely for token received event or interrupt
|
|
187
|
+
await self.token_received_event.wait()
|
|
188
|
+
finally:
|
|
189
|
+
self.stop()
|
|
190
|
+
|
|
191
|
+
return self.token_data if self.token_data else {}
|
|
192
|
+
|
|
193
|
+
def stop(self):
|
|
194
|
+
"""Stop the server gracefully and cleanup resources."""
|
|
195
|
+
self.should_shutdown = True
|
|
196
|
+
if self.httpd:
|
|
197
|
+
self.httpd.server_close()
|
|
198
|
+
self.httpd = None
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import os
|
|
3
|
+
import webbrowser
|
|
4
|
+
|
|
5
|
+
from uipath._cli._auth._auth_server import HTTPServer
|
|
6
|
+
from uipath._cli._auth._oidc_utils import OidcUtils
|
|
7
|
+
from uipath._cli._auth._portal_service import (
|
|
8
|
+
PortalService,
|
|
9
|
+
)
|
|
10
|
+
from uipath._cli._auth._url_utils import extract_org_tenant, resolve_domain
|
|
11
|
+
from uipath._cli._auth._utils import get_parsed_token_data
|
|
12
|
+
from uipath._cli._utils._console import ConsoleLogger
|
|
13
|
+
from uipath._utils._auth import update_env_file
|
|
14
|
+
from uipath.platform.common import ExternalApplicationService, TokenData
|
|
15
|
+
|
|
16
|
+
from ._utils import update_auth_file
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AuthService:
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
environment: str | None,
|
|
23
|
+
*,
|
|
24
|
+
force: bool,
|
|
25
|
+
client_id: str | None = None,
|
|
26
|
+
client_secret: str | None = None,
|
|
27
|
+
base_url: str | None = None,
|
|
28
|
+
tenant: str | None = None,
|
|
29
|
+
scope: str | None = None,
|
|
30
|
+
):
|
|
31
|
+
self._force = force
|
|
32
|
+
self._console = ConsoleLogger()
|
|
33
|
+
self._client_id = client_id
|
|
34
|
+
self._client_secret = client_secret
|
|
35
|
+
self._base_url = base_url
|
|
36
|
+
self._tenant = tenant
|
|
37
|
+
self._domain = resolve_domain(self._base_url, environment)
|
|
38
|
+
self._scope = scope
|
|
39
|
+
|
|
40
|
+
def authenticate(self) -> None:
|
|
41
|
+
if self._client_id and self._client_secret:
|
|
42
|
+
self._authenticate_client_credentials()
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
self._authenticate_authorization_code()
|
|
46
|
+
|
|
47
|
+
def _authenticate_client_credentials(self):
|
|
48
|
+
assert self._client_id and self._client_secret, (
|
|
49
|
+
"Client ID and Client Secret must be provided."
|
|
50
|
+
)
|
|
51
|
+
external_app_service = ExternalApplicationService(self._base_url)
|
|
52
|
+
token_data = external_app_service.get_token_data(
|
|
53
|
+
self._client_id,
|
|
54
|
+
self._client_secret,
|
|
55
|
+
self._scope,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
organization_name, tenant_name = extract_org_tenant(
|
|
59
|
+
external_app_service._base_url
|
|
60
|
+
)
|
|
61
|
+
if not (organization_name and tenant_name):
|
|
62
|
+
self._console.warning(
|
|
63
|
+
"--base-url should include both organization and tenant, "
|
|
64
|
+
"e.g., 'https://cloud.uipath.com/{organization}/{tenant}'."
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
env_vars = {
|
|
68
|
+
"UIPATH_ACCESS_TOKEN": token_data.access_token,
|
|
69
|
+
"UIPATH_URL": external_app_service._base_url,
|
|
70
|
+
"UIPATH_ORGANIZATION_ID": get_parsed_token_data(token_data).get("prt_id"),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if tenant_name:
|
|
74
|
+
self._tenant = tenant_name
|
|
75
|
+
with PortalService(self._domain) as portal_service:
|
|
76
|
+
portal_service.update_token_data(token_data)
|
|
77
|
+
tenant_info = portal_service.resolve_tenant_info(self._tenant)
|
|
78
|
+
env_vars["UIPATH_TENANT_ID"] = tenant_info["tenant_id"]
|
|
79
|
+
else:
|
|
80
|
+
self._console.warning("Could not extract tenant from --base-url.")
|
|
81
|
+
update_env_file(env_vars)
|
|
82
|
+
|
|
83
|
+
def _authenticate_authorization_code(self) -> None:
|
|
84
|
+
with PortalService(self._domain) as portal_service:
|
|
85
|
+
if not self._force and self._can_reuse_existing_token(portal_service):
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
token_data = self._perform_oauth_flow()
|
|
89
|
+
portal_service.update_token_data(token_data)
|
|
90
|
+
update_auth_file(token_data)
|
|
91
|
+
|
|
92
|
+
tenant_info = portal_service.resolve_tenant_info(self._tenant)
|
|
93
|
+
uipath_url = portal_service.build_tenant_url()
|
|
94
|
+
|
|
95
|
+
update_env_file(
|
|
96
|
+
{
|
|
97
|
+
"UIPATH_ACCESS_TOKEN": token_data.access_token,
|
|
98
|
+
"UIPATH_URL": uipath_url,
|
|
99
|
+
"UIPATH_TENANT_ID": tenant_info["tenant_id"],
|
|
100
|
+
"UIPATH_ORGANIZATION_ID": tenant_info["organization_id"],
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
portal_service.enable_studio_web(uipath_url)
|
|
106
|
+
except Exception:
|
|
107
|
+
self._console.error(
|
|
108
|
+
"Could not prepare the environment. Please try again."
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def _can_reuse_existing_token(self, portal_service: PortalService) -> bool:
|
|
112
|
+
if (
|
|
113
|
+
os.getenv("UIPATH_URL")
|
|
114
|
+
and os.getenv("UIPATH_TENANT_ID")
|
|
115
|
+
and os.getenv("UIPATH_ORGANIZATION_ID")
|
|
116
|
+
):
|
|
117
|
+
try:
|
|
118
|
+
portal_service.ensure_valid_token()
|
|
119
|
+
return True
|
|
120
|
+
except Exception:
|
|
121
|
+
self._console.error(
|
|
122
|
+
"Authentication token is invalid. Please reauthenticate using the '--force' flag."
|
|
123
|
+
)
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
def _perform_oauth_flow(self) -> TokenData:
|
|
127
|
+
auth_config = OidcUtils.get_auth_config(self._domain)
|
|
128
|
+
auth_url, code_verifier, state = OidcUtils.get_auth_url(
|
|
129
|
+
self._domain, auth_config
|
|
130
|
+
)
|
|
131
|
+
self._open_browser(auth_url)
|
|
132
|
+
|
|
133
|
+
server = HTTPServer(
|
|
134
|
+
port=auth_config["port"],
|
|
135
|
+
redirect_uri=auth_config["redirect_uri"],
|
|
136
|
+
client_id=auth_config["client_id"],
|
|
137
|
+
)
|
|
138
|
+
token_data = asyncio.run(server.start(state, code_verifier, self._domain))
|
|
139
|
+
|
|
140
|
+
if not token_data:
|
|
141
|
+
self._console.error(
|
|
142
|
+
"Authentication failed. Please try again.",
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
return TokenData.model_validate(token_data)
|
|
146
|
+
|
|
147
|
+
def _open_browser(self, url: str) -> None:
|
|
148
|
+
# Try to open browser. Always print the fallback link.
|
|
149
|
+
webbrowser.open(url, new=1)
|
|
150
|
+
self._console.link(
|
|
151
|
+
"If a browser window did not open, please open the following URL in your browser:",
|
|
152
|
+
url,
|
|
153
|
+
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import TypedDict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AuthConfig(TypedDict):
|
|
5
|
+
"""TypedDict for auth_config.json structure."""
|
|
6
|
+
|
|
7
|
+
client_id: str
|
|
8
|
+
port: int
|
|
9
|
+
redirect_uri: str
|
|
10
|
+
scope: str
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AccessTokenData(TypedDict):
|
|
14
|
+
"""TypedDict for access token data structure."""
|
|
15
|
+
|
|
16
|
+
sub: str
|
|
17
|
+
prt_id: str
|
|
18
|
+
client_id: str
|
|
19
|
+
exp: float
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TenantInfo(TypedDict):
|
|
23
|
+
"""TypedDict for tenant info structure."""
|
|
24
|
+
|
|
25
|
+
name: str
|
|
26
|
+
id: str
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class OrganizationInfo(TypedDict):
|
|
30
|
+
"""TypedDict for organization info structure."""
|
|
31
|
+
|
|
32
|
+
id: str
|
|
33
|
+
name: str
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TenantsAndOrganizationInfoResponse(TypedDict):
|
|
37
|
+
"""TypedDict for tenants and organization info response structure."""
|
|
38
|
+
|
|
39
|
+
tenants: list[TenantInfo]
|
|
40
|
+
organization: OrganizationInfo
|