Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend): classify trigger blocks as inputs (#13353)

Rayan Salhab70928bb94624
diff --git a/autogpt_platform/backend/backend/api/features/builder/db.py b/autogpt_platform/backend/backend/api/features/builder/db.py
index 8225ccee18..0a99132bc9 100644
--- a/autogpt_platform/backend/backend/api/features/builder/db.py
+++ b/autogpt_platform/backend/backend/api/features/builder/db.py
@@ -56,6 +56,14 @@ EXCLUDED_BLOCK_IDS = frozenset(
}
)
+INPUT_BLOCK_TYPES = frozenset(
+ {
+ BlockType.INPUT,
+ BlockType.WEBHOOK,
+ BlockType.WEBHOOK_MANUAL,
+ }
+)
+
SearchResultItem = BlockInfo | library_model.LibraryAgent | store_model.StoreAgent
@@ -152,9 +160,12 @@ def get_blocks(
continue
# Skip blocks that don't match the type
if (
- (type == "input" and block.block_type.value != "Input")
- or (type == "output" and block.block_type.value != "Output")
- or (type == "action" and block.block_type.value in ("Input", "Output"))
+ (type == "input" and block.block_type not in INPUT_BLOCK_TYPES)
+ or (type == "output" and block.block_type != BlockType.OUTPUT)
+ or (
+ type == "action"
+ and block.block_type in (*INPUT_BLOCK_TYPES, BlockType.OUTPUT)
+ )
):
continue
# Skip blocks that don't match the provider
@@ -655,9 +666,9 @@ async def _get_static_counts():
all_blocks += 1
- if block.block_type.value == "Input":
+ if block.block_type in INPUT_BLOCK_TYPES:
input_blocks += 1
- elif block.block_type.value == "Output":
+ elif block.block_type == BlockType.OUTPUT:
output_blocks += 1
else:
action_blocks += 1
diff --git a/autogpt_platform/backend/backend/api/features/builder/db_test.py b/autogpt_platform/backend/backend/api/features/builder/db_test.py
index 3b0c9e9dde..918c2f3b63 100644
--- a/autogpt_platform/backend/backend/api/features/builder/db_test.py
+++ b/autogpt_platform/backend/backend/api/features/builder/db_test.py
@@ -8,14 +8,107 @@ real ~400-block registry; one test exercises the real index builder.
from types import SimpleNamespace
from typing import Any
+from unittest.mock import AsyncMock
import pytest
import backend.api.features.builder.db as db
-from backend.blocks._base import BlockInfo
+from backend.blocks._base import BlockInfo, BlockType
from backend.util.text import split_camelcase
+class _EmptyInputSchema:
+ def get_credentials_fields_info(self):
+ return {}
+
+ def get_credentials_fields(self):
+ return {}
+
+
+def _block_info(block_id: str, name: str) -> BlockInfo:
+ return BlockInfo(
+ id=block_id,
+ name=name,
+ inputSchema={},
+ outputSchema={},
+ costs=[],
+ description="",
+ categories=[],
+ contributors=[],
+ staticOutput=False,
+ uiType="",
+ )
+
+
+def _block(block_id: str, name: str, block_type: BlockType):
+ class FakeBlock:
+ id = block_id
+ disabled = False
+ categories = []
+ input_schema = _EmptyInputSchema()
+
+ def __init__(self):
+ self.id = block_id
+ self.name = name
+ self.block_type = block_type
+ self.disabled = False
+ self.categories = []
+ self.input_schema = _EmptyInputSchema()
+
+ def get_info(self):
+ return _block_info(block_id, name)
+
+ return FakeBlock
+
+
+def mixed_blocks(monkeypatch):
+ blocks = {
+ "input": _block("input", "Input", BlockType.INPUT),
+ "webhook": _block("webhook", "Webhook", BlockType.WEBHOOK),
+ "webhook_manual": _block(
+ "webhook_manual", "Webhook Manual", BlockType.WEBHOOK_MANUAL
+ ),
+ "output": _block("output", "Output", BlockType.OUTPUT),
+ "standard": _block("standard", "Action", BlockType.STANDARD),
+ }
+ monkeypatch.setattr(db, "load_all_blocks", lambda: blocks)
+ db._get_static_counts.cache_clear()
+ return blocks
+
+
+def test_get_blocks_treats_webhook_triggers_as_input_blocks(mixed_blocks):
+ response = db.get_blocks(type="input")
+
+ assert {block.id for block in response.blocks} == {
+ "input",
+ "webhook",
+ "webhook_manual",
+ }
+
+
+def test_get_blocks_excludes_webhook_triggers_from_action_blocks(mixed_blocks):
+ response = db.get_blocks(type="action")
+
+ assert {block.id for block in response.blocks} == {"standard"}
+
+
+async def test_static_counts_classify_webhook_triggers_as_input_blocks(
+ mixed_blocks, monkeypatch
+):
+ store_agent = SimpleNamespace(
+ prisma=lambda: SimpleNamespace(count=AsyncMock(return_value=0))
+ )
+ monkeypatch.setattr(db.prisma.models, "StoreAgent", store_agent)
+
+ counts = await db._get_static_counts()
+
+ assert counts["input_blocks"] == 3
+ assert counts["action_blocks"] == 1
+ assert counts["output_blocks"] == 1
+
+
def _entry(
name: str,
normalized_name: str,