feat(sandbox): enhance sandbox initialization with draft support and asset management

- Introduced DraftAppAssetsInitializer for handling draft assets.
- Updated SandboxLayer to conditionally set sandbox ID and storage based on workflow version.
- Improved asset initialization logging and error handling.
- Refactored ArchiveSandboxStorage to support exclusion patterns during archiving.
- Modified command and LLM nodes to retrieve sandbox from workflow context, supporting draft workflows.
This commit is contained in:
Harry
2026-01-20 19:44:20 +08:00
parent da6fdc963c
commit 18a589003e
8 changed files with 114 additions and 369 deletions

View File

@ -18,10 +18,19 @@ ARCHIVE_DOWNLOAD_TIMEOUT = 60 * 5
ARCHIVE_UPLOAD_TIMEOUT = 60 * 5
def build_tar_exclude_args(patterns: list[str]) -> list[str]:
return [f"--exclude={p}" for p in patterns]
class ArchiveSandboxStorage(SandboxStorage):
def __init__(self, tenant_id: str, sandbox_id: str):
_tenant_id: str
_sandbox_id: str
_exclude_patterns: list[str]
def __init__(self, tenant_id: str, sandbox_id: str, exclude_patterns: list[str] | None = None):
self._tenant_id = tenant_id
self._sandbox_id = sandbox_id
self._exclude_patterns = exclude_patterns or []
@property
def _storage_key(self) -> str:
@ -36,7 +45,7 @@ class ArchiveSandboxStorage(SandboxStorage):
try:
(
pipeline(sandbox)
.add(["wget", download_url, "-O", ARCHIVE_NAME], error_message="Failed to download archive")
.add(["wget", "-q", download_url, "-O", ARCHIVE_NAME], error_message="Failed to download archive")
.add(["tar", "-xzf", ARCHIVE_NAME], error_message="Failed to extract archive")
.add(["rm", ARCHIVE_NAME], error_message="Failed to cleanup archive")
.execute(timeout=ARCHIVE_DOWNLOAD_TIMEOUT, raise_on_error=True)
@ -53,10 +62,22 @@ class ArchiveSandboxStorage(SandboxStorage):
(
pipeline(sandbox)
.add(
["tar", "-czf", ARCHIVE_PATH, "--warning=no-file-changed", "-C", WORKSPACE_DIR, "."],
[
"tar",
"-czf",
ARCHIVE_PATH,
"--warning=no-file-changed",
*build_tar_exclude_args(self._exclude_patterns),
"-C",
WORKSPACE_DIR,
".",
],
error_message="Failed to create archive",
)
.add(["wget", upload_url, "-O", ARCHIVE_PATH], error_message="Failed to upload archive")
.add(
["curl", "-s", "-f", "-X", "PUT", "-T", ARCHIVE_PATH, upload_url],
error_message="Failed to upload archive",
)
.execute(timeout=ARCHIVE_UPLOAD_TIMEOUT, raise_on_error=True)
)
logger.info("Unmounted archive for sandbox %s", self._sandbox_id)