Skip to content

Commit

Permalink
Fix trigger names and suppress pusher logs (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade authored Jun 28, 2024
1 parent 5c028d8 commit 22a5f76
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 54 deletions.
8 changes: 1 addition & 7 deletions python/composio/cli/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,7 @@ def _update_triggers(
)
for app in apps:
for trigger in [trigger for trigger in triggers if trigger.appKey == app.key]:
trigger_names.append(
(
_get_enum_key(name=app.key)
+ "_"
+ _get_enum_key(name=trigger.display_name)
).upper()
)
trigger_names.append(_get_enum_key(name=trigger.name).upper())
enums.base.TriggerData(
name=trigger.name,
app=app.key,
Expand Down
3 changes: 3 additions & 0 deletions python/composio/client/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typing as t
import warnings
from concurrent.futures import Future, ThreadPoolExecutor
from unittest import mock

import pysher
import typing_extensions as te
Expand Down Expand Up @@ -624,6 +625,8 @@ def connect(self, timeout: float = 15.0) -> TriggerSubscription:
"x-api-key": self.api_key,
},
)
# Patch pusher logger
pusher.connection.logger = mock.MagicMock() # type: ignore
pusher.connection.bind(
"pusher:connection_established",
self._get_connection_handler(
Expand Down
28 changes: 14 additions & 14 deletions python/composio/client/enums/_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ class Trigger(_AnnotatedEnum[TriggerData], path=TRIGGERS_CACHE):
GITHUB_STAR_ADDED_EVENT: "Trigger"
GMAIL_NEW_GMAIL_MESSAGE: "Trigger"
GOOGLEDRIVE_GOOGLE_DRIVE_CHANGES: "Trigger"
NOTION_NEW_PAGE: "Trigger"
SLACK_NEW_CHANNEL_CREATED: "Trigger"
NOTION_PAGE_ADDED_TO_DATABASE: "Trigger"
SLACK_CHANNEL_CREATED: "Trigger"
SLACK_REACTION_ADDED: "Trigger"
SLACK_REACTION_REMOVED: "Trigger"
SLACK_NEW_MESSAGE: "Trigger"
SLACK_THREAD_REPLY: "Trigger"
SLACKBOT_NEW_CHANNEL_CREATED: "Trigger"
SLACK_RECEIVE_MESSAGE: "Trigger"
SLACK_RECEIVE_THREAD_REPLY: "Trigger"
SLACKBOT_CHANNEL_CREATED: "Trigger"
SLACKBOT_REACTION_ADDED: "Trigger"
SLACKBOT_REACTION_REMOVED: "Trigger"
SLACKBOT_NEW_MESSAGE: "Trigger"
SLACKBOT_THREAD_REPLY: "Trigger"
SPOTIFY_NEW_DEVICE_ADDED: "Trigger"
SPOTIFY_NEW_SONG_ADDED_TO_PLAYLIST: "Trigger"
SPOTIFY_NEW_PLAYLIST_CREATED_OR_DELETED: "Trigger"
YOUTUBE_NEW_YOUTUBE_ACTIVITY: "Trigger"
YOUTUBE_NEW_ITEM_IN_YOUTUBE_PLAYLIST: "Trigger"
YOUTUBE_NEW_PLAYLIST_IN_YOUTUBE_CHANNEL: "Trigger"
YOUTUBE_NEW_YOUTUBE_CHANNEL_SUBSCRIPTION: "Trigger"
SLACKBOT_RECEIVE_MESSAGE: "Trigger"
SLACKBOT_RECEIVE_THREAD_REPLY: "Trigger"
SPOTIFY_NEW_DEVICE_TRIGGER: "Trigger"
SPOTIFY_PLAYLIST_ITEM_TRIGGER: "Trigger"
SPOTIFY_PLAYLIST_TRIGGER: "Trigger"
YOUTUBE_NEW_ACTIVITY_TRIGGER: "Trigger"
YOUTUBE_NEW_ITEM_IN_PLAYLIST_TRIGGER: "Trigger"
YOUTUBE_NEW_PLAYLIST_TRIGGER: "Trigger"
YOUTUBE_NEW_SUBSCRIPTION_TRIGGER: "Trigger"

@property
def name(self) -> str:
Expand Down
38 changes: 32 additions & 6 deletions python/composio/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from composio.client import Composio
from composio.client.collections import (
ActionModel,
ConnectedAccountModel,
FileModel,
SuccessExecuteActionResponseModel,
TriggerSubscription,
)
from composio.client.enums import Action, ActionType, App, AppType, Tag, TagType
from composio.client.enums import Action, ActionType, App, AppType, TagType
from composio.client.exceptions import ComposioClientError
from composio.client.local_handler import LocalToolHandler
from composio.constants import (
Expand All @@ -27,14 +28,15 @@
LOCAL_OUTPUT_FILE_DIRECTORY_NAME,
USER_DATA_FILE_NAME,
)
from composio.exceptions import raise_api_key_missing
from composio.exceptions import ComposioSDKError, raise_api_key_missing
from composio.storage.user import UserData


class ComposioToolSet:
"""Composio toolset."""

_remote_client: Composio
_connected_accounts: t.Optional[t.List[ConnectedAccountModel]] = None

def __init__(
self,
Expand Down Expand Up @@ -86,6 +88,26 @@ def client(self) -> Composio:
def runtime(self) -> t.Optional[str]:
return self._runtime

def check_connected_account(self, action: ActionType) -> None:
"""Check if connected account is required and if required it exists or not."""
action = Action(action)
if action.no_auth:
return

if self._connected_accounts is None:
self._connected_accounts = t.cast(
t.List[ConnectedAccountModel],
self.client.connected_accounts.get(),
)

if action.app not in [
connection.appUniqueId for connection in self._connected_accounts
]:
raise ComposioSDKError(
f"No connected account found for app `{action.app}`; "
f"Run `composio add {action.app}` to fix this"
)

def execute_action(
self,
action: t.Union[Action, str],
Expand All @@ -102,12 +124,14 @@ def execute_action(
Any: The output of the action execution.
:return: Output object from the function call.
"""
if isinstance(action, str):
action = Action(action)

action = Action(action)
if action.is_local:
return self._local_client.execute_action(action=action, request_data=params)
return self._local_client.execute_action(
action=action,
request_data=params,
)

self.check_connected_account(action=action)
output = self.client.get_entity(
id=entity_id,
).execute(
Expand Down Expand Up @@ -196,6 +220,8 @@ def get_action_schemas(
)
items = items + remote_items

for item in items:
self.check_connected_account(action=item.name)
return items

def create_trigger_listener(self, timeout: float = 15.0) -> TriggerSubscription:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/autogen/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_autogen",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your Autogen agent.",
Expand All @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
],
python_requires=">=3.9,<4",
install_requires=["composio_core==0.3.15", "pyautogen>=0.2.19"],
install_requires=["composio_core==0.3.16", "pyautogen>=0.2.19"],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/claude/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_claude",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your Claude LLMs.",
Expand All @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
],
python_requires=">=3.9,<4",
install_requires=["composio_openai==0.3.15", "anthropic>=0.25.7"],
install_requires=["composio_openai==0.3.16", "anthropic>=0.25.7"],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/crew_ai/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_crewai",
version="0.3.15",
version="0.3.16",
author="Himanshu",
author_email="[email protected]",
description="Use Composio to get an array of tools with your CrewAI agent.",
Expand All @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
],
python_requires=">=3.9,<4",
install_requires=["composio_langchain==0.3.15"],
install_requires=["composio_langchain==0.3.16"],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/griptape/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_griptape",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your Griptape wokflow.",
Expand All @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
],
python_requires=">=3.9,<4",
install_requires=["composio_core==0.3.15", "griptape>=0.24.2"],
install_requires=["composio_core==0.3.16", "griptape>=0.24.2"],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/julep/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_julep",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your Julep wokflow.",
Expand All @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
],
python_requires=">=3.9,<4",
install_requires=["composio_openai==0.3.15", "julep>=0.3.2"],
install_requires=["composio_openai==0.3.16", "julep>=0.3.2"],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/langchain/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_langchain",
version="0.3.15",
version="0.3.16",
author="Karan",
author_email="[email protected]",
description="Use Composio to get an array of tools with your LangChain agent.",
Expand All @@ -27,7 +27,7 @@
"langchain-openai>=0.0.2.post1",
"pydantic>=2.6.4",
"langchainhub>=0.1.15",
"composio_core==0.3.15",
"composio_core==0.3.16",
],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/llamaindex/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_llamaindex",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your LlamaIndex agent.",
Expand All @@ -24,7 +24,7 @@
python_requires=">=3.9,<4",
install_requires=[
"llama_index>=0.10.43",
"composio_langchain==0.3.15",
"composio_langchain==0.3.16",
],
include_package_data=True,
)
4 changes: 2 additions & 2 deletions python/plugins/lyzr/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_lyzr",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your Lyzr workflow.",
Expand All @@ -25,7 +25,7 @@
install_requires=[
"lyzr-automata>=0.1.3",
"pydantic>=2.6.4",
"composio_core==0.3.15",
"composio_core==0.3.16",
"langchain>=0.1.0",
],
include_package_data=True,
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/openai/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="composio_openai",
version="0.3.15",
version="0.3.16",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your OpenAI Function Call.",
Expand All @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
],
python_requires=">=3.9,<4",
install_requires=["composio_core==0.3.15"],
install_requires=["composio_core==0.3.16"],
include_package_data=True,
)
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="composio_core",
version="0.3.15",
version="0.3.16",
author="Utkarsh",
author_email="[email protected]",
description="Core package to act as a bridge between composio platform and other services.",
Expand Down
12 changes: 6 additions & 6 deletions python/tests/test_client/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class TestTriggerNamesSerialization:
def test_converts_trigger_objects_to_comma_separated_string(self):
trigger_list = [
Trigger.GITHUB_COMMIT_EVENT,
Trigger.SLACK_NEW_MESSAGE,
Trigger.YOUTUBE_NEW_YOUTUBE_ACTIVITY,
Trigger.SLACK_RECEIVE_MESSAGE,
Trigger.YOUTUBE_NEW_ACTIVITY_TRIGGER,
]
result = to_trigger_names(trigger_list)
assert (
Expand All @@ -32,8 +32,8 @@ def test_converts_trigger_objects_to_comma_separated_string(self):
def test_converts_trigger_strings_to_comma_separated_string(self):
trigger_list = [
"github_commit_event",
"slack_new_message",
"youtube_new_youtube_activity",
"slack_receive_message",
"youtube_new_activity_trigger",
]
result = to_trigger_names(trigger_list)
assert (
Expand All @@ -44,8 +44,8 @@ def test_converts_trigger_strings_to_comma_separated_string(self):
def test_converts_mix_of_trigger_objects_and_strings(self):
trigger_list = [
Trigger.GITHUB_COMMIT_EVENT,
"slack_new_message",
Trigger.YOUTUBE_NEW_YOUTUBE_ACTIVITY,
"slack_receive_message",
Trigger.YOUTUBE_NEW_ACTIVITY_TRIGGER,
]
result = to_trigger_names(trigger_list)
assert (
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_client/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_action_enum() -> None:

def test_trigger_enum() -> None:
"""Test `Trigger` enum."""
trigger = Trigger("slack_new_message")
trigger = Trigger("slack_receive_message")
assert trigger.app == "slack"
assert trigger.name == "slack_receive_message"

Expand Down
17 changes: 16 additions & 1 deletion python/tests/test_tools/test_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Test composio toolset.
"""

from composio import App
import pytest

from composio import Action, App
from composio.exceptions import ComposioSDKError
from composio.tools import ComposioToolSet


Expand All @@ -17,3 +20,15 @@ def test_find_actions_by_tags() -> None:
):
assert "important" in action.tags
assert action.app in ("github", "slack", "slackbot")


def test_uninitialize_app() -> None:
"""Test if the usage of an app without connected account raises erorr or not."""
with pytest.raises(
ComposioSDKError,
match=(
"No connected account found for app `apify`; "
"Run `composio add apify` to fix this"
),
):
ComposioToolSet().get_action_schemas(actions=[Action.APIFY_CREATE_APIFY_ACTOR])

0 comments on commit 22a5f76

Please sign in to comment.