mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-08 22:05:08 -05:00
Update
This commit is contained in:
@@ -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}"
|
||||
# )
|
||||
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}
|
||||
# )
|
||||
# )
|
||||
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"
|
||||
# )
|
||||
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
|
||||
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"
|
||||
# )
|
||||
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,
|
||||
# }
|
||||
# )
|
||||
# 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
|
||||
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}")
|
||||
# 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
|
||||
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
|
||||
|
||||
@@ -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<AgentInfoProps> = ({
|
||||
const api = useBackendAPI();
|
||||
const { user } = useSupabase();
|
||||
const { toast } = useToast();
|
||||
const [userAgent, setAgent] = React.useState<GraphMeta | null>(null);
|
||||
const [userAgent, setUserAgent] = React.useState<GraphMeta | null>(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<AgentInfoProps> = ({
|
||||
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<AgentInfoProps> = ({
|
||||
{processing ? (
|
||||
<LoaderIcon className="h-5 w-5 animate-spin text-white sm:h-5 sm:w-5 lg:h-6 lg:w-6" />
|
||||
) : (
|
||||
<IconPlay className="h-5 w-5 text-white sm:h-5 sm:w-5 lg:h-6 lg:w-6" />
|
||||
userAgent ? (
|
||||
<CheckIcon className="h-5 w-5 text-white sm:h-5 sm:w-5 lg:h-6 lg:w-6" />
|
||||
) : (
|
||||
<IconPlay className="h-5 w-5 text-white sm:h-5 sm:w-5 lg:h-6 lg:w-6" />)
|
||||
)}
|
||||
<span className="font-poppins text-base font-medium text-neutral-50 sm:text-lg">
|
||||
{processing
|
||||
|
||||
Reference in New Issue
Block a user