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.

feat: add screenshotone block (#9308)

Nicholas Tindle4302c5d60af1
diff --git a/autogpt_platform/backend/backend/blocks/screenshotone.py b/autogpt_platform/backend/backend/blocks/screenshotone.py
new file mode 100644
index 0000000000..8cad4816e5
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/screenshotone.py
@@ -0,0 +1,174 @@
+from base64 import b64encode
+from enum import Enum
+from typing import Literal
+
+from pydantic import SecretStr
+
+from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
+from backend.data.model import (
+ APIKeyCredentials,
+ CredentialsField,
+ CredentialsMetaInput,
+ SchemaField,
+)
+from backend.integrations.providers import ProviderName
+from backend.util.file import MediaFile, store_media_file
+from backend.util.request import Requests
+
+
+class Format(str, Enum):
+ PNG = "png"
+ JPEG = "jpeg"
+ WEBP = "webp"
+
+
+class ScreenshotWebPageBlock(Block):
+ """Block for taking screenshots using ScreenshotOne API"""
+
+ class Input(BlockSchema):
+ credentials: CredentialsMetaInput[
+ Literal[ProviderName.SCREENSHOTONE], Literal["api_key"]
+ ] = CredentialsField(description="The ScreenshotOne API key")
+ url: str = SchemaField(
+ description="URL of the website to screenshot",
+ placeholder="https://example.com",
+ )
+ viewport_width: int = SchemaField(
+ description="Width of the viewport in pixels", default=1920
+ )
+ viewport_height: int = SchemaField(
+ description="Height of the viewport in pixels", default=1080
+ )
+ full_page: bool = SchemaField(
+ description="Whether to capture the full page length", default=False
+ )
+ format: Format = SchemaField(
+ description="Output format (png, jpeg, webp)", default=Format.PNG
+ )
+ block_ads: bool = SchemaField(description="Whether to block ads", default=True)
+ block_cookie_banners: bool = SchemaField(
+ description="Whether to block cookie banners", default=True
+ )
+ block_chats: bool = SchemaField(
+ description="Whether to block chat widgets", default=True
+ )
+ cache: bool = SchemaField(
+ description="Whether to enable caching", default=False
+ )
+
+ class Output(BlockSchema):
+ image: MediaFile = SchemaField(description="The screenshot image data")
+ error: str = SchemaField(description="Error message if the screenshot failed")
+
+ def __init__(self):
+ super().__init__(
+ id="3a7c4b8d-6e2f-4a5d-b9c1-f8d23c5a9b0e", # Generated UUID
+ description="Takes a screenshot of a specified website using ScreenshotOne API",
+ categories={BlockCategory.DATA},
+ input_schema=ScreenshotWebPageBlock.Input,
+ output_schema=ScreenshotWebPageBlock.Output,
+ test_input={
+ "url": "https://example.com",
+ "viewport_width": 1920,
+ "viewport_height": 1080,
+ "full_page": False,
+ "format": "png",
+ "block_ads": True,
+ "block_cookie_banners": True,
+ "block_chats": True,
+ "cache": False,
+ "credentials": {
+ "provider": "screenshotone",
+ "type": "api_key",
+ "id": "test-id",
+ "title": "Test API Key",
+ },
+ },
+ test_credentials=APIKeyCredentials(
+ id="test-id",
+ provider="screenshotone",
+ api_key=SecretStr("test-key"),
+ title="Test API Key",
+ expires_at=None,
+ ),
+ test_output=[
+ (
+ "image",
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAB5JREFUOE9jZPjP8J+BAsA4agDDaBgwjIYBw7AIAwCV5B/xAsMbygAAAABJRU5ErkJggg==",
+ ),
+ ],
+ test_mock={
+ "take_screenshot": lambda *args, **kwargs: {
+ "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAB5JREFUOE9jZPjP8J+BAsA4agDDaBgwjIYBw7AIAwCV5B/xAsMbygAAAABJRU5ErkJggg==",
+ }
+ },
+ )
+
+ @staticmethod
+ def take_screenshot(
+ credentials: APIKeyCredentials,
+ graph_exec_id: str,
+ url: str,
+ viewport_width: int,
+ viewport_height: int,
+ full_page: bool,
+ format: Format,
+ block_ads: bool,
+ block_cookie_banners: bool,
+ block_chats: bool,
+ cache: bool,
+ ) -> dict:
+ """
+ Takes a screenshot using the ScreenshotOne API
+ """
+ api = Requests(trusted_origins=["https://api.screenshotone.com"])
+
+ # Build API URL with parameters
+ params = {
+ "access_key": credentials.api_key.get_secret_value(),
+ "url": url,
+ "viewport_width": viewport_width,
+ "viewport_height": viewport_height,
+ "full_page": str(full_page).lower(),
+ "format": format.value,
+ "block_ads": str(block_ads).lower(),
+ "block_cookie_banners": str(block_cookie_banners).lower(),
+ "block_chats": str(block_chats).lower(),
+ "cache": str(cache).lower(),
+ }
+
+ response = api.get("https://api.screenshotone.com/take", params=params)
+
+ return {
+ "image": store_media_file(
+ graph_exec_id=graph_exec_id,
+ file=f"data:image/{format.value};base64,{b64encode(response.content).decode('utf-8')}",
+ return_content=True,
+ )
+ }
+
+ def run(
+ self,
+ input_data: Input,
+ *,
+ credentials: APIKeyCredentials,
+ graph_exec_id: str,
+ **kwargs,
+ ) -> BlockOutput:
+ try:
+ screenshot_data = self.take_screenshot(
+ credentials=credentials,
+ graph_exec_id=graph_exec_id,
+ url=input_data.url,
+ viewport_width=input_data.viewport_width,
+ viewport_height=input_data.viewport_height,
+ full_page=input_data.full_page,
+ format=input_data.format,
+ block_ads=input_data.block_ads,
+ block_cookie_banners=input_data.block_cookie_banners,
+ block_chats=input_data.block_chats,
+ cache=input_data.cache,
+ )
+ yield "image", screenshot_data["image"]
+ except Exception as e:
+ yield "error", str(e)
diff --git a/autogpt_platform/backend/backend/integrations/credentials_store.py b/autogpt_platform/backend/backend/integrations/credentials_store.py
index 79edc769b7..5968cbe32d 100644
--- a/autogpt_platform/backend/backend/integrations/credentials_store.py
+++ b/autogpt_platform/backend/backend/integrations/credentials_store.py
@@ -130,6 +130,13 @@ nvidia_credentials = APIKeyCredentials(
title="Use Credits for Nvidia",
expires_at=None,
)
+screenshotone_credentials = APIKeyCredentials(
+ id="3b1bdd16-8818-4bc2-8cbb-b23f9a3439ed",
+ provider="screenshotone",
+ api_key=SecretStr(settings.secrets.screenshotone_api_key),
+ title="Use Credits for ScreenshotOne",
+ expires_at=None,
+)
mem0_credentials = APIKeyCredentials(
id="ed55ac19-356e-4243-a6cb-bc599e9b716f",
provider="mem0",
@@ -154,8 +161,9 @@ DEFAULT_CREDENTIALS = [
fal_credentials,
exa_credentials,
e2b_credentials,
- nvidia_credentials,
mem0_credentials,
+ nvidia_credentials,
+ screenshotone_credentials,
]
@@ -219,6 +227,8 @@ class IntegrationCredentialsStore:
all_credentials.append(e2b_credentials)
if settings.secrets.nvidia_api_key:
all_credentials.append(nvidia_credentials)
+ if settings.secrets.screenshotone_api_key:
+ all_credentials.append(screenshotone_credentials)
if settings.secrets.mem0_api_key:
all_credentials.append(mem0_credentials)
return all_credentials
diff --git a/autogpt_platform/backend/backend/integrations/providers.py b/autogpt_platform/backend/backend/integrations/providers.py
index 4898db13a4..6f31988d7f 100644
--- a/autogpt_platform/backend/backend/integrations/providers.py
+++ b/autogpt_platform/backend/backend/integrations/providers.py
@@ -30,6 +30,7 @@ class ProviderName(str, Enum):
REDDIT = "reddit"
REPLICATE = "replicate"
REVID = "revid"
+ SCREENSHOTONE = "screenshotone"
SLANT3D = "slant3d"
SMTP = "smtp"
TWITTER = "twitter"
diff --git a/autogpt_platform/backend/backend/util/settings.py b/autogpt_platform/backend/backend/util/settings.py
index 698703dea8..17786670b8 100644
--- a/autogpt_platform/backend/backend/util/settings.py
+++ b/autogpt_platform/backend/backend/util/settings.py
@@ -326,6 +326,8 @@ class Secrets(UpdateTrackingModel["Secrets"], BaseSettings):
stripe_api_key: str = Field(default="", description="Stripe API Key")
stripe_webhook_secret: str = Field(default="", description="Stripe Webhook Secret")
+ screenshotone_api_key: str = Field(default="", description="ScreenshotOne API Key")
+
# Add more secret fields as needed
model_config = SettingsConfigDict(
diff --git a/autogpt_platform/backend/backend/util/test.py b/autogpt_platform/backend/backend/util/test.py
index 91718f5da3..ed4a343ab3 100644
--- a/autogpt_platform/backend/backend/util/test.py
+++ b/autogpt_platform/backend/backend/util/test.py
@@ -106,11 +106,11 @@ def execute_block_test(block: Block):
# Populate credentials argument(s)
extra_exec_kwargs: dict = {
- "graph_id": uuid.uuid4(),
- "node_id": uuid.uuid4(),
- "graph_exec_id": uuid.uuid4(),
- "node_exec_id": uuid.uuid4(),
- "user_id": uuid.uuid4(),
+ "graph_id": str(uuid.uuid4()),
+ "node_id": str(uuid.uuid4()),
+ "graph_exec_id": str(uuid.uuid4()),
+ "node_exec_id": str(uuid.uuid4()),
+ "user_id": str(uuid.uuid4()),
}
input_model = cast(type[BlockSchema], block.input_schema)
credentials_input_fields = input_model.get_credentials_fields()
diff --git a/autogpt_platform/frontend/src/components/integrations/credentials-input.tsx b/autogpt_platform/frontend/src/components/integrations/credentials-input.tsx
index 950b2fb25a..9663c8cc5f 100644
--- a/autogpt_platform/frontend/src/components/integrations/credentials-input.tsx
+++ b/autogpt_platform/frontend/src/components/integrations/credentials-input.tsx
@@ -76,6 +76,7 @@ export const providerIcons: Record<
open_router: fallbackIcon,
pinecone: fallbackIcon,
slant3d: fallbackIcon,
+ screenshotone: fallbackIcon,
smtp: fallbackIcon,
replicate: fallbackIcon,
reddit: fallbackIcon,
diff --git a/autogpt_platform/frontend/src/components/integrations/credentials-provider.tsx b/autogpt_platform/frontend/src/components/integrations/credentials-provider.tsx
index 0caec6eeab..990cc04f99 100644
--- a/autogpt_platform/frontend/src/components/integrations/credentials-provider.tsx
+++ b/autogpt_platform/frontend/src/components/integrations/credentials-provider.tsx
@@ -41,6 +41,7 @@ const providerDisplayNames: Record<CredentialsProviderName, string> = {
open_router: "Open Router",
pinecone: "Pinecone",
slant3d: "Slant3D",
+ screenshotone: "ScreenshotOne",
smtp: "SMTP",
reddit: "Reddit",
replicate: "Replicate",
diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts
index acb72573e8..381917dbb3 100644
--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts
+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts
@@ -135,6 +135,7 @@ export const PROVIDER_NAMES = {
OPEN_ROUTER: "open_router",
PINECONE: "pinecone",
SLANT3D: "slant3d",
+ SCREENSHOTONE: "screenshotone",
SMTP: "smtp",
TWITTER: "twitter",
REPLICATE: "replicate",