Skip to content

Commit c6e5cb0

Browse files
TLSDCCopilot
andauthored
Update src/agentlab/analyze/agent_xray.py
Co-authored-by: Copilot <[email protected]>
1 parent 6569fb1 commit c6e5cb0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/agentlab/analyze/agent_xray.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,18 +544,21 @@ def tag_screenshot_with_action(screenshot: Image, action: str) -> Image:
544544
The tagged screenshot.
545545
"""
546546
if action.startswith("mouse_click"):
547-
coords = action[action.index("(") + 1 : action.index(")")].split(",")
548-
coords = [c.strip() for c in coords]
549-
if coords[0].startswith("x="):
550-
coords[0] = coords[0][2:]
551-
if coords[1].startswith("y="):
552-
coords[1] = coords[1][2:]
553-
x, y = float(coords[0].strip()), float(coords[1].strip())
554-
draw = ImageDraw.Draw(screenshot)
555-
radius = 5
556-
draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill="red", outline="red")
557-
return screenshot
558-
547+
try:
548+
coords = action[action.index("(") + 1 : action.index(")")].split(",")
549+
coords = [c.strip() for c in coords]
550+
if len(coords) != 2:
551+
raise ValueError(f"Invalid coordinate format: {coords}")
552+
if coords[0].startswith("x="):
553+
coords[0] = coords[0][2:]
554+
if coords[1].startswith("y="):
555+
coords[1] = coords[1][2:]
556+
x, y = float(coords[0].strip()), float(coords[1].strip())
557+
draw = ImageDraw.Draw(screenshot)
558+
radius = 5
559+
draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill="red", outline="red")
560+
except (ValueError, IndexError) as e:
561+
warning(f"Failed to parse action '{action}': {e}")
559562

560563
def update_screenshot(som_or_not: str):
561564
global info

0 commit comments

Comments
 (0)