Skip to content

feat(cli): add uipath resources and derive bindings.json from uipath_resources.py - #2037

Open
vldcmp-uipath wants to merge 8 commits into
mainfrom
feat/resources-declarations-cli
Open

vldcmp-uipath wants to merge 8 commits into
mainfrom
feat/resources-declarations-cli

Conversation

@vldcmp-uipath

@vldcmp-uipath vldcmp-uipath commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Python side of bindings unification. A coded agent or Python function declares the platform resources it uses in one file, uipath_resources.py, and bindings.json is derived from it instead of written by hand. The uip CLI will forward uip codedagent resources / uip function resources here for Python projects, as it forwards the other codedagent commands (follow-up in UiPath/cli, after UiPath/cli#6337).

Summary

  • uipath.resources (uipath-platform, new module in the uipath namespace): from uipath.resources import resource; resource.<kind>(...) returns a frozen pydantic handle (kind, name, folder_path, plus a connection's id/connector, a skill bundle's version, type for asset/bucket/process). Plain data the code passes to today's SDK methods; no SDK signature changes. One method per kind the SDK can override, read from the overwrite models in common/_bindings.py, with a test that fails when a kind lacks a method.
  • uipath resources add | list | remove | generate-bindings: edits the file as text with ast, literal values only, never imports it, makes no requests. add and list take the same flags as uip <tool> resources, so forwarding is one to one.
  • pack, push, debug and eval regenerate bindings.json first when the project has a uipath_resources.py. A project without one behaves exactly as before. Pack then packs it as content/bindings_v2.json as today; debug and eval upload it to Studio Web for the overrides, so a resource declared after the last pack now gets its override in a local run.

Commands

Command Does
add <name> --kind <kind> [--folder-path] [--type]; connection: --id --connector; skill bundle: --version Creates uipath_resources.py (import + class ProjectResources) when missing, appends attr = resource.<kind>(...). Same kind and key already declared: unchanged. Same key with another type or version: fails and names the line. --kind takes mcpServer or mcp_server. --skip-verify is accepted (hidden) for uip parity.
list [--kind] Prints the declarations. One the parser can't read (non-literal value, positional arg, unknown keyword) is a warning with its line and is left out.
remove [name] [--kind] [--folder-path] [--id] Removes the one declaration matching what is passed (name exactly). No match is an error; several matches (same name in two folders, a queue and an entity with one name) are listed with their lines and nothing is removed. A declaration sharing its line with other code or nested in an expression is refused, so a neighbour is never cut. Code using the attribute is left to you. Not in uip; the Python-side editor of the file.
generate-bindings Writes bindings.json: one entry per declaration, after the hand-written entries. Same kind and key replaced; entries stamped metadata.Source: "code" by an earlier run regenerated; everything else kept. Named for what it does, since uip has no such verb (it derives bindings in memory; the Python project model reads the file from disk in push, debug and eval).

All take --project-path and --format json (also honour the global uipath --format json); JSON on stdout, warnings on stderr.

Not in this PR

  • The uip side: forwarding resources to uipath for Python projects.

https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m


Generated by Claude Code

…resources.py (PC-5725)

Coded agents and Python functions declare the platform resources they use in
one file, uipath_resources.py, and bindings.json is derived from it instead
of written by hand.

- uipath.resources (uipath-platform): `resource.<kind>(...)` returns a frozen
  data handle (kind, name, folder_path, type; a connection's id and connector;
  a skill bundle's version). One method per kind the SDK can override, taken
  from the overwrite models in _bindings.py; a test keeps them in step.
- `uipath resources add | list | remove | bindings`: edits the file as text
  with `ast`, literal values only, offline. `add` creates the file with the
  import and the ProjectResources class when missing, re-adding the same kind
  and key leaves the file unchanged, a different type fails and names the
  line. `bindings` writes bindings.json over the hand-written entries (same
  kind and key replaced, entries stamped Source "code" regenerated).
- `uipath pack` and `uipath push` regenerate bindings.json first when the
  project has a uipath_resources.py; a project without one packs as before.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
Copilot AI balanced review requested due to automatic review settings December 2, 2026 10:35
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-runtime test:uipath-integrations labels Dec 2, 2026
uip has no remove on purpose: a declaration is one line the user deletes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved editing and binding defects can delete unrelated declarations, produce invalid Python, and silently create incorrect or missing resource bindings.

5 open issues
What changed in this PR

Adds declaration-driven resource bindings to the Python SDK and CLI, making uipath_resources.py the source for generated bindings.

Changes:

  • Introduces typed resource handles and offline resource-management commands.
  • Regenerates bindings before pack and push while preserving unrelated hand-written entries.
  • Adds tests, documentation, and package version updates.
File Description
README.md Documents resource declarations and commands.
packages/​uipath/​tests/​cli/​test_resources.py Tests commands and packaging integration.
packages/​uipath/​tests/​cli/​test_resource_declarations.py Tests parsing, editing, and binding generation.
packages/​uipath/​src/​uipath/​_cli/​cli_resources.py Implements resource-management commands.
packages/​uipath/​src/​uipath/​_cli/​cli_push.py Regenerates bindings before push.
packages/​uipath/​src/​uipath/​_cli/​cli_pack.py Regenerates bindings before packaging.
packages/​uipath/​src/​uipath/​_cli/​_declarations/​_project.py Locates and accesses declaration files.
packages/​uipath/​src/​uipath/​_cli/​_declarations/​_parser.py Parses declarations without importing them.
packages/​uipath/​src/​uipath/​_cli/​_declarations/​_model.py Defines declaration identities and kind resolution.
packages/​uipath/​src/​uipath/​_cli/​_declarations/​_editor.py Adds and removes declarations as text.
packages/​uipath/​src/​uipath/​_cli/​_declarations/​_bindings.py Generates and merges bindings.
packages/​uipath/​src/​uipath/​_cli/​_declarations/​__init__.py Documents declaration-processing modules.
packages/​uipath/​src/​uipath/​_cli/​__init__.py Registers the lazy-loaded command group.
packages/​uipath/​README.md Documents the declaration workflow.
packages/​uipath/​pyproject.toml Updates SDK version and platform dependency.
packages/​uipath-platform/​tests/​resources/​test_handles.py Tests handles and factory coverage.
packages/​uipath-platform/​src/​uipath/​resources/​py.typed Marks the module as typed.
packages/​uipath-platform/​src/​uipath/​resources/​_handles.py Implements frozen handles and resource factories.
packages/​uipath-platform/​src/​uipath/​resources/​__init__.py Exports the public resource API.
packages/​uipath-platform/​pyproject.toml Bumps the platform package version.
packages/​uipath-platform/​CLAUDE.md Documents the new module’s location and purpose.

Review effort: Balanced

Comment on lines +131 to +144
derived: dict[str, dict[str, Any]] = {}
declared_types: dict[str, str | None] = {}
diagnostics: list[str] = []
for declaration in declarations:
identity = declaration.identity
if identity in derived:
if declared_types[identity] != declaration.type:
diagnostics.append(
f'{declaration.kind} "{declaration.key}" is declared more than once '
f"with different types; the first declaration is used."
)
continue
derived[identity] = binding_entry(declaration)
declared_types[identity] = declaration.type
Comment on lines +194 to +196
line = render_declaration(attribute, declaration, info.indent) + _line_end(
lines, body_end - 1
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the one-line class case is now rejected and the file stays unchanged. a class header spanning several lines with an inline body still gets an invalid edit, tracked here: #2037 (comment)

Comment on lines +75 to +77
if self.kind == CONNECTION_KIND:
return self.id or ""
return binding_key(self.name, self.folder_path or None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bare-name key is fixed on the current head, also with a folder option. existing entities still fail on push because the default . folder goes to an exact folder lookup instead of a tenant-wide search, tracked here: #2037 (comment)

Comment on lines +277 to +285
statements: dict[int, tuple[str | None, tuple[int, int]]] = {}
for node in ast.walk(tree):
if isinstance(node, ast.stmt):
value = _statement_value(node)
if isinstance(value, ast.Call) and _declared_method(value):
statements[id(value)] = (
_bound_name(node),
(node.lineno, node.end_lineno or node.lineno),
)
)

if kind == CONNECTION_KIND:
if not connection_id or not connector:
…ides

A resource declared after the last pack or push had no override in a debug
or eval run, because Studio Web keys the overrides by the bindings it is
sent and bindings.json was stale. Same derivation as pack and push.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
An entity is found by name across the tenant and the solution never creates
one, so a folder on its declaration has no meaning and uip drops it. The
handle takes no folder_path, the parser reports one as an argument an entity
does not take, and add warns and ignores --folder-path for an entity.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
… findings

- the verb is generate-bindings, named after what it does (uip has no
  such verb to match)
- two skill bundles pinned to different versions are reported, as two
  assets with different types are
- a class whose body sits on the class line is refused instead of edited
  into a second class
- a blank --connector is refused before anything is written

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
Removes the one declaration that matches the name and whatever else is
passed (--kind, --folder-path, --id). No match is an error; several matches
are listed with their lines and nothing is removed. A declaration that
shares its line with other code or sits inside a larger expression is left
to the user, so no neighbouring statement is ever cut.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
Inside the debug and eval execution loop the console stream is not the
command's to write to: on Windows click refuses it with a bad file
descriptor. Those two callers now report through logging, as they do for
the rest of that path, and an error is raised for their own handler.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
@vldcmp-uipath vldcmp-uipath changed the title feat(cli): add uipath resources and derive bindings.json from uipath_resources.py (PC-5725) feat(cli): add uipath resources and derive bindings.json from uipath_resources.py Dec 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-integrations cross-tests are FAILING 🚨

Your changes may break one or more integrations in uipath-integrations-python:

  • uipath-openai-agents
  • uipath-google-adk
  • uipath-agent-framework
  • uipath-llamaindex
  • uipath-pydantic-ai

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

metadata["SubType"] = declaration.type
metadata["Source"] = DERIVED_BINDING_SOURCE
return {
"resource": declaration.kind,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the shared solution packager derives bindings again from uipath_resources.py with its own Python grammar that only knows six kinds, so a skill bundle added with uipath resources add lands in this bindings.json but is silently dropped from the solution contribution and the staged package. let s align the supported kinds in both packagers before exposing them here.

# The bindings pushed (and the resources imported) are derived from uipath_resources.py.
from .cli_resources import regenerate_bindings

regenerate_bindings(root)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uipath push child regenerates child/bindings.json here, but create_resources then opens bindings.json relative to the working directory, so the push fails with FileNotFoundError right after the upload. let s generate and import the bindings from the same project root.

return _connection_entry(declaration)
value: dict[str, Any] = {
"name": _value(declaration.name, "Name"),
"folderPath": _value(declaration.folder_path or _PROJECT_FOLDER, "Folder Path"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bare entity key now matches the runtime (#2037 (comment)), but on push the default . folder goes to the exact folder lookup and the Resource Catalog is never searched, so an existing tenant entity fails with "kind entity is not supported". let s resolve existing entities tenant-wide by name.

diagnostics: list[str] = []
for declaration in declarations:
identity = declaration.identity
details = (declaration.type, declaration.version)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asset(name="Review.Shared") and asset(name="Review", folder_path="Shared") get the same key, so the CLI declines the second one as already declared and the SDK applies the same override to both addresses. let s reject distinct declarations that collide instead of treating them as a repeat.

if sync is None:
return
if not via_logger:
_report_sync(sync, quiet=not sync.changed)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a previously generated declaration becomes unreadable (for example its name turns into a variable), pack strips its binding, warns and still produces a package without it. let s fail pack before replacing the previous bindings.json when a declaration cannot be read.

with open(path, encoding="utf-8") as f:
changed = f.read() != content
if changed:
with open(path, "w", encoding="utf-8") as f:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this rewrites bindings.json in place, so a write that fails midway (disk full) leaves truncated JSON and every later generation fails to read it, including projects with hand-written bindings. let s write to a temp file next to it and os.replace the old one.

)
start, end = target.statement_lines
lines = source.split("\n")
del lines[start - 1 : end]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the only declaration under an if in ProjectResources succeeds but leaves an empty suite, and the file no longer compiles (IndentationError). let s either refuse that removal or keep a valid body there, like the pass inserted for an empty class.

indent=indent,
taken=frozenset(taken),
only_placeholder=only_placeholder,
inline=first.lineno == statement.lineno,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the one-line class case is fixed (#2037 (comment)), but a class ProjectResources(...) header spanning several lines and ending in ): existing = ... is not detected as inline, because this compares against the first header line, and add still writes invalid Python (unmatched )). let s reject inline suites when the class header spans multiple lines too.

indent = lines[first.lineno - 1][: first.col_offset]
taken: set[str] = set()
for member in statement.body:
bound = _bound_name(member)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_bound_name skips chained assignments, so with review = alias = 42 in the class, adding a resource named Review appends a second review that overwrites the 42. let s take every existing class attribute, including each chained target, into account when picking the new name.

BindingsFileError: The existing bindings file cannot be read.
"""
declarations = read_declarations_file(root)
if not declarations.exists:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after uipath_resources.py is deleted this returns early, so the next pack still ships the bindings marked as generated from it. let s keep the hand-written entries and drop the stale generated ones when the declarations file is absent.

for field_name in ("type", "version"):
wanted = getattr(declaration, field_name)
current = getattr(saved.declaration, field_name)
if wanted is not None and current != wanted:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an explicit --version latest against a saved version="7" is reported as already declared and the pin silently stays in place. let s treat an explicit latest as a conflicting version too.

]
version = (base or {}).get("version")
return DerivedBindings(
document={

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regeneration rebuilds the document from version and resources only, so top-level fields such as $schema, which the existing bindings reader and pack preserve, are dropped. let s keep the base document and replace only its generated entries.

@@ -0,0 +1,916 @@
# type: ignore

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this disables type checking for the whole test module. let s remove it and scope any ignore that is still needed to its line.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants