The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(connectors): gateway contracts for named connector accounts
Siddharth Balyan4834cf0d9723
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex e9eca2dbdd0..b0842b8488a 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -1043,6 +1043,7 @@ export interface ConnectionOperationTarget {discovery_error?: string | nullconnect_url?: string | nullconnection_id?: string | null+ alias?: string | nullattempt?: string | nullrequired_env?: ConnectionTargetEnvField[] | nulltools?: string[] | null@@ -1149,6 +1150,7 @@ export interface ConnectorsConnectParams {owner: SessionOwner | AccountOwnerconnectors: string[]reconnect?: boolean+ alias?: string | null}/** ``methods_connectors._reissue`` / ``managed._off_desktop_result``: the operation the connect opened; ``status``/``note`` ride along from the tool result. */export interface ConnectorsConnectResult {@@ -1226,6 +1228,11 @@ export interface ConnectorAccountsRemoveResult {connector: stringstatus: 'removed'}+export interface ConnectorAccountsRenameParams {+ profile?: string | null+ connection_id: string+ alias: string+}export interface ConnectorPolicyGetResult {layers: ConnectorPolicyLayer[]effective: ConnectorPolicyEffectiveUnrestricted | ConnectorPolicyEffectiveDenyAll | ConnectorPolicyEffectiveAllow | ConnectorPolicyEffectiveDeny@@ -4997,7 +5004,7 @@ export interface PetHatchProgressPayload {}/** ``change_watcher._CHANGE_WATCHES`` payload fn — ``{}`` for every watch except pet.changed. */export type ChangeSignalPayload = Record<string, unknown>-export type ConnectorErrorReason = 'INVALID_PARAMS' | 'NOT_OWNER' | 'UNSUPPORTED_RUNTIME' | 'CONNECTOR_REQUEST_FAILED' | 'INVALID_CONNECTOR_RESPONSE' | 'UNKNOWN_TARGET' | 'LINK_STILL_VALID' | 'REISSUE_REFUSED' | 'UNKNOWN_OPERATION' | 'INVALID_ANSWER' | 'NEEDS_NOUS_AUTH' | 'CONNECTOR_NOT_FOUND' | 'TOOLS_UNAVAILABLE' | 'CONNECTORS_UNAVAILABLE' | 'CATALOG_UNAVAILABLE' | 'ACCOUNTS_UNAVAILABLE' | 'CONNECTION_NOT_FOUND' | 'POLICY_UNAVAILABLE' | 'POLICY_CONFLICT' | 'FORBIDDEN_SCOPE' | 'ORG_REQUIRED' | 'ORG_ACCESS_DENIED' | 'INVALID_POLICY'+export type ConnectorErrorReason = 'INVALID_PARAMS' | 'NOT_OWNER' | 'UNSUPPORTED_RUNTIME' | 'CONNECTOR_REQUEST_FAILED' | 'INVALID_CONNECTOR_RESPONSE' | 'UNKNOWN_TARGET' | 'LINK_STILL_VALID' | 'REISSUE_REFUSED' | 'UNKNOWN_OPERATION' | 'INVALID_ANSWER' | 'NEEDS_NOUS_AUTH' | 'CONNECTOR_NOT_FOUND' | 'TOOLS_UNAVAILABLE' | 'CONNECTORS_UNAVAILABLE' | 'CATALOG_UNAVAILABLE' | 'ACCOUNTS_UNAVAILABLE' | 'CONNECTION_NOT_FOUND' | 'POLICY_UNAVAILABLE' | 'POLICY_CONFLICT' | 'FORBIDDEN_SCOPE' | 'ORG_REQUIRED' | 'ORG_ACCESS_DENIED' | 'INVALID_POLICY' | 'ALIAS_TAKEN'// ── Client→server methods ──export interface RpcMethods {@@ -5067,6 +5074,8 @@ export interface RpcMethods {'connectors.accounts': { params: ConnectorAccountsParams; result: ConnectorAccountsResult }/** Remove one hosted connector account owned by the scoped member. */'connectors.accounts.remove': { params: ConnectorAccountsRemoveParams; result: ConnectorAccountsRemoveResult }+ /** Name or rename one hosted connector account owned by the scoped member. */+ 'connectors.accounts.rename': { params: ConnectorAccountsRenameParams; result: ConnectorAccountRow }/** The hosted connector catalog available to the scoped member. */'connectors.catalog': { params: ProfileParams; result: ConnectorsCatalogResult }/** Start or re-initiate authorization for named connectors on a session or account operation. */@@ -5547,6 +5556,7 @@ export const RPC_METHODS = ['connection.respond','connectors.accounts','connectors.accounts.remove',+ 'connectors.accounts.rename','connectors.catalog','connectors.connect','connectors.list',diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex e9a670f8f31..2be45684163 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -600,6 +600,24 @@}}},+ {+ "name": "connectors.accounts.rename",+ "summary": "Name or rename one hosted connector account owned by the scoped member.",+ "params": [+ {+ "name": "params",+ "schema": {+ "$ref": "#/components/schemas/ConnectorAccountsRenameParams"+ }+ }+ ],+ "result": {+ "name": "result",+ "schema": {+ "$ref": "#/components/schemas/ConnectorAccountRow"+ }+ }+ },{"name": "connectors.catalog","summary": "The hosted connector catalog available to the scoped member.",@@ -9480,6 +9498,18 @@"default": null,"title": "Connection Id"},+ "alias": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Alias"+ },"attempt": {"anyOf": [{@@ -10298,6 +10328,39 @@"title": "ConnectorAccountsRemoveResult","type": "object"},+ "ConnectorAccountsRenameParams": {+ "additionalProperties": false,+ "properties": {+ "profile": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Profile"+ },+ "connection_id": {+ "minLength": 1,+ "title": "Connection Id",+ "type": "string"+ },+ "alias": {+ "pattern": "^[a-z0-9][a-z0-9-]{0,31}$",+ "title": "Alias",+ "type": "string"+ }+ },+ "required": [+ "connection_id",+ "alias"+ ],+ "title": "ConnectorAccountsRenameParams",+ "type": "object"+ },"ConnectorAccountsResult": {"additionalProperties": false,"properties": {@@ -11184,6 +11247,19 @@"default": false,"title": "Reconnect","type": "boolean"+ },+ "alias": {+ "anyOf": [+ {+ "pattern": "^[a-z0-9][a-z0-9-]{0,31}$",+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Alias"}},"required": [@@ -40043,7 +40119,8 @@"FORBIDDEN_SCOPE","ORG_REQUIRED","ORG_ACCESS_DENIED",- "INVALID_POLICY"+ "INVALID_POLICY",+ "ALIAS_TAKEN"]}}diff --git a/tui_gateway/contracts/connectors.py b/tui_gateway/contracts/connectors.pyindex 3f326eee487..2f56e417e9d 100644--- a/tui_gateway/contracts/connectors.py+++ b/tui_gateway/contracts/connectors.py@@ -4,7 +4,7 @@ from __future__ import annotationsfrom typing import Annotated, Literal-from pydantic import Field+from pydantic import Field, model_validatorfrom .base import Result, WireEnumfrom .common import ConnectorOwner, ProfileParams@@ -12,6 +12,8 @@ from .connectors_operation import ConnectionOperationStatusfrom .registry import methodConnectorSlug = Annotated[str, Field(pattern=r"^[a-z0-9][a-z0-9_-]*$")]+# The name of one hosted account of a connector (the gateway's account alias format).+ConnectorAlias = Annotated[str, Field(pattern=r"^[a-z0-9][a-z0-9-]{0,31}$")]class ConnectorErrorReason(WireEnum):@@ -38,6 +40,7 @@ class ConnectorErrorReason(WireEnum):org_required = "ORG_REQUIRED"org_access_denied = "ORG_ACCESS_DENIED"invalid_policy = "INVALID_POLICY"+ alias_taken = "ALIAS_TAKEN"class ConnectorsListParams(ProfileParams):@@ -70,6 +73,14 @@ class ConnectorsConnectParams(ProfileParams):owner: ConnectorOwnerconnectors: list[ConnectorSlug] = Field(min_length=1)reconnect: bool = False+ # Connects (or, with ``reconnect``, repairs) the account of that name; one connector per call.+ alias: ConnectorAlias | None = None++ @model_validator(mode="after")+ def _one_connector_per_alias(self):+ if self.alias is not None and len(self.connectors) != 1:+ raise ValueError("alias names one account, so it takes exactly one connector")+ return selfclass ConnectorsConnectResult(ConnectionOperationStatus):@@ -217,6 +228,19 @@ method()+class ConnectorAccountsRenameParams(ProfileParams):+ connection_id: str = Field(min_length=1)+ alias: ConnectorAlias+++method(+ "connectors.accounts.rename",+ params=ConnectorAccountsRenameParams,+ result=ConnectorAccountRow,+ doc="Name or rename one hosted connector account owned by the scoped member.",+)++class ConnectorPolicyLayerKind(WireEnum):org = "org"role = "role"diff --git a/tui_gateway/contracts/connectors_operation.py b/tui_gateway/contracts/connectors_operation.pyindex eb526dfd4bb..98a2f9d86d3 100644--- a/tui_gateway/contracts/connectors_operation.py+++ b/tui_gateway/contracts/connectors_operation.py@@ -135,6 +135,8 @@ class ConnectionOperationTarget(Payload):connect_url: str | None = None# The vendor account a managed mint created or observed; never the desktop transport's id.connection_id: str | None = None+ # The name of the one hosted account this row connects or repairs.+ alias: str | None = Noneattempt: str | None = None# Present only on an MCP install that is waiting for credentials.required_env: list[ConnectionTargetEnvField] | None = Nonediff --git a/tui_gateway/methods_connectors.py b/tui_gateway/methods_connectors.pyindex ab583a251d6..2409a6713fb 100644--- a/tui_gateway/methods_connectors.py+++ b/tui_gateway/methods_connectors.py@@ -194,7 +194,8 @@ def _account_connector_connect(rid, request):action = "reconnect" if request.reconnect else "connect"try:- start = account.find_or_start_operation(request.connectors, action=action, profile_home=_account_home(request))+ start = account.find_or_start_operation(+ request.connectors, action=action, profile_home=_account_home(request), alias=request.alias)if not start.started:from tools.connectors.contract import TargetStatediff --git a/tui_gateway/methods_connectors_account.py b/tui_gateway/methods_connectors_account.pyindex 7094de64fbd..f9858b6ee0c 100644--- a/tui_gateway/methods_connectors_account.py+++ b/tui_gateway/methods_connectors_account.py@@ -1,6 +1,7 @@from tui_gateway.contracts.connectors import (ConnectorAccountsParams,ConnectorAccountsRemoveParams,+ ConnectorAccountsRenameParams,ConnectorErrorReason,ConnectorPolicySetParams,ConnectorToolsParams,@@ -100,7 +101,14 @@ def _(rid, request):accounts = PortalConnectorClient().list_accounts()rows = [account for account in accounts if request.connector is None or account["connector"] == request.connector]- result = ConnectorAccountsResult(accounts=[ConnectorAccountRow(+ result = ConnectorAccountsResult(accounts=[_account_row(account) for account in rows])+ return _ok(rid, result.model_dump(mode="json"))+++def _account_row(account):+ from tui_gateway.contracts.connectors import ConnectorAccountRow++ return ConnectorAccountRow(connection_id=account["connectionId"],connector=account["connector"],status=account["status"],@@ -110,8 +118,44 @@ def _(rid, request):active=account["active"],created_at=account["createdAt"],updated_at=account["updatedAt"],- ) for account in rows])- return _ok(rid, result.model_dump(mode="json"))+ )+++@method("connectors.accounts.rename")+@_profile_scoped+@_account_method(+ ConnectorAccountsRenameParams,+ invalid="connection_id and a valid alias are required.",+ unavailable=ConnectorErrorReason.accounts_unavailable,+ unavailable_message="Connector accounts are unavailable.",+)+def _(rid, request):+ from tools.connectors.gateway.errors import (+ GatewayAuthError,+ GatewayUnavailable,+ IdempotencyConflict,+ ToolGatewayError,+ )+ from tools.connectors.portal.client import PortalConnectorClient+ from tui_gateway.contracts.connectors import ConnectorErrorReason++ try:+ account = PortalConnectorClient().rename_account(request.connection_id, request.alias)+ except IdempotencyConflict:+ return _connector_rpc_error(rid, 4090, ConnectorErrorReason.alias_taken, "That name is already used.")+ except GatewayUnavailable as exc:+ if exc.code == "connection_not_found":+ return _connector_rpc_error(rid, 4041, ConnectorErrorReason.connection_not_found, "Connector account not found.")+ return _connector_rpc_error(rid, 5034, ConnectorErrorReason.accounts_unavailable, "Connector accounts are unavailable.")+ except GatewayAuthError:+ raise+ except ToolGatewayError as exc:+ if exc.code == "org_required":+ raise+ if exc.status == 400:+ return _connector_rpc_error(rid, 4000, ConnectorErrorReason.invalid_params, "That name is invalid.")+ return _connector_rpc_error(rid, 5034, ConnectorErrorReason.accounts_unavailable, "Connector accounts are unavailable.")+ return _ok(rid, _account_row(account).model_dump(mode="json"))@method("connectors.accounts.remove")