mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
feat: add check for auth accounts
This commit is contained in:
@@ -18,6 +18,26 @@ class ComposioTool(BaseTool):
|
|||||||
"""Run the composio action with given arguments."""
|
"""Run the composio action with given arguments."""
|
||||||
return self.composio_action(*args, **kwargs)
|
return self.composio_action(*args, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _check_connected_account(tool: t.Any, toolset: t.Any) -> None:
|
||||||
|
"""Check if connected account is required and if required it exists or not."""
|
||||||
|
from composio import Action
|
||||||
|
from composio.client.collections import ConnectedAccountModel
|
||||||
|
|
||||||
|
tool = t.cast(Action, tool)
|
||||||
|
if tool.no_auth:
|
||||||
|
return
|
||||||
|
|
||||||
|
connections = t.cast(
|
||||||
|
t.List[ConnectedAccountModel],
|
||||||
|
toolset.client.connected_accounts.get(),
|
||||||
|
)
|
||||||
|
if tool.app not in [connection.appUniqueId for connection in connections]:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"No connected account found for app `{tool.app}`; "
|
||||||
|
f"Run `composio add {tool.app}` to fix this"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_tool(
|
def from_tool(
|
||||||
cls,
|
cls,
|
||||||
@@ -35,6 +55,11 @@ class ComposioTool(BaseTool):
|
|||||||
tool = Action(tool)
|
tool = Action(tool)
|
||||||
|
|
||||||
tool = t.cast(Action, tool)
|
tool = t.cast(Action, tool)
|
||||||
|
cls._check_connected_account(
|
||||||
|
tool=tool,
|
||||||
|
toolset=toolset,
|
||||||
|
)
|
||||||
|
|
||||||
(action,) = toolset.get_action_schemas(actions=[tool])
|
(action,) = toolset.get_action_schemas(actions=[tool])
|
||||||
schema = action.model_dump(exclude_none=True)
|
schema = action.model_dump(exclude_none=True)
|
||||||
entity_id = kwargs.pop("entity_id", DEFAULT_ENTITY_ID)
|
entity_id = kwargs.pop("entity_id", DEFAULT_ENTITY_ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user