From 250ffdfaed8b6c3fa67057baeb924f007f587c5b Mon Sep 17 00:00:00 2001 From: Krzysztof Czerwinski Date: Wed, 8 Jan 2025 16:25:25 +0100 Subject: [PATCH 1/6] Redirect to Builder after adding to library --- .../backend/backend/server/v2/library/db.py | 117 +++++++++++---- .../backend/server/v2/library/routes.py | 45 +++++- .../src/components/agptui/AgentInfo.tsx | 138 +++++++++++------- .../src/lib/autogpt-server-api/client.ts | 15 +- 4 files changed, 230 insertions(+), 85 deletions(-) diff --git a/autogpt_platform/backend/backend/server/v2/library/db.py b/autogpt_platform/backend/backend/server/v2/library/db.py index 8d142ef40c76..2b6ad1fdfb44 100644 --- a/autogpt_platform/backend/backend/server/v2/library/db.py +++ b/autogpt_platform/backend/backend/server/v2/library/db.py @@ -95,13 +95,14 @@ async def get_library_agents( ) from e -async def add_agent_to_library(store_listing_version_id: str, user_id: str) -> None: +async def get_library_agent( + store_listing_version_id: str, user_id: str +) -> backend.data.graph.Graph | None: """ - Finds the agent from the store listing version and adds it to the user's library (UserAgent table) - if they don't already have it + Get user agent from the store listing version """ logger.debug( - f"Adding agent from store listing version {store_listing_version_id} to library for user {user_id}" + f"Getting agent by store listing version {store_listing_version_id} for user {user_id}" ) try: @@ -122,14 +123,6 @@ async def add_agent_to_library(store_listing_version_id: str, user_id: str) -> N agent = store_listing_version.Agent - if agent.userId == user_id: - logger.warning( - f"User {user_id} cannot add their own agent to their library" - ) - raise backend.server.v2.store.exceptions.DatabaseError( - "Cannot add own agent to library" - ) - # Check if user already has this agent existing_user_agent = await prisma.models.UserAgent.prisma().find_first( where={ @@ -140,26 +133,94 @@ async def add_agent_to_library(store_listing_version_id: str, user_id: str) -> N ) if existing_user_agent: - logger.debug( - f"User {user_id} already has agent {agent.id} in their library" - ) - return - - # Create UserAgent entry - await prisma.models.UserAgent.prisma().create( - data=prisma.types.UserAgentCreateInput( - userId=user_id, - agentId=agent.id, - agentVersion=agent.version, - isCreatedByUser=False, + logger.debug(f"User {user_id} has agent {agent.id} in their library") + return backend.data.graph.Graph( + id=agent.id, + version=agent.version, + is_active=agent.isActive, + name=agent.name or "", + description=agent.description or "", ) - ) - logger.debug(f"Added agent {agent.id} to library for user {user_id}") + + logger.debug(f"User {user_id} does not have agent {agent.id} in their library") + return None except backend.server.v2.store.exceptions.AgentNotFoundError: raise except prisma.errors.PrismaError as e: - logger.error(f"Database error adding agent to library: {str(e)}") + logger.error(f"Database error checking library agent: {str(e)}") raise backend.server.v2.store.exceptions.DatabaseError( - "Failed to add agent to library" + "Failed to check library agent" ) from e + + +# async def add_agent_to_library( +# store_listing_version_id: str, user_id: str +# ) -> backend.data.graph.Graph | None: +# """ +# Finds the agent from the store listing version and adds it to the user's library (UserAgent table) +# if they don't already have it +# """ +# logger.debug( +# f"Adding agent from store listing version {store_listing_version_id} to library for user {user_id}" +# ) + +# try: +# # Get store listing version to find agent +# store_listing_version = ( +# await prisma.models.StoreListingVersion.prisma().find_unique( +# where={"id": store_listing_version_id}, include={"Agent": True} +# ) +# ) + +# if not store_listing_version or not store_listing_version.Agent: +# logger.warning( +# f"Store listing version not found: {store_listing_version_id}" +# ) +# raise backend.server.v2.store.exceptions.AgentNotFoundError( +# f"Store listing version {store_listing_version_id} not found" +# ) + +# agent = store_listing_version.Agent + +# if agent.userId == user_id: +# logger.warning( +# f"User {user_id} cannot add their own agent to their library" +# ) +# raise backend.server.v2.store.exceptions.DatabaseError( +# "Cannot add own agent to library" +# ) + +# # Check if user already has this agent +# existing_user_agent = await prisma.models.UserAgent.prisma().find_first( +# where={ +# "userId": user_id, +# "agentId": agent.id, +# "agentVersion": agent.version, +# } +# ) + +# if existing_user_agent: +# logger.debug( +# f"User {user_id} already has agent {agent.id} in their library" +# ) +# return + +# # Create UserAgent entry +# await prisma.models.UserAgent.prisma().create( +# data=prisma.types.UserAgentCreateInput( +# userId=user_id, +# agentId=agent.id, +# agentVersion=agent.version, +# isCreatedByUser=False, +# ) +# ) +# logger.debug(f"Added agent {agent.id} to library for user {user_id}") + +# except backend.server.v2.store.exceptions.AgentNotFoundError: +# raise +# except prisma.errors.PrismaError as e: +# logger.error(f"Database error adding agent to library: {str(e)}") +# raise backend.server.v2.store.exceptions.DatabaseError( +# "Failed to add agent to library" +# ) from e diff --git a/autogpt_platform/backend/backend/server/v2/library/routes.py b/autogpt_platform/backend/backend/server/v2/library/routes.py index 0c3b1a77ec93..ae456d7f3ff3 100644 --- a/autogpt_platform/backend/backend/server/v2/library/routes.py +++ b/autogpt_platform/backend/backend/server/v2/library/routes.py @@ -43,18 +43,54 @@ async def get_library_agents( ) +@router.get( + "/agents/{store_listing_version_id}", + tags=["library", "private"], + dependencies=[fastapi.Depends(autogpt_libs.auth.middleware.auth_middleware)], +) +async def get_library_agent( + store_listing_version_id: str, + user_id: typing.Annotated[ + str, fastapi.Depends(autogpt_libs.auth.depends.get_user_id) + ], +) -> backend.data.graph.Graph | None: + """ + Get an agent from the user's library by store listing version ID. + + Args: + store_listing_version_id (str): ID of the store listing version to get + user_id (str): ID of the authenticated user + + Returns: + backend.data.graph.Graph: Agent from the user's library + None: If the agent is not found in the user's library + + Raises: + HTTPException: If there is an error getting the agent from the library + """ + try: + agent = await backend.server.v2.library.db.get_library_agent( + store_listing_version_id, user_id + ) + return agent + except Exception: + logger.exception("Exception occurred whilst getting library agent") + raise fastapi.HTTPException( + status_code=500, detail="Failed to get library agent" + ) + + @router.post( "/agents/{store_listing_version_id}", tags=["library", "private"], dependencies=[fastapi.Depends(autogpt_libs.auth.middleware.auth_middleware)], - status_code=201, ) async def add_agent_to_library( store_listing_version_id: str, user_id: typing.Annotated[ str, fastapi.Depends(autogpt_libs.auth.depends.get_user_id) ], -) -> fastapi.Response: +) -> backend.data.graph.Graph | None: """ Add an agent from the store to the user's library. @@ -63,7 +99,8 @@ async def add_agent_to_library( user_id (str): ID of the authenticated user Returns: - fastapi.Response: 201 status code on success + backend.data.graph.Graph: Agent added to the user's library + None: On failure Raises: HTTPException: If there is an error adding the agent to the library @@ -114,7 +151,7 @@ async def add_agent_to_library( ) ) - return fastapi.Response(status_code=201) + return graph except Exception: logger.exception("Exception occurred whilst adding agent to library") diff --git a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx index 03f7d141d7a8..d003cbf7105c 100644 --- a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx +++ b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx @@ -3,13 +3,14 @@ import * as React from "react"; import { IconPlay, StarRatingIcons } from "@/components/ui/icons"; import { Separator } from "@/components/ui/separator"; -import BackendAPI from "@/lib/autogpt-server-api"; +import BackendAPI, { GraphMeta } from "@/lib/autogpt-server-api"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { useToast } from "@/components/ui/use-toast"; import useSupabase from "@/hooks/useSupabase"; import { DownloadIcon, LoaderIcon } from "lucide-react"; +import { useBackendAPI } from "@/lib/autogpt-server-api/context"; interface AgentInfoProps { name: string; creator: string; @@ -36,61 +37,87 @@ export const AgentInfo: React.FC = ({ storeListingVersionId, }) => { const router = useRouter(); - const api = React.useMemo(() => new BackendAPI(), []); + const api = useBackendAPI(); const { user } = useSupabase(); const { toast } = useToast(); + const [userAgent, setAgent] = React.useState(null); + // Either downloading or adding to library + const [processing, setProcessing] = React.useState(false); - const [downloading, setDownloading] = React.useState(false); + React.useEffect(() => { + (async () => { + try { + const agent = await api.getUserLibraryAgent(storeListingVersionId); + setAgent(agent); + } catch (error) { + console.error("Failed to fetch library agent:", error); + } + })(); + }, [api, storeListingVersionId]); + + const handleAddToLibrary = React.useCallback(async () => { + if (!user || userAgent) { + return; + } + + toast({ + title: "Adding to Library", + description: "Adding agent to library and opening builder...", + duration: 2000, + }); + setProcessing(true); - const handleAddToLibrary = async () => { try { - await api.addAgentToLibrary(storeListingVersionId); + const agent = await api.addAgentToLibrary(storeListingVersionId); + if (!agent) { + throw new Error(); + } console.log("Agent added to library successfully"); - router.push("/monitoring"); + router.push(`/builder?flowID=${agent.id}`); } catch (error) { console.error("Failed to add agent to library:", error); } - }; - - const handleDownloadToLibrary = async () => { - const downloadAgent = async (): Promise => { - setDownloading(true); - try { - const file = await api.downloadStoreAgent(storeListingVersionId); - - // Similar to Marketplace v1 - const jsonData = JSON.stringify(file, null, 2); - // Create a Blob from the file content - const blob = new Blob([jsonData], { type: "application/json" }); - - // Create a temporary URL for the Blob - const url = window.URL.createObjectURL(blob); + setProcessing(false); + }, [api, router, storeListingVersionId, toast, user, userAgent]); - // Create a temporary anchor element - const a = document.createElement("a"); - a.href = url; - a.download = `agent_${storeListingVersionId}.json`; // Set the filename - - // Append the anchor to the body, click it, and remove it - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - - // Revoke the temporary URL - window.URL.revokeObjectURL(url); + const handleDownloadToLibrary = React.useCallback(async () => { + setProcessing(true); + try { + const file = await api.downloadStoreAgent(storeListingVersionId); + + // Similar to Marketplace v1 + const jsonData = JSON.stringify(file, null, 2); + // Create a Blob from the file content + const blob = new Blob([jsonData], { type: "application/json" }); + + // Create a temporary URL for the Blob + const url = window.URL.createObjectURL(blob); + + // Create a temporary anchor element + const a = document.createElement("a"); + a.href = url; + a.download = `agent_${storeListingVersionId}.json`; // Set the filename + + // Append the anchor to the body, click it, and remove it + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + + // Revoke the temporary URL + window.URL.revokeObjectURL(url); + + toast({ + title: "Download Complete", + description: "Your agent has been successfully downloaded.", + duration: 2000, + }); + } catch (error) { + console.error(`Error downloading agent:`, error); + throw error; + } - toast({ - title: "Download Complete", - description: "Your agent has been successfully downloaded.", - }); - } catch (error) { - console.error(`Error downloading agent:`, error); - throw error; - } - }; - await downloadAgent(); - setDownloading(false); - }; + setProcessing(false); + }, [api, storeListingVersionId, toast]); return (
@@ -123,29 +150,38 @@ export const AgentInfo: React.FC = ({ ) : ( )} diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/client.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/client.ts index 1f74e67f636a..010b65aaba46 100644 --- a/autogpt_platform/frontend/src/lib/autogpt-server-api/client.ts +++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/client.ts @@ -367,8 +367,19 @@ export default class BackendAPI { return this._get("/library/agents"); } - async addAgentToLibrary(storeListingVersionId: string): Promise { - await this._request("POST", `/library/agents/${storeListingVersionId}`); + getUserLibraryAgent( + storeListingVersionId: string, + ): Promise { + return this._get(`/library/agents/${storeListingVersionId}`); + } + + async addAgentToLibrary( + storeListingVersionId: string, + ): Promise { + return await this._request( + "POST", + `/library/agents/${storeListingVersionId}`, + ); } /////////////////////////////////////////// From 725b38425a679a743c89d855e4b431b8d43ba84a Mon Sep 17 00:00:00 2001 From: Krzysztof Czerwinski Date: Wed, 8 Jan 2025 16:25:33 +0100 Subject: [PATCH 2/6] Remove unused files --- .../marketplace/AgentDetailContent.tsx | 96 ------------------- .../src/components/marketplace/actions.ts | 18 ---- 2 files changed, 114 deletions(-) delete mode 100644 autogpt_platform/frontend/src/components/marketplace/AgentDetailContent.tsx delete mode 100644 autogpt_platform/frontend/src/components/marketplace/actions.ts diff --git a/autogpt_platform/frontend/src/components/marketplace/AgentDetailContent.tsx b/autogpt_platform/frontend/src/components/marketplace/AgentDetailContent.tsx deleted file mode 100644 index cbaa72e9906d..000000000000 --- a/autogpt_platform/frontend/src/components/marketplace/AgentDetailContent.tsx +++ /dev/null @@ -1,96 +0,0 @@ -// "use client"; -// import Link from "next/link"; -// import { ArrowLeft, Download, Calendar, Tag } from "lucide-react"; -// import { Button } from "@/components/ui/button"; -// import BackendAPI, { GraphCreatable } from "@/lib/autogpt-server-api"; -// import "@xyflow/react/dist/style.css"; -// import { useToast } from "../ui/use-toast"; - -// function AgentDetailContent({ agent }: { agent: GraphCreatable }) { -// const { toast } = useToast(); - -// // const downloadAgent = async (id: string): Promise => { -// // const api = new MarketplaceAPI(); -// // try { -// // const file = await api.downloadAgentFile(id); -// // console.debug(`Agent file downloaded:`, file); - -// // // Create a Blob from the file content -// // const blob = new Blob([file], { type: "application/json" }); - -// // // Create a temporary URL for the Blob -// // const url = window.URL.createObjectURL(blob); - -// // // Create a temporary anchor element -// // const a = document.createElement("a"); -// // a.href = url; -// // a.download = `agent_${id}.json`; // Set the filename - -// // // Append the anchor to the body, click it, and remove it -// // document.body.appendChild(a); -// // a.click(); -// // document.body.removeChild(a); - -// // // Revoke the temporary URL -// // window.URL.revokeObjectURL(url); -// // } catch (error) { -// // console.error(`Error downloading agent:`, error); -// // throw error; -// // } -// // }; - -// return ( -//
-//
-// -// -// Back to Marketplace -// -//
-// -//
-//
-//
-//
-//

{agent.name}

-//

-// {agent.description} -//

-//
-//
-//
-//
-//
-// -// Last Updated -//
-//
-// {new Date(agent.updatedAt).toLocaleDateString()} -//
-//
-//
-//
-// -// Categories -//
-//
-// {agent.categories.join(", ")} -//
-//
-//
-//
-//
-//
-// ); -// } - -// export default AgentDetailContent; diff --git a/autogpt_platform/frontend/src/components/marketplace/actions.ts b/autogpt_platform/frontend/src/components/marketplace/actions.ts deleted file mode 100644 index d6ebec32a0b7..000000000000 --- a/autogpt_platform/frontend/src/components/marketplace/actions.ts +++ /dev/null @@ -1,18 +0,0 @@ -// "use server"; - -// import * as Sentry from "@sentry/nextjs"; -// import MarketplaceAPI, { AnalyticsEvent } from "@/lib/marketplace-api"; -// import { checkAuth } from "@/lib/supabase/server"; - -// export async function makeAnalyticsEvent(event: AnalyticsEvent) { -// return await Sentry.withServerActionInstrumentation( -// "makeAnalyticsEvent", -// {}, -// async () => { -// await checkAuth(); -// const apiUrl = process.env.AGPT_SERVER_API_URL; -// const api = new MarketplaceAPI(); -// await api.makeAnalyticsEvent(event); -// }, -// ); -// } From 56affddad796cd38508ad9fbe85cbb0e2ebb7086 Mon Sep 17 00:00:00 2001 From: Krzysztof Czerwinski Date: Wed, 8 Jan 2025 17:26:14 +0100 Subject: [PATCH 3/6] Fix agent check --- autogpt_platform/backend/backend/server/v2/library/db.py | 6 +++--- .../frontend/src/components/agptui/AgentInfo.tsx | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/autogpt_platform/backend/backend/server/v2/library/db.py b/autogpt_platform/backend/backend/server/v2/library/db.py index 2b6ad1fdfb44..f097160581a0 100644 --- a/autogpt_platform/backend/backend/server/v2/library/db.py +++ b/autogpt_platform/backend/backend/server/v2/library/db.py @@ -124,11 +124,11 @@ async def get_library_agent( agent = store_listing_version.Agent # Check if user already has this agent - existing_user_agent = await prisma.models.UserAgent.prisma().find_first( + existing_user_agent = await prisma.models.AgentGraph.prisma().find_first( where={ "userId": user_id, - "agentId": agent.id, - "agentVersion": agent.version, + "id": agent.id, + "version": agent.version, } ) diff --git a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx index d003cbf7105c..bd271a61f70b 100644 --- a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx +++ b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx @@ -45,14 +45,18 @@ export const AgentInfo: React.FC = ({ const [processing, setProcessing] = React.useState(false); React.useEffect(() => { - (async () => { + console.log("Fetching library agent..."); + const fetchAgent = async () => { try { + console.log("Trying..."); const agent = await api.getUserLibraryAgent(storeListingVersionId); setAgent(agent); + console.log("Fetched agent:", agent); } catch (error) { console.error("Failed to fetch library agent:", error); } - })(); + }; + fetchAgent(); }, [api, storeListingVersionId]); const handleAddToLibrary = React.useCallback(async () => { From 266cac057bfe1592cbcf8228d422781b1b4d4f69 Mon Sep 17 00:00:00 2001 From: Krzysztof Czerwinski Date: Wed, 8 Jan 2025 18:29:07 +0100 Subject: [PATCH 4/6] Update --- .../backend/backend/server/v2/library/db.py | 140 +++++++++--------- .../src/components/agptui/AgentInfo.tsx | 16 +- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/autogpt_platform/backend/backend/server/v2/library/db.py b/autogpt_platform/backend/backend/server/v2/library/db.py index f097160581a0..c8e225095c75 100644 --- a/autogpt_platform/backend/backend/server/v2/library/db.py +++ b/autogpt_platform/backend/backend/server/v2/library/db.py @@ -154,73 +154,73 @@ async def get_library_agent( ) from e -# async def add_agent_to_library( -# store_listing_version_id: str, user_id: str -# ) -> backend.data.graph.Graph | None: -# """ -# Finds the agent from the store listing version and adds it to the user's library (UserAgent table) -# if they don't already have it -# """ -# logger.debug( -# f"Adding agent from store listing version {store_listing_version_id} to library for user {user_id}" -# ) - -# try: -# # Get store listing version to find agent -# store_listing_version = ( -# await prisma.models.StoreListingVersion.prisma().find_unique( -# where={"id": store_listing_version_id}, include={"Agent": True} -# ) -# ) - -# if not store_listing_version or not store_listing_version.Agent: -# logger.warning( -# f"Store listing version not found: {store_listing_version_id}" -# ) -# raise backend.server.v2.store.exceptions.AgentNotFoundError( -# f"Store listing version {store_listing_version_id} not found" -# ) - -# agent = store_listing_version.Agent - -# if agent.userId == user_id: -# logger.warning( -# f"User {user_id} cannot add their own agent to their library" -# ) -# raise backend.server.v2.store.exceptions.DatabaseError( -# "Cannot add own agent to library" -# ) - -# # Check if user already has this agent -# existing_user_agent = await prisma.models.UserAgent.prisma().find_first( -# where={ -# "userId": user_id, -# "agentId": agent.id, -# "agentVersion": agent.version, -# } -# ) - -# if existing_user_agent: -# logger.debug( -# f"User {user_id} already has agent {agent.id} in their library" -# ) -# return - -# # Create UserAgent entry -# await prisma.models.UserAgent.prisma().create( -# data=prisma.types.UserAgentCreateInput( -# userId=user_id, -# agentId=agent.id, -# agentVersion=agent.version, -# isCreatedByUser=False, -# ) -# ) -# logger.debug(f"Added agent {agent.id} to library for user {user_id}") - -# except backend.server.v2.store.exceptions.AgentNotFoundError: -# raise -# except prisma.errors.PrismaError as e: -# logger.error(f"Database error adding agent to library: {str(e)}") -# raise backend.server.v2.store.exceptions.DatabaseError( -# "Failed to add agent to library" -# ) from e +async def add_agent_to_library( + store_listing_version_id: str, user_id: str +) -> backend.data.graph.Graph | None: + """ + Finds the agent from the store listing version and adds it to the user's library (UserAgent table) + if they don't already have it + """ + logger.debug( + f"Adding agent from store listing version {store_listing_version_id} to library for user {user_id}" + ) + + try: + # Get store listing version to find agent + store_listing_version = ( + await prisma.models.StoreListingVersion.prisma().find_unique( + where={"id": store_listing_version_id}, include={"Agent": True} + ) + ) + + if not store_listing_version or not store_listing_version.Agent: + logger.warning( + f"Store listing version not found: {store_listing_version_id}" + ) + raise backend.server.v2.store.exceptions.AgentNotFoundError( + f"Store listing version {store_listing_version_id} not found" + ) + + agent = store_listing_version.Agent + + if agent.userId == user_id: + logger.warning( + f"User {user_id} cannot add their own agent to their library" + ) + raise backend.server.v2.store.exceptions.DatabaseError( + "Cannot add own agent to library" + ) + + # Check if user already has this agent + existing_user_agent = await prisma.models.UserAgent.prisma().find_first( + where={ + "userId": user_id, + "agentId": agent.id, + "agentVersion": agent.version, + } + ) + + if existing_user_agent: + logger.debug( + f"User {user_id} already has agent {agent.id} in their library" + ) + return + + # Create UserAgent entry + await prisma.models.UserAgent.prisma().create( + data=prisma.types.UserAgentCreateInput( + userId=user_id, + agentId=agent.id, + agentVersion=agent.version, + isCreatedByUser=False, + ) + ) + logger.debug(f"Added agent {agent.id} to library for user {user_id}") + + except backend.server.v2.store.exceptions.AgentNotFoundError: + raise + except prisma.errors.PrismaError as e: + logger.error(f"Database error adding agent to library: {str(e)}") + raise backend.server.v2.store.exceptions.DatabaseError( + "Failed to add agent to library" + ) from e diff --git a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx index bd271a61f70b..93cde8207e7e 100644 --- a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx +++ b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx @@ -9,7 +9,7 @@ import Link from "next/link"; import { useToast } from "@/components/ui/use-toast"; import useSupabase from "@/hooks/useSupabase"; -import { DownloadIcon, LoaderIcon } from "lucide-react"; +import { DownloadIcon, LoaderIcon, CheckIcon } from "lucide-react"; import { useBackendAPI } from "@/lib/autogpt-server-api/context"; interface AgentInfoProps { name: string; @@ -40,18 +40,15 @@ export const AgentInfo: React.FC = ({ const api = useBackendAPI(); const { user } = useSupabase(); const { toast } = useToast(); - const [userAgent, setAgent] = React.useState(null); + const [userAgent, setUserAgent] = React.useState(null); // Either downloading or adding to library const [processing, setProcessing] = React.useState(false); React.useEffect(() => { - console.log("Fetching library agent..."); const fetchAgent = async () => { try { - console.log("Trying..."); const agent = await api.getUserLibraryAgent(storeListingVersionId); - setAgent(agent); - console.log("Fetched agent:", agent); + setUserAgent(agent); } catch (error) { console.error("Failed to fetch library agent:", error); } @@ -77,7 +74,7 @@ export const AgentInfo: React.FC = ({ throw new Error(); } console.log("Agent added to library successfully"); - router.push(`/builder?flowID=${agent.id}`); + router.push(`/build?flowID=${agent.id}`); } catch (error) { console.error("Failed to add agent to library:", error); } @@ -159,7 +156,10 @@ export const AgentInfo: React.FC = ({ {processing ? ( ) : ( - + userAgent ? ( + + ) : ( + ) )} {processing From fb773fbb83ead1566319a35e7d3c5f566d060b18 Mon Sep 17 00:00:00 2001 From: Krzysztof Czerwinski Date: Thu, 9 Jan 2025 16:39:38 +0100 Subject: [PATCH 5/6] Lint --- .../frontend/src/components/agptui/AgentInfo.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx index 93cde8207e7e..dfe8f38f7694 100644 --- a/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx +++ b/autogpt_platform/frontend/src/components/agptui/AgentInfo.tsx @@ -155,11 +155,10 @@ export const AgentInfo: React.FC = ({ > {processing ? ( - ) : ( - userAgent ? ( + ) : userAgent ? ( - ) : ( - ) + ) : ( + )} {processing From 5ee23cc8cf070f20de6992889d40f049f24c15b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Czerwinski Date: Sat, 11 Jan 2025 15:58:52 +0100 Subject: [PATCH 6/6] Fix `add_store_agent_to_library` --- .../backend/backend/server/v2/library/db.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/server/v2/library/db.py b/autogpt_platform/backend/backend/server/v2/library/db.py index fa370f9e91a9..c8d24d3ebc7f 100644 --- a/autogpt_platform/backend/backend/server/v2/library/db.py +++ b/autogpt_platform/backend/backend/server/v2/library/db.py @@ -265,7 +265,13 @@ async def add_store_agent_to_library( logger.debug( f"User {user_id} already has agent {agent.id} in their library" ) - return existing_user_agent.Agent + return backend.data.graph.Graph( + id=agent.id, + version=agent.version, + is_active=agent.isActive, + name=agent.name or "", + description=agent.description or "", + ) # Create LibraryAgent entry library_agent = await prisma.models.LibraryAgent.prisma().create( @@ -277,7 +283,13 @@ async def add_store_agent_to_library( ) ) logger.debug(f"Added agent {agent.id} to library for user {user_id}") - return library_agent.Agent + return backend.data.graph.Graph( + id=library_agent.agentId, + version=library_agent.agentVersion, + is_active=agent.isActive, + name=agent.name or "", + description=agent.description or "", + ) except backend.server.v2.store.exceptions.AgentNotFoundError: raise