[chore] Extract provider connections into a shared connections domain#4737
[chore] Extract provider connections into a shared connections domain#4737junaway wants to merge 1 commit into
Conversation
…ions domain Move the provider connection out of /tools into a shared connections domain (rename tool_connections -> gateway_connections) so triggers can reuse it. The /tools/connections HTTP contract is unchanged. - New core/connections (ConnectionsService + ConnectionsGatewayInterface adapter port) and dbs/postgres/connections; ToolsService delegates connection mgmt. - Composio auth verbs move behind ComposioConnectionsAdapter; connections never imports tools. - revoke stays local-only (is_valid=False); cross-domain effect via the shared row; usage() reports consumers. - Migration authored once in core_oss (oss000000002), runs in both editions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
⚠️ Not ready to approve
The PR removes tools connection DTOs/interfaces but leaves the legacy dbs.postgres.tools.dao import path broken (ImportError risk) and the new acceptance tests don’t currently assert DELETE success, so correctness and test signal need tightening before approval.
Pull request overview
This PR extracts provider connection management out of the /tools domain into a new shared, routerless core.connections domain backed by the renamed gateway_connections table, so other domains (e.g. triggers) can reuse the same connection records while keeping the public /tools/connections HTTP contract unchanged.
Changes:
- Introduces a new
core.connectionsdomain (DTOs, service, interfaces, registry) plus a Postgres DAO/DBE mapping forgateway_connections. - Splits Composio responsibilities: tool catalog/execution remain in
ComposioToolsAdapter, while connection auth verbs move toComposioConnectionsAdapter. - Adds OSS + EE acceptance tests to pin
/tools/connectionsbehavior and adds a migration renamingtool_connections→gateway_connections.
File summaries
| File | Description |
|---|---|
| api/oss/tests/pytest/unit/models/test_lifecycle_conventions.py | Updates lifecycle conventions list to reference connections DBEs. |
| api/oss/tests/pytest/acceptance/tools/test_tools_connections.py | New OSS acceptance tests for /tools/connections contract. |
| api/oss/src/dbs/postgres/connections/mappings.py | Maps between connection DTOs and gateway_connections DBE. |
| api/oss/src/dbs/postgres/connections/dbes.py | New SQLAlchemy model for gateway_connections. |
| api/oss/src/dbs/postgres/connections/dao.py | New async DAO implementing connection CRUD/query for Postgres. |
| api/oss/src/dbs/postgres/connections/init.py | Package init for new connections DB layer. |
| api/oss/src/core/tools/service.py | Refactors tools service to delegate connection management to ConnectionsService. |
| api/oss/src/core/tools/providers/composio/adapter.py | Removes connection-auth verbs from tools adapter; keeps catalog + execution. |
| api/oss/src/core/tools/interfaces.py | Removes ToolsDAOInterface, leaving only the tools gateway port. |
| api/oss/src/core/tools/dtos.py | Removes tool-connection DTOs and keeps only catalog/call/execution DTOs. |
| api/oss/src/core/connections/utils.py | Renames state helper module docstring for generic connections callbacks. |
| api/oss/src/core/connections/service.py | New service owning connection lifecycle + provider auth orchestration. |
| api/oss/src/core/connections/registry.py | New provider-keyed registry for connection adapters. |
| api/oss/src/core/connections/providers/composio/adapter.py | New Composio adapter for connection auth verbs (initiate/status/refresh/revoke). |
| api/oss/src/core/connections/providers/composio/init.py | Lazy import wrapper for Composio connections adapter. |
| api/oss/src/core/connections/providers/init.py | Package init for connections providers. |
| api/oss/src/core/connections/interfaces.py | Defines DAO + gateway interfaces for the connections domain. |
| api/oss/src/core/connections/exceptions.py | Adds connections-domain exception types. |
| api/oss/src/core/connections/dtos.py | Adds connections-domain DTOs (Connection, create/request/response, usage). |
| api/oss/src/core/connections/init.py | Package init for new connections domain. |
| api/oss/src/apis/fastapi/tools/router.py | Switches OAuth state decode helper import to the connections domain. |
| api/oss/src/apis/fastapi/tools/models.py | Updates /tools/connections request/response models to use Connection* DTOs. |
| api/oss/databases/postgres/migrations/core_oss/versions/oss000000002_rename_tool_connections_to_gateway_connections.py | Adds migration renaming table + constraint/index names. |
| api/entrypoints/routers.py | Wires ConnectionsDAO/Service + Composio connections adapter; updates ToolsService DI; closes new adapters on shutdown. |
| api/ee/tests/pytest/acceptance/tools/test_tools_connections.py | New EE acceptance tests mirroring OSS /tools/connections contract with EE auth gating. |
| api/ee/tests/pytest/acceptance/tools/init.py | Package init for EE tools acceptance tests. |
Copilot's findings
Comments suppressed due to low confidence (1)
api/oss/src/core/tools/dtos.py:15
ToolConnection/ToolConnectionCreateDTOs were removed from this module, butoss.src.dbs.postgres.tools.daostill imports them. That makes the legacy DAO module fail to import, which can break any remaining callers or tooling that still touches it.
from enum import Enum
from typing import Any, Dict, List, Optional
from agenta.sdk.models.workflows import JsonSchemas
from pydantic import BaseModel
from oss.src.core.shared.dtos import (
Identifier,
Json,
Status,
)
# ---------------------------------------------------------------------------
# Tool Enums
# ---------------------------------------------------------------------------
- Files reviewed: 22/26 changed files
- Comments generated: 5
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from abc import ABC, abstractmethod | ||
| from typing import List, Optional, Tuple | ||
|
|
||
| from oss.src.core.tools.dtos import ( | ||
| ToolCatalogAction, | ||
| ToolCatalogActionDetails, | ||
| ToolCatalogIntegration, | ||
| ToolCatalogProvider, | ||
| ToolExecutionRequest, | ||
| ToolExecutionResponse, | ||
| ) | ||
|
|
||
|
|
||
| class ToolsGatewayInterface(ABC): | ||
| """Port for external tool providers (Composio, Agenta, etc.). | ||
|
|
||
| Tool-specific verbs only — catalog browse and execution. Connection auth | ||
| verbs live behind ``ConnectionsGatewayInterface`` in the connections domain. | ||
| """ | ||
|
|
|
|
||
| from pydantic import BaseModel | ||
|
|
| provider_connection_id: str | ||
| redirect_url: Optional[str] = None | ||
| connection_data: Dict[str, Any] = {} |
| assert revoke.json()["connection"]["flags"]["is_valid"] is False | ||
|
|
||
| authed_api("DELETE", f"/tools/connections/{connection_id}") |
| revoke = connections_api("POST", f"/tools/connections/{connection_id}/revoke") | ||
| assert revoke.status_code == 200, revoke.text | ||
| assert revoke.json()["connection"]["flags"]["is_valid"] is False | ||
|
|
||
| connections_api("DELETE", f"/tools/connections/{connection_id}") |
Context
Provider connections (the OAuth/API-key links to Composio) lived inside the tools domain. Triggers need the same connections, so leaving them in tools would force the new triggers code to import from tools and entangle the two domains. We extract connections into their own domain first, so both tools and triggers depend on it one way.
Changes
Adds a routerless
connectionsdomain that owns the shared connection rows and the provider auth verbs:core/connections/—ConnectionsService(project-scoped, returns domain DTOs) andConnectionsGatewayInterface(the provider-keyed adapter port: initiate / get-status / refresh / revoke), implemented byComposioConnectionsAdapter.dbs/postgres/connections/—ConnectionDBEbacked by thegateway_connectionstable, plus DAO and mappings.tool_connectionstogateway_connections. It lands in the sharedcore_osschain so it runs in both editions.The tools domain no longer owns connections.
ToolsServicenow delegates toConnectionsService, and the auth verbs were removed from the tools interface and adapter. Nothing inconnectionsimports fromtools; the dependency points one way.The
/tools/connectionsHTTP view is unchanged (itsoperation_idstaysquery_tool_connections, part of the frozen OpenAPI contract). It now reads the samegateway_connectionsrows through the new service.Tests / notes