mirror of
https://github.com/cpacker/MemGPT.git
synced 2025-06-03 04:30:22 +00:00
feat: Add sandbox_type filter when listing sandbox configurations (#567)
This commit is contained in:
parent
46e1fe61b7
commit
23bc188270
@ -69,11 +69,12 @@ def delete_sandbox_config(
|
|||||||
def list_sandbox_configs(
|
def list_sandbox_configs(
|
||||||
limit: int = Query(1000, description="Number of results to return"),
|
limit: int = Query(1000, description="Number of results to return"),
|
||||||
cursor: Optional[str] = Query(None, description="Pagination cursor to fetch the next set of results"),
|
cursor: 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),
|
server: SyncServer = Depends(get_letta_server),
|
||||||
user_id: str = Depends(get_user_id),
|
user_id: str = Depends(get_user_id),
|
||||||
):
|
):
|
||||||
actor = server.user_manager.get_user_or_default(user_id=user_id)
|
actor = server.user_manager.get_user_or_default(user_id=user_id)
|
||||||
return server.sandbox_config_manager.list_sandbox_configs(actor, limit=limit, cursor=cursor)
|
return server.sandbox_config_manager.list_sandbox_configs(actor, limit=limit, cursor=cursor, sandbox_type=sandbox_type)
|
||||||
|
|
||||||
|
|
||||||
### Sandbox Environment Variable Routes
|
### Sandbox Environment Variable Routes
|
||||||
|
@ -111,16 +111,15 @@ class SandboxConfigManager:
|
|||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def list_sandbox_configs(
|
def list_sandbox_configs(
|
||||||
self, actor: PydanticUser, cursor: Optional[str] = None, limit: Optional[int] = 50
|
self, actor: PydanticUser, cursor: Optional[str] = None, limit: Optional[int] = 50, sandbox_type: Optional[SandboxType] = None
|
||||||
) -> List[PydanticSandboxConfig]:
|
) -> List[PydanticSandboxConfig]:
|
||||||
"""List all sandbox configurations with optional pagination."""
|
"""List all sandbox configurations with optional pagination."""
|
||||||
|
kwargs = {"organization_id": actor.organization_id}
|
||||||
|
if sandbox_type:
|
||||||
|
kwargs.update({"type": sandbox_type})
|
||||||
|
|
||||||
with self.session_maker() as session:
|
with self.session_maker() as session:
|
||||||
sandboxes = SandboxConfigModel.list(
|
sandboxes = SandboxConfigModel.list(db_session=session, cursor=cursor, limit=limit, **kwargs)
|
||||||
db_session=session,
|
|
||||||
cursor=cursor,
|
|
||||||
limit=limit,
|
|
||||||
organization_id=actor.organization_id,
|
|
||||||
)
|
|
||||||
return [sandbox.to_pydantic() for sandbox in sandboxes]
|
return [sandbox.to_pydantic() for sandbox in sandboxes]
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
|
@ -2057,16 +2057,16 @@ def test_get_sandbox_config_by_type(server: SyncServer, sandbox_config_fixture,
|
|||||||
|
|
||||||
def test_list_sandbox_configs(server: SyncServer, default_user):
|
def test_list_sandbox_configs(server: SyncServer, default_user):
|
||||||
# Creating multiple sandbox configs
|
# Creating multiple sandbox configs
|
||||||
config_a = SandboxConfigCreate(
|
config_e2b_create = SandboxConfigCreate(
|
||||||
config=E2BSandboxConfig(),
|
config=E2BSandboxConfig(),
|
||||||
)
|
)
|
||||||
config_b = SandboxConfigCreate(
|
config_local_create = SandboxConfigCreate(
|
||||||
config=LocalSandboxConfig(sandbox_dir=""),
|
config=LocalSandboxConfig(sandbox_dir=""),
|
||||||
)
|
)
|
||||||
server.sandbox_config_manager.create_or_update_sandbox_config(config_a, actor=default_user)
|
config_e2b = server.sandbox_config_manager.create_or_update_sandbox_config(config_e2b_create, actor=default_user)
|
||||||
if USING_SQLITE:
|
if USING_SQLITE:
|
||||||
time.sleep(CREATE_DELAY_SQLITE)
|
time.sleep(CREATE_DELAY_SQLITE)
|
||||||
server.sandbox_config_manager.create_or_update_sandbox_config(config_b, actor=default_user)
|
config_local = server.sandbox_config_manager.create_or_update_sandbox_config(config_local_create, actor=default_user)
|
||||||
|
|
||||||
# List configs without pagination
|
# List configs without pagination
|
||||||
configs = server.sandbox_config_manager.list_sandbox_configs(actor=default_user)
|
configs = server.sandbox_config_manager.list_sandbox_configs(actor=default_user)
|
||||||
@ -2080,6 +2080,15 @@ def test_list_sandbox_configs(server: SyncServer, default_user):
|
|||||||
assert len(next_page) == 1
|
assert len(next_page) == 1
|
||||||
assert next_page[0].id != paginated_configs[0].id
|
assert next_page[0].id != paginated_configs[0].id
|
||||||
|
|
||||||
|
# List configs using sandbox_type filter
|
||||||
|
configs = server.sandbox_config_manager.list_sandbox_configs(actor=default_user, sandbox_type=SandboxType.E2B)
|
||||||
|
assert len(configs) == 1
|
||||||
|
assert configs[0].id == config_e2b.id
|
||||||
|
|
||||||
|
configs = server.sandbox_config_manager.list_sandbox_configs(actor=default_user, sandbox_type=SandboxType.LOCAL)
|
||||||
|
assert len(configs) == 1
|
||||||
|
assert configs[0].id == config_local.id
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
# SandboxConfigManager Tests - Environment Variables
|
# SandboxConfigManager Tests - Environment Variables
|
||||||
|
Loading…
Reference in New Issue
Block a user