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
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
from core.skill.entities.skill_metadata import ToolReference
|
|
from core.tools.entities.tool_entities import ToolProviderType
|
|
|
|
|
|
class ToolDependency(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
type: ToolProviderType
|
|
provider: str
|
|
tool_name: str
|
|
enabled: bool = True
|
|
|
|
def tool_id(self) -> str:
|
|
return f"{self.provider}.{self.tool_name}"
|
|
|
|
|
|
class ToolDependencies(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
dependencies: list[ToolDependency] = Field(default_factory=list)
|
|
references: list[ToolReference] = Field(default_factory=list)
|
|
|
|
def is_empty(self) -> bool:
|
|
return not self.dependencies and not self.references
|
|
|
|
def filter(self, tools: list[tuple[str, str]]) -> "ToolDependencies":
|
|
tool_names = {f"{provider}.{tool_name}" for provider, tool_name in tools}
|
|
return ToolDependencies(
|
|
dependencies=[
|
|
dependency
|
|
for dependency in self.dependencies
|
|
if f"{dependency.provider}.{dependency.tool_name}" in tool_names
|
|
],
|
|
references=[
|
|
reference
|
|
for reference in self.references
|
|
if f"{reference.provider}.{reference.tool_name}" in tool_names
|
|
],
|
|
)
|
|
|
|
def merge(self, other: "ToolDependencies") -> "ToolDependencies":
|
|
dep_map: dict[str, ToolDependency] = {}
|
|
for dep in self.dependencies:
|
|
key = f"{dep.provider}.{dep.tool_name}"
|
|
dep_map[key] = dep
|
|
for dep in other.dependencies:
|
|
key = f"{dep.provider}.{dep.tool_name}"
|
|
if key not in dep_map:
|
|
dep_map[key] = dep
|
|
|
|
ref_map: dict[str, ToolReference] = {}
|
|
for ref in self.references:
|
|
ref_map[ref.uuid] = ref
|
|
for ref in other.references:
|
|
if ref.uuid not in ref_map:
|
|
ref_map[ref.uuid] = ref
|
|
|
|
return ToolDependencies(
|
|
dependencies=list(dep_map.values()),
|
|
references=list(ref_map.values()),
|
|
)
|
|
|
|
def remove_tools(self, tools: list[ToolDependency]) -> "ToolDependencies":
|
|
tool_keys = {f"{tool.provider}.{tool.tool_name}" for tool in tools}
|
|
return ToolDependencies(
|
|
dependencies=[
|
|
dependency
|
|
for dependency in self.dependencies
|
|
if f"{dependency.provider}.{dependency.tool_name}" not in tool_keys
|
|
],
|
|
references=[
|
|
reference
|
|
for reference in self.references
|
|
if f"{reference.provider}.{reference.tool_name}" not in tool_keys
|
|
],
|
|
)
|