mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
refactor(sandbox): remove unused SANDBOX_WORK_DIR constant and update bash command descriptions for clarity
This commit is contained in:
parent
201a18d6ba
commit
1082d73355
@ -3,7 +3,6 @@ from core.sandbox.constants import (
|
||||
DIFY_CLI_CONFIG_PATH,
|
||||
DIFY_CLI_PATH,
|
||||
DIFY_CLI_PATH_PATTERN,
|
||||
SANDBOX_WORK_DIR,
|
||||
)
|
||||
from core.sandbox.dify_cli import (
|
||||
DifyCliBinary,
|
||||
@ -19,7 +18,6 @@ __all__ = [
|
||||
"DIFY_CLI_CONFIG_PATH",
|
||||
"DIFY_CLI_PATH",
|
||||
"DIFY_CLI_PATH_PATTERN",
|
||||
"SANDBOX_WORK_DIR",
|
||||
"DifyCliBinary",
|
||||
"DifyCliConfig",
|
||||
"DifyCliEnvConfig",
|
||||
|
||||
@ -33,18 +33,18 @@ class SandboxBashTool(Tool):
|
||||
parameters=[
|
||||
ToolParameter.get_simple_instance(
|
||||
name="command",
|
||||
llm_description="The bash command to execute in the sandbox environment",
|
||||
llm_description="The bash command to execute in current working directory",
|
||||
typ=ToolParameter.ToolParameterType.STRING,
|
||||
required=True,
|
||||
),
|
||||
],
|
||||
description=ToolDescription(
|
||||
human=I18nObject(
|
||||
en_US="Execute bash commands in the sandbox environment",
|
||||
en_US="Execute bash commands in current working directory",
|
||||
),
|
||||
llm="Execute bash commands in the sandbox environment. "
|
||||
llm="Execute bash commands in current working directory. "
|
||||
"Use this tool to run shell commands, scripts, or interact with the system. "
|
||||
"The command will be executed in an isolated sandbox environment.",
|
||||
"The command will be executed in the current working directory.",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
from typing import Final
|
||||
|
||||
SANDBOX_WORK_DIR: Final[str] = "work"
|
||||
|
||||
DIFY_CLI_PATH: Final[str] = f"{SANDBOX_WORK_DIR}/.dify/bin/dify"
|
||||
DIFY_CLI_PATH: Final[str] = ".dify/bin/dify"
|
||||
|
||||
DIFY_CLI_PATH_PATTERN: Final[str] = "dify-cli-{os}-{arch}"
|
||||
|
||||
DIFY_CLI_CONFIG_PATH: Final[str] = f"{SANDBOX_WORK_DIR}/.dify_cli.json"
|
||||
DIFY_CLI_CONFIG_PATH: Final[str] = ".dify_cli.json"
|
||||
|
||||
@ -12,8 +12,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class SandboxInitializer(ABC):
|
||||
@abstractmethod
|
||||
def initialize(self, env: VirtualEnvironment) -> None:
|
||||
...
|
||||
def initialize(self, env: VirtualEnvironment) -> None: ...
|
||||
|
||||
|
||||
class DifyCliInitializer(SandboxInitializer):
|
||||
|
||||
@ -197,7 +197,7 @@ class DaytonaEnvironment(VirtualEnvironment):
|
||||
stderr_stream = QueueTransportReadCloser()
|
||||
pid = uuid4().hex
|
||||
|
||||
working_dir = cwd or self._working_dir
|
||||
working_dir = self._workspace_path(cwd) if cwd else self._working_dir
|
||||
|
||||
thread = threading.Thread(
|
||||
target=self._exec_thread,
|
||||
|
||||
@ -461,7 +461,7 @@ class DockerDaemonEnvironment(VirtualEnvironment):
|
||||
raise RuntimeError("Docker container ID is not available for exec.")
|
||||
api_client = self.get_docker_api_client(self.get_docker_sock())
|
||||
|
||||
working_dir = cwd or self._working_dir
|
||||
working_dir = self._container_path(cwd) if cwd else self._working_dir
|
||||
|
||||
exec_info: dict[str, object] = cast(
|
||||
dict[str, object],
|
||||
|
||||
@ -216,7 +216,7 @@ class E2BEnvironment(VirtualEnvironment):
|
||||
stdout_stream = QueueTransportReadCloser()
|
||||
stderr_stream = QueueTransportReadCloser()
|
||||
|
||||
working_dir = cwd or self._WORKDIR
|
||||
working_dir = os.path.join(self._WORKDIR, cwd) if cwd else self._WORKDIR
|
||||
|
||||
threading.Thread(
|
||||
target=self._cmd_thread,
|
||||
|
||||
@ -177,7 +177,7 @@ class LocalVirtualEnvironment(VirtualEnvironment):
|
||||
environments: Mapping[str, str] | None = None,
|
||||
cwd: str | None = None,
|
||||
) -> tuple[str, TransportWriteCloser, TransportReadCloser, TransportReadCloser]:
|
||||
working_path = cwd or self.get_working_path()
|
||||
working_path = os.path.join(self.get_working_path(), cwd) if cwd else self.get_working_path()
|
||||
stdin_read_fd, stdin_write_fd = os.pipe()
|
||||
stdout_read_fd, stdout_write_fd = os.pipe()
|
||||
stderr_read_fd, stderr_write_fd = os.pipe()
|
||||
|
||||
@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from core.agent.entities import AgentLog, AgentResult, AgentToolEntity, ExecutionContext
|
||||
from core.agent.entities import AgentEntity, AgentLog, AgentResult, AgentToolEntity, ExecutionContext
|
||||
from core.agent.patterns import StrategyFactory
|
||||
from core.app.entities.app_invoke_entities import ModelConfigWithCredentialsEntity
|
||||
from core.file import File, FileTransferMethod, FileType, file_manager
|
||||
@ -1610,6 +1610,7 @@ class LLMNode(Node[LLMNodeData]):
|
||||
tools=[sandbox_session.bash_tool],
|
||||
files=prompt_files,
|
||||
max_iterations=self._node_data.max_iterations or 100,
|
||||
agent_strategy=AgentEntity.Strategy.CHAIN_OF_THOUGHT,
|
||||
context=ExecutionContext(user_id=self.user_id, app_id=self.app_id, tenant_id=self.tenant_id),
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user