Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

misc: move auth fields helpers to `toolkits` names

angrybaybladeedfadf11423f
diff --git a/python/composio/client/types.py b/python/composio/client/types.py
index f7aad2b17..b16fb9375 100644
--- a/python/composio/client/types.py
+++ b/python/composio/client/types.py
@@ -33,6 +33,34 @@ Tool: t.TypeAlias = tool_list_response.Item
ToolkitMinimal: t.TypeAlias = tool_list_response.ItemToolkit
AuthConfig: t.TypeAlias = connected_account_create_params.AuthConfig
+Oauth1L: t.TypeAlias = t.Literal["OAUTH1"]
+Oauth2L: t.TypeAlias = t.Literal["OAUTH2"]
+ApiKeyL: t.TypeAlias = t.Literal["API_KEY"]
+BasicL: t.TypeAlias = t.Literal["BASIC"]
+NoAuthL: t.TypeAlias = t.Literal["NO_AUTH"]
+SnowflakeL: t.TypeAlias = t.Literal["SNOWFLAKE"]
+CalcomAuthL: t.TypeAlias = t.Literal["CALCOM_AUTH"]
+BearerTokenL: t.TypeAlias = t.Literal["BEARER_TOKEN"]
+BillcomAuthL: t.TypeAlias = t.Literal["BILLCOM_AUTH"]
+ComposioLinkL: t.TypeAlias = t.Literal["COMPOSIO_LINK"]
+BasicWithJwtL: t.TypeAlias = t.Literal["BASIC_WITH_JWT"]
+GoogleServiceAccountL: t.TypeAlias = t.Literal["GOOGLE_SERVICE_ACCOUNT"]
+
+AuthSchemeL: t.TypeAlias = t.Literal[
+ Oauth1L,
+ Oauth2L,
+ ApiKeyL,
+ BasicL,
+ NoAuthL,
+ SnowflakeL,
+ CalcomAuthL,
+ BearerTokenL,
+ BillcomAuthL,
+ ComposioLinkL,
+ BasicWithJwtL,
+ GoogleServiceAccountL,
+]
+
__all__ = (
"auth_config_create_params",
"auth_config_create_response",
@@ -59,4 +87,5 @@ __all__ = (
"ToolkitMinimal",
"AuthConfig",
"NotGiven",
+ "AuthSchemeL",
)
diff --git a/python/composio/core/models/auth_configs.py b/python/composio/core/models/auth_configs.py
index 473105788..1c3449537 100644
--- a/python/composio/core/models/auth_configs.py
+++ b/python/composio/core/models/auth_configs.py
@@ -4,7 +4,6 @@ import typing as t
import typing_extensions as te
-from composio import exceptions
from composio.client.types import (
auth_config_create_params,
auth_config_create_response,
@@ -12,13 +11,9 @@ from composio.client.types import (
auth_config_list_response,
auth_config_retrieve_response,
auth_config_update_params,
- toolkit_retrieve_response,
)
from composio.core.models.base import Resource
-if t.TYPE_CHECKING:
- from .connected_accounts import AuthSchemeL
-
class AuthConfigs(Resource):
"""
@@ -145,22 +140,3 @@ class AuthConfigs(Resource):
:return: The disabled auth config.
"""
return self.__update_status(nanoid, "DISABLED")
-
- def get_required_fields(
- self,
- toolkit: str,
- auth_scheme: AuthSchemeL,
- ) -> t.List[
- toolkit_retrieve_response.AuthConfigDetailFieldsAuthConfigCreationRequired
- ]:
- """
- Get the required property for a given toolkit and auth scheme.
- """
- info = self._client.toolkits.retrieve(slug=toolkit)
- for auth_detail in info.auth_config_details or []:
- if auth_detail.mode == auth_scheme:
- return auth_detail.fields.auth_config_creation.required
-
- raise exceptions.InvalidParams(
- f"auth config details not found with {toolkit=} and {auth_scheme=}"
- )
diff --git a/python/composio/core/models/connected_accounts.py b/python/composio/core/models/connected_accounts.py
index 9c209e541..228245901 100644
--- a/python/composio/core/models/connected_accounts.py
+++ b/python/composio/core/models/connected_accounts.py
@@ -10,39 +10,10 @@ from composio.client.types import (
connected_account_create_params,
connected_account_retrieve_response,
connected_account_update_status_response,
- toolkit_retrieve_response,
)
from .base import Resource
-Oauth1L: t.TypeAlias = t.Literal["OAUTH1"]
-Oauth2L: t.TypeAlias = t.Literal["OAUTH2"]
-ApiKeyL: t.TypeAlias = t.Literal["API_KEY"]
-BasicL: t.TypeAlias = t.Literal["BASIC"]
-NoAuthL: t.TypeAlias = t.Literal["NO_AUTH"]
-SnowflakeL: t.TypeAlias = t.Literal["SNOWFLAKE"]
-CalcomAuthL: t.TypeAlias = t.Literal["CALCOM_AUTH"]
-BearerTokenL: t.TypeAlias = t.Literal["BEARER_TOKEN"]
-BillcomAuthL: t.TypeAlias = t.Literal["BILLCOM_AUTH"]
-ComposioLinkL: t.TypeAlias = t.Literal["COMPOSIO_LINK"]
-BasicWithJwtL: t.TypeAlias = t.Literal["BASIC_WITH_JWT"]
-GoogleServiceAccountL: t.TypeAlias = t.Literal["GOOGLE_SERVICE_ACCOUNT"]
-
-AuthSchemeL: t.TypeAlias = t.Literal[
- Oauth1L,
- Oauth2L,
- ApiKeyL,
- BasicL,
- NoAuthL,
- SnowflakeL,
- CalcomAuthL,
- BearerTokenL,
- BillcomAuthL,
- ComposioLinkL,
- BasicWithJwtL,
- GoogleServiceAccountL,
-]
-
class ConnectionRequest(Resource):
"""
@@ -384,24 +355,5 @@ class ConnectedAccounts:
client=self._client,
)
- def get_required_fields(
- self,
- toolkit: str,
- auth_scheme: AuthSchemeL,
- ) -> t.List[
- toolkit_retrieve_response.AuthConfigDetailFieldsConnectedAccountInitiationRequired
- ]:
- """
- Get the required property for a given toolkit and auth scheme.
- """
- info = self._client.toolkits.retrieve(slug=toolkit)
- for auth_detail in info.auth_config_details or []:
- if auth_detail.mode == auth_scheme:
- return auth_detail.fields.connected_account_initiation.required
-
- raise exceptions.InvalidParams(
- f"auth config details not found with {toolkit=} and {auth_scheme=}"
- )
-
auth_scheme = AuthScheme()
diff --git a/python/composio/core/models/toolkits.py b/python/composio/core/models/toolkits.py
index e70c09131..764e04b2a 100644
--- a/python/composio/core/models/toolkits.py
+++ b/python/composio/core/models/toolkits.py
@@ -2,8 +2,10 @@ from __future__ import annotations
import typing as t
+from composio import exceptions
from composio.client import HttpClient
from composio.client.types import (
+ AuthSchemeL,
toolkit_list_params,
toolkit_list_response,
toolkit_retrieve_response,
@@ -12,6 +14,13 @@ from composio.core.models.connected_accounts import ConnectedAccounts
from .base import Resource
+AuthFieldsT: t.TypeAlias = t.List[
+ toolkit_retrieve_response.AuthConfigDetailFieldsConnectedAccountInitiationRequired
+ | toolkit_retrieve_response.AuthConfigDetailFieldsConnectedAccountInitiationOptional
+ | toolkit_retrieve_response.AuthConfigDetailFieldsAuthConfigCreationRequired
+ | toolkit_retrieve_response.AuthConfigDetailFieldsAuthConfigCreationOptional
+]
+
class Toolkits(Resource):
"""
@@ -32,17 +41,14 @@ class Toolkits(Resource):
"""Get all toolkits."""
@t.overload
- def get(
- self,
- slug: t.Optional[str] = None,
- ) -> toolkit_retrieve_response.ToolkitRetrieveResponse:
+ def get(self, slug: str) -> toolkit_retrieve_response.ToolkitRetrieveResponse:
"""Get a toolkit by slug."""
@t.overload
def get(
self,
*,
- query: t.Optional[toolkit_list_params.ToolkitListParams] = None,
+ query: toolkit_list_params.ToolkitListParams,
) -> list[toolkit_list_response.Item]:
"""Get a list of toolkits by query."""
@@ -98,3 +104,63 @@ class Toolkits(Resource):
toolkit=toolkit,
),
)
+
+ def get_connected_account_initiation_fields(
+ self,
+ toolkit: str,
+ auth_scheme: AuthSchemeL,
+ required_only: bool = False,
+ ) -> AuthFieldsT:
+ """
+ Get the required property for a given toolkit and auth scheme.
+ """
+ details = self._client.toolkits.retrieve(slug=toolkit).auth_config_details or []
+ for auth_detail in details:
+ if auth_detail.mode != auth_scheme:
+ continue
+
+ if required_only:
+ return t.cast(
+ AuthFieldsT,
+ auth_detail.fields.connected_account_initiation.required,
+ )
+
+ return t.cast(
+ AuthFieldsT,
+ auth_detail.fields.connected_account_initiation.required
+ + auth_detail.fields.connected_account_initiation.optional,
+ )
+
+ raise exceptions.InvalidParams(
+ f"auth config details not found with {toolkit=} and {auth_scheme=}"
+ )
+
+ def get_auth_config_creation_fields(
+ self,
+ toolkit: str,
+ auth_scheme: AuthSchemeL,
+ required_only: bool = False,
+ ) -> AuthFieldsT:
+ """
+ Get the required property for a given toolkit and auth scheme.
+ """
+ info = self._client.toolkits.retrieve(slug=toolkit)
+ for auth_detail in info.auth_config_details or []:
+ if auth_detail.mode != auth_scheme:
+ continue
+
+ if required_only:
+ return t.cast(
+ AuthFieldsT,
+ auth_detail.fields.auth_config_creation.required,
+ )
+
+ return t.cast(
+ AuthFieldsT,
+ auth_detail.fields.auth_config_creation.required
+ + auth_detail.fields.auth_config_creation.optional,
+ )
+
+ raise exceptions.InvalidParams(
+ f"auth config details not found with {toolkit=} and {auth_scheme=}"
+ )
diff --git a/python/examples/auth_configs.py b/python/examples/auth_configs.py
index 9e5c4b618..954db7425 100644
--- a/python/examples/auth_configs.py
+++ b/python/examples/auth_configs.py
@@ -32,7 +32,7 @@ auth_config = composio.auth_configs.create(
print(auth_config)
# When creating an auth config, you can check for required fields
-required_fields = composio.auth_configs.get_required_fields(
+required_fields = composio.toolkits.get_auth_config_creation_fields(
toolkit="NOTION",
auth_scheme="OAUTH2",
)
diff --git a/python/examples/connected_accounts.py b/python/examples/connected_accounts.py
index 59c8c2d6e..1c48eb4e6 100644
--- a/python/examples/connected_accounts.py
+++ b/python/examples/connected_accounts.py
@@ -31,7 +31,7 @@ connection_request = composio.connected_accounts.initiate(
print(connection_request)
# When creating a connected account, you can check for required fields
-required_fields = composio.connected_accounts.get_required_fields(
+required_fields = composio.toolkits.get_connected_account_initiation_fields(
toolkit="NOTION",
auth_scheme="API_KEY",
)