fix(computer_use): honor custom vision routing
This commit is contained in:
parent
ffe665277c
commit
591e6fb8f4
6 changed files with 207 additions and 7 deletions
|
|
@ -126,6 +126,45 @@ def _parse_elements_from_tree(markdown: str) -> List[UIElement]:
|
|||
return elements
|
||||
|
||||
|
||||
def _image_dimensions_from_bytes(raw: bytes) -> Tuple[int, int]:
|
||||
"""Best-effort PNG/JPEG dimension sniffing without extra dependencies."""
|
||||
if raw.startswith(b"\x89PNG\r\n\x1a\n") and len(raw) >= 24:
|
||||
width = int.from_bytes(raw[16:20], "big")
|
||||
height = int.from_bytes(raw[20:24], "big")
|
||||
if width > 0 and height > 0:
|
||||
return width, height
|
||||
|
||||
if raw.startswith(b"\xff\xd8"):
|
||||
i = 2
|
||||
n = len(raw)
|
||||
while i + 9 < n:
|
||||
if raw[i] != 0xFF:
|
||||
i += 1
|
||||
continue
|
||||
marker = raw[i + 1]
|
||||
i += 2
|
||||
if marker in {0xD8, 0xD9} or 0xD0 <= marker <= 0xD7:
|
||||
continue
|
||||
if i + 2 > n:
|
||||
break
|
||||
segment_len = int.from_bytes(raw[i:i + 2], "big")
|
||||
if segment_len < 2 or i + segment_len > n:
|
||||
break
|
||||
if marker in {
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7,
|
||||
0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF,
|
||||
}:
|
||||
if segment_len >= 7:
|
||||
height = int.from_bytes(raw[i + 3:i + 5], "big")
|
||||
width = int.from_bytes(raw[i + 5:i + 7], "big")
|
||||
if width > 0 and height > 0:
|
||||
return width, height
|
||||
break
|
||||
i += segment_len
|
||||
|
||||
return 0, 0
|
||||
|
||||
|
||||
def _split_tree_text(full_text: str) -> Tuple[str, str]:
|
||||
"""Split get_window_state text into (summary_line, tree_markdown)."""
|
||||
lines = full_text.split("\n", 1)
|
||||
|
|
@ -491,7 +530,12 @@ class CuaDriverBackend(ComputerUseBackend):
|
|||
png_bytes_len = 0
|
||||
if png_b64:
|
||||
try:
|
||||
png_bytes_len = len(base64.b64decode(png_b64, validate=False))
|
||||
raw = base64.b64decode(png_b64, validate=False)
|
||||
png_bytes_len = len(raw)
|
||||
detected_width, detected_height = _image_dimensions_from_bytes(raw)
|
||||
if detected_width and detected_height:
|
||||
width = detected_width
|
||||
height = detected_height
|
||||
except Exception:
|
||||
png_bytes_len = len(png_b64) * 3 // 4
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue