Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat(asyncify): migrate sandbox config routes (#2233)
cthomas251d2f8ad2f5
diff --git a/letta/server/rest_api/routers/v1/sandbox_configs.py b/letta/server/rest_api/routers/v1/sandbox_configs.pyindex 6ef76a5b4..505e08a3d 100644--- a/letta/server/rest_api/routers/v1/sandbox_configs.py+++ b/letta/server/rest_api/routers/v1/sandbox_configs.py@@ -100,15 +100,15 @@ def delete_sandbox_config(@router.get("/", response_model=List[PydanticSandboxConfig])-def list_sandbox_configs(+async def list_sandbox_configs(limit: int = Query(1000, description="Number of results to return"),after: Optional[str] = Query(None, description="Pagination cursor to fetch the next set of results"),sandbox_type: Optional[SandboxType] = Query(None, description="Filter for this specific sandbox type"),server: SyncServer = Depends(get_letta_server),actor_id: str = Depends(get_user_id),):- actor = server.user_manager.get_user_or_default(user_id=actor_id)- return server.sandbox_config_manager.list_sandbox_configs(actor, limit=limit, after=after, sandbox_type=sandbox_type)+ actor = await server.user_manager.get_actor_or_default_async(actor_id=actor_id)+ return await server.sandbox_config_manager.list_sandbox_configs_async(actor, limit=limit, after=after, sandbox_type=sandbox_type)@router.post("/local/recreate-venv", response_model=PydanticSandboxConfig)@@ -190,12 +190,12 @@ def delete_sandbox_env_var(@router.get("/{sandbox_config_id}/environment-variable", response_model=List[PydanticEnvVar])-def list_sandbox_env_vars(+async def list_sandbox_env_vars(sandbox_config_id: str,limit: int = Query(1000, description="Number of results to return"),after: Optional[str] = Query(None, description="Pagination cursor to fetch the next set of results"),server: SyncServer = Depends(get_letta_server),actor_id: str = Depends(get_user_id),):- actor = server.user_manager.get_user_or_default(user_id=actor_id)- return server.sandbox_config_manager.list_sandbox_env_vars(sandbox_config_id, actor, limit=limit, after=after)+ actor = await server.user_manager.get_actor_or_default_async(actor_id=actor_id)+ return await server.sandbox_config_manager.list_sandbox_env_vars_async(sandbox_config_id, actor, limit=limit, after=after)diff --git a/letta/services/sandbox_config_manager.py b/letta/services/sandbox_config_manager.pyindex 5b25b25ea..0f55a0bc5 100644--- a/letta/services/sandbox_config_manager.py+++ b/letta/services/sandbox_config_manager.py@@ -122,6 +122,23 @@ class SandboxConfigManager:sandboxes = SandboxConfigModel.list(db_session=session, after=after, limit=limit, **kwargs)return [sandbox.to_pydantic() for sandbox in sandboxes]+ @enforce_types+ async def list_sandbox_configs_async(+ self,+ actor: PydanticUser,+ after: Optional[str] = None,+ limit: Optional[int] = 50,+ sandbox_type: Optional[SandboxType] = None,+ ) -> List[PydanticSandboxConfig]:+ """List all sandbox configurations with optional pagination."""+ kwargs = {"organization_id": actor.organization_id}+ if sandbox_type:+ kwargs.update({"type": sandbox_type})++ async with db_registry.async_session() as session:+ sandboxes = await SandboxConfigModel.list_async(db_session=session, after=after, limit=limit, **kwargs)+ return [sandbox.to_pydantic() for sandbox in sandboxes]+@enforce_typesdef get_sandbox_config_by_id(self, sandbox_config_id: str, actor: Optional[PydanticUser] = None) -> Optional[PydanticSandboxConfig]:"""Retrieve a sandbox configuration by its ID."""@@ -224,6 +241,25 @@ class SandboxConfigManager:)return [env_var.to_pydantic() for env_var in env_vars]+ @enforce_types+ async def list_sandbox_env_vars_async(+ self,+ sandbox_config_id: str,+ actor: PydanticUser,+ after: Optional[str] = None,+ limit: Optional[int] = 50,+ ) -> List[PydanticEnvVar]:+ """List all sandbox environment variables with optional pagination."""+ async with db_registry.async_session() as session:+ env_vars = await SandboxEnvVarModel.list_async(+ db_session=session,+ after=after,+ limit=limit,+ organization_id=actor.organization_id,+ sandbox_config_id=sandbox_config_id,+ )+ return [env_var.to_pydantic() for env_var in env_vars]+@enforce_typesdef list_sandbox_env_vars_by_key(self, key: str, actor: PydanticUser, after: Optional[str] = None, limit: Optional[int] = 50