From 7d3de101a63d38d39eca83653aa9f210bfe7f287 Mon Sep 17 00:00:00 2001 From: angrybayblade Date: Thu, 17 Oct 2024 13:48:11 +0530 Subject: [PATCH] feat: add separate method for customer expected fields --- python/composio/tools/toolset.py | 36 ++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/python/composio/tools/toolset.py b/python/composio/tools/toolset.py index f12cf2e7c27..2d65cc1989b 100644 --- a/python/composio/tools/toolset.py +++ b/python/composio/tools/toolset.py @@ -26,7 +26,6 @@ ActionModel, AppAuthScheme, AppModel, - AuthSchemeField, ConnectedAccountModel, ConnectionParams, ConnectionRequestModel, @@ -978,7 +977,7 @@ def get_entity(self, id: t.Optional[str] = None) -> Entity: """Get entity object for given ID.""" return self.client.get_entity(id=id or self.entity_id) - def get_expected_params( + def get_auth_scheme_for_app( self, app: t.Optional[AppType] = None, auth_scheme: t.Optional[ @@ -989,9 +988,9 @@ def get_expected_params( "BASIC", ] ] = None, - ) -> t.List[AuthSchemeField]: + ) -> AppAuthScheme: auth_schemes = { - scheme.auth_mode: scheme.fields + scheme.auth_mode: scheme for scheme in self.client.apps.get(name=str(app)).auth_schemes or [] } @@ -1019,6 +1018,35 @@ def get_expected_params( ) ) + def get_expected_params_for_user( + self, + app: t.Optional[AppType] = None, + integration_id: t.Optional[str] = None, + entity_id: t.Optional[str] = None, + ) -> t.List[ExpectedFieldInput]: + if integration_id is None and app is None: + raise ComposioSDKError( + message="Both `integration_id` and `app` cannot be None" + ) + + if integration_id is None: + try: + integration_id = ( + self.get_entity(id=entity_id or self.entity_id) + .get_connection(app=app) + .integrationId + ) + except NoItemsFound as e: + raise ComposioSDKError( + message=( + f"No existing integration found for `{str(app)}`, " + "Please create an integration and use the ID to " + "initiate connection." + ) + ) from e + + return self.get_integration(id=integration_id).expectedInputFields + def create_integration( self, app: AppType,