dify/api/extensions/storage/storage_wrapper.py
Yansong Zhang 0c7e7e0c4e feat(api): port Sandbox + VirtualEnvironment + Skill system from feat/support-agent-sandbox (Phase 5-6)
Port the complete infrastructure for agent sandbox execution and skill system:

Sandbox & Virtual Environment (core/sandbox/, core/virtual_environment/):
- Sandbox entity with lifecycle management (ready/failed/cancelled states)
- SandboxBuilder with fluent API for configuring providers
- 5 VM providers: Local, SSH, Docker, E2B, AWS CodeInterpreter
- VirtualEnvironment base with command execution, file transfer, transport layers
- Channel transport: pipe, queue, socket implementations
- Bash session management and DifyCli binary integration
- Storage: archive storage, file storage, noop storage, presign storage
- Initializers: DifyCli, AppAssets, DraftAppAssets, Skills
- Inspector: file browser, archive/runtime source, script utils
- Security: encryption utils, debug helpers

Skill & App Assets (core/skill/, core/app_assets/, core/app_bundle/):
- Skill entity and manager
- App asset accessor, builder pipeline (file, skill builders)
- App bundle source zip extractor
- Storage and converter utilities

API Endpoints:
- CLI API blueprint (controllers/cli_api/) for sandbox callback
- Sandbox provider management (workspace/sandbox_providers)
- Sandbox file browser (console/sandbox_files)
- App asset management (console/app/app_asset)
- Skill management (console/app/skills)
- Storage file endpoints (controllers/files/storage_files)

Services:
- Sandbox service, provider service, file service
- App asset service, app bundle service

Config:
- CliApiConfig, CreatorsPlatformConfig, CollaborationConfig
- FILES_API_URL for sandbox file access

Note: Controller route registration temporarily commented out (marked TODO)
pending resolution of deep dependency chains (socketio, workflow_comment,
command node, etc.). Core sandbox modules are fully ported and syntax-validated.
110 files changed, 10,549 insertions.

Made-with: Cursor
2026-04-08 17:39:02 +08:00

67 lines
2.2 KiB
Python

"""Base class for storage wrappers that delegate to an inner storage."""
from collections.abc import Generator
from extensions.storage.base_storage import BaseStorage
class StorageWrapper(BaseStorage):
"""Base class for storage wrappers using the decorator pattern.
Forwards all BaseStorage methods to the wrapped storage by default.
Subclasses can override specific methods to customize behavior.
Example:
class MyCustomStorage(StorageWrapper):
def save(self, filename: str, data: bytes):
# Custom logic before save
super().save(filename, data)
# Custom logic after save
"""
def __init__(self, storage: BaseStorage):
super().__init__()
self._storage = storage
def save(self, filename: str, data: bytes):
self._storage.save(filename, data)
def load_once(self, filename: str) -> bytes:
return self._storage.load_once(filename)
def load_stream(self, filename: str) -> Generator:
return self._storage.load_stream(filename)
def download(self, filename: str, target_filepath: str):
self._storage.download(filename, target_filepath)
def exists(self, filename: str) -> bool:
return self._storage.exists(filename)
def delete(self, filename: str):
self._storage.delete(filename)
def scan(self, path: str, files: bool = True, directories: bool = False) -> list[str]:
return self._storage.scan(path, files=files, directories=directories)
def get_download_url(
self,
filename: str,
expires_in: int = 3600,
*,
download_filename: str | None = None,
) -> str:
return self._storage.get_download_url(filename, expires_in, download_filename=download_filename)
def get_download_urls(
self,
filenames: list[str],
expires_in: int = 3600,
*,
download_filenames: list[str] | None = None,
) -> list[str]:
return self._storage.get_download_urls(filenames, expires_in, download_filenames=download_filenames)
def get_upload_url(self, filename: str, expires_in: int = 3600) -> str:
return self._storage.get_upload_url(filename, expires_in)