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): Unbreak `add_marketplace_agent_to_library` (#9578)
Reinier van der Leer231775f4d457
diff --git a/autogpt_platform/backend/backend/data/includes.py b/autogpt_platform/backend/backend/data/includes.pyindex 0b791f502a..badf7804f2 100644--- a/autogpt_platform/backend/backend/data/includes.py+++ b/autogpt_platform/backend/backend/data/includes.py@@ -32,3 +32,15 @@ GRAPH_EXECUTION_INCLUDE: prisma.types.AgentGraphExecutionInclude = {INTEGRATION_WEBHOOK_INCLUDE: prisma.types.IntegrationWebhookInclude = {"AgentNodes": {"include": AGENT_NODE_INCLUDE} # type: ignore}+++def library_agent_include(user_id: str) -> prisma.types.LibraryAgentInclude:+ return {+ "Agent": {+ "include": {+ **AGENT_GRAPH_INCLUDE,+ "AgentGraphExecution": {"where": {"userId": user_id}},+ }+ },+ "Creator": True,+ }diff --git a/autogpt_platform/backend/backend/server/v2/library/db.py b/autogpt_platform/backend/backend/server/v2/library/db.pyindex ae4f151347..59ca701914 100644--- a/autogpt_platform/backend/backend/server/v2/library/db.py+++ b/autogpt_platform/backend/backend/server/v2/library/db.py@@ -9,12 +9,12 @@ import prisma.modelsimport prisma.typesimport backend.data.graph-import backend.data.includesimport backend.server.modelimport backend.server.v2.library.model as library_modelimport backend.server.v2.store.exceptions as store_exceptionsimport backend.server.v2.store.image_gen as store_image_genimport backend.server.v2.store.media as store_media+from backend.data.includes import library_agent_includefrom backend.util.settings import Configlogger = logging.getLogger(__name__)@@ -92,15 +92,7 @@ async def list_library_agents(try:library_agents = await prisma.models.LibraryAgent.prisma().find_many(where=where_clause,- include={- "Agent": {- "include": {- **backend.data.includes.AGENT_GRAPH_INCLUDE,- "AgentGraphExecution": {"where": {"userId": user_id}},- }- },- "Creator": True,- },+ include=library_agent_include(user_id),order=order_by,skip=(page - 1) * page_size,take=page_size,@@ -151,15 +143,7 @@ async def get_library_agent(id: str, user_id: str) -> library_model.LibraryAgent"userId": user_id,"isDeleted": False,},- include={- "Agent": {- "include": {- **backend.data.includes.AGENT_GRAPH_INCLUDE,- "AgentGraphExecution": {"where": {"userId": user_id}},- }- },- "Creator": True,- },+ include=library_agent_include(user_id),)if not library_agent:@@ -391,8 +375,8 @@ async def add_store_agent_to_library(f"Store listing version {store_listing_version_id} not found or invalid")- store_agent = store_listing_version.Agent- if store_agent.userId == user_id:+ graph = store_listing_version.Agent+ if graph.userId == user_id:logger.warning(f"User #{user_id} attempted to add their own agent to their library")@@ -402,13 +386,14 @@ async def add_store_agent_to_library(existing_library_agent = await prisma.models.LibraryAgent.prisma().find_first(where={"userId": user_id,- "agentId": store_agent.id,- "agentVersion": store_agent.version,- }+ "agentId": graph.id,+ "agentVersion": graph.version,+ },+ include=library_agent_include(user_id),)if existing_library_agent:logger.debug(- f"User #{user_id} already has agent #{store_agent.id} in their library"+ f"User #{user_id} already has graph #{graph.id} in their library")return library_model.LibraryAgent.from_db(existing_library_agent)@@ -416,12 +401,16 @@ async def add_store_agent_to_library(added_agent = await prisma.models.LibraryAgent.prisma().create(data={"userId": user_id,- "agentId": store_agent.id,- "agentVersion": store_agent.version,+ "Agent": {+ "connect": {+ "graphVersionId": {"id": graph.id, "version": graph.version}+ },+ },"isCreatedByUser": False,- }+ },+ include=library_agent_include(user_id),)- logger.debug(f"Added agent #{store_agent.id} to library for user #{user_id}")+ logger.debug(f"Added agent #{graph.id} to library for user #{user_id}")return library_model.LibraryAgent.from_db(added_agent)except store_exceptions.AgentNotFoundError:diff --git a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsxindex c039419513..ec96f0cfb4 100644--- a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx+++ b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx@@ -48,7 +48,7 @@ export const AgentInfo: React.FC<AgentInfoProps> = ({storeListingVersionId,);console.log("Agent added to library successfully");- router.push(`/library/agents/${newLibraryAgent.agent_id}`);+ router.push(`/library/agents/${newLibraryAgent.id}`);} catch (error) {console.error("Failed to add agent to library:", error);}