mirror of
				https://github.com/microsoft/autogen.git
				synced 2025-10-31 17:59:50 +00:00 
			
		
		
		
	 fe96f7de24
			
		
	
	
		fe96f7de24
		
			
		
	
	
	
	
		
			
			* fix import issue related to agentchat update #4245 * update uv lock file * fix db auto_upgrade logic issue. * im prove msg rendering issue * Support termination condition combination. Closes #4325 * fix db instantiation bug * update yarn.lock, closes #4260 #4262 * remove deps for now with vulnerabilities found by dependabot #4262 * update db tests * add ability to load sessions from db .. * format updates, add format checks to ags * format check fixes * linting and ruff check fixes * make tests for ags non-parrallel to avoid db race conditions. * format updates * fix concurrency issue * minor ui tweaks, move run start to websocket * lint fixes * update uv.lock * Update python/packages/autogen-studio/autogenstudio/datamodel/types.py Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> * Update python/packages/autogen-studio/autogenstudio/teammanager.py Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> * reuse user proxy from agentchat * ui tweaks --------- Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> Co-authored-by: Hussein Mozannar <hmozannar@microsoft.com>
		
			
				
	
	
		
			110 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # api/initialization.py
 | |
| import os
 | |
| from pathlib import Path
 | |
| from typing import Dict
 | |
| 
 | |
| from dotenv import load_dotenv
 | |
| from loguru import logger
 | |
| from pydantic import BaseModel
 | |
| 
 | |
| from .config import Settings
 | |
| 
 | |
| 
 | |
| class _AppPaths(BaseModel):
 | |
|     """Internal model representing all application paths"""
 | |
| 
 | |
|     app_root: Path
 | |
|     static_root: Path
 | |
|     user_files: Path
 | |
|     ui_root: Path
 | |
|     config_dir: Path
 | |
|     database_uri: str
 | |
| 
 | |
| 
 | |
| class AppInitializer:
 | |
|     """Handles application initialization including paths and environment setup"""
 | |
| 
 | |
|     def __init__(self, settings: Settings, app_path: str):
 | |
|         """
 | |
|         Initialize the application structure.
 | |
| 
 | |
|         Args:
 | |
|             settings: Application settings
 | |
|             app_path: Path to the application code directory
 | |
|         """
 | |
|         self.settings = settings
 | |
|         self._app_path = Path(app_path)
 | |
|         self._paths = self._init_paths()
 | |
|         self._create_directories()
 | |
|         self._load_environment()
 | |
|         logger.info(f"Initialized application data folder: {self.app_root}")
 | |
| 
 | |
|     def _get_app_root(self) -> Path:
 | |
|         """Determine application root directory"""
 | |
|         if app_dir := os.getenv("AUTOGENSTUDIO_APPDIR"):
 | |
|             return Path(app_dir)
 | |
|         return Path.home() / ".autogenstudio"
 | |
| 
 | |
|     def _get_database_uri(self, app_root: Path) -> str:
 | |
|         """Generate database URI based on settings or environment"""
 | |
|         if db_uri := os.getenv("AUTOGENSTUDIO_DATABASE_URI"):
 | |
|             return db_uri
 | |
|         return self.settings.DATABASE_URI.replace("./", str(app_root) + "/")
 | |
| 
 | |
|     def _init_paths(self) -> _AppPaths:
 | |
|         """Initialize and return AppPaths instance"""
 | |
|         app_root = self._get_app_root()
 | |
|         return _AppPaths(
 | |
|             app_root=app_root,
 | |
|             static_root=app_root / "files",
 | |
|             user_files=app_root / "files" / "user",
 | |
|             ui_root=self._app_path / "ui",
 | |
|             config_dir=app_root / self.settings.CONFIG_DIR,
 | |
|             database_uri=self._get_database_uri(app_root),
 | |
|         )
 | |
| 
 | |
|     def _create_directories(self) -> None:
 | |
|         """Create all required directories"""
 | |
|         self.app_root.mkdir(parents=True, exist_ok=True)
 | |
|         dirs = [self.static_root, self.user_files, self.ui_root, self.config_dir]
 | |
|         for path in dirs:
 | |
|             path.mkdir(parents=True, exist_ok=True)
 | |
| 
 | |
|     def _load_environment(self) -> None:
 | |
|         """Load environment variables from .env file if it exists"""
 | |
|         env_file = self.app_root / ".env"
 | |
|         if env_file.exists():
 | |
|             logger.info(f"Loading environment variables from {env_file}")
 | |
|             load_dotenv(str(env_file))
 | |
| 
 | |
|     # Properties for accessing paths
 | |
|     @property
 | |
|     def app_root(self) -> Path:
 | |
|         """Root directory for the application"""
 | |
|         return self._paths.app_root
 | |
| 
 | |
|     @property
 | |
|     def static_root(self) -> Path:
 | |
|         """Directory for static files"""
 | |
|         return self._paths.static_root
 | |
| 
 | |
|     @property
 | |
|     def user_files(self) -> Path:
 | |
|         """Directory for user files"""
 | |
|         return self._paths.user_files
 | |
| 
 | |
|     @property
 | |
|     def ui_root(self) -> Path:
 | |
|         """Directory for UI files"""
 | |
|         return self._paths.ui_root
 | |
| 
 | |
|     @property
 | |
|     def config_dir(self) -> Path:
 | |
|         """Directory for configuration files"""
 | |
|         return self._paths.config_dir
 | |
| 
 | |
|     @property
 | |
|     def database_uri(self) -> str:
 | |
|         """Database connection URI"""
 | |
|         return self._paths.database_uri
 |