Removendo arquivos __pycache__ do controle de versão
This commit is contained in:
parent
3c3b9cfa9f
commit
8816c9aafd
2
.env
2
.env
@ -1,6 +1,6 @@
|
|||||||
OPENAI_API_KEY=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
|
OPENAI_API_KEY=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
|
||||||
|
|
||||||
POSTGRES_CONNECTION_STRING=postgresql://postgres:root@localhost:5432/google-a2a-saas
|
POSTGRES_CONNECTION_STRING=postgresql://postgres:root@localhost:5432/evo_ai
|
||||||
|
|
||||||
TENANT_ID=45cffb85-51c8-41ed-aa8d-710970a7ce50
|
TENANT_ID=45cffb85-51c8-41ed-aa8d-710970a7ce50
|
||||||
KNOWLEDGE_API_URL=http://localhost:5540
|
KNOWLEDGE_API_URL=http://localhost:5540
|
||||||
|
@ -9,3 +9,4 @@ python-dotenv
|
|||||||
google-adk
|
google-adk
|
||||||
litellm
|
litellm
|
||||||
python-multipart
|
python-multipart
|
||||||
|
alembic
|
@ -3,9 +3,9 @@ from sqlalchemy.ext.declarative import declarative_base
|
|||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from src.config.settings import settings
|
from src.config.settings import settings
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = settings.POSTGRES_CONNECTION_STRING
|
POSTGRES_CONNECTION_STRING = settings.POSTGRES_CONNECTION_STRING
|
||||||
|
|
||||||
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
engine = create_engine(POSTGRES_CONNECTION_STRING)
|
||||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
@ -13,7 +13,7 @@ class Settings(BaseSettings):
|
|||||||
# Configurações do banco de dados
|
# Configurações do banco de dados
|
||||||
POSTGRES_CONNECTION_STRING: str = os.getenv(
|
POSTGRES_CONNECTION_STRING: str = os.getenv(
|
||||||
"POSTGRES_CONNECTION_STRING",
|
"POSTGRES_CONNECTION_STRING",
|
||||||
"postgresql://postgres:root@localhost:5432/google-a2a-saas"
|
"postgresql://postgres:root@localhost:5432/evo_ai"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Configurações do OpenAI
|
# Configurações do OpenAI
|
||||||
|
@ -26,7 +26,7 @@ app = FastAPI(
|
|||||||
# Configuração do PostgreSQL
|
# Configuração do PostgreSQL
|
||||||
POSTGRES_CONNECTION_STRING = os.getenv(
|
POSTGRES_CONNECTION_STRING = os.getenv(
|
||||||
"POSTGRES_CONNECTION_STRING",
|
"POSTGRES_CONNECTION_STRING",
|
||||||
"postgresql://postgres:root@localhost:5432/google-a2a-saas"
|
"postgresql://postgres:root@localhost:5432/evo_ai"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Criar as tabelas no banco de dados
|
# Criar as tabelas no banco de dados
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from sqlalchemy import Column, String, UUID, DateTime, ForeignKey, JSON, Text, BigInteger, CheckConstraint
|
from sqlalchemy import Column, String, UUID, DateTime, ForeignKey, JSON, Text, BigInteger, CheckConstraint, Boolean
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from src.config.database import Base
|
from src.config.database import Base
|
||||||
import uuid
|
import uuid
|
||||||
@ -35,3 +35,30 @@ class Agent(Base):
|
|||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
CheckConstraint("type IN ('llm', 'sequential', 'parallel', 'loop')", name='check_agent_type'),
|
CheckConstraint("type IN ('llm', 'sequential', 'parallel', 'loop')", name='check_agent_type'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class MCPServer(Base):
|
||||||
|
__tablename__ = "mcp_servers"
|
||||||
|
|
||||||
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
|
name = Column(String, nullable=False)
|
||||||
|
description = Column(Text, nullable=True)
|
||||||
|
config_json = Column(JSON, nullable=False, default={})
|
||||||
|
environments = Column(JSON, nullable=False, default={})
|
||||||
|
type = Column(String, nullable=False, default="official")
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
CheckConstraint("type IN ('official', 'community')", name='check_mcp_server_type'),
|
||||||
|
)
|
||||||
|
|
||||||
|
class Tool(Base):
|
||||||
|
__tablename__ = "tools"
|
||||||
|
|
||||||
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
|
name = Column(String, nullable=False)
|
||||||
|
description = Column(Text, nullable=True)
|
||||||
|
config_json = Column(JSON, nullable=False, default={})
|
||||||
|
environments = Column(JSON, nullable=False, default={})
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
@ -1,35 +1,124 @@
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
from fastapi import HTTPException, status
|
||||||
from src.models.models import Agent
|
from src.models.models import Agent
|
||||||
from src.schemas.schemas import AgentCreate
|
from src.schemas.schemas import AgentCreate
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
import uuid
|
import uuid
|
||||||
|
import logging
|
||||||
|
|
||||||
def get_agent(db: Session, agent_id: uuid.UUID) -> Agent:
|
logger = logging.getLogger(__name__)
|
||||||
return db.query(Agent).filter(Agent.id == agent_id).first()
|
|
||||||
|
|
||||||
def get_agents_by_client(db: Session, client_id: uuid.UUID, skip: int = 0, limit: int = 100) -> List[Agent]:
|
def get_agent(db: Session, agent_id: uuid.UUID) -> Optional[Agent]:
|
||||||
return db.query(Agent).filter(Agent.client_id == client_id).offset(skip).limit(limit).all()
|
"""Busca um agente pelo ID"""
|
||||||
|
try:
|
||||||
|
agent = db.query(Agent).filter(Agent.id == agent_id).first()
|
||||||
|
if not agent:
|
||||||
|
logger.warning(f"Agente não encontrado: {agent_id}")
|
||||||
|
return None
|
||||||
|
return agent
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
logger.error(f"Erro ao buscar agente {agent_id}: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Erro ao buscar agente"
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_agents_by_client(
|
||||||
|
db: Session,
|
||||||
|
client_id: uuid.UUID,
|
||||||
|
skip: int = 0,
|
||||||
|
limit: int = 100,
|
||||||
|
active_only: bool = True
|
||||||
|
) -> List[Agent]:
|
||||||
|
"""Busca agentes de um cliente com paginação"""
|
||||||
|
try:
|
||||||
|
query = db.query(Agent).filter(Agent.client_id == client_id)
|
||||||
|
|
||||||
|
if active_only:
|
||||||
|
query = query.filter(Agent.is_active == True)
|
||||||
|
|
||||||
|
return query.offset(skip).limit(limit).all()
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
logger.error(f"Erro ao buscar agentes do cliente {client_id}: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Erro ao buscar agentes"
|
||||||
|
)
|
||||||
|
|
||||||
def create_agent(db: Session, agent: AgentCreate) -> Agent:
|
def create_agent(db: Session, agent: AgentCreate) -> Agent:
|
||||||
|
"""Cria um novo agente"""
|
||||||
|
try:
|
||||||
db_agent = Agent(**agent.model_dump())
|
db_agent = Agent(**agent.model_dump())
|
||||||
db.add(db_agent)
|
db.add(db_agent)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(db_agent)
|
db.refresh(db_agent)
|
||||||
|
logger.info(f"Agente criado com sucesso: {db_agent.id}")
|
||||||
return db_agent
|
return db_agent
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
db.rollback()
|
||||||
|
logger.error(f"Erro ao criar agente: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Erro ao criar agente"
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_agent(db: Session, agent_id: uuid.UUID, agent: AgentCreate) -> Optional[Agent]:
|
||||||
|
"""Atualiza um agente existente"""
|
||||||
|
try:
|
||||||
|
db_agent = get_agent(db, agent_id)
|
||||||
|
if not db_agent:
|
||||||
|
return None
|
||||||
|
|
||||||
def update_agent(db: Session, agent_id: uuid.UUID, agent: AgentCreate) -> Agent:
|
|
||||||
db_agent = db.query(Agent).filter(Agent.id == agent_id).first()
|
|
||||||
if db_agent:
|
|
||||||
for key, value in agent.model_dump().items():
|
for key, value in agent.model_dump().items():
|
||||||
setattr(db_agent, key, value)
|
setattr(db_agent, key, value)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(db_agent)
|
db.refresh(db_agent)
|
||||||
|
logger.info(f"Agente atualizado com sucesso: {agent_id}")
|
||||||
return db_agent
|
return db_agent
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
db.rollback()
|
||||||
|
logger.error(f"Erro ao atualizar agente {agent_id}: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Erro ao atualizar agente"
|
||||||
|
)
|
||||||
|
|
||||||
def delete_agent(db: Session, agent_id: uuid.UUID) -> bool:
|
def delete_agent(db: Session, agent_id: uuid.UUID) -> bool:
|
||||||
db_agent = db.query(Agent).filter(Agent.id == agent_id).first()
|
"""Remove um agente (soft delete)"""
|
||||||
if db_agent:
|
try:
|
||||||
db.delete(db_agent)
|
db_agent = get_agent(db, agent_id)
|
||||||
db.commit()
|
if not db_agent:
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
db_agent.is_active = False
|
||||||
|
db.commit()
|
||||||
|
logger.info(f"Agente desativado com sucesso: {agent_id}")
|
||||||
|
return True
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
db.rollback()
|
||||||
|
logger.error(f"Erro ao desativar agente {agent_id}: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Erro ao desativar agente"
|
||||||
|
)
|
||||||
|
|
||||||
|
def activate_agent(db: Session, agent_id: uuid.UUID) -> bool:
|
||||||
|
"""Reativa um agente"""
|
||||||
|
try:
|
||||||
|
db_agent = get_agent(db, agent_id)
|
||||||
|
if not db_agent:
|
||||||
|
return False
|
||||||
|
|
||||||
|
db_agent.is_active = True
|
||||||
|
db.commit()
|
||||||
|
logger.info(f"Agente reativado com sucesso: {agent_id}")
|
||||||
|
return True
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
db.rollback()
|
||||||
|
logger.error(f"Erro ao reativar agente {agent_id}: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Erro ao reativar agente"
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user