This commit is contained in:
@@ -20,21 +20,36 @@ class ArtifactStore:
|
||||
*,
|
||||
task_id: str,
|
||||
index: int,
|
||||
screenshot: bytes | None,
|
||||
before_screenshot: bytes | None,
|
||||
after_screenshot: bytes | None,
|
||||
record: dict[str, Any],
|
||||
) -> dict[str, str | None]:
|
||||
task_dir = self.task_dir(task_id)
|
||||
task_dir.mkdir(parents=True, exist_ok=True)
|
||||
stem = f"{index:03d}"
|
||||
screenshot_path: Path | None = None
|
||||
if screenshot is not None:
|
||||
screenshot_path = task_dir / f"{stem}.png"
|
||||
screenshot_path.write_bytes(screenshot)
|
||||
before_screenshot_path: Path | None = None
|
||||
after_screenshot_path: Path | None = None
|
||||
if before_screenshot is not None:
|
||||
before_screenshot_path = task_dir / f"{stem}-before.png"
|
||||
before_screenshot_path.write_bytes(before_screenshot)
|
||||
if after_screenshot is not None:
|
||||
# Preserve the original filename as the compatibility alias for the
|
||||
# screenshot captured after a step.
|
||||
after_screenshot_path = task_dir / f"{stem}.png"
|
||||
after_screenshot_path.write_bytes(after_screenshot)
|
||||
|
||||
json_path = task_dir / f"{stem}.json"
|
||||
payload = {
|
||||
**record,
|
||||
"screenshot_path": str(screenshot_path) if screenshot_path else None,
|
||||
"before_screenshot_path": (
|
||||
str(before_screenshot_path) if before_screenshot_path else None
|
||||
),
|
||||
"after_screenshot_path": (
|
||||
str(after_screenshot_path) if after_screenshot_path else None
|
||||
),
|
||||
"screenshot_path": (
|
||||
str(after_screenshot_path) if after_screenshot_path else None
|
||||
),
|
||||
}
|
||||
json_path.write_text(
|
||||
json.dumps(_jsonable(payload), ensure_ascii=False, indent=2),
|
||||
@@ -42,7 +57,15 @@ class ArtifactStore:
|
||||
)
|
||||
return {
|
||||
"json_path": str(json_path),
|
||||
"screenshot_path": str(screenshot_path) if screenshot_path else None,
|
||||
"before_screenshot_path": (
|
||||
str(before_screenshot_path) if before_screenshot_path else None
|
||||
),
|
||||
"after_screenshot_path": (
|
||||
str(after_screenshot_path) if after_screenshot_path else None
|
||||
),
|
||||
"screenshot_path": (
|
||||
str(after_screenshot_path) if after_screenshot_path else None
|
||||
),
|
||||
}
|
||||
|
||||
def read_steps(self, task_id: str) -> list[dict[str, Any]]:
|
||||
|
||||
Reference in New Issue
Block a user