mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
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
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
"""App assets storage key generation.
|
|
|
|
Provides AssetPaths facade for generating storage keys for app assets.
|
|
Storage instances are obtained via AppAssetService.get_storage().
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from uuid import UUID
|
|
|
|
_BASE = "app_assets"
|
|
|
|
|
|
def _check_uuid(value: str, name: str) -> None:
|
|
try:
|
|
UUID(value)
|
|
except (ValueError, TypeError) as e:
|
|
raise ValueError(f"{name} must be a valid UUID") from e
|
|
|
|
|
|
class AssetPaths:
|
|
"""Facade for generating app asset storage keys."""
|
|
|
|
@staticmethod
|
|
def draft(tenant_id: str, app_id: str, node_id: str) -> str:
|
|
"""app_assets/{tenant}/{app}/draft/{node_id}"""
|
|
_check_uuid(tenant_id, "tenant_id")
|
|
_check_uuid(app_id, "app_id")
|
|
_check_uuid(node_id, "node_id")
|
|
return f"{_BASE}/{tenant_id}/{app_id}/draft/{node_id}"
|
|
|
|
@staticmethod
|
|
def build_zip(tenant_id: str, app_id: str, assets_id: str) -> str:
|
|
"""app_assets/{tenant}/{app}/artifacts/{assets_id}.zip"""
|
|
_check_uuid(tenant_id, "tenant_id")
|
|
_check_uuid(app_id, "app_id")
|
|
_check_uuid(assets_id, "assets_id")
|
|
return f"{_BASE}/{tenant_id}/{app_id}/artifacts/{assets_id}.zip"
|
|
|
|
@staticmethod
|
|
def skill_bundle(tenant_id: str, app_id: str, assets_id: str) -> str:
|
|
"""app_assets/{tenant}/{app}/artifacts/{assets_id}/skill_artifact_set.json"""
|
|
_check_uuid(tenant_id, "tenant_id")
|
|
_check_uuid(app_id, "app_id")
|
|
_check_uuid(assets_id, "assets_id")
|
|
return f"{_BASE}/{tenant_id}/{app_id}/artifacts/{assets_id}/skill_artifact_set.json"
|
|
|
|
@staticmethod
|
|
def source_zip(tenant_id: str, app_id: str, workflow_id: str) -> str:
|
|
"""app_assets/{tenant}/{app}/sources/{workflow_id}.zip"""
|
|
_check_uuid(tenant_id, "tenant_id")
|
|
_check_uuid(app_id, "app_id")
|
|
_check_uuid(workflow_id, "workflow_id")
|
|
return f"{_BASE}/{tenant_id}/{app_id}/sources/{workflow_id}.zip"
|
|
|
|
@staticmethod
|
|
def bundle_export(tenant_id: str, app_id: str, export_id: str) -> str:
|
|
"""app_assets/{tenant}/{app}/bundle_exports/{export_id}.zip"""
|
|
_check_uuid(tenant_id, "tenant_id")
|
|
_check_uuid(app_id, "app_id")
|
|
_check_uuid(export_id, "export_id")
|
|
return f"{_BASE}/{tenant_id}/{app_id}/bundle_exports/{export_id}.zip"
|
|
|
|
@staticmethod
|
|
def bundle_import(tenant_id: str, import_id: str) -> str:
|
|
"""app_assets/{tenant}/imports/{import_id}.zip"""
|
|
_check_uuid(tenant_id, "tenant_id")
|
|
return f"{_BASE}/{tenant_id}/imports/{import_id}.zip"
|