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.

refactor(backend): delete functions and classes nothing calls (#15818)

Reinier van der Leercc2d63e6cebc
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/storage.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/storage.py
index 392a3455bb..5bc7f0069f 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/storage.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/storage.py
@@ -218,8 +218,3 @@ async def audio_download_url(user_id: str, audio_path: str) -> str:
return await handler.generate_signed_url(
audio_path, expiration_hours=1, user_id=user_id
)
-
-
-async def retrieve_audio(user_id: str, audio_path: str) -> bytes:
- handler = await get_cloud_storage_handler()
- return await handler.retrieve_file(audio_path, user_id=user_id)
diff --git a/autogpt_platform/backend/backend/api/test_helpers.py b/autogpt_platform/backend/backend/api/test_helpers.py
index c6ba333a2e..6b3e707fe8 100644
--- a/autogpt_platform/backend/backend/api/test_helpers.py
+++ b/autogpt_platform/backend/backend/api/test_helpers.py
@@ -1,113 +1,7 @@
"""Helper functions for improved test assertions and error handling."""
-import json
from contextlib import contextmanager
-from typing import Any, Dict, Iterator, Optional
-
-
-def assert_response_status(
- response: Any, expected_status: int = 200, error_context: Optional[str] = None
-) -> None:
- """Assert response status with helpful error message.
-
- Args:
- response: The HTTP response object
- expected_status: Expected status code
- error_context: Optional context to include in error message
- """
- if response.status_code != expected_status:
- error_msg = f"Expected status {expected_status}, got {response.status_code}"
- if error_context:
- error_msg = f"{error_context}: {error_msg}"
-
- # Try to include response body in error
- try:
- body = response.json()
- error_msg += f"\nResponse body: {json.dumps(body, indent=2)}"
- except Exception:
- error_msg += f"\nResponse text: {response.text}"
-
- raise AssertionError(error_msg)
-
-
-def safe_parse_json(
- response: Any, error_context: Optional[str] = None
-) -> Dict[str, Any]:
- """Safely parse JSON response with error handling.
-
- Args:
- response: The HTTP response object
- error_context: Optional context for error messages
-
- Returns:
- Parsed JSON data
-
- Raises:
- AssertionError: If JSON parsing fails
- """
- try:
- return response.json()
- except Exception as e:
- error_msg = f"Failed to parse JSON response: {e}"
- if error_context:
- error_msg = f"{error_context}: {error_msg}"
- error_msg += f"\nResponse text: {response.text[:500]}"
- raise AssertionError(error_msg)
-
-
-def assert_error_response_structure(
- response: Any,
- expected_status: int = 422,
- expected_error_fields: Optional[list[str]] = None,
-) -> Dict[str, Any]:
- """Assert error response has expected structure.
-
- Args:
- response: The HTTP response object
- expected_status: Expected error status code
- expected_error_fields: List of expected fields in error detail
-
- Returns:
- Parsed error response
- """
- assert_response_status(response, expected_status, "Error response check")
-
- error_data = safe_parse_json(response, "Error response parsing")
-
- # Check basic error structure
- assert "detail" in error_data, f"Missing 'detail' in error response: {error_data}"
-
- # Check specific error fields if provided
- if expected_error_fields:
- detail = error_data["detail"]
- if isinstance(detail, list):
- # FastAPI validation errors
- for error in detail:
- assert "loc" in error, f"Missing 'loc' in error: {error}"
- assert "msg" in error, f"Missing 'msg' in error: {error}"
- assert "type" in error, f"Missing 'type' in error: {error}"
-
- return error_data
-
-
-def assert_mock_called_with_partial(mock_obj: Any, **expected_kwargs: Any) -> None:
- """Assert mock was called with expected kwargs (partial match).
-
- Args:
- mock_obj: The mock object to check
- **expected_kwargs: Expected keyword arguments
- """
- assert mock_obj.called, f"Mock {mock_obj} was not called"
-
- actual_kwargs = mock_obj.call_args.kwargs if mock_obj.call_args else {}
-
- for key, expected_value in expected_kwargs.items():
- assert (
- key in actual_kwargs
- ), f"Missing key '{key}' in mock call. Actual keys: {list(actual_kwargs.keys())}"
- assert (
- actual_kwargs[key] == expected_value
- ), f"Mock called with {key}={actual_kwargs[key]}, expected {expected_value}"
+from typing import Any, Iterator
@contextmanager
diff --git a/autogpt_platform/backend/backend/blocks/airtable/_api.py b/autogpt_platform/backend/backend/blocks/airtable/_api.py
index 53ace72d98..dbd53433c1 100644
--- a/autogpt_platform/backend/backend/blocks/airtable/_api.py
+++ b/autogpt_platform/backend/backend/blocks/airtable/_api.py
@@ -1087,18 +1087,6 @@ async def list_webhook_payloads(
)
-async def list_webhooks(
- credentials: Credentials,
- base_id: str,
-) -> Any:
-
- response = await Requests().get(
- f"https://api.airtable.com/v0/bases/{base_id}/webhooks",
- headers={"Authorization": credentials.auth_header()},
- )
- return response.json()
-
-
class OAuthAuthorizeRequest(BaseModel):
"""OAuth authorization request parameters for Airtable.
diff --git a/autogpt_platform/backend/backend/blocks/apollo/_auth.py b/autogpt_platform/backend/backend/blocks/apollo/_auth.py
index c813c72d99..06f78e8fde 100644
--- a/autogpt_platform/backend/backend/blocks/apollo/_auth.py
+++ b/autogpt_platform/backend/backend/blocks/apollo/_auth.py
@@ -2,7 +2,7 @@ from typing import Literal
from pydantic import SecretStr
-from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
+from backend.data.model import APIKeyCredentials, CredentialsMetaInput
from backend.integrations.providers import ProviderName
ApolloCredentials = APIKeyCredentials
@@ -24,12 +24,3 @@ TEST_CREDENTIALS_INPUT = {
"type": TEST_CREDENTIALS.type,
"title": TEST_CREDENTIALS.title,
}
-
-
-def ApolloCredentialsField() -> ApolloCredentialsInput:
- """
- Creates a Apollo credentials input on a block.
- """
- return CredentialsField(
- description="The Apollo integration can be used with an API Key.",
- )
diff --git a/autogpt_platform/backend/backend/blocks/baas/_api.py b/autogpt_platform/backend/backend/blocks/baas/_api.py
index 6a53653aa3..db92828038 100644
--- a/autogpt_platform/backend/backend/blocks/baas/_api.py
+++ b/autogpt_platform/backend/backend/blocks/baas/_api.py
@@ -3,7 +3,7 @@ Meeting BaaS API client module.
All API calls centralized for consistency and maintainability.
"""
-from typing import Any, Dict, List, Optional
+from typing import Any, Dict, Optional
from backend.sdk import Requests
@@ -144,22 +144,6 @@ class MeetingBaasAPI:
)
return response.json()
- async def get_screenshots(self, bot_id: str) -> List[Dict[str, Any]]:
- """
- Retrieve screenshots captured during a meeting.
-
- GET /bots/{uuid}/screenshots
- """
- response = await self.requests.get(
- f"{self.BASE_URL}/bots/{bot_id}/screenshots",
- headers=self.headers,
- )
- result = response.json()
- # Ensure we return a list
- if isinstance(result, list):
- return result
- return []
-
async def delete_data(self, bot_id: str) -> bool:
"""
Delete a bot's recorded data.
@@ -171,35 +155,3 @@ class MeetingBaasAPI:
headers=self.headers,
)
return response.status == 200
-
- async def list_bots_with_metadata(
- self,
- limit: Optional[int] = None,
- offset: Optional[int] = None,
- sort_by: Optional[str] = None,
- sort_order: Optional[str] = None,
- filter_by: Optional[Dict[str, Any]] = None,
- ) -> Dict[str, Any]:
- """
- List bots with metadata including IDs, names, and meeting details.
-
- GET /bots/bots_with_metadata
- """
- params = {}
- if limit is not None:
- params["limit"] = limit
- if offset is not None:
- params["offset"] = offset
- if sort_by is not None:
- params["sort_by"] = sort_by
- if sort_order is not None:
- params["sort_order"] = sort_order
- if filter_by is not None:
- params.update(filter_by)
-
- response = await self.requests.get(
- f"{self.BASE_URL}/bots/bots_with_metadata",
- headers=self.headers,
- params=params,
- )
- return response.json()
diff --git a/autogpt_platform/backend/backend/blocks/exa/helpers.py b/autogpt_platform/backend/backend/blocks/exa/helpers.py
index 3baf86aea0..d6264936f9 100644
--- a/autogpt_platform/backend/backend/blocks/exa/helpers.py
+++ b/autogpt_platform/backend/backend/blocks/exa/helpers.py
@@ -437,34 +437,6 @@ def process_context_field(
return None
-def format_date_fields(
- input_data: Any, date_field_mapping: Dict[str, str]
-) -> Dict[str, str]:
- """Format datetime fields for API payload."""
- formatted_dates = {}
- for input_field, api_field in date_field_mapping.items():
- value = getattr(input_data, input_field, None)
- if value:
- formatted_dates[api_field] = value.strftime("%Y-%m-%dT%H:%M:%S.000Z")
- return formatted_dates
-
-
-def add_optional_fields(
- input_data: Any,
- field_mapping: Dict[str, str],
- payload: Dict[str, Any],
- process_enums: bool = False,
-) -> None:
- """Add optional fields to payload if they have values."""
- for input_field, api_field in field_mapping.items():
- value = getattr(input_data, input_field, None)
- if value: # Only add non-empty values
- if process_enums and hasattr(value, "value"):
- payload[api_field] = value.value
- else:
- payload[api_field] = value
-
-
def extract_exa_cost_usd(response: Any) -> Optional[float]:
"""Return ``cost_dollars.total`` (USD) from an Exa SDK response, or None.
diff --git a/autogpt_platform/backend/backend/blocks/fal/ai_video_generator.py b/autogpt_platform/backend/backend/blocks/fal/ai_video_generator.py
index ec59d83295..23c6e0a019 100644
--- a/autogpt_platform/backend/backend/blocks/fal/ai_video_generator.py
+++ b/autogpt_platform/backend/backend/blocks/fal/ai_video_generator.py
@@ -1,7 +1,6 @@
import asyncio
import logging
from enum import Enum
-from typing import Any
from backend.blocks._base import (
Block,
@@ -86,28 +85,6 @@ class AIVideoGeneratorBlock(Block):
"Content-Type": "application/json",
}
- async def _submit_request(
- self, url: str, headers: dict[str, str], data: dict[str, Any]
- ) -> dict[str, Any]:
- """Submit a request to the FAL API."""
- try:
- response = await Requests().post(url, headers=headers, json=data)
- return response.json()
- except ClientResponseError as e:
- logger.error(f"FAL API request failed: {str(e)}")
- raise RuntimeError(f"Failed to submit request: {str(e)}")
-
- async def _poll_status(
- self, status_url: str, headers: dict[str, str]
- ) -> dict[str, Any]:
- """Poll the status endpoint until completion or failure."""
- try:
- response = await Requests().get(status_url, headers=headers)
- return response.json()
- except ClientResponseError as e:
- logger.error(f"Failed to get status: {str(e)}")
- raise RuntimeError(f"Failed to get status: {str(e)}")
-
async def generate_video(
self, input_data: Input, credentials: FalCredentials
) -> str:
diff --git a/autogpt_platform/backend/backend/blocks/github/issues.py b/autogpt_platform/backend/backend/blocks/github/issues.py
index c9524afa7f..b0992b0cbf 100644
--- a/autogpt_platform/backend/backend/blocks/github/issues.py
+++ b/autogpt_platform/backend/backend/blocks/github/issues.py
@@ -26,10 +26,6 @@ from ._auth import (
logger = logging.getLogger(__name__)
-def is_github_url(url: str) -> bool:
- return urlparse(url).netloc == "github.com"
-
-
# --8<-- [start:GithubCommentBlockExample]
class GithubCommentBlock(Block):
class Input(BlockSchemaInput):
diff --git a/autogpt_platform/backend/backend/blocks/linear/_oauth.py b/autogpt_platform/backend/backend/blocks/linear/_oauth.py
index 14f3de4e41..57be2a486c 100644
--- a/autogpt_platform/backend/backend/blocks/linear/_oauth.py
+++ b/autogpt_platform/backend/backend/blocks/linear/_oauth.py
@@ -285,17 +285,6 @@ class LinearOAuthHandler(BaseOAuthHandler):
return credentials.access_token.get_secret_value()
- def needs_migration(self, credentials: OAuth2Credentials) -> bool:
- """
- Check if credentials represent an old long-lived token that needs migration.
-
- Old tokens have no expiration time and no refresh token.
- """
- return (
- credentials.access_token_expires_at is None
- and credentials.refresh_token is None
- )
-
async def _request_username(self, access_token: str) -> Optional[str]:
# Use the LinearClient to fetch user details using GraphQL
from ._api import LinearClient
diff --git a/autogpt_platform/backend/backend/blocks/smartlead/_auth.py b/autogpt_platform/backend/backend/blocks/smartlead/_auth.py
index 219524126c..e42ea6ca93 100644
--- a/autogpt_platform/backend/backend/blocks/smartlead/_auth.py
+++ b/autogpt_platform/backend/backend/blocks/smartlead/_auth.py
@@ -2,7 +2,7 @@ from typing import Literal
from pydantic import SecretStr
-from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
+from backend.data.model import APIKeyCredentials, CredentialsMetaInput
from backend.integrations.providers import ProviderName
SmartLeadCredentials = APIKeyCredentials
@@ -24,12 +24,3 @@ TEST_CREDENTIALS_INPUT = {
"type": TEST_CREDENTIALS.type,
"title": TEST_CREDENTIALS.title,
}
-
-
-def SmartLeadCredentialsField() -> SmartLeadCredentialsInput:
- """
- Creates a SmartLead credentials input on a block.
- """
- return CredentialsField(
- description="The SmartLead integration can be used with an API Key.",
- )
diff --git a/autogpt_platform/backend/backend/blocks/twitter/_builders.py b/autogpt_platform/backend/backend/blocks/twitter/_builders.py
index 5f396b11ad..e0503bbcd6 100644
--- a/autogpt_platform/backend/backend/blocks/twitter/_builders.py
+++ b/autogpt_platform/backend/backend/blocks/twitter/_builders.py
@@ -410,15 +410,3 @@ class TweetPostBuilder:
def build(self):
return self.params
-
-
-class TweetGetsBuilder:
- def __init__(self):
- self.params: Dict[str, Any] = {"user_auth": False}
-
- def add_id(self, tweet_id: list[str]):
- self.params["id"] = tweet_id
- return self
-
- def build(self):
- return self.params
diff --git a/autogpt_platform/backend/backend/blocks/twitter/_mappers.py b/autogpt_platform/backend/backend/blocks/twitter/_mappers.py
index a564174ed0..b0e925c7e2 100644
--- a/autogpt_platform/backend/backend/blocks/twitter/_mappers.py
+++ b/autogpt_platform/backend/backend/blocks/twitter/_mappers.py
@@ -21,22 +21,7 @@ def get_backend_expansion(frontend_key: str) -> str:
return result
-# TweetReplySettings
-REPLY_SETTINGS_FRONTEND_TO_BACKEND_MAPPING = {
- "Mentioned_Users_Only": "mentionedUsers",
- "Following_Users_Only": "following",
- "All_Users": "all",
-}
-
-
# TweetUserFields
-def get_backend_reply_setting(frontend_key: str) -> str:
- result = REPLY_SETTINGS_FRONTEND_TO_BACKEND_MAPPING.get(frontend_key)
- if result is None:
- raise KeyError(f"Invalid reply setting key: {frontend_key}")
- return result
-
-
USER_FIELDS_FRONTEND_TO_BACKEND_MAPPING = {
"Account_Creation_Date": "created_at",
"User_Bio": "description",
diff --git a/autogpt_platform/backend/backend/blocks/twitter/_serializer.py b/autogpt_platform/backend/backend/blocks/twitter/_serializer.py
index bb570d995d..2fc1046591 100644
--- a/autogpt_platform/backend/backend/blocks/twitter/_serializer.py
+++ b/autogpt_platform/backend/backend/blocks/twitter/_serializer.py
@@ -56,23 +56,3 @@ class ResponseDataSerializer(BaseSerializer):
if not data:
return []
return [cls.serialize_dict(item) for item in data]
-
-
-class ResponseSerializer:
- @classmethod
- def serialize(cls, response) -> Dict[str, Any]:
- """Main serializer that handles both data and includes"""
- result = {"data": None, "included": {}}
-
- # Handle response.data
- if response.data:
- if isinstance(response.data, list):
- result["data"] = ResponseDataSerializer.serialize_list(response.data)
- else:
- result["data"] = ResponseDataSerializer.serialize_dict(response.data)
-
- # Handle includes
- if hasattr(response, "includes") and response.includes:
- result["included"] = IncludesSerializer.serialize(response.includes)
-
- return result
diff --git a/autogpt_platform/backend/backend/blocks/zerobounce/_auth.py b/autogpt_platform/backend/backend/blocks/zerobounce/_auth.py
index e7125fc3c9..70af5e1e42 100644
--- a/autogpt_platform/backend/backend/blocks/zerobounce/_auth.py
+++ b/autogpt_platform/backend/backend/blocks/zerobounce/_auth.py
@@ -2,7 +2,7 @@ from typing import Literal
from pydantic import SecretStr
-from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
+from backend.data.model import APIKeyCredentials, CredentialsMetaInput
from backend.integrations.providers import ProviderName
ZeroBounceCredentials = APIKeyCredentials
@@ -24,12 +24,3 @@ TEST_CREDENTIALS_INPUT = {
"type": TEST_CREDENTIALS.type,
"title": TEST_CREDENTIALS.title,
}
-
-
-def ZeroBounceCredentialsField() -> ZeroBounceCredentialsInput:
- """
- Creates a ZeroBounce credentials input on a block.
- """
- return CredentialsField(
- description="The ZeroBounce integration can be used with an API Key.",
- )
diff --git a/autogpt_platform/backend/backend/copilot/tools/agent_generator/fixer.py b/autogpt_platform/backend/backend/copilot/tools/agent_generator/fixer.py
index a69c77600f..932716ab64 100644
--- a/autogpt_platform/backend/backend/copilot/tools/agent_generator/fixer.py
+++ b/autogpt_platform/backend/backend/copilot/tools/agent_generator/fixer.py
@@ -1805,7 +1805,3 @@ class AgentFixer:
def get_fixes_applied(self) -> list[str]:
"""Get a list of all fixes that were applied."""
return self.fixes_applied.copy()
-
- def clear_fixes_log(self) -> None:
- """Clear the list of applied fixes."""
- self.fixes_applied = []
diff --git a/autogpt_platform/backend/backend/sdk/builder.py b/autogpt_platform/backend/backend/sdk/builder.py
index 65ec59a35e..cc633844df 100644
--- a/autogpt_platform/backend/backend/sdk/builder.py
+++ b/autogpt_platform/backend/backend/sdk/builder.py
@@ -19,7 +19,6 @@ from backend.integrations.oauth.base import BaseOAuthHandler
from backend.integrations.webhooks._base import BaseWebhooksManager
from backend.sdk.provider import OAuthConfig, Provider
from backend.sdk.registry import AutoRegistry
-from backend.util.settings import Settings
logger = logging.getLogger(__name__)
@@ -105,26 +104,6 @@ class ProviderBuilder:
self._supported_auth_types.add("api_key")
return self
- def with_api_key_from_settings(
- self, settings_attr: str, title: str
- ) -> "ProviderBuilder":
- """Use existing API key from settings."""
- self._supported_auth_types.add("api_key")
-
- # Try to get the API key from settings
- settings = Settings()
- api_key = getattr(settings.secrets, settings_attr, None)
- if api_key:
- self._default_credentials.append(
- APIKeyCredentials(
- id=f"{self.name}-default",
- provider=self.name,
- api_key=api_key,
- title=title,
- )
- )
- return self
-
def with_user_password(
self, username_env_var: str, password_env_var: str, title: str
) -> "ProviderBuilder":
diff --git a/autogpt_platform/backend/backend/util/data.py b/autogpt_platform/backend/backend/util/data.py
index d77d4cc789..7830f9252b 100644
--- a/autogpt_platform/backend/backend/util/data.py
+++ b/autogpt_platform/backend/backend/util/data.py
@@ -3,18 +3,6 @@ import pathlib
import sys
-def get_frontend_path() -> pathlib.Path:
- if getattr(sys, "frozen", False):
- # The application is frozen
- datadir = pathlib.Path(os.path.dirname(sys.executable)) / "example_files"
- else:
- # The application is not frozen
- # Change this bit to match where you store your data files:
- filedir = os.path.dirname(__file__)
- datadir = pathlib.Path(filedir).parent.parent.parent / "example_files"
- return pathlib.Path(datadir)
-
-
def get_data_path() -> pathlib.Path:
if getattr(sys, "frozen", False):
# The application is frozen
diff --git a/autogpt_platform/backend/backend/util/timezone_utils.py b/autogpt_platform/backend/backend/util/timezone_utils.py
index 76614a8357..7e4eda842c 100644
--- a/autogpt_platform/backend/backend/util/timezone_utils.py
+++ b/autogpt_platform/backend/backend/util/timezone_utils.py
@@ -8,75 +8,11 @@ from datetime import datetime
from typing import Optional
from zoneinfo import ZoneInfo
-from croniter import croniter
-
from backend.data.model import USER_TIMEZONE_NOT_SET
logger = logging.getLogger(__name__)
-def convert_cron_to_utc(cron_expr: str, user_timezone: str) -> str:
- """
- Convert a cron expression from user timezone to UTC.
-
- NOTE: This is a simplified conversion that only adjusts minute and hour fields.
- Complex cron expressions with specific day/month/weekday patterns may not
- convert accurately due to timezone offset variations throughout the year.
-
- Args:
- cron_expr: Cron expression in user timezone
- user_timezone: User's IANA timezone identifier
-
- Returns:
- Cron expression adjusted for UTC execution
-
- Raises:
- ValueError: If timezone or cron expression is invalid
- """
- try:
- user_tz = ZoneInfo(user_timezone)
- utc_tz = ZoneInfo("UTC")
-
- # Split the cron expression into its five fields
- cron_fields = cron_expr.strip().split()
- if len(cron_fields) != 5:
- raise ValueError(
- "Cron expression must have 5 fields (minute hour day month weekday)"
- )
-
- # Get the current time in the user's timezone
- now_user = datetime.now(user_tz)
-
- # Get the next scheduled time in user timezone
- cron = croniter(cron_expr, now_user)
- next_user_time = cron.get_next(datetime)
-
- # Convert to UTC
- next_utc_time = next_user_time.astimezone(utc_tz)
-
- # Adjust minute and hour fields for UTC, keep day/month/weekday as in original
- utc_cron_parts = [
- str(next_utc_time.minute),
- str(next_utc_time.hour),
- cron_fields[2], # day of month
- cron_fields[3], # month
- cron_fields[4], # day of week
- ]
-
- utc_cron = " ".join(utc_cron_parts)
-
- logger.debug(
- f"Converted cron '{cron_expr}' from {user_timezone} to UTC: '{utc_cron}'"
- )
- return utc_cron
-
- except Exception as e:
- logger.error(
- f"Failed to convert cron expression '{cron_expr}' from {user_timezone} to UTC: {e}"
- )
- raise ValueError(f"Invalid cron expression or timezone: {e}")
-
-
def convert_utc_time_to_user_timezone(utc_time_str: str, user_timezone: str) -> str:
"""
Convert a UTC datetime string to user timezone.