fix: Resize file in screen toolkit (#81)
Co-authored-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from rich.markdown import Markdown
|
||||||
|
from rich.panel import Panel
|
||||||
|
|
||||||
from goose.toolkit.base import Toolkit, tool
|
from goose.toolkit.base import Toolkit, tool
|
||||||
|
|
||||||
|
|
||||||
@@ -8,17 +11,30 @@ class Screen(Toolkit):
|
|||||||
"""Provides an instructions on when and how to work with screenshots"""
|
"""Provides an instructions on when and how to work with screenshots"""
|
||||||
|
|
||||||
@tool
|
@tool
|
||||||
def take_screenshot(self) -> str:
|
def take_screenshot(self, display: int = 1) -> str:
|
||||||
"""
|
"""
|
||||||
Take a screenshot to assist the user in debugging or designing an app. They may need help with moving a screen element, or interacting in some way where you could do with seeing the screen.
|
Take a screenshot to assist the user in debugging or designing an app. They may need
|
||||||
|
help with moving a screen element, or interacting in some way where you could do with
|
||||||
|
seeing the screen.
|
||||||
|
|
||||||
Return:
|
Args:
|
||||||
(str) a path to the screenshot file, in the format of image: followed by the path to the file.
|
display (int): Display to take the screen shot in. Default is the main display (1). Must be a value greater than 1.
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
# Generate a random tmp filename for screenshot
|
# Generate a random tmp filename for screenshot
|
||||||
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.png"
|
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.jpg"
|
||||||
|
screen_capture_command = ["screencapture", "-x", "-D", str(display), filename, "-f", "jpg"]
|
||||||
|
|
||||||
subprocess.run(["screencapture", "-x", filename])
|
subprocess.run(screen_capture_command, check=True, capture_output=True)
|
||||||
|
|
||||||
|
resize_command = ["sips", "--resampleWidth", "768", filename, "-s", "format", "jpeg"]
|
||||||
|
subprocess.run(resize_command, check=True, capture_output=True)
|
||||||
|
|
||||||
|
self.notifier.log(
|
||||||
|
Panel.fit(
|
||||||
|
Markdown(f"```bash\n{' '.join(screen_capture_command)}"),
|
||||||
|
title="screen",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return f"image:{filename}"
|
return f"image:{filename}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user