Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
feat(ts/core): address cursorbot
jkomyno07d9fe577665
diff --git a/python/composio/core/models/triggers.py b/python/composio/core/models/triggers.pyindex 0d2927683..922667c53 100644--- a/python/composio/core/models/triggers.py+++ b/python/composio/core/models/triggers.py@@ -1074,18 +1074,11 @@ class Triggers(Resource):f"Failed to parse webhook payload as JSON: {e}") from e- # Try V3 first (has 'type' starting with 'composio.' and 'metadata')- # Validate metadata is a dict with all required fields (matching TypeScript's zod schema)+ # Try V3 first (has 'type' starting with 'composio.' and 'metadata' as dict)+ # Metadata shape varies by event type (trigger vs connection events),+ # so we only check that it's a dict here.v3_metadata = data.get("metadata") if isinstance(data, dict) else None- v3_metadata_valid = (- isinstance(v3_metadata, dict)- and "log_id" in v3_metadata- and "trigger_slug" in v3_metadata- and "trigger_id" in v3_metadata- and "connected_account_id" in v3_metadata- and "auth_config_id" in v3_metadata- and "user_id" in v3_metadata- )+ v3_metadata_valid = isinstance(v3_metadata, dict)v3_type = data.get("type", "") if isinstance(data, dict) else ""if (isinstance(data, dict)@@ -1214,36 +1207,82 @@ class Triggers(Resource):def _normalize_v3_payload(self, data: WebhookPayloadV3) -> TriggerEvent:"""Normalize V3 payload to TriggerEvent format."""metadata = data["metadata"]- return t.cast(- TriggerEvent,- {- "id": metadata["trigger_id"],- "uuid": metadata["trigger_id"],- "user_id": metadata["user_id"],- "toolkit_slug": metadata["trigger_slug"].split("_")[0].upper()- if "_" in metadata["trigger_slug"]- else "UNKNOWN",- "trigger_slug": metadata["trigger_slug"],- "metadata": {++ # Check if this is a trigger event (has trigger-specific metadata fields)+ is_trigger_event = all(+ k in metadata+ for k in (+ "trigger_id",+ "trigger_slug",+ "user_id",+ "connected_account_id",+ "auth_config_id",+ "log_id",+ )+ )++ if is_trigger_event:+ return t.cast(+ TriggerEvent,+ {"id": metadata["trigger_id"],"uuid": metadata["trigger_id"],+ "user_id": metadata["user_id"],"toolkit_slug": metadata["trigger_slug"].split("_")[0].upper()if "_" in metadata["trigger_slug"]else "UNKNOWN","trigger_slug": metadata["trigger_slug"],+ "metadata": {+ "id": metadata["trigger_id"],+ "uuid": metadata["trigger_id"],+ "toolkit_slug": metadata["trigger_slug"].split("_")[0].upper()+ if "_" in metadata["trigger_slug"]+ else "UNKNOWN",+ "trigger_slug": metadata["trigger_slug"],+ "trigger_data": None,+ "trigger_config": {},+ "connected_account": {+ "id": metadata["connected_account_id"],+ "uuid": metadata["connected_account_id"],+ "auth_config_id": metadata["auth_config_id"],+ "auth_config_uuid": metadata["auth_config_id"],+ "user_id": metadata["user_id"],+ "status": "ACTIVE",+ },+ },+ "payload": data["data"],+ "original_payload": None,+ },+ )++ # Non-trigger V3 event (e.g., connection expired)+ event_type = data.get("type", "")+ return t.cast(+ TriggerEvent,+ {+ "id": data.get("id", ""),+ "uuid": data.get("id", ""),+ "user_id": "",+ "toolkit_slug": "COMPOSIO",+ "trigger_slug": event_type,+ "metadata": {+ "id": data.get("id", ""),+ "uuid": data.get("id", ""),+ "toolkit_slug": "COMPOSIO",+ "trigger_slug": event_type,"trigger_data": None,"trigger_config": {},"connected_account": {- "id": metadata["connected_account_id"],- "uuid": metadata["connected_account_id"],- "auth_config_id": metadata["auth_config_id"],- "auth_config_uuid": metadata["auth_config_id"],- "user_id": metadata["user_id"],+ "id": "",+ "uuid": "",+ "auth_config_id": "",+ "auth_config_uuid": "",+ "user_id": "","status": "ACTIVE",},},- "payload": data["data"],- "original_payload": None,+ "payload": data.get("data", {}),+ "original_payload": data,},)diff --git a/python/tests/test_triggers.py b/python/tests/test_triggers.pyindex c3912596a..fa32dbae2 100644--- a/python/tests/test_triggers.py+++ b/python/tests/test_triggers.py@@ -580,23 +580,24 @@ class TestVerifyWebhook:):"""Test V3 payload with non-trigger event type is detected as V3, not V2.- This is a regression test for PLEN-1397: V3 payloads with event types- other than 'composio.trigger.message' should still be detected as V3.+ Uses realistic connection metadata (project_id, org_id) instead of+ fabricated trigger metadata, verifying V3 detection works for events+ with different metadata shapes."""- # V3 payload with a different event typepayload_dict = {"id": "msg_abc123","timestamp": "2024-01-01T00:00:00Z",- "type": "composio.connected_account.expired", # Not 'composio.trigger.message'+ "type": "composio.connected_account.expired","metadata": {- "log_id": "log-123",- "trigger_slug": "",- "trigger_id": "",- "connected_account_id": "conn-123",- "auth_config_id": "auth-123",- "user_id": "user-456",+ "project_id": "pr_koucdrMIwRsf",+ "org_id": "4a4ded8f-d3ae-4dea-a229-c30234298b05",+ },+ "data": {+ "toolkit": {"slug": "gmail"},+ "id": "ca__IvSeEzEBjVt",+ "user_id": "test-user",+ "status": "EXPIRED",},- "data": {"reason": "token_expired"},}payload = json.dumps(payload_dict)signature = self.create_signature(