mirror of
https://github.com/langgenius/dify.git
synced 2026-07-15 09:27:36 +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
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from core.sandbox.sandbox import Sandbox
|
|
from core.skill import SkillAttrs
|
|
from core.skill.skill_manager import SkillManager
|
|
|
|
from .base import SandboxInitializeContext, SyncSandboxInitializer
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SkillInitializer(SyncSandboxInitializer):
|
|
"""Ensure ``sandbox.attrs[BUNDLE]`` is populated for downstream consumers.
|
|
|
|
In the draft path ``DraftAppAssetsInitializer`` already sets the
|
|
bundle on attrs from the in-memory build result, so this initializer
|
|
becomes a no-op. In the published path no prior initializer sets
|
|
it, so we fall back to ``SkillManager.load_bundle()`` (Redis/S3).
|
|
"""
|
|
|
|
def initialize(self, sandbox: Sandbox, ctx: SandboxInitializeContext) -> None:
|
|
# Draft path: bundle already populated by DraftAppAssetsInitializer.
|
|
if sandbox.attrs.has(SkillAttrs.BUNDLE):
|
|
return
|
|
|
|
# Published path: load from Redis/S3.
|
|
bundle = SkillManager.load_bundle(
|
|
ctx.tenant_id,
|
|
ctx.app_id,
|
|
ctx.assets_id,
|
|
)
|
|
sandbox.attrs.set(SkillAttrs.BUNDLE, bundle)
|