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
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
import logging
|
|
|
|
from core.app_assets.storage import AssetPaths
|
|
from core.skill.entities.skill_bundle import SkillBundle
|
|
from extensions.ext_redis import redis_client
|
|
from services.app_asset_service import AppAssetService
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_CACHE_PREFIX = "skill_bundle"
|
|
_CACHE_TTL = 86400 # 24 hours
|
|
|
|
|
|
class SkillManager:
|
|
@staticmethod
|
|
def load_bundle(tenant_id: str, app_id: str, assets_id: str) -> SkillBundle:
|
|
cache_key = f"{_CACHE_PREFIX}:{tenant_id}:{app_id}:{assets_id}"
|
|
data = redis_client.get(cache_key)
|
|
if data:
|
|
return SkillBundle.model_validate_json(data)
|
|
|
|
key = AssetPaths.skill_bundle(tenant_id, app_id, assets_id)
|
|
try:
|
|
data = AppAssetService.get_storage().load_once(key)
|
|
except FileNotFoundError:
|
|
logger.exception(
|
|
"Skill bundle not found in storage: key=%s, tenant_id=%s, app_id=%s, assets_id=%s",
|
|
key,
|
|
tenant_id,
|
|
app_id,
|
|
assets_id,
|
|
)
|
|
raise
|
|
bundle = SkillBundle.model_validate_json(data)
|
|
redis_client.setex(cache_key, _CACHE_TTL, bundle.model_dump_json(indent=2).encode("utf-8"))
|
|
return bundle
|
|
|
|
@staticmethod
|
|
def save_bundle(tenant_id: str, app_id: str, assets_id: str, bundle: SkillBundle) -> None:
|
|
key = AssetPaths.skill_bundle(tenant_id, app_id, assets_id)
|
|
AppAssetService.get_storage().save(key, data=bundle.model_dump_json(indent=2).encode("utf-8"))
|
|
cache_key = f"{_CACHE_PREFIX}:{tenant_id}:{app_id}:{assets_id}"
|
|
redis_client.delete(cache_key)
|