This commit is contained in:
marko-kraemer 2025-04-24 04:34:45 +01:00
parent b4ac29f366
commit 7325559d26
3 changed files with 31 additions and 8 deletions

View File

@ -6,7 +6,7 @@ from agentpress.thread_manager import ThreadManager
from services.supabase import DBConnection
from datetime import datetime, timezone
from dotenv import load_dotenv
from utils.config import config
from utils.config import config, EnvMode
import asyncio
from utils.logger import logger
import uuid
@ -112,9 +112,20 @@ app = FastAPI(lifespan=lifespan)
# logger.info(f"New connection from IP {client_ip}. Total connections: {len(ip_tracker)}")
# return await call_next(request)
# Define allowed origins based on environment
allowed_origins = ["https://www.suna.so", "https://suna.so", "https://staging.suna.so"]
# Add staging-specific origins
if config.ENV_MODE == EnvMode.STAGING:
allowed_origins.append("http://localhost:3000")
# Add local-specific origins
if config.ENV_MODE == EnvMode.LOCAL:
allowed_origins.append("http://localhost:3000")
app.add_middleware(
CORSMiddleware,
allow_origins=["https://www.suna.so", "https://suna.so", "https://staging.suna.so", "http://localhost:3000"], #http://localhost:3000
allow_origins=allowed_origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["Content-Type", "Authorization"],
@ -126,7 +137,7 @@ app.include_router(agent_api.router, prefix="/api")
# Include the sandbox router with a prefix
app.include_router(sandbox_api.router, prefix="/api")
@app.get("/api/health-check")
@app.get("/api/")
async def health_check():
"""Health check endpoint to verify API is working."""
logger.info("Health check endpoint called")

View File

@ -1,5 +1,5 @@
"""
Configuration management for AgentPress backend.
Configuration management.
This module provides a centralized way to access configuration settings and
environment variables across the application. It supports different environment
@ -52,7 +52,7 @@ class Configuration:
AWS_REGION_NAME: Optional[str] = None
# Model configuration
MODEL_TO_USE: str = "claude-3-haiku-20240307"
MODEL_TO_USE: str = "anthropic/claude-3-7-sonnet-latest"
# Supabase configuration
SUPABASE_URL: Optional[str] = None
@ -82,7 +82,7 @@ class Configuration:
# Open Router configuration
OR_SITE_URL: Optional[str] = None
OR_APP_NAME: Optional[str] = "AgentPress"
OR_APP_NAME: Optional[str] = "Suna.so"
def __init__(self):
"""Initialize configuration by loading from environment variables."""

View File

@ -19,6 +19,8 @@ from functools import wraps
import traceback
from logging.handlers import RotatingFileHandler
from utils.config import config, EnvMode
# Context variable for request correlation ID
request_id: ContextVar[str] = ContextVar('request_id', default='')
@ -64,7 +66,12 @@ def setup_logger(name: str = 'agentpress') -> logging.Logger:
logging.Logger: Configured logger instance
"""
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
# Set console logging level based on environment
if config.ENV_MODE == EnvMode.PRODUCTION:
logger.setLevel(logging.WARNING)
else:
logger.setLevel(logging.INFO)
# Create logs directory if it doesn't exist
log_dir = 'logs'
@ -83,7 +90,12 @@ def setup_logger(name: str = 'agentpress') -> logging.Logger:
# Console handler
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.DEBUG)
# Set console logging level based on environment
if config.ENV_MODE == EnvMode.PRODUCTION:
console_handler.setLevel(logging.INFO)
else:
console_handler.setLevel(logging.DEBUG)
# Create formatters
file_formatter = logging.Formatter(