Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 21:00 UTC
feat(connected-accounts-py): surface account_type + per-user ACL on SHARED connections (#3401)
## Summary **Python mirror of [#3392](https://github.com/ComposioHQ/composio/pull/3392) (TypeScript SDK).** Same Apollo-side Shared Accounts feature shipped across four Hermes PRs ([#9860](https://github.com/ComposioHQ/hermes/pull/9860), [#9882](https://github.com/ComposioHQ/hermes/pull/9882), [#9887](https://github.com/ComposioHQ/hermes/pull/9887) internal-only, [#9902](https://github.com/ComposioHQ/hermes/pull/9902)), now exposed through `composio.*` Python SDK wrappers. `composio-client` bumped from `1.37.0` → `1.38.0` ([composio-base-py#66](https://github.com/ComposioHQ/composio-base-py/pull/66), merged 2026-05-11). The regenerated client already carries `account_type` + `acl_config_for_shared` on `LinkCreateParams`, `ConnectedAccountPatchParams`, `SessionLinkParams`, the retrieve response, and the list response item — so the Python SDK consumes generated types directly without local body-shape declarations (no Python equivalent of the TS forward-compat casts needed). ## Implemented ### `composio/core/models/connected_accounts.py` - **`link()`** — new optional kwargs `account_type: Literal['PRIVATE','SHARED']` and `acl_config_for_shared: link_create_params.ACLConfigForShared`. Default behaviour (both omitted) creates a PRIVATE connection exactly as before. - **New `update_acl(nanoid, *, allow_all_users, allowed_user_ids, not_allowed_user_ids)`** — wraps `PATCH /connected_accounts/{id}` with the same semantics as the TS sibling. PATCH semantics: omit a param to leave unchanged; pass `[]` to clear an allow/deny list. Raises `ValidationError` if all three are `None`. Returns the `ConnectedAccountPatchResponse` (`{id, status, success}`) — to read the updated ACL block, call `get(nanoid)` after. - Both methods wrap `BadRequestError` whose message contains `"acl_config_for_shared is only valid on SHARED"` and re-raise as `ComposioAclOnlyForSharedError`. Verified against Apollo's `apps/apollo/src/lib/connected_accounts/createConnectedAccount.ts` in hermes#9902 — same substring match the TS SDK uses. ### `composio/core/models/tool_router_session.py` - **`authorize()`** — new optional kwargs `account_type` and `acl_config_for_shared`, plus the same `ComposioAclOnlyForSharedError` mapping. So a SHARED connection with an ACL can be created in one call from inside a tool-router session. ### `composio/exceptions.py` Three new typed exception classes under `ConnectedAccountError`: | Class | Status | Wired? | |---|---|---| | `ComposioAclOnlyForSharedError` | 400 | ✅ Wrapped at `link()`, `update_acl()`, `authorize()` | | `ComposioSharedAccessDeniedError` | 403 | ⚠️ Exported, not yet wrapped — wraps when `Tools.execute()` error mapping lands (separate PR) | | `ComposioSharedConnectionNotAccessibleError` | 400 | ⚠️ Exported, not yet wrapped — wraps when `tool_router_session.create()/patch()` session-validator error mapping lands (separate PR) | The two non-wired classes are exported now so the public API surface is stable; doctstrings explicitly disclose when they'll start being raised. ### `composio/client/types.py` - Re-exports `link_create_params` (the generated client's TypedDicts for link create payloads, including `ACLConfigForShared`). ### Tests (`tests/test_connected_accounts.py`) New `TestConnectedAccountsAcl` class with 12 tests mirroring the TS PR's coverage: - **link() ACL forwarding (4)**: forwards `account_type` + nested `acl_config_for_shared`; omits ACL when not provided; forwards only fields the caller supplied; preserves explicit empty lists. - **link() error mapping (2)**: maps `AclOnlyForShared` 400 to `ComposioAclOnlyForSharedError`; rethrows unrelated `BadRequestError` unchanged. - **update_acl() body construction (3)**: serializes nested body; omits absent fields (PATCH semantics); preserves empty array. - **update_acl() validation + mapping (3)**: rejects all-`None` params; maps `AclOnlyForShared` 400; rethrows unrelated errors. ### Version Package version bumped `0.13.0` → `0.14.0` (minor — purely additive surface, no breaking changes). ## Verified - ✅ `uv run nox -s chk` — ruff + mypy clean across `composio/`, `providers/`, `tests/`, `scripts/` - ✅ `uv run pytest tests/test_connected_accounts.py` — 49/49 pass (37 pre-existing + 12 new) - ✅ `uv run pytest tests/` — 635 pass / 31 skipped (1 pre-existing failure in `test_provider.py` is `composio_langchain` not installed in env — unrelated) ## Not implemented (deliberate scope cuts — match TS PR) | Skipped | Why | Where it lands | |---|---|---| | **Wrapping `ComposioSharedAccessDeniedError`** | Throw site is in `Tools.execute()` and direct-execute paths — outside this PR's surface. | Follow-up PR scoped to execute error mapping. | | **Wrapping `ComposioSharedConnectionNotAccessibleError`** | Throw site is in `tool_router_session.create()`/`patch()` session-validator. | Follow-up PR scoped to session error mapping. | | **`account_type` / `acl_config_for_shared` on `initiate()` (legacy create)** | `initiate()` is the retiring legacy path. Customers should use `link()` for SHARED. | N/A — deprecated surface. | | **Internal link-session GET (hermes#9887)** | Internal route, not in public OpenAPI spec; consumed by dashboard UI, not the SDK. | N/A. | ## Test plan - [x] `uv run nox -s chk` clean - [x] `uv run pytest tests/test_connected_accounts.py` 49/49 pass - [x] `uv run pytest tests/` 635 pass / 31 skipped (langchain-dep failure is pre-existing env issue) - [ ] Manual smoke after publish: `pip install composio==0.14.0` → create SHARED → `update_acl(allow_all_users=True, not_allowed_user_ids=['user_bob'])` → verify `get()` returns `acl_config_for_shared` block for creator, omits it for non-creator. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
No changes.