Repository navigation
feat(cli): add uipath resources and derive bindings.json from uipath_resources.py - #2037
vldcmp-uipath wants to merge 8 commits into
Conversation
…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
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
There was a problem hiding this comment.
🟡 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
Duplicate skill bundles with different versions are not reported · New Adding a binding to an inline class creates a duplicate class · New Folder-qualified entity keys do not match SDK entity resolution · New Removing a shared-line declaration also deletes neighboring statements · New Reject whitespace-only connector values · New
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
| 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 |
| line = render_declaration(attribute, declaration, info.indent) + _line_end( | ||
| lines, body_end - 1 | ||
| ) |
There was a problem hiding this comment.
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)
| if self.kind == CONNECTION_KIND: | ||
| return self.id or "" | ||
| return binding_key(self.name, self.folder_path or None) |
There was a problem hiding this comment.
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)
| 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
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
|
🚨 Heads up:
|
🚨 Heads up:
|
| metadata["SubType"] = declaration.type | ||
| metadata["Source"] = DERIVED_BINDING_SOURCE | ||
| return { | ||
| "resource": declaration.kind, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
_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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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={ |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
this disables type checking for the whole test module. let s remove it and scope any ignore that is still needed to its line.




Python side of bindings unification. A coded agent or Python function declares the platform resources it uses in one file,
uipath_resources.py, andbindings.jsonis derived from it instead of written by hand. TheuipCLI will forwarduip codedagent resources/uip function resourceshere for Python projects, as it forwards the othercodedagentcommands (follow-up in UiPath/cli, after UiPath/cli#6337).Summary
uipath.resources(uipath-platform, new module in theuipathnamespace):from uipath.resources import resource;resource.<kind>(...)returns a frozen pydantic handle (kind, name, folder_path, plus a connection'sid/connector, a skill bundle'sversion,typefor 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 incommon/_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 withast, literal values only, never imports it, makes no requests.addandlisttake the same flags asuip <tool> resources, so forwarding is one to one.pack,push,debugandevalregeneratebindings.jsonfirst when the project has auipath_resources.py. A project without one behaves exactly as before. Pack then packs it ascontent/bindings_v2.jsonas 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
add <name> --kind <kind> [--folder-path] [--type]; connection:--id --connector; skill bundle:--versionuipath_resources.py(import +class ProjectResources) when missing, appendsattr = resource.<kind>(...). Same kind and key already declared: unchanged. Same key with another type or version: fails and names the line.--kindtakesmcpServerormcp_server.--skip-verifyis accepted (hidden) foruipparity.list [--kind]remove [name] [--kind] [--folder-path] [--id]uip; the Python-side editor of the file.generate-bindingsbindings.json: one entry per declaration, after the hand-written entries. Same kind and key replaced; entries stampedmetadata.Source: "code"by an earlier run regenerated; everything else kept. Named for what it does, sinceuiphas 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-pathand--format json(also honour the globaluipath --format json); JSON on stdout, warnings on stderr.Not in this PR
uipside: forwardingresourcestouipathfor Python projects.https://claude.ai/code/session_014t9fy7CGYG2vBLEfHwu12m
Generated by Claude Code