From 8deb0cfd483f8cabf84b43a65bdc7ed1533adfbb Mon Sep 17 00:00:00 2001 From: Mirian Okradze Date: Thu, 30 Nov 2023 12:24:43 +0400 Subject: [PATCH] fix: template agents --- apps/server/controllers/agent.py | 12 +++-- apps/server/models/agent.py | 30 +++++++---- apps/ui/src/pages/Discover/Discover.tsx | 9 +--- apps/ui/src/pages/Home/Home.tsx | 66 +++++++------------------ 4 files changed, 50 insertions(+), 67 deletions(-) diff --git a/apps/server/controllers/agent.py b/apps/server/controllers/agent.py index 8d9f42e48..fc13d8c51 100644 --- a/apps/server/controllers/agent.py +++ b/apps/server/controllers/agent.py @@ -134,7 +134,9 @@ def get_agents( # todo need remove, is depricated @router.get("/discover", response_model=Dict[str, List[AgentWithConfigsOutput]]) def get_template_and_system_agents() -> Dict[str, List[AgentWithConfigsOutput]]: - template_agents = AgentModel.get_template_agents(db=db) + template_agents = AgentModel.get_template_agents( + session=db.session, account_id=None + ) system_agents = AgentModel.get_public_agents(db=db) template_agents_list = convert_agents_to_agent_list(template_agents) @@ -156,8 +158,12 @@ def get_public_agents() -> Dict[str, List[AgentWithConfigsOutput]]: @router.get("/discover/templates", response_model=List[AgentWithConfigsOutput]) -def get_template_agents() -> Dict[str, List[AgentWithConfigsOutput]]: - template_agents = AgentModel.get_template_agents(db=db) +def get_template_agents( + auth: UserAccount = Depends(authenticate), +) -> Dict[str, List[AgentWithConfigsOutput]]: + template_agents = AgentModel.get_template_agents( + session=db.session, account_id=auth.account.id + ) return convert_agents_to_agent_list(template_agents) diff --git a/apps/server/models/agent.py b/apps/server/models/agent.py index 3120830e1..b7cb40a68 100644 --- a/apps/server/models/agent.py +++ b/apps/server/models/agent.py @@ -4,7 +4,8 @@ from typing import List from sqlalchemy import UUID, Boolean, Column, ForeignKey, Index, String, or_ -from sqlalchemy.orm import joinedload, relationship +from sqlalchemy.orm import Session, joinedload, relationship +from sqlalchemy.sql import and_ from exceptions import AgentNotFoundException from models.agent_config import AgentConfigModel @@ -216,17 +217,28 @@ def get_agents(cls, db, account): return agents @classmethod - def get_template_agents(cls, db): + def get_template_agents(cls, session: Session, account_id: UUID): + query = session.query(AgentModel) + + if account_id is not None: + query = query.filter( + or_( + and_( + AgentModel.account_id == account_id, + AgentModel.is_template.is_(True), + ), + AgentModel.is_public.is_(True), + ) + ) + else: + query = query.filter(AgentModel.is_public.is_(True)) + agents = ( - db.session.query(AgentModel) - .filter( - or_(AgentModel.is_deleted.is_(False), AgentModel.is_deleted.is_(None)), - AgentModel.is_template.is_(True), + query.filter( + AgentModel.is_deleted.is_(False), ) .options(joinedload(AgentModel.creator)) - .options( - joinedload(AgentModel.configs) - ) # if you have a relationship set up named "configs" + .options(joinedload(AgentModel.configs)) .all() ) return agents diff --git a/apps/ui/src/pages/Discover/Discover.tsx b/apps/ui/src/pages/Discover/Discover.tsx index 1acebca24..3d3ea46c5 100644 --- a/apps/ui/src/pages/Discover/Discover.tsx +++ b/apps/ui/src/pages/Discover/Discover.tsx @@ -1,10 +1,8 @@ import styled from 'styled-components' import DiscoverTeamAgents from './components/DiscoverTeamAgents' -import DiscoverTemplateAgents from './components/DiscoverTemplateAgents' import { StyledTab, StyledTabListSpan, StyledTabListWrapper } from 'styles/tabStyles.css' -import Tab from '@l3-lib/ui-core/dist/Tab' import TabList from '@l3-lib/ui-core/dist/TabList' import TabPanel from '@l3-lib/ui-core/dist/TabPanel' import TabPanels from '@l3-lib/ui-core/dist/TabPanels' @@ -12,6 +10,7 @@ import TabsContext from '@l3-lib/ui-core/dist/TabsContext' import { t } from 'i18next' import { useState } from 'react' import { useLocation, useNavigate } from 'react-router-dom' +import DiscoverSystemAgents from './components/DiscoverSystemAgents' const Discover = () => { const navigate = useNavigate() @@ -50,14 +49,10 @@ const Discover = () => { - + - - {/* {} */} - - {/* {!user && } */} ) } diff --git a/apps/ui/src/pages/Home/Home.tsx b/apps/ui/src/pages/Home/Home.tsx index b71932637..def4bb768 100644 --- a/apps/ui/src/pages/Home/Home.tsx +++ b/apps/ui/src/pages/Home/Home.tsx @@ -1,26 +1,16 @@ import React from 'react' - import { StyledInnerWrapper } from 'components/Layout/LayoutStyle' - import styled from 'styled-components' - import Agents from 'pages/Agents' - import { AuthContext } from 'contexts' - import DiscoverTeamAgents from 'pages/Discover/components/DiscoverTeamAgents' -import DiscoverTemplateAgents from 'pages/Discover/components/DiscoverTemplateAgents' - import TeamOfAgents from 'pages/TeamOfAgents' import { useTeamOfAgents } from 'pages/TeamOfAgents/useTeamOfAgents' import { useAgents } from 'pages/Agents/useAgents' - - import { useGetAccountModule } from 'utils/useGetAccountModule' import DiscoverSystemAgents from 'pages/Discover/components/DiscoverSystemAgents' const Home = () => { - // const isProduction = import.meta.env.REACT_APP_ENV === 'production' const { user } = React.useContext(AuthContext) const { teamOfAgents } = useTeamOfAgents() @@ -31,40 +21,25 @@ const Home = () => { const agentModules = getHomeModules('agent') return ( - <> - - {/* {!user && } */} - {user ? ( - <> - - {teamModules?.list && - (teamOfAgents?.length > 0 ? : )} - - {agentModules?.list && agentsData?.length > 0 ? ( - - ) : ( - - )} - - - ) : ( - <> - {/* */} - - + + {user ? ( + + {teamModules?.list && + (teamOfAgents?.length > 0 ? : )} + + {agentModules?.list && agentsData?.length > 0 ? ( + + ) : ( - - )} - - + )} + + ) : ( + <> + + + + )} + ) } @@ -81,8 +56,3 @@ const StyledWrapper = styled.div` flex-direction: column; gap: 100px; ` - -const StyledIframe = styled.iframe` - border-radius: 10px; - margin: auto; -`