refactor(sandbox): reorganize sandbox-related imports and rename SandboxFactory to VMFactory for clarity

This commit is contained in:
Harry
2026-01-12 02:07:26 +08:00
parent 9dd0361d0e
commit 51ac23c9f1
12 changed files with 65 additions and 78 deletions

View File

@ -23,7 +23,7 @@ from core.tools.utils.system_encryption import (
decrypt_system_params,
)
from core.virtual_environment.__base.virtual_environment import VirtualEnvironment
from core.virtual_environment.factory import SandboxFactory, SandboxType
from core.virtual_environment.factory import VMFactory, VMType
from extensions.ext_database import db
from models.sandbox import SandboxProvider, SandboxProviderSystemConfig
from services.sandbox.encryption import create_sandbox_config_encrypter, masked_config
@ -172,7 +172,7 @@ class SandboxProviderService:
if model_class:
model_class.model_validate(config)
SandboxFactory.validate(SandboxType(provider_type), config)
VMFactory.validate(VMType(provider_type), config)
@classmethod
def save_config(
@ -334,9 +334,9 @@ class SandboxProviderService:
if not config or not provider_type:
raise ValueError(f"No active sandbox provider for tenant {tenant_id} or system default")
return SandboxFactory.create(
return VMFactory.create(
tenant_id=tenant_id,
sandbox_type=SandboxType(provider_type),
vm_type=VMType(provider_type),
options=dict(config),
environments=environments or {},
)

View File

@ -14,6 +14,7 @@ from core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfig
from core.app.apps.workflow.app_config_manager import WorkflowAppConfigManager
from core.file import File
from core.repositories import DifyCoreRepositoryFactory
from core.sandbox.manager import SandboxManager
from core.variables import Variable
from core.variables.variables import VariableUnion
from core.workflow.entities import WorkflowNodeExecution
@ -703,7 +704,6 @@ class WorkflowService:
if draft_workflow.get_feature(WorkflowFeatures.SANDBOX).enabled:
sandbox = SandboxProviderService.create_sandbox(tenant_id=draft_workflow.tenant_id)
single_step_execution_id = f"single-step-{uuid.uuid4()}"
from core.virtual_environment.sandbox_manager import SandboxManager
SandboxManager.register(single_step_execution_id, sandbox)
variable_pool.system_variables.workflow_execution_id = single_step_execution_id
@ -727,8 +727,6 @@ class WorkflowService:
)
finally:
if single_step_execution_id:
from core.virtual_environment.sandbox_manager import SandboxManager
sandbox = SandboxManager.unregister(single_step_execution_id)
if sandbox:
try: