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): Rename & move `IntegrationCredentialsStore` to backend (#8648)
Nicholas Tindle75f9b072a643
diff --git a/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/__init__.py b/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/__init__.pydeleted file mode 100644index bae73dfbf2..0000000000--- a/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .store import SupabaseIntegrationCredentialsStore-from .types import APIKeyCredentials, Credentials, OAuth2Credentials--__all__ = [- "SupabaseIntegrationCredentialsStore",- "Credentials",- "APIKeyCredentials",- "OAuth2Credentials",-]diff --git a/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/types.py b/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/types.pydeleted file mode 100644index 384dfdc797..0000000000--- a/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/types.py+++ /dev/null@@ -1,75 +0,0 @@-from typing import Annotated, Any, Literal, Optional, TypedDict-from uuid import uuid4--from pydantic import BaseModel, Field, SecretStr, field_serializer---class _BaseCredentials(BaseModel):- id: str = Field(default_factory=lambda: str(uuid4()))- provider: str- title: Optional[str]-- @field_serializer("*")- def dump_secret_strings(value: Any, _info):- if isinstance(value, SecretStr):- return value.get_secret_value()- return value---class OAuth2Credentials(_BaseCredentials):- type: Literal["oauth2"] = "oauth2"- username: Optional[str]- """Username of the third-party service user that these credentials belong to"""- access_token: SecretStr- access_token_expires_at: Optional[int]- """Unix timestamp (seconds) indicating when the access token expires (if at all)"""- refresh_token: Optional[SecretStr]- refresh_token_expires_at: Optional[int]- """Unix timestamp (seconds) indicating when the refresh token expires (if at all)"""- scopes: list[str]- metadata: dict[str, Any] = Field(default_factory=dict)-- def bearer(self) -> str:- return f"Bearer {self.access_token.get_secret_value()}"---class APIKeyCredentials(_BaseCredentials):- type: Literal["api_key"] = "api_key"- api_key: SecretStr- expires_at: Optional[int]- """Unix timestamp (seconds) indicating when the API key expires (if at all)"""-- def bearer(self) -> str:- return f"Bearer {self.api_key.get_secret_value()}"---Credentials = Annotated[- OAuth2Credentials | APIKeyCredentials,- Field(discriminator="type"),-]---CredentialsType = Literal["api_key", "oauth2"]---class OAuthState(BaseModel):- token: str- provider: str- expires_at: int- scopes: list[str]- """Unix timestamp (seconds) indicating when this OAuth state expires"""---class UserMetadata(BaseModel):- integration_credentials: list[Credentials] = Field(default_factory=list)- integration_oauth_states: list[OAuthState] = Field(default_factory=list)---class UserMetadataRaw(TypedDict, total=False):- integration_credentials: list[dict]- integration_oauth_states: list[dict]---class UserIntegrations(BaseModel):- credentials: list[Credentials] = Field(default_factory=list)- oauth_states: list[OAuthState] = Field(default_factory=list)diff --git a/autogpt_platform/backend/backend/blocks/ai_image_generator_block.py b/autogpt_platform/backend/backend/blocks/ai_image_generator_block.pyindex f2441708ce..ee94f016aa 100644--- a/autogpt_platform/backend/backend/blocks/ai_image_generator_block.py+++ b/autogpt_platform/backend/backend/blocks/ai_image_generator_block.py@@ -2,12 +2,16 @@ from enum import Enumfrom typing import Literalimport replicate-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom replicate.helpers import FileOutputfrom backend.data.block import Block, BlockCategory, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)class ImageSize(str, Enum):diff --git a/autogpt_platform/backend/backend/blocks/ai_music_generator.py b/autogpt_platform/backend/backend/blocks/ai_music_generator.pyindex 6b2c086a0a..f70d43ce37 100644--- a/autogpt_platform/backend/backend/blocks/ai_music_generator.py+++ b/autogpt_platform/backend/backend/blocks/ai_music_generator.py@@ -4,11 +4,15 @@ from enum import Enumfrom typing import Literalimport replicate-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)logger = logging.getLogger(__name__)diff --git a/autogpt_platform/backend/backend/blocks/ai_shortform_video_block.py b/autogpt_platform/backend/backend/blocks/ai_shortform_video_block.pyindex e70f8fd40e..08023b8771 100644--- a/autogpt_platform/backend/backend/blocks/ai_shortform_video_block.py+++ b/autogpt_platform/backend/backend/blocks/ai_shortform_video_block.py@@ -3,11 +3,15 @@ import timefrom enum import Enumfrom typing import Literal-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)from backend.util.request import requestsTEST_CREDENTIALS = APIKeyCredentials(diff --git a/autogpt_platform/backend/backend/blocks/discord.py b/autogpt_platform/backend/backend/blocks/discord.pyindex 69d3c3bc74..c638e40250 100644--- a/autogpt_platform/backend/backend/blocks/discord.py+++ b/autogpt_platform/backend/backend/blocks/discord.py@@ -3,11 +3,15 @@ from typing import Literalimport aiohttpimport discord-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)DiscordCredentials = CredentialsMetaInput[Literal["discord"], Literal["api_key"]]diff --git a/autogpt_platform/backend/backend/blocks/github/_auth.py b/autogpt_platform/backend/backend/blocks/github/_auth.pyindex 4ea31e98be..72aa8f6480 100644--- a/autogpt_platform/backend/backend/blocks/github/_auth.py+++ b/autogpt_platform/backend/backend/blocks/github/_auth.py@@ -1,12 +1,13 @@from typing import Literal-from autogpt_libs.supabase_integration_credentials_store.types import (+from pydantic import SecretStr++from backend.data.model import (APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,OAuth2Credentials,)-from pydantic import SecretStr--from backend.data.model import CredentialsField, CredentialsMetaInputfrom backend.util.settings import Secretssecrets = Secrets()diff --git a/autogpt_platform/backend/backend/blocks/google/_auth.py b/autogpt_platform/backend/backend/blocks/google/_auth.pyindex 742fcb36fa..ccae2e4622 100644--- a/autogpt_platform/backend/backend/blocks/google/_auth.py+++ b/autogpt_platform/backend/backend/blocks/google/_auth.py@@ -1,9 +1,8 @@from typing import Literal-from autogpt_libs.supabase_integration_credentials_store.types import OAuth2Credentialsfrom pydantic import SecretStr-from backend.data.model import CredentialsField, CredentialsMetaInput+from backend.data.model import CredentialsField, CredentialsMetaInput, OAuth2Credentialsfrom backend.util.settings import Secrets# --8<-- [start:GoogleOAuthIsConfigured]diff --git a/autogpt_platform/backend/backend/blocks/google_maps.py b/autogpt_platform/backend/backend/blocks/google_maps.pyindex 97d91c8370..d211fe8ff3 100644--- a/autogpt_platform/backend/backend/blocks/google_maps.py+++ b/autogpt_platform/backend/backend/blocks/google_maps.py@@ -1,11 +1,15 @@from typing import Literalimport googlemaps-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import BaseModel, SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)TEST_CREDENTIALS = APIKeyCredentials(id="01234567-89ab-cdef-0123-456789abcdef",diff --git a/autogpt_platform/backend/backend/blocks/hubspot/_auth.py b/autogpt_platform/backend/backend/blocks/hubspot/_auth.pyindex 3fa5f64945..c32af8c38c 100644--- a/autogpt_platform/backend/backend/blocks/hubspot/_auth.py+++ b/autogpt_platform/backend/backend/blocks/hubspot/_auth.py@@ -1,9 +1,8 @@from typing import Literal-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStr-from backend.data.model import CredentialsField, CredentialsMetaInput+from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInputHubSpotCredentials = APIKeyCredentialsHubSpotCredentialsInput = CredentialsMetaInput[diff --git a/autogpt_platform/backend/backend/blocks/ideogram.py b/autogpt_platform/backend/backend/blocks/ideogram.pyindex 8c9e4b6f59..b6a21e7ace 100644--- a/autogpt_platform/backend/backend/blocks/ideogram.py+++ b/autogpt_platform/backend/backend/blocks/ideogram.py@@ -1,12 +1,16 @@from enum import Enumfrom typing import Any, Dict, Literal, Optional-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom requests.exceptions import RequestExceptionfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)from backend.util.request import requestsTEST_CREDENTIALS = APIKeyCredentials(diff --git a/autogpt_platform/backend/backend/blocks/jina/_auth.py b/autogpt_platform/backend/backend/blocks/jina/_auth.pyindex c8d9f6b05a..2bffeecce7 100644--- a/autogpt_platform/backend/backend/blocks/jina/_auth.py+++ b/autogpt_platform/backend/backend/blocks/jina/_auth.py@@ -1,9 +1,8 @@from typing import Literal-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStr-from backend.data.model import CredentialsField, CredentialsMetaInput+from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInputJinaCredentials = APIKeyCredentialsJinaCredentialsInput = CredentialsMetaInput[diff --git a/autogpt_platform/backend/backend/blocks/llm.py b/autogpt_platform/backend/backend/blocks/llm.pyindex a30ed1576c..50a9bfb3c6 100644--- a/autogpt_platform/backend/backend/blocks/llm.py+++ b/autogpt_platform/backend/backend/blocks/llm.py@@ -5,7 +5,6 @@ from json import JSONDecodeErrorfrom types import MappingProxyTypefrom typing import TYPE_CHECKING, Any, List, Literal, NamedTuple-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrif TYPE_CHECKING:@@ -17,7 +16,12 @@ import openaifrom groq import Groqfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)from backend.util import jsonfrom backend.util.settings import BehaveAs, Settingsdiff --git a/autogpt_platform/backend/backend/blocks/medium.py b/autogpt_platform/backend/backend/blocks/medium.pyindex 60abb46598..da8c367c78 100644--- a/autogpt_platform/backend/backend/blocks/medium.py+++ b/autogpt_platform/backend/backend/blocks/medium.py@@ -1,11 +1,11 @@from enum import Enumfrom typing import List, Literal-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchemafrom backend.data.model import (+ APIKeyCredentials,BlockSecret,CredentialsField,CredentialsMetaInput,diff --git a/autogpt_platform/backend/backend/blocks/pinecone.py b/autogpt_platform/backend/backend/blocks/pinecone.pyindex 5ef8e63992..a62c1fa777 100644--- a/autogpt_platform/backend/backend/blocks/pinecone.py+++ b/autogpt_platform/backend/backend/blocks/pinecone.py@@ -1,11 +1,15 @@import uuidfrom typing import Any, Literal-from autogpt_libs.supabase_integration_credentials_store import APIKeyCredentialsfrom pinecone import Pinecone, ServerlessSpecfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)PineconeCredentials = APIKeyCredentialsPineconeCredentialsInput = CredentialsMetaInput[diff --git a/autogpt_platform/backend/backend/blocks/replicate_flux_advanced.py b/autogpt_platform/backend/backend/blocks/replicate_flux_advanced.pyindex 9200084c47..b346c87a38 100644--- a/autogpt_platform/backend/backend/blocks/replicate_flux_advanced.py+++ b/autogpt_platform/backend/backend/blocks/replicate_flux_advanced.py@@ -3,12 +3,16 @@ from enum import Enumfrom typing import Literalimport replicate-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom replicate.helpers import FileOutputfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)TEST_CREDENTIALS = APIKeyCredentials(id="01234567-89ab-cdef-0123-456789abcdef",diff --git a/autogpt_platform/backend/backend/blocks/search.py b/autogpt_platform/backend/backend/blocks/search.pyindex a736762699..f89232703a 100644--- a/autogpt_platform/backend/backend/blocks/search.py+++ b/autogpt_platform/backend/backend/blocks/search.py@@ -1,12 +1,16 @@from typing import Literalfrom urllib.parse import quote-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.blocks.helpers.http import GetRequestfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)class GetWikipediaSummaryBlock(Block, GetRequest):diff --git a/autogpt_platform/backend/backend/blocks/talking_head.py b/autogpt_platform/backend/backend/blocks/talking_head.pyindex 9f372b0abf..20aadcd214 100644--- a/autogpt_platform/backend/backend/blocks/talking_head.py+++ b/autogpt_platform/backend/backend/blocks/talking_head.py@@ -1,11 +1,15 @@import timefrom typing import Literal-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)from backend.util.request import requestsTEST_CREDENTIALS = APIKeyCredentials(diff --git a/autogpt_platform/backend/backend/blocks/text_to_speech_block.py b/autogpt_platform/backend/backend/blocks/text_to_speech_block.pyindex 510d028176..b92cc9fa44 100644--- a/autogpt_platform/backend/backend/blocks/text_to_speech_block.py+++ b/autogpt_platform/backend/backend/blocks/text_to_speech_block.py@@ -1,10 +1,14 @@from typing import Any, Literal-from autogpt_libs.supabase_integration_credentials_store.types import APIKeyCredentialsfrom pydantic import SecretStrfrom backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema-from backend.data.model import CredentialsField, CredentialsMetaInput, SchemaField+from backend.data.model import (+ APIKeyCredentials,+ CredentialsField,+ CredentialsMetaInput,+ SchemaField,+)from backend.util.request import requestsTEST_CREDENTIALS = APIKeyCredentials(diff --git a/autogpt_platform/backend/backend/cli.py b/autogpt_platform/backend/backend/cli.pyindex 154c22207b..efaadd02b2 100755--- a/autogpt_platform/backend/backend/cli.py+++ b/autogpt_platform/backend/backend/cli.py@@ -93,6 +93,16 @@ def stop():print("Server Stopped")+def gen_encrypt_key():+ """+ Generate a new encryption key+ """+ from cryptography.fernet import Fernet++ print(Fernet.generate_key().decode())++@click.group()def test():"""diff --git a/autogpt_platform/backend/backend/data/__init__.py b/autogpt_platform/backend/backend/data/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/autogpt_platform/backend/backend/data/block.py b/autogpt_platform/backend/backend/data/block.pyindex 2ce8b75d1b..e1035e84fe 100644--- a/autogpt_platform/backend/backend/data/block.py+++ b/autogpt_platform/backend/backend/data/block.py@@ -15,14 +15,18 @@ from typing import (import jsonrefimport jsonschema-from autogpt_libs.supabase_integration_credentials_store.types import Credentialsfrom prisma.models import AgentBlockfrom pydantic import BaseModelfrom backend.util import jsonfrom backend.util.settings import Config-from .model import CREDENTIALS_FIELD_NAME, ContributorDetails, CredentialsMetaInput+from .model import (+ CREDENTIALS_FIELD_NAME,+ ContributorDetails,+ Credentials,+ CredentialsMetaInput,+)app_config = Config()diff --git a/autogpt_platform/backend/backend/data/block_cost_config.py b/autogpt_platform/backend/backend/data/block_cost_config.pyindex 42b43d95dc..6b5a124097 100644--- a/autogpt_platform/backend/backend/data/block_cost_config.py+++ b/autogpt_platform/backend/backend/data/block_cost_config.py@@ -1,18 +1,5 @@from typing import Type-from autogpt_libs.supabase_integration_credentials_store.store import (- anthropic_credentials,- did_credentials,- groq_credentials,- ideogram_credentials,- jina_credentials,- open_router_credentials,- openai_credentials,- replicate_credentials,- revid_credentials,- unreal_credentials,-)-from backend.blocks.ai_music_generator import AIMusicGeneratorBlockfrom backend.blocks.ai_shortform_video_block import AIShortformVideoCreatorBlockfrom backend.blocks.ideogram import IdeogramModelBlock@@ -32,6 +19,18 @@ from backend.blocks.talking_head import CreateTalkingAvatarVideoBlockfrom backend.blocks.text_to_speech_block import UnrealTextToSpeechBlockfrom backend.data.block import Blockfrom backend.data.cost import BlockCost, BlockCostType+from backend.integrations.credentials_store import (+ anthropic_credentials,+ did_credentials,+ groq_credentials,+ ideogram_credentials,+ jina_credentials,+ open_router_credentials,+ openai_credentials,+ replicate_credentials,+ revid_credentials,+ unreal_credentials,+)# =============== Configure the cost for each LLM Model call =============== #diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.pyindex 1081d6b90e..dbe7b753b8 100644--- a/autogpt_platform/backend/backend/data/graph.py+++ b/autogpt_platform/backend/backend/data/graph.py@@ -615,14 +615,11 @@ def make_graph_model(creatable_graph: Graph, user_id: str) -> GraphModel:async def fix_llm_provider_credentials():"""Fix node credentials with provider `llm`"""- from autogpt_libs.supabase_integration_credentials_store import (- SupabaseIntegrationCredentialsStore,- )+ from backend.integrations.credentials_store import IntegrationCredentialsStore- from .redis import get_redisfrom .user import get_user_integrations- store = SupabaseIntegrationCredentialsStore(get_redis())+ store = IntegrationCredentialsStore()broken_nodes = await prisma.get_client().query_raw("""diff --git a/autogpt_platform/backend/backend/data/model.py b/autogpt_platform/backend/backend/data/model.pyindex 9a988133eb..f8b6781e0c 100644--- a/autogpt_platform/backend/backend/data/model.py+++ b/autogpt_platform/backend/backend/data/model.py@@ -1,10 +1,20 @@from __future__ import annotationsimport logging-from typing import Any, Callable, ClassVar, Generic, Optional, TypeVar+from typing import (+ Annotated,+ Any,+ Callable,+ ClassVar,+ Generic,+ Literal,+ Optional,+ TypedDict,+ TypeVar,+)+from uuid import uuid4-from autogpt_libs.supabase_integration_credentials_store.types import CredentialsType-from pydantic import BaseModel, Field, GetCoreSchemaHandler+from pydantic import BaseModel, Field, GetCoreSchemaHandler, SecretStr, field_serializerfrom pydantic_core import (CoreSchema,PydanticUndefined,@@ -139,6 +149,77 @@ def SchemaField()+class _BaseCredentials(BaseModel):+ id: str = Field(default_factory=lambda: str(uuid4()))+ provider: str+ title: Optional[str]++ @field_serializer("*")+ def dump_secret_strings(value: Any, _info):+ if isinstance(value, SecretStr):+ return value.get_secret_value()+ return value+++class OAuth2Credentials(_BaseCredentials):+ type: Literal["oauth2"] = "oauth2"+ username: Optional[str]+ """Username of the third-party service user that these credentials belong to"""+ access_token: SecretStr+ access_token_expires_at: Optional[int]+ """Unix timestamp (seconds) indicating when the access token expires (if at all)"""+ refresh_token: Optional[SecretStr]+ refresh_token_expires_at: Optional[int]+ """Unix timestamp (seconds) indicating when the refresh token expires (if at all)"""+ scopes: list[str]+ metadata: dict[str, Any] = Field(default_factory=dict)++ def bearer(self) -> str:+ return f"Bearer {self.access_token.get_secret_value()}"+++class APIKeyCredentials(_BaseCredentials):+ type: Literal["api_key"] = "api_key"+ api_key: SecretStr+ expires_at: Optional[int]+ """Unix timestamp (seconds) indicating when the API key expires (if at all)"""++ def bearer(self) -> str:+ return f"Bearer {self.api_key.get_secret_value()}"+++Credentials = Annotated[+ OAuth2Credentials | APIKeyCredentials,+ Field(discriminator="type"),+]+++CredentialsType = Literal["api_key", "oauth2"]+++class OAuthState(BaseModel):+ token: str+ provider: str+ expires_at: int+ """Unix timestamp (seconds) indicating when this OAuth state expires"""+ scopes: list[str]+++class UserMetadata(BaseModel):+ integration_credentials: list[Credentials] = Field(default_factory=list)+ integration_oauth_states: list[OAuthState] = Field(default_factory=list)+++class UserMetadataRaw(TypedDict, total=False):+ integration_credentials: list[dict]+ integration_oauth_states: list[dict]+++class UserIntegrations(BaseModel):+ credentials: list[Credentials] = Field(default_factory=list)+ oauth_states: list[OAuthState] = Field(default_factory=list)++CP = TypeVar("CP", bound=str)CT = TypeVar("CT", bound=CredentialsType)diff --git a/autogpt_platform/backend/backend/data/user.py b/autogpt_platform/backend/backend/data/user.pyindex a9599bfdde..8602d0f3b1 100644--- a/autogpt_platform/backend/backend/data/user.py+++ b/autogpt_platform/backend/backend/data/user.py@@ -2,16 +2,12 @@ import loggingfrom typing import Optional, castfrom autogpt_libs.auth.models import DEFAULT_USER_ID-from autogpt_libs.supabase_integration_credentials_store.types import (- UserIntegrations,- UserMetadata,- UserMetadataRaw,-)from fastapi import HTTPExceptionfrom prisma import Jsonfrom prisma.models import Userfrom backend.data.db import prisma+from backend.data.model import UserIntegrations, UserMetadata, UserMetadataRawfrom backend.util.encryption import JSONCryptorlogger = logging.getLogger(__name__)diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.pyindex 46cb554db8..c6db354049 100644--- a/autogpt_platform/backend/backend/executor/manager.py+++ b/autogpt_platform/backend/backend/executor/manager.py@@ -725,13 +725,9 @@ class ExecutionManager(AppService):return settings.config.execution_manager_portdef run_service(self):- from autogpt_libs.supabase_integration_credentials_store import (- SupabaseIntegrationCredentialsStore,- )+ from backend.integrations.credentials_store import IntegrationCredentialsStore- self.credentials_store = SupabaseIntegrationCredentialsStore(- redis=redis.get_redis()- )+ self.credentials_store = IntegrationCredentialsStore()self.executor = ProcessPoolExecutor(max_workers=self.pool_size,initializer=Executor.on_graph_executor_start,diff --git a/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/store.py b/autogpt_platform/backend/backend/integrations/credentials_store.pysimilarity index 98%rename from autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/store.pyrename to autogpt_platform/backend/backend/integrations/credentials_store.pyindex c4167b3173..7d539b73c4 100644--- a/autogpt_platform/autogpt_libs/autogpt_libs/supabase_integration_credentials_store/store.py+++ b/autogpt_platform/backend/backend/integrations/credentials_store.py@@ -6,20 +6,18 @@ from pydantic import SecretStrif TYPE_CHECKING:from backend.executor.database import DatabaseManager- from redis import Redisfrom autogpt_libs.utils.cache import thread_cachedfrom autogpt_libs.utils.synchronize import RedisKeyedMutex-from backend.util.settings import Settings--from .types import (+from backend.data.model import (APIKeyCredentials,Credentials,OAuth2Credentials,OAuthState,UserIntegrations,)+from backend.util.settings import Settingssettings = Settings()@@ -109,9 +107,11 @@ DEFAULT_CREDENTIALS = []-class SupabaseIntegrationCredentialsStore:- def __init__(self, redis: "Redis"):- self.locks = RedisKeyedMutex(redis)+class IntegrationCredentialsStore:+ def __init__(self):+ from backend.data.redis import get_redis++ self.locks = RedisKeyedMutex(get_redis())@property@thread_cacheddiff --git a/autogpt_platform/backend/backend/integrations/creds_manager.py b/autogpt_platform/backend/backend/integrations/creds_manager.pyindex 9898afcc79..7cbf8f4af7 100644--- a/autogpt_platform/backend/backend/integrations/creds_manager.py+++ b/autogpt_platform/backend/backend/integrations/creds_manager.py@@ -2,14 +2,12 @@ import loggingfrom contextlib import contextmanagerfrom datetime import datetime-from autogpt_libs.supabase_integration_credentials_store import (- Credentials,- SupabaseIntegrationCredentialsStore,-)from autogpt_libs.utils.synchronize import RedisKeyedMutexfrom redis.lock import Lock as RedisLockfrom backend.data import redis+from backend.data.model import Credentials+from backend.integrations.credentials_store import IntegrationCredentialsStorefrom backend.integrations.oauth import HANDLERS_BY_NAME, BaseOAuthHandlerfrom backend.util.exceptions import MissingConfigErrorfrom backend.util.settings import Settings@@ -53,7 +51,7 @@ class IntegrationCredentialsManager:def __init__(self):redis_conn = redis.get_redis()self._locks = RedisKeyedMutex(redis_conn)- self.store = SupabaseIntegrationCredentialsStore(redis=redis_conn)+ self.store = IntegrationCredentialsStore()def create(self, user_id: str, credentials: Credentials) -> None:return self.store.add_creds(user_id, credentials)diff --git a/autogpt_platform/backend/backend/integrations/oauth/base.py b/autogpt_platform/backend/backend/integrations/oauth/base.pyindex a12200af65..ad5433d734 100644--- a/autogpt_platform/backend/backend/integrations/oauth/base.py+++ b/autogpt_platform/backend/backend/integrations/oauth/base.py@@ -3,7 +3,7 @@ import timefrom abc import ABC, abstractmethodfrom typing import ClassVar-from autogpt_libs.supabase_integration_credentials_store import OAuth2Credentials+from backend.data.model import OAuth2Credentialslogger = logging.getLogger(__name__)diff --git a/autogpt_platform/backend/backend/integrations/oauth/github.py b/autogpt_platform/backend/backend/integrations/oauth/github.pyindex 402dbe21a9..ed883b6320 100644--- a/autogpt_platform/backend/backend/integrations/oauth/github.py+++ b/autogpt_platform/backend/backend/integrations/oauth/github.py@@ -2,8 +2,7 @@ import timefrom typing import Optionalfrom urllib.parse import urlencode-from autogpt_libs.supabase_integration_credentials_store import OAuth2Credentials-+from backend.data.model import OAuth2Credentialsfrom backend.util.request import requestsfrom .base import BaseOAuthHandlerdiff --git a/autogpt_platform/backend/backend/integrations/oauth/google.py b/autogpt_platform/backend/backend/integrations/oauth/google.pyindex 1f410b5e59..13175b0b46 100644--- a/autogpt_platform/backend/backend/integrations/oauth/google.py+++ b/autogpt_platform/backend/backend/integrations/oauth/google.py@@ -1,6 +1,5 @@import logging-from autogpt_libs.supabase_integration_credentials_store import OAuth2Credentialsfrom google.auth.external_account_authorized_user import (Credentials as ExternalAccountCredentials,)@@ -9,6 +8,8 @@ from google.oauth2.credentials import Credentialsfrom google_auth_oauthlib.flow import Flowfrom pydantic import SecretStr+from backend.data.model import OAuth2Credentials+from .base import BaseOAuthHandlerlogger = logging.getLogger(__name__)diff --git a/autogpt_platform/backend/backend/integrations/oauth/notion.py b/autogpt_platform/backend/backend/integrations/oauth/notion.pyindex 75f7a91eee..7f5458ae9a 100644--- a/autogpt_platform/backend/backend/integrations/oauth/notion.py+++ b/autogpt_platform/backend/backend/integrations/oauth/notion.py@@ -1,8 +1,7 @@from base64 import b64encodefrom urllib.parse import urlencode-from autogpt_libs.supabase_integration_credentials_store import OAuth2Credentials-+from backend.data.model import OAuth2Credentialsfrom backend.util.request import requestsfrom .base import BaseOAuthHandlerdiff --git a/autogpt_platform/backend/backend/integrations/webhooks/base.py b/autogpt_platform/backend/backend/integrations/webhooks/base.pyindex b30f419a03..61a07ce203 100644--- a/autogpt_platform/backend/backend/integrations/webhooks/base.py+++ b/autogpt_platform/backend/backend/integrations/webhooks/base.py@@ -4,11 +4,11 @@ from abc import ABC, abstractmethodfrom typing import ClassVar, Generic, TypeVarfrom uuid import uuid4-from autogpt_libs.supabase_integration_credentials_store import Credentialsfrom fastapi import Requestfrom strenum import StrEnumfrom backend.data import integrations+from backend.data.model import Credentialsfrom backend.util.exceptions import MissingConfigErrorfrom backend.util.settings import Configdiff --git a/autogpt_platform/backend/backend/integrations/webhooks/github.py b/autogpt_platform/backend/backend/integrations/webhooks/github.pyindex 25152caff4..2393437d20 100644--- a/autogpt_platform/backend/backend/integrations/webhooks/github.py+++ b/autogpt_platform/backend/backend/integrations/webhooks/github.py@@ -3,11 +3,11 @@ import hmacimport loggingimport requests-from autogpt_libs.supabase_integration_credentials_store import Credentialsfrom fastapi import HTTPException, Requestfrom strenum import StrEnumfrom backend.data import integrations+from backend.data.model import Credentialsfrom .base import BaseWebhooksManagerdiff --git a/autogpt_platform/backend/backend/integrations/webhooks/graph_lifecycle_hooks.py b/autogpt_platform/backend/backend/integrations/webhooks/graph_lifecycle_hooks.pyindex 1f6351d5fa..363bf535c5 100644--- a/autogpt_platform/backend/backend/integrations/webhooks/graph_lifecycle_hooks.py+++ b/autogpt_platform/backend/backend/integrations/webhooks/graph_lifecycle_hooks.py@@ -7,9 +7,8 @@ from backend.data.model import CREDENTIALS_FIELD_NAMEfrom backend.integrations.webhooks import WEBHOOK_MANAGERS_BY_NAMEif TYPE_CHECKING:- from autogpt_libs.supabase_integration_credentials_store.types import Credentials-from backend.data.graph import GraphModel, NodeModel+ from backend.data.model import Credentialsfrom .base import BaseWebhooksManagerdiff --git a/autogpt_platform/backend/backend/server/integrations/router.py b/autogpt_platform/backend/backend/server/integrations/router.pyindex d18ba5c46e..4220ac3c03 100644--- a/autogpt_platform/backend/backend/server/integrations/router.py+++ b/autogpt_platform/backend/backend/server/integrations/router.py@@ -1,12 +1,6 @@import loggingfrom typing import Annotated, Literal-from autogpt_libs.supabase_integration_credentials_store.types import (- APIKeyCredentials,- Credentials,- CredentialsType,- OAuth2Credentials,-)from fastapi import APIRouter, Body, Depends, HTTPException, Path, Query, Requestfrom pydantic import BaseModel, Field, SecretStr@@ -18,6 +12,12 @@ from backend.data.integrations import (listen_for_webhook_event,publish_webhook_event,)+from backend.data.model import (+ APIKeyCredentials,+ Credentials,+ CredentialsType,+ OAuth2Credentials,+)from backend.executor.manager import ExecutionManagerfrom backend.integrations.creds_manager import IntegrationCredentialsManagerfrom backend.integrations.oauth import HANDLERS_BY_NAME, BaseOAuthHandlerdiff --git a/autogpt_platform/backend/backend/server/routers/v1.py b/autogpt_platform/backend/backend/server/routers/v1.pyindex 31a777a572..c600c067c4 100644--- a/autogpt_platform/backend/backend/server/routers/v1.py+++ b/autogpt_platform/backend/backend/server/routers/v1.py@@ -48,7 +48,7 @@ from backend.util.service import get_service_clientfrom backend.util.settings import Settingsif TYPE_CHECKING:- from autogpt_libs.supabase_integration_credentials_store.types import Credentials+ from backend.data.model import Credentials@thread_cacheddiff --git a/autogpt_platform/backend/test/data/test_credit.py b/autogpt_platform/backend/test/data/test_credit.pyindex 77cef7735f..37236e3467 100644--- a/autogpt_platform/backend/test/data/test_credit.py+++ b/autogpt_platform/backend/test/data/test_credit.py@@ -1,12 +1,12 @@from datetime import datetimeimport pytest-from autogpt_libs.supabase_integration_credentials_store.store import openai_credentialsfrom prisma.models import UserBlockCreditfrom backend.blocks.llm import AITextGeneratorBlockfrom backend.data.credit import UserCreditfrom backend.data.user import DEFAULT_USER_ID+from backend.integrations.credentials_store import openai_credentialsfrom backend.util.test import SpinTestServerREFILL_VALUE = 1000diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.tsindex fc42b49af9..edeb87e556 100644--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts@@ -289,7 +289,7 @@ export type CredentialsMetaInput = {provider: string;};-/* Mirror of autogpt_libs/supabase_integration_credentials_store/types.py:_BaseCredentials */+/* Mirror of backend/backend/data/model.py:_BaseCredentials */type BaseCredentials = {id: string;type: CredentialsType;@@ -297,7 +297,7 @@ type BaseCredentials = {provider: CredentialsProviderName;};-/* Mirror of autogpt_libs/supabase_integration_credentials_store/types.py:OAuth2Credentials */+/* Mirror of backend/backend/data/model.py:OAuth2Credentials */export type OAuth2Credentials = BaseCredentials & {type: "oauth2";scopes: string[];@@ -309,7 +309,7 @@ export type OAuth2Credentials = BaseCredentials & {metadata: Record<string, any>;};-/* Mirror of autogpt_libs/supabase_integration_credentials_store/types.py:APIKeyCredentials */+/* Mirror of backend/backend/data/model.py:APIKeyCredentials */export type APIKeyCredentials = BaseCredentials & {type: "api_key";title: string;diff --git a/docs/content/platform/getting-started.md b/docs/content/platform/getting-started.mdindex b57ff7de8f..3613d014f5 100644--- a/docs/content/platform/getting-started.md+++ b/docs/content/platform/getting-started.md@@ -128,3 +128,21 @@ By default the application for different services run on the following ports:Frontend UI Server: 3000Backend Websocket Server: 8001Execution API Rest Server: 8006++#### Additional Notes++You may want to change your encryption key in the `.env` file in the `autogpt_platform/backend` directory.++To generate a new encryption key, run the following command in python:++```python+from cryptography.fernet import Fernet;Fernet.generate_key().decode()+```++Or run the following command in the `autogpt_platform/backend` directory:++```bash+poetry run cli gen-encrypt-key+```++Then, replace the existing key in the `autogpt_platform/backend/.env` file with the new one.diff --git a/docs/content/platform/new_blocks.md b/docs/content/platform/new_blocks.mdindex faad5e8a9d..623b1d9b52 100644--- a/docs/content/platform/new_blocks.md+++ b/docs/content/platform/new_blocks.md@@ -113,7 +113,7 @@ Implementing the block itself is relatively simple. On top of the instructions ayou're going to add a `credentials` parameter to the `Input` model and the `run` method:```python-from autogpt_libs.supabase_integration_credentials_store.types import (+from backend.data.model import (APIKeyCredentials,OAuth2Credentials,Credentials,