Files
agent-zero/api/delete_work_dir_files.py
Jan Tomášek 188cff2073 Move optional runtimes into persistent gVisor plugin sandboxes
Move tunnel, browser, document, speech and integration runtimes into plugin-owned
sandboxes with lazy dependencies and instance-scoped lifecycle management.
Reuse Tuxee display assets and the sandbox image's Python/Node runtimes, enable
automatic Desktop login, and show elapsed time for each browser launch.

Slim the outer image, use offline ONNX embeddings, and calculate sandbox storage
only on demand. Include regression coverage and updated runtime documentation.
Exclude local handoff notes and temporary verification artifacts from publication.
2026-11-08 21:43:22 +01:00

82 lines
2.3 KiB
Python

from helpers.api import ApiHandler, Input, Output, Request
from helpers.file_browser import FileBrowser
from helpers import extension
from api import get_work_dir_files
from helpers.file_archives import normalize_paths
class DeleteWorkDirFiles(ApiHandler):
async def process(self, input: Input, request: Request) -> Output:
try:
paths = normalize_paths(input.get("paths", []))
except ValueError as exc:
return {"error": str(exc)}
current_path = input.get("currentPath", "")
if not paths:
return {"error": "No file paths provided"}
result = await delete_files(paths)
deleted = result["deleted"]
failed = result["failed"]
if deleted:
await extension.call_extensions_async(
"workdir_file_mutation_after",
agent=None,
data={
"action": "bulk_delete",
"path": deleted[0],
"paths": deleted,
"current_path": current_path,
},
)
files_result = await get_work_dir_files.get_files(current_path)
if not deleted:
return {
"error": "Selected items could not be deleted",
"data": files_result,
"deleted": deleted,
"failed": failed,
}
return {
"data": files_result,
"deleted": deleted,
"failed": failed,
}
async def delete_files(paths: list[str]) -> dict:
browser = FileBrowser()
deleted: list[str] = []
failed: list[str] = []
for path in collapse_nested_paths(paths):
if path == "/":
failed.append(path)
continue
if browser.delete_file(path):
deleted.append(path)
else:
failed.append(path)
return {"deleted": deleted, "failed": failed}
def collapse_nested_paths(paths: list[str]) -> list[str]:
collapsed: list[str] = []
for path in sorted(normalize_paths(paths), key=lambda item: item.count("/")):
clean_path = "/" + path.strip("/")
if any(
clean_path == parent or clean_path.startswith(parent.rstrip("/") + "/")
for parent in collapsed
):
continue
collapsed.append(clean_path)
return collapsed